bitcoinjs-lib
Advanced tools
Comparing version 3.0.3 to 3.1.0
{ | ||
"name": "bitcoinjs-lib", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "Client-side Bitcoin JavaScript library", | ||
@@ -64,2 +64,3 @@ "main": "./src/index.js", | ||
"randombytes": "^2.0.1", | ||
"safe-buffer": "^5.0.1", | ||
"typeforce": "^1.8.7", | ||
@@ -66,0 +67,0 @@ "varuint-bitcoin": "^1.0.4", |
@@ -91,3 +91,3 @@ # BitcoinJS (bitcoinjs-lib) | ||
[You can either download them directly](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_%3E%3Dv0.17.x/bitcoinjs-lib_v2.x.x.js) from the repo, or with the flow-typed CLI | ||
[You can either download them directly](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js) from the repo, or with the flow-typed CLI | ||
@@ -105,3 +105,3 @@ # npm install -g flow-typed | ||
- [Generate a address from a SHA256 hash](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/basic.js#L20) | ||
- [Generate a address and WIF for Litecoin](https://github.com/bitcoin/bitcoinjs-lib/blob/d853806/test/integration/basic.js#L29) | ||
- [Generate a address and WIF for Litecoin](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/basic.js#L30) | ||
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/basic.js#L43) | ||
@@ -108,0 +108,0 @@ - [Create a Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/d853806/test/integration/basic.js#L50) |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var bs58check = require('bs58check') | ||
@@ -12,3 +13,3 @@ var bscript = require('./script') | ||
var version = payload[0] | ||
var version = payload.readUInt8(0) | ||
var hash = payload.slice(1) | ||
@@ -22,3 +23,3 @@ | ||
var payload = new Buffer(21) | ||
var payload = Buffer.allocUnsafe(21) | ||
payload.writeUInt8(version, 0) | ||
@@ -25,0 +26,0 @@ hash.copy(payload, 1) |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var bcrypto = require('./crypto') | ||
@@ -81,3 +82,3 @@ var fastMerkleRoot = require('merkle-lib/fastRoot') | ||
Block.fromHex = function (hex) { | ||
return Block.fromBuffer(new Buffer(hex, 'hex')) | ||
return Block.fromBuffer(Buffer.from(hex, 'hex')) | ||
} | ||
@@ -102,3 +103,3 @@ | ||
Block.prototype.toBuffer = function (headersOnly) { | ||
var buffer = new Buffer(this.byteLength(headersOnly)) | ||
var buffer = Buffer.allocUnsafe(this.byteLength(headersOnly)) | ||
@@ -148,4 +149,3 @@ var offset = 0 | ||
var mantissa = bits & 0x007fffff | ||
var target = new Buffer(32) | ||
target.fill(0) | ||
var target = Buffer.alloc(32, 0) | ||
target.writeUInt32BE(mantissa, 28 - exponent) | ||
@@ -152,0 +152,0 @@ return target |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var createHmac = require('create-hmac') | ||
@@ -8,4 +9,4 @@ var typeforce = require('typeforce') | ||
var ZERO = new Buffer([0]) | ||
var ONE = new Buffer([1]) | ||
var ZERO = Buffer.alloc(1, 0) | ||
var ONE = Buffer.alloc(1, 1) | ||
@@ -23,11 +24,7 @@ var ecurve = require('ecurve') | ||
var k = new Buffer(32) | ||
var v = new Buffer(32) | ||
// Step A, ignored as hash already provided | ||
// Step B | ||
v.fill(1) | ||
// Step C | ||
k.fill(0) | ||
var k = Buffer.alloc(32, 0) | ||
var v = Buffer.alloc(32, 1) | ||
@@ -34,0 +31,0 @@ // Step D |
@@ -61,5 +61,4 @@ var bip66 = require('bip66') | ||
var buffer = new Buffer(65) | ||
var buffer = Buffer.alloc(65) | ||
buffer.writeUInt8(i, 0) | ||
this.r.toBuffer(32).copy(buffer, 1) | ||
@@ -72,4 +71,4 @@ this.s.toBuffer(32).copy(buffer, 33) | ||
ECSignature.prototype.toDER = function () { | ||
var r = new Buffer(this.r.toDERInteger()) | ||
var s = new Buffer(this.s.toDERInteger()) | ||
var r = Buffer.from(this.r.toDERInteger()) | ||
var s = Buffer.from(this.s.toDERInteger()) | ||
@@ -83,3 +82,3 @@ return bip66.encode(r, s) | ||
var hashTypeBuffer = new Buffer(1) | ||
var hashTypeBuffer = Buffer.alloc(1) | ||
hashTypeBuffer.writeUInt8(hashType, 0) | ||
@@ -86,0 +85,0 @@ |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var base58check = require('bs58check') | ||
@@ -28,3 +29,3 @@ var bcrypto = require('./crypto') | ||
HDNode.LENGTH = 78 | ||
HDNode.MASTER_SECRET = new Buffer('Bitcoin seed') | ||
HDNode.MASTER_SECRET = Buffer.from('Bitcoin seed', 'utf8') | ||
@@ -52,3 +53,3 @@ HDNode.fromSeedBuffer = function (seed, network) { | ||
HDNode.fromSeedHex = function (hex, network) { | ||
return HDNode.fromSeedBuffer(new Buffer(hex, 'hex'), network) | ||
return HDNode.fromSeedBuffer(Buffer.from(hex, 'hex'), network) | ||
} | ||
@@ -173,3 +174,3 @@ | ||
var version = (!this.isNeutered()) ? network.bip32.private : network.bip32.public | ||
var buffer = new Buffer(78) | ||
var buffer = Buffer.allocUnsafe(78) | ||
@@ -212,3 +213,3 @@ // 4 bytes: version bytes | ||
var isHardened = index >= HDNode.HIGHEST_BIT | ||
var data = new Buffer(37) | ||
var data = Buffer.allocUnsafe(37) | ||
@@ -215,0 +216,0 @@ // Hardened child |
@@ -0,1 +1,3 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
function decode (buffer, maxLength, minimal) { | ||
@@ -19,4 +21,4 @@ maxLength = maxLength || 4 | ||
if (b & 0x80) return -((b & ~0x80) * 0x100000000 + a) | ||
return b * 0x100000000 + a | ||
if (b & 0x80) return -(((b & ~0x80) * 0x100000000) + a) | ||
return (b * 0x100000000) + a | ||
} | ||
@@ -47,3 +49,3 @@ | ||
var size = scriptNumSize(value) | ||
var buffer = new Buffer(size) | ||
var buffer = Buffer.allocUnsafe(size) | ||
var negative = number < 0 | ||
@@ -50,0 +52,0 @@ |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var bip66 = require('bip66') | ||
@@ -47,3 +48,3 @@ var pushdata = require('pushdata-bitcoin') | ||
var buffer = new Buffer(bufferSize) | ||
var buffer = Buffer.allocUnsafe(bufferSize) | ||
var offset = 0 | ||
@@ -146,3 +147,3 @@ | ||
// data! | ||
return new Buffer(chunkStr, 'hex') | ||
return Buffer.from(chunkStr, 'hex') | ||
})) | ||
@@ -157,3 +158,3 @@ } | ||
if (Buffer.isBuffer(op)) return op | ||
if (op === OPS.OP_0) return new Buffer(0) | ||
if (op === OPS.OP_0) return Buffer.allocUnsafe(0) | ||
@@ -160,0 +161,0 @@ return scriptNumber.encode(op - OP_INT_BASE) |
// OP_0 [signatures ...] | ||
var Buffer = require('safe-buffer').Buffer | ||
var bscript = require('../../script') | ||
@@ -24,2 +25,4 @@ var typeforce = require('typeforce') | ||
var EMPTY_BUFFER = Buffer.allocUnsafe(0) | ||
function encodeStack (signatures, scriptPubKey) { | ||
@@ -40,3 +43,3 @@ typeforce([partialSignature], signatures) | ||
return [].concat(new Buffer(0), signatures) | ||
return [].concat(EMPTY_BUFFER, signatures) | ||
} | ||
@@ -43,0 +46,0 @@ |
// <scriptSig> {serialized scriptPubKey script} | ||
var Buffer = require('safe-buffer').Buffer | ||
var bscript = require('../../script') | ||
@@ -4,0 +5,0 @@ var typeforce = require('typeforce') |
// OP_RETURN {aa21a9ed} {commitment} | ||
var Buffer = require('safe-buffer').Buffer | ||
var bscript = require('../../script') | ||
@@ -8,3 +9,3 @@ var types = require('../../types') | ||
var HEADER = new Buffer('aa21a9ed', 'hex') | ||
var HEADER = Buffer.from('aa21a9ed', 'hex') | ||
@@ -25,3 +26,7 @@ function check (script) { | ||
return bscript.compile([OPS.OP_RETURN, Buffer.concat([HEADER, commitment])]) | ||
var buffer = Buffer.allocUnsafe(36) | ||
HEADER.copy(buffer, 0) | ||
commitment.copy(buffer, 4) | ||
return bscript.compile([OPS.OP_RETURN, buffer]) | ||
} | ||
@@ -28,0 +33,0 @@ |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var baddress = require('./address') | ||
@@ -370,5 +371,5 @@ var bcrypto = require('./crypto') | ||
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) { | ||
@@ -519,3 +520,3 @@ if (signatures.length > 0) { | ||
// transaction hashs's are displayed in reverse order, un-reverse it | ||
txHash = new Buffer(txHash, 'hex').reverse() | ||
txHash = Buffer.from(txHash, 'hex').reverse() | ||
@@ -522,0 +523,0 @@ // is it a Transaction object? |
@@ -0,1 +1,2 @@ | ||
var Buffer = require('safe-buffer').Buffer | ||
var bcrypto = require('./crypto') | ||
@@ -38,7 +39,7 @@ var bscript = require('./script') | ||
var EMPTY_SCRIPT = new Buffer(0) | ||
var EMPTY_SCRIPT = Buffer.allocUnsafe(0) | ||
var EMPTY_WITNESS = [] | ||
var ZERO = new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex') | ||
var ONE = new Buffer('0000000000000000000000000000000000000000000000000000000000000001', 'hex') | ||
var VALUE_UINT64_MAX = new Buffer('ffffffffffffffff', 'hex') | ||
var ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex') | ||
var ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex') | ||
var VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex') | ||
var BLANK_OUTPUT = { | ||
@@ -194,2 +195,12 @@ script: EMPTY_SCRIPT, | ||
Transaction.prototype.weight = function () { | ||
var base = this.__byteLength(false) | ||
var total = this.__byteLength(true) | ||
return base * 3 + total | ||
} | ||
Transaction.prototype.virtualSize = function () { | ||
return Math.ceil(this.weight() / 4) | ||
} | ||
Transaction.prototype.byteLength = function () { | ||
@@ -303,3 +314,3 @@ return this.__byteLength(true) | ||
// serialize and hash | ||
var buffer = new Buffer(txTmp.__byteLength(false) + 4) | ||
var buffer = Buffer.allocUnsafe(txTmp.__byteLength(false) + 4) | ||
buffer.writeInt32LE(hashType, buffer.length - 4) | ||
@@ -329,3 +340,3 @@ txTmp.__toBuffer(buffer, 0, false) | ||
if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) { | ||
tbuffer = new Buffer(36 * this.ins.length) | ||
tbuffer = Buffer.allocUnsafe(36 * this.ins.length) | ||
toffset = 0 | ||
@@ -344,3 +355,3 @@ | ||
(hashType & 0x1f) !== Transaction.SIGHASH_NONE) { | ||
tbuffer = new Buffer(4 * this.ins.length) | ||
tbuffer = Buffer.allocUnsafe(4 * this.ins.length) | ||
toffset = 0 | ||
@@ -361,3 +372,3 @@ | ||
tbuffer = new Buffer(txOutsSize) | ||
tbuffer = Buffer.allocUnsafe(txOutsSize) | ||
toffset = 0 | ||
@@ -374,3 +385,3 @@ | ||
tbuffer = new Buffer(8 + varSliceSize(output.script)) | ||
tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script)) | ||
toffset = 0 | ||
@@ -383,3 +394,3 @@ writeUInt64(output.value) | ||
tbuffer = new Buffer(156 + varSliceSize(prevOutScript)) | ||
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript)) | ||
toffset = 0 | ||
@@ -416,3 +427,3 @@ | ||
Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitness) { | ||
if (!buffer) buffer = new Buffer(this.__byteLength(__allowWitness)) | ||
if (!buffer) buffer = Buffer.allocUnsafe(this.__byteLength(__allowWitness)) | ||
@@ -419,0 +430,0 @@ var offset = initialOffset || 0 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108983
2613
14
+ Addedsafe-buffer@^5.0.1