Skip to content

Commit 049be6f

Browse files
authored
Merge pull request #285 from BitGo/veetragjain/cshld-909-add-client-side-verification-for-reclaim-transaction
fix(wasm-utxo): skip empty bip32Derivation when resolving PSBT input descriptors
2 parents fd615ad + f19106a commit 049be6f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

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

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

125125
function getDerivationPaths(v: WithBip32Derivation | WithTapBip32Derivation): string[] | undefined {
126-
if ("bip32Derivation" in v && v.bip32Derivation) {
126+
if ("bip32Derivation" in v && v.bip32Derivation && v.bip32Derivation.length > 0) {
127127
return v.bip32Derivation.map((v) => v.path);
128128
}
129-
if ("tapBip32Derivation" in v && v.tapBip32Derivation) {
129+
if ("tapBip32Derivation" in v && v.tapBip32Derivation && v.tapBip32Derivation.length > 0) {
130130
return v.tapBip32Derivation.map((v) => v.path).filter((v) => v !== "" && v !== "m");
131131
}
132132
return undefined;

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)