Skip to content

Commit

Permalink
fix: Properly compare Buffer objects in Descriptors
Browse files Browse the repository at this point in the history
- Introduced a utility function, `eqBuffers`, to accurately compare two Buffer objects or their fallback values.
- Updated buffer comparisons for `getWitnessScript` and `getRedeemScript` to use the new utility function, ensuring correct and more readable comparisons.

Resolves #20.
  • Loading branch information
landabaso committed Sep 12, 2023
1 parent d5dbf16 commit fea09b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,16 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
let sequence = this.getSequence();
if (sequence === undefined && locktime !== 0) sequence = 0xfffffffe;
if (sequence === undefined && locktime === 0) sequence = 0xffffffff;
const eqBuffers = (buf1: Buffer | undefined, buf2: Buffer | undefined) =>
buf1 instanceof Buffer && buf2 instanceof Buffer
? Buffer.compare(buf1, buf2) === 0
: buf1 === buf2;
if (
Buffer.compare(scriptPubKey, this.getScriptPubKey()) !== 0 ||
sequence !== inputSequence ||
locktime !== psbt.locktime ||
this.getWitnessScript() !== input.witnessScript ||
this.getRedeemScript() !== input.redeemScript
!eqBuffers(this.getWitnessScript(), input.witnessScript) ||
!eqBuffers(this.getRedeemScript(), input.redeemScript)
) {
throw new Error(
`Error: cannot finalize psbt index ${index} since it does not correspond to this descriptor`
Expand Down

0 comments on commit fea09b3

Please sign in to comment.