From 0ece4538a995320da863126157a5c1ee1716d242 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 31 Jul 2019 11:24:08 +0200 Subject: [PATCH 01/14] Bump schnorrkel to 0.8 --- package.json | 2 +- packages/wasm-crypto/Cargo.lock | 45 ++++++++++++----------------- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/src/sr25519.rs | 14 +++++---- yarn.lock | 8 ++--- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index d2b583cc..e24f4f32 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "devDependencies": { "@babel/core": "^7.5.4", "@polkadot/dev": "^0.30.0-beta.23", - "@polkadot/util": "^0.94.0-beta.19", + "@polkadot/util": "^0.95.0-beta.3", "override-require": "^1.1.1" } } diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index bbcb39c2..83ad128c 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -137,7 +137,7 @@ dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -271,13 +271,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merlin" -version = "1.0.3" +version = "1.2.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)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -483,19 +483,17 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.1.1" +version = "0.8.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)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -527,18 +525,6 @@ dependencies = [ "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sha3" -version = "0.8.1" -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)", - "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak 0.1.0 (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" @@ -551,7 +537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -639,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.8.0 (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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -727,6 +713,11 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.9.3" +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" @@ -764,7 +755,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "83c2dda19c01176e8e7148f7bdb88bbdf215a8db0641f89fc40e4b81736aeda5" +"checksum merlin 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "66448a173ad394ef5ebf734efa724f3644dcffda083b1e89979da4461ddac079" "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" @@ -788,15 +779,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" +"checksum schnorrkel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8bf8bb3d2b309218262456dd161b24456e977120f572e5ec5c6686dddad467e2" "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 sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" "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 subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" +"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" "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" @@ -815,3 +805,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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" +"checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index 993b9da5..cb5a7d86 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { version = "0.1.1", features = ["nightly"] } +schnorrkel = { version = "0.8.0", features = ["nightly"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 15e70b46..bc40e381 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -28,7 +28,7 @@ fn create_cc(data: &[u8]) -> ChainCode { /// Keypair helper function. fn create_from_seed(seed: &[u8]) -> Keypair { match MiniSecretKey::from_bytes(seed) { - Ok(mini) => return mini.expand_to_keypair(), + Ok(mini) => mini.expand_ed25519_to_keypair(), Err(_) => panic!("Provided seed is invalid.") } } @@ -36,7 +36,7 @@ fn create_from_seed(seed: &[u8]) -> Keypair { /// Keypair helper function. fn create_from_pair(pair: &[u8]) -> Keypair { match Keypair::from_bytes(pair) { - Ok(pair) => return pair, + Ok(pair) => pair, Err(_) => panic!("Provided pair is invalid.") } } @@ -44,7 +44,7 @@ fn create_from_pair(pair: &[u8]) -> Keypair { /// PublicKey helper fn create_public(public: &[u8]) -> PublicKey { match PublicKey::from_bytes(public) { - Ok(public) => return public, + Ok(public) => public, Err(_) => panic!("Provided public key is invalid.") } } @@ -52,7 +52,7 @@ fn create_public(public: &[u8]) -> PublicKey { /// SecretKey helper fn create_secret(secret: &[u8]) -> SecretKey { match SecretKey::from_bytes(secret) { - Ok(secret) => return secret, + Ok(secret) => secret, Err(_) => panic!("Provided private key is invalid.") } } @@ -67,7 +67,7 @@ fn create_secret(secret: &[u8]) -> SecretKey { pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { create_from_pair(pair).secret .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 - .expand_to_keypair() + .expand_ed25519_to_keypair() .to_bytes() .to_vec() } @@ -96,7 +96,8 @@ pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec { create_public(public) .derived_key_simple(create_cc(cc), &[]).0 - .to_bytes().to_vec() + .to_bytes() + .to_vec() } /// Generate a key pair. @@ -144,6 +145,7 @@ pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool { create_public(public) .verify_simple(SIGNING_CTX, message, &signature) + .is_ok() } #[cfg(test)] diff --git a/yarn.lock b/yarn.lock index 6242155d..53123ddb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2030,10 +2030,10 @@ typescript "^3.5.3" vuepress "^1.0.2" -"@polkadot/util@^0.94.0-beta.19": - version "0.94.0-beta.19" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.94.0-beta.19.tgz#ed2f379cc644e5663941ac9058050e6227bb9c23" - integrity sha512-jJaMPXuCW7Ch+AKvu4YYT39uL2l/JwKL4jPQDO4StVshyOfr5fvpMSGxE2NGbsntFjLqvb0kODIsv2sFdbMF4Q== +"@polkadot/util@^0.95.0-beta.3": + version "0.95.0-beta.3" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.95.0-beta.3.tgz#80354da564f9b17c0257f55809feebc14a0f338d" + integrity sha512-zM1lBvMXNdfWTDG546cnKJkE9dTE1woDN0pKhEEJsHh4wwas+hxePQbJRNpXrQOYeTXpYRdr0EdRMzDL5PyA0g== dependencies: "@babel/runtime" "^7.5.5" "@types/bn.js" "^4.11.5" From ba705fc2a207f092cc20e6b4bf88c35a88add40c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 31 Jul 2019 11:28:16 +0200 Subject: [PATCH 02/14] Remove unneeded return refactor (stick to issues at-hand) --- packages/wasm-crypto/src/sr25519.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index bc40e381..d07a4746 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -28,7 +28,7 @@ fn create_cc(data: &[u8]) -> ChainCode { /// Keypair helper function. fn create_from_seed(seed: &[u8]) -> Keypair { match MiniSecretKey::from_bytes(seed) { - Ok(mini) => mini.expand_ed25519_to_keypair(), + Ok(mini) => return mini.expand_ed25519_to_keypair(), Err(_) => panic!("Provided seed is invalid.") } } @@ -36,7 +36,7 @@ fn create_from_seed(seed: &[u8]) -> Keypair { /// Keypair helper function. fn create_from_pair(pair: &[u8]) -> Keypair { match Keypair::from_bytes(pair) { - Ok(pair) => pair, + Ok(pair) => return pair, Err(_) => panic!("Provided pair is invalid.") } } @@ -44,7 +44,7 @@ fn create_from_pair(pair: &[u8]) -> Keypair { /// PublicKey helper fn create_public(public: &[u8]) -> PublicKey { match PublicKey::from_bytes(public) { - Ok(public) => public, + Ok(public) => return public, Err(_) => panic!("Provided public key is invalid.") } } @@ -52,7 +52,7 @@ fn create_public(public: &[u8]) -> PublicKey { /// SecretKey helper fn create_secret(secret: &[u8]) -> SecretKey { match SecretKey::from_bytes(secret) { - Ok(secret) => secret, + Ok(secret) => return secret, Err(_) => panic!("Provided private key is invalid.") } } From 84217ffdfda732d5fdef7e8ae34dd55d7efe2114 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 09:35:50 +0200 Subject: [PATCH 03/14] Mid-point step, use rev, verify signatures --- packages/wasm-crypto/Cargo.lock | 8 ++++---- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/src/sr25519.rs | 16 ++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index 83ad128c..d1ef8fa7 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -483,8 +483,8 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.8.1" +source = "git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8#b6c40cb5bfed03e85acd0794301205cfc5d928a8" dependencies = [ "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -625,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.8.1 (git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8)", "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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8bf8bb3d2b309218262456dd161b24456e977120f572e5ec5c6686dddad467e2" +"checksum schnorrkel 0.8.1 (git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8)" = "" "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" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index cb5a7d86..0481e7b2 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { version = "0.8.0", features = ["nightly"] } +schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev = "b6c40cb5bfed03e85acd0794301205cfc5d928a8", features = ["nightly", "preaudit_deprecated"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index d07a4746..3499104a 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -8,7 +8,7 @@ // forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f use schnorrkel::{ - Keypair, MiniSecretKey, PublicKey, SecretKey, Signature, + Keypair, MiniSecretKey, PublicKey, SecretKey, derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH}, }; use wasm_bindgen::prelude::*; @@ -138,13 +138,17 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec { /// * pubkey: UIntArray with 32 element #[wasm_bindgen] pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool { - let signature = match Signature::from_bytes(signature) { - Ok(signature) => signature, - Err(_) => return false - }; + // This is where we only verify 0.8.2 signatures, replacing the code below + // + // match Signature::from_bytes(signature) { + // Ok(signature) => create_public(public) + // .verify_simple(SIGNING_CTX, message, &signature) + // .is_ok(), + // Err(_) => false + // }; create_public(public) - .verify_simple(SIGNING_CTX, message, &signature) + .verify_simple_preaudit_deprecated(SIGNING_CTX, message, &signature) .is_ok() } From 0408186dddd22d2ee28fd71810143b617564d9e9 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 12:30:38 +0200 Subject: [PATCH 04/14] Update to 0.8.2 --- packages/wasm-crypto/Cargo.lock | 8 ++++---- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/src/sr25519.rs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index d1ef8fa7..5a123ac3 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -483,8 +483,8 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.8.1" -source = "git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8#b6c40cb5bfed03e85acd0794301205cfc5d928a8" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -625,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.8.1 (git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8)", + "schnorrkel 0.8.2 (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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.1 (git+https://github.com/w3f/schnorrkel?rev=b6c40cb5bfed03e85acd0794301205cfc5d928a8)" = "" +"checksum schnorrkel 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dbbd10b71915a60017e5bb3accdbe4664ca1c52f5ff37fa94ea44f26819d72e" "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" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index 0481e7b2..c2392248 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev = "b6c40cb5bfed03e85acd0794301205cfc5d928a8", features = ["nightly", "preaudit_deprecated"] } +schnorrkel = { version = "0.8.2", features = ["nightly", "preaudit_deprecated"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 3499104a..8ab16f5a 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -8,7 +8,7 @@ // forked at commit eff430ddc3090f56317c80654208b8298ef7ab3f use schnorrkel::{ - Keypair, MiniSecretKey, PublicKey, SecretKey, + ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, derive::{Derivation, ChainCode, CHAIN_CODE_LENGTH}, }; use wasm_bindgen::prelude::*; @@ -28,7 +28,7 @@ fn create_cc(data: &[u8]) -> ChainCode { /// Keypair helper function. fn create_from_seed(seed: &[u8]) -> Keypair { match MiniSecretKey::from_bytes(seed) { - Ok(mini) => return mini.expand_ed25519_to_keypair(), + Ok(mini) => return mini.expand_to_keypair(ExpansionMode::Ed25519), Err(_) => panic!("Provided seed is invalid.") } } @@ -67,7 +67,7 @@ fn create_secret(secret: &[u8]) -> SecretKey { pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { create_from_pair(pair).secret .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 - .expand_ed25519_to_keypair() + .expand_to_keypair(ExpansionMode::Ed25519) .to_bytes() .to_vec() } From 14adb637d1e32567bc63ab321cec111a16bfdb38 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 12:44:29 +0200 Subject: [PATCH 05/14] Flatten for easier inspection --- packages/wasm-crypto/src/sr25519.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 8ab16f5a..428e0847 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -65,11 +65,14 @@ fn create_secret(secret: &[u8]) -> SecretKey { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { - create_from_pair(pair).secret - .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 - .expand_to_keypair(ExpansionMode::Ed25519) - .to_bytes() - .to_vec() + match Keypair::from_bytes(pair) { + Ok(pair) => pair.secret + .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 + .expand_to_keypair(ExpansionMode::Ed25519) + .to_bytes() + .to_vec(), + Err(_) => panic!("Provided pair is invalid.") + } } /// Perform a derivation on a secret @@ -80,10 +83,13 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { - create_from_pair(pair) - .derived_key_simple(create_cc(cc), &[]).0 - .to_bytes() - .to_vec() + match Keypair::from_bytes(pair) { + Ok(pair) => pair + .derived_key_simple(create_cc(cc), &[]).0 + .to_bytes() + .to_vec(), + Err(_) => panic!("Provided pair is invalid.") + } } /// Perform a derivation on a publicKey From b4c0ee0fb73e88028b0cb35ab8064e65240064e1 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 13:48:43 +0200 Subject: [PATCH 06/14] 0.8.3 rev that passes the tests --- packages/wasm-crypto/Cargo.lock | 8 ++++---- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/src/sr25519.rs | 24 +++++++++--------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index 5a123ac3..59e41590 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -483,8 +483,8 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.8.3" +source = "git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6#8e352760b331d3830b1d4b660056ced59b21dee6" dependencies = [ "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -625,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6)", "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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dbbd10b71915a60017e5bb3accdbe4664ca1c52f5ff37fa94ea44f26819d72e" +"checksum schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6)" = "" "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" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index c2392248..eed7cf01 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { version = "0.8.2", features = ["nightly", "preaudit_deprecated"] } +schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev="8e352760b331d3830b1d4b660056ced59b21dee6", features = ["nightly", "preaudit_deprecated"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 428e0847..8ab16f5a 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -65,14 +65,11 @@ fn create_secret(secret: &[u8]) -> SecretKey { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { - match Keypair::from_bytes(pair) { - Ok(pair) => pair.secret - .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 - .expand_to_keypair(ExpansionMode::Ed25519) - .to_bytes() - .to_vec(), - Err(_) => panic!("Provided pair is invalid.") - } + create_from_pair(pair).secret + .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 + .expand_to_keypair(ExpansionMode::Ed25519) + .to_bytes() + .to_vec() } /// Perform a derivation on a secret @@ -83,13 +80,10 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { - match Keypair::from_bytes(pair) { - Ok(pair) => pair - .derived_key_simple(create_cc(cc), &[]).0 - .to_bytes() - .to_vec(), - Err(_) => panic!("Provided pair is invalid.") - } + create_from_pair(pair) + .derived_key_simple(create_cc(cc), &[]).0 + .to_bytes() + .to_vec() } /// Perform a derivation on a publicKey From 0d0cf0c5c45540c984005bd3545151277f2f4521 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 15:12:19 +0200 Subject: [PATCH 07/14] Updates for 0.8.3 memory allocation --- packages/wasm-crypto/src/sr25519.rs | 58 +++++++----------------- packages/wasm-crypto/test/all/sr25519.js | 45 ++++++++++++++---- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 8ab16f5a..77dd75fa 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -25,38 +25,6 @@ fn create_cc(data: &[u8]) -> ChainCode { ChainCode(cc) } -/// Keypair helper function. -fn create_from_seed(seed: &[u8]) -> Keypair { - match MiniSecretKey::from_bytes(seed) { - Ok(mini) => return mini.expand_to_keypair(ExpansionMode::Ed25519), - Err(_) => panic!("Provided seed is invalid.") - } -} - -/// Keypair helper function. -fn create_from_pair(pair: &[u8]) -> Keypair { - match Keypair::from_bytes(pair) { - Ok(pair) => return pair, - Err(_) => panic!("Provided pair is invalid.") - } -} - -/// PublicKey helper -fn create_public(public: &[u8]) -> PublicKey { - match PublicKey::from_bytes(public) { - Ok(public) => return public, - Err(_) => panic!("Provided public key is invalid.") - } -} - -/// SecretKey helper -fn create_secret(secret: &[u8]) -> SecretKey { - match SecretKey::from_bytes(secret) { - Ok(secret) => return secret, - Err(_) => panic!("Provided private key is invalid.") - } -} - /// Perform a derivation on a secret /// /// * secret: UIntArray with 64 bytes @@ -65,7 +33,9 @@ fn create_secret(secret: &[u8]) -> SecretKey { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { - create_from_pair(pair).secret + Keypair::from_bytes(pair) + .unwrap() + .secret .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 .expand_to_keypair(ExpansionMode::Ed25519) .to_bytes() @@ -80,7 +50,8 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { - create_from_pair(pair) + Keypair::from_bytes(pair) + .unwrap() .derived_key_simple(create_cc(cc), &[]).0 .to_bytes() .to_vec() @@ -94,7 +65,8 @@ pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { /// returned vector is the derived publicKey as a array of 32 bytes #[wasm_bindgen] pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec { - create_public(public) + PublicKey::from_bytes(public) + .unwrap() .derived_key_simple(create_cc(cc), &[]).0 .to_bytes() .to_vec() @@ -108,7 +80,9 @@ pub fn ext_sr_derive_public_soft(public: &[u8], cc: &[u8]) -> Vec { /// followed by the public key (32) bytes. #[wasm_bindgen] pub fn ext_sr_from_seed(seed: &[u8]) -> Vec { - create_from_seed(seed) + MiniSecretKey::from_bytes(seed) + .unwrap() + .expand_to_keypair(ExpansionMode::Ed25519) .to_bytes() .to_vec() } @@ -125,8 +99,9 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec { /// * returned vector is the signature consisting of 64 bytes. #[wasm_bindgen] pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec { - create_secret(secret) - .sign_simple(SIGNING_CTX, message, &create_public(public)) + SecretKey::from_bytes(secret) + .unwrap() + .sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(public).unwrap()) .to_bytes() .to_vec() } @@ -138,16 +113,17 @@ pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec { /// * pubkey: UIntArray with 32 element #[wasm_bindgen] pub fn ext_sr_verify(signature: &[u8], message: &[u8], public: &[u8]) -> bool { - // This is where we only verify 0.8.2 signatures, replacing the code below + // This is where we only verify 0.8.0+ signatures, replacing the code below // // match Signature::from_bytes(signature) { - // Ok(signature) => create_public(public) + // Ok(signature) => PublicKey::from_bytes(public).unwrap() // .verify_simple(SIGNING_CTX, message, &signature) // .is_ok(), // Err(_) => false // }; - create_public(public) + PublicKey::from_bytes(public) + .unwrap() .verify_simple_preaudit_deprecated(SIGNING_CTX, message, &signature) .is_ok() } diff --git a/packages/wasm-crypto/test/all/sr25519.js b/packages/wasm-crypto/test/all/sr25519.js index c099a777..977b355f 100644 --- a/packages/wasm-crypto/test/all/sr25519.js +++ b/packages/wasm-crypto/test/all/sr25519.js @@ -18,27 +18,39 @@ module.exports = function (wasm) { } function sr25519_pairFromSeed () { + const expected = [ + '1ec20c6cb85bf4c7423b95752b70c312e6ae9e5701ffb310f0a9019d9c041e0af98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1', + '741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63' + ]; const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')); console.log('\tSEC', u8aToHex(pair.slice(0, 64))); console.log('\tPUB', u8aToHex(pair.slice(64))); - assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match'); + assert(u8aToHex(pair) === `0x${expected.join('')}`, 'ERROR: pairFromSeed() does not match'); } function sr25519_devFromSeed () { - const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e')); + const expected = [ + '05d65584630d16cd4af6d0bec10f34bb504a5dcb62dba2122d49f5a663763d0afd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca34', + '46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' + ]; + const pair = wasm.sr25519KeypairFromSeed( + hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e') + ); console.log('\tSEC', u8aToHex(pair.slice(0, 64))); console.log('\tPUB', u8aToHex(pair.slice(64))); - assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match'); + assert(u8aToHex(pair) === `0x${expected.join('')}`, 'ERROR: devFromSeed() does not match'); } function sr25519_verifyExisting () { const PK = hexToU8a('0xb4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918'); const MESSAGE = stringToU8a('Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n'); - const SIGNATURE = hexToU8a('0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202'); + const SIGNATURE = hexToU8a( + '0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202' + ); const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK); @@ -60,14 +72,21 @@ module.exports = function (wasm) { function sr25519_deriveHard () { const [pair] = randomPair(); - const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); + const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a( + '0x0c666f6f00000000000000000000000000000000000000000000000000000000' + )); console.log('\tSEC', u8aToHex(derived.slice(0, 64))); console.log('\tPUB', u8aToHex(derived.slice(64))); } function sr25519_deriveHardKnown () { - const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000')); + const derived = wasm.sr25519DeriveKeypairHard( + hexToU8a( + '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' + ), + hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000') + ); const publicKey = u8aToHex(derived.slice(64)); console.log('\tSEC', u8aToHex(derived.slice(0, 64))); @@ -85,7 +104,12 @@ module.exports = function (wasm) { } function sr25519_deriveSoftKnown () { - const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); + const derived = wasm.sr25519DeriveKeypairSoft( + hexToU8a( + '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' + ), + hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000') + ); const publicKey = u8aToHex(derived.slice(64)); console.log('\tSEC', u8aToHex(derived.slice(0, 64))); @@ -95,7 +119,12 @@ module.exports = function (wasm) { } function sr25519_deriveSoftPubkey () { - const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'))); + const derived = u8aToHex( + wasm.sr25519DerivePublicSoft( + hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), + hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000') + ) + ); console.log('\tPUB', derived); From a8c3f308866481ffc4b473b28af931fba95e2e7e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 18:06:42 +0200 Subject: [PATCH 08/14] Test for Rust keypair imports --- packages/wasm-crypto/src/sr25519.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 77dd75fa..57f192a1 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -87,6 +87,19 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec { .to_vec() } +/// Generate a key pair from a known pair. (This is not exposed via WASM) +/// +/// * seed: UIntArray with 96 element +/// +/// returned vector is the concatenation of first the private key (64 bytes) +/// followed by the public key (32) bytes. +pub fn ext_sr_from_pair(pair: &[u8]) -> Vec { + Keypair::from_bytes(pair) + .unwrap() + .to_bytes() + .to_vec() +} + /// Sign a message /// /// The combination of both public and private key must be provided. @@ -150,7 +163,7 @@ pub mod tests { } #[test] - fn creates_pair_from_known() { + fn creates_pair_from_known_seed() { let seed = hex!("fac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e"); let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a"); let keypair = ext_sr_from_seed(&seed); @@ -159,6 +172,16 @@ pub mod tests { assert_eq!(public, expected); } + #[test] + fn create_pair_from_known_pair() { + let input = hex!("28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a"); + let keypair = ext_sr_from_pair(&input); + let expected = hex!("46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a"); + let public = &keypair[SECRET_KEY_LENGTH..KEYPAIR_LENGTH]; + + assert_eq!(public, expected); + } + #[test] fn can_sign_message() { let seed = generate_random_seed(); From 896f452f7d6e62cec0cd325c9b3a32dca7e2c001 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 1 Aug 2019 21:59:27 +0200 Subject: [PATCH 09/14] Rust ed25519 compat --- packages/wasm-crypto/Cargo.lock | 6 +- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/src/sr25519.rs | 16 +- packages/wasm-crypto/test/all/sr25519.js | 197 ++++++++++------------- 4 files changed, 95 insertions(+), 126 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index 59e41590..c6fd6c87 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -484,7 +484,7 @@ dependencies = [ [[package]] name = "schnorrkel" version = "0.8.3" -source = "git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6#8e352760b331d3830b1d4b660056ced59b21dee6" +source = "git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5#0645b98ff5e8b49a3dccc1146407897afddbffa5" dependencies = [ "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -625,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6)", + "schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5)", "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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=8e352760b331d3830b1d4b660056ced59b21dee6)" = "" +"checksum schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5)" = "" "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" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index eed7cf01..1e7fc98b 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev="8e352760b331d3830b1d4b660056ced59b21dee6", features = ["nightly", "preaudit_deprecated"] } +schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev="0645b98ff5e8b49a3dccc1146407897afddbffa5", features = ["nightly", "preaudit_deprecated"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 57f192a1..aabb653b 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -33,12 +33,12 @@ fn create_cc(data: &[u8]) -> ChainCode { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { - Keypair::from_bytes(pair) + Keypair::from_half_ed25519_bytes(pair) .unwrap() .secret .hard_derive_mini_secret_key(Some(create_cc(cc)), &[]).0 .expand_to_keypair(ExpansionMode::Ed25519) - .to_bytes() + .to_half_ed25519_bytes() .to_vec() } @@ -50,10 +50,10 @@ pub fn ext_sr_derive_keypair_hard(pair: &[u8], cc: &[u8]) -> Vec { /// returned vector the derived keypair as a array of 96 bytes #[wasm_bindgen] pub fn ext_sr_derive_keypair_soft(pair: &[u8], cc: &[u8]) -> Vec { - Keypair::from_bytes(pair) + Keypair::from_half_ed25519_bytes(pair) .unwrap() .derived_key_simple(create_cc(cc), &[]).0 - .to_bytes() + .to_half_ed25519_bytes() .to_vec() } @@ -83,7 +83,7 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec { MiniSecretKey::from_bytes(seed) .unwrap() .expand_to_keypair(ExpansionMode::Ed25519) - .to_bytes() + .to_half_ed25519_bytes() .to_vec() } @@ -94,9 +94,9 @@ pub fn ext_sr_from_seed(seed: &[u8]) -> Vec { /// returned vector is the concatenation of first the private key (64 bytes) /// followed by the public key (32) bytes. pub fn ext_sr_from_pair(pair: &[u8]) -> Vec { - Keypair::from_bytes(pair) + Keypair::from_half_ed25519_bytes(pair) .unwrap() - .to_bytes() + .to_half_ed25519_bytes() .to_vec() } @@ -112,7 +112,7 @@ pub fn ext_sr_from_pair(pair: &[u8]) -> Vec { /// * returned vector is the signature consisting of 64 bytes. #[wasm_bindgen] pub fn ext_sr_sign(public: &[u8], secret: &[u8], message: &[u8]) -> Vec { - SecretKey::from_bytes(secret) + SecretKey::from_ed25519_bytes(secret) .unwrap() .sign_simple(SIGNING_CTX, message, &PublicKey::from_bytes(public).unwrap()) .to_bytes() diff --git a/packages/wasm-crypto/test/all/sr25519.js b/packages/wasm-crypto/test/all/sr25519.js index 977b355f..f1bca0ec 100644 --- a/packages/wasm-crypto/test/all/sr25519.js +++ b/packages/wasm-crypto/test/all/sr25519.js @@ -8,149 +8,118 @@ const crypto = require('crypto'); const { assert, hexToU8a, stringToU8a, u8aToHex } = require('@polkadot/util'); -module.exports = function (wasm) { - function extractKeys (pair) { - return [pair, pair.slice(64), pair.slice(0, 64)]; - } +function extractKeys (pair) { + return [pair, pair.slice(64), pair.slice(0, 64)]; +} - function randomPair () { - return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32))); - } +function randomPair (wasm) { + return extractKeys(wasm.sr25519KeypairFromSeed(crypto.randomBytes(32))); +} - function sr25519_pairFromSeed () { - const expected = [ - '1ec20c6cb85bf4c7423b95752b70c312e6ae9e5701ffb310f0a9019d9c041e0af98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1', - '741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63' - ]; - const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')); +function sr25519_pairFromSeed (wasm) { + const pair = wasm.sr25519KeypairFromSeed(stringToU8a('12345678901234567890123456789012')); - console.log('\tSEC', u8aToHex(pair.slice(0, 64))); - console.log('\tPUB', u8aToHex(pair.slice(64))); + console.log('\tSEC', u8aToHex(pair.slice(0, 64))); + console.log('\tPUB', u8aToHex(pair.slice(64))); - assert(u8aToHex(pair) === `0x${expected.join('')}`, 'ERROR: pairFromSeed() does not match'); - } + assert(u8aToHex(pair) === '0xf0106660c3dda23f16daa9ac5b811b963077f5bc0af89f85804f0de8e424f050f98d66f39442506ff947fd911f18c7a7a5da639a63e8d3b4e233f74143d951c1741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63', 'ERROR: pairFromSeed() does not match'); +} - function sr25519_devFromSeed () { - const expected = [ - '05d65584630d16cd4af6d0bec10f34bb504a5dcb62dba2122d49f5a663763d0afd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca34', - '46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ]; - const pair = wasm.sr25519KeypairFromSeed( - hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e') - ); +function sr25519_devFromSeed (wasm) { + const pair = wasm.sr25519KeypairFromSeed(hexToU8a('0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e')); - console.log('\tSEC', u8aToHex(pair.slice(0, 64))); - console.log('\tPUB', u8aToHex(pair.slice(64))); + console.log('\tSEC', u8aToHex(pair.slice(0, 64))); + console.log('\tPUB', u8aToHex(pair.slice(64))); - assert(u8aToHex(pair) === `0x${expected.join('')}`, 'ERROR: devFromSeed() does not match'); - } + assert(u8aToHex(pair) === '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a', 'ERROR: devFromSeed() does not match'); +} - function sr25519_verifyExisting () { - const PK = hexToU8a('0xb4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918'); - const MESSAGE = stringToU8a('Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n'); - const SIGNATURE = hexToU8a( - '0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202' - ); +function sr25519_verifyExisting (wasm) { + const PK = hexToU8a('0xb4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918'); + const MESSAGE = stringToU8a('Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n'); + const SIGNATURE = hexToU8a('0x5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202'); - const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK); + const isValid = wasm.sr25519Verify(SIGNATURE, MESSAGE, PK); - console.log('\tRES', isValid); + console.log('\tRES', isValid); - assert(isValid, 'ERROR: Unable to verify signature'); - } + assert(isValid, 'ERROR: Unable to verify signature'); +} - function sr25519_signAndVerify () { - const [, pk, sk] = randomPair(); - const signature = wasm.sr25519Sign(pk, sk, stringToU8a('this is a message')); - const isValid = wasm.sr25519Verify(signature, stringToU8a('this is a message'), pk); +function sr25519_signAndVerify (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); - console.log('\tSIG', u8aToHex(signature)); - console.log('\tRES', isValid); + console.log('\tSIG', u8aToHex(signature)); + console.log('\tRES', isValid); - assert(isValid, 'ERROR: Unable to verify signature'); - } + assert(isValid, 'ERROR: Unable to verify signature'); +} - function sr25519_deriveHard () { - const [pair] = randomPair(); - const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a( - '0x0c666f6f00000000000000000000000000000000000000000000000000000000' - )); +function sr25519_deriveHard (wasm) { + const [pair] = randomPair(wasm); + const derived = wasm.sr25519DeriveKeypairHard(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); - console.log('\tSEC', u8aToHex(derived.slice(0, 64))); - console.log('\tPUB', u8aToHex(derived.slice(64))); - } + console.log('\tSEC', u8aToHex(derived.slice(0, 64))); + console.log('\tPUB', u8aToHex(derived.slice(64))); +} - function sr25519_deriveHardKnown () { - const derived = wasm.sr25519DeriveKeypairHard( - hexToU8a( - '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ), - hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000') - ); - const publicKey = u8aToHex(derived.slice(64)); +function sr25519_deriveHardKnown (wasm) { + const derived = wasm.sr25519DeriveKeypairHard(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x14416c6963650000000000000000000000000000000000000000000000000000')); + const publicKey = u8aToHex(derived.slice(64)); - console.log('\tSEC', u8aToHex(derived.slice(0, 64))); - console.log('\tPUB', publicKey); + console.log('\tSEC', u8aToHex(derived.slice(0, 64))); + console.log('\tPUB', publicKey); - assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys'); - } + assert(publicKey === '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', 'Unmatched resulting public keys'); +} - function sr25519_deriveSoft () { - const [pair] = randomPair(); - const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); +function sr25519_deriveSoft (wasm) { + const [pair] = randomPair(wasm); + const derived = wasm.sr25519DeriveKeypairSoft(pair, hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); - console.log('\tSEC', u8aToHex(derived.slice(0, 64))); - console.log('\tPUB', u8aToHex(derived.slice(64))); - } + console.log('\tSEC', u8aToHex(derived.slice(0, 64))); + console.log('\tPUB', u8aToHex(derived.slice(64))); +} - function sr25519_deriveSoftKnown () { - const derived = wasm.sr25519DeriveKeypairSoft( - hexToU8a( - '0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a' - ), - hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000') - ); - const publicKey = u8aToHex(derived.slice(64)); +function sr25519_deriveSoftKnown (wasm) { + const derived = wasm.sr25519DeriveKeypairSoft(hexToU8a('0x28b0ae221c6bb06856b287f60d7ea0d98552ea5a16db16956849aa371db3eb51fd190cce74df356432b410bd64682309d6dedb27c76845daf388557cbac3ca3446ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000')); + const publicKey = u8aToHex(derived.slice(64)); - console.log('\tSEC', u8aToHex(derived.slice(0, 64))); - console.log('\tPUB', publicKey); + console.log('\tSEC', u8aToHex(derived.slice(0, 64))); + console.log('\tPUB', publicKey); - assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys'); - } + assert(publicKey === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys'); +} - function sr25519_deriveSoftPubkey () { - const derived = u8aToHex( - wasm.sr25519DerivePublicSoft( - hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), - hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000') - ) - ); +function sr25519_deriveSoftPubkey (wasm) { + const derived = u8aToHex(wasm.sr25519DerivePublicSoft(hexToU8a('0x46ebddef8cd9bb167dc30878d7113b7e168e6f0646beffd77d69d39bad76b47a'), hexToU8a('0x0c666f6f00000000000000000000000000000000000000000000000000000000'))); - console.log('\tPUB', derived); + console.log('\tPUB', derived); - assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys'); - } + assert(derived === '0x40b9675df90efa6069ff623b0fdfcf706cd47ca7452a5056c7ad58194d23440a', 'Unmatched resulting public keys'); +} - function sr25519_benchmark () { - const MESSAGE = stringToU8a('this is a message'); +function sr25519_benchmark (wasm) { + const MESSAGE = stringToU8a('this is a message'); - for (let i = 0; i < 256; i++) { - const [, pk, sk] = randomPair(); + for (let i = 0; i < 256; i++) { + const [, pk, sk] = randomPair(wasm); - assert(wasm.sr25519Verify(wasm.sr25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature'); - } + assert(wasm.sr25519Verify(wasm.sr25519Sign(pk, sk, MESSAGE), MESSAGE, pk), 'ERROR: Unable to verify signature'); } - - return { - sr25519_pairFromSeed, - sr25519_devFromSeed, - sr25519_deriveHard, - sr25519_deriveHardKnown, - sr25519_deriveSoft, - sr25519_deriveSoftKnown, - sr25519_deriveSoftPubkey, - sr25519_signAndVerify, - sr25519_verifyExisting, - sr25519_benchmark - }; +} + +module.exports = { + sr25519_pairFromSeed, + sr25519_devFromSeed, + sr25519_deriveHard, + sr25519_deriveHardKnown, + sr25519_deriveSoft, + sr25519_deriveSoftKnown, + sr25519_deriveSoftPubkey, + sr25519_signAndVerify, + sr25519_verifyExisting, + sr25519_benchmark }; From 4a2249a220b4c3e2744c29cee9979c470b11ce42 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 2 Aug 2019 16:41:43 +0200 Subject: [PATCH 10/14] 0.8.4 --- packages/wasm-crypto/Cargo.lock | 8 ++++---- packages/wasm-crypto/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index c6fd6c87..c98178fe 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -483,8 +483,8 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.8.3" -source = "git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5#0645b98ff5e8b49a3dccc1146407897afddbffa5" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -625,7 +625,7 @@ dependencies = [ "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)", - "schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5)", + "schnorrkel 0.8.4 (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)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.3 (git+https://github.com/w3f/schnorrkel?rev=0645b98ff5e8b49a3dccc1146407897afddbffa5)" = "" +"checksum schnorrkel 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "77e8d6a92f49a53f21b71c090a5559bf45c469071ebe556aebaf2dca3abc5cb5" "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" diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index 1e7fc98b..26d18cfc 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -21,7 +21,7 @@ ed25519-dalek = { version = "1.0.0-pre.1", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { git = "https://github.com/w3f/schnorrkel", rev="0645b98ff5e8b49a3dccc1146407897afddbffa5", features = ["nightly", "preaudit_deprecated"] } +schnorrkel = { version = "0.8.4", features = ["nightly", "preaudit_deprecated"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.1", default-features = false } tiny-keccak = "1.4.2" From 0b19ca9fd26ad5f854d940fccfd59904af032019 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 13 Jan 2020 11:54:44 +0100 Subject: [PATCH 11/14] sr25519 0.8.5, bump deps --- CHANGELOG.md | 4 +++ lerna.json | 2 +- package.json | 2 +- packages/wasm-crypto/Cargo.toml | 10 +++--- packages/wasm-crypto/package.json | 2 +- yarn.lock | 60 ++++++++----------------------- 6 files changed, 27 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7b607c..d73db540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.20.1 + +- Pull in schnorrkel 0.8.5 for full Substrate 2.x compatibility + # 0.14.1 - No functionality changes at all, everything done is "under the hood" to give the codebase better maintainability diff --git a/lerna.json b/lerna.json index e53a7807..3bbf41f0 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "0.15.0-beta.184" + "version": "0.20.0-beta.0" } diff --git a/package.json b/package.json index 39209a20..b4424cf2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "devDependencies": { "@babel/core": "^7.7.7", "@polkadot/dev": "^0.32.14", - "@polkadot/util": "^1.7.1", + "@polkadot/util": "^1.8.1", "override-require": "^1.1.1" } } diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index 405f4826..2a852dfb 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -18,15 +18,15 @@ crate-type = ["cdylib", "rlib"] backtrace = "0.3.38" blake2-rfc = "0.2.18" byteorder = "1.3.1" -ed25519-dalek = { version = "1.0.0-pre.2", features = ["nightly"] } +ed25519-dalek = { version = "1.0.0-pre.3", features = ["nightly"] } hmac = "0.7.0" # libsecp256k1 = "0.2.2" pbkdf2 = { version = "0.3.0", default-features = false } -schnorrkel = { version = "0.8.4", features = ["nightly", "preaudit_deprecated"] } +schnorrkel = { version = "0.8.5", features = ["nightly", "preaudit_deprecated", "u64_backend"] } sha2 = "0.8.0" -tiny-bip39 = { version = "0.6.1", default-features = false } -tiny-keccak = "1.4.2" -twox-hash = "1.1.2" +tiny-bip39 = { version = "0.6.2", default-features = false } +tiny-keccak = "2.0.1" +twox-hash = "1.5.0" wasm-bindgen = "0.2" wee_alloc = "0.4.3" diff --git a/packages/wasm-crypto/package.json b/packages/wasm-crypto/package.json index b7ee1f51..2a52948f 100644 --- a/packages/wasm-crypto/package.json +++ b/packages/wasm-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/wasm-crypto", - "version": "0.15.0-beta.184", + "version": "0.20.0-beta.0", "author": "Jaco Greeff ", "files": [ "crypto-polyfill.js", diff --git a/yarn.lock b/yarn.lock index 4cec20b4..19ca5781 100644 --- a/yarn.lock +++ b/yarn.lock @@ -823,7 +823,7 @@ core-js "^2.6.5" regenerator-runtime "^0.13.2" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.7.4", "@babel/runtime@^7.7.7": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.7.7": version "7.7.7" resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.7.7.tgz#194769ca8d6d7790ec23605af9ee3e42a0aa79cf" integrity sha512-uCnC2JEVAu8AKB5do1WRIsvrdJ0flYx/A/9f/6chdacnEZ7LmavjdsDXr5ksYBegxtuTPR5Va9/+13QF/kFkCA== @@ -1902,13 +1902,13 @@ typescript "^3.7.4" vuepress "^1.2.0" -"@polkadot/util@^1.7.1": - version "1.7.1" - resolved "https://registry.npmjs.org/@polkadot/util/-/util-1.7.1.tgz#cb262fa5a441097c0c093532f70d0b7e0503fbb1" - integrity sha512-tWvh+vYDIiXDIWgAGd9zyJWlDKxQ5KYTKZ9uTlLxfuy1qXEdVOjlX9Qz5+FACU2742e8tTvtvM9KfK05VK5X/A== +"@polkadot/util@^1.8.1": + version "1.8.1" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-1.8.1.tgz#7473383a1eb26bec59cca53643cf07bc078fe052" + integrity sha512-sFpr+JLCG9d+epjboXsmJ1qcKa96r8ZYzXmVo8+aPzI/9jKKyez6Unox/dnfnpKppZB2nJuLcsxQm6nocp2Caw== dependencies: - "@babel/runtime" "^7.7.4" - "@types/bn.js" "^4.11.5" + "@babel/runtime" "^7.7.7" + "@types/bn.js" "^4.11.6" bn.js "^4.11.8" camelcase "^5.3.1" chalk "^3.0.0" @@ -1948,9 +1948,9 @@ dependencies: "@babel/types" "^7.3.0" -"@types/bn.js@^4.11.5": +"@types/bn.js@^4.11.6": version "4.11.6" - resolved "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg== dependencies: "@types/node" "*" @@ -4371,7 +4371,7 @@ debug@3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6: +debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5: version "3.2.6" resolved "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== @@ -4557,11 +4557,6 @@ detect-indent@^5.0.0: resolved "https://registry.npmjs.org/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50= -detect-libc@^1.0.2: - version "1.0.3" - resolved "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" - integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= - detect-newline@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2" @@ -6409,7 +6404,7 @@ humanize-url@^1.0.0: normalize-url "^1.0.0" strip-url-auth "^1.0.0" -iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13: +iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@~0.4.13: version "0.4.24" resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== @@ -8531,15 +8526,6 @@ natural-compare@^1.4.0: resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= -needle@^2.2.1: - version "2.4.0" - resolved "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c" - integrity sha512-4Hnwzr3mi5L97hMYeNl8wRW/Onhy4nUKR/lVemJ8gJedxxUyBLm9kkrDColJvoSfwi0jCNhD+xCdOtiGDQiRZg== - dependencies: - debug "^3.2.6" - iconv-lite "^0.4.4" - sax "^1.2.4" - negotiator@0.6.2: version "0.6.2" resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" @@ -8648,22 +8634,6 @@ node-notifier@^5.4.2: shellwords "^0.1.1" which "^1.3.0" -node-pre-gyp@*: - version "0.14.0" - resolved "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83" - integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA== - dependencies: - detect-libc "^1.0.2" - mkdirp "^0.5.1" - needle "^2.2.1" - nopt "^4.0.1" - npm-packlist "^1.1.6" - npmlog "^4.0.2" - rc "^1.2.7" - rimraf "^2.6.1" - semver "^5.3.0" - tar "^4.4.2" - node-releases@^1.1.44: version "1.1.44" resolved "https://registry.npmjs.org/node-releases/-/node-releases-1.1.44.tgz#cd66438a6eb875e3eb012b6a12e48d9f4326ffd7" @@ -8780,7 +8750,7 @@ npm-normalize-package-bin@^1.0.0, npm-normalize-package-bin@^1.0.1: semver "^5.6.0" validate-npm-package-name "^3.0.0" -npm-packlist@^1.1.6, npm-packlist@^1.4.4: +npm-packlist@^1.4.4: version "1.4.7" resolved "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.7.tgz#9e954365a06b80b18111ea900945af4f88ed4848" integrity sha512-vAj7dIkp5NhieaGZxBJB8fF4R0078rqsmhJcAfXZ6O7JJhjhPK96n5Ry1oZcfLXgfun0GWTZPOxaEyqv8GBykQ== @@ -8804,7 +8774,7 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" -npmlog@^4.0.2, npmlog@^4.1.2: +npmlog@^4.1.2: version "4.1.2" resolved "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" integrity sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg== @@ -10613,7 +10583,7 @@ rimraf@2.6.3: dependencies: glob "^7.1.3" -rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3: +rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3: version "2.7.1" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== @@ -11523,7 +11493,7 @@ tapable@^1.0.0, tapable@^1.1.3: resolved "https://registry.npmjs.org/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2" integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== -tar@^4.4.10, tar@^4.4.12, tar@^4.4.2, tar@^4.4.8: +tar@^4.4.10, tar@^4.4.12, tar@^4.4.8: version "4.4.13" resolved "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA== From 24926232b475faa7a2489dce6ab636b786996de8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 13 Jan 2020 11:58:04 +0100 Subject: [PATCH 12/14] tiny-keccak config --- packages/wasm-crypto/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wasm-crypto/Cargo.toml b/packages/wasm-crypto/Cargo.toml index 2a852dfb..05d41f79 100644 --- a/packages/wasm-crypto/Cargo.toml +++ b/packages/wasm-crypto/Cargo.toml @@ -25,7 +25,7 @@ pbkdf2 = { version = "0.3.0", default-features = false } schnorrkel = { version = "0.8.5", features = ["nightly", "preaudit_deprecated", "u64_backend"] } sha2 = "0.8.0" tiny-bip39 = { version = "0.6.2", default-features = false } -tiny-keccak = "2.0.1" +tiny-keccak = { version = "2.0.1", features = ["keccak"] } twox-hash = "1.5.0" wasm-bindgen = "0.2" wee_alloc = "0.4.3" From 23411e9941e8a090447ce517e7fdbf55b90bac44 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 13 Jan 2020 12:32:22 +0100 Subject: [PATCH 13/14] Update keccack hashing --- packages/wasm-crypto/src/hashing.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/wasm-crypto/src/hashing.rs b/packages/wasm-crypto/src/hashing.rs index 187016a7..55b5d64f 100644 --- a/packages/wasm-crypto/src/hashing.rs +++ b/packages/wasm-crypto/src/hashing.rs @@ -9,7 +9,7 @@ use pbkdf2::pbkdf2; use sha2::{Digest, Sha512}; // use secp256k1; use std::hash::Hasher; -use tiny_keccak::keccak256; +use tiny_keccak::Keccak; use twox_hash::XxHash; use wasm_bindgen::prelude::*; @@ -49,8 +49,13 @@ pub fn ext_blake2b(data: &[u8], key: &[u8], size: u32) -> Vec { /// Returns the hash as a vector #[wasm_bindgen] pub fn ext_keccak256(data: &[u8]) -> Vec { - keccak256(data) - .to_vec() + let mut keccak = Keccak::v256(); + let mut result = [0u8; 32]; + + keccak.update(data); + keccak.finalize(&mut result); + + result.to_vec() } /// pbkdf2 hash from an input, salt for the number of specified rounds From 9f36e86f775794f3a7040d3e1a344a395c6e122e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 13 Jan 2020 12:53:22 +0100 Subject: [PATCH 14/14] Update hashing --- packages/wasm-crypto/Cargo.lock | 186 +++++++++++++++++++++------- packages/wasm-crypto/src/hashing.rs | 4 +- 2 files changed, 141 insertions(+), 49 deletions(-) diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index 97633816..70aa9b7f 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -20,7 +20,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -30,7 +30,7 @@ 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)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -81,6 +81,14 @@ name = "byteorder" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "c2-chacha" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cc" version = "1.0.31" @@ -114,7 +122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.1.6" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -128,14 +136,26 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "1.1.3" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "curve25519-dalek" +version = "2.0.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)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -148,14 +168,12 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "1.0.0-pre.2" +version = "1.0.0-pre.3" 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)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -197,6 +215,16 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "getrandom" +version = "0.1.14" +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.66 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hashbrown" version = "0.1.8" @@ -244,7 +272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.50" +version = "0.2.66" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -276,7 +304,7 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -319,7 +347,7 @@ 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)", + "libc 0.2.66 (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)", @@ -335,6 +363,11 @@ dependencies = [ "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ppv-lite86" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "proc-macro-hack" version = "0.5.8" @@ -367,10 +400,10 @@ 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)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "packed_simd 0.3.3 (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_core 0.4.2 (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)", @@ -380,6 +413,19 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "packed_simd 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_chacha" version = "0.1.1" @@ -389,18 +435,35 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_chacha" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.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)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" -version = "0.4.0" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_core" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "rand_hc" @@ -410,6 +473,14 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_isaac" version = "0.1.1" @@ -423,8 +494,8 @@ 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)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -435,8 +506,8 @@ 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)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (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)", @@ -448,7 +519,7 @@ 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)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -482,16 +553,17 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "merlin 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -536,7 +608,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.1.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -562,7 +634,7 @@ dependencies = [ [[package]] name = "tiny-bip39" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -576,15 +648,15 @@ dependencies = [ [[package]] name = "tiny-keccak" -version = "1.4.2" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "twox-hash" -version = "1.1.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -613,6 +685,11 @@ name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wasm" version = "0.0.0" @@ -620,16 +697,16 @@ dependencies = [ "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", "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)", - "ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ed25519-dalek 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (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)", - "schnorrkel 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.8.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)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.5.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)", ] @@ -688,7 +765,7 @@ 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)", + "libc 0.2.66 (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)", @@ -718,6 +795,11 @@ name = "zeroize" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "1.1.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" @@ -730,28 +812,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" "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 clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "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 crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" -"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" +"checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" +"checksum curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "845aaacc16f01178f33349e7c992ecd0cee095aa5e577f0f4dee35971bd36455" +"checksum ed25519-dalek 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)" = "978710b352437433c97b2bff193f2fb1dfd58a093f863dd95e225a19baa599a2" "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 getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c3da68162fdd2147e66682e78e729bd77f93b4c99656db058c5782d8c6b6225a" "checksum hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06095d08c7c05760f11a071b3e1d4c5b723761c01bd8d7201c30a9536668a612" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "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 libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "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" @@ -763,14 +848,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum proc-macro-hack 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "982a35d1194084ba319d65c4a68d24ca28f5fdb5b8bc20899e4eef8641ea5178" "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 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "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_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" "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" @@ -779,23 +869,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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 schnorrkel 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "77e8d6a92f49a53f21b71c090a5559bf45c469071ebe556aebaf2dca3abc5cb5" +"checksum schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eacd8381b3c37840c9c9f40472af529e49975bdcbc24f83c31059fd6539023d3" "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 subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" +"checksum subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941" "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 tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" -"checksum twox-hash 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "555cd4909480122bbbf21e34faac4cb08a171f324775670447ed116726c474af" +"checksum tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" +"checksum tiny-keccak 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2953ca5148619bc99695c1274cb54c5275bbb913c6adad87e72eaf8db9787f69" +"checksum twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" "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 wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" "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" @@ -806,3 +897,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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" "checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" +"checksum zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" diff --git a/packages/wasm-crypto/src/hashing.rs b/packages/wasm-crypto/src/hashing.rs index 55b5d64f..25a05c55 100644 --- a/packages/wasm-crypto/src/hashing.rs +++ b/packages/wasm-crypto/src/hashing.rs @@ -8,13 +8,13 @@ use hmac::Hmac; use pbkdf2::pbkdf2; use sha2::{Digest, Sha512}; // use secp256k1; -use std::hash::Hasher; -use tiny_keccak::Keccak; +use tiny_keccak::{Hasher, Keccak}; use twox_hash::XxHash; use wasm_bindgen::prelude::*; /// helper function for a single twox round with a seed fn create_twox(data: &[u8], seed: u64) -> [u8; 8] { + use ::std::hash::Hasher; let mut hasher = XxHash::with_seed(seed); hasher.write(data);