Skip to content
Open
4 changes: 2 additions & 2 deletions packages/bitcore-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"engines": {
"node": ">=8.0.0"
},
"version": "8.25.33",
"version": "8.25.34",
"author": "Justin Langston <[email protected]>",
"main": "./ts_build/index.js",
"types": "./ts_build/index.d.ts",
Expand All @@ -25,7 +25,7 @@
},
"dependencies": {
"@abcpros/bitcore-mnemonic": "^8.25.33",
"@abcpros/crypto-wallet-core": "^8.25.35",
"@abcpros/crypto-wallet-core": "^8.25.36",
"JSONStream": "~1.3.1",
"async": "2.5.0",
"bcrypt": "3.0.8",
Expand Down
29 changes: 22 additions & 7 deletions packages/bitcore-lib-xpi/lib/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,21 +775,21 @@ Script.buildMultisigIn = function(pubkeys, threshold, signatures, opts) {
} 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) {
$.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers');
// TODO: allow signatures to be an array of Signature objects
Expand Down Expand Up @@ -818,7 +818,7 @@ Script.buildP2SHMultisigIn = function(pubkeys, threshold, signatures, opts) {
$.checkArgument(_.isArray(signatures));
opts = opts || {};
var s = new Script();

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
Expand All @@ -843,15 +843,15 @@ Script.buildP2SHMultisigIn = function(pubkeys, threshold, signatures, opts) {
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) {
$.checkArgument(BufferUtil.isBuffer(signature), 'Signatures must be an array of Buffers');
// TODO: allow signatures to be an array of Signature objects
Expand Down Expand Up @@ -914,6 +914,21 @@ Script.buildDataOut = function(data, encoding) {
return s;
};

/**
* @returns {Script} a new OP_RETURN script with data
* @param {(string|Buffer)} data - the data to embed in the output
*/
Script.buildOnchainMessage = function(data) {
$.checkArgument(!_.isUndefined(data));
var s = new Script();
s.add(Opcode.OP_RETURN);
if (!_.isUndefined(data)) {
s.add( Buffer.from('03030303', 'hex'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the lokad id to constant instead of hardcode

s.add( Buffer.from(data));
}
return s;
};

/**
* @param {Script|Address} script - the redeemScript for the new p2sh output.
* It can also be a p2sh address
Expand Down
17 changes: 12 additions & 5 deletions packages/bitcore-lib-xpi/lib/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@ Transaction.prototype.addData = function(value) {
return this;
};

Transaction.prototype.addOnchainMessage = function(value) {
this.addOutput(new Output({
script: Script.buildOnchainMessage(value),
satoshis: 0
}));
return this;
};

/**
* Add an output to the transaction.
Expand Down Expand Up @@ -1089,7 +1096,7 @@ Transaction.prototype.removeOutput = function(index) {
Transaction.prototype.sort = function() {
this.sortInputs(function(inputs) {
var copy = Array.prototype.concat.apply([], inputs);
let i = 0;
let i = 0;
copy.forEach((x) => { x.i = i++});
copy.sort(function(first, second) {
return compare(first.prevTxId, second.prevTxId)
Expand All @@ -1100,7 +1107,7 @@ Transaction.prototype.sort = function() {
});
this.sortOutputs(function(outputs) {
var copy = Array.prototype.concat.apply([], outputs);
let i = 0;
let i = 0;
copy.forEach((x) => { x.i = i++});
copy.sort(function(first, second) {
return first.satoshis - second.satoshis
Expand Down Expand Up @@ -1198,7 +1205,7 @@ Transaction.prototype.removeInput = function(txId, outputIndex) {
*/
Transaction.prototype.sign = function(privateKey, sigtype, signingMethod) {
signingMethod = signingMethod || "ecdsa"

$.checkState(this.hasAllUtxoInfo(), 'Not all utxo information is available to sign the transaction.');
var self = this;
if (_.isArray(privateKey)) {
Expand All @@ -1220,7 +1227,7 @@ Transaction.prototype.getSignatures = function(privKey, sigtype, signingMethod)
sigtype = sigtype || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);
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) {
Expand Down Expand Up @@ -1353,7 +1360,7 @@ Transaction.prototype.isCoinbase = function() {

Transaction.prototype.setVersion = function(version) {
$.checkArgument(
JSUtil.isNaturalNumber(version) && version <= CURRENT_VERSION,
JSUtil.isNaturalNumber(version) && version <= CURRENT_VERSION,
'Wrong version number');
this.version = version;
return this;
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-lib-xpi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abcpros/bitcore-lib-xpi",
"version": "8.25.37",
"version": "8.25.38",
"description": "A pure and powerful JavaScript Lotus library.",
"main": "index.js",
"types": "index.d.js",
Expand Down
13 changes: 7 additions & 6 deletions packages/bitcore-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"engines": {
"node": ">=8.0.0"
},
"version": "8.25.38",
"version": "8.25.39",
"author": "Justin Langston <[email protected]>",
"contributors": [
"Justin Langston <[email protected]>",
Expand Down Expand Up @@ -92,20 +92,20 @@
"typescript-eslint-parser": "15.0.0"
},
"dependencies": {
"@abcpros/bitcore-client": "^8.25.33",
"@abcpros/bitcore-client": "^8.25.34",
"@abcpros/bitcore-lib": "^8.25.32",
"@abcpros/bitcore-lib-cash": "^8.25.32",
"@abcpros/bitcore-lib-doge": "^8.25.32",
"@abcpros/bitcore-lib-ltc": "^8.25.32",
"@abcpros/bitcore-lib-xec": "^8.25.37",
"@abcpros/bitcore-lib-xpi": "^8.25.37",
"@abcpros/bitcore-lib-xpi": "^8.25.38",
"@abcpros/bitcore-p2p": "^8.25.32",
"@abcpros/bitcore-p2p-cash": "^8.25.32",
"@abcpros/bitcore-p2p-doge": "^8.25.32",
"@abcpros/bitcore-p2p-xec": "^8.25.34",
"@abcpros/bitcore-p2p-xpi": "^8.25.33",
"@abcpros/bitcore-wallet-client": "^8.25.40",
"@abcpros/crypto-wallet-core": "^8.25.35",
"@abcpros/bitcore-p2p-xpi": "^8.25.34",
"@abcpros/bitcore-wallet-client": "^8.25.41",
"@abcpros/crypto-wallet-core": "^8.25.36",
"JSONStream": "~1.3.1",
"abi-decoder": "^2.0.4",
"body-parser": "1.18.3",
Expand All @@ -117,6 +117,7 @@
"lru-cache": "4.1.3",
"mkdirp": "0.5.1",
"mongodb": "3.1.1",
"node-forge": "^1.3.1",
"progress": "2.0.0",
"request": "2.88.0",
"ripple-lib": "1.4.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-p2p-xpi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abcpros/bitcore-p2p-xpi",
"version": "8.25.33",
"version": "8.25.34",
"description": "Interface to the bitcoin P2P network for lotus",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -61,7 +61,7 @@
},
"dependencies": {
"@abcpros/bitcore-lib": "^8.25.32",
"@abcpros/bitcore-lib-xpi": "^8.25.37",
"@abcpros/bitcore-lib-xpi": "^8.25.38",
"bloom-filter": "^0.2.0",
"buffers": "bitpay/node-buffers#v0.1.2-bitpay",
"socks5-client": "^0.3.6"
Expand Down
Loading