Closed notmandatory closed 2 years ago
happy to handle this.
I see that the coin type is set here:
pub(super) fn make_bipxx_private<K: DerivableKey<$ctx>>(
bip: u32,
key: K,
keychain: KeychainKind,
) -> Result<impl IntoDescriptorKey<$ctx>, DescriptorError> {
let mut derivation_path = Vec::with_capacity(4);
derivation_path.push(bip32::ChildNumber::from_hardened_idx(bip)?);
-> derivation_path.push(bip32::ChildNumber::from_hardened_idx(0)?);
derivation_path.push(bip32::ChildNumber::from_hardened_idx(0)?);
match keychain {
KeychainKind::External => {
derivation_path.push(bip32::ChildNumber::from_normal_idx(0)?)
}
KeychainKind::Internal => {
derivation_path.push(bip32::ChildNumber::from_normal_idx(1)?)
}
};
let derivation_path: bip32::DerivationPath = derivation_path.into();
Ok((key, derivation_path))
}
I wonder how would this macro know if this is testnet or mainnet ?
I think the best way to fix this would be to add a network argument to DescriptorTemplate::build
, then you can adapt the macro and everything accordingly.
It's an API break but I think it's reasonable
Describe the bug
When using one of the BIP(44,49,84) templates the "coin type" part of the key derivation path is always set to 0, which represents bitcoin mainnet, no matter what the type of the key(s) used are. These templates should use 1 if the type of the key is testnet, regtest, or signet.
(Originally reported on discord by marcosalejandro)
To Reproduce
test output:
Expected behavior
According to BIP44 Coin Type for
Testnet
theChildNumber
at index 1 should beHardened { index: 1 }
.Build environment
Additional context
The Bip44, Bip49, and Bip84 macros all use the
descriptor::template::expand_make_bipxx
macro and this is where the coin type part of the derivation path is set.