Socket
Socket
Sign inDemoInstall

bitcore-lib-cash

Package Overview
Dependencies
Maintainers
3
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-lib-cash - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

lib/crypto/schnorr.js

1

index.js

@@ -22,2 +22,3 @@ 'use strict';

bitcore.crypto.ECDSA = require('./lib/crypto/ecdsa');
bitcore.crypto.Schnorr = require('./lib/crypto/schnorr');
bitcore.crypto.Hash = require('./lib/crypto/hash');

@@ -24,0 +25,0 @@ bitcore.crypto.Random = require('./lib/crypto/random');

@@ -273,2 +273,16 @@ 'use strict';

/**
* Creates a P2SH Zero-Confirmation Escrow (ZCE) address from a set of input public keys and a reclaim public key.
*
* @param {Array} inputPublicKeys - the set of public keys needed to sign all inputs in a ZCE transaction
* @param {PublicKey} reclaimPublicKey - the public key required to reclaim the escrow
* @param {String|Network} network - either a Network instance, 'livenet', or 'testnet'
* @return {Address}
*/
Address.createEscrow = function(inputPublicKeys, reclaimPublicKey, network) {
const zceRedeemScript = Script.buildEscrowOut(inputPublicKeys, reclaimPublicKey);
network = network || reclaimPublicKey.network || Networks.defaultNetwork;
return Address.payingTo(zceRedeemScript, network);
};
function decodeCashAddress(address) {

@@ -359,3 +373,3 @@

info.hashBuffer = new Buffer(hash);
info.hashBuffer = Buffer.from(hash);
info.network = network;

@@ -591,3 +605,3 @@ info.type = type;

Address.prototype.toBuffer = function() {
var version = new Buffer([this.network[this.type]]);
var version = Buffer.from([this.network[this.type]]);
var buf = Buffer.concat([version, this.hashBuffer]);

@@ -626,3 +640,3 @@ return buf;

Address.prototype.toCashBuffer = function() {
var version = new Buffer([this.network[this.type]]);
var version = Buffer.from([this.network[this.type]]);
var buf = Buffer.concat([version, this.hashBuffer]);

@@ -629,0 +643,0 @@ return buf;

@@ -190,2 +190,32 @@ 'use strict';

BN.prototype.getSize = function() {
const bin = this.toString(2).replace('-', '');
const numBits = bin.length + 1;
return numBits / 8;
};
BN.prototype.checkOperationForOverflow = function (operand, result, maxSize) {
if (this.getSize() > maxSize || operand.getSize() > maxSize || result.getSize() > 8) {
throw new Error('overflow');
}
};
BN.prototype.safeAdd = function(bigNumToAdd, maxSize) {
const sum = this.add(bigNumToAdd);
this.checkOperationForOverflow(bigNumToAdd, sum, maxSize);
return sum;
};
BN.prototype.safeSub = function(bigNumToSubtract, maxSize) {
const difference = this.sub(bigNumToSubtract);
this.checkOperationForOverflow(bigNumToSubtract, difference, maxSize);
return difference;
};
BN.prototype.safeMul = function(bigNumToMultiply, maxSize) {
const product = this.mul(bigNumToMultiply);
this.checkOperationForOverflow(bigNumToMultiply, product, maxSize);
return product;
};
module.exports = BN;

@@ -152,2 +152,16 @@ 'use strict';

// todo: needs test case
Point.prototype.hasSquare = function() {
return !this.isInfinity() && this.isSquare(this.getY());
}
// todo: needs test cases
Point.prototype.isSquare = function(x) {
let p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex');
let x0 = new BN(x);
let base = x0.toRed(BN.red(p));
let res = base.redPow(p.sub(BN.One).div(new BN(2))).fromRed(); //refactor to BN arithmetic operations
return res.eq(new BN(1));
}
module.exports = Point;

@@ -9,5 +9,5 @@ 'use strict';

var Signature = function Signature(r, s) {
var Signature = function Signature(r, s, isSchnorr) {
if (!(this instanceof Signature)) {
return new Signature(r, s);
return new Signature(r, s, isSchnorr);
}

@@ -17,3 +17,4 @@ if (r instanceof BN) {

r: r,
s: s
s: s,
isSchnorr: isSchnorr,
});

@@ -33,3 +34,4 @@ } else if (r) {

this.compressed = typeof obj.compressed !== 'undefined' ?
obj.compressed : this.compressed; //whether the recovered pubkey is compressed
obj.compressed : this.compressed; // whether the recovered pubkey is compressed
this.isSchnorr = obj.isSchnorr;
this.nhashtype = obj.nhashtype || this.nhashtype || undefined;

@@ -67,2 +69,14 @@ return this;

Signature.fromDER = Signature.fromBuffer = function(buf, strict) {
// Schnorr Signatures use 65 byte for in tx r [len] 32 , s [len] 32, nhashtype
if((buf.length === 64 || buf.length === 65) && buf[0] != 0x30) {
let obj = Signature.parseSchnorrEncodedSig(buf);
let sig = new Signature();
sig.r = obj.r;
sig.s = obj.s;
sig.isSchnorr = true;
return sig;
} if (buf.length === 64 && buf[0] === 0x30) {
return "64 DER (ecdsa) signatures not allowed";
}
var obj = Signature.parseDER(buf, strict);

@@ -97,2 +111,3 @@ var sig = new Signature();

var buf = Buffer.from(str, 'hex');
return Signature.fromDER(buf);

@@ -102,2 +117,20 @@ };

Signature.parseSchnorrEncodedSig = function(buf) {
let r = buf.slice(0,32);
let s = buf.slice(32, 64);
let hashtype;
if (buf.length === 65) {
hashtype = buf.slice(64,65);
this.nhashtype = hashtype;
}
var obj = {
r: BN.fromBuffer(r),
s: BN.fromBuffer(s),
nhashtype: hashtype
};
return obj;
};
/**

@@ -183,6 +216,16 @@ * In order to mimic the non-strict DER encoding of OpenSSL, set strict = false.

Signature.prototype.toBuffer = Signature.prototype.toDER = function() {
Signature.prototype.toBuffer = Signature.prototype.toDER = function(signingMethod) {
// Schnorr signatures use a 64 byte r,s format, where as ECDSA takes the form decribed
// below, above the isDER function signature.
signingMethod = signingMethod || "ecdsa";
if(signingMethod === "schnorr") {
return Buffer.concat([this.r.toBuffer({size: 32}), this.s.toBuffer({size: 32})]);
}
var rnbuf = this.r.toBuffer();
var snbuf = this.s.toBuffer();
var rneg = rnbuf[0] & 0x80 ? true : false;

@@ -387,4 +430,4 @@ var sneg = snbuf[0] & 0x80 ? true : false;

Signature.prototype.toTxFormat = function() {
var derbuf = this.toDER();
Signature.prototype.toTxFormat = function(signingMethod) {
var derbuf = this.toDER(signingMethod);
var buf = Buffer.alloc(1);

@@ -391,0 +434,0 @@ buf.writeUInt8(this.nhashtype, 0);

4

lib/encoding/base58check.js

@@ -29,6 +29,6 @@ 'use strict';

if (_.isString(data)) {
data = new buffer.Buffer(Base58.decode(data));
data = Buffer.from(Base58.decode(data));
}
if (_.isString(checksum)) {
checksum = new buffer.Buffer(Base58.decode(checksum));
checksum = Buffer.from(Base58.decode(checksum));
}

@@ -35,0 +35,0 @@ if (!checksum) {

@@ -69,3 +69,10 @@ 'use strict';

message: 'No previous output information.'
}]
}, {
name: 'BlockHeightOutOfRange',
message: 'Block Height can only be between 0 and 65535'
} , {
name: 'LockTimeRange',
message: 'Seconds needs to be more that 0 and less that 33553920'
}
]
}, {

@@ -72,0 +79,0 @@ name: 'NeedMoreInfo',

@@ -242,3 +242,3 @@ 'use strict';

var nonZeroPadded = this.privateKey.bn.toBuffer();
data = BufferUtil.concat([new buffer.Buffer([0]), nonZeroPadded, indexBuffer]);
data = BufferUtil.concat([Buffer.from([0]), nonZeroPadded, indexBuffer]);
} else if (hardened) {

@@ -248,3 +248,3 @@ // This will use a 32 byte zero padded serialization of the private key

assert(privateKeyBuffer.length === 32, 'length of private key buffer is expected to be 32 bytes');
data = BufferUtil.concat([new buffer.Buffer([0]), privateKeyBuffer, indexBuffer]);
data = BufferUtil.concat([Buffer.from([0]), privateKeyBuffer, indexBuffer]);
} else {

@@ -374,4 +374,4 @@ data = BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]);

childIndex: _.isNumber(arg.childIndex) ? BufferUtil.integerAsBuffer(arg.childIndex) : arg.childIndex,
chainCode: _.isString(arg.chainCode) ? BufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode,
privateKey: (_.isString(arg.privateKey) && JSUtil.isHexa(arg.privateKey)) ? BufferUtil.hexToBuffer(arg.privateKey) : arg.privateKey,
chainCode: _.isString(arg.chainCode) ? Buffer.from(arg.chainCode,'hex') : arg.chainCode,
privateKey: (_.isString(arg.privateKey) && JSUtil.isHexa(arg.privateKey)) ? Buffer.from(arg.privateKey,'hex') : arg.privateKey,
checksum: arg.checksum ? (arg.checksum.length ? arg.checksum : BufferUtil.integerAsBuffer(arg.checksum)) : undefined

@@ -412,3 +412,3 @@ };

if (JSUtil.isHexaString(hexa)) {
hexa = BufferUtil.hexToBuffer(hexa);
hexa = Buffer.from(hexa,'hex');
}

@@ -424,3 +424,3 @@ if (!Buffer.isBuffer(hexa)) {

}
var hash = Hash.sha512hmac(hexa, new buffer.Buffer('Bitcoin seed'));
var hash = Hash.sha512hmac(hexa, Buffer.from('Bitcoin seed'));

@@ -589,3 +589,3 @@ return new HDPrivateKey({

childIndex: BufferUtil.integerFromBuffer(this._buffers.childIndex),
chainCode: BufferUtil.bufferToHex(this._buffers.chainCode),
chainCode: this._buffers.chainCode.toString('hex'),
privateKey: this.privateKey.toBuffer().toString('hex'),

@@ -592,0 +592,0 @@ checksum: BufferUtil.integerFromBuffer(this._buffers.checksum),

@@ -284,4 +284,4 @@ 'use strict';

childIndex: _.isNumber(arg.childIndex) ? BufferUtil.integerAsBuffer(arg.childIndex) : arg.childIndex,
chainCode: _.isString(arg.chainCode) ? BufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode,
publicKey: _.isString(arg.publicKey) ? BufferUtil.hexToBuffer(arg.publicKey) :
chainCode: _.isString(arg.chainCode) ? Buffer.from(arg.chainCode,'hex') : arg.chainCode,
publicKey: _.isString(arg.publicKey) ? Buffer.from(arg.publicKey,'hex') :
BufferUtil.isBuffer(arg.publicKey) ? arg.publicKey : arg.publicKey.toBuffer(),

@@ -439,3 +439,3 @@ checksum: _.isNumber(arg.checksum) ? BufferUtil.integerAsBuffer(arg.checksum) : arg.checksum

childIndex: BufferUtil.integerFromBuffer(this._buffers.childIndex),
chainCode: BufferUtil.bufferToHex(this._buffers.chainCode),
chainCode: Buffer.from(this._buffers.chainCode,'hex'),
publicKey: this.publicKey.toString(),

@@ -442,0 +442,0 @@ checksum: BufferUtil.integerFromBuffer(this._buffers.checksum),

@@ -136,10 +136,2 @@ 'use strict';

function unindexNetworkBy(network, values) {
for(var index = 0; index < values.length; index++){
var value = values[index];
if(networkMaps[value] === network) {
delete networkMaps[value];
}
}
}

@@ -153,2 +145,5 @@ /**

function removeNetwork(network) {
if (typeof network !== 'object') {
network = get(network);
}
for (var i = 0; i < networks.length; i++) {

@@ -159,11 +154,25 @@ if (networks[i] === network) {

}
unindexNetworkBy(network, Object.keys(networkMaps));
for (var key in networkMaps) {
if (networkMaps[key].length) {
const index = networkMaps[key].indexOf(network);
if (index >= 0) {
networkMaps[key].splice(index, 1);
}
if (networkMaps[key].length === 0) {
delete networkMaps[key];
}
} else if (networkMaps[key] === network) {
delete networkMaps[key];
}
}
}
// from https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/chainparams.cpp#L212
var dnsSeeds = [
'seed.bitcoinabc.org',
'seed-abc.bitcoinforks.org',
'seed.bitcoinunlimited.info',
'seed.bitprim.org ',
'seed.deadalnix.me'
'btccash-seeder.bitcoinunlimited.info',
'seeder.jasonbcox.com',
'seed.deadalnix.me',
'seed.bchd.cash'
];

@@ -170,0 +179,0 @@

@@ -199,3 +199,6 @@ 'use strict';

// timelocks
OP_NOP2: 177,
OP_CHECKLOCKTIMEVERIFY: 177,
OP_NOP3: 178,
OP_CHECKSEQUENCEVERIFY: 178,

@@ -205,4 +208,2 @@

OP_NOP1: 176,
OP_NOP2: 177,
OP_NOP3: 178,
OP_NOP4: 179,

@@ -219,2 +220,3 @@ OP_NOP5: 180,

OP_CHECKDATASIGVERIFY: 187,
OP_REVERSEBYTES: 188,

@@ -229,3 +231,22 @@ OP_PREFIX_BEGIN: 240,

OP_PUBKEY: 254,
OP_INVALIDOPCODE: 255
OP_INVALIDOPCODE: 255,
// introspection
OP_INPUTINDEX: 192,
OP_ACTIVEBYTECODE: 193,
OP_TXVERSION: 194,
OP_TXINPUTCOUNT: 195,
OP_TXOUTPUTCOUNT: 196,
OP_TXLOCKTIME: 197,
OP_UTXOVALUE: 198,
OP_UTXOBYTECODE: 199,
OP_OUTPOINTTXHASH: 200,
OP_OUTPOINTINDEX: 201,
OP_INPUTBYTECODE: 202,
OP_INPUTSEQUENCENUMBER: 203,
OP_OUTPUTVALUE: 204,
OP_OUTPUTBYTECODE: 205,
OP_RESERVED3: 206,
OP_RESERVED4: 207
};

@@ -232,0 +253,0 @@

@@ -15,2 +15,3 @@ var Address = require('../address');

var JSUtil = require('../util/js');
var Escrow = require('./escrow');

@@ -176,3 +177,3 @@ /**

Script.fromHex = function(str) {
return new Script(new buffer.Buffer(str, 'hex'));
return new Script(Buffer.from(str, 'hex'));
};

@@ -182,3 +183,3 @@

if (JSUtil.isHexa(str) || str.length === 0) {
return new Script(new buffer.Buffer(str, 'hex'));
return new Script(Buffer.from(str, 'hex'));
}

@@ -332,3 +333,2 @@ var script = new Script();

signatureBuf.length &&
signatureBuf[0] === 0x30 &&
pubkeyBuf &&

@@ -351,4 +351,4 @@ pubkeyBuf.length

Script.prototype.getPublicKey = function() {
$.checkState(this.isPublicKeyOut(), 'Can\'t retrieve PublicKey from a non-PK output');
return this.chunks[0].buf;
$.checkState(this.isPublicKeyOut() || this.isPublicKeyHashIn(), "Can't retrieve PublicKey from a non-PK output or non-PKH input");
return this.isPublicKeyOut() ? this.chunks[0].buf : this.chunks[1].buf;
};

@@ -402,2 +402,29 @@

/**
* @param {Object=} values - The return values
* @param {Number} values.version - Set with the witness version
* @param {Buffer} values.program - Set with the witness program
* @returns {boolean} if this is a p2wpkh output script
*/
Script.prototype.isWitnessProgram = function(values) {
if (!values) {
values = {};
}
var buf = this.toBuffer();
if (buf.length < 4 || buf.length > 42) {
return false;
}
if (buf[0] !== Opcode.OP_0 && !(buf[0] >= Opcode.OP_1 && buf[0] <= Opcode.OP_16)) {
return false;
}
if (buf.length === buf[1] + 2) {
values.version = buf[0];
values.program = buf.slice(2, buf.length);
return true;
}
return false;
};
/**
* @returns {boolean} if this is a p2sh output script

@@ -716,2 +743,20 @@ */

/**
* @returns {Script} a new escrow output redeem script for given input public keys and reclaim public key
* @param {PublicKey[]} inputPublicKeys - list of all public keys associated with each P2PKH input of the
* zero-confirmation escrow transaction
* @param {PublicKey} reclaimPublicKey - the public key used to reclaim the escrow by the customer
*/
Script.buildEscrowOut = function(inputPublicKeys, reclaimPublicKey) {
// Escrow redeem scripts support a max of 2^16 input public keys:
// https://github.com/bitjson/bch-zce#zce-root-hash
$.checkArgument(inputPublicKeys.length < 65536, 'Number of input public keys exceeds 65,536');
$.checkArgument(inputPublicKeys.length > 0, 'Must provide at least one input public key');
$.checkArgument(reclaimPublicKey, 'Must provide a reclaim public key');
const redeemScript = new Script();
const redeemScriptOperations = Escrow.generateRedeemScriptOperations(inputPublicKeys, reclaimPublicKey);
redeemScriptOperations.forEach(operation => redeemScript.add(operation));
return redeemScript;
};
/**
* @returns {Script} a new Multisig output script for given public keys,

@@ -765,3 +810,38 @@ * requiring m of those public keys to spend

var s = new Script();
s.add(Opcode.OP_0);
if (opts.signingMethod === "schnorr" && opts.checkBits) {
// Spec according to https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2019-11-15-schnorrmultisig.md#scriptsig-size
let checkBitsString = Buffer.from(opts.checkBits).reverse().join('');
let checkBitsDecimal = parseInt(checkBitsString, 2);
let checkBitsHex = parseInt(checkBitsDecimal.toString(16), 16);
let N = pubkeys.length;
// N should only be 1-20
if (N >= 1 && N <= 4) {
s.add(Opcode(checkBitsHex));
}
else if (N >= 5 && N <= 8) {
if(checkBitsHex === 0x81) {
s.add(Opcode("OP_1NEGATE")) // OP_1NEGATE
} else if(checkBitsHex > 0x10) {
s.add(0x01);
s.add(checkBitsHex);
} else {
s.add(Opcode(checkBitsHex));
}
}
else if (N >= 9 && N <= 16) {
s.add(0x02);
s.add(checkBitsHex);
}
else if (N >= 17 && N <= 20) {
s.add(0x03);
s.add(checkBitsHex);
}
} else {
s.add(Opcode.OP_0); // ecdsa schnorr mode; multisig dummy param of 0
}
_.each(signatures, function(signature) {

@@ -784,2 +864,4 @@ $.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers');

* @param {Script=} opts.cachedMultisig don't recalculate the redeemScript
* @param {Uint8Array} opts.checkBits bitfield map 1 or 0 to check which signatures to map against public keys for verification in schnorr multisig mode
* @param {String} opts.signingMethod method with which input will be signed "ecdsa" or "schnorr"
*

@@ -794,3 +876,36 @@ * @returns {Script}

var s = new Script();
s.add(Opcode.OP_0);
if (opts.signingMethod === "schnorr" && opts.checkBits) {
// Spec according to https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2019-11-15-schnorrmultisig.md#scriptsig-size
let checkBitsString = Buffer.from(opts.checkBits).reverse().join('');
let checkBitsDecimal = parseInt(checkBitsString, 2);
let checkBitsHex = parseInt(checkBitsDecimal.toString(16), 16);
let N = pubkeys.length;
// N should only be 1-20
if (N >= 1 && N <= 4) {
s.add(Opcode.smallInt(checkBitsDecimal));
}
else if (N >= 5 && N <= 8) {
if(checkBitsHex === 0x81) {
s.add(Opcode("OP_1NEGATE")) // OP_1NEGATE
} else if(checkBitsHex > 0x10) {
s.add(0x01);
s.add(checkBitsHex);
} else {
s.add(Opcode.smallInt(checkBitsDecimal));
}
}
else if (N >= 9 && N <= 16) {
s.add(0x02);
s.add(checkBitsHex);
}
else if (N >= 17 && N <= 20) {
s.add(0x03);
s.add(checkBitsHex);
}
} else {
s.add(Opcode.OP_0); // ecdsa schnorr mode; multisig dummy param of 0
}
_.each(signatures, function(signature) {

@@ -919,2 +1034,18 @@ $.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers');

/**
* Builds a scriptSig (a script for an input) that signs an escrow output script.
*
* @param {PublicKey} publicKey
* @param {Signature} signature - a Signature object
* @param {RedeemScript} redeemScript - the escrow redeemScript
*/
Script.buildEscrowIn = function(publicKey, signature, redeemScript) {
$.checkArgument(signature instanceof Signature);
const sighashAll = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID;
return new Script()
.add(BufferUtil.concat([signature.toBuffer('schnorr'), BufferUtil.integerAsSingleByteBuffer(sighashAll)]))
.add(publicKey.toBuffer())
.add(redeemScript.toBuffer());
};
/**
* @returns {Script} an empty script

@@ -1046,3 +1177,3 @@ */

Script.prototype.checkMinimalPush = function(i) {
var chunk = this.chunks[i];
var chunk = this. chunks[i];
var buf = chunk.buf;

@@ -1058,6 +1189,7 @@ var opcodenum = chunk.opcodenum;

// Could have used OP_1 .. OP_16.
return opcodenum === Opcode.OP_1 + (buf[0] - 1);
// return opcodenum === Opcode.OP_1 + (buf[0] - 1);
return false;
} else if (buf.length === 1 && buf[0] === 0x81) {
// Could have used OP_1NEGATE
return opcodenum === Opcode.OP_1NEGATE;
return false;
} else if (buf.length <= 75) {

@@ -1064,0 +1196,0 @@ // Could have used a direct push (opcode indicating number of bytes pushed + those bytes).

@@ -7,1 +7,2 @@ module.exports = require('./input');

module.exports.MultiSigScriptHash = require('./multisigscripthash.js');
module.exports.Escrow = require('./escrow.js')

@@ -18,3 +18,11 @@ 'use strict';

var DEFAULT_LOCKTIME_SEQNUMBER = MAXINT - 1;
const SEQUENCE_LOCKTIME_DISABLE_FLAG = Math.pow(2,31); // (1 << 31);
const SEQUENCE_LOCKTIME_TYPE_FLAG = Math.pow(2,22); // (1 << 22);
const SEQUENCE_LOCKTIME_MASK = 0xffff;
const SEQUENCE_LOCKTIME_GRANULARITY = 512; // 512 seconds
const SEQUENCE_BLOCKDIFF_LIMIT = Math.pow(2,16)-1; // 16 bits
function Input(params) {

@@ -33,2 +41,3 @@ if (!(this instanceof Input)) {

Input.DEFAULT_RBF_SEQNUMBER = DEFAULT_RBF_SEQNUMBER;
Input.SEQUENCE_LOCKTIME_TYPE_FLAG = SEQUENCE_LOCKTIME_TYPE_FLAG;

@@ -59,3 +68,3 @@ Object.defineProperty(Input.prototype, 'script', {

if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) {
prevTxId = new buffer.Buffer(params.prevTxId, 'hex');
prevTxId = Buffer.from(params.prevTxId, 'hex');
} else {

@@ -130,3 +139,3 @@ prevTxId = params.prevTxId;

// hex string script
this._scriptBuffer = new buffer.Buffer(script, 'hex');
this._scriptBuffer = Buffer.from(script, 'hex');
} else if (_.isString(script)) {

@@ -139,3 +148,3 @@ // human readable string script

// buffer script
this._scriptBuffer = new buffer.Buffer(script);
this._scriptBuffer = Buffer.from(script);
} else {

@@ -156,2 +165,3 @@ throw new TypeError('Invalid argument type: script');

* public key associated with the private key provided
* @param {String} signingMethod "schnorr" or "ecdsa", default to "ecdsa" if not provided
* @abstract

@@ -182,3 +192,3 @@ */

Input.prototype.isValidSignature = function(transaction, signature) {
Input.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary

@@ -192,3 +202,5 @@ signature.signature.nhashtype = signature.sigtype;

this.output.script,
this.output.satoshisBN
this.output.satoshisBN,
undefined,
signingMethod
);

@@ -209,2 +221,64 @@ };

/**
* Sets sequence number so that transaction is not valid until the desired seconds
* since the transaction is mined
*
* @param {Number} time in seconds
* @return {Transaction} this
*/
Input.prototype.lockForSeconds = function(seconds) {
$.checkArgument(_.isNumber(seconds));
if (seconds < 0 || seconds >= SEQUENCE_LOCKTIME_GRANULARITY * SEQUENCE_LOCKTIME_MASK) {
throw new errors.Transaction.Input.LockTimeRange();
}
seconds = parseInt(Math.floor(seconds / SEQUENCE_LOCKTIME_GRANULARITY));
// SEQUENCE_LOCKTIME_DISABLE_FLAG = 1
this.sequenceNumber = seconds | SEQUENCE_LOCKTIME_TYPE_FLAG ;
return this;
};
/**
* Sets sequence number so that transaction is not valid until the desired block height differnece since the tx is mined
*
* @param {Number} height
* @return {Transaction} this
*/
Input.prototype.lockUntilBlockHeight = function(heightDiff) {
$.checkArgument(_.isNumber(heightDiff));
if (heightDiff < 0 || heightDiff >= SEQUENCE_BLOCKDIFF_LIMIT) {
throw new errors.Transaction.Input.BlockHeightOutOfRange();
}
// SEQUENCE_LOCKTIME_TYPE_FLAG = 0
// SEQUENCE_LOCKTIME_DISABLE_FLAG = 0
this.sequenceNumber = heightDiff ;
return this;
};
/**
* Returns a semantic version of the input's sequence nLockTime.
* @return {Number|Date}
* If sequence lock is disabled it returns null,
* if is set to block height lock, returns a block height (number)
* else it returns a Date object.
*/
Input.prototype.getLockTime = function() {
if (this.sequenceNumber & SEQUENCE_LOCKTIME_DISABLE_FLAG) {
return null;
}
if (this.sequenceNumber & SEQUENCE_LOCKTIME_TYPE_FLAG) {
var seconds = SEQUENCE_LOCKTIME_GRANULARITY * (this.sequenceNumber & SEQUENCE_LOCKTIME_MASK);
return seconds;
} else {
var blockHeight = this.sequenceNumber & SEQUENCE_LOCKTIME_MASK;
return blockHeight;
}
};
module.exports = Input;

@@ -70,3 +70,3 @@ 'use strict';

MultiSigInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) {
MultiSigInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) {
$.checkState(this.output instanceof Output);

@@ -84,3 +84,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, self.output.satoshisBN),
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, self.output.satoshisBN, undefined, signingMethod),
sigtype: sigtype

@@ -94,17 +94,17 @@ }));

MultiSigInput.prototype.addSignature = function(transaction, signature) {
MultiSigInput.prototype.addSignature = function(transaction, signature, signingMethod) {
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added');
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]),
'Signature has no matching public key');
$.checkState(this.isValidSignature(transaction, signature));
$.checkState(this.isValidSignature(transaction, signature, signingMethod));
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature;
this._updateScript();
this._updateScript(signingMethod);
return this;
};
MultiSigInput.prototype._updateScript = function() {
MultiSigInput.prototype._updateScript = function(signingMethod) {
this.setScript(Script.buildMultisigIn(
this.publicKeys,
this.threshold,
this._createSignatures()
this._createSignatures(signingMethod)
));

@@ -114,3 +114,3 @@ return this;

MultiSigInput.prototype._createSignatures = function() {
MultiSigInput.prototype._createSignatures = function(signingMethod) {
return _.map(

@@ -120,3 +120,3 @@ _.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }),

return BufferUtil.concat([
signature.signature.toDER(),
signature.signature.toDER(signingMethod),
BufferUtil.integerAsSingleByteBuffer(signature.sigtype)

@@ -154,3 +154,3 @@ ]);

MultiSigInput.prototype.isValidSignature = function(transaction, signature) {
MultiSigInput.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary

@@ -164,3 +164,5 @@ signature.signature.nhashtype = signature.sigtype;

this.output.script,
this.output.satoshisBN
this.output.satoshisBN,
undefined,
signingMethod
);

@@ -178,3 +180,3 @@ };

*/
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys) {
MultiSigInput.normalizeSignatures = function(transaction, input, inputIndex, signatures, publicKeys, signingMethod) {
return publicKeys.map(function (pubKey) {

@@ -202,3 +204,5 @@ var signatureMatch = null;

signature.inputIndex,
input.output.script
input.output.script,
undefined,
signingMethod
);

@@ -205,0 +209,0 @@

@@ -32,3 +32,3 @@ 'use strict';

}
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold, opts);
$.checkState(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script),

@@ -43,2 +43,3 @@ 'Provided public keys don\'t hash to the provided output');

this.signatures = signatures ? this._deserializeSignatures(signatures) : new Array(this.publicKeys.length);
this.checkBitsField = new Uint8Array(this.publicKeys.length);
}

@@ -73,3 +74,3 @@ inherits(MultiSigScriptHashInput, Input);

MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) {
MultiSigScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) {
$.checkState(this.output instanceof Output);

@@ -87,3 +88,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, self.output.satoshisBN),
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, self.output.satoshisBN, undefined, signingMethod),
sigtype: sigtype

@@ -96,18 +97,19 @@ }));

MultiSigScriptHashInput.prototype.addSignature = function(transaction, signature) {
MultiSigScriptHashInput.prototype.addSignature = function(transaction, signature, signingMethod) {
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added');
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]),
'Signature has no matching public key');
$.checkState(this.isValidSignature(transaction, signature));
$.checkState(this.isValidSignature(transaction, signature, signingMethod));
this.signatures[this.publicKeyIndex[signature.publicKey.toString()]] = signature;
this._updateScript();
this.checkBitsField[this.publicKeyIndex[signature.publicKey.toString()]] = (signature !== undefined) ? 1 : 0;
this._updateScript(signingMethod, this.checkBitsField);
return this;
};
MultiSigScriptHashInput.prototype._updateScript = function() {
MultiSigScriptHashInput.prototype._updateScript = function(signingMethod, checkBitsField) {
this.setScript(Script.buildP2SHMultisigIn(
this.publicKeys,
this.threshold,
this._createSignatures(),
{ cachedMultisig: this.redeemScript }
this._createSignatures(signingMethod),
{ cachedMultisig: this.redeemScript, checkBits: checkBitsField, signingMethod }
));

@@ -117,3 +119,3 @@ return this;

MultiSigScriptHashInput.prototype._createSignatures = function() {
MultiSigScriptHashInput.prototype._createSignatures = function(signingMethod) {
return _.map(

@@ -123,3 +125,3 @@ _.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }),

return BufferUtil.concat([
signature.signature.toDER(),
signature.signature.toDER(signingMethod),
BufferUtil.integerAsSingleByteBuffer(signature.sigtype)

@@ -157,4 +159,5 @@ ]);

MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature) {
MultiSigScriptHashInput.prototype.isValidSignature = function(transaction, signature, signingMethod) {
// FIXME: Refactor signature so this is not necessary
signingMethod = signingMethod || "ecdsa";
signature.signature.nhashtype = signature.sigtype;

@@ -167,3 +170,5 @@ return Sighash.verify(

this.redeemScript,
this.output.satoshisBN
this.output.satoshisBN,
undefined,
signingMethod
);

@@ -170,0 +175,0 @@ };

@@ -29,5 +29,6 @@ 'use strict';

* @param {number=} sigtype - the type of signature, defaults to Signature.SIGHASH_ALL
* @param {String} signingMethod - the signing method used to sign tx "ecdsa" or "schnorr"
* @return {Array} of objects that can be
*/
PublicKeyInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype) {
PublicKeyInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) {
$.checkState(this.output instanceof Output);

@@ -42,3 +43,3 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN),
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN, undefined, signingMethod),
sigtype: sigtype

@@ -57,8 +58,9 @@ })];

* @param {number=} signature.sigtype
* @param {String} signingMethod - the method used in signing the tx "ecdsa" or "schnorr"
* @return {PublicKeyInput} this, for chaining
*/
PublicKeyInput.prototype.addSignature = function(transaction, signature) {
$.checkState(this.isValidSignature(transaction, signature), 'Signature is invalid');
PublicKeyInput.prototype.addSignature = function(transaction, signature, signingMethod) {
$.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
this.setScript(Script.buildPublicKeyIn(
signature.signature.toDER(),
signature.signature.toDER(signingMethod),
signature.sigtype

@@ -65,0 +67,0 @@ ));

@@ -32,5 +32,6 @@ 'use strict';

* @param {Buffer=} hashData - the precalculated hash of the public key associated with the privateKey provided
* @param {String} signingMethod - the signing method used to sign tx "ecdsa" or "schnorr"
* @return {Array} of objects that can be
*/
PublicKeyHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData) {
PublicKeyHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData, signingMethod) {
$.checkState(this.output instanceof Output);

@@ -46,3 +47,3 @@ hashData = hashData || Hash.sha256ripemd160(privateKey.publicKey.toBuffer());

inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN),
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, this.output.satoshisBN, undefined, signingMethod),
sigtype: sigtype

@@ -62,10 +63,12 @@ })];

* @param {number=} signature.sigtype
* @param {String} signingMethod "ecdsa" or "schnorr"
* @return {PublicKeyHashInput} this, for chaining
*/
PublicKeyHashInput.prototype.addSignature = function(transaction, signature) {
$.checkState(this.isValidSignature(transaction, signature), 'Signature is invalid');
PublicKeyHashInput.prototype.addSignature = function(transaction, signature, signingMethod) {
$.checkState(this.isValidSignature(transaction, signature, signingMethod), 'Signature is invalid');
this.setScript(Script.buildPublicKeyHashIn(
signature.publicKey,
signature.signature.toDER(),
signature.signature.toDER(signingMethod),
signature.sigtype

@@ -72,0 +75,0 @@ ));

@@ -26,3 +26,3 @@ 'use strict';

if (_.isString(args.script) && JSUtil.isHexa(args.script)) {
script = new buffer.Buffer(args.script, 'hex');
script = Buffer.from(args.script, 'hex');
} else {

@@ -171,3 +171,3 @@ script = args.script;

} else {
obj.script = new buffer.Buffer([]);
obj.script = Buffer.from([]);
}

@@ -174,0 +174,0 @@ return new Output(obj);

@@ -13,2 +13,3 @@ 'use strict';

var ECDSA = require('../crypto/ecdsa');
var Schnorr = require('../crypto/schnorr');
var $ = require('../util/preconditions');

@@ -163,3 +164,3 @@ var BufferUtil = require('../util/buffer');

var Input = require('./input');
if (_.isUndefined(flags)){

@@ -225,3 +226,3 @@ flags = DEFAULT_SIGN_FLAGS;

txcopy.outputs[i] = new Output({
satoshis: BN.fromBuffer(new buffer.Buffer(BITS_64_ON, 'hex')),
satoshis: BN.fromBuffer(Buffer.from(BITS_64_ON, 'hex')),
script: Script.empty()

@@ -231,3 +232,3 @@ });

}
if (sighashType & Signature.SIGHASH_ANYONECANPAY) {

@@ -256,13 +257,22 @@ txcopy.inputs = [txcopy.inputs[inputNumber]];

* @param {satoshisBN} input's amount
* @param {signingMethod} signingMethod "ecdsa" or "schnorr" to sign a tx
* @return {Signature}
*/
function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags) {
function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod) {
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags);
signingMethod = signingMethod || "ecdsa";
let sig;
var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({
nhashtype: sighashType
});
return sig;
if (signingMethod === "schnorr") {
sig = Schnorr.sign(hashbuf, privateKey, 'little').set({
nhashtype: sighashType
});
return sig;
} else if (signingMethod === "ecdsa") {
sig = ECDSA.sign(hashbuf, privateKey, 'little').set({
nhashtype: sighashType
});
return sig;
}
}

@@ -281,9 +291,17 @@

* @param {flags} verification flags
* @param {signingMethod} signingMethod "ecdsa" or "schnorr" to sign a tx
* @return {boolean}
*/
function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags) {
function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags, signingMethod) {
$.checkArgument(!_.isUndefined(transaction));
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype));
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags);
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
signingMethod = signingMethod || "ecdsa";
if (signingMethod === "schnorr") {
return Schnorr.verify(hashbuf, signature, publicKey, 'little')
} else if(signingMethod === "ecdsa") {
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
}
}

@@ -290,0 +308,0 @@

@@ -24,5 +24,7 @@ 'use strict';

var MultiSigInput = Input.MultiSig;
var EscrowInput = Input.Escrow;
var Output = require('./output');
var Script = require('../script');
var PrivateKey = require('../privatekey');
var PublicKey = require('../publickey');
var BN = require('../crypto/bn');

@@ -62,3 +64,3 @@

var CURRENT_VERSION = 1;
var CURRENT_VERSION = 2;
var DEFAULT_NLOCKTIME = 0;

@@ -545,3 +547,3 @@ var MAX_BLOCK_SIZE = 1000000;

_.each(utxo, function(utxo) {
self.from(utxo, pubkeys, threshold);
self.from(utxo, pubkeys, threshold, opts);
});

@@ -559,2 +561,4 @@ return this;

this._fromMultisigUtxo(utxo, pubkeys, threshold, opts);
} else if (utxo.publicKeys && utxo.publicKeys.length > 1) {
this._fromEscrowUtxo(utxo, utxo.publicKeys);
} else {

@@ -566,2 +570,83 @@ this._fromNonP2SH(utxo);

/**
* associateInputs - Update inputs with utxos, allowing you to specify value, and pubkey.
* Populating these inputs allows for them to be signed with .sign(privKeys)
*
* @param {Array<Object>} utxos
* @param {Array<string | PublicKey>} pubkeys
* @param {number} threshold
* @param {Object} opts
* @returns {Array<number>}
*/
Transaction.prototype.associateInputs = function(utxos, pubkeys, threshold, opts) {
let indexes = [];
for(let utxo of utxos) {
const index = this.inputs.findIndex(i => i.prevTxId.toString('hex') === utxo.txId && i.outputIndex === utxo.outputIndex);
indexes.push(index);
if(index >= 0) {
this.inputs[index] = this._getInputFrom(utxo, pubkeys, threshold, opts);
}
}
return indexes;
};
Transaction.prototype._selectInputType = function(utxo, pubkeys, threshold) {
var clazz;
utxo = new UnspentOutput(utxo);
if(pubkeys && threshold) {
if (utxo.script.isMultisigOut()) {
clazz = MultiSigInput;
} else if (utxo.script.isScriptHashOut() || utxo.script.isWitnessScriptHashOut()) {
clazz = MultiSigScriptHashInput;
}
} else if (utxo.script.isPublicKeyHashOut() || utxo.script.isWitnessPublicKeyHashOut() || utxo.script.isScriptHashOut()) {
clazz = PublicKeyHashInput;
} else if (utxo.script.isPublicKeyOut()) {
clazz = PublicKeyInput;
} else {
clazz = Input;
}
return clazz;
};
Transaction.prototype._getInputFrom = function(utxo, pubkeys, threshold, opts) {
utxo = new UnspentOutput(utxo);
const InputClass = this._selectInputType(utxo, pubkeys, threshold);
const input = {
output: new Output({
script: utxo.script,
satoshis: utxo.satoshis
}),
prevTxId: utxo.txId,
outputIndex: utxo.outputIndex,
sequenceNumber: utxo.sequenceNumber,
script: Script.empty()
};
let args = pubkeys && threshold ? [pubkeys, threshold, false, opts] : []
return new InputClass(input, ...args);
}
Transaction.prototype._fromEscrowUtxo = function(utxo, pubkeys) {
const publicKeys = pubkeys.map(pubkey => new PublicKey(pubkey));
const inputPublicKeys = publicKeys.slice(1);
const reclaimPublicKey = publicKeys[0];
utxo = new UnspentOutput(utxo);
this.addInput(
new EscrowInput(
{
output: new Output({
script: utxo.script,
satoshis: utxo.satoshis
}),
prevTxId: utxo.txId,
outputIndex: utxo.outputIndex,
script: Script.empty()
},
inputPublicKeys,
reclaimPublicKey
)
);
};
Transaction.prototype._fromNonP2SH = function(utxo) {

@@ -608,3 +693,3 @@ var clazz;

script: Script.empty()
}, pubkeys, threshold, opts));
}, pubkeys, threshold, undefined, opts));
};

@@ -728,2 +813,23 @@

/**
* Set the Zero-Confirmation Escrow (ZCE) address for this transaction
*
* @param {Address} address The Zero-Confirmation Escrow (ZCE) address for this payment
* @param {number} amount The amount in satoshis to send to the ZCE address
* @return {Transaction} this, for chaining
*/
Transaction.prototype.escrow = function(address, amount) {
$.checkArgument(this.inputs.length > 0, 'inputs must have already been set when setting escrow');
$.checkArgument(this.outputs.length > 0, 'non-change outputs must have already been set when setting escrow');
$.checkArgument(!this.getChangeOutput(), 'change must still be unset when setting escrow');
$.checkArgument(address, 'address is required');
$.checkArgument(amount, 'amount is required');
const totalSendAmountWithoutChange = this._getOutputAmount() + this.getFee() + amount;
const hasChange = this._getInputAmount() - totalSendAmountWithoutChange > Transaction.DUST_AMOUNT;
this.to(address, amount);
if(!hasChange) {
this._fee = undefined;
}
return this;
};

@@ -875,3 +981,3 @@ /**

var changeAmount = available - fee;
if (changeAmount > 0) {
if (changeAmount >= Transaction.DUST_AMOUNT) {
this._changeIndex = this.outputs.length;

@@ -949,3 +1055,5 @@ this._addOutput(new Output({

_.each(this.inputs, function(input) {
result += input._estimateSize();
let scriptSigLen = input._estimateSize();
let varintLen = BufferWriter.varintBufNum(scriptSigLen).length;
result += 36 + varintLen + scriptSigLen;
});

@@ -978,3 +1086,3 @@ _.each(this.outputs, function(output) {

var copy = Array.prototype.concat.apply([], inputs);
let i = 0;
let i = 0;
copy.forEach((x) => { x.i = i++});

@@ -990,3 +1098,3 @@ copy.sort(function(first, second) {

var copy = Array.prototype.concat.apply([], outputs);
let i = 0;
let i = 0;
copy.forEach((x) => { x.i = i++});

@@ -1087,3 +1195,5 @@ copy.sort(function(first, second) {

*/
Transaction.prototype.sign = function(privateKey, sigtype) {
Transaction.prototype.sign = function(privateKey, sigtype, signingMethod) {
signingMethod = signingMethod || "ecdsa"
$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.');

@@ -1093,8 +1203,8 @@ var self = this;

_.each(privateKey, function(privateKey) {
self.sign(privateKey, sigtype);
self.sign(privateKey, sigtype, signingMethod);
});
return this;
}
_.each(this.getSignatures(privateKey, sigtype), function(signature) {
self.applySignature(signature);
_.each(this.getSignatures(privateKey, sigtype, signingMethod), function(signature) {
self.applySignature(signature, signingMethod);
});

@@ -1104,6 +1214,5 @@ return this;

Transaction.prototype.getSignatures = function(privKey, sigtype) {
Transaction.prototype.getSignatures = function(privKey, sigtype, signingMethod) {
privKey = new PrivateKey(privKey);
// By default, signs using ALL|FORKID

@@ -1113,5 +1222,6 @@ sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);

var results = [];
var hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer());
_.each(this.inputs, function forEachInput(input, index) {
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData), function(signature) {
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod), function(signature) {
results.push(signature);

@@ -1131,6 +1241,7 @@ });

* @param {Signature} signature.signature
* @param {String} signingMethod "ecdsa" or "schnorr"
* @return {Transaction} this, for chaining
*/
Transaction.prototype.applySignature = function(signature) {
this.inputs[signature.inputIndex].addSignature(this, signature);
Transaction.prototype.applySignature = function(signature, signingMethod) {
this.inputs[signature.inputIndex].addSignature(this, signature, signingMethod);
return this;

@@ -1167,4 +1278,4 @@ };

*/
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, satoshisBN, flags) {
return Sighash.verify(this, sig, pubkey, nin, subscript, satoshisBN, flags);
Transaction.prototype.verifySignature = function(sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod) {
return Sighash.verify(this, sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod);
};

@@ -1237,2 +1348,109 @@

Transaction.prototype.isZceSecured = function(escrowReclaimTx, instantAcceptanceEscrow, requiredFeeRate) {
// ZCE-secured transactions must not contain more than 2^16 inputs (65,536)
// https://github.com/bitjson/bch-zce#zce-root-hash
if(this.inputs.length > 65536) {
return false;
}
const allInputsAreP2pkh = this.inputs.every(input => input.script.isPublicKeyHashIn());
if (!allInputsAreP2pkh) {
return false;
}
const escrowInputIndex = 0;
let reclaimTx;
try {
reclaimTx = new Transaction(escrowReclaimTx);
} catch (e) {
return false;
}
const escrowInput = reclaimTx.inputs[escrowInputIndex];
if (escrowInput.prevTxId.toString('hex') !== this.id) {
return false;
}
const escrowUtxo = this.outputs[escrowInput.outputIndex];
if (!escrowUtxo) {
return false;
}
// The escrow address must contain the instantAcceptanceEscrow satoshis specified
// by the merchant plus the minimum required miner fee on the ZCE-secured payment.
// Rationale: https://github.com/bitjson/bch-zce#zce-extension-to-json-payment-protocol
const zceRawTx = this.uncheckedSerialize();
const zceTxSize = zceRawTx.length / 2;
const minFee = zceTxSize * requiredFeeRate;
if (escrowUtxo.toObject().satoshis < instantAcceptanceEscrow + minFee) {
return false;
}
escrowInput.output = escrowUtxo;
const reclaimTxSize = escrowReclaimTx.length / 2;
const reclaimTxFeeRate = reclaimTx.getFee() / reclaimTxSize;
if (reclaimTxFeeRate < requiredFeeRate) {
return false;
}
const escrowUnlockingScriptParts = escrowInput.script.toASM().split(' ');
if (escrowUnlockingScriptParts.length !== 3) {
return false;
}
const [reclaimSignatureString, reclaimPublicKeyString, redeemScriptString] = escrowUnlockingScriptParts;
const reclaimPublicKey = new PublicKey(reclaimPublicKeyString);
const inputPublicKeys = this.inputs.map(input => new PublicKey(input.script.getPublicKey()));
const inputSignatureStrings = this.inputs.map(input => input.script.toASM().split(' ')[0]);
const sighashAll = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID;
const allSignaturesSighashAll = [reclaimSignatureString, ...inputSignatureStrings].every(signatureString =>
signatureString.endsWith(sighashAll.toString(16))
);
if (!allSignaturesSighashAll) {
return false;
}
const correctEscrowRedeemScript = Script.buildEscrowOut(inputPublicKeys, reclaimPublicKey);
const correctEscrowRedeemScriptHash = Hash.sha256ripemd160(correctEscrowRedeemScript.toBuffer());
const escrowUtxoRedeemScriptHash = escrowUtxo.script.getData();
const escrowInputRedeemScript = new Script(redeemScriptString);
const escrowInputRedeemScriptHash = Hash.sha256ripemd160(escrowInputRedeemScript.toBuffer());
const allRedeemScriptHashes = [
correctEscrowRedeemScriptHash,
escrowInputRedeemScriptHash,
escrowUtxoRedeemScriptHash
].map(hash => hash.toString('hex'));
if (!allRedeemScriptHashes.every(hash => hash === allRedeemScriptHashes[0])) {
return false;
}
const reclaimSignature = Signature.fromString(reclaimSignatureString);
reclaimSignature.nhashtype = sighashAll;
const reclaimSigValid = reclaimTx.verifySignature(
reclaimSignature,
reclaimPublicKey,
escrowInputIndex,
escrowInputRedeemScript,
escrowUtxo.satoshisBN,
undefined,
reclaimSignature.isSchnorr ? 'schnorr' : 'ecdsa'
);
if (!reclaimSigValid) {
return false;
}
return true;
};
/**

@@ -1245,2 +1463,12 @@ * Analogous to bitcoind's IsCoinBase function in transaction.h

Transaction.prototype.setVersion = function(version) {
$.checkArgument(
JSUtil.isNaturalNumber(version) && version <= CURRENT_VERSION,
'Wrong version number');
this.version = version;
return this;
};
module.exports = Transaction;

@@ -44,5 +44,5 @@ 'use strict';

}
$.checkArgument(!_.isUndefined(data.scriptPubKey) || !_.isUndefined(data.script),
'Must provide the scriptPubKey for that output!');
var script = new Script(data.scriptPubKey || data.script);
$.checkArgument(!_.isUndefined(data.scriptPubKey) || !_.isUndefined(data.script) || !_.isUndefined(address),
'Must provide the scriptPubKey, script, or address for that output!');
var script = new Script(data.scriptPubKey || data.script || Script.fromAddress(address));
$.checkArgument(!_.isUndefined(data.amount) || !_.isUndefined(data.satoshis),

@@ -49,0 +49,0 @@ 'Must provide an amount for the output');

@@ -71,3 +71,3 @@ 'use strict';

$.checkArgumentType(bytes, 'number', 'bytes');
var result = new buffer.Buffer(bytes);
var result = Buffer.alloc(bytes);
for (var i = 0; i < bytes; i++) {

@@ -97,3 +97,3 @@ result.write('\0', i);

$.checkArgumentType(integer, 'number', 'integer');
return new buffer.Buffer([integer & 0xff]);
return Buffer.from([integer & 0xff]);
},

@@ -157,21 +157,6 @@

reverse: function reverse(param) {
var ret = new buffer.Buffer(param.length);
for (var i = 0; i < param.length; i++) {
ret[i] = param[param.length - i - 1];
}
return ret;
return (Buffer.from(param)).reverse();
},
/**
* Transforms an hexa encoded string into a Buffer with binary values
*
* Shorthand for <tt>Buffer(string, 'hex')</tt>
*
* @param {string} string
* @return {Buffer}
*/
hexToBuffer: function hexToBuffer(string) {
assert(js.isHexa(string));
return new buffer.Buffer(string, 'hex');
},
};

@@ -178,0 +163,0 @@

{
"name": "bitcore-lib-cash",
"version": "9.0.0",
"version": "10.0.0",
"description": "A pure and powerful JavaScript Bitcoin Cash library.",

@@ -8,3 +8,2 @@ "author": "BitPay <dev@bitpay.com>",

"scripts": {
"lint": "gulp lint",
"test": "gulp test",

@@ -40,13 +39,13 @@ "test:ci": "npm run test",

"dependencies": {
"bitcore-lib": "^9.0.0",
"bitcore-lib": "^10.0.0",
"bn.js": "=4.11.8",
"bs58": "^4.0.1",
"buffer-compare": "=1.1.1",
"elliptic": "=6.4.0",
"elliptic": "^6.5.3",
"inherits": "=2.0.1",
"lodash": "=4.17.15"
"lodash": "^4.17.20"
},
"devDependencies": {
"base-x": "=3.0.4",
"bitcore-build": "^9.0.0",
"bitcore-build": "^10.0.0",
"brfs": "^2.0.1",

@@ -58,3 +57,3 @@ "chai": "^4.2.0",

"license": "MIT",
"gitHead": "012cc0216a9bc6b195035855bd17149bad41acd1"
"gitHead": "b3564dff1463378532092b9c600bf5358163226e"
}

@@ -21,4 +21,4 @@ 'use strict';

var pubkeyhash = new Buffer('3c3fa3d4adcaf8f52d5b1843975e122548269937', 'hex');
var buf = Buffer.concat([new Buffer([28]), pubkeyhash]);
var pubkeyhash = Buffer.from('3c3fa3d4adcaf8f52d5b1843975e122548269937', 'hex');
var buf = Buffer.concat([Buffer.from([28]), pubkeyhash]);
var str = 'bitcoincash:qq7rlg754h903afdtvvy8967zgj5sf5exueg36nyc7';

@@ -400,3 +400,3 @@

(function() {
return Address._transformBuffer(new Buffer(20));
return Address._transformBuffer(Buffer.alloc(20));
}).should.throw('Address buffers must be exactly 21 bytes.');

@@ -407,3 +407,3 @@ });

(function() {
return Address._transformPublicKey(new Buffer(20));
return Address._transformPublicKey(Buffer.alloc(20));
}).should.throw('Address must be an instance of PublicKey.');

@@ -414,3 +414,3 @@ });

(function() {
return Address._transformScript(new Buffer(20));
return Address._transformScript( Buffer.alloc(20));
}).should.throw('Invalid Argument: script must be a Script instance');

@@ -421,3 +421,3 @@ });

(function() {
return Address._transformString(new Buffer(20));
return Address._transformString(Buffer.alloc(20));
}).should.throw('data parameter supplied is not a string.');

@@ -424,0 +424,0 @@ });

@@ -31,4 +31,4 @@ 'use strict';

version = data.version;
prevblockidbuf = new Buffer(data.prevblockidhex, 'hex');
merklerootbuf = new Buffer(data.merkleroothex, 'hex');
prevblockidbuf = Buffer.from(data.prevblockidhex, 'hex');
merklerootbuf = Buffer.from(data.merkleroothex, 'hex');
time = data.time;

@@ -46,3 +46,3 @@ bits = data.bits;

bhhex = data.blockheaderhex;
bhbuf = new Buffer(bhhex, 'hex');
bhbuf = Buffer.from(bhhex, 'hex');
});

@@ -98,3 +98,3 @@

var hex = 'ffffffff00000000000000000000000000000000000000000000000000000000000000004141414141414141414141414141414141414141414141414141414141414141010000000200000003000000';
var header = BlockHeader.fromBuffer(new Buffer(hex, 'hex'));
var header = BlockHeader.fromBuffer(Buffer.from(hex, 'hex'));
header.version.should.equal(-1);

@@ -101,0 +101,0 @@ header.timestamp.should.equal(1);

@@ -22,3 +22,3 @@ 'use strict';

blockhex = data.HEX[0];
blockbuf = new Buffer(blockhex,'hex');
blockbuf = Buffer.from(blockhex,'hex');
blockJSON = JSON.stringify(data.JSON[0]);

@@ -197,3 +197,3 @@ blockObject = JSON.parse(JSON.stringify(data.JSON[0]));

var jsonData = data.JSON[0];
var txId = new Buffer(jsonData.hashes[1],'hex').toString('hex');
var txId = Buffer.from(jsonData.hashes[1],'hex').toString('hex');
var b = MerkleBlock(jsonData);

@@ -206,3 +206,3 @@ b.hasTransaction(txId).should.equal(true);

var jsonData = data.JSON[0];
var txBuf = new Buffer(data.TXHEX[0][0],'hex');
var txBuf = Buffer.from(data.TXHEX[0][0],'hex');
var tx = new Transaction().fromBuffer(txBuf);

@@ -216,3 +216,3 @@ var b = MerkleBlock(jsonData);

var serialized = transactionVector[0][7];
var tx = new Transaction().fromBuffer(new Buffer(serialized, 'hex'));
var tx = new Transaction().fromBuffer( Buffer.from(serialized, 'hex'));
var b = MerkleBlock(data.JSON[0]);

@@ -219,0 +219,0 @@ b.hasTransaction(tx).should.equal(false);

@@ -97,3 +97,3 @@ 'use strict';

it('should work with big endian', function() {
var bn = BN.fromBuffer(new Buffer('0001', 'hex'), {
var bn = BN.fromBuffer( Buffer.from('0001', 'hex'), {
endian: 'big'

@@ -105,3 +105,3 @@ });

it('should work with big endian 256', function() {
var bn = BN.fromBuffer(new Buffer('0100', 'hex'), {
var bn = BN.fromBuffer( Buffer.from('0100', 'hex'), {
endian: 'big'

@@ -113,3 +113,3 @@ });

it('should work with little endian if we specify the size', function() {
var bn = BN.fromBuffer(new Buffer('0100', 'hex'), {
var bn = BN.fromBuffer( Buffer.from('0100', 'hex'), {
size: 2,

@@ -116,0 +116,0 @@ endian: 'little'

@@ -21,5 +21,5 @@ 'use strict';

var ecdsa = new ECDSA();
ecdsa.hashbuf = Hash.sha256(new Buffer('test data'));
ecdsa.hashbuf = Hash.sha256(Buffer.from('test data'));
ecdsa.privkey = new Privkey(BN.fromBuffer(
new Buffer('fee0a1f7afebf9d2a5a80c0c98a31c709681cce195cbcd06342b517970c0be1e', 'hex')
Buffer.from('fee0a1f7afebf9d2a5a80c0c98a31c709681cce195cbcd06342b517970c0be1e', 'hex')
));

@@ -45,7 +45,7 @@ ecdsa.privkey2pubkey();

it('calulates this known i', function() {
var hashbuf = Hash.sha256(new Buffer('some data'));
var hashbuf = Hash.sha256(Buffer.from('some data'));
var r = new BN('71706645040721865894779025947914615666559616020894583599959600180037551395766', 10);
var s = new BN('109412465507152403114191008482955798903072313614214706891149785278625167723646', 10);
var ecdsa = new ECDSA({
privkey: new Privkey(BN.fromBuffer(Hash.sha256(new Buffer('test')))),
privkey: new Privkey(BN.fromBuffer(Hash.sha256(Buffer.from('test')))),
hashbuf: hashbuf,

@@ -114,3 +114,3 @@ sig: new Signature({

var ecdsa = new ECDSA();
ecdsa.hashbuf = Hash.sha256(new Buffer('Everything should be made as simple as possible, but not simpler.'));
ecdsa.hashbuf = Hash.sha256(Buffer.from('Everything should be made as simple as possible, but not simpler.'));
ecdsa.privkey = new Privkey(new BN(1));

@@ -168,4 +168,4 @@ ecdsa.privkey2pubkey();

var ecdsa = new ECDSA();
ecdsa.hashbuf = Hash.sha256(new Buffer('test'));
var pk = Pubkey.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49' +
ecdsa.hashbuf = Hash.sha256(Buffer.from('test'));
var pk = Pubkey.fromDER(Buffer.from('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49' +
'710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));

@@ -219,5 +219,5 @@ ecdsa.pubkey = pk;

it('should generate right K', function() {
var msg1 = new Buffer('52204d20fd0131ae1afd173fd80a3a746d2dcc0cddced8c9dc3d61cc7ab6e966', 'hex');
var msg2 = [].reverse.call(new Buffer(msg1))
var pk = new Buffer('16f243e962c59e71e54189e67e66cf2440a1334514c09c00ddcc21632bac9808', 'hex');
var msg1 = Buffer.from('52204d20fd0131ae1afd173fd80a3a746d2dcc0cddced8c9dc3d61cc7ab6e966', 'hex');
var msg2 = [].reverse.call(Buffer.from(msg1))
var pk = Buffer.from('16f243e962c59e71e54189e67e66cf2440a1334514c09c00ddcc21632bac9808', 'hex');
var signature1 = ECDSA.sign(msg1, Privkey.fromBuffer(pk)).toBuffer().toString('hex');

@@ -283,5 +283,5 @@ var signature2 = ECDSA.sign(msg2, Privkey.fromBuffer(pk), 'little').toBuffer().toString('hex');

var ecdsa = ECDSA().set({
privkey: new Privkey(BN.fromBuffer(new Buffer(obj.d, 'hex'))),
k: BN.fromBuffer(new Buffer(obj.k, 'hex')),
hashbuf: Hash.sha256(new Buffer(obj.message)),
privkey: new Privkey(BN.fromBuffer(Buffer.from(obj.d, 'hex'))),
k: BN.fromBuffer(Buffer.from(obj.k, 'hex')),
hashbuf: Hash.sha256(Buffer.from(obj.message)),
sig: new Signature().set({

@@ -309,3 +309,3 @@ r: new BN(obj.signature.r),

sig: new Signature(new BN(obj.signature.r), new BN(obj.signature.s)),
hashbuf: Hash.sha256(new Buffer(obj.message))
hashbuf: Hash.sha256(Buffer.from(obj.message))
});

@@ -318,4 +318,4 @@ ecdsa.sigError().should.equal(obj.exception);

it('should validate deterministicK vector ' + i, function() {
var hashbuf = Hash.sha256(new Buffer(obj.message));
var privkey = Privkey(BN.fromBuffer(new Buffer(obj.privkey, 'hex')), 'mainnet');
var hashbuf = Hash.sha256(Buffer.from(obj.message));
var privkey = Privkey(BN.fromBuffer(Buffer.from(obj.privkey, 'hex')), 'mainnet');
var ecdsa = ECDSA({

@@ -322,0 +322,0 @@ privkey: privkey,

@@ -8,3 +8,3 @@ 'use strict';

describe('Hash', function() {
var buf = new Buffer([0, 1, 2, 3, 253, 254, 255]);
var buf = Buffer.from([0, 1, 2, 3, 253, 254, 255]);
var str = 'test string';

@@ -17,3 +17,3 @@

hash.toString('hex').should.equal('de69b8a4a5604d0486e6420db81e39eb464a17b2');
hash = Hash.sha1(new Buffer(0));
hash = Hash.sha1(Buffer.alloc(0));
hash.toString('hex').should.equal('da39a3ee5e6b4b0d3255bfef95601890afd80709');

@@ -44,7 +44,7 @@ });

it('computes this known big key correctly', function() {
var key = new Buffer('b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad' +
var key = Buffer.from('b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad' +
'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad' +
'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad' +
'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad');
var data = new Buffer('');
var data = Buffer.alloc(0);
Hash.sha256hmac(data, key).toString('hex')

@@ -55,4 +55,4 @@ .should.equal('fb1f87218671f1c0c4593a88498e02b6dfe8afd814c1729e89a1f1f6600faa23');

it('computes this known empty test vector correctly', function() {
var key = new Buffer('');
var data = new Buffer('');
var key = Buffer.alloc(0);
var data = Buffer.alloc(0);
Hash.sha256hmac(data, key).toString('hex')

@@ -63,4 +63,4 @@ .should.equal('b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad');

it('computes this known non-empty test vector correctly', function() {
var key = new Buffer('key');
var data = new Buffer('The quick brown fox jumps over the lazy dog');
var key = Buffer.from('key');
var data = Buffer.from('The quick brown fox jumps over the lazy dog');
Hash.sha256hmac(data, key).toString('hex')

@@ -131,3 +131,3 @@ .should.equal('f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8');

'c6730c6c515421b327ec1d69402e53dfb49ad7381eb067b338fd7b0cb22247225d47';
Hash.sha512hmac(new Buffer([]), new Buffer([])).toString('hex').should.equal(hex);
Hash.sha512hmac(Buffer.alloc(0), Buffer.alloc(0)).toString('hex').should.equal(hex);
});

@@ -138,4 +138,4 @@

'b13cc403a78e6150d83595f3b17c4cc331f12ca5952691de3735a63c1d4c69a2bac';
var data = new Buffer('test1');
var key = new Buffer('test2');
var data = Buffer.from('test1');
var key = Buffer.from('test2');
Hash.sha512hmac(data, key).toString('hex').should.equal(hex);

@@ -142,0 +142,0 @@ });

@@ -42,3 +42,3 @@ 'use strict';

a.length.should.equal(32);
a.should.deep.equal(new Buffer(valid.x, 'hex'));
a.should.deep.equal( Buffer.from(valid.x, 'hex'));
});

@@ -59,3 +59,3 @@

a.length.should.equal(32);
a.should.deep.equal(new Buffer(valid.y, 'hex'));
a.should.deep.equal( Buffer.from(valid.y, 'hex'));
});

@@ -62,0 +62,0 @@

@@ -54,6 +54,6 @@ 'use strict';

it('should create a signature from a compressed signature', function() {
var blank = new Buffer(32);
var blank = Buffer.alloc(32);
blank.fill(0);
var compressed = Buffer.concat([
new Buffer([0 + 27 + 4]),
Buffer.from([0 + 27 + 4]),
blank,

@@ -71,3 +71,3 @@ blank

'0dc553a2588be2b5b68dbbd7f092894aa3397786e9c769c5348dc6';
var sig = Signature.fromCompact(new Buffer(sigHexaStr, 'hex'));
var sig = Signature.fromCompact(Buffer.from(sigHexaStr, 'hex'));
var r = 'd5e61ab5bfd0d1450997894cb1a53e917f89d82eb43f06fa96f32c96e061aec1';

@@ -84,3 +84,3 @@ var s = '2fc1188e8b0dc553a2588be2b5b68dbbd7f092894aa3397786e9c769c5348dc6';

var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');
var buf = Buffer.from('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

@@ -101,3 +101,3 @@ it('should parse this DER format signature', function() {

var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');
var buf = Buffer.from('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex');

@@ -120,3 +120,3 @@ it('should parse this DER format signature in hex', function() {

var original = '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201';
var buf = new Buffer(original, 'hex');
var buf = Buffer.from(original, 'hex');
var sig = Signature.fromTxFormat(buf);

@@ -139,3 +139,3 @@ sig.nhashtype.should.equal(Signature.SIGHASH_ALL);

it('should convert from this known tx-format buffer', function() {
var buf = new Buffer('30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201', 'hex');
var buf = Buffer.from('30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e7201', 'hex');
var sig = Signature.fromTxFormat(buf);

@@ -149,3 +149,3 @@ sig.r.toString().should.equal('63173831029936981022572627018246571655303050627048489594159321588908385378810');

var hex = '3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501';
var buf = new Buffer(hex, 'hex');
var buf = Buffer.from(hex, 'hex');
var sig = Signature.fromTxFormat(buf);

@@ -161,3 +161,3 @@ sig.toTxFormat().toString('hex').should.equal(hex);

var sighex = '30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72';
var sig = new Buffer(sighex, 'hex');
var sig = Buffer.from(sighex, 'hex');
var parsed = Signature.parseDER(sig);

@@ -178,3 +178,3 @@ parsed.header.should.equal(0x30);

var sighex = '3043021f59e4705959cc78acbfcf8bd0114e9cc1b389a4287fb33152b73a38c319b50302202f7428a27284c757e409bf41506183e9e49dfb54d5063796dfa0d403a4deccfa';
var sig = new Buffer(sighex, 'hex');
var sig = Buffer.from(sighex, 'hex');
var parsed = Signature.parseDER(sig);

@@ -195,3 +195,3 @@ parsed.header.should.equal(0x30);

var sighex = '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a51';
var sig = new Buffer(sighex, 'hex');
var sig = Buffer.from(sighex, 'hex');
var parsed = Signature.parseDER(sig);

@@ -212,3 +212,3 @@ parsed.header.should.equal(0x30);

var sighex = '304502203e4516da7253cf068effec6b95c41221c0cf3a8e6ccb8cbf1725b562e9afde2c022100ab1e3da73d67e32045a20e0b999e049978ea8d6ee5480d485fcf2ce0d03b2ef051';
var sig = Buffer(sighex, 'hex');
var sig = Buffer.from(sighex, 'hex');
var parsed = Signature.parseDER(sig, false);

@@ -252,3 +252,3 @@ should.exist(parsed);

var sighex = '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a5101';
var sigbuf = new Buffer(sighex, 'hex');
var sigbuf = Buffer.from(sighex, 'hex');
Signature.isTxDER(sigbuf).should.equal(true);

@@ -260,3 +260,3 @@ });

var sighex = '3042021e17cfe77536c3fb0526bd1a72d7a8e0973f463add210be14063c8a9c37632022061bfa677f825ded82ba0863fb0c46ca1388dd3e647f6a93c038168b59d131a5101';
var sigbuf = new Buffer(sighex, 'hex');
var sigbuf = Buffer.from(sighex, 'hex');
sigbuf[0] = 0x31;

@@ -280,3 +280,3 @@ Signature.isTxDER(sigbuf).should.equal(false);

Interpreter.SCRIPT_VERIFY_STRICTENC;
var result = interp.checkTxSignatureEncoding(new Buffer(sighex, 'hex'));
var result = interp.checkTxSignatureEncoding(Buffer.from(sighex, 'hex'));
result.should.equal(expected);

@@ -283,0 +283,0 @@ });

@@ -83,4 +83,4 @@ [

"sign", ["L4jFVcDaqZCkknP5KQWjCBgiLFxKxRxywNGTucm3jC3ozByZcbZv", 1],
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fc004730440220658e8a9a15d05dc72f5ac59823bc82472fa8cdc7853910111dc4717850b4a6ca02201c2e3479704a6581cc8b233fd5533b8f19d093815d60e62b508716ea28010826014730440220054502b9dbf26a962b9b83e719b6c70a55ce6a931d977da0ad26bfcd483d438402205a4ae4193b502592b573bd995d3fa370ef56c6e381ee6356991d14173b0dc396014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fc0047304402207e1a40f986ee26942f780bb2f384d5425b84079149ee659e3ee8d243568cc02102200519928c0c1cd098d296a64316335db5f894f1ddf27453c4dc07e1cc4f4bbf6d014730440220760ef53cf380eeb6683999090577f9b644bf44039f4a887fdd44ccbd9ece72ba02206ad3cf8bb6c1433a203a818eaa43d89c657dc44f9ac514a02fcc295f3beb405e014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af38723b203000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fdfd0000483045022100ab2455803055f7ddc88e6888ddbbfccec6c37e484e72a736422f9f03a9dd7ce102206b75f630e424e3b9d5b192b57621f1b07c6d18bfda4775dfa71a2060a8252f8b0147304402204a08611ab4ad7deaba2fc5491af69b7a156f01df7e39b0d86922b701cc30de00022005216da06468f52da62a7b1e499da9606b1806592b703f4690a494f7f4c86e2e014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fdfd0000483045022100fbc65e3608656da9c7607686293f83c09c76089324810e52f26e787e29a5fcaf0220154842b8bbb661c223fb96913bf4a41f00632e2f25e4c3f226a29bcdc8b42e7e01473044022046430f499b10c61bd8acaee5129b5ad0977e9e9f7d342bde281c9adaaf3f20f802202cbe8239be12dba464a6b1a881328005e843f1ff56cb6746eba43af512c668d2014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387ab9303000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
]
]

@@ -9,3 +9,3 @@ 'use strict';

describe('Base58', function() {
var buf = new buffer.Buffer([0, 1, 2, 3, 253, 254, 255]);
var buf = Buffer.from([0, 1, 2, 3, 253, 254, 255]);
var enc = '1W7N4RuG';

@@ -25,3 +25,3 @@

Base58.validCharacters(
new buffer.Buffer('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')
Buffer.from('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')
).should.equal(true);

@@ -48,3 +48,3 @@ });

Base58().set({
buf: new buffer.Buffer([])
buf: Buffer.from([])
});

@@ -51,0 +51,0 @@ });

@@ -9,3 +9,3 @@ 'use strict';

describe('Base58Check', function() {
var buf = new Buffer([0, 1, 2, 3, 253, 254, 255]);
var buf = Buffer.from([0, 1, 2, 3, 253, 254, 255]);
var enc = '14HV44ipwoaqfg';

@@ -12,0 +12,0 @@

@@ -19,3 +19,3 @@ 'use strict';

it('should create a new bufferreader with a buffer', function() {
var buf = new Buffer(0);
var buf = Buffer.alloc(0);
var br = new BufferReader(buf);

@@ -45,3 +45,3 @@ should.exist(br);

it('should return true for a blank br', function() {
var br = new BufferReader(new Buffer([]));
var br = new BufferReader( Buffer.alloc(0));
br.finished().should.equal(true);

@@ -55,3 +55,3 @@ });

it('should return the same buffer', function() {
var buf = new Buffer([0]);
var buf = Buffer.alloc(0);
var br = new BufferReader(buf);

@@ -62,3 +62,3 @@ br.readAll().toString('hex').should.equal(buf.toString('hex'));

it('should return a buffer of this length', function() {
var buf = new Buffer(10);
var buf = Buffer.alloc(10);
buf.fill(0);

@@ -73,3 +73,3 @@ var br = new BufferReader(buf);

it('should work with 0 length', function() {
var buf = new Buffer(10);
var buf = Buffer.alloc(10);
buf.fill(1);

@@ -88,3 +88,3 @@ var br = new BufferReader(buf);

it('returns correct buffer', function() {
var buf = new Buffer('73010000003766404f00000000b305434f00000000f203' +
var buf = Buffer.from('73010000003766404f00000000b305434f00000000f203' +
'0000f1030000001027000048ee00000064000000004653656520626974636f696' +

@@ -108,3 +108,3 @@ 'e2e6f72672f666562323020696620796f7520686176652074726f75626c652063' +

it('fails on length too big', function() {
var buf = new Buffer('0a00', 'hex');
var buf = Buffer.from('0a00', 'hex');
var br = new BufferReader(buf);

@@ -119,3 +119,3 @@ br.readVarLengthBuffer.bind(br).should.throw('Invalid length while reading varlength buffer');

it('should return 1', function() {
var buf = new Buffer(1);
var buf = Buffer.alloc(1);
buf.writeUInt8(1, 0);

@@ -131,3 +131,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(2);
var buf = Buffer.alloc(2);
buf.writeUInt16BE(1, 0);

@@ -143,3 +143,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(2);
var buf = Buffer.alloc(2);
buf.writeUInt16LE(1, 0);

@@ -155,3 +155,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(4);
var buf = Buffer.alloc(4);
buf.writeUInt32BE(1, 0);

@@ -167,3 +167,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(4);
var buf = Buffer.alloc(4);
buf.writeUInt32LE(1, 0);

@@ -179,3 +179,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0);

@@ -188,3 +188,3 @@ buf.writeUInt32BE(1, 4);

it('should return 2^64', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0xff);

@@ -200,3 +200,3 @@ var br = new BufferReader(buf);

it('should return 1', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0);

@@ -210,3 +210,3 @@ buf.writeUInt32LE(1, 0);

var tenbtc = 10 * 1e8;
var tenbtcBuffer = new Buffer('00ca9a3b00000000', 'hex');
var tenbtcBuffer = Buffer.from('00ca9a3b00000000', 'hex');
var br = new BufferReader(tenbtcBuffer);

@@ -217,3 +217,3 @@ br.readUInt64LEBN().toNumber().should.equal(tenbtc);

it('should return 2^30', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0);

@@ -227,3 +227,3 @@ buf.writeUInt32LE(Math.pow(2, 30), 0);

var num = Math.pow(2, 32) + 1;
var numBuffer = new Buffer('0100000001000000', 'hex');
var numBuffer = Buffer.from('0100000001000000', 'hex');
var br = new BufferReader(numBuffer);

@@ -235,3 +235,3 @@ br.readUInt64LEBN().toNumber().should.equal(num);

var maxSatoshis = 21000000 * 1e8;
var maxSatoshisBuffer = new Buffer('0040075af0750700', 'hex');
var maxSatoshisBuffer = Buffer.from('0040075af0750700', 'hex');
var br = new BufferReader(maxSatoshisBuffer);

@@ -243,3 +243,3 @@ br.readUInt64LEBN().toNumber().should.equal(maxSatoshis);

var maxSafe = Math.pow(2, 53) - 1;
var maxSafeBuffer = new Buffer('ffffffffffff1f00', 'hex');
var maxSafeBuffer = Buffer.from('ffffffffffff1f00', 'hex');
var br = new BufferReader(maxSafeBuffer);

@@ -251,3 +251,3 @@ br.readUInt64LEBN().toNumber().should.equal(maxSafe);

var bn = new BN('20000000000000', 16);
var bnBuffer = new Buffer('0000000000002000', 'hex');
var bnBuffer = Buffer.from('0000000000002000', 'hex');
var br = new BufferReader(bnBuffer);

@@ -259,3 +259,3 @@ var readbn = br.readUInt64LEBN();

it('should return 0', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0);

@@ -267,3 +267,3 @@ var br = new BufferReader(buf);

it('should return 2^64', function() {
var buf = new Buffer(8);
var buf = Buffer.alloc(8);
buf.fill(0xff);

@@ -279,3 +279,3 @@ var br = new BufferReader(buf);

it('should read a 1 byte varint', function() {
var buf = new Buffer([50]);
var buf = Buffer.from([50]);
var br = new BufferReader(buf);

@@ -286,3 +286,3 @@ br.readVarintBuf().length.should.equal(1);

it('should read a 3 byte varint', function() {
var buf = new Buffer([253, 253, 0]);
var buf = Buffer.from([253, 253, 0]);
var br = new BufferReader(buf);

@@ -293,3 +293,3 @@ br.readVarintBuf().length.should.equal(3);

it('should read a 5 byte varint', function() {
var buf = new Buffer([254, 0, 0, 0, 0]);
var buf = Buffer.from([254, 0, 0, 0, 0]);
buf.writeUInt32LE(50000, 1);

@@ -311,3 +311,3 @@ var br = new BufferReader(buf);

it('should read a 1 byte varint', function() {
var buf = new Buffer([50]);
var buf = Buffer.from([50]);
var br = new BufferReader(buf);

@@ -318,3 +318,3 @@ br.readVarintNum().should.equal(50);

it('should read a 3 byte varint', function() {
var buf = new Buffer([253, 253, 0]);
var buf = Buffer.from([253, 253, 0]);
var br = new BufferReader(buf);

@@ -325,3 +325,3 @@ br.readVarintNum().should.equal(253);

it('should read a 5 byte varint', function() {
var buf = new Buffer([254, 0, 0, 0, 0]);
var buf = Buffer.from([254, 0, 0, 0, 0]);
buf.writeUInt32LE(50000, 1);

@@ -353,3 +353,3 @@ var br = new BufferReader(buf);

it('should read a 1 byte varint', function() {
var buf = new Buffer([50]);
var buf = Buffer.from([50]);
var br = new BufferReader(buf);

@@ -360,3 +360,3 @@ br.readVarintBN().toNumber().should.equal(50);

it('should read a 3 byte varint', function() {
var buf = new Buffer([253, 253, 0]);
var buf = Buffer.from([253, 253, 0]);
var br = new BufferReader(buf);

@@ -367,3 +367,3 @@ br.readVarintBN().toNumber().should.equal(253);

it('should read a 5 byte varint', function() {
var buf = new Buffer([254, 0, 0, 0, 0]);
var buf = Buffer.from([254, 0, 0, 0, 0]);
buf.writeUInt32LE(50000, 1);

@@ -375,3 +375,3 @@ var br = new BufferReader(buf);

it('should read a 9 byte varint', function() {
var buf = Buffer.concat([new Buffer([255]), new Buffer('ffffffffffffffff', 'hex')]);
var buf = Buffer.concat([Buffer.from([255]), Buffer.from('ffffffffffffffff', 'hex')]);
var br = new BufferReader(buf);

@@ -386,3 +386,3 @@ br.readVarintBN().toNumber().should.equal(Math.pow(2, 64));

it('should reverse this [0, 1]', function() {
var buf = new Buffer([0, 1]);
var buf = Buffer.from([0, 1]);
var br = new BufferReader(buf);

@@ -389,0 +389,0 @@ br.reverse().readAll().toString('hex').should.equal('0100');

@@ -19,4 +19,4 @@ 'use strict';

it('set bufs', function() {
var buf1 = new Buffer([0]);
var buf2 = new Buffer([1]);
var buf1 = Buffer.from([0]);
var buf2 = Buffer.from([1]);
var bw = new BufferWriter().set({bufs: [buf1, buf2]});

@@ -31,4 +31,4 @@ bw.concat().toString('hex').should.equal('0001');

it('should concat these two bufs', function() {
var buf1 = new Buffer([0]);
var buf2 = new Buffer([1]);
var buf1 = Buffer.from([0]);
var buf2 = Buffer.from([1]);
var bw = new BufferWriter({bufs: [buf1, buf2]});

@@ -43,4 +43,4 @@ bw.toBuffer().toString('hex').should.equal('0001');

it('should concat these two bufs', function() {
var buf1 = new Buffer([0]);
var buf2 = new Buffer([1]);
var buf1 = Buffer.from([0]);
var buf2 = Buffer.from([1]);
var bw = new BufferWriter({bufs: [buf1, buf2]});

@@ -55,3 +55,3 @@ bw.concat().toString('hex').should.equal('0001');

it('should write a buffer', function() {
var buf = new Buffer([0]);
var buf = Buffer.from([0]);
var bw = new BufferWriter();

@@ -58,0 +58,0 @@ bw.write(buf);

@@ -13,3 +13,3 @@ 'use strict';

it('should make a new varint', function() {
var buf = new Buffer('00', 'hex');
var buf = Buffer.from('00', 'hex');
var varint = new Varint(buf);

@@ -31,3 +31,3 @@ should.exist(varint);

it('should set a buffer', function() {
var buf = new Buffer('00', 'hex');
var buf = Buffer.from('00', 'hex');
var varint = Varint().set({buf: buf});

@@ -34,0 +34,0 @@ varint.buf.toString('hex').should.equal('00');

@@ -227,4 +227,4 @@ 'use strict';

// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
var privateKeyBuffer = new Buffer('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = new Buffer('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var key = HDPrivateKey.fromObject({

@@ -244,4 +244,4 @@ network: 'testnet',

// This is to test that the previously implemented non-compliant to BIP32
var privateKeyBuffer = new Buffer('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = new Buffer('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var key = HDPrivateKey.fromObject({

@@ -261,4 +261,4 @@ network: 'testnet',

// This is to test that the previously implemented non-compliant to BIP32
var privateKeyBuffer = new Buffer('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = new Buffer('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex');
var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex');
var key = HDPrivateKey.fromObject({

@@ -277,3 +277,3 @@ network: 'testnet',

describe('edge cases', function() {
var sandbox = sinon.sandbox.create();
var sandbox = sinon.createSandbox();
afterEach(function() {

@@ -283,5 +283,5 @@ sandbox.restore();

it('will handle edge case that derived private key is invalid', function() {
var invalid = new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
var privateKeyBuffer = new Buffer('5f72914c48581fc7ddeb944a9616389200a9560177d24f458258e5b04527bcd1', 'hex');
var chainCodeBuffer = new Buffer('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex');
var invalid = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
var privateKeyBuffer = Buffer.from('5f72914c48581fc7ddeb944a9616389200a9560177d24f458258e5b04527bcd1', 'hex');
var chainCodeBuffer = Buffer.from('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex');
var unstubbed = bitcore.crypto.BN.prototype.toBuffer;

@@ -313,4 +313,4 @@ var count = 0;

it('will handle edge case that a derive public key is invalid', function() {
var publicKeyBuffer = new Buffer('029e58b241790284ef56502667b15157b3fc58c567f044ddc35653860f9455d099', 'hex');
var chainCodeBuffer = new Buffer('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex');
var publicKeyBuffer = Buffer.from('029e58b241790284ef56502667b15157b3fc58c567f044ddc35653860f9455d099', 'hex');
var chainCodeBuffer = Buffer.from('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex');
var key = new HDPublicKey({

@@ -317,0 +317,0 @@ network: 'testnet',

@@ -143,3 +143,3 @@ 'use strict';

it('returns InvalidLength if data of invalid length is given to getSerializedError', function() {
var b58s = Base58Check.encode(new buffer.Buffer('onestring'));
var b58s = Base58Check.encode(Buffer.from('onestring'));
expect(

@@ -146,0 +146,0 @@ HDPrivateKey.getSerializedError(b58s) instanceof hdErrors.InvalidLength

@@ -81,3 +81,3 @@ 'use strict';

expectFailBuilding(
Base58Check.encode(new buffer.Buffer([1, 2, 3])),
Base58Check.encode(Buffer.from([1, 2, 3])),
hdErrors.InvalidLength

@@ -84,0 +84,0 @@ );

@@ -40,3 +40,3 @@ 'use strict';

} else {
var expected = new Buffer('e7beb4d4', 'hex');
var expected = Buffer.from('e7beb4d4', 'hex');
customnet[key].should.deep.equal(expected);

@@ -79,5 +79,12 @@ }

somenet.name.should.equal('somenet');
networks.remove(somenet);
});
it('can remove a custom network by name', function() {
var net = networks.get('somenet');
should.exist(net);
networks.remove('somenet');
var net = networks.get('somenet');
should.equal(net, undefined);
});
var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey'];

@@ -84,0 +91,0 @@

@@ -57,3 +57,3 @@ 'use strict';

it('should correctly input/output a buffer', function() {
var buf = new Buffer('a6', 'hex');
var buf = Buffer.from('a6', 'hex');
Opcode.fromBuffer(buf).toBuffer().should.deep.equal(buf);

@@ -86,7 +86,15 @@ });

});
it('should work for every non-duplicate opcode', function() {
Object.keys(Opcode.map).forEach(function(key) {
if (key === 'OP_TRUE' || key === 'OP_FALSE') return;
if (key === 'OP_NOP2' || key === 'OP_NOP3') return;
Opcode.fromString(key).toString().should.equal(key);
})
})
});
describe('@map', function() {
it('should have a map containing 124 elements', function() {
_.size(Opcode.map).should.equal(124);
it('should have a map containing 141 elements', function() {
_.size(Opcode.map).should.equal(141);
});

@@ -96,7 +104,9 @@ });

describe('@reverseMap', function() {
it('should exist and have op 185', function() {
it('should exist and have ops 185 and 188', function() {
should.exist(Opcode.reverseMap);
Opcode.reverseMap[185].should.equal('OP_NOP10');
Opcode.reverseMap[188].should.equal('OP_REVERSEBYTES');
});
});
var smallints = [

@@ -144,2 +154,3 @@ Opcode('OP_0'),

});
describe('@isSmallIntOp', function() {

@@ -146,0 +157,0 @@ var testIsSmallInt = function(op) {

@@ -20,3 +20,3 @@ 'use strict';

var hex2 = '8080808080808080808080808080808080808080808080808080808080808080';
var buf = new Buffer(hex, 'hex');
var buf = Buffer.from(hex, 'hex');
var wifTestnet = 'cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG';

@@ -131,3 +131,3 @@ var wifTestnetUncompressed = '92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu';

var buf = Base58Check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf2 = Buffer.concat([buf, new Buffer(0x01)]);
var buf2 = Buffer.concat([buf, Buffer.from([0x01])]);
return new PrivateKey(buf2);

@@ -140,3 +140,3 @@ }).to.throw('Length of buffer must be 33 (uncompressed) or 34 (compressed');

var buf = Base58Check.decode('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var buf2 = Buffer.concat([new Buffer('ff', 'hex'), buf.slice(1, 33)]);
var buf2 = Buffer.concat([ Buffer.from('ff', 'hex'), buf.slice(1, 33)]);
return new PrivateKey(buf2);

@@ -338,3 +338,3 @@ }).to.throw('Invalid network');

it('will output a 31 byte buffer', function() {
var bn = BN.fromBuffer(new Buffer('9b5a0e8fee1835e21170ce1431f9b6f19b487e67748ed70d8a4462bc031915', 'hex'));
var bn = BN.fromBuffer(Buffer.from('9b5a0e8fee1835e21170ce1431f9b6f19b487e67748ed70d8a4462bc031915', 'hex'));
var privkey = new PrivateKey(bn);

@@ -423,3 +423,3 @@ var buffer = privkey.toBufferNoPadding();

var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
var privkey = new PrivateKey(new BN(new Buffer(privhex, 'hex')));
var privkey = new PrivateKey(new BN(Buffer.from(privhex, 'hex')));
var pubkey = privkey.toPublicKey();

@@ -432,3 +432,3 @@ pubkey.toString().should.equal(pubhex);

var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
var privkey = new PrivateKey(new BN(new Buffer(privhex, 'hex')));
var privkey = new PrivateKey(new BN(Buffer.from(privhex, 'hex')));
privkey.publicKey.toString().should.equal(pubhex);

@@ -435,0 +435,0 @@ });

@@ -52,3 +52,3 @@ 'use strict';

var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
var privkey = new PrivateKey(new BN(new Buffer(privhex, 'hex')));
var privkey = new PrivateKey(new BN(Buffer.from(privhex, 'hex')));
var pk = new PublicKey(privkey);

@@ -113,3 +113,3 @@ pk.toString().should.equal(pubhex);

it('from a hex encoded DER buffer', function() {
var pk = new PublicKey(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
var pk = new PublicKey(Buffer.from('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
should.exist(pk.point);

@@ -225,3 +225,3 @@ pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

it('should parse this uncompressed public key', function() {
var pk = PublicKey.fromBuffer(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
var pk = PublicKey.fromBuffer(Buffer.from('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

@@ -232,3 +232,3 @@ pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');

it('should parse this compressed public key', function() {
var pk = PublicKey.fromBuffer(new Buffer('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromBuffer(Buffer.from('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

@@ -240,3 +240,3 @@ pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');

(function() {
PublicKey.fromBuffer(new Buffer('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
PublicKey.fromBuffer(Buffer.from('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
}).should.throw();

@@ -253,3 +253,3 @@ });

(function() {
PublicKey.fromBuffer(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a34112', 'hex'));
PublicKey.fromBuffer(Buffer.from('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a34112', 'hex'));
}).should.throw('Length of x and y must be 32 bytes');

@@ -263,3 +263,3 @@ });

it('should parse this uncompressed public key', function() {
var pk = PublicKey.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
var pk = PublicKey.fromDER(Buffer.from('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

@@ -270,3 +270,3 @@ pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');

it('should parse this compressed public key', function() {
var pk = PublicKey.fromDER(new Buffer('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromDER(Buffer.from('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

@@ -278,3 +278,3 @@ pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');

(function() {
PublicKey.fromDER(new Buffer('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
PublicKey.fromDER(Buffer.from('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
}).should.throw();

@@ -298,3 +298,3 @@ });

it('should create this known public key', function() {
var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var x = BN.fromBuffer(Buffer.from('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromX(true, x);

@@ -307,3 +307,3 @@ pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

it('should error because odd was not included as a param', function() {
var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var x = BN.fromBuffer(Buffer.from('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
(function() {

@@ -319,3 +319,3 @@ return PublicKey.fromX(null, x);

it('should return this compressed DER format', function() {
var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var x = BN.fromBuffer(Buffer.from('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromX(true, x);

@@ -326,3 +326,3 @@ pk.toBuffer().toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

it('should return this uncompressed DER format', function() {
var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var x = BN.fromBuffer(Buffer.from('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromX(true, x);

@@ -337,3 +337,3 @@ pk.toBuffer().toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

it('should return this compressed DER format', function() {
var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var x = BN.fromBuffer(Buffer.from('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
var pk = PublicKey.fromX(true, x);

@@ -340,0 +340,0 @@ pk.toDER().toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');

@@ -7,5 +7,7 @@ 'use strict';

var Transaction = bitcore.Transaction;
var Output = bitcore.Transaction.Output;
var PrivateKey = bitcore.PrivateKey;
var Script = bitcore.Script;
var BN = bitcore.crypto.BN;
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;

@@ -18,2 +20,3 @@ var Opcode = bitcore.Opcode;

var tx_invalid = require('../data/bitcoind/tx_invalid');
var vmb_tests = require('../data/libauth/vmb_tests');

@@ -29,3 +32,5 @@ //the script string format used in bitcoind data tests

}
if (token === '-1') {
token = '1NEGATE';
}
var opstr;

@@ -36,6 +41,6 @@ var opcodenum;

var hex = token.slice(2);
bw.write(new Buffer(hex, 'hex'));
bw.write(Buffer.from(hex, 'hex'));
} else if (token[0] === '\'') {
var tstr = token.slice(1, token.length - 1);
var cbuf = new Buffer(tstr);
var cbuf = Buffer.from(tstr);
tbuf = Script().add(cbuf).toBuffer();

@@ -86,3 +91,3 @@ bw.write(tbuf);

})).should.equal(false);
Interpreter.castToBool(new Buffer('0080', 'hex')).should.equal(false); //negative 0
Interpreter.castToBool(Buffer.from('0080', 'hex')).should.equal(false); //negative 0
Interpreter.castToBool(new BN(1).toSM({

@@ -95,3 +100,3 @@ endian: 'little'

var buf = new Buffer('00', 'hex');
var buf = Buffer.from('00', 'hex');
var bool = BN.fromSM(buf, {

@@ -205,2 +210,6 @@ endian: 'little'

if(flagstr.indexOf('DISALLOW_SEGWIT_RECOVERY') !== -1) {
flags = flags | Interpreter.SCRIPT_DISALLOW_SEGWIT_RECOVERY;
}
if (flagstr.indexOf('FORKID') !== -1) {

@@ -218,5 +227,22 @@ flags = flags | Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID;

if (flagstr.indexOf('SCHNORR_MULTISIG') !== -1) {
flags = flags | Interpreter.SCRIPT_ENABLE_SCHNORR_MULTISIG;
}
if (flagstr.indexOf('MINIMALIF') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_MINIMALIF;
}
if (flagstr.indexOf('64_BIT_INTEGERS') !== -1) {
flags = flags | Interpreter.SCRIPT_64_BIT_INTEGERS;
}
if (flagstr.indexOf('INPUT_SIGCHECKS') !== -1) {
flags = flags | Interpreter.SCRIPT_VERIFY_INPUT_SIGCHECKS;
}
if (flagstr.indexOf('NATIVE_INTROSPECTION') !== -1) {
flags = flags | Interpreter.SCRIPT_NATIVE_INTROSPECTION;
}
return flags;

@@ -232,2 +258,3 @@ };

var testFixture = function(vector, expected, extraData) {
var scriptSig = Script.fromBitcoindString(vector[0]);

@@ -241,5 +268,6 @@ var scriptPubkey = Script.fromBitcoindString(vector[1]);

var hashbuf = new Buffer(32);
var hashbuf = Buffer.alloc(32);
hashbuf.fill(0);
var credtx = new Transaction();
credtx.setVersion(1);
credtx.uncheckedAddInput(new Transaction.Input({

@@ -253,3 +281,3 @@ prevTxId: '0000000000000000000000000000000000000000000000000000000000000000',

script: scriptPubkey,
satoshis: inputAmount,
satoshis: inputAmount,
}));

@@ -259,2 +287,3 @@ var idbuf = credtx.id;

var spendtx = new Transaction();
spendtx.setVersion(1);
spendtx.uncheckedAddInput(new Transaction.Input({

@@ -303,2 +332,28 @@ prevTxId: idbuf.toString('hex'),

});
describe('libauth vmb evaluation fixtures', () => {
const flags = getFlags('P2SH CLEANSTACK MINIMALDATA VERIFY_CHECKLOCKTIMEVERIFY NATIVE_INTROSPECTION 64_BIT_INTEGERS');
const getOutputsFromHex = outputsHex => {
const reader = new BufferReader(Buffer.from(outputsHex,'hex'));
const numOutputs = reader.readVarintNum();
const outputs = new Array(numOutputs).fill(1).map(() => Output.fromBufferReader(reader));
return outputs;
};
vmb_tests.forEach(test => {
const testId = test[0];
const txHex = test[4];
const sourceOutputsHex = test[5];
const labels = test[6];
const inputIndex = test[7] || 0;
const tx = new Transaction(txHex);
const outputs = getOutputsFromHex(sourceOutputsHex);
tx.inputs.forEach((input, index) => input.output = outputs[index]);
const scriptSig = tx.inputs[inputIndex].script;
const scriptPubkey = tx.inputs[inputIndex].output.script;
it(`should pass vmb_tests vector ${testId}`, () => {
const valid = Interpreter().verify(scriptSig, scriptPubkey, tx, inputIndex, flags);
const expectedValidity = !labels[0].endsWith('invalid');
valid.should.equal(expectedValidity);
});
});
});
describe('bitcoind transaction evaluation fixtures', function() {

@@ -330,2 +385,3 @@ var test_txs = function(set, expected) {

var tx = new Transaction(txhex);
tx.setVersion(1);
var allInputsVerified = true;

@@ -332,0 +388,0 @@ tx.inputs.forEach(function(txin, j) {

@@ -377,6 +377,2 @@ 'use strict';

it('should identify this known non-pubkeyhashin (bad signature version)', function() {
Script('70 0x4043021f336721e4343f67c835cbfd465477db09073dc38a936f9c445d573c1c8a7fdf022064b0e3cb6892a9ecf870030e3066bc259e1f24841c9471d97f9be08b73f6530701 33 0x0370b2e1dcaa8f51cb0ead1221dd8cb31721502b3b5b7d4b374d263dfec63a4369').isPublicKeyHashIn().should.equal(false);
});
it('should identify this known non-pubkeyhashin (no public key)', function() {

@@ -897,2 +893,18 @@ Script('70 0x3043021f336721e4343f67c835cbfd465477db09073dc38a936f9c445d573c1c8a7fdf022064b0e3cb6892a9ecf870030e3066bc259e1f24841c9471d97f9be08b73f6530701 OP_CHECKSIG').isPublicKeyHashIn().should.equal(false);

describe('#getPublicKey', () => {
const publicKey = PublicKey.fromString('02371b6955629ea6fd014b9e14612e72de2729d33ff26ad20b9e7c558c6a611221');
it('should return the public key for a public key output', () => {
const publicKeyOutput = Script.buildPublicKeyOut(publicKey);
const retrievedPublicKey = publicKeyOutput.getPublicKey();
retrievedPublicKey.toString('hex').should.equal(publicKey.toString('hex'));
})
it('should return the public key for a public key hash input', () => {
const signature = bitcore.crypto.Signature.fromString('e4acdce75b9033de8f3b0384f1e8eba3be6aade38b2c3ea17037b57ccf3c6b82589b6e39d8cd375839fa8990faa45948a70b07dec76140c956d48586404f3123');
const sigtype = 0x41;
const publicKeyHashInput = Script.buildPublicKeyHashIn(publicKey, signature, sigtype);
const retrievedPublicKey = publicKeyHashInput.getPublicKey();
retrievedPublicKey.toString('hex').should.equal(publicKey.toString('hex'));
});
});
describe('getData returns associated data', function() {

@@ -899,0 +911,0 @@ it('works with this testnet transaction', function() {

@@ -99,2 +99,38 @@ 'use strict';

});
describe('handling the BIP68 (sequenceNumber locktime)', function() {
var blockHeight = 3434;
it('handles a null locktime', function() {
var input = new Input(output);
expect(input.getLockTime()).to.equal(null);
});
it('handles a simple seconds example', function() {
var input = new Input()
.lockForSeconds(1e5);
var expected = (parseInt(1e5 / 512) * 512) ;
input.getLockTime().should.deep.equal(expected);
expected = (Math.floor(expected/512) ) | Input.SEQUENCE_LOCKTIME_TYPE_FLAG;
input.sequenceNumber.should.equal(expected | Input.SEQUENCE_LOCKTIME_TYPE_FLAG);
});
it('accepts a block height', function() {
var input = new Input()
.lockUntilBlockHeight(blockHeight);
input.sequenceNumber.should.equal(blockHeight);
input.getLockTime().should.deep.equal(blockHeight);
});
it('fails if the block height is too high', function() {
expect(function() {
return new Input().lockUntilBlockHeight(5e8);
}).to.throw(errors.Transaction.Input.BlockHeightOutOfRange);
});
it('fails if the block height is negative', function() {
expect(function() {
return new Input().lockUntilBlockHeight(-1);
}).to.throw(errors.Transaction.Input.BlockHeightOutOfRange);
});
});
});

@@ -114,2 +114,22 @@ 'use strict';

});
it('can build a redeem script from non-sorted public keys with a noSorting option', function() {
var nonSortedPublicKeys = [public1, public2, public3];
var threshold = 2;
var opts = { noSorting: true };
var nonSortedRedeemScript = Script.buildMultisigOut(nonSortedPublicKeys, threshold, opts);
var nonSortedAddress = Address.payingTo(nonSortedRedeemScript);
nonSortedAddress.toLegacyAddress().should.equal('HLEAcJ3iYF5sRGR4oSowZx5fuqigfD5Ah7');
var nonSortedOutput = Object.assign({}, output, {
address: nonSortedAddress.toLegacyAddress(),
script: new Script(nonSortedAddress)
});
var transaction = new Transaction()
.from(nonSortedOutput, nonSortedPublicKeys, threshold, opts)
.to(address, 1000000);
var input = transaction.inputs[0];
input.redeemScript.equals(nonSortedRedeemScript).should.equal(true);
});
});

@@ -158,3 +158,3 @@ "use strict";

it("#toObject roundtrip will handle an invalid (null) script", function() {
var invalidOutputScript = new Buffer("0100000000000000014c", "hex");
var invalidOutputScript = Buffer.from("0100000000000000014c", "hex");
var br = new bitcore.encoding.BufferReader(invalidOutputScript);

@@ -168,3 +168,3 @@ var output = Output.fromBufferReader(br);

it("inspect will work with an invalid (null) script", function() {
var invalidOutputScript = new Buffer("0100000000000000014c", "hex");
var invalidOutputScript = Buffer.from("0100000000000000014c", "hex");
var br = new bitcore.encoding.BufferReader(invalidOutputScript);

@@ -189,3 +189,3 @@ var output = Output.fromBufferReader(br);

satoshis: 1000,
script: new Buffer("4c", "hex")
script: Buffer.from("4c", "hex")
});

@@ -192,0 +192,0 @@ should.equal(output.script, null);

@@ -31,8 +31,8 @@ 'use strict';

var vector = ["3eb87070042d16f9469b0080a3c1fe8de0feae345200beef8b1e0d7c62501ae0df899dca1e03000000066a0065525365ffffffffd14a9a335e8babddd89b5d0b6a0f41dd6b18848050a0fc48ce32d892e11817fd030000000863acac00535200527ff62cf3ad30d9064e180eaed5e6303950121a8086b5266b55156e4f7612f2c7ebf223e0020000000100ffffffff6273ca3aceb55931160fa7a3064682b4790ee016b4a5c0c0d101fd449dff88ba01000000055351ac526aa3b8223d0421f25b0400000000026552f92db70500000000075253516a656a53c4a908010000000000b5192901000000000652525251516aa148ca38", "acab53", 3, -1325231124, "fbbc83ed610e416d94dcee2bb3bc35dfea8060b8052c59eabd7e998e3e978328"];
var txbuf = new buffer.Buffer(vector[0], 'hex');
var scriptbuf = new buffer.Buffer(vector[1], 'hex');
var txbuf = Buffer.from(vector[0], 'hex');
var scriptbuf = Buffer.from(vector[1], 'hex');
var subscript = Script(scriptbuf);
var nin = vector[2];
var nhashtype = vector[3];
var sighashbuf = new buffer.Buffer(vector[4], 'hex');
var sighashbuf = Buffer.from(vector[4], 'hex');
var tx = new Transaction(txbuf);

@@ -56,4 +56,4 @@

it('test vector from bitcoind #' + i + ' (' + vector[4].substring(0, 16) + ')', function() {
var txbuf = new buffer.Buffer(vector[0], 'hex');
var scriptbuf = new buffer.Buffer(vector[1], 'hex');
var txbuf = Buffer.from(vector[0], 'hex');
var scriptbuf = Buffer.from(vector[1], 'hex');
var subscript = Script(scriptbuf);

@@ -63,3 +63,3 @@ var nin = vector[2];

// var nhashtype = vector[3]>>>0;
var sighashbuf = new buffer.Buffer(vector[4], 'hex');
var sighashbuf = Buffer.from(vector[4], 'hex');
var tx = new Transaction(txbuf);

@@ -66,0 +66,0 @@

@@ -107,3 +107,3 @@ 'use strict';

var serialized = signature.toObject();
serialized.signature = new Buffer(serialized.signature, 'hex');
serialized.signature = Buffer.from(serialized.signature, 'hex');
expect(TransactionSignature.fromObject(serialized).toObject()).to.deep.equal(signature.toObject());

@@ -110,0 +110,0 @@ });

@@ -13,2 +13,3 @@ 'use strict';

var Transaction = bitcore.Transaction;
var Signature = bitcore.Signature;
var Input = bitcore.Transaction.Input;

@@ -186,3 +187,3 @@ var Output = bitcore.Transaction.Output;

var i = 0;
var transaction = new Transaction();
var transaction = (new Transaction()).setVersion(1);
while (i < vector.length) {

@@ -318,3 +319,3 @@ var command = vector[i];

transaction.outputs.length.should.equal(2);
transaction.outputs[1].satoshis.should.equal(477100);
transaction.outputs[1].satoshis.should.equal(473400);
transaction.outputs[1].script.toString()

@@ -393,3 +394,3 @@ .should.equal(Script.fromAddress(changeAddress).toString());

transaction.outputs.length.should.equal(2);
transaction.outputs[1].satoshis.should.equal(40464);
transaction.outputs[1].satoshis.should.equal(37504);
});

@@ -1011,3 +1012,3 @@ it('fee per byte (low fee) can be set up manually', function () {

transaction.inputAmount.should.equal(100000000);
transaction.outputAmount.should.equal(99977100);
transaction.outputAmount.should.equal(99973400);
});

@@ -1110,3 +1111,3 @@ it('returns correct values for coinjoin transaction', function() {

tx.outputs[0].script.toAddress().toString().should.equal(toAddress);
tx.outputs[1].satoshis.should.equal(89977100);
tx.outputs[1].satoshis.should.equal(89973400);
tx.outputs[1].script.toAddress().toString().should.equal(changeAddress);

@@ -1117,2 +1118,26 @@ });

describe('isZceSecured', () => {
const zceRawTx = '0100000004ff8abba28b308eb0c1e6bd10b29f30b957dad3be871b40553d8324a79ad1bdea010000006441c4f26e20f40e01f186c70cf89c4003c07870fa4b4370999ed14b4700425a39f89bdc8324abd5245db2df5b9f63f1232a7907e87f05843c2db5062b35dc7b77b9412103978af6aff2c8b93b8776fbb6e33b532316326667ec79f21704589576548f3dcaffffffff85ee380cc3329273aa667d3c29ea9fc81167e8a06ed0feac4df12809f60a064100000000644171dccb5867d2dc9fe9278c2de3916260994a32fc4c724663fb1b9f0fe3f10d8d46a20f3881487c0d391b45419b57d301db4811174ba3fc05c6d16865f4e4f136412103351c7e4cc8e77ccab99b23de6c1585defc72b99da42d2878d6cb64a4186bb0c7ffffffffbcdf29fde37c27c291f585cb83af678dc54ce950f8c5bc7e1d25413b240c94ea000000006441092d7d0dc3b785d13c8e910d8533272a33812b7a61479002ffb7d5cf620fd813c6f59c70f874e78ac65ed720afe1ff6b09a299c03ebb4f8f14f4e7370db852f5412103f4d946e03044e8314e5d87b674154b21c5c7a72f26b96c8a734b1b4ded7263ebffffffff9dc766918e1deed380ddce878c4239f5dd434498f5b65ac3520980dadf3375c3000000006441ae19b88f8503b6beb9d9508d46984486d01ace007fceb90c1b813be51b88ab7e576ba1711e52fcfd8487f22373acc9550a107d5565b9f07a2b004368247358bb412103de52c25690cf07f3f95ba76129c43b9099b51fe151789bc96ac75515b3d48df9ffffffff033c7a0300000000001976a9140157345215a85cbdd767cf947e0c3503e349bfbf88acf63b0000000000001976a914754f61f94a91042b40e5eb804d4db5d766239f4488ac832c00000000000017a914ad6306ad48a63fd28884974ae1ef579af4279a6b8700000000';
const zceTx = new Transaction(zceRawTx);
const reclaimRawTx = '0100000001b5389a3c3ddcdf02569f7d44442923ddaa7ac6bc889983dff8a1823d7f33169402000000b44135429e569603d928f65e808a3163b59431317c2032f8b611cc1a5a8c7bc6e577b0697000d85950a5a29b7544abdcda3467cc0b5f513e3f7bb616f8ad257badf04121035fb4cada6334e9179b4ed1294a510bcaf8e6f8622030f301e1a76856649924194c4e76a914f92b0b93d58cbb77b51e4f76de22fe47d5000e0f8763ac676b6b5279a96c637c687ea96c637c687ea914c319f2ebff371fd5fcff74768e8200d446fb803188785479879169766bbb6cba68ffffffff017a2b0000000000001976a91425707fbb5f80cd52cc86e88a456a95bbdb4f0c8788ac00000000';
const instantAcceptanceEscrow = 10721;
const requiredFeeRate = 1;
it('should return true for a properly constructed escrowReclaimTx', () => {
const zceSecured = zceTx.isZceSecured(reclaimRawTx, instantAcceptanceEscrow, requiredFeeRate);
zceSecured.should.equal(true);
});
it('should return false if insufficient escrow provided', () => {
const zceSecured = zceTx.isZceSecured(reclaimRawTx, instantAcceptanceEscrow + 1, requiredFeeRate);
zceSecured.should.equal(false);
});
it('should return false if insufficient fee rate used', () => {
const zceSecured = zceTx.isZceSecured(reclaimRawTx, instantAcceptanceEscrow, requiredFeeRate + 1);
zceSecured.should.equal(false);
});
it('should not crash and return false if invalid escrowReclaimTx provided', () => {
const zceSecured = zceTx.isZceSecured('invalidhex', instantAcceptanceEscrow, requiredFeeRate);
zceSecured.should.equal(false);
});
});
describe('BIP69 Sorting', function() {

@@ -1221,3 +1246,2 @@

});
});

@@ -1228,3 +1252,3 @@ });

var tx_empty_hex = '01000000000000000000';
var tx_empty_hex = '02000000000000000000';

@@ -1231,0 +1255,0 @@ /* jshint maxlen: 1000 */

@@ -15,19 +15,19 @@ 'use strict';

it('recognizes these two equal buffers', function() {
var bufferA = new Buffer([1, 2, 3]);
var bufferB = new Buffer('010203', 'hex');
var bufferA = Buffer.from([1, 2, 3]);
var bufferB = Buffer.from('010203', 'hex');
BufferUtil.equal(bufferA, bufferB).should.equal(true);
});
it('no false positive: returns false with two different buffers', function() {
var bufferA = new Buffer([1, 2, 3]);
var bufferB = new Buffer('010204', 'hex');
var bufferA = Buffer.from([1, 2, 3]);
var bufferB = Buffer.from('010204', 'hex');
BufferUtil.equal(bufferA, bufferB).should.equal(false);
});
it('coverage: quickly realizes a difference in size and returns false', function() {
var bufferA = new Buffer([1, 2, 3]);
var bufferB = new Buffer([]);
var bufferA = Buffer.from([1, 2, 3]);
var bufferB = Buffer.from([]);
BufferUtil.equal(bufferA, bufferB).should.equal(false);
});
it('"equals" is an an alias for "equal"', function() {
var bufferA = new Buffer([1, 2, 3]);
var bufferB = new Buffer([1, 2, 3]);
var bufferA = Buffer.from([1, 2, 3]);
var bufferB = Buffer.from([1, 2, 3]);
BufferUtil.equal(bufferA, bufferB).should.equal(true);

@@ -44,7 +44,7 @@ BufferUtil.equals(bufferA, bufferB).should.equal(true);

expect(function() {
BufferUtil.fill(new Buffer([0, 0, 0]), 'invalid');
BufferUtil.fill(Buffer.from([0, 0, 0]), 'invalid');
}).to.throw(errors.InvalidArgumentType);
});
it('works correctly for a small buffer', function() {
var buffer = BufferUtil.fill(new Buffer(10), 6);
var buffer = BufferUtil.fill(Buffer.alloc(10), 6);
for (var i = 0; i < 10; i++) {

@@ -61,3 +61,3 @@ buffer[i].should.equal(6);

it('has no false negative', function() {
expect(BufferUtil.isBuffer(new Buffer(0))).to.equal(true);
expect(BufferUtil.isBuffer(Buffer.alloc(0))).to.equal(true);
});

@@ -99,3 +99,3 @@ });

expect(BufferUtil.integerAsSingleByteBuffer(
BufferUtil.integerFromSingleByteBuffer(new Buffer([255]))
BufferUtil.integerFromSingleByteBuffer(Buffer.from([255]))
)[0]).to.equal(255);

@@ -133,23 +133,6 @@ });

describe('buffer to hex', function() {
it('returns an expected value in hexa', function() {
expect(BufferUtil.bufferToHex(new Buffer([255, 0, 128]))).to.equal('ff0080');
});
it('checks the argument type', function() {
expect(function() {
BufferUtil.bufferToHex('invalid');
}).to.throw(errors.InvalidArgumentType);
});
it('round trips', function() {
var original = new Buffer([255, 0, 128]);
var hexa = BufferUtil.bufferToHex(original);
var back = BufferUtil.hexToBuffer(hexa);
expect(BufferUtil.equal(original, back)).to.equal(true);
});
});
describe('reverse', function() {
it('reverses a buffer', function() {
// http://bit.ly/1J2Ai4x
var original = new Buffer([255, 0, 128]);
var original = Buffer.from([255, 0, 128]);
var reversed = BufferUtil.reverse(original);

@@ -156,0 +139,0 @@ original[0].should.equal(reversed[2]);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc