Skip to content

Commit

Permalink
Merge pull request #650 from bitcoinjs/no10
Browse files Browse the repository at this point in the history
drop 0.10 support
  • Loading branch information
jprichardson authored Oct 6, 2016
2 parents 3d9e228 + fd40232 commit 80b1b50
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: node_js
before_install:
- npm install npm -g
node_js:
- "0.10"
- "0.12"
- "io.js"
- "4"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "2.3.0",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"engines" : {
"node" : ">=0.12"
},
"keywords": [
"bitcoin",
"browser",
Expand Down Expand Up @@ -51,8 +54,6 @@
"bigi": "^1.4.0",
"bip66": "^1.1.0",
"bs58check": "^1.0.5",
"buffer-compare": "^1.1.0",
"buffer-equals": "^1.0.3",
"buffer-reverse": "^1.0.0",
"create-hash": "^1.1.0",
"create-hmac": "^1.1.3",
Expand Down
5 changes: 2 additions & 3 deletions src/block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var createHash = require('create-hash')
var bufferutils = require('./bufferutils')
var bcrypto = require('./crypto')
var bufferCompare = require('buffer-compare')
var bufferReverse = require('buffer-reverse')

var Transaction = require('./transaction')
Expand Down Expand Up @@ -160,14 +159,14 @@ Block.prototype.checkMerkleRoot = function () {
if (!this.transactions) return false

var actualMerkleRoot = Block.calculateMerkleRoot(this.transactions)
return bufferCompare(this.merkleRoot, actualMerkleRoot) === 0
return this.merkleRoot.compare(actualMerkleRoot) === 0
}

Block.prototype.checkProofOfWork = function () {
var hash = bufferReverse(this.getHash())
var target = Block.calculateTarget(this.bits)

return bufferCompare(hash, target) <= 0
return hash.compare(target) <= 0
}

module.exports = Block
8 changes: 5 additions & 3 deletions src/bufferutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,17 @@ function varIntBuffer (i) {
}

module.exports = {
equal: require('buffer-equals'),
pushDataSize: pushDataSize,
readPushDataInt: readPushDataInt,
readUInt64LE: readUInt64LE,
readVarInt: readVarInt,
reverse: require('buffer-reverse'),
varIntBuffer: varIntBuffer,
varIntSize: varIntSize,
writePushDataInt: writePushDataInt,
writeUInt64LE: writeUInt64LE,
writeVarInt: writeVarInt
writeVarInt: writeVarInt,

// TODO: remove in 3.0.0
equal: function BufferEquals (a, b) { return a.equals(b) },
reverse: require('buffer-reverse')
}
9 changes: 4 additions & 5 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var baddress = require('./address')
var bcrypto = require('./crypto')
var bscript = require('./script')
var bufferEquals = require('buffer-equals')
var bufferReverse = require('buffer-reverse')
var networks = require('./networks')
var ops = require('./opcodes.json')
Expand Down Expand Up @@ -103,7 +102,7 @@ function expandOutput (script, ourPubKey) {

var pkh1 = scriptChunks[2]
var pkh2 = bcrypto.hash160(ourPubKey)
if (bufferEquals(pkh1, pkh2)) pubKeys = [ourPubKey]
if (pkh1.equals(pkh2)) pubKeys = [ourPubKey]
break

case 'pubkey':
Expand Down Expand Up @@ -189,7 +188,7 @@ function prepareInput (input, kpPubKey, redeemScript, hashType) {
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')

var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
if (!bufferEquals(prevOutScriptScriptHash, redeemScriptHash)) throw new Error('Inconsistent hash160(RedeemScript)')
if (!prevOutScriptScriptHash.equals(redeemScriptHash)) throw new Error('Inconsistent hash160(RedeemScript)')

// or, we don't have a prevOutScript, so generate a P2SH script
} else {
Expand Down Expand Up @@ -454,7 +453,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
if (canSign) {
// if redeemScript was provided, enforce consistency
if (redeemScript) {
if (!bufferEquals(input.redeemScript, redeemScript)) throw new Error('Inconsistent redeemScript')
if (!input.redeemScript.equals(redeemScript)) throw new Error('Inconsistent redeemScript')
}

if (input.hashType !== hashType) throw new Error('Inconsistent hashType')
Expand All @@ -468,7 +467,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy

// enforce in order signing of public keys
var valid = input.pubKeys.some(function (pubKey, i) {
if (!bufferEquals(kpPubKey, pubKey)) return false
if (!kpPubKey.equals(pubKey)) return false
if (input.signatures[i]) throw new Error('Signature already exists')

input.signatures[i] = keyPair.sign(signatureHash)
Expand Down
19 changes: 19 additions & 0 deletions test/bufferutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ var bufferutils = require('../src/bufferutils')
var fixtures = require('./fixtures/bufferutils.json')

describe('bufferutils', function () {
// TODO: remove
describe('equals', function () {
it('works', function () {
var a = new Buffer('abcd', 'hex')
var b = new Buffer('bbbb', 'hex')

assert.strictEqual(bufferutils.equal(a, a), true)
assert.strictEqual(bufferutils.equal(a, b), false)
})
})

describe('reverse', function () {
it('works', function () {
var a = new Buffer('abcd', 'hex')

assert.strictEqual(bufferutils.reverse(a).toString('hex'), 'cdab')
})
})

describe('pushDataSize', function () {
fixtures.valid.forEach(function (f) {
it('determines the pushDataSize of ' + f.dec + ' correctly', function () {
Expand Down

0 comments on commit 80b1b50

Please sign in to comment.