Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
b139d44907 | ||
|
|
a81698c61c | ||
|
|
9e1d439c55 | ||
|
|
a18d50f501 | ||
|
|
55a3e96698 | ||
|
|
c4ab178926 | ||
|
|
be787021c7 | ||
|
|
037d857085 | ||
|
|
c140ac97e5 | ||
|
|
8e370e4c19 | ||
|
|
6ab362ea57 | ||
|
|
666d679b4e | ||
|
|
1228617330 | ||
|
|
5da4f3a324 | ||
|
|
07742c9d03 | ||
|
|
af94d0d001 | ||
|
|
8d96c8aed4 | ||
|
|
2d48df8986 | ||
|
|
2d07c0a6a3 | ||
|
|
8b7c7e93af | ||
|
|
393d898dab | ||
|
|
fcf6d439ef | ||
|
|
5ccb1b4982 | ||
|
|
7ee706a99f | ||
|
|
da491efef6 | ||
|
|
2ff45e1ca6 | ||
|
|
6aac8e8771 | ||
|
|
6ebdfe9362 | ||
|
|
de9bf473f1 | ||
|
|
735584aef9 | ||
|
|
7a33da9e53 | ||
|
|
0faca1b98e | ||
|
|
ab867541d7 | ||
|
|
f50d6af2bb | ||
|
|
8c4bf9470a | ||
|
|
e5875a73c3 | ||
|
|
e32e52a94c | ||
|
|
59673150ba | ||
|
|
9f84fc3250 | ||
|
|
678063e12a | ||
|
|
02324280e3 | ||
|
|
9bc97a4e1d | ||
|
|
4cc1d4e515 | ||
|
|
8ae9bbd3b6 | ||
|
|
08c9e9e8ac | ||
|
|
b3c32738e3 | ||
|
|
72ff8a13dc | ||
|
|
1d75701361 | ||
|
|
2fd1daf39a | ||
|
|
ef6db82c52 | ||
|
|
1e2caa35ce | ||
|
|
8c0aa030cf | ||
|
|
ff9fe99ca5 | ||
|
|
e0feb7864d | ||
|
|
c8431fc3d1 | ||
|
|
849285a35d | ||
|
|
5fe38fa47b | ||
|
|
241bbe99c5 | ||
|
|
65d89a7b41 | ||
|
|
a0cbf8c531 | ||
|
|
c50fe071cb | ||
|
|
526b79435e | ||
|
|
b621b79bae | ||
|
|
37b04af274 | ||
|
|
84f0d27744 | ||
|
|
ff2315bff8 | ||
|
|
6fa0e99141 | ||
|
|
7c9bbb05a6 | ||
|
|
3ef1b2073f | ||
|
|
b56924a5b3 | ||
|
|
bf7feafaaa | ||
|
|
184edb6e4e | ||
|
|
d511310ba0 | ||
|
|
7ad87c6ce2 | ||
|
|
01a5539c28 | ||
|
|
dd107338e9 | ||
|
|
61ffef08e3 | ||
|
|
76a436f22c | ||
|
|
86a66de726 | ||
|
|
7c4d2f7af5 | ||
|
|
a20b14a8b7 | ||
|
|
e5c31a0fe7 | ||
|
|
0fc0207bcb | ||
|
|
645cf3dbf7 | ||
|
|
0fd350f5d6 | ||
|
|
5e85feae7b | ||
|
|
2a61459682 | ||
|
|
370d0de745 | ||
|
|
07dd07c9db | ||
|
|
e6b892df6f | ||
|
|
e93e764a72 | ||
|
|
331111b895 | ||
|
|
31afd5143f | ||
|
|
a0126f374e | ||
|
|
f11be090e8 | ||
|
|
f3dbf059b7 | ||
|
|
eba92df762 | ||
|
|
e4a717faa6 | ||
|
|
075ba8a365 | ||
|
|
a9b2ac1240 | ||
|
|
d336b1f894 | ||
|
|
c976f3ebf9 | ||
|
|
cdcfe2823d | ||
|
|
57030cb591 | ||
|
|
88ebaf650b | ||
|
|
28bac70cfe | ||
|
|
aaab1725b8 | ||
|
|
4c7a9609bd | ||
|
|
e1c51d766f | ||
|
|
c30a354b67 | ||
|
|
b2d0c437be | ||
|
|
59c9bbec25 | ||
|
|
7be59495b9 | ||
|
|
33c2413247 | ||
|
|
2345285e3d | ||
|
|
d1f188444c | ||
|
|
a3cc64ed51 | ||
|
|
721ae96a7c | ||
|
|
70dfe47d79 | ||
|
|
2ad1132a48 | ||
|
|
9246bef8bb | ||
|
|
9f08e7832f | ||
|
|
c14d84749a | ||
|
|
1f4612bf32 | ||
|
|
e724536d9c | ||
|
|
0d7ec76900 | ||
|
|
6dc6de5629 | ||
|
|
bd42b2b9ee | ||
|
|
8024f524b3 | ||
|
|
b10190e6cf | ||
|
|
2147464449 | ||
|
|
e74c15b239 | ||
|
|
3112aa8acb | ||
|
|
2ad4e10a32 | ||
|
|
db3f3d273d | ||
|
|
e4cc9ffbe9 | ||
|
|
d74d9e8de4 | ||
|
|
0c946aa527 | ||
|
|
ab61af29ab | ||
|
|
576aeba620 | ||
|
|
10f06d932a | ||
|
|
5531f01815 | ||
|
|
5a88a13454 | ||
|
|
4c069d8e8d | ||
|
|
45fbe693f5 | ||
|
|
e4fd0ad6df | ||
|
|
63f7cdb4b7 | ||
|
|
aba850b6c9 | ||
|
|
c7aeb572dd | ||
|
|
e7e8d8a208 | ||
|
|
b285352df3 | ||
|
|
39670ea9ee | ||
|
|
3553f939d4 | ||
|
|
462c90eed8 | ||
|
|
1c7a209a83 | ||
|
|
f95c200aa0 | ||
|
|
6865b98d39 | ||
|
|
e62e90666b | ||
|
|
bbacc24ee8 | ||
|
|
c4ced11a81 | ||
|
|
ce1a686926 | ||
|
|
3225b9514d | ||
|
|
0c28ddbd03 | ||
|
|
3584e354a9 | ||
|
|
837d308414 | ||
|
|
8b5d7e6ad1 | ||
|
|
b605e99c8c | ||
|
|
db84a84ab9 | ||
|
|
538ba3cee7 | ||
|
|
249d33e88d | ||
|
|
b508b757b3 | ||
|
|
7dfec78e7f | ||
|
|
007d3ef42c | ||
|
|
8968e50d8e | ||
|
|
860ac9df24 | ||
|
|
1d28086018 | ||
|
|
e437ce892c | ||
|
|
273ad749c2 | ||
|
|
99eb14e9b2 | ||
|
|
bbaee7325a | ||
|
|
063d13e18d | ||
|
|
9ce3f2cf9f | ||
|
|
64d5140f03 | ||
|
|
9236196c02 | ||
|
|
aa9b9286cc | ||
|
|
a649085e56 | ||
|
|
5910f02ea1 | ||
|
|
dca5a6df90 | ||
|
|
2a2428e1a5 | ||
|
|
0ed359751a | ||
|
|
024ffa3c5e | ||
|
|
a6e1d16905 | ||
|
|
2f0c01e042 | ||
|
|
03008cae4f | ||
|
|
3e6bd38b8f | ||
|
|
18b17b143b | ||
|
|
2844ce085a | ||
|
|
77909c9ba6 | ||
|
|
ef753fb65d | ||
|
|
a85b5d3a72 | ||
|
|
e2c8d1f3a2 | ||
|
|
61b0126178 | ||
|
|
3b672c8ca6 | ||
|
|
de18cff30c | ||
|
|
e626d1696d | ||
|
|
69341f4482 | ||
|
|
0adada79bb | ||
|
|
67adc55627 | ||
|
|
5d4a033e2c | ||
|
|
cd3341c6ec | ||
|
|
56d4f5175f | ||
|
|
96ea859573 | ||
|
|
34a02db84b | ||
|
|
1f0ff1c354 | ||
|
|
22a27e7f84 | ||
|
|
bd8139ed2d | ||
|
|
173cd0e11a | ||
|
|
7b5cf39299 | ||
|
|
a19f2fff19 | ||
|
|
7f681861c5 | ||
|
|
ad18d92ea0 | ||
|
|
73a72470e3 | ||
|
|
57a5e112fa | ||
|
|
7357faf057 | ||
|
|
b4c739b184 | ||
|
|
cd8daafaaa | ||
|
|
bc39b735ba | ||
|
|
bb73f7ab43 | ||
|
|
6c202bbe19 | ||
|
|
79a7087cf8 | ||
|
|
e14d722350 | ||
|
|
94e0cadc00 | ||
|
|
aedab18bca | ||
|
|
f0e9e7f790 | ||
|
|
7dbf14084e | ||
|
|
14118ac058 | ||
|
|
d7f2604933 | ||
|
|
6897201132 | ||
|
|
fa77c76025 | ||
|
|
b6679e7fae | ||
|
|
960419060b | ||
|
|
379f2c175d | ||
|
|
29394b37cc | ||
|
|
b96a04bdc6 | ||
|
|
f263d88684 | ||
|
|
013448697d | ||
|
|
77a5c59381 | ||
|
|
c4b0e5278d | ||
|
|
fa0bd6a57d | ||
|
|
6920eeced6 | ||
|
|
c290dc1d68 | ||
|
|
16f52c8d47 | ||
|
|
a99ffac9fb | ||
|
|
24735d6386 | ||
|
|
ba00017218 | ||
|
|
a863dc61fb | ||
|
|
9c574a5461 | ||
|
|
2e9597de51 | ||
|
|
c492416534 | ||
|
|
7a922c6942 | ||
|
|
1fb7f9f1a4 | ||
|
|
3278a0f5ab | ||
|
|
97619eb27c | ||
|
|
04edfe2725 | ||
|
|
e79fb448a3 | ||
|
|
96dbe40681 | ||
|
|
22bb4c2202 | ||
|
|
1e25c033f1 | ||
|
|
3627fd2d5f | ||
|
|
85949e11d7 | ||
|
|
0f7bdcd711 | ||
|
|
828d44fbd4 | ||
|
|
f3c9ae14f4 | ||
|
|
e022247db7 | ||
|
|
b18fa247bd | ||
|
|
33f09b6d1d | ||
|
|
21159707c8 | ||
|
|
7b11865751 | ||
|
|
737ddf36c5 | ||
|
|
3851d11ab5 | ||
|
|
28233e9664 | ||
|
|
af535a67cc | ||
|
|
be6db81065 | ||
|
|
9822c34dc7 | ||
|
|
b46005f180 | ||
|
|
4ceec33fc7 | ||
|
|
ef78d10989 | ||
|
|
fe232a9ab4 | ||
|
|
da78a24aa3 | ||
|
|
3c6e806db5 | ||
|
|
0176c82db1 | ||
|
|
98bb6453dd | ||
|
|
839e4d3fa3 | ||
|
|
91b55caf09 | ||
|
|
b03aaa4bf7 | ||
|
|
811411f606 | ||
|
|
107c410346 | ||
|
|
43d0bfaaf1 | ||
|
|
543c6a7512 | ||
|
|
9ee302fd79 | ||
|
|
30f7dc3549 | ||
|
|
5cab032133 | ||
|
|
6df8568f85 | ||
|
|
f23f4eb986 | ||
|
|
d0b3317c28 | ||
|
|
61b227436e | ||
|
|
1cc5190fa0 | ||
|
|
311ac2e0e3 | ||
|
|
52a14a7928 | ||
|
|
498e089342 | ||
|
|
b75cb172ba | ||
|
|
ab1952a3f5 | ||
|
|
c46a890234 | ||
|
|
80d6d9f9ff | ||
|
|
b3f006d5c0 | ||
|
|
0f16e58760 | ||
|
|
648adf840d | ||
|
|
0e50f267d1 | ||
|
|
2c02b44c0d | ||
|
|
416e0c58f8 | ||
|
|
49968708d3 | ||
|
|
340ccd18d2 | ||
|
|
173fca3a81 | ||
|
|
24af3cf2ce | ||
|
|
c1186a3743 | ||
|
|
bd18b42439 | ||
|
|
d047be77b3 | ||
|
|
e467308ac1 | ||
|
|
4dbe2214a9 | ||
|
|
2844c15911 | ||
|
|
419630da5f | ||
|
|
0e9f04fd33 | ||
|
|
2ecb1d209f | ||
|
|
d282dbd54c | ||
|
|
e5680e8823 | ||
|
|
c1c27d7a7d | ||
|
|
44c62a7b3d |
@@ -0,0 +1 @@
|
||||
4
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('./babel.config.js');
|
||||
@@ -1,4 +0,0 @@
|
||||
**/binaryen/*
|
||||
**/build/*
|
||||
**/coverage/*
|
||||
**/node_modules/*
|
||||
+24
-1
@@ -1 +1,24 @@
|
||||
module.exports = require('@polkadot/dev/config/eslint');
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const base = require('@polkadot/dev/config/eslint');
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
ignorePatterns: [
|
||||
'.eslintrc.js',
|
||||
'.github/**',
|
||||
'.vscode/**',
|
||||
'.yarn/**',
|
||||
'**/binaryen/*',
|
||||
'**/build/*',
|
||||
'**/coverage/*',
|
||||
'**/node_modules/*'
|
||||
],
|
||||
parserOptions: {
|
||||
...base.parserOptions,
|
||||
project: [
|
||||
'./tsconfig.json'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
name: PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
pr:
|
||||
strategy:
|
||||
matrix:
|
||||
step: ['lint', 'test', 'build']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: ${{ matrix.step }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
./scripts/install-build-deps.sh
|
||||
yarn ${{ matrix.step }}
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Master
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
master:
|
||||
strategy:
|
||||
matrix:
|
||||
step: ['build:release']
|
||||
name: ${{ matrix.step }}
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/wasm'"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
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
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
dummy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: dummy
|
||||
run: |
|
||||
echo "Dummy skip step"
|
||||
@@ -1,4 +1,5 @@
|
||||
binaryen/
|
||||
bindgen/
|
||||
build/
|
||||
build-docs/
|
||||
coverage/
|
||||
@@ -7,12 +8,18 @@ node_modules/
|
||||
pkg/
|
||||
target/
|
||||
tmp/
|
||||
wabt/
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.npmrc
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
!.yarn/plugins
|
||||
!.yarn/sdks
|
||||
cc-test-reporter
|
||||
lerna-debug.log*
|
||||
npm-debug.log*
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
dist: xenial
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
env:
|
||||
global:
|
||||
- CC_TEST_REPORTER_ID=979056b20f7c89193ed7b4cdcd6bb6252231f069171fd73b072d0da6f5dd2338
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['cmake', 'g++-5']
|
||||
cache:
|
||||
cargo: true
|
||||
yarn: true
|
||||
directories:
|
||||
- node_modules
|
||||
compiler:
|
||||
- clang
|
||||
before_install:
|
||||
- curl -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=nightly -y
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
||||
- chmod +x ./cc-test-reporter
|
||||
- export PATH=$HOME/.yarn/bin:$HOME/.cargo/bin:$(yarn global bin):$PATH
|
||||
before_script:
|
||||
- ./cc-test-reporter before-build
|
||||
script:
|
||||
- yarn polkadot-dev-travis-build
|
||||
after_script:
|
||||
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
provider: script
|
||||
script: yarn polkadot-dev-travis-deploy
|
||||
on:
|
||||
branch: master
|
||||
File diff suppressed because one or more lines are too long
+52
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+55
File diff suppressed because one or more lines are too long
+15
@@ -0,0 +1,15 @@
|
||||
enableImmutableInstalls: false
|
||||
|
||||
enableProgressBars: false
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
|
||||
spec: "@yarnpkg/plugin-workspace-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-2.3.3.cjs
|
||||
+120
-13
@@ -1,59 +1,166 @@
|
||||
# 0.13.1
|
||||
# CHANGELOG
|
||||
|
||||
## 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
|
||||
|
||||
Changes:
|
||||
|
||||
- Re-add the BTC/ETH compatible `bip39ToSeed` dropped in the previous version (ETH-compatible pairs)
|
||||
|
||||
|
||||
## 1.3.1 Aug 9, 2020
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `scrypt` function for KDF generation
|
||||
- Remove `bip39ToSeed`, we only use the `bip39ToMiniSecret` variant in Substrate
|
||||
- Update ed25519-dalek to 1.0.0-pre.4
|
||||
- Rework generation based on latest wasm-pack generator
|
||||
|
||||
|
||||
## 1.2.1 Feb 29, 2020
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
|
||||
- Unpin nightly from nightly-2020-02-17 version
|
||||
- Swap to yarn 2 and add support for use by yarn 2 projects
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
Changes:
|
||||
|
||||
- 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)
|
||||
|
||||
|
||||
## 1.0.1 Feb 15, 2020
|
||||
|
||||
Changes:
|
||||
|
||||
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
||||
|
||||
|
||||
## 0.20.1 Jan 30, 2020
|
||||
|
||||
Changes:
|
||||
|
||||
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
||||
|
||||
|
||||
## 0.14.1 Sep 09, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
||||
|
||||
|
||||
## 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`)
|
||||
|
||||
# 0.12.1
|
||||
|
||||
## 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)
|
||||
- Security dependency bumps
|
||||
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
||||
|
||||
# 0.11.1
|
||||
|
||||
## 0.11.1 May 31, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Security dependency bumps
|
||||
|
||||
# 0.10.1
|
||||
|
||||
## 0.10.1 May 09, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
||||
- Added known subkey signature test (Rust & JS)
|
||||
|
||||
# 0.9.1
|
||||
|
||||
## 0.9.1 Apr 29, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Dependency bumps
|
||||
|
||||
# 0.8.1
|
||||
|
||||
## 0.8.1 Mar 31, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
||||
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
||||
- Improve error messaging, instead of `__wasm_malloc of null`
|
||||
|
||||
# 0.7.1
|
||||
|
||||
## 0.7.1 Mar 30, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
||||
|
||||
# 0.6.1
|
||||
|
||||
## 0.6.1 Mar 27, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
||||
|
||||
# 0.5.1
|
||||
|
||||
## 0.5.1 Mar 23, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Add password argument to bip39ToSeed
|
||||
|
||||
# 0.4.1
|
||||
|
||||
## 0.4.1 Mar 23, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Add bip39ToSeed
|
||||
|
||||
# 0.3.1
|
||||
|
||||
## 0.3.1 Mar 23, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Add wasm-dalek-ed25519 for all used crypto there
|
||||
- Add keccak256
|
||||
- Try secp256k1 (bloating code, not used atm)
|
||||
|
||||
# 0.2.1
|
||||
|
||||
## 0.2.1 Mar 20, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Add basic crypto functions, creation of wasm-crypto package
|
||||
- blake2, bip39, sha2, xxhash
|
||||
|
||||
# 0.1.1
|
||||
|
||||
## 0.1.1 Mar 18, 2019
|
||||
|
||||
Changes:
|
||||
|
||||
- Initial release
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
[](https://polkadot.js.org)
|
||||

|
||||
[](https://github.com/Flet/semistandard)
|
||||
[](https://travis-ci.com/polkadot-js/wasm)
|
||||
[](https://codeclimate.com/github/polkadot-js/wasm/maintainability)
|
||||
[](https://greenkeeper.io/)
|
||||
[](https://polkadot.js.org)
|
||||

|
||||
[](https://www.npmjs.com/package/@polkadot/wasm-crypto)
|
||||
[](https://www.npmjs.com/package/@polkadot/wasm-crypto)
|
||||
[](https://codeclimate.com/github/polkadot-js/wasm/maintainability)
|
||||
|
||||
# @polkadot/wasm
|
||||
|
||||
|
||||
+4
-3
@@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
extends: '@polkadot/dev/config/babel'
|
||||
};
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = require('@polkadot/dev/config/babel');
|
||||
|
||||
@@ -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>
|
||||
+7
-4
@@ -1,11 +1,14 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const config = require('@polkadot/dev/config/jest');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
moduleNameMapper: {
|
||||
'@polkadot/wasm-(schnorrkel)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
|
||||
'@polkadot/wasm-(crypto)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
|
||||
},
|
||||
modulePathIgnorePatterns: [
|
||||
'<rootDir>/packages/wasm-schnorrkel/build'
|
||||
]
|
||||
'<rootDir>/packages/wasm-crypto/build'
|
||||
],
|
||||
resolver: '@polkadot/dev/config/jest-resolver'
|
||||
});
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"command": {
|
||||
"publish": {
|
||||
"allowBranch": "master"
|
||||
}
|
||||
},
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "0.13.1"
|
||||
}
|
||||
+17
-15
@@ -1,28 +1,30 @@
|
||||
{
|
||||
"version": "0.13.1",
|
||||
"repository": "https://github.com/polkadot-js/wasm",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "Apache-2",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"yarn": "^1.10.1"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"babel-core": "^7.0.0-bridge.0",
|
||||
"typescript": "^3.5.3"
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "./scripts/build.sh",
|
||||
"check": "yarn lint",
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx . && tsc --noEmit --pretty",
|
||||
"build": "yarn build:wasm",
|
||||
"build:release": "polkadot-ci-ghact-build",
|
||||
"build:wasm": "./scripts/build.sh",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "./scripts/clean.sh",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "echo \"Tests included in build\""
|
||||
"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": {
|
||||
"@babel/core": "^7.5.4",
|
||||
"@polkadot/dev": "^0.30.0-beta.23",
|
||||
"@polkadot/util": "^0.94.0-beta.19",
|
||||
"override-require": "^1.1.1"
|
||||
}
|
||||
"@babel/core": "^7.12.3",
|
||||
"@polkadot/dev": "^0.59.19"
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
||||
|
||||
Generated
+386
-419
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
|
||||
[package]
|
||||
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
||||
description = "WASM bindings to Rust crypto libaries."
|
||||
description = "WASM bindings to Rust crypto libraries."
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
name = "wasm"
|
||||
@@ -12,26 +12,34 @@ repository = "https://github.com/polkadot-js/wasm/"
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
blake2-rfc = "0.2.18"
|
||||
byteorder = "1.3.1"
|
||||
ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] }
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||
hmac = "0.7.0"
|
||||
# libsecp256k1 = "0.2.2"
|
||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||
schnorrkel = { version = "0.1.1", features = ["nightly"] }
|
||||
sha2 = "0.8.0"
|
||||
tiny-bip39 = { version = "0.6.1", default-features = false }
|
||||
tiny-keccak = "1.4.2"
|
||||
twox-hash = "1.1.2"
|
||||
wasm-bindgen = "0.2"
|
||||
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"
|
||||
wee_alloc = "0.4.3"
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.2.0"
|
||||
rand = { version = "0.6.5", features = ["wasm-bindgen"] }
|
||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = false
|
||||
debug-assertions = false
|
||||
incremental = false
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
rpath = false
|
||||
|
||||
@@ -12,14 +12,14 @@ Use it -
|
||||
|
||||
```js
|
||||
const { u8aToHex } = require('@polkadot/util');
|
||||
const { bio39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
||||
const { bip39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
||||
|
||||
async function main () {
|
||||
// first wait until the WASM has been loaded (async init)
|
||||
await waitReady();
|
||||
|
||||
// generate phrase
|
||||
const phrase = bip39Generate();
|
||||
const phrase = bip39Generate(12);
|
||||
|
||||
// get ed25519 seed from phrase
|
||||
const seed = bip39ToSeed(phrase, '');
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[dependencies]
|
||||
std = { default-features = false, features = ["panic_immediate_abort"] }
|
||||
@@ -1,25 +1,20 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto",
|
||||
"version": "0.13.1",
|
||||
"version": "2.0.1",
|
||||
"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"
|
||||
"./wasm/asm-empty.js": "./wasm/asm.js"
|
||||
},
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.59.19",
|
||||
"@polkadot/util": "^4.0.0-7",
|
||||
"@polkadot/x-randomvalues": "^4.0.0-7",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
"@polkadot/util": "*",
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const { assert, stringToU8a, u8aToString } = require('@polkadot/util');
|
||||
|
||||
let wasm;
|
||||
let cachegetInt32 = null;
|
||||
let cachegetUint8 = null;
|
||||
|
||||
async function initWasm (wasmBytes, asmFn, wbg) {
|
||||
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;
|
||||
} catch (error) {
|
||||
// if we have a valid supplied asm.js, return that
|
||||
if (asmFn) {
|
||||
wasm = asmFn(wbg);
|
||||
} else {
|
||||
console.error('ERROR: Unable to initialize @polkadot/wasm-crypto');
|
||||
console.error(error);
|
||||
|
||||
wasm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function withWasm (fn) {
|
||||
return (...params) => {
|
||||
assert(wasm, '@polkadot/wasm-crypto has not been initialized. Ensure that you wait for the initialization Promise with waitReady() (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
|
||||
|
||||
return fn(wasm, ...params);
|
||||
};
|
||||
}
|
||||
|
||||
function getWasm () {
|
||||
return wasm;
|
||||
}
|
||||
|
||||
function getInt32 () {
|
||||
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm.memory.buffer) {
|
||||
cachegetInt32 = new Int32Array(wasm.memory.buffer);
|
||||
}
|
||||
|
||||
return cachegetInt32;
|
||||
}
|
||||
|
||||
function getUint8 () {
|
||||
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm.memory.buffer) {
|
||||
cachegetUint8 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
|
||||
return cachegetUint8;
|
||||
}
|
||||
|
||||
function getU8a (ptr, len) {
|
||||
return getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||
}
|
||||
|
||||
function getString (ptr, len) {
|
||||
return u8aToString(getU8a(ptr, len));
|
||||
}
|
||||
|
||||
function allocU8a (arg) {
|
||||
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
||||
|
||||
getUint8().set(arg, ptr / 1);
|
||||
|
||||
return [ptr, arg.length];
|
||||
}
|
||||
|
||||
function allocString (arg) {
|
||||
return allocU8a(stringToU8a(arg));
|
||||
}
|
||||
|
||||
function resultU8a () {
|
||||
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;
|
||||
}
|
||||
|
||||
function resultString () {
|
||||
return u8aToString(resultU8a());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
allocString,
|
||||
allocU8a,
|
||||
getInt32,
|
||||
getString,
|
||||
getU8a,
|
||||
getWasm,
|
||||
initWasm,
|
||||
resultString,
|
||||
resultU8a,
|
||||
withWasm
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const getRandomValues = require('@polkadot/x-randomvalues').default;
|
||||
|
||||
const { getString, getU8a } = require('./bridge');
|
||||
|
||||
const DEFAULT_SELF = { crypto: { getRandomValues } };
|
||||
|
||||
const heap = new Array(32).fill(undefined).concat(undefined, null, true, false);
|
||||
let heapNext = heap.length;
|
||||
|
||||
function getObject (idx) {
|
||||
return heap[idx];
|
||||
}
|
||||
|
||||
function dropObject (idx) {
|
||||
if (idx < 36) {
|
||||
return;
|
||||
}
|
||||
|
||||
heap[idx] = heapNext;
|
||||
heapNext = idx;
|
||||
}
|
||||
|
||||
function takeObject (idx) {
|
||||
const ret = getObject(idx);
|
||||
|
||||
dropObject(idx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function addObject (obj) {
|
||||
if (heapNext === heap.length) {
|
||||
heap.push(heap.length + 1);
|
||||
}
|
||||
|
||||
const idx = heapNext;
|
||||
|
||||
heapNext = heap[idx];
|
||||
heap[idx] = obj;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
module.exports.__wbindgen_is_undefined = function (arg0) {
|
||||
return getObject(arg0) === undefined;
|
||||
};
|
||||
|
||||
module.exports.__wbg_self_1b7a39e3a92c949c = function () {
|
||||
return addObject(DEFAULT_SELF);
|
||||
};
|
||||
|
||||
module.exports.__wbg_require_604837428532a733 = function (arg0, arg1) {
|
||||
throw new Error(`Unable to import ${getString(arg0, arg1)}`);
|
||||
};
|
||||
|
||||
module.exports.__wbg_crypto_968f1772287e2df0 = function (arg0) {
|
||||
return addObject(getObject(arg0).crypto);
|
||||
};
|
||||
|
||||
module.exports.__wbg_getRandomValues_a3d34b4fee3c2869 = function (arg0) {
|
||||
return addObject(getObject(arg0).getRandomValues);
|
||||
};
|
||||
|
||||
module.exports.__wbg_getRandomValues_f5e14ab7ac8e995d = function (arg0, arg1, arg2) {
|
||||
getObject(arg0).getRandomValues(getU8a(arg1, arg2));
|
||||
};
|
||||
|
||||
module.exports.__wbg_randomFillSync_d5bd2d655fdf256a = function (arg0, arg1, arg2) {
|
||||
getObject(arg0).randomFillSync(getU8a(arg1, arg2));
|
||||
};
|
||||
|
||||
module.exports.__wbindgen_object_drop_ref = function (arg0) {
|
||||
takeObject(arg0);
|
||||
};
|
||||
|
||||
module.exports.abort = function () {
|
||||
throw new Error('abort');
|
||||
};
|
||||
+3
-3
@@ -1,6 +1,5 @@
|
||||
// Copyright 2019 @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.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string;
|
||||
export function bip39ToEntropy (phrase: string): Uint8Array;
|
||||
@@ -22,6 +21,7 @@ export function sr25519Verify (signature: Uint8Array, message: Uint8Array, publi
|
||||
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;
|
||||
@@ -0,0 +1,188 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const asmFallback = require('./wasm/asm-empty');
|
||||
const wasmBytes = require('./wasm/bytes');
|
||||
const { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } = require('./bridge');
|
||||
const imports = require('./imports');
|
||||
|
||||
const wasmPromise = initWasm(wasmBytes, asmFallback, imports).catch(() => null);
|
||||
|
||||
module.exports.bip39Generate = withWasm((wasm, words) => {
|
||||
wasm.ext_bip39_generate(8, words);
|
||||
|
||||
return resultString();
|
||||
});
|
||||
|
||||
module.exports.bip39ToEntropy = withWasm((wasm, phrase) => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
|
||||
wasm.ext_bip39_to_entropy(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.bip39ToMiniSecret = withWasm((wasm, phrase, password) => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
|
||||
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.bip39ToSeed = withWasm((wasm, phrase, password) => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
|
||||
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.bip39Validate = withWasm((wasm, phrase) => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const ret = wasm.ext_bip39_validate(ptr0, len0);
|
||||
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
module.exports.ed25519KeypairFromSeed = withWasm((wasm, seed) => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
|
||||
wasm.ext_ed_from_seed(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.ed25519Sign = withWasm((wasm, pubkey, seckey, message) => {
|
||||
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();
|
||||
});
|
||||
|
||||
module.exports.ed25519Verify = withWasm((wasm, signature, message, pubkey) => {
|
||||
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;
|
||||
});
|
||||
|
||||
module.exports.blake2b = withWasm((wasm, data, key, size) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(key);
|
||||
|
||||
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.keccak256 = withWasm((wasm, data) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_keccak256(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.pbkdf2 = withWasm((wasm, data, salt, rounds) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
|
||||
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.scrypt = withWasm((wasm, password, salt, log2n, r, p) => {
|
||||
const [ptr0, len0] = allocU8a(password);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
|
||||
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sha512 = withWasm((wasm, data) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_sha512(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.twox = withWasm((wasm, data, rounds) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_twox(8, ptr0, len0, rounds);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sr25519DeriveKeypairHard = withWasm((wasm, pair, cc) => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sr25519DeriveKeypairSoft = withWasm((wasm, pair, cc) => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sr25519DerivePublicSoft = withWasm((wasm, pubkey, cc) => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sr25519KeypairFromSeed = withWasm((wasm, seed) => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
|
||||
wasm.ext_sr_from_seed(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
});
|
||||
|
||||
module.exports.sr25519Sign = withWasm((wasm, pubkey, secret, message) => {
|
||||
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();
|
||||
});
|
||||
|
||||
module.exports.sr25519Verify = withWasm((wasm, signature, message, pubkey) => {
|
||||
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;
|
||||
});
|
||||
|
||||
module.exports.isReady = function () {
|
||||
return !!getWasm();
|
||||
};
|
||||
|
||||
module.exports.waitReady = function () {
|
||||
return wasmPromise.then(() => !!getWasm());
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @polkadot/wasm-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.
|
||||
|
||||
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,49 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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 { assert } = require('@polkadot/util');
|
||||
|
||||
const INIT_ERRROR = '@polkadot/wasm-crypto has not been initialized';
|
||||
|
||||
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),
|
||||
|
||||
// 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
|
||||
};
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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 @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,27 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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, { './wasm': 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 @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.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Use `wee_alloc` as the global allocator.
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
#[path = "rs/bip39.rs"]
|
||||
pub mod bip39;
|
||||
|
||||
#[path = "rs/ed25519.rs"]
|
||||
pub mod ed25519;
|
||||
|
||||
#[path = "rs/hashing.rs"]
|
||||
pub mod hashing;
|
||||
|
||||
#[path = "rs/sr25519.rs"]
|
||||
pub mod sr25519;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Copyright 2019 @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.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||
use hmac::Hmac;
|
||||
@@ -48,7 +47,7 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
|
||||
result[..32].to_vec()
|
||||
}
|
||||
|
||||
/// Creates a see from a bip-39 phrase
|
||||
/// Creates a BTC/ETH compatible seed from a bip-39 phrase
|
||||
///
|
||||
/// @phrase: mnemonic phrase
|
||||
///
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2019 @polkadot/wasm-dalek-ed25519 authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature};
|
||||
use std::convert::TryFrom;
|
||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Keypair helper function.
|
||||
@@ -14,27 +14,27 @@ fn create_from_pair(pair: &[u8]) -> Keypair {
|
||||
}
|
||||
|
||||
/// Keypair helper function
|
||||
fn create_from_parts(public: &[u8], secret: &[u8]) -> Keypair {
|
||||
fn create_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
|
||||
let mut pair = vec![];
|
||||
|
||||
pair.extend_from_slice(secret);
|
||||
pair.extend_from_slice(public);
|
||||
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 secret = SecretKey::from_bytes(seed).unwrap();
|
||||
let public: PublicKey = (&secret).into();
|
||||
let seckey = SecretKey::from_bytes(seed).unwrap();
|
||||
let pubkey: PublicKey = (&seckey).into();
|
||||
|
||||
create_from_parts(public.as_bytes(), seed)
|
||||
create_from_parts(pubkey.as_bytes(), seed)
|
||||
}
|
||||
|
||||
/// PublicKey helper
|
||||
fn create_public(public: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(public) {
|
||||
Ok(public) => return public,
|
||||
fn create_public(pubkey: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(pubkey) {
|
||||
Ok(pubkey) => return pubkey,
|
||||
Err(_) => panic!("Provided public key is invalid.")
|
||||
}
|
||||
}
|
||||
@@ -57,14 +57,14 @@ pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
/// The combination of both public and private key must be provided.
|
||||
/// This is effectively equivalent to a keypair.
|
||||
///
|
||||
/// * public: UIntArray with 32 element
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
/// * private: UIntArray with 64 element
|
||||
/// * message: Arbitrary length UIntArray
|
||||
///
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_from_parts(public, secret)
|
||||
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_from_parts(pubkey, seckey)
|
||||
.sign(message)
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
@@ -76,13 +76,13 @@ pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * message: Arbitrary length UIntArray
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
||||
let signature = match Signature::from_bytes(signature) {
|
||||
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(public)
|
||||
create_public(pubkey)
|
||||
.verify(message, &signature)
|
||||
.is_ok()
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
// Copyright 2019 @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.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use blake2_rfc::blake2b::blake2b;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use hmac::Hmac;
|
||||
use pbkdf2::pbkdf2;
|
||||
use scrypt::{ScryptParams, scrypt};
|
||||
use sha2::{Digest, Sha512};
|
||||
// use secp256k1;
|
||||
use std::hash::Hasher;
|
||||
use tiny_keccak::keccak256;
|
||||
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);
|
||||
@@ -49,17 +49,22 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
|
||||
/// Returns the hash as a vector
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
|
||||
keccak256(data)
|
||||
.to_vec()
|
||||
let mut keccak = Keccak::v256();
|
||||
let mut result = [0u8; 32];
|
||||
|
||||
keccak.update(data);
|
||||
keccak.finalize(&mut result);
|
||||
|
||||
result.to_vec()
|
||||
}
|
||||
|
||||
/// pbkdf2 hash from an input, salt for the number of specified rounds
|
||||
/// pbkdf2 kdf from an input, salt for the number of specified rounds
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
/// * salt: Salt for this hash
|
||||
/// * rounds: The number of rounds to perform
|
||||
///
|
||||
/// Returns a vecor with the hash result
|
||||
/// 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];
|
||||
@@ -70,6 +75,26 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
result.to_vec()
|
||||
}
|
||||
|
||||
/// scrypt kdf from input, salt and config
|
||||
///
|
||||
/// * password: Password to hash
|
||||
/// * salt: Salt for this hash
|
||||
/// * log2_n: log2(n)
|
||||
/// * r: r
|
||||
/// * p: p
|
||||
///
|
||||
/// 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 scrypt(password, salt, ¶ms, &mut result) {
|
||||
Ok(_) => return result.to_vec(),
|
||||
Err(_) => panic!("Invalid scrypt hash.")
|
||||
}
|
||||
}
|
||||
|
||||
// /// Checks for the recoverability of a signature from message
|
||||
// ///
|
||||
// /// * message: The message
|
||||
@@ -126,7 +151,7 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
///
|
||||
/// Returns a vecor with the hash result
|
||||
/// Returns a vector with the hash result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
||||
let mut hasher = Sha512::new();
|
||||
@@ -143,7 +168,7 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
||||
/// * data: Arbitrary data to be hashed
|
||||
/// * 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]
|
||||
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
||||
let mut vec = vec![];
|
||||
@@ -161,7 +186,7 @@ pub mod tests {
|
||||
use hex_literal::hex;
|
||||
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> {
|
||||
// let prefix = b"Pay DOTs to the Polkadot account:";
|
||||
// let mut l = prefix.len() + data.len();
|
||||
@@ -210,6 +235,16 @@ pub mod tests {
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_scrypt() {
|
||||
let password = b"password";
|
||||
let salt = b"salt";
|
||||
let expected = hex!("745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6");
|
||||
let hash = ext_scrypt(password, salt, 14, 8, 1);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn can_secp256k1_real_eth_sig() {
|
||||
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
|
||||
@@ -1,14 +1,14 @@
|
||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||
// Copyright 2019 @polkadot/wasm-schnorrkel authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Copyright 2019 Paritytech via https://github.com/paritytech/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/
|
||||
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
|
||||
|
||||
use schnorrkel::{
|
||||
Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
|
||||
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
|
||||
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -25,38 +25,6 @@ fn create_cc(data: &[u8]) -> ChainCode {
|
||||
ChainCode(cc)
|
||||
}
|
||||
|
||||
/// Keypair helper function.
|
||||
fn create_from_seed(seed: &[u8]) -> Keypair {
|
||||
match MiniSecretKey::from_bytes(seed) {
|
||||
Ok(mini) => return mini.expand_to_keypair(),
|
||||
Err(_) => panic!("Provided seed is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.")
|
||||
}
|
||||
}
|
||||
|
||||
/// PublicKey helper
|
||||
fn create_public(public: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(public) {
|
||||
Ok(public) => return public,
|
||||
Err(_) => panic!("Provided public key is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
/// SecretKey helper
|
||||
fn create_secret(secret: &[u8]) -> SecretKey {
|
||||
match SecretKey::from_bytes(secret) {
|
||||
Ok(secret) => return secret,
|
||||
Err(_) => panic!("Provided private key is invalid.")
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform a derivation on a secret
|
||||
///
|
||||
/// * secret: UIntArray with 64 bytes
|
||||
@@ -65,10 +33,12 @@ fn create_secret(secret: &[u8]) -> SecretKey {
|
||||
/// 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> {
|
||||
create_from_pair(pair).secret
|
||||
Keypair::from_half_ed25519_bytes(pair)
|
||||
.unwrap()
|
||||
.secret
|
||||
.hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0
|
||||
.expand_to_keypair()
|
||||
.to_bytes()
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
@@ -80,9 +50,10 @@ 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> {
|
||||
create_from_pair(pair)
|
||||
Keypair::from_half_ed25519_bytes(pair)
|
||||
.unwrap()
|
||||
.derived_key_simple(create_cc(cc), &[]).0
|
||||
.to_bytes()
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
@@ -93,10 +64,12 @@ 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(public: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
create_public(public)
|
||||
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()
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// Generate a key pair.
|
||||
@@ -107,8 +80,23 @@ pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
/// followed by the public key (32) bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
create_from_seed(seed)
|
||||
.to_bytes()
|
||||
MiniSecretKey::from_bytes(seed)
|
||||
.unwrap()
|
||||
.expand_to_keypair(ExpansionMode::Ed25519)
|
||||
.to_half_ed25519_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// Generate a key pair from a known pair. (This is not exposed via WASM)
|
||||
///
|
||||
/// * seed: UIntArray with 96 element
|
||||
///
|
||||
/// 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()
|
||||
}
|
||||
|
||||
@@ -117,15 +105,16 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
/// The combination of both public and private key must be provided.
|
||||
/// This is effectively equivalent to a keypair.
|
||||
///
|
||||
/// * public: UIntArray with 32 element
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
/// * private: UIntArray with 64 element
|
||||
/// * message: Arbitrary length UIntArray
|
||||
///
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_secret(secret)
|
||||
.sign_simple(SIGNING_CTX, message, &create_public(public))
|
||||
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()
|
||||
}
|
||||
@@ -136,14 +125,13 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * message: Arbitrary length UIntArray
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
||||
let signature = match Signature::from_bytes(signature) {
|
||||
Ok(signature) => signature,
|
||||
Err(_) => return false
|
||||
};
|
||||
|
||||
create_public(public)
|
||||
.verify_simple(SIGNING_CTX, message, &signature)
|
||||
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)
|
||||
.is_ok(),
|
||||
Err(_) => false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -168,7 +156,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_pair_from_known() {
|
||||
fn creates_pair_from_known_seed() {
|
||||
let seed = hex!("fac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e");
|
||||
let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
|
||||
let keypair = ext_sr_from_seed(&seed);
|
||||
@@ -177,6 +165,16 @@ pub mod tests {
|
||||
assert_eq!(public, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_pair_from_known_pair() {
|
||||
let input = hex!("28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
|
||||
let keypair = ext_sr_from_pair(&input);
|
||||
let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a");
|
||||
let public = &keypair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||
|
||||
assert_eq!(public, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_sign_message() {
|
||||
let seed = generate_random_seed();
|
||||
@@ -204,9 +202,9 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_verify_known_message() {
|
||||
let message = b"Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n";
|
||||
let public = hex!("b4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918");
|
||||
let signature = hex!("5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202");
|
||||
let message = b"I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
|
||||
let public = hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d");
|
||||
let signature = hex!("1037eb7e51613d0dcf5930ae518819c87d655056605764840d9280984e1b7063c4566b55bf292fcab07b369d01095879b50517beca4d26e6a65866e25fec0d83");
|
||||
let is_valid = ext_sr_verify(&signature, message, &public);
|
||||
|
||||
assert!(is_valid);
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = null;
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Stub replaced at build time
|
||||
|
||||
module.exports = require('./asm-empty');
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = null;
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Stub replaced at build time
|
||||
|
||||
module.exports = require('./bytes-empty');
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -1,58 +1,66 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// @ts-check
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const { assert, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
module.exports = function (wasm) {
|
||||
function bip39_generate () {
|
||||
const RESULT = wasm.bip39Generate(21);
|
||||
function bip39_generate (wasm) {
|
||||
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_validate () {
|
||||
const RESULT = wasm.bip39Validate(wasm.bip39Generate(12));
|
||||
function bip39_generate_subsequent (wasm) {
|
||||
const val1 = wasm.bip39Generate(24);
|
||||
const val2 = wasm.bip39Generate(24);
|
||||
|
||||
console.log('\tVAL', RESULT);
|
||||
console.log('\tVL1', val1);
|
||||
console.log('\tVL2', val2);
|
||||
|
||||
assert(RESULT, 'ERROR: Invalid bip39 validation');
|
||||
}
|
||||
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
|
||||
}
|
||||
|
||||
function bip39_toEntropy () {
|
||||
const RESULT = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
||||
function bip39_validate (wasm) {
|
||||
const res = wasm.bip39Validate(wasm.bip39Generate(12));
|
||||
|
||||
console.log('\tENT', RESULT);
|
||||
console.log('\tVAL', res);
|
||||
|
||||
assert(RESULT === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
||||
}
|
||||
assert(res, 'ERROR: Invalid bip39 validation');
|
||||
}
|
||||
|
||||
function bip39_toMiniSecret () {
|
||||
const RESULT = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
||||
function bip39_toEntropy (wasm) {
|
||||
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
||||
|
||||
console.log('\tMIN', RESULT);
|
||||
console.log('\tENT', res);
|
||||
|
||||
assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
||||
}
|
||||
|
||||
function bip39_toSeed () {
|
||||
const RESULT = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
||||
function bip39_toMiniSecret (wasm) {
|
||||
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
||||
|
||||
console.log('\tSEE', RESULT);
|
||||
console.log('\tMIN', res);
|
||||
|
||||
assert(RESULT === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
|
||||
return {
|
||||
bip39_generate,
|
||||
bip39_validate,
|
||||
bip39_toEntropy,
|
||||
bip39_toMiniSecret,
|
||||
bip39_toSeed
|
||||
};
|
||||
function bip39_toSeed (wasm) {
|
||||
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
||||
|
||||
console.log('\tSEE', res);
|
||||
|
||||
assert(res === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
bip39_generate,
|
||||
bip39_generate_subsequent,
|
||||
bip39_toEntropy,
|
||||
bip39_toMiniSecret,
|
||||
bip39_toSeed,
|
||||
bip39_validate
|
||||
};
|
||||
|
||||
@@ -1,64 +1,60 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
module.exports = function (wasm) {
|
||||
function extractKeys (pair) {
|
||||
return [pair, pair.slice(32), pair.slice(0, 32)];
|
||||
function extractKeys (pair) {
|
||||
return [pair, pair.slice(32), pair.slice(0, 32)];
|
||||
}
|
||||
|
||||
function randomPair (wasm) {
|
||||
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||
}
|
||||
|
||||
function ed25519_pairFromSeed (wasm) {
|
||||
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
|
||||
|
||||
console.log('\tSEC', u8aToHex(sk));
|
||||
console.log('\tPUB', u8aToHex(pk));
|
||||
|
||||
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
|
||||
}
|
||||
|
||||
function ed25519_signAndVerify (wasm) {
|
||||
const [, pk, sk] = randomPair(wasm);
|
||||
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||
|
||||
console.log('\tSIG', u8aToHex(signature));
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function ed25519_verifyExisting (wasm) {
|
||||
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
|
||||
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function ed25519_benchmark (wasm) {
|
||||
const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const [, pk, sk] = randomPair(wasm);
|
||||
|
||||
assert(wasm.ed25519Verify(wasm.ed25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature');
|
||||
}
|
||||
}
|
||||
|
||||
function randomPair () {
|
||||
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||
}
|
||||
|
||||
function ed25519_pairFromSeed () {
|
||||
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
|
||||
|
||||
console.log('\tSEC', u8aToHex(sk));
|
||||
console.log('\tPUB', u8aToHex(pk));
|
||||
|
||||
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
|
||||
}
|
||||
|
||||
function ed25519_signAndVerify () {
|
||||
const [, pk, sk] = randomPair();
|
||||
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||
|
||||
console.log('\tSIG', u8aToHex(signature));
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function ed25519_verifyExisting () {
|
||||
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
|
||||
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function ed25519_benchmark () {
|
||||
const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const [, pk, sk] = randomPair();
|
||||
|
||||
assert(wasm.ed25519Verify(wasm.ed25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature');
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ed25519_pairFromSeed,
|
||||
ed25519_signAndVerify,
|
||||
ed25519_verifyExisting,
|
||||
ed25519_benchmark
|
||||
};
|
||||
module.exports = {
|
||||
ed25519_benchmark,
|
||||
ed25519_pairFromSeed,
|
||||
ed25519_signAndVerify,
|
||||
ed25519_verifyExisting
|
||||
};
|
||||
|
||||
@@ -1,72 +1,77 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
module.exports = function (wasm) {
|
||||
function blake2bHash () {
|
||||
const hash = u8aToHex(wasm.blake2b(stringToU8a('abc'), new Uint8Array(), 64));
|
||||
function blake2bHash (wasm) {
|
||||
const hash = u8aToHex(wasm.blake2b(stringToU8a('abc'), new Uint8Array(), 64));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
|
||||
}
|
||||
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
|
||||
}
|
||||
|
||||
function keccak256 () {
|
||||
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
|
||||
function keccak256 (wasm) {
|
||||
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
|
||||
}
|
||||
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
|
||||
}
|
||||
|
||||
function pbkdf2Hash () {
|
||||
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
|
||||
function pbkdf2Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
|
||||
}
|
||||
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
|
||||
}
|
||||
|
||||
// function secp256k1Recover () {
|
||||
// const pk = u8aToHex(wasm.keccak256(wasm.secp256k1Recover(
|
||||
// hexToU8a('0x2bbfa926ee947dfac384d981f8913b4e0992e52d7b6711e0ec3d9f8b0f752648'),
|
||||
// hexToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c')
|
||||
// )));
|
||||
// function secp256k1Recover (wasm) {
|
||||
// const pk = u8aToHex(wasm.keccak256(wasm.secp256k1Recover(
|
||||
// hexToU8a('0x2bbfa926ee947dfac384d981f8913b4e0992e52d7b6711e0ec3d9f8b0f752648'),
|
||||
// hexToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c')
|
||||
// )));
|
||||
|
||||
// console.log('\tPUB', pk);
|
||||
// console.log('\tPUB', pk);
|
||||
|
||||
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
|
||||
// }
|
||||
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
|
||||
// }
|
||||
|
||||
function sha512Hash () {
|
||||
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
||||
function scryptHash (wasm) {
|
||||
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f', 'ERROR: sha512Hash does not match');
|
||||
}
|
||||
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
|
||||
}
|
||||
|
||||
function twoxHash () {
|
||||
const hash64 = u8aToHex(wasm.twox(stringToU8a('abc'), 1));
|
||||
const hash256 = u8aToHex(wasm.twox(stringToU8a('abc'), 4));
|
||||
function sha512Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
||||
|
||||
console.log('\t64 ', hash64);
|
||||
console.log('\t256', hash256);
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash64 === '0x990977adf52cbc44' && hash256 === '0x990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b', 'ERROR: twoxHash does not match');
|
||||
}
|
||||
assert(hash === '0x309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f', 'ERROR: sha512Hash does not match');
|
||||
}
|
||||
|
||||
return {
|
||||
blake2bHash,
|
||||
keccak256,
|
||||
pbkdf2Hash,
|
||||
// secp256k1Recover,
|
||||
sha512Hash,
|
||||
twoxHash
|
||||
};
|
||||
function twoxHash (wasm) {
|
||||
const hash64 = u8aToHex(wasm.twox(stringToU8a('abc'), 1));
|
||||
const hash256 = u8aToHex(wasm.twox(stringToU8a('abc'), 4));
|
||||
|
||||
console.log('\t64 ', hash64);
|
||||
console.log('\t256', hash256);
|
||||
|
||||
assert(hash64 === '0x990977adf52cbc44' && hash256 === '0x990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b', 'ERROR: twoxHash does not match');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
blake2bHash,
|
||||
keccak256,
|
||||
pbkdf2Hash,
|
||||
scryptHash,
|
||||
// secp256k1Recover,
|
||||
sha512Hash,
|
||||
twoxHash
|
||||
};
|
||||
|
||||
@@ -1,51 +1,65 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const wasm = require('../../build/index');
|
||||
const bip39 = require('./bip39');
|
||||
const ed25519 = require('./ed25519');
|
||||
const hashing = require('./hashing');
|
||||
const sr25519 = require('./sr25519');
|
||||
|
||||
module.exports = function (wasm) {
|
||||
const tests = {
|
||||
...bip39(wasm),
|
||||
...ed25519(wasm),
|
||||
...hashing(wasm),
|
||||
...sr25519(wasm)
|
||||
};
|
||||
|
||||
return {
|
||||
beforeAll: async function beforeAll () {
|
||||
return wasm.waitReady();
|
||||
},
|
||||
runAll: function runAll () {
|
||||
const failed = [];
|
||||
let count = 0;
|
||||
|
||||
Object.keys(tests).forEach((name) => {
|
||||
count++;
|
||||
|
||||
try {
|
||||
console.time(name);
|
||||
console.log();
|
||||
console.log(name);
|
||||
|
||||
tests[name]();
|
||||
|
||||
console.timeEnd(name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
failed.push(name);
|
||||
}
|
||||
});
|
||||
|
||||
if (failed.length) {
|
||||
throw new Error(`Failed: ${failed.length} of ${count}: ${failed.concat(', ')}`);
|
||||
}
|
||||
},
|
||||
tests
|
||||
};
|
||||
const tests = {
|
||||
...bip39,
|
||||
...ed25519,
|
||||
...hashing,
|
||||
...sr25519
|
||||
};
|
||||
|
||||
function beforeAll () {
|
||||
return wasm.waitReady();
|
||||
}
|
||||
|
||||
function runAll () {
|
||||
const failed = [];
|
||||
let count = 0;
|
||||
|
||||
Object.keys(tests).forEach((name) => {
|
||||
count++;
|
||||
|
||||
try {
|
||||
console.time(name);
|
||||
console.log();
|
||||
console.log(name);
|
||||
|
||||
tests[name](wasm);
|
||||
|
||||
console.timeEnd(name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
failed.push(name);
|
||||
}
|
||||
});
|
||||
|
||||
if (failed.length) {
|
||||
throw new Error(`Failed: ${failed.length} of ${count}: ${failed.concat(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
function runUnassisted () {
|
||||
(async () => {
|
||||
await beforeAll();
|
||||
|
||||
runAll();
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
beforeAll,
|
||||
runAll,
|
||||
runUnassisted,
|
||||
tests,
|
||||
wasm
|
||||
};
|
||||
|
||||
@@ -1,127 +1,135 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
module.exports = function (wasm) {
|
||||
function extractKeys (pair) {
|
||||
return [pair, pair.slice(64), pair.slice(0, 64)];
|
||||
function extractKeys (pair) {
|
||||
return [pair, pair.slice(64), pair.slice(0, 64)];
|
||||
}
|
||||
|
||||
function randomPair (wasm) {
|
||||
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||
}
|
||||
|
||||
function sr25519_pairFromSeed (wasm) {
|
||||
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(pair.slice(64)));
|
||||
|
||||
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
|
||||
}
|
||||
|
||||
function sr25519_devFromSeed (wasm) {
|
||||
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(pair.slice(64)));
|
||||
|
||||
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
|
||||
}
|
||||
|
||||
function sr25519_verifyExisting (wasm) {
|
||||
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
|
||||
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
||||
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
|
||||
|
||||
const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK);
|
||||
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
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) {
|
||||
const [, pk, sk] = randomPair(wasm);
|
||||
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||
|
||||
console.log('\tSIG', u8aToHex(signature));
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function sr25519_deriveHard (wasm) {
|
||||
const [pair] = randomPair(wasm);
|
||||
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||
}
|
||||
|
||||
function sr25519_deriveHardKnown (wasm) {
|
||||
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
|
||||
const publicKey = u8aToHex(derived.slice(64));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', publicKey);
|
||||
|
||||
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_deriveSoft (wasm) {
|
||||
const [pair] = randomPair(wasm);
|
||||
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||
}
|
||||
|
||||
function sr25519_deriveSoftKnown (wasm) {
|
||||
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
const publicKey = u8aToHex(derived.slice(64));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', publicKey);
|
||||
|
||||
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_deriveSoftPubkey (wasm) {
|
||||
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
|
||||
|
||||
console.log('\tPUB', derived);
|
||||
|
||||
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_benchmark (wasm) {
|
||||
const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const [, pk, sk] = randomPair(wasm);
|
||||
|
||||
assert(wasm.sr25519Verify(wasm.sr25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature');
|
||||
}
|
||||
}
|
||||
|
||||
function randomPair () {
|
||||
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||
}
|
||||
|
||||
function sr25519_pairFromSeed () {
|
||||
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(pair.slice(64)));
|
||||
|
||||
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
|
||||
}
|
||||
|
||||
function sr25519_devFromSeed () {
|
||||
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(pair.slice(64)));
|
||||
|
||||
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
|
||||
}
|
||||
|
||||
function sr25519_verifyExisting () {
|
||||
const PK = hexToU8a('0xb4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918');
|
||||
const MESSAGE = stringToU8a('Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n');
|
||||
const SIGNATURE = hexToU8a('0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202');
|
||||
|
||||
const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK);
|
||||
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function sr25519_signAndVerify () {
|
||||
const [, pk, sk] = randomPair();
|
||||
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||
|
||||
console.log('\tSIG', u8aToHex(signature));
|
||||
console.log('\tRES', isValid);
|
||||
|
||||
assert(isValid, 'ERROR: Unable to verify signature');
|
||||
}
|
||||
|
||||
function sr25519_deriveHard () {
|
||||
const [pair] = randomPair();
|
||||
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||
}
|
||||
|
||||
function sr25519_deriveHardKnown () {
|
||||
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
|
||||
const publicKey = u8aToHex(derived.slice(64));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', publicKey);
|
||||
|
||||
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_deriveSoft () {
|
||||
const [pair] = randomPair();
|
||||
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||
}
|
||||
|
||||
function sr25519_deriveSoftKnown () {
|
||||
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||
const publicKey = u8aToHex(derived.slice(64));
|
||||
|
||||
console.log('\tSEC', u8aToHex(derived.slice(0, 64)));
|
||||
console.log('\tPUB', publicKey);
|
||||
|
||||
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_deriveSoftPubkey () {
|
||||
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
|
||||
|
||||
console.log('\tPUB', derived);
|
||||
|
||||
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||
}
|
||||
|
||||
function sr25519_benchmark () {
|
||||
const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const [, pk, sk] = randomPair();
|
||||
|
||||
assert(wasm.sr25519Verify(wasm.sr25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature');
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
sr25519_pairFromSeed,
|
||||
sr25519_devFromSeed,
|
||||
sr25519_deriveHard,
|
||||
sr25519_deriveHardKnown,
|
||||
sr25519_deriveSoft,
|
||||
sr25519_deriveSoftKnown,
|
||||
sr25519_deriveSoftPubkey,
|
||||
sr25519_signAndVerify,
|
||||
sr25519_verifyExisting,
|
||||
sr25519_benchmark
|
||||
};
|
||||
module.exports = {
|
||||
sr25519_benchmark,
|
||||
sr25519_deriveHard,
|
||||
sr25519_deriveHardKnown,
|
||||
sr25519_deriveSoft,
|
||||
sr25519_deriveSoftKnown,
|
||||
sr25519_deriveSoftPubkey,
|
||||
sr25519_devFromSeed,
|
||||
sr25519_pairFromSeed,
|
||||
sr25519_signAndVerify,
|
||||
sr25519_sign_deterministic,
|
||||
sr25519_verifyExisting
|
||||
};
|
||||
|
||||
@@ -1,28 +1,13 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// @ts-ignore
|
||||
global.WebAssembly = null;
|
||||
|
||||
require('override-require')(
|
||||
(request) => request === './wasm_asm_stub',
|
||||
// @ts-ignore
|
||||
() => require('../build/wasm_asm')
|
||||
(request) => request.endsWith('wasm/asm-empty'),
|
||||
() => require('../build/wasm/asm')
|
||||
);
|
||||
|
||||
// @ts-ignore
|
||||
const wasm = require('../build/index');
|
||||
const { beforeAll, runAll } = require('./all')(wasm);
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
(async () => {
|
||||
await beforeAll();
|
||||
|
||||
runAll();
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
process.exit(-1);
|
||||
});
|
||||
runUnassisted();
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// @ts-ignore
|
||||
require('../build/crypto-polyfill');
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
// @ts-ignore
|
||||
const wasm = require('../build/index');
|
||||
const { beforeAll, tests } = require('./all')(wasm);
|
||||
const { beforeAll, tests, wasm } = require('./all');
|
||||
|
||||
describe('schnorrkel-js', () => {
|
||||
beforeEach(beforeAll);
|
||||
describe('wasm-crypto', () => {
|
||||
beforeEach(async () => {
|
||||
await beforeAll();
|
||||
});
|
||||
|
||||
Object.keys(tests).forEach((name) => {
|
||||
it(name, tests[name]);
|
||||
it(name, () => tests[name](wasm));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019 @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.
|
||||
// @ts-check
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// @ts-ignore
|
||||
const wasm = require('../build/index');
|
||||
const { beforeAll, runAll } = require('./all')(wasm);
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
(async () => {
|
||||
await beforeAll();
|
||||
|
||||
runAll();
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
process.exit(-1);
|
||||
});
|
||||
runUnassisted();
|
||||
|
||||
+30
-56
@@ -1,79 +1,53 @@
|
||||
#!/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
|
||||
# also change in install-build-deps
|
||||
RUST_VER=nightly-2020-10-25
|
||||
|
||||
WSM=pkg/wasm_bg.wasm
|
||||
OPT=pkg/wasm_opt.wasm
|
||||
ASM=build/wasm/asm.js
|
||||
|
||||
echo "*** Building package"
|
||||
|
||||
# cleanup old
|
||||
echo "*** Cleaning old builds"
|
||||
rm -rf ./build ./pkg
|
||||
mkdir -p build/wasm
|
||||
|
||||
# build new via nightly & wasm-pack
|
||||
# copy our package interfaces
|
||||
echo "*** Copying package sources"
|
||||
cp package.json build/
|
||||
cp src/index.d.ts src/*.js build/
|
||||
cp src/wasm/* build/wasm/
|
||||
|
||||
# build new via wasm-pack
|
||||
echo "*** Building WASM output"
|
||||
rustup run nightly wasm-pack build --release --scope polkadot --target nodejs
|
||||
mv pkg build
|
||||
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
|
||||
../../bindgen/wasm-bindgen target/wasm32-unknown-unknown/release/wasm.wasm --out-dir pkg --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 base64"
|
||||
node ../../scripts/pack-wasm-base64.js
|
||||
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 output, sadly there are no node-js outputs above
|
||||
sed -i -e 's/import {/\/\/ import {/g' $ASM
|
||||
sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $ASM
|
||||
sed -i -e 's/{abort.*},memasmFunc/schnorrkel, 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/
|
||||
|
||||
# we are swapping to a async interface for webpack support (wasm limits)
|
||||
sed -i -e 's/wasm = require/\/\/ wasm = require/g' $SRC_WASM
|
||||
|
||||
# We don't want inline requires
|
||||
sed -i -e 's/var wasm;/const crypto = require('\''crypto'\''); let wasm; const requires = { crypto };/g' $SRC_WASM
|
||||
sed -i -e 's/return addHeapObject(require(varg0));/return addHeapObject(requires[varg0]);/g' $SRC_WASM
|
||||
|
||||
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
|
||||
sed -i -e 's/const TextEncoder = require('\''util'\'')\.TextEncoder;/const { stringToU8a } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
|
||||
sed -i -e 's/let cachedTextEncoder = new /\/\/ let cachedTextEncoder = new /g' $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 's/const TextDecoder = require('\''util'\'')\.TextDecoder;/const { u8aToString } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
|
||||
sed -i -e 's/let cachedTextDecoder = new /\/\/ let cachedTextDecoder = new /g' $SRC_WASM
|
||||
sed -i -e 's/cachedTextDecoder\.decode/u8aToString/g' $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
|
||||
# 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 = /module.exports = (wbg) => /' $ASM
|
||||
rm -rf build/wasm/*-e
|
||||
|
||||
+8
-18
@@ -1,27 +1,17 @@
|
||||
#!/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
|
||||
|
||||
./scripts/install-build-deps.sh
|
||||
|
||||
echo "*** Building packages"
|
||||
cd packages
|
||||
cd packages/wasm-crypto
|
||||
|
||||
PACKAGES=( $(ls -1d *) )
|
||||
../../scripts/build-package.sh
|
||||
|
||||
for PKG in "${PACKAGES[@]}"; do
|
||||
if [ -f "$PKG/package.json" ]; then
|
||||
echo "*** Building $PKG"
|
||||
cd $PKG
|
||||
yarn test:wasm:js
|
||||
|
||||
../../scripts/build-package.sh
|
||||
../../scripts/test-package.sh
|
||||
ls -alR build
|
||||
|
||||
rm -rf build/*-e build/package.json build/README.md
|
||||
ls -al build
|
||||
|
||||
cd ..
|
||||
fi
|
||||
done
|
||||
|
||||
cd ..
|
||||
cd ../..
|
||||
|
||||
+7
-17
@@ -1,24 +1,14 @@
|
||||
#!/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
|
||||
|
||||
./scripts/install-build-deps.sh
|
||||
|
||||
echo "*** Cleaning packages"
|
||||
cd packages
|
||||
cd packages/wasm-crypto
|
||||
|
||||
PACKAGES=( $(ls -1d *) )
|
||||
rm -rf build
|
||||
cargo clean
|
||||
|
||||
for PKG in "${PACKAGES[@]}"; do
|
||||
if [ -f "$PKG/package.json" ]; then
|
||||
echo "*** Cleaning $PKG"
|
||||
cd $PKG
|
||||
|
||||
rm -rf build
|
||||
cargo clean
|
||||
|
||||
cd ..
|
||||
fi
|
||||
done
|
||||
|
||||
cd ..
|
||||
cd ../..
|
||||
|
||||
@@ -1,28 +1,67 @@
|
||||
#!/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
|
||||
|
||||
# wasm2js for wasm -> asm.js
|
||||
BINARYEN=( "wasm-opt" "wasm2js" )
|
||||
# also change in build-package
|
||||
RUST_VER=nightly-2020-10-25
|
||||
|
||||
# install wasm-pack as required
|
||||
if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||
echo "*** Installing wasm-pack"
|
||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
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`
|
||||
|
||||
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
|
||||
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||
cargo install xargo
|
||||
|
||||
# if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||
# echo "*** Installing wasm-pack"
|
||||
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
# fi
|
||||
|
||||
if [[ "$unamestr" == 'Linux' ]]; then
|
||||
echo "*** Detected Linux"
|
||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-unknown-linux-musl
|
||||
WABT_ZIP=wabt-$WABT_VER-ubuntu
|
||||
elif [[ "$unamestr" == "Darwin" ]]; then
|
||||
echo "*** Detected Mac"
|
||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-macos
|
||||
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-apple-darwin
|
||||
WABT_ZIP=wabt-$WABT_VER-macos
|
||||
else
|
||||
echo "*** Unknown platform $unamestr, unable to install wasm helper binaries"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# install binaryen as required
|
||||
if [ ! -d "binaryen" ]; then
|
||||
echo "*** Installing binaryen"
|
||||
git clone --recursive https://github.com/WebAssembly/binaryen.git
|
||||
rm -rf binaryen/test
|
||||
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
|
||||
|
||||
for BIN in "${BINARYEN[@]}"; do
|
||||
if [ ! -f "binaryen/bin/$BIN" ]; then
|
||||
echo "*** Building $BIN"
|
||||
cd binaryen
|
||||
cmake . && make $BIN
|
||||
cd ..
|
||||
fi
|
||||
done
|
||||
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
+11
@@ -0,0 +1,11 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const buffer = fs.readFileSync('./pkg/wasm_opt.wasm');
|
||||
|
||||
fs.writeFileSync('./build/wasm/bytes.js', `// Generated as part of the build, do not edit
|
||||
|
||||
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
|
||||
`);
|
||||
@@ -1,7 +0,0 @@
|
||||
/* 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,17 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "*** Testing package"
|
||||
|
||||
echo "*** Testing Rust"
|
||||
RUST_BACKTRACE=full rustup run nightly cargo test --release -- --nocapture
|
||||
|
||||
echo "*** Testing WASM"
|
||||
node ./test/wasm.js
|
||||
|
||||
echo "*** Testing ASM.js"
|
||||
node ./test/asm.js
|
||||
|
||||
echo "*** Testing via Jest"
|
||||
yarn jest ./test/jest.spec.js
|
||||
+7
-2
@@ -1,10 +1,15 @@
|
||||
{
|
||||
"extends": "./node_modules/@polkadot/dev/config/tsconfig",
|
||||
"extends": "@polkadot/dev/config/tsconfig",
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"**/build/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@polkadot/wasm-schnorrkel": [ "packages/wasm-schnorrkel/src" ]
|
||||
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||
},
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@polkadot/ts",
|
||||
"./node_modules/@types"
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "@polkadot/dev/config/tslint"
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
module.exports = {
|
||||
name: 'Polkadot JS WASM',
|
||||
exclude: '**/*+(index|e2e|spec).ts',
|
||||
excludeExternals: true,
|
||||
excludeNotExported: true,
|
||||
excludeProtected: true,
|
||||
excludePrivate: true,
|
||||
hideGenerator: true,
|
||||
includeDeclarations: false,
|
||||
out: 'docs',
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node',
|
||||
mdEngine: 'gitbook',
|
||||
stripInternal: 'true',
|
||||
theme: 'markdown'
|
||||
};
|
||||
Reference in New Issue
Block a user