From 912d6d41becf3b4b77b00038c481d71b34c64b2e Mon Sep 17 00:00:00 2001
From: junderw <junderwood@bitcoinbank.co.jp>
Date: Sat, 29 Dec 2018 17:02:32 +0900
Subject: [PATCH] Fix some small bugs

---
 src/payments/p2ms.js       |  2 +-
 src/transaction_builder.js |  4 ++--
 test/fixtures/p2ms.json    | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/payments/p2ms.js b/src/payments/p2ms.js
index 5c90a4d..8c5a380 100644
--- a/src/payments/p2ms.js
+++ b/src/payments/p2ms.js
@@ -129,7 +129,7 @@ function p2ms (a, opts) {
       if (a.input[0] !== OPS.OP_0) throw new TypeError('Input is invalid')
       if (o.signatures.length === 0 || !o.signatures.every(isAcceptableSignature)) throw new TypeError('Input has invalid signature(s)')
 
-      if (a.signatures && !stacksEqual(a.signatures.equals(o.signatures))) throw new TypeError('Signature mismatch')
+      if (a.signatures && !stacksEqual(a.signatures, o.signatures)) throw new TypeError('Signature mismatch')
       if (a.m !== undefined && a.m !== a.signatures.length) throw new TypeError('Signature count mismatch')
     }
   }
diff --git a/src/transaction_builder.js b/src/transaction_builder.js
index bea1ded..6508a86 100644
--- a/src/transaction_builder.js
+++ b/src/transaction_builder.js
@@ -217,7 +217,7 @@ function expandOutput (script, ourPubKey) {
   return { type }
 }
 
-function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScript) {
+function prepareInput (input, ourPubKey, redeemScript, witnessScript) {
   if (redeemScript && witnessScript) {
     const p2wsh = payments.p2wsh({ redeem: { output: witnessScript } })
     const p2wshAlt = payments.p2wsh({ output: redeemScript })
@@ -665,7 +665,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
     }
 
     if (!canSign(input)) {
-      const prepared = prepareInput(input, ourPubKey, redeemScript, witnessValue, witnessScript)
+      const prepared = prepareInput(input, ourPubKey, redeemScript, witnessScript)
 
       // updates inline
       Object.assign(input, prepared)
diff --git a/test/fixtures/p2ms.json b/test/fixtures/p2ms.json
index 8ea033e..2f41270 100644
--- a/test/fixtures/p2ms.json
+++ b/test/fixtures/p2ms.json
@@ -310,6 +310,20 @@
         ]
       }
     },
+    {
+      "exception": "Signature mismatch",
+      "arguments": {
+        "m": 1,
+        "pubkeys": [
+          "030000000000000000000000000000000000000000000000000000000000000001",
+          "030000000000000000000000000000000000000000000000000000000000000001"
+        ],
+        "signatures": [
+          "300602010002010001"
+        ],
+        "input": "OP_0 300602010002010101"
+      }
+    },
     {
       "exception": "Too many signatures provided",
       "arguments": {