Browse Source

Merge pull request #650 from bitcoinjs/no10

drop 0.10 support
hk-custom-address
JP Richardson 8 years ago
committed by GitHub
parent
commit
80b1b50155
  1. 1
      .travis.yml
  2. 5
      package.json
  3. 5
      src/block.js
  4. 8
      src/bufferutils.js
  5. 9
      src/transaction_builder.js
  6. 19
      test/bufferutils.js

1
.travis.yml

@ -3,7 +3,6 @@ language: node_js
before_install: before_install:
- npm install npm -g - npm install npm -g
node_js: node_js:
- "0.10"
- "0.12" - "0.12"
- "io.js" - "io.js"
- "4" - "4"

5
package.json

@ -3,6 +3,9 @@
"version": "2.3.0", "version": "2.3.0",
"description": "Client-side Bitcoin JavaScript library", "description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js", "main": "./src/index.js",
"engines" : {
"node" : ">=0.12"
},
"keywords": [ "keywords": [
"bitcoin", "bitcoin",
"browser", "browser",
@ -51,8 +54,6 @@
"bigi": "^1.4.0", "bigi": "^1.4.0",
"bip66": "^1.1.0", "bip66": "^1.1.0",
"bs58check": "^1.0.5", "bs58check": "^1.0.5",
"buffer-compare": "^1.1.0",
"buffer-equals": "^1.0.3",
"buffer-reverse": "^1.0.0", "buffer-reverse": "^1.0.0",
"create-hash": "^1.1.0", "create-hash": "^1.1.0",
"create-hmac": "^1.1.3", "create-hmac": "^1.1.3",

5
src/block.js

@ -1,7 +1,6 @@
var createHash = require('create-hash') var createHash = require('create-hash')
var bufferutils = require('./bufferutils') var bufferutils = require('./bufferutils')
var bcrypto = require('./crypto') var bcrypto = require('./crypto')
var bufferCompare = require('buffer-compare')
var bufferReverse = require('buffer-reverse') var bufferReverse = require('buffer-reverse')
var Transaction = require('./transaction') var Transaction = require('./transaction')
@ -160,14 +159,14 @@ Block.prototype.checkMerkleRoot = function () {
if (!this.transactions) return false if (!this.transactions) return false
var actualMerkleRoot = Block.calculateMerkleRoot(this.transactions) var actualMerkleRoot = Block.calculateMerkleRoot(this.transactions)
return bufferCompare(this.merkleRoot, actualMerkleRoot) === 0 return this.merkleRoot.compare(actualMerkleRoot) === 0
} }
Block.prototype.checkProofOfWork = function () { Block.prototype.checkProofOfWork = function () {
var hash = bufferReverse(this.getHash()) var hash = bufferReverse(this.getHash())
var target = Block.calculateTarget(this.bits) var target = Block.calculateTarget(this.bits)
return bufferCompare(hash, target) <= 0 return hash.compare(target) <= 0
} }
module.exports = Block module.exports = Block

8
src/bufferutils.js

@ -168,15 +168,17 @@ function varIntBuffer (i) {
} }
module.exports = { module.exports = {
equal: require('buffer-equals'),
pushDataSize: pushDataSize, pushDataSize: pushDataSize,
readPushDataInt: readPushDataInt, readPushDataInt: readPushDataInt,
readUInt64LE: readUInt64LE, readUInt64LE: readUInt64LE,
readVarInt: readVarInt, readVarInt: readVarInt,
reverse: require('buffer-reverse'),
varIntBuffer: varIntBuffer, varIntBuffer: varIntBuffer,
varIntSize: varIntSize, varIntSize: varIntSize,
writePushDataInt: writePushDataInt, writePushDataInt: writePushDataInt,
writeUInt64LE: writeUInt64LE, 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
src/transaction_builder.js

@ -1,7 +1,6 @@
var baddress = require('./address') var baddress = require('./address')
var bcrypto = require('./crypto') var bcrypto = require('./crypto')
var bscript = require('./script') var bscript = require('./script')
var bufferEquals = require('buffer-equals')
var bufferReverse = require('buffer-reverse') var bufferReverse = require('buffer-reverse')
var networks = require('./networks') var networks = require('./networks')
var ops = require('./opcodes.json') var ops = require('./opcodes.json')
@ -103,7 +102,7 @@ function expandOutput (script, ourPubKey) {
var pkh1 = scriptChunks[2] var pkh1 = scriptChunks[2]
var pkh2 = bcrypto.hash160(ourPubKey) var pkh2 = bcrypto.hash160(ourPubKey)
if (bufferEquals(pkh1, pkh2)) pubKeys = [ourPubKey] if (pkh1.equals(pkh2)) pubKeys = [ourPubKey]
break break
case 'pubkey': case 'pubkey':
@ -189,7 +188,7 @@ function prepareInput (input, kpPubKey, redeemScript, hashType) {
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH') if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1] 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 // or, we don't have a prevOutScript, so generate a P2SH script
} else { } else {
@ -454,7 +453,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
if (canSign) { if (canSign) {
// if redeemScript was provided, enforce consistency // if redeemScript was provided, enforce consistency
if (redeemScript) { 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') if (input.hashType !== hashType) throw new Error('Inconsistent hashType')
@ -468,7 +467,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
// enforce in order signing of public keys // enforce in order signing of public keys
var valid = input.pubKeys.some(function (pubKey, i) { 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') if (input.signatures[i]) throw new Error('Signature already exists')
input.signatures[i] = keyPair.sign(signatureHash) input.signatures[i] = keyPair.sign(signatureHash)

19
test/bufferutils.js

@ -6,6 +6,25 @@ var bufferutils = require('../src/bufferutils')
var fixtures = require('./fixtures/bufferutils.json') var fixtures = require('./fixtures/bufferutils.json')
describe('bufferutils', function () { 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 () { describe('pushDataSize', function () {
fixtures.valid.forEach(function (f) { fixtures.valid.forEach(function (f) {
it('determines the pushDataSize of ' + f.dec + ' correctly', function () { it('determines the pushDataSize of ' + f.dec + ' correctly', function () {

Loading…
Cancel
Save