Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIP Compatibility test #327

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
49 changes: 49 additions & 0 deletions manta-pay/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,52 @@ impl TryFrom<String> 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<C>(value: [u8; 32])
where
C: CoinType,
{
let mut rng = ChaCha12Rng::from_seed([0u8; 32]);
let xpr_secret_key = KeySecret::<C>::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::<Testnet>(SECRET_KEY_TESTNET);
secret_key_generation::<Manta>(SECRET_KEY_MANTA);
secret_key_generation::<Calamari>(SECRET_KEY_CALAMARI);
}
}