From f19106a42afe2d1cf11e006e647848a857011914 Mon Sep 17 00:00:00 2001 From: Veetrag Jain Date: Tue, 26 May 2026 21:35:23 +0530 Subject: [PATCH] fix(wasm-utxo): skip empty bip32Derivation when resolving PSBT input descriptors --- .../descriptorWallet/psbt/findDescriptors.ts | 4 ++-- .../descriptorWallet/psbt/findDescriptors.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/wasm-utxo/js/descriptorWallet/psbt/findDescriptors.ts b/packages/wasm-utxo/js/descriptorWallet/psbt/findDescriptors.ts index 566d322e896..cd54e99743a 100644 --- a/packages/wasm-utxo/js/descriptorWallet/psbt/findDescriptors.ts +++ b/packages/wasm-utxo/js/descriptorWallet/psbt/findDescriptors.ts @@ -123,10 +123,10 @@ type WithBip32Derivation = { bip32Derivation?: { path: string }[] }; type WithTapBip32Derivation = { tapBip32Derivation?: { path: string }[] }; function getDerivationPaths(v: WithBip32Derivation | WithTapBip32Derivation): string[] | undefined { - if ("bip32Derivation" in v && v.bip32Derivation) { + if ("bip32Derivation" in v && v.bip32Derivation && v.bip32Derivation.length > 0) { return v.bip32Derivation.map((v) => v.path); } - if ("tapBip32Derivation" in v && v.tapBip32Derivation) { + if ("tapBip32Derivation" in v && v.tapBip32Derivation && v.tapBip32Derivation.length > 0) { return v.tapBip32Derivation.map((v) => v.path).filter((v) => v !== "" && v !== "m"); } return undefined; diff --git a/packages/wasm-utxo/test/descriptorWallet/psbt/findDescriptors.ts b/packages/wasm-utxo/test/descriptorWallet/psbt/findDescriptors.ts index 41bd0318bfd..09e79fd6f95 100644 --- a/packages/wasm-utxo/test/descriptorWallet/psbt/findDescriptors.ts +++ b/packages/wasm-utxo/test/descriptorWallet/psbt/findDescriptors.ts @@ -70,6 +70,24 @@ describe("descriptorWallet/psbt/findDescriptors", () => { assert.strictEqual(result.index, 10); }); + it("should find derivable descriptor using tapBip32Derivation when bip32Derivation is empty", () => { + const descriptor = Descriptor.fromStringDetectType(derivableDescriptor); + const derivedScript = descriptor.atDerivationIndex(7).scriptPubkey(); + + const descriptorMap = toDescriptorMap([{ name: "derivable", value: derivableDescriptor }]); + + const input: PsbtInput = { + witnessUtxo: { script: derivedScript, value: 100000n }, + bip32Derivation: [], + tapBip32Derivation: [{ path: "m/0/7" }], + }; + + const result = findDescriptorForInput(input, descriptorMap); + + assert.ok(result); + assert.strictEqual(result.index, 7); + }); + it("should return undefined when no matching descriptor", () => { const descriptorMap = toDescriptorMap([{ name: "wpkh", value: wpkhDescriptor }]);