Socket
Socket
Sign inDemoInstall

ldk

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldk - npm Package Compare versions

Comparing version 0.3.15 to 0.3.16

dist/coinselection/utils.d.ts

4

dist/coinselection/coinSelector.d.ts

@@ -1,2 +0,2 @@

import { UtxoInterface, RecipientInterface, ChangeAddressFromAssetGetter } from './../types';
import { UtxoInterface, RecipientInterface, ChangeAddressFromAssetGetter, CoinSelectorErrorFn } from './../types';
export interface CoinSelectionResult {

@@ -6,2 +6,2 @@ selectedUtxos: UtxoInterface[];

}
export declare type CoinSelector = (unspents: UtxoInterface[], outputs: RecipientInterface[], changeGetter: ChangeAddressFromAssetGetter) => CoinSelectionResult;
export declare type CoinSelector = (errorHandler: CoinSelectorErrorFn) => (unspents: UtxoInterface[], outputs: RecipientInterface[], changeGetter: ChangeAddressFromAssetGetter) => CoinSelectionResult;

@@ -1,4 +0,8 @@

import { UtxoInterface } from './../types';
import { CompareUtxoFn } from './../types';
import { CoinSelector } from './coinSelector';
export declare type CompareUtxoFn = (a: UtxoInterface, b: UtxoInterface) => number;
export declare function greedyCoinSelector(compare?: CompareUtxoFn): CoinSelector;
/**
* select utxo for outputs among unspents.
* @param unspents a set of unspents.
* @param outputs the outputs targetted by the coin selection
*/
export declare function greedyCoinSelector(sortFn?: CompareUtxoFn): CoinSelector;
import { BIP32Interface } from 'bip32';
import { BlindingDataLike } from 'liquidjs-lib/types/psbt';
import { Slip77Interface } from 'slip77';
import { AddressInterface, MultisigPayment, CosignerMultisig } from '../types';

@@ -21,2 +22,3 @@ import { IdentityInterface, IdentityOpts } from './identity';

cosigners: BIP32Interface[];
blindingKeyMasterNode: Slip77Interface;
requiredSignatures: number;

@@ -23,0 +25,0 @@ constructor(args: IdentityOpts<MultisigWatchOnlyOpts>);

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("liquidjs-lib"),r=require("bip32"),n=require("bip39"),i=e(require("bs58check")),o=require("slip77"),s=e(require("axios"));function a(e){this.wrapped=e}function u(e){var t,r;function n(t,r){try{var o=e[t](r),s=o.value,u=s instanceof a;Promise.resolve(u?s.wrapped:s).then((function(e){u?n("return"===t?"return":"next",e):i(o.done?"return":"normal",e)}),(function(e){n("throw",e)}))}catch(e){i("throw",e)}}function i(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?n(t.key,t.arg):r=null}this._invoke=function(e,i){return new Promise((function(o,s){var a={key:e,arg:i,resolve:o,reject:s,next:null};r?r=r.next=a:(t=r=a,n(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function c(e){return function(){return new u(e.apply(this,arguments))}}function p(e){return new a(e)}function f(e,t,r,n,i,o,s){try{var a=e[o](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,i)}function d(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function s(e){f(o,n,i,s,a,"next",e)}function a(e){f(o,n,i,s,a,"throw",e)}s(void 0)}))}}function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,y(e,t)}function v(e){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function x(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function g(e,t,r){return(g=x()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&y(i,r.prototype),i}).apply(null,arguments)}function b(e){var t="function"==typeof Map?new Map:void 0;return(b=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return g(e,arguments,v(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)})(e)}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function w(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return m(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?m(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}u.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},u.prototype.next=function(e){return this._invoke("next",e)},u.prototype.throw=function(e){return this._invoke("throw",e)},u.prototype.return=function(e){return this._invoke("return",e)};var P,k,A=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=Object.create((t&&t.prototype instanceof f?t:f).prototype),o=new k(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=m(s,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,o),i}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function d(){}function l(){}var h={};a(h,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(A([])));y&&y!==t&&r.call(y,i)&&(h=y);var x=l.prototype=f.prototype=Object.create(h);function g(e){["next","throw","return"].forEach((function(t){a(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(i,o){function s(){return new t((function(n,s){!function n(i,o,s,a){var u=c(e[i],e,o);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,s,a)}),(function(e){n("throw",e,s,a)})):t.resolve(f).then((function(e){p.value=e,s(p)}),(function(e){return n("throw",e,s,a)}))}a(u.arg)}(i,o,n,s)}))}return n=n?n.then(s,s):s()}}function m(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function A(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:K}}function K(){return{value:void 0,done:!0}}return d.prototype=l,a(x,"constructor",l),a(l,"constructor",d),d.displayName=a(l,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,a(e,s,"GeneratorFunction")),e.prototype=Object.create(x),e},e.awrap=function(e){return{__await:e}},g(b.prototype),a(b.prototype,o,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var s=new b(u(t,r,n,i),o);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},g(x),a(x,s,"Generator"),a(x,i,(function(){return this})),a(x,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=A,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(k={exports:{}}),k.exports);function K(e){return"surjectionProof"in e&&"rangeProof"in e}function E(e){return e.slice(1).reverse().toString("hex")}function I(e){return t.confidential.confidentialValueToSatoshi(e)}(P=exports.IdentityType||(exports.IdentityType={}))[P.PrivateKey=1]="PrivateKey",P[P.Mnemonic=2]="Mnemonic",P[P.MasterPublicKey=3]="MasterPublicKey",P[P.Inject=4]="Inject",P[P.Ledger=5]="Ledger",P[P.Trezor=6]="Trezor",P[P.MultisigWatchOnly=7]="MultisigWatchOnly",P[P.Multisig=8]="Multisig";var B=Buffer.from("0x00","hex");function T(e){return null!=e&&e.length>0}function S(e){var t=e.surjectionProof,r=e.nonce;return T(e.rangeProof)&&T(t)&&r!==B}var N=function(){function e(){this.map=new Map}var t=e.prototype;return t.bufferToStringPrimitive=function(e){return e.toString("hex").valueOf()},t.get=function(e){return this.map.get(this.bufferToStringPrimitive(e))},t.set=function(e,t){return this.map.set(this.bufferToStringPrimitive(e),t),this},t.values=function(){return Array.from(this.map.values())},e}(),O=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function _(e,t){if(!O.has(t))return"Invalid target version";e=e.trim();try{var r=i.decode(e);return r=r.slice(4),r=Buffer.concat([Buffer.from(O.get(t),"hex"),r]),i.encode(r)}catch(e){throw new Error("Invalid extended public key! Please double check that you didn't accidentally paste extra data.")}}function M(e,t){return _(e,"regtest"===t?"vpub":"zpub")}function L(e){return _(e,"xpub")}function U(e,t){try{r.fromBase58(e,t)}catch(e){return!1}return!0}function j(e){try{o.fromMasterBlindingKey(e)}catch(e){return!1}return!0}function C(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r.data.globalMap.unsignedTx.toBuffer().toString("hex")}function F(e){return{txid:e.txid,vout:e.vout}}function W(e){return!e.asset||!e.value}function D(e){return e?t.networks[e]:t.networks.liquid}function R(e,t){return X.apply(this,arguments)}function X(){return(X=d(A.mark((function e(r,n){var i,o,s,a;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={asset:r.blindedAsset,value:r.blindedValue,rangeProof:r.rangeProof,surjectionProof:r.surjectionProof,nonce:r.nonce,script:Buffer.from(r.script,"hex")},o=Buffer.from(n,"hex"),e.next=4,t.confidential.unblindOutputWithKey(i,o);case 4:return s=e.sent,a={asset:Buffer.from(s.asset.reverse()).toString("hex"),value:parseInt(s.value,10),script:r.script,assetBlinder:s.assetBlindingFactor.toString("hex"),valueBlinder:s.valueBlindingFactor.toString("hex")},e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function q(e,t){if(e!==t)throw new Error("Incorrect Identity type: need "+t+" and get "+e+".")}function H(e,t){if(t&&n.setDefaultWordlist(t),!n.validateMnemonic(e))throw new Error("Mnemonic is not valid.")}function G(e){try{r.fromBase58(e)}catch(t){throw new Error("invalid master public key: "+e)}}function V(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r}var z=function(){function e(e){if(!e.chain||!t.networks.hasOwnProperty(e.chain))throw new Error("Network is missing or not valid");if(!e.type||!(e.type in exports.IdentityType))throw new Error("Type is missing or not valid");this.network=t.networks[e.chain],this.type=e.type}return e.prototype.blindPsetWithBlindKeysGetter=function(){var e=d(A.mark((function e(r,n,i,o,s){var a,u,c,p,f,d,l,h,v,y,x,g,b,m,P;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=new Map,u=new Map,c=V(n),p=t.Transaction.fromHex(C(n)),f=w(i);case 5:if((d=f()).done){e.next=16;break}if(l=d.value,null==o||!o.has(l)){e.next=11;break}return h=Buffer.from(o.get(l),"hex"),u.set(l,h),e.abrupt("continue",14);case 11:v=r(p.outs[l].script).publicKey,u.set(l,v);case 14:e.next=5;break;case 16:y=0;case 17:if(!(y<c.data.inputs.length)){e.next=43;break}if(g=void 0,!(x=c.data.inputs[y]).witnessUtxo){e.next=24;break}if(S(x.witnessUtxo)){e.next=23;break}return e.abrupt("continue",40);case 23:g=x.witnessUtxo.script;case 24:if(!x.nonWitnessUtxo){e.next=30;break}if(b=p.ins[y].index,S(m=t.Transaction.fromBuffer(x.nonWitnessUtxo).outs[b])){e.next=29;break}return e.abrupt("continue",40);case 29:g=m.script;case 30:if(null==s||!s.has(y)){e.next=33;break}return a.set(y,s.get(y)),e.abrupt("continue",40);case 33:if(g){e.next=35;break}throw new Error("no witness script for input #"+y);case 35:return P=r(g).privateKey,e.next=38,t.confidential.unblindOutputWithKey(x.witnessUtxo,P);case 38:a.set(y,e.sent);case 40:y++,e.next=17;break;case 43:return e.next=45,c.blindOutputsByIndex(a,u);case 45:return e.abrupt("return",e.sent.toBase64());case 47:case"end":return e.stop()}}),e)})));return function(t,r,n,i,o){return e.apply(this,arguments)}}(),e}(),Y=function(e){function n(t){var i;(i=e.call(this,t)||this).index=n.INITIAL_INDEX,i.changeIndex=n.INITIAL_INDEX,i.scriptToAddressCache={};var s=L(t.opts.masterPublicKey);if(q(t.type,exports.IdentityType.MasterPublicKey),!U(s))throw new Error("Master public key is not valid");if(!j(t.opts.masterBlindingKey))throw new Error("Master blinding key is not valid");return i.masterPublicKeyNode=r.fromBase58(s),i.masterBlindingKeyNode=o.fromMasterBlindingKey(t.opts.masterBlindingKey),i.baseDerivationPath=t.opts.baseDerivationPath||n.INITIAL_BASE_PATH,i}h(n,e);var i=n.prototype;return i.blindPset=function(){var t=d(A.mark((function t(r,n,i,o){var s=this;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return s.getBlindingKeyPair(e.toString("hex"),!0)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),i.isAbleToSign=function(){return!1},i.derivePublicKeyWithIndex=function(e,t){return this.masterPublicKeyNode.derive(e?1:0).derive(t).publicKey},i.getBlindingKeyPair=function(e,t){if(void 0===t&&(t=!1),t&&!this.scriptToAddressCache[e])throw new Error("unknow blinding key for script "+e);var r=this.masterBlindingKeyNode.derive(e);return{publicKey:r.publicKey,privateKey:r.privateKey}},i.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output.toString("hex")},i.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},i.persistAddressToCache=function(e){var t=Buffer.from(e.publicKey,"hex"),r=this.scriptFromPublicKey(t);this.scriptToAddressCache[r]=e},i.getAddress=function(e,t){var r=this.derivePublicKeyWithIndex(e,t),n=this.scriptFromPublicKey(r),i=this.getBlindingKeyPair(n),o=this.createConfidentialAddress(r,i.publicKey),s=this.baseDerivationPath+"/"+(e?1:0)+"/"+t;return{address:{confidentialAddress:o,blindingPrivateKey:i.privateKey.toString("hex"),derivationPath:s},publicKey:r.toString("hex")}},i.getNextAddress=function(){var e=d(A.mark((function e(){var t;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.getAddress(!1,this.index),this.persistAddressToCache(t),this.index=this.index+1,e.abrupt("return",t.address);case 4:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),i.getNextChangeAddress=function(){var e=d(A.mark((function e(){var t;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.getAddress(!0,this.changeIndex),this.persistAddressToCache(t),this.changeIndex=this.changeIndex+1,e.abrupt("return",t.address);case 4:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),i.getBlindingPrivateKey=function(){var e=d(A.mark((function e(t){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.getBlindingKeyPair(t).privateKey.toString("hex"));case 1:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),i.signPset=function(e){throw new Error("MasterPublicKey is a watch only identity. Use Mnemonic to sign transactions")},i.getAddresses=function(){var e=d(A.mark((function e(){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Object.values(this.scriptToAddressCache).map((function(e){return e.address})));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),i.getXPub=function(){return this.masterPublicKeyNode.toBase58()},n}(z);Y.INITIAL_BASE_PATH="m/84'/0'/0'",Y.INITIAL_INDEX=0;var Z=function(e){function i(i){var s;q(i.type,exports.IdentityType.Mnemonic),n.setDefaultWordlist(i.opts.language||"english"),H(i.opts.mnemonic);var a=n.mnemonicToSeedSync(i.opts.mnemonic),u=r.fromSeed(a,t.networks[i.chain]),c=u.derivePath(Y.INITIAL_BASE_PATH),p=M(t.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58(),i.chain),f=o.fromSeed(a),d=f.masterKey.toString("hex");return(s=e.call(this,l({},i,{type:exports.IdentityType.MasterPublicKey,opts:{masterPublicKey:p,masterBlindingKey:d,baseDerivationPath:i.opts.baseDerivationPath}}))||this).masterBlindingKey=d,s.masterBlindingKeyNode=f,s.masterPublicKey=p,s.masterPrivateKeyNode=u,s.mnemonic=i.opts.mnemonic,s}h(i,e);var s=i.prototype;return s.blindPset=function(){var t=d(A.mark((function t(r,n,i,o){var s=this;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(t){return e.prototype.getBlindingKeyPair.call(s,t.toString("hex"),!0)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),s.isAbleToSign=function(){return!0},s.derivePath=function(e){var r=this.masterPrivateKeyNode.derivePath(e).toWIF(),n=t.ECPair.fromWIF(r,this.network);return{publicKey:n.publicKey,privateKey:n.privateKey}},s.signPset=function(){var e=d(A.mark((function e(r){var n,i,o,s,a,u,c;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo&&(a=this.scriptToAddressCache[s.witnessUtxo.script.toString("hex")])&&(u=this.derivePath(a.address.derivationPath).privateKey,c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c)));return e.next=5,Promise.all(i);case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),i.Random=function(e,t){var r=n.generateMnemonic();return new i({chain:e,type:exports.IdentityType.Mnemonic,opts:{mnemonic:r,baseDerivationPath:t}})},i}(Y),$=function(e){function r(r){var n;n=e.call(this,r)||this,q(r.type,exports.IdentityType.PrivateKey),n.signingKeyPair=n.decodeFromWif(r.opts.signingKeyWIF),n.blindingKeyPair=n.decodeFromWif(r.opts.blindingKeyWIF);var i=t.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=i.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=i.output,n}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(A.mark((function t(r,n,i,o){var s=this;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return s.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.getBlindingKeyPair=function(e){if(!e.equals(this.scriptPubKey))throw new Error(e+" is unknown by the PrivateKey Identity");return{publicKey:this.blindingKeyPair.publicKey,privateKey:this.blindingKeyPair.privateKey}},n.isAbleToSign=function(){return!0},n.decodeFromWif=function(e){return t.ECPair.fromWIF(e,this.network)},n.getAddress=function(){return{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey,derivationPath:void 0}},n.getNextAddress=function(){var e=d(A.mark((function e(){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.getAddress());case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.getNextChangeAddress=function(){var e=d(A.mark((function e(){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.getAddress());case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.getBlindingPrivateKey=function(){var e=d(A.mark((function e(t){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Buffer.from(t,"hex").equals(this.scriptPubKey)){e.next=3;break}throw new Error("The script is not PrivateKey.scriptPubKey.");case 3:return e.abrupt("return",this.blindingPrivateKey);case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.signPset=function(){var e=d(A.mark((function e(r){var n,i,o,s,a=this;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo?s.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(o):i.push(o);return e.next=5,Promise.all(i.map((function(e){return n.signInputAsync(e,a.signingKeyPair)})));case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getAddresses=function(){var e=d(A.mark((function e(){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",[{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey,derivationPath:void 0}]);case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r}(z),J=function(e){function t(t){var r;if(r=e.call(this,t)||this,q(t.type,exports.IdentityType.Inject),void 0===window||void 0===window[t.opts.windowProvider])throw new Error("The value.windowProvider of IdentityOpts is not valid or the script is to injected in the window");return r.provider=window[t.opts.windowProvider],r}h(t,e);var r=t.prototype;return r.getNextAddress=function(){return this.provider.getNextAddress()},r.getNextChangeAddress=function(){return this.provider.getNextChangeAddress()},r.signPset=function(e){return this.provider.signTransaction(e)},r.getAddresses=function(){return this.provider.getAddresses()},r.getBlindingPrivateKey=function(e){throw new Error("Method not implemented.")},r.isAbleToSign=function(){return!0},r.blindPset=function(e,t,r,n){throw new Error("Method not implemented.")},t}(z);function Q(e){var r=function(e){for(var r,n=Buffer.from("blinding_key"),i=Buffer.alloc(32),o=w(e);!(r=o()).done;)i=ee(i,r.value);return t.crypto.sha256(Buffer.concat([n,i]))}(e.map((function(e){return e.chainCode})));return o.fromSeed(r)}function ee(e,t){if(e.length!==t.length)throw new Error("a.length !== b.length (xor)");for(var r=Buffer.alloc(e.length),n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}var te=function(e){function i(t){var i;(i=e.call(this,t)||this).nextIndex=0,i.nextChangeIndex=0,q(t.type,exports.IdentityType.MultisigWatchOnly),function(e,t){if(e<=0||e>t)throw new Error("number of required signatures must be > 0 and <= "+t)}(t.opts.requiredSignatures,t.opts.cosigners.length);var o=t.opts.cosigners.map((function(e){return function(e,t){if("string"==typeof e)return e;var i=n.mnemonicToSeedSync(e.mnemonic),o=r.fromSeed(i,t).derivePath(e.baseDerivationPath||"m/48'/0'/0'/2'");return L(r.fromPublicKey(o.publicKey,o.chainCode,t).toBase58())}(e,i.network)}));return o.forEach(G),i.cosigners=o.sort().map((function(e){return r.fromBase58(e)})),i.requiredSignatures=t.opts.requiredSignatures,i}h(i,e);var o=i.prototype;return o.getNextAddress=function(){var e=this.getMultisigAddress(i.EXTERNAL_INDEX,this.nextIndex);return this.nextIndex++,Promise.resolve(e)},o.getNextChangeAddress=function(){var e=this.getMultisigAddress(i.INTERNAL_INDEX,this.nextChangeIndex);return this.nextChangeIndex++,Promise.resolve(e)},o.getAddresses=function(){var e=this,t=Array.from(Array(this.nextIndex).keys()).map((function(t){return e.getMultisigAddress(i.EXTERNAL_INDEX,t)})),r=Array.from(Array(this.nextChangeIndex).keys()).map((function(t){return e.getMultisigAddress(i.INTERNAL_INDEX,t)}));return Promise.resolve(t.concat(r))},o.getBlindingPrivateKey=function(e){var t=this.getBlindingKeyPair(e).privateKey;return Promise.resolve(t.toString("hex"))},o.getBlindingKeyPair=function(e){var t=Q(this.cosigners).derive(e);if(!t.publicKey||!t.privateKey)throw new Error("unable to generate blinding key pair");return{publicKey:t.publicKey,privateKey:t.privateKey}},o.isAbleToSign=function(){return!1},o.signPset=function(e){throw new Error("WatchOnly Multisig Identity is not able to sign pset")},o.blindPset=function(t,r,n,i){var o=this;return e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return o.getBlindingKeyPair(e.toString("hex"))}),t,r,n,i)},o.getMultisigAddress=function(e,r){return l({},function(e,r,n,i){var o=t.payments.p2wsh({redeem:t.payments.p2ms({m:parseInt(n.toString()),pubkeys:e.map((function(e){return e.publicKey})),network:i}),network:i});if(!o.output)throw new Error("Invalid payment");var s=r.derive(o.output),a=s.publicKey,u=s.privateKey;if(!a||!u)throw new Error("something went wrong while generating blinding key pair");if(!(o=t.payments.p2wsh({redeem:t.payments.p2ms({m:parseInt(n.toString()),pubkeys:e.map((function(e){return e.publicKey})),network:i}),blindkey:a,network:i})).confidentialAddress||!o.redeem||!o.redeem.output)throw new Error("invalid payment");return{blindingPrivateKey:u.toString("hex"),confidentialAddress:o.confidentialAddress,witnessScript:o.redeem.output.toString("hex")}}(this.cosigners.map((function(t){return t.derive(e).derive(r)})),Q(this.cosigners),this.requiredSignatures,this.network),{derivationPath:e+"/"+r})},i}(z);te.EXTERNAL_INDEX=0,te.INTERNAL_INDEX=1;var re=function(e){function i(i){var o;q(i.type,exports.IdentityType.Multisig),H(i.opts.signer.mnemonic);var s=n.mnemonicToSeedSync(i.opts.signer.mnemonic),a=r.fromSeed(s,t.networks[i.chain]).derivePath(i.opts.signer.baseDerivationPath||"m/48'/0'/0'/2'");return(o=e.call(this,l({},i,{opts:l({},i.opts,{cosigners:i.opts.cosigners.concat([i.opts.signer])}),type:exports.IdentityType.MultisigWatchOnly}))||this).baseDerivationPath=i.opts.signer.baseDerivationPath||"m/48'/0'/0'/2'",o.baseNode=a,o.scriptToPath={},o}h(i,e);var o=i.prototype;return o.getNextAddress=function(){var t=d(A.mark((function t(){var r;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.getNextAddress.call(this);case 2:if((r=t.sent).derivationPath){t.next=5;break}throw new Error("need derivation path to cache addresses");case 5:return this.scriptToPath[this.toScript(r.confidentialAddress)]=r.derivationPath,t.abrupt("return",r);case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.getNextChangeAddress=function(){var t=d(A.mark((function t(){var r;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.prototype.getNextChangeAddress.call(this);case 2:if((r=t.sent).derivationPath){t.next=5;break}throw new Error("need derivation path to cache addresses");case 5:return this.scriptToPath[this.toScript(r.confidentialAddress)]=r.derivationPath,t.abrupt("return",r);case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.isAbleToSign=function(){return!0},o.signPset=function(){var e=d(A.mark((function e(r){var n,i,o,s,a,u,c;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=t.Psbt.fromBase64(r),i=[],o=0;case 3:if(!(o<n.data.inputs.length)){e.next=16;break}if(!(s=n.data.inputs[o]).witnessUtxo){e.next=13;break}if(!(a=this.scriptToPath[s.witnessUtxo.script.toString("hex")])){e.next=13;break}if(u=this.baseNode.derivePath(a).privateKey){e.next=11;break}throw new Error("signing private key is undefined");case 11:c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c));case 13:o++,e.next=3;break;case 16:return e.next=18,Promise.all(i);case 18:return e.abrupt("return",n.toBase64());case 19:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o.getXPub=function(){return L(r.fromPublicKey(this.baseNode.publicKey,this.baseNode.chainCode,this.network).toBase58())},o.toScript=function(e){return t.address.toOutputScript(e,this.network).toString("hex")},i}(te),ne=function(e,t){return e.value-t.value};function ie(e,t,r){for(var n,i=[],o=0,s=w(e=e.sort(r));!(n=s()).done;){var a=n.value;if(W(a)||(i.push(a),o+=a.value),o>=t)return{selected:i,changeAmount:o-t}}throw new Error("not enough utxos in wallet to fund: "+t)}function oe(e,t){return e.reduce((function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e}),{})}var se=Buffer.alloc(32).toString("hex");function ae(e,t){return ue.apply(this,arguments)}function ue(){return(ue=d(A.mark((function e(t,r){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.get(r+"/tx/"+t+"/hex");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ce(){return(ce=d(A.mark((function e(t,r){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=de,e.next=3,s.get(r+"/tx/"+t);case 3:return e.t1=e.sent.data,e.t2=r,e.abrupt("return",(0,e.t0)(e.t1,e.t2));case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function pe(e,t){return fe.apply(this,arguments)}function fe(){return(fe=d(A.mark((function e(t,r){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.get(r+"/address/"+t+"/utxo");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function de(e,t){return le.apply(this,arguments)}function le(){return(le=d(A.mark((function e(r,n){var i,o,s,a,u,c,p,f,d;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],o=[],s=w(r.vin);!(a=s()).done;)i.push((u=a.value).txid),o.push(u.vout);return e.next=5,Promise.all(i.map((function(e,t){return r.vin[t].is_pegin?Promise.resolve(void 0):ae(e,n)})));case 5:return c=e.sent.map((function(e,r){if(e)return he(t.Transaction.fromHex(e).outs[o[r]])})),p=i.map((function(e,t){return{prevout:c[t],txid:e,vout:o[t],isPegin:r.vin[t].is_pegin}})),e.next=10,ae(r.txid,n);case 10:return f=t.Transaction.fromHex(e.sent),d=f.outs.map(he),e.abrupt("return",{txid:r.txid,vin:p,vout:d,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function he(e){return S(e)?{blindedAsset:e.asset,blindedValue:e.value,nonce:e.nonce,rangeProof:e.rangeProof,surjectionProof:e.surjectionProof,script:e.script.toString("hex")}:{asset:E(e.asset),value:I(e.value),script:e.script.toString("hex"),assetBlinder:se,valueBlinder:se}}function ve(e,t,r){return e+"/tx/"+t+"#blinded="+r.map((function(e){return e.value+","+e.asset+","+e.valueBlinder+","+e.assetBlinder})).join(",")}var ye=function(e){function t(t,r,n){return e.call(this,"UnblindError output ("+t+":"+r+") with blind key "+n)||this}return h(t,e),t}(b(Error));function xe(e,t,r,n){return ge.apply(this,arguments)}function ge(){return(ge=c(A.mark((function e(t,r,n,i){var o,s,a,u,c,f,d,l,h,v;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=[],s=[],a=w(t);case 3:if((u=a()).done){e.next=40;break}return c=u.value,e.prev=5,f=me(c,n,i),e.next=9,p(f.next());case 9:d=e.sent;case 10:if(d.done){e.next=31;break}if(!o.includes((l=d.value).txid)){e.next=17;break}return e.next=15,p(f.next());case 15:return d=e.sent,e.abrupt("continue",10);case 17:return e.next=19,p(Pe(l,r));case 19:return v=(h=e.sent).unblindedTx,s.push.apply(s,h.errors),e.next=25,v;case 25:return o.push(l.txid),e.next=28,p(f.next());case 28:d=e.sent,e.next=10;break;case 31:e.next=38;break;case 33:e.prev=33,e.t0=e.catch(5),e.t0 instanceof Error&&s.push(e.t0),"string"==typeof e.t0&&s.push(new Error(e.t0)),s.push(new Error("unknown error"));case 38:e.next=3;break;case 40:return e.abrupt("return",{txIDs:o,errors:s});case 41:case"end":return e.stop()}}),e,null,[[5,33]])})))).apply(this,arguments)}function be(){return(be=d(A.mark((function e(t,r,n,i){var o,s,a;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=xe(t,r,n,i),s=[],e.next=4,o.next();case 4:a=e.sent;case 5:if(a.done){e.next=12;break}return s.push(a.value),e.next=9,o.next();case 9:a=e.sent,e.next=5;break;case 12:return e.abrupt("return",s);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function me(e,t,r){return we.apply(this,arguments)}function we(){return(we=c(A.mark((function e(t,r,n){var i,o,s,a,u,c,f,d;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=void 0,o=[],s=0;case 3:return e.next=5,p(Ae(t,r,i));case 5:if(0!==(o=e.sent).length){e.next=8;break}return e.abrupt("break",24);case 8:i=o[o.length-1].txid,s+=o.length,a=o.map((function(e){return de(e,r)})),u=w(a);case 12:if((c=u()).done){e.next=23;break}return f=c.value,e.next=16,p(f);case 16:if(d=e.sent,null==n||!n(d)){e.next=19;break}return e.abrupt("continue",21);case 19:return e.next=21,d;case 21:e.next=12;break;case 23:if(i){e.next=3;break}case 24:return e.abrupt("return",s);case 25:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pe(e,t){return ke.apply(this,arguments)}function ke(){return(ke=d(A.mark((function e(t,r){var n,i,o,s,a,u;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],i=[],o=function(e){var o=t.vin[e].prevout;o&&K(o)&&n.push(function(){var n=d(A.mark((function n(){var s;return A.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.script))){n.next=12;break}return n.prev=2,n.next=5,R(o,s);case 5:t.vin[e].prevout=n.sent,n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i.push(new ye(t.vin[e].txid,t.vin[e].vout,s));case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(){return n.apply(this,arguments)}}()())},s=0;s<t.vin.length;s++)o(s);for(a=function(e){var o=t.vout[e];K(o)&&n.push(function(){var n=d(A.mark((function n(){var s;return A.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.script))){n.next=12;break}return n.prev=2,n.next=5,R(o,s);case 5:t.vout[e]=n.sent,n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i.push(new ye(t.txid,e,s));case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(){return n.apply(this,arguments)}}()())},u=0;u<t.vout.length;u++)a(u);return e.next=8,Promise.all(n);case 8:return e.abrupt("return",{unblindedTx:t,errors:i});case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ae(e,t,r){return Ke.apply(this,arguments)}function Ke(){return(Ke=d(A.mark((function e(t,r,n){var i;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r+"/address/"+t+"/txs/chain",n&&(i+="/"+n),e.next=4,s.get(i);case 4:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ee(){return(Ee=d(A.mark((function e(t,r,n){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Te([{confidentialAddress:t,blindingPrivateKey:r}],n);case 2:return e.abrupt("return",e.sent.reduce((function(e,t){var r=t.asset;return e[r]=e[r]||0,e[r]+=t.value,e}),{}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ie(e,t,r){return Be.apply(this,arguments)}function Be(){return(Be=c(A.mark((function e(r,n,i){var o,s,a,u,c,f,d,l,h,v,y,x,g,b,m;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=0,s=[],a=w(r);case 3:if((u=a()).done){e.next=41;break}if(f=(c=u.value).confidentialAddress,d=c.blindingPrivateKey,e.prev=5,!(d.length>0)){e.next=11;break}if(l=t.ECPair.fromPrivateKey(Buffer.from(d,"hex")),h=t.address.fromConfidential(f).blindingKey,l.publicKey.equals(h)){e.next=11;break}throw new Error("wrong blinding private key");case 11:return e.next=13,p(pe(f,n));case 13:v=w(e.sent);case 15:if((y=v()).done){e.next=32;break}if(x=y.value,null==i||!i(x)){e.next=21;break}return e.next=20,x;case 20:return e.abrupt("continue",30);case 21:return e.next=23,p(_e(x,d,n));case 23:return b=(g=e.sent).unblindedUtxo,(m=g.error)&&s.push(m),e.next=29,b;case 29:o++;case 30:e.next=15;break;case 32:e.next=39;break;case 34:e.prev=34,e.t0=e.catch(5),e.t0 instanceof Error&&s.push(e.t0),"string"==typeof e.t0&&s.push(new Error(e.t0)),s.push(new Error("unknow error"));case 39:e.next=3;break;case 41:return e.abrupt("return",{numberOfUtxos:o,errors:s});case 42:case"end":return e.stop()}}),e,null,[[5,34]])})))).apply(this,arguments)}function Te(e,t,r){return Se.apply(this,arguments)}function Se(){return(Se=d(A.mark((function e(t,r,n){var i,o,s;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=Ie(t,r,n),o=[],e.next=4,i.next();case 4:s=e.sent;case 5:if(s.done){e.next=12;break}return o.push(s.value),e.next=9,i.next();case 9:s=e.sent,e.next=5;break;case 12:return e.abrupt("return",o);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ne(e,t){return Oe.apply(this,arguments)}function Oe(){return(Oe=d(A.mark((function e(r,n){var i;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ae(r.txid,n);case 2:return i=t.Transaction.fromHex(e.sent).outs[r.vout],e.abrupt("return",l({},r,{prevout:i}));case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _e(e,t,r){return Me.apply(this,arguments)}function Me(){return(Me=d(A.mark((function e(t,r,n){var i;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.prevout){e.next=4;break}return e.next=3,Ne(t,n);case 3:t=e.sent;case 4:return e.prev=4,e.next=7,Le(t,r);case 7:return e.abrupt("return",{unblindedUtxo:e.sent});case 11:return e.prev=11,e.t0=e.catch(4),i=new ye(t.txid,t.vout,r),e.abrupt("return",{unblindedUtxo:t,error:i});case 15:case"end":return e.stop()}}),e,null,[[4,11]])})))).apply(this,arguments)}function Le(e,t){return Ue.apply(this,arguments)}function Ue(){return(Ue=d(A.mark((function e(r,n){var i,o;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r.prevout){e.next=2;break}throw new Error("utxo need utxo.prevout to be defined. Use utxoWithPrevout.");case 2:if(S(r.prevout)){e.next=4;break}return e.abrupt("return",r);case 4:return e.next=6,t.confidential.unblindOutputWithKey(r.prevout,Buffer.from(n,"hex"));case 6:return i=e.sent,o=Buffer.alloc(32),i.asset.copy(o),e.abrupt("return",l({},r,{asset:o.reverse().toString("hex"),value:parseInt(i.value,10),unblindData:i}));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function je(e){var r=function(e){if(e.satsPerByte||(e.satsPerByte=.1),e.addFee||(e.addFee=!1),e.addFee&&e.satsPerByte<.1)throw new Error("satsPerByte minimum value is 0.1");if(0===e.recipients.length)throw new Error("need a least one recipient output to build the transaction");if(0===e.unspents.length)throw new Error("need at least one unspent to fund the transaction");return e}(e),n=r.changeAddressByAsset,i=r.coinSelector,o=r.psetBase64,s=r.recipients,a=r.unspents,u=r.addFee,c=r.satsPerByte,p=i(a,s,n),f=p.selectedUtxos,d=p.changeOutputs,l=f;if(!u)return Fe(o,l,s.concat(d));var h=V(o),v=h.data.inputs.length+l.length,y=h.data.outputs.length+s.length+d.length,x=t.address.getNetwork(s[0].address).assetHash,g=Ce(v,y,c,x),b=d.findIndex((function(e){return e.asset===x})),m=-1===b?0-g.value:d[b].value-g.value;if(m>0)return d[b].value=m,Fe(o,l,s.concat(d).concat(g));if(0===m)return Fe(o,l,s.concat(g));for(var P,k=[],A=w(a);!(P=A()).done;){var K=P.value;f.includes(K)||k.push(K)}var E=Ce(v+1,y+1,c,x),I=i(k,[E],n);return Fe(o,l.concat(I.selectedUtxos),s.concat(d).concat(I.changeOutputs).concat(E))}function Ce(e,t,r,n){var i=We(e,t);return{asset:n,value:Math.ceil(i*r),address:""}}function Fe(e,r,n){for(var i,o=V(e),s=Buffer.from("00","hex"),a=w(n);!(i=a()).done;){var u=i.value,c=u.asset,p=u.value,f=u.address,d=""===f?"":t.address.toOutputScript(f);o.addOutput({asset:c,value:p,script:d,nonce:s})}for(var l,h=w(r);!(l=h()).done;){var v=l.value;o.addInput({hash:v.txid,index:v.vout,witnessUtxo:v.prevout})}return o.toBase64()}function We(e,t){return(3*De(!1,e,t,!1)+De(!0,e,t,!0)+3)/4}function De(e,t,r,n){var i=function(e,t){var r=40*t;return e&&(r+=105*t),r}(e,t),o=function(e,t){var r=67*t;return e&&(r+=4273*t),r+43}(n,r);return 9+Re(r)+Re(t)+i+o}function Re(e){return e<253?1:e<=65535?3:e<=4294967295?5:9}var Xe=function(){function e(e,t){this.network=t,this.cache=e}var r=e.prototype;return r.createTx=function(){return new t.Psbt({network:this.network}).toBase64()},r.buildTx=function(e,t,r,n,i,o){return je({psetBase64:e,recipients:t,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:o,unspents:this.cache.getAll()})},e}();function qe(){return(qe=d(A.mark((function e(t,r,n){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Te(t,r);case 2:return e.abrupt("return",He(e.sent,n));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function He(e,t){return new Xe(new Ge(e),D(t))}var Ge=function(){function e(e){this.utxoMap=new Map,e&&this.push(e)}var t=e.prototype;return t.push=function(e){for(var t,r=w(e);!(t=r()).done;){var n=t.value;this.utxoMap.set(F(n),n)}},t.delete=function(e){return this.utxoMap.delete(e)},t.getAll=function(){return Array.from(this.utxoMap.values())},e}();function Ve(e,t){return function(){var r=d(A.mark((function r(n){var i,o,s,a,u,c,p,f,l,h;return A.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=void 0===(i=n.esploraURL)?"https://blockstream.info/liquid/api":i,a=void 0===(s=n.gapLimit)?20:s,c=(u=function(){var e=d(A.mark((function e(t){var r,n,i,s,u;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=0,n=0,i=void 0,s=A.mark((function e(){var s,u,c,p,f;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=n,e.next=3,Promise.all(Array.from(Array(a).keys()).map((function(e){return e+s})).map(t));case 3:return u=e.sent,e.next=6,Promise.all(u.map((function(e){return ze(e,o)})));case 6:c=0,p=w(e.sent);case 9:if((f=p()).done){e.next=22;break}if(!f.value){e.next=16;break}i=c+n,r=0,e.next=19;break;case 16:if(++r!==a){e.next=19;break}return e.abrupt("return",{v:i});case 19:c++;case 20:e.next=9;break;case 22:n+=a;case 23:case"end":return e.stop()}}),e)}));case 4:if(!(r<a)){e.next=11;break}return e.delegateYield(s(),"t0",6);case 6:if("object"!=typeof(u=e.t0)){e.next=9;break}return e.abrupt("return",u.v);case 9:e.next=4;break;case 11:return e.abrupt("return",i);case 12:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())((function(e){return Promise.resolve(t(!1,e))})),p=u((function(e){return Promise.resolve(t(!0,e))})),r.next=6,Promise.all([c,p]);case 6:return l=(f=r.sent)[0],h=f[1],r.abrupt("return",Ze(e)({lastUsedExternalIndex:l,lastUsedInternalIndex:h}));case 10:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()}function ze(e,t){return Ye.apply(this,arguments)}function Ye(){return(Ye=d(A.mark((function e(t,r){return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.get(r+"/address/"+t+"/txs");case 2:return e.abrupt("return",e.sent.data.length>0);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ze(e){return function(){var t=d(A.mark((function t(r){var n,i,o,s,a,u,c;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=r.lastUsedInternalIndex,o=[],void 0!==(n=r.lastUsedExternalIndex))for(s=0;s<=n;s++)a=e.getNextAddress(),o.push(a);if(void 0!==i)for(u=0;u<=i;u++)c=e.getNextChangeAddress(),o.push(c);return t.next=6,Promise.all(o);case 6:return t.abrupt("return",e);case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}Object.defineProperty(exports,"ECPair",{enumerable:!0,get:function(){return t.ECPair}}),Object.defineProperty(exports,"address",{enumerable:!0,get:function(){return t.address}}),Object.defineProperty(exports,"networks",{enumerable:!0,get:function(){return t.networks}}),Object.defineProperty(exports,"payments",{enumerable:!0,get:function(){return t.payments}}),exports.BLOCKSTREAM_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api",exports.BrowserInject=J,exports.BufferMap=N,exports.DEFAULT_BASE_DERIVATION_PATH="m/48'/0'/0'/2'",exports.Identity=z,exports.MasterPublicKey=Y,exports.Mnemonic=Z,exports.Multisig=re,exports.MultisigWatchOnly=te,exports.PrivateKey=$,exports.UtxoCache=Ge,exports.Wallet=Xe,exports.addToTx=Fe,exports.buildTx=je,exports.checkIdentityType=q,exports.checkMasterPublicKey=G,exports.checkMnemonic=H,exports.createFeeOutput=Ce,exports.decodePset=V,exports.esploraTxToTxInterface=de,exports.estimateTxSize=We,exports.fetchAndUnblindTxs=function(e,t,r,n){return be.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=xe,exports.fetchAndUnblindUtxos=Te,exports.fetchAndUnblindUtxosGenerator=Ie,exports.fetchBalances=function(e,t,r){return Ee.apply(this,arguments)},exports.fetchPrevoutAndTryToUnblindUtxo=_e,exports.fetchTx=function(e,t){return ce.apply(this,arguments)},exports.fetchTxHex=ae,exports.fetchUtxos=pe,exports.fromAssetHash=function(e){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(e,"hex").reverse()])},exports.fromXpub=M,exports.getIndexFromAddress=function(e){if(!e.derivationPath)throw new Error("need derivation path to be defined");var t=e.derivationPath.split("/");return parseInt(t[t.length-1])},exports.getNetwork=D,exports.getUnblindURLFromTx=function(e,t){for(var r,n=[],i=function(e){return Buffer.from(e,"hex").reverse().toString("hex")},o=w(e.vout);!(r=o()).done;){var s=r.value;s.script.length>0&&!K(s)&&n.push(l({},s,{assetBlinder:i(s.assetBlinder),valueBlinder:i(s.valueBlinder)}))}return ve(t,e.txid,n)},exports.greedyCoinSelector=function(e){return void 0===e&&(e=ne),function(t,r,n){return function(e,t,r,n){for(var i={selectedUtxos:[],changeOutputs:[]},o=oe(e=e.filter((function(e){return!W(e)})),"asset"),s=oe(t,"asset"),a=0,u=Object.entries(s);a<u.length;a++){var c,p=u[a],f=p[0],d=p[1],l=o[f];if(!l)throw new Error("need unspents for the asset: "+f);var h=ie(l,d.reduce((function(e,t){return e+t.value}),0),n),v=h.changeAmount;if((c=i.selectedUtxos).push.apply(c,h.selected),v>0){var y=r(f);if(!y)throw new Error("need change address for asset: "+f);i.changeOutputs.push({asset:f,value:v,address:y})}}return i}(t,r,n,e)}},exports.isBlindedOutputInterface=K,exports.isBlindedUtxo=W,exports.isConfidentialOutput=S,exports.isValidAmount=function(e){return!(e<=0||!Number.isSafeInteger(e))},exports.isValidExtendedBlindKey=j,exports.isValidXpub=U,exports.makeUnblindURL=ve,exports.masterPubKeyRestorerFromEsplora=function(e){return Ve(e,(function(t,r){return e.getAddress(t,r).address.confidentialAddress}))},exports.masterPubKeyRestorerFromState=function(e){return Ze(e)},exports.mnemonicRestorerFromEsplora=function(e){return Ve(e,(function(t,r){return e.getAddress(t,r).address.confidentialAddress}))},exports.mnemonicRestorerFromState=function(e){return Ze(e)},exports.multisigFromEsplora=function(e){return Ve(e,(function(t,r){return e.getMultisigAddress(t?te.INTERNAL_INDEX:te.EXTERNAL_INDEX,r).confidentialAddress}))},exports.multisigWatchOnlyFromEsplora=function(e){return Ve(e,(function(t,r){return e.getMultisigAddress(t?te.INTERNAL_INDEX:te.EXTERNAL_INDEX,r).confidentialAddress}))},exports.psetToUnsignedHex=C,exports.psetToUnsignedTx=function(e){return t.Transaction.fromHex(C(e))},exports.restorerFromState=Ze,exports.toAssetHash=E,exports.toNumber=I,exports.toOutpoint=F,exports.toXpub=L,exports.unblindOutput=R,exports.unblindTransaction=Pe,exports.unblindUtxo=Le,exports.utxoWithPrevout=Ne,exports.walletFromAddresses=function(e,t,r){return qe.apply(this,arguments)},exports.walletFromCoins=He;
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("liquidjs-lib"),r=require("bip32"),n=require("bip39"),i=t(require("bs58check")),o=require("slip77"),s=t(require("axios"));function a(t){this.wrapped=t}function u(t){var e,r;function n(e,r){try{var o=t[e](r),s=o.value,u=s instanceof a;Promise.resolve(u?s.wrapped:s).then((function(t){u?n("return"===e?"return":"next",t):i(o.done?"return":"normal",t)}),(function(t){n("throw",t)}))}catch(t){i("throw",t)}}function i(t,i){switch(t){case"return":e.resolve({value:i,done:!0});break;case"throw":e.reject(i);break;default:e.resolve({value:i,done:!1})}(e=e.next)?n(e.key,e.arg):r=null}this._invoke=function(t,i){return new Promise((function(o,s){var a={key:t,arg:i,resolve:o,reject:s,next:null};r?r=r.next=a:(e=r=a,n(t,i))}))},"function"!=typeof t.return&&(this.return=void 0)}function c(t){return function(){return new u(t.apply(this,arguments))}}function p(t){return new a(t)}function f(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function d(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){f(o,n,i,s,a,"next",t)}function a(t){f(o,n,i,s,a,"throw",t)}s(void 0)}))}}function l(){return(l=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function h(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,y(t,e)}function v(t){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function y(t,e){return(y=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function x(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function g(t,e,r){return(g=x()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&y(i,r.prototype),i}).apply(null,arguments)}function b(t){var e="function"==typeof Map?new Map:void 0;return(b=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return g(t,arguments,v(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,t)})(t)}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function w(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return m(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?m(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}u.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},u.prototype.next=function(t){return this._invoke("next",t)},u.prototype.throw=function(t){return this._invoke("throw",t)},u.prototype.return=function(t){return this._invoke("return",t)};var P,k,A=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=Object.create((e&&e.prototype instanceof f?e:f).prototype),o=new k(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=m(s,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,o),i}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p={};function f(){}function d(){}function l(){}var h={};a(h,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(A([])));y&&y!==e&&r.call(y,i)&&(h=y);var x=l.prototype=f.prototype=Object.create(h);function g(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(i,o){function s(){return new e((function(n,s){!function n(i,o,s,a){var u=c(t[i],t,o);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,s,a)}),(function(t){n("throw",t,s,a)})):e.resolve(f).then((function(t){p.value=t,s(p)}),(function(t){return n("throw",t,s,a)}))}a(u.arg)}(i,o,n,s)}))}return n=n?n.then(s,s):s()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function A(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:K}}function K(){return{value:void 0,done:!0}}return d.prototype=l,a(x,"constructor",l),a(l,"constructor",d),d.displayName=a(l,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,a(t,s,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},g(b.prototype),a(b.prototype,o,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var s=new b(u(e,r,n,i),o);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},g(x),a(x,s,"Generator"),a(x,i,(function(){return this})),a(x,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=A,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:A(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(k={exports:{}}),k.exports);function K(t){return"surjectionProof"in t&&"rangeProof"in t}function E(t){return t.slice(1).reverse().toString("hex")}function I(t){return e.confidential.confidentialValueToSatoshi(t)}(P=exports.IdentityType||(exports.IdentityType={}))[P.PrivateKey=1]="PrivateKey",P[P.Mnemonic=2]="Mnemonic",P[P.MasterPublicKey=3]="MasterPublicKey",P[P.Inject=4]="Inject",P[P.Ledger=5]="Ledger",P[P.Trezor=6]="Trezor",P[P.MultisigWatchOnly=7]="MultisigWatchOnly",P[P.Multisig=8]="Multisig";var T=Buffer.from("0x00","hex");function B(t){return null!=t&&t.length>0}function S(t){var e=t.surjectionProof,r=t.nonce;return B(t.rangeProof)&&B(e)&&r!==T}var N=function(){function t(){this.map=new Map}var e=t.prototype;return e.bufferToStringPrimitive=function(t){return t.toString("hex").valueOf()},e.get=function(t){return this.map.get(this.bufferToStringPrimitive(t))},e.set=function(t,e){return this.map.set(this.bufferToStringPrimitive(t),e),this},e.values=function(){return Array.from(this.map.values())},t}(),O=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function M(t,e){if(!O.has(e))return"Invalid target version";t=t.trim();try{var r=i.decode(t);return r=r.slice(4),r=Buffer.concat([Buffer.from(O.get(e),"hex"),r]),i.encode(r)}catch(t){throw new Error("Invalid extended public key! Please double check that you didn't accidentally paste extra data.")}}function _(t,e){return M(t,"regtest"===e?"vpub":"zpub")}function L(t){return M(t,"xpub")}function U(t,e){try{r.fromBase58(t,e)}catch(t){return!1}return!0}function j(t){try{o.fromMasterBlindingKey(t)}catch(t){return!1}return!0}function C(t){var r;try{r=e.Psbt.fromBase64(t)}catch(t){throw new Error("Invalid pset")}return r.data.globalMap.unsignedTx.toBuffer().toString("hex")}function F(t){return{txid:t.txid,vout:t.vout}}function R(t){return t?e.networks[t]:e.networks.liquid}function W(t,e){return D.apply(this,arguments)}function D(){return(D=d(A.mark((function t(r,n){var i,o,s,a;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i={asset:r.blindedAsset,value:r.blindedValue,rangeProof:r.rangeProof,surjectionProof:r.surjectionProof,nonce:r.nonce,script:Buffer.from(r.script,"hex")},o=Buffer.from(n,"hex"),t.next=4,e.confidential.unblindOutputWithKey(i,o);case 4:return s=t.sent,a={asset:Buffer.from(s.asset.reverse()).toString("hex"),value:parseInt(s.value,10),script:r.script,assetBlinder:s.assetBlindingFactor.toString("hex"),valueBlinder:s.valueBlindingFactor.toString("hex")},t.abrupt("return",a);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function X(t,e){if(t!==e)throw new Error("Incorrect Identity type: need "+e+" and get "+t+".")}function H(t,e){if(e&&n.setDefaultWordlist(e),!n.validateMnemonic(t))throw new Error("Mnemonic is not valid.")}function q(t){try{r.fromBase58(t)}catch(e){throw new Error("invalid master public key: "+t)}}function G(t){var r;try{r=e.Psbt.fromBase64(t)}catch(t){throw new Error("Invalid pset")}return r}var V=function(){function t(t){if(!t.chain||!e.networks.hasOwnProperty(t.chain))throw new Error("Network is missing or not valid");if(!t.type||!(t.type in exports.IdentityType))throw new Error("Type is missing or not valid");this.network=e.networks[t.chain],this.type=t.type}return t.prototype.blindPsetWithBlindKeysGetter=function(){var t=d(A.mark((function t(r,n,i,o,s){var a,u,c,p,f,d,l,h,v,y,x,g,b,m,P;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=new Map,u=new Map,c=G(n),p=e.Transaction.fromHex(C(n)),f=w(i);case 5:if((d=f()).done){t.next=16;break}if(l=d.value,null==o||!o.has(l)){t.next=11;break}return h=Buffer.from(o.get(l),"hex"),u.set(l,h),t.abrupt("continue",14);case 11:v=r(p.outs[l].script).publicKey,u.set(l,v);case 14:t.next=5;break;case 16:y=0;case 17:if(!(y<c.data.inputs.length)){t.next=43;break}if(g=void 0,!(x=c.data.inputs[y]).witnessUtxo){t.next=24;break}if(S(x.witnessUtxo)){t.next=23;break}return t.abrupt("continue",40);case 23:g=x.witnessUtxo.script;case 24:if(!x.nonWitnessUtxo){t.next=30;break}if(b=p.ins[y].index,S(m=e.Transaction.fromBuffer(x.nonWitnessUtxo).outs[b])){t.next=29;break}return t.abrupt("continue",40);case 29:g=m.script;case 30:if(null==s||!s.has(y)){t.next=33;break}return a.set(y,s.get(y)),t.abrupt("continue",40);case 33:if(g){t.next=35;break}throw new Error("no witness script for input #"+y);case 35:return P=r(g).privateKey,t.next=38,e.confidential.unblindOutputWithKey(x.witnessUtxo,P);case 38:a.set(y,t.sent);case 40:y++,t.next=17;break;case 43:return t.next=45,c.blindOutputsByIndex(a,u);case 45:return t.abrupt("return",t.sent.toBase64());case 47:case"end":return t.stop()}}),t)})));return function(e,r,n,i,o){return t.apply(this,arguments)}}(),t}(),z=function(t){function n(e){var i;(i=t.call(this,e)||this).index=n.INITIAL_INDEX,i.changeIndex=n.INITIAL_INDEX,i.scriptToAddressCache={};var s=L(e.opts.masterPublicKey);if(X(e.type,exports.IdentityType.MasterPublicKey),!U(s))throw new Error("Master public key is not valid");if(!j(e.opts.masterBlindingKey))throw new Error("Master blinding key is not valid");return i.masterPublicKeyNode=r.fromBase58(s),i.masterBlindingKeyNode=o.fromMasterBlindingKey(e.opts.masterBlindingKey),i.baseDerivationPath=e.opts.baseDerivationPath||n.INITIAL_BASE_PATH,i}h(n,t);var i=n.prototype;return i.blindPset=function(){var e=d(A.mark((function e(r,n,i,o){var s=this;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.prototype.blindPsetWithBlindKeysGetter.call(this,(function(t){return s.getBlindingKeyPair(t.toString("hex"),!0)}),r,n,i,o));case 1:case"end":return e.stop()}}),e,this)})));return function(t,r,n,i){return e.apply(this,arguments)}}(),i.isAbleToSign=function(){return!1},i.derivePublicKeyWithIndex=function(t,e){return this.masterPublicKeyNode.derive(t?1:0).derive(e).publicKey},i.getBlindingKeyPair=function(t,e){if(void 0===e&&(e=!1),e&&!this.scriptToAddressCache[t])throw new Error("unknow blinding key for script "+t);var r=this.masterBlindingKeyNode.derive(t);return{publicKey:r.publicKey,privateKey:r.privateKey}},i.scriptFromPublicKey=function(t){return e.payments.p2wpkh({pubkey:t,network:this.network}).output.toString("hex")},i.createConfidentialAddress=function(t,r){return e.payments.p2wpkh({pubkey:t,blindkey:r,network:this.network}).confidentialAddress},i.persistAddressToCache=function(t){var e=Buffer.from(t.publicKey,"hex"),r=this.scriptFromPublicKey(e);this.scriptToAddressCache[r]=t},i.getAddress=function(t,e){var r=this.derivePublicKeyWithIndex(t,e),n=this.scriptFromPublicKey(r),i=this.getBlindingKeyPair(n),o=this.createConfidentialAddress(r,i.publicKey),s=this.baseDerivationPath+"/"+(t?1:0)+"/"+e;return{address:{confidentialAddress:o,blindingPrivateKey:i.privateKey.toString("hex"),derivationPath:s},publicKey:r.toString("hex")}},i.getNextAddress=function(){var t=d(A.mark((function t(){var e;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getAddress(!1,this.index),this.persistAddressToCache(e),this.index=this.index+1,t.abrupt("return",e.address);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),i.getNextChangeAddress=function(){var t=d(A.mark((function t(){var e;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getAddress(!0,this.changeIndex),this.persistAddressToCache(e),this.changeIndex=this.changeIndex+1,t.abrupt("return",e.address);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),i.getBlindingPrivateKey=function(){var t=d(A.mark((function t(e){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getBlindingKeyPair(e).privateKey.toString("hex"));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.signPset=function(t){throw new Error("MasterPublicKey is a watch only identity. Use Mnemonic to sign transactions")},i.getAddresses=function(){var t=d(A.mark((function t(){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Object.values(this.scriptToAddressCache).map((function(t){return t.address})));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),i.getXPub=function(){return this.masterPublicKeyNode.toBase58()},n}(V);z.INITIAL_BASE_PATH="m/84'/0'/0'",z.INITIAL_INDEX=0;var Y=function(t){function i(i){var s;X(i.type,exports.IdentityType.Mnemonic),n.setDefaultWordlist(i.opts.language||"english"),H(i.opts.mnemonic);var a=n.mnemonicToSeedSync(i.opts.mnemonic),u=r.fromSeed(a,e.networks[i.chain]),c=u.derivePath(z.INITIAL_BASE_PATH),p=_(e.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58(),i.chain),f=o.fromSeed(a),d=f.masterKey.toString("hex");return(s=t.call(this,l({},i,{type:exports.IdentityType.MasterPublicKey,opts:{masterPublicKey:p,masterBlindingKey:d,baseDerivationPath:i.opts.baseDerivationPath}}))||this).masterBlindingKey=d,s.masterBlindingKeyNode=f,s.masterPublicKey=p,s.masterPrivateKeyNode=u,s.mnemonic=i.opts.mnemonic,s}h(i,t);var s=i.prototype;return s.blindPset=function(){var e=d(A.mark((function e(r,n,i,o){var s=this;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return t.prototype.getBlindingKeyPair.call(s,e.toString("hex"),!0)}),r,n,i,o));case 1:case"end":return e.stop()}}),e,this)})));return function(t,r,n,i){return e.apply(this,arguments)}}(),s.isAbleToSign=function(){return!0},s.derivePath=function(t){var r=this.masterPrivateKeyNode.derivePath(t).toWIF(),n=e.ECPair.fromWIF(r,this.network);return{publicKey:n.publicKey,privateKey:n.privateKey}},s.signPset=function(){var t=d(A.mark((function t(r){var n,i,o,s,a,u,c;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(n=e.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo&&(a=this.scriptToAddressCache[s.witnessUtxo.script.toString("hex")])&&(u=this.derivePath(a.address.derivationPath).privateKey,c=e.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c)));return t.next=5,Promise.all(i);case 5:return t.abrupt("return",n.toBase64());case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.Random=function(t,e){var r=n.generateMnemonic();return new i({chain:t,type:exports.IdentityType.Mnemonic,opts:{mnemonic:r,baseDerivationPath:e}})},i}(z),Z=function(t){function r(r){var n;n=t.call(this,r)||this,X(r.type,exports.IdentityType.PrivateKey),n.signingKeyPair=n.decodeFromWif(r.opts.signingKeyWIF),n.blindingKeyPair=n.decodeFromWif(r.opts.blindingKeyWIF);var i=e.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=i.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=i.output,n}h(r,t);var n=r.prototype;return n.blindPset=function(){var e=d(A.mark((function e(r,n,i,o){var s=this;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.prototype.blindPsetWithBlindKeysGetter.call(this,(function(t){return s.getBlindingKeyPair(t)}),r,n,i,o));case 1:case"end":return e.stop()}}),e,this)})));return function(t,r,n,i){return e.apply(this,arguments)}}(),n.getBlindingKeyPair=function(t){if(!t.equals(this.scriptPubKey))throw new Error(t+" is unknown by the PrivateKey Identity");return{publicKey:this.blindingKeyPair.publicKey,privateKey:this.blindingKeyPair.privateKey}},n.isAbleToSign=function(){return!0},n.decodeFromWif=function(t){return e.ECPair.fromWIF(t,this.network)},n.getAddress=function(){return{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey,derivationPath:void 0}},n.getNextAddress=function(){var t=d(A.mark((function t(){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAddress());case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getNextChangeAddress=function(){var t=d(A.mark((function t(){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAddress());case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getBlindingPrivateKey=function(){var t=d(A.mark((function t(e){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Buffer.from(e,"hex").equals(this.scriptPubKey)){t.next=3;break}throw new Error("The script is not PrivateKey.scriptPubKey.");case 3:return t.abrupt("return",this.blindingPrivateKey);case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.signPset=function(){var t=d(A.mark((function t(r){var n,i,o,s,a=this;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(n=e.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo?s.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(o):i.push(o);return t.next=5,Promise.all(i.map((function(t){return n.signInputAsync(t,a.signingKeyPair)})));case 5:return t.abrupt("return",n.toBase64());case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getAddresses=function(){var t=d(A.mark((function t(){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",[{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey,derivationPath:void 0}]);case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r}(V),$=function(t){function e(e){var r;if(r=t.call(this,e)||this,X(e.type,exports.IdentityType.Inject),void 0===window||void 0===window[e.opts.windowProvider])throw new Error("The value.windowProvider of IdentityOpts is not valid or the script is to injected in the window");return r.provider=window[e.opts.windowProvider],r}h(e,t);var r=e.prototype;return r.getNextAddress=function(){return this.provider.getNextAddress()},r.getNextChangeAddress=function(){return this.provider.getNextChangeAddress()},r.signPset=function(t){return this.provider.signTransaction(t)},r.getAddresses=function(){return this.provider.getAddresses()},r.getBlindingPrivateKey=function(t){throw new Error("Method not implemented.")},r.isAbleToSign=function(){return!0},r.blindPset=function(t,e,r,n){throw new Error("Method not implemented.")},e}(V);function J(t,e){if(t.length!==e.length)throw new Error("a.length !== b.length (xor)");for(var r=Buffer.alloc(t.length),n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Q(t){return t.sort(tt)}function tt(t,e){return t.toString("hex")<e.toString("hex")?-1:1}var et=function(t){function i(i){var s;(s=t.call(this,i)||this).nextIndex=0,s.nextChangeIndex=0,X(i.type,exports.IdentityType.MultisigWatchOnly),function(t,e){if(t<=0||t>e)throw new Error("number of required signatures must be > 0 and <= "+e)}(i.opts.requiredSignatures,i.opts.cosigners.length);var a,u=i.opts.cosigners.map((function(t){return function(t,e){if("string"==typeof t)return t;var i=n.mnemonicToSeedSync(t.mnemonic),o=r.fromSeed(i,e).derivePath(t.baseDerivationPath||"m/48'/0'/0'/2'");return L(r.fromPublicKey(o.publicKey,o.chainCode,e).toBase58())}(t,s.network)}));return u.forEach(q),s.cosigners=u.sort().map((function(t){return r.fromBase58(t)})),s.blindingKeyMasterNode=(a=function(t){for(var r,n=Buffer.from("blinding_key"),i=Buffer.alloc(32),o=w(t);!(r=o()).done;)i=J(i,r.value);return e.crypto.sha256(Buffer.concat([n,i]))}(s.cosigners.map((function(t){return t.chainCode}))),o.fromSeed(a)),s.requiredSignatures=i.opts.requiredSignatures,s}h(i,t);var s=i.prototype;return s.getNextAddress=function(){var t=this.getMultisigAddress(i.EXTERNAL_INDEX,this.nextIndex);return this.nextIndex++,Promise.resolve(t)},s.getNextChangeAddress=function(){var t=this.getMultisigAddress(i.INTERNAL_INDEX,this.nextChangeIndex);return this.nextChangeIndex++,Promise.resolve(t)},s.getAddresses=function(){var t=this,e=Array.from(Array(this.nextIndex).keys()).map((function(e){return t.getMultisigAddress(i.EXTERNAL_INDEX,e)})),r=Array.from(Array(this.nextChangeIndex).keys()).map((function(e){return t.getMultisigAddress(i.INTERNAL_INDEX,e)}));return Promise.resolve(e.concat(r))},s.getBlindingPrivateKey=function(t){var e=this.getBlindingKeyPair(t).privateKey;return Promise.resolve(e.toString("hex"))},s.getBlindingKeyPair=function(t){var e=this.blindingKeyMasterNode.derive(t);if(!e.publicKey||!e.privateKey)throw new Error("unable to generate blinding key pair");return{publicKey:e.publicKey,privateKey:e.privateKey}},s.isAbleToSign=function(){return!1},s.signPset=function(t){throw new Error("WatchOnly Multisig Identity is not able to sign pset")},s.blindPset=function(e,r,n,i){var o=this;return t.prototype.blindPsetWithBlindKeysGetter.call(this,(function(t){return o.getBlindingKeyPair(t.toString("hex"))}),e,r,n,i)},s.getMultisigAddress=function(t,r){return l({},function(t,r,n,i){var o=e.payments.p2wsh({redeem:e.payments.p2ms({m:parseInt(n.toString()),pubkeys:Q(t.map((function(t){return t.publicKey}))),network:i}),network:i});if(!o.address)throw new Error("Invalid payment");var s=r.derive(e.address.toOutputScript(o.address,i)),a=s.publicKey,u=s.privateKey;if(!a||!u)throw new Error("something went wrong while generating blinding key pair");if(!(o=e.payments.p2wsh({redeem:e.payments.p2ms({m:parseInt(n.toString()),pubkeys:Q(t.map((function(t){return t.publicKey}))),network:i}),blindkey:a,network:i})).confidentialAddress||!o.redeem||!o.redeem.output)throw new Error("invalid payment");return{blindingPrivateKey:u.toString("hex"),confidentialAddress:o.confidentialAddress,witnessScript:o.redeem.output.toString("hex")}}(this.cosigners.map((function(e){return e.derive(t).derive(r)})),this.blindingKeyMasterNode,this.requiredSignatures,this.network),{derivationPath:t+"/"+r})},i}(V);et.EXTERNAL_INDEX=0,et.INTERNAL_INDEX=1;var rt=function(t){function i(i){var o;X(i.type,exports.IdentityType.Multisig),H(i.opts.signer.mnemonic);var s=n.mnemonicToSeedSync(i.opts.signer.mnemonic),a=r.fromSeed(s,e.networks[i.chain]).derivePath(i.opts.signer.baseDerivationPath||"m/48'/0'/0'/2'");return(o=t.call(this,l({},i,{opts:l({},i.opts,{cosigners:i.opts.cosigners.concat([i.opts.signer])}),type:exports.IdentityType.MultisigWatchOnly}))||this).baseDerivationPath=i.opts.signer.baseDerivationPath||"m/48'/0'/0'/2'",o.baseNode=a,o.scriptToPath={},o}h(i,t);var o=i.prototype;return o.getNextAddress=function(){var e=d(A.mark((function e(){var r;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.prototype.getNextAddress.call(this);case 2:if((r=e.sent).derivationPath){e.next=5;break}throw new Error("need derivation path to cache addresses");case 5:return this.scriptToPath[this.toScript(r.confidentialAddress)]=r.derivationPath,e.abrupt("return",r);case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.getNextChangeAddress=function(){var e=d(A.mark((function e(){var r;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.prototype.getNextChangeAddress.call(this);case 2:if((r=e.sent).derivationPath){e.next=5;break}throw new Error("need derivation path to cache addresses");case 5:return this.scriptToPath[this.toScript(r.confidentialAddress)]=r.derivationPath,e.abrupt("return",r);case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.isAbleToSign=function(){return!0},o.signPset=function(){var t=d(A.mark((function t(r){var n,i,o,s,a,u,c;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=e.Psbt.fromBase64(r),i=[],o=0;case 3:if(!(o<n.data.inputs.length)){t.next=16;break}if(!(s=n.data.inputs[o]).witnessUtxo){t.next=13;break}if(!(a=this.scriptToPath[s.witnessUtxo.script.toString("hex")])){t.next=13;break}if(u=this.baseNode.derivePath(a).privateKey){t.next=11;break}throw new Error("signing private key is undefined");case 11:c=e.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c));case 13:o++,t.next=3;break;case 16:return t.next=18,Promise.all(i);case 18:return t.abrupt("return",n.toBase64());case 19:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),o.getXPub=function(){return L(r.fromPublicKey(this.baseNode.publicKey,this.baseNode.chainCode,this.network).toBase58())},o.toScript=function(t){return e.address.toOutputScript(t,this.network).toString("hex")},i}(et),nt=function(t,e,r){throw new Error("not enought funds to fill "+e+"sats of "+t+" (amount selected: "+r+")")};function it(t,e){return t.set(e.asset,(t.get(e.asset)||0)+e.value),t}var ot=function(t){return function(e){var r=e.asset;return r&&r===t}},st=function(t){return function(e){var r=e.map((function(t){return{value:t.value||0,asset:t.asset||""}}));return at(r)(t)}},at=function(t){return function(e){var r=function(t){return t.reduce((function(t,e){return(t[e.asset]=t[e.asset]||[]).push(e),t}),{})},n=r(t),i=r(e),o=Object.keys(n).sort(),s=Object.keys(i).sort();if(!o.every((function(t){return s.includes(t)})))throw new Error("inputs and outputs don't have the same assets. Inputs assets = "+o+", Outputs assets = "+s);for(var a in n){var u=ut(n[a].map((function(t){return t.value}))),c=ut(i[a].map((function(t){return t.value})));if(u!==c)throw new Error("missing funds for asset "+a+" (inputs: "+u+", outputs: "+c+")")}}},ut=function(t){return t.reduce((function(t,e){return t+e}),0)},ct=function(t,e){return t.value-e.value},pt=Buffer.alloc(32).toString("hex");function ft(t,e){return dt.apply(this,arguments)}function dt(){return(dt=d(A.mark((function t(e,r){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.get(r+"/tx/"+e+"/hex");case 2:return t.abrupt("return",t.sent.data);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function lt(){return(lt=d(A.mark((function t(e,r){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=yt,t.next=3,s.get(r+"/tx/"+e);case 3:return t.t1=t.sent.data,t.t2=r,t.abrupt("return",(0,t.t0)(t.t1,t.t2));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ht(t,e){return vt.apply(this,arguments)}function vt(){return(vt=d(A.mark((function t(e,r){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.get(r+"/address/"+e+"/utxo");case 2:return t.abrupt("return",t.sent.data);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function yt(t,e){return xt.apply(this,arguments)}function xt(){return(xt=d(A.mark((function t(r,n){var i,o,s,a,u,c,p,f,d;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(i=[],o=[],s=w(r.vin);!(a=s()).done;)i.push((u=a.value).txid),o.push(u.vout);return t.next=5,Promise.all(i.map((function(t,e){return r.vin[e].is_pegin?Promise.resolve(void 0):ft(t,n)})));case 5:return c=t.sent.map((function(t,r){if(t)return gt(e.Transaction.fromHex(t).outs[o[r]])})),p=i.map((function(t,e){return{prevout:c[e],txid:t,vout:o[e],isPegin:r.vin[e].is_pegin}})),t.next=10,ft(r.txid,n);case 10:return f=e.Transaction.fromHex(t.sent),d=f.outs.map(gt),t.abrupt("return",{txid:r.txid,vin:p,vout:d,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 15:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function gt(t){return S(t)?{blindedAsset:t.asset,blindedValue:t.value,nonce:t.nonce,rangeProof:t.rangeProof,surjectionProof:t.surjectionProof,script:t.script.toString("hex")}:{asset:E(t.asset),value:I(t.value),script:t.script.toString("hex"),assetBlinder:pt,valueBlinder:pt}}function bt(t,e,r){return t+"/tx/"+e+"#blinded="+r.map((function(t){return t.value+","+t.asset+","+t.valueBlinder+","+t.assetBlinder})).join(",")}var mt=function(t){function e(e,r,n){return t.call(this,"UnblindError output ("+e+":"+r+") with blind key "+n)||this}return h(e,t),e}(b(Error));function wt(t,e,r,n){return Pt.apply(this,arguments)}function Pt(){return(Pt=c(A.mark((function t(e,r,n,i){var o,s,a,u,c,f,d,l,h,v;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=[],s=[],a=w(e);case 3:if((u=a()).done){t.next=40;break}return c=u.value,t.prev=5,f=At(c,n,i),t.next=9,p(f.next());case 9:d=t.sent;case 10:if(d.done){t.next=31;break}if(!o.includes((l=d.value).txid)){t.next=17;break}return t.next=15,p(f.next());case 15:return d=t.sent,t.abrupt("continue",10);case 17:return t.next=19,p(Et(l,r));case 19:return v=(h=t.sent).unblindedTx,s.push.apply(s,h.errors),t.next=25,v;case 25:return o.push(l.txid),t.next=28,p(f.next());case 28:d=t.sent,t.next=10;break;case 31:t.next=38;break;case 33:t.prev=33,t.t0=t.catch(5),t.t0 instanceof Error&&s.push(t.t0),"string"==typeof t.t0&&s.push(new Error(t.t0)),s.push(new Error("unknown error"));case 38:t.next=3;break;case 40:return t.abrupt("return",{txIDs:o,errors:s});case 41:case"end":return t.stop()}}),t,null,[[5,33]])})))).apply(this,arguments)}function kt(){return(kt=d(A.mark((function t(e,r,n,i){var o,s,a;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=wt(e,r,n,i),s=[],t.next=4,o.next();case 4:a=t.sent;case 5:if(a.done){t.next=12;break}return s.push(a.value),t.next=9,o.next();case 9:a=t.sent,t.next=5;break;case 12:return t.abrupt("return",s);case 13:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function At(t,e,r){return Kt.apply(this,arguments)}function Kt(){return(Kt=c(A.mark((function t(e,r,n){var i,o,s,a,u,c,f,d;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=void 0,o=[],s=0;case 3:return t.next=5,p(Tt(e,r,i));case 5:if(0!==(o=t.sent).length){t.next=8;break}return t.abrupt("break",24);case 8:i=o[o.length-1].txid,s+=o.length,a=o.map((function(t){return yt(t,r)})),u=w(a);case 12:if((c=u()).done){t.next=23;break}return f=c.value,t.next=16,p(f);case 16:if(d=t.sent,null==n||!n(d)){t.next=19;break}return t.abrupt("continue",21);case 19:return t.next=21,d;case 21:t.next=12;break;case 23:if(i){t.next=3;break}case 24:return t.abrupt("return",s);case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Et(t,e){return It.apply(this,arguments)}function It(){return(It=d(A.mark((function t(e,r){var n,i,o,s,a,u;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(n=[],i=[],o=function(t){var o=e.vin[t].prevout;o&&K(o)&&n.push(function(){var n=d(A.mark((function n(){var s;return A.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.script))){n.next=12;break}return n.prev=2,n.next=5,W(o,s);case 5:e.vin[t].prevout=n.sent,n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i.push(new mt(e.vin[t].txid,e.vin[t].vout,s));case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(){return n.apply(this,arguments)}}()())},s=0;s<e.vin.length;s++)o(s);for(a=function(t){var o=e.vout[t];K(o)&&n.push(function(){var n=d(A.mark((function n(){var s;return A.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.script))){n.next=12;break}return n.prev=2,n.next=5,W(o,s);case 5:e.vout[t]=n.sent,n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i.push(new mt(e.txid,t,s));case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(){return n.apply(this,arguments)}}()())},u=0;u<e.vout.length;u++)a(u);return t.next=8,Promise.all(n);case 8:return t.abrupt("return",{unblindedTx:e,errors:i});case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Tt(t,e,r){return Bt.apply(this,arguments)}function Bt(){return(Bt=d(A.mark((function t(e,r,n){var i;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=r+"/address/"+e+"/txs/chain",n&&(i+="/"+n),t.next=4,s.get(i);case 4:return t.abrupt("return",t.sent.data);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function St(){return(St=d(A.mark((function t(e,r,n){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Mt([{confidentialAddress:e,blindingPrivateKey:r}],n);case 2:return t.abrupt("return",t.sent.reduce((function(t,e){var r=e.asset;return t[r]=t[r]||0,t[r]+=e.value,t}),{}));case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Nt(t,e,r){return Ot.apply(this,arguments)}function Ot(){return(Ot=c(A.mark((function t(r,n,i){var o,s,a,u,c,f,d,l,h,v,y,x,g,b,m;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=0,s=[],a=w(r);case 3:if((u=a()).done){t.next=41;break}if(f=(c=u.value).confidentialAddress,d=c.blindingPrivateKey,t.prev=5,!(d.length>0)){t.next=11;break}if(l=e.ECPair.fromPrivateKey(Buffer.from(d,"hex")),h=e.address.fromConfidential(f).blindingKey,l.publicKey.equals(h)){t.next=11;break}throw new Error("wrong blinding private key");case 11:return t.next=13,p(ht(f,n));case 13:v=w(t.sent);case 15:if((y=v()).done){t.next=32;break}if(x=y.value,null==i||!i(x)){t.next=21;break}return t.next=20,x;case 20:return t.abrupt("continue",30);case 21:return t.next=23,p(jt(x,d,n));case 23:return b=(g=t.sent).unblindedUtxo,(m=g.error)&&s.push(m),t.next=29,b;case 29:o++;case 30:t.next=15;break;case 32:t.next=39;break;case 34:t.prev=34,t.t0=t.catch(5),t.t0 instanceof Error&&s.push(t.t0),"string"==typeof t.t0&&s.push(new Error(t.t0)),s.push(new Error("unknow error"));case 39:t.next=3;break;case 41:return t.abrupt("return",{numberOfUtxos:o,errors:s});case 42:case"end":return t.stop()}}),t,null,[[5,34]])})))).apply(this,arguments)}function Mt(t,e,r){return _t.apply(this,arguments)}function _t(){return(_t=d(A.mark((function t(e,r,n){var i,o,s;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=Nt(e,r,n),o=[],t.next=4,i.next();case 4:s=t.sent;case 5:if(s.done){t.next=12;break}return o.push(s.value),t.next=9,i.next();case 9:s=t.sent,t.next=5;break;case 12:return t.abrupt("return",o);case 13:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lt(t,e){return Ut.apply(this,arguments)}function Ut(){return(Ut=d(A.mark((function t(r,n){var i;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ft(r.txid,n);case 2:return i=e.Transaction.fromHex(t.sent).outs[r.vout],t.abrupt("return",l({},r,{prevout:i}));case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function jt(t,e,r){return Ct.apply(this,arguments)}function Ct(){return(Ct=d(A.mark((function t(e,r,n){var i;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.prevout){t.next=4;break}return t.next=3,Lt(e,n);case 3:e=t.sent;case 4:return t.prev=4,t.next=7,Ft(e,r);case 7:return t.abrupt("return",{unblindedUtxo:t.sent});case 11:return t.prev=11,t.t0=t.catch(4),i=new mt(e.txid,e.vout,r),t.abrupt("return",{unblindedUtxo:e,error:i});case 15:case"end":return t.stop()}}),t,null,[[4,11]])})))).apply(this,arguments)}function Ft(t,e){return Rt.apply(this,arguments)}function Rt(){return(Rt=d(A.mark((function t(r,n){var i,o;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r.prevout){t.next=2;break}throw new Error("utxo need utxo.prevout to be defined. Use utxoWithPrevout.");case 2:if(S(r.prevout)){t.next=4;break}return t.abrupt("return",r);case 4:return t.next=6,e.confidential.unblindOutputWithKey(r.prevout,Buffer.from(n,"hex"));case 6:return i=t.sent,o=Buffer.alloc(32),i.asset.copy(o),t.abrupt("return",l({},r,{asset:o.reverse().toString("hex"),value:parseInt(i.value,10),unblindData:i}));case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Wt(t,r,n,i,o,s){void 0===o&&(o=!1),void 0===s&&(s=Dt);var a=e.address.getNetwork(r.address),u=o&&r.asset===a.assetHash,c=Ht(n(nt)(t,[r],(function(){return i})).selectedUtxos.length,2,s,a.assetHash),p=nt;u&&(p=function(t,e,n){t!==r.asset?nt(t,e,n):r.value=n-c.value});var f=n(p)(t,[r,c],(function(){return i})),d=f.selectedUtxos,l=[r].concat(f.changeOutputs,[c]);return st(l)(d),qt(new e.Psbt({network:a}).toBase64(),d,l)}var Dt=.1;function Xt(t){var r=function(t){if(t.satsPerByte||(t.satsPerByte=Dt),t.errorHandler||(t.errorHandler=nt),t.addFee||(t.addFee=!1),t.addFee&&t.satsPerByte<.1)throw new Error("satsPerByte minimum value is 0.1");if(0===t.recipients.length)throw new Error("need a least one recipient output to build the transaction");if(0===t.unspents.length)throw new Error("need at least one unspent to fund the transaction");return t}(t),n=r.changeAddressByAsset,i=r.coinSelector,o=r.psetBase64,s=r.recipients,a=r.unspents,u=r.addFee,c=r.satsPerByte,p=r.errorHandler,f=i(p)(a,s,n);if(!u){var d=s.concat(f.changeOutputs);return st(d)(f.selectedUtxos),qt(o,f.selectedUtxos,d)}var l=function(t,r,n,i){var o=G(t);return Ht(o.data.inputs.length+r.selectedUtxos.length+1,o.data.outputs.length+n.length+r.changeOutputs.length+1,i,e.address.getNetwork(n[0].address).assetHash)}(o,f,s,c),h=i(p)(a,[].concat(s,[l]),n),v=h.selectedUtxos,y=[].concat(s,h.changeOutputs,[l]);return st(y)(v),qt(o,v,y)}function Ht(t,e,r,n){var i=Gt(t,e);return{asset:n,value:Math.ceil(i*r),address:""}}function qt(t,r,n){for(var i,o=G(t),s=Buffer.from("00","hex"),a=w(n);!(i=a()).done;){var u=i.value,c=u.asset,p=u.value,f=u.address,d=""===f?"":e.address.toOutputScript(f);o.addOutput({asset:c,value:p,script:d,nonce:s})}for(var l,h=w(r);!(l=h()).done;){var v=l.value;o.addInput({hash:v.txid,index:v.vout,witnessUtxo:v.prevout})}return o.toBase64()}function Gt(t,e){return(3*Vt(!1,t,e,!1)+Vt(!0,t,e,!0)+3)/4}function Vt(t,e,r,n){var i=function(t,e){var r=40*e;return t&&(r+=105*e),r}(t,e),o=function(t,e){var r=67*e;return t&&(r+=4273*e),r+43}(n,r);return 9+zt(r)+zt(e)+i+o}function zt(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}var Yt=function(){function t(t,e){this.network=e,this.cache=t}var r=t.prototype;return r.createTx=function(){return new e.Psbt({network:this.network}).toBase64()},r.buildTx=function(t,e,r,n,i,o){return Xt({psetBase64:t,recipients:e,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:o,unspents:this.cache.getAll()})},r.sendTx=function(t,e,r,n,i){return void 0===n&&(n=!1),void 0===i&&(i=Dt),Wt(this.cache.getAll(),t,e,r,n,i)},t}();function Zt(){return(Zt=d(A.mark((function t(e,r,n){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Mt(e,r);case 2:return t.abrupt("return",$t(t.sent,n));case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $t(t,e){return new Yt(new Jt(t),R(e))}var Jt=function(){function t(t){this.utxoMap=new Map,t&&this.push(t)}var e=t.prototype;return e.push=function(t){for(var e,r=w(t);!(e=r()).done;){var n=e.value;this.utxoMap.set(F(n),n)}},e.delete=function(t){return this.utxoMap.delete(t)},e.getAll=function(){return Array.from(this.utxoMap.values())},t}();function Qt(t,e){return function(){var r=d(A.mark((function r(n){var i,o,s,a,u,c,p,f,l,h;return A.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=void 0===(i=n.esploraURL)?"https://blockstream.info/liquid/api":i,a=void 0===(s=n.gapLimit)?20:s,c=(u=function(){var t=d(A.mark((function t(e){var r,n,i,s,u;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=0,n=0,i=void 0,s=A.mark((function t(){var s,u,c,p,f;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=n,t.next=3,Promise.all(Array.from(Array(a).keys()).map((function(t){return t+s})).map(e));case 3:return u=t.sent,t.next=6,Promise.all(u.map((function(t){return te(t,o)})));case 6:c=0,p=w(t.sent);case 9:if((f=p()).done){t.next=22;break}if(!f.value){t.next=16;break}i=c+n,r=0,t.next=19;break;case 16:if(++r!==a){t.next=19;break}return t.abrupt("return",{v:i});case 19:c++;case 20:t.next=9;break;case 22:n+=a;case 23:case"end":return t.stop()}}),t)}));case 4:if(!(r<a)){t.next=11;break}return t.delegateYield(s(),"t0",6);case 6:if("object"!=typeof(u=t.t0)){t.next=9;break}return t.abrupt("return",u.v);case 9:t.next=4;break;case 11:return t.abrupt("return",i);case 12:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())((function(t){return Promise.resolve(e(!1,t))})),p=u((function(t){return Promise.resolve(e(!0,t))})),r.next=6,Promise.all([c,p]);case 6:return l=(f=r.sent)[0],h=f[1],r.abrupt("return",re(t)({lastUsedExternalIndex:l,lastUsedInternalIndex:h}));case 10:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()}function te(t,e){return ee.apply(this,arguments)}function ee(){return(ee=d(A.mark((function t(e,r){return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.get(r+"/address/"+e+"/txs");case 2:return t.abrupt("return",t.sent.data.length>0);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function re(t){return function(){var e=d(A.mark((function e(r){var n,i,o,s,a,u,c;return A.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=r.lastUsedInternalIndex,o=[],void 0!==(n=r.lastUsedExternalIndex))for(s=0;s<=n;s++)a=t.getNextAddress(),o.push(a);if(void 0!==i)for(u=0;u<=i;u++)c=t.getNextChangeAddress(),o.push(c);return e.next=6,Promise.all(o);case 6:return e.abrupt("return",t);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()}Object.defineProperty(exports,"ECPair",{enumerable:!0,get:function(){return e.ECPair}}),Object.defineProperty(exports,"address",{enumerable:!0,get:function(){return e.address}}),Object.defineProperty(exports,"networks",{enumerable:!0,get:function(){return e.networks}}),Object.defineProperty(exports,"payments",{enumerable:!0,get:function(){return e.payments}}),exports.BLOCKSTREAM_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api",exports.BrowserInject=$,exports.BufferMap=N,exports.DEFAULT_BASE_DERIVATION_PATH="m/48'/0'/0'/2'",exports.DEFAULT_SATS_PER_BYTE=Dt,exports.Identity=V,exports.MasterPublicKey=z,exports.Mnemonic=Y,exports.Multisig=rt,exports.MultisigWatchOnly=et,exports.PrivateKey=Z,exports.UtxoCache=Jt,exports.Wallet=Yt,exports.addToTx=qt,exports.checkIdentityType=X,exports.checkMasterPublicKey=q,exports.checkMnemonic=H,exports.craftMultipleRecipientsPset=Xt,exports.craftSingleRecipientPset=Wt,exports.createFeeOutput=Ht,exports.decodePset=G,exports.esploraTxToTxInterface=yt,exports.estimateTxSize=Gt,exports.fetchAndUnblindTxs=function(t,e,r,n){return kt.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=wt,exports.fetchAndUnblindUtxos=Mt,exports.fetchAndUnblindUtxosGenerator=Nt,exports.fetchBalances=function(t,e,r){return St.apply(this,arguments)},exports.fetchPrevoutAndTryToUnblindUtxo=jt,exports.fetchTx=function(t,e){return lt.apply(this,arguments)},exports.fetchTxHex=ft,exports.fetchUtxos=ht,exports.fromAssetHash=function(t){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(t,"hex").reverse()])},exports.fromXpub=_,exports.getIndexFromAddress=function(t){if(!t.derivationPath)throw new Error("need derivation path to be defined");var e=t.derivationPath.split("/");return parseInt(e[e.length-1])},exports.getNetwork=R,exports.getUnblindURLFromTx=function(t,e){for(var r,n=[],i=function(t){return Buffer.from(t,"hex").reverse().toString("hex")},o=w(t.vout);!(r=o()).done;){var s=r.value;s.script.length>0&&!K(s)&&n.push(l({},s,{assetBlinder:i(s.assetBlinder),valueBlinder:i(s.valueBlinder)}))}return bt(e,t.txid,n)},exports.greedyCoinSelector=function(t){return void 0===t&&(t=ct),function(e){void 0===e&&(e=nt);var r,n=(r=t,function(t){return function(e){return function(n){var i=[],o=function(t){return function(e){return function(r){return function(n){return function(i){var o=0,s=i.filter(ot(r)).sort(t).reduce((function(t,e){return o<=n&&e.value&&(t.push(e),o+=e.value),t}),[]);return o<n&&e(r,n,o),s}}}}}(r)(t);return n.forEach((function(t,e){i.push(o(e)(t))})),i.flatMap((function(t){return t(e)}))}}})(e);return function(t,e,r){var i=function(t){return function(e){return function(r){var n=[];return e.forEach((function(e,i){var o,s=(o=r,function(t){var e=function(t){return function(e){return e.filter(ot(t)).reduce((function(t,e){return e.value?t+e.value:t}),0)}}(t)(o);return function(t){return e-t}})(i)(e);s>0&&n.push({address:t(i),asset:i,value:s})})),n}}}(r),o=function(t){return t.reduce(it,new Map)}(e),s=n(t)(o);return{selectedUtxos:s,changeOutputs:i(o)(s)}}}},exports.isBlindedOutputInterface=K,exports.isBlindedUtxo=function(t){return!t.asset||!t.value},exports.isConfidentialOutput=S,exports.isValidAmount=function(t){return!(t<=0||!Number.isSafeInteger(t))},exports.isValidExtendedBlindKey=j,exports.isValidXpub=U,exports.makeUnblindURL=bt,exports.masterPubKeyRestorerFromEsplora=function(t){return Qt(t,(function(e,r){return t.getAddress(e,r).address.confidentialAddress}))},exports.masterPubKeyRestorerFromState=function(t){return re(t)},exports.mnemonicRestorerFromEsplora=function(t){return Qt(t,(function(e,r){return t.getAddress(e,r).address.confidentialAddress}))},exports.mnemonicRestorerFromState=function(t){return re(t)},exports.multisigFromEsplora=function(t){return Qt(t,(function(e,r){return t.getMultisigAddress(e?et.INTERNAL_INDEX:et.EXTERNAL_INDEX,r).confidentialAddress}))},exports.multisigWatchOnlyFromEsplora=function(t){return Qt(t,(function(e,r){return t.getMultisigAddress(e?et.INTERNAL_INDEX:et.EXTERNAL_INDEX,r).confidentialAddress}))},exports.psetToUnsignedHex=C,exports.psetToUnsignedTx=function(t){return e.Transaction.fromHex(C(t))},exports.restorerFromState=re,exports.toAssetHash=E,exports.toNumber=I,exports.toOutpoint=F,exports.toXpub=L,exports.unblindOutput=W,exports.unblindTransaction=Et,exports.unblindUtxo=Ft,exports.utxoWithPrevout=Lt,exports.walletFromAddresses=function(t,e,r){return Zt.apply(this,arguments)},exports.walletFromCoins=$t;
//# sourceMappingURL=ldk.cjs.production.min.js.map

@@ -0,1 +1,2 @@

/// <reference types="node" />
import { BIP32Interface, networks } from 'liquidjs-lib';

@@ -19,1 +20,2 @@ import { Slip77Interface } from 'slip77';

export declare function blindingKeyFromXPubs(extendedKeys: BIP32Interface[]): Slip77Interface;
export declare function bip67sort(array: Buffer[]): Buffer[];
import { CoinSelector } from './coinselection/coinSelector';
import { UtxoInterface, ChangeAddressFromAssetGetter, RecipientInterface } from './types';
import { UtxoInterface, ChangeAddressFromAssetGetter, RecipientInterface, CoinSelectorErrorFn } from './types';
export declare function craftSingleRecipientPset(unspents: UtxoInterface[], recipient: RecipientInterface, coinSelector: CoinSelector, changeAddress: string, substractFeeFromRecipient?: boolean, satsPerByte?: number): string;
export interface BuildTxArgs {

@@ -11,3 +12,5 @@ psetBase64: string;

satsPerByte?: number;
errorHandler?: CoinSelectorErrorFn;
}
export declare const DEFAULT_SATS_PER_BYTE = 0.1;
/**

@@ -19,5 +22,5 @@ * buildTx selects utxos among unspents to fill outputs' requirements,

*/
export declare function buildTx(args: BuildTxArgs): string;
export declare function craftMultipleRecipientsPset(args: BuildTxArgs): string;
export declare function createFeeOutput(numInputs: number, numOutputs: number, satsPerByte: number, assetHash: string): RecipientInterface;
export declare function addToTx(psetBase64: string, unspents: UtxoInterface[], outputs: RecipientInterface[]): string;
export declare function estimateTxSize(numInputs: number, numOutputs: number): number;

@@ -26,3 +26,3 @@ /// <reference types="node" />

}
export declare type ChangeAddressFromAssetGetter = (asset: string) => string | undefined;
export declare type ChangeAddressFromAssetGetter = (asset: string) => string;
export declare type BlindingKeyGetter = (script: string) => string | undefined;

@@ -82,2 +82,4 @@ export interface RecipientInterface {

}
export declare type CompareUtxoFn = (a: UtxoInterface, b: UtxoInterface) => number;
export declare type CoinSelectorErrorFn = (asset: string, need: number, has: number) => void;
export declare type MultisigPayment = AddressInterface & {

@@ -84,0 +86,0 @@ witnessScript: string;

@@ -12,2 +12,3 @@ import { Network } from 'liquidjs-lib';

buildTx(psetBase64: string, recipients: RecipientInterface[], coinSelector: CoinSelector, changeAddressByAsset: ChangeAddressFromAssetGetter, addFee?: boolean, satsPerByte?: number): string;
sendTx(recipient: RecipientInterface, coinSelector: CoinSelector, changeAddress: string, substractFee?: boolean, satsPerByte?: number): string;
}

@@ -31,2 +32,3 @@ /**

buildTx(psetBase64: string, recipients: RecipientInterface[], coinSelector: CoinSelector, changeAddressByAsset: ChangeAddressFromAssetGetter, addFee?: boolean, satsPerByte?: number): string;
sendTx(recipient: RecipientInterface, coinSelector: CoinSelector, changeAddress: string, substractFee?: boolean, satsPerByte?: number): string;
}

@@ -33,0 +35,0 @@ /**

{
"version": "0.3.15",
"version": "0.3.16",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc