Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
+5
-1
@@ -1 +1,5 @@
|
||||
4
|
||||
5
|
||||
3.2.2
|
||||
3.2.3
|
||||
3.2.4
|
||||
4.0.2
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const base = require('@polkadot/dev/config/eslint.cjs');
|
||||
|
||||
@@ -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.
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
@@ -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');
|
||||
+7
-9
File diff suppressed because one or more lines are too long
+7
-9
File diff suppressed because one or more lines are too long
Vendored
-55
File diff suppressed because one or more lines are too long
+591
File diff suppressed because one or more lines are too long
+1
-1
@@ -10,4 +10,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-2.4.0.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.0.0-rc.2.cjs
|
||||
|
||||
@@ -1,5 +1,63 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 4.1.1 Jul 7, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
- Add an explicit `engines` field to `package.json`
|
||||
- Allow building as a completely stand-alone browser bundle
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const config = require('@polkadot/dev/config/jest.cjs');
|
||||
@@ -15,5 +15,5 @@ module.exports = Object.assign({}, config, {
|
||||
'<rootDir>/packages/wasm-crypto-wasm/build',
|
||||
'<rootDir>/packages/wasm-crypto/build'
|
||||
],
|
||||
resolver: '@polkadot/dev/config/jest-resolver.cjs'
|
||||
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
|
||||
});
|
||||
+8
-6
@@ -7,11 +7,12 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^4.1.3"
|
||||
"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",
|
||||
@@ -19,13 +20,14 @@
|
||||
"test": "yarn test:wasm:rust",
|
||||
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
||||
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
||||
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.js && node ./test/asm.js",
|
||||
"test:wasm: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": {
|
||||
"@babel/core": "^7.12.10",
|
||||
"@polkadot/dev": "^0.61.13",
|
||||
"fflate": "^0.4.3"
|
||||
"@babel/core": "^7.14.6",
|
||||
"@polkadot/dev": "^0.62.52",
|
||||
"fflate": "^0.7.1",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
"version": "3.1.1"
|
||||
"version": "4.1.1"
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto-asmjs",
|
||||
"version": "3.1.1",
|
||||
"version": "4.1.1",
|
||||
"type": "module",
|
||||
"description": "Asm.js content for wasm-crypto",
|
||||
"browser": "empty.js",
|
||||
"main": "empty.js",
|
||||
"module": "empty.mjs",
|
||||
"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.12.5"
|
||||
"@babel/runtime": "^7.14.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const asmJsInit = null;
|
||||
import { asmJsInit as _asmJsInit } from './cjs/data.js';
|
||||
|
||||
export const asmJsInit = _asmJsInit;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||
// 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.1.1' };
|
||||
@@ -1,12 +1,15 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto-wasm",
|
||||
"version": "3.1.1",
|
||||
"version": "4.1.1",
|
||||
"type": "module",
|
||||
"description": "Wasm content for wasm-crypto",
|
||||
"browser": "data.js",
|
||||
"main": "data.js",
|
||||
"module": "data.mjs",
|
||||
"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.12.5"
|
||||
"@babel/runtime": "^7.14.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
let tmp;
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const buffer = Buffer.from([]);
|
||||
|
||||
export const sizeCompressed = 0;
|
||||
|
||||
export const sizeUncompressed = 0;
|
||||
@@ -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"
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { buffer, sizeUncompressed } from './buffer';
|
||||
import { toByteArray } from './base64';
|
||||
import { bytes, sizeUncompressed } from './bytes';
|
||||
import { unzlibSync } from './fflate';
|
||||
|
||||
export const wasmBytes = unzlibSync(buffer, new Uint8Array(sizeUncompressed));
|
||||
export const wasmBytes = unzlibSync(toByteArray(bytes), new Uint8Array(sizeUncompressed));
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const wasmBytes = null;
|
||||
export const bytes = null;
|
||||
|
||||
export const sizeCompressed = 0;
|
||||
|
||||
export const sizeUncompressed = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// MIT License
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.1.1' };
|
||||
Generated
+1
@@ -662,6 +662,7 @@ dependencies = [
|
||||
"ed25519-dalek",
|
||||
"hex-literal",
|
||||
"hmac",
|
||||
"merlin",
|
||||
"pbkdf2",
|
||||
"rand",
|
||||
"schnorrkel",
|
||||
|
||||
@@ -20,6 +20,7 @@ byteorder = "1.3.1"
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||
hmac = "0.7.0"
|
||||
# libsecp256k1 = "0.2.2"
|
||||
merlin = { version = "2.0", default-features = false }
|
||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
|
||||
scrypt = { version = "0.2", default-features = false }
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto",
|
||||
"version": "3.1.1",
|
||||
"version": "4.1.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/wasm-crypto-asmjs": "^3.1.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^3.1.1"
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/wasm-crypto-asmjs": "^4.1.1",
|
||||
"@polkadot/wasm-crypto-wasm": "^4.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.61.13",
|
||||
"@polkadot/util": "^5.0.2-9",
|
||||
"@polkadot/x-randomvalues": "^5.0.2-9",
|
||||
"override-require": "^1.1.1"
|
||||
"@polkadot/util": "^6.11.1",
|
||||
"@polkadot/x-randomvalues": "^6.11.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
// 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 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,25 +1,10 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
||||
//
|
||||
// new URL(import.meta.url).pathname)
|
||||
//
|
||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
||||
// there is a complete dead end with usage thereof
|
||||
//
|
||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
||||
//
|
||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
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 './package-info.json';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [asmInfo, wasmInfo]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
@@ -1,231 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
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';
|
||||
|
||||
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
|
||||
|
||||
export const bip39Generate = withWasm((wasm) =>
|
||||
(words: 12 | 15 | 18 | 21 | 24): string => {
|
||||
wasm.ext_bip39_generate(8, words);
|
||||
|
||||
return resultString();
|
||||
}
|
||||
);
|
||||
|
||||
export const bip39ToEntropy = withWasm((wasm) =>
|
||||
(phrase: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
|
||||
wasm.ext_bip39_to_entropy(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const bip39ToMiniSecret = withWasm((wasm) =>
|
||||
(phrase: string, password: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
|
||||
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const bip39ToSeed = withWasm((wasm) =>
|
||||
(phrase: string, password: string): Uint8Array => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const [ptr1, len1] = allocString(password);
|
||||
|
||||
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const bip39Validate = withWasm((wasm) =>
|
||||
(phrase: string): boolean => {
|
||||
const [ptr0, len0] = allocString(phrase);
|
||||
const ret = wasm.ext_bip39_validate(ptr0, len0);
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
|
||||
export const ed25519KeypairFromSeed = withWasm((wasm) =>
|
||||
(seed: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
|
||||
wasm.ext_ed_from_seed(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const ed25519Sign = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(seckey);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
|
||||
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const ed25519Verify = withWasm((wasm) =>
|
||||
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const [ptr0, len0] = allocU8a(signature);
|
||||
const [ptr1, len1] = allocU8a(message);
|
||||
const [ptr2, len2] = allocU8a(pubkey);
|
||||
const ret = wasm.ext_ed_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519DeriveKeypairHard = withWasm((wasm) =>
|
||||
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
|
||||
(pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pair);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519DerivePublicSoft = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(cc);
|
||||
|
||||
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519KeypairFromSeed = withWasm((wasm) =>
|
||||
(seed: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(seed);
|
||||
|
||||
wasm.ext_sr_from_seed(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519Sign = withWasm((wasm) =>
|
||||
(pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(pubkey);
|
||||
const [ptr1, len1] = allocU8a(secret);
|
||||
const [ptr2, len2] = allocU8a(message);
|
||||
|
||||
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sr25519Verify = withWasm((wasm) =>
|
||||
(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const [ptr0, len0] = allocU8a(signature);
|
||||
const [ptr1, len1] = allocU8a(message);
|
||||
const [ptr2, len2] = allocU8a(pubkey);
|
||||
const ret = wasm.ext_sr_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
|
||||
return ret !== 0;
|
||||
}
|
||||
);
|
||||
|
||||
export const blake2b = withWasm((wasm) =>
|
||||
(data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(key);
|
||||
|
||||
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const keccak256 = withWasm((wasm) =>
|
||||
(data: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_keccak256(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const pbkdf2 = withWasm((wasm) =>
|
||||
(data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
|
||||
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const scrypt = withWasm((wasm) =>
|
||||
(password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(password);
|
||||
const [ptr1, len1] = allocU8a(salt);
|
||||
|
||||
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const sha512 = withWasm((wasm) =>
|
||||
(data: Uint8Array): Uint8Array => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_sha512(8, ptr0, len0);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export const twox = withWasm((wasm) =>
|
||||
(data: Uint8Array, rounds: number) => {
|
||||
const [ptr0, len0] = allocU8a(data);
|
||||
|
||||
wasm.ext_twox(8, ptr0, len0, rounds);
|
||||
|
||||
return resultU8a();
|
||||
}
|
||||
);
|
||||
|
||||
export function isReady (): boolean {
|
||||
return !!getWasm();
|
||||
}
|
||||
|
||||
export function waitReady (): Promise<boolean> {
|
||||
return wasmPromise.then(() => isReady());
|
||||
}
|
||||
export * from './bundle';
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Be able to import json in TS
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Use `wee_alloc` as the global allocator.
|
||||
@@ -16,3 +16,6 @@ pub mod hashing;
|
||||
|
||||
#[path = "rs/sr25519.rs"]
|
||||
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.1.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,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use blake2_rfc::blake2b::blake2b;
|
||||
@@ -7,7 +7,6 @@ use hmac::Hmac;
|
||||
use pbkdf2::pbkdf2;
|
||||
use scrypt::{ScryptParams, scrypt};
|
||||
use sha2::{Digest, Sha512};
|
||||
// use secp256k1;
|
||||
use tiny_keccak::{Hasher, Keccak};
|
||||
use twox_hash::XxHash;
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -95,58 +94,6 @@ pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> V
|
||||
}
|
||||
}
|
||||
|
||||
// /// Checks for the recoverability of a signature from message
|
||||
// ///
|
||||
// /// * message: The message
|
||||
// /// * signature: The signature
|
||||
// ///
|
||||
// /// Returns 0 on success, or a specific error code
|
||||
// #[wasm_bindgen]
|
||||
// pub fn ext_secp256k1_is_recoverable(message: &[u8], signature: &[u8]) -> u32 {
|
||||
// let rs = match secp256k1::Signature::parse_slice(&signature[0..64]) {
|
||||
// Ok(rs) => rs,
|
||||
// _ => return 1
|
||||
// };
|
||||
// let v = match secp256k1::RecoveryId::parse(if signature[64] > 26 { signature[64] - 27 } else { signature[64] } as u8) {
|
||||
// Ok(v) => v,
|
||||
// _ => return 2
|
||||
// };
|
||||
// let mut msg = [0u8; 32];
|
||||
|
||||
// msg.copy_from_slice(&message);
|
||||
|
||||
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
|
||||
// Ok(_) => 0,
|
||||
// _ => 3
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// Recovers the secp256k1 signature from the input
|
||||
// ///
|
||||
// /// * 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);
|
||||
|
||||
// match secp256k1::recover(&secp256k1::Message::parse(&msg), &rs, &v) {
|
||||
// Ok(pk) => return pk.serialize()[1..65].to_vec(),
|
||||
// _ => panic!("Unable to recover publickey")
|
||||
// }
|
||||
// }
|
||||
|
||||
/// sha512 hash for the specified input
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
@@ -186,24 +133,6 @@ pub mod tests {
|
||||
use hex_literal::hex;
|
||||
use super::*;
|
||||
|
||||
// // Constructs the message that Ethereum RPCs `personal_sign` and `eth_sign` would sign.
|
||||
// fn ethereum_signable_message(data: &[u8]) -> Vec<u8> {
|
||||
// let prefix = b"Pay DOTs to the Polkadot account:";
|
||||
// let mut l = prefix.len() + data.len();
|
||||
// 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]
|
||||
fn can_blake2b() {
|
||||
let data = b"abc";
|
||||
@@ -245,17 +174,6 @@ pub mod tests {
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn can_secp256k1_real_eth_sig() {
|
||||
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
|
||||
// let pk = hex!("DF67EC7EAe23D2459694685257b6FC59d1BAA1FE");
|
||||
// let data = [42, 0, 0, 0, 0, 0, 0, 0];
|
||||
// let msg = ext_keccak256(ðereum_signable_message(&data));
|
||||
// let result = ext_keccak256(&ext_secp256k1_recover(&msg[..], &sig[..]));
|
||||
|
||||
// assert_eq!(result[12..], pk[..]);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn can_sha512() {
|
||||
let data = b"hello world";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Copyright 2019 Paritytech via https://github.com/paritytech/schnorrkel-js/
|
||||
|
||||
@@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -32,6 +32,8 @@ 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_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;
|
||||
}
|
||||
|
||||
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')}`)
|
||||
);
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
require('override-require')(
|
||||
(request) =>
|
||||
request.endsWith('@polkadot/wasm-crypto-asmjs') ||
|
||||
request.endsWith('@polkadot/wasm-crypto-wasm'),
|
||||
(request) =>
|
||||
request.endsWith('@polkadot/wasm-crypto-asmjs')
|
||||
? require('../../wasm-crypto-asmjs/build/data')
|
||||
: require('../../wasm-crypto-wasm/build/empty')
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
+1
-13
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -29,17 +29,6 @@ function pbkdf2Hash (wasm) {
|
||||
assert(hash === '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270', 'ERROR: pbkdf2Hash does not match');
|
||||
}
|
||||
|
||||
// function secp256k1Recover (wasm) {
|
||||
// const pk = u8aToHex(wasm.keccak256(wasm.secp256k1Recover(
|
||||
// hexToU8a('0x2bbfa926ee947dfac384d981f8913b4e0992e52d7b6711e0ec3d9f8b0f752648'),
|
||||
// hexToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c')
|
||||
// )));
|
||||
|
||||
// console.log('\tPUB', pk);
|
||||
|
||||
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
|
||||
// }
|
||||
|
||||
function scryptHash (wasm) {
|
||||
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
|
||||
|
||||
@@ -71,7 +60,6 @@ module.exports = {
|
||||
keccak256,
|
||||
pbkdf2Hash,
|
||||
scryptHash,
|
||||
// secp256k1Recover,
|
||||
sha512Hash,
|
||||
twoxHash
|
||||
};
|
||||
@@ -1,17 +1,19 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const wasm = require('../../build/index');
|
||||
const bip39 = require('./bip39');
|
||||
const ed25519 = require('./ed25519');
|
||||
const hashing = require('./hashing');
|
||||
const sr25519 = require('./sr25519');
|
||||
const wasm = require('../../build/index.cjs');
|
||||
const bip39 = require('./bip39.cjs');
|
||||
const ed25519 = require('./ed25519.cjs');
|
||||
const hashing = require('./hashing.cjs');
|
||||
const sr25519 = require('./sr25519.cjs');
|
||||
const vrf = require('./vrf.cjs');
|
||||
|
||||
const tests = {
|
||||
...bip39,
|
||||
...ed25519,
|
||||
...hashing,
|
||||
...sr25519
|
||||
...sr25519,
|
||||
...vrf
|
||||
};
|
||||
|
||||
function beforeAll () {
|
||||
@@ -45,15 +47,14 @@ function runAll () {
|
||||
}
|
||||
|
||||
function runUnassisted () {
|
||||
(async () => {
|
||||
await beforeAll();
|
||||
beforeAll()
|
||||
.then(() => runAll())
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
runAll();
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
|
||||
process.exit(-1);
|
||||
});
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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');
|
||||
|
||||
function extractKeys (pair) {
|
||||
return [pair, pair.slice(64), pair.slice(0, 64)];
|
||||
}
|
||||
|
||||
function randomPair (wasm) {
|
||||
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
|
||||
}
|
||||
|
||||
function vrf_signAndVerify_compat (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 vrf_signAndVerify (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 vrf_signAndVerify_deterministic (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 = {
|
||||
vrf_signAndVerify,
|
||||
vrf_signAndVerify_compat,
|
||||
vrf_signAndVerify_deterministic
|
||||
};
|
||||
@@ -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,10 +0,0 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
global.WebAssembly = null;
|
||||
|
||||
require('./alias-imports');
|
||||
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
runUnassisted();
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
// override-require in jest.config.js
|
||||
|
||||
const { beforeAll, tests, wasm } = require('./all');
|
||||
import { beforeAll, tests, wasm } from './all/index.cjs';
|
||||
|
||||
describe('wasm-crypto', () => {
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -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,8 +0,0 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
require('./alias-imports');
|
||||
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
runUnassisted();
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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}`).map((p) => ({
|
||||
find: `@polkadot/${p}`,
|
||||
replacement: `../../${p}/build`
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
export default pkgs.map((pkg) =>
|
||||
createBundle({ external, pkg, ...(overrides[pkg] || {}) })
|
||||
);
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -10,7 +10,7 @@ RUST_VER=nightly-2020-10-25
|
||||
|
||||
WSM=bytes/wasm_bg.wasm
|
||||
OPT=bytes/wasm_opt.wasm
|
||||
ASM=wasm-crypto-asmjs/build/data.js
|
||||
ASM=wasm-crypto-asmjs/build/cjs/data.js
|
||||
|
||||
# build new via wasm-pack
|
||||
echo "*** Building Rust sources"
|
||||
@@ -30,7 +30,7 @@ echo "*** Optimising WASM output"
|
||||
|
||||
# convert wasm to base64 structure
|
||||
echo "*** Packing WASM into baseX"
|
||||
node ../scripts/pack-wasm-base.js
|
||||
node ../scripts/pack-wasm-base.cjs
|
||||
|
||||
# build asmjs version from the input (optimised) WASM
|
||||
echo "*** Building asm.js version"
|
||||
@@ -44,5 +44,5 @@ sed -i -e 's/var retasmFunc = /const asmJsInit = (wbg) => /' $ASM
|
||||
echo "module.exports = { asmJsInit };" >> $ASM
|
||||
|
||||
# cleanups
|
||||
rm -rf wasm-crypto-asmjs/build/*-e
|
||||
rm -rf wasm-crypto-wasm/build/*-e
|
||||
rm -rf wasm-crypto-asmjs/build/cjs/*-e
|
||||
rm -rf wasm-crypto-wasm/build/cjs/*-e
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -26,3 +26,5 @@ echo "*** wasm-crypto-wasm"
|
||||
ls -alR wasm-crypto-wasm/build
|
||||
|
||||
cd ..
|
||||
|
||||
yarn build:rollup
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -26,11 +26,6 @@ unamestr=`uname`
|
||||
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||
cargo install xargo
|
||||
|
||||
# if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||
# echo "*** Installing wasm-pack"
|
||||
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
# fi
|
||||
|
||||
if [[ "$unamestr" == 'Linux' ]]; then
|
||||
echo "*** Detected Linux"
|
||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||
@@ -59,9 +54,3 @@ if [ ! -d "bindgen" ]; then
|
||||
mv $BINDGEN_ZIP bindgen
|
||||
ls -alR bindgen
|
||||
fi
|
||||
|
||||
# if [ ! -d "wabt" ]; then
|
||||
# echo "*** Downloading wabt"
|
||||
# curl -L $WABT_REPO/releases/download/$WABT_VER/$WABT_ZIP.tar.gz | tar xz
|
||||
# mv wabt-$WABT_VER wabt
|
||||
# fi
|
||||
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019-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 A_NAME = 'wasm-crypto-asmjs';
|
||||
const W_NAME = 'wasm-crypto-wasm';
|
||||
|
||||
function hdr (package) {
|
||||
return `// Copyright 2019-2021 @polkadot/${package} 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 bytes = '${compressed.toString('base64')}';
|
||||
|
||||
module.exports = { bytes, sizeCompressed, sizeUncompressed };
|
||||
`);
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const fs = require('fs');
|
||||
const { formatNumber } = require('@polkadot/util');
|
||||
|
||||
const A_NAME = 'wasm-crypto-asmjs';
|
||||
const W_NAME = 'wasm-crypto-wasm';
|
||||
|
||||
function hdr (package) {
|
||||
return `// Copyright 2019-2020 @polkadot/${package} authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Generated as part of the build, do not edit
|
||||
`;
|
||||
}
|
||||
|
||||
// only one of the deps are included, here are the details for package.json -
|
||||
// "fflate": "^0.4.2"
|
||||
// "lz4js": "^0.2.0"
|
||||
function getWasmBuffer (lib = 'fflate') {
|
||||
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
||||
const compressed = lib === 'fflate'
|
||||
? Buffer.from(require('fflate').zlibSync(data, { level: 9 }))
|
||||
: Buffer.from(require('lz4js').compress(data));
|
||||
|
||||
console.log(`*** Compressed WASM via ${lib}: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
||||
|
||||
return { compressed, sizeUncompressed: data.length };
|
||||
}
|
||||
|
||||
fs.writeFileSync(`./${A_NAME}/build/data.mjs`, `${hdr(A_NAME)}
|
||||
export { asmJsInit } from './data.js';
|
||||
`);
|
||||
|
||||
fs.writeFileSync(`./${W_NAME}/build/buffer.mjs`, `${hdr(W_NAME)}
|
||||
export { buffer, sizeCompressed, sizeUncompressed } from './buffer.js';
|
||||
`);
|
||||
|
||||
const { compressed, sizeUncompressed } = getWasmBuffer();
|
||||
|
||||
fs.writeFileSync(`./${W_NAME}/build/buffer.js`, `${hdr(W_NAME)}
|
||||
const sizeCompressed = ${compressed.length};
|
||||
const sizeUncompressed = ${sizeUncompressed};
|
||||
const buffer = Buffer.from('${compressed.toString('base64')}', 'base64');
|
||||
|
||||
module.exports = { buffer, sizeCompressed, sizeUncompressed };
|
||||
`);
|
||||
@@ -7,7 +7,9 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@polkadot/wasm-crypto-asmjs/packageInfo": [ "packages/wasm-crypto-asmjs/src/packageInfo" ],
|
||||
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
|
||||
"@polkadot/wasm-crypto-wasm/packageInfo": [ "packages/wasm-crypto-wasm/src/packageInfo" ],
|
||||
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
|
||||
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user