Skip to content

Commit 1e3cff3

Browse files
committed
fix(wasm-utxo): skip empty bip32Derivation when resolving PSBT input descriptors
1 parent fd615ad commit 1e3cff3

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/wasm-utxo/js/descriptorWallet/psbt/findDescriptors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@ type WithTapBip32Derivation = { tapBip32Derivation?: { path: string }[] };
124124

125125
function getDerivationPaths(v: WithBip32Derivation | WithTapBip32Derivation): string[] | undefined {
126126
if ("bip32Derivation" in v && v.bip32Derivation) {
127-
return v.bip32Derivation.map((v) => v.path);
127+
if (!Array.isArray(v.bip32Derivation) || v.bip32Derivation.length > 0) {
128+
return v.bip32Derivation.map((v) => v.path);
129+
}
128130
}
129131
if ("tapBip32Derivation" in v && v.tapBip32Derivation) {
130-
return v.tapBip32Derivation.map((v) => v.path).filter((v) => v !== "" && v !== "m");
132+
if (!Array.isArray(v.tapBip32Derivation) || v.tapBip32Derivation.length > 0) {
133+
return v.tapBip32Derivation.map((v) => v.path).filter((v) => v !== "" && v !== "m");
134+
}
131135
}
132136
return undefined;
133137
}

packages/wasm-utxo/test/descriptorWallet/psbt/findDescriptors.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ describe("descriptorWallet/psbt/findDescriptors", () => {
7070
assert.strictEqual(result.index, 10);
7171
});
7272

73+
it("should find derivable descriptor using tapBip32Derivation when bip32Derivation is empty", () => {
74+
const descriptor = Descriptor.fromStringDetectType(derivableDescriptor);
75+
const derivedScript = descriptor.atDerivationIndex(7).scriptPubkey();
76+
77+
const descriptorMap = toDescriptorMap([{ name: "derivable", value: derivableDescriptor }]);
78+
79+
const input: PsbtInput = {
80+
witnessUtxo: { script: derivedScript, value: 100000n },
81+
bip32Derivation: [],
82+
tapBip32Derivation: [{ path: "m/0/7" }],
83+
};
84+
85+
const result = findDescriptorForInput(input, descriptorMap);
86+
87+
assert.ok(result);
88+
assert.strictEqual(result.index, 7);
89+
});
90+
7391
it("should return undefined when no matching descriptor", () => {
7492
const descriptorMap = toDescriptorMap([{ name: "wpkh", value: wpkhDescriptor }]);
7593

0 commit comments

Comments
 (0)