diff --git a/README.md b/README.md index 89cf109d..9017fa21 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Various WASM wrappers around Rust crates It is split up into a number of internal packages, namely utilities - +- [wasm-crypto](packages/wasm-crypto/) Various hashing functions - [wasm-schnorrkel](packages/wasm-schnorrkel/) sr25519 ## development diff --git a/lerna.json b/lerna.json index e49aef07..28d196dd 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "0.1.1" + "version": "0.2.0-beta.0" } diff --git a/package.json b/package.json index f6c7c218..a6c95ab4 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,6 @@ }, "devDependencies": { "@polkadot/dev": "^0.27.1", - "@polkadot/util": "^0.38.0-beta.4" + "@polkadot/util": "^0.38.1" } } diff --git a/packages/wasm-schnorrkel/CHANGELOG.md b/packages/wasm-crypto/CHANGELOG.md similarity index 100% rename from packages/wasm-schnorrkel/CHANGELOG.md rename to packages/wasm-crypto/CHANGELOG.md diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock new file mode 100644 index 00000000..91861e9a --- /dev/null +++ b/packages/wasm-crypto/Cargo.lock @@ -0,0 +1,703 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "arrayvec" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "autocfg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "backtrace" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "block-buffer" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "block-padding" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bumpalo" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cc" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crypto-mac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "digest" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "generic-array" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hex-literal" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hex-literal-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hmac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.50" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "nodrop" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "once_cell" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "opaque-debug" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "pbkdf2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-hack" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-hack-impl" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_jitter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "sha2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "smallvec" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "0.15.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synstructure" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tiny-bip39" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "twox-hash" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "typenum" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "wasm" +version = "0.0.0" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "wee_alloc 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wasm-bindgen-macro 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bumpalo 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "wee_alloc" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" +"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" +"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" +"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" +"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" +"checksum bumpalo 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e244c3d946bd68dc2c8996d35363d3a855ff55d59aa1c4b41df8b52334c5e19c" +"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" +"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" +"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" +"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" +"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" +"checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" +"checksum hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" +"checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" +"checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" +"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" +"checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" +"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" +"checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" +"checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" +"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" +"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" +"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" +"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" +"checksum tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5388a470627f97a01a6e13389ced797a42b1611f9de7e0f6ca705675ac55297" +"checksum twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "555cd4909480122bbbf21e34faac4cb08a171f324775670447ed116726c474af" +"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum wasm-bindgen 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "06e36714cc3947a9c80ddc9715edb319e445e5ab0d0b083debec0dd52558580e" +"checksum wasm-bindgen-backend 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "6764493f6eeb3f8632ffd418bf7db6a7e7aca98417c115833e4663976cd60a5e" +"checksum wasm-bindgen-macro 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a473501c40a2a4da83ae7176fead61f10d003554b701071a704dd0667397027a" +"checksum wasm-bindgen-macro-support 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "72e5a249738c6315f65ce5527632e2a3a067cdf1765422d8ac1572dcee14f819" +"checksum wasm-bindgen-shared 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "70f57643dac7decc3b53f0e4ffd027e225b79281648842eb46015e58a2400870" +"checksum wee_alloc 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e841fed992c6c70cf2af5dbcffb0d988b1a7ffc5177ae4fb714ed14944b39d0a" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml new file mode 100644 index 00000000..cc9f9784 --- /dev/null +++ b/packages/wasm-crypto/Cargo.toml @@ -0,0 +1,30 @@ +# name & version is only used internally, doesn't need to be adjusted. In the case of +# name keep it consistent at "wasm" since the scripts (for re-use purposes) expect that + +[package] +authors = ["Jaco Greeff "] +edition = "2018" +name = "wasm" +publish = false +version = "0.0.0" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +blake2-rfc = "0.2.18" +byteorder = "1.3.1" +hmac = "0.7.0" +pbkdf2 = { version = "0.3.0", default-features = false } +sha2 = "0.8.0" +tiny-bip39 = { version = "0.6.1", default-features = false } +twox-hash = "1.1.2" +wasm-bindgen = "0.2" +wee_alloc = "0.4.3" + +[dev-dependencies] +hex-literal = "0.1.4" +rand = { version = "0.6.5", features = ["wasm-bindgen"] } + +[profile.release] +lto = true diff --git a/packages/wasm-crypto/LICENSE b/packages/wasm-crypto/LICENSE new file mode 100644 index 00000000..0d381b2e --- /dev/null +++ b/packages/wasm-crypto/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/wasm-crypto/README.md b/packages/wasm-crypto/README.md new file mode 100644 index 00000000..9a59f136 --- /dev/null +++ b/packages/wasm-crypto/README.md @@ -0,0 +1,3 @@ +# @polkadot/wasm-crypto + +Wrapper around crypto hashing functions diff --git a/packages/wasm-crypto/build.sh b/packages/wasm-crypto/build.sh new file mode 100755 index 00000000..c5057d6f --- /dev/null +++ b/packages/wasm-crypto/build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e + +echo "*** Building package" +../../scripts/build-package.sh + +# shortcuts for files +echo "*** Adjusting output" +SRC=build/wasm.js + +# # we do not want the __ imports (used by WASM) to clutter up +# sed -i -e 's/var wasm;/const crypto = require('\''crypto'\''); let wasm; const requires = { crypto };/g' $SRC + +# # 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 + +# # TextDecoder is not available on RN, so use the @polkadot/util replacement (with polyfill) +# sed -i -e 's/let cachedTextDecoder = new /\/\/ let cachedTextDecoder = new /g' $SRC +# sed -i -e 's/cachedTextDecoder\.decode/u8aToString/g' $SRC + +# # pull the requires from the imports and the `requires` object +# sed -i -e 's/return addHeapObject(require(varg0));/return addHeapObject(requires[varg0]);/g' $SRC +# # sed -i -e 's/return addHeapObject(require(varg0));/throw new Error(`Invalid require from WASM for ${varg0}`);/g' $SRC + +echo "*** Testing package" +cargo test -- --nocapture +node ./test/wasm.js +yarn jest ./test/jest.spec.js diff --git a/packages/wasm-crypto/package.json b/packages/wasm-crypto/package.json new file mode 100644 index 00000000..7aa08dff --- /dev/null +++ b/packages/wasm-crypto/package.json @@ -0,0 +1,25 @@ +{ + "name": "@polkadot/wasm-crypto", + "author": "Jaco Greeff ", + "files": [ + "crypto-polyfill.js", + "index.d.ts", + "index.js", + "wasm.d.ts", + "wasm.js", + "wasm_bg.js", + "wasm_wasm.js" + ], + "main": "index.js", + "types": "index.d.ts", + "scripts": { + "build": "./build.sh" + }, + "version": "0.2.0-beta.0", + "peerDependencies": { + "@polkadot/util": "*" + }, + "devDependencies": { + "jest": "*" + } +} diff --git a/packages/wasm-crypto/src/js/crypto-polyfill.js b/packages/wasm-crypto/src/js/crypto-polyfill.js new file mode 100644 index 00000000..5013c265 --- /dev/null +++ b/packages/wasm-crypto/src/js/crypto-polyfill.js @@ -0,0 +1,21 @@ +// Copyright 2019 @polkadot/wasm-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. + +const crypto = require('crypto'); + +if (!global.crypto) { + global.crypto = {}; +} + +if (!global.crypto.getRandomValues) { + global.crypto.getRandomValues = function (arr) { + const buffer = crypto.randomBytes(arr.length); + + return buffer.reduce((arr, value, index) => { + arr[index] = value; + + return arr; + }, arr); + } +} diff --git a/packages/wasm-crypto/src/js/index.d.ts b/packages/wasm-crypto/src/js/index.d.ts new file mode 100644 index 00000000..9eb970a7 --- /dev/null +++ b/packages/wasm-crypto/src/js/index.d.ts @@ -0,0 +1,15 @@ +// Copyright 2019 @polkadot/wasm-crypto authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +export function bip39Generate (words: 12 | 15 | 18 | 21 | 24): string; +export function bip39ToEntropy (phrase: string): Uint8Array; +export function bip39ToMiniSecret (phrase: string, password: string): Uint8Array; +export function bip39Validate (phrase: string): boolean; +export function blake2b (data: Uint8Array, key: Uint8Array, byteSize: number): Uint8Array; +export function pbkdf2 (data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array; +export function sha512 (data: Uint8Array): Uint8Array; +export function twox (data: Uint8Array, rounds: number): Uint8Array; + +export function isReady (): boolean; +export function waitReady (): Promise; diff --git a/packages/wasm-crypto/src/js/index.js b/packages/wasm-crypto/src/js/index.js new file mode 100644 index 00000000..09a42647 --- /dev/null +++ b/packages/wasm-crypto/src/js/index.js @@ -0,0 +1,17 @@ +// Copyright 2019 @polkadot/wasm-crypto authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +const stubbed = require('./wasm'); + +module.exports.bip39Generate = stubbed.ext_bip39_generate; +module.exports.bip39ToEntropy = stubbed.ext_bip39_to_entropy; +module.exports.bip39ToMiniSecret = stubbed.ext_bip39_to_mini_secret; +module.exports.bip39Validate = stubbed.ext_bip39_validate +module.exports.blake2b = stubbed.ext_blake2b; +module.exports.pbkdf2 = stubbed.ext_pbkdf2; +module.exports.sha512 = stubbed.ext_sha512; +module.exports.twox = stubbed.ext_twox; + +module.exports.isReady = stubbed.isReady; +module.exports.waitReady = stubbed.waitReady; diff --git a/packages/wasm-crypto/src/lib.rs b/packages/wasm-crypto/src/lib.rs new file mode 100644 index 00000000..3602611f --- /dev/null +++ b/packages/wasm-crypto/src/lib.rs @@ -0,0 +1,230 @@ +// Copyright 2019 @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. + +extern crate bip39; +extern crate blake2_rfc; +extern crate hmac; +extern crate pbkdf2; +extern crate sha2; +extern crate twox_hash; +extern crate wasm_bindgen; +extern crate wee_alloc; + +use bip39::{Mnemonic, MnemonicType, Language}; +use blake2_rfc::blake2b::blake2b; +use byteorder::{ByteOrder, LittleEndian}; +use hmac::Hmac; +use pbkdf2::pbkdf2; +use sha2::{Digest, Sha512}; +use std::hash::Hasher; +use twox_hash::XxHash; +use wasm_bindgen::prelude::*; + +// Use `wee_alloc` as the global allocator. +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +/// helper function for a single twox round with a seed +fn create_twox(data: &[u8], seed: u64) -> [u8; 8] { + let mut hasher = XxHash::with_seed(seed); + + hasher.write(data); + + let hash64 = hasher.finish(); + let mut result = [0u8; 8]; + + LittleEndian::write_u64(&mut result, hash64); + + result +} + +/// Generate a bip39 phrase +/// +/// words: number of words, either 12, 15, 18 21 or 24 +/// +/// Returns the bip 39 phrase +#[wasm_bindgen] +pub fn ext_bip39_generate(words: u32) -> String { + Mnemonic::new(MnemonicType::for_word_count(words as usize).unwrap(), Language::English) + .into_phrase() +} + +/// Create entropy from a bip39 phrase +/// +/// * phrase: mnemonic phrase +/// +/// Returns the entropy +#[wasm_bindgen] +pub fn ext_bip39_to_entropy(phrase: &str) -> Vec { + Mnemonic::from_phrase(phrase, Language::English) + .unwrap() + .entropy() + .to_vec() +} + +/// Create a mini-secret from a bip39 phrase +/// +/// * phrase: mnemonic phrase +/// +/// Returns the 32-byte mini-secret via entropy +#[wasm_bindgen] +pub fn ext_bip39_to_mini_secret(phrase: &str, password: &str) -> Vec { + let salt = format!("mnemonic{}", password); + let mnemonic = Mnemonic::from_phrase(phrase, Language::English); + let mut result = [0u8; 64]; + + pbkdf2::>(mnemonic.unwrap().entropy(), salt.as_bytes(), 2048, &mut result); + + result[..32].to_vec() +} + +/// Validates a bip39 phrase +/// +/// * phrase: mnemonic phrase +/// +/// Returns the true/false +#[wasm_bindgen] +pub fn ext_bip39_validate(phrase: &str) -> bool { + match Mnemonic::validate(phrase, Language::English) { + Err(_) => false, + _ => true + } +} + +/// blake2b hash for the specified input +/// +/// * data: Arbitrary data to be hashed +/// * key: Key to add to the hashing (normally empty) +/// * size: Size in bytes of the resulting output +/// +/// Returns a vecor with the hash result +#[wasm_bindgen] +pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec { + // we cast to usize here - due to the WASM, we'd rather have u32 inputs + blake2b(size as usize, key, data) + .as_bytes() + .to_vec() +} + +/// pbkdf2 hash 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 +#[wasm_bindgen] +pub fn ext_pbkdf2(data: &[u8], salt: &[u8], rounds: u32) -> Vec { + let mut result = [0u8; 64]; + + // we cast to usize here - due to the WASM, we'd rather have u32 inputs + pbkdf2::>(data, salt, rounds as usize, &mut result); + + result.to_vec() +} + +/// sha512 hash for the specified input +/// +/// * data: Arbitrary data to be hashed +/// +/// Returns a vecor with the hash result +#[wasm_bindgen] +pub fn ext_sha512(data: &[u8]) -> Vec { + let mut hasher = Sha512::new(); + + hasher.input(data); + + hasher + .result() + .to_vec() +} + +/// twox hash for the specified input and rounds +/// +/// * data: Arbitrary data to be hashed +/// * rounds: Number of 8-byte rounds to add to the output +/// +/// Returns a vecor with the hash result +#[wasm_bindgen] +pub fn ext_twox(data: &[u8], rounds: u32) -> Vec { + let mut vec = vec![]; + + for round in 0..rounds { + // we cast to u64 here - due to the WASM, we'd rather have u32 inputs + vec.extend_from_slice(&create_twox(data, round as u64)); + } + + vec +} + +#[cfg(test)] +pub mod tests { + use hex_literal::{hex, hex_impl}; + use super::*; + + #[test] + fn can_bip39_entropy() { + let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow"; + let entropy = hex!("7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f"); + + assert_eq!(ext_bip39_to_entropy(phrase), entropy); + } + + #[test] + fn can_bip39_mini_secret() { + let phrase = "legal winner thank year wave sausage worth useful legal winner thank yellow"; + let password = "Substrate"; + let mini = hex!("4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685"); + + assert_eq!(ext_bip39_to_mini_secret(phrase, password)[..], mini[..]); + } + + #[test] + fn can_bip39_generate() { + assert!(ext_bip39_validate(&ext_bip39_generate(12))); + } + + #[test] + fn can_bip39_validate() { + assert_eq!(ext_bip39_validate("seed sock milk update focus rotate barely fade car face mechanic mercy"), true); + assert_eq!(ext_bip39_validate("wine photo extra cushion basket dwarf humor cloud truck job boat submit"), false); + } + + #[test] + fn can_blake2b() { + let data = b"abc"; + let expected_32 = hex!("bddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319"); + let expected_64 = hex!("ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"); + + assert_eq!(ext_blake2b(data, &[], 32)[..], expected_32[..]); + assert_eq!(ext_blake2b(data, &[], 64)[..], expected_64[..]); + } + + #[test] + fn can_pbkdf2() { + let salt = b"this is a salt"; + let data = b"hello world"; + let expected = hex!("5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270"); + + assert_eq!(ext_pbkdf2(data, salt, 2048)[..], expected[..]); + } + + #[test] + fn can_sha512() { + let data = b"hello world"; + let expected = hex!("309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"); + + assert_eq!(ext_sha512(data)[..], expected[..]); + } + + #[test] + fn can_twox() { + let data = b"abc"; + let expected_64 = hex!("990977adf52cbc44"); + let expected_256 = hex!("990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b"); + + assert_eq!(ext_twox(data, 1)[..], expected_64[..]); + assert_eq!(ext_twox(data, 4)[..], expected_256[..]); + } +} diff --git a/packages/wasm-crypto/test/all.js b/packages/wasm-crypto/test/all.js new file mode 100644 index 00000000..f549a560 --- /dev/null +++ b/packages/wasm-crypto/test/all.js @@ -0,0 +1,118 @@ +// Copyright 2019 @polkadot/wasm-crypto authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. +// @ts-check + +const { assert, stringToU8a, u8aToHex } = require('@polkadot/util'); +const crypto = require('../build/index'); + +async function beforeAll () { + return crypto.waitReady(); +} + +function bip39Generate () { + const RESULT = crypto.bip39Generate(21); + + console.log('\tPHR', RESULT); + + assert(RESULT.split(' ').length === 21, 'ERROR: Invalid bip39 Phase length'); +} + +function bip39Validate () { + const RESULT = crypto.bip39Validate(crypto.bip39Generate(12)); + + console.log('\tVAL', RESULT); + + assert(RESULT, 'ERROR: Invalid bip39 validation'); +} + +function bip39ToEntropy () { + const RESULT = u8aToHex(crypto.bip39ToEntropy('legal winner thank year wave sausage worth useful legal winner thank yellow')); + + console.log('\tENT', RESULT); + + assert(RESULT === '0x7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'ERROR: Invalid bip39 entropy'); +} + +function bip39ToMiniSecret () { + const RESULT = u8aToHex(crypto.bip39ToMiniSecret('legal winner thank year wave sausage worth useful legal winner thank yellow', 'Substrate')); + + console.log('\tMIN', RESULT); + + assert(RESULT === '0x4313249608fe8ac10fd5886c92c4579007272cb77c21551ee5b8d60b78041685', 'ERROR: Invalid bip39 mini secret'); +} + +function blake2bHash () { + const DATA = stringToU8a('abc'); + const EXPECTED = '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923'; + + const hash = u8aToHex(crypto.blake2b(DATA, new Uint8Array(), 64)); + + console.log('\tRES', hash); + + assert(hash === EXPECTED, 'ERROR: blake2bHash does not match'); +} + +function pbkdf2Hash () { + const SALT = stringToU8a('this is a salt'); + const DATA = stringToU8a('hello world'); + const EXPECTED = '0x5fcbe04f05300a3ecc5c35d18ea0b78f3f6853d2ae5f3fca374f69a7d1f78b5def5c60dae1a568026c7492511e0c53521e8bb6e03a650e1263265fee92722270'; + + const hash = u8aToHex(crypto.pbkdf2(DATA, SALT, 2048)); + + console.log('\tRES', hash); + + assert(hash === EXPECTED, 'ERROR: pbkdf2Hash does not match'); +} + +function sha512Hash () { + const DATA = stringToU8a('hello world'); + const EXPECTED = '0x309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f'; + + const hash = u8aToHex(crypto.sha512(DATA)); + + console.log('\tRES', hash); + + assert(hash === EXPECTED, 'ERROR: sha512Hash does not match'); +} + +function twoxHash () { + const DATA = stringToU8a('abc'); + const EXPECTED_64 = '0x990977adf52cbc44'; + const EXPECTED_256 = '0x990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b'; + + const hash64 = u8aToHex(crypto.twox(DATA, 1)); + const hash256 = u8aToHex(crypto.twox(DATA, 4)); + + console.log('\t64 ', hash64); + console.log('\t256', hash256); + + assert(hash64 === EXPECTED_64 && hash256 === EXPECTED_256, 'ERROR: twoxHash does not match'); +} + +const tests = { + bip39Generate, + bip39Validate, + bip39ToEntropy, + bip39ToMiniSecret, + blake2bHash, + pbkdf2Hash, + sha512Hash, + twoxHash +}; + +function runAll () { + Object.keys(tests).forEach((name) => { + console.time(name); + console.log(); + console.log(name); + + tests[name](); + + console.timeEnd(name); + }); +} + +module.exports.beforeAll = beforeAll; +module.exports.runAll = runAll; +module.exports.tests = tests; diff --git a/packages/wasm-crypto/test/asm.js b/packages/wasm-crypto/test/asm.js new file mode 100644 index 00000000..5f8f944d --- /dev/null +++ b/packages/wasm-crypto/test/asm.js @@ -0,0 +1,9 @@ +// Copyright 2019 @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 + +// @ts-ignore +global.WebAssembly = null; + +require('./wasm'); diff --git a/packages/wasm-crypto/test/jest.spec.js b/packages/wasm-crypto/test/jest.spec.js new file mode 100644 index 00000000..c9d4b9ee --- /dev/null +++ b/packages/wasm-crypto/test/jest.spec.js @@ -0,0 +1,16 @@ +// Copyright 2019 @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 + +require('../build/crypto-polyfill'); + +const { beforeAll, tests } = require('./all.js'); + +describe('schnorrkel-js', () => { + beforeEach(beforeAll); + + Object.keys(tests).forEach((name) => { + it(name, tests[name]); + }); +}); diff --git a/packages/wasm-crypto/test/wasm.js b/packages/wasm-crypto/test/wasm.js new file mode 100644 index 00000000..21cb4c9c --- /dev/null +++ b/packages/wasm-crypto/test/wasm.js @@ -0,0 +1,11 @@ +// Copyright 2019 @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 { beforeAll, runAll } = require('./all'); + +(async () => { + await beforeAll(); + runAll(); +})(); diff --git a/packages/wasm-schnorrkel/Cargo.lock b/packages/wasm-schnorrkel/Cargo.lock index f50a99ff..9c615f2e 100644 --- a/packages/wasm-schnorrkel/Cargo.lock +++ b/packages/wasm-schnorrkel/Cargo.lock @@ -331,8 +331,8 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.0.0" -source = "git+https://github.com/w3f/schnorrkel?rev=d3289df76b8ae6dfb68e733204c5c009df5343a9#d3289df76b8ae6dfb68e733204c5c009df5343a9" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -413,7 +413,7 @@ version = "0.0.0" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel?rev=d3289df76b8ae6dfb68e733204c5c009df5343a9)", + "schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "wee_alloc 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -541,7 +541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel?rev=d3289df76b8ae6dfb68e733204c5c009df5343a9)" = "" +"checksum schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" "checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" diff --git a/packages/wasm-schnorrkel/Cargo.toml b/packages/wasm-schnorrkel/Cargo.toml index b71816f9..66d82f33 100644 --- a/packages/wasm-schnorrkel/Cargo.toml +++ b/packages/wasm-schnorrkel/Cargo.toml @@ -1,21 +1,23 @@ # name & version is only used internally, doesn't need to be adjusted. In the case of # name keep it consistent at "wasm" since the scripts (for re-use purposes) expect that + [package] -name = "wasm" -version = "0.0.0" authors = ["Jaco Greeff ", "kianenigma "] edition = "2018" +name = "wasm" +publish = false +version = "0.0.0" [lib] crate-type = ["cdylib", "rlib"] [dependencies] -wasm-bindgen = { version = "0.2" } -wee_alloc = { version = "0.4.3" } -schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev = "d3289df76b8ae6dfb68e733204c5c009df5343a9", features = ["nightly"] } +schnorrkel = { version = "0.1.0", features = ["nightly"] } +wasm-bindgen = "0.2" +wee_alloc = "0.4.3" [dev-dependencies] -hex-literal = { version = "0.1.4" } +hex-literal = "0.1.4" rand = { version = "0.6.5", features = ["wasm-bindgen"] } [profile.release] diff --git a/packages/wasm-schnorrkel/README.md b/packages/wasm-schnorrkel/README.md index d4e14b04..1be40329 100644 --- a/packages/wasm-schnorrkel/README.md +++ b/packages/wasm-schnorrkel/README.md @@ -1,4 +1,4 @@ -# @polkadot/schnorrkel-js +# @polkadot/wasm-schnorrkel A fork of [@parity/schnorrkel-js](https://github.com/polkadot-js/schnorrkel-js/tree/b1a1bf25be7397d3c21bba5ddde14286a58b269c) that allows proper operation against all the environments that the `@polkadot/api` supports. Changes from the base repo - diff --git a/packages/wasm-schnorrkel/package.json b/packages/wasm-schnorrkel/package.json index d1941869..c8456d47 100644 --- a/packages/wasm-schnorrkel/package.json +++ b/packages/wasm-schnorrkel/package.json @@ -1,7 +1,7 @@ { "name": "@polkadot/wasm-schnorrkel", "collaborators": [ - "Jaco Greeff ", + "Jaco Greeff ", "kianenigma " ], "files": [ @@ -18,7 +18,7 @@ "scripts": { "build": "./build.sh" }, - "version": "0.1.1", + "version": "0.2.0-beta.0", "peerDependencies": { "@polkadot/util": "*" }, diff --git a/packages/wasm-schnorrkel/src/js/crypto-polyfill.js b/packages/wasm-schnorrkel/src/js/crypto-polyfill.js index 603acfda..f0f609d5 100644 --- a/packages/wasm-schnorrkel/src/js/crypto-polyfill.js +++ b/packages/wasm-schnorrkel/src/js/crypto-polyfill.js @@ -1,7 +1,6 @@ // Copyright 2019 @polkadot/wasm-schnorrkel authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -// @ts-check const crypto = require('crypto'); diff --git a/packages/wasm-schnorrkel/src/js/index.d.ts b/packages/wasm-schnorrkel/src/js/index.d.ts index 1375655f..a68e3942 100644 --- a/packages/wasm-schnorrkel/src/js/index.d.ts +++ b/packages/wasm-schnorrkel/src/js/index.d.ts @@ -5,8 +5,9 @@ export function deriveKeypairHard (pair: Uint8Array, chainCode: Uint8Array): Uint8Array; export function deriveKeypairSoft (pair: Uint8Array, chainCode: Uint8Array): Uint8Array; export function derivePublicSoft (publicKey: Uint8Array, chainCode: Uint8Array): Uint8Array; -export function isReady (): boolean; export function keypairFromSeed (seed: Uint8Array): Uint8Array; export function sign (publicKey: Uint8Array, secretKey: Uint8Array, message: Uint8Array): Uint8Array; export function verify (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean; + +export function isReady (): boolean; export function waitReady (): Promise; diff --git a/packages/wasm-schnorrkel/src/js/index.js b/packages/wasm-schnorrkel/src/js/index.js index b9b2368c..bb66c612 100644 --- a/packages/wasm-schnorrkel/src/js/index.js +++ b/packages/wasm-schnorrkel/src/js/index.js @@ -1,15 +1,15 @@ // Copyright 2019 @polkadot/wasm-schnorrkel 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 stubbed = require('./wasm'); module.exports.deriveKeypairHard = stubbed.derive_keypair_hard; module.exports.deriveKeypairSoft = stubbed.derive_keypair_soft; module.exports.derivePublicSoft = stubbed.derive_public_soft; -module.exports.isReady = stubbed.isReady; module.exports.keypairFromSeed = stubbed.keypair_from_seed; module.exports.sign = stubbed.sign; module.exports.verify = stubbed.verify; + +module.exports.isReady = stubbed.isReady; module.exports.waitReady = stubbed.waitReady; diff --git a/packages/wasm-schnorrkel/src/lib.rs b/packages/wasm-schnorrkel/src/lib.rs index f690867f..0c0fa0f0 100644 --- a/packages/wasm-schnorrkel/src/lib.rs +++ b/packages/wasm-schnorrkel/src/lib.rs @@ -1,3 +1,7 @@ +// Copyright 2019 Paritytech, @polkadot/wasm-schnorrkel authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + // Originally developed (as a fork) in https://github.com/polkadot-js/schnorrkel-js/ // which was adpated from the initial https://github.com/paritytech/schnorrkel-js/ // forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f diff --git a/packages/wasm-schnorrkel/test/all.js b/packages/wasm-schnorrkel/test/all.js index c8e435eb..19556289 100644 --- a/packages/wasm-schnorrkel/test/all.js +++ b/packages/wasm-schnorrkel/test/all.js @@ -8,33 +8,20 @@ const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util'); const schnorrkel = require('../build/index'); function extractKeys (pair) { - const pk = pair.slice(64); - const sk = pair.slice(0, 64); - - return [pair, pk, sk]; + return [pair, pair.slice(64), pair.slice(0, 64)]; } function randomPair () { - const seed = crypto.randomBytes(32); - const pair = schnorrkel.keypairFromSeed(seed); - - assert(pair.length === 96, 'ERROR: Invalid pair created'); - - return extractKeys(pair); + return extractKeys(schnorrkel.keypairFromSeed(crypto.randomBytes(32))); } async function beforeAll () { return schnorrkel.waitReady(); } -async function pairFromSeed () { +function pairFromSeed () { const SEED = stringToU8a('12345678901234567890123456789012'); - const PAIR = hexToU8a( - '0x' + - 'f0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050' + - 'f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1' + - '741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63' - ); + const PAIR = hexToU8a('0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63'); const pair = schnorrkel.keypairFromSeed(SEED); @@ -44,14 +31,9 @@ async function pairFromSeed () { assert(u8aToHex(pair) === u8aToHex(PAIR), 'ERROR: pairFromSeed() does not match'); } -async function devFromSeed () { +function devFromSeed () { const SEED = hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e'); - const PAIR = hexToU8a( - '0x' + - '28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51' + - 'fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca34' + - '46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ); + const PAIR = hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'); const pair = schnorrkel.keypairFromSeed(SEED); @@ -61,14 +43,11 @@ async function devFromSeed () { assert(u8aToHex(pair) === u8aToHex(PAIR), 'ERROR: devFromSeed() does not match'); } -async function verifyExisting () { +function verifyExisting () { const PK = hexToU8a('0x741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63'); const MESSAGE = stringToU8a('this is a message'); - const SIGNATURE = hexToU8a( - '0x' + - 'decef12cf20443e7c7a9d406c237e90bcfcf145860722622f92ebfd5eb4b5b39' + - '90b6443934b5cba8f925a0ae75b3a77d35b8490cbb358dd850806e58eaf72904' - ); + const SIGNATURE = hexToU8a('0xdecef12cf20443e7c7a9d406c237e90bcfcf145860722622f92ebfd5eb4b5b3990b6443934b5cba8f925a0ae75b3a77d35b8490cbb358dd850806e58eaf72904' +); const isValid = schnorrkel.verify(SIGNATURE, MESSAGE, PK); @@ -77,7 +56,7 @@ async function verifyExisting () { assert(isValid, 'ERROR: Unable to verify signature'); } -async function signAndVerify () { +function signAndVerify () { const MESSAGE = stringToU8a('this is a message'); const [, pk, sk] = randomPair(); @@ -90,7 +69,7 @@ async function signAndVerify () { assert(isValid, 'ERROR: Unable to verify signature'); } -async function deriveHard () { +function deriveHard () { const CC = hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'); const [pair] = randomPair(); const derived = schnorrkel.deriveKeypairHard(pair, CC); @@ -99,14 +78,9 @@ async function deriveHard () { console.log('\tPUB', u8aToHex(derived.slice(64))); } -async function deriveHardKnown () { +function deriveHardKnown () { const CC = hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000'); - const PAIR = hexToU8a( - '0x' + - '28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51' + - 'fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca34' + - '46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ); + const PAIR = hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'); const PUBLIC = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; const derived = schnorrkel.deriveKeypairHard(PAIR, CC); @@ -118,7 +92,7 @@ async function deriveHardKnown () { assert(publicKey === PUBLIC, 'Unmatched resulting public keys'); } -async function deriveSoft () { +function deriveSoft () { const CC = hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'); const [pair] = randomPair(); @@ -128,15 +102,10 @@ async function deriveSoft () { console.log('\tPUB', u8aToHex(derived.slice(64))); } -async function deriveSoftKnown () { +function deriveSoftKnown () { const CC = hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'); const PUBLIC = '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a'; - const PAIR = hexToU8a( - '0x' + - '28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51' + - 'fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca34' + - '46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ); + const PAIR = hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'); const derived = schnorrkel.deriveKeypairSoft(PAIR, CC); const publicKey = u8aToHex(derived.slice(64)); @@ -147,7 +116,7 @@ async function deriveSoftKnown () { assert(publicKey === PUBLIC, 'Unmatched resulting public keys'); } -async function deriveSoftPubkey () { +function deriveSoftPubkey () { const CC = hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'); const PUBLIC = hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'); const DERIVED = '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a'; @@ -159,16 +128,13 @@ async function deriveSoftPubkey () { assert(derived === DERIVED, 'Unmatched resulting public keys'); } -async function benchmark () { +function benchmark () { const MESSAGE = stringToU8a('this is a message'); for (let i = 0; i < 256; i++) { const [, pk, sk] = randomPair(); - const signature = schnorrkel.sign(pk, sk, MESSAGE); - const isValid = schnorrkel.verify(signature, MESSAGE, pk); - - assert(isValid, 'ERROR: Unable to verify signature'); + assert(schnorrkel.verify(schnorrkel.sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature'); } } @@ -185,13 +151,13 @@ const tests = { benchmark }; -async function runAll () { - Object.keys(tests).forEach(async (name) => { +function runAll () { + Object.keys(tests).forEach((name) => { console.time(name); console.log(); console.log(name); - await tests[name](); + tests[name](); console.timeEnd(name); }); diff --git a/packages/wasm-schnorrkel/test/jest.spec.js b/packages/wasm-schnorrkel/test/jest.spec.js index 71d34657..bbadd9b4 100644 --- a/packages/wasm-schnorrkel/test/jest.spec.js +++ b/packages/wasm-schnorrkel/test/jest.spec.js @@ -8,15 +8,9 @@ require('../build/crypto-polyfill'); const { beforeAll, tests } = require('./all.js'); describe('schnorrkel-js', () => { - beforeEach(async () => { - await beforeAll(); - }); + beforeEach(beforeAll); Object.keys(tests).forEach((name) => { - const test = tests[name]; - - it(name, async () => { - await test(); - }); + it(name, tests[name]); }); }); diff --git a/packages/wasm-schnorrkel/test/wasm.js b/packages/wasm-schnorrkel/test/wasm.js index e549ae36..265bbecf 100644 --- a/packages/wasm-schnorrkel/test/wasm.js +++ b/packages/wasm-schnorrkel/test/wasm.js @@ -7,5 +7,5 @@ const { beforeAll, runAll } = require('./all'); (async () => { await beforeAll(); - await runAll(); + runAll(); })(); diff --git a/scripts/build-package.sh b/scripts/build-package.sh index 209aa2f2..1226cfe2 100755 --- a/scripts/build-package.sh +++ b/scripts/build-package.sh @@ -11,13 +11,23 @@ echo "*** Building WASM output" rustup run nightly wasm-pack build --release --scope polkadot --target nodejs mv pkg build +# shortcuts for files +echo "*** Adjusting output" +BGJ=build/wasm_bg.js +SRC=build/wasm.js +DEF=build/wasm.d.ts +WSM=build/wasm_bg.wasm +OPT=build/wasm_opt.wasm +ASM=build/wasm_asm.js + # optimise echo "*** Optimising WASM output" -../../binaryen/bin/wasm-opt build/wasm_bg.wasm -Os -o build/wasm_opt.wasm +../../binaryen/bin/wasm-opt $WSM -Os -o $OPT +# cp -f build/wasm_bg.wasm build/wasm_opt.wasm # build asmjs version from the input (optimised) WASM # echo "*** Building asm.js version" -# ../../binaryen/bin/wasm2js --no-validation --output build/wasm_temp.js build/wasm_opt.wasm +# ../../binaryen/bin/wasm2js --no-validation --output $ASM $OPT # convert wasm to base64 structure echo "*** Packing WASM into base64" @@ -27,25 +37,11 @@ node ../../scripts/pack-wasm-base64.js echo "*** Copying package sources" cp src/js/* build/ -# shortcuts for files -echo "*** Adjusting output" -BGJ=build/wasm_bg.js -SRC=build/wasm.js -DEF=build/wasm.d.ts -TMP=build/wasm_temp.js -ASM=build/wasm_asm.js - -# update the files (new addition) -# excluded: "wasm_asm\.js", -# sed -i -e 's/wasm_bg\.wasm/wasm_wasm\.js", "index\.js", "index\.d\.ts/g' $PKG -# sed -i -e 's/"main": "wasm\.js"/"main": "index\.js"/g' $PKG -# sed -i -e 's/"types": "wasm\.d\.ts"/"types": "index\.d\.ts"/g' $PKG - # cleanup asm -# sed -i -e 's/import {/\/\/ import {/g' $TMP -# sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $TMP -# sed -i -e 's/export const /module\.exports\./g' $TMP -# sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $TMP +# 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/export const /module\.exports\./g' $ASM +# sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $ASM # we are swapping to a async interface for webpack support (wasm limits) sed -i -e 's/wasm = require/\/\/ wasm = require/g' $SRC @@ -73,11 +69,11 @@ export function waitReady(): Promise; echo " const asm = null; // require('./wasm_asm'); const bytes = require('./wasm_wasm'); -const imported = require('./wasm'); +const js = require('./wasm'); module.exports = async function createExportPromise () { const imports = { - './wasm': imported + './wasm': js }; if (!WebAssembly) { diff --git a/scripts/build.sh b/scripts/build.sh index 1a0dd6f6..ee7012b7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,20 +4,22 @@ set -e ./scripts/install-build-deps.sh -PACKAGES=( "schnorrkel" ) - echo "*** Building packages" cd packages +PACKAGES=( $(ls -1d *) ) + for PKG in "${PACKAGES[@]}"; do - echo "*** Building wasm-$PKG" - cd wasm-$PKG + if [ -f "$PKG/package.json" ]; then + echo "*** Building $PKG" + cd $PKG - ./build.sh - rm -rf build/*-e build/package.json build/README.md - ls -al build + ./build.sh + rm -rf build/*-e build/package.json build/README.md + ls -al build - cd .. + cd .. + fi done cd .. diff --git a/yarn.lock b/yarn.lock index 86a36d7c..c03279da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1578,10 +1578,10 @@ typescript "^3.3.3333" vuepress "^1.0.0-alpha.40" -"@polkadot/util@^0.38.0-beta.4": - version "0.38.0-beta.4" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.38.0-beta.4.tgz#ae791b53feed18240f1335db47de1ef05ba4be15" - integrity sha512-Aq1Ul1JEQDdZSUhQPztbWrZHqFGkWMMK3bg47xtoxrWdtqYhS52a89i+LANSNqli65Z2KhVSTsBakj/tCMBxNQ== +"@polkadot/util@^0.38.1": + version "0.38.1" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.38.1.tgz#602a16e801b0deaae83af6d0ef0d56978ca84c54" + integrity sha512-js8Lc1GsAIDPqjTefySFNThQTZ0XDS6uU9cWIcfJSSL/rjkAB0noiVf7WOkRMFz847kfeT5cjbQb9ZO+3Iqgyw== dependencies: "@babel/runtime" "^7.3.4" "@types/bn.js" "^4.11.4"