Compare commits

..
99 Commits
Author SHA1 Message Date
Github Actions b236d50c3c [CI Skip] release/stable 4.2.1
skip-checks: true
2021-08-28 05:30:23 +00:00
Jaco e2ac301993 4.2.1 (#212) 2021-08-28 07:24:12 +02:00
Github Actions d6bdcaccd7 [CI Skip] release/beta 4.1.3-7
skip-checks: true
2021-08-26 07:36:51 +00:00
Jaco Greeff a7f0e68443 Bump deps 2021-08-26 10:31:04 +03:00
Github Actions dc24ab5804 [CI Skip] release/beta 4.1.3-6
skip-checks: true
2021-08-25 10:01:34 +00:00
Jaco d5512418d2 Use stable as nightly compiler (#192)
* Use stable as nightly compiler

* detect stable

* Apply suggestions from code review

* CHANGELOG

* De-dupe Rust version

* Adjust script location

* Script cleanups

* trigger

* Script location
2021-08-25 11:55:17 +02:00
Github Actions 7a8e570dfa [CI Skip] release/beta 4.1.3-5
skip-checks: true
2021-08-25 08:58:11 +00:00
Jaco 3794a30b4b Adjust JS tests (#211) 2021-08-25 10:53:04 +02:00
Github Actions 700acfe764 [CI Skip] release/beta 4.1.3-4
skip-checks: true
2021-08-24 11:07:21 +00:00
Shunfan ZhouandJaco 9b8d6e0b64 Support sr25519 agreement (#209)
* Support sr25519 ecdh agreement

* Align version of curve25519-dalek

Co-authored-by: Jaco <jacogr@gmail.com>

* Reduce code size

Co-authored-by: Jaco <jacogr@gmail.com>

* Add explicit tests on sr25519 key agreement

* Fix linting issues

* Fix sr25519 key_agreement test

Co-authored-by: Jaco <jacogr@gmail.com>
2021-08-24 13:00:54 +02:00
Github Actions 3575f57a2a [CI Skip] release/beta 4.1.3-3
skip-checks: true
2021-08-24 07:05:13 +00:00
Jaco 8838651405 Bump deps (#210) 2021-08-24 08:59:29 +02:00
Github Actions 6cb8f2254a [CI Skip] release/beta 4.1.3-2
skip-checks: true
2021-08-16 06:04:41 +00:00
Jaco 72c2a70a32 Bump deps (#208) 2021-08-16 07:58:49 +02:00
Github Actions 51b1d12aab [CI Skip] release/beta 4.1.3-1
skip-checks: true
2021-08-13 11:52:29 +00:00
Jaco Greeff 93159192bb berry 3.0.1 2021-08-13 14:46:26 +03:00
Github Actions d208694d05 [CI Skip] release/beta 4.1.3-0
skip-checks: true
2021-08-13 11:40:39 +00:00
Jaco e7cb8a4907 Bump deps (#207) 2021-08-13 13:35:19 +02:00
Github Actions 01dfe6e35c [CI Skip] release/stable 4.1.2
skip-checks: true
2021-07-09 05:54:46 +00:00
Jaco a5d4c4b43c 4.1.2 (#206) 2021-07-09 07:49:27 +02:00
Github Actions 9a5107534d [CI Skip] release/stable 4.1.1
skip-checks: true
2021-07-07 16:04:14 +00:00
Jaco d50d04318e 4.1 (#205) 2021-07-07 17:59:17 +02:00
Github Actions a0afa3cef6 [CI Skip] release/beta 4.0.3-35
skip-checks: true
2021-07-07 15:40:39 +00:00
Jaco cf20e027af Single module bundle via rollup (#203)
* Single module bundle via rollup

* Adjust naming

* Allow multiple bundles (consistency)

* Remove unused rollup plugins

* Update rollup.config.js

* preferConst

* Rollup with dev build

* Use createBundle

* Update rollup.config.mjs

* Add bundle entrypoint

* Bump dev

* Bump dev

* Remove x-* overrides
2021-07-07 17:34:32 +02:00
Github Actions b68ab94939 [CI Skip] release/beta 4.0.3-34
skip-checks: true
2021-07-06 11:16:52 +00:00
Jaco Greeff af94bc472d Bump dev 2021-07-06 14:11:15 +03:00
Github Actions 289b102b38 [CI Skip] release/beta 4.0.3-33
skip-checks: true
2021-07-06 07:13:57 +00:00
Jaco Greeff ba6cbc2247 Bump deps 2021-07-06 10:08:04 +03:00
Jaco Greeff 379b574b84 Bump dev 2021-07-06 09:56:08 +03:00
Github Actions f1c44a65b1 [CI Skip] release/beta 4.0.3-32
skip-checks: true
2021-07-06 05:52:17 +00:00
Jaco Greeff 7ddb5ebbe5 Bump dev 2021-07-06 08:46:29 +03:00
Github Actions afd2fe3228 [CI Skip] release/beta 4.0.3-31
skip-checks: true
2021-07-05 15:00:16 +00:00
Jaco 292197a3a2 Bump dev (#204) 2021-07-05 16:54:53 +02:00
Github Actions 8fac7feabd [CI Skip] release/beta 4.0.3-30
skip-checks: true
2021-07-02 07:12:59 +00:00
Jaco ca69955332 Bump TS (#202) 2021-07-02 09:08:21 +02:00
Github Actions eacb24a133 [CI Skip] release/beta 4.0.3-29
skip-checks: true
2021-06-27 08:19:12 +00:00
Jaco 21b3dbbb94 Bump deps (#201) 2021-06-27 10:14:23 +02:00
Github Actions 57ff683121 [CI Skip] release/beta 4.0.3-28
skip-checks: true
2021-06-22 13:51:08 +00:00
Jaco 8b7e35ad0b Bump deps (#200) 2021-06-22 15:45:31 +02:00
Github Actions 0732f053b8 [CI Skip] release/beta 4.0.3-27
skip-checks: true
2021-06-08 15:09:51 +00:00
Jaco 831a72b519 Prettier ignore all (#199)
* Prettier ignore all

* Add scripts
2021-06-08 17:04:07 +02:00
Github Actions a5dad40521 [CI Skip] release/beta 4.0.3-26
skip-checks: true
2021-06-07 14:05:43 +00:00
Jaco Greeff e8263b2597 Adjust cron locks 2021-06-07 16:59:58 +03:00
Github Actions 9d6c0afc8e [CI Skip] release/beta 4.0.3-25
skip-checks: true
2021-06-06 19:30:29 +00:00
Jaco Greeff 6393d078e8 Adjust semgrep check 2021-06-06 22:25:08 +03:00
Github Actions c62f6493d9 [CI Skip] release/beta 4.0.3-24
skip-checks: true
2021-06-05 11:13:51 +00:00
Jaco Greeff e8737c403e No semgrep.yml on forks 2021-06-05 14:07:33 +03:00
Github Actions f279a89dc7 [CI Skip] release/beta 4.0.3-23
skip-checks: true
2021-06-05 06:43:12 +00:00
Jaco Greeff 30463cfe75 push-master.yml adjust skip 2021-06-05 09:38:11 +03:00
Github Actions c1405bbe2e [CI Skip] release/beta 4.0.3-22
skip-checks: true
2021-06-05 06:28:05 +00:00
Jaco 7d9dafd9e1 semgrep.yml on PR (#198)
* semgrep.yml on PR

* if

* if adjust

* if test

* Check
2021-06-05 08:22:35 +02:00
Github Actions e0e3634714 [CI Skip] release/beta 4.0.3-21
skip-checks: true
2021-06-04 14:38:13 +00:00
Jaco Greeff a5818af5fe Update semgrep.yml 2021-06-04 17:32:21 +03:00
Github Actions 6ebec52ffc [CI Skip] release/beta 4.0.3-20
skip-checks: true
2021-06-04 10:50:23 +00:00
Jaco Greeff ebd96dea49 semgrep skip 2021-06-04 13:44:52 +03:00
Github Actions d692383d80 [CI Skip] release/beta 4.0.3-19
skip-checks: true
2021-06-04 08:44:52 +00:00
Jaco Greeff cefc8c97ec semgrep on master only 2021-06-04 11:38:32 +03:00
Github Actions 8ce18ff065 [CI Skip] release/beta 4.0.3-18
skip-checks: true
2021-06-04 05:41:43 +00:00
Jaco Greeff 40a97d2206 semgrep only for non-forked 2021-06-04 08:35:56 +03:00
Github Actions e111d9e91d [CI Skip] release/beta 4.0.3-17
skip-checks: true
2021-06-02 16:09:06 +00:00
Jaco Greeff faf407d62d fix stale.yml 2021-06-02 19:03:33 +03:00
Github Actions cf5759a324 [CI Skip] release/beta 4.0.3-16
skip-checks: true
2021-06-02 07:11:39 +00:00
Jaco Greeff d220a69ab1 cron workflows 2021-06-02 10:05:48 +03:00
Github Actions 4d8dde58dc [CI Skip] release/beta 4.0.3-15
skip-checks: true
2021-06-01 10:04:28 +00:00
Jaco Greeff c5b98fcd5b semgrep.yml 2021-06-01 12:58:33 +03:00
Github Actions 482576be81 [CI Skip] release/beta 4.0.3-14
skip-checks: true
2021-06-01 06:08:44 +00:00
Jaco Greeff fdea2aa4dc cron daily only 2021-06-01 09:03:50 +03:00
Github Actions e4dbdc570d [CI Skip] release/beta 4.0.3-13
skip-checks: true
2021-05-31 20:21:54 +00:00
Jaco Greeff 7f3146ce64 cron locks 2021-05-31 23:15:39 +03:00
Github Actions 1bf001b2f3 [CI Skip] release/beta 4.0.3-12
skip-checks: true
2021-05-31 07:55:52 +00:00
Jaco 2a99496e9a Update .123trigger 2021-05-31 09:49:34 +02:00
Github Actions 59ba89a032 [CI Skip] release/beta 4.0.3-11
skip-checks: true
2021-05-31 07:48:52 +00:00
Jaco Greeff be9786fc4c Bump dev 2021-05-31 10:42:50 +03:00
Jaco 629140e6c3 Bump dev (#197) 2021-05-31 09:15:12 +02:00
Jaco Greeff 5f46f9e698 lock.yml 2021-05-30 22:22:16 +03:00
Github Actions d4daf14c77 [CI Skip] release/beta 4.0.3-11
skip-checks: true
2021-05-30 09:38:55 +00:00
Jaco cfdaab8f86 Bump berry (#196)
* Bump berry

* Bumps
2021-05-30 11:33:41 +02:00
Github Actions 70ca570a66 [CI Skip] release/beta 4.0.3-10
skip-checks: true
2021-05-29 08:24:22 +00:00
Jaco Greeff ab7e12a30d Update stale.yml 2021-05-29 11:18:37 +03:00
Github Actions 87a95b9ab2 [CI Skip] release/beta 4.0.3-9
skip-checks: true
2021-05-28 08:45:18 +00:00
Jaco Greeff 9aff03c5b6 Update stale.yml 2021-05-28 11:39:36 +03:00
Github Actions adfa4fb099 [CI Skip] release/beta 4.0.3-8
skip-checks: true
2021-05-28 08:11:42 +00:00
Jaco 5e8b3c1c24 Add stale.yml (#195) 2021-05-28 10:06:59 +02:00
Github Actions 714b9ebf48 [CI Skip] release/beta 4.0.3-7
skip-checks: true
2021-05-28 06:45:01 +00:00
Jaco c93dbd2d2e Apply lgtm alert fixes (#194) 2021-05-28 08:40:18 +02:00
Github Actions 7139f1fe42 [CI Skip] release/beta 4.0.3-6
skip-checks: true
2021-05-26 20:20:07 +00:00
Jaco 7e490f1f96 Bump deps (#193) 2021-05-26 22:15:16 +02:00
Github Actions b6aa432b26 [CI Skip] release/beta 4.0.3-5
skip-checks: true
2021-05-07 05:26:26 +00:00
Jaco 547e31ffef Bump dev (#191) 2021-05-07 07:20:53 +02:00
Github Actions 092ee15603 [CI Skip] release/beta 4.0.3-4
skip-checks: true
2021-04-30 05:55:01 +00:00
Jaco dd52d5158e Bump deps (#190) 2021-04-30 07:47:21 +02:00
Github Actions 88d8f79e3c [CI Skip] release/beta 4.0.3-3
skip-checks: true
2021-04-24 07:39:11 +00:00
Jaco 3a1a75f99f Add engines field to package.json (#189) 2021-04-24 09:32:52 +02:00
Github Actions 422c23dbbd [CI Skip] release/beta 4.0.3-2
skip-checks: true
2021-04-21 07:20:11 +00:00
Jaco 13fd02d455 Bump deps (#188) 2021-04-21 09:13:36 +02:00
Github Actions b75e2e4778 [CI Skip] release/beta 4.0.3-1
skip-checks: true
2021-04-08 08:22:23 +00:00
Jaco Greeff 43222700be Bump deps (#187) 2021-04-08 10:16:07 +02:00
Github Actions 05abb02b64 [CI Skip] release/beta 4.0.3-0
skip-checks: true
2021-03-08 15:27:35 +00:00
Jaco Greeff bf1590ab70 Bump TS (#186) 2021-03-08 16:21:16 +01:00
40 changed files with 4350 additions and 3579 deletions
+3 -4
View File
@@ -1,7 +1,6 @@
4
6
3.2.2
3.2.3
3.2.4
4.0.2
4.0.2
4.1.2
+23
View File
@@ -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.
+1 -8
View File
@@ -6,11 +6,11 @@ on:
jobs:
master:
if: "! startsWith(github.event.head_commit.message, '[CI Skip]')"
strategy:
matrix:
step: ['build:release']
name: ${{ matrix.step }}
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/wasm'"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@@ -26,10 +26,3 @@ jobs:
yarn install --immutable | grep -v 'YN0013'
./scripts/install-build-deps.sh
yarn ${{ matrix.step }}
dummy:
runs-on: ubuntu-latest
steps:
- name: dummy
run: |
echo "Dummy skip step"
+18
View File
@@ -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
+17
View File
@@ -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
+4
View File
@@ -0,0 +1,4 @@
build
coverage
packages
scripts
+4
View File
@@ -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
-55
View File
File diff suppressed because one or more lines are too long
+631
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -10,4 +10,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
yarnPath: .yarn/releases/yarn-2.4.1.cjs
yarnPath: .yarn/releases/yarn-3.0.1.cjs
+27
View File
@@ -1,5 +1,32 @@
# CHANGELOG
## 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:
+7 -5
View File
@@ -7,11 +7,12 @@
"packages/*"
],
"resolutions": {
"typescript": "^4.2.2"
"typescript": "^4.3.5"
},
"scripts": {
"build": "yarn build:wasm",
"build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config",
"build:wasm": "./scripts/build.sh",
"lint": "polkadot-dev-run-lint",
"clean": "./scripts/clean.sh",
@@ -23,10 +24,11 @@
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
},
"devDependencies": {
"@babel/core": "^7.13.8",
"@polkadot/dev": "^0.62.5",
"fflate": "^0.6.7",
"@babel/core": "^7.15.0",
"@polkadot/dev": "^0.62.62",
"fflate": "^0.7.1",
"override-require": "^1.1.1"
},
"version": "4.0.2"
"version": "4.2.1",
"packageManager": "yarn@3.0.1"
}
+5 -2
View File
@@ -1,12 +1,15 @@
{
"name": "@polkadot/wasm-crypto-asmjs",
"version": "4.0.2",
"version": "4.2.1",
"type": "module",
"description": "Asm.js content for wasm-crypto",
"browser": "empty.js",
"main": "empty.js",
"react-native": "data.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
@@ -14,6 +17,6 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"dependencies": {
"@babel/runtime": "^7.13.9"
"@babel/runtime": "^7.15.3"
}
}
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.0.2' };
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.2.1' };
+5 -2
View File
@@ -1,12 +1,15 @@
{
"name": "@polkadot/wasm-crypto-wasm",
"version": "4.0.2",
"version": "4.2.1",
"type": "module",
"description": "Wasm content for wasm-crypto",
"browser": "data.js",
"main": "data.js",
"react-native": "data.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
@@ -14,6 +17,6 @@
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"dependencies": {
"@babel/runtime": "^7.13.9"
"@babel/runtime": "^7.15.3"
}
}
+2 -2
View File
@@ -46,8 +46,8 @@ 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;
let tmp;
let i: number;
let tmp: number;
// if there are placeholders, only get up to the last complete 4 chars
const len = placeHoldersLen > 0
+2 -2
View File
@@ -265,7 +265,7 @@ const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
// length tree distance tree
const lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
// max length bits
lbt = max(lt)
lbt = max(lt);
// max dist bits
dbt = max(dt);
lm = hMap(lt, lbt, 1);
@@ -321,7 +321,7 @@ const inflt = (dat: Uint8Array, buf?: Uint8Array, st?: InflateState) => {
}
st.l = lm, st.p = pos, st.b = bt;
if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
} while (!final)
} while (!final);
return bt == buf.length ? buf : slc(buf, 0, bt);
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.0.2' };
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.2.1' };
+3
View File
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.13.0"
@@ -659,6 +661,7 @@ version = "0.0.0"
dependencies = [
"blake2-rfc",
"byteorder",
"curve25519-dalek",
"ed25519-dalek",
"hex-literal",
"hmac",
+1
View File
@@ -22,6 +22,7 @@ hmac = "0.7.0"
# libsecp256k1 = "0.2.2"
merlin = { version = "2.0", default-features = false }
pbkdf2 = { version = "0.3.0", default-features = false }
curve25519-dalek = { version = "2.1.0", default-features = false }
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
scrypt = { version = "0.2", default-features = false }
sha2 = "0.8.1"
+9 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/wasm-crypto",
"version": "4.0.2",
"version": "4.2.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"main": "index.js",
@@ -8,14 +8,17 @@
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"dependencies": {
"@babel/runtime": "^7.13.9",
"@polkadot/wasm-crypto-asmjs": "^4.0.2",
"@polkadot/wasm-crypto-wasm": "^4.0.2"
"@babel/runtime": "^7.15.3",
"@polkadot/wasm-crypto-asmjs": "^4.2.1",
"@polkadot/wasm-crypto-wasm": "^4.2.1"
},
"devDependencies": {
"@polkadot/util": "^6.0.1-6",
"@polkadot/x-randomvalues": "^6.0.1-6"
"@polkadot/util": "^7.2.1",
"@polkadot/x-randomvalues": "^7.2.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+268
View File
@@ -0,0 +1,268 @@
// 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 wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
export const bip39Generate = withWasm((wasm) =>
(words: 12 | 15 | 18 | 21 | 24): string => {
wasm.ext_bip39_generate(8, words);
return resultString();
}
);
export const bip39ToEntropy = withWasm((wasm) =>
(phrase: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
wasm.ext_bip39_to_entropy(8, ptr0, len0);
return resultU8a();
}
);
export const bip39ToMiniSecret = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39ToSeed = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39Validate = withWasm((wasm) =>
(phrase: string): boolean => {
const [ptr0, len0] = allocString(phrase);
const ret = wasm.ext_bip39_validate(ptr0, len0);
return ret !== 0;
}
);
export const ed25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_ed_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const ed25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(seckey);
const [ptr2, len2] = allocU8a(message);
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const ed25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DerivePublicSoft = withWasm((wasm) =>
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_sr_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const sr25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(secret);
const [ptr2, len2] = allocU8a(message);
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const sr25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const sr25519Agree = withWasm((wasm) =>
(pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(secret);
wasm.ext_sr_agree(8, 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(8, 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(8, ptr0, len0, ptr1, len1, size);
return resultU8a();
}
);
export const keccak256 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak256(8, ptr0, len0);
return resultU8a();
}
);
export const pbkdf2 = withWasm((wasm) =>
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
return resultU8a();
}
);
export const scrypt = withWasm((wasm) =>
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
const [ptr0, len0] = allocU8a(password);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
return resultU8a();
}
);
export const sha512 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha512(8, ptr0, len0);
return resultU8a();
}
);
export const twox = withWasm((wasm) =>
(data: Uint8Array, rounds: number) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_twox(8, ptr0, len0, rounds);
return resultU8a();
}
);
export function isReady (): boolean {
return !!getWasm();
}
export function waitReady (): Promise<boolean> {
return wasmPromise.then(() => isReady());
}
+1 -254
View File
@@ -3,257 +3,4 @@
import './detectPackage';
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 wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
export const bip39Generate = withWasm((wasm) =>
(words: 12 | 15 | 18 | 21 | 24): string => {
wasm.ext_bip39_generate(8, words);
return resultString();
}
);
export const bip39ToEntropy = withWasm((wasm) =>
(phrase: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
wasm.ext_bip39_to_entropy(8, ptr0, len0);
return resultU8a();
}
);
export const bip39ToMiniSecret = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39ToSeed = withWasm((wasm) =>
(phrase: string, password: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const bip39Validate = withWasm((wasm) =>
(phrase: string): boolean => {
const [ptr0, len0] = allocString(phrase);
const ret = wasm.ext_bip39_validate(ptr0, len0);
return ret !== 0;
}
);
export const ed25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_ed_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const ed25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(seckey);
const [ptr2, len2] = allocU8a(message);
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const ed25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519DerivePublicSoft = withWasm((wasm) =>
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const sr25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_sr_from_seed(8, ptr0, len0);
return resultU8a();
}
);
export const sr25519Sign = withWasm((wasm) =>
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(secret);
const [ptr2, len2] = allocU8a(message);
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
);
export const sr25519Verify = withWasm((wasm) =>
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
const [ptr0, len0] = allocU8a(signature);
const [ptr1, len1] = allocU8a(message);
const [ptr2, len2] = allocU8a(pubkey);
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
return ret !== 0;
}
);
export const 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(8, 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(8, ptr0, len0, ptr1, len1, size);
return resultU8a();
}
);
export const keccak256 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak256(8, ptr0, len0);
return resultU8a();
}
);
export const pbkdf2 = withWasm((wasm) =>
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
return resultU8a();
}
);
export const scrypt = withWasm((wasm) =>
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
const [ptr0, len0] = allocU8a(password);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
return resultU8a();
}
);
export const sha512 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha512(8, ptr0, len0);
return resultU8a();
}
);
export const twox = withWasm((wasm) =>
(data: Uint8Array, rounds: number) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_twox(8, ptr0, len0, rounds);
return resultU8a();
}
);
export function isReady (): boolean {
return !!getWasm();
}
export function waitReady (): Promise<boolean> {
return wasmPromise.then(() => isReady());
}
export * from './bundle';
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.0.2' };
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.2.1' };
+53 -1
View File
@@ -7,6 +7,7 @@
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
use curve25519_dalek::scalar::Scalar;
use schnorrkel::{
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
@@ -134,13 +135,36 @@ pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
}
}
/// 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)]
pub mod tests {
extern crate rand;
extern crate schnorrkel;
use hex_literal::hex;
use super::*;
use hex_literal::hex;
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
fn generate_random_seed() -> Vec<u8> {
@@ -243,4 +267,32 @@ pub mod tests {
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));
}
}
+1
View File
@@ -32,6 +32,7 @@ export interface WasmCryptoInstance {
ext_sr_from_seed(a: number, b: number, c: number): void;
ext_sr_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
ext_sr_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
ext_sr_agree(a: number, b: number, c: number, d: number, e: number): void;
ext_vrf_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void;
ext_vrf_verify(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number;
}
+12 -14
View File
@@ -1,11 +1,9 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, u8aToHex } = require('@polkadot/util');
function bip39_generate (wasm) {
function bip39Generate (wasm) {
const res = wasm.bip39Generate(21);
console.log('\tPHR', res);
@@ -13,7 +11,7 @@ function bip39_generate (wasm) {
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
}
function bip39_generate_subsequent (wasm) {
function bip39GenerateSubsequent (wasm) {
const val1 = wasm.bip39Generate(24);
const val2 = wasm.bip39Generate(24);
@@ -23,7 +21,7 @@ function bip39_generate_subsequent (wasm) {
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
}
function bip39_validate (wasm) {
function bip39Validate (wasm) {
const res = wasm.bip39Validate(wasm.bip39Generate(12));
console.log('\tVAL', res);
@@ -31,7 +29,7 @@ function bip39_validate (wasm) {
assert(res, 'ERROR: Invalid bip39 validation');
}
function bip39_toEntropy (wasm) {
function bip39ToEntropy (wasm) {
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
console.log('\tENT', res);
@@ -39,7 +37,7 @@ function bip39_toEntropy (wasm) {
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
}
function bip39_toMiniSecret (wasm) {
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);
@@ -47,7 +45,7 @@ function bip39_toMiniSecret (wasm) {
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
}
function bip39_toSeed (wasm) {
function bip39ToSeed (wasm) {
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
console.log('\tSEE', res);
@@ -56,10 +54,10 @@ function bip39_toSeed (wasm) {
}
module.exports = {
bip39_generate,
bip39_generate_subsequent,
bip39_toEntropy,
bip39_toMiniSecret,
bip39_toSeed,
bip39_validate
bip39Generate,
bip39GenerateSubsequent,
bip39ToEntropy,
bip39ToMiniSecret,
bip39ToSeed,
bip39Validate
};
+8 -10
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
}
function ed25519_pairFromSeed (wasm) {
function ed25519PairFromSeed (wasm) {
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
console.log('\tSEC', u8aToHex(sk));
@@ -23,7 +21,7 @@ function ed25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
}
function ed25519_signAndVerify (wasm) {
function ed25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -34,7 +32,7 @@ function ed25519_signAndVerify (wasm) {
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'));
console.log('\tRES', isValid);
@@ -42,7 +40,7 @@ function ed25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function ed25519_benchmark (wasm) {
function ed25519Benchmark (wasm) {
const MESSAGE = stringToU8a('this is a message');
for (let i = 0; i < 256; i++) {
@@ -53,8 +51,8 @@ function ed25519_benchmark (wasm) {
}
module.exports = {
ed25519_benchmark,
ed25519_pairFromSeed,
ed25519_signAndVerify,
ed25519_verifyExisting
ed25519Benchmark,
ed25519PairFromSeed,
ed25519SignAndVerify,
ed25519VerifyExisting
};
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
function blake2bHash (wasm) {
+40 -24
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function sr25519_pairFromSeed (wasm) {
function sr25519PairFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -23,7 +21,7 @@ function sr25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
}
function sr25519_devFromSeed (wasm) {
function sr25519DevFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -32,7 +30,7 @@ function sr25519_devFromSeed (wasm) {
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
}
function sr25519_verifyExisting (wasm) {
function sr25519VerifyExisting (wasm) {
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
@@ -44,7 +42,7 @@ function sr25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_sign_deterministic (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')));
@@ -55,7 +53,7 @@ function sr25519_sign_deterministic (wasm) {
assert(sig1 !== sig2, 'ERROR: Signatures are deterministic');
}
function sr25519_signAndVerify (wasm) {
function sr25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -66,7 +64,7 @@ function sr25519_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_deriveHard (wasm) {
function sr25519DeriveHard (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -74,7 +72,7 @@ function sr25519_deriveHard (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveHardKnown (wasm) {
function sr25519DeriveHardKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -84,7 +82,7 @@ function sr25519_deriveHardKnown (wasm) {
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
}
function sr25519_deriveSoft (wasm) {
function sr25519DeriveSoft (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -92,7 +90,7 @@ function sr25519_deriveSoft (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveSoftKnown (wasm) {
function sr25519DeriveSoftKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -102,7 +100,7 @@ function sr25519_deriveSoftKnown (wasm) {
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
}
function sr25519_deriveSoftPubkey (wasm) {
function sr25519DeriveSoftPubkey (wasm) {
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
console.log('\tPUB', derived);
@@ -110,7 +108,24 @@ function sr25519_deriveSoftPubkey (wasm) {
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');
for (let i = 0; i < 256; i++) {
@@ -121,15 +136,16 @@ function sr25519_benchmark (wasm) {
}
module.exports = {
sr25519_benchmark,
sr25519_deriveHard,
sr25519_deriveHardKnown,
sr25519_deriveSoft,
sr25519_deriveSoftKnown,
sr25519_deriveSoftPubkey,
sr25519_devFromSeed,
sr25519_pairFromSeed,
sr25519_signAndVerify,
sr25519_sign_deterministic,
sr25519_verifyExisting
sr25519Benchmark,
sr25519DeriveHard,
sr25519DeriveHardKnown,
sr25519DeriveSoft,
sr25519DeriveSoftKnown,
sr25519DeriveSoftPubkey,
sr25519DevFromSeed,
sr25519KeyAgreement,
sr25519PairFromSeed,
sr25519SignAndVerify,
sr25519SignDeterministic,
sr25519VerifyExisting
};
+6 -8
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function vrf_signAndVerify_compat (wasm) {
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);
@@ -25,7 +23,7 @@ function vrf_signAndVerify_compat (wasm) {
assert(isValid, 'ERROR: Unable to verify VRF output & proof');
}
function vrf_signAndVerify (wasm) {
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);
@@ -36,7 +34,7 @@ function vrf_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify VRF extra output & proof');
}
function vrf_signAndVerify_deterministic (wasm) {
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'));
@@ -50,7 +48,7 @@ function vrf_signAndVerify_deterministic (wasm) {
}
module.exports = {
vrf_signAndVerify,
vrf_signAndVerify_compat,
vrf_signAndVerify_deterministic
vrfSignAndVerify,
vrfSignAndVerifyCompat,
vrfSignAndVerifyDeterministic
};
+30
View File
@@ -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] || {})
})
);
+6 -6
View File
@@ -5,8 +5,7 @@
set -e
# also change in install-build-deps
RUST_VER=nightly-2020-10-25
source ../scripts/rust-version.sh
WSM=bytes/wasm_bg.wasm
OPT=bytes/wasm_opt.wasm
@@ -15,17 +14,18 @@ ASM=wasm-crypto-asmjs/build/cjs/data.js
# build new via wasm-pack
echo "*** Building Rust sources"
cd wasm-crypto
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
# rustup run $RUST_VER cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
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
# wasm-pack build --release --scope polkadot --target web
# optimise
echo "*** Optimising WASM output"
# ../../wabt/bin/wasm-strip $WSM
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
+2
View File
@@ -26,3 +26,5 @@ echo "*** wasm-crypto-wasm"
ls -alR wasm-crypto-wasm/build
cd ..
yarn build:rollup
+5 -3
View File
@@ -5,8 +5,7 @@
set -e
# also change in build-package
RUST_VER=nightly-2020-10-25
source ./scripts/rust-version.sh
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
BINARYEN_VER=version_97
@@ -24,7 +23,10 @@ unamestr=`uname`
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
cargo install xargo
if [ "$RUST_VER" != "stable" ]; then
cargo install xargo
fi
if [[ "$unamestr" == 'Linux' ]]; then
echo "*** Detected Linux"
+7 -26
View File
@@ -5,39 +5,20 @@ const fflate = require('fflate/node');
const fs = require('fs');
const { formatNumber } = require('@polkadot/util');
// const A_NAME = 'wasm-crypto-asmjs';
const W_NAME = 'wasm-crypto-wasm';
function hdr (package) {
return `// Copyright 2019-2021 @polkadot/${package} authors & contributors
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
`;
}
function getWasmBuffer () {
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)}%)`);
return { compressed, sizeUncompressed: data.length };
}
// fs.writeFileSync(`./${A_NAME}/build/data.js`, `${hdr(A_NAME)}
// export { asmJsInit } from './data.cjs';
// `);
// fs.writeFileSync(`./${W_NAME}/build/bytes.js`, `${hdr(W_NAME)}
// export { bytes, sizeCompressed, sizeUncompressed } from './bytes.cjs';
// `);
const { compressed, sizeUncompressed } = getWasmBuffer();
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `${hdr(W_NAME)}
const sizeCompressed = ${compressed.length};
const sizeUncompressed = ${sizeUncompressed};
const sizeUncompressed = ${data.length};
const bytes = '${compressed.toString('base64')}';
module.exports = { bytes, sizeCompressed, sizeUncompressed };
+7
View File
@@ -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
+3124 -3123
View File
File diff suppressed because it is too large Load Diff