diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fed7d5ef..ca6a978e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [\#328](https://github.com/Manta-Network/manta-rs/pull/328) Expose reset wallet method. ### Changed +- [\#327](https://github.com/Manta-Network/manta-rs/pull/327) Update BIP32 to v0.4.0. ### Deprecated 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..acf65006a 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); + } +}