From f961724c73b97e1d503d5311a64d8d228e1476bd Mon Sep 17 00:00:00 2001
From: Luke Childs <lukechilds123@gmail.com>
Date: Fri, 28 Jun 2019 18:26:42 +0700
Subject: [PATCH] Prefer buf1.equals(buf2) over Buffer.compare(buf1, buf2) !==
 0

---
 src/psbt.js    | 4 ++--
 ts_src/psbt.ts | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/psbt.js b/src/psbt.js
index c68afb0..55e6ac9 100644
--- a/src/psbt.js
+++ b/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`,
         );
diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts
index 70e04c9..7e5d13c 100644
--- a/ts_src/psbt.ts
+++ b/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`,
         );