btcOperator v1.0.14a
- Added multisig-bech32 to auto-fee calc - Fixed: createMultiSigTx not working with bech32 sender - Fixed: checkSigned for multisig-bech32
This commit is contained in:
parent
aebda7ec80
commit
a71c851cc2
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //btcOperator v1.0.14
|
(function (EXPORTS) { //btcOperator v1.0.14a
|
||||||
/* BTC Crypto and API Operator */
|
/* BTC Crypto and API Operator */
|
||||||
const btcOperator = EXPORTS;
|
const btcOperator = EXPORTS;
|
||||||
|
|
||||||
@ -108,12 +108,15 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
btcOperator.multiSigAddress = function (pubKeys, minRequired) {
|
btcOperator.multiSigAddress = function (pubKeys, minRequired, bech32 = true) {
|
||||||
if (!Array.isArray(pubKeys))
|
if (!Array.isArray(pubKeys))
|
||||||
throw "pubKeys must be an array of public keys";
|
throw "pubKeys must be an array of public keys";
|
||||||
else if (pubKeys.length < minRequired)
|
else if (pubKeys.length < minRequired)
|
||||||
throw "minimum required should be less than the number of pubKeys";
|
throw "minimum required should be less than the number of pubKeys";
|
||||||
return coinjs.pubkeys2MultisigAddress(pubKeys, minRequired);
|
if (bech32)
|
||||||
|
return coinjs.pubkeys2MultisigAddressBech32(pubKeys, minRequired);
|
||||||
|
else
|
||||||
|
return coinjs.pubkeys2MultisigAddress(pubKeys, minRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
//convert from one blockchain to another blockchain (target version)
|
//convert from one blockchain to another blockchain (target version)
|
||||||
@ -222,11 +225,13 @@
|
|||||||
BASE_INPUT_SIZE = 41,
|
BASE_INPUT_SIZE = 41,
|
||||||
LEGACY_INPUT_SIZE = 107,
|
LEGACY_INPUT_SIZE = 107,
|
||||||
BECH32_INPUT_SIZE = 27,
|
BECH32_INPUT_SIZE = 27,
|
||||||
|
BECH32_MULTISIG_INPUT_SIZE = 35,
|
||||||
SEGWIT_INPUT_SIZE = 59,
|
SEGWIT_INPUT_SIZE = 59,
|
||||||
MULTISIG_INPUT_SIZE_ES = 351,
|
MULTISIG_INPUT_SIZE_ES = 351,
|
||||||
BASE_OUTPUT_SIZE = 9,
|
BASE_OUTPUT_SIZE = 9,
|
||||||
LEGACY_OUTPUT_SIZE = 25,
|
LEGACY_OUTPUT_SIZE = 25,
|
||||||
BECH32_OUTPUT_SIZE = 23,
|
BECH32_OUTPUT_SIZE = 23,
|
||||||
|
BECH32_MULTISIG_OUTPUT_SIZE = 34,
|
||||||
SEGWIT_OUTPUT_SIZE = 23;
|
SEGWIT_OUTPUT_SIZE = 23;
|
||||||
|
|
||||||
function _redeemScript(addr, key) {
|
function _redeemScript(addr, key) {
|
||||||
@ -249,6 +254,8 @@
|
|||||||
return BASE_INPUT_SIZE + LEGACY_INPUT_SIZE;
|
return BASE_INPUT_SIZE + LEGACY_INPUT_SIZE;
|
||||||
case "bech32":
|
case "bech32":
|
||||||
return BASE_INPUT_SIZE + BECH32_INPUT_SIZE;
|
return BASE_INPUT_SIZE + BECH32_INPUT_SIZE;
|
||||||
|
case "multisigBech32":
|
||||||
|
return BASE_INPUT_SIZE + BECH32_MULTISIG_INPUT_SIZE;
|
||||||
case "multisig":
|
case "multisig":
|
||||||
switch (coinjs.script().decodeRedeemScript(rs).type) {
|
switch (coinjs.script().decodeRedeemScript(rs).type) {
|
||||||
case "segwit__":
|
case "segwit__":
|
||||||
@ -269,6 +276,8 @@
|
|||||||
return BASE_OUTPUT_SIZE + LEGACY_OUTPUT_SIZE;
|
return BASE_OUTPUT_SIZE + LEGACY_OUTPUT_SIZE;
|
||||||
case "bech32":
|
case "bech32":
|
||||||
return BASE_OUTPUT_SIZE + BECH32_OUTPUT_SIZE;
|
return BASE_OUTPUT_SIZE + BECH32_OUTPUT_SIZE;
|
||||||
|
case "multisigBech32":
|
||||||
|
return BASE_OUTPUT_SIZE + BECH32_MULTISIG_OUTPUT_SIZE;
|
||||||
case "multisig":
|
case "multisig":
|
||||||
return BASE_OUTPUT_SIZE + SEGWIT_OUTPUT_SIZE;
|
return BASE_OUTPUT_SIZE + SEGWIT_OUTPUT_SIZE;
|
||||||
default:
|
default:
|
||||||
@ -564,11 +573,14 @@
|
|||||||
btcOperator.createMultiSigTx = function (sender, redeemScript, receivers, amounts, fee = null, options = {}) {
|
btcOperator.createMultiSigTx = function (sender, redeemScript, receivers, amounts, fee = null, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
//validate tx parameters
|
//validate tx parameters
|
||||||
if (validateAddress(sender) !== "multisig")
|
let addr_type = validateAddress(sender);
|
||||||
|
if (!(["multisig", "multisigBech32"].includes(addr_type)))
|
||||||
return reject("Invalid sender (multisig):" + sender);
|
return reject("Invalid sender (multisig):" + sender);
|
||||||
else {
|
else {
|
||||||
let script = coinjs.script();
|
let script = coinjs.script();
|
||||||
let decode = script.decodeRedeemScript(redeemScript);
|
let decode = (addr_type == "multisig") ?
|
||||||
|
script.decodeRedeemScript(redeemScript) :
|
||||||
|
script.decodeRedeemScriptBech32(redeemScript);
|
||||||
if (!decode || decode.address !== sender)
|
if (!decode || decode.address !== sender)
|
||||||
return reject("Invalid redeem-script");
|
return reject("Invalid redeem-script");
|
||||||
}
|
}
|
||||||
@ -623,10 +635,10 @@
|
|||||||
let n = [];
|
let n = [];
|
||||||
for (let i in tx.ins) {
|
for (let i in tx.ins) {
|
||||||
var s = tx.extractScriptKey(i);
|
var s = tx.extractScriptKey(i);
|
||||||
if (s['type'] !== 'multisig')
|
if (s['type'] !== 'multisig' && s['type'] !== 'multisig_bech32')
|
||||||
n.push(s.signed == 'true' || (tx.witness[i] && tx.witness[i].length == 2))
|
n.push(s.signed == 'true' || (tx.witness[i] && tx.witness[i].length == 2))
|
||||||
else {
|
else {
|
||||||
var rs = coinjs.script().decodeRedeemScript(s.script);
|
var rs = coinjs.script().decodeRedeemScript(s.script); //will work for bech32 too, as only address is diff
|
||||||
let x = {
|
let x = {
|
||||||
s: s['signatures'],
|
s: s['signatures'],
|
||||||
r: rs['signaturesRequired'],
|
r: rs['signaturesRequired'],
|
||||||
@ -682,10 +694,10 @@
|
|||||||
result.outputs = tx.outs.map(out => {
|
result.outputs = tx.outs.map(out => {
|
||||||
var address;
|
var address;
|
||||||
switch (out.script.chunks[0]) {
|
switch (out.script.chunks[0]) {
|
||||||
case 0: //bech32
|
case 0: //bech32, multisig-bech32
|
||||||
address = encodeBech32(Crypto.util.bytesToHex(out.script.chunks[1]), coinjs.bech32.version, coinjs.bech32.hrp);
|
address = encodeBech32(Crypto.util.bytesToHex(out.script.chunks[1]), coinjs.bech32.version, coinjs.bech32.hrp);
|
||||||
break;
|
break;
|
||||||
case 169: //multisig, segwit
|
case 169: //segwit, multisig-segwit
|
||||||
address = encodeLegacy(Crypto.util.bytesToHex(out.script.chunks[1]), coinjs.multisig);
|
address = encodeLegacy(Crypto.util.bytesToHex(out.script.chunks[1]), coinjs.multisig);
|
||||||
break;
|
break;
|
||||||
case 118: //legacy
|
case 118: //legacy
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user