Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
801ed235cf | ||
|
|
98433c7399 | ||
|
|
b537dcf3f4 | ||
|
|
eaf8ecf2c1 | ||
|
|
9f232459d9 | ||
|
|
b92661cfe0 | ||
|
|
6ca4470752 | ||
|
|
6cecb67edd | ||
|
|
91388ca10d | ||
|
|
11e2acbdb5 | ||
|
|
4e3d1b631c | ||
|
|
4f06de4844 | ||
|
|
affb3c57e3 | ||
|
|
39e762a419 | ||
|
|
fe966c8576 | ||
|
|
12c90dfb53 | ||
|
|
03aabfd6d1 | ||
|
|
49b3cf552b | ||
|
|
6300012c32 | ||
|
|
9d0773c185 | ||
|
|
96bd2f466e | ||
|
|
c6151e1a7d | ||
|
|
c0c6671bd0 | ||
|
|
2b9d90ff49 | ||
|
|
2caa6fb41a | ||
|
|
df00473ae2 | ||
|
|
2acce9283f | ||
|
|
7971624cf9 | ||
|
|
e353fe7f2c | ||
|
|
e797e7a7e4 | ||
|
|
cb91f766c7 | ||
|
|
c983de54f6 | ||
|
|
9d9b983694 | ||
|
|
6db930d03d | ||
|
|
0233a868ab | ||
|
|
ed98d4820e | ||
|
|
971d40ba18 | ||
|
|
f3e1e30838 | ||
|
|
bff8604c8a | ||
|
|
6cf4fc0989 | ||
|
|
308374c7da | ||
|
|
06bb7ae090 | ||
|
|
b236d50c3c | ||
|
|
e2ac301993 | ||
|
|
d6bdcaccd7 | ||
|
|
a7f0e68443 | ||
|
|
dc24ab5804 | ||
|
|
d5512418d2 | ||
|
|
7a8e570dfa | ||
|
|
3794a30b4b | ||
|
|
700acfe764 | ||
|
|
9b8d6e0b64 | ||
|
|
3575f57a2a | ||
|
|
8838651405 | ||
|
|
6cb8f2254a | ||
|
|
72c2a70a32 | ||
|
|
51b1d12aab | ||
|
|
93159192bb | ||
|
|
d208694d05 | ||
|
|
e7cb8a4907 | ||
|
|
01dfe6e35c | ||
|
|
a5d4c4b43c | ||
|
|
9a5107534d | ||
|
|
d50d04318e | ||
|
|
a0afa3cef6 | ||
|
|
cf20e027af | ||
|
|
b68ab94939 | ||
|
|
af94bc472d | ||
|
|
289b102b38 | ||
|
|
ba6cbc2247 | ||
|
|
379b574b84 | ||
|
|
f1c44a65b1 | ||
|
|
7ddb5ebbe5 | ||
|
|
afd2fe3228 | ||
|
|
292197a3a2 | ||
|
|
8fac7feabd | ||
|
|
ca69955332 | ||
|
|
eacb24a133 | ||
|
|
21b3dbbb94 | ||
|
|
57ff683121 | ||
|
|
8b7e35ad0b | ||
|
|
0732f053b8 | ||
|
|
831a72b519 | ||
|
|
a5dad40521 | ||
|
|
e8263b2597 | ||
|
|
9d6c0afc8e | ||
|
|
6393d078e8 | ||
|
|
c62f6493d9 | ||
|
|
e8737c403e | ||
|
|
f279a89dc7 | ||
|
|
30463cfe75 | ||
|
|
c1405bbe2e | ||
|
|
7d9dafd9e1 | ||
|
|
e0e3634714 | ||
|
|
a5818af5fe | ||
|
|
6ebec52ffc | ||
|
|
ebd96dea49 | ||
|
|
d692383d80 | ||
|
|
cefc8c97ec | ||
|
|
8ce18ff065 | ||
|
|
40a97d2206 | ||
|
|
e111d9e91d | ||
|
|
faf407d62d | ||
|
|
cf5759a324 | ||
|
|
d220a69ab1 | ||
|
|
4d8dde58dc | ||
|
|
c5b98fcd5b | ||
|
|
482576be81 | ||
|
|
fdea2aa4dc | ||
|
|
e4dbdc570d | ||
|
|
7f3146ce64 | ||
|
|
1bf001b2f3 | ||
|
|
2a99496e9a | ||
|
|
59ba89a032 | ||
|
|
be9786fc4c | ||
|
|
629140e6c3 | ||
|
|
5f46f9e698 | ||
|
|
d4daf14c77 | ||
|
|
cfdaab8f86 | ||
|
|
70ca570a66 | ||
|
|
ab7e12a30d | ||
|
|
87a95b9ab2 | ||
|
|
9aff03c5b6 | ||
|
|
adfa4fb099 | ||
|
|
5e8b3c1c24 | ||
|
|
714b9ebf48 | ||
|
|
c93dbd2d2e | ||
|
|
7139f1fe42 | ||
|
|
7e490f1f96 | ||
|
|
b6aa432b26 | ||
|
|
547e31ffef | ||
|
|
092ee15603 | ||
|
|
dd52d5158e | ||
|
|
88d8f79e3c | ||
|
|
3a1a75f99f | ||
|
|
422c23dbbd | ||
|
|
13fd02d455 | ||
|
|
b75e2e4778 | ||
|
|
43222700be | ||
|
|
05abb02b64 | ||
|
|
bf1590ab70 | ||
|
|
f9b5b9f55f | ||
|
|
25d9e21b38 | ||
|
|
77641fc43d | ||
|
|
90865fe9c1 | ||
|
|
15fbfc3c51 | ||
|
|
340b6a0cd6 | ||
|
|
064e13268a | ||
|
|
641ea0f9d8 | ||
|
|
98bc7147e3 | ||
|
|
3d9e5d49b8 | ||
|
|
8bdcfbb049 | ||
|
|
13dcd606ea | ||
|
|
6576688f92 | ||
|
|
33e63df4ad | ||
|
|
e910e9fc77 | ||
|
|
a00b36d50d | ||
|
|
0f6e143a6f | ||
|
|
854d209be8 | ||
|
|
3f50efb951 | ||
|
|
aceaa90466 | ||
|
|
63622edcf4 | ||
|
|
4a1c0563cb | ||
|
|
b34181f104 | ||
|
|
141a067b85 | ||
|
|
4c48d91f8e | ||
|
|
9158d7c066 | ||
|
|
135affe3e3 | ||
|
|
1460ce9301 | ||
|
|
8510120701 | ||
|
|
1e5b33413f | ||
|
|
16d1b28f77 | ||
|
|
33a54be279 | ||
|
|
e6bc31ac5d | ||
|
|
a7f8342458 | ||
|
|
b1752ad001 | ||
|
|
28e3f6018d | ||
|
|
1bb6db86f7 | ||
|
|
571cdabc78 | ||
|
|
11c6315409 | ||
|
|
3a1740a5a2 | ||
|
|
c725e8ee03 | ||
|
|
6650a8e160 | ||
|
|
a3d1878453 | ||
|
|
73b2109666 | ||
|
|
3c13f266df | ||
|
|
d9a4572c7c | ||
|
|
f6187ca00b | ||
|
|
c0193ba4ad | ||
|
|
a96c6337a0 | ||
|
|
ba926e920d | ||
|
|
29d1ac009a | ||
|
|
74c7e05fed | ||
|
|
8618b57ee8 | ||
|
|
bdf7fb55fb | ||
|
|
e7389c2f15 | ||
|
|
f176d0b733 | ||
|
|
81101b69a3 | ||
|
|
4625944ee4 | ||
|
|
15d1166637 | ||
|
|
40f2990895 | ||
|
|
123bb2a09c | ||
|
|
f863cb418e | ||
|
|
0510eb869a | ||
|
|
16226a1919 | ||
|
|
836fa8fb5f | ||
|
|
97f02c2dc5 | ||
|
|
a3ed8293f8 | ||
|
|
b12b73df85 | ||
|
|
f01a9b187e | ||
|
|
7898d95844 | ||
|
|
2c4f8bbe4e | ||
|
|
ef1caeb94e | ||
|
|
8837ec9386 | ||
|
|
653aa56f12 | ||
|
|
9ece350f21 | ||
|
|
bd6435053d | ||
|
|
9c5c22ddbe | ||
|
|
77622d8408 | ||
|
|
3e1249ca2c | ||
|
|
9c09490f62 | ||
|
|
c46c08d296 | ||
|
|
f4d4bb90f0 | ||
|
|
45b51adfc7 | ||
|
|
aa084bf11b | ||
|
|
0a1aec2acf | ||
|
|
463626d75c | ||
|
|
dc4203fe7c | ||
|
|
0fa386b93a | ||
|
|
5c563bb95f | ||
|
|
4a10b7b066 | ||
|
|
c31c8537be | ||
|
|
7aebad00eb | ||
|
|
7af6734e26 | ||
|
|
edcdd48830 | ||
|
|
ad4ac2e101 | ||
|
|
2a44e076c2 | ||
|
|
9ed88fe53a | ||
|
|
856bf68abd | ||
|
|
b36ad6fdf2 | ||
|
|
78d56fa82e | ||
|
|
294d30cb3b | ||
|
|
3185b23a97 | ||
|
|
a8df6878b8 | ||
|
|
148b1c1f98 | ||
|
|
355b225428 | ||
|
|
7e0cfe73f1 | ||
|
|
618d5ad6d6 | ||
|
|
23df722466 | ||
|
|
d3a90d7362 | ||
|
|
2b8ee5f655 | ||
|
|
1db2f57b8c | ||
|
|
8d93a4b665 | ||
|
|
2fca9b83c1 | ||
|
|
5be84df651 | ||
|
|
11997092c3 | ||
|
|
15788efd34 | ||
|
|
cbb7e6f9e8 | ||
|
|
141f5e6488 | ||
|
|
1c54650396 | ||
|
|
ae748a828d | ||
|
|
9d840d89e6 | ||
|
|
c03750d97c | ||
|
|
df579b6ab0 | ||
|
|
5455b1bc8c | ||
|
|
4095777139 | ||
|
|
be0a41e4b0 | ||
|
|
bf9aceb4a9 | ||
|
|
c6135e28d4 | ||
|
|
9f199fee77 | ||
|
|
d937dda6ba | ||
|
|
5bdc33d0cd | ||
|
|
511986b7cf | ||
|
|
1d7addf6ef | ||
|
|
cc63edbd5c | ||
|
|
f8efe32b43 | ||
|
|
bb748c0225 | ||
|
|
9e9535cc2b | ||
|
|
e2d0726608 | ||
|
|
5209c934a6 | ||
|
|
da946b18ce | ||
|
|
2ac68bdb18 | ||
|
|
83762d9997 | ||
|
|
311263ad83 | ||
|
|
b3ae90f330 | ||
|
|
327f35143d | ||
|
|
35b2bb2d13 | ||
|
|
08b72cc782 | ||
|
|
f5c439cee4 | ||
|
|
0eb440d93a | ||
|
|
5860c204e1 | ||
|
|
597ded7e79 | ||
|
|
1c5a9e8152 | ||
|
|
6bdeda218c | ||
|
|
e8cfce5ede | ||
|
|
2276c06826 | ||
|
|
bf1307fda2 | ||
|
|
696d369a29 | ||
|
|
d419f2e919 | ||
|
|
f966423808 | ||
|
|
15a1020321 | ||
|
|
29ab5f2e50 | ||
|
|
4ce48c701f | ||
|
|
52c5a506ac | ||
|
|
ecf02ec26d | ||
|
|
6611c3d136 | ||
|
|
e5a4d644ab | ||
|
|
90853435d8 | ||
|
|
5211b58995 | ||
|
|
a68aaeceba | ||
|
|
cfddf2bdb6 | ||
|
|
597c1bf0d0 | ||
|
|
25ecaf51bf | ||
|
|
445585309b | ||
|
|
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 |
+6
-1
@@ -1 +1,6 @@
|
|||||||
4
|
6
|
||||||
|
3.2.2
|
||||||
|
3.2.3
|
||||||
|
3.2.4
|
||||||
|
4.0.2
|
||||||
|
4.1.2
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
module.exports = require('./babel.config.js');
|
|
||||||
@@ -2,3 +2,4 @@ exclude_patterns:
|
|||||||
- "**/*.spec.js"
|
- "**/*.spec.js"
|
||||||
- "**/*.spec.ts"
|
- "**/*.spec.ts"
|
||||||
- "docs/**/*.js"
|
- "docs/**/*.js"
|
||||||
|
- "**/test/**/*.js"
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
**/binaryen/*
|
|
||||||
**/build/*
|
|
||||||
**/coverage/*
|
|
||||||
**/node_modules/*
|
|
||||||
+16
-1
@@ -1,7 +1,22 @@
|
|||||||
const base = require('@polkadot/dev/config/eslint');
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const base = require('@polkadot/dev/config/eslint.cjs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...base,
|
...base,
|
||||||
|
ignorePatterns: [
|
||||||
|
'.eslintrc.js',
|
||||||
|
'.github/**',
|
||||||
|
'.vscode/**',
|
||||||
|
'.yarn/**',
|
||||||
|
'**/binaryen/*',
|
||||||
|
'**/build/*',
|
||||||
|
'**/coverage/*',
|
||||||
|
'**/node_modules/*',
|
||||||
|
'**/pkg/*',
|
||||||
|
'**/target/*'
|
||||||
|
],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
...base.parserOptions,
|
...base.parserOptions,
|
||||||
project: [
|
project: [
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: 'Lock Threads'
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '30 1/2 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lock:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: dessant/lock-threads@v2
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GH_PAT_BOT }}
|
||||||
|
issue-lock-inactive-days: '7'
|
||||||
|
issue-lock-comment: >
|
||||||
|
This thread has been automatically locked since there has not been
|
||||||
|
any recent activity after it was closed. Please open a new issue
|
||||||
|
if you think you have a related problem or query.
|
||||||
|
pr-lock-inactive-days: '2'
|
||||||
|
pr-lock-comment: >
|
||||||
|
This pull request has been automatically locked since there
|
||||||
|
has not been any recent activity after it was closed.
|
||||||
|
Please open a new issue for related bugs.
|
||||||
@@ -2,85 +2,16 @@ name: PR
|
|||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
pr:
|
||||||
name: Linting
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
step: ['lint', 'test', 'build']
|
||||||
steps:
|
name: ${{ matrix.step }}
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: lint
|
|
||||||
run: |
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn lint
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Testing
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: ${{ matrix.step }}
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: test
|
|
||||||
run: |
|
run: |
|
||||||
rustup toolchain install nightly
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
yarn test
|
./scripts/install-build-deps.sh
|
||||||
|
yarn ${{ matrix.step }}
|
||||||
build_code:
|
|
||||||
name: Build Code
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
|
||||||
run: |
|
|
||||||
rustup toolchain install nightly
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
|
||||||
yarn build
|
|
||||||
|
|||||||
@@ -5,50 +5,24 @@ on:
|
|||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_code:
|
master:
|
||||||
name: Build Code
|
if: "! startsWith(github.event.head_commit.message, '[CI Skip]')"
|
||||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
step: ['build:release']
|
||||||
|
name: ${{ matrix.step }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_PAT }}
|
token: ${{ secrets.GH_PAT }}
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Config yarn cache
|
|
||||||
id: yarn-cache-dir-path
|
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
|
||||||
- uses: actions/cache@v1
|
|
||||||
id: yarn-cache
|
|
||||||
with:
|
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-yarn-
|
|
||||||
- name: build
|
- name: build
|
||||||
env:
|
env:
|
||||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
GH_PAT: ${{ secrets.GH_PAT }}
|
GH_PAT: ${{ secrets.GH_PAT }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
rustup toolchain install nightly
|
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
yarn polkadot-ci-ghact-build
|
./scripts/install-build-deps.sh
|
||||||
|
yarn ${{ matrix.step }}
|
||||||
dummy:
|
|
||||||
name: Dummy
|
|
||||||
if: "contains(github.event.head_commit.message, '[CI Skip]')"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [12.x]
|
|
||||||
steps:
|
|
||||||
- name: dummy
|
|
||||||
run: |
|
|
||||||
echo "Dummy skip step"
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
name: Semgrep
|
||||||
|
on:
|
||||||
|
pull_request: {}
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: returntocorp/semgrep-action@v1
|
||||||
|
with:
|
||||||
|
auditOn: push
|
||||||
|
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
|
||||||
|
publishDeployment: 1395
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
name: 'Close stale issues and PRs'
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '30 2/2 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v3
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GH_PAT_BOT }}
|
||||||
|
stale-issue-message: 'This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.'
|
||||||
|
stale-issue-label: 'stale'
|
||||||
|
exempt-issue-labels: '-size-l,-size-m,-size-s,-size-xl,-size-xs,[bug]'
|
||||||
|
days-before-stale: 21
|
||||||
|
days-before-close: 7
|
||||||
+6
-2
@@ -1,22 +1,26 @@
|
|||||||
binaryen*
|
binaryen/
|
||||||
|
bindgen/
|
||||||
build/
|
build/
|
||||||
build-docs/
|
build-docs/
|
||||||
|
bytes/
|
||||||
coverage/
|
coverage/
|
||||||
docs/.vuepress/dist/
|
docs/.vuepress/dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
pkg/
|
pkg/
|
||||||
target/
|
target/
|
||||||
tmp/
|
tmp/
|
||||||
|
wabt/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
.env.production.local
|
.env.production.local
|
||||||
.npmrc
|
.npmrc
|
||||||
|
.pnp.*
|
||||||
.yarn/*
|
.yarn/*
|
||||||
!.yarn/releases
|
!.yarn/releases
|
||||||
!.yarn/plugins
|
!.yarn/plugins
|
||||||
.pnp.*
|
!.yarn/sdks
|
||||||
cc-test-reporter
|
cc-test-reporter
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
build
|
||||||
|
coverage
|
||||||
|
packages
|
||||||
|
scripts
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
module.exports = require('@polkadot/dev/config/prettier.cjs');
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+75
File diff suppressed because one or more lines are too long
+631
File diff suppressed because one or more lines are too long
Vendored
-58
File diff suppressed because one or more lines are too long
+5
-2
@@ -1,10 +1,13 @@
|
|||||||
enableImmutableInstalls: false
|
enableImmutableInstalls: false
|
||||||
|
|
||||||
enableProgressBars: false
|
enableProgressBars: false
|
||||||
|
|
||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
spec: "@yarnpkg/plugin-interactive-tools"
|
||||||
|
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||||
|
spec: "@yarnpkg/plugin-version"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-berry.js
|
yarnPath: .yarn/releases/yarn-3.0.1.cjs
|
||||||
|
|||||||
+218
-18
@@ -1,83 +1,283 @@
|
|||||||
# 1.2.1 Feb 29, 2020
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 4.4.1 Nov 22, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add `hmacSha256` & `hmacSha512` functions
|
||||||
|
|
||||||
|
|
||||||
|
## 4.3.1 Nov 19, 2021
|
||||||
|
|
||||||
|
Contributed:
|
||||||
|
|
||||||
|
- Updated package.json to include repo (Thanks to https://github.com/v-zhzhou)
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add `keccak512` function
|
||||||
|
- Add `sha256` function
|
||||||
|
|
||||||
|
|
||||||
|
## 4.2.1 Aug 28, 2021
|
||||||
|
|
||||||
|
Contributed:
|
||||||
|
|
||||||
|
- Add sr25519 agreement external (Thanks to https://github.com/shelvenzhou)
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Adjust tests to align with JS coding standards
|
||||||
|
- Allow for optional build with Rust stable bootstrap
|
||||||
|
|
||||||
|
|
||||||
|
## 4.1.2 Jul 9, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Bump `@polkadot/dev` to allow for bundles with new-format
|
||||||
|
|
||||||
|
|
||||||
|
## 4.1.1 Jul 7, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add an explicit `engines` field to `package.json`
|
||||||
|
- Allow building as a completely stand-alone browser bundle (experimental)
|
||||||
|
|
||||||
|
|
||||||
|
## 4.0.2 Mar 5, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add import indirection for both CJS & ESM (where generated source file is commonjs)
|
||||||
|
|
||||||
|
|
||||||
|
## 4.0.1 Mar 4, 2021
|
||||||
|
|
||||||
|
**Important** In the 4.0 version the default package type has been changed to ESM modules by default. This should not affect usage, however since the output formats changed, a new major version is required.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Build to ESM by default (with cjs versions via export map)
|
||||||
|
|
||||||
|
|
||||||
|
## 3.2.4 Feb 24, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Cleanup implicit dependencies, perform base64 decoding using base64-js
|
||||||
|
|
||||||
|
|
||||||
|
## 3.2.3 Feb 16, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Change package detect import to use `.js` source, not `.json`
|
||||||
|
|
||||||
|
|
||||||
|
## 3.2.2 Jan 24, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Remove `module` field in `package.json`
|
||||||
|
|
||||||
|
|
||||||
|
## 3.2.1 Jan 22, 2021
|
||||||
|
|
||||||
|
Contributed:
|
||||||
|
|
||||||
|
- Expose sr25519 `ext_vrf_{sign, verify}` methods (Thanks to https://github.com/stiiifff)
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add explicit `.editorconfig` for Rust sources
|
||||||
|
- Remove unused code bundles (`vrf_{sign,verify}_extra`, `secp256k1` with tests)
|
||||||
|
- Test run wrapper cleanups
|
||||||
|
|
||||||
|
|
||||||
|
## 3.1.1 Dec 19, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Single-instance package detection
|
||||||
|
- Adjust WASM inflate with localized methods
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.1 Dec 13, 2020
|
||||||
|
|
||||||
|
**Important** This assumes `@polkadot/util` 5+ peerDependencies
|
||||||
|
**Important** While this package contains no external interface changes, it doe now compile and ship both cjs and esm modules. This means that modern bundlers will have more information for tree-shaking available. Additionally when using Node with `.mjs` extensions, the esm version imports will be used on recent Node versions. Adding an export map, as here, may have some impacts so a major semver bump is advised. There may be (small) dragons hiding in the dark corners...
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Build and expose both cjs and esm via exports map
|
||||||
|
- Split wasm and asmjs files into the `@polkadot/wasm-crypto-{wasm,asmjs}` packages
|
||||||
|
- Add fflate WASM compression, with 180K raw savings (37K over-the-wire)
|
||||||
|
- Convert the package to full TypeScript sources
|
||||||
|
|
||||||
|
|
||||||
|
## 2.0.1 Nov 8, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Rework generation of WASM interfaces (proper cross-platform JS support)
|
||||||
|
- Remove explicit `crypto` dependency, this is now applied by `@polkadot/x-randomvalues`
|
||||||
|
- Build via xargo for panic abort, an overall small sizes without stack (Pinned nightly)
|
||||||
|
- Move Rust library sources in to `rs/` subfolder
|
||||||
|
|
||||||
|
|
||||||
|
## 1.4.1 Aug 27, 2020
|
||||||
|
|
||||||
|
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)
|
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
|
||||||
- Unpin nightly from nightly-2020-02-17 version
|
- Unpin nightly from nightly-2020-02-17 version
|
||||||
- Swap to yarn 2 and add support for use by yarn 2 projects
|
- Swap to yarn 2 and add support for use by yarn 2 projects
|
||||||
|
|
||||||
# 1.1.1 Feb 24, 2020
|
|
||||||
|
## 1.1.1 Feb 24, 2020
|
||||||
|
|
||||||
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
|
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
|
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
|
||||||
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
|
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
|
||||||
|
|
||||||
# 1.0.1 Feb 15, 2020
|
|
||||||
|
## 1.0.1 Feb 15, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
||||||
|
|
||||||
# 0.20.1 Jan 30, 2020
|
|
||||||
|
## 0.20.1 Jan 30, 2020
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
||||||
|
|
||||||
# 0.14.1 Sep 09, 2019
|
|
||||||
|
## 0.14.1 Sep 09, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
||||||
|
|
||||||
# 0.13.1 Jul 20, 2019
|
|
||||||
|
## 0.13.1 Jul 20, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
|
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
|
||||||
|
|
||||||
# 0.12.1 Jul 17, 2019
|
|
||||||
|
## 0.12.1 Jul 17, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
|
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
|
||||||
- Security dependency bumps
|
- Security dependency bumps
|
||||||
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
||||||
|
|
||||||
# 0.11.1 May 31, 2019
|
|
||||||
|
## 0.11.1 May 31, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Security dependency bumps
|
- Security dependency bumps
|
||||||
|
|
||||||
# 0.10.1 May 09, 2019
|
|
||||||
|
## 0.10.1 May 09, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
||||||
- Added known subkey signature test (Rust & JS)
|
- Added known subkey signature test (Rust & JS)
|
||||||
|
|
||||||
# 0.9.1 Apr 29, 2019
|
|
||||||
|
## 0.9.1 Apr 29, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Dependency bumps
|
- Dependency bumps
|
||||||
|
|
||||||
# 0.8.1 Mar 31, 2019
|
|
||||||
|
## 0.8.1 Mar 31, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
||||||
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
||||||
- Improve error messaging, instead of `__wasm_malloc of null`
|
- Improve error messaging, instead of `__wasm_malloc of null`
|
||||||
|
|
||||||
# 0.7.1 Mar 30, 2019
|
|
||||||
|
## 0.7.1 Mar 30, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
||||||
|
|
||||||
# 0.6.1 Mar 27, 2019
|
|
||||||
|
## 0.6.1 Mar 27, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
||||||
|
|
||||||
# 0.5.1 Mar 23, 2019
|
|
||||||
|
## 0.5.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add password argument to bip39ToSeed
|
- Add password argument to bip39ToSeed
|
||||||
|
|
||||||
# 0.4.1 Mar 23, 2019
|
|
||||||
|
## 0.4.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add bip39ToSeed
|
- Add bip39ToSeed
|
||||||
|
|
||||||
# 0.3.1 Mar 23, 2019
|
|
||||||
|
## 0.3.1 Mar 23, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add wasm-dalek-ed25519 for all used crypto there
|
- Add wasm-dalek-ed25519 for all used crypto there
|
||||||
- Add keccak256
|
- Add keccak256
|
||||||
- Try secp256k1 (bloating code, not used atm)
|
- Try secp256k1 (bloating code, not used atm)
|
||||||
|
|
||||||
# 0.2.1 Mar 20, 2019
|
|
||||||
|
## 0.2.1 Mar 20, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Add basic crypto functions, creation of wasm-crypto package
|
- Add basic crypto functions, creation of wasm-crypto package
|
||||||
- blake2, bip39, sha2, xxhash
|
- blake2, bip39, sha2, xxhash
|
||||||
|
|
||||||
# 0.1.1 Mar 18, 2019
|
|
||||||
|
## 0.1.1 Mar 18, 2019
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
module.exports = require('@polkadot/dev/config/babel-config-cjs.cjs');
|
||||||
@@ -1 +0,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>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const config = require('@polkadot/dev/config/jest.cjs');
|
||||||
|
|
||||||
|
module.exports = Object.assign({}, config, {
|
||||||
|
moduleNameMapper: {
|
||||||
|
'@polkadot/wasm-crypto-asmjs(.*)$': '<rootDir>/packages/wasm-crypto-asmjs/build/$1',
|
||||||
|
'@polkadot/wasm-crypto-wasm(.*)$': '<rootDir>/packages/wasm-crypto-wasm/build/$1',
|
||||||
|
// eslint-disable-next-line sort-keys
|
||||||
|
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
const config = require('@polkadot/dev/config/jest');
|
|
||||||
|
|
||||||
module.exports = Object.assign({}, config, {
|
|
||||||
moduleNameMapper: {
|
|
||||||
'@polkadot/wasm-(schnorrkel)(.*)$': '<rootDir>/packages/wasm-$1/src/$2'
|
|
||||||
},
|
|
||||||
modulePathIgnorePatterns: [
|
|
||||||
'<rootDir>/packages/wasm-schnorrkel/build'
|
|
||||||
],
|
|
||||||
resolver: './jest.resolver.js'
|
|
||||||
});
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = function resolver (file, config) {
|
|
||||||
return file.includes('package.json')
|
|
||||||
? path.join(config.basedir.replace('/src', '/'), file)
|
|
||||||
: config.defaultResolver(file, config);
|
|
||||||
};
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"npmClient": "yarn",
|
|
||||||
"useWorkspaces": true,
|
|
||||||
"command": {
|
|
||||||
"publish": {
|
|
||||||
"allowBranch": "master"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
],
|
|
||||||
"version": "1.2.1"
|
|
||||||
}
|
|
||||||
+25
-12
@@ -1,27 +1,40 @@
|
|||||||
{
|
{
|
||||||
"repository": "https://github.com/polkadot-js/wasm",
|
|
||||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm#readme",
|
||||||
"license": "Apache-2",
|
"license": "Apache-2",
|
||||||
|
"packageManager": "yarn@3.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"version": "4.4.1",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"resolutions": {
|
|
||||||
"@polkadot/dev": "^0.50.14",
|
|
||||||
"babel-core": "^7.0.0-bridge.0",
|
|
||||||
"typescript": "^3.8.3"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./scripts/build.sh",
|
"build": "yarn build:wasm",
|
||||||
"lint": "polkadot-dev-run-lint",
|
"build:release": "polkadot-ci-ghact-build",
|
||||||
|
"build:rollup": "polkadot-exec-rollup --config",
|
||||||
|
"build:wasm": "./scripts/build.sh",
|
||||||
"clean": "./scripts/clean.sh",
|
"clean": "./scripts/clean.sh",
|
||||||
|
"lint": "polkadot-dev-run-lint",
|
||||||
"postinstall": "polkadot-dev-yarn-only",
|
"postinstall": "polkadot-dev-yarn-only",
|
||||||
"test": "./scripts/test-rust.sh"
|
"test": "yarn test:wasm:rust",
|
||||||
|
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
||||||
|
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
||||||
|
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.cjs && node ./test/asm.cjs",
|
||||||
|
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.8.4",
|
"@babel/core": "^7.16.0",
|
||||||
"@polkadot/dev": "^0.50.14",
|
"@polkadot/dev": "^0.63.29",
|
||||||
"@polkadot/util": "^2.5.1",
|
"fflate": "^0.7.1",
|
||||||
"override-require": "^1.1.1"
|
"override-require": "^1.1.1"
|
||||||
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"typescript": "^4.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "Asm.js content for wasm-crypto",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-asmjs#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-crypto-asmjs",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-crypto-asmjs",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"type": "module",
|
||||||
|
"version": "4.4.1",
|
||||||
|
"browser": "empty.js",
|
||||||
|
"main": "empty.js",
|
||||||
|
"react-native": "data.js",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.16.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const asmJsInit: null;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const asmJsInit = null;
|
||||||
|
|
||||||
|
exports.asmJsInit = asmJsInit;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { asmJsInit as _asmJsInit } from './cjs/data.js';
|
||||||
|
|
||||||
|
export const asmJsInit = _asmJsInit;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const asmJsInit = null;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.4.1' };
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "Wasm content for wasm-crypto",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-wasm#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-crypto-wasm",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-crypto-wasm",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"type": "module",
|
||||||
|
"version": "4.4.1",
|
||||||
|
"browser": "data.js",
|
||||||
|
"main": "data.js",
|
||||||
|
"react-native": "data.js",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.16.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Jameson Little
|
||||||
|
//
|
||||||
|
// https://github.com/beatgammit/base64-js/blob/88957c9943c7e2a0f03cdf73e71d579e433627d3/index.js
|
||||||
|
// This only contains the toByteArray function (no encoding)
|
||||||
|
//
|
||||||
|
// Only tweaks make here are some TS adjustments (we use strict null checks), the code is otherwise as-is with
|
||||||
|
// only the single required function provided
|
||||||
|
|
||||||
|
const CODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
|
||||||
|
const lookup: string[] = [];
|
||||||
|
const revLookup: number[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < CODE.length; ++i) {
|
||||||
|
lookup[i] = CODE[i];
|
||||||
|
revLookup[CODE.charCodeAt(i)] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support decoding URL-safe base64 strings, as Node.js does.
|
||||||
|
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
||||||
|
revLookup['-'.charCodeAt(0)] = 62;
|
||||||
|
revLookup['_'.charCodeAt(0)] = 63;
|
||||||
|
|
||||||
|
function getLens (b64: string): [number, number] {
|
||||||
|
const len = b64.length;
|
||||||
|
|
||||||
|
if (len % 4 > 0) {
|
||||||
|
throw new Error('Invalid string. Length must be a multiple of 4');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim off extra bytes after placeholder bytes are found
|
||||||
|
// See: https://github.com/beatgammit/base64-js/issues/42
|
||||||
|
const validLen = b64.indexOf('=');
|
||||||
|
|
||||||
|
return validLen === -1
|
||||||
|
? [len, 0]
|
||||||
|
: [validLen, 4 - (validLen % 4)];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toByteArray (b64: string): Uint8Array {
|
||||||
|
const [validLen, placeHoldersLen] = getLens(b64);
|
||||||
|
const arr = new Uint8Array(((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen);
|
||||||
|
let curByte = 0;
|
||||||
|
let i: number;
|
||||||
|
let tmp: number;
|
||||||
|
|
||||||
|
// if there are placeholders, only get up to the last complete 4 chars
|
||||||
|
const len = placeHoldersLen > 0
|
||||||
|
? validLen - 4
|
||||||
|
: validLen;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 4) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 18) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
||||||
|
revLookup[b64.charCodeAt(i + 3)];
|
||||||
|
|
||||||
|
arr[curByte++] = (tmp >> 16) & 0xFF;
|
||||||
|
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placeHoldersLen === 2) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 2) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
||||||
|
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
} else if (placeHoldersLen === 1) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 10) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
||||||
|
|
||||||
|
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { bytes as _bytes, sizeCompressed as _sizeCompressed, sizeUncompressed as _sizeUncompressed } from './cjs/bytes';
|
||||||
|
|
||||||
|
export const bytes = _bytes;
|
||||||
|
|
||||||
|
export const sizeCompressed = _sizeCompressed;
|
||||||
|
|
||||||
|
export const sizeUncompressed = _sizeUncompressed;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const bytes = '';
|
||||||
|
export declare const sizeCompressed = 0;
|
||||||
|
export declare const sizeUncompressed = 0;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
exports.bytes = '';
|
||||||
|
|
||||||
|
exports.sizeCompressed = 0;
|
||||||
|
|
||||||
|
exports.sizeUncompressed = 0;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { toByteArray } from './base64';
|
||||||
|
import { bytes, sizeUncompressed } from './bytes';
|
||||||
|
import { unzlibSync } from './fflate';
|
||||||
|
|
||||||
|
export const wasmBytes = unzlibSync(toByteArray(bytes), new Uint8Array(sizeUncompressed));
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export const bytes = null;
|
||||||
|
|
||||||
|
export const sizeCompressed = 0;
|
||||||
|
|
||||||
|
export const sizeUncompressed = 0;
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2020 Arjun Barrett
|
||||||
|
//
|
||||||
|
// Copied from https://github.com/101arrowz/fflate/blob/73c737941ec89d85cdf0ad39ee6f26c5fdc95fd7/src/index.ts
|
||||||
|
// This only contains the unzlibSync function, no compression, no async, no workers
|
||||||
|
//
|
||||||
|
// These 2 issues are addressed as a short-term, stop-gap solution
|
||||||
|
// - https://github.com/polkadot-js/api/issues/2963
|
||||||
|
// - https://github.com/101arrowz/fflate/issues/17
|
||||||
|
//
|
||||||
|
// Only tweaks make here are some TS adjustments (we use strict null checks), the code is otherwise as-is with
|
||||||
|
// only the single required function provided (compression is still being done in the build with fflate)
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
// inflate state
|
||||||
|
type InflateState = {
|
||||||
|
// lmap
|
||||||
|
l?: Uint16Array;
|
||||||
|
// dmap
|
||||||
|
d?: Uint16Array;
|
||||||
|
// lbits
|
||||||
|
m?: number;
|
||||||
|
// dbits
|
||||||
|
n?: number;
|
||||||
|
// final
|
||||||
|
f?: number;
|
||||||
|
// pos
|
||||||
|
p?: number;
|
||||||
|
// byte
|
||||||
|
b?: number;
|
||||||
|
// lstchk
|
||||||
|
i?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
// aliases for shorter compressed code (most minifers don't do this)
|
||||||
|
const u8 = Uint8Array, u16 = Uint16Array, u32 = Uint32Array;
|
||||||
|
|
||||||
|
// code length index map
|
||||||
|
const clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
||||||
|
|
||||||
|
// fixed length extra bits
|
||||||
|
const fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
|
||||||
|
|
||||||
|
// fixed distance extra bits
|
||||||
|
// see fleb note
|
||||||
|
const fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
|
||||||
|
|
||||||
|
// get base, reverse index map from extra bits
|
||||||
|
const freb = (eb: Uint8Array, start: number) => {
|
||||||
|
const b = new u16(31);
|
||||||
|
for (let i = 0; i < 31; ++i) {
|
||||||
|
b[i] = start += 1 << eb[i - 1];
|
||||||
|
}
|
||||||
|
// numbers here are at max 18 bits
|
||||||
|
const r = new u32(b[30]);
|
||||||
|
for (let i = 1; i < 30; ++i) {
|
||||||
|
for (let j = b[i]; j < b[i + 1]; ++j) {
|
||||||
|
r[j] = ((j - b[i]) << 5) | i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [b, r] as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [fl, revfl] = freb(fleb, 2);
|
||||||
|
// we can ignore the fact that the other numbers are wrong; they never happen anyway
|
||||||
|
fl[28] = 258, revfl[258] = 28;
|
||||||
|
const [fd] = freb(fdeb, 0);
|
||||||
|
|
||||||
|
// map of value to reverse (assuming 16 bits)
|
||||||
|
const rev = new u16(32768);
|
||||||
|
for (let i = 0; i < 32768; ++i) {
|
||||||
|
// reverse table algorithm from SO
|
||||||
|
let x = ((i & 0xAAAA) >>> 1) | ((i & 0x5555) << 1);
|
||||||
|
x = ((x & 0xCCCC) >>> 2) | ((x & 0x3333) << 2);
|
||||||
|
x = ((x & 0xF0F0) >>> 4) | ((x & 0x0F0F) << 4);
|
||||||
|
rev[i] = (((x & 0xFF00) >>> 8) | ((x & 0x00FF) << 8)) >>> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create huffman tree from u8 "map": index -> code length for code index
|
||||||
|
// mb (max bits) must be at most 15
|
||||||
|
// TODO: optimize/split up?
|
||||||
|
const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
|
||||||
|
const s = cd.length;
|
||||||
|
// index
|
||||||
|
let i = 0;
|
||||||
|
// u16 "map": index -> # of codes with bit length = index
|
||||||
|
const l = new u16(mb);
|
||||||
|
// length of cd must be 288 (total # of codes)
|
||||||
|
for (; i < s; ++i) ++l[cd[i] - 1];
|
||||||
|
// u16 "map": index -> minimum code for bit length = index
|
||||||
|
const le = new u16(mb);
|
||||||
|
for (i = 0; i < mb; ++i) {
|
||||||
|
le[i] = (le[i - 1] + l[i - 1]) << 1;
|
||||||
|
}
|
||||||
|
let co: Uint16Array;
|
||||||
|
if (r) {
|
||||||
|
// u16 "map": index -> number of actual bits, symbol for code
|
||||||
|
co = new u16(1 << mb);
|
||||||
|
// bits to remove for reverser
|
||||||
|
const rvb = 15 - mb;
|
||||||
|
for (i = 0; i < s; ++i) {
|
||||||
|
// ignore 0 lengths
|
||||||
|
if (cd[i]) {
|
||||||
|
// num encoding both symbol and bits read
|
||||||
|
const sv = (i << 4) | cd[i];
|
||||||
|
// free bits
|
||||||
|
const r = mb - cd[i];
|
||||||
|
// start value
|
||||||
|
let v = le[cd[i] - 1]++ << r;
|
||||||
|
// m is end value
|
||||||
|
for (const m = v | ((1 << r) - 1); v <= m; ++v) {
|
||||||
|
// every 16 bit value starting with the code yields the same result
|
||||||
|
co[rev[v] >>> rvb] = sv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
co = new u16(s);
|
||||||
|
for (i = 0; i < s; ++i) co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);
|
||||||
|
}
|
||||||
|
return co;
|
||||||
|
});
|
||||||
|
|
||||||
|
// fixed length tree
|
||||||
|
const flt = new u8(288);
|
||||||
|
for (let i = 0; i < 144; ++i) flt[i] = 8;
|
||||||
|
for (let i = 144; i < 256; ++i) flt[i] = 9;
|
||||||
|
for (let i = 256; i < 280; ++i) flt[i] = 7;
|
||||||
|
for (let i = 280; i < 288; ++i) flt[i] = 8;
|
||||||
|
// fixed distance tree
|
||||||
|
const fdt = new u8(32);
|
||||||
|
for (let i = 0; i < 32; ++i) fdt[i] = 5;
|
||||||
|
|
||||||
|
// fixed length map
|
||||||
|
const flrm = hMap(flt, 9, 1);
|
||||||
|
// fixed distance map
|
||||||
|
const fdrm = hMap(fdt, 5, 1);
|
||||||
|
|
||||||
|
// read d, starting at bit p and mask with m
|
||||||
|
const bits = (d: Uint8Array, p: number, m: number) => {
|
||||||
|
const o = p >>> 3;
|
||||||
|
return ((d[o] | (d[o + 1] << 8)) >>> (p & 7)) & m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read d, starting at bit p continuing for at least 16 bits
|
||||||
|
const bits16 = (d: Uint8Array, p: number) => {
|
||||||
|
const o = p >>> 3;
|
||||||
|
return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >>> (p & 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
// get end of byte
|
||||||
|
const shft = (p: number) => (p >>> 3) + (p & 7 && 1);
|
||||||
|
|
||||||
|
// typed array slice - allows garbage collector to free original reference,
|
||||||
|
// while being more compatible than .slice
|
||||||
|
const slc = <T extends Uint8Array | Uint16Array | Uint32Array>(v: T, s: number, e?: number): T => {
|
||||||
|
if (s == null || s < 0) s = 0;
|
||||||
|
if (e == null || e > v.length) e = v.length;
|
||||||
|
// can't use .constructor in case user-supplied
|
||||||
|
const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s) as T;
|
||||||
|
n.set(v.subarray(s, e));
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find max of array
|
||||||
|
const max = (a: Uint8Array | number[]) => {
|
||||||
|
let m = a[0];
|
||||||
|
for (let i = 1; i < a.length; ++i) {
|
||||||
|
if (a[i] > m) m = a[i];
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
};
|
||||||
|
|
||||||
|
// expands raw DEFLATE data
|
||||||
|
const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
|
||||||
|
const noSt = !st || st.i;
|
||||||
|
if (!st) st = {};
|
||||||
|
// source length
|
||||||
|
const sl = dat.length;
|
||||||
|
// have to estimate size
|
||||||
|
const noBuf = !buf || !noSt;
|
||||||
|
// Assumes roughly 33% compression ratio average
|
||||||
|
if (!buf) buf = new u8(sl * 3);
|
||||||
|
// ensure buffer can fit at least l elements
|
||||||
|
const cbuf = (l: number) => {
|
||||||
|
let bl = buf!.length;
|
||||||
|
// need to increase size to fit
|
||||||
|
if (l > bl) {
|
||||||
|
// Double or set to necessary, whichever is greater
|
||||||
|
const nbuf = new u8(Math.max(bl << 1, l));
|
||||||
|
nbuf.set(buf!);
|
||||||
|
buf = nbuf;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// last chunk bitpos bytes
|
||||||
|
let final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
|
||||||
|
if (final && !lm) return buf;
|
||||||
|
// total bits
|
||||||
|
const tbts = sl << 3;
|
||||||
|
do {
|
||||||
|
if (!lm) {
|
||||||
|
// BFINAL - this is only 1 when last chunk is next
|
||||||
|
st.f = final = bits(dat, pos, 1);
|
||||||
|
// type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
|
||||||
|
const type = bits(dat, pos + 1, 3);
|
||||||
|
pos += 3;
|
||||||
|
if (!type) {
|
||||||
|
// go to end of byte boundary
|
||||||
|
const s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
|
||||||
|
if (t > sl) {
|
||||||
|
if (noSt) throw 'unexpected EOF';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// ensure size
|
||||||
|
if (noBuf) cbuf(bt + l);
|
||||||
|
// Copy over uncompressed data
|
||||||
|
buf.set(dat.subarray(s, t), bt);
|
||||||
|
// Get new bitpos, update byte count
|
||||||
|
st.b = bt += l, st.p = pos = t << 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
|
||||||
|
else if (type == 2) {
|
||||||
|
// literal lengths
|
||||||
|
const hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
|
||||||
|
const tl = hLit + bits(dat, pos + 5, 31) + 1;
|
||||||
|
pos += 14;
|
||||||
|
// length+distance tree
|
||||||
|
const ldt = new u8(tl);
|
||||||
|
// code length tree
|
||||||
|
const clt = new u8(19);
|
||||||
|
for (let i = 0; i < hcLen; ++i) {
|
||||||
|
// use index map to get real code
|
||||||
|
clt[clim[i]] = bits(dat, pos + i * 3, 7);
|
||||||
|
}
|
||||||
|
pos += hcLen * 3;
|
||||||
|
// code lengths bits
|
||||||
|
const clb = max(clt), clbmsk = (1 << clb) - 1;
|
||||||
|
if (!noSt && pos + tl * (clb + 7) > tbts) break;
|
||||||
|
// code lengths map
|
||||||
|
const clm = hMap(clt, clb, 1);
|
||||||
|
for (let i = 0; i < tl;) {
|
||||||
|
const r = clm[bits(dat, pos, clbmsk)];
|
||||||
|
// bits read
|
||||||
|
pos += r & 15;
|
||||||
|
// symbol
|
||||||
|
const s = r >>> 4;
|
||||||
|
// code length to copy
|
||||||
|
if (s < 16) {
|
||||||
|
ldt[i++] = s;
|
||||||
|
} else {
|
||||||
|
// copy count
|
||||||
|
let c = 0, n = 0;
|
||||||
|
if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
|
||||||
|
else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;
|
||||||
|
else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
|
||||||
|
while (n--) ldt[i++] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// length tree distance tree
|
||||||
|
const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
||||||
|
// max length bits
|
||||||
|
lbt = max(lt);
|
||||||
|
// max dist bits
|
||||||
|
dbt = max(dt);
|
||||||
|
lm = hMap(lt, lbt, 1);
|
||||||
|
dm = hMap(dt, dbt, 1);
|
||||||
|
} else throw 'invalid block type';
|
||||||
|
if (pos > tbts) throw 'unexpected EOF';
|
||||||
|
}
|
||||||
|
// Make sure the buffer can hold this + the largest possible addition
|
||||||
|
// maximum chunk size (practically, theoretically infinite) is 2^17;
|
||||||
|
if (noBuf) cbuf(bt + 131072);
|
||||||
|
const lms = (1 << lbt!) - 1, dms = (1 << dbt!) - 1;
|
||||||
|
const mxa = lbt! + dbt! + 18;
|
||||||
|
while (noSt || pos + mxa < tbts) {
|
||||||
|
// bits read, code
|
||||||
|
const c = lm[bits16(dat, pos) & lms], sym = c >>> 4;
|
||||||
|
pos += c & 15;
|
||||||
|
if (pos > tbts) throw 'unexpected EOF';
|
||||||
|
if (!c) throw 'invalid length/literal';
|
||||||
|
if (sym < 256) buf[bt++] = sym;
|
||||||
|
else if (sym == 256) {
|
||||||
|
lm = undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let add = sym - 254;
|
||||||
|
// no extra bits needed if less
|
||||||
|
if (sym > 264) {
|
||||||
|
// index
|
||||||
|
const i = sym - 257, b = fleb[i];
|
||||||
|
add = bits(dat, pos, (1 << b) - 1) + fl[i];
|
||||||
|
pos += b;
|
||||||
|
}
|
||||||
|
// dist
|
||||||
|
const d = dm![bits16(dat, pos) & dms], dsym = d >>> 4;
|
||||||
|
if (!d) throw 'invalid distance';
|
||||||
|
pos += d & 15;
|
||||||
|
let dt = fd[dsym];
|
||||||
|
if (dsym > 3) {
|
||||||
|
const b = fdeb[dsym];
|
||||||
|
dt += bits16(dat, pos) & ((1 << b) - 1), pos += b;
|
||||||
|
}
|
||||||
|
if (pos > tbts) throw 'unexpected EOF';
|
||||||
|
if (noBuf) cbuf(bt + 131072);
|
||||||
|
const end = bt + add;
|
||||||
|
for (; bt < end; bt += 4) {
|
||||||
|
buf[bt] = buf[bt - dt];
|
||||||
|
buf[bt + 1] = buf[bt + 1 - dt];
|
||||||
|
buf[bt + 2] = buf[bt + 2 - dt];
|
||||||
|
buf[bt + 3] = buf[bt + 3 - dt];
|
||||||
|
}
|
||||||
|
bt = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st.l = lm, st.p = pos, st.b = bt;
|
||||||
|
if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
|
||||||
|
} while (!final);
|
||||||
|
return bt == buf.length ? buf : slc(buf, 0, bt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// zlib valid
|
||||||
|
const zlv = (d: Uint8Array) => {
|
||||||
|
if ((d[0] & 15) != 8 || (d[0] >>> 4) > 7 || ((d[0] << 8 | d[1]) % 31)) throw 'invalid zlib data';
|
||||||
|
if (d[1] & 32) throw 'invalid zlib data: preset dictionaries not supported';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands Zlib data
|
||||||
|
* @param data The data to decompress
|
||||||
|
* @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
|
||||||
|
* @returns The decompressed version of the data
|
||||||
|
*/
|
||||||
|
export function unzlibSync(data: Uint8Array, out?: Uint8Array) {
|
||||||
|
return inflt((zlv(data), data.subarray(2, -4)), out);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.4.1' };
|
||||||
Generated
+369
-481
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
||||||
description = "WASM bindings to Rust crypto libaries."
|
description = "WASM bindings to Rust crypto libraries."
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
name = "wasm"
|
name = "wasm"
|
||||||
@@ -12,28 +12,36 @@ repository = "https://github.com/polkadot-js/wasm/"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
backtrace = "0.3.38"
|
|
||||||
blake2-rfc = "0.2.18"
|
blake2-rfc = "0.2.18"
|
||||||
byteorder = "1.3.1"
|
byteorder = "1.3.1"
|
||||||
ed25519-dalek = { version = "1.0.0-pre.3", features = ["nightly"] }
|
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||||
hmac = "0.7.0"
|
hmac = "0.7.0"
|
||||||
# libsecp256k1 = "0.2.2"
|
# libsecp256k1 = "0.2.2"
|
||||||
|
merlin = { version = "2.0", default-features = false }
|
||||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||||
schnorrkel = { version = "0.8.5", features = ["nightly", "preaudit_deprecated", "u64_backend"] }
|
curve25519-dalek = { version = "2.1.0", default-features = false }
|
||||||
sha2 = "0.8.0"
|
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
|
||||||
tiny-bip39 = { version = "0.6.2", default-features = false }
|
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"] }
|
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
|
||||||
twox-hash = "1.5.0"
|
twox-hash = "1.5.0"
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "=0.2.65"
|
||||||
wee_alloc = "0.4.3"
|
wee_alloc = "0.4.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.2.0"
|
hex-literal = "0.2.0"
|
||||||
rand = { version = "0.6.5", features = ["wasm-bindgen"] }
|
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = false
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
lto = true
|
lto = true
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
|
panic = "abort"
|
||||||
|
rpath = false
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Use it -
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const { u8aToHex } = require('@polkadot/util');
|
const { u8aToHex } = require('@polkadot/util');
|
||||||
const { bio39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
const { bip39Generate, bip39ToSeed, waitReady } = require('@polkadot/wasm-crypto');
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
// first wait until the WASM has been loaded (async init)
|
// first wait until the WASM has been loaded (async init)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[dependencies]
|
||||||
|
std = { default-features = false, features = ["panic_immediate_abort"] }
|
||||||
@@ -1,28 +1,38 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/wasm-crypto",
|
|
||||||
"version": "1.2.1",
|
|
||||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
"files": [
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
"crypto-polyfill.js",
|
"contributors": [],
|
||||||
"exports.js",
|
"description": "A wasm interface layer for use by @polkadot/util-crypto",
|
||||||
"index.d.ts",
|
"engines": {
|
||||||
"index.js",
|
"node": ">=14.0.0"
|
||||||
"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"
|
|
||||||
},
|
},
|
||||||
|
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto#readme",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"maintainers": [],
|
||||||
|
"name": "@polkadot/wasm-crypto",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/wasm-crypto",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/polkadot-js/wasm.git"
|
||||||
|
},
|
||||||
|
"sideEffects": [
|
||||||
|
"./detectPackage.js",
|
||||||
|
"./detectPackage.cjs"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"version": "4.4.1",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.16.3",
|
||||||
|
"@polkadot/wasm-crypto-asmjs": "^4.4.1",
|
||||||
|
"@polkadot/wasm-crypto-wasm": "^4.4.1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/dev": "^0.50.8"
|
"@polkadot/util": "^7.9.1",
|
||||||
|
"@polkadot/x-randomvalues": "^7.9.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*"
|
"@polkadot/util": "*",
|
||||||
|
"@polkadot/x-randomvalues": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
|
|
||||||
|
import type { AsmCreator, WasmCryptoInstance } from './types';
|
||||||
|
|
||||||
|
import { assert, stringToU8a, u8aToString } from '@polkadot/util';
|
||||||
|
|
||||||
|
let wasm: WasmCryptoInstance | null = null;
|
||||||
|
let cachegetInt32: Int32Array | null = null;
|
||||||
|
let cachegetUint8: Uint8Array | null = null;
|
||||||
|
|
||||||
|
export async function initWasm (wasmBytes: Uint8Array | null, asmFn: AsmCreator | null, wbg: Record<string, WebAssembly.ImportValue>): Promise<void> {
|
||||||
|
try {
|
||||||
|
assert(typeof WebAssembly !== 'undefined' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||||
|
|
||||||
|
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||||
|
|
||||||
|
wasm = source.instance.exports as unknown as WasmCryptoInstance;
|
||||||
|
} catch (error) {
|
||||||
|
// if we have a valid supplied asm.js, return that
|
||||||
|
if (asmFn) {
|
||||||
|
wasm = asmFn(wbg);
|
||||||
|
} else {
|
||||||
|
console.error('FATAL: Unable to initialize @polkadot/wasm-crypto');
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
wasm = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME We really would love to clean this up and have a sign like (wasm, ...params) => T
|
||||||
|
// Alas, TypeScript foo is not that great today, so we sadly have an extra closure here
|
||||||
|
export function withWasm <T, F extends (...params: never[]) => T> (fn: (wasm: WasmCryptoInstance) => F): F {
|
||||||
|
return ((...params: never[]): T => {
|
||||||
|
assert(wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
|
||||||
|
|
||||||
|
return fn(wasm)(...params);
|
||||||
|
}) as unknown as F;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWasm (): WasmCryptoInstance {
|
||||||
|
return wasm!;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getInt32 (): Int32Array {
|
||||||
|
if (cachegetInt32 === null || cachegetInt32.buffer !== wasm!.memory.buffer) {
|
||||||
|
cachegetInt32 = new Int32Array(wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachegetInt32;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUint8 (): Uint8Array {
|
||||||
|
if (cachegetUint8 === null || cachegetUint8.buffer !== wasm!.memory.buffer) {
|
||||||
|
cachegetUint8 = new Uint8Array(wasm!.memory.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachegetUint8;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getU8a (ptr: number, len: number): Uint8Array {
|
||||||
|
return getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getString (ptr: number, len: number): string {
|
||||||
|
return u8aToString(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allocU8a (arg: Uint8Array): [number, number] {
|
||||||
|
const ptr = wasm!.__wbindgen_malloc(arg.length * 1);
|
||||||
|
|
||||||
|
getUint8().set(arg, ptr / 1);
|
||||||
|
|
||||||
|
return [ptr, arg.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allocString (arg: string): [number, number] {
|
||||||
|
return allocU8a(stringToU8a(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resultU8a (): Uint8Array {
|
||||||
|
const r0 = getInt32()[8 / 4 + 0];
|
||||||
|
const r1 = getInt32()[8 / 4 + 1];
|
||||||
|
const ret = getU8a(r0, r1).slice();
|
||||||
|
|
||||||
|
wasm!.__wbindgen_free(r0, r1 * 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resultString (): string {
|
||||||
|
return u8aToString(resultU8a());
|
||||||
|
}
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||||
|
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||||
|
|
||||||
|
import { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } from './bridge';
|
||||||
|
import * as imports from './imports';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
const PTR_VEC = 8;
|
||||||
|
|
||||||
|
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
|
||||||
|
|
||||||
|
export const bip39Generate = withWasm((wasm) =>
|
||||||
|
(words: 12 | 15 | 18 | 21 | 24): string => {
|
||||||
|
wasm.ext_bip39_generate(PTR_VEC, words);
|
||||||
|
|
||||||
|
return resultString();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToEntropy = withWasm((wasm) =>
|
||||||
|
(phrase: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_entropy(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToMiniSecret = withWasm((wasm) =>
|
||||||
|
(phrase: string, password: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const [ptr1, len1] = allocString(password);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_mini_secret(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39ToSeed = withWasm((wasm) =>
|
||||||
|
(phrase: string, password: string): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const [ptr1, len1] = allocString(password);
|
||||||
|
|
||||||
|
wasm.ext_bip39_to_seed(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const bip39Validate = withWasm((wasm) =>
|
||||||
|
(phrase: string): boolean => {
|
||||||
|
const [ptr0, len0] = allocString(phrase);
|
||||||
|
const ret = wasm.ext_bip39_validate(ptr0, len0);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ed25519KeypairFromSeed = withWasm((wasm) =>
|
||||||
|
(seed: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(seed);
|
||||||
|
|
||||||
|
wasm.ext_ed_from_seed(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ed25519Sign = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(seckey);
|
||||||
|
const [ptr2, len2] = allocU8a(message);
|
||||||
|
|
||||||
|
wasm.ext_ed_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ed25519Verify = withWasm((wasm) =>
|
||||||
|
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||||
|
const [ptr0, len0] = allocU8a(signature);
|
||||||
|
const [ptr1, len1] = allocU8a(message);
|
||||||
|
const [ptr2, len2] = allocU8a(pubkey);
|
||||||
|
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
|
||||||
|
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pair);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_keypair_hard(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
|
||||||
|
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pair);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_keypair_soft(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519DerivePublicSoft = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(cc);
|
||||||
|
|
||||||
|
wasm.ext_sr_derive_public_soft(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519KeypairFromSeed = withWasm((wasm) =>
|
||||||
|
(seed: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(seed);
|
||||||
|
|
||||||
|
wasm.ext_sr_from_seed(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519Sign = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(secret);
|
||||||
|
const [ptr2, len2] = allocU8a(message);
|
||||||
|
|
||||||
|
wasm.ext_sr_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519Verify = withWasm((wasm) =>
|
||||||
|
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||||
|
const [ptr0, len0] = allocU8a(signature);
|
||||||
|
const [ptr1, len1] = allocU8a(message);
|
||||||
|
const [ptr2, len2] = allocU8a(pubkey);
|
||||||
|
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sr25519Agree = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(secret);
|
||||||
|
|
||||||
|
wasm.ext_sr_agree(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const vrfSign = withWasm((wasm) =>
|
||||||
|
(secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(secret);
|
||||||
|
const [ptr1, len1] = allocU8a(context);
|
||||||
|
const [ptr2, len2] = allocU8a(message);
|
||||||
|
const [ptr3, len3] = allocU8a(extra);
|
||||||
|
|
||||||
|
wasm.ext_vrf_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const vrfVerify = withWasm((wasm) =>
|
||||||
|
(pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
|
||||||
|
const [ptr0, len0] = allocU8a(pubkey);
|
||||||
|
const [ptr1, len1] = allocU8a(context);
|
||||||
|
const [ptr2, len2] = allocU8a(message);
|
||||||
|
const [ptr3, len3] = allocU8a(extra);
|
||||||
|
const [ptr4, len4] = allocU8a(outAndProof);
|
||||||
|
const ret = wasm.ext_vrf_verify(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
||||||
|
|
||||||
|
return ret !== 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const blake2b = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
const [ptr1, len1] = allocU8a(key);
|
||||||
|
|
||||||
|
wasm.ext_blake2b(PTR_VEC, ptr0, len0, ptr1, len1, size);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const hmacSha256 = withWasm((wasm) =>
|
||||||
|
(key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(key);
|
||||||
|
const [ptr1, len1] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_hmac_sha256(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const hmacSha512 = withWasm((wasm) =>
|
||||||
|
(key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(key);
|
||||||
|
const [ptr1, len1] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_hmac_sha512(PTR_VEC, ptr0, len0, ptr1, len1);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const keccak256 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_keccak256(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const keccak512 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_keccak512(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const pbkdf2 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
const [ptr1, len1] = allocU8a(salt);
|
||||||
|
|
||||||
|
wasm.ext_pbkdf2(PTR_VEC, ptr0, len0, ptr1, len1, rounds);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const scrypt = withWasm((wasm) =>
|
||||||
|
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(password);
|
||||||
|
const [ptr1, len1] = allocU8a(salt);
|
||||||
|
|
||||||
|
wasm.ext_scrypt(PTR_VEC, ptr0, len0, ptr1, len1, log2n, r, p);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sha256 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_sha256(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const sha512 = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array): Uint8Array => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_sha512(PTR_VEC, ptr0, len0);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const twox = withWasm((wasm) =>
|
||||||
|
(data: Uint8Array, rounds: number) => {
|
||||||
|
const [ptr0, len0] = allocU8a(data);
|
||||||
|
|
||||||
|
wasm.ext_twox(PTR_VEC, ptr0, len0, rounds);
|
||||||
|
|
||||||
|
return resultU8a();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export function isReady (): boolean {
|
||||||
|
return !!getWasm();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function waitReady (): Promise<boolean> {
|
||||||
|
return wasmPromise.then(() => isReady());
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { detectPackage } from '@polkadot/util';
|
||||||
|
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||||
|
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||||
|
|
||||||
|
import { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
|
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [asmInfo, wasmInfo]);
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||||
|
|
||||||
|
import { getString, getU8a } from './bridge';
|
||||||
|
|
||||||
|
const DEFAULT_CRYPTO = { getRandomValues };
|
||||||
|
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
|
||||||
|
|
||||||
|
const heap: Array<unknown> = new Array(32).fill(undefined).concat(undefined, null, true, false);
|
||||||
|
let heapNext = heap.length;
|
||||||
|
|
||||||
|
function getObject (idx: number): unknown {
|
||||||
|
return heap[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
function dropObject (idx: number) {
|
||||||
|
if (idx < 36) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
heap[idx] = heapNext;
|
||||||
|
heapNext = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
function takeObject (idx: number): unknown {
|
||||||
|
const ret = getObject(idx);
|
||||||
|
|
||||||
|
dropObject(idx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addObject (obj: unknown): number {
|
||||||
|
if (heapNext === heap.length) {
|
||||||
|
heap.push(heap.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const idx = heapNext;
|
||||||
|
|
||||||
|
heapNext = heap[idx] as number;
|
||||||
|
heap[idx] = obj;
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbindgen_is_undefined (idx: number): boolean {
|
||||||
|
return getObject(idx) === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbg_self_1b7a39e3a92c949c (): number {
|
||||||
|
return addObject(DEFAULT_SELF);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbg_require_604837428532a733 (ptr: number, len: number): never {
|
||||||
|
throw new Error(`Unable to require ${getString(ptr, len)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_crypto_968f1772287e2df0 (_idx: number): number {
|
||||||
|
return addObject(DEFAULT_CRYPTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_getRandomValues_a3d34b4fee3c2869 (_idx: number): number {
|
||||||
|
return addObject(DEFAULT_CRYPTO.getRandomValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_getRandomValues_f5e14ab7ac8e995d (_arg0: number, ptr: number, len: number): void {
|
||||||
|
DEFAULT_CRYPTO.getRandomValues(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export function __wbg_randomFillSync_d5bd2d655fdf256a (_idx: number, _ptr: number, _len: number): never {
|
||||||
|
throw new Error('randomFillsync is not available');
|
||||||
|
|
||||||
|
// getObject(idx).randomFillSync(getU8a(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbindgen_object_drop_ref (idx: number): void {
|
||||||
|
takeObject(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function abort (): never {
|
||||||
|
throw new Error('abort');
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import './detectPackage';
|
||||||
|
|
||||||
|
export * from './bundle';
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const crypto = require('crypto');
|
|
||||||
|
|
||||||
if (!global.crypto) {
|
|
||||||
global.crypto = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.crypto.getRandomValues) {
|
|
||||||
global.crypto.getRandomValues = function (arr) {
|
|
||||||
const buffer = crypto.randomBytes(arr.length);
|
|
||||||
|
|
||||||
return buffer.reduce((arr, value, index) => {
|
|
||||||
arr[index] = value;
|
|
||||||
|
|
||||||
return arr;
|
|
||||||
}, arr);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const { 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
|
|
||||||
};
|
|
||||||
};
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string;
|
|
||||||
export function bip39ToEntropy (phrase: string): Uint8Array;
|
|
||||||
export function bip39ToMiniSecret (phrase: string, password: string): Uint8Array;
|
|
||||||
export function bip39ToSeed (phrase: string, password: string): Uint8Array;
|
|
||||||
export function bip39Validate (phrase: string): boolean;
|
|
||||||
|
|
||||||
export function ed25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
|
|
||||||
export function ed25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
|
|
||||||
export function ed25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
||||||
|
|
||||||
export function sr25519DeriveKeypairHard (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519DeriveKeypairSoft (pair: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519DerivePublicSoft (publicKey: Uint8Array, chainCode: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519Sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array;
|
|
||||||
export function sr25519Verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
|
||||||
|
|
||||||
export function blake2b (data: Uint8Array, key: Uint8Array, byteSize: number): Uint8Array;
|
|
||||||
export function keccak256 (data: Uint8Array): Uint8Array;
|
|
||||||
export function pbkdf2 (data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array;
|
|
||||||
// export function secp256k1IsRecoverable (message: Uint8Array, signature: Uint8Array): number;
|
|
||||||
// export function secp256k1Recover (message: Uint8Array, signature: Uint8Array): Uint8Array;
|
|
||||||
export function sha512 (data: Uint8Array): Uint8Array;
|
|
||||||
export function twox (data: Uint8Array, rounds: number): Uint8Array;
|
|
||||||
|
|
||||||
export function isReady (): boolean;
|
|
||||||
export function waitReady (): Promise<boolean>;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const stubbed = require('./wasm');
|
|
||||||
|
|
||||||
module.exports = require('./exports')(stubbed);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = {};
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const pkg = require('./package.json');
|
|
||||||
const asm = require('./wasm_asm_stub');
|
|
||||||
const bytes = require('./wasm_wasm');
|
|
||||||
const imports = require('./wasm');
|
|
||||||
|
|
||||||
module.exports = async function createExportPromise () {
|
|
||||||
try {
|
|
||||||
const { instance } = await WebAssembly.instantiate(bytes, { './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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Be able to import json in TS
|
||||||
|
// https://stackoverflow.com/questions/49996456/importing-json-file-in-typescript
|
||||||
|
declare module '*.json' {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const value: any;
|
||||||
|
|
||||||
|
export default value;
|
||||||
|
}
|
||||||
@@ -1,12 +1,21 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
// Use `wee_alloc` as the global allocator.
|
// Use `wee_alloc` as the global allocator.
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
|
#[path = "rs/bip39.rs"]
|
||||||
pub mod bip39;
|
pub mod bip39;
|
||||||
|
|
||||||
|
#[path = "rs/ed25519.rs"]
|
||||||
pub mod ed25519;
|
pub mod ed25519;
|
||||||
|
|
||||||
|
#[path = "rs/hashing.rs"]
|
||||||
pub mod hashing;
|
pub mod hashing;
|
||||||
|
|
||||||
|
#[path = "rs/sr25519.rs"]
|
||||||
pub mod sr25519;
|
pub mod sr25519;
|
||||||
|
|
||||||
|
#[path = "rs/vrf.rs"]
|
||||||
|
pub mod vrf;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
|
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.4.1' };
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
root = true
|
||||||
|
[*]
|
||||||
|
indent_style=tab
|
||||||
|
indent_size=tab
|
||||||
|
tab_width=4
|
||||||
|
end_of_line=lf
|
||||||
|
charset=utf-8
|
||||||
|
trim_trailing_whitespace=true
|
||||||
|
max_line_length=100
|
||||||
|
insert_final_newline=true
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||||
use hmac::Hmac;
|
use hmac::Hmac;
|
||||||
@@ -48,7 +47,7 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
|
|||||||
result[..32].to_vec()
|
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
|
/// @phrase: mnemonic phrase
|
||||||
///
|
///
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use 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::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
/// Keypair helper function.
|
/// Keypair helper function.
|
||||||
@@ -14,27 +14,27 @@ fn create_from_pair(pair: &[u8]) -> Keypair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Keypair helper function
|
/// 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![];
|
let mut pair = vec![];
|
||||||
|
|
||||||
pair.extend_from_slice(secret);
|
pair.extend_from_slice(seckey);
|
||||||
pair.extend_from_slice(public);
|
pair.extend_from_slice(pubkey);
|
||||||
|
|
||||||
create_from_pair(&pair)
|
create_from_pair(&pair)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Keypair helper function.
|
/// Keypair helper function.
|
||||||
fn create_from_seed(seed: &[u8]) -> Keypair {
|
fn create_from_seed(seed: &[u8]) -> Keypair {
|
||||||
let secret = SecretKey::from_bytes(seed).unwrap();
|
let seckey = SecretKey::from_bytes(seed).unwrap();
|
||||||
let public: PublicKey = (&secret).into();
|
let pubkey: PublicKey = (&seckey).into();
|
||||||
|
|
||||||
create_from_parts(public.as_bytes(), seed)
|
create_from_parts(pubkey.as_bytes(), seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PublicKey helper
|
/// PublicKey helper
|
||||||
fn create_public(public: &[u8]) -> PublicKey {
|
fn create_public(pubkey: &[u8]) -> PublicKey {
|
||||||
match PublicKey::from_bytes(public) {
|
match PublicKey::from_bytes(pubkey) {
|
||||||
Ok(public) => return public,
|
Ok(pubkey) => return pubkey,
|
||||||
Err(_) => panic!("Provided public key is invalid.")
|
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.
|
/// The combination of both public and private key must be provided.
|
||||||
/// This is effectively equivalent to a keypair.
|
/// This is effectively equivalent to a keypair.
|
||||||
///
|
///
|
||||||
/// * public: UIntArray with 32 element
|
/// * pubkey: UIntArray with 32 element
|
||||||
/// * private: UIntArray with 64 element
|
/// * private: UIntArray with 64 element
|
||||||
/// * message: Arbitrary length UIntArray
|
/// * message: Arbitrary length UIntArray
|
||||||
///
|
///
|
||||||
/// * returned vector is the signature consisting of 64 bytes.
|
/// * returned vector is the signature consisting of 64 bytes.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
|
||||||
create_from_parts(public, secret)
|
create_from_parts(pubkey, seckey)
|
||||||
.sign(message)
|
.sign(message)
|
||||||
.to_bytes()
|
.to_bytes()
|
||||||
.to_vec()
|
.to_vec()
|
||||||
@@ -76,13 +76,13 @@ pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
|||||||
/// * message: Arbitrary length UIntArray
|
/// * message: Arbitrary length UIntArray
|
||||||
/// * pubkey: UIntArray with 32 element
|
/// * pubkey: UIntArray with 32 element
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_ed_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
pub fn ext_ed_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||||
let signature = match Signature::from_bytes(signature) {
|
let signature = match Signature::try_from(signature) {
|
||||||
Ok(signature) => signature,
|
Ok(signature) => signature,
|
||||||
Err(_) => return false
|
Err(_) => return false
|
||||||
};
|
};
|
||||||
|
|
||||||
create_public(public)
|
create_public(pubkey)
|
||||||
.verify(message, &signature)
|
.verify(message, &signature)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
use blake2_rfc::blake2b::blake2b;
|
use blake2_rfc::blake2b::blake2b;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use hmac::Hmac;
|
use hmac::{Hmac, Mac};
|
||||||
use pbkdf2::pbkdf2;
|
use pbkdf2::pbkdf2;
|
||||||
use sha2::{Digest, Sha512};
|
use scrypt::{ScryptParams, scrypt};
|
||||||
// use secp256k1;
|
use sha2::{Digest, Sha256, Sha512};
|
||||||
use tiny_keccak::{Hasher, Keccak};
|
use tiny_keccak::{Hasher, Keccak};
|
||||||
use twox_hash::XxHash;
|
use twox_hash::XxHash;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
@@ -42,6 +41,39 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
|
|||||||
.to_vec()
|
.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// hmac with sha256
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_hmac_sha256(key: &[u8], data: &[u8]) -> Vec<u8> {
|
||||||
|
match Hmac::<Sha256>::new_varkey(key){
|
||||||
|
Ok(mut mac) => {
|
||||||
|
mac.input(data);
|
||||||
|
|
||||||
|
mac
|
||||||
|
.result()
|
||||||
|
.code()
|
||||||
|
.to_vec()
|
||||||
|
},
|
||||||
|
Err(_) => panic!("Invalid key provided.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// hmac with sha512
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_hmac_sha512(key: &[u8], data: &[u8]) -> Vec<u8> {
|
||||||
|
match Hmac::<Sha512>::new_varkey(key) {
|
||||||
|
Ok(mut mac) => {
|
||||||
|
mac.input(data);
|
||||||
|
|
||||||
|
mac
|
||||||
|
.result()
|
||||||
|
.code()
|
||||||
|
.to_vec()
|
||||||
|
},
|
||||||
|
Err(_) => panic!("Invalid key provided.")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a keccak256 hash for the specified input
|
/// Create a keccak256 hash for the specified input
|
||||||
///
|
///
|
||||||
// * data: Arbitrary data to be hashed
|
// * data: Arbitrary data to be hashed
|
||||||
@@ -58,80 +90,80 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
|
|||||||
result.to_vec()
|
result.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// pbkdf2 hash from an input, salt for the number of specified rounds
|
/// Create a keccak512 hash for the specified input
|
||||||
|
///
|
||||||
|
// * data: Arbitrary data to be hashed
|
||||||
|
///
|
||||||
|
/// Returns the hash as a vector
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_keccak512(data: &[u8]) -> Vec<u8> {
|
||||||
|
let mut keccak = Keccak::v512();
|
||||||
|
let mut result = [0u8; 64];
|
||||||
|
|
||||||
|
keccak.update(data);
|
||||||
|
keccak.finalize(&mut result);
|
||||||
|
|
||||||
|
result.to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// pbkdf2 kdf from an input, salt for the number of specified rounds
|
||||||
///
|
///
|
||||||
/// * data: Arbitrary data to be hashed
|
/// * data: Arbitrary data to be hashed
|
||||||
/// * salt: Salt for this hash
|
/// * salt: Salt for this hash
|
||||||
/// * rounds: The number of rounds to perform
|
/// * rounds: The number of rounds to perform
|
||||||
///
|
///
|
||||||
/// Returns a vecor with the hash result
|
/// Returns a vector with the hashed result
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||||
let mut result = [0u8; 64];
|
let mut result = [0u8; 64];
|
||||||
|
|
||||||
// we cast to usize here - due to the WASM, we'd rather have u32 inputs
|
// we cast to usize here - due to the WASM, we'd rather have u32 inputs
|
||||||
pbkdf2::<Hmac<Sha512>>(data, salt, rounds as usize, &mut result);
|
pbkdf2::<Hmac::<Sha512>>(data, salt, rounds as usize, &mut result);
|
||||||
|
|
||||||
result.to_vec()
|
result.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Checks for the recoverability of a signature from message
|
/// scrypt kdf from input, salt and config
|
||||||
// ///
|
///
|
||||||
// /// * message: The message
|
/// * password: Password to hash
|
||||||
// /// * signature: The signature
|
/// * salt: Salt for this hash
|
||||||
// ///
|
/// * log2_n: log2(n)
|
||||||
// /// Returns 0 on success, or a specific error code
|
/// * r: r
|
||||||
// #[wasm_bindgen]
|
/// * p: p
|
||||||
// pub fn ext_secp256k1_is_recoverable(message: &[u8], signature: &[u8]) -> u32 {
|
///
|
||||||
// let rs = match secp256k1::Signature::parse_slice(&signature[0..64]) {
|
/// Returns vector with the hashed result
|
||||||
// Ok(rs) => rs,
|
#[wasm_bindgen]
|
||||||
// _ => return 1
|
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 v = match secp256k1::RecoveryId::parse(if signature[64] > 26 { signature[64] - 27 } else { signature[64] } as u8) {
|
let mut result = [0u8; 64];
|
||||||
// Ok(v) => v,
|
|
||||||
// _ => return 2
|
|
||||||
// };
|
|
||||||
// let mut msg = [0u8; 32];
|
|
||||||
|
|
||||||
// msg.copy_from_slice(&message);
|
match scrypt(password, salt, ¶ms, &mut result) {
|
||||||
|
Ok(_) => result.to_vec(),
|
||||||
|
Err(_) => panic!("Invalid scrypt hash.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
|
/// sha256 hash for the specified input
|
||||||
// Ok(_) => 0,
|
///
|
||||||
// _ => 3
|
/// * data: Arbitrary data to be hashed
|
||||||
// }
|
///
|
||||||
// }
|
/// Returns a vector with the hash result
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_sha256(data: &[u8]) -> Vec<u8> {
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
|
||||||
// /// Recovers the secp256k1 signature from the input
|
hasher.input(data);
|
||||||
// ///
|
|
||||||
// /// * message: The message
|
|
||||||
// /// * signature: The signature
|
|
||||||
// ///
|
|
||||||
// /// Returns a vector with the recovered public key
|
|
||||||
// #[wasm_bindgen]
|
|
||||||
// pub fn ext_secp256k1_recover(message: &[u8], signature: &[u8]) -> Vec<u8> {
|
|
||||||
// let rs = match secp256k1::Signature::parse_slice(&signature[0..64]) {
|
|
||||||
// Ok(rs) => rs,
|
|
||||||
// _ => panic!("Unable to recover r,s")
|
|
||||||
// };
|
|
||||||
// let v = match secp256k1::RecoveryId::parse(if signature[64] > 26 { signature[64] - 27 } else { signature[64] } as u8) {
|
|
||||||
// Ok(v) => v,
|
|
||||||
// _ => panic!("Unable to recover v")
|
|
||||||
// };
|
|
||||||
// let mut msg = [0u8; 32];
|
|
||||||
|
|
||||||
// msg.copy_from_slice(&message);
|
hasher
|
||||||
|
.result()
|
||||||
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
|
.to_vec()
|
||||||
// Ok(pk) => return pk.serialize()[1..65].to_vec(),
|
}
|
||||||
// _ => panic!("Unable to recover publickey")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// sha512 hash for the specified input
|
/// sha512 hash for the specified input
|
||||||
///
|
///
|
||||||
/// * data: Arbitrary data to be hashed
|
/// * data: Arbitrary data to be hashed
|
||||||
///
|
///
|
||||||
/// Returns a vecor with the hash result
|
/// Returns a vector with the hash result
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
||||||
let mut hasher = Sha512::new();
|
let mut hasher = Sha512::new();
|
||||||
@@ -148,7 +180,7 @@ pub fn ext_sha512(data: &[u8]) -> Vec<u8> {
|
|||||||
/// * data: Arbitrary data to be hashed
|
/// * data: Arbitrary data to be hashed
|
||||||
/// * rounds: Number of 8-byte rounds to add to the output
|
/// * rounds: Number of 8-byte rounds to add to the output
|
||||||
///
|
///
|
||||||
/// Returns a vecor with the hash result
|
/// Returns a vector with the hash result
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
pub fn ext_twox(data: &[u8], rounds: u32) -> Vec<u8> {
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
@@ -166,24 +198,6 @@ pub mod tests {
|
|||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// // Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign.
|
|
||||||
// fn ethereum_signable_message(data: &[u8]) -> Vec<u8> {
|
|
||||||
// let prefix = b"Pay DOTs to the Polkadot account:";
|
|
||||||
// let mut l = prefix.len() + data.len();
|
|
||||||
// let mut rev = Vec::new();
|
|
||||||
// let mut v = b"\x19Ethereum Signed Message:\n".to_vec();
|
|
||||||
|
|
||||||
// while l > 0 {
|
|
||||||
// rev.push(b'0' + (l % 10) as u8);
|
|
||||||
// l /= 10;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// v.extend(rev.into_iter().rev());
|
|
||||||
// v.extend_from_slice(&prefix[..]);
|
|
||||||
// v.extend_from_slice(data);
|
|
||||||
// v
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_blake2b() {
|
fn can_blake2b() {
|
||||||
let data = b"abc";
|
let data = b"abc";
|
||||||
@@ -205,6 +219,35 @@ pub mod tests {
|
|||||||
assert_eq!(hash[..], expected[..]);
|
assert_eq!(hash[..], expected[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_hmac_sha256() {
|
||||||
|
let key = b"secret";
|
||||||
|
let data = b"some message";
|
||||||
|
let expected = hex!("f28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7");
|
||||||
|
let hash = ext_hmac_sha256(key, data);
|
||||||
|
|
||||||
|
assert_eq!(hash[..], expected[..]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_hmac_sha512() {
|
||||||
|
let key = b"secret";
|
||||||
|
let data = b"some message";
|
||||||
|
let expected = hex!("295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841");
|
||||||
|
let hash = ext_hmac_sha512(key, data);
|
||||||
|
|
||||||
|
assert_eq!(hash[..], expected[..]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_keccak512() {
|
||||||
|
let data = b"test";
|
||||||
|
let expected = hex!("1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e");
|
||||||
|
let hash = ext_keccak512(data);
|
||||||
|
|
||||||
|
assert_eq!(hash[..], expected[..]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_pbkdf2() {
|
fn can_pbkdf2() {
|
||||||
let salt = b"this is a salt";
|
let salt = b"this is a salt";
|
||||||
@@ -215,16 +258,24 @@ pub mod tests {
|
|||||||
assert_eq!(hash[..], expected[..]);
|
assert_eq!(hash[..], expected[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn can_secp256k1_real_eth_sig() {
|
fn can_scrypt() {
|
||||||
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
|
let password = b"password";
|
||||||
// let pk = hex!("DF67EC7EAe23D2459694685257b6FC59d1BAA1FE");
|
let salt = b"salt";
|
||||||
// let data = [42, 0, 0, 0, 0, 0, 0, 0];
|
let expected = hex!("745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6");
|
||||||
// let msg = ext_keccak256(ðereum_signable_message(&data));
|
let hash = ext_scrypt(password, salt, 14, 8, 1);
|
||||||
// let result = ext_keccak256(&ext_secp256k1_recover(&msg[..], &sig[..]));
|
|
||||||
|
|
||||||
// assert_eq!(result[12..], pk[..]);
|
assert_eq!(hash[..], expected[..]);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_sha256() {
|
||||||
|
let data = b"hello world";
|
||||||
|
let expected = hex!("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
|
||||||
|
let hash = ext_sha256(data);
|
||||||
|
|
||||||
|
assert_eq!(hash[..], expected[..]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_sha512() {
|
fn can_sha512() {
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
|
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||||
|
//
|
||||||
// Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/
|
// Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/
|
||||||
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
|
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
|
||||||
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
|
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
|
||||||
|
|
||||||
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use schnorrkel::{
|
use schnorrkel::{
|
||||||
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
|
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
|
||||||
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
|
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
|
||||||
@@ -64,8 +65,8 @@ 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
|
/// returned vector is the derived publicKey as a array of 32 bytes
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec<u8> {
|
pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||||
PublicKey::from_bytes(public)
|
PublicKey::from_bytes(pubkey)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.derived_key_simple(create_cc(cc), &[]).0
|
.derived_key_simple(create_cc(cc), &[]).0
|
||||||
.to_bytes()
|
.to_bytes()
|
||||||
@@ -105,16 +106,16 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
|
|||||||
/// The combination of both public and private key must be provided.
|
/// The combination of both public and private key must be provided.
|
||||||
/// This is effectively equivalent to a keypair.
|
/// This is effectively equivalent to a keypair.
|
||||||
///
|
///
|
||||||
/// * public: UIntArray with 32 element
|
/// * pubkey: UIntArray with 32 element
|
||||||
/// * private: UIntArray with 64 element
|
/// * private: UIntArray with 64 element
|
||||||
/// * message: Arbitrary length UIntArray
|
/// * message: Arbitrary length UIntArray
|
||||||
///
|
///
|
||||||
/// * returned vector is the signature consisting of 64 bytes.
|
/// * returned vector is the signature consisting of 64 bytes.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||||
SecretKey::from_ed25519_bytes(secret)
|
SecretKey::from_ed25519_bytes(secret)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(public).unwrap())
|
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(pubkey).unwrap())
|
||||||
.to_bytes()
|
.to_bytes()
|
||||||
.to_vec()
|
.to_vec()
|
||||||
}
|
}
|
||||||
@@ -125,22 +126,45 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
|||||||
/// * message: Arbitrary length UIntArray
|
/// * message: Arbitrary length UIntArray
|
||||||
/// * pubkey: UIntArray with 32 element
|
/// * pubkey: UIntArray with 32 element
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||||
match Signature::from_bytes(signature) {
|
match Signature::from_bytes(signature) {
|
||||||
Ok(signature) => PublicKey::from_bytes(public).unwrap()
|
Ok(signature) => PublicKey::from_bytes(pubkey).unwrap()
|
||||||
.verify_simple(SIGNING_CTX, message, &signature)
|
.verify_simple(SIGNING_CTX, message, &signature)
|
||||||
.is_ok(),
|
.is_ok(),
|
||||||
Err(_) => false
|
Err(_) => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Key agreement between other's public key and self secret key.
|
||||||
|
///
|
||||||
|
/// * pubkey: UIntArray with 32 element
|
||||||
|
/// * secret: UIntArray with 64 element
|
||||||
|
///
|
||||||
|
/// * returned vector is the generated secret of 32 bytes.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_sr_agree(pubkey: &[u8], secret: &[u8]) -> Vec<u8> {
|
||||||
|
// The first 32 bytes holds the canonical private key
|
||||||
|
let mut key = [0u8; 32];
|
||||||
|
|
||||||
|
key.copy_from_slice(
|
||||||
|
&SecretKey::from_ed25519_bytes(secret)
|
||||||
|
.unwrap()
|
||||||
|
.to_bytes()[0..32]
|
||||||
|
);
|
||||||
|
|
||||||
|
(
|
||||||
|
&Scalar::from_canonical_bytes(key).unwrap() *
|
||||||
|
PublicKey::from_bytes(pubkey).unwrap().as_point()
|
||||||
|
).compress().0.to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate schnorrkel;
|
extern crate schnorrkel;
|
||||||
|
|
||||||
use hex_literal::hex;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use hex_literal::hex;
|
||||||
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
|
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
|
||||||
|
|
||||||
fn generate_random_seed() -> Vec<u8> {
|
fn generate_random_seed() -> Vec<u8> {
|
||||||
@@ -243,4 +267,32 @@ pub mod tests {
|
|||||||
|
|
||||||
assert_eq!(public, expected);
|
assert_eq!(public, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn key_agreement() {
|
||||||
|
let self_seed = hex!("98b3d305d5a5eace562387e47e59badd4d77e3f72cabfb10a60f8a197059f0a8");
|
||||||
|
let other_seed = hex!("9732eea001851ff862d949a1699c9971f3a26edbede2ad7922cbbe9a0701f366");
|
||||||
|
let expected = hex!("b03a0b198c34c16f35cae933d88b16341b4cef3e84e851f20e664c6a30527f4e");
|
||||||
|
let self_pair = ext_sr_from_seed(&self_seed);
|
||||||
|
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
|
||||||
|
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||||
|
let other_pair = ext_sr_from_seed(&other_seed);
|
||||||
|
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
|
||||||
|
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||||
|
|
||||||
|
assert_eq!(ext_sr_agree(self_pk, other_sk), expected);
|
||||||
|
assert_eq!(ext_sr_agree(other_pk, self_sk), expected);
|
||||||
|
|
||||||
|
let seed = generate_random_seed();
|
||||||
|
let self_pair = ext_sr_from_seed(seed.as_slice());
|
||||||
|
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
|
||||||
|
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||||
|
|
||||||
|
let seed = generate_random_seed();
|
||||||
|
let other_pair = ext_sr_from_seed(seed.as_slice());
|
||||||
|
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
|
||||||
|
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||||
|
|
||||||
|
assert_eq!(ext_sr_agree(self_pk, other_sk), ext_sr_agree(other_pk, self_sk));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// Copyright 2019-2021 @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 merlin::Transcript;
|
||||||
|
use schnorrkel::{signing_context, vrf::{VRFOutput, VRFProof}, PublicKey, SecretKey};
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
/// Size of VRF output, bytes
|
||||||
|
pub const VRF_OUTPUT_SIZE: usize = 32;
|
||||||
|
|
||||||
|
/// Size of VRF proof, bytes
|
||||||
|
pub const VRF_PROOF_SIZE: usize = 64;
|
||||||
|
|
||||||
|
/// Size of VRF raw output, bytes
|
||||||
|
pub const VRF_RAW_OUTPUT_SIZE: usize = 16;
|
||||||
|
|
||||||
|
/// Size of VRF limit, bytes
|
||||||
|
pub const VRF_THRESHOLD_SIZE: usize = 16;
|
||||||
|
|
||||||
|
/// Size of the final full output
|
||||||
|
pub const VRF_RESULT_SIZE: usize = VRF_OUTPUT_SIZE + VRF_PROOF_SIZE;
|
||||||
|
|
||||||
|
pub fn create_transcript(extra: &[u8]) -> Transcript {
|
||||||
|
let mut transcript = Transcript::new(b"VRF");
|
||||||
|
|
||||||
|
// if is important that we don't append when empty, since the
|
||||||
|
// append in merging encodes length information
|
||||||
|
if extra.len() > 0 {
|
||||||
|
transcript.append_message(b"", extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
transcript
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't use the non-extra vrf_sign and vrf_verify internally since in sr25519 they only wrap -
|
||||||
|
//
|
||||||
|
// https://github.com/w3f/schnorrkel/blob/8fa2ad3e9fbf0b652c724df6a87a4b3c5500f759/src/vrf.rs#L660
|
||||||
|
|
||||||
|
/// Run a Random Verifiable Function (VRF) on one single input
|
||||||
|
/// (message) transcript, and an extra message transcript,
|
||||||
|
/// producing the output signature and corresponding short proof.
|
||||||
|
///
|
||||||
|
/// * secret: UIntArray with 64 element
|
||||||
|
/// * context: Arbitrary length UIntArray
|
||||||
|
/// * message: Arbitrary length UIntArray
|
||||||
|
/// * extra: Arbitrary length UIntArray
|
||||||
|
///
|
||||||
|
/// * returned vector is the 32-byte output (signature) and 64-byte proof.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_vrf_sign(secret: &[u8], context: &[u8], message: &[u8], extra: &[u8]) -> Vec<u8> {
|
||||||
|
let keypair = SecretKey::from_ed25519_bytes(secret).unwrap().to_keypair();
|
||||||
|
let transcript = create_transcript(extra);
|
||||||
|
let (io, proof, _) = keypair.vrf_sign_extra(signing_context(context).bytes(message), transcript);
|
||||||
|
let mut result: [u8; VRF_RESULT_SIZE] = [0u8; VRF_RESULT_SIZE];
|
||||||
|
|
||||||
|
result[..VRF_OUTPUT_SIZE].copy_from_slice(io.as_output_bytes());
|
||||||
|
result[VRF_OUTPUT_SIZE..].copy_from_slice(&proof.to_bytes());
|
||||||
|
result.to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify VRF proof for one single input transcript, and an extra message transcript,
|
||||||
|
/// and corresponding output.
|
||||||
|
///
|
||||||
|
/// * pubkey: UIntArray with 32 element
|
||||||
|
/// * context: Arbitrary length UIntArray
|
||||||
|
/// * message: Arbitrary length UIntArray
|
||||||
|
/// * extra: Arbitrary length UIntArray
|
||||||
|
/// * out_and_proof: 96-byte output & proof array from the ext_vrf_sign function.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn ext_vrf_verify(pubkey: &[u8], context: &[u8], message: &[u8], extra: &[u8], out_and_proof: &[u8]) -> bool {
|
||||||
|
match (
|
||||||
|
PublicKey::from_bytes(pubkey),
|
||||||
|
VRFOutput::from_bytes(&out_and_proof[..VRF_OUTPUT_SIZE]),
|
||||||
|
VRFProof::from_bytes(&out_and_proof[VRF_OUTPUT_SIZE..VRF_RESULT_SIZE])
|
||||||
|
) {
|
||||||
|
(Ok(public), Ok(out), Ok(proof)) => {
|
||||||
|
public
|
||||||
|
.vrf_verify_extra(
|
||||||
|
signing_context(context).bytes(message),
|
||||||
|
&out,
|
||||||
|
&proof,
|
||||||
|
create_transcript(extra)
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
extern crate rand;
|
||||||
|
extern crate schnorrkel;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::sr25519::ext_sr_from_seed;
|
||||||
|
use schnorrkel::{KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
|
||||||
|
|
||||||
|
fn generate_random_seed() -> Vec<u8> {
|
||||||
|
(0..32).map(|_| rand::random::<u8>()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vrf_sign_extra_and_verify() {
|
||||||
|
let seed = generate_random_seed();
|
||||||
|
let keypair = ext_sr_from_seed(seed.as_slice());
|
||||||
|
let private = &keypair[0..SECRET_KEY_LENGTH];
|
||||||
|
let public = &keypair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
|
||||||
|
let context = b"my VRF context";
|
||||||
|
let message = b"this is a message";
|
||||||
|
let extra = b"this is an extra";
|
||||||
|
|
||||||
|
// Perform multiple vrf_sign_extra calls w/ same context, message, extra args
|
||||||
|
let out_and_proof1 = ext_vrf_sign(private, context, message, extra);
|
||||||
|
let out_and_proof2 = ext_vrf_sign(private, context, message, extra);
|
||||||
|
|
||||||
|
// Basic size checks
|
||||||
|
assert!(out_and_proof1.len() == VRF_RESULT_SIZE);
|
||||||
|
assert!(out_and_proof2.len() == VRF_RESULT_SIZE);
|
||||||
|
|
||||||
|
// Given the same context, message & extra, output should be deterministic
|
||||||
|
let out1 = &out_and_proof1[..VRF_OUTPUT_SIZE];
|
||||||
|
let out2 = &out_and_proof2[..VRF_OUTPUT_SIZE];
|
||||||
|
assert_eq!(out1, out2);
|
||||||
|
|
||||||
|
// But proof is non-deterministic
|
||||||
|
let proof1 = &out_and_proof1[VRF_OUTPUT_SIZE..];
|
||||||
|
let proof2 = &out_and_proof2[VRF_OUTPUT_SIZE..];
|
||||||
|
assert_ne!(proof1, proof2);
|
||||||
|
|
||||||
|
// VRF outputs can verified w/ original context, message & extra args
|
||||||
|
assert!(ext_vrf_verify(
|
||||||
|
public,
|
||||||
|
context,
|
||||||
|
message,
|
||||||
|
extra,
|
||||||
|
&out_and_proof1
|
||||||
|
));
|
||||||
|
assert!(ext_vrf_verify(
|
||||||
|
public,
|
||||||
|
context,
|
||||||
|
message,
|
||||||
|
extra,
|
||||||
|
&out_and_proof2
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2019-2021 @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 functions (required and used internally)
|
||||||
|
|
||||||
|
__wbindgen_free(a: number, b: number): void;
|
||||||
|
|
||||||
|
__wbindgen_malloc(a: number): number;
|
||||||
|
|
||||||
|
__wbindgen_realloc(a: number, b: number, c: number): number;
|
||||||
|
|
||||||
|
__wbindgen_exn_store(a: number): void;
|
||||||
|
|
||||||
|
// exposed functions
|
||||||
|
|
||||||
|
ext_bip39_generate(resLen: 8, words: number): void;
|
||||||
|
|
||||||
|
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
|
||||||
|
|
||||||
|
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||||
|
|
||||||
|
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||||
|
|
||||||
|
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
|
||||||
|
|
||||||
|
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||||
|
|
||||||
|
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||||
|
|
||||||
|
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||||
|
|
||||||
|
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
|
||||||
|
|
||||||
|
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
|
||||||
|
|
||||||
|
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
|
||||||
|
|
||||||
|
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
|
||||||
|
|
||||||
|
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
|
||||||
|
|
||||||
|
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
|
||||||
|
|
||||||
|
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||||
|
|
||||||
|
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||||
|
|
||||||
|
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||||
|
|
||||||
|
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||||
|
|
||||||
|
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||||
|
|
||||||
|
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
|
||||||
|
|
||||||
|
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
|
||||||
|
|
||||||
|
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const rootIncl = ['@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
|
||||||
|
const detcIncl = rootIncl.map((p) => `${p}/packageInfo`);
|
||||||
|
|
||||||
|
require('override-require')(
|
||||||
|
(request) =>
|
||||||
|
rootIncl.some((p) => request.endsWith(p)) ||
|
||||||
|
detcIncl.some((p) => request.endsWith(p)),
|
||||||
|
(request) =>
|
||||||
|
rootIncl.some((p) => request.endsWith(p))
|
||||||
|
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/data.cjs`)
|
||||||
|
: require(`${detcIncl.find((p) => request.endsWith(p)).replace('packageInfo', 'build/packageInfo.cjs')}`)
|
||||||
|
);
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const { assert, u8aToHex } = require('@polkadot/util');
|
||||||
|
|
||||||
|
function bip39Generate (wasm) {
|
||||||
|
const res = wasm.bip39Generate(21);
|
||||||
|
|
||||||
|
console.log('\tPHR', res);
|
||||||
|
|
||||||
|
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39GenerateSubsequent (wasm) {
|
||||||
|
const val1 = wasm.bip39Generate(24);
|
||||||
|
const val2 = wasm.bip39Generate(24);
|
||||||
|
|
||||||
|
console.log('\tVL1', val1);
|
||||||
|
console.log('\tVL2', val2);
|
||||||
|
|
||||||
|
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39Validate (wasm) {
|
||||||
|
const res = wasm.bip39Validate(wasm.bip39Generate(12));
|
||||||
|
|
||||||
|
console.log('\tVAL', res);
|
||||||
|
|
||||||
|
assert(res, 'ERROR: Invalid bip39 validation');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39ToEntropy (wasm) {
|
||||||
|
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
||||||
|
|
||||||
|
console.log('\tENT', res);
|
||||||
|
|
||||||
|
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39ToMiniSecret (wasm) {
|
||||||
|
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
||||||
|
|
||||||
|
console.log('\tMIN', res);
|
||||||
|
|
||||||
|
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bip39ToSeed (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 = {
|
||||||
|
bip39Generate,
|
||||||
|
bip39GenerateSubsequent,
|
||||||
|
bip39ToEntropy,
|
||||||
|
bip39ToMiniSecret,
|
||||||
|
bip39ToSeed,
|
||||||
|
bip39Validate
|
||||||
|
};
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/camelcase */
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const { assert, u8aToHex } = require('@polkadot/util');
|
|
||||||
|
|
||||||
function bip39_generate (wasm) {
|
|
||||||
const RESULT = wasm.bip39Generate(21);
|
|
||||||
|
|
||||||
console.log('\tPHR', RESULT);
|
|
||||||
|
|
||||||
assert(RESULT.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip39_validate (wasm) {
|
|
||||||
const RESULT = wasm.bip39Validate(wasm.bip39Generate(12));
|
|
||||||
|
|
||||||
console.log('\tVAL', RESULT);
|
|
||||||
|
|
||||||
assert(RESULT, 'ERROR: Invalid bip39 validation');
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip39_toEntropy (wasm) {
|
|
||||||
const RESULT = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
|
|
||||||
|
|
||||||
console.log('\tENT', RESULT);
|
|
||||||
|
|
||||||
assert(RESULT === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip39_toMiniSecret (wasm) {
|
|
||||||
const RESULT = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
|
|
||||||
|
|
||||||
console.log('\tMIN', RESULT);
|
|
||||||
|
|
||||||
assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip39_toSeed (wasm) {
|
|
||||||
const RESULT = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
|
||||||
|
|
||||||
console.log('\tSEE', RESULT);
|
|
||||||
|
|
||||||
assert(RESULT === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
bip39_generate,
|
|
||||||
bip39_validate,
|
|
||||||
bip39_toEntropy,
|
|
||||||
bip39_toMiniSecret,
|
|
||||||
bip39_toSeed
|
|
||||||
};
|
|
||||||
+10
-14
@@ -1,9 +1,5 @@
|
|||||||
/* eslint-disable @typescript-eslint/camelcase */
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||||
@@ -16,7 +12,7 @@ function randomPair (wasm) {
|
|||||||
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
|
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function ed25519_pairFromSeed (wasm) {
|
function ed25519PairFromSeed (wasm) {
|
||||||
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
|
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
|
||||||
|
|
||||||
console.log('\tSEC', u8aToHex(sk));
|
console.log('\tSEC', u8aToHex(sk));
|
||||||
@@ -25,7 +21,7 @@ function ed25519_pairFromSeed (wasm) {
|
|||||||
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
|
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ed25519_signAndVerify (wasm) {
|
function ed25519SignAndVerify (wasm) {
|
||||||
const [, pk, sk] = randomPair(wasm);
|
const [, pk, sk] = randomPair(wasm);
|
||||||
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
|
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||||
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
|
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||||
@@ -36,7 +32,7 @@ function ed25519_signAndVerify (wasm) {
|
|||||||
assert(isValid, 'ERROR: Unable to verify signature');
|
assert(isValid, 'ERROR: Unable to verify signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ed25519_verifyExisting (wasm) {
|
function ed25519VerifyExisting (wasm) {
|
||||||
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
|
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
|
||||||
|
|
||||||
console.log('\tRES', isValid);
|
console.log('\tRES', isValid);
|
||||||
@@ -44,7 +40,7 @@ function ed25519_verifyExisting (wasm) {
|
|||||||
assert(isValid, 'ERROR: Unable to verify signature');
|
assert(isValid, 'ERROR: Unable to verify signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ed25519_benchmark (wasm) {
|
function ed25519Benchmark (wasm) {
|
||||||
const MESSAGE = stringToU8a('this is a message');
|
const MESSAGE = stringToU8a('this is a message');
|
||||||
|
|
||||||
for (let i = 0; i < 256; i++) {
|
for (let i = 0; i < 256; i++) {
|
||||||
@@ -55,8 +51,8 @@ function ed25519_benchmark (wasm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ed25519_pairFromSeed,
|
ed25519Benchmark,
|
||||||
ed25519_signAndVerify,
|
ed25519PairFromSeed,
|
||||||
ed25519_verifyExisting,
|
ed25519SignAndVerify,
|
||||||
ed25519_benchmark
|
ed25519VerifyExisting
|
||||||
};
|
};
|
||||||
+44
-15
@@ -1,9 +1,5 @@
|
|||||||
/* eslint-disable @typescript-eslint/camelcase */
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||||
|
|
||||||
@@ -15,6 +11,22 @@ function blake2bHash (wasm) {
|
|||||||
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
|
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hmacSha256 (wasm) {
|
||||||
|
const hash = u8aToHex(wasm.hmacSha256(stringToU8a('secret'), stringToU8a('some message')));
|
||||||
|
|
||||||
|
console.log('\tRES', hash);
|
||||||
|
|
||||||
|
assert(hash === '0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7', 'ERROR: hmacSha256 does not match');
|
||||||
|
}
|
||||||
|
|
||||||
|
function hmacSha512 (wasm) {
|
||||||
|
const hash = u8aToHex(wasm.hmacSha512(stringToU8a('secret'), stringToU8a('some message')));
|
||||||
|
|
||||||
|
console.log('\tRES', hash);
|
||||||
|
|
||||||
|
assert(hash === '0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841', 'ERROR: hmacSha512 does not match');
|
||||||
|
}
|
||||||
|
|
||||||
function keccak256 (wasm) {
|
function keccak256 (wasm) {
|
||||||
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
|
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
|
||||||
|
|
||||||
@@ -23,6 +35,14 @@ function keccak256 (wasm) {
|
|||||||
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
|
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keccak512 (wasm) {
|
||||||
|
const hash = u8aToHex(wasm.keccak512(stringToU8a('test')));
|
||||||
|
|
||||||
|
console.log('\tRES', hash);
|
||||||
|
|
||||||
|
assert(hash === '0x1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e', 'ERROR: keccak512 does not match');
|
||||||
|
}
|
||||||
|
|
||||||
function pbkdf2Hash (wasm) {
|
function pbkdf2Hash (wasm) {
|
||||||
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
|
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
|
||||||
|
|
||||||
@@ -31,16 +51,21 @@ function pbkdf2Hash (wasm) {
|
|||||||
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
|
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
// function secp256k1Recover (wasm) {
|
function scryptHash (wasm) {
|
||||||
// const pk = u8aToHex(wasm.keccak256(wasm.secp256k1Recover(
|
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
|
||||||
// hexToU8a('0x2bbfa926ee947dfac384d981f8913b4e0992e52d7b6711e0ec3d9f8b0f752648'),
|
|
||||||
// hexToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c')
|
|
||||||
// )));
|
|
||||||
|
|
||||||
// console.log('\tPUB', pk);
|
console.log('\tRES', hash);
|
||||||
|
|
||||||
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
|
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
function sha256Hash (wasm) {
|
||||||
|
const hash = u8aToHex(wasm.sha256(stringToU8a('hello world')));
|
||||||
|
|
||||||
|
console.log('\tRES', hash);
|
||||||
|
|
||||||
|
assert(hash === '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9', 'ERROR: sha256Hash does not match');
|
||||||
|
}
|
||||||
|
|
||||||
function sha512Hash (wasm) {
|
function sha512Hash (wasm) {
|
||||||
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
||||||
@@ -62,9 +87,13 @@ function twoxHash (wasm) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
blake2bHash,
|
blake2bHash,
|
||||||
|
hmacSha256,
|
||||||
|
hmacSha512,
|
||||||
keccak256,
|
keccak256,
|
||||||
|
keccak512,
|
||||||
pbkdf2Hash,
|
pbkdf2Hash,
|
||||||
// secp256k1Recover,
|
scryptHash,
|
||||||
|
sha256Hash,
|
||||||
sha512Hash,
|
sha512Hash,
|
||||||
twoxHash
|
twoxHash
|
||||||
};
|
};
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const wasm = require('../../build/index');
|
const wasm = require('../../build/index.cjs');
|
||||||
const bip39 = require('./bip39');
|
const bip39 = require('./bip39.cjs');
|
||||||
const ed25519 = require('./ed25519');
|
const ed25519 = require('./ed25519.cjs');
|
||||||
const hashing = require('./hashing');
|
const hashing = require('./hashing.cjs');
|
||||||
const sr25519 = require('./sr25519');
|
const sr25519 = require('./sr25519.cjs');
|
||||||
|
const vrf = require('./vrf.cjs');
|
||||||
|
|
||||||
const tests = {
|
const tests = {
|
||||||
...bip39,
|
...bip39,
|
||||||
...ed25519,
|
...ed25519,
|
||||||
...hashing,
|
...hashing,
|
||||||
...sr25519
|
...sr25519,
|
||||||
|
...vrf
|
||||||
};
|
};
|
||||||
|
|
||||||
function beforeAll () {
|
function beforeAll () {
|
||||||
@@ -47,15 +47,14 @@ function runAll () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runUnassisted () {
|
function runUnassisted () {
|
||||||
(async () => {
|
beforeAll()
|
||||||
await beforeAll();
|
.then(() => runAll())
|
||||||
|
.then(() => process.exit(0))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
runAll();
|
process.exit(-1);
|
||||||
})().catch((error) => {
|
});
|
||||||
console.error(error);
|
|
||||||
|
|
||||||
process.exit(-1);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
+52
-26
@@ -1,9 +1,5 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
/* eslint-disable @typescript-eslint/camelcase */
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||||
@@ -16,7 +12,7 @@ function randomPair (wasm) {
|
|||||||
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_pairFromSeed (wasm) {
|
function sr25519PairFromSeed (wasm) {
|
||||||
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
|
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
|
||||||
|
|
||||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||||
@@ -25,7 +21,7 @@ function sr25519_pairFromSeed (wasm) {
|
|||||||
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
|
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_devFromSeed (wasm) {
|
function sr25519DevFromSeed (wasm) {
|
||||||
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
|
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
|
||||||
|
|
||||||
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
|
||||||
@@ -34,7 +30,7 @@ function sr25519_devFromSeed (wasm) {
|
|||||||
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
|
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_verifyExisting (wasm) {
|
function sr25519VerifyExisting (wasm) {
|
||||||
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
|
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
|
||||||
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
|
||||||
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
|
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
|
||||||
@@ -46,7 +42,18 @@ function sr25519_verifyExisting (wasm) {
|
|||||||
assert(isValid, 'ERROR: Unable to verify signature');
|
assert(isValid, 'ERROR: Unable to verify signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_signAndVerify (wasm) {
|
function sr25519SignDeterministic (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 sr25519SignAndVerify (wasm) {
|
||||||
const [, pk, sk] = randomPair(wasm);
|
const [, pk, sk] = randomPair(wasm);
|
||||||
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
|
||||||
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
|
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
|
||||||
@@ -57,7 +64,7 @@ function sr25519_signAndVerify (wasm) {
|
|||||||
assert(isValid, 'ERROR: Unable to verify signature');
|
assert(isValid, 'ERROR: Unable to verify signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_deriveHard (wasm) {
|
function sr25519DeriveHard (wasm) {
|
||||||
const [pair] = randomPair(wasm);
|
const [pair] = randomPair(wasm);
|
||||||
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||||
|
|
||||||
@@ -65,7 +72,7 @@ function sr25519_deriveHard (wasm) {
|
|||||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_deriveHardKnown (wasm) {
|
function sr25519DeriveHardKnown (wasm) {
|
||||||
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
|
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
|
||||||
const publicKey = u8aToHex(derived.slice(64));
|
const publicKey = u8aToHex(derived.slice(64));
|
||||||
|
|
||||||
@@ -75,7 +82,7 @@ function sr25519_deriveHardKnown (wasm) {
|
|||||||
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
|
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_deriveSoft (wasm) {
|
function sr25519DeriveSoft (wasm) {
|
||||||
const [pair] = randomPair(wasm);
|
const [pair] = randomPair(wasm);
|
||||||
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||||
|
|
||||||
@@ -83,7 +90,7 @@ function sr25519_deriveSoft (wasm) {
|
|||||||
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
console.log('\tPUB', u8aToHex(derived.slice(64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_deriveSoftKnown (wasm) {
|
function sr25519DeriveSoftKnown (wasm) {
|
||||||
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
|
||||||
const publicKey = u8aToHex(derived.slice(64));
|
const publicKey = u8aToHex(derived.slice(64));
|
||||||
|
|
||||||
@@ -93,7 +100,7 @@ function sr25519_deriveSoftKnown (wasm) {
|
|||||||
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_deriveSoftPubkey (wasm) {
|
function sr25519DeriveSoftPubkey (wasm) {
|
||||||
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
|
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
|
||||||
|
|
||||||
console.log('\tPUB', derived);
|
console.log('\tPUB', derived);
|
||||||
@@ -101,7 +108,24 @@ function sr25519_deriveSoftPubkey (wasm) {
|
|||||||
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
function sr25519_benchmark (wasm) {
|
function sr25519KeyAgreement (wasm) {
|
||||||
|
const pair1 = wasm.sr25519KeypairFromSeed(hexToU8a('0x3b44c558f9a8f3dc9690d53088558c1ba2529b677e316c6054d1852595b004af'));
|
||||||
|
const pair2 = wasm.sr25519KeypairFromSeed(hexToU8a('0x923b80f79c6981fe756272128ec236eb510ae016dd20bdccbd77a9416b7ab94e'));
|
||||||
|
const [, pk1, sk1] = extractKeys(pair1);
|
||||||
|
const [, pk2, sk2] = extractKeys(pair2);
|
||||||
|
|
||||||
|
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
|
||||||
|
assert(u8aToHex(wasm.sr25519Agree(pk2, sk1)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
|
||||||
|
|
||||||
|
for (let i = 0; i < 256; i++) {
|
||||||
|
const [, pk1, sk1] = randomPair(wasm);
|
||||||
|
const [, pk2, sk2] = randomPair(wasm);
|
||||||
|
|
||||||
|
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === u8aToHex(wasm.sr25519Agree(pk2, sk1)), 'Unmatched agreement keys');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sr25519Benchmark (wasm) {
|
||||||
const MESSAGE = stringToU8a('this is a message');
|
const MESSAGE = stringToU8a('this is a message');
|
||||||
|
|
||||||
for (let i = 0; i < 256; i++) {
|
for (let i = 0; i < 256; i++) {
|
||||||
@@ -112,14 +136,16 @@ function sr25519_benchmark (wasm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sr25519_pairFromSeed,
|
sr25519Benchmark,
|
||||||
sr25519_devFromSeed,
|
sr25519DeriveHard,
|
||||||
sr25519_deriveHard,
|
sr25519DeriveHardKnown,
|
||||||
sr25519_deriveHardKnown,
|
sr25519DeriveSoft,
|
||||||
sr25519_deriveSoft,
|
sr25519DeriveSoftKnown,
|
||||||
sr25519_deriveSoftKnown,
|
sr25519DeriveSoftPubkey,
|
||||||
sr25519_deriveSoftPubkey,
|
sr25519DevFromSeed,
|
||||||
sr25519_signAndVerify,
|
sr25519KeyAgreement,
|
||||||
sr25519_verifyExisting,
|
sr25519PairFromSeed,
|
||||||
sr25519_benchmark
|
sr25519SignAndVerify,
|
||||||
|
sr25519SignDeterministic,
|
||||||
|
sr25519VerifyExisting
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||||
|
|
||||||
|
function extractKeys (pair) {
|
||||||
|
return [pair, pair.slice(64), pair.slice(0, 64)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomPair (wasm) {
|
||||||
|
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function vrfSignAndVerifyCompat (wasm) {
|
||||||
|
const [, pk, sk] = randomPair(wasm);
|
||||||
|
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array());
|
||||||
|
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array(), outAndProof);
|
||||||
|
|
||||||
|
console.log('\tVRF', u8aToHex(outAndProof));
|
||||||
|
console.log('\tRES', isValid);
|
||||||
|
|
||||||
|
assert(isValid, 'ERROR: Unable to verify VRF output & proof');
|
||||||
|
}
|
||||||
|
|
||||||
|
function vrfSignAndVerify (wasm) {
|
||||||
|
const [, pk, sk] = randomPair(wasm);
|
||||||
|
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
|
||||||
|
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'), outAndProof);
|
||||||
|
|
||||||
|
console.log('\tVRF', u8aToHex(outAndProof));
|
||||||
|
console.log('\tRES', isValid);
|
||||||
|
|
||||||
|
assert(isValid, 'ERROR: Unable to verify VRF extra output & proof');
|
||||||
|
}
|
||||||
|
|
||||||
|
function vrfSignAndVerifyDeterministic (wasm) {
|
||||||
|
const [,, sk] = randomPair(wasm);
|
||||||
|
const outAndProof1 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
|
||||||
|
const outAndProof2 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
|
||||||
|
const sig1 = u8aToHex(outAndProof1.slice(0, 32));
|
||||||
|
const sig2 = u8aToHex(outAndProof2.slice(0, 32));
|
||||||
|
|
||||||
|
console.log('\tSG1', sig1);
|
||||||
|
console.log('\tSG2', sig2);
|
||||||
|
|
||||||
|
assert(sig1 === sig2, 'ERROR: VRF extra outputs are non-deterministic');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
vrfSignAndVerify,
|
||||||
|
vrfSignAndVerifyCompat,
|
||||||
|
vrfSignAndVerifyDeterministic
|
||||||
|
};
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
global.WebAssembly = null;
|
||||||
|
|
||||||
|
require('./alias-imports.cjs');
|
||||||
|
|
||||||
|
const { runUnassisted } = require('./all/index.cjs');
|
||||||
|
|
||||||
|
runUnassisted();
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
global.WebAssembly = null;
|
|
||||||
|
|
||||||
require('override-require')(
|
|
||||||
(request) => request === './wasm_asm_stub',
|
|
||||||
() => require('../build/wasm_asm')
|
|
||||||
);
|
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
|
||||||
|
|
||||||
runUnassisted();
|
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
require('../build/crypto-polyfill');
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
const { beforeAll, tests, wasm } = require('./all');
|
// override-require in jest.config.js
|
||||||
|
|
||||||
describe('schnorrkel-js', () => {
|
import { beforeAll, tests, wasm } from './all/index.cjs';
|
||||||
|
|
||||||
|
describe('wasm-crypto', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await beforeAll();
|
await beforeAll();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
require('./alias-imports.cjs');
|
||||||
|
|
||||||
|
const { runUnassisted } = require('./all/index.cjs');
|
||||||
|
|
||||||
|
runUnassisted();
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
|
||||||
|
|
||||||
runUnassisted();
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { createBundle } from '@polkadot/dev/config/rollup';
|
||||||
|
|
||||||
|
const pkgs = [
|
||||||
|
'@polkadot/wasm-crypto'
|
||||||
|
];
|
||||||
|
|
||||||
|
const external = [
|
||||||
|
...pkgs,
|
||||||
|
'@polkadot/util'
|
||||||
|
];
|
||||||
|
|
||||||
|
const overrides = {
|
||||||
|
'@polkadot/wasm-crypto': {
|
||||||
|
entries: ['asmjs', 'wasm'].map((p) => `wasm-crypto-${p}`).reduce((all, p) => ({
|
||||||
|
...all,
|
||||||
|
[`@polkadot/${p}`]: `../../${p}/build`
|
||||||
|
}), {})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default pkgs.map((pkg) =>
|
||||||
|
createBundle({
|
||||||
|
external,
|
||||||
|
pkg,
|
||||||
|
...(overrides[pkg] || {})
|
||||||
|
})
|
||||||
|
);
|
||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2019-2021 @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
|
||||||
|
|
||||||
|
DEST=packages/wasm-crypto/build/esm
|
||||||
|
|
||||||
|
./scripts/clean-js.sh
|
||||||
|
yarn polkadot-dev-build-ts
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
|
||||||
# This software may be modified and distributed under the terms
|
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
BGJ=build/wasm_bg.js
|
|
||||||
SRC_WASM=build/wasm.js
|
|
||||||
DEF=build/wasm.d.ts
|
|
||||||
WSM=build/wasm_bg.wasm
|
|
||||||
OPT=build/wasm_opt.wasm
|
|
||||||
ASM=build/wasm_asm.js
|
|
||||||
|
|
||||||
echo "*** Building package"
|
|
||||||
|
|
||||||
# cleanup old
|
|
||||||
echo "*** Cleaning old builds"
|
|
||||||
rm -rf ./build ./pkg
|
|
||||||
|
|
||||||
# build new via nightly & wasm-pack
|
|
||||||
echo "*** Building WASM output"
|
|
||||||
rustup run nightly wasm-pack build --release --scope polkadot --target nodejs
|
|
||||||
mv pkg build
|
|
||||||
|
|
||||||
# optimise
|
|
||||||
echo "*** Optimising WASM output"
|
|
||||||
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
|
||||||
|
|
||||||
# convert wasm to base64 structure
|
|
||||||
echo "*** Packing WASM into base64"
|
|
||||||
node ../../scripts/pack-wasm-base64.js
|
|
||||||
|
|
||||||
# build asmjs version from the input (optimised) WASM
|
|
||||||
echo "*** Building asm.js version"
|
|
||||||
../../binaryen/bin/wasm2js --output $ASM $OPT
|
|
||||||
|
|
||||||
# cleanup the generated 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
|
|
||||||
Executable
+48
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2019-2021 @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
|
||||||
|
|
||||||
|
source ../scripts/rust-version.sh
|
||||||
|
|
||||||
|
WSM=bytes/wasm_bg.wasm
|
||||||
|
OPT=bytes/wasm_opt.wasm
|
||||||
|
ASM=wasm-crypto-asmjs/build/cjs/data.js
|
||||||
|
|
||||||
|
# build new via wasm-pack
|
||||||
|
echo "*** Building Rust sources"
|
||||||
|
cd wasm-crypto
|
||||||
|
if [ "$RUST_VER" == "stable" ]; then
|
||||||
|
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||||
|
else
|
||||||
|
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
|
||||||
|
fi
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo "*** Converting to WASM"
|
||||||
|
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
|
||||||
|
|
||||||
|
# optimise
|
||||||
|
echo "*** Optimising WASM output"
|
||||||
|
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
||||||
|
|
||||||
|
# convert wasm to base64 structure
|
||||||
|
echo "*** Packing WASM into baseX"
|
||||||
|
node ../scripts/pack-wasm-base.cjs
|
||||||
|
|
||||||
|
# build asmjs version from the input (optimised) WASM
|
||||||
|
echo "*** Building asm.js version"
|
||||||
|
../binaryen/bin/wasm2js --output $ASM $OPT
|
||||||
|
|
||||||
|
# cleanup the generated asm, converting to cjs
|
||||||
|
sed -i -e '/import {/d' $ASM
|
||||||
|
sed -i -e '/export var /d' $ASM
|
||||||
|
sed -i -e 's/{abort.*},memasmFunc/wbg, memasmFunc/g' $ASM
|
||||||
|
sed -i -e 's/var retasmFunc = /const asmJsInit = (wbg) => /' $ASM
|
||||||
|
echo "module.exports = { asmJsInit };" >> $ASM
|
||||||
|
|
||||||
|
# cleanups
|
||||||
|
rm -rf wasm-crypto-asmjs/build/cjs/*-e
|
||||||
|
rm -rf wasm-crypto-wasm/build/cjs/*-e
|
||||||
+17
-17
@@ -1,30 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
# This software may be modified and distributed under the terms
|
# This software may be modified and distributed under the terms
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
./scripts/install-build-deps.sh
|
echo "*** Building JavaScript"
|
||||||
|
./scripts/build-js.sh
|
||||||
|
|
||||||
echo "*** Building packages"
|
echo "*** Building WASM"
|
||||||
cd packages
|
cd packages
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
../scripts/build-wasm.sh
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
yarn test:wasm:js
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
echo "*** Building $PKG"
|
|
||||||
cd $PKG
|
|
||||||
|
|
||||||
../../scripts/build-package.sh
|
echo ""
|
||||||
../../scripts/test-package.sh
|
echo "*** wasm-crypto"
|
||||||
|
ls -alR wasm-crypto/build
|
||||||
rm -rf build/*-e build/package.json build/README.md
|
echo ""
|
||||||
ls -al build
|
echo "*** wasm-crypto-asmjs"
|
||||||
|
ls -alR wasm-crypto-asmjs/build
|
||||||
cd ..
|
echo ""
|
||||||
fi
|
echo "*** wasm-crypto-wasm"
|
||||||
done
|
ls -alR wasm-crypto-wasm/build
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
yarn build:rollup
|
||||||
|
|||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2019-2021 @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
|
||||||
|
|
||||||
|
# cleanup old
|
||||||
|
echo "*** Cleaning old builds"
|
||||||
|
rm -rf packages/*/build packages/bytes
|
||||||
+6
-18
@@ -1,27 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
# This software may be modified and distributed under the terms
|
# This software may be modified and distributed under the terms
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
./scripts/install-build-deps.sh
|
./scripts/clean-js.sh
|
||||||
|
|
||||||
echo "*** Cleaning packages"
|
echo "*** Cleaning wasm"
|
||||||
cd packages
|
cd packages/wasm-crypto
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
cargo clean
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
cd ../..
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
echo "*** Cleaning $PKG"
|
|
||||||
cd $PKG
|
|
||||||
|
|
||||||
rm -rf build
|
|
||||||
cargo clean
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
|
|||||||
@@ -1,47 +1,58 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
# This software may be modified and distributed under the terms
|
# This software may be modified and distributed under the terms
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# wasm2js for wasm -> asm.js
|
source ./scripts/rust-version.sh
|
||||||
BINARYEN=( "wasm-opt" "wasm2js" )
|
|
||||||
|
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||||
|
BINARYEN_VER=version_97
|
||||||
|
BINARYEN_ZIP=
|
||||||
|
|
||||||
|
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
|
||||||
|
BINDGEN_VER=0.2.65
|
||||||
|
BINDGEN_ZIP=
|
||||||
|
|
||||||
|
WABT_REPO=https://github.com/WebAssembly/wabt
|
||||||
|
WABT_VER=1.0.19
|
||||||
|
WABT_ZIP=
|
||||||
|
|
||||||
unamestr=`uname`
|
unamestr=`uname`
|
||||||
|
|
||||||
# install wasm-pack as required
|
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
|
||||||
if ! [ -x "$(command -v wasm-pack)" ]; then
|
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||||
echo "*** Installing wasm-pack"
|
|
||||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
if [ "$RUST_VER" != "stable" ]; then
|
||||||
|
cargo install xargo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# CI, Linux
|
|
||||||
if [[ "$unamestr" == 'Linux' ]]; then
|
if [[ "$unamestr" == 'Linux' ]]; then
|
||||||
if [ ! -d "binaryen" ]; then
|
echo "*** Detected Linux"
|
||||||
echo "*** Downloading binaryen"
|
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||||
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_91/binaryen-version_91-x86-linux.tar.gz | tar xz
|
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-unknown-linux-musl
|
||||||
mkdir -p binaryen/bin
|
WABT_ZIP=wabt-$WABT_VER-ubuntu
|
||||||
|
elif [[ "$unamestr" == "Darwin" ]]; then
|
||||||
for BIN in "${BINARYEN[@]}"; do
|
echo "*** Detected Mac"
|
||||||
mv binaryen-version_91/$BIN binaryen/bin
|
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-macos
|
||||||
done
|
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-apple-darwin
|
||||||
fi
|
WABT_ZIP=wabt-$WABT_VER-macos
|
||||||
else
|
else
|
||||||
# install binaryen as required
|
echo "*** Unknown platform $unamestr, unable to install wasm helper binaries"
|
||||||
if [ ! -d "binaryen" ]; then
|
exit 1
|
||||||
echo "*** Cloning binaryen"
|
|
||||||
git clone --recursive https://github.com/WebAssembly/binaryen.git
|
|
||||||
rm -rf binaryen/test
|
|
||||||
fi
|
|
||||||
|
|
||||||
for BIN in "${BINARYEN[@]}"; do
|
|
||||||
if [ ! -f "binaryen/bin/$BIN" ]; then
|
|
||||||
echo "*** Building $BIN"
|
|
||||||
cd binaryen
|
|
||||||
cmake . && make $BIN
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "binaryen" ]; then
|
||||||
|
echo "*** Downloading binaryen"
|
||||||
|
curl -L $BINARYEN_REPO/releases/download/$BINARYEN_VER/$BINARYEN_ZIP.tar.gz | tar xz
|
||||||
|
mv binaryen-$BINARYEN_VER binaryen
|
||||||
|
ls -alR binaryen
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "bindgen" ]; then
|
||||||
|
echo "*** Downloading bindgen"
|
||||||
|
curl -L $BINDGEN_REPO/releases/download/$BINDGEN_VER/$BINDGEN_ZIP.tar.gz | tar xz
|
||||||
|
mv $BINDGEN_ZIP bindgen
|
||||||
|
ls -alR bindgen
|
||||||
|
fi
|
||||||
|
|||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const fflate = require('fflate/node');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { formatNumber } = require('@polkadot/util');
|
||||||
|
|
||||||
|
const W_NAME = 'wasm-crypto-wasm';
|
||||||
|
|
||||||
|
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
||||||
|
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
||||||
|
|
||||||
|
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `// Copyright 2019-2021 @polkadot/${W_NAME} authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Generated as part of the build, do not edit
|
||||||
|
|
||||||
|
const sizeCompressed = ${compressed.length};
|
||||||
|
const sizeUncompressed = ${data.length};
|
||||||
|
const bytes = '${compressed.toString('base64')}';
|
||||||
|
|
||||||
|
module.exports = { bytes, sizeCompressed, sizeUncompressed };
|
||||||
|
`);
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright 2019-2020 @polkadot/wasm authors & contributors
|
|
||||||
// This software may be modified and distributed under the terms
|
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
const fs = require('fs');
|
|
||||||
const buffer = fs.readFileSync('./build/wasm_opt.wasm');
|
|
||||||
|
|
||||||
fs.writeFileSync('./build/wasm_wasm.js', `
|
|
||||||
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
|
|
||||||
`);
|
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
|
# This software may be modified and distributed under the terms
|
||||||
|
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
RUST_VER=nightly-2020-10-25
|
||||||
|
# RUST_VER=stable
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
|
||||||
# This software may be modified and distributed under the terms
|
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "*** Testing WASM"
|
|
||||||
node ./test/wasm.js
|
|
||||||
|
|
||||||
echo "*** Testing ASM.js"
|
|
||||||
node ./test/asm.js
|
|
||||||
|
|
||||||
echo "*** Testing via Jest"
|
|
||||||
yarn polkadot-dev-run-test ./test/jest.spec.js
|
|
||||||
# FIXME, this should be via yarn
|
|
||||||
# ../../node_modules/@polkadot/dev/scripts/polkadot-dev-run-test.js ./test/jest.spec.js
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
|
||||||
# This software may be modified and distributed under the terms
|
|
||||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd packages
|
|
||||||
|
|
||||||
PACKAGES=( $(ls -1d *) )
|
|
||||||
|
|
||||||
for PKG in "${PACKAGES[@]}"; do
|
|
||||||
if [ -f "$PKG/package.json" ]; then
|
|
||||||
cd $PKG
|
|
||||||
echo "*** Testing Rust $PKG"
|
|
||||||
|
|
||||||
RUST_BACKTRACE=full rustup run nightly cargo test --release -- --nocapture
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user