Skip to content

Commit

Permalink
Merge pull request #4252 from anoma/murisi/ledger-zip32-default
Browse files Browse the repository at this point in the history
Make modified ZIP 32 derivations the default.
  • Loading branch information
mergify[bot] authored Jan 23, 2025
2 parents 0f54f09 + cfa36a0 commit 6d5ccec
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Make modified ZIP 32 derivations the default
([\#4248](https://github.com/anoma/namada/issues/4248))
22 changes: 13 additions & 9 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3559,7 +3559,6 @@ pub mod args {
let raw = "http://127.0.0.1:26657";
Url::from_str(raw).unwrap()
}));
pub const LEDGER_ZIP32: ArgFlag = flag("ledger-zip32");
pub const LIST_FIND_ADDRESSES_ONLY: ArgFlag = flag("addr");
pub const LIST_FIND_KEYS_ONLY: ArgFlag = flag("keys");
pub const LOCALHOST: ArgFlag = flag("localhost");
Expand Down Expand Up @@ -3672,6 +3671,7 @@ pub mod args {
pub const TX_HASH: Arg<String> = arg("tx-hash");
pub const THRESHOLD: ArgOpt<u8> = arg_opt("threshold");
pub const UNSAFE_DONT_ENCRYPT: ArgFlag = flag("unsafe-dont-encrypt");
pub const UNSAFE_PURE_ZIP32: ArgFlag = flag("unsafe-pure-zip32");
pub const UNSAFE_SHOW_SECRET: ArgFlag = flag("unsafe-show-secret");
pub const USE_DEVICE: ArgFlag = flag("use-device");
pub const VALIDATOR: Arg<WalletAddress> = arg("validator");
Expand Down Expand Up @@ -7980,14 +7980,14 @@ pub mod args {
HD_PROMPT_BIP39_PASSPHRASE.parse(matches);
let use_device = USE_DEVICE.parse(matches);
let device_transport = DEVICE_TRANSPORT.parse(matches);
let ledger_zip32 = LEDGER_ZIP32.parse(matches);
let unsafe_pure_zip32 = UNSAFE_PURE_ZIP32.parse(matches);
Self {
scheme,
shielded,
alias,
alias_force,
unsafe_dont_encrypt,
ledger_zip32,
unsafe_pure_zip32,
derivation_path,
allow_non_compliant,
prompt_bip39_passphrase,
Expand Down Expand Up @@ -8059,12 +8059,16 @@ pub mod args {
"Use an additional passphrase for HD-key generation."
)))
.arg(
LEDGER_ZIP32.def().requires(SHIELDED.name).help(wrap!(
"Use the modified ZIP 32 algorithm supported by Ledger \
devices. This flag is necessary if importing the \
generated mnemonic code onto the Ledger device at some \
future time is a requirement."
)),
UNSAFE_PURE_ZIP32
.def()
.requires(SHIELDED.name)
.conflicts_with(USE_DEVICE.name)
.help(wrap!(
"Use the deprecated pure ZIP 32 algorithm to derive \
shielded keys. This flag is necessary if importing a \
mnemonic code that was generated on Namada 1.0.0 or \
before."
)),
)
}
}
Expand Down
12 changes: 10 additions & 2 deletions crates/apps_lib/src/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async fn shielded_key_derive(
alias,
alias_force,
unsafe_dont_encrypt,
ledger_zip32,
unsafe_pure_zip32,
derivation_path,
allow_non_compliant,
prompt_bip39_passphrase,
Expand All @@ -203,6 +203,14 @@ async fn shielded_key_derive(
}: args::KeyDerive,
) {
let mut wallet = load_wallet(ctx);
if !unsafe_pure_zip32 {
tracing::warn!(
"The default shielded key derivation algorithm has been changed \
to achieve hardware wallet compatibility. For information on the \
deprecated algorithm, see the documentation for \
--unsafe-pure-zip32."
);
}
let derivation_path = decode_shielded_derivation_path(derivation_path)
.unwrap_or_else(|err| {
edisplay_line!(io, "{}", err);
Expand All @@ -223,7 +231,7 @@ async fn shielded_key_derive(
alias,
alias_force,
birthday,
ledger_zip32,
unsafe_pure_zip32,
derivation_path,
None,
prompt_bip39_passphrase,
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2894,8 +2894,8 @@ pub struct KeyDerive {
pub alias_force: bool,
/// Don't encrypt the keypair
pub unsafe_dont_encrypt: bool,
/// Use the modified ZIP 32 algorithm supported by Ledger devices
pub ledger_zip32: bool,
/// Use the deprecated pure ZIP 32 algorithm
pub unsafe_pure_zip32: bool,
/// BIP44 / ZIP32 derivation path
pub derivation_path: String,
/// Allow non-compliant derivation path
Expand Down
8 changes: 4 additions & 4 deletions crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl<U: WalletIo> Wallet<U> {
alias: String,
alias_force: bool,
birthday: Option<BlockHeight>,
ledger_zip32: bool,
unsafe_pure_zip32: bool,
derivation_path: DerivationPath,
mnemonic_passphrase: Option<(Mnemonic, Zeroizing<String>)>,
prompt_bip39_passphrase: bool,
Expand All @@ -594,7 +594,9 @@ impl<U: WalletIo> Wallet<U> {
(mnemonic, passphrase)
};
let seed = Seed::new(&mnemonic, &passphrase);
let seed = if ledger_zip32 {
let seed = if unsafe_pure_zip32 {
seed.as_bytes()
} else {
// Path to obtain the ZIP32 seed
let zip32_seed_path =
DerivationPath::default_for_transparent_scheme(
Expand All @@ -610,8 +612,6 @@ impl<U: WalletIo> Wallet<U> {
.expect("Expected Ed25519 key")
.0
.to_bytes()[..]
} else {
seed.as_bytes()
};
// Now ZIP32 derive the extended spending key from the new seed
let spend_key = derive_hd_spending_key(seed, derivation_path.clone());
Expand Down

0 comments on commit 6d5ccec

Please sign in to comment.