From fe0ad814723f58c16eab901a9d5c5dc27b62e090 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 23 May 2017 15:14:08 +1000 Subject: [PATCH] package: use safe-buffer --- package.json | 1 + src/address.js | 1 + src/block.js | 1 + src/ecdsa.js | 1 + src/hdnode.js | 1 + src/script.js | 1 + src/script_number.js | 2 ++ src/templates/multisig/input.js | 1 + src/templates/scripthash/input.js | 1 + src/templates/witnesscommitment/output.js | 1 + src/transaction.js | 1 + src/transaction_builder.js | 5 +++-- 12 files changed, 15 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1f3cc12..4cca717 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "merkle-lib": "^2.0.10", "pushdata-bitcoin": "^1.0.1", "randombytes": "^2.0.1", + "safe-buffer": "^5.0.1", "typeforce": "^1.8.7", "varuint-bitcoin": "^1.0.4", "wif": "^2.0.1" diff --git a/src/address.js b/src/address.js index b2a56f8..8799015 100644 --- a/src/address.js +++ b/src/address.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var bs58check = require('bs58check') var bscript = require('./script') var networks = require('./networks') diff --git a/src/block.js b/src/block.js index 4ac5188..c545996 100644 --- a/src/block.js +++ b/src/block.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var bcrypto = require('./crypto') var fastMerkleRoot = require('merkle-lib/fastRoot') var typeforce = require('typeforce') diff --git a/src/ecdsa.js b/src/ecdsa.js index 1ecf29e..8841f6e 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var createHmac = require('create-hmac') var typeforce = require('typeforce') var types = require('./types') diff --git a/src/hdnode.js b/src/hdnode.js index b845f50..a96b20c 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var base58check = require('bs58check') var bcrypto = require('./crypto') var createHmac = require('create-hmac') diff --git a/src/script.js b/src/script.js index 265e1c6..ecb4e85 100644 --- a/src/script.js +++ b/src/script.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var bip66 = require('bip66') var pushdata = require('pushdata-bitcoin') var typeforce = require('typeforce') diff --git a/src/script_number.js b/src/script_number.js index 13a96bb..44f4bec 100644 --- a/src/script_number.js +++ b/src/script_number.js @@ -1,3 +1,5 @@ +var Buffer = require('safe-buffer').Buffer + function decode (buffer, maxLength, minimal) { maxLength = maxLength || 4 minimal = minimal === undefined ? true : minimal diff --git a/src/templates/multisig/input.js b/src/templates/multisig/input.js index 20b22a6..79cad91 100644 --- a/src/templates/multisig/input.js +++ b/src/templates/multisig/input.js @@ -1,5 +1,6 @@ // OP_0 [signatures ...] +var Buffer = require('safe-buffer').Buffer var bscript = require('../../script') var typeforce = require('typeforce') var OPS = require('bitcoin-ops') diff --git a/src/templates/scripthash/input.js b/src/templates/scripthash/input.js index 2bfd3c1..ac34149 100644 --- a/src/templates/scripthash/input.js +++ b/src/templates/scripthash/input.js @@ -1,5 +1,6 @@ // {serialized scriptPubKey script} +var Buffer = require('safe-buffer').Buffer var bscript = require('../../script') var typeforce = require('typeforce') diff --git a/src/templates/witnesscommitment/output.js b/src/templates/witnesscommitment/output.js index e57ff6d..3984ea5 100644 --- a/src/templates/witnesscommitment/output.js +++ b/src/templates/witnesscommitment/output.js @@ -1,5 +1,6 @@ // OP_RETURN {aa21a9ed} {commitment} +var Buffer = require('safe-buffer').Buffer var bscript = require('../../script') var types = require('../../types') var typeforce = require('typeforce') diff --git a/src/transaction.js b/src/transaction.js index d9e9868..41e00d9 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var bcrypto = require('./crypto') var bscript = require('./script') var bufferutils = require('./bufferutils') diff --git a/src/transaction_builder.js b/src/transaction_builder.js index fa3ddb2..05ed464 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -1,3 +1,4 @@ +var Buffer = require('safe-buffer').Buffer var baddress = require('./address') var bcrypto = require('./crypto') var bscript = require('./script') @@ -367,9 +368,9 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip function buildStack (type, signatures, pubKeys, allowIncomplete) { if (type === scriptTypes.P2PKH) { - if (signatures.length === 1 && signatures[0] instanceof Buffer && pubKeys.length === 1) return bscript.pubKeyHash.input.encodeStack(signatures[0], pubKeys[0]) + if (signatures.length === 1 && Buffer.isBuffer(signatures[0]) && pubKeys.length === 1) return bscript.pubKeyHash.input.encodeStack(signatures[0], pubKeys[0]) } else if (type === scriptTypes.P2PK) { - if (signatures.length === 1 && signatures[0] instanceof Buffer) return bscript.pubKey.input.encodeStack(signatures[0]) + if (signatures.length === 1 && Buffer.isBuffer(signatures[0])) return bscript.pubKey.input.encodeStack(signatures[0]) } else if (type === scriptTypes.MULTISIG) { if (signatures.length > 0) { signatures = signatures.map(function (signature) {