bitcore-lib-ltc
Advanced tools
Comparing version 10.0.21 to 10.0.28
@@ -253,3 +253,3 @@ 'use strict'; | ||
} | ||
info.network = bufferVersion.network; | ||
info.network = networkObj || bufferVersion.network; | ||
info.type = bufferVersion.type; | ||
@@ -256,0 +256,0 @@ return info; |
@@ -47,3 +47,7 @@ 'use strict'; | ||
} | ||
return networkMaps[arg]; | ||
if(networkMaps[arg] && networkMaps[arg].length >= 1) { | ||
return networkMaps[arg][0]; | ||
} else { | ||
return networkMaps[arg]; | ||
} | ||
} | ||
@@ -80,2 +84,3 @@ | ||
scripthash2: data.scripthash2, | ||
bech32prefix: data.bech32prefix, | ||
xpubkey: data.xpubkey, | ||
@@ -112,3 +117,6 @@ xprivkey: data.xprivkey | ||
if (!_.isUndefined(value) && !_.isObject(value)) { | ||
networkMaps[value] = network; | ||
if(!networkMaps[value]) { | ||
networkMaps[value] = []; | ||
} | ||
networkMaps[value].push(network); | ||
} | ||
@@ -182,3 +190,3 @@ }); | ||
name: 'testnet', | ||
alias: 'regtest', | ||
alias: 'test', | ||
pubkeyhash: 0x6f, // 111 | ||
@@ -188,4 +196,11 @@ privatekey: 0xef, // 239 | ||
scripthash2: 0xc4, // 196 | ||
bech32prefix: 'tltc', | ||
xpubkey: 0x043587cf, | ||
xprivkey: 0x04358394 | ||
xprivkey: 0x04358394, | ||
networkMagic: 0xfdd2c8f1, | ||
port: 19335, | ||
dnsSeeds: [ | ||
'testnet-seed.litecointools.com', | ||
'seed-b.litecoin.loshan.co.uk' | ||
] | ||
}); | ||
@@ -199,85 +214,26 @@ | ||
// Add configurable values for testnet/regtest | ||
var TESTNET = { | ||
PORT: 19335, | ||
NETWORK_MAGIC: BufferUtil.integerAsBuffer(0xfdd2c8f1), | ||
DNS_SEEDS: [ | ||
'testnet-seed.litecointools.com', | ||
'seed-b.litecoin.loshan.co.uk' | ||
], | ||
BECH32_PREFIX: 'tltc' | ||
}; | ||
for (var key in TESTNET) { | ||
if (!_.isObject(TESTNET[key])) { | ||
networkMaps[TESTNET[key]] = testnet; | ||
} | ||
} | ||
networkMaps[TESTNET.NETWORK_MAGIC.toString('hex')] = testnet; | ||
var REGTEST = { | ||
PORT: 19444, | ||
NETWORK_MAGIC: BufferUtil.integerAsBuffer(0xfabfb5da), | ||
DNS_SEEDS: [], | ||
BECH32_PREFIX: 'rltc' | ||
}; | ||
for (var key in REGTEST) { | ||
if (!_.isObject(REGTEST[key])) { | ||
networkMaps[REGTEST[key]] = testnet; | ||
} | ||
} | ||
networkMaps[REGTEST.NETWORK_MAGIC.toString('hex')] = testnet; | ||
Object.defineProperty(testnet, 'port', { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
if (this.regtestEnabled) { | ||
return REGTEST.PORT; | ||
} else { | ||
return TESTNET.PORT; | ||
} | ||
} | ||
addNetwork({ | ||
name: 'regtest', | ||
alias: 'dev', | ||
pubkeyhash: 0x6f, // 111 | ||
privatekey: 0xef, // 239 | ||
scripthash: 0x3a, // 58 | ||
scripthash2: 0xc4, // 196 | ||
bech32prefix: 'rltc', | ||
xpubkey: 0x043587cf, | ||
xprivkey: 0x04358394, | ||
networkMagic: 0xfabfb5da, | ||
port: 19444, | ||
dnsSeeds: [] | ||
}); | ||
Object.defineProperty(testnet, 'networkMagic', { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
if (this.regtestEnabled) { | ||
return REGTEST.NETWORK_MAGIC; | ||
} else { | ||
return TESTNET.NETWORK_MAGIC; | ||
} | ||
} | ||
}); | ||
/** | ||
* @instance | ||
* @member Networks#testnet | ||
*/ | ||
var regtest = get('regtest'); | ||
Object.defineProperty(testnet, 'dnsSeeds', { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
if (this.regtestEnabled) { | ||
return REGTEST.DNS_SEEDS; | ||
} else { | ||
return TESTNET.DNS_SEEDS; | ||
} | ||
} | ||
}); | ||
Object.defineProperty(testnet, 'bech32prefix', { | ||
enumerable: true, | ||
configurable: false, | ||
get: function() { | ||
if (this.regtestEnabled) { | ||
return REGTEST.BECH32_PREFIX | ||
} else { | ||
return TESTNET.BECH32_PREFIX | ||
} | ||
} | ||
}) | ||
/** | ||
* @function | ||
* @deprecated | ||
* @member Networks#enableRegtest | ||
@@ -292,2 +248,3 @@ * Will enable regtest features for testnet | ||
* @function | ||
* @deprecated | ||
* @member Networks#disableRegtest | ||
@@ -310,2 +267,3 @@ * Will disable regtest features for testnet | ||
testnet: testnet, | ||
regtest: regtest, | ||
get: get, | ||
@@ -312,0 +270,0 @@ enableRegtest: enableRegtest, |
@@ -38,5 +38,5 @@ 'use strict'; | ||
return Script.fromBuffer(from.toBuffer()); | ||
} else if (_.isString(from)) { | ||
} else if (typeof from === 'string') { | ||
return Script.fromString(from); | ||
} else if (_.isObject(from) && _.isArray(from.chunks)) { | ||
} else if (_.isObject(from) && Array.isArray(from.chunks)) { | ||
this.set(from); | ||
@@ -48,3 +48,3 @@ } | ||
$.checkArgument(_.isObject(obj)); | ||
$.checkArgument(_.isArray(obj.chunks)); | ||
$.checkArgument(Array.isArray(obj.chunks)); | ||
this.chunks = obj.chunks; | ||
@@ -148,3 +148,3 @@ return this; | ||
if (_.isUndefined(opcodenum)) { | ||
if (opcodenum == null) { | ||
var buf = Buffer.from(tokens[i], 'hex'); | ||
@@ -194,3 +194,3 @@ script.chunks.push({ | ||
if (_.isUndefined(opcodenum)) { | ||
if (opcodenum == null) { | ||
opcodenum = parseInt(token); | ||
@@ -533,3 +533,3 @@ if (opcodenum > 0 && opcodenum < Opcode.OP_PUSHDATA1) { | ||
if (this.isDataOut() || this.isScriptHashOut() || this.isWitnessScriptHashOut() || this.isWitnessPublicKeyHashOut()) { | ||
if (_.isUndefined(this.chunks[1])) { | ||
if (this.chunks[1] == null) { | ||
return Buffer.alloc(0); | ||
@@ -551,3 +551,3 @@ } else { | ||
Script.prototype.isPushOnly = function() { | ||
return _.every(this.chunks, function(chunk) { | ||
return this.chunks.every(function(chunk) { | ||
return chunk.opcodenum <= Opcode.OP_16; | ||
@@ -782,3 +782,3 @@ }); | ||
script.add(Opcode.smallInt(threshold)); | ||
publicKeys = _.map(publicKeys, PublicKey); | ||
publicKeys = publicKeys.map(PublicKey); | ||
var sorted = publicKeys; | ||
@@ -823,13 +823,13 @@ if (!opts.noSorting) { | ||
Script.buildMultisigIn = function(pubkeys, threshold, signatures, opts) { | ||
$.checkArgument(_.isArray(pubkeys)); | ||
$.checkArgument(_.isNumber(threshold)); | ||
$.checkArgument(_.isArray(signatures)); | ||
$.checkArgument(Array.isArray(pubkeys)); | ||
$.checkArgument(!isNaN(threshold)); | ||
$.checkArgument(Array.isArray(signatures)); | ||
opts = opts || {}; | ||
var s = new Script(); | ||
s.add(Opcode.OP_0); | ||
_.each(signatures, function(signature) { | ||
for (const signature of signatures) { | ||
$.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers'); | ||
// TODO: allow signatures to be an array of Signature objects | ||
s.add(signature); | ||
}); | ||
} | ||
return s; | ||
@@ -851,13 +851,13 @@ }; | ||
Script.buildP2SHMultisigIn = function(pubkeys, threshold, signatures, opts) { | ||
$.checkArgument(_.isArray(pubkeys)); | ||
$.checkArgument(_.isNumber(threshold)); | ||
$.checkArgument(_.isArray(signatures)); | ||
$.checkArgument(Array.isArray(pubkeys)); | ||
$.checkArgument(!isNaN(threshold)); | ||
$.checkArgument(Array.isArray(signatures)); | ||
opts = opts || {}; | ||
var s = new Script(); | ||
s.add(Opcode.OP_0); | ||
_.each(signatures, function(signature) { | ||
for (const signature of signatures) { | ||
$.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers'); | ||
// TODO: allow signatures to be an array of Signature objects | ||
s.add(signature); | ||
}); | ||
} | ||
s.add((opts.cachedMultisig || Script.buildMultisigOut(pubkeys, threshold, opts)).toBuffer()); | ||
@@ -873,7 +873,7 @@ return s; | ||
Script.buildPublicKeyHashOut = function(to) { | ||
$.checkArgument(!_.isUndefined(to)); | ||
$.checkArgument(to instanceof PublicKey || to instanceof Address || _.isString(to)); | ||
$.checkArgument(to != null); | ||
$.checkArgument(to instanceof PublicKey || to instanceof Address || typeof to === 'string'); | ||
if (to instanceof PublicKey) { | ||
to = to.toAddress(); | ||
} else if (_.isString(to)) { | ||
} else if (typeof to === 'string') { | ||
to = new Address(to); | ||
@@ -897,7 +897,7 @@ } | ||
Script.buildWitnessV0Out = function(to) { | ||
$.checkArgument(!_.isUndefined(to)); | ||
$.checkArgument(to instanceof PublicKey || to instanceof Address || _.isString(to)); | ||
$.checkArgument(to != null); | ||
$.checkArgument(to instanceof PublicKey || to instanceof Address || typeof to === 'string'); | ||
if (to instanceof PublicKey) { | ||
to = to.toAddress(null, Address.PayToWitnessPublicKeyHash); | ||
} else if (_.isString(to)) { | ||
} else if (typeof to === 'string') { | ||
to = new Address(to); | ||
@@ -930,4 +930,4 @@ } | ||
Script.buildDataOut = function(data, encoding) { | ||
$.checkArgument(_.isUndefined(data) || _.isString(data) || BufferUtil.isBuffer(data)); | ||
if (_.isString(data)) { | ||
$.checkArgument(data == null || typeof data === 'string' || BufferUtil.isBuffer(data)); | ||
if (typeof data === 'string') { | ||
data = Buffer.from(data, encoding); | ||
@@ -937,3 +937,3 @@ } | ||
s.add(Opcode.OP_RETURN); | ||
if (!_.isUndefined(data)) { | ||
if (data != null) { | ||
s.add(data); | ||
@@ -969,3 +969,3 @@ } | ||
$.checkArgument(signature instanceof Signature || BufferUtil.isBuffer(signature)); | ||
$.checkArgument(_.isUndefined(sigtype) || _.isNumber(sigtype)); | ||
$.checkArgument(sigtype == null || !isNaN(sigtype)); | ||
if (signature instanceof Signature) { | ||
@@ -992,3 +992,3 @@ signature = signature.toBuffer(); | ||
$.checkArgument(signature instanceof Signature || BufferUtil.isBuffer(signature)); | ||
$.checkArgument(_.isUndefined(sigtype) || _.isNumber(sigtype)); | ||
$.checkArgument(sigtype == null || !isNaN(sigtype)); | ||
if (signature instanceof Signature) { | ||
@@ -1192,7 +1192,6 @@ signature = signature.toBuffer(); | ||
Script.prototype.getSignatureOperationsCount = function(accurate) { | ||
accurate = (_.isUndefined(accurate) ? true : accurate); | ||
var self = this; | ||
accurate = (accurate == null ? true : accurate); | ||
var n = 0; | ||
var lastOpcode = Opcode.OP_INVALIDOPCODE; | ||
_.each(self.chunks, function getChunk(chunk) { | ||
for (const chunk of this.chunks) { | ||
var opcode = chunk.opcodenum; | ||
@@ -1203,3 +1202,3 @@ if (opcode == Opcode.OP_CHECKSIG || opcode == Opcode.OP_CHECKSIGVERIFY) { | ||
if (accurate && lastOpcode >= Opcode.OP_1 && lastOpcode <= Opcode.OP_16) { | ||
n += self._decodeOP_N(lastOpcode); | ||
n += this._decodeOP_N(lastOpcode); | ||
} else { | ||
@@ -1210,3 +1209,3 @@ n += 20; | ||
lastOpcode = opcode; | ||
}); | ||
} | ||
return n; | ||
@@ -1213,0 +1212,0 @@ }; |
@@ -62,3 +62,3 @@ 'use strict'; | ||
var prevTxId; | ||
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) { | ||
if (typeof params.prevTxId === 'string' && JSUtil.isHexa(params.prevTxId)) { | ||
prevTxId = Buffer.from(params.prevTxId, 'hex'); | ||
@@ -70,3 +70,3 @@ } else { | ||
this.witnesses = []; | ||
if (params.witnesses && _.isArray(params.witnesses)) { | ||
if (params.witnesses && Array.isArray(params.witnesses)) { | ||
this.witnesses = params.witnesses; | ||
@@ -78,6 +78,7 @@ } | ||
this.prevTxId = prevTxId || params.txidbuf; | ||
this.outputIndex = _.isUndefined(params.outputIndex) ? params.txoutnum : params.outputIndex; | ||
this.sequenceNumber = _.isUndefined(params.sequenceNumber) ? | ||
(_.isUndefined(params.seqnum) ? DEFAULT_SEQNUMBER : params.seqnum) : params.sequenceNumber; | ||
if (_.isUndefined(params.script) && _.isUndefined(params.scriptBuffer)) { | ||
this.outputIndex = params.outputIndex == null ? params.txoutnum : params.outputIndex; | ||
this.sequenceNumber = params.sequenceNumber == null ? | ||
(params.seqnum == null ? DEFAULT_SEQNUMBER : params.seqnum) : params.sequenceNumber; | ||
// null script is allowed in setScript() | ||
if (params.script === undefined && params.scriptBuffer === undefined) { | ||
throw new errors.Transaction.Input.MissingScript(); | ||
@@ -139,3 +140,3 @@ } | ||
this._scriptBuffer = Buffer.from(script, 'hex'); | ||
} else if (_.isString(script)) { | ||
} else if (typeof script === 'string') { | ||
// human readable string script | ||
@@ -236,3 +237,7 @@ this._script = new Script(script); | ||
Input.prototype._getBaseSize = function() { | ||
return 32 + 4 + 4; // outpoint (32 + 4) + sequence (4) | ||
}; | ||
/** | ||
@@ -246,3 +251,3 @@ * Sets sequence number so that transaction is not valid until the desired seconds | ||
Input.prototype.lockForSeconds = function(seconds) { | ||
$.checkArgument(_.isNumber(seconds)); | ||
$.checkArgument(!isNaN(seconds)); | ||
if (seconds < 0 || seconds >= SEQUENCE_LOCKTIME_GRANULARITY * SEQUENCE_LOCKTIME_MASK) { | ||
@@ -265,3 +270,3 @@ throw new errors.Transaction.Input.LockTimeRange(); | ||
Input.prototype.lockUntilBlockHeight = function(heightDiff) { | ||
$.checkArgument(_.isNumber(heightDiff)); | ||
$.checkArgument(!isNaN(heightDiff)); | ||
if (heightDiff < 0 || heightDiff >= SEQUENCE_BLOCKDIFF_LIMIT) { | ||
@@ -268,0 +273,0 @@ throw new errors.Transaction.Input.BlockHeightOutOfRange(); |
@@ -23,3 +23,2 @@ 'use strict'; | ||
Input.apply(this, arguments); | ||
var self = this; | ||
pubkeys = pubkeys || input.publicKeys; | ||
@@ -36,5 +35,6 @@ threshold = threshold || input.threshold; | ||
this.publicKeyIndex = {}; | ||
_.each(this.publicKeys, function(publicKey, index) { | ||
self.publicKeyIndex[publicKey.toString()] = index; | ||
}); | ||
for (let index = 0; index < this.publicKeys.length; index++) { | ||
const publicKey = this.publicKeys[index]; | ||
this.publicKeyIndex[publicKey.toString()] = index; | ||
} | ||
this.threshold = threshold; | ||
@@ -49,3 +49,3 @@ // Empty array of signatures | ||
obj.threshold = this.threshold; | ||
obj.publicKeys = _.map(this.publicKeys, function(publicKey) { return publicKey.toString(); }); | ||
obj.publicKeys = this.publicKeys.map(function(publicKey) { return publicKey.toString(); }); | ||
obj.signatures = this._serializeSignatures(); | ||
@@ -56,3 +56,3 @@ return obj; | ||
MultiSigInput.prototype._deserializeSignatures = function(signatures) { | ||
return _.map(signatures, function(signature) { | ||
return signatures.map(function(signature) { | ||
if (!signature) { | ||
@@ -66,3 +66,3 @@ return undefined; | ||
MultiSigInput.prototype._serializeSignatures = function() { | ||
return _.map(this.signatures, function(signature) { | ||
return this.signatures.map(function(signature) { | ||
if (!signature) { | ||
@@ -80,16 +80,15 @@ return undefined; | ||
var self = this; | ||
var results = []; | ||
_.each(this.publicKeys, function(publicKey) { | ||
const results = []; | ||
for (const publicKey of this.publicKeys) { | ||
if (publicKey.toString() === privateKey.publicKey.toString()) { | ||
results.push(new TransactionSignature({ | ||
publicKey: privateKey.publicKey, | ||
prevTxId: self.prevTxId, | ||
outputIndex: self.outputIndex, | ||
prevTxId: this.prevTxId, | ||
outputIndex: this.outputIndex, | ||
inputIndex: index, | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, self.output.script, signingMethod), | ||
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script, signingMethod), | ||
sigtype: sigtype | ||
})); | ||
} | ||
}); | ||
} | ||
@@ -101,3 +100,3 @@ return results; | ||
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added'); | ||
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()], "Signature Undefined"), | ||
$.checkArgument(this.publicKeyIndex[signature.publicKey.toString()] != null, | ||
'Signature has no matching public key'); | ||
@@ -120,6 +119,6 @@ $.checkState(this.isValidSignature(transaction, signature, signingMethod), "Invalid Signature"); | ||
MultiSigInput.prototype._createSignatures = function() { | ||
return _.map( | ||
_.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }), | ||
return this.signatures | ||
.filter(function(signature) { return signature != null; }) | ||
// Future signature types may need refactor of toDER | ||
function(signature) { | ||
.map(function(signature) { | ||
return BufferUtil.concat([ | ||
@@ -147,3 +146,3 @@ signature.signature.toDER(), | ||
MultiSigInput.prototype.countSignatures = function() { | ||
return _.reduce(this.signatures, function(sum, signature) { | ||
return this.signatures.reduce(function(sum, signature) { | ||
return sum + (!!signature); | ||
@@ -154,5 +153,4 @@ }, 0); | ||
MultiSigInput.prototype.publicKeysWithoutSignature = function() { | ||
var self = this; | ||
return _.filter(this.publicKeys, function(publicKey) { | ||
return !(self.signatures[self.publicKeyIndex[publicKey.toString()]]); | ||
return this.publicKeys.filter((publicKey) => { | ||
return !(this.signatures[this.publicKeyIndex[publicKey.toString()]]); | ||
}); | ||
@@ -227,3 +225,3 @@ }; | ||
MultiSigInput.prototype._estimateSize = function() { | ||
return MultiSigInput.OPCODES_SIZE + | ||
return this._getBaseSize() + MultiSigInput.OPCODES_SIZE + | ||
this.threshold * MultiSigInput.SIGNATURE_SIZE; | ||
@@ -230,0 +228,0 @@ }; |
@@ -27,3 +27,2 @@ 'use strict'; | ||
Input.apply(this, arguments); | ||
var self = this; | ||
pubkeys = pubkeys || input.publicKeys; | ||
@@ -59,5 +58,6 @@ threshold = threshold || input.threshold; | ||
this.publicKeyIndex = {}; | ||
_.each(this.publicKeys, function(publicKey, index) { | ||
self.publicKeyIndex[publicKey.toString()] = index; | ||
}); | ||
for (var index = 0; index < this.publicKeys.length; index++) { | ||
const publicKey = this.publicKeys[index]; | ||
this.publicKeyIndex[publicKey.toString()] = index; | ||
} | ||
this.threshold = threshold; | ||
@@ -72,3 +72,3 @@ // Empty array of signatures | ||
obj.threshold = this.threshold; | ||
obj.publicKeys = _.map(this.publicKeys, function(publicKey) { return publicKey.toString(); }); | ||
obj.publicKeys = this.publicKeys.map(function(publicKey) { return publicKey.toString(); }); | ||
obj.signatures = this._serializeSignatures(); | ||
@@ -79,3 +79,3 @@ return obj; | ||
MultiSigScriptHashInput.prototype._deserializeSignatures = function(signatures) { | ||
return _.map(signatures, function(signature) { | ||
return signatures.map(function(signature) { | ||
if (!signature) { | ||
@@ -89,3 +89,3 @@ return undefined; | ||
MultiSigScriptHashInput.prototype._serializeSignatures = function() { | ||
return _.map(this.signatures, function(signature) { | ||
return this.signatures.map(function(signature) { | ||
if (!signature) { | ||
@@ -111,10 +111,9 @@ return undefined; | ||
MultiSigScriptHashInput.prototype.getSighash = function(transaction, privateKey, index, sigtype) { | ||
var self = this; | ||
var hash; | ||
if (self.nestedWitness || self.type === Address.PayToWitnessScriptHash) { | ||
var scriptCode = self.getScriptCode(); | ||
var satoshisBuffer = self.getSatoshisBuffer(); | ||
if (this.nestedWitness || this.type === Address.PayToWitnessScriptHash) { | ||
var scriptCode = this.getScriptCode(); | ||
var satoshisBuffer = this.getSatoshisBuffer(); | ||
hash = SighashWitness.sighash(transaction, sigtype, index, scriptCode, satoshisBuffer); | ||
} else { | ||
hash = Sighash.sighash(transaction, sigtype, index, self.redeemScript); | ||
hash = Sighash.sighash(transaction, sigtype, index, this.redeemScript); | ||
} | ||
@@ -129,18 +128,17 @@ return hash; | ||
var self = this; | ||
var results = []; | ||
_.each(this.publicKeys, function(publicKey) { | ||
const results = []; | ||
for (const publicKey of this.publicKeys) { | ||
if (publicKey.toString() === privateKey.publicKey.toString()) { | ||
var signature; | ||
if (self.nestedWitness || self.type === Address.PayToWitnessScriptHash) { | ||
var scriptCode = self.getScriptCode(); | ||
var satoshisBuffer = self.getSatoshisBuffer(); | ||
if (this.nestedWitness || this.type === Address.PayToWitnessScriptHash) { | ||
var scriptCode = this.getScriptCode(); | ||
var satoshisBuffer = this.getSatoshisBuffer(); | ||
signature = SighashWitness.sign(transaction, privateKey, sigtype, index, scriptCode, satoshisBuffer, signingMethod); | ||
} else { | ||
signature = Sighash.sign(transaction, privateKey, sigtype, index, self.redeemScript, signingMethod); | ||
signature = Sighash.sign(transaction, privateKey, sigtype, index, this.redeemScript, signingMethod); | ||
} | ||
results.push(new TransactionSignature({ | ||
publicKey: privateKey.publicKey, | ||
prevTxId: self.prevTxId, | ||
outputIndex: self.outputIndex, | ||
prevTxId: this.prevTxId, | ||
outputIndex: this.outputIndex, | ||
inputIndex: index, | ||
@@ -151,3 +149,3 @@ signature: signature, | ||
} | ||
}); | ||
} | ||
return results; | ||
@@ -158,3 +156,3 @@ }; | ||
$.checkState(!this.isFullySigned(), 'All needed signatures have already been added'); | ||
$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]), | ||
$.checkArgument(this.publicKeyIndex[signature.publicKey.toString()] != null, | ||
'Signature has no matching public key'); | ||
@@ -191,5 +189,5 @@ $.checkState(this.isValidSignature(transaction, signature, signingMethod), "Invalid Signature!"); | ||
MultiSigScriptHashInput.prototype._createSignatures = function() { | ||
return _.map( | ||
_.filter(this.signatures, function(signature) { return !_.isUndefined(signature); }), | ||
function(signature) { | ||
return this.signatures | ||
.filter(function(signature) { return signature != null; }) | ||
.map(function(signature) { | ||
return BufferUtil.concat([ | ||
@@ -199,4 +197,3 @@ signature.signature.toDER(), | ||
]); | ||
} | ||
); | ||
}); | ||
}; | ||
@@ -218,3 +215,3 @@ | ||
MultiSigScriptHashInput.prototype.countSignatures = function() { | ||
return _.reduce(this.signatures, function(sum, signature) { | ||
return this.signatures.reduce(function(sum, signature) { | ||
return sum + (!!signature); | ||
@@ -225,5 +222,4 @@ }, 0); | ||
MultiSigScriptHashInput.prototype.publicKeysWithoutSignature = function() { | ||
var self = this; | ||
return _.filter(this.publicKeys, function(publicKey) { | ||
return !(self.signatures[self.publicKeyIndex[publicKey.toString()]]); | ||
return this.publicKeys.filter((publicKey) => { | ||
return !(this.signatures[this.publicKeyIndex[publicKey.toString()]]); | ||
}); | ||
@@ -261,21 +257,23 @@ }; | ||
MultiSigScriptHashInput.OPCODES_SIZE = 7; // serialized size (<=3) + 0 .. N .. M OP_CHECKMULTISIG | ||
MultiSigScriptHashInput.SIGNATURE_SIZE = 74; // size (1) + DER (<=72) + sighash (1) | ||
MultiSigScriptHashInput.PUBKEY_SIZE = 34; // size (1) + DER (<=33) | ||
MultiSigScriptHashInput.MAX_OPCODES_SIZE = 8; // serialized size (<=3) + 0 .. OP_PUSHDATAx N .. M OP_CHECKMULTISIG | ||
MultiSigScriptHashInput.MAX_SIGNATURE_SIZE = 74; // size (1) + DER (<=72) + sighash (1) | ||
MultiSigScriptHashInput.MAX_PUBKEY_SIZE = 34; // size (1) + DER (<=33) | ||
MultiSigScriptHashInput.REDEEM_SCRIPT_SIZE = 34; // OP_0 (1) + scriptHash (1 + 32) | ||
MultiSigScriptHashInput.prototype._estimateSize = function() { | ||
var WITNESS_DISCOUNT = 4; | ||
var witnessSize = MultiSigScriptHashInput.OPCODES_SIZE + | ||
this.threshold * MultiSigScriptHashInput.SIGNATURE_SIZE + | ||
this.publicKeys.length * MultiSigScriptHashInput.PUBKEY_SIZE; | ||
let result = this._getBaseSize(); | ||
const WITNESS_DISCOUNT = 4; | ||
const witnessSize = MultiSigScriptHashInput.MAX_OPCODES_SIZE + | ||
this.threshold * MultiSigScriptHashInput.MAX_SIGNATURE_SIZE + | ||
this.publicKeys.length * MultiSigScriptHashInput.MAX_PUBKEY_SIZE; | ||
if (this.type === Address.PayToWitnessScriptHash) { | ||
return witnessSize / WITNESS_DISCOUNT; | ||
result += witnessSize / WITNESS_DISCOUNT; | ||
} else if (this.nestedWitness) { | ||
return witnessSize / WITNESS_DISCOUNT + MultiSigScriptHashInput.REDEEM_SCRIPT_SIZE; | ||
result += witnessSize / WITNESS_DISCOUNT + MultiSigScriptHashInput.REDEEM_SCRIPT_SIZE; | ||
} else { | ||
return witnessSize; | ||
result += witnessSize; | ||
} | ||
return result; | ||
}; | ||
module.exports = MultiSigScriptHashInput; |
@@ -88,5 +88,5 @@ 'use strict'; | ||
PublicKeyInput.prototype._estimateSize = function() { | ||
return PublicKeyInput.SCRIPT_MAX_SIZE; | ||
return this._getBaseSize() + PublicKeyInput.SCRIPT_MAX_SIZE; | ||
}; | ||
module.exports = PublicKeyInput; |
@@ -185,16 +185,19 @@ 'use strict'; | ||
PublicKeyHashInput.SCRIPT_MAX_SIZE = 73 + 34; // sigsize (1 + 72) + pubkey (1 + 33) | ||
PublicKeyHashInput.REDEEM_SCRIPT_SIZE = 22; // OP_0 (1) pubkeyhash (1 + 20) | ||
PublicKeyHashInput.REDEEM_SCRIPT_SIZE = 1 + 22; // len (1) OP_0 (1) pubkeyhash (1 + 20) | ||
PublicKeyHashInput.prototype._estimateSize = function() { | ||
var WITNESS_DISCOUNT = 4; | ||
let result = this._getBaseSize(); | ||
result += 1; // script size | ||
const WITNESS_DISCOUNT = 4; | ||
const witnessSize = PublicKeyHashInput.SCRIPT_MAX_SIZE / WITNESS_DISCOUNT; | ||
if (this.output.script.isWitnessPublicKeyHashOut()) { | ||
return witnessSize; | ||
result += witnessSize; | ||
} else if (this.output.script.isScriptHashOut()) { | ||
return witnessSize + PublicKeyHashInput.REDEEM_SCRIPT_SIZE; | ||
result += witnessSize + PublicKeyHashInput.REDEEM_SCRIPT_SIZE; | ||
} else { | ||
return PublicKeyHashInput.SCRIPT_MAX_SIZE; | ||
result += PublicKeyHashInput.SCRIPT_MAX_SIZE; | ||
} | ||
return result; | ||
}; | ||
module.exports = PublicKeyHashInput; |
@@ -24,3 +24,3 @@ 'use strict'; | ||
var script; | ||
if (_.isString(args.script) && JSUtil.isHexa(args.script)) { | ||
if (typeof args.script === 'string' && JSUtil.isHexa(args.script)) { | ||
script = Buffer.from(args.script, 'hex'); | ||
@@ -61,3 +61,3 @@ } else { | ||
this._satoshis = num.toNumber(); | ||
} else if (_.isString(num)) { | ||
} else if (typeof num === 'string') { | ||
this._satoshis = parseInt(num); | ||
@@ -124,3 +124,3 @@ this._satoshisBN = BN.fromNumber(this._satoshis); | ||
this._script._isOutput = true; | ||
} else if (_.isString(script)) { | ||
} else if (typeof script === 'string') { | ||
this._script = Script.fromString(script); | ||
@@ -170,2 +170,9 @@ this._scriptBuffer = this._script.toBuffer(); | ||
Output.prototype.calculateSize = function() { | ||
let result = 8; // satoshis | ||
result += BufferWriter.varintBufNum(this._scriptBuffer.length).length; | ||
result += this._scriptBuffer.length; | ||
return result; | ||
}; | ||
module.exports = Output; |
@@ -136,2 +136,26 @@ 'use strict'; | ||
Object.defineProperty(Transaction.prototype, 'size', { | ||
configurable: false, | ||
enumerable: false, | ||
get: function() { | ||
return this._calculateSize(); | ||
} | ||
}); | ||
Object.defineProperty(Transaction.prototype, 'vsize', { | ||
configurable: false, | ||
enumerable: false, | ||
get: function() { | ||
return this._calculateVSize(); | ||
} | ||
}); | ||
Object.defineProperty(Transaction.prototype, 'weight', { | ||
configurable: false, | ||
enumerable: false, | ||
get: function() { | ||
return this._calculateWeight(); | ||
} | ||
}); | ||
/** | ||
@@ -237,3 +261,3 @@ * Retrieve the little endian hash of the transaction (used for serialization) | ||
if (!_.isUndefined(this._fee) && this._fee !== unspent) { | ||
if (this._fee != null && this._fee !== unspent) { | ||
return new errors.Transaction.FeeError.Different( | ||
@@ -315,3 +339,3 @@ 'Unspent value is ' + unspent + ' but specified fee is ' + this._fee | ||
var hasWitnesses = this.hasWitnesses(); | ||
const hasWitnesses = this.hasWitnesses(); | ||
@@ -322,22 +346,21 @@ if (hasWitnesses && !noWitness) { | ||
writer.writeVarintNum(this.inputs.length); | ||
_.each(this.inputs, function(input) { | ||
writer.writeVarintNum(this.inputs ? this.inputs.length : 0); | ||
for (const input of this.inputs || []) { | ||
input.toBufferWriter(writer); | ||
}); | ||
} | ||
writer.writeVarintNum(this.outputs.length); | ||
_.each(this.outputs, function(output) { | ||
writer.writeVarintNum(this.outputs ? this.outputs.length : 0); | ||
for (const output of this.outputs || []) { | ||
output.toBufferWriter(writer); | ||
}); | ||
} | ||
if (hasWitnesses && !noWitness) { | ||
_.each(this.inputs, function(input) { | ||
var witnesses = input.getWitnesses(); | ||
for (const input of this.inputs) { | ||
const witnesses = input.getWitnesses(); | ||
writer.writeVarintNum(witnesses.length); | ||
for (var j = 0; j < witnesses.length; j++) { | ||
for (let j = 0; j < witnesses.length; j++) { | ||
writer.writeVarintNum(witnesses[j].length); | ||
writer.write(witnesses[j]); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -415,6 +438,6 @@ | ||
} | ||
if (!_.isUndefined(this._changeIndex)) { | ||
if (this._changeIndex != null) { | ||
obj.changeIndex = this._changeIndex; | ||
} | ||
if (!_.isUndefined(this._fee)) { | ||
if (this._fee != null) { | ||
obj.fee = this._fee; | ||
@@ -428,13 +451,12 @@ } | ||
$.checkArgument(_.isObject(arg) || arg instanceof Transaction); | ||
var self = this; | ||
var transaction; | ||
if (arg instanceof Transaction) { | ||
transaction = transaction.toObject(); | ||
transaction = arg.toObject(); | ||
} else { | ||
transaction = arg; | ||
} | ||
_.each(transaction.inputs, function(input) { | ||
for (const input of transaction.inputs || []) { | ||
if (!input.output || !input.output.script) { | ||
self.uncheckedAddInput(new Input(input)); | ||
return; | ||
this.uncheckedAddInput(new Input(input)); | ||
continue; | ||
} | ||
@@ -454,7 +476,7 @@ var script = new Script(input.output.script); | ||
} | ||
self.addInput(txin); | ||
}); | ||
_.each(transaction.outputs, function(output) { | ||
self.addOutput(new Output(output)); | ||
}); | ||
this.addInput(txin); | ||
} | ||
for (const output of transaction.outputs || []) { | ||
this.addOutput(new Output(output)); | ||
} | ||
if (transaction.changeIndex) { | ||
@@ -476,3 +498,3 @@ this._changeIndex = transaction.changeIndex; | ||
Transaction.prototype._checkConsistency = function(arg) { | ||
if (!_.isUndefined(this._changeIndex)) { | ||
if (this._changeIndex != null) { | ||
$.checkState(this._changeScript, 'Change script is expected.'); | ||
@@ -497,3 +519,3 @@ $.checkState(this.outputs[this._changeIndex], 'Change index points to undefined output.'); | ||
$.checkArgument(time); | ||
if (_.isNumber(time) && time < Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) { | ||
if (!isNaN(time) && time < Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) { | ||
throw new errors.Transaction.LockTimeTooEarly(); | ||
@@ -523,3 +545,3 @@ } | ||
Transaction.prototype.lockUntilBlockHeight = function(height) { | ||
$.checkArgument(_.isNumber(height)); | ||
$.checkArgument(!isNaN(height)); | ||
if (height >= Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) { | ||
@@ -624,10 +646,9 @@ throw new errors.Transaction.BlockHeightTooHigh(); | ||
Transaction.prototype.from = function(utxo, pubkeys, threshold, opts) { | ||
if (_.isArray(utxo)) { | ||
var self = this; | ||
_.each(utxo, function(utxo) { | ||
self.from(utxo, pubkeys, threshold, opts); | ||
}); | ||
if (Array.isArray(utxo)) { | ||
for (const u of utxo) { | ||
this.from(u, pubkeys, threshold, opts); | ||
} | ||
return this; | ||
} | ||
var exists = _.some(this.inputs, function(input) { | ||
var exists = this.inputs.some(function(input) { | ||
// TODO: Maybe prevTxId should be a string? Or defined as read only property? | ||
@@ -731,6 +752,6 @@ return input.prevTxId.toString('hex') === utxo.txId && input.outputIndex === utxo.outputIndex; | ||
$.checkArgumentType(input, Input, 'input'); | ||
if (!input.output && (_.isUndefined(outputScript) || _.isUndefined(satoshis))) { | ||
if (!input.output && (outputScript == null || satoshis == null)) { | ||
throw new errors.Transaction.NeedMoreInfo('Need information about the UTXO script and satoshis'); | ||
} | ||
if (!input.output && outputScript && !_.isUndefined(satoshis)) { | ||
if (!input.output && outputScript && satoshis != null) { | ||
outputScript = outputScript instanceof Script ? outputScript : new Script(outputScript); | ||
@@ -767,5 +788,5 @@ $.checkArgumentType(satoshis, 'number', 'satoshis'); | ||
Transaction.prototype.hasAllUtxoInfo = function() { | ||
return _.every(this.inputs.map(function(input) { | ||
return this.inputs.every(function(input) { | ||
return !!input.output; | ||
})); | ||
}); | ||
}; | ||
@@ -782,3 +803,3 @@ | ||
Transaction.prototype.fee = function(amount) { | ||
$.checkArgument(_.isNumber(amount), 'amount must be a number'); | ||
$.checkArgument(!isNaN(amount), 'amount must be a number'); | ||
this._fee = amount; | ||
@@ -798,3 +819,3 @@ this._updateChangeOutput(); | ||
Transaction.prototype.feePerKb = function(amount) { | ||
$.checkArgument(_.isNumber(amount), 'amount must be a number'); | ||
$.checkArgument(!isNaN(amount), 'amount must be a number'); | ||
this._feePerKb = amount; | ||
@@ -815,3 +836,3 @@ this._updateChangeOutput(); | ||
Transaction.prototype.feePerByte = function (amount) { | ||
$.checkArgument(_.isNumber(amount), 'amount must be a number'); | ||
$.checkArgument(!isNaN(amount), 'amount must be a number'); | ||
this._feePerByte = amount; | ||
@@ -845,3 +866,3 @@ this._updateChangeOutput(); | ||
Transaction.prototype.getChangeOutput = function() { | ||
if (!_.isUndefined(this._changeIndex)) { | ||
if (this._changeIndex != null) { | ||
return this.outputs[this._changeIndex]; | ||
@@ -869,7 +890,6 @@ } | ||
Transaction.prototype.to = function(address, amount) { | ||
if (_.isArray(address)) { | ||
var self = this; | ||
_.each(address, function(to) { | ||
self.to(to.address, to.satoshis); | ||
}); | ||
if (Array.isArray(address)) { | ||
for (const to of address) { | ||
this.to(to.address, to.satoshis); | ||
} | ||
return this; | ||
@@ -949,8 +969,7 @@ } | ||
Transaction.prototype._getOutputAmount = function() { | ||
if (_.isUndefined(this._outputAmount)) { | ||
var self = this; | ||
if (this._outputAmount == null) { | ||
this._outputAmount = 0; | ||
_.each(this.outputs, function(output) { | ||
self._outputAmount += output.satoshis; | ||
}); | ||
for (const output of this.outputs) { | ||
this._outputAmount += output.satoshis; | ||
} | ||
} | ||
@@ -967,5 +986,5 @@ return this._outputAmount; | ||
Transaction.prototype._getInputAmount = function() { | ||
if (_.isUndefined(this._inputAmount)) { | ||
if (this._inputAmount == null) { | ||
this._inputAmount = _.sumBy(this.inputs, function(input) { | ||
if (_.isUndefined(input.output)) { | ||
if (input.output == null) { | ||
throw new errors.Transaction.Input.MissingPreviousOutput(); | ||
@@ -984,3 +1003,3 @@ } | ||
this._clearSignatures(); | ||
if (!_.isUndefined(this._changeIndex)) { | ||
if (this._changeIndex != null) { | ||
this._removeOutput(this._changeIndex); | ||
@@ -1023,3 +1042,3 @@ } | ||
} | ||
if (!_.isUndefined(this._fee)) { | ||
if (this._fee != null) { | ||
return this._fee; | ||
@@ -1038,10 +1057,10 @@ } | ||
Transaction.prototype._estimateFee = function () { | ||
var estimatedSize = this._estimateSize(); | ||
var available = this._getUnspentValue(); | ||
var feeRate = this._feePerByte || (this._feePerKb || Transaction.FEE_PER_KB) / 1000; | ||
const estimatedSize = this._estimateSize(); | ||
const available = this._getUnspentValue(); | ||
const feeRate = this._feePerByte || (this._feePerKb || Transaction.FEE_PER_KB) / 1000; | ||
function getFee(size) { | ||
return size * feeRate; | ||
} | ||
var fee = Math.ceil(getFee(estimatedSize)); | ||
var feeWithChange = Math.ceil(getFee(estimatedSize) + getFee(Transaction.CHANGE_OUTPUT_MAX_SIZE)); | ||
const fee = Math.ceil(getFee(estimatedSize)); | ||
const feeWithChange = Math.ceil(getFee(estimatedSize) + getFee(this._estimateSizeOfChangeOutput())); | ||
if (!this._changeScript || available <= feeWithChange) { | ||
@@ -1053,2 +1072,11 @@ return fee; | ||
Transaction.prototype._estimateSizeOfChangeOutput = function () { | ||
if (!this._changeScript) { | ||
return 0; | ||
} | ||
const scriptLen = this._changeScript.toBuffer().length; | ||
// 8 bytes for satoshis + script size + actual script size | ||
return 8 + BufferWriter.varintBufNum(scriptLen).length + scriptLen; | ||
}; | ||
Transaction.prototype._getUnspentValue = function() { | ||
@@ -1059,19 +1087,44 @@ return this._getInputAmount() - this._getOutputAmount(); | ||
Transaction.prototype._clearSignatures = function() { | ||
_.each(this.inputs, function(input) { | ||
for (const input of this.inputs) { | ||
input.clearSignatures(); | ||
}); | ||
} | ||
}; | ||
/** | ||
* Estimate the tx size before input signatures are added. | ||
*/ | ||
Transaction.prototype._estimateSize = function() { | ||
var result = Transaction.MAXIMUM_EXTRA_SIZE; | ||
_.each(this.inputs, function(input) { | ||
result += 32 + 4; // prevout size:w | ||
let result = 4; // version | ||
if (this.hasWitnesses()) { | ||
result += .5; | ||
} | ||
result += BufferWriter.varintBufNum(this.inputs.length).length; | ||
for (const input of this.inputs || []) { | ||
result += input._estimateSize(); | ||
}); | ||
_.each(this.outputs, function(output) { | ||
result += output.script.toBuffer().length + 9; | ||
}); | ||
} | ||
result += BufferWriter.varintBufNum(this.outputs.length).length; | ||
for (const output of this.outputs || []) { | ||
result += output.calculateSize(); | ||
} | ||
result += 4; // nLockTime | ||
return Math.ceil(result); | ||
}; | ||
Transaction.prototype._calculateSize = function() { | ||
return this.toBuffer().length; | ||
}; | ||
Transaction.prototype._calculateVSize = function(noRound) { | ||
const vsize = this._calculateWeight() / 4; | ||
return noRound ? vsize : Math.ceil(vsize); | ||
}; | ||
Transaction.prototype._calculateWeight = function() { | ||
return (this.toBuffer(true).length * 3) + this.toBuffer(false).length; | ||
}; | ||
Transaction.prototype._removeOutput = function(index) { | ||
@@ -1165,5 +1218,5 @@ var output = this.outputs[index]; | ||
if (!_.isUndefined(this._changeIndex)) { | ||
if (this._changeIndex != null) { | ||
var changeOutput = this.outputs[this._changeIndex]; | ||
this._changeIndex = _.findIndex(newOutputs, changeOutput); | ||
this._changeIndex = newOutputs.indexOf(changeOutput); | ||
} | ||
@@ -1177,6 +1230,6 @@ | ||
var index; | ||
if (!outputIndex && _.isNumber(txId)) { | ||
if (!outputIndex && !isNaN(txId)) { | ||
index = txId; | ||
} else { | ||
index = _.findIndex(this.inputs, function(input) { | ||
index = this.inputs.findIndex(function(input) { | ||
return input.prevTxId.toString('hex') === txId && input.outputIndex === outputIndex; | ||
@@ -1209,12 +1262,11 @@ }); | ||
$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.'); | ||
var self = this; | ||
if (_.isArray(privateKey)) { | ||
_.each(privateKey, function(privateKey) { | ||
self.sign(privateKey, sigtype, signingMethod); | ||
}); | ||
if (Array.isArray(privateKey)) { | ||
for (const pk of privateKey) { | ||
this.sign(pk, sigtype, signingMethod); | ||
} | ||
return this; | ||
} | ||
_.each(this.getSignatures(privateKey, sigtype, signingMethod), function(signature) { | ||
self.applySignature(signature, signingMethod); | ||
}); | ||
for (const signature of this.getSignatures(privateKey, sigtype, signingMethod)) { | ||
this.applySignature(signature, signingMethod); | ||
} | ||
return this; | ||
@@ -1226,10 +1278,11 @@ }; | ||
sigtype = sigtype || Signature.SIGHASH_ALL; | ||
var transaction = this; | ||
var results = []; | ||
var hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer()); | ||
_.each(this.inputs, function forEachInput(input, index) { | ||
_.each(input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod), function(signature) { | ||
const transaction = this; | ||
const results = []; | ||
const hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer()); | ||
for (let index = 0; index < this.inputs.length; index++) { | ||
const input = this.inputs[index]; | ||
for (const signature of input.getSignatures(transaction, privKey, index, sigtype, hashData, signingMethod)) { | ||
results.push(signature); | ||
}); | ||
}); | ||
} | ||
} | ||
return results; | ||
@@ -1255,3 +1308,3 @@ }; | ||
Transaction.prototype.isFullySigned = function() { | ||
_.each(this.inputs, function(input) { | ||
for (const input of this.inputs) { | ||
if (input.isFullySigned === Input.prototype.isFullySigned) { | ||
@@ -1263,10 +1316,9 @@ throw new errors.Transaction.UnableToVerifySignature( | ||
} | ||
} | ||
return this.inputs.every(function(input) { | ||
return input.isFullySigned(); | ||
}); | ||
return _.every(_.map(this.inputs, function(input) { | ||
return input.isFullySigned(); | ||
})); | ||
}; | ||
Transaction.prototype.isValidSignature = function(signature, signingMethod) { | ||
var self = this; | ||
if (this.inputs[signature.inputIndex].isValidSignature === Input.prototype.isValidSignature) { | ||
@@ -1278,3 +1330,3 @@ throw new errors.Transaction.UnableToVerifySignature( | ||
} | ||
return this.inputs[signature.inputIndex].isValidSignature(self, signature, signingMethod); | ||
return this.inputs[signature.inputIndex].isValidSignature(this, signature, signingMethod); | ||
}; | ||
@@ -1288,3 +1340,3 @@ | ||
if (_.isUndefined(sigversion)) { | ||
if (sigversion == null) { | ||
sigversion = 0; | ||
@@ -1364,3 +1416,3 @@ } | ||
var inputid = txin.prevTxId + ':' + txin.outputIndex; | ||
if (!_.isUndefined(txinmap[inputid])) { | ||
if (txinmap[inputid] != null) { | ||
return 'transaction input ' + i + ' duplicate input'; | ||
@@ -1367,0 +1419,0 @@ } |
{ | ||
"name": "bitcore-lib-ltc", | ||
"version": "10.0.21", | ||
"version": "10.0.28", | ||
"description": "A pure and powerful JavaScript Litecoin library.", | ||
@@ -106,3 +106,3 @@ "author": "BitPay <dev@bitpay.com>", | ||
"license": "MIT", | ||
"gitHead": "ed1ed2f132440f3d946af2c687cad0359a28f113" | ||
"gitHead": "c47030e29c2ef353b41955d78fd0ca5c8422c590" | ||
} |
@@ -83,4 +83,4 @@ [ | ||
"sign", ["TAZWwMWmEwBMXd1ws3TbQYE6H7be2WyskaAimRPbJADyW5T7wD6P"], | ||
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fdfd00004830450221009ef4278c726d4a09eb76343e784bf48c5194e20b1c2e5f284410b6d5133dd29e0220420bfab48e3f5c83764a676c509928d81508b626080897869edcfaa3aa6c5e660147304402202896effc5498e72fb5112e7c428c580db0fe8973d9ac6b54698fb4ca3de6ebc802205f494d2871b1424b5451ea97ca70601e654c55d597c3f244bd8deaf29bf418ac014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fdfd0000483045022100f7e3b498825ec60fd8b8deacbc44debffa9f855d90d14073a234f8739e1a5937022065066a6ad5bbe6d9dfc5c765b178bf30d7708cfc43992942f9a1ced217aee7990147304402206c76624835649170158b1b4484c4494c674d853ca2b9380391a4a77d7860388b02202b6648ee73e85d8db28d4520f1abf5f29e1d09d93692c46ec90091e3d9b53ba9014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af38793f504000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000" | ||
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fc004730440220033f38881580229e12c5e24e91807fc49c54dcc8f745240ebef24e76da8ad2d702201d78659583cf9282af127978ce92cf3b6eccb8364de34e3a2f6b1d7d087acb46014730440220179355b76eb00f60e6271386b9be2aad07486ee3519c3795b331c7c1ad3eead9022075e735f5ff7e07865610492bbcdb4502ecb69587de1224bf5aa20bdabcded6d7014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fdfd00004830450221009bb9598289077838105811d9cd8700c2124c47b3ae27ae3ae6cfe1fff1fcdae802207ac7d3c5b06973e08574fb4ca85510c8f4b1cceecf259c60943761ba75ce943d0147304402207e0497aa306e5f690212232f8ebcfa2bfb6e9a2a188831633e8c5fb5d96ce0ac02205ae25dd813d04af863c24652dc8e2ecdf7f44b219eaee0827d2803bbcf0e4c25014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387a30305000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000" | ||
] | ||
] |
@@ -18,16 +18,9 @@ 'use strict'; | ||
it('will enable/disable regtest Network', function() { | ||
it('should not replace testnet network with regtest', function() { | ||
const beforeEnable = networks.testnet; | ||
networks.enableRegtest(); | ||
networks.testnet.networkMagic.should.deep.equal(Buffer.from('fabfb5da', 'hex')); | ||
networks.testnet.port.should.equal(19444); | ||
networks.testnet.dnsSeeds.should.deep.equal([]); | ||
networks.testnet.regtestEnabled.should.equal(true); | ||
networks.testnet.should.deep.equal(beforeEnable); | ||
networks.disableRegtest(); | ||
networks.testnet.networkMagic.should.deep.equal(Buffer.from('fdd2c8f1', 'hex')); | ||
networks.testnet.port.should.equal(19335); | ||
networks.testnet.dnsSeeds.should.deep.equal([ | ||
'testnet-seed.litecointools.com', | ||
'seed-b.litecoin.loshan.co.uk' | ||
]); | ||
networks.testnet.should.deep.equal(beforeEnable); | ||
}); | ||
@@ -37,3 +30,3 @@ | ||
var network = networks.get('regtest'); | ||
network.should.equal(networks.testnet); | ||
network.should.equal(networks.regtest); | ||
}); | ||
@@ -40,0 +33,0 @@ |
@@ -104,3 +104,3 @@ 'use strict'; | ||
var input = transaction.inputs[0]; | ||
input._estimateSize().should.equal(147); | ||
input._estimateSize().should.equal(187); | ||
}); | ||
@@ -107,0 +107,0 @@ it('uses SIGHASH_ALL by default', function() { |
@@ -97,3 +97,3 @@ 'use strict'; | ||
var input = transaction.inputs[0]; | ||
input._estimateSize().should.equal(257); | ||
input._estimateSize().should.equal(298); | ||
}); | ||
@@ -213,3 +213,3 @@ it('uses SIGHASH_ALL by default', function() { | ||
var input = transaction.inputs[0]; | ||
input._estimateSize().should.equal(64.25); | ||
input._estimateSize().should.equal(104.5); | ||
}); | ||
@@ -216,0 +216,0 @@ it('uses SIGHASH_ALL by default', function() { |
@@ -48,3 +48,3 @@ 'use strict'; | ||
var input = tx.inputs[0]; | ||
input._estimateSize().should.equal(73); | ||
input._estimateSize().should.equal(113); | ||
}); | ||
@@ -51,0 +51,0 @@ |
@@ -44,3 +44,3 @@ 'use strict'; | ||
var input = transaction.inputs[0]; | ||
input._estimateSize().should.equal(107); | ||
input._estimateSize().should.equal(148); | ||
}); | ||
@@ -47,0 +47,0 @@ it('it\'s signature can be removed', function() { |
Sorry, the diff of this file is too big to display
4322459
87921