lib v1.4.2b: bug fix

- Fixed: FLO multisig signing not working when redeemscript length is large
This commit is contained in:
sairajzero 2023-02-25 15:01:13 +05:30
parent 1a8e1abe45
commit 2e24f024d1

38
lib.js
View File

@ -1,4 +1,4 @@
(function (GLOBAL) { //lib v1.4.2a (function (GLOBAL) { //lib v1.4.2b
'use strict'; 'use strict';
/* Utility Libraries required for Standard operations /* Utility Libraries required for Standard operations
* All credits for these codes belong to their respective creators, moderators and owners. * All credits for these codes belong to their respective creators, moderators and owners.
@ -4527,14 +4527,12 @@
if (addr.version === bitjs.pub) { // regular address if (addr.version === bitjs.pub) { // regular address
buf.push(118); //OP_DUP buf.push(118); //OP_DUP
buf.push(169); //OP_HASH160 buf.push(169); //OP_HASH160
buf.push(addr.bytes.length); buf = this.writeBytesToScriptBuffer(buf, addr.bytes);// address in bytes
buf = buf.concat(addr.bytes); // address in bytes
buf.push(136); //OP_EQUALVERIFY buf.push(136); //OP_EQUALVERIFY
buf.push(172); //OP_CHECKSIG buf.push(172); //OP_CHECKSIG
} else if (addr.version === bitjs.multisig) { // multisig address } else if (addr.version === bitjs.multisig) { // multisig address
buf.push(169); //OP_HASH160 buf.push(169); //OP_HASH160
buf.push(addr.bytes.length); buf = this.writeBytesToScriptBuffer(buf, addr.bytes);// address in bytes
buf = buf.concat(addr.bytes); // address in bytes
buf.push(135); //OP_EQUAL buf.push(135); //OP_EQUAL
} }
@ -4796,6 +4794,27 @@
return KBigInt; return KBigInt;
}; };
btrx.writeBytesToScriptBuffer = function (buf, bytes) {
if (bytes.length < 76) { //OP_PUSHDATA1
buf.push(bytes.length);
} else if (bytes.length <= 0xff) {
buf.push(76); //OP_PUSHDATA1
buf.push(bytes.length);
} else if (bytes.length <= 0xffff) {
buf.push(77); //OP_PUSHDATA2
buf.push(bytes.length & 0xff);
buf.push((bytes.length >>> 8) & 0xff);
} else {
buf.push(78); //OP_PUSHDATA4
buf.push(bytes.length & 0xff);
buf.push((bytes.length >>> 8) & 0xff);
buf.push((bytes.length >>> 16) & 0xff);
buf.push((bytes.length >>> 24) & 0xff);
}
buf = buf.concat(bytes);
return buf;
}
btrx.parseScript = function (script) { btrx.parseScript = function (script) {
var chunks = []; var chunks = [];
@ -4859,8 +4878,7 @@
var signature = this.transactionSig(index, wif, shType); var signature = this.transactionSig(index, wif, shType);
var buf = []; var buf = [];
var sigBytes = Crypto.util.hexToBytes(signature); var sigBytes = Crypto.util.hexToBytes(signature);
buf.push(sigBytes.length); buf = this.writeBytesToScriptBuffer(buf, sigBytes);
buf = buf.concat(sigBytes);
var pubKeyBytes = Crypto.util.hexToBytes(key['pubkey']); var pubKeyBytes = Crypto.util.hexToBytes(key['pubkey']);
buf.push(pubKeyBytes.length); buf.push(pubKeyBytes.length);
buf = buf.concat(pubKeyBytes); buf = buf.concat(pubKeyBytes);
@ -4908,16 +4926,14 @@
for (let y in sigsList) { for (let y in sigsList) {
var sighash = Crypto.util.hexToBytes(this.transactionHash(index, sigsList[y].slice(-1)[0] * 1)); var sighash = Crypto.util.hexToBytes(this.transactionHash(index, sigsList[y].slice(-1)[0] * 1));
if (bitjs.verifySignature(sighash, sigsList[y], pubkeyList[x])) { if (bitjs.verifySignature(sighash, sigsList[y], pubkeyList[x])) {
buf.push(sigsList[y].length); buf = this.writeBytesToScriptBuffer(buf, sigsList[y]);
buf = buf.concat(sigsList[y]);
break; //ensures duplicate sigs from same pubkey are not added break; //ensures duplicate sigs from same pubkey are not added
} }
} }
} }
//append redeemscript //append redeemscript
buf.push(redeemScript.length); buf = this.writeBytesToScriptBuffer(buf, redeemScript);
buf = buf.concat(redeemScript);
this.inputs[index].script = buf; this.inputs[index].script = buf;
return true; return true;