Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d07c0a6a3 | ||
|
|
8b7c7e93af | ||
|
|
393d898dab | ||
|
|
fcf6d439ef | ||
|
|
5ccb1b4982 | ||
|
|
7ee706a99f | ||
|
|
da491efef6 | ||
|
|
2ff45e1ca6 | ||
|
|
6aac8e8771 | ||
|
|
6ebdfe9362 | ||
|
|
de9bf473f1 | ||
|
|
735584aef9 | ||
|
|
7a33da9e53 | ||
|
|
0faca1b98e | ||
|
|
ab867541d7 | ||
|
|
f50d6af2bb | ||
|
|
8c4bf9470a | ||
|
|
e5875a73c3 | ||
|
|
e32e52a94c | ||
|
|
59673150ba | ||
|
|
9f84fc3250 | ||
|
|
678063e12a | ||
|
|
02324280e3 | ||
|
|
9bc97a4e1d | ||
|
|
4cc1d4e515 | ||
|
|
8ae9bbd3b6 | ||
|
|
08c9e9e8ac | ||
|
|
b3c32738e3 | ||
|
|
72ff8a13dc | ||
|
|
1d75701361 | ||
|
|
2fd1daf39a | ||
|
|
ef6db82c52 | ||
|
|
1e2caa35ce | ||
|
|
8c0aa030cf | ||
|
|
ff9fe99ca5 | ||
|
|
e0feb7864d | ||
|
|
c8431fc3d1 | ||
|
|
849285a35d | ||
|
|
5fe38fa47b | ||
|
|
241bbe99c5 | ||
|
|
65d89a7b41 | ||
|
|
a0cbf8c531 | ||
|
|
c50fe071cb | ||
|
|
526b79435e | ||
|
|
b621b79bae | ||
|
|
37b04af274 | ||
|
|
84f0d27744 | ||
|
|
ff2315bff8 | ||
|
|
6fa0e99141 | ||
|
|
7c9bbb05a6 | ||
|
|
3ef1b2073f | ||
|
|
b56924a5b3 | ||
|
|
bf7feafaaa | ||
|
|
184edb6e4e | ||
|
|
d511310ba0 | ||
|
|
7ad87c6ce2 | ||
|
|
01a5539c28 | ||
|
|
dd107338e9 | ||
|
|
61ffef08e3 | ||
|
|
76a436f22c | ||
|
|
86a66de726 | ||
|
|
7c4d2f7af5 | ||
|
|
a20b14a8b7 | ||
|
|
e5c31a0fe7 | ||
|
|
0fc0207bcb |
@@ -1 +1,5 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
module.exports = require('./babel.config.js');
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
.eslintrc.js
|
||||
.github/**
|
||||
.vscode/**
|
||||
.yarn/**
|
||||
**/binaryen/*
|
||||
**/build/*
|
||||
**/coverage/*
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
const base = require('@polkadot/dev/config/eslint');
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -2,85 +2,15 @@ name: PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Linting
|
||||
runs-on: ubuntu-latest
|
||||
pr:
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Config yarn cache
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- uses: actions/cache@v1
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: lint
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn lint
|
||||
|
||||
test:
|
||||
name: Testing
|
||||
step: ['lint', 'test', 'build']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Config yarn cache
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- uses: actions/cache@v1
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: test
|
||||
- name: ${{ matrix.step }}
|
||||
run: |
|
||||
rustup toolchain install nightly
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn test
|
||||
|
||||
build_code:
|
||||
name: Build Code
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Config yarn cache
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- uses: actions/cache@v1
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: build
|
||||
run: |
|
||||
rustup toolchain install nightly
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn build
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
@@ -5,49 +5,29 @@ on:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_code:
|
||||
name: Build Code
|
||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
master:
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
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@v1
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Config yarn cache
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- uses: actions/cache@v1
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: build
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
rustup toolchain install nightly
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn polkadot-ci-ghact-build
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
dummy:
|
||||
name: Dummy
|
||||
if: "contains(github.event.head_commit.message, '[CI Skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- name: dummy
|
||||
run: |
|
||||
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"editor.tabSize": 2,
|
||||
"files.eol": "\n",
|
||||
"npm.packageManager": "yarn",
|
||||
"eslint.enable": true,
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"typescript",
|
||||
"typescriptreact"
|
||||
]
|
||||
}
|
||||
+86
File diff suppressed because one or more lines are too long
Vendored
-58
File diff suppressed because one or more lines are too long
+2
-1
@@ -1,4 +1,5 @@
|
||||
enableImmutableInstalls: false
|
||||
|
||||
enableProgressBars: false
|
||||
|
||||
nodeLinker: node-modules
|
||||
@@ -7,4 +8,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-berry.js
|
||||
yarnPath: .yarn/releases/yarn-2.1.1.js
|
||||
|
||||
+27
-18
@@ -1,83 +1,92 @@
|
||||
# 1.2.1 Feb 29, 2020
|
||||
# CHANGELOG
|
||||
|
||||
## 1.3.1 Aug 9, 2020
|
||||
|
||||
- Add `scrypt` function for KDF generation
|
||||
- Remove `bip39ToSeed`, we only use the `bip39ToMiniSecret` variant in Substrate
|
||||
- Update ed25519-dalek to 1.0.0-pre.4
|
||||
- Rework generation based on latest wasm-pack generator
|
||||
|
||||
## 1.2.1 Feb 29, 2020
|
||||
|
||||
- Adjust build process for smaller wasm bundle outputs (~50K dropped from base bundle)
|
||||
- Unpin nightly from nightly-2020-02-17 version
|
||||
- Swap to yarn 2 and add support for use by yarn 2 projects
|
||||
|
||||
# 1.1.1 Feb 24, 2020
|
||||
## 1.1.1 Feb 24, 2020
|
||||
|
||||
- **Important** The sr25519 interface dropped the use of `verify_simple_preaudit_deprecated` for signature verification, instead it now uses `verify_simple`. Only schnorrkel 0.8+ signatures will now pass verification. This is a follow-up of the 0.1 signing support that was dropped in a previous version.
|
||||
- Rework schnorrkel signatures test vectors based on the above change (Rust, WASM and ASM.js tests)
|
||||
- Rust nightly pinned to last-known-working 2020-02-17 on CI (compiler issues, should to be reverted in a future release)
|
||||
|
||||
# 1.0.1 Feb 15, 2020
|
||||
## 1.0.1 Feb 15, 2020
|
||||
|
||||
- No functionality changes from 0.20.1. The interfaces here are stable in the current iteration.
|
||||
|
||||
# 0.20.1 Jan 30, 2020
|
||||
## 0.20.1 Jan 30, 2020
|
||||
|
||||
- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility
|
||||
|
||||
# 0.14.1 Sep 09, 2019
|
||||
## 0.14.1 Sep 09, 2019
|
||||
|
||||
- No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability
|
||||
|
||||
# 0.13.1 Jul 20, 2019
|
||||
## 0.13.1 Jul 20, 2019
|
||||
|
||||
- Added an asm.js fallback which is active for React Native via the `"react-native"` entry in `package.json`. Ensure that you run the build step with the `NODE_OPTIONS=--max_old_space_size=8192` flags, since the asm.js bundle is large. (For RN the full command would therefore be `NODE_OPTIONS=--max_old_space_size=8192 npm start`)
|
||||
|
||||
# 0.12.1 Jul 17, 2019
|
||||
## 0.12.1 Jul 17, 2019
|
||||
|
||||
- Remove deprecated `@polkadot/wasm-schnorrkel` & `@polkadot/wasm-dalek-ed25519` source (all combined in `@polkadot/wasm-crypto`, was kept for historical purposes)
|
||||
- Security dependency bumps
|
||||
- Updated Rust `hex-literal` for recent versions of the compiler (used in tests only)
|
||||
|
||||
# 0.11.1 May 31, 2019
|
||||
## 0.11.1 May 31, 2019
|
||||
|
||||
- Security dependency bumps
|
||||
|
||||
# 0.10.1 May 09, 2019
|
||||
## 0.10.1 May 09, 2019
|
||||
|
||||
- w3f/schnorrkel updated to 0.1.1 as per substrate
|
||||
- Added known subkey signature test (Rust & JS)
|
||||
|
||||
# 0.9.1 Apr 29, 2019
|
||||
## 0.9.1 Apr 29, 2019
|
||||
|
||||
- Dependency bumps
|
||||
|
||||
# 0.8.1 Mar 31, 2019
|
||||
## 0.8.1 Mar 31, 2019
|
||||
|
||||
- Pull ed25519 & sr25519 into `@polkadot/wasm-crypto` as well (smaller final size)
|
||||
- Disable build/publish of `wasm-dalek-ed25519` & `wasm-schnorrkel`
|
||||
- Improve error messaging, instead of `__wasm_malloc of null`
|
||||
|
||||
# 0.7.1 Mar 30, 2019
|
||||
## 0.7.1 Mar 30, 2019
|
||||
|
||||
- Fix build scripts to properly attach errors in the log (dropped in 0.6.1)
|
||||
|
||||
# 0.6.1 Mar 27, 2019
|
||||
## 0.6.1 Mar 27, 2019
|
||||
|
||||
- Log init errors for both non-WebAssembly usage as well as WebAssembly errors
|
||||
|
||||
# 0.5.1 Mar 23, 2019
|
||||
## 0.5.1 Mar 23, 2019
|
||||
|
||||
- Add password argument to bip39ToSeed
|
||||
|
||||
# 0.4.1 Mar 23, 2019
|
||||
## 0.4.1 Mar 23, 2019
|
||||
|
||||
- Add bip39ToSeed
|
||||
|
||||
# 0.3.1 Mar 23, 2019
|
||||
## 0.3.1 Mar 23, 2019
|
||||
|
||||
- Add wasm-dalek-ed25519 for all used crypto there
|
||||
- Add keccak256
|
||||
- Try secp256k1 (bloating code, not used atm)
|
||||
|
||||
# 0.2.1 Mar 20, 2019
|
||||
## 0.2.1 Mar 20, 2019
|
||||
|
||||
- Add basic crypto functions, creation of wasm-crypto package
|
||||
- blake2, bip39, sha2, xxhash
|
||||
|
||||
# 0.1.1 Mar 18, 2019
|
||||
## 0.1.1 Mar 18, 2019
|
||||
|
||||
- Initial release
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
module.exports = require('@polkadot/dev/config/babel');
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
const config = require('@polkadot/dev/config/jest');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
const path = require('path');
|
||||
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "1.2.1"
|
||||
"version": "1.3.1"
|
||||
}
|
||||
|
||||
+7
-9
@@ -7,21 +7,19 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"@polkadot/dev": "^0.50.14",
|
||||
"babel-core": "^7.0.0-bridge.0",
|
||||
"typescript": "^3.8.3"
|
||||
"babel-core": "^7.0.0-bridge.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "./scripts/build.sh",
|
||||
"build": "NIGHTLY= ./scripts/build.sh",
|
||||
"build:release": "NIGHTLY= ./scripts/build-release.sh",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "./scripts/clean.sh",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "./scripts/test-rust.sh"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.8.4",
|
||||
"@polkadot/dev": "^0.50.14",
|
||||
"@polkadot/util": "^2.5.1",
|
||||
"override-require": "^1.1.1"
|
||||
}
|
||||
"@babel/core": "^7.11.1",
|
||||
"@polkadot/dev": "^0.55.35"
|
||||
},
|
||||
"version": "1.3.1"
|
||||
}
|
||||
|
||||
Generated
+323
-426
File diff suppressed because it is too large
Load Diff
@@ -18,22 +18,26 @@ crate-type = ["cdylib", "rlib"]
|
||||
backtrace = "0.3.38"
|
||||
blake2-rfc = "0.2.18"
|
||||
byteorder = "1.3.1"
|
||||
ed25519-dalek = { version = "1.0.0-pre.3", features = ["nightly"] }
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", features = ["nightly"] }
|
||||
hmac = "0.7.0"
|
||||
# libsecp256k1 = "0.2.2"
|
||||
pbkdf2 = { version = "0.3.0", default-features = false }
|
||||
schnorrkel = { version = "0.8.5", features = ["nightly", "preaudit_deprecated", "u64_backend"] }
|
||||
sha2 = "0.8.0"
|
||||
tiny-bip39 = { version = "0.6.2", default-features = false }
|
||||
schnorrkel = { version = "0.9.1", features = ["nightly", "preaudit_deprecated", "u64_backend"] }
|
||||
scrypt = { version = "0.2", default-features = false }
|
||||
sha2 = "0.8.1"
|
||||
tiny-bip39 = { version = "0.7", default-features = false }
|
||||
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
|
||||
twox-hash = "1.5.0"
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen = "=0.2.65"
|
||||
wee_alloc = "0.4.3"
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.2.0"
|
||||
rand = { version = "0.6.5", features = ["wasm-bindgen"] }
|
||||
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/wasm-crypto",
|
||||
"version": "1.2.1",
|
||||
"version": "1.3.1",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"files": [
|
||||
"crypto-polyfill.js",
|
||||
@@ -20,7 +20,9 @@
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.50.8"
|
||||
"@polkadot/dev": "^0.55.35",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
use bip39::{Mnemonic, MnemonicType, Language, Seed};
|
||||
use bip39::{Mnemonic, MnemonicType, Language};
|
||||
use hmac::Hmac;
|
||||
use pbkdf2::pbkdf2;
|
||||
use sha2::Sha512;
|
||||
@@ -48,20 +48,6 @@ pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec<u8> {
|
||||
result[..32].to_vec()
|
||||
}
|
||||
|
||||
/// Creates a see from a bip-39 phrase
|
||||
///
|
||||
/// @phrase: mnemonic phrase
|
||||
///
|
||||
/// Returns a 32-byte seed
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_bip39_to_seed(phrase: &str, password: &str) -> Vec<u8> {
|
||||
let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();
|
||||
|
||||
Seed::new(&mnemonic, password)
|
||||
.as_bytes()[..32]
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// Validates a bip39 phrase
|
||||
///
|
||||
/// * phrase: mnemonic phrase
|
||||
@@ -99,15 +85,6 @@ pub mod tests {
|
||||
assert_eq!(result[..], mini[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_bip39_seed() {
|
||||
let phrase = "seed sock milk update focus rotate barely fade car face mechanic mercy";
|
||||
let seed = hex!("3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027");
|
||||
let result = ext_bip39_to_seed(phrase, "");
|
||||
|
||||
assert_eq!(result[..], seed[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_bip39_generate() {
|
||||
let phrase = ext_bip39_generate(12);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature};
|
||||
use std::convert::TryFrom;
|
||||
use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verifier as _};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Keypair helper function.
|
||||
@@ -14,27 +15,27 @@ fn create_from_pair(pair: &[u8]) -> Keypair {
|
||||
}
|
||||
|
||||
/// Keypair helper function
|
||||
fn create_from_parts(public: &[u8], secret: &[u8]) -> Keypair {
|
||||
fn create_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
|
||||
let mut pair = vec![];
|
||||
|
||||
pair.extend_from_slice(secret);
|
||||
pair.extend_from_slice(public);
|
||||
pair.extend_from_slice(seckey);
|
||||
pair.extend_from_slice(pubkey);
|
||||
|
||||
create_from_pair(&pair)
|
||||
}
|
||||
|
||||
/// Keypair helper function.
|
||||
fn create_from_seed(seed: &[u8]) -> Keypair {
|
||||
let secret = SecretKey::from_bytes(seed).unwrap();
|
||||
let public: PublicKey = (&secret).into();
|
||||
let seckey = SecretKey::from_bytes(seed).unwrap();
|
||||
let pubkey: PublicKey = (&seckey).into();
|
||||
|
||||
create_from_parts(public.as_bytes(), seed)
|
||||
create_from_parts(pubkey.as_bytes(), seed)
|
||||
}
|
||||
|
||||
/// PublicKey helper
|
||||
fn create_public(public: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(public) {
|
||||
Ok(public) => return public,
|
||||
fn create_public(pubkey: &[u8]) -> PublicKey {
|
||||
match PublicKey::from_bytes(pubkey) {
|
||||
Ok(pubkey) => return pubkey,
|
||||
Err(_) => panic!("Provided public key is invalid.")
|
||||
}
|
||||
}
|
||||
@@ -57,14 +58,14 @@ pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
|
||||
/// The combination of both public and private key must be provided.
|
||||
/// This is effectively equivalent to a keypair.
|
||||
///
|
||||
/// * public: UIntArray with 32 element
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
/// * private: UIntArray with 64 element
|
||||
/// * message: Arbitrary length UIntArray
|
||||
///
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_from_parts(public, secret)
|
||||
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
create_from_parts(pubkey, seckey)
|
||||
.sign(message)
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
@@ -76,13 +77,13 @@ pub fn ext_ed_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * message: Arbitrary length UIntArray
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_ed_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
||||
let signature = match Signature::from_bytes(signature) {
|
||||
pub fn ext_ed_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||
let signature = match Signature::try_from(signature) {
|
||||
Ok(signature) => signature,
|
||||
Err(_) => return false
|
||||
};
|
||||
|
||||
create_public(public)
|
||||
create_public(pubkey)
|
||||
.verify(message, &signature)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use blake2_rfc::blake2b::blake2b;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use hmac::Hmac;
|
||||
use pbkdf2::pbkdf2;
|
||||
use scrypt::{ScryptParams, scrypt};
|
||||
use sha2::{Digest, Sha512};
|
||||
// use secp256k1;
|
||||
use tiny_keccak::{Hasher, Keccak};
|
||||
@@ -58,13 +59,13 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
|
||||
result.to_vec()
|
||||
}
|
||||
|
||||
/// pbkdf2 hash from an input, salt for the number of specified rounds
|
||||
/// pbkdf2 kdf from an input, salt for the number of specified rounds
|
||||
///
|
||||
/// * data: Arbitrary data to be hashed
|
||||
/// * salt: Salt for this hash
|
||||
/// * rounds: The number of rounds to perform
|
||||
///
|
||||
/// Returns a vecor with the hash result
|
||||
/// Returns a vector with the hashed result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
let mut result = [0u8; 64];
|
||||
@@ -75,6 +76,26 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
|
||||
result.to_vec()
|
||||
}
|
||||
|
||||
/// scrypt kdf from input, salt and config
|
||||
///
|
||||
/// * password: Password to hash
|
||||
/// * salt: Salt for this hash
|
||||
/// * log2_n: log2(n)
|
||||
/// * r: r
|
||||
/// * p: p
|
||||
///
|
||||
/// Returns vector with the hashed result
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> Vec<u8> {
|
||||
let params = ScryptParams::new(log2_n, r, p).unwrap();
|
||||
let mut result = [0u8; 64];
|
||||
|
||||
match scrypt(password, salt, ¶ms, &mut result) {
|
||||
Ok(_) => return result.to_vec(),
|
||||
Err(_) => panic!("Invalid scrypt hash.")
|
||||
}
|
||||
}
|
||||
|
||||
// /// Checks for the recoverability of a signature from message
|
||||
// ///
|
||||
// /// * message: The message
|
||||
@@ -215,6 +236,16 @@ pub mod tests {
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_scrypt() {
|
||||
let password = b"password";
|
||||
let salt = b"salt";
|
||||
let expected = hex!("745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6");
|
||||
let hash = ext_scrypt(password, salt, 14, 8, 1);
|
||||
|
||||
assert_eq!(hash[..], expected[..]);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn can_secp256k1_real_eth_sig() {
|
||||
// let sig = hex!("7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff1c");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
const { assert } = require('@polkadot/util');
|
||||
|
||||
const INIT_ERRROR = '@polkadot/wasm-crypto has not been initialized';
|
||||
@@ -36,6 +37,7 @@ module.exports = function (stubbed) {
|
||||
blake2b: wrapReady(stubbed.ext_blake2b),
|
||||
keccak256: wrapReady(stubbed.ext_keccak256),
|
||||
pbkdf2: wrapReady(stubbed.ext_pbkdf2),
|
||||
scrypt: wrapReady(stubbed.ext_scrypt),
|
||||
|
||||
// secp256k1IsRecoverable: wrapReady(stubbed.ext_secp256k1_is_recoverable);
|
||||
// secp256k1Recover: wrapReady(stubbed.ext_secp256k1_recover);
|
||||
|
||||
+1
-1
@@ -5,7 +5,6 @@
|
||||
export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string;
|
||||
export function bip39ToEntropy (phrase: string): Uint8Array;
|
||||
export function bip39ToMiniSecret (phrase: string, password: string): Uint8Array;
|
||||
export function bip39ToSeed (phrase: string, password: string): Uint8Array;
|
||||
export function bip39Validate (phrase: string): boolean;
|
||||
|
||||
export function ed25519KeypairFromSeed (seed: Uint8Array): Uint8Array;
|
||||
@@ -22,6 +21,7 @@ export function sr25519Verify (signature: Uint8Array, message: Uint8Array, publi
|
||||
export function blake2b (data: Uint8Array, key: Uint8Array, byteSize: number): Uint8Array;
|
||||
export function keccak256 (data: Uint8Array): Uint8Array;
|
||||
export function pbkdf2 (data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array;
|
||||
export function scrypt (password: Uint8Array, salt: Uint8Array, log2N: number, r: number, p: number): Uint8Array;
|
||||
// export function secp256k1IsRecoverable (message: Uint8Array, signature: Uint8Array): number;
|
||||
// export function secp256k1Recover (message: Uint8Array, signature: Uint8Array): Uint8Array;
|
||||
export function sha512 (data: Uint8Array): Uint8Array;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@@ -10,7 +9,7 @@ const imports = require('./wasm');
|
||||
|
||||
module.exports = async function createExportPromise () {
|
||||
try {
|
||||
const { instance } = await WebAssembly.instantiate(bytes, { './wasm': imports });
|
||||
const { instance } = await WebAssembly.instantiate(bytes, { __wbindgen_placeholder__: imports });
|
||||
|
||||
return instance.exports;
|
||||
} catch (error) {
|
||||
|
||||
@@ -64,8 +64,8 @@ pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
///
|
||||
/// returned vector is the derived publicKey as a array of 32 bytes
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
PublicKey::from_bytes(public)
|
||||
pub fn ext_sr_derive_public_soft(pubkey: &[u8], cc: &[u8]) -> Vec<u8> {
|
||||
PublicKey::from_bytes(pubkey)
|
||||
.unwrap()
|
||||
.derived_key_simple(create_cc(cc), &[]).0
|
||||
.to_bytes()
|
||||
@@ -105,16 +105,16 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec<u8> {
|
||||
/// The combination of both public and private key must be provided.
|
||||
/// This is effectively equivalent to a keypair.
|
||||
///
|
||||
/// * public: UIntArray with 32 element
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
/// * private: UIntArray with 64 element
|
||||
/// * message: Arbitrary length UIntArray
|
||||
///
|
||||
/// * returned vector is the signature consisting of 64 bytes.
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
pub fn ext_sr_sign(pubkey: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
SecretKey::from_ed25519_bytes(secret)
|
||||
.unwrap()
|
||||
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(public).unwrap())
|
||||
.sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(pubkey).unwrap())
|
||||
.to_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
@@ -125,9 +125,9 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
/// * message: Arbitrary length UIntArray
|
||||
/// * pubkey: UIntArray with 32 element
|
||||
#[wasm_bindgen]
|
||||
pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool {
|
||||
pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
|
||||
match Signature::from_bytes(signature) {
|
||||
Ok(signature) => PublicKey::from_bytes(public).unwrap()
|
||||
Ok(signature) => PublicKey::from_bytes(pubkey).unwrap()
|
||||
.verify_simple(SIGNING_CTX, message, &signature)
|
||||
.is_ok(),
|
||||
Err(_) => false
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const { assert, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
function bip39_generate (wasm) {
|
||||
@@ -39,18 +39,9 @@ function bip39_toMiniSecret (wasm) {
|
||||
assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
|
||||
function bip39_toSeed (wasm) {
|
||||
const RESULT = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
|
||||
|
||||
console.log('\tSEE', RESULT);
|
||||
|
||||
assert(RESULT === '0x3c121e20de068083b49c2315697fb59a2d9e8643c24e5ea7628132c58969a027', 'ERROR: Invalid bip39 mini secret');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
bip39_generate,
|
||||
bip39_validate,
|
||||
bip39_toEntropy,
|
||||
bip39_toMiniSecret,
|
||||
bip39_toSeed
|
||||
bip39_validate
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
@@ -55,8 +54,8 @@ function ed25519_benchmark (wasm) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ed25519_benchmark,
|
||||
ed25519_pairFromSeed,
|
||||
ed25519_signAndVerify,
|
||||
ed25519_verifyExisting,
|
||||
ed25519_benchmark
|
||||
ed25519_verifyExisting
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
|
||||
@@ -42,6 +41,14 @@ function pbkdf2Hash (wasm) {
|
||||
// assert(pk === '0x91d366769d44a7c7690428bfdf67ec7eae23d2459694685257b6fc59d1baa1fe', 'ERROR: secp256k1Recover does not match');
|
||||
// }
|
||||
|
||||
function scryptHash (wasm) {
|
||||
const hash = u8aToHex(wasm.scrypt(stringToU8a('password'), stringToU8a('salt'), 14, 8, 1));
|
||||
|
||||
console.log('\tRES', hash);
|
||||
|
||||
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
|
||||
}
|
||||
|
||||
function sha512Hash (wasm) {
|
||||
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
|
||||
|
||||
@@ -64,6 +71,7 @@ module.exports = {
|
||||
blake2bHash,
|
||||
keccak256,
|
||||
pbkdf2Hash,
|
||||
scryptHash,
|
||||
// secp256k1Recover,
|
||||
sha512Hash,
|
||||
twoxHash
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// @ts-check
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
|
||||
@@ -112,14 +111,14 @@ function sr25519_benchmark (wasm) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sr25519_pairFromSeed,
|
||||
sr25519_devFromSeed,
|
||||
sr25519_benchmark,
|
||||
sr25519_deriveHard,
|
||||
sr25519_deriveHardKnown,
|
||||
sr25519_deriveSoft,
|
||||
sr25519_deriveSoftKnown,
|
||||
sr25519_deriveSoftPubkey,
|
||||
sr25519_devFromSeed,
|
||||
sr25519_pairFromSeed,
|
||||
sr25519_signAndVerify,
|
||||
sr25519_verifyExisting,
|
||||
sr25519_benchmark
|
||||
sr25519_verifyExisting
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @ts-check
|
||||
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
|
||||
+33
-14
@@ -20,7 +20,7 @@ rm -rf ./build ./pkg
|
||||
|
||||
# build new via nightly & wasm-pack
|
||||
echo "*** Building WASM output"
|
||||
rustup run nightly wasm-pack build --release --scope polkadot --target nodejs
|
||||
rustup run nightly$NIGHTLY wasm-pack build --release --scope polkadot --target nodejs
|
||||
mv pkg build
|
||||
|
||||
# optimise
|
||||
@@ -35,36 +35,55 @@ node ../../scripts/pack-wasm-base64.js
|
||||
echo "*** Building asm.js version"
|
||||
../../binaryen/bin/wasm2js --output $ASM $OPT
|
||||
|
||||
# cleanup the generated output, sadly there are no node-js outputs above
|
||||
sed -i -e 's/import {/\/\/ import {/g' $ASM
|
||||
sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $ASM
|
||||
sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $ASM
|
||||
# cleanup the generated asm, converting to cjs
|
||||
sed -i -e '/import {/d' $ASM
|
||||
echo "const imported = require('./wasm');
|
||||
$(cat $ASM)" > $ASM
|
||||
sed -i -e 's/{abort.*},memasmFunc/imported, memasmFunc/g' $ASM
|
||||
sed -i -e 's/export var /module\.exports\./g' $ASM
|
||||
|
||||
# copy our package interfaces
|
||||
echo "*** Copying package sources"
|
||||
cp src/js/* build/
|
||||
|
||||
echo "const crypto = require('crypto');
|
||||
const { stringToU8a, u8aToString } = require('@polkadot/util');
|
||||
|
||||
const requires = { crypto };
|
||||
|
||||
$(cat $SRC_WASM)
|
||||
" > $SRC_WASM
|
||||
|
||||
# whack comments
|
||||
sed -i -e '/^\/\*\*/d' $SRC_WASM
|
||||
sed -i -e '/^\*/d' $SRC_WASM
|
||||
sed -i -e '/^\*\//d' $SRC_WASM
|
||||
|
||||
# we are swapping to a async interface for webpack support (wasm limits)
|
||||
sed -i -e 's/wasm = require/\/\/ wasm = require/g' $SRC_WASM
|
||||
sed -i -e '/^wasm = require/d' $SRC_WASM
|
||||
|
||||
# We don't want inline requires
|
||||
sed -i -e 's/var wasm;/const crypto = require('\''crypto'\''); let wasm; const requires = { crypto };/g' $SRC_WASM
|
||||
sed -i -e 's/return addHeapObject(require(varg0));/return addHeapObject(requires[varg0]);/g' $SRC_WASM
|
||||
sed -i -e 's/ret = require(getStringFromWasm0(arg0, arg1));/ret = requires[getStringFromWasm0(arg0, arg1)];/g' $SRC_WASM
|
||||
|
||||
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
|
||||
sed -i -e 's/const TextEncoder = require('\''util'\'')\.TextEncoder;/const { stringToU8a } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
|
||||
sed -i -e 's/let cachedTextEncoder = new /\/\/ let cachedTextEncoder = new /g' $SRC_WASM
|
||||
sed -i -e '/^const { TextEncoder } = require/d' $SRC_WASM
|
||||
sed -i -e '/^let cachedTextEncoder = new /d' $SRC_WASM
|
||||
sed -i -e 's/cachedTextEncoder\.encode/stringToU8a/g' $SRC_WASM
|
||||
|
||||
# this creates issues in both the browser and RN (@polkadot/util has a polyfill)
|
||||
sed -i -e 's/const TextDecoder = require('\''util'\'')\.TextDecoder;/const { u8aToString } = require('\''@polkadot\/util'\'');/g' $SRC_WASM
|
||||
sed -i -e 's/let cachedTextDecoder = new /\/\/ let cachedTextDecoder = new /g' $SRC_WASM
|
||||
sed -i -e '/^const { TextDecoder } = require/d' $SRC_WASM
|
||||
sed -i -e '/^let cachedTextDecoder = new/d' $SRC_WASM
|
||||
sed -i -e 's/cachedTextDecoder\.decode/u8aToString/g' $SRC_WASM
|
||||
|
||||
# this is where we get the actual bg file
|
||||
sed -i -e '/^const path = require/d' $SRC_WASM
|
||||
sed -i -e '/^const bytes = require/d' $SRC_WASM
|
||||
sed -i -e '/^const wasmModule =/d' $SRC_WASM
|
||||
sed -i -e '/^const wasmInstance =/d' $SRC_WASM
|
||||
sed -i -e '/^wasm = wasmInstance/d' $SRC_WASM
|
||||
|
||||
# construct our promise and add ready helpers (WASM)
|
||||
echo "
|
||||
module.exports.abort = function () { throw new Error('abort'); };
|
||||
echo "module.exports.abort = function () { throw new Error('abort'); };
|
||||
|
||||
const createPromise = require('./wasm_promise');
|
||||
const wasmPromise = createPromise().catch(() => null);
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2020 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
rustup toolchain install nightly$NIGHTLY
|
||||
yarn polkadot-ci-ghact-build
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
rustup toolchain install nightly$NIGHTLY
|
||||
./scripts/install-build-deps.sh
|
||||
|
||||
echo "*** Building packages"
|
||||
|
||||
@@ -13,5 +13,3 @@ node ./test/asm.js
|
||||
|
||||
echo "*** Testing via Jest"
|
||||
yarn polkadot-dev-run-test ./test/jest.spec.js
|
||||
# FIXME, this should be via yarn
|
||||
# ../../node_modules/@polkadot/dev/scripts/polkadot-dev-run-test.js ./test/jest.spec.js
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
set -e
|
||||
|
||||
rustup toolchain install nightly$NIGHTLY
|
||||
|
||||
cd packages
|
||||
|
||||
PACKAGES=( $(ls -1d *) )
|
||||
@@ -14,7 +16,7 @@ for PKG in "${PACKAGES[@]}"; do
|
||||
cd $PKG
|
||||
echo "*** Testing Rust $PKG"
|
||||
|
||||
RUST_BACKTRACE=full rustup run nightly cargo test --release -- --nocapture
|
||||
RUST_BACKTRACE=full rustup run nightly$NIGHTLY cargo test --release -- --nocapture
|
||||
|
||||
cd ..
|
||||
fi
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "./node_modules/@polkadot/dev/config/tsconfig",
|
||||
"extends": "@polkadot/dev/config/tsconfig",
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"**/build/**/*"
|
||||
|
||||
+8
-4
@@ -1,16 +1,20 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
module.exports = {
|
||||
name: 'Polkadot JS WASM',
|
||||
exclude: '**/*+(index|e2e|spec).ts',
|
||||
excludeExternals: true,
|
||||
excludeNotExported: true,
|
||||
excludeProtected: true,
|
||||
excludePrivate: true,
|
||||
excludeProtected: true,
|
||||
hideGenerator: true,
|
||||
includeDeclarations: false,
|
||||
out: 'docs',
|
||||
mdEngine: 'gitbook',
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node',
|
||||
mdEngine: 'gitbook',
|
||||
name: 'Polkadot JS WASM',
|
||||
out: 'docs',
|
||||
stripInternal: 'true',
|
||||
theme: 'markdown'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user