From dac87a85958f8e01e27f8ae9c83c99842edc35bb Mon Sep 17 00:00:00 2001 From: sairajzero Date: Mon, 20 Feb 2023 03:10:15 +0530 Subject: [PATCH] floCrypto v2.3.4: multisig address - Added getMultisigAddress(pubkeys, required_sigs): returns a multisig address from given pubkey list and required signatures - Added decodeRedeemScript (redeemScript): decodes the given redeemscript (of multisig) - Updated validateFloID: now validates FLO regular and multisig address. optional argument regularOnly(default=false) if true validates only FLO regular address. --- floCrypto.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/floCrypto.js b/floCrypto.js index 563d77f..5e8376f 100644 --- a/floCrypto.js +++ b/floCrypto.js @@ -1,4 +1,4 @@ -(function (EXPORTS) { //floCrypto v2.3.3e +(function (EXPORTS) { //floCrypto v2.3.4 /* FLO Crypto Operators */ 'use strict'; const floCrypto = EXPORTS; @@ -231,12 +231,36 @@ } } + floCrypto.getMultisigAddress = function (publicKeyList, requiredSignatures) { + if (!Array.isArray(publicKeyList) || !publicKeyList.length) + return null; + if (!Number.isInteger(requiredSignatures) || requiredSignatures < 1) + return null; + try { + var multisig = bitjs.pubkeys2multisig(publicKeyList, requiredSignatures); + return multisig; + } catch { + return null; + } + } + + floCrypto.decodeRedeemScript = function (redeemScript) { + try { + var decoded = bitjs.transaction().decodeRedeemScript(redeemScript); + return decoded; + } catch { + return null; + } + } + //Check if the given flo-id is valid or not - floCrypto.validateFloID = function (floID) { + floCrypto.validateFloID = function (floID, regularOnly = false) { if (!floID) return false; try { let addr = new Bitcoin.Address(floID); + if (regularOnly && addr.version != Bitcoin.Address.standardVersion) + return false; return true; } catch { return false;