bip32: change several cryptographically unreachable paths to expects

These paths cannot be reached. In general, key derivation cannot fail
for cryptographic reasons.
This commit is contained in:
Andrew Poelstra 2025-04-21 22:19:30 +00:00
parent ddd27eddc4
commit 0e5e021b69
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 6 additions and 3 deletions

View File

@ -610,7 +610,8 @@ impl Xpriv {
child_number: ChildNumber::ZERO_NORMAL,
private_key: secp256k1::SecretKey::from_byte_array(
hmac.as_byte_array().split_array::<32, 32>().0,
)?,
)
.expect("cryptographically unreachable"),
chain_code: ChainCode::from_hmac(hmac),
})
}
@ -828,7 +829,8 @@ impl Xpub {
let hmac = engine.finalize();
let private_key = secp256k1::SecretKey::from_byte_array(
hmac.as_byte_array().split_array::<32, 32>().0,
)?;
)
.expect("cryptographically unreachable");
let chain_code = ChainCode::from_hmac(hmac);
Ok((private_key, chain_code))
}
@ -842,7 +844,8 @@ impl Xpub {
i: ChildNumber,
) -> Result<Xpub, Error> {
let (sk, chain_code) = self.ckd_pub_tweak(i)?;
let tweaked = self.public_key.add_exp_tweak(secp, &sk.into())?;
let tweaked =
self.public_key.add_exp_tweak(secp, &sk.into()).expect("cryptographically unreachable");
Ok(Xpub {
network: self.network,