Support GetKey where the Xpriv is a direct child of the looked up KeySource

This commit is contained in:
Nadav Ivgi 2024-09-13 11:46:07 +03:00
parent 055aa9d4dc
commit b593c886e3
No known key found for this signature in database
GPG Key ID: 81F6104CD0F150FC
1 changed files with 8 additions and 1 deletions

View File

@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet};
use internals::write_err;
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
use crate::bip32::{self, KeySource, Xpriv, Xpub};
use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub};
use crate::crypto::key::{PrivateKey, PublicKey};
use crate::crypto::{ecdsa, taproot};
use crate::key::{TapTweak, XOnlyPublicKey};
@ -764,6 +764,13 @@ impl GetKey for Xpriv {
let key = if self.fingerprint(secp) == *fingerprint {
let k = self.derive_priv(secp, &path);
Some(k.to_priv())
} else if self.parent_fingerprint == *fingerprint
&& !path.is_empty()
&& path[0] == self.child_number
{
let path = DerivationPath::from_iter(path.into_iter().skip(1).copied());
let k = self.derive_priv(secp, &path);
Some(k.to_priv())
} else {
None
};