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 | ||
|
|
44b70b745a | ||
|
|
3bf0e29d94 | ||
|
|
60759e7a1a | ||
|
|
28f4457e0a | ||
|
|
aca9e2655b | ||
|
|
567ebe69d0 | ||
|
|
6c3b30fe53 | ||
|
|
e9b2ba93c4 | ||
|
|
a9fa4ce1a5 | ||
|
|
18e2ab6389 | ||
|
|
917b654c63 | ||
|
|
c7a202525c | ||
|
|
4c80c9bd0f | ||
|
|
480d8e2dc8 | ||
|
|
73a4c5d37f | ||
|
|
b003749832 | ||
|
|
0ef6797ce9 | ||
|
|
0013bbc14d | ||
|
|
93c4f62b3d | ||
|
|
0008428ae0 | ||
|
|
49818a5aef | ||
|
|
9acb068f26 | ||
|
|
2e35918650 | ||
|
|
c6877b7207 | ||
|
|
af598af917 | ||
|
|
fd98695a1c | ||
|
|
737c373706 | ||
|
|
2fe9d88068 | ||
|
|
81f6e8b214 | ||
|
|
b484c66f9c | ||
|
|
a30354dd22 | ||
|
|
98ba005cbc | ||
|
|
5ef4c0c3e3 | ||
|
|
748cf146c2 | ||
|
|
9d86641a09 | ||
|
|
4940a58942 | ||
|
|
56560d767b | ||
|
|
c024262479 | ||
|
|
91616be8c1 | ||
|
|
14bf2209c1 | ||
|
|
26352dfb2c | ||
|
|
56a5bc7f4e | ||
|
|
c5cca3da2d | ||
|
|
b8b72adc38 | ||
|
|
e69571d469 | ||
|
|
859bef5d24 | ||
|
|
1b6ffdd728 | ||
|
|
cedfc3ddc2 | ||
|
|
317d837c26 | ||
|
|
10e42c4a5f | ||
|
|
ccd71cc6fe | ||
|
|
4981ca3f50 | ||
|
|
20f9969b90 | ||
|
|
f34deb94be | ||
|
|
b98d787dd9 | ||
|
|
fa8ab999d3 | ||
|
|
b9e7d5a2c1 | ||
|
|
6b8634462d | ||
|
|
f3706b4975 | ||
|
|
66c70aba9a | ||
|
|
2ee13d5063 | ||
|
|
b81eb9037d | ||
|
|
2a261ab180 | ||
|
|
b3facfeafe | ||
|
|
edbd81d6a6 | ||
|
|
c22c861534 | ||
|
|
b256423ee7 | ||
|
|
cda39039ea | ||
|
|
64242926e2 | ||
|
|
a6357d8b23 | ||
|
|
84387bc56d | ||
|
|
3d1dee1164 | ||
|
|
b9c627d4c3 | ||
|
|
c588a37cc3 | ||
|
|
372bfccb68 | ||
|
|
be4f3ce82c | ||
|
|
d7ced7c0e4 | ||
|
|
3454f0685c | ||
|
|
3810eff007 | ||
|
|
a03283fe32 | ||
|
|
96d016f0a4 | ||
|
|
622e60990a | ||
|
|
112fbaa97d | ||
|
|
516cf8347c | ||
|
|
9f0fff863f | ||
|
|
44c77e5bf3 | ||
|
|
1fa4de4276 | ||
|
|
9f6aa8dd33 | ||
|
|
f5563c9ed3 | ||
|
|
32245f5b61 | ||
|
|
edcd6ee44b | ||
|
|
93fae330ae | ||
|
|
2f13511810 | ||
|
|
9d1b58917b | ||
|
|
0eb06843f7 | ||
|
|
a977c8fc9f | ||
|
|
c33ccd1cf9 | ||
|
|
55c3107e91 | ||
|
|
387334854e | ||
|
|
19a852bee3 | ||
|
|
4c06f8c69b | ||
|
|
39deef5b8b | ||
|
|
bc605481d2 | ||
|
|
60dc2ce9c5 | ||
|
|
7ba258f750 | ||
|
|
4ec72cac9e | ||
|
|
cd4ec3ece5 | ||
|
|
30385b85e4 | ||
|
|
27bef46818 | ||
|
|
2b4ed56dcb | ||
|
|
e167eba7d8 | ||
|
|
272050938f | ||
|
|
3ee381512b | ||
|
|
a2d5affb88 | ||
|
|
2b759aab12 | ||
|
|
223d7bf514 | ||
|
|
fa2eb4e214 | ||
|
|
7689afb616 | ||
|
|
10002e9ec5 | ||
|
|
b2a0af0df4 | ||
|
|
4966fd2837 | ||
|
|
421d36d159 | ||
|
|
74270adba7 | ||
|
|
2b97759fa7 | ||
|
|
b8b9784763 | ||
|
|
8439d5c668 | ||
|
|
cb3a0f667a | ||
|
|
adf21a5fc2 | ||
|
|
4c28fadc07 | ||
|
|
2849a05507 | ||
|
|
801ed235cf | ||
|
|
98433c7399 | ||
|
|
b537dcf3f4 | ||
|
|
eaf8ecf2c1 | ||
|
|
9f232459d9 | ||
|
|
b92661cfe0 | ||
|
|
6ca4470752 | ||
|
|
6cecb67edd | ||
|
|
91388ca10d | ||
|
|
11e2acbdb5 | ||
|
|
4e3d1b631c | ||
|
|
4f06de4844 | ||
|
|
affb3c57e3 | ||
|
|
39e762a419 | ||
|
|
fe966c8576 | ||
|
|
12c90dfb53 | ||
|
|
03aabfd6d1 | ||
|
|
49b3cf552b | ||
|
|
6300012c32 | ||
|
|
9d0773c185 | ||
|
|
96bd2f466e | ||
|
|
c6151e1a7d | ||
|
|
c0c6671bd0 | ||
|
|
2b9d90ff49 | ||
|
|
2caa6fb41a | ||
|
|
df00473ae2 | ||
|
|
2acce9283f | ||
|
|
7971624cf9 | ||
|
|
e353fe7f2c | ||
|
|
e797e7a7e4 | ||
|
|
cb91f766c7 | ||
|
|
c983de54f6 | ||
|
|
9d9b983694 | ||
|
|
6db930d03d | ||
|
|
0233a868ab | ||
|
|
ed98d4820e | ||
|
|
971d40ba18 | ||
|
|
f3e1e30838 | ||
|
|
bff8604c8a | ||
|
|
6cf4fc0989 | ||
|
|
308374c7da | ||
|
|
06bb7ae090 |
+3
-1
@@ -1,6 +1,8 @@
|
||||
6
|
||||
7
|
||||
|
||||
3.2.2
|
||||
3.2.3
|
||||
3.2.4
|
||||
|
||||
4.0.2
|
||||
4.1.2
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
checks:
|
||||
argument-count:
|
||||
config:
|
||||
threshold: 5
|
||||
method-complexity:
|
||||
config:
|
||||
threshold: 7
|
||||
method-count:
|
||||
config:
|
||||
threshold: 25
|
||||
method-lines:
|
||||
config:
|
||||
threshold: 30
|
||||
|
||||
exclude_patterns:
|
||||
- "**/*.spec.js"
|
||||
- "**/*.spec.ts"
|
||||
- "docs/**/*.js"
|
||||
- "**/test/**/*.js"
|
||||
- "packages/wasm-crypto-wasm/src/fflate.ts"
|
||||
|
||||
+5
-12
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const base = require('@polkadot/dev/config/eslint.cjs');
|
||||
@@ -6,21 +6,14 @@ const base = require('@polkadot/dev/config/eslint.cjs');
|
||||
module.exports = {
|
||||
...base,
|
||||
ignorePatterns: [
|
||||
'.eslintrc.js',
|
||||
'.github/**',
|
||||
'.vscode/**',
|
||||
'.yarn/**',
|
||||
'**/binaryen/*',
|
||||
'**/build/*',
|
||||
'**/coverage/*',
|
||||
'**/node_modules/*',
|
||||
'**/pkg/*',
|
||||
'**/target/*'
|
||||
...base.ignorePatterns,
|
||||
'**/target/*',
|
||||
'packages/bytes/*'
|
||||
],
|
||||
parserOptions: {
|
||||
...base.parserOptions,
|
||||
project: [
|
||||
'./tsconfig.json'
|
||||
'./tsconfig.eslint.json'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
name: bot
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
|
||||
jobs:
|
||||
approve:
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: jacogr/action-approve@master
|
||||
with:
|
||||
authors: jacogr
|
||||
labels: -auto
|
||||
token: ${{ secrets.GH_PAT_BOT }}
|
||||
@@ -0,0 +1,16 @@
|
||||
name: bot
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
|
||||
jobs:
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: jacogr/action-merge@master
|
||||
with:
|
||||
checks: build,lint,test
|
||||
labels: -auto
|
||||
strategy: squash
|
||||
token: ${{ secrets.GH_PAT_BOT }}
|
||||
@@ -2,11 +2,13 @@ name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '30 1/2 * * *'
|
||||
- cron: '20 1/3 * * *'
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v2
|
||||
with:
|
||||
|
||||
@@ -8,6 +8,8 @@ jobs:
|
||||
step: ['lint', 'test', 'build']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: ${{ matrix.step }}
|
||||
|
||||
@@ -12,16 +12,18 @@ jobs:
|
||||
step: ['build:release']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
- name: build
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
./scripts/install-build-deps.sh
|
||||
|
||||
@@ -9,6 +9,8 @@ jobs:
|
||||
check:
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: returntocorp/semgrep-action@v1
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
name: 'Close stale issues and PRs'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '30 2/2 * * *'
|
||||
- cron: '35 1/3 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
|
||||
@@ -26,5 +26,6 @@ lerna-debug.log*
|
||||
npm-debug.log*
|
||||
package-lock.json
|
||||
report.*.json
|
||||
tsconfig.*buildinfo
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Jaco <jacogr@gmail.com>
|
||||
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> <action@github.com>
|
||||
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Github Actions <action@github.com>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
||||
// Copyright 2017-2022 @polkadot/dev authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = require('@polkadot/dev/config/prettier.cjs');
|
||||
|
||||
+344
-56
File diff suppressed because one or more lines are too long
+526
-51
File diff suppressed because one or more lines are too long
Vendored
-631
File diff suppressed because one or more lines are too long
+785
File diff suppressed because one or more lines are too long
+1
-1
@@ -10,4 +10,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.0.1.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.2.0.cjs
|
||||
|
||||
@@ -1,5 +1,68 @@
|
||||
# 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:
|
||||
|
||||
- Adjust ed25519 internals, consistency in code
|
||||
- Ensure package path is available under ESM & CJS
|
||||
- JS wrapped bytes interoperability test
|
||||
- Adjust for bundlers where `import.meta.url` is undefined
|
||||
|
||||
|
||||
## 4.5.1 Dec 3, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `secp256k1{Compress, Expand, Recover, Sign}` functions
|
||||
- Remove all occurences of `.unwrap()` (match everywhere)
|
||||
- Adjust and optimize WASM function JS interface construction
|
||||
- Simplify base64 bytes decoding on construction
|
||||
|
||||
|
||||
## 4.4.1 Nov 22, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `hmacSha256` & `hmacSha512` functions
|
||||
|
||||
|
||||
## 4.3.1 Nov 19, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Updated package.json to include repo (Thanks to https://github.com/v-zhzhou)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `keccak512` function
|
||||
- Add `sha256` function
|
||||
|
||||
|
||||
## 4.2.1 Aug 28, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
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)
|
||||
1 Zhongpeng Zhou Update package.json to include the repository (#220)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs');
|
||||
|
||||
+6
-12
@@ -1,19 +1,13 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const config = require('@polkadot/dev/config/jest.cjs');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
module.exports = {
|
||||
...config,
|
||||
moduleNameMapper: {
|
||||
'@polkadot/wasm-crypto-asmjs(.*)$': '<rootDir>/packages/wasm-crypto-asmjs/build/$1',
|
||||
'@polkadot/wasm-crypto-wasm(.*)$': '<rootDir>/packages/wasm-crypto-wasm/build/$1',
|
||||
'@polkadot/wasm-crypto-(asmjs|wasm)(.*)$': '<rootDir>/packages/wasm-crypto-$1/build/$2',
|
||||
// eslint-disable-next-line sort-keys
|
||||
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
|
||||
},
|
||||
modulePathIgnorePatterns: [
|
||||
'<rootDir>/packages/wasm-crypto-asmjs/build',
|
||||
'<rootDir>/packages/wasm-crypto-wasm/build',
|
||||
'<rootDir>/packages/wasm-crypto/build'
|
||||
],
|
||||
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
+20
-12
@@ -1,34 +1,42 @@
|
||||
{
|
||||
"repository": "https://github.com/polkadot-js/wasm",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "Apache-2",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"homepage": "https://github.com/polkadot-js/wasm#readme",
|
||||
"license": "Apache-2.0",
|
||||
"packageManager": "yarn@3.2.0",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "5.1.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"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",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "./scripts/clean.sh",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "yarn test:wasm:rust",
|
||||
"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.15.0",
|
||||
"@polkadot/dev": "^0.62.62",
|
||||
"fflate": "^0.7.1",
|
||||
"@babel/core": "^7.17.8",
|
||||
"@polkadot/dev": "^0.65.101",
|
||||
"fflate": "^0.7.3",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
"version": "4.2.1",
|
||||
"packageManager": "yarn@3.0.1"
|
||||
"resolutions": {
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto-asmjs",
|
||||
"version": "4.2.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"contributors": [],
|
||||
"description": "Asm.js content for wasm-crypto",
|
||||
"browser": "empty.js",
|
||||
"main": "empty.js",
|
||||
"react-native": "data.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-asmjs#readme",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"homepage": "https://github.com/polkadot-js/wasm",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/wasm-crypto-asmjs",
|
||||
"repository": {
|
||||
"directory": "packages/wasm-crypto-asmjs",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.3"
|
||||
"@babel/runtime": "^7.17.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { asmJsInit } from './cjs/data.js';
|
||||
export { packageInfo } from './packageInfo';
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export declare const asmJsInit: null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const asmJsInit = null;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asmJsInit as _asmJsInit } from './cjs/data.js';
|
||||
|
||||
export const asmJsInit = _asmJsInit;
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default [];
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, null, others);
|
||||
@@ -1,4 +0,0 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const asmJsInit = null;
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
export * from './bundle';
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.2.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
@@ -1,22 +1,31 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto-wasm",
|
||||
"version": "4.2.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"contributors": [],
|
||||
"description": "Wasm content for wasm-crypto",
|
||||
"browser": "data.js",
|
||||
"main": "data.js",
|
||||
"react-native": "data.js",
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-wasm#readme",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"homepage": "https://github.com/polkadot-js/wasm",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/wasm-crypto-wasm",
|
||||
"repository": {
|
||||
"directory": "packages/wasm-crypto-wasm",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.3"
|
||||
"@babel/runtime": "^7.17.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,22 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2014 Jameson Little
|
||||
//
|
||||
// https://github.com/beatgammit/base64-js/blob/88957c9943c7e2a0f03cdf73e71d579e433627d3/index.js
|
||||
// This only contains the toByteArray function (no encoding)
|
||||
//
|
||||
// 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
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
|
||||
const CODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
export function base64Decode (data: string): Uint8Array {
|
||||
const bytes = [];
|
||||
let byte = 0;
|
||||
let bits = 0;
|
||||
|
||||
const lookup: string[] = [];
|
||||
const revLookup: number[] = [];
|
||||
for (let i = 0; i < data.length && data[i] !== '='; i++) {
|
||||
// each character represents 6 bits
|
||||
byte = (byte << 6) | chars.indexOf(data[i]);
|
||||
|
||||
for (let i = 0; i < CODE.length; ++i) {
|
||||
lookup[i] = CODE[i];
|
||||
revLookup[CODE.charCodeAt(i)] = i;
|
||||
}
|
||||
|
||||
// Support decoding URL-safe base64 strings, as Node.js does.
|
||||
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
||||
revLookup['-'.charCodeAt(0)] = 62;
|
||||
revLookup['_'.charCodeAt(0)] = 63;
|
||||
|
||||
function getLens (b64: string): [number, number] {
|
||||
const len = b64.length;
|
||||
|
||||
if (len % 4 > 0) {
|
||||
throw new Error('Invalid string. Length must be a multiple of 4');
|
||||
// each byte needs to contain 8 bits
|
||||
if ((bits += 6) >= 8) {
|
||||
bytes.push((byte >>> (bits -= 8)) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
// Trim off extra bytes after placeholder bytes are found
|
||||
// See: https://github.com/beatgammit/base64-js/issues/42
|
||||
const validLen = b64.indexOf('=');
|
||||
|
||||
return validLen === -1
|
||||
? [len, 0]
|
||||
: [validLen, 4 - (validLen % 4)];
|
||||
}
|
||||
|
||||
export function toByteArray (b64: string): Uint8Array {
|
||||
const [validLen, placeHoldersLen] = getLens(b64);
|
||||
const arr = new Uint8Array(((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen);
|
||||
let curByte = 0;
|
||||
let i: number;
|
||||
let tmp: number;
|
||||
|
||||
// if there are placeholders, only get up to the last complete 4 chars
|
||||
const len = placeHoldersLen > 0
|
||||
? validLen - 4
|
||||
: validLen;
|
||||
|
||||
for (i = 0; i < len; i += 4) {
|
||||
tmp =
|
||||
(revLookup[b64.charCodeAt(i)] << 18) |
|
||||
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
||||
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
||||
revLookup[b64.charCodeAt(i + 3)];
|
||||
|
||||
arr[curByte++] = (tmp >> 16) & 0xFF;
|
||||
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||
arr[curByte++] = tmp & 0xFF;
|
||||
}
|
||||
|
||||
if (placeHoldersLen === 2) {
|
||||
tmp =
|
||||
(revLookup[b64.charCodeAt(i)] << 2) |
|
||||
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
||||
|
||||
arr[curByte++] = tmp & 0xFF;
|
||||
} else if (placeHoldersLen === 1) {
|
||||
tmp =
|
||||
(revLookup[b64.charCodeAt(i)] << 10) |
|
||||
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
||||
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
||||
|
||||
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||
arr[curByte++] = tmp & 0xFF;
|
||||
}
|
||||
|
||||
return arr;
|
||||
return Uint8Array.from(bytes);
|
||||
}
|
||||
|
||||
@@ -0,0 +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 { unzlibSync } from './fflate';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright 2019-2021 @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
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export declare const bytes = '';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
exports.bytes = '';
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { toByteArray } from './base64';
|
||||
import { bytes, sizeUncompressed } from './bytes';
|
||||
import { unzlibSync } from './fflate';
|
||||
|
||||
export const wasmBytes = unzlibSync(toByteArray(bytes), new Uint8Array(sizeUncompressed));
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default [];
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, null, others);
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const bytes = null;
|
||||
|
||||
export const sizeCompressed = 0;
|
||||
|
||||
export const sizeUncompressed = 0;
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// MIT License
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
export * from './bundle';
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.2.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
Generated
+86
-26
@@ -45,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
@@ -107,12 +107,24 @@ 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"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
@@ -232,9 +244,22 @@ version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi 0.10.2+wasi-snapshot-preview1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
@@ -273,6 +298,15 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keccak"
|
||||
version = "0.1.0"
|
||||
@@ -287,9 +321,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.74"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
@@ -306,7 +340,7 @@ version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -379,7 +413,7 @@ version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"cloudabi",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
@@ -411,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",
|
||||
]
|
||||
@@ -433,7 +467,7 @@ version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.1.14",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
@@ -456,7 +490,7 @@ version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -495,7 +529,7 @@ dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec 0.5.1",
|
||||
"curve25519-dalek",
|
||||
"getrandom",
|
||||
"getrandom 0.1.14",
|
||||
"merlin",
|
||||
"rand",
|
||||
"rand_core",
|
||||
@@ -523,6 +557,24 @@ dependencies = [
|
||||
"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]]
|
||||
name = "serde"
|
||||
version = "1.0.114"
|
||||
@@ -567,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",
|
||||
@@ -655,6 +707,12 @@ version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "wasm"
|
||||
version = "0.0.0"
|
||||
@@ -663,6 +721,7 @@ dependencies = [
|
||||
"byteorder",
|
||||
"curve25519-dalek",
|
||||
"ed25519-dalek",
|
||||
"getrandom 0.2.3",
|
||||
"hex-literal",
|
||||
"hmac",
|
||||
"merlin",
|
||||
@@ -670,6 +729,7 @@ dependencies = [
|
||||
"rand",
|
||||
"schnorrkel",
|
||||
"scrypt",
|
||||
"secp256k1",
|
||||
"sha2",
|
||||
"tiny-bip39",
|
||||
"tiny-keccak",
|
||||
@@ -680,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",
|
||||
"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",
|
||||
@@ -705,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",
|
||||
@@ -715,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",
|
||||
@@ -728,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"
|
||||
@@ -738,7 +798,7 @@ version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"memory_units",
|
||||
"winapi",
|
||||
|
||||
@@ -9,6 +9,7 @@ license = "Apache-2.0"
|
||||
name = "wasm"
|
||||
publish = false
|
||||
repository = "https://github.com/polkadot-js/wasm/"
|
||||
resolver = "2"
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
@@ -17,19 +18,21 @@ crate-type = ["cdylib"]
|
||||
[dependencies]
|
||||
blake2-rfc = "0.2.18"
|
||||
byteorder = "1.3.1"
|
||||
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 = "0.2.2"
|
||||
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 }
|
||||
curve25519-dalek = { version = "2.1.0", default-features = false }
|
||||
rand = { version="0.7.3", default-features = false, features = ["wasm-bindgen"] }
|
||||
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
|
||||
scrypt = { version = "0.2", default-features = false }
|
||||
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]
|
||||
|
||||
@@ -1,24 +1,43 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto",
|
||||
"version": "4.2.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"main": "index.js",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"contributors": [],
|
||||
"description": "A wasm interface layer for use by @polkadot/util-crypto",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/wasm-crypto",
|
||||
"repository": {
|
||||
"directory": "packages/wasm-crypto",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs",
|
||||
"./initNone.js",
|
||||
"./initNone.cjs",
|
||||
"./initOnlyAsm.js",
|
||||
"./initOnlyAsm.cjs",
|
||||
"./initOnlyWasm.js",
|
||||
"./initOnlyWasm.cjs",
|
||||
"./initWasmAsm.js",
|
||||
"./initWasmAsm.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "5.1.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.3",
|
||||
"@polkadot/wasm-crypto-asmjs": "^4.2.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^4.2.1"
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/wasm-crypto-asmjs": "^5.1.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^7.2.1",
|
||||
"@polkadot/x-randomvalues": "^7.2.1"
|
||||
"@polkadot/util": "^8.6.1",
|
||||
"@polkadot/x-randomvalues": "^8.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*",
|
||||
|
||||
@@ -1,64 +1,61 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* 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';
|
||||
|
||||
let wasm: WasmCryptoInstance | null = null;
|
||||
let cachegetInt32: Int32Array | null = null;
|
||||
let cachegetUint8: Uint8Array | null = null;
|
||||
type PopFirst<T extends unknown[]> =
|
||||
T extends [WasmCryptoInstance, ...infer N]
|
||||
? N
|
||||
: [];
|
||||
|
||||
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>);
|
||||
}
|
||||
|
||||
// FIXME We really would love to clean this up and have a sign like (wasm, ...params) => T
|
||||
// Alas, TypeScript foo is not that great today, so we sadly have an extra closure here
|
||||
export function withWasm <T, F extends (...params: never[]) => T> (fn: (wasm: WasmCryptoInstance) => F): F {
|
||||
return ((...params: never[]): T => {
|
||||
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.');
|
||||
export const __bridge: Bridge = {
|
||||
cachegetInt32: null,
|
||||
cachegetUint8: null,
|
||||
type: 'wasm',
|
||||
wasm: null,
|
||||
wasmPromise: null,
|
||||
wasmPromiseFn: null
|
||||
};
|
||||
|
||||
return fn(wasm)(...params);
|
||||
}) as unknown as F;
|
||||
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(__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(__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 {
|
||||
@@ -70,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);
|
||||
|
||||
@@ -86,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;
|
||||
}
|
||||
|
||||
+147
-194
@@ -1,268 +1,221 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// 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);
|
||||
|
||||
export const bip39Generate = withWasm((wasm) =>
|
||||
(words: 12 | 15 | 18 | 21 | 24): string => {
|
||||
wasm.ext_bip39_generate(8, words);
|
||||
return resultString();
|
||||
});
|
||||
|
||||
return resultString();
|
||||
}
|
||||
);
|
||||
export const bip39ToEntropy = withWasm((wasm, phrase: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_entropy(8, ...allocString(phrase));
|
||||
|
||||
export const bip39ToEntropy = withWasm((wasm) =>
|
||||
(phrase: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_bip39_to_entropy(8, ptr0, len0);
|
||||
export const bip39ToMiniSecret = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_mini_secret(8, ...allocString(phrase), ...allocString(password));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const bip39ToMiniSecret = withWasm((wasm) =>
|
||||
(phrase: string, password: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
export const bip39ToSeed = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_seed(8, ...allocString(phrase), ...allocString(password));
|
||||
|
||||
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const bip39Validate = withWasm((wasm, phrase: string): boolean => {
|
||||
const ret = wasm.ext_bip39_validate(...allocString(phrase));
|
||||
|
||||
export const bip39ToSeed = withWasm((wasm) =>
|
||||
(phrase: string, password: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
|
||||
export const ed25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||
wasm.ext_ed_from_seed(8, ...allocU8a(seed));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const bip39Validate = withWasm((wasm) =>
|
||||
(phrase: string): boolean => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const ret = wasm.ext_bip39_validate(ptr0, len0);
|
||||
export const ed25519Sign = withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
wasm.ext_ed_sign(8, ...allocU8a(pubkey), ...allocU8a(seckey), ...allocU8a(message));
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const ed25519KeypairFromSeed = withWasm((wasm) =>
|
||||
(seed: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
export const ed25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_ed_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
||||
|
||||
wasm.ext_ed_from_seed(8, ptr0, len0);
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const secp256k1FromSeed = withWasm((wasm, seckey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_from_seed(8, ...allocU8a(seckey));
|
||||
|
||||
export const ed25519Sign = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(seckey);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
export const secp256k1Compress = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_pub_compress(8, ...allocU8a(pubkey));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const ed25519Verify = withWasm((wasm) =>
|
||||
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const [ptr0, len0] = allocU8a(signature);
|
||||
const [ptr1, len1] = allocU8a(message);
|
||||
const [ptr2, len2] = allocU8a(pubkey);
|
||||
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
export const secp256k1Expand = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_pub_expand(8, ...allocU8a(pubkey));
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
|
||||
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
export const secp256k1Recover = withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
|
||||
wasm.ext_secp_recover(8, ...allocU8a(msgHash), ...allocU8a(sig), recovery);
|
||||
|
||||
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const secp256k1Sign = withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_sign(8, ...allocU8a(msgHash), ...allocU8a(seckey));
|
||||
|
||||
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
|
||||
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
|
||||
export const sr25519DeriveKeypairHard = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_keypair_hard(8, ...allocU8a(pair), ...allocU8a(cc));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519DerivePublicSoft = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
export const sr25519DeriveKeypairSoft = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_keypair_soft(8, ...allocU8a(pair), ...allocU8a(cc));
|
||||
|
||||
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const sr25519DerivePublicSoft = withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_public_soft(8, ...allocU8a(pubkey), ...allocU8a(cc));
|
||||
|
||||
export const sr25519KeypairFromSeed = withWasm((wasm) =>
|
||||
(seed: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_sr_from_seed(8, ptr0, len0);
|
||||
export const sr25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_from_seed(8, ...allocU8a(seed));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519Sign = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(secret);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
export const sr25519Sign = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_sign(8, ...allocU8a(pubkey), ...allocU8a(secret), ...allocU8a(message));
|
||||
|
||||
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const sr25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_sr_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
||||
|
||||
export const sr25519Verify = withWasm((wasm) =>
|
||||
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const [ptr0, len0] = allocU8a(signature);
|
||||
const [ptr1, len1] = allocU8a(message);
|
||||
const [ptr2, len2] = allocU8a(pubkey);
|
||||
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
export const sr25519Agree = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_agree(8, ...allocU8a(pubkey), ...allocU8a(secret));
|
||||
|
||||
export const sr25519Agree = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(secret);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_sr_agree(8, ptr0, len0, ptr1, len1);
|
||||
export const vrfSign = withWasm((wasm, secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
|
||||
wasm.ext_vrf_sign(8, ...allocU8a(secret), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const vrfSign = withWasm((wasm) =>
|
||||
(secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(secret);
|
||||
const [ptr1, len1] = allocU8a(context);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
const [ptr3, len3] = allocU8a(extra);
|
||||
export const vrfVerify = withWasm((wasm, pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_vrf_verify(...allocU8a(pubkey), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra), ...allocU8a(outAndProof));
|
||||
|
||||
wasm.ext_vrf_sign(8, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const blake2b = withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||
wasm.ext_blake2b(8, ...allocU8a(data), ...allocU8a(key), size);
|
||||
|
||||
export const vrfVerify = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(context);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
const [ptr3, len3] = allocU8a(extra);
|
||||
const [ptr4, len4] = allocU8a(outAndProof);
|
||||
const ret = wasm.ext_vrf_verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
export const hmacSha256 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_hmac_sha256(8, ...allocU8a(key), ...allocU8a(data));
|
||||
|
||||
export const blake2b = withWasm((wasm) =>
|
||||
(data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(key);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
|
||||
export const hmacSha512 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_hmac_sha512(8, ...allocU8a(key), ...allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const keccak256 = withWasm((wasm) =>
|
||||
(data: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
export const keccak256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_keccak256(8, ...allocU8a(data));
|
||||
|
||||
wasm.ext_keccak256(8, ptr0, len0);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const keccak512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_keccak512(8, ...allocU8a(data));
|
||||
|
||||
export const pbkdf2 = withWasm((wasm) =>
|
||||
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
|
||||
export const pbkdf2 = withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||
wasm.ext_pbkdf2(8, ...allocU8a(data), ...allocU8a(salt), rounds);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const scrypt = withWasm((wasm) =>
|
||||
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(password);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
export const scrypt = withWasm((wasm, password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
||||
wasm.ext_scrypt(8, ...allocU8a(password), ...allocU8a(salt), log2n, r, p);
|
||||
|
||||
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
export const sha256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sha256(8, ...allocU8a(data));
|
||||
|
||||
export const sha512 = withWasm((wasm) =>
|
||||
(data: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
wasm.ext_sha512(8, ptr0, len0);
|
||||
export const sha512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sha512(8, ...allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
export const twox = withWasm((wasm) =>
|
||||
(data: Uint8Array, rounds: number) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
export const twox = withWasm((wasm, data: Uint8Array, rounds: number) => {
|
||||
wasm.ext_twox(8, ...allocU8a(data), rounds);
|
||||
|
||||
wasm.ext_twox(8, ptr0, len0, rounds);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
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,7 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||
|
||||
export default [asmInfo, wasmInfo];
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [asmInfo, wasmInfo]);
|
||||
detectPackage(packageInfo, null, others);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -51,6 +51,10 @@ export function __wbindgen_is_undefined (idx: number): boolean {
|
||||
return getObject(idx) === undefined;
|
||||
}
|
||||
|
||||
export function __wbindgen_throw (ptr: number, len: number): boolean {
|
||||
throw new Error(getString(ptr, len));
|
||||
}
|
||||
|
||||
export function __wbg_self_1b7a39e3a92c949c (): number {
|
||||
return addObject(DEFAULT_SELF);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
@@ -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);
|
||||
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Be able to import json in TS
|
||||
// https://stackoverflow.com/questions/49996456/importing-json-file-in-typescript
|
||||
declare module '*.json' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const value: any;
|
||||
|
||||
export default value;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Use `wee_alloc` as the global allocator.
|
||||
@@ -14,6 +14,9 @@ pub mod ed25519;
|
||||
#[path = "rs/hashing.rs"]
|
||||
pub mod hashing;
|
||||
|
||||
#[path = "rs/secp256k1.rs"]
|
||||
pub mod secp256k1;
|
||||
|
||||
#[path = "rs/sr25519.rs"]
|
||||
pub mod sr25519;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.2.1' };
|
||||
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '5.1.1' };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||
@@ -14,8 +14,11 @@ use wasm_bindgen::prelude::*;
|
||||
/// Returns the bip 39 phrase
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_generate(words: u32) -> String {
|
||||
Mnemonic::new(MnemonicType::for_word_count(words as usize).unwrap(), Language::English)
|
||||
.into_phrase()
|
||||
match MnemonicType::for_word_count(words as usize) {
|
||||
Ok(p) => Mnemonic::new(p, Language::English)
|
||||
.into_phrase(),
|
||||
_ => panic!("Invalid count provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Create entropy from a bip39 phrase
|
||||
@@ -25,10 +28,12 @@ pub fn ext_bip39_generate(words: u32) -> String {
|
||||
/// Returns the entropy
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_to_entropy(phrase: &str) -> Vec<u8> {
|
||||
Mnemonic::from_phrase(phrase, Language::English)
|
||||
.unwrap()
|
||||
.entropy()
|
||||
.to_vec()
|
||||
match Mnemonic::from_phrase(phrase, Language::English) {
|
||||
Ok(m) => m
|
||||
.entropy()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid phrase provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a mini-secret from a bip39 phrase
|
||||
@@ -38,13 +43,20 @@ pub fn ext_bip39_to_entropy(phrase: &str) -> Vec<u8> {
|
||||
/// Returns the 32-byte mini-secret via entropy
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
|
||||
let salt = format!("mnemonic{}", password);
|
||||
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
|
||||
let mut result = [0u8; 64];
|
||||
match Mnemonic::from_phrase(phrase, Language::English) {
|
||||
Ok(m) => {
|
||||
let mut res = [0u8; 64];
|
||||
let mut seed = vec![];
|
||||
|
||||
pbkdf2::<Hmac<Sha512>>(mnemonic.entropy(), salt.as_bytes(), 2048, &mut result);
|
||||
seed.extend_from_slice(b"mnemonic");
|
||||
seed.extend_from_slice(password.as_bytes());
|
||||
|
||||
result[..32].to_vec()
|
||||
pbkdf2::<Hmac<Sha512>>(m.entropy(), &seed, 2048, &mut res);
|
||||
|
||||
res[..32].to_vec()
|
||||
},
|
||||
_ => panic!("Invalid phrase provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a BTC/ETH compatible seed from a bip-39 phrase
|
||||
@@ -54,11 +66,12 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
|
||||
/// Returns a 32-byte seed
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_to_seed(phrase: &str, password: &str) -> Vec<u8> {
|
||||
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
|
||||
|
||||
Seed::new(&mnemonic, password)
|
||||
.as_bytes()[..32]
|
||||
.to_vec()
|
||||
match Mnemonic::from_phrase(phrase, Language::English) {
|
||||
Ok(m) => Seed::new(&m, password)
|
||||
.as_bytes()[..32]
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid phrase provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates a bip39 phrase
|
||||
@@ -69,8 +82,8 @@ pub fn ext_bip39_to_seed(phrase: &str, password: &str) -> Vec<u8> {
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_validate(phrase: &str) -> bool {
|
||||
match Mnemonic::validate(phrase, Language::English) {
|
||||
Err(_) => false,
|
||||
_ => true
|
||||
Ok(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +96,9 @@ pub mod tests {
|
||||
fn can_bip39_entropy() {
|
||||
let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow";
|
||||
let entropy = hex!("7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f");
|
||||
let result = ext_bip39_to_entropy(phrase);
|
||||
let res = ext_bip39_to_entropy(phrase);
|
||||
|
||||
assert_eq!(result, entropy);
|
||||
assert_eq!(res, entropy);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -93,18 +106,18 @@ pub mod tests {
|
||||
let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow";
|
||||
let password = "Substrate";
|
||||
let mini = hex!("4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685");
|
||||
let result = ext_bip39_to_mini_secret(phrase, password);
|
||||
let res = ext_bip39_to_mini_secret(phrase, password);
|
||||
|
||||
assert_eq!(result[..], mini[..]);
|
||||
assert_eq!(res[..], mini[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_bip39_seed() {
|
||||
let phrase = "seed sock milk update focus rotate barely fade car face mechanic mercy";
|
||||
let seed = hex!("3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027");
|
||||
let result = ext_bip39_to_seed(phrase, "");
|
||||
let res = ext_bip39_to_seed(phrase, "");
|
||||
|
||||
assert_eq!(result[..], seed[..]);
|
||||
assert_eq!(res[..], seed[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,41 +1,20 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Keypair helper function.
|
||||
fn create_from_pair(pair: &[u8]) -> Keypair {
|
||||
match Keypair::from_bytes(pair) {
|
||||
Ok(pair) => return pair,
|
||||
Err(_) => panic!("Provided pair is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Keypair helper function
|
||||
fn create_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
|
||||
fn new_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
|
||||
let mut pair = vec![];
|
||||
|
||||
pair.extend_from_slice(seckey);
|
||||
pair.extend_from_slice(pubkey);
|
||||
|
||||
create_from_pair(&pair)
|
||||
}
|
||||
|
||||
/// Keypair helper function.
|
||||
fn create_from_seed(seed: &[u8]) -> Keypair {
|
||||
let seckey = SecretKey::from_bytes(seed).unwrap();
|
||||
let pubkey: PublicKey = (&seckey).into();
|
||||
|
||||
create_from_parts(pubkey.as_bytes(), seed)
|
||||
}
|
||||
|
||||
/// PublicKey helper
|
||||
fn create_public(pubkey: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(pubkey) {
|
||||
Ok(pubkey) => return pubkey,
|
||||
Err(_) => panic!("Provided public key is invalid.")
|
||||
match Keypair::from_bytes(&pair) {
|
||||
Ok(p) => p,
|
||||
_ => panic!("Provided pair is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +26,16 @@ fn create_public(pubkey: &[u8]) -> PublicKey {
|
||||
/// followed by the public key (32) bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
create_from_seed(seed)
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
match &SecretKey::from_bytes(seed) {
|
||||
Ok(s) => {
|
||||
let pubkey: PublicKey = s.into();
|
||||
|
||||
new_from_parts(pubkey.as_bytes(), seed)
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
},
|
||||
_ => panic!("Invalid seed provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Sign a message
|
||||
@@ -64,7 +50,7 @@ pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_from_parts(pubkey, seckey)
|
||||
new_from_parts(pubkey, seckey)
|
||||
.sign(message)
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
@@ -77,14 +63,12 @@ pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||
let signature = match Signature::try_from(signature) {
|
||||
Ok(signature) => signature,
|
||||
Err(_) => return false
|
||||
};
|
||||
|
||||
create_public(pubkey)
|
||||
.verify(message, &signature)
|
||||
.is_ok()
|
||||
match (Signature::try_from(signature), PublicKey::from_bytes(pubkey)) {
|
||||
(Ok(s), Ok(k)) => k
|
||||
.verify(message, &s)
|
||||
.is_ok(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -100,7 +84,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create_keypair() {
|
||||
fn can_new_keypair() {
|
||||
let seed = generate_random_seed();
|
||||
let keypair = ext_ed_from_seed(seed.as_slice());
|
||||
|
||||
|
||||
@@ -1,31 +1,16 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use blake2_rfc::blake2b::blake2b;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use hmac::Hmac;
|
||||
use hmac::{Hmac, Mac};
|
||||
use pbkdf2::pbkdf2;
|
||||
use scrypt::{ScryptParams, scrypt};
|
||||
use sha2::{Digest, Sha512};
|
||||
use sha2::{Digest, Sha256, Sha512};
|
||||
use tiny_keccak::{Hasher, Keccak};
|
||||
use twox_hash::XxHash;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// helper function for a single twox round with a seed
|
||||
fn create_twox(data: &[u8], seed: u64) -> [u8; 8] {
|
||||
use ::std::hash::Hasher;
|
||||
let mut hasher = XxHash::with_seed(seed);
|
||||
|
||||
hasher.write(data);
|
||||
|
||||
let hash64 = hasher.finish();
|
||||
let mut result = [0u8; 8];
|
||||
|
||||
LittleEndian::write_u64(&mut result, hash64);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// blake2b hash for the specified input
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
@@ -41,6 +26,39 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// hmac with sha256
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_hmac_sha256(key: &[u8], data: &[u8]) -> Vec<u8> {
|
||||
match Hmac::<Sha256>::new_varkey(key) {
|
||||
Ok(mut m) => {
|
||||
m.input(data);
|
||||
|
||||
m
|
||||
.result()
|
||||
.code()
|
||||
.to_vec()
|
||||
},
|
||||
_ => panic!("Invalid key provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// hmac with sha512
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_hmac_sha512(key: &[u8], data: &[u8]) -> Vec<u8> {
|
||||
match Hmac::<Sha512>::new_varkey(key) {
|
||||
Ok(mut m) => {
|
||||
m.input(data);
|
||||
|
||||
m
|
||||
.result()
|
||||
.code()
|
||||
.to_vec()
|
||||
},
|
||||
_ => panic!("Invalid key provided.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Create a keccak256 hash for the specified input
|
||||
///
|
||||
// * data: Arbitrary data to be hashed
|
||||
@@ -49,12 +67,28 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
|
||||
let mut keccak = Keccak::v256();
|
||||
let mut result = [0u8; 32];
|
||||
let mut res = [0u8; 32];
|
||||
|
||||
keccak.update(data);
|
||||
keccak.finalize(&mut result);
|
||||
keccak.finalize(&mut res);
|
||||
|
||||
result.to_vec()
|
||||
res.to_vec()
|
||||
}
|
||||
|
||||
/// Create a keccak512 hash for the specified input
|
||||
///
|
||||
// * data: Arbitrary data to be hashed
|
||||
///
|
||||
/// Returns the hash as a vector
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_keccak512(data: &[u8]) -> Vec<u8> {
|
||||
let mut keccak = Keccak::v512();
|
||||
let mut res = [0u8; 64];
|
||||
|
||||
keccak.update(data);
|
||||
keccak.finalize(&mut res);
|
||||
|
||||
res.to_vec()
|
||||
}
|
||||
|
||||
/// pbkdf2 kdf from an input, salt for the number of specified rounds
|
||||
@@ -66,12 +100,12 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
|
||||
/// Returns a vector with the hashed result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
let mut result = [0u8; 64];
|
||||
let mut res = [0u8; 64];
|
||||
|
||||
// we cast to usize here - due to the WASM, we'd rather have u32 inputs
|
||||
pbkdf2::<Hmac<Sha512>>(data, salt, rounds as usize, &mut result);
|
||||
pbkdf2::<Hmac::<Sha512>>(data, salt, rounds as usize, &mut res);
|
||||
|
||||
result.to_vec()
|
||||
res.to_vec()
|
||||
}
|
||||
|
||||
/// scrypt kdf from input, salt and config
|
||||
@@ -85,13 +119,34 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
/// Returns vector with the hashed result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> Vec<u8> {
|
||||
let params = ScryptParams::new(log2_n, r, p).unwrap();
|
||||
let mut result = [0u8; 64];
|
||||
match ScryptParams::new(log2_n, r, p) {
|
||||
Ok(p) => {
|
||||
let mut res = [0u8; 64];
|
||||
|
||||
match scrypt(password, salt, ¶ms, &mut result) {
|
||||
Ok(_) => return result.to_vec(),
|
||||
Err(_) => panic!("Invalid scrypt hash.")
|
||||
match scrypt(password, salt, &p, &mut res) {
|
||||
Ok(_) => res.to_vec(),
|
||||
_ => panic!("Invalid scrypt hash.")
|
||||
}
|
||||
},
|
||||
_ => panic!("Invalid scrypt params.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// sha256 hash for the specified input
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
///
|
||||
/// Returns a vector with the hash result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sha256(data: &[u8]) -> Vec<u8> {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
hasher.input(data);
|
||||
|
||||
hasher
|
||||
.result()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// sha512 hash for the specified input
|
||||
@@ -118,14 +173,20 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
||||
/// Returns a vector with the hash result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
||||
let mut vec = vec![];
|
||||
use ::std::hash::Hasher;
|
||||
let mut res = vec![];
|
||||
let mut buf = [0u8; 8];
|
||||
|
||||
for round in 0..rounds {
|
||||
// we cast to u64 here - due to the WASM, we'd rather have u32 inputs
|
||||
vec.extend_from_slice(&create_twox(data, round as u64));
|
||||
let mut hasher = XxHash::with_seed(round as u64);
|
||||
|
||||
hasher.write(data);
|
||||
LittleEndian::write_u64(&mut buf, hasher.finish());
|
||||
res.extend_from_slice(&buf);
|
||||
}
|
||||
|
||||
vec
|
||||
res
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -154,6 +215,35 @@ pub mod tests {
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_hmac_sha256() {
|
||||
let key = b"secret";
|
||||
let data = b"some message";
|
||||
let expected = hex!("f28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7");
|
||||
let hash = ext_hmac_sha256(key, data);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_hmac_sha512() {
|
||||
let key = b"secret";
|
||||
let data = b"some message";
|
||||
let expected = hex!("295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841");
|
||||
let hash = ext_hmac_sha512(key, data);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_keccak512() {
|
||||
let data = b"test";
|
||||
let expected = hex!("1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e");
|
||||
let hash = ext_keccak512(data);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_pbkdf2() {
|
||||
let salt = b"this is a salt";
|
||||
@@ -174,6 +264,15 @@ pub mod tests {
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_sha256() {
|
||||
let data = b"hello world";
|
||||
let expected = hex!("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
|
||||
let hash = ext_sha256(data);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_sha512() {
|
||||
let data = b"hello world";
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
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::from_slice(&pubkey) {
|
||||
Ok(p) => p
|
||||
.serialize()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pubkey provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
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_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()
|
||||
.to_vec(),
|
||||
_ => 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::from_slice(hash), SecretKey::from_slice(seckey)) {
|
||||
(Ok(m), Ok(s)) => {
|
||||
let mut res = vec![];
|
||||
let (rec, sig) = SECP256K1
|
||||
.sign_ecdsa_recoverable(&m, &s)
|
||||
.serialize_compact();
|
||||
|
||||
res.extend_from_slice(&sig);
|
||||
res.push(rec.to_i32() as u8);
|
||||
|
||||
res
|
||||
},
|
||||
_ => panic!("Invalid message or secret provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use hex_literal::hex;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn can_create_pair() {
|
||||
let seckey = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae");
|
||||
let expected = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae03fd8c74f795ced92064b86191cb2772b1e3a0947740aa0a5a6e379592471fd85b");
|
||||
let res = ext_secp_from_seed(&seckey);
|
||||
|
||||
assert_eq!(res[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_pub_compress_full() {
|
||||
let pubkey = hex!("04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af");
|
||||
let expected = hex!("03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077");
|
||||
let res = ext_secp_pub_compress(&pubkey);
|
||||
|
||||
assert_eq!(res[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_pub_expand_comp() {
|
||||
let pubkey = hex!("03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077");
|
||||
let expected = hex!("04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af");
|
||||
let res = ext_secp_pub_expand(&pubkey);
|
||||
|
||||
assert_eq!(res[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_recover() {
|
||||
let expected = hex!("028d13da15a02f3a70677339d51b14177ee9b49657662b35e56a9d9dee17db1d30");
|
||||
let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff");
|
||||
let msg = hex!("a30b64ce1eedf409c8afb801d72c05234e64849ea538c15dd3c8cf4ffcf166c9");
|
||||
let res = ext_secp_recover(&msg, &sig, 0);
|
||||
|
||||
assert_eq!(res[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_sign() {
|
||||
// JS expectation - doesn't match?
|
||||
// let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba8c4efa521361678d9b8582744d77aa4b8d886d7380b7808a683174afad9c4700300");
|
||||
let expected = hex!("df92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba83b105adec9e9872647a7d8bb28855b45e22805aea3d097953cbb1391f671d13e01");
|
||||
let seckey = hex!("4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae");
|
||||
let msg = hex!("68c731589a583d08b70861683b59ce3dd56284cb2f0da5b6cd83e6641dac3aab");
|
||||
let res = ext_secp_sign(&msg, &seckey);
|
||||
|
||||
assert_eq!(res[..], expected[..]);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||
@@ -15,10 +15,10 @@ use schnorrkel::{
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// We must make sure that this is the same as declared in the substrate source code.
|
||||
const SIGNING_CTX: &'static [u8] = b"substrate";
|
||||
const CTX: &'static [u8] = b"substrate";
|
||||
|
||||
/// ChainCode construction helper
|
||||
fn create_cc(data: &[u8]) -> ChainCode {
|
||||
fn new_cc(data: &[u8]) -> ChainCode {
|
||||
let mut cc = [0u8; CHAIN_CODE_LENGTH];
|
||||
|
||||
cc.copy_from_slice(&data);
|
||||
@@ -34,13 +34,14 @@ fn create_cc(data: &[u8]) -> ChainCode {
|
||||
/// returned vector the derived keypair as a array of 96 bytes
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
Keypair::from_half_ed25519_bytes(pair)
|
||||
.unwrap()
|
||||
.secret
|
||||
.hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
match Keypair::from_half_ed25519_bytes(pair) {
|
||||
Ok(p) => p.secret
|
||||
.hard_derive_mini_secret_key(Some(new_cc(cc)), &[]).0
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pair provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform a derivation on a secret
|
||||
@@ -51,11 +52,13 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
/// returned vector the derived keypair as a array of 96 bytes
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
Keypair::from_half_ed25519_bytes(pair)
|
||||
.unwrap()
|
||||
.derived_key_simple(create_cc(cc), &[]).0
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
match Keypair::from_half_ed25519_bytes(pair) {
|
||||
Ok(p) => p
|
||||
.derived_key_simple(new_cc(cc), &[]).0
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pair provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform a derivation on a publicKey
|
||||
@@ -66,11 +69,13 @@ pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
/// returned vector is the derived publicKey as a array of 32 bytes
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
PublicKey::from_bytes(pubkey)
|
||||
.unwrap()
|
||||
.derived_key_simple(create_cc(cc), &[]).0
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
match PublicKey::from_bytes(pubkey) {
|
||||
Ok(k) => k
|
||||
.derived_key_simple(new_cc(cc), &[]).0
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pubkey provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a key pair.
|
||||
@@ -81,11 +86,13 @@ pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
/// followed by the public key (32) bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
MiniSecretKey::from_bytes(seed)
|
||||
.unwrap()
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
match MiniSecretKey::from_bytes(seed) {
|
||||
Ok(s) => s
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid seed provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a key pair from a known pair. (This is not exposed via WASM)
|
||||
@@ -95,10 +102,12 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
/// returned vector is the concatenation of first the private key (64 bytes)
|
||||
/// followed by the public key (32) bytes.
|
||||
pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
|
||||
Keypair::from_half_ed25519_bytes(pair)
|
||||
.unwrap()
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
match Keypair::from_half_ed25519_bytes(pair) {
|
||||
Ok(p) => p
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid pair provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Sign a message
|
||||
@@ -113,11 +122,13 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
SecretKey::from_ed25519_bytes(secret)
|
||||
.unwrap()
|
||||
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(pubkey).unwrap())
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
match (SecretKey::from_ed25519_bytes(secret), PublicKey::from_bytes(pubkey)) {
|
||||
(Ok(s), Ok(k)) => s
|
||||
.sign_simple(CTX, message, &k)
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid secret or pubkey provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify a message and its corresponding against a public key;
|
||||
@@ -127,11 +138,11 @@ pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||
match Signature::from_bytes(signature) {
|
||||
Ok(signature) => PublicKey::from_bytes(pubkey).unwrap()
|
||||
.verify_simple(SIGNING_CTX, message, &signature)
|
||||
match (Signature::from_bytes(signature), PublicKey::from_bytes(pubkey)) {
|
||||
(Ok(s), Ok(k)) => k
|
||||
.verify_simple(CTX, message, &s)
|
||||
.is_ok(),
|
||||
Err(_) => false
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,19 +154,22 @@ pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||
/// * returned vector is the generated secret of 32 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_agree(pubkey: &[u8], secret: &[u8]) -> Vec<u8> {
|
||||
// The first 32 bytes holds the canonical private key
|
||||
let mut key = [0u8; 32];
|
||||
match SecretKey::from_ed25519_bytes(secret) {
|
||||
Ok(s) => {
|
||||
// The first 32 bytes holds the canonical private key
|
||||
let mut key = [0u8; 32];
|
||||
|
||||
key.copy_from_slice(
|
||||
&SecretKey::from_ed25519_bytes(secret)
|
||||
.unwrap()
|
||||
.to_bytes()[0..32]
|
||||
);
|
||||
key.copy_from_slice(&s.to_bytes()[0..32]);
|
||||
|
||||
(
|
||||
&Scalar::from_canonical_bytes(key).unwrap() *
|
||||
PublicKey::from_bytes(pubkey).unwrap().as_point()
|
||||
).compress().0.to_vec()
|
||||
match (Scalar::from_canonical_bytes(key), PublicKey::from_bytes(pubkey)) {
|
||||
(Some(n), Ok(k)) => (&n * k.as_point())
|
||||
.compress().0
|
||||
.to_vec(),
|
||||
_ => panic!("Invalid scalar or pubkey provided.")
|
||||
}
|
||||
},
|
||||
_ => panic!("Invalid secret provided.")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -168,11 +182,11 @@ pub mod tests {
|
||||
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
|
||||
|
||||
fn generate_random_seed() -> Vec<u8> {
|
||||
(0..32).map(|_| rand::random::<u8>() ).collect()
|
||||
(0..32).map(|_| rand::random::<u8>()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create_keypair() {
|
||||
fn can_new_keypair() {
|
||||
let seed = generate_random_seed();
|
||||
let keypair = ext_sr_from_seed(seed.as_slice());
|
||||
|
||||
@@ -190,7 +204,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_pair_from_known_pair() {
|
||||
fn new_pair_from_known_pair() {
|
||||
let input = hex!("28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
|
||||
let keypair = ext_sr_from_pair(&input);
|
||||
let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
|
||||
@@ -234,6 +248,26 @@ pub mod tests {
|
||||
assert!(is_valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_verify_known_wrapped_message() {
|
||||
let message = b"<Bytes>message to sign</Bytes>";
|
||||
let public = hex!("f84d048da2ddae2d9d8fd6763f469566e8817a26114f39408de15547f6d47805");
|
||||
let signature = hex!("48ce2c90e08651adfc8ecef84e916f6d1bb51ebebd16150ee12df247841a5437951ea0f9d632ca165e6ab391532e75e701be6a1caa88c8a6bcca3511f55b4183");
|
||||
let is_valid = ext_sr_verify(&signature, message, &public);
|
||||
|
||||
assert!(is_valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_verify_known_wrapped_message_fail() {
|
||||
let message = b"message to sign";
|
||||
let public = hex!("f84d048da2ddae2d9d8fd6763f469566e8817a26114f39408de15547f6d47805");
|
||||
let signature = hex!("48ce2c90e08651adfc8ecef84e916f6d1bb51ebebd16150ee12df247841a5437951ea0f9d632ca165e6ab391532e75e701be6a1caa88c8a6bcca3511f55b4183");
|
||||
let is_valid = ext_sr_verify(&signature, message, &public);
|
||||
|
||||
assert!(!is_valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn soft_derives_pair() {
|
||||
let cc = hex!("0c666f6f00000000000000000000000000000000000000000000000000000000"); // foo
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||
@@ -12,21 +12,21 @@ use schnorrkel::{signing_context, vrf::{VRFOutput, VRFProof}, PublicKey, SecretK
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Size of VRF output, bytes
|
||||
pub const VRF_OUTPUT_SIZE: usize = 32;
|
||||
pub const OUTPUT_SIZE: usize = 32;
|
||||
|
||||
/// Size of VRF proof, bytes
|
||||
pub const VRF_PROOF_SIZE: usize = 64;
|
||||
pub const PROOF_SIZE: usize = 64;
|
||||
|
||||
/// Size of VRF raw output, bytes
|
||||
pub const VRF_RAW_OUTPUT_SIZE: usize = 16;
|
||||
pub const RAW_OUTPUT_SIZE: usize = 16;
|
||||
|
||||
/// Size of VRF limit, bytes
|
||||
pub const VRF_THRESHOLD_SIZE: usize = 16;
|
||||
pub const THRESHOLD_SIZE: usize = 16;
|
||||
|
||||
/// Size of the final full output
|
||||
pub const VRF_RESULT_SIZE: usize = VRF_OUTPUT_SIZE + VRF_PROOF_SIZE;
|
||||
pub const RESULT_SIZE: usize = OUTPUT_SIZE + PROOF_SIZE;
|
||||
|
||||
pub fn create_transcript(extra: &[u8]) -> Transcript {
|
||||
pub fn new_transcript(extra: &[u8]) -> Transcript {
|
||||
let mut transcript = Transcript::new(b"VRF");
|
||||
|
||||
// if is important that we don't append when empty, since the
|
||||
@@ -38,7 +38,7 @@ pub fn create_transcript(extra: &[u8]) -> Transcript {
|
||||
transcript
|
||||
}
|
||||
|
||||
// We don't use the non-extra vrf_sign and vrf_verify internally since in sr25519 they only wrap -
|
||||
// We don't use the non-extra sign and verify internally since in sr25519 they only wrap -
|
||||
//
|
||||
// https://github.com/w3f/schnorrkel/blob/8fa2ad3e9fbf0b652c724df6a87a4b3c5500f759/src/vrf.rs#L660
|
||||
|
||||
@@ -53,15 +53,21 @@ pub fn create_transcript(extra: &[u8]) -> Transcript {
|
||||
///
|
||||
/// * returned vector is the 32-byte output (signature) and 64-byte proof.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_vrf_sign(secret: &[u8], context: &[u8], message: &[u8], extra: &[u8]) -> Vec<u8> {
|
||||
let keypair = SecretKey::from_ed25519_bytes(secret).unwrap().to_keypair();
|
||||
let transcript = create_transcript(extra);
|
||||
let (io, proof, _) = keypair.vrf_sign_extra(signing_context(context).bytes(message), transcript);
|
||||
let mut result: [u8; VRF_RESULT_SIZE] = [0u8; VRF_RESULT_SIZE];
|
||||
pub fn ext_vrf_sign(secret: &[u8], ctx: &[u8], msg: &[u8], extra: &[u8]) -> Vec<u8> {
|
||||
match SecretKey::from_ed25519_bytes(secret) {
|
||||
Ok(s) => {
|
||||
let mut res: [u8; RESULT_SIZE] = [0u8; RESULT_SIZE];
|
||||
let (io, proof, _) = s
|
||||
.to_keypair()
|
||||
.vrf_sign_extra(signing_context(ctx).bytes(msg), new_transcript(extra));
|
||||
|
||||
result[..VRF_OUTPUT_SIZE].copy_from_slice(io.as_output_bytes());
|
||||
result[VRF_OUTPUT_SIZE..].copy_from_slice(&proof.to_bytes());
|
||||
result.to_vec()
|
||||
res[..OUTPUT_SIZE].copy_from_slice(io.as_output_bytes());
|
||||
res[OUTPUT_SIZE..].copy_from_slice(&proof.to_bytes());
|
||||
|
||||
res.to_vec()
|
||||
},
|
||||
_ => panic!("Invalid secret provided.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify VRF proof for one single input transcript, and an extra message transcript,
|
||||
@@ -71,24 +77,13 @@ pub fn ext_vrf_sign(secret: &[u8], context: &[u8], message: &[u8], extra: &[u8])
|
||||
/// * context: Arbitrary length UIntArray
|
||||
/// * message: Arbitrary length UIntArray
|
||||
/// * extra: Arbitrary length UIntArray
|
||||
/// * out_and_proof: 96-byte output & proof array from the ext_vrf_sign function.
|
||||
/// * out_and_proof: 96-byte output & proof array from the ext_sign function.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_vrf_verify(pubkey: &[u8], context: &[u8], message: &[u8], extra: &[u8], out_and_proof: &[u8]) -> bool {
|
||||
match (
|
||||
PublicKey::from_bytes(pubkey),
|
||||
VRFOutput::from_bytes(&out_and_proof[..VRF_OUTPUT_SIZE]),
|
||||
VRFProof::from_bytes(&out_and_proof[VRF_OUTPUT_SIZE..VRF_RESULT_SIZE])
|
||||
) {
|
||||
(Ok(public), Ok(out), Ok(proof)) => {
|
||||
public
|
||||
.vrf_verify_extra(
|
||||
signing_context(context).bytes(message),
|
||||
&out,
|
||||
&proof,
|
||||
create_transcript(extra)
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
pub fn ext_vrf_verify(pubkey: &[u8], ctx: &[u8], msg: &[u8], extra: &[u8], out: &[u8]) -> bool {
|
||||
match (PublicKey::from_bytes(pubkey), VRFOutput::from_bytes(&out[..OUTPUT_SIZE]), VRFProof::from_bytes(&out[OUTPUT_SIZE..RESULT_SIZE])) {
|
||||
(Ok(k), Ok(o), Ok(p)) => k
|
||||
.vrf_verify_extra(signing_context(ctx).bytes(msg), &o, &p, new_transcript(extra))
|
||||
.is_ok(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -107,7 +102,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vrf_sign_extra_and_verify() {
|
||||
fn sign_extra_and_verify() {
|
||||
let seed = generate_random_seed();
|
||||
let keypair = ext_sr_from_seed(seed.as_slice());
|
||||
let private = &keypair[0..SECRET_KEY_LENGTH];
|
||||
@@ -116,23 +111,19 @@ pub mod tests {
|
||||
let message = b"this is a message";
|
||||
let extra = b"this is an extra";
|
||||
|
||||
// Perform multiple vrf_sign_extra calls w/ same context, message, extra args
|
||||
let out_and_proof1 = ext_vrf_sign(private, context, message, extra);
|
||||
let out_and_proof2 = ext_vrf_sign(private, context, message, extra);
|
||||
// Perform multiple sign_extra calls w/ same context, message, extra args
|
||||
let out1 = ext_vrf_sign(private, context, message, extra);
|
||||
let out2 = ext_vrf_sign(private, context, message, extra);
|
||||
|
||||
// Basic size checks
|
||||
assert!(out_and_proof1.len() == VRF_RESULT_SIZE);
|
||||
assert!(out_and_proof2.len() == VRF_RESULT_SIZE);
|
||||
assert!(out1.len() == RESULT_SIZE);
|
||||
assert!(out2.len() == RESULT_SIZE);
|
||||
|
||||
// Given the same context, message & extra, output should be deterministic
|
||||
let out1 = &out_and_proof1[..VRF_OUTPUT_SIZE];
|
||||
let out2 = &out_and_proof2[..VRF_OUTPUT_SIZE];
|
||||
assert_eq!(out1, out2);
|
||||
assert_eq!(&out1[..OUTPUT_SIZE], &out2[..OUTPUT_SIZE]);
|
||||
|
||||
// But proof is non-deterministic
|
||||
let proof1 = &out_and_proof1[VRF_OUTPUT_SIZE..];
|
||||
let proof2 = &out_and_proof2[VRF_OUTPUT_SIZE..];
|
||||
assert_ne!(proof1, proof2);
|
||||
assert_ne!(&out1[OUTPUT_SIZE..], &out2[OUTPUT_SIZE..]);
|
||||
|
||||
// VRF outputs can verified w/ original context, message & extra args
|
||||
assert!(ext_vrf_verify(
|
||||
@@ -140,14 +131,14 @@ pub mod tests {
|
||||
context,
|
||||
message,
|
||||
extra,
|
||||
&out_and_proof1
|
||||
&out1
|
||||
));
|
||||
assert!(ext_vrf_verify(
|
||||
public,
|
||||
context,
|
||||
message,
|
||||
extra,
|
||||
&out_and_proof2
|
||||
&out2
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -7,34 +7,81 @@
|
||||
export interface WasmCryptoInstance {
|
||||
memory: WebAssembly.Memory;
|
||||
|
||||
// wbindgen functions (required and used internally)
|
||||
|
||||
__wbindgen_free(a: number, b: number): void;
|
||||
|
||||
__wbindgen_malloc(a: number): number;
|
||||
|
||||
__wbindgen_realloc(a: number, b: number, c: number): number;
|
||||
|
||||
__wbindgen_exn_store(a: number): void;
|
||||
|
||||
ext_bip39_generate(a: number, b: number): void;
|
||||
ext_bip39_to_entropy(a: number, b: number, c: number): void;
|
||||
ext_bip39_to_mini_secret(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_bip39_to_seed(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_bip39_validate(a: number, b: number): number;
|
||||
ext_ed_from_seed(a: number, b: number, c: number): void;
|
||||
ext_ed_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
|
||||
ext_ed_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
|
||||
ext_blake2b(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
ext_keccak256(a: number, b: number, c: number): void;
|
||||
ext_pbkdf2(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
||||
ext_scrypt(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void;
|
||||
ext_sha512(a: number, b: number, c: number): void;
|
||||
ext_twox(a: number, b: number, c: number, d: number): void;
|
||||
ext_sr_derive_keypair_hard(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_sr_derive_keypair_soft(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_sr_derive_public_soft(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_sr_from_seed(a: number, b: number, c: number): void;
|
||||
ext_sr_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
|
||||
ext_sr_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
|
||||
ext_sr_agree(a: number, b: number, c: number, d: number, e: number): void;
|
||||
ext_vrf_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void;
|
||||
ext_vrf_verify(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number;
|
||||
// exposed functions
|
||||
|
||||
ext_bip39_generate(resLen: 8, words: number): void;
|
||||
|
||||
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
|
||||
|
||||
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
|
||||
|
||||
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
|
||||
|
||||
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
|
||||
|
||||
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
|
||||
|
||||
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
|
||||
|
||||
ext_secp_from_seed(reslen: 8, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_secp_pub_compress(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_pub_expand(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_recover(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSig: number, lenSig: number, recovery: number): void;
|
||||
|
||||
ext_secp_sign(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
|
||||
|
||||
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
|
||||
}
|
||||
|
||||
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// 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`);
|
||||
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', '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')
|
||||
}`)
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const { assert, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
@@ -11,6 +11,22 @@ function blake2bHash (wasm) {
|
||||
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
|
||||
}
|
||||
|
||||
function hmacSha256 (wasm) {
|
||||
const hash = u8aToHex(wasm.hmacSha256(stringToU8a('secret'), stringToU8a('some message')));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7', 'ERROR: hmacSha256 does not match');
|
||||
}
|
||||
|
||||
function hmacSha512 (wasm) {
|
||||
const hash = u8aToHex(wasm.hmacSha512(stringToU8a('secret'), stringToU8a('some message')));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841', 'ERROR: hmacSha512 does not match');
|
||||
}
|
||||
|
||||
function keccak256 (wasm) {
|
||||
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
|
||||
|
||||
@@ -19,6 +35,14 @@ function keccak256 (wasm) {
|
||||
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
|
||||
}
|
||||
|
||||
function keccak512 (wasm) {
|
||||
const hash = u8aToHex(wasm.keccak512(stringToU8a('test')));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e', 'ERROR: keccak512 does not match');
|
||||
}
|
||||
|
||||
function pbkdf2Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
|
||||
|
||||
@@ -35,6 +59,14 @@ function scryptHash (wasm) {
|
||||
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
|
||||
}
|
||||
|
||||
function sha256Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.sha256(stringToU8a('hello world')));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9', 'ERROR: sha256Hash does not match');
|
||||
}
|
||||
|
||||
function sha512Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
||||
|
||||
@@ -55,9 +87,13 @@ function twoxHash (wasm) {
|
||||
|
||||
module.exports = {
|
||||
blake2bHash,
|
||||
hmacSha256,
|
||||
hmacSha512,
|
||||
keccak256,
|
||||
keccak512,
|
||||
pbkdf2Hash,
|
||||
scryptHash,
|
||||
sha256Hash,
|
||||
sha512Hash,
|
||||
twoxHash
|
||||
};
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const wasm = require('../../build/index.cjs');
|
||||
const bip39 = require('./bip39.cjs');
|
||||
const ed25519 = require('./ed25519.cjs');
|
||||
const hashing = require('./hashing.cjs');
|
||||
const secp256k1 = require('./secp256k1.cjs');
|
||||
const sr25519 = require('./sr25519.cjs');
|
||||
const vrf = require('./vrf.cjs');
|
||||
|
||||
const tests = {
|
||||
...bip39,
|
||||
// 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,
|
||||
...hashing,
|
||||
...sr25519,
|
||||
...vrf
|
||||
...vrf,
|
||||
...bip39,
|
||||
...hashing
|
||||
};
|
||||
|
||||
function beforeAll () {
|
||||
return wasm.waitReady();
|
||||
}
|
||||
|
||||
function runAll () {
|
||||
function runAll (name) {
|
||||
const failed = [];
|
||||
let count = 0;
|
||||
|
||||
@@ -36,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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const { assert, hexToU8a, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
function secp256k1Compress (wasm) {
|
||||
const pubkey = '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af';
|
||||
const result = u8aToHex(wasm.secp256k1Compress(hexToU8a(pubkey)));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
assert(result === '0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077', 'ERROR: secp256k1Compress does not match');
|
||||
}
|
||||
|
||||
function secp256k1Expand (wasm) {
|
||||
const pubkey = '0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077';
|
||||
const result = u8aToHex(wasm.secp256k1Expand(hexToU8a(pubkey)));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
assert(result === '0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af', 'ERROR: secp256k1Expand does not match');
|
||||
}
|
||||
|
||||
function secp256k1FromSeed1 (wasm) {
|
||||
const seckey = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
|
||||
const result = u8aToHex(wasm.secp256k1FromSeed(hexToU8a(seckey)));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
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';
|
||||
const result = u8aToHex(wasm.secp256k1Recover(hexToU8a(msg), hexToU8a(sig), 0));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
assert(result === '0x028d13da15a02f3a70677339d51b14177ee9b49657662b35e56a9d9dee17db1d30', 'ERROR: secp256k1Recover does not match');
|
||||
}
|
||||
|
||||
function secp256k1Sign (wasm) {
|
||||
const sec = '0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae';
|
||||
const msg = '0x68c731589a583d08b70861683b59ce3dd56284cb2f0da5b6cd83e6641dac3aab';
|
||||
const result = u8aToHex(wasm.secp256k1Sign(hexToU8a(msg), hexToU8a(sec)));
|
||||
|
||||
console.log('\tRES', result);
|
||||
|
||||
assert(result === '0xdf92f73d9f060cefacf187b5414491cb992998ace017fa48839b5cda3e264ba83b105adec9e9872647a7d8bb28855b45e22805aea3d097953cbb1391f671d13e01', 'ERROR: secp256k1Sign does not match');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
secp256k1Compress,
|
||||
secp256k1Expand,
|
||||
secp256k1FromSeed1,
|
||||
secp256k1FromSeed2,
|
||||
secp256k1Recover,
|
||||
secp256k1Sign
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// 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');
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
// override-require in jest.config.js
|
||||
|
||||
import { beforeAll, tests, wasm } from './all/index.cjs';
|
||||
|
||||
describe('wasm-crypto', () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
require('./alias-imports.cjs');
|
||||
|
||||
const { runUnassisted } = require('./all/index.cjs');
|
||||
|
||||
runUnassisted();
|
||||
runUnassisted('WASM');
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { createBundle } from '@polkadot/dev/config/rollup';
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -7,4 +7,4 @@ set -e
|
||||
|
||||
# cleanup old
|
||||
echo "*** Cleaning old builds"
|
||||
rm -rf packages/*/build packages/bytes
|
||||
rm -rf build packages/*/build packages/bytes
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const fflate = require('fflate/node');
|
||||
@@ -12,7 +12,7 @@ const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
||||
|
||||
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
||||
|
||||
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `// Copyright 2019-2021 @polkadot/${W_NAME} authors & contributors
|
||||
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `// Copyright 2019-2022 @polkadot/${W_NAME} authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Generated as part of the build, do not edit
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||
# Copyright 2019-2022 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
RUST_VER=nightly-2020-10-25
|
||||
RUST_VER=nightly-2021-12-02
|
||||
# RUST_VER=stable
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "@polkadot/dev/config/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"paths": {
|
||||
"@polkadot/wasm-crypto-asmjs/packageInfo": ["wasm-crypto-asmjs/src/packageInfo"],
|
||||
"@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"],
|
||||
"@polkadot/wasm-crypto": ["wasm-crypto/src"]
|
||||
},
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./packages/wasm-crypto/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-crypto-asmjs/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./packages",
|
||||
"composite": false
|
||||
},
|
||||
"include": [
|
||||
"packages/**/src/**/*",
|
||||
"packages/**/test/**/*",
|
||||
"scripts/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**/*"
|
||||
]
|
||||
}
|
||||
+10
-19
@@ -1,22 +1,13 @@
|
||||
{
|
||||
"extends": "@polkadot/dev/config/tsconfig.json",
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"**/build/**/*"
|
||||
],
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@polkadot/wasm-crypto-asmjs/packageInfo": [ "packages/wasm-crypto-asmjs/src/packageInfo" ],
|
||||
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
|
||||
"@polkadot/wasm-crypto-wasm/packageInfo": [ "packages/wasm-crypto-wasm/src/packageInfo" ],
|
||||
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
|
||||
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||
},
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@polkadot/ts",
|
||||
"./node_modules/@types"
|
||||
]
|
||||
}
|
||||
"baseUrl": "./packages",
|
||||
"composite": false
|
||||
},
|
||||
"include": [
|
||||
"packages/**/src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**/*"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user