Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]);

Expand Down
Loading