Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7898d95844 | ||
|
|
2c4f8bbe4e | ||
|
|
ef1caeb94e | ||
|
|
8837ec9386 | ||
|
|
653aa56f12 | ||
|
|
9ece350f21 | ||
|
|
bd6435053d | ||
|
|
9c5c22ddbe | ||
|
|
77622d8408 | ||
|
|
3e1249ca2c | ||
|
|
9c09490f62 | ||
|
|
c46c08d296 | ||
|
|
f4d4bb90f0 | ||
|
|
45b51adfc7 | ||
|
|
aa084bf11b | ||
|
|
0a1aec2acf | ||
|
|
463626d75c | ||
|
|
dc4203fe7c | ||
|
|
0fa386b93a | ||
|
|
5c563bb95f | ||
|
|
4a10b7b066 | ||
|
|
c31c8537be | ||
|
|
7aebad00eb | ||
|
|
7af6734e26 | ||
|
|
edcdd48830 | ||
|
|
ad4ac2e101 | ||
|
|
2a44e076c2 | ||
|
|
9ed88fe53a | ||
|
|
856bf68abd | ||
|
|
b36ad6fdf2 | ||
|
|
78d56fa82e | ||
|
|
294d30cb3b | ||
|
|
3185b23a97 | ||
|
|
a8df6878b8 | ||
|
|
148b1c1f98 | ||
|
|
355b225428 | ||
|
|
7e0cfe73f1 | ||
|
|
618d5ad6d6 | ||
|
|
23df722466 | ||
|
|
d3a90d7362 | ||
|
|
2b8ee5f655 | ||
|
|
1db2f57b8c | ||
|
|
8d93a4b665 | ||
|
|
2fca9b83c1 | ||
|
|
5be84df651 | ||
|
|
11997092c3 | ||
|
|
15788efd34 | ||
|
|
cbb7e6f9e8 | ||
|
|
141f5e6488 | ||
|
|
1c54650396 | ||
|
|
ae748a828d | ||
|
|
9d840d89e6 | ||
|
|
c03750d97c | ||
|
|
df579b6ab0 | ||
|
|
5455b1bc8c | ||
|
|
4095777139 | ||
|
|
be0a41e4b0 | ||
|
|
bf9aceb4a9 | ||
|
|
c6135e28d4 | ||
|
|
9f199fee77 | ||
|
|
d937dda6ba | ||
|
|
5bdc33d0cd | ||
|
|
511986b7cf | ||
|
|
1d7addf6ef | ||
|
|
cc63edbd5c | ||
|
|
f8efe32b43 | ||
|
|
bb748c0225 | ||
|
|
9e9535cc2b | ||
|
|
e2d0726608 | ||
|
|
5209c934a6 | ||
|
|
da946b18ce | ||
|
|
2ac68bdb18 | ||
|
|
83762d9997 | ||
|
|
311263ad83 | ||
|
|
b3ae90f330 | ||
|
|
327f35143d | ||
|
|
35b2bb2d13 | ||
|
|
08b72cc782 | ||
|
|
f5c439cee4 | ||
|
|
0eb440d93a | ||
|
|
5860c204e1 | ||
|
|
597ded7e79 | ||
|
|
1c5a9e8152 | ||
|
|
6bdeda218c | ||
|
|
e8cfce5ede | ||
|
|
2276c06826 | ||
|
|
bf1307fda2 | ||
|
|
696d369a29 | ||
|
|
d419f2e919 | ||
|
|
f966423808 | ||
|
|
15a1020321 | ||
|
|
29ab5f2e50 | ||
|
|
4ce48c701f | ||
|
|
52c5a506ac | ||
|
|
ecf02ec26d | ||
|
|
6611c3d136 | ||
|
|
e5a4d644ab | ||
|
|
90853435d8 | ||
|
|
5211b58995 | ||
|
|
a68aaeceba | ||
|
|
cfddf2bdb6 | ||
|
|
597c1bf0d0 | ||
|
|
25ecaf51bf | ||
|
|
445585309b |
@@ -1,5 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = require('./babel.config.js');
|
|
||||||
@@ -2,3 +2,4 @@ exclude_patterns:
|
|||||||
- "**/*.spec.js"
|
- "**/*.spec.js"
|
||||||
- "**/*.spec.ts"
|
- "**/*.spec.ts"
|
||||||
- "docs/**/*.js"
|
- "docs/**/*.js"
|
||||||
|
- "**/test/**/*.js"
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
.eslintrc.js
|
|
||||||
.github/**
|
|
||||||
.vscode/**
|
|
||||||
.yarn/**
|
|
||||||
**/binaryen/*
|
|
||||||
**/build/*
|
|
||||||
**/coverage/*
|
|
||||||
**/node_modules/*
|
|
||||||
+14
-3
@@ -1,11 +1,22 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const base = require('@polkadot/dev/config/eslint');
|
const base = require('@polkadot/dev/config/eslint.cjs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...base,
|
...base,
|
||||||
|
ignorePatterns: [
|
||||||
|
'.eslintrc.js',
|
||||||
|
'.github/**',
|
||||||
|
'.vscode/**',
|
||||||
|
'.yarn/**',
|
||||||
|
'**/binaryen/*',
|
||||||
|
'**/build/*',
|
||||||
|
'**/coverage/*',
|
||||||
|
'**/node_modules/*',
|
||||||
|
'**/pkg/*',
|
||||||
|
'**/target/*'
|
||||||
|
],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
...base.parserOptions,
|
...base.parserOptions,
|
||||||
project: [
|
project: [
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ jobs:
|
|||||||
name: ${{ matrix.step }}
|
name: ${{ matrix.step }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: ${{ matrix.step }}
|
- name: ${{ matrix.step }}
|
||||||
run: |
|
run: |
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
|
./scripts/install-build-deps.sh
|
||||||
yarn ${{ matrix.step }}
|
yarn ${{ matrix.step }}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/wasm'"
|
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/wasm'"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_PAT }}
|
token: ${{ secrets.GH_PAT }}
|
||||||
- name: build
|
- name: build
|
||||||
@@ -24,6 +24,7 @@ jobs:
|
|||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
|
./scripts/install-build-deps.sh
|
||||||
yarn ${{ matrix.step }}
|
yarn ${{ matrix.step }}
|
||||||
|
|
||||||
dummy:
|
dummy:
|
||||||
|
|||||||
+4
-1
@@ -1,12 +1,15 @@
|
|||||||
binaryen*
|
binaryen/
|
||||||
|
bindgen/
|
||||||
build/
|
build/
|
||||||
build-docs/
|
build-docs/
|
||||||
|
bytes/
|
||||||
coverage/
|
coverage/
|
||||||
docs/.vuepress/dist/
|
docs/.vuepress/dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
pkg/
|
pkg/
|
||||||
target/
|
target/
|
||||||
tmp/
|
tmp/
|
||||||
|
wabt/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
|
|||||||
Vendored
-11
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"editor.tabSize": 2,
|
|
||||||
"files.eol": "\n",
|
|
||||||
"npm.packageManager": "yarn",
|
|
||||||
"eslint.enable": true,
|
|
||||||
"eslint.validate": [
|
|
||||||
"javascript",
|
|
||||||
"typescript",
|
|
||||||
"typescriptreact"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+77
File diff suppressed because one or more lines are too long
Vendored
-86
File diff suppressed because one or more lines are too long
+55
File diff suppressed because one or more lines are too long
+4
-2
@@ -5,7 +5,9 @@ enableProgressBars: false
|
|||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
spec: "@yarnpkg/plugin-interactive-tools"
|
||||||
|
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||||
|
spec: "@yarnpkg/plugin-version"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-2.1.1.cjs
|
yarnPath: .yarn/releases/yarn-2.4.0.cjs
|
||||||
|
|||||||
+84
-1
@@ -1,96 +1,179 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 3.0.1 Dec 13, 2020
|
||||||
|
|
||||||
|
**Important** This assumes `@polkadot/util` 5+ peerDependencies
|
||||||
|
**Important** While this package contains no external interface changes, it doe now compile and ship both cjs and esm modules. This means that modern bundlers will have more information for tree-shaking available. Additionally when using Node with `.mjs` extensions, the esm version imports will be used on recent Node versions. Adding an export map, as here, may have some impacts so a major semver bump is advised. There may be (small) dragons hiding in the dark corners...
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Build and expose both cjs and esm via exports map
|
||||||
|
- Split wasm and asmjs files into the `@polkadot/wasm-crypto-{wasm,asmjs}` packages
|
||||||
|
- Add fflate WASM compression, with 180K raw savings (37K over-the-wire)
|
||||||
|
- Convert the package to full TypeScript sources
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.1 Nov 8, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Rework generation of WASM interfaces (proper cross-platform JS support)
|
||||||
|
- Remove explicit `crypto` dependency, this is now applied by `@polkadot/x-randomvalues`
|
||||||
|
- Build via xargo for panic abort, an overall small sizes without stack (Pinned nightly)
|
||||||
|
- Move Rust library sources in to `rs/` subfolder
|
||||||
|
|
||||||
|
|
||||||
## 1.4.1 Aug 27, 2020
|
## 1.4.1 Aug 27, 2020
|
||||||
|
|
||||||
- Rea-add the BTC/ETH compatible `bip39ToSeed` dropped in the previous version (ETH-compatible pairs)
|
Changes:
|
||||||
|
|
||||||
|
- Re-add the BTC/ETH compatible `bip39ToSeed` dropped in the previous version (ETH-compatible pairs)
|
||||||
|
|
||||||
|
|
||||||
## 1.3.1 Aug 9, 2020
|
## 1.3.1 Aug 9, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add `scrypt` function for KDF generation
|
- Add `scrypt` function for KDF generation
|
||||||
- Remove `bip39ToSeed`, we only use the `bip39ToMiniSecret` variant in Substrate
|
- Remove `bip39ToSeed`, we only use the `bip39ToMiniSecret` variant in Substrate
|
||||||
- Update ed25519-dalek to 1.0.0-pre.4
|
- Update ed25519-dalek to 1.0.0-pre.4
|
||||||
- Rework generation based on latest wasm-pack generator
|
- Rework generation based on latest wasm-pack generator
|
||||||
|
|
||||||
|
|
||||||
## 1.2.1 Feb 29, 2020
|
## 1.2.1 Feb 29, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
|
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
|
||||||
- Unpin nightly from nightly-2020-02-17 version
|
- Unpin nightly from nightly-2020-02-17 version
|
||||||
- Swap to yarn 2 and add support for use by yarn 2 projects
|
- Swap to yarn 2 and add support for use by yarn 2 projects
|
||||||
|
|
||||||
|
|
||||||
## 1.1.1 Feb 24, 2020
|
## 1.1.1 Feb 24, 2020
|
||||||
|
|
||||||
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
|
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
|
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
|
||||||
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
|
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
|
||||||
|
|
||||||
|
|
||||||
## 1.0.1 Feb 15, 2020
|
## 1.0.1 Feb 15, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
||||||
|
|
||||||
|
|
||||||
## 0.20.1 Jan 30, 2020
|
## 0.20.1 Jan 30, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
||||||
|
|
||||||
|
|
||||||
## 0.14.1 Sep 09, 2019
|
## 0.14.1 Sep 09, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
||||||
|
|
||||||
|
|
||||||
## 0.13.1 Jul 20, 2019
|
## 0.13.1 Jul 20, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
|
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
|
||||||
|
|
||||||
|
|
||||||
## 0.12.1 Jul 17, 2019
|
## 0.12.1 Jul 17, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
|
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
|
||||||
- Security dependency bumps
|
- Security dependency bumps
|
||||||
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
||||||
|
|
||||||
|
|
||||||
## 0.11.1 May 31, 2019
|
## 0.11.1 May 31, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Security dependency bumps
|
- Security dependency bumps
|
||||||
|
|
||||||
|
|
||||||
## 0.10.1 May 09, 2019
|
## 0.10.1 May 09, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
||||||
- Added known subkey signature test (Rust & JS)
|
- Added known subkey signature test (Rust & JS)
|
||||||
|
|
||||||
|
|
||||||
## 0.9.1 Apr 29, 2019
|
## 0.9.1 Apr 29, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Dependency bumps
|
- Dependency bumps
|
||||||
|
|
||||||
|
|
||||||
## 0.8.1 Mar 31, 2019
|
## 0.8.1 Mar 31, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
||||||
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
||||||
- Improve error messaging, instead of `__wasm_malloc of null`
|
- Improve error messaging, instead of `__wasm_malloc of null`
|
||||||
|
|
||||||
|
|
||||||
## 0.7.1 Mar 30, 2019
|
## 0.7.1 Mar 30, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
||||||
|
|
||||||
|
|
||||||
## 0.6.1 Mar 27, 2019
|
## 0.6.1 Mar 27, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
||||||
|
|
||||||
|
|
||||||
## 0.5.1 Mar 23, 2019
|
## 0.5.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add password argument to bip39ToSeed
|
- Add password argument to bip39ToSeed
|
||||||
|
|
||||||
|
|
||||||
## 0.4.1 Mar 23, 2019
|
## 0.4.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add bip39ToSeed
|
- Add bip39ToSeed
|
||||||
|
|
||||||
|
|
||||||
## 0.3.1 Mar 23, 2019
|
## 0.3.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add wasm-dalek-ed25519 for all used crypto there
|
- Add wasm-dalek-ed25519 for all used crypto there
|
||||||
- Add keccak256
|
- Add keccak256
|
||||||
- Try secp256k1 (bloating code, not used atm)
|
- Try secp256k1 (bloating code, not used atm)
|
||||||
|
|
||||||
|
|
||||||
## 0.2.1 Mar 20, 2019
|
## 0.2.1 Mar 20, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add basic crypto functions, creation of wasm-crypto package
|
- Add basic crypto functions, creation of wasm-crypto package
|
||||||
- blake2, bip39, sha2, xxhash
|
- blake2, bip39, sha2, xxhash
|
||||||
|
|
||||||
|
|
||||||
## 0.1.1 Mar 18, 2019
|
## 0.1.1 Mar 18, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = require('@polkadot/dev/config/babel');
|
module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs');
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
|
||||||
|
<meta http-equiv="refresh" content="0;URL='https://polkadot.js.org/docs/'" />
|
||||||
|
<title>Redirecting to https://polkadot.js.org/docs/</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Redirecting to <a href="https://polkadot.js.org/docs/">https://polkadot.js.org/docs/</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
|
||||||
|
<meta http-equiv="refresh" content="0;URL='https://polkadot.js.org/docs/'" />
|
||||||
|
<title>Redirecting to https://polkadot.js.org/docs/</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Redirecting to <a href="https://polkadot.js.org/docs/">https://polkadot.js.org/docs/</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+10
-6
@@ -1,15 +1,19 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const config = require('@polkadot/dev/config/jest');
|
const config = require('@polkadot/dev/config/jest.cjs');
|
||||||
|
|
||||||
module.exports = Object.assign({}, config, {
|
module.exports = Object.assign({}, config, {
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'@polkadot/wasm-(schnorrkel)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
|
'@polkadot/wasm-crypto-asmjs(.*)$': '<rootDir>/packages/wasm-crypto-asmjs/build/$1',
|
||||||
|
'@polkadot/wasm-crypto-wasm(.*)$': '<rootDir>/packages/wasm-crypto-wasm/build/$1',
|
||||||
|
// eslint-disable-next-line sort-keys
|
||||||
|
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
|
||||||
},
|
},
|
||||||
modulePathIgnorePatterns: [
|
modulePathIgnorePatterns: [
|
||||||
'<rootDir>/packages/wasm-schnorrkel/build'
|
'<rootDir>/packages/wasm-crypto-asmjs/build',
|
||||||
|
'<rootDir>/packages/wasm-crypto-wasm/build',
|
||||||
|
'<rootDir>/packages/wasm-crypto/build'
|
||||||
],
|
],
|
||||||
resolver: './jest.resolver.js'
|
resolver: '@polkadot/dev/config/jest-resolver.cjs'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = function resolver (file, config) {
|
|
||||||
return file.includes('package.json')
|
|
||||||
? path.join(config.basedir.replace('/src', '/'), file)
|
|
||||||
: config.defaultResolver(file, config);
|
|
||||||
};
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"npmClient": "yarn",
|
|
||||||
"useWorkspaces": true,
|
|
||||||
"command": {
|
|
||||||
"publish": {
|
|
||||||
"allowBranch": "master"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
],
|
|
||||||
"version": "1.4.1"
|
|
||||||
}
|
|
||||||
+12
-7
@@ -7,19 +7,24 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"babel-core": "^7.0.0-bridge.0"
|
"typescript": "^4.1.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "NIGHTLY= ./scripts/build.sh",
|
"build": "yarn build:wasm",
|
||||||
"build:release": "NIGHTLY= ./scripts/build-release.sh",
|
"build:release": "polkadot-ci-ghact-build",
|
||||||
|
"build:wasm": "./scripts/build.sh",
|
||||||
"lint": "polkadot-dev-run-lint",
|
"lint": "polkadot-dev-run-lint",
|
||||||
"clean": "./scripts/clean.sh",
|
"clean": "./scripts/clean.sh",
|
||||||
"postinstall": "polkadot-dev-yarn-only",
|
"postinstall": "polkadot-dev-yarn-only",
|
||||||
"test": "./scripts/test-rust.sh"
|
"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.js && node ./test/asm.js",
|
||||||
|
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.11.4",
|
"@babel/core": "^7.12.10",
|
||||||
"@polkadot/dev": "^0.55.43"
|
"@polkadot/dev": "^0.61.1"
|
||||||
},
|
},
|
||||||
"version": "1.4.1"
|
"version": "3.0.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "@polkadot/wasm-crypto-asmjs",
|
||||||
|
"version": "3.0.1",
|
||||||
|
"description": "Asm.js content for wasm-crypto",
|
||||||
|
"browser": "empty.js",
|
||||||
|
"main": "empty.js",
|
||||||
|
"react-native": "data.js",
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"maintainers": [],
|
||||||
|
"contributors": [],
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.12.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const asmJsInit = null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const asmJsInit = null;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "@polkadot/wasm-crypto-wasm",
|
||||||
|
"version": "3.0.1",
|
||||||
|
"description": "Wasm content for wasm-crypto",
|
||||||
|
"browser": "data.js",
|
||||||
|
"main": "data.js",
|
||||||
|
"react-native": "data.js",
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"maintainers": [],
|
||||||
|
"contributors": [],
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.12.5",
|
||||||
|
"fflate": "^0.4.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const buffer = Buffer.from([]);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { unzlibSync } from 'fflate';
|
||||||
|
|
||||||
|
import { buffer } from './buffer';
|
||||||
|
|
||||||
|
export const wasmBytes = unzlibSync(buffer);
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const wasmBytes = null;
|
||||||
Generated
+242
-255
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
||||||
description = "WASM bindings to Rust crypto libaries."
|
description = "WASM bindings to Rust crypto libraries."
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
@@ -12,17 +12,16 @@ repository = "https://github.com/polkadot-js/wasm/"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
backtrace = "0.3.38"
|
|
||||||
blake2-rfc = "0.2.18"
|
blake2-rfc = "0.2.18"
|
||||||
byteorder = "1.3.1"
|
byteorder = "1.3.1"
|
||||||
ed25519-dalek = { version = "1.0.0-pre.4", features = ["nightly"] }
|
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||||
hmac = "0.7.0"
|
hmac = "0.7.0"
|
||||||
# libsecp256k1 = "0.2.2"
|
# libsecp256k1 = "0.2.2"
|
||||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||||
schnorrkel = { version = "0.9.1", features = ["nightly", "preaudit_deprecated", "u64_backend"] }
|
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
|
||||||
scrypt = { version = "0.2", default-features = false }
|
scrypt = { version = "0.2", default-features = false }
|
||||||
sha2 = "0.8.1"
|
sha2 = "0.8.1"
|
||||||
tiny-bip39 = { version = "0.7", default-features = false }
|
tiny-bip39 = { version = "0.7", default-features = false }
|
||||||
@@ -37,9 +36,10 @@ rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
|||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
debug = false
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
lto = true
|
lto = true
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
rpath = false
|
||||||
[package.metadata.wasm-pack.profile.release]
|
|
||||||
wasm-opt = false
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Use it -
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const { u8aToHex } = require('@polkadot/util');
|
const { u8aToHex } = require('@polkadot/util');
|
||||||
const { bio39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
const { bip39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
// first wait until the WASM has been loaded (async init)
|
// first wait until the WASM has been loaded (async init)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[dependencies]
|
||||||
|
std = { default-features = false, features = ["panic_immediate_abort"] }
|
||||||
@@ -1,30 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/wasm-crypto",
|
"name": "@polkadot/wasm-crypto",
|
||||||
"version": "1.4.1",
|
"version": "3.0.1",
|
||||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
"files": [
|
|
||||||
"crypto-polyfill.js",
|
|
||||||
"exports.js",
|
|
||||||
"index.d.ts",
|
|
||||||
"index.js",
|
|
||||||
"wasm.d.ts",
|
|
||||||
"wasm.js",
|
|
||||||
"wasm_asm.js",
|
|
||||||
"wasm_asm_stub.js",
|
|
||||||
"wasm_promise.js",
|
|
||||||
"wasm_wasm.js"
|
|
||||||
],
|
|
||||||
"react-native": {
|
|
||||||
"./wasm_asm_stub.js": "./wasm_asm.js"
|
|
||||||
},
|
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.12.5",
|
||||||
|
"@polkadot/wasm-crypto-asmjs": "^3.0.1",
|
||||||
|
"@polkadot/wasm-crypto-wasm": "^3.0.1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/dev": "^0.55.43",
|
"@polkadot/dev": "^0.61.1",
|
||||||
"@polkadot/util": "^3.3.1",
|
"@polkadot/util": "^4.2.2-15",
|
||||||
|
"@polkadot/x-randomvalues": "^4.2.2-15",
|
||||||
"override-require": "^1.1.1"
|
"override-require": "^1.1.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*"
|
"@polkadot/util": "*",
|
||||||
|
"@polkadot/x-randomvalues": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// Copyright 2019-2020 @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 { assert, stringToU8a, u8aToString } from '@polkadot/util';
|
||||||
|
|
||||||
|
let wasm: WasmCryptoInstance | null = null;
|
||||||
|
let cachegetInt32: Int32Array | null = null;
|
||||||
|
let cachegetUint8: Uint8Array | null = null;
|
||||||
|
|
||||||
|
export async function initWasm (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null, wbg: Record<string, WebAssembly.ImportValue>): Promise<void> {
|
||||||
|
try {
|
||||||
|
assert(typeof WebAssembly !== 'undefined' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||||
|
|
||||||
|
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||||
|
|
||||||
|
wasm = source.instance.exports as unknown as WasmCryptoInstance;
|
||||||
|
} catch (error) {
|
||||||
|
// if we have a valid supplied asm.js, return that
|
||||||
|
if (asmFn) {
|
||||||
|
wasm = asmFn(wbg);
|
||||||
|
} else {
|
||||||
|
console.error('FATAL: Unable to initialize @polkadot/wasm-crypto');
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
wasm = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.');
|
||||||
|
|
||||||
|
return fn(wasm)(...params);
|
||||||
|
}) as unknown as F;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWasm (): WasmCryptoInstance {
|
||||||
|
return wasm!;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInt32 (): Int32Array {
|
||||||
|
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm!.memory.buffer) {
|
||||||
|
cachegetInt32 = new Int32Array(wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachegetInt32;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUint8 (): Uint8Array {
|
||||||
|
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm!.memory.buffer) {
|
||||||
|
cachegetUint8 = new Uint8Array(wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachegetUint8;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getU8a (ptr: number, len: number): Uint8Array {
|
||||||
|
return getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getString (ptr: number, len: number): string {
|
||||||
|
return u8aToString(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allocU8a (arg: Uint8Array): [number, number] {
|
||||||
|
const ptr = wasm!.__wbindgen_malloc(arg.length * 1);
|
||||||
|
|
||||||
|
getUint8().set(arg, ptr / 1);
|
||||||
|
|
||||||
|
return [ptr, arg.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allocString (arg: string): [number, number] {
|
||||||
|
return allocU8a(stringToU8a(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resultU8a (): Uint8Array {
|
||||||
|
const r0 = getInt32()[8 / 4 + 0];
|
||||||
|
const r1 = getInt32()[8 / 4 + 1];
|
||||||
|
const ret = getU8a(r0, r1).slice();
|
||||||
|
|
||||||
|
wasm!.__wbindgen_free(r0, r1 * 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resultString (): string {
|
||||||
|
return u8aToString(resultU8a());
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||||
|
|
||||||
|
import { getString, getU8a } from './bridge';
|
||||||
|
|
||||||
|
const DEFAULT_CRYPTO = { getRandomValues };
|
||||||
|
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
|
||||||
|
|
||||||
|
const heap: Array<unknown> = new Array(32).fill(undefined).concat(undefined, null, true, false);
|
||||||
|
let heapNext = heap.length;
|
||||||
|
|
||||||
|
function getObject (idx: number): unknown {
|
||||||
|
return heap[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
function dropObject (idx: number) {
|
||||||
|
if (idx < 36) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
heap[idx] = heapNext;
|
||||||
|
heapNext = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeObject (idx: number): unknown {
|
||||||
|
const ret = getObject(idx);
|
||||||
|
|
||||||
|
dropObject(idx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addObject (obj: unknown): number {
|
||||||
|
if (heapNext === heap.length) {
|
||||||
|
heap.push(heap.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const idx = heapNext;
|
||||||
|
|
||||||
|
heapNext = heap[idx] as number;
|
||||||
|
heap[idx] = obj;
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbindgen_is_undefined (idx: number): boolean {
|
||||||
|
return getObject(idx) === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbg_self_1b7a39e3a92c949c (): number {
|
||||||
|
return addObject(DEFAULT_SELF);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbg_require_604837428532a733 (ptr: number, len: number): never {
|
||||||
|
throw new Error(`Unable to require ${getString(ptr, len)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_crypto_968f1772287e2df0 (_idx: number): number {
|
||||||
|
return addObject(DEFAULT_CRYPTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_getRandomValues_a3d34b4fee3c2869 (_idx: number): number {
|
||||||
|
return addObject(DEFAULT_CRYPTO.getRandomValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_getRandomValues_f5e14ab7ac8e995d (_arg0: number, ptr: number, len: number): void {
|
||||||
|
DEFAULT_CRYPTO.getRandomValues(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_randomFillSync_d5bd2d655fdf256a (_idx: number, _ptr: number, _len: number): never {
|
||||||
|
throw new Error('randomFillsync is not available');
|
||||||
|
|
||||||
|
// getObject(idx).randomFillSync(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbindgen_object_drop_ref (idx: number): void {
|
||||||
|
takeObject(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function abort (): never {
|
||||||
|
throw new Error('abort');
|
||||||
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
// Copyright 2019-2020 @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';
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return resultString();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToEntropy = withWasm((wasm) =>
|
||||||
|
(phrase: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_entropy(8, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToMiniSecret = withWasm((wasm) =>
|
||||||
|
(phrase: string, password: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const [ptr1, len1] = allocString(password);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToSeed = withWasm((wasm) =>
|
||||||
|
(phrase: string, password: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const [ptr1, len1] = allocString(password);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39Validate = withWasm((wasm) =>
|
||||||
|
(phrase: string): boolean => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const ret = wasm.ext_bip39_validate(ptr0, len0);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ed25519KeypairFromSeed = withWasm((wasm) =>
|
||||||
|
(seed: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(seed);
|
||||||
|
|
||||||
|
wasm.ext_ed_from_seed(8, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
|
||||||
|
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pair);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
|
||||||
|
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pair);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DerivePublicSoft = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519KeypairFromSeed = withWasm((wasm) =>
|
||||||
|
(seed: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(seed);
|
||||||
|
|
||||||
|
wasm.ext_sr_from_seed(8, ptr0, len0);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const blake2b = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
const [ptr1, len1] = allocU8a(key);
|
||||||
|
|
||||||
|
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const keccak256 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_keccak256(8, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const pbkdf2 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
const [ptr1, len1] = allocU8a(salt);
|
||||||
|
|
||||||
|
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sha512 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_sha512(8, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const twox = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, rounds: number) => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_twox(8, ptr0, len0, rounds);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export function isReady (): boolean {
|
||||||
|
return !!getWasm();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function waitReady (): Promise<boolean> {
|
||||||
|
return wasmPromise.then(() => !!getWasm());
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const crypto = require('crypto');
|
|
||||||
|
|
||||||
if (!global.crypto) {
|
|
||||||
global.crypto = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.crypto.getRandomValues) {
|
|
||||||
global.crypto.getRandomValues = function (arr) {
|
|
||||||
const buffer = crypto.randomBytes(arr.length);
|
|
||||||
|
|
||||||
return buffer.reduce((arr, value, index) => {
|
|
||||||
arr[index] = value;
|
|
||||||
|
|
||||||
return arr;
|
|
||||||
}, arr);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
/* eslint-disable sort-keys */
|
|
||||||
|
|
||||||
const { assert } = require('@polkadot/util');
|
|
||||||
|
|
||||||
const INIT_ERRROR = '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.';
|
|
||||||
|
|
||||||
module.exports = function (stubbed) {
|
|
||||||
const wrapReady = (fn) =>
|
|
||||||
(...params) => {
|
|
||||||
assert(stubbed.isReady(), INIT_ERRROR);
|
|
||||||
|
|
||||||
return fn(...params);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
bip39Generate: wrapReady(stubbed.ext_bip39_generate),
|
|
||||||
bip39ToEntropy: wrapReady(stubbed.ext_bip39_to_entropy),
|
|
||||||
bip39ToMiniSecret: wrapReady(stubbed.ext_bip39_to_mini_secret),
|
|
||||||
bip39ToSeed: wrapReady(stubbed.ext_bip39_to_seed),
|
|
||||||
bip39Validate: wrapReady(stubbed.ext_bip39_validate),
|
|
||||||
|
|
||||||
ed25519KeypairFromSeed: wrapReady(stubbed.ext_ed_from_seed),
|
|
||||||
ed25519Sign: wrapReady(stubbed.ext_ed_sign),
|
|
||||||
ed25519Verify: wrapReady(stubbed.ext_ed_verify),
|
|
||||||
|
|
||||||
sr25519DeriveKeypairHard: wrapReady(stubbed.ext_sr_derive_keypair_hard),
|
|
||||||
sr25519DeriveKeypairSoft: wrapReady(stubbed.ext_sr_derive_keypair_soft),
|
|
||||||
sr25519DerivePublicSoft: wrapReady(stubbed.ext_sr_derive_public_soft),
|
|
||||||
sr25519KeypairFromSeed: wrapReady(stubbed.ext_sr_from_seed),
|
|
||||||
sr25519Sign: wrapReady(stubbed.ext_sr_sign),
|
|
||||||
sr25519Verify: wrapReady(stubbed.ext_sr_verify),
|
|
||||||
|
|
||||||
blake2b: wrapReady(stubbed.ext_blake2b),
|
|
||||||
keccak256: wrapReady(stubbed.ext_keccak256),
|
|
||||||
pbkdf2: wrapReady(stubbed.ext_pbkdf2),
|
|
||||||
scrypt: wrapReady(stubbed.ext_scrypt),
|
|
||||||
|
|
||||||
// secp256k1IsRecoverable: wrapReady(stubbed.ext_secp256k1_is_recoverable);
|
|
||||||
// secp256k1Recover: wrapReady(stubbed.ext_secp256k1_recover);
|
|
||||||
|
|
||||||
sha512: wrapReady(stubbed.ext_sha512),
|
|
||||||
twox: wrapReady(stubbed.ext_twox),
|
|
||||||
|
|
||||||
isReady: stubbed.isReady,
|
|
||||||
waitReady: stubbed.waitReady
|
|
||||||
};
|
|
||||||
};
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string;
|
|
||||||
export function bip39ToEntropy (phrase: string): Uint8Array;
|
|
||||||
export function bip39ToMiniSecret (phrase: string, password: string): Uint8Array;
|
|
||||||
export function bip39ToSeed (phrase: string, password: string): Uint8Array;
|
|
||||||
export function bip39Validate (phrase: string): boolean;
|
|
||||||
|
|
||||||
export function ed25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
|
|
||||||
export function ed25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
|
|
||||||
export function ed25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
||||||
|
|
||||||
export function sr25519DeriveKeypairHard (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519DeriveKeypairSoft (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519DerivePublicSoft (publicKey: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
||||||
|
|
||||||
export function blake2b (data: Uint8Array, key: Uint8Array, byteSize: number): Uint8Array;
|
|
||||||
export function keccak256 (data: Uint8Array): Uint8Array;
|
|
||||||
export function pbkdf2 (data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array;
|
|
||||||
export function scrypt (password: Uint8Array, salt: Uint8Array, log2N: number, r: number, p: number): Uint8Array;
|
|
||||||
// export function secp256k1IsRecoverable (message: Uint8Array, signature: Uint8Array): number;
|
|
||||||
// export function secp256k1Recover (message: Uint8Array, signature: Uint8Array): Uint8Array;
|
|
||||||
export function sha512 (data: Uint8Array): Uint8Array;
|
|
||||||
export function twox (data: Uint8Array, rounds: number): Uint8Array;
|
|
||||||
|
|
||||||
export function isReady (): boolean;
|
|
||||||
export function waitReady (): Promise<boolean>;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const stubbed = require('./wasm');
|
|
||||||
|
|
||||||
module.exports = require('./exports')(stubbed);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = {};
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const pkg = require('./package.json');
|
|
||||||
const asm = require('./wasm_asm_stub');
|
|
||||||
const bytes = require('./wasm_wasm');
|
|
||||||
const imports = require('./wasm');
|
|
||||||
|
|
||||||
module.exports = async function createExportPromise () {
|
|
||||||
try {
|
|
||||||
const { instance } = await WebAssembly.instantiate(bytes, { __wbindgen_placeholder__: imports });
|
|
||||||
|
|
||||||
return instance.exports;
|
|
||||||
} catch (error) {
|
|
||||||
// if we have a valid supplied asm.js, return that
|
|
||||||
if (asm && asm.ext_blake2b) {
|
|
||||||
return asm;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.error(`ERROR: Unable to initialize ${pkg.name} ${pkg.version}`);
|
|
||||||
console.error(error);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
// Use `wee_alloc` as the global allocator.
|
// Use `wee_alloc` as the global allocator.
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
|
#[path = "rs/bip39.rs"]
|
||||||
pub mod bip39;
|
pub mod bip39;
|
||||||
|
|
||||||
|
#[path = "rs/ed25519.rs"]
|
||||||
pub mod ed25519;
|
pub mod ed25519;
|
||||||
|
|
||||||
|
#[path = "rs/hashing.rs"]
|
||||||
pub mod hashing;
|
pub mod hashing;
|
||||||
|
|
||||||
|
#[path = "rs/sr25519.rs"]
|
||||||
pub mod sr25519;
|
pub mod sr25519;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||||
use hmac::Hmac;
|
use hmac::Hmac;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
|
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use blake2_rfc::blake2b::blake2b;
|
use blake2_rfc::blake2b::blake2b;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
@@ -152,7 +151,7 @@ pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> V
|
|||||||
///
|
///
|
||||||
/// * data: Arbitrary data to be hashed
|
/// * data: Arbitrary data to be hashed
|
||||||
///
|
///
|
||||||
/// Returns a vecor with the hash result
|
/// Returns a vector with the hash result
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
||||||
let mut hasher = Sha512::new();
|
let mut hasher = Sha512::new();
|
||||||
@@ -169,7 +168,7 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
|||||||
/// * data: Arbitrary data to be hashed
|
/// * data: Arbitrary data to be hashed
|
||||||
/// * rounds: Number of 8-byte rounds to add to the output
|
/// * rounds: Number of 8-byte rounds to add to the output
|
||||||
///
|
///
|
||||||
/// Returns a vecor with the hash result
|
/// Returns a vector with the hash result
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
@@ -187,7 +186,7 @@ pub mod tests {
|
|||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// // Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign.
|
// // Constructs the message that Ethereum RPCs `personal_sign` and `eth_sign` would sign.
|
||||||
// fn ethereum_signable_message(data: &[u8]) -> Vec<u8> {
|
// fn ethereum_signable_message(data: &[u8]) -> Vec<u8> {
|
||||||
// let prefix = b"Pay DOTs to the Polkadot account:";
|
// let prefix = b"Pay DOTs to the Polkadot account:";
|
||||||
// let mut l = prefix.len() + data.len();
|
// let mut l = prefix.len() + data.len();
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
|
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||||
|
//
|
||||||
// Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/
|
// Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/
|
||||||
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
|
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
|
||||||
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
|
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
|
||||||
|
export interface WasmCryptoInstance {
|
||||||
|
memory: WebAssembly.Memory;
|
||||||
|
|
||||||
|
__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;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
|
||||||
@@ -1,54 +1,63 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
const { assert, u8aToHex } = require('@polkadot/util');
|
const { assert, u8aToHex } = require('@polkadot/util');
|
||||||
|
|
||||||
function bip39_generate (wasm) {
|
function bip39_generate (wasm) {
|
||||||
const RESULT = wasm.bip39Generate(21);
|
const res = wasm.bip39Generate(21);
|
||||||
|
|
||||||
console.log('\tPHR', RESULT);
|
console.log('\tPHR', res);
|
||||||
|
|
||||||
assert(RESULT.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
|
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39_generate_subsequent (wasm) {
|
||||||
|
const val1 = wasm.bip39Generate(24);
|
||||||
|
const val2 = wasm.bip39Generate(24);
|
||||||
|
|
||||||
|
console.log('\tVL1', val1);
|
||||||
|
console.log('\tVL2', val2);
|
||||||
|
|
||||||
|
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bip39_validate (wasm) {
|
function bip39_validate (wasm) {
|
||||||
const RESULT = wasm.bip39Validate(wasm.bip39Generate(12));
|
const res = wasm.bip39Validate(wasm.bip39Generate(12));
|
||||||
|
|
||||||
console.log('\tVAL', RESULT);
|
console.log('\tVAL', res);
|
||||||
|
|
||||||
assert(RESULT, 'ERROR: Invalid bip39 validation');
|
assert(res, 'ERROR: Invalid bip39 validation');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bip39_toEntropy (wasm) {
|
function bip39_toEntropy (wasm) {
|
||||||
const RESULT = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
||||||
|
|
||||||
console.log('\tENT', RESULT);
|
console.log('\tENT', res);
|
||||||
|
|
||||||
assert(RESULT === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bip39_toMiniSecret (wasm) {
|
function bip39_toMiniSecret (wasm) {
|
||||||
const RESULT = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
||||||
|
|
||||||
console.log('\tMIN', RESULT);
|
console.log('\tMIN', res);
|
||||||
|
|
||||||
assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
function bip39_toSeed (wasm) {
|
function bip39_toSeed (wasm) {
|
||||||
const RESULT = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
||||||
|
|
||||||
console.log('\tSEE', RESULT);
|
console.log('\tSEE', res);
|
||||||
|
|
||||||
assert(RESULT === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
assert(res === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bip39_generate,
|
bip39_generate,
|
||||||
|
bip39_generate_subsequent,
|
||||||
bip39_toEntropy,
|
bip39_toEntropy,
|
||||||
bip39_toMiniSecret,
|
bip39_toMiniSecret,
|
||||||
bip39_toSeed,
|
bip39_toSeed,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const wasm = require('../../build/index');
|
const wasm = require('../../build/index');
|
||||||
const bip39 = require('./bip39');
|
const bip39 = require('./bip39');
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
@@ -45,6 +44,17 @@ function sr25519_verifyExisting (wasm) {
|
|||||||
assert(isValid, 'ERROR: Unable to verify signature');
|
assert(isValid, 'ERROR: Unable to verify signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sr25519_sign_deterministic (wasm) {
|
||||||
|
const [, pk, sk] = randomPair(wasm);
|
||||||
|
const sig1 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
|
||||||
|
const sig2 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
|
||||||
|
|
||||||
|
console.log('\tSG1', sig1);
|
||||||
|
console.log('\tSG2', sig2);
|
||||||
|
|
||||||
|
assert(sig1 !== sig2, 'ERROR: Signatures are deterministic');
|
||||||
|
}
|
||||||
|
|
||||||
function sr25519_signAndVerify (wasm) {
|
function sr25519_signAndVerify (wasm) {
|
||||||
const [, pk, sk] = randomPair(wasm);
|
const [, pk, sk] = randomPair(wasm);
|
||||||
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||||
@@ -120,5 +130,6 @@ module.exports = {
|
|||||||
sr25519_devFromSeed,
|
sr25519_devFromSeed,
|
||||||
sr25519_pairFromSeed,
|
sr25519_pairFromSeed,
|
||||||
sr25519_signAndVerify,
|
sr25519_signAndVerify,
|
||||||
|
sr25519_sign_deterministic,
|
||||||
sr25519_verifyExisting
|
sr25519_verifyExisting
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
global.WebAssembly = null;
|
global.WebAssembly = null;
|
||||||
|
|
||||||
require('override-require')(
|
require('override-require')(
|
||||||
(request) => request === './wasm_asm_stub',
|
(request) =>
|
||||||
() => require('../build/wasm_asm')
|
request.endsWith('@polkadot/wasm-crypto-asmjs') ||
|
||||||
|
request.endsWith('@polkadot/wasm-crypto-wasm'),
|
||||||
|
(request) =>
|
||||||
|
request.endsWith('@polkadot/wasm-crypto-asmjs')
|
||||||
|
? require('../../wasm-crypto-asmjs/build/data')
|
||||||
|
: require('../../wasm-crypto-wasm/build/empty')
|
||||||
);
|
);
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
const { runUnassisted } = require('./all');
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
require('../build/crypto-polyfill');
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
|
// override-require in jest.config.js
|
||||||
|
|
||||||
const { beforeAll, tests, wasm } = require('./all');
|
const { beforeAll, tests, wasm } = require('./all');
|
||||||
|
|
||||||
describe('schnorrkel-js', () => {
|
describe('wasm-crypto', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await beforeAll();
|
await beforeAll();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
require('override-require')(
|
||||||
|
(request) =>
|
||||||
|
request.endsWith('@polkadot/wasm-crypto-asmjs') ||
|
||||||
|
request.endsWith('@polkadot/wasm-crypto-wasm'),
|
||||||
|
(request) =>
|
||||||
|
request.endsWith('@polkadot/wasm-crypto-asmjs')
|
||||||
|
? require('../../wasm-crypto-asmjs/build/empty')
|
||||||
|
: require('../../wasm-crypto-wasm/build/data')
|
||||||
|
);
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
const { runUnassisted } = require('./all');
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,7 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "*** Testing WASM"
|
DEST=packages/wasm-crypto/build/esm
|
||||||
node ./test/wasm.js
|
|
||||||
|
|
||||||
echo "*** Testing ASM.js"
|
./scripts/clean-js.sh
|
||||||
node ./test/asm.js
|
yarn polkadot-dev-build-ts
|
||||||
|
|
||||||
echo "*** Testing via Jest"
|
|
||||||
yarn polkadot-dev-run-test ./test/jest.spec.js
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright 2019-2020 @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.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
BGJ=build/wasm_bg.js
|
|
||||||
SRC_WASM=build/wasm.js
|
|
||||||
DEF=build/wasm.d.ts
|
|
||||||
WSM=build/wasm_bg.wasm
|
|
||||||
OPT=build/wasm_opt.wasm
|
|
||||||
ASM=build/wasm_asm.js
|
|
||||||
|
|
||||||
echo "*** Building package"
|
|
||||||
|
|
||||||
# cleanup old
|
|
||||||
echo "*** Cleaning old builds"
|
|
||||||
rm -rf ./build ./pkg
|
|
||||||
|
|
||||||
# build new via nightly & wasm-pack
|
|
||||||
echo "*** Building WASM output"
|
|
||||||
rustup run nightly$NIGHTLY wasm-pack build --release --scope polkadot --target nodejs
|
|
||||||
mv pkg build
|
|
||||||
|
|
||||||
# optimise
|
|
||||||
echo "*** Optimising WASM output"
|
|
||||||
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
|
||||||
|
|
||||||
# convert wasm to base64 structure
|
|
||||||
echo "*** Packing WASM into base64"
|
|
||||||
node ../../scripts/pack-wasm-base64.js
|
|
||||||
|
|
||||||
# build asmjs version from the input (optimised) WASM
|
|
||||||
echo "*** Building asm.js version"
|
|
||||||
../../binaryen/bin/wasm2js --output $ASM $OPT
|
|
||||||
|
|
||||||
# cleanup the generated asm, converting to cjs
|
|
||||||
sed -i -e '/import {/d' $ASM
|
|
||||||
echo "const imported = require('./wasm');
|
|
||||||
$(cat $ASM)" > $ASM
|
|
||||||
sed -i -e 's/{abort.*},memasmFunc/imported, memasmFunc/g' $ASM
|
|
||||||
sed -i -e 's/export var /module\.exports\./g' $ASM
|
|
||||||
|
|
||||||
# copy our package interfaces
|
|
||||||
echo "*** Copying package sources"
|
|
||||||
cp src/js/* build/
|
|
||||||
|
|
||||||
echo "const crypto = require('crypto');
|
|
||||||
const { stringToU8a, u8aToString } = require('@polkadot/util');
|
|
||||||
|
|
||||||
const requires = { crypto };
|
|
||||||
|
|
||||||
$(cat $SRC_WASM)
|
|
||||||
" > $SRC_WASM
|
|
||||||
|
|
||||||
# whack comments
|
|
||||||
sed -i -e '/^\/\*\*/d' $SRC_WASM
|
|
||||||
sed -i -e '/^\*/d' $SRC_WASM
|
|
||||||
sed -i -e '/^\*\//d' $SRC_WASM
|
|
||||||
|
|
||||||
# we are swapping to a async interface for webpack support (wasm limits)
|
|
||||||
sed -i -e '/^wasm = require/d' $SRC_WASM
|
|
||||||
|
|
||||||
# We don't want inline requires
|
|
||||||
sed -i -e 's/ret = require(getStringFromWasm0(arg0, arg1));/ret = requires[getStringFromWasm0(arg0, arg1)];/g' $SRC_WASM
|
|
||||||
|
|
||||||
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
|
|
||||||
sed -i -e '/^const { TextEncoder } = require/d' $SRC_WASM
|
|
||||||
sed -i -e '/^let cachedTextEncoder = new /d' $SRC_WASM
|
|
||||||
sed -i -e 's/cachedTextEncoder\.encode/stringToU8a/g' $SRC_WASM
|
|
||||||
|
|
||||||
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
|
|
||||||
sed -i -e '/^const { TextDecoder } = require/d' $SRC_WASM
|
|
||||||
sed -i -e '/^let cachedTextDecoder = new/d' $SRC_WASM
|
|
||||||
sed -i -e 's/cachedTextDecoder\.decode/u8aToString/g' $SRC_WASM
|
|
||||||
|
|
||||||
# this is where we get the actual bg file
|
|
||||||
sed -i -e '/^const path = require/d' $SRC_WASM
|
|
||||||
sed -i -e '/^const bytes = require/d' $SRC_WASM
|
|
||||||
sed -i -e '/^const wasmModule =/d' $SRC_WASM
|
|
||||||
sed -i -e '/^const wasmInstance =/d' $SRC_WASM
|
|
||||||
sed -i -e '/^wasm = wasmInstance/d' $SRC_WASM
|
|
||||||
|
|
||||||
# construct our promise and add ready helpers (WASM)
|
|
||||||
echo "module.exports.abort = function () { throw new Error('abort'); };
|
|
||||||
|
|
||||||
const createPromise = require('./wasm_promise');
|
|
||||||
const wasmPromise = createPromise().catch(() => null);
|
|
||||||
|
|
||||||
module.exports.isReady = function () { return !!wasm; }
|
|
||||||
module.exports.waitReady = function () { return wasmPromise.then(() => !!wasm); }
|
|
||||||
|
|
||||||
wasmPromise.then((_wasm) => { wasm = _wasm });
|
|
||||||
" >> $SRC_WASM
|
|
||||||
|
|
||||||
# add extra methods to type definitions
|
|
||||||
echo "
|
|
||||||
export function isReady(): boolean;
|
|
||||||
export function waitReady(): Promise<boolean>;
|
|
||||||
" >> $DEF
|
|
||||||
Executable
+48
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2019-2020 @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.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# also change in install-build-deps
|
||||||
|
RUST_VER=nightly-2020-10-25
|
||||||
|
|
||||||
|
WSM=bytes/wasm_bg.wasm
|
||||||
|
OPT=bytes/wasm_opt.wasm
|
||||||
|
ASM=wasm-crypto-asmjs/build/data.js
|
||||||
|
|
||||||
|
# build new via wasm-pack
|
||||||
|
echo "*** Building Rust sources"
|
||||||
|
cd wasm-crypto
|
||||||
|
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
|
||||||
|
# rustup run $RUST_VER cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo "*** Converting to WASM"
|
||||||
|
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
|
||||||
|
# wasm-pack build --release --scope polkadot --target web
|
||||||
|
|
||||||
|
# optimise
|
||||||
|
echo "*** Optimising WASM output"
|
||||||
|
# ../../wabt/bin/wasm-strip $WSM
|
||||||
|
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
||||||
|
|
||||||
|
# convert wasm to base64 structure
|
||||||
|
echo "*** Packing WASM into baseX"
|
||||||
|
node ../scripts/pack-wasm-base.js
|
||||||
|
|
||||||
|
# build asmjs version from the input (optimised) WASM
|
||||||
|
echo "*** Building asm.js version"
|
||||||
|
../binaryen/bin/wasm2js --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
|
||||||
|
|
||||||
|
# cleanups
|
||||||
|
rm -rf wasm-crypto-asmjs/build/*-e
|
||||||
|
rm -rf wasm-crypto-wasm/build/*-e
|
||||||
+14
-17
@@ -5,27 +5,24 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
rustup toolchain install nightly$NIGHTLY
|
echo "*** Building JavaScript"
|
||||||
./scripts/install-build-deps.sh
|
./scripts/build-js.sh
|
||||||
|
|
||||||
echo "*** Building packages"
|
echo "*** Building WASM"
|
||||||
cd packages
|
cd packages
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
../scripts/build-wasm.sh
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
yarn test:wasm:js
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
echo "*** Building $PKG"
|
|
||||||
cd $PKG
|
|
||||||
|
|
||||||
../../scripts/build-package.sh
|
echo ""
|
||||||
../../scripts/test-package.sh
|
echo "*** wasm-crypto"
|
||||||
|
ls -alR wasm-crypto/build
|
||||||
rm -rf build/*-e build/package.json build/README.md
|
echo ""
|
||||||
ls -al build
|
echo "*** wasm-crypto-asmjs"
|
||||||
|
ls -alR wasm-crypto-asmjs/build
|
||||||
cd ..
|
echo ""
|
||||||
fi
|
echo "*** wasm-crypto-wasm"
|
||||||
done
|
ls -alR wasm-crypto-wasm/build
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
rustup toolchain install nightly$NIGHTLY
|
# cleanup old
|
||||||
yarn polkadot-ci-ghact-build
|
echo "*** Cleaning old builds"
|
||||||
|
rm -rf packages/*/build packages/bytes
|
||||||
+5
-17
@@ -5,23 +5,11 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
./scripts/install-build-deps.sh
|
./scripts/clean-js.sh
|
||||||
|
|
||||||
echo "*** Cleaning packages"
|
echo "*** Cleaning wasm"
|
||||||
cd packages
|
cd packages/wasm-crypto
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
cargo clean
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
cd ../..
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
echo "*** Cleaning $PKG"
|
|
||||||
cd $PKG
|
|
||||||
|
|
||||||
rm -rf build
|
|
||||||
cargo clean
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
|
|||||||
@@ -5,43 +5,63 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# wasm2js for wasm -> asm.js
|
# also change in build-package
|
||||||
BINARYEN=( "wasm-opt" "wasm2js" )
|
RUST_VER=nightly-2020-10-25
|
||||||
|
|
||||||
|
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||||
|
BINARYEN_VER=version_97
|
||||||
|
BINARYEN_ZIP=
|
||||||
|
|
||||||
|
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
|
||||||
|
BINDGEN_VER=0.2.65
|
||||||
|
BINDGEN_ZIP=
|
||||||
|
|
||||||
|
WABT_REPO=https://github.com/WebAssembly/wabt
|
||||||
|
WABT_VER=1.0.19
|
||||||
|
WABT_ZIP=
|
||||||
|
|
||||||
unamestr=`uname`
|
unamestr=`uname`
|
||||||
|
|
||||||
# install wasm-pack as required
|
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
|
||||||
if ! [ -x "$(command -v wasm-pack)" ]; then
|
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||||
echo "*** Installing wasm-pack"
|
cargo install xargo
|
||||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
||||||
fi
|
# if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||||
|
# echo "*** Installing wasm-pack"
|
||||||
|
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
|
# fi
|
||||||
|
|
||||||
# CI, Linux
|
|
||||||
if [[ "$unamestr" == 'Linux' ]]; then
|
if [[ "$unamestr" == 'Linux' ]]; then
|
||||||
if [ ! -d "binaryen" ]; then
|
echo "*** Detected Linux"
|
||||||
echo "*** Downloading binaryen"
|
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||||
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_91/binaryen-version_91-x86-linux.tar.gz | tar xz
|
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-unknown-linux-musl
|
||||||
mkdir -p binaryen/bin
|
WABT_ZIP=wabt-$WABT_VER-ubuntu
|
||||||
|
elif [[ "$unamestr" == "Darwin" ]]; then
|
||||||
for BIN in "${BINARYEN[@]}"; do
|
echo "*** Detected Mac"
|
||||||
mv binaryen-version_91/$BIN binaryen/bin
|
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-macos
|
||||||
done
|
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-apple-darwin
|
||||||
fi
|
WABT_ZIP=wabt-$WABT_VER-macos
|
||||||
else
|
else
|
||||||
# install binaryen as required
|
echo "*** Unknown platform $unamestr, unable to install wasm helper binaries"
|
||||||
if [ ! -d "binaryen" ]; then
|
exit 1
|
||||||
echo "*** Cloning binaryen"
|
|
||||||
git clone --recursive https://github.com/WebAssembly/binaryen.git
|
|
||||||
rm -rf binaryen/test
|
|
||||||
fi
|
|
||||||
|
|
||||||
for BIN in "${BINARYEN[@]}"; do
|
|
||||||
if [ ! -f "binaryen/bin/$BIN" ]; then
|
|
||||||
echo "*** Building $BIN"
|
|
||||||
cd binaryen
|
|
||||||
cmake . && make $BIN
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "binaryen" ]; then
|
||||||
|
echo "*** Downloading binaryen"
|
||||||
|
curl -L $BINARYEN_REPO/releases/download/$BINARYEN_VER/$BINARYEN_ZIP.tar.gz | tar xz
|
||||||
|
mv binaryen-$BINARYEN_VER binaryen
|
||||||
|
ls -alR binaryen
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "bindgen" ]; then
|
||||||
|
echo "*** Downloading bindgen"
|
||||||
|
curl -L $BINDGEN_REPO/releases/download/$BINDGEN_VER/$BINDGEN_ZIP.tar.gz | tar xz
|
||||||
|
mv $BINDGEN_ZIP bindgen
|
||||||
|
ls -alR bindgen
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if [ ! -d "wabt" ]; then
|
||||||
|
# echo "*** Downloading wabt"
|
||||||
|
# curl -L $WABT_REPO/releases/download/$WABT_VER/$WABT_ZIP.tar.gz | tar xz
|
||||||
|
# mv wabt-$WABT_VER wabt
|
||||||
|
# fi
|
||||||
|
|||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019-2020 @polkadot/wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const { formatNumber } = require('@polkadot/util');
|
||||||
|
|
||||||
|
const A_NAME = 'wasm-crypto-asmjs';
|
||||||
|
const W_NAME = 'wasm-crypto-wasm';
|
||||||
|
|
||||||
|
function hdr (package) {
|
||||||
|
return `// Copyright 2019-2020 @polkadot/${package} authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Generated as part of the build, do not edit
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only one of the deps are included, here are the details for package.json -
|
||||||
|
// "fflate": "^0.4.2"
|
||||||
|
// "lz4js": "^0.2.0"
|
||||||
|
function getWasmBuffer (lib = 'fflate') {
|
||||||
|
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
||||||
|
const comp = lib === 'fflate'
|
||||||
|
? Buffer.from(require('fflate').zlibSync(data, { level: 9 }))
|
||||||
|
: Buffer.from(require('lz4js').compress(data));
|
||||||
|
|
||||||
|
console.log(`*** Compressed WASM via ${lib}: ${formatNumber(data.length)} -> ${formatNumber(comp.length)} (${(100 * comp.length / data.length).toFixed(2)}%)`);
|
||||||
|
|
||||||
|
return comp.toString('base64');
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${A_NAME}/build/data.mjs`, `${hdr(A_NAME)}
|
||||||
|
export { asmJsInit } from './data.js';
|
||||||
|
`);
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${W_NAME}/build/buffer.mjs`, `${hdr(W_NAME)}
|
||||||
|
export { buffer } from './buffer.js';
|
||||||
|
`);
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${W_NAME}/build/buffer.js`, `${hdr(W_NAME)}
|
||||||
|
const buffer = Buffer.from('${getWasmBuffer()}', 'base64');
|
||||||
|
|
||||||
|
module.exports = { buffer };
|
||||||
|
`);
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright 2019-2020 @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.
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
const fs = require('fs');
|
|
||||||
const buffer = fs.readFileSync('./build/wasm_opt.wasm');
|
|
||||||
|
|
||||||
fs.writeFileSync('./build/wasm_wasm.js', `
|
|
||||||
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
|
|
||||||
`);
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright 2019-2020 @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.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
rustup toolchain install nightly$NIGHTLY
|
|
||||||
|
|
||||||
cd packages
|
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
cd $PKG
|
|
||||||
echo "*** Testing Rust $PKG"
|
|
||||||
|
|
||||||
RUST_BACKTRACE=full rustup run nightly$NIGHTLY cargo test --release -- --nocapture
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
+4
-2
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"extends": "@polkadot/dev/config/tsconfig",
|
"extends": "@polkadot/dev/config/tsconfig.json",
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"build/**/*",
|
"build/**/*",
|
||||||
"**/build/**/*"
|
"**/build/**/*"
|
||||||
@@ -7,7 +7,9 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@polkadot/wasm-schnorrkel": [ "packages/wasm-schnorrkel/src" ]
|
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
|
||||||
|
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
|
||||||
|
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||||
},
|
},
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
|
|||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
exclude: '**/*+(index|e2e|spec).ts',
|
|
||||||
excludeExternals: true,
|
|
||||||
excludeNotExported: true,
|
|
||||||
excludePrivate: true,
|
|
||||||
excludeProtected: true,
|
|
||||||
hideGenerator: true,
|
|
||||||
includeDeclarations: false,
|
|
||||||
mdEngine: 'gitbook',
|
|
||||||
module: 'commonjs',
|
|
||||||
moduleResolution: 'node',
|
|
||||||
name: 'Polkadot JS WASM',
|
|
||||||
out: 'docs',
|
|
||||||
stripInternal: 'true',
|
|
||||||
theme: 'markdown'
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user