upgrade bigi & remove monkey patching
This commit is contained in:
parent
39516d5532
commit
af1f121fd4
13 changed files with 12 additions and 95 deletions
|
@ -42,7 +42,7 @@
|
|||
"compile": "./node_modules/.bin/browserify ./src/index.js -s Bitcoin | ./node_modules/.bin/uglifyjs > bitcoinjs-min.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bigi": "0.2.0",
|
||||
"bigi": "1.0.0",
|
||||
"crypto-js": "3.1.2-3",
|
||||
"secure-random": "0.2.1"
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// Merged Buffer refactorings from base58-native by Stephen Pair
|
||||
// Copyright (c) 2013 BitPay Inc
|
||||
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
|
||||
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
var ALPHABET_BUF = new Buffer(ALPHABET, 'ascii')
|
||||
|
|
38
src/bigi.js
38
src/bigi.js
|
@ -1,38 +0,0 @@
|
|||
var assert = require('assert')
|
||||
var BigInteger = require('bigi')
|
||||
|
||||
// Import operations
|
||||
BigInteger.fromHex = function(hex) {
|
||||
var buffer = new Buffer(hex, 'hex')
|
||||
assert.equal(buffer.length, Buffer.byteLength(hex) / 2)
|
||||
|
||||
return BigInteger.fromBuffer(buffer)
|
||||
}
|
||||
|
||||
BigInteger.fromBuffer = function(buffer) {
|
||||
assert(Array.isArray(buffer) || Buffer.isBuffer(buffer)) // FIXME: Transitionary
|
||||
|
||||
// FIXME: Transitionary
|
||||
if (Buffer.isBuffer(buffer)) {
|
||||
buffer = Array.prototype.slice.call(buffer)
|
||||
}
|
||||
|
||||
return BigInteger.fromByteArrayUnsigned(buffer)
|
||||
}
|
||||
|
||||
// Export operations
|
||||
BigInteger.prototype.toBuffer = function(s) {
|
||||
if (s != undefined) assert(Number.isFinite(s))
|
||||
|
||||
var buffer = new Buffer(this.toByteArrayUnsigned())
|
||||
var padded = new Buffer(s - buffer.length)
|
||||
padded.fill(0)
|
||||
|
||||
return Buffer.concat([padded, buffer], s)
|
||||
}
|
||||
|
||||
BigInteger.prototype.toHex = function(s) {
|
||||
return this.toBuffer(s).toString('hex')
|
||||
}
|
||||
|
||||
module.exports = BigInteger
|
|
@ -2,7 +2,7 @@
|
|||
// Ported loosely from BouncyCastle's Java EC code
|
||||
// Only Fp curves implemented for now
|
||||
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
|
||||
function ECFieldElementFp(q,x) {
|
||||
this.x = x;
|
||||
|
|
|
@ -3,7 +3,7 @@ var crypto = require('crypto')
|
|||
var sec = require('./sec')
|
||||
var ecparams = sec("secp256k1")
|
||||
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
var ECPointFp = require('./ec').ECPointFp
|
||||
|
||||
var P_OVER_FOUR = null
|
||||
|
@ -178,6 +178,8 @@ var ecdsa = {
|
|||
* }
|
||||
*/
|
||||
parseSig: function (sig) {
|
||||
if(Array.isArray(sig)) sig = new Buffer(sig);
|
||||
|
||||
var cursor
|
||||
if (sig[0] != 0x30) {
|
||||
throw new Error("Signature not a valid DERSequence")
|
||||
|
|
|
@ -10,7 +10,7 @@ var crypto = require('./crypto')
|
|||
var sec = require('./sec')
|
||||
var ecparams = sec('secp256k1')
|
||||
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
var ECPointFp = require('./ec').ECPointFp
|
||||
|
||||
function ECKey(D, compressed) {
|
||||
|
|
|
@ -3,7 +3,7 @@ var base58 = require('./base58')
|
|||
var convert = require('./convert')
|
||||
|
||||
var Address = require('./address')
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
var CJS = require('crypto-js')
|
||||
var crypto = require('./crypto')
|
||||
var ECKey = require('./eckey').ECKey
|
||||
|
|
|
@ -6,7 +6,6 @@ module.exports = {
|
|||
Address: require('./address'),
|
||||
base58: require('./base58'),
|
||||
base58check: require('./base58check'),
|
||||
BigInteger: require('./bigi'),
|
||||
convert: require('./convert'),
|
||||
crypto: require('./crypto'),
|
||||
ec: ec,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Named EC curves
|
||||
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
var ECCurveFp = require('./ec')
|
||||
var ECPointFp = ECCurveFp.ECPointFp
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
var assert = require('assert')
|
||||
var Address = require('./address')
|
||||
var BigInteger = require('./bigi')
|
||||
var BigInteger = require('bigi')
|
||||
var Script = require('./script')
|
||||
var convert = require('./convert')
|
||||
var crypto = require('./crypto')
|
||||
|
|
46
test/bigi.js
46
test/bigi.js
|
@ -1,46 +0,0 @@
|
|||
var assert = require('assert')
|
||||
var BigInteger = require('../').BigInteger
|
||||
|
||||
var fixtures = require('./fixtures/bigi')
|
||||
|
||||
describe('BigInteger', function() {
|
||||
describe('fromBuffer/fromHex', function() {
|
||||
it('should match the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
assert.equal(BigInteger.fromHex(f.hex).toString(), f.dec)
|
||||
assert.equal(BigInteger.fromHex(f.hexPadded).toString(), f.dec)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.forEach(function(f) {
|
||||
it('throws on ' + f.description, function() {
|
||||
assert.throws(function() {
|
||||
BigInteger.fromHex(f.string)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toBuffer/toHex', function() {
|
||||
it('should match the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var bi = new BigInteger(f.dec)
|
||||
|
||||
assert.equal(bi.toHex(), f.hex)
|
||||
assert.equal(bi.toHex(32), f.hexPadded)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws on non-finite padding value', function() {
|
||||
var bi = new BigInteger('1')
|
||||
|
||||
assert.throws(function() { bi.toHex({}) })
|
||||
assert.throws(function() { bi.toHex([]) })
|
||||
assert.throws(function() { bi.toHex('') })
|
||||
assert.throws(function() { bi.toHex(0 / 0) })
|
||||
assert.throws(function() { bi.toHex(1 / 0) })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = BigInteger
|
|
@ -3,7 +3,7 @@ var assert = require('assert')
|
|||
var sec = require('../').sec
|
||||
var ecparams = sec('secp256k1')
|
||||
|
||||
var BigInteger = require('..').BigInteger
|
||||
var BigInteger = require('bigi')
|
||||
var ECPointFp = require('../').ECPointFp
|
||||
|
||||
describe('ec', function() {
|
||||
|
|
|
@ -4,7 +4,7 @@ var ecdsa = require('..').ecdsa
|
|||
var sec = require('..').sec
|
||||
var ecparams = sec("secp256k1")
|
||||
|
||||
var BigInteger = require('..').BigInteger
|
||||
var BigInteger = require('bigi')
|
||||
var ECKey = require('..').ECKey
|
||||
var ECPubKey = require('..').ECPubKey
|
||||
var Message = require('..').Message
|
||||
|
|
Loading…
Reference in a new issue