add additional fingerprint check when finding signing nodes from provided psbt input derivation paths

This commit is contained in:
Craig Raw 2024-05-06 09:51:17 +02:00
parent e298033cbb
commit a7dd28dde7

View file

@ -246,14 +246,16 @@ public class Keystore extends Persistable {
public ECKey getPubKeyForDerivation(KeyDerivation keyDerivation) { public ECKey getPubKeyForDerivation(KeyDerivation keyDerivation) {
if(keyDerivation != null) { if(keyDerivation != null) {
List<ChildNumber> derivation = keyDerivation.getDerivation(); List<ChildNumber> derivation = keyDerivation.getDerivation();
String fingerprint = Utils.bytesToHex(this.extendedPublicKey.getKey().getFingerprint());
if(derivation.size() > this.keyDerivation.getDerivation().size()) { if(derivation.size() > this.keyDerivation.getDerivation().size()) {
List<ChildNumber> xpubDerivation = derivation.subList(0, this.keyDerivation.getDerivation().size()); List<ChildNumber> xpubDerivation = derivation.subList(0, this.keyDerivation.getDerivation().size());
if(xpubDerivation.equals(this.keyDerivation.getDerivation())) { if(xpubDerivation.equals(this.keyDerivation.getDerivation())) {
derivation = derivation.subList(this.keyDerivation.getDerivation().size(), derivation.size()); derivation = derivation.subList(this.keyDerivation.getDerivation().size(), derivation.size());
fingerprint = this.keyDerivation.getMasterFingerprint();
} }
} }
if(derivation.size() == 2 && KeyPurpose.fromChildNumber(derivation.get(0)) != null) { if(derivation.size() == 2 && KeyPurpose.fromChildNumber(derivation.get(0)) != null && fingerprint.equals(keyDerivation.getMasterFingerprint())) {
return getPubKey(new WalletNode(KeyDerivation.writePath(derivation))); return getPubKey(new WalletNode(KeyDerivation.writePath(derivation)));
} }
} }