Compare commits

...
62 Commits
Author SHA1 Message Date
Github Actions 801ed235cf [CI Skip] release/stable 4.4.1
skip-checks: true
2021-11-22 05:03:50 +00:00
Jaco 98433c7399 4.4.1 (#234) 2021-11-22 06:58:30 +02:00
Github Actions b537dcf3f4 [CI Skip] release/beta 4.3.2-0
skip-checks: true
2021-11-21 05:54:49 +00:00
Jaco eaf8ecf2c1 Add hmacSha{256, 512} functions (#233)
* Add hmacSha{256, 512} functions

* type

* Adjust

* Apply suggestions from code review

* Update packages/wasm-crypto/src/rs/hashing.rs

* Update packages/wasm-crypto/src/rs/hashing.rs

* Update packages/wasm-crypto/src/rs/hashing.rs

* Fix Rust side

* naming for wasm interfaces

* Remove type

* Bump common
2021-11-21 07:49:53 +02:00
Github Actions 9f232459d9 [CI Skip] release/stable 4.3.1
skip-checks: true
2021-11-19 13:14:30 +00:00
Jaco b92661cfe0 4.3.1 (#232) 2021-11-19 15:08:46 +02:00
Github Actions 6ca4470752 [CI Skip] release/beta 4.2.2-17
skip-checks: true
2021-11-19 12:34:40 +00:00
Jaco 6cecb67edd keccak512 & sha256 (#231)
* keccak512 & sha256

* Update interface

* Correct test
2021-11-19 14:28:44 +02:00
Github Actions 91388ca10d [CI Skip] release/beta 4.2.2-16
skip-checks: true
2021-11-18 08:28:57 +00:00
Jaco 11e2acbdb5 Bump deps (#230) 2021-11-18 10:24:03 +02:00
Github Actions 4e3d1b631c [CI Skip] release/beta 4.2.2-15
skip-checks: true
2021-11-12 07:39:59 +00:00
Jaco 4f06de4844 Bump deps (#229) 2021-11-12 09:34:30 +02:00
Github Actions affb3c57e3 [CI Skip] release/beta 4.2.2-14
skip-checks: true
2021-11-07 10:44:51 +00:00
Jaco 39e762a419 Bump @polkadot deps (#227) 2021-11-07 12:38:53 +02:00
Github Actions fe966c8576 [CI Skip] release/beta 4.2.2-13
skip-checks: true
2021-11-06 11:42:08 +00:00
Jaco 12c90dfb53 Bump deps (#226) 2021-11-06 13:37:22 +02:00
Github Actions 03aabfd6d1 [CI Skip] release/beta 4.2.2-12
skip-checks: true
2021-11-03 12:50:00 +00:00
Jaco 49b3cf552b Bump dev (#225) 2021-11-03 14:45:06 +02:00
Github Actions 6300012c32 [CI Skip] release/beta 4.2.2-11
skip-checks: true
2021-10-26 07:25:50 +00:00
Jaco 9d0773c185 Bump dev (#224) 2021-10-26 10:20:33 +03:00
Github Actions 96bd2f466e [CI Skip] release/beta 4.2.2-10
skip-checks: true
2021-10-25 13:28:49 +00:00
Jaco c6151e1a7d Bump dev deps (#223) 2021-10-25 16:22:19 +03:00
Github Actions c0c6671bd0 [CI Skip] release/beta 4.2.2-9
skip-checks: true
2021-10-25 11:38:15 +00:00
Jaco 2b9d90ff49 Bump dev (#222) 2021-10-25 14:32:37 +03:00
Github Actions 2caa6fb41a [CI Skip] release/beta 4.2.2-8
skip-checks: true
2021-10-25 09:13:13 +00:00
Jaco df00473ae2 Adjust package.json consistency (#221)
* Adjust package.json consistency

* Bump deps
2021-10-25 12:08:38 +03:00
Github Actions 2acce9283f [CI Skip] release/beta 4.2.2-7
skip-checks: true
2021-10-25 08:52:12 +00:00
Zhongpeng Zhouandmsftenanceprovenance 7971624cf9 Update package.json to include the repository (#220)
* Update package.json to include the repository

Hi there!
This change adds the repository property to your package.json file(s). Having this available provides a number of benefits to security tooling. For example, it allows for greater trust by checking for signed commits, contributors to a release and validating history with the project. It also allows for comparison between the source code and the published artifact in order to detect attacks on authors during the publication process.
We validate that we're making a PR against the correct repository by comparing the metadata for the published artifact on [npmjs.com](www.npmjs.com) against the metadata in the package.json file in the repository.
This change is provided by a team at Microsoft -- we're happy to answer any questions you may have. (Members of this team include [@s-tuli](https://github.com/s-tuli), [@iarna](https://github.com/iarna), [@v-rr](https://github.com/v-rr), [@v-jiepeng](https://github.com/v-jiepeng), [@v-zhzhou](https://github.com/v-zhzhou) and [@v-gjy](https://github.com/v-gjy)). If you would prefer that we not make these sorts of PRs to projects you maintain, please just say. If you'd like to learn more about what we're doing here, we've prepared a document talking about both this project and some of our other activities around supply chain security here: [microsoft/Secure-Supply-Chain](https://github.com/microsoft/Secure-Supply-Chain)
This PR provides repository metadata for the following packages:
* @polkadot/wasm-crypto
* @polkadot/wasm-crypto-asmjs
* @polkadot/wasm-crypto-wasm

* update

* update

Co-authored-by: msftenanceprovenance <msftenanceprovenance@microsoft.com>
2021-10-25 11:45:36 +03:00
Github Actions e353fe7f2c [CI Skip] release/beta 4.2.2-6
skip-checks: true
2021-10-17 09:37:46 +00:00
Jaco e797e7a7e4 Bump dev (#219)
* Bump dev

* Bump
2021-10-17 12:32:50 +03:00
Github Actions cb91f766c7 [CI Skip] release/beta 4.2.2-5
skip-checks: true
2021-10-16 06:46:50 +00:00
Jaco c983de54f6 Bump deps (#218) 2021-10-16 09:40:31 +03:00
Github Actions 9d9b983694 [CI Skip] release/beta 4.2.2-4
skip-checks: true
2021-09-27 05:45:44 +00:00
Jaco 6db930d03d Bump deps (#217) 2021-09-27 07:39:52 +02:00
Github Actions 0233a868ab [CI Skip] release/beta 4.2.2-3
skip-checks: true
2021-09-20 08:39:48 +00:00
Jaco ed98d4820e Bump util (#216) 2021-09-20 10:33:18 +02:00
Github Actions 971d40ba18 [CI Skip] release/beta 4.2.2-2
skip-checks: true
2021-09-14 11:29:28 +00:00
Jaco f3e1e30838 Bump deps (#215) 2021-09-14 13:24:17 +02:00
Github Actions bff8604c8a [CI Skip] release/beta 4.2.2-1
skip-checks: true
2021-09-05 08:28:45 +00:00
Jaco 6cf4fc0989 Bump deps (#214) 2021-09-05 10:22:39 +02:00
Github Actions 308374c7da [CI Skip] release/beta 4.2.2-0
skip-checks: true
2021-09-01 16:49:58 +00:00
Jaco 06bb7ae090 Jest config cleanup (#213)
* Jest config cleanup

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

* detect stable

* Apply suggestions from code review

* CHANGELOG

* De-dupe Rust version

* Adjust script location

* Script cleanups

* trigger

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

* Align version of curve25519-dalek

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

* Reduce code size

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

* Add explicit tests on sr25519 key agreement

* Fix linting issues

* Fix sr25519 key_agreement test

Co-authored-by: Jaco <jacogr@gmail.com>
2021-08-24 13:00:54 +02:00
Github Actions 3575f57a2a [CI Skip] release/beta 4.1.3-3
skip-checks: true
2021-08-24 07:05:13 +00:00
Jaco 8838651405 Bump deps (#210) 2021-08-24 08:59:29 +02:00
Github Actions 6cb8f2254a [CI Skip] release/beta 4.1.3-2
skip-checks: true
2021-08-16 06:04:41 +00:00
Jaco 72c2a70a32 Bump deps (#208) 2021-08-16 07:58:49 +02:00
Github Actions 51b1d12aab [CI Skip] release/beta 4.1.3-1
skip-checks: true
2021-08-13 11:52:29 +00:00
Jaco Greeff 93159192bb berry 3.0.1 2021-08-13 14:46:26 +03:00
Github Actions d208694d05 [CI Skip] release/beta 4.1.3-0
skip-checks: true
2021-08-13 11:40:39 +00:00
Jaco e7cb8a4907 Bump deps (#207) 2021-08-13 13:35:19 +02:00
Github Actions 01dfe6e35c [CI Skip] release/stable 4.1.2
skip-checks: true
2021-07-09 05:54:46 +00:00
Jaco a5d4c4b43c 4.1.2 (#206) 2021-07-09 07:49:27 +02:00
31 changed files with 2884 additions and 3345 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
5
6
3.2.2
3.2.3
3.2.4
4.0.2
4.1.2
File diff suppressed because one or more lines are too long
+631
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -10,4 +10,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
yarnPath: .yarn/releases/yarn-3.0.0-rc.2.cjs
yarnPath: .yarn/releases/yarn-3.0.1.cjs
+39 -1
View File
@@ -1,11 +1,49 @@
# CHANGELOG
## 4.4.1 Nov 22, 2021
Changes:
- Add `hmacSha256` & `hmacSha512` functions
## 4.3.1 Nov 19, 2021
Contributed:
- Updated package.json to include repo (Thanks to https://github.com/v-zhzhou)
Changes:
- Add `keccak512` function
- Add `sha256` function
## 4.2.1 Aug 28, 2021
Contributed:
- Add sr25519 agreement external (Thanks to https://github.com/shelvenzhou)
Changes:
- Adjust tests to align with JS coding standards
- Allow for optional build with Rust stable bootstrap
## 4.1.2 Jul 9, 2021
Changes:
- Bump `@polkadot/dev` to allow for bundles with new-format
## 4.1.1 Jul 7, 2021
Changes:
- Add an explicit `engines` field to `package.json`
- Allow building as a completely stand-alone browser bundle
- Allow building as a completely stand-alone browser bundle (experimental)
## 4.0.2 Mar 5, 2021
+1 -7
View File
@@ -9,11 +9,5 @@ module.exports = Object.assign({}, config, {
'@polkadot/wasm-crypto-wasm(.*)$': '<rootDir>/packages/wasm-crypto-wasm/build/$1',
// eslint-disable-next-line sort-keys
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/src/$1'
},
modulePathIgnorePatterns: [
'<rootDir>/packages/wasm-crypto-asmjs/build',
'<rootDir>/packages/wasm-crypto-wasm/build',
'<rootDir>/packages/wasm-crypto/build'
],
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
}
});
+15 -8
View File
@@ -1,21 +1,26 @@
{
"repository": "https://github.com/polkadot-js/wasm",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm#readme",
"license": "Apache-2",
"packageManager": "yarn@3.0.1",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"version": "4.4.1",
"workspaces": [
"packages/*"
],
"resolutions": {
"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",
"lint": "polkadot-dev-run-lint",
"postinstall": "polkadot-dev-yarn-only",
"test": "yarn test:wasm:rust",
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
@@ -24,10 +29,12 @@
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@polkadot/dev": "^0.62.52",
"@babel/core": "^7.16.0",
"@polkadot/dev": "^0.63.29",
"fflate": "^0.7.1",
"override-require": "^1.1.1"
},
"version": "4.1.1"
"resolutions": {
"typescript": "^4.5.2"
}
}
+18 -13
View File
@@ -1,22 +1,27 @@
{
"name": "@polkadot/wasm-crypto-asmjs",
"version": "4.1.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "Asm.js content for wasm-crypto",
"browser": "empty.js",
"main": "empty.js",
"react-native": "data.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-asmjs#readme",
"license": "Apache-2.0",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"maintainers": [],
"name": "@polkadot/wasm-crypto-asmjs",
"repository": {
"directory": "packages/wasm-crypto-asmjs",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"type": "module",
"version": "4.4.1",
"browser": "empty.js",
"main": "empty.js",
"react-native": "data.js",
"dependencies": {
"@babel/runtime": "^7.14.6"
"@babel/runtime": "^7.16.3"
}
}
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.4.1' };
+18 -13
View File
@@ -1,22 +1,27 @@
{
"name": "@polkadot/wasm-crypto-wasm",
"version": "4.1.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "Wasm content for wasm-crypto",
"browser": "data.js",
"main": "data.js",
"react-native": "data.js",
"sideEffects": false,
"engines": {
"node": ">=14.0.0"
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto-wasm#readme",
"license": "Apache-2.0",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"homepage": "https://github.com/polkadot-js/wasm",
"maintainers": [],
"name": "@polkadot/wasm-crypto-wasm",
"repository": {
"directory": "packages/wasm-crypto-wasm",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"type": "module",
"version": "4.4.1",
"browser": "data.js",
"main": "data.js",
"react-native": "data.js",
"dependencies": {
"@babel/runtime": "^7.14.6"
"@babel/runtime": "^7.16.3"
}
}
+2 -2
View File
@@ -46,8 +46,8 @@ export function toByteArray (b64: string): Uint8Array {
const [validLen, placeHoldersLen] = getLens(b64);
const arr = new Uint8Array(((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen);
let curByte = 0;
let i;
let tmp;
let i: number;
let tmp: number;
// if there are placeholders, only get up to the last complete 4 chars
const len = placeHoldersLen > 0
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.4.1' };
+3
View File
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.13.0"
@@ -659,6 +661,7 @@ version = "0.0.0"
dependencies = [
"blake2-rfc",
"byteorder",
"curve25519-dalek",
"ed25519-dalek",
"hex-literal",
"hmac",
+1
View File
@@ -22,6 +22,7 @@ hmac = "0.7.0"
# libsecp256k1 = "0.2.2"
merlin = { version = "2.0", default-features = false }
pbkdf2 = { version = "0.3.0", default-features = false }
curve25519-dalek = { version = "2.1.0", default-features = false }
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
scrypt = { version = "0.2", default-features = false }
sha2 = "0.8.1"
+23 -12
View File
@@ -1,24 +1,35 @@
{
"name": "@polkadot/wasm-crypto",
"version": "4.1.1",
"type": "module",
"author": "Jaco Greeff <jacogr@gmail.com>",
"main": "index.js",
"bugs": "https://github.com/polkadot-js/wasm/issues",
"contributors": [],
"description": "A wasm interface layer for use by @polkadot/util-crypto",
"engines": {
"node": ">=14.0.0"
},
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-crypto#readme",
"license": "Apache-2.0",
"maintainers": [],
"name": "@polkadot/wasm-crypto",
"repository": {
"directory": "packages/wasm-crypto",
"type": "git",
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": [
"./detectPackage.js",
"./detectPackage.cjs"
],
"engines": {
"node": ">=14.0.0"
},
"type": "module",
"version": "4.4.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/wasm-crypto-asmjs": "^4.1.1",
"@polkadot/wasm-crypto-wasm": "^4.1.1"
"@babel/runtime": "^7.16.3",
"@polkadot/wasm-crypto-asmjs": "^4.4.1",
"@polkadot/wasm-crypto-wasm": "^4.4.1"
},
"devDependencies": {
"@polkadot/util": "^6.11.1",
"@polkadot/x-randomvalues": "^6.11.1"
"@polkadot/util": "^7.9.1",
"@polkadot/x-randomvalues": "^7.9.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+73 -18
View File
@@ -9,11 +9,13 @@ import * as imports from './imports';
export { packageInfo } from './packageInfo';
const PTR_VEC = 8;
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
export const bip39Generate = withWasm((wasm) =>
(words: 12 | 15 | 18 | 21 | 24): string => {
wasm.ext_bip39_generate(8, words);
wasm.ext_bip39_generate(PTR_VEC, words);
return resultString();
}
@@ -23,7 +25,7 @@ export const bip39ToEntropy = withWasm((wasm) =>
(phrase: string): Uint8Array => {
const [ptr0, len0] = allocString(phrase);
wasm.ext_bip39_to_entropy(8, ptr0, len0);
wasm.ext_bip39_to_entropy(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -34,7 +36,7 @@ export const bip39ToMiniSecret = withWasm((wasm) =>
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_mini_secret(8, ptr0, len0, ptr1, len1);
wasm.ext_bip39_to_mini_secret(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -45,7 +47,7 @@ export const bip39ToSeed = withWasm((wasm) =>
const [ptr0, len0] = allocString(phrase);
const [ptr1, len1] = allocString(password);
wasm.ext_bip39_to_seed(8, ptr0, len0, ptr1, len1);
wasm.ext_bip39_to_seed(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -64,7 +66,7 @@ export const ed25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_ed_from_seed(8, ptr0, len0);
wasm.ext_ed_from_seed(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -76,7 +78,7 @@ export const ed25519Sign = withWasm((wasm) =>
const [ptr1, len1] = allocU8a(seckey);
const [ptr2, len2] = allocU8a(message);
wasm.ext_ed_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
wasm.ext_ed_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
@@ -98,7 +100,7 @@ export const sr25519DeriveKeypairHard = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_hard(8, ptr0, len0, ptr1, len1);
wasm.ext_sr_derive_keypair_hard(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -109,7 +111,7 @@ export const sr25519DeriveKeypairSoft = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(pair);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_keypair_soft(8, ptr0, len0, ptr1, len1);
wasm.ext_sr_derive_keypair_soft(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -120,7 +122,7 @@ export const sr25519DerivePublicSoft = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(cc);
wasm.ext_sr_derive_public_soft(8, ptr0, len0, ptr1, len1);
wasm.ext_sr_derive_public_soft(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -130,7 +132,7 @@ export const sr25519KeypairFromSeed = withWasm((wasm) =>
(seed: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(seed);
wasm.ext_sr_from_seed(8, ptr0, len0);
wasm.ext_sr_from_seed(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -142,7 +144,7 @@ export const sr25519Sign = withWasm((wasm) =>
const [ptr1, len1] = allocU8a(secret);
const [ptr2, len2] = allocU8a(message);
wasm.ext_sr_sign(8, ptr0, len0, ptr1, len1, ptr2, len2);
wasm.ext_sr_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2);
return resultU8a();
}
@@ -159,6 +161,17 @@ export const sr25519Verify = withWasm((wasm) =>
}
);
export const sr25519Agree = withWasm((wasm) =>
(pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(pubkey);
const [ptr1, len1] = allocU8a(secret);
wasm.ext_sr_agree(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const vrfSign = withWasm((wasm) =>
(secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(secret);
@@ -166,7 +179,7 @@ export const vrfSign = withWasm((wasm) =>
const [ptr2, len2] = allocU8a(message);
const [ptr3, len3] = allocU8a(extra);
wasm.ext_vrf_sign(8, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
wasm.ext_vrf_sign(PTR_VEC, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
return resultU8a();
}
@@ -190,7 +203,29 @@ export const blake2b = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(key);
wasm.ext_blake2b(8, ptr0, len0, ptr1, len1, size);
wasm.ext_blake2b(PTR_VEC, ptr0, len0, ptr1, len1, size);
return resultU8a();
}
);
export const hmacSha256 = withWasm((wasm) =>
(key: Uint8Array, data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(key);
const [ptr1, len1] = allocU8a(data);
wasm.ext_hmac_sha256(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
);
export const hmacSha512 = withWasm((wasm) =>
(key: Uint8Array, data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(key);
const [ptr1, len1] = allocU8a(data);
wasm.ext_hmac_sha512(PTR_VEC, ptr0, len0, ptr1, len1);
return resultU8a();
}
@@ -200,7 +235,17 @@ export const keccak256 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak256(8, ptr0, len0);
wasm.ext_keccak256(PTR_VEC, ptr0, len0);
return resultU8a();
}
);
export const keccak512 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_keccak512(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -211,7 +256,7 @@ export const pbkdf2 = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(data);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_pbkdf2(8, ptr0, len0, ptr1, len1, rounds);
wasm.ext_pbkdf2(PTR_VEC, ptr0, len0, ptr1, len1, rounds);
return resultU8a();
}
@@ -222,7 +267,17 @@ export const scrypt = withWasm((wasm) =>
const [ptr0, len0] = allocU8a(password);
const [ptr1, len1] = allocU8a(salt);
wasm.ext_scrypt(8, ptr0, len0, ptr1, len1, log2n, r, p);
wasm.ext_scrypt(PTR_VEC, ptr0, len0, ptr1, len1, log2n, r, p);
return resultU8a();
}
);
export const sha256 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha256(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -232,7 +287,7 @@ export const sha512 = withWasm((wasm) =>
(data: Uint8Array): Uint8Array => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_sha512(8, ptr0, len0);
wasm.ext_sha512(PTR_VEC, ptr0, len0);
return resultU8a();
}
@@ -242,7 +297,7 @@ export const twox = withWasm((wasm) =>
(data: Uint8Array, rounds: number) => {
const [ptr0, len0] = allocU8a(data);
wasm.ext_twox(8, ptr0, len0, rounds);
wasm.ext_twox(PTR_VEC, ptr0, len0, rounds);
return resultU8a();
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.4.1' };
+107 -4
View File
@@ -3,10 +3,10 @@
use blake2_rfc::blake2b::blake2b;
use byteorder::{ByteOrder, LittleEndian};
use hmac::Hmac;
use hmac::{Hmac, Mac};
use pbkdf2::pbkdf2;
use scrypt::{ScryptParams, scrypt};
use sha2::{Digest, Sha512};
use sha2::{Digest, Sha256, Sha512};
use tiny_keccak::{Hasher, Keccak};
use twox_hash::XxHash;
use wasm_bindgen::prelude::*;
@@ -41,6 +41,39 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec<u8> {
.to_vec()
}
/// hmac with sha256
#[wasm_bindgen]
pub fn ext_hmac_sha256(key: &[u8], data: &[u8]) -> Vec<u8> {
match Hmac::<Sha256>::new_varkey(key){
Ok(mut mac) => {
mac.input(data);
mac
.result()
.code()
.to_vec()
},
Err(_) => panic!("Invalid key provided.")
}
}
/// hmac with sha512
#[wasm_bindgen]
pub fn ext_hmac_sha512(key: &[u8], data: &[u8]) -> Vec<u8> {
match Hmac::<Sha512>::new_varkey(key) {
Ok(mut mac) => {
mac.input(data);
mac
.result()
.code()
.to_vec()
},
Err(_) => panic!("Invalid key provided.")
}
}
/// Create a keccak256 hash for the specified input
///
// * data: Arbitrary data to be hashed
@@ -57,6 +90,22 @@ pub fn ext_keccak256(data: &[u8]) -> Vec<u8> {
result.to_vec()
}
/// Create a keccak512 hash for the specified input
///
// * data: Arbitrary data to be hashed
///
/// Returns the hash as a vector
#[wasm_bindgen]
pub fn ext_keccak512(data: &[u8]) -> Vec<u8> {
let mut keccak = Keccak::v512();
let mut result = [0u8; 64];
keccak.update(data);
keccak.finalize(&mut result);
result.to_vec()
}
/// pbkdf2 kdf from an input, salt for the number of specified rounds
///
/// * data: Arbitrary data to be hashed
@@ -69,7 +118,7 @@ pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec<u8> {
let mut result = [0u8; 64];
// we cast to usize here - due to the WASM, we'd rather have u32 inputs
pbkdf2::<Hmac<Sha512>>(data, salt, rounds as usize, &mut result);
pbkdf2::<Hmac::<Sha512>>(data, salt, rounds as usize, &mut result);
result.to_vec()
}
@@ -89,11 +138,27 @@ pub fn ext_scrypt(password: &[u8], salt: &[u8], log2_n: u8, r: u32, p: u32) -> V
let mut result = [0u8; 64];
match scrypt(password, salt, &params, &mut result) {
Ok(_) => return result.to_vec(),
Ok(_) => result.to_vec(),
Err(_) => panic!("Invalid scrypt hash.")
}
}
/// sha256 hash for the specified input
///
/// * data: Arbitrary data to be hashed
///
/// Returns a vector with the hash result
#[wasm_bindgen]
pub fn ext_sha256(data: &[u8]) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.input(data);
hasher
.result()
.to_vec()
}
/// sha512 hash for the specified input
///
/// * data: Arbitrary data to be hashed
@@ -154,6 +219,35 @@ pub mod tests {
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_hmac_sha256() {
let key = b"secret";
let data = b"some message";
let expected = hex!("f28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7");
let hash = ext_hmac_sha256(key, data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_hmac_sha512() {
let key = b"secret";
let data = b"some message";
let expected = hex!("295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841");
let hash = ext_hmac_sha512(key, data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_keccak512() {
let data = b"test";
let expected = hex!("1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e");
let hash = ext_keccak512(data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_pbkdf2() {
let salt = b"this is a salt";
@@ -174,6 +268,15 @@ pub mod tests {
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_sha256() {
let data = b"hello world";
let expected = hex!("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
let hash = ext_sha256(data);
assert_eq!(hash[..], expected[..]);
}
#[test]
fn can_sha512() {
let data = b"hello world";
+53 -1
View File
@@ -7,6 +7,7 @@
// which was adpated from the initial https://github.com/paritytech/schnorrkel-js/
// forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f
use curve25519_dalek::scalar::Scalar;
use schnorrkel::{
ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, Signature,
derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH},
@@ -134,13 +135,36 @@ pub fn ext_sr_verify(signature: &[u8], message: &[u8], pubkey: &[u8]) -> bool {
}
}
/// Key agreement between other's public key and self secret key.
///
/// * pubkey: UIntArray with 32 element
/// * secret: UIntArray with 64 element
///
/// * returned vector is the generated secret of 32 bytes.
#[wasm_bindgen]
pub fn ext_sr_agree(pubkey: &[u8], secret: &[u8]) -> Vec<u8> {
// The first 32 bytes holds the canonical private key
let mut key = [0u8; 32];
key.copy_from_slice(
&SecretKey::from_ed25519_bytes(secret)
.unwrap()
.to_bytes()[0..32]
);
(
&Scalar::from_canonical_bytes(key).unwrap() *
PublicKey::from_bytes(pubkey).unwrap().as_point()
).compress().0.to_vec()
}
#[cfg(test)]
pub mod tests {
extern crate rand;
extern crate schnorrkel;
use hex_literal::hex;
use super::*;
use hex_literal::hex;
use schnorrkel::{SIGNATURE_LENGTH, KEYPAIR_LENGTH, SECRET_KEY_LENGTH};
fn generate_random_seed() -> Vec<u8> {
@@ -243,4 +267,32 @@ pub mod tests {
assert_eq!(public, expected);
}
#[test]
fn key_agreement() {
let self_seed = hex!("98b3d305d5a5eace562387e47e59badd4d77e3f72cabfb10a60f8a197059f0a8");
let other_seed = hex!("9732eea001851ff862d949a1699c9971f3a26edbede2ad7922cbbe9a0701f366");
let expected = hex!("b03a0b198c34c16f35cae933d88b16341b4cef3e84e851f20e664c6a30527f4e");
let self_pair = ext_sr_from_seed(&self_seed);
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
let other_pair = ext_sr_from_seed(&other_seed);
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
assert_eq!(ext_sr_agree(self_pk, other_sk), expected);
assert_eq!(ext_sr_agree(other_pk, self_sk), expected);
let seed = generate_random_seed();
let self_pair = ext_sr_from_seed(seed.as_slice());
let self_sk = &self_pair[0..SECRET_KEY_LENGTH];
let self_pk = &self_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
let seed = generate_random_seed();
let other_pair = ext_sr_from_seed(seed.as_slice());
let other_sk = &other_pair[0..SECRET_KEY_LENGTH];
let other_pk = &other_pair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH];
assert_eq!(ext_sr_agree(self_pk, other_sk), ext_sr_agree(other_pk, self_sk));
}
}
+60 -22
View File
@@ -7,33 +7,71 @@
export interface WasmCryptoInstance {
memory: WebAssembly.Memory;
// wbindgen functions (required and used internally)
__wbindgen_free(a: number, b: number): void;
__wbindgen_malloc(a: number): number;
__wbindgen_realloc(a: number, b: number, c: number): number;
__wbindgen_exn_store(a: number): void;
ext_bip39_generate(a: number, b: number): void;
ext_bip39_to_entropy(a: number, b: number, c: number): void;
ext_bip39_to_mini_secret(a: number, b: number, c: number, d: number, e: number): void;
ext_bip39_to_seed(a: number, b: number, c: number, d: number, e: number): void;
ext_bip39_validate(a: number, b: number): number;
ext_ed_from_seed(a: number, b: number, c: number): void;
ext_ed_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
ext_ed_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
ext_blake2b(a: number, b: number, c: number, d: number, e: number, f: number): void;
ext_keccak256(a: number, b: number, c: number): void;
ext_pbkdf2(a: number, b: number, c: number, d: number, e: number, f: number): void;
ext_scrypt(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): void;
ext_sha512(a: number, b: number, c: number): void;
ext_twox(a: number, b: number, c: number, d: number): void;
ext_sr_derive_keypair_hard(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_derive_keypair_soft(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_derive_public_soft(a: number, b: number, c: number, d: number, e: number): void;
ext_sr_from_seed(a: number, b: number, c: number): void;
ext_sr_sign(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
ext_sr_verify(a: number, b: number, c: number, d: number, e: number, f: number): number;
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;
// exposed functions
ext_bip39_generate(resLen: 8, words: number): void;
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
}
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
+12 -14
View File
@@ -1,11 +1,9 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, u8aToHex } = require('@polkadot/util');
function bip39_generate (wasm) {
function bip39Generate (wasm) {
const res = wasm.bip39Generate(21);
console.log('\tPHR', res);
@@ -13,7 +11,7 @@ function bip39_generate (wasm) {
assert(res.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length');
}
function bip39_generate_subsequent (wasm) {
function bip39GenerateSubsequent (wasm) {
const val1 = wasm.bip39Generate(24);
const val2 = wasm.bip39Generate(24);
@@ -23,7 +21,7 @@ function bip39_generate_subsequent (wasm) {
assert(val1 !== val2, 'ERROR: Subsequent mnemonics are the same');
}
function bip39_validate (wasm) {
function bip39Validate (wasm) {
const res = wasm.bip39Validate(wasm.bip39Generate(12));
console.log('\tVAL', res);
@@ -31,7 +29,7 @@ function bip39_validate (wasm) {
assert(res, 'ERROR: Invalid bip39 validation');
}
function bip39_toEntropy (wasm) {
function bip39ToEntropy (wasm) {
const res = u8aToHex(wasm.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow'));
console.log('\tENT', res);
@@ -39,7 +37,7 @@ function bip39_toEntropy (wasm) {
assert(res === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy');
}
function bip39_toMiniSecret (wasm) {
function bip39ToMiniSecret (wasm) {
const res = u8aToHex(wasm.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate'));
console.log('\tMIN', res);
@@ -47,7 +45,7 @@ function bip39_toMiniSecret (wasm) {
assert(res === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret');
}
function bip39_toSeed (wasm) {
function bip39ToSeed (wasm) {
const res = u8aToHex(wasm.bip39ToSeed('seed sock milk update focus rotate barely fade car face mechanic mercy', ''));
console.log('\tSEE', res);
@@ -56,10 +54,10 @@ function bip39_toSeed (wasm) {
}
module.exports = {
bip39_generate,
bip39_generate_subsequent,
bip39_toEntropy,
bip39_toMiniSecret,
bip39_toSeed,
bip39_validate
bip39Generate,
bip39GenerateSubsequent,
bip39ToEntropy,
bip39ToMiniSecret,
bip39ToSeed,
bip39Validate
};
+8 -10
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.ed25519KeypairFromSeed(crypto.randomBytes(32)));
}
function ed25519_pairFromSeed (wasm) {
function ed25519PairFromSeed (wasm) {
const [pair, pk, sk] = extractKeys(wasm.ed25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')));
console.log('\tSEC', u8aToHex(sk));
@@ -23,7 +21,7 @@ function ed25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0x31323334353637383930313233343536373839303132333435363738393031322f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee', 'ERROR: pairFromSeed() does not match');
}
function ed25519_signAndVerify (wasm) {
function ed25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.ed25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.ed25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -34,7 +32,7 @@ function ed25519_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function ed25519_verifyExisting (wasm) {
function ed25519VerifyExisting (wasm) {
const isValid = wasm.ed25519Verify(hexToU8a('0x90588f3f512496f2dd40571d162e8182860081c74e2085316e7c4396918f07da412ee029978e4dd714057fe973bd9e7d645148bf7b66680d67c93227cde95202'), stringToU8a('this is a message'), hexToU8a('0x2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee'));
console.log('\tRES', isValid);
@@ -42,7 +40,7 @@ function ed25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function ed25519_benchmark (wasm) {
function ed25519Benchmark (wasm) {
const MESSAGE = stringToU8a('this is a message');
for (let i = 0; i < 256; i++) {
@@ -53,8 +51,8 @@ function ed25519_benchmark (wasm) {
}
module.exports = {
ed25519_benchmark,
ed25519_pairFromSeed,
ed25519_signAndVerify,
ed25519_verifyExisting
ed25519Benchmark,
ed25519PairFromSeed,
ed25519SignAndVerify,
ed25519VerifyExisting
};
+36 -2
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
function blake2bHash (wasm) {
@@ -13,6 +11,22 @@ function blake2bHash (wasm) {
assert(hash === '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923', 'ERROR: blake2bHash does not match');
}
function hmacSha256 (wasm) {
const hash = u8aToHex(wasm.hmacSha256(stringToU8a('secret'), stringToU8a('some message')));
console.log('\tRES', hash);
assert(hash === '0xf28a70b41263840e5c059a0a733336e0957efba87902aa8cca11441d4b0c96d7', 'ERROR: hmacSha256 does not match');
}
function hmacSha512 (wasm) {
const hash = u8aToHex(wasm.hmacSha512(stringToU8a('secret'), stringToU8a('some message')));
console.log('\tRES', hash);
assert(hash === '0x295832e97ed77be75a9fa98029497e4a722c4b9a2f21b39d34f1befa931a39ec520fd24711d6f5c03501384ea66b83066a01a82c57a0460f8cd1f471fcce5841', 'ERROR: hmacSha512 does not match');
}
function keccak256 (wasm) {
const hash = u8aToHex(wasm.keccak256(stringToU8a('test value')));
@@ -21,6 +35,14 @@ function keccak256 (wasm) {
assert(hash === '0x2d07364b5c231c56ce63d49430e085ea3033c750688ba532b24029124c26ca5e', 'ERROR: keccak256 does not match');
}
function keccak512 (wasm) {
const hash = u8aToHex(wasm.keccak512(stringToU8a('test')));
console.log('\tRES', hash);
assert(hash === '0x1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e', 'ERROR: keccak512 does not match');
}
function pbkdf2Hash (wasm) {
const hash = u8aToHex(wasm.pbkdf2(stringToU8a('hello world'), stringToU8a('this is a salt'), 2048));
@@ -37,6 +59,14 @@ function scryptHash (wasm) {
assert(hash === '0x745731af4484f323968969eda289aeee005b5903ac561e64a5aca121797bf7734ef9fd58422e2e22183bcacba9ec87ba0c83b7a2e788f03ce0da06463433cda6', 'ERROR: scryptHash does not match');
}
function sha256Hash (wasm) {
const hash = u8aToHex(wasm.sha256(stringToU8a('hello world')));
console.log('\tRES', hash);
assert(hash === '0xb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9', 'ERROR: sha256Hash does not match');
}
function sha512Hash (wasm) {
const hash = u8aToHex(wasm.sha512(stringToU8a('hello world')));
@@ -57,9 +87,13 @@ function twoxHash (wasm) {
module.exports = {
blake2bHash,
hmacSha256,
hmacSha512,
keccak256,
keccak512,
pbkdf2Hash,
scryptHash,
sha256Hash,
sha512Hash,
twoxHash
};
+40 -24
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function sr25519_pairFromSeed (wasm) {
function sr25519PairFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -23,7 +21,7 @@ function sr25519_pairFromSeed (wasm) {
assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match');
}
function sr25519_devFromSeed (wasm) {
function sr25519DevFromSeed (wasm) {
const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'));
console.log('\tSEC', u8aToHex(pair.slice(0, 64)));
@@ -32,7 +30,7 @@ function sr25519_devFromSeed (wasm) {
assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match');
}
function sr25519_verifyExisting (wasm) {
function sr25519VerifyExisting (wasm) {
const PK = hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d');
const MESSAGE = stringToU8a('I hereby verify that I control 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
const SIGNATURE = hexToU8a('0xb83881d3bd7302981ee1c504fe5b7b394682927131fc0846fd616bb40fa14d02640fd2aca785b4cb57904765c2e4e75f59a7dd30154c209964369912091f6981');
@@ -44,7 +42,7 @@ function sr25519_verifyExisting (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_sign_deterministic (wasm) {
function sr25519SignDeterministic (wasm) {
const [, pk, sk] = randomPair(wasm);
const sig1 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
const sig2 = u8aToHex(wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')));
@@ -55,7 +53,7 @@ function sr25519_sign_deterministic (wasm) {
assert(sig1 !== sig2, 'ERROR: Signatures are deterministic');
}
function sr25519_signAndVerify (wasm) {
function sr25519SignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message'));
const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk);
@@ -66,7 +64,7 @@ function sr25519_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify signature');
}
function sr25519_deriveHard (wasm) {
function sr25519DeriveHard (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -74,7 +72,7 @@ function sr25519_deriveHard (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveHardKnown (wasm) {
function sr25519DeriveHardKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -84,7 +82,7 @@ function sr25519_deriveHardKnown (wasm) {
assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys');
}
function sr25519_deriveSoft (wasm) {
function sr25519DeriveSoft (wasm) {
const [pair] = randomPair(wasm);
const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
@@ -92,7 +90,7 @@ function sr25519_deriveSoft (wasm) {
console.log('\tPUB', u8aToHex(derived.slice(64)));
}
function sr25519_deriveSoftKnown (wasm) {
function sr25519DeriveSoftKnown (wasm) {
const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'));
const publicKey = u8aToHex(derived.slice(64));
@@ -102,7 +100,7 @@ function sr25519_deriveSoftKnown (wasm) {
assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
}
function sr25519_deriveSoftPubkey (wasm) {
function sr25519DeriveSoftPubkey (wasm) {
const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')));
console.log('\tPUB', derived);
@@ -110,7 +108,24 @@ function sr25519_deriveSoftPubkey (wasm) {
assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys');
}
function sr25519_benchmark (wasm) {
function sr25519KeyAgreement (wasm) {
const pair1 = wasm.sr25519KeypairFromSeed(hexToU8a('0x3b44c558f9a8f3dc9690d53088558c1ba2529b677e316c6054d1852595b004af'));
const pair2 = wasm.sr25519KeypairFromSeed(hexToU8a('0x923b80f79c6981fe756272128ec236eb510ae016dd20bdccbd77a9416b7ab94e'));
const [, pk1, sk1] = extractKeys(pair1);
const [, pk2, sk2] = extractKeys(pair2);
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
assert(u8aToHex(wasm.sr25519Agree(pk2, sk1)) === '0xfa7b90001b790fe42ff78b8cd86f6cf7a7c0a70b72f6b4c771b5d67536450222', 'Unmatched agreement keys');
for (let i = 0; i < 256; i++) {
const [, pk1, sk1] = randomPair(wasm);
const [, pk2, sk2] = randomPair(wasm);
assert(u8aToHex(wasm.sr25519Agree(pk1, sk2)) === u8aToHex(wasm.sr25519Agree(pk2, sk1)), 'Unmatched agreement keys');
}
}
function sr25519Benchmark (wasm) {
const MESSAGE = stringToU8a('this is a message');
for (let i = 0; i < 256; i++) {
@@ -121,15 +136,16 @@ function sr25519_benchmark (wasm) {
}
module.exports = {
sr25519_benchmark,
sr25519_deriveHard,
sr25519_deriveHardKnown,
sr25519_deriveSoft,
sr25519_deriveSoftKnown,
sr25519_deriveSoftPubkey,
sr25519_devFromSeed,
sr25519_pairFromSeed,
sr25519_signAndVerify,
sr25519_sign_deterministic,
sr25519_verifyExisting
sr25519Benchmark,
sr25519DeriveHard,
sr25519DeriveHardKnown,
sr25519DeriveSoft,
sr25519DeriveSoftKnown,
sr25519DeriveSoftPubkey,
sr25519DevFromSeed,
sr25519KeyAgreement,
sr25519PairFromSeed,
sr25519SignAndVerify,
sr25519SignDeterministic,
sr25519VerifyExisting
};
+6 -8
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
const crypto = require('crypto');
const { assert, stringToU8a, u8aToHex } = require('@polkadot/util');
@@ -14,7 +12,7 @@ function randomPair (wasm) {
return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32)));
}
function vrf_signAndVerify_compat (wasm) {
function vrfSignAndVerifyCompat (wasm) {
const [, pk, sk] = randomPair(wasm);
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array());
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), new Uint8Array(), outAndProof);
@@ -25,7 +23,7 @@ function vrf_signAndVerify_compat (wasm) {
assert(isValid, 'ERROR: Unable to verify VRF output & proof');
}
function vrf_signAndVerify (wasm) {
function vrfSignAndVerify (wasm) {
const [, pk, sk] = randomPair(wasm);
const outAndProof = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
const isValid = wasm.vrfVerify(pk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'), outAndProof);
@@ -36,7 +34,7 @@ function vrf_signAndVerify (wasm) {
assert(isValid, 'ERROR: Unable to verify VRF extra output & proof');
}
function vrf_signAndVerify_deterministic (wasm) {
function vrfSignAndVerifyDeterministic (wasm) {
const [,, sk] = randomPair(wasm);
const outAndProof1 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
const outAndProof2 = wasm.vrfSign(sk, stringToU8a('my VRF context'), stringToU8a('this is a message'), stringToU8a('extra param'));
@@ -50,7 +48,7 @@ function vrf_signAndVerify_deterministic (wasm) {
}
module.exports = {
vrf_signAndVerify,
vrf_signAndVerify_compat,
vrf_signAndVerify_deterministic
vrfSignAndVerify,
vrfSignAndVerifyCompat,
vrfSignAndVerifyDeterministic
};
+9 -5
View File
@@ -14,13 +14,17 @@ const external = [
const overrides = {
'@polkadot/wasm-crypto': {
entries: ['asmjs', 'wasm'].map((p) => `wasm-crypto-${p}`).map((p) => ({
find: `@polkadot/${p}`,
replacement: `../../${p}/build`
}))
entries: ['asmjs', 'wasm'].map((p) => `wasm-crypto-${p}`).reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: `../../${p}/build`
}), {})
}
};
export default pkgs.map((pkg) =>
createBundle({ external, pkg, ...(overrides[pkg] || {}) })
createBundle({
external,
pkg,
...(overrides[pkg] || {})
})
);
+6 -6
View File
@@ -5,8 +5,7 @@
set -e
# also change in install-build-deps
RUST_VER=nightly-2020-10-25
source ../scripts/rust-version.sh
WSM=bytes/wasm_bg.wasm
OPT=bytes/wasm_opt.wasm
@@ -15,17 +14,18 @@ ASM=wasm-crypto-asmjs/build/cjs/data.js
# build new via wasm-pack
echo "*** Building Rust sources"
cd wasm-crypto
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
# rustup run $RUST_VER cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
if [ "$RUST_VER" == "stable" ]; then
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
else
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
fi
cd ..
echo "*** Converting to WASM"
../bindgen/wasm-bindgen wasm-crypto/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir bytes --target web
# wasm-pack build --release --scope polkadot --target web
# optimise
echo "*** Optimising WASM output"
# ../../wabt/bin/wasm-strip $WSM
../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
+5 -3
View File
@@ -5,8 +5,7 @@
set -e
# also change in build-package
RUST_VER=nightly-2020-10-25
source ./scripts/rust-version.sh
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
BINARYEN_VER=version_97
@@ -24,7 +23,10 @@ unamestr=`uname`
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
cargo install xargo
if [ "$RUST_VER" != "stable" ]; then
cargo install xargo
fi
if [[ "$unamestr" == 'Linux' ]]; then
echo "*** Detected Linux"
+7 -26
View File
@@ -5,39 +5,20 @@ const fflate = require('fflate/node');
const fs = require('fs');
const { formatNumber } = require('@polkadot/util');
// const A_NAME = 'wasm-crypto-asmjs';
const W_NAME = 'wasm-crypto-wasm';
function hdr (package) {
return `// Copyright 2019-2021 @polkadot/${package} authors & contributors
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `// Copyright 2019-2021 @polkadot/${W_NAME} authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Generated as part of the build, do not edit
`;
}
function getWasmBuffer () {
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
return { compressed, sizeUncompressed: data.length };
}
// fs.writeFileSync(`./${A_NAME}/build/data.js`, `${hdr(A_NAME)}
// export { asmJsInit } from './data.cjs';
// `);
// fs.writeFileSync(`./${W_NAME}/build/bytes.js`, `${hdr(W_NAME)}
// export { bytes, sizeCompressed, sizeUncompressed } from './bytes.cjs';
// `);
const { compressed, sizeUncompressed } = getWasmBuffer();
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `${hdr(W_NAME)}
const sizeCompressed = ${compressed.length};
const sizeUncompressed = ${sizeUncompressed};
const sizeUncompressed = ${data.length};
const bytes = '${compressed.toString('base64')}';
module.exports = { bytes, sizeCompressed, sizeUncompressed };
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Copyright 2019-2021 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
RUST_VER=nightly-2020-10-25
# RUST_VER=stable
+1698 -2550
View File
File diff suppressed because it is too large Load Diff