Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
346720f384 | ||
|
|
aeade5636a | ||
|
|
9f3c8f1f74 | ||
|
|
3d1e48ec4b | ||
|
|
cbffca3984 | ||
|
|
9d6427d9da | ||
|
|
368cb6806f | ||
|
|
9795eaf31c | ||
|
|
b4f7b0b177 | ||
|
|
44048626cd | ||
|
|
7fb8a1cb93 | ||
|
|
2d544e7bc3 | ||
|
|
0f0a8131c5 | ||
|
|
f7e6acbf9c | ||
|
|
eb445e79e2 | ||
|
|
ddee3dfd25 | ||
|
|
8b7e6b90a1 | ||
|
|
dd571dd35f | ||
|
|
c4e4414bbf | ||
|
|
221b50e905 | ||
|
|
42598dc36b | ||
|
|
ea9d986a48 | ||
|
|
64b10dd4ad | ||
|
|
729b46ee5f | ||
|
|
0dfb491e9d | ||
|
|
63585ff3a7 | ||
|
|
698e62d70a | ||
|
|
ab9ca9f49d | ||
|
|
257080e1f9 | ||
|
|
068c83b9fb | ||
|
|
cb86c48bc4 | ||
|
|
f0ceed5454 | ||
|
|
f0e4b29d73 | ||
|
|
4d23c75fa4 | ||
|
|
0ae73cbad3 |
+1
-1
@@ -1,4 +1,4 @@
|
||||
6
|
||||
7
|
||||
|
||||
3.2.2
|
||||
3.2.3
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 5.1.1 Mar 27, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Swap from `libsecp256k1` to `secp256k1` (this aligns with the Substrate use)
|
||||
- Adjust `wasm-crypto/init*` to also export `initWasm(): Promise<void>` (optional manual init)
|
||||
- Allow for `wasm-crypto/initNone` with no defined Wasm or Asm interfaces
|
||||
- Fix initialization on React Native with only ASM
|
||||
|
||||
|
||||
## 5.0.1 Mar 19, 2022
|
||||
|
||||
- **Breaking change** For users of React Native, you are now required to add `import '@polkadot/wasm-crypto/initOnlyAsm'` at your project top-level to ensure that asm.js is initialized. (Or alternatively `import '@polkadot/wasm-crypto/initWasmAsm'` to future-proof when WASM does become available)
|
||||
- **Breaking change** For users who used to map the `data` and `empty` of the internal `wasm-crypto-{wasm, asmjs}` packages in their bundlers, swap to one of the `@polkadot/wasm-crypto/init*` top-level imports to set the type of interfaces you would prefer. A full writeup of the rationale and other options can be found [in the FAQ](https://polkadot.js.org/docs/util-crypto/FAQ#i-dont-have-wasm-available-in-my-environment)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add (optional) `@polkadot/wasm-crypto/init{OnlyAsm, OnlyWasm, WasmAsm}` to allow specific interface types
|
||||
- Add work-around for lazy secp256k1 init in asm.js environments
|
||||
- Optimize asm.js output size
|
||||
- Use latest `wasm-bindgen`, `binaryen` & `wabt` packages in build
|
||||
- Additional workaround for Vite bundling
|
||||
|
||||
|
||||
## 4.6.1 Mar 12, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
376 Jaco 4.6.1 (#302)
|
||||
394 Jaco 5.1.1 (#322)
|
||||
1 Evgeny Fixed type (#121)
|
||||
1 Shunfan Zhou Support sr25519 agreement (#209)
|
||||
1 Steve Degosserie Expose Schnorrkel's VRF capabilities (#170)
|
||||
|
||||
+6
-5
@@ -10,13 +10,14 @@
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "4.6.1",
|
||||
"version": "5.1.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"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",
|
||||
@@ -27,15 +28,15 @@
|
||||
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
||||
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
||||
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.cjs && node ./test/asm.cjs",
|
||||
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
|
||||
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --test-threads=1 --nocapture"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.17.5",
|
||||
"@polkadot/dev": "^0.65.87",
|
||||
"@babel/core": "^7.17.8",
|
||||
"@polkadot/dev": "^0.65.101",
|
||||
"fflate": "^0.7.3",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^4.6.2"
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "4.6.1",
|
||||
"browser": "empty.js",
|
||||
"main": "empty.js",
|
||||
"react-native": "data.js",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.2"
|
||||
"@babel/runtime": "^7.17.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^8.4.1"
|
||||
"@polkadot/util": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asmJsInit as _asmJsInit } from './cjs/data.js';
|
||||
|
||||
export const asmJsInit = _asmJsInit;
|
||||
export { asmJsInit } from './cjs/data.js';
|
||||
export { packageInfo } from './packageInfo';
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const asmJsInit = null;
|
||||
import './detectPackage';
|
||||
|
||||
export * from './bundle';
|
||||
@@ -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: '4.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "4.6.1",
|
||||
"browser": "data.js",
|
||||
"main": "data.js",
|
||||
"react-native": "data.js",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.2"
|
||||
"@babel/runtime": "^7.17.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^8.4.1"
|
||||
"@polkadot/util": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { bytes, sizeUncompressed } from './cjs/bytes';
|
||||
import { base64Decode } from './base64';
|
||||
import { bytes, sizeUncompressed } from './bytes';
|
||||
import { unzlibSync } from './fflate';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { bytes as _bytes, sizeCompressed as _sizeCompressed, sizeUncompressed as _sizeUncompressed } from './cjs/bytes';
|
||||
|
||||
export const bytes = _bytes;
|
||||
|
||||
export const sizeCompressed = _sizeCompressed;
|
||||
|
||||
export const sizeUncompressed = _sizeUncompressed;
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const bytes = null;
|
||||
import './detectPackage';
|
||||
|
||||
export const sizeCompressed = 0;
|
||||
|
||||
export const sizeUncompressed = 0;
|
||||
export * from './bundle';
|
||||
@@ -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: '4.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
Generated
+70
-238
@@ -52,12 +52,6 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@@ -83,16 +77,7 @@ dependencies = [
|
||||
"block-padding",
|
||||
"byte-tools",
|
||||
"byteorder",
|
||||
"generic-array 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -122,6 +107,12 @@ version = "1.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
@@ -149,15 +140,6 @@ version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
@@ -170,20 +152,10 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
|
||||
dependencies = [
|
||||
"generic-array 0.12.3",
|
||||
"generic-array",
|
||||
"subtle 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-mac"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
"subtle 2.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "2.1.0"
|
||||
@@ -191,8 +163,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"digest 0.8.1",
|
||||
"rand_core 0.5.1",
|
||||
"digest",
|
||||
"rand_core",
|
||||
"subtle 2.2.3",
|
||||
"zeroize",
|
||||
]
|
||||
@@ -203,16 +175,7 @@ version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
|
||||
dependencies = [
|
||||
"generic-array 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -232,9 +195,9 @@ checksum = "21a8a37f4e8b35af971e6db5e3897e7a6344caa3f92f6544f88125a1f5f0035a"
|
||||
dependencies = [
|
||||
"curve25519-dalek",
|
||||
"ed25519",
|
||||
"rand 0.7.3",
|
||||
"rand",
|
||||
"serde",
|
||||
"sha2 0.8.2",
|
||||
"sha2",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -275,16 +238,6 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.14"
|
||||
@@ -341,29 +294,8 @@ version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695"
|
||||
dependencies = [
|
||||
"crypto-mac 0.7.0",
|
||||
"digest 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840"
|
||||
dependencies = [
|
||||
"crypto-mac 0.8.0",
|
||||
"digest 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hmac-drbg"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1"
|
||||
dependencies = [
|
||||
"digest 0.9.0",
|
||||
"generic-array 0.14.4",
|
||||
"hmac 0.8.1",
|
||||
"crypto-mac",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -393,55 +325,6 @@ version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0452aac8bab02242429380e9b2f94ea20cea2b37e2c1777a1358799bbe97f37"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"base64",
|
||||
"digest 0.9.0",
|
||||
"hmac-drbg",
|
||||
"lazy_static",
|
||||
"libsecp256k1-core",
|
||||
"libsecp256k1-gen-ecmult",
|
||||
"libsecp256k1-gen-genmult",
|
||||
"rand 0.8.4",
|
||||
"serde",
|
||||
"sha2 0.9.8",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-core"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
"digest 0.9.0",
|
||||
"subtle 2.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-ecmult"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-genmult"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.3.4"
|
||||
@@ -474,7 +357,7 @@ checksum = "c6feca46f4fa3443a01769d768727f10c10a20fdb65e52dc16a81f0c8269bb78"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"keccak",
|
||||
"rand_core 0.5.1",
|
||||
"rand_core",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -514,12 +397,6 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.10.2"
|
||||
@@ -551,7 +428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"crypto-mac 0.7.0",
|
||||
"crypto-mac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -568,9 +445,9 @@ checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
@@ -592,22 +469,11 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom 0.1.14",
|
||||
"libc",
|
||||
"rand_chacha 0.2.2",
|
||||
"rand_core 0.5.1",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha 0.3.1",
|
||||
"rand_core 0.6.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
@@ -615,17 +481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.6.3",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -637,22 +493,13 @@ dependencies = [
|
||||
"getrandom 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||
dependencies = [
|
||||
"getrandom 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core 0.5.1",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -684,9 +531,9 @@ dependencies = [
|
||||
"curve25519-dalek",
|
||||
"getrandom 0.1.14",
|
||||
"merlin",
|
||||
"rand 0.7.3",
|
||||
"rand_core 0.5.1",
|
||||
"sha2 0.8.2",
|
||||
"rand",
|
||||
"rand_core",
|
||||
"sha2",
|
||||
"subtle 2.2.3",
|
||||
"zeroize",
|
||||
]
|
||||
@@ -705,9 +552,27 @@ checksum = "656c79d0e90d0ab28ac86bf3c3d10bfbbac91450d3f190113b4e76d9fec3cfdd"
|
||||
dependencies = [
|
||||
"byte-tools",
|
||||
"byteorder",
|
||||
"hmac 0.7.1",
|
||||
"hmac",
|
||||
"pbkdf2",
|
||||
"sha2 0.8.2",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c42e6f1735c5f00f51e43e28d6634141f2bcad10931b2609ddd74a86d751260"
|
||||
dependencies = [
|
||||
"secp256k1-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1-sys"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "957da2573cde917463ece3570eab4a0b3f19de6f1646cde62e6fd3868f566036"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -715,20 +580,6 @@ name = "serde"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
@@ -736,23 +587,10 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
|
||||
dependencies = [
|
||||
"block-buffer 0.7.3",
|
||||
"digest 0.8.1",
|
||||
"block-buffer",
|
||||
"digest",
|
||||
"fake-simd",
|
||||
"opaque-debug 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
|
||||
dependencies = [
|
||||
"block-buffer 0.9.0",
|
||||
"cfg-if 1.0.0",
|
||||
"cpufeatures",
|
||||
"digest 0.9.0",
|
||||
"opaque-debug 0.3.0",
|
||||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -781,9 +619,9 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.38"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4"
|
||||
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -809,12 +647,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0165e045cc2ae1660270ca65e1676dbaab60feb0f91b10f7d0665e9b47e31f2"
|
||||
dependencies = [
|
||||
"failure",
|
||||
"hmac 0.7.1",
|
||||
"hmac",
|
||||
"once_cell",
|
||||
"pbkdf2",
|
||||
"rand 0.7.3",
|
||||
"rand",
|
||||
"rustc-hash",
|
||||
"sha2 0.8.2",
|
||||
"sha2",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
@@ -839,7 +677,7 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56"
|
||||
dependencies = [
|
||||
"rand 0.7.3",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -863,12 +701,6 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
@@ -891,14 +723,14 @@ dependencies = [
|
||||
"ed25519-dalek",
|
||||
"getrandom 0.2.3",
|
||||
"hex-literal",
|
||||
"hmac 0.7.1",
|
||||
"libsecp256k1",
|
||||
"hmac",
|
||||
"merlin",
|
||||
"pbkdf2",
|
||||
"rand 0.7.3",
|
||||
"rand",
|
||||
"schnorrkel",
|
||||
"scrypt",
|
||||
"sha2 0.8.2",
|
||||
"secp256k1",
|
||||
"sha2",
|
||||
"tiny-bip39",
|
||||
"tiny-keccak",
|
||||
"twox-hash",
|
||||
@@ -908,19 +740,19 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.65"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
|
||||
checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"cfg-if 1.0.0",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.65"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
|
||||
checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
@@ -933,9 +765,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.65"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
|
||||
checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -943,9 +775,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.65"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
|
||||
checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -956,9 +788,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.65"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
|
||||
checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2"
|
||||
|
||||
[[package]]
|
||||
name = "wee_alloc"
|
||||
|
||||
@@ -22,7 +22,7 @@ curve25519-dalek = { version = "2.1.0", default-features = false }
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||
getrandom = { version="0.2.3", features = ["js"] }
|
||||
hmac = "0.7.0"
|
||||
libsecp256k1 = { version = "0.7.0", default-features = false, features=["hmac", "lazy-static-context"] }
|
||||
secp256k1 = { version = "0.21.2", default-features = false, features = ["recovery", "global-context"] }
|
||||
merlin = { version = "2.0", default-features = false }
|
||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||
rand = { version="0.7.3", default-features = false, features = ["wasm-bindgen"] }
|
||||
@@ -32,7 +32,7 @@ sha2 = "0.8.1"
|
||||
tiny-bip39 = { version = "0.7", default-features = false }
|
||||
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
|
||||
twox-hash = "1.5.0"
|
||||
wasm-bindgen = "=0.2.65"
|
||||
wasm-bindgen = "=0.2.79"
|
||||
wee_alloc = "0.4.3"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -17,19 +17,27 @@
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
"./detectPackage.cjs",
|
||||
"./initNone.js",
|
||||
"./initNone.cjs",
|
||||
"./initOnlyAsm.js",
|
||||
"./initOnlyAsm.cjs",
|
||||
"./initOnlyWasm.js",
|
||||
"./initOnlyWasm.cjs",
|
||||
"./initWasmAsm.js",
|
||||
"./initWasmAsm.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "4.6.1",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.2",
|
||||
"@polkadot/wasm-crypto-asmjs": "^4.6.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^4.6.1"
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/wasm-crypto-asmjs": "^5.1.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^8.4.1",
|
||||
"@polkadot/x-randomvalues": "^8.4.1"
|
||||
"@polkadot/util": "^8.6.1",
|
||||
"@polkadot/x-randomvalues": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import type { AsmCreator, WasmCryptoInstance } from './types';
|
||||
import type { WasmCryptoInstance } from './types';
|
||||
|
||||
import { assert, stringToU8a, u8aToString } from '@polkadot/util';
|
||||
|
||||
@@ -12,56 +12,50 @@ type PopFirst<T extends unknown[]> =
|
||||
? N
|
||||
: [];
|
||||
|
||||
let wasm: WasmCryptoInstance | null = null;
|
||||
let cachegetInt32: Int32Array | null = null;
|
||||
let cachegetUint8: Uint8Array | null = null;
|
||||
|
||||
export async function initWasm (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null, wbg: Record<string, WebAssembly.ImportValue>): Promise<void> {
|
||||
try {
|
||||
assert(typeof WebAssembly !== 'undefined' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||
|
||||
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||
|
||||
wasm = source.instance.exports as unknown as WasmCryptoInstance;
|
||||
} catch (error) {
|
||||
// if we have a valid supplied asm.js, return that
|
||||
if (asmFn) {
|
||||
wasm = asmFn(wbg);
|
||||
} else {
|
||||
console.error('FATAL: Unable to initialize @polkadot/wasm-crypto');
|
||||
console.error(error);
|
||||
|
||||
wasm = null;
|
||||
}
|
||||
}
|
||||
interface Bridge {
|
||||
cachegetInt32: Int32Array | null;
|
||||
cachegetUint8: Uint8Array | null;
|
||||
type: 'wasm' | 'asm';
|
||||
wasm: WasmCryptoInstance | null;
|
||||
wasmPromise: Promise<void> | null;
|
||||
wasmPromiseFn: null | (() => Promise<void>);
|
||||
}
|
||||
|
||||
export const __bridge: Bridge = {
|
||||
cachegetInt32: null,
|
||||
cachegetUint8: null,
|
||||
type: 'wasm',
|
||||
wasm: null,
|
||||
wasmPromise: null,
|
||||
wasmPromiseFn: null
|
||||
};
|
||||
|
||||
export function withWasm <T, F extends (wasm: WasmCryptoInstance, ...params: never[]) => T> (fn: F): (...params: PopFirst<Parameters<F>>) => ReturnType<F> {
|
||||
return (...params: PopFirst<Parameters<F>>): ReturnType<F> => {
|
||||
assert(wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
|
||||
assert(__bridge.wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
|
||||
|
||||
return fn(wasm, ...params) as ReturnType<F>;
|
||||
return fn(__bridge.wasm, ...params) as ReturnType<F>;
|
||||
};
|
||||
}
|
||||
|
||||
export function getWasm (): WasmCryptoInstance {
|
||||
return wasm!;
|
||||
return __bridge.wasm!;
|
||||
}
|
||||
|
||||
export function getInt32 (): Int32Array {
|
||||
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm!.memory.buffer) {
|
||||
cachegetInt32 = new Int32Array(wasm!.memory.buffer);
|
||||
if (__bridge.cachegetInt32 === null || __bridge.cachegetInt32.buffer !== __bridge.wasm!.memory.buffer) {
|
||||
__bridge.cachegetInt32 = new Int32Array(__bridge.wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return cachegetInt32;
|
||||
return __bridge.cachegetInt32;
|
||||
}
|
||||
|
||||
export function getUint8 (): Uint8Array {
|
||||
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm!.memory.buffer) {
|
||||
cachegetUint8 = new Uint8Array(wasm!.memory.buffer);
|
||||
if (__bridge.cachegetUint8 === null || __bridge.cachegetUint8.buffer !== __bridge.wasm!.memory.buffer) {
|
||||
__bridge.cachegetUint8 = new Uint8Array(__bridge.wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return cachegetUint8;
|
||||
return __bridge.cachegetUint8;
|
||||
}
|
||||
|
||||
export function getU8a (ptr: number, len: number): Uint8Array {
|
||||
@@ -73,7 +67,7 @@ export function getString (ptr: number, len: number): string {
|
||||
}
|
||||
|
||||
export function allocU8a (arg: Uint8Array): [number, number] {
|
||||
const ptr = wasm!.__wbindgen_malloc(arg.length * 1);
|
||||
const ptr = __bridge.wasm!.__wbindgen_malloc(arg.length * 1);
|
||||
|
||||
getUint8().set(arg, ptr / 1);
|
||||
|
||||
@@ -89,7 +83,7 @@ export function resultU8a (): Uint8Array {
|
||||
const r1 = getInt32()[8 / 4 + 1];
|
||||
const ret = getU8a(r0, r1).slice();
|
||||
|
||||
wasm!.__wbindgen_free(r0, r1 * 1);
|
||||
__bridge.wasm!.__wbindgen_free(r0, r1 * 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||
|
||||
import { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } from './bridge';
|
||||
import * as imports from './imports';
|
||||
import { __bridge, allocString, allocU8a, getWasm, resultString, resultU8a, withWasm } from './bridge';
|
||||
import { initWasm } from './init';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
|
||||
|
||||
export const bip39Generate = withWasm((wasm, words: 12 | 15 | 18 | 21 | 24): string => {
|
||||
wasm.ext_bip39_generate(8, words);
|
||||
|
||||
@@ -207,6 +202,20 @@ export function isReady (): boolean {
|
||||
return !!getWasm();
|
||||
}
|
||||
|
||||
export function waitReady (): Promise<boolean> {
|
||||
return wasmPromise.then(() => isReady());
|
||||
export async function waitReady (): Promise<boolean> {
|
||||
try {
|
||||
if (!__bridge.wasmPromise) {
|
||||
if (!__bridge.wasmPromiseFn) {
|
||||
__bridge.wasmPromiseFn = initWasm;
|
||||
}
|
||||
|
||||
__bridge.wasmPromise = __bridge.wasmPromiseFn();
|
||||
}
|
||||
|
||||
await __bridge.wasmPromise;
|
||||
|
||||
return isReady();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AsmCreator, WasmCryptoInstance } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||
|
||||
import { __bridge } from './bridge';
|
||||
import * as wbg from './imports';
|
||||
|
||||
async function createPromise (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null): Promise<void> {
|
||||
try {
|
||||
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||
|
||||
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||
|
||||
__bridge.wasm = (source.instance.exports as unknown as WasmCryptoInstance);
|
||||
} catch (error) {
|
||||
// if we have a valid supplied asm.js, return that
|
||||
if (asmFn) {
|
||||
__bridge.type = 'asm';
|
||||
__bridge.wasm = asmFn(wbg);
|
||||
} else {
|
||||
console.error(`FATAL: Unable to initialize @polkadot/wasm-crypto:: ${(error as Error).message}`);
|
||||
|
||||
__bridge.wasm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function setWasmPromise (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null): Promise<void> {
|
||||
__bridge.wasmPromise = createPromise(wasmBytes, asmFn);
|
||||
|
||||
return __bridge.wasmPromise;
|
||||
}
|
||||
|
||||
export function setWasmPromiseFn (fn: () => Promise<void>): void {
|
||||
__bridge.wasmPromiseFn = fn;
|
||||
}
|
||||
|
||||
export function initWasm (): Promise<void> {
|
||||
return setWasmPromise(wasmBytes, null);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AsmCreator } from './types';
|
||||
|
||||
import { __bridge } from './bridge';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setWasmPromise (_wasmBytes: Uint8Array | null, _asmFn: AsmCreator | null): Promise<void> {
|
||||
__bridge.wasmPromise = Promise.resolve();
|
||||
|
||||
return __bridge.wasmPromise;
|
||||
}
|
||||
|
||||
export function setWasmPromiseFn (fn: () => Promise<void>): void {
|
||||
__bridge.wasmPromiseFn = fn;
|
||||
}
|
||||
|
||||
export function setWasmOnlyPromise (): Promise<void> {
|
||||
return setWasmPromise(null, null);
|
||||
}
|
||||
|
||||
export function initWasm (): Promise<void> {
|
||||
return setWasmOnlyPromise();
|
||||
}
|
||||
|
||||
setWasmPromiseFn(initWasm);
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||
|
||||
import { setWasmPromise, setWasmPromiseFn } from './init';
|
||||
|
||||
export function initWasm (): Promise<void> {
|
||||
return setWasmPromise(null, asmJsInit);
|
||||
}
|
||||
|
||||
setWasmPromiseFn(initWasm);
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { initWasm as baseInitWasm, setWasmPromiseFn } from './init';
|
||||
|
||||
export function initWasm (): Promise<void> {
|
||||
return baseInitWasm();
|
||||
}
|
||||
|
||||
setWasmPromiseFn(initWasm);
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||
|
||||
import { setWasmPromise, setWasmPromiseFn } from './init';
|
||||
|
||||
export function initWasm (): Promise<void> {
|
||||
return setWasmPromise(wasmBytes, asmJsInit);
|
||||
}
|
||||
|
||||
setWasmPromiseFn(initWasm);
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '4.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use libsecp256k1::{Message, PublicKey, RecoveryId, SecretKey, Signature, recover, sign};
|
||||
use secp256k1::{ecdsa::{RecoverableSignature, RecoveryId}, Message, PublicKey, SecretKey, SECP256K1};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_pub_compress(pubkey: &[u8]) -> Vec<u8> {
|
||||
match PublicKey::parse_slice(&pubkey, None) {
|
||||
Ok(p) => p
|
||||
.serialize_compressed()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pubkey provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_pub_expand(pubkey: &[u8]) -> Vec<u8> {
|
||||
match PublicKey::parse_slice(&pubkey, None) {
|
||||
match PublicKey::from_slice(&pubkey) {
|
||||
Ok(p) => p
|
||||
.serialize()
|
||||
.to_vec(),
|
||||
@@ -25,44 +15,58 @@ pub fn ext_secp_pub_expand(pubkey: &[u8]) -> Vec<u8> {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
match SecretKey::parse_slice(seed) {
|
||||
Ok(s) => {
|
||||
let mut res = vec![];
|
||||
let pubkey = PublicKey::from_secret_key(&s);
|
||||
|
||||
res.extend_from_slice(&s.serialize());
|
||||
res.extend_from_slice(&pubkey.serialize_compressed());
|
||||
|
||||
res
|
||||
},
|
||||
_ => panic!("Incalid seed provided.")
|
||||
pub fn ext_secp_pub_expand(pubkey: &[u8]) -> Vec<u8> {
|
||||
match PublicKey::from_slice(&pubkey) {
|
||||
Ok(p) => p
|
||||
.serialize_uncompressed()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pubkey provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_recover(hash: &[u8], sig: &[u8], rec: u8) -> Vec<u8> {
|
||||
match (Message::parse_slice(hash), Signature::parse_standard_slice(sig), RecoveryId::parse(rec)) {
|
||||
(Ok(m), Ok(s), Ok(r)) =>
|
||||
match recover(&m, &s, &r) {
|
||||
pub fn ext_secp_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
match SecretKey::from_slice(seed) {
|
||||
Ok(s) => {
|
||||
let mut res = vec![];
|
||||
let pubkey = PublicKey::from_secret_key(SECP256K1, &s);
|
||||
|
||||
res.extend_from_slice(&s.serialize_secret());
|
||||
res.extend_from_slice(&pubkey.serialize());
|
||||
|
||||
res
|
||||
},
|
||||
_ => panic!("Invalid seed provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_recover(hash: &[u8], sig: &[u8], rec: i32) -> Vec<u8> {
|
||||
match RecoveryId::from_i32(rec) {
|
||||
Ok(r) => match (Message::from_slice(hash), RecoverableSignature::from_compact(&sig, r)) {
|
||||
(Ok(m), Ok(s)) => match s.recover(&m) {
|
||||
Ok(k) => k
|
||||
.serialize_compressed()
|
||||
.serialize()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid message provided.")
|
||||
_ => panic!("Unable to recover.")
|
||||
},
|
||||
_ => panic!("Invalid signature provided.")
|
||||
},
|
||||
_ => panic!("Invalid recovery data provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_secp_sign(hash: &[u8], seckey: &[u8]) -> Vec<u8> {
|
||||
match (Message::parse_slice(hash), SecretKey::parse_slice(seckey)) {
|
||||
match (Message::from_slice(hash), SecretKey::from_slice(seckey)) {
|
||||
(Ok(m), Ok(s)) => {
|
||||
let mut res = vec![];
|
||||
let (sig, rec) = sign(&m, &s);
|
||||
let (rec, sig) = SECP256K1
|
||||
.sign_ecdsa_recoverable(&m, &s)
|
||||
.serialize_compact();
|
||||
|
||||
res.extend_from_slice(&sig.serialize());
|
||||
res.push(rec.into());
|
||||
res.extend_from_slice(&sig);
|
||||
res.push(rec.to_i32() as u8);
|
||||
|
||||
res
|
||||
},
|
||||
@@ -114,7 +118,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_sign() {
|
||||
// JS expectiation - doesn't match?
|
||||
// JS expectation - doesn't match?
|
||||
// let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba8c4efa521361678d9b8582744d77aa4b8d886d7380b7808a683174afad9c4700300");
|
||||
let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba83b105adec9e9872647a7d8bb28855b45e22805aea3d097953cbb1391f671d13e01");
|
||||
let seckey = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae");
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const rootIncl = ['@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
|
||||
const detcIncl = rootIncl.map((p) => `${p}/packageInfo.cjs`);
|
||||
const rootIncl = ['@polkadot/wasm-crypto', '@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
|
||||
const detcIncl = [
|
||||
...rootIncl.map((p) => `${p}/initOnlyAsm.cjs`),
|
||||
...rootIncl.map((p) => `${p}/initOnlyWasm.cjs`),
|
||||
...rootIncl.map((p) => `${p}/packageInfo.cjs`)
|
||||
];
|
||||
|
||||
require('override-require')(
|
||||
(request) =>
|
||||
@@ -10,6 +14,10 @@ require('override-require')(
|
||||
detcIncl.some((p) => request.endsWith(p)),
|
||||
(request) =>
|
||||
rootIncl.some((p) => request.endsWith(p))
|
||||
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/data.cjs`)
|
||||
: require(`${detcIncl.find((p) => request.endsWith(p)).replace('packageInfo.cjs', 'build/packageInfo.cjs')}`)
|
||||
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/index.cjs`)
|
||||
: require(`${detcIncl.find((p) => request.endsWith(p))
|
||||
.replace('initOnlyAsm.cjs', 'build/initOnlyAsm.cjs')
|
||||
.replace('initOnlyWasm.cjs', 'build/initOnlyWasm.cjs')
|
||||
.replace('packageInfo.cjs', 'build/packageInfo.cjs')
|
||||
}`)
|
||||
);
|
||||
|
||||
@@ -10,19 +10,22 @@ const sr25519 = require('./sr25519.cjs');
|
||||
const vrf = require('./vrf.cjs');
|
||||
|
||||
const tests = {
|
||||
...bip39,
|
||||
...ed25519,
|
||||
...hashing,
|
||||
// We place secp256k1 first, this allows the interaction with it in the
|
||||
// hashing (specifically scrypt) test not be an issue (ASM.js only)
|
||||
// https://github.com/polkadot-js/wasm/issues/307
|
||||
...secp256k1,
|
||||
...ed25519,
|
||||
...sr25519,
|
||||
...vrf
|
||||
...vrf,
|
||||
...bip39,
|
||||
...hashing
|
||||
};
|
||||
|
||||
function beforeAll () {
|
||||
return wasm.waitReady();
|
||||
}
|
||||
|
||||
function runAll () {
|
||||
function runAll (name) {
|
||||
const failed = [];
|
||||
let count = 0;
|
||||
|
||||
@@ -38,23 +41,29 @@ function runAll () {
|
||||
|
||||
console.timeEnd(name);
|
||||
} catch (error) {
|
||||
console.error();
|
||||
console.error(error);
|
||||
|
||||
failed.push(name);
|
||||
}
|
||||
});
|
||||
|
||||
if (failed.length) {
|
||||
throw new Error(`Failed: ${failed.length} of ${count}: ${failed.concat(', ')}`);
|
||||
throw new Error(`\n*** ${name}: FAILED: ${failed.length} of ${count}: ${failed.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
function runUnassisted () {
|
||||
beforeAll()
|
||||
.then(() => runAll())
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
function runUnassisted (name) {
|
||||
console.log(`\n*** ${name}: Running tests`);
|
||||
|
||||
beforeAll()
|
||||
.then(() => runAll(name))
|
||||
.then(() => {
|
||||
console.log(`\n*** ${name}: All passed`);
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error.message, '\n');
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ function secp256k1Expand (wasm) {
|
||||
assert(result === '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af', 'ERROR: secp256k1Expand does not match');
|
||||
}
|
||||
|
||||
function secp256k1FromSeed (wasm) {
|
||||
function secp256k1FromSeed1 (wasm) {
|
||||
const seckey = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
|
||||
const result = u8aToHex(wasm.secp256k1FromSeed(hexToU8a(seckey)));
|
||||
|
||||
@@ -30,6 +30,28 @@ function secp256k1FromSeed (wasm) {
|
||||
assert(result === '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae03fd8c74f795ced92064b86191cb2772b1e3a0947740aa0a5a6e379592471fd85b', 'ERROR: secp256k1FromSeed does not match');
|
||||
}
|
||||
|
||||
function secp256k1FromSeed2 (wasm) {
|
||||
// https://github.com/polkadot-js/wasm/issues/307
|
||||
const seckey = new Uint8Array([
|
||||
203, 109, 249, 222, 30, 252, 167, 163, 153, 138, 142,
|
||||
173, 78, 2, 21, 157, 95, 169, 156, 62, 13, 79,
|
||||
214, 67, 38, 103, 57, 11, 180, 114, 104, 84
|
||||
]);
|
||||
const expected = u8aToHex(new Uint8Array([
|
||||
203, 109, 249, 222, 30, 252, 167, 163, 153, 138, 142,
|
||||
173, 78, 2, 21, 157, 95, 169, 156, 62, 13, 79,
|
||||
214, 67, 38, 103, 57, 11, 180, 114, 104, 84, 2,
|
||||
10, 16, 145, 52, 31, 229, 102, 75, 250, 23, 130,
|
||||
213, 224, 71, 121, 104, 144, 104, 201, 22, 176, 76,
|
||||
179, 101, 236, 49, 83, 117, 86, 132, 217, 161
|
||||
]));
|
||||
const result = u8aToHex(wasm.secp256k1FromSeed(seckey));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
assert(result === expected, 'ERROR: secp256k1FromSeed does not match');
|
||||
}
|
||||
|
||||
function secp256k1Recover (wasm) {
|
||||
const sig = '0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff';
|
||||
const msg = '0xa30b64ce1eedf409c8afb801d72c05234e64849ea538c15dd3c8cf4ffcf166c9';
|
||||
@@ -53,7 +75,8 @@ function secp256k1Sign (wasm) {
|
||||
module.exports = {
|
||||
secp256k1Compress,
|
||||
secp256k1Expand,
|
||||
secp256k1FromSeed,
|
||||
secp256k1FromSeed1,
|
||||
secp256k1FromSeed2,
|
||||
secp256k1Recover,
|
||||
secp256k1Sign
|
||||
};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
global.WebAssembly = null;
|
||||
|
||||
require('./alias-imports.cjs');
|
||||
require('@polkadot/wasm-crypto/initOnlyAsm.cjs');
|
||||
|
||||
const { runUnassisted } = require('./all/index.cjs');
|
||||
|
||||
runUnassisted();
|
||||
runUnassisted('ASM');
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
// override-require in jest.config.js
|
||||
|
||||
import { beforeAll, tests, wasm } from './all/index.cjs';
|
||||
|
||||
describe('wasm-crypto', () => {
|
||||
|
||||
@@ -5,4 +5,4 @@ require('./alias-imports.cjs');
|
||||
|
||||
const { runUnassisted } = require('./all/index.cjs');
|
||||
|
||||
runUnassisted();
|
||||
runUnassisted('WASM');
|
||||
|
||||
@@ -26,7 +26,7 @@ echo "*** Converting to WASM"
|
||||
|
||||
# optimise
|
||||
echo "*** Optimising WASM output"
|
||||
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
||||
../binaryen/bin/wasm-opt $WSM -Oz -o $OPT
|
||||
|
||||
# convert wasm to base64 structure
|
||||
echo "*** Packing WASM into baseX"
|
||||
@@ -34,14 +34,12 @@ node ../scripts/pack-wasm-base.cjs
|
||||
|
||||
# build asmjs version from the input (optimised) WASM
|
||||
echo "*** Building asm.js version"
|
||||
../binaryen/bin/wasm2js --output $ASM $OPT
|
||||
../binaryen/bin/wasm2js -Oz --output $ASM $OPT
|
||||
|
||||
# cleanup the generated asm, converting to cjs
|
||||
sed -i -e '/import {/d' $ASM
|
||||
sed -i -e '/export var /d' $ASM
|
||||
sed -i -e 's/{abort.*},memasmFunc/wbg, memasmFunc/g' $ASM
|
||||
sed -i -e 's/var retasmFunc = /const asmJsInit = (wbg) => /' $ASM
|
||||
echo "module.exports = { asmJsInit };" >> $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
|
||||
|
||||
# cleanups
|
||||
rm -rf wasm-crypto-asmjs/build/cjs/*-e
|
||||
|
||||
@@ -7,16 +7,17 @@ set -e
|
||||
|
||||
source ./scripts/rust-version.sh
|
||||
|
||||
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||
BINARYEN_VER=version_97
|
||||
BINARYEN_ZIP=
|
||||
|
||||
# NOTE If this is bumped, bump the version in Cargo.toml as well
|
||||
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
|
||||
BINDGEN_VER=0.2.65
|
||||
BINDGEN_VER=0.2.79
|
||||
BINDGEN_ZIP=
|
||||
|
||||
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||
BINARYEN_VER=version_105
|
||||
BINARYEN_ZIP=
|
||||
|
||||
WABT_REPO=https://github.com/WebAssembly/wabt
|
||||
WABT_VER=1.0.19
|
||||
WABT_VER=1.0.27
|
||||
WABT_ZIP=
|
||||
|
||||
unamestr=`uname`
|
||||
|
||||
+2
-2
@@ -4,9 +4,9 @@
|
||||
"composite": true,
|
||||
"paths": {
|
||||
"@polkadot/wasm-crypto-asmjs/packageInfo": ["wasm-crypto-asmjs/src/packageInfo"],
|
||||
"@polkadot/wasm-crypto-asmjs": ["wasm-crypto-asmjs/src/data"],
|
||||
"@polkadot/wasm-crypto-asmjs": ["wasm-crypto-asmjs/src"],
|
||||
"@polkadot/wasm-crypto-wasm/packageInfo": ["wasm-crypto-wasm/src/packageInfo"],
|
||||
"@polkadot/wasm-crypto-wasm": ["wasm-crypto-wasm/src/data"],
|
||||
"@polkadot/wasm-crypto-wasm": ["wasm-crypto-wasm/src"],
|
||||
"@polkadot/wasm-crypto": ["wasm-crypto/src"]
|
||||
},
|
||||
"skipLibCheck": true
|
||||
|
||||
Reference in New Issue
Block a user