From f39b68f83dc5d770f51b877c32cddeaa4308a475 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 9 May 2019 15:18:44 +0200 Subject: [PATCH] Add known signature tests (from subkey, actual values) (#20) * Add know signing test (from subkey) * Align sr25519 known sigs * 0.10 (schnorrkel got a bump) --- CHANGELOG.md | 5 +++++ lerna.json | 2 +- package.json | 4 ++-- packages/wasm-crypto/Cargo.lock | 6 +++--- packages/wasm-crypto/Cargo.toml | 2 +- packages/wasm-crypto/package.json | 2 +- packages/wasm-crypto/src/sr25519.rs | 10 ++++++++++ packages/wasm-crypto/test/all/sr25519.js | 7 +++---- scripts/test-package.sh | 2 +- yarn.lock | 16 ++++++++-------- 10 files changed, 35 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a14f5b..f67e310f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.10.1 + +- w3f/schnorrkel updated to 0.1.1 as per substrate +- Added known subkey signature test (Rust & JS) + # 0.9.1 - Dependency bumps diff --git a/lerna.json b/lerna.json index a29ddc4a..223c4eb3 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "0.9.1" + "version": "0.10.0" } diff --git a/package.json b/package.json index b16392c2..685f5ba5 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "devDependencies": { "@babel/core": "^7.4.4", - "@polkadot/dev": "^0.30.0-beta.3", - "@polkadot/util": "^0.90.0-beta.1" + "@polkadot/dev": "^0.30.0-beta.4", + "@polkadot/util": "^0.90.1" } } diff --git a/packages/wasm-crypto/Cargo.lock b/packages/wasm-crypto/Cargo.lock index 2913ed70..6149a645 100644 --- a/packages/wasm-crypto/Cargo.lock +++ b/packages/wasm-crypto/Cargo.lock @@ -486,7 +486,7 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.1.0" +version = "0.1.1" 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)", @@ -642,7 +642,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.0 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 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)", "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)", @@ -792,7 +792,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.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c" +"checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" "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 2933f06b..e8ac3a57 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.0", features = ["nightly"] } +schnorrkel = { version = "0.1.1", 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/package.json b/packages/wasm-crypto/package.json index 06a480dd..ac286323 100644 --- a/packages/wasm-crypto/package.json +++ b/packages/wasm-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/wasm-crypto", - "version": "0.9.1", + "version": "0.10.0", "author": "Jaco Greeff ", "files": [ "crypto-polyfill.js", diff --git a/packages/wasm-crypto/src/sr25519.rs b/packages/wasm-crypto/src/sr25519.rs index 5359d2f1..826a0602 100644 --- a/packages/wasm-crypto/src/sr25519.rs +++ b/packages/wasm-crypto/src/sr25519.rs @@ -202,6 +202,16 @@ pub mod tests { assert!(is_valid); } + #[test] + fn can_verify_known_message() { + let message = b"Verifying that I am the owner of 5G9hQLdsKQswNPgB499DeA5PkFBbgkLPJWkkS6FAM6xGQ8xD. Hash: 221455a3\n"; + let public = hex!("b4bfa1f7a5166695eb75299fd1c4c03ea212871c342f2c5dfea0902b2c246918"); + let signature = hex!("5a9755f069939f45d96aaf125cf5ce7ba1db998686f87f2fb3cbdea922078741a73891ba265f70c31436e18a9acd14d189d73c12317ab6c313285cd938453202"); + let is_valid = ext_sr_verify(&signature, message, &public); + + assert!(is_valid); + } + #[test] fn soft_derives_pair() { let cc = hex!("0c666f6f00000000000000000000000000000000000000000000000000000000"); // foo diff --git a/packages/wasm-crypto/test/all/sr25519.js b/packages/wasm-crypto/test/all/sr25519.js index 24e9fd71..360004e0 100644 --- a/packages/wasm-crypto/test/all/sr25519.js +++ b/packages/wasm-crypto/test/all/sr25519.js @@ -35,10 +35,9 @@ function sr25519_devFromSeed () { } function sr25519_verifyExisting () { - const PK = hexToU8a('0x741c08a06f41c596608f6774259bd9043304adfa5d3eea62760bd9be97634d63'); - const MESSAGE = stringToU8a('this is a message'); - const SIGNATURE = hexToU8a('0xdecef12cf20443e7c7a9d406c237e90bcfcf145860722622f92ebfd5eb4b5b3990b6443934b5cba8f925a0ae75b3a77d35b8490cbb358dd850806e58eaf72904' -); + 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); diff --git a/scripts/test-package.sh b/scripts/test-package.sh index a338fd9d..86119aa3 100755 --- a/scripts/test-package.sh +++ b/scripts/test-package.sh @@ -5,7 +5,7 @@ set -e echo "*** Testing package" echo "*** Testing Rust" -cargo test --release +RUST_BACKTRACE=full rustup run nightly cargo test --release -- --nocapture echo "*** Testing WASM" node ./test/wasm.js diff --git a/yarn.lock b/yarn.lock index 428e2e8e..ae4c4286 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1625,10 +1625,10 @@ universal-user-agent "^2.0.0" url-template "^2.0.8" -"@polkadot/dev@^0.30.0-beta.3": - version "0.30.0-beta.3" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.30.0-beta.3.tgz#22ed6cfa735520f75e43020cf6673ec4d376ee48" - integrity sha512-mb4d+OJfWRx/pmsOKH29rRUq0Htoxl8MdIufnbikIW9aTROK5yULhkeB7SUKuYglVFhr+z1HGDx7MYBzDqjrhA== +"@polkadot/dev@^0.30.0-beta.4": + version "0.30.0-beta.4" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.30.0-beta.4.tgz#10403838cba964a21d2cc6740fdb74c9b9244038" + integrity sha512-ugJkBxvGOebSQQSL+zhIPAHUdnNxy5qGSUPnSh+7ss5g2rYzf6zIpUIlAJ78heF+vmTebD+6VmjwW9jQ7XbnCA== dependencies: "@babel/cli" "^7.4.4" "@babel/core" "^7.4.4" @@ -1662,10 +1662,10 @@ typescript "^3.4.5" vuepress "^1.0.0-alpha.47" -"@polkadot/util@^0.90.0-beta.1": - version "0.90.0-beta.1" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.90.0-beta.1.tgz#e70c5120f1fb20e9c78983598dc6e17030ab7550" - integrity sha512-gRF6DWq/PVtD4EnVxyta8tuiAG2j3mvP88xcyMcWDqENZfw43Rnor+bT9YhsZ0AkLuad4KbPOw3cWbVnBPIoIg== +"@polkadot/util@^0.90.1": + version "0.90.1" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.90.1.tgz#25f4f1bd1702cb12f10b8f94de5b79d4eda98ed9" + integrity sha512-vquT0fnBycm1jCG9gpLkJruLmA1J4P1nJvmvoLfZn5lDI4IChgwoK2rv9aDDfEfO/sYIRUqyiuMiT9TwzL2udA== dependencies: "@babel/runtime" "^7.4.4" "@types/bn.js" "^4.11.5"