Compare commits

...
58 Commits
Author SHA1 Message Date
github-actions[bot] 41c7af32c9 [CI Skip] release/stable 7.3.2
skip-checks: true
2023-12-06 09:28:24 +00:00
Jaco 68d698502d 7.3.2 (#553) 2023-12-06 11:23:54 +02:00
github-actions[bot] 3d4a87af6a [CI Skip] bump/beta 7.3.2-2-x
skip-checks: true
2023-12-06 08:57:15 +00:00
Jaco 77b1e338cf Sync fflate huffman tree with upstream (#552) 2023-12-06 10:52:27 +02:00
github-actions[bot] 3af17400ba [CI Skip] bump/beta 7.3.2-1-x
skip-checks: true
2023-12-06 08:48:37 +00:00
Jaco e16029776f Fix base64 last decoding offset (#551) 2023-12-06 10:44:07 +02:00
github-actions[bot] 61624a627b [CI Skip] bump/beta 7.3.2-0-x
skip-checks: true
2023-11-18 08:41:17 +00:00
Jaco c964570806 Bump common (#549) 2023-11-18 10:34:43 +02:00
github-actions[bot] f32846d41b [CI Skip] release/stable 7.3.1
skip-checks: true
2023-11-17 09:20:13 +00:00
Jaco 705b08765b 7.3.1 (#548) 2023-11-17 11:13:36 +02:00
github-actions[bot] 4f6771e758 [CI Skip] bump/beta 7.2.3-9-x
skip-checks: true
2023-11-17 08:15:49 +00:00
Jaco 731dee91e4 Update dev, drop Node 16 (#547) 2023-11-17 10:09:14 +02:00
github-actions[bot] b82e28ad4e [CI Skip] bump/beta 7.2.3-8-x
skip-checks: true
2023-10-15 10:55:03 +00:00
Jaco 6d5b3f5404 Bump TS (#546) 2023-10-15 13:46:13 +03:00
github-actions[bot] 1f643dd705 [CI Skip] bump/beta 7.2.3-7-x
skip-checks: true
2023-10-11 08:57:16 +00:00
Jaco af9491f7fd Bump deps (#545) 2023-10-11 11:49:18 +03:00
github-actions[bot] 7377da8e7e [CI Skip] bump/beta 7.2.3-6-x
skip-checks: true
2023-09-15 07:00:35 +00:00
Jaco 32fa12c3fa Bump deps (w/ util) (#543) 2023-09-15 09:53:57 +03:00
github-actions[bot] 6aabb2f869 [CI Skip] bump/beta 7.2.3-5-x
skip-checks: true
2023-09-14 05:23:44 +00:00
Jaco 0edb0289a9 Bump dev deps (#542) 2023-09-14 08:16:59 +03:00
github-actions[bot] 004996d772 [CI Skip] bump/beta 7.2.3-4-x
skip-checks: true
2023-08-31 12:51:49 +00:00
Jaco 7611fd1788 Collapse build:mac command into build (w/ detect) (#541) 2023-08-31 15:44:26 +03:00
github-actions[bot] e4f85e2358 [CI Skip] bump/beta 7.2.3-3-x
skip-checks: true
2023-08-30 06:37:28 +00:00
Jaco 6c5e7deaa5 Bump dev deps (#540) 2023-08-30 09:31:36 +03:00
github-actions[bot] 1f024c1da0 [CI Skip] bump/beta 7.2.3-2-x
skip-checks: true
2023-08-23 10:42:00 +00:00
Jaco 26b6cf843a Bump deps (#539) 2023-08-23 13:35:59 +03:00
github-actions[bot] 8e54efe4a5 [CI Skip] bump/beta 7.2.3-1-x
skip-checks: true
2023-08-20 06:57:44 +00:00
Jaco daecf47197 Bump deps (#537) 2023-08-20 09:51:51 +03:00
github-actions[bot] 6f5ed67aad [CI Skip] bump/beta 7.2.3-0-x
skip-checks: true
2023-08-18 06:44:50 +00:00
Jaco 8556566c1d Bump common (#536) 2023-08-18 09:38:25 +03:00
github-actions[bot] e28a5ffd4b [CI Skip] release/stable 7.2.2
skip-checks: true
2023-08-17 07:42:59 +00:00
Jaco 7f3ca3159d 7.2.2 (#535)
* 7.2.2

* CHANGELOG typo

* Adjust root dependencies
2023-08-17 10:37:26 +03:00
github-actions[bot] 3a3214e602 [CI Skip] bump/beta 7.2.2-12-x
skip-checks: true
2023-08-16 08:21:33 +00:00
Jaco 319f33bec1 Bump dev (#534)
* Bump dev

* Adjust linting
2023-08-16 11:14:44 +03:00
github-actions[bot] a8f5189252 [CI Skip] bump/beta 7.2.2-11-x
skip-checks: true
2023-08-16 06:22:41 +00:00
Jaco ee26a6ef98 Bump deps (w/ eslint updates) (#533) 2023-08-16 09:17:00 +03:00
github-actions[bot] 71291442bb [CI Skip] bump/beta 7.2.2-10-x
skip-checks: true
2023-07-06 07:27:43 +00:00
Jaco f26f855942 Bump deps (#532) 2023-07-06 10:22:27 +03:00
github-actions[bot] 3a06871f82 [CI Skip] bump/beta 7.2.2-9-x
skip-checks: true
2023-06-12 06:04:02 +00:00
Jaco 279da24ca1 Bump util (#531) 2023-06-12 08:57:00 +03:00
github-actions[bot] af81a69ba6 [CI Skip] bump/beta 7.2.2-8-x
skip-checks: true
2023-06-11 07:08:14 +00:00
Jaco 0b39c9d2f1 Bump common (#530) 2023-06-11 10:02:36 +03:00
github-actions[bot] 7d2de26fdb [CI Skip] bump/beta 7.2.2-7-x
skip-checks: true
2023-06-04 14:48:02 +00:00
Jaco fc370eedb2 Bump common (#529) 2023-06-04 17:42:36 +03:00
github-actions[bot] 792baf352c [CI Skip] bump/beta 7.2.2-6-x
skip-checks: true
2023-06-02 10:29:57 +00:00
Jaco a79d6ded77 Bump deps (w/ TS 5.1) (#528) 2023-06-02 13:24:22 +03:00
github-actions[bot] 51b45133d9 [CI Skip] bump/beta 7.2.2-5-x
skip-checks: true
2023-05-25 07:32:56 +00:00
Jaco b3c934d602 Bump dev deps (#527) 2023-05-25 10:27:24 +03:00
github-actions[bot] 25cd084f30 [CI Skip] bump/beta 7.2.2-4-x
skip-checks: true
2023-05-21 09:48:55 +00:00
Jaco 9df575ad7b Bump dev (w/ eslint config adj) (#526) 2023-05-21 12:43:14 +03:00
github-actions[bot] 0175ac56a7 [CI Skip] bump/beta 7.2.2-3-x
skip-checks: true
2023-05-18 09:04:24 +00:00
Jaco e589fba3b1 Adjust tsconfig usage (w/ latest dev) (#525) 2023-05-18 11:59:20 +03:00
github-actions[bot] 570c46e889 [CI Skip] bump/beta 7.2.2-2-x
skip-checks: true
2023-05-18 05:28:27 +00:00
Jaco 4d002c7563 Bump dev deps (#524) 2023-05-18 08:22:56 +03:00
github-actions[bot] 6aeaa69a8b [CI Skip] bump/beta 7.2.2-1-x
skip-checks: true
2023-05-16 06:36:58 +00:00
Jaco 4565f85077 CJS export cleanups (#523) 2023-05-16 09:31:41 +03:00
github-actions[bot] 0d0dcbf005 [CI Skip] bump/beta 7.2.2-0-x
skip-checks: true
2023-05-13 08:49:41 +00:00
Jaco 7e38ff8faf Bump util (#522) 2023-05-13 11:43:56 +03:00
55 changed files with 1781 additions and 827 deletions
-19
View File
@@ -1,19 +0,0 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const base = require('@polkadot/dev/config/eslint.cjs');
module.exports = {
...base,
ignorePatterns: [
...base.ignorePatterns,
'**/target/*',
'**/test/*.ts'
],
parserOptions: {
...base.parserOptions,
project: [
'./tsconfig.eslint.json'
]
}
};
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
if: always()
continue-on-error: true
run: |
yarn install --immutable | grep -v 'YN0013'
yarn install --immutable
if [ "${{ matrix.step }}" != "lint" ]; then
./scripts/install-build-deps.sh
fi
+1 -1
View File
@@ -27,6 +27,6 @@ jobs:
node-version: 'lts/*'
- name: build
run: |
yarn install --immutable | grep -v 'YN0013'
yarn install --immutable
./scripts/install-build-deps.sh
yarn ${{ matrix.step }}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2023 @polkadot/dev authors & contributors
// Copyright 2017-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
module.exports = require('@polkadot/dev/config/prettier.cjs');
+4
View File
@@ -0,0 +1,4 @@
{
"eslint.enable": true,
"eslint.experimental.useFlatConfig": true
}
+5
View File
@@ -2,6 +2,11 @@ enableImmutableInstalls: false
enableProgressBars: false
logFilters:
# Discard any "cannot be found in cache" messages
- code: YN0013
level: discard
nodeLinker: node-modules
plugins:
+23 -1
View File
@@ -1,5 +1,27 @@
# CHANGELOG
## 7.3.2 Dec 6, 2023
Changes:
- Apply fixes for OOB array access
## 7.3.1 Nov 17, 2023
Changes:
- Drop support for Node 16 (EOL 11 Sep 2023)
## 7.2.2 Aug 17, 2023
Changes:
- Adjust cjs exports for consistency
- Adjust usage of `?.` as per (latest) linting rules
## 7.2.1 May 13, 2023
Changes:
@@ -20,7 +42,7 @@ Changes:
Changes:
- Add `wasm-util` as dependency where `x-randowmvalues` is a peer
- Add `wasm-util` as dependency where `x-randomvalues` is a peer
- Drop support for Node 14 (EOL 30 Apr 2023)
+1 -1
View File
@@ -1,4 +1,4 @@
583 Jaco 7.2.1 (#521)
612 Jaco 7.3.2 (#553)
1 Evgeny Fixed type (#121)
1 Shunfan Zhou Support sr25519 agreement (#209)
1 Steve Degosserie Expose Schnorrkel's VRF capabilities (#170)
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import baseConfig from '@polkadot/dev/config/eslint';
export default [
...baseConfig
];
+8 -10
View File
@@ -14,10 +14,10 @@
},
"sideEffects": false,
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"versions": {
"git": "7.2.1",
"npm": "7.2.1"
"git": "7.3.2",
"npm": "7.3.2"
},
"workspaces": [
"packages/*"
@@ -25,7 +25,6 @@
"scripts": {
"build": "yarn build:wasm",
"build:js": "./scripts/build-js.sh",
"build:mac": "PATH=\"/opt/homebrew/opt/llvm/bin:$PATH\" CC=/opt/homebrew/opt/llvm/bin/clang AR=/opt/homebrew/opt/llvm/bin/llvm-ar yarn build",
"build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config",
"build:wasm": "./scripts/build.sh",
@@ -44,13 +43,12 @@
"test:wasm-crypto:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --test-threads=1 --nocapture"
},
"devDependencies": {
"@polkadot/dev": "^0.73.17",
"@polkadot/util": "^12.1.2",
"@polkadot/x-randomvalues": "^12.1.2",
"@types/node": "^20.1.3",
"fflate": "^0.7.4"
"@polkadot/dev": "^0.77.1",
"@polkadot/util": "^12.6.1",
"@types/node": "^20.9.1",
"fflate": "^0.8.1"
},
"resolutions": {
"typescript": "^5.0.4"
"typescript": "^5.2.2"
}
}
+6 -6
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "A bridge layer between JS and Wasm",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-bridge#readme",
"license": "Apache-2.0",
@@ -18,15 +18,15 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"main": "index.js",
"dependencies": {
"@polkadot/wasm-util": "7.2.1",
"tslib": "^2.5.0"
"@polkadot/wasm-util": "7.3.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2",
"@polkadot/x-randomvalues": "^12.1.2"
"@polkadot/util": "^12.6.1",
"@polkadot/x-randomvalues": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+1 -1
View File
@@ -18,7 +18,7 @@ import { Wbg } from './wbg.js';
* @description
* Creates a bridge between the JS and WASM environments.
*
* For any bridge it is passed an function white is then called internally at the
* For any bridge it is passed an function which is then called internally at the
* time of initialization. This affectively implements the layer between WASM and
* the native environment, providing all the plumbing needed for the Wbg classes.
*/
+3 -3
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/wasm-bundle authors & contributors
// Copyright 2019-2023 @polkadot/wasm-bridge authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { InitFn, InitPromise, InitResult, WasmBaseInstance, WasmImports } from './types.js';
@@ -11,7 +11,7 @@ import type { InitFn, InitPromise, InitResult, WasmBaseInstance, WasmImports } f
* It will attempt to create a WASM interface first and if this fails or is not available in
* the environment, will fallback to attempting to create an ASM.js interface.
*/
export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WasmImports) => C)): InitFn<C> {
export function createWasmFn <C extends WasmBaseInstance> (root: 'crypto', wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WasmImports) => C)): InitFn<C> {
return async (wbg: WasmImports): InitPromise<C> => {
const result: InitResult<C> = {
error: null,
@@ -20,7 +20,7 @@ export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmByt
};
try {
if (!wasmBytes || !wasmBytes.length) {
if (!wasmBytes?.length) {
throw new Error('No WebAssembly provided for initialization');
} else if (typeof WebAssembly !== 'object' || typeof WebAssembly.instantiate !== 'function') {
throw new Error('WebAssembly is not available in your environment');
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '7.3.2' };
+6 -6
View File
@@ -7,7 +7,7 @@ export type WasmImports = Record<string, (...args: never[]) => unknown>;
// Use non-strong types instead of WebAssembly.Memory which may not
// be available as part of the TS environment types (it needs dom)
export type WasmMemory = { buffer: ArrayBuffer };
export interface WasmMemory { buffer: ArrayBuffer }
export declare interface InitResult<C extends WasmBaseInstance> {
error: string | null;
@@ -35,13 +35,13 @@ export interface BridgeBase<C extends WasmBaseInstance> extends InitResult<C> {
resultString (): string;
}
export interface WasmBaseInstance {
memory: WasmMemory;
// wbindgen functions (required and used internally)
export interface WasmBindGen {
__wbindgen_exn_store (a: number): void;
__wbindgen_free (a: number, b: number): void;
__wbindgen_malloc (a: number): number;
__wbindgen_realloc (a: number, b: number, c: number): number;
}
export interface WasmBaseInstance extends WasmBindGen {
memory: WasmMemory;
}
+4 -2
View File
@@ -5,6 +5,8 @@
"outDir": "./build",
"rootDir": "./src"
},
"references": [
]
"exclude": [
"**/mod.ts"
],
"references": []
}
+4 -4
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "Asm.js content for wasm-crypto",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-asmjs#readme",
"license": "Apache-2.0",
@@ -15,13 +15,13 @@
},
"sideEffects": false,
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"main": "index.js",
"dependencies": {
"tslib": "^2.5.0"
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2"
"@polkadot/util": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+1 -1
View File
@@ -3,4 +3,4 @@
const asmJsInit = null;
module.exports.asmJsInit = asmJsInit;
exports.asmJsInit = asmJsInit;
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '7.3.2' };
@@ -5,5 +5,8 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts"
],
"references": []
}
+9 -9
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "Init handlers for wasm-crypto",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-init#readme",
"license": "Apache-2.0",
@@ -18,20 +18,20 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"browser": "wasm.js",
"main": "wasm.js",
"react-native": "asm.js",
"dependencies": {
"@polkadot/wasm-bridge": "7.2.1",
"@polkadot/wasm-crypto-asmjs": "7.2.1",
"@polkadot/wasm-crypto-wasm": "7.2.1",
"@polkadot/wasm-util": "7.2.1",
"tslib": "^2.5.0"
"@polkadot/wasm-bridge": "7.3.2",
"@polkadot/wasm-crypto-asmjs": "7.3.2",
"@polkadot/wasm-crypto-wasm": "7.3.2",
"@polkadot/wasm-util": "7.3.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2",
"@polkadot/x-randomvalues": "^12.1.2"
"@polkadot/util": "^12.6.1",
"@polkadot/x-randomvalues": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-init', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-init', path: 'auto', type: 'auto', version: '7.3.2' };
@@ -5,6 +5,9 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts"
],
"references": [
{ "path": "../wasm-bridge/tsconfig.build.json" },
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
+5 -5
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "Wasm content for wasm-crypto",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-wasm#readme",
"license": "Apache-2.0",
@@ -15,14 +15,14 @@
},
"sideEffects": false,
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"main": "index.js",
"dependencies": {
"@polkadot/wasm-util": "7.2.1",
"tslib": "^2.5.0"
"@polkadot/wasm-util": "7.3.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2"
"@polkadot/util": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '7.3.2' };
@@ -5,6 +5,9 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts"
],
"references": [
{ "path": "../wasm-util/tsconfig.build.json" }
]
+10 -10
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "A wasm interface layer for use by @polkadot/util-crypto",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto#readme",
"license": "Apache-2.0",
@@ -26,19 +26,19 @@
"./initWasmAsm.cjs"
],
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"main": "index.js",
"dependencies": {
"@polkadot/wasm-bridge": "7.2.1",
"@polkadot/wasm-crypto-asmjs": "7.2.1",
"@polkadot/wasm-crypto-init": "7.2.1",
"@polkadot/wasm-crypto-wasm": "7.2.1",
"@polkadot/wasm-util": "7.2.1",
"tslib": "^2.5.0"
"@polkadot/wasm-bridge": "7.3.2",
"@polkadot/wasm-crypto-asmjs": "7.3.2",
"@polkadot/wasm-crypto-init": "7.3.2",
"@polkadot/wasm-crypto-wasm": "7.3.2",
"@polkadot/wasm-util": "7.3.2",
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2",
"@polkadot/x-randomvalues": "^12.1.2"
"@polkadot/util": "^12.6.1",
"@polkadot/x-randomvalues": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '7.3.2' };
+20
View File
@@ -1,8 +1,13 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import { assert, u8aToHex } from '@polkadot/util';
/**
* @param {*} wasm
*/
export function bip39Generate (wasm) {
it('generates a bip39 phrase', () => {
const res = wasm.bip39Generate(21);
@@ -13,6 +18,9 @@ export function bip39Generate (wasm) {
});
}
/**
* @param {*} wasm
*/
export function bip39GenerateSubsequent (wasm) {
it('generates different subsequent mnemonics', () => {
const val1 = wasm.bip39Generate(24);
@@ -25,6 +33,9 @@ export function bip39GenerateSubsequent (wasm) {
});
}
/**
* @param {*} wasm
*/
export function bip39Validate (wasm) {
it('validates a created mnemonic', () => {
const res = wasm.bip39Validate(wasm.bip39Generate(12));
@@ -35,6 +46,9 @@ export function bip39Validate (wasm) {
});
}
/**
* @param {*} wasm
*/
export function bip39ToEntropy (wasm) {
it('creates correct entropy for a known mnemonic', () => {
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
@@ -45,6 +59,9 @@ export function bip39ToEntropy (wasm) {
});
}
/**
* @param {*} wasm
*/
export function bip39ToMiniSecret (wasm) {
it('creates the correct minisecret from a mnemonic', () => {
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
@@ -55,6 +72,9 @@ export function bip39ToMiniSecret (wasm) {
});
}
/**
* @param {*} wasm
*/
export function bip39ToSeed (wasm) {
it('creates the correct seed for a mnemonic', () => {
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
+24 -4
View File
@@ -1,20 +1,31 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import crypto from 'crypto';
import { assert, hexToU8a, stringToU8a, u8aToHex } from '@polkadot/util';
/** @internal */
/**
* @internal
* @param {*} pair
*/
function extractKeys (pair) {
return [pair, pair.slice(32), pair.slice(0, 32)];
}
/** @internal */
/**
* @internal
* @param {*} wasm
*/
function randomPair (wasm) {
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
}
/**
* @param {*} wasm
*/
export function ed25519PairFromSeed (wasm) {
it('creates a known pair from a known seed', () => {
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
@@ -22,12 +33,15 @@ export function ed25519PairFromSeed (wasm) {
// console.log('\tSEC', u8aToHex(sk));
// console.log('\tPUB', u8aToHex(pk));
assert(u8aToHex(sk) === '0x3132333435363738393031323334353637383930313233343536373839303132');
assert(u8aToHex(pk) === '0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee');
assert(u8aToHex(sk) === '0x3132333435363738393031323334353637383930313233343536373839303132', 'Secretkey does not match');
assert(u8aToHex(pk) === '0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'Public key does not match');
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
});
}
/**
* @param {*} wasm
*/
export function ed25519SignAndVerify (wasm) {
it('signs and verifies', () => {
const [, pk, sk] = randomPair(wasm);
@@ -41,6 +55,9 @@ export function ed25519SignAndVerify (wasm) {
});
}
/**
* @param {*} wasm
*/
export function ed25519VerifyExisting (wasm) {
it('verifies a known signature', () => {
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
@@ -51,6 +68,9 @@ export function ed25519VerifyExisting (wasm) {
});
}
/**
* @param {*} wasm
*/
export function ed25519Benchmark (wasm) {
it('runs a verification benchamark', () => {
const MESSAGE = stringToU8a('this is a message');
+32
View File
@@ -1,8 +1,13 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import { assert, stringToU8a, u8aToHex } from '@polkadot/util';
/**
* @param {*} wasm
*/
export function blake2bHash (wasm) {
it('creates a known blake2b hash', () => {
const hash = u8aToHex(wasm.blake2b(stringToU8a('abc'), new Uint8Array(), 64));
@@ -13,6 +18,9 @@ export function blake2bHash (wasm) {
});
}
/**
* @param {*} wasm
*/
export function hmacSha256 (wasm) {
it('creates a known hmacSha256', () => {
const hash = u8aToHex(wasm.hmacSha256(stringToU8a('secret'), stringToU8a('some message')));
@@ -23,6 +31,9 @@ export function hmacSha256 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function hmacSha512 (wasm) {
it('creates a known hmacSha512', () => {
const hash = u8aToHex(wasm.hmacSha512(stringToU8a('secret'), stringToU8a('some message')));
@@ -33,6 +44,9 @@ export function hmacSha512 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function keccak256 (wasm) {
it('creates a known keccak256 hash', () => {
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
@@ -43,6 +57,9 @@ export function keccak256 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function keccak512 (wasm) {
it('creates a known keccak512 hash', () => {
const hash = u8aToHex(wasm.keccak512(stringToU8a('test')));
@@ -53,6 +70,9 @@ export function keccak512 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function pbkdf2Hash (wasm) {
it('creates a known pbkdf2 hash', () => {
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
@@ -63,6 +83,9 @@ export function pbkdf2Hash (wasm) {
});
}
/**
* @param {*} wasm
*/
export function scryptHash (wasm) {
it('creates a known scrypt hash', () => {
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
@@ -73,6 +96,9 @@ export function scryptHash (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sha256Hash (wasm) {
it('creates a known sha256 hash', () => {
const hash = u8aToHex(wasm.sha256(stringToU8a('hello world')));
@@ -83,6 +109,9 @@ export function sha256Hash (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sha512Hash (wasm) {
it('creates a known sha512 hash', () => {
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
@@ -93,6 +122,9 @@ export function sha512Hash (wasm) {
});
}
/**
* @param {*} wasm
*/
export function twoxHash (wasm) {
it('creates a known twox hash', () => {
const hash64 = u8aToHex(wasm.twox(stringToU8a('abc'), 1));
+22 -2
View File
@@ -1,6 +1,8 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global describe */
import { assert } from '@polkadot/util';
import * as bip39 from './bip39.js';
@@ -23,6 +25,10 @@ export const tests = {
vrf
};
/**
* @param {string} name
* @param {*} wasm
*/
export async function initRun (name, wasm) {
const result = await wasm.waitReady();
@@ -33,7 +39,12 @@ export async function initRun (name, wasm) {
return result;
}
/**
* @param {string} name
* @param {*} wasm
*/
export function runAll (name, wasm) {
/** @type {string[]} */
const failed = [];
let count = 0;
@@ -51,7 +62,6 @@ export function runAll (name, wasm) {
try {
console.time(timerId);
console.log();
// console.log(timerId);
test(wasm);
@@ -71,19 +81,29 @@ export function runAll (name, wasm) {
}
}
/**
* @param {string} type
* @param {*} wasm
*/
export function runUnassisted (type, wasm) {
console.log(`\n*** ${type}: Running tests`);
// for these we are pass-through describe and it handlers
// For these we are pass-through describe and it handlers
// @ts-expect-error We are hacking this, so expect TS to be unhappy...
globalThis.describe = (name, fn) => {
console.log('\n', name);
// We expect this to be handled top-level, in the test itself
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fn();
};
// @ts-expect-error We are hacking this, so expect TS to be unhappy...
globalThis.it = (name, fn) => {
console.log(`\t${name}`);
// We expect this to be handled top-level, in the test itself
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fn();
};
@@ -1,8 +1,13 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import { assert, hexToU8a, u8aToHex } from '@polkadot/util';
/**
* @param {*} wasm
*/
export function secp256k1Compress (wasm) {
it('compresses a known publicKey', () => {
const pubkey = '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af';
@@ -14,6 +19,9 @@ export function secp256k1Compress (wasm) {
});
}
/**
* @param {*} wasm
*/
export function secp256k1Expand (wasm) {
it('expands a known compressed key', () => {
const pubkey = '0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077';
@@ -25,6 +33,9 @@ export function secp256k1Expand (wasm) {
});
}
/**
* @param {*} wasm
*/
export function secp256k1FromSeed1 (wasm) {
it('creates a known pair from seed (1)', () => {
const seckey = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
@@ -36,6 +47,9 @@ export function secp256k1FromSeed1 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function secp256k1FromSeed2 (wasm) {
it('creates a known pair from seed (2)', () => {
// https://github.com/polkadot-js/wasm/issues/307
@@ -60,6 +74,9 @@ export function secp256k1FromSeed2 (wasm) {
});
}
/**
* @param {*} wasm
*/
export function secp256k1Recover (wasm) {
it('recovers a publicKey from signature', () => {
const sig = '0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff';
@@ -72,6 +89,9 @@ export function secp256k1Recover (wasm) {
});
}
/**
* @param {*} wasm
*/
export function secp256k1Sign (wasm) {
it('creates a known signature', () => {
const sec = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
+48 -4
View File
@@ -1,20 +1,31 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import crypto from 'crypto';
import { assert, hexToU8a, stringToU8a, u8aToHex } from '@polkadot/util';
/** @internal */
/**
* @internal
* @param {*} pair
*/
function extractKeys (pair) {
return [pair, pair.slice(64), pair.slice(0, 64)];
}
/** @internal */
/**
* @internal
* @param {*} wasm
*/
function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
/**
* @param {*} wasm
*/
export function sr25519PairFromSeed (wasm) {
it('creates a known pair from a known seed', () => {
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
@@ -26,6 +37,9 @@ export function sr25519PairFromSeed (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519DevFromSeed (wasm) {
it('creates a known development pair', () => {
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
@@ -37,6 +51,9 @@ export function sr25519DevFromSeed (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519VerifyExisting (wasm) {
it('verifies a known signature', () => {
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
@@ -51,6 +68,9 @@ export function sr25519VerifyExisting (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519SignDeterministic (wasm) {
it('creates non-deterministic signatures', () => {
const [, pk, sk] = randomPair(wasm);
@@ -64,6 +84,9 @@ export function sr25519SignDeterministic (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519SignAndVerify (wasm) {
it('verifies a created signature', () => {
const [, pk, sk] = randomPair(wasm);
@@ -77,6 +100,9 @@ export function sr25519SignAndVerify (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519DeriveHard (wasm) {
it('derives using a hard path', () => {
const [pair] = randomPair(wasm);
@@ -85,10 +111,13 @@ export function sr25519DeriveHard (wasm) {
// console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
// console.log('\tPUB', u8aToHex(derived.slice(64)));
assert(derived.length === 96);
assert(derived.length === 96, 'Derived key length mismatch');
});
}
/**
* @param {*} wasm
*/
export function sr25519DeriveHardKnown (wasm) {
it('derives a known hard key', () => {
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
@@ -101,6 +130,9 @@ export function sr25519DeriveHardKnown (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519DeriveSoft (wasm) {
it('derives using a soft path', () => {
const [pair] = randomPair(wasm);
@@ -109,10 +141,13 @@ export function sr25519DeriveSoft (wasm) {
// console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
// console.log('\tPUB', u8aToHex(derived.slice(64)));
assert(derived.length === 96);
assert(derived.length === 96, 'Derived key length mismatch');
});
}
/**
* @param {*} wasm
*/
export function sr25519DeriveSoftKnown (wasm) {
it('derives a known soft key', () => {
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -125,6 +160,9 @@ export function sr25519DeriveSoftKnown (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519DeriveSoftPubkey (wasm) {
it('derives a known soft publicKey', () => {
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
@@ -135,6 +173,9 @@ export function sr25519DeriveSoftPubkey (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519KeyAgreement (wasm) {
it('allows for agreements', () => {
const pair1 = wasm.sr25519KeypairFromSeed(hexToU8a('0x3b44c558f9a8f3dc9690d53088558c1ba2529b677e316c6054d1852595b004af'));
@@ -154,6 +195,9 @@ export function sr25519KeyAgreement (wasm) {
});
}
/**
* @param {*} wasm
*/
export function sr25519Benchmark (wasm) {
it('runs a verification benchmark', () => {
const MESSAGE = stringToU8a('this is a message');
+19
View File
@@ -1,18 +1,31 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* global it */
import crypto from 'crypto';
import { assert, stringToU8a, u8aToHex } from '@polkadot/util';
/**
* @internal
* @param {*} pair
*/
function extractKeys (pair) {
return [pair, pair.slice(64), pair.slice(0, 64)];
}
/**
* @internal
* @param {*} wasm
*/
function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
/**
* @param {*} wasm
*/
export function vrfSignAndVerifyCompat (wasm) {
it('can sign and verify (1)', () => {
const [, pk, sk] = randomPair(wasm);
@@ -26,6 +39,9 @@ export function vrfSignAndVerifyCompat (wasm) {
});
}
/**
* @param {*} wasm
*/
export function vrfSignAndVerify (wasm) {
it('can sign and verify (2)', () => {
const [, pk, sk] = randomPair(wasm);
@@ -39,6 +55,9 @@ export function vrfSignAndVerify (wasm) {
});
}
/**
* @param {*} wasm
*/
export function vrfSignAndVerifyDeterministic (wasm) {
it('has non-deterministic outputs', () => {
const [,, sk] = randomPair(wasm);
+15 -3
View File
@@ -1,13 +1,25 @@
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// This is a Deno file, so we can allow .ts imports
/* eslint-disable import/extensions */
// NOTE We don't use ts-expect-error here since the build folder may or may
// not exist (so the error may or may not be there)
//
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore This should only run against the compiled ouput, where this should exist
import * as wasm from '../build-deno/mod.ts';
import { initRun, tests } from './all/index.js';
declare const globalThis;
type Tests = Record<string, (wasm: unknown) => void>;
declare const globalThis: {
it: (name: string, fn: () => void) => unknown;
};
declare const Deno: {
test: (name: string, test: () => unknown) => unknown;
}
};
await initRun('wasm', wasm);
@@ -15,7 +27,7 @@ await initRun('wasm', wasm);
globalThis.it = (name: string, fn: () => void) => Deno.test(name, () => fn());
Object
.entries<{ [key: string]: (wasm: unknown) => void }>(tests)
.entries<Tests>(tests)
.forEach(([describeName, tests]) => {
console.log('***', describeName);
+7 -2
View File
@@ -3,6 +3,11 @@
/// <reference types="@polkadot/dev-test/globals.d.ts" />
// NOTE We don't use ts-expect-error here since the build folder may or may
// not exist (so the error may or may not be there)
//
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore This should only run against the compiled ouput, where this should exist
import * as wasm from '../build/index.js';
import { initRun, tests } from './all/index.js';
@@ -10,9 +15,9 @@ describe('wasm-crypto', (): void => {
beforeAll(() => initRun('wasm', wasm));
for (const name of Object.keys(tests)) {
describe(name, (): void => {
describe(`${name}`, (): void => {
Object
.values<(wasm: unknown) => void>(tests[name])
.values<(wasm: unknown) => void>(tests[name as keyof typeof tests])
.forEach((fn) => fn(wasm));
});
}
+9 -2
View File
@@ -5,9 +5,16 @@ import path from 'node:path';
import process from 'node:process';
import { pathToFileURL } from 'node:url';
// Adjusts the resolver to point to the build output
/**
* Adjusts the resolver to point to the build output
*
* @param {*} specifier
* @param {*} context
* @param {*} nextResolve
* @returns {*}
*/
export function resolve (specifier, context, nextResolve) {
if (/^@polkadot\/wasm-/.test(specifier)) {
if (specifier.startsWith('@polkadot/wasm-')) {
const parts = specifier.split(/[\\/]/);
return {
+2 -1
View File
@@ -6,7 +6,8 @@
"rootDir": "./src"
},
"exclude": [
"**/test/*.ts"
"**/mod.ts",
"**/test/**/*"
],
"references": [
{ "path": "../wasm-bridge/tsconfig.build.json" },
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./test",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/test/**/*"
],
"references": [
{ "path": "../wasm-crypto/tsconfig.build.json" }
]
}
+4 -4
View File
@@ -3,7 +3,7 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"description": "Utilities used exclusively inside Wasm decoding",
"engines": {
"node": ">=16"
"node": ">=18"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-util#readme",
"license": "Apache-2.0",
@@ -18,13 +18,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "7.2.1",
"version": "7.3.2",
"main": "index.js",
"dependencies": {
"tslib": "^2.5.0"
"tslib": "^2.6.2"
},
"devDependencies": {
"@polkadot/util": "^12.1.2"
"@polkadot/util": "^12.6.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+1 -3
View File
@@ -5,12 +5,10 @@
import { base64Decode } from './base64.js';
const HELLO_DUAL = 'aGVsbG8gd29ybGQg0J/RgNC40LLQtdGC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==';
const TESTS = [
{
// hello world Приветствую ми 你好
base64: HELLO_DUAL,
base64: 'aGVsbG8gd29ybGQg0J/RgNC40LLQtdGC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==',
output: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 209, 129, 209, 130, 208, 178, 209, 131, 209, 142, 32, 208, 188, 208, 184, 32, 228, 189, 160, 229, 165, 189])
},
{
+8 -8
View File
@@ -3,33 +3,33 @@
// Use an array for our indexer - this is faster than using map access. In
// this case we assume ASCII-only inputs, so we cannot overflow the array
const chr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const CHR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' as const;
const map = new Array<number>(256);
// We use charCodeAt for access here and in the decoder loop - this is faster
// on lookups (array + numbers) and also faster than accessing the specific
// character via data[i]
for (let i = 0, count = chr.length; i < count; i++) {
map[chr.charCodeAt(i)] = i;
for (let i = 0, count = CHR.length; i < count; i++) {
map[CHR.charCodeAt(i)] = i;
}
/**
* @name base64Decode
* @description
* A base64Decoding function that operates in all environments. Unlike decoding
* A base64 decoding function that operates in all environments. Unlike decoding
* from Buffer (Node.js only) or atob (browser-only) this implementation is
* slightly slower, but it is platform independent.
*
* For our usage, since we have access to the static final size (where used), we
* decode to a specified output buffer. This also means we have applied a number
* of optimizations based on this - checking output position instead of chars.
* For our usage, since we have access to the static final size, so we decode
* to a specified output buffer. This also means we have applied a number of
* optimizations based on this - checking output position instead of chars.
*/
export function base64Decode (data: string, out: Uint8Array): Uint8Array {
let byte = 0;
let bits = 0;
let pos = -1;
for (let i = 0, count = out.length; pos < count; i++) {
for (let i = 0, last = out.length - 1; pos !== last; i++) {
// each character represents 6 bits
byte = (byte << 6) | map[data.charCodeAt(i)];
+13 -6
View File
@@ -12,8 +12,9 @@
// - https://github.com/polkadot-js/api/issues/2963
// - https://github.com/101arrowz/fflate/issues/17
//
// Only tweaks make here are some TS adjustments (we use strict null checks), the code is otherwise as-is with
// only the single required function provided (compression is still being done in the build with fflate)
// Only tweaks made here are some TS adjustments (we use strict null checks),
// the code is otherwise as-is with only the single required function provided
// (compression is still being done in the build with fflate)
/* eslint-disable */
@@ -91,10 +92,12 @@ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
// u16 "map": index -> # of codes with bit length = index
const l = new u16(mb);
// length of cd must be 288 (total # of codes)
for (; i < s; ++i) ++l[cd[i] - 1];
for (; i < s; ++i) {
if (cd[i]) ++l[cd[i] - 1];
}
// u16 "map": index -> minimum code for bit length = index
const le = new u16(mb);
for (i = 0; i < mb; ++i) {
for (i = 1; i < mb; ++i) {
le[i] = (le[i - 1] + l[i - 1]) << 1;
}
let co: Uint16Array;
@@ -115,13 +118,17 @@ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
// m is end value
for (const m = v | ((1 << r) - 1); v <= m; ++v) {
// every 16 bit value starting with the code yields the same result
co[rev[v] >>> rvb] = sv;
co[rev[v] >> rvb] = sv;
}
}
}
} else {
co = new u16(s);
for (i = 0; i < s; ++i) co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);
for (i = 0; i < s; ++i) {
if (cd[i]) {
co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
}
}
}
return co;
});
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '7.2.1' };
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '7.3.2' };
+4
View File
@@ -5,5 +5,9 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts",
"**/*.spec.ts",
],
"references": []
}
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/*.spec.ts"
],
"references": [
{ "path": "../wasm-util/tsconfig.build.json" }
]
}
+1 -1
View File
@@ -45,7 +45,7 @@ cp $ASM $DENO_ASM
# cleanup the generated asm, converting to cjs
sed -i -e '/import {/d' $ASM
sed -i -e '1,/var retasmFunc = /!d' $ASM
sed -i -e 's/var retasmFunc = .*/const asmJsInit = (wbg) => asmFunc(wbg);\n\nmodule.exports = { asmJsInit };/g' $ASM
sed -i -e 's/var retasmFunc = .*/exports.asmJsInit = (wbg) => asmFunc(wbg);/g' $ASM
# same as the cjs version, this time for deno
sed -i -e '/import {/d' $DENO_ASM
+13 -1
View File
@@ -11,7 +11,19 @@ echo "*** Building JavaScript"
echo "*** Building WASM"
cd packages
PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
unamestr=`uname`
# For Mac we set extra paths for clang
if [[ "$unamestr" == "Darwin" ]]; then
if [ ! -f "/opt/homebrew/opt/llvm/bin/clang" ]; then
echo "FATAL: Ensure you have clang installed via homebrew"
exit 1
fi
PATH="/opt/homebrew/opt/llvm/bin:$PATH" CC=/opt/homebrew/opt/llvm/bin/clang AR=/opt/homebrew/opt/llvm/bin/llvm-ar PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
else
PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
fi
if [ -z "$WITH_DENO" ]; then
yarn test:wasm-crypto:js
+6 -5
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2023 @polkadot/wasm authors & contributors
// Copyright 2019-2023 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { zlibSync } from 'fflate/node';
@@ -6,11 +6,12 @@ import fs from 'node:fs';
import { formatNumber } from '@polkadot/util';
const DIR_DENO = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
const DIR_CJS = `./${process.env.PKG_NAME}-wasm/build/cjs`;
const HDR = `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Generated as part of the build, do not edit\n`;
const PKG_NAME = process.env['PKG_NAME'];
const DIR_DENO = `./${PKG_NAME}-wasm/build-deno/deno`;
const DIR_CJS = `./${PKG_NAME}-wasm/build/cjs`;
const HDR = `// Copyright 2019-${new Date().getFullYear()} @polkadot/${PKG_NAME}-wasm authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Generated as part of the build, do not edit\n`;
const data = fs.readFileSync(`./${process.env.PKG_NAME}/build-wasm/wasm_opt.wasm`);
const data = fs.readFileSync(`./${PKG_NAME}/build-wasm/wasm_opt.wasm`);
const compressed = Buffer.from(zlibSync(data, { level: 9 }));
const base64 = compressed.toString('base64');
+4 -1
View File
@@ -4,10 +4,13 @@
},
"files": [],
"references": [
{ "path": "./packages/wasm-bridge/tsconfig.build.json" },
{ "path": "./packages/wasm-crypto/tsconfig.build.json" },
{ "path": "./packages/wasm-crypto/tsconfig.spec.json" },
{ "path": "./packages/wasm-crypto-init/tsconfig.build.json" },
{ "path": "./packages/wasm-crypto-asmjs/tsconfig.build.json" },
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" },
{ "path": "./packages/wasm-util/tsconfig.build.json" }
{ "path": "./packages/wasm-util/tsconfig.build.json" },
{ "path": "./packages/wasm-util/tsconfig.spec.json" }
]
}
+4 -1
View File
@@ -7,7 +7,10 @@
"include": [
"packages/**/src/**/*",
"packages/**/test/**/*",
"scripts/**/*"
"scripts/**/*",
".prettierrc.cjs",
"eslint.config.js",
"rollup.config.js"
],
"exclude": [
"**/node_modules/**/*"
+3 -1
View File
@@ -5,7 +5,9 @@
"composite": false
},
"include": [
"packages/**/src/**/*"
"packages/**/src/**/*",
"packages/**/test/**/*",
"scripts/**/*"
],
"exclude": [
"**/node_modules/**/*"
+1354 -691
View File
File diff suppressed because it is too large Load Diff