Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41c7af32c9 | ||
|
|
68d698502d | ||
|
|
3d4a87af6a | ||
|
|
77b1e338cf | ||
|
|
3af17400ba | ||
|
|
e16029776f | ||
|
|
61624a627b | ||
|
|
c964570806 | ||
|
|
f32846d41b | ||
|
|
705b08765b | ||
|
|
4f6771e758 | ||
|
|
731dee91e4 | ||
|
|
b82e28ad4e | ||
|
|
6d5b3f5404 | ||
|
|
1f643dd705 | ||
|
|
af9491f7fd | ||
|
|
7377da8e7e | ||
|
|
32fa12c3fa | ||
|
|
6aabb2f869 | ||
|
|
0edb0289a9 | ||
|
|
004996d772 | ||
|
|
7611fd1788 | ||
|
|
e4f85e2358 | ||
|
|
6c5e7deaa5 | ||
|
|
1f024c1da0 | ||
|
|
26b6cf843a | ||
|
|
8e54efe4a5 | ||
|
|
daecf47197 | ||
|
|
6f5ed67aad | ||
|
|
8556566c1d | ||
|
|
e28a5ffd4b | ||
|
|
7f3ca3159d | ||
|
|
3a3214e602 | ||
|
|
319f33bec1 | ||
|
|
a8f5189252 | ||
|
|
ee26a6ef98 | ||
|
|
71291442bb | ||
|
|
f26f855942 | ||
|
|
3a06871f82 | ||
|
|
279da24ca1 | ||
|
|
af81a69ba6 | ||
|
|
0b39c9d2f1 | ||
|
|
7d2de26fdb | ||
|
|
fc370eedb2 | ||
|
|
792baf352c | ||
|
|
a79d6ded77 | ||
|
|
51b45133d9 | ||
|
|
b3c934d602 | ||
|
|
25cd084f30 | ||
|
|
9df575ad7b | ||
|
|
0175ac56a7 | ||
|
|
e589fba3b1 | ||
|
|
570c46e889 | ||
|
|
4d002c7563 | ||
|
|
6aeaa69a8b | ||
|
|
4565f85077 | ||
|
|
0d0dcbf005 | ||
|
|
7e38ff8faf |
@@ -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'
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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');
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"eslint.enable": true,
|
||||
"eslint.experimental.useFlatConfig": true
|
||||
}
|
||||
@@ -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
@@ -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
@@ -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)
|
||||
|
||||
@@ -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
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": "*",
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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' };
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
]
|
||||
"exclude": [
|
||||
"**/mod.ts"
|
||||
],
|
||||
"references": []
|
||||
}
|
||||
|
||||
@@ -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": "*"
|
||||
|
||||
@@ -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": []
|
||||
}
|
||||
|
||||
@@ -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": "*",
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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": "*"
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
|
||||
@@ -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": "*",
|
||||
|
||||
@@ -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' };
|
||||
|
||||
@@ -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', ''));
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/test/*.ts"
|
||||
"**/mod.ts",
|
||||
"**/test/**/*"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../wasm-bridge/tsconfig.build.json" },
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -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": "*"
|
||||
|
||||
@@ -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])
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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)];
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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' };
|
||||
|
||||
@@ -5,5 +5,9 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/mod.ts",
|
||||
"**/*.spec.ts",
|
||||
],
|
||||
"references": []
|
||||
}
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -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" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
"include": [
|
||||
"packages/**/src/**/*",
|
||||
"packages/**/test/**/*",
|
||||
"scripts/**/*"
|
||||
"scripts/**/*",
|
||||
".prettierrc.cjs",
|
||||
"eslint.config.js",
|
||||
"rollup.config.js"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**/*"
|
||||
|
||||
+3
-1
@@ -5,7 +5,9 @@
|
||||
"composite": false
|
||||
},
|
||||
"include": [
|
||||
"packages/**/src/**/*"
|
||||
"packages/**/src/**/*",
|
||||
"packages/**/test/**/*",
|
||||
"scripts/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**/*"
|
||||
|
||||
Reference in New Issue
Block a user