Browse Source

Prefer buf1.equals(buf2) over Buffer.compare(buf1, buf2) !== 0

psbt
Luke Childs 6 years ago
parent
commit
f961724c73
  1. 4
      src/psbt.js
  2. 4
      ts_src/psbt.ts

4
src/psbt.js

@ -8,7 +8,7 @@ const checkRedeemScript = (inputIndex, scriptPubKey, redeemScript) => {
redeem: { output: redeemScript },
}).output;
// If a redeemScript is provided, the scriptPubKey must be for that redeemScript
if (Buffer.compare(scriptPubKey, redeemScriptOutput) !== 0) {
if (!scriptPubKey.equals(redeemScriptOutput)) {
throw new Error(
`Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`,
);
@ -54,7 +54,7 @@ class Psbt extends bip174_1.Psbt {
const prevoutHash = unsignedTx.ins[inputIndex].hash;
const utxoHash = nonWitnessUtxoTx.getHash();
// If a non-witness UTXO is provided, its hash must match the hash specified in the prevout
if (Buffer.compare(prevoutHash, utxoHash) !== 0) {
if (!prevoutHash.equals(utxoHash)) {
throw new Error(
`Non-witness UTXO hash for input #${inputIndex} doesn't match the hash specified in the prevout`,
);

4
ts_src/psbt.ts

@ -13,7 +13,7 @@ const checkRedeemScript = (
}).output as Buffer;
// If a redeemScript is provided, the scriptPubKey must be for that redeemScript
if (Buffer.compare(scriptPubKey, redeemScriptOutput) !== 0) {
if (!scriptPubKey.equals(redeemScriptOutput)) {
throw new Error(
`Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`,
);
@ -61,7 +61,7 @@ export class Psbt extends PsbtBase {
const utxoHash = nonWitnessUtxoTx.getHash();
// If a non-witness UTXO is provided, its hash must match the hash specified in the prevout
if (Buffer.compare(prevoutHash, utxoHash) !== 0) {
if (!prevoutHash.equals(utxoHash)) {
throw new Error(
`Non-witness UTXO hash for input #${inputIndex} doesn't match the hash specified in the prevout`,
);

Loading…
Cancel
Save