From b6ecc519048625c96d7541223ee2bdd473a6e453 Mon Sep 17 00:00:00 2001 From: SupremoUGH Date: Fri, 10 Mar 2023 16:37:11 +0100 Subject: [PATCH 1/2] bip compatibility test --- manta-pay/Cargo.toml | 2 +- manta-pay/src/key.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/manta-pay/Cargo.toml b/manta-pay/Cargo.toml index 0d6dda485..4ec0d3525 100644 --- a/manta-pay/Cargo.toml +++ b/manta-pay/Cargo.toml @@ -110,7 +110,7 @@ websocket = [ [dependencies] aes-gcm = { version = "0.9.4", default-features = false, features = ["aes", "alloc"] } bip0039 = { version = "0.10.1", optional = true, default-features = false } -bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] } +bip32 = { version = "0.4.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] } blake2 = { version = "0.10.6", default-features = false } bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] } clap = { version = "4.1.8", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] } diff --git a/manta-pay/src/key.rs b/manta-pay/src/key.rs index 06d332cc2..784ecae0a 100644 --- a/manta-pay/src/key.rs +++ b/manta-pay/src/key.rs @@ -306,3 +306,52 @@ impl TryFrom for Mnemonic { Self::new(string.as_str()) } } + +/// Testing framework +#[cfg(test)] +pub mod test { + use crate::key::{Calamari, CoinType, KeySecret, Manta, Testnet}; + use manta_crypto::rand::{ChaCha12Rng, SeedableRng}; + + /// Hardcoded testnet secret key value in bytes for the BIP32 0.3.0 version + const SECRET_KEY_TESTNET: [u8; 32] = [ + 55, 177, 88, 96, 186, 231, 197, 20, 152, 186, 220, 249, 99, 7, 206, 216, 161, 49, 179, 32, + 62, 26, 87, 161, 13, 69, 41, 84, 20, 146, 126, 20, + ]; + + /// Hardcoded manta secret key value in bytes for the BIP32 0.3.0 version + const SECRET_KEY_MANTA: [u8; 32] = [ + 228, 135, 94, 228, 192, 30, 201, 41, 57, 204, 21, 73, 71, 4, 79, 69, 6, 223, 159, 72, 196, + 237, 14, 159, 211, 248, 36, 248, 128, 71, 142, 251, + ]; + + /// Hardcoded calamari secret key value in bytes for the BIP32 0.3.0 version + const SECRET_KEY_CALAMARI: [u8; 32] = [ + 170, 5, 152, 195, 158, 157, 166, 172, 135, 10, 191, 238, 53, 71, 37, 124, 103, 223, 17, + 194, 178, 237, 231, 204, 21, 14, 23, 174, 90, 248, 129, 208, + ]; + + /// Computes a secret key and asserts it is equal to the hardcoded `value`. + #[inline] + pub fn secret_key_generation(value: [u8; 32]) + where + C: CoinType, + { + let mut rng = ChaCha12Rng::from_seed([0u8; 32]); + let xpr_secret_key = KeySecret::::sample(&mut rng) + .xpr_secret_key(&Default::default()) + .to_bytes(); + assert_eq!( + xpr_secret_key, value, + "BIP32 version is not backward-compatible with 0.3.0." + ); + } + + /// Runs the test above for [`Testnet`], [`Manta`] and [`Calamari`]. + #[test] + fn secret_key_generation_test() { + secret_key_generation::(SECRET_KEY_TESTNET); + secret_key_generation::(SECRET_KEY_MANTA); + secret_key_generation::(SECRET_KEY_CALAMARI); + } +} \ No newline at end of file From d7a1e4039bb45805d78344f4860d82753cca0aab Mon Sep 17 00:00:00 2001 From: SupremoUGH Date: Fri, 10 Mar 2023 16:44:08 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + manta-pay/src/key.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e55d29f5e..ea47a6540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added ### Changed +- [\#327](https://github.com/Manta-Network/manta-rs/pull/327) Update BIP32 to v0.4.0. ### Deprecated diff --git a/manta-pay/src/key.rs b/manta-pay/src/key.rs index 784ecae0a..acf65006a 100644 --- a/manta-pay/src/key.rs +++ b/manta-pay/src/key.rs @@ -354,4 +354,4 @@ pub mod test { secret_key_generation::(SECRET_KEY_MANTA); secret_key_generation::(SECRET_KEY_CALAMARI); } -} \ No newline at end of file +}