diff --git a/src/ecsignature.js b/src/ecsignature.js index cbf9f817c..151e962d6 100644 --- a/src/ecsignature.js +++ b/src/ecsignature.js @@ -71,7 +71,7 @@ ECSignature.parseScriptSignature = function (buffer) { var hashType = buffer.readUInt8(buffer.length - 1) var hashTypeMod = hashType & ~0x80 - assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType ' + hashType) + if (hashTypeMod <= 0x00 || hashTypeMod >= 0x04) throw new Error('Invalid hashType ' + hashType) return { signature: ECSignature.fromDER(buffer.slice(0, -1)), diff --git a/src/message.js b/src/message.js index b2c584c4d..75a3e2efc 100644 --- a/src/message.js +++ b/src/message.js @@ -30,7 +30,6 @@ function sign (keyPair, message, network) { return signature.toCompact(i, keyPair.compressed) } -// TODO: network could be implied from address function verify (address, signature, message, network) { if (!Buffer.isBuffer(signature)) { signature = new Buffer(signature, 'base64') diff --git a/src/networks.js b/src/networks.js index d694bf767..60690ffec 100644 --- a/src/networks.js +++ b/src/networks.js @@ -3,7 +3,6 @@ module.exports = { bitcoin: { - magic: 0xd9b4bef9, messagePrefix: '\x18Bitcoin Signed Message:\n', bip32: { public: 0x0488b21e, @@ -15,7 +14,6 @@ module.exports = { dustThreshold: 546 // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/core.h#L151-L162 }, testnet: { - magic: 0xd9b4bef9, messagePrefix: '\x18Bitcoin Signed Message:\n', bip32: { public: 0x043587cf, @@ -27,7 +25,6 @@ module.exports = { dustThreshold: 546 }, litecoin: { - magic: 0xd9b4bef9, messagePrefix: '\x19Litecoin Signed Message:\n', bip32: { public: 0x019da462, diff --git a/src/transaction.js b/src/transaction.js index 63705fa8f..95cd2be50 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -177,7 +177,7 @@ Transaction.prototype.clone = function () { return newTx } -var one = new Buffer('0000000000000000000000000000000000000000000000000000000000000001', 'hex') +var ONE = new Buffer('0000000000000000000000000000000000000000000000000000000000000001', 'hex') /** * Hash transaction for signing a specific input. @@ -195,7 +195,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT assert(inIndex >= 0, 'Invalid vin index') // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29 - if (inIndex >= this.ins.length) return one + if (inIndex >= this.ins.length) return ONE var txTmp = this.clone() @@ -225,7 +225,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT // only lock-in the txOut payee at same index as txIn // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60 - if (nOut >= this.outs.length) return one + if (nOut >= this.outs.length) return ONE txTmp.outs = txTmp.outs.slice(0, nOut + 1)