Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.16 to 0.3.17

dist/balance.d.ts

6

dist/coinselection/coinSelector.d.ts

@@ -1,6 +0,6 @@

import { UtxoInterface, RecipientInterface, ChangeAddressFromAssetGetter, CoinSelectorErrorFn } from './../types';
import { RecipientInterface, ChangeAddressFromAssetGetter, UnblindedOutput, CoinSelectorErrorFn } from './../types';
export interface CoinSelectionResult {
selectedUtxos: UtxoInterface[];
selectedUtxos: UnblindedOutput[];
changeOutputs: RecipientInterface[];
}
export declare type CoinSelector = (errorHandler: CoinSelectorErrorFn) => (unspents: UtxoInterface[], outputs: RecipientInterface[], changeGetter: ChangeAddressFromAssetGetter) => CoinSelectionResult;
export declare type CoinSelector = (errorHandler: CoinSelectorErrorFn) => (unspents: UnblindedOutput[], outputs: RecipientInterface[], changeGetter: ChangeAddressFromAssetGetter) => CoinSelectionResult;

@@ -1,8 +0,9 @@

import { CompareUtxoFn } from './../types';
import { UnblindedOutput } from './../types';
import { CoinSelector } from './coinSelector';
export declare type CompareUtxoFn = (a: UnblindedOutput, b: UnblindedOutput) => number;
/**
* select utxo for outputs among unspents.
* @param unspents a set of unspents.
* @param outputs the outputs targetted by the coin selection
* @param recipients the outputs targetted by the coin selection
*/
export declare function greedyCoinSelector(sortFn?: CompareUtxoFn): CoinSelector;

@@ -1,6 +0,7 @@

import { ChangeAddressFromAssetGetter, CompareUtxoFn, CoinSelectorErrorFn, RecipientInterface, UtxoInterface } from '../types';
import { ChangeAddressFromAssetGetter, CoinSelectorErrorFn, RecipientInterface, UnblindedOutput } from '../types';
import { CompareUtxoFn } from './greedy';
export declare const throwErrorHandler: CoinSelectorErrorFn;
export declare const makeChanges: (changeAddressGetter: ChangeAddressFromAssetGetter) => (toSelect: Map<string, number>) => (selectedUtxos: UtxoInterface[]) => RecipientInterface[];
export declare const coinSelect: (compareFn: CompareUtxoFn) => (errorHandler: CoinSelectorErrorFn) => (utxos: UtxoInterface[]) => (toSelect: Map<string, number>) => UtxoInterface[];
export declare const makeChanges: (changeAddressGetter: ChangeAddressFromAssetGetter) => (toSelect: Map<string, number>) => (selectedUtxos: UnblindedOutput[]) => RecipientInterface[];
export declare const coinSelect: (compareFn: CompareUtxoFn) => (errorHandler: CoinSelectorErrorFn) => (utxos: UnblindedOutput[]) => (toSelect: Map<string, number>) => UnblindedOutput[];
export declare function reduceRecipients(recipients: RecipientInterface[]): Map<string, number>;
export declare const checkCoinSelect: (recipients: RecipientInterface[]) => (selectedUtxos: UtxoInterface[]) => void;
export declare const checkCoinSelect: (recipients: RecipientInterface[]) => (selectedUtxos: UnblindedOutput[]) => void;

@@ -1,3 +0,3 @@

import { TxInterface } from '../types';
import { EsploraTx, EsploraUtxo } from './types';
import { TxInterface, Output } from '../types';
import { EsploraTx } from './types';
/**

@@ -20,3 +20,3 @@ * Fetch the raw transaction by txid

*/
export declare function fetchUtxos(address: string, url: string): Promise<EsploraUtxo[]>;
export declare function fetchUtxos(address: string, url: string): Promise<Output[]>;
/**

@@ -23,0 +23,0 @@ * Convert an esplora transaction to a TxInterface

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

import { Outpoint } from '../types';
export interface EsploraTx {

@@ -30,3 +31,3 @@ txid: string;

}
export interface EsploraUtxo {
export declare type EsploraUtxo = Outpoint & {
txid: string;

@@ -43,2 +44,2 @@ vout: number;

noncecommitment: string;
}
};

@@ -1,11 +0,3 @@

import UnblindError from '../error/unblind-error';
import { AddressInterface, UtxoInterface } from '../types';
import { AddressInterface, TxInterface, UnblindedOutput, Output } from '../types';
/**
* Fetch balances for a given address
* @param address the address to fetch utxos
* @param blindPrivKey the blinding private key (if the address is confidential one)
* @param url esplora URL
*/
export declare function fetchBalances(address: string, blindPrivKey: string, url: string): Promise<any>;
/**
* fetchAndUnblindUtxosGenerator returns the unblinded utxos associated with a set of addresses.

@@ -16,35 +8,13 @@ * @param addressesAndBlindingKeys the set of addresses with blinding key (if confidential)

*/
export declare function fetchAndUnblindUtxosGenerator(addressesAndBlindingKeys: AddressInterface[], url: string, skip?: (utxo: UtxoInterface) => boolean): AsyncGenerator<UtxoInterface, {
export declare function fetchAndUnblindUtxosGenerator(addressesAndBlindingKeys: AddressInterface[], url: string, skip?: (utxo: Output) => boolean): AsyncGenerator<UnblindedOutput, {
numberOfUtxos: number;
errors: Error[];
}, undefined>;
export declare function fetchAndUnblindUtxos(addressesAndBlindingKeys: AddressInterface[], url: string, skip?: (utxo: Output) => boolean): Promise<UnblindedOutput[]>;
/**
* Aggregate generator's result.
* @param addressesAndBlindingKeys
* @param url
* @param skip optional
* Reduce a set of transactions using a set of scripts
* @param txs the wallet's transactions
* @param walletScripts the set of scripts to use in order to filter tx's outputs
* @param initialState initial utxos state (set in txs reducer) - optional (default: [])
*/
export declare function fetchAndUnblindUtxos(addressesAndBlindingKeys: AddressInterface[], url: string, skip?: (utxo: UtxoInterface) => boolean): Promise<UtxoInterface[]>;
/**
* Fetch utxo's prevout and set it
* @param utxo an unspent without prevout
* @param explorerURL esplora URL
*/
export declare function utxoWithPrevout(utxo: UtxoInterface, explorerURL: string): Promise<UtxoInterface>;
/**
* try to unblind the utxo with blindPrivKey. if unblind fails, return utxo
* if unblind step success: set prevout & unblindData members in UtxoInterface result
* @param utxo utxo to unblind
* @param blindPrivKey the blinding private key using to unblind
* @param url esplora endpoint URL
*/
export declare function fetchPrevoutAndTryToUnblindUtxo(utxo: UtxoInterface, blindPrivKey: string, url: string): Promise<{
unblindedUtxo: UtxoInterface;
error?: UnblindError;
}>;
/**
* Unblind utxo using hex encoded blinding private key
* @param utxo blinded utxo
* @param blindPrivKey blinding private key
*/
export declare function unblindUtxo(utxo: UtxoInterface, blindPrivKey: string): Promise<UtxoInterface>;
export declare function utxosFromTransactions(txs: TxInterface[], walletScripts: Set<string>, initialState?: (Output | UnblindedOutput)[]): (Output | UnblindedOutput)[];

@@ -19,3 +19,4 @@ export { networks, address, payments, ECPair } from 'liquidjs-lib';

export * from './types';
export * from './balance';
export * from './restorer/mnemonic-restorer';
export * from './restorer/restorer';

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

"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;
"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 u(t){this.wrapped=t}function a(t){var e,r;function n(e,r){try{var o=t[e](r),s=o.value,a=s instanceof u;Promise.resolve(a?s.wrapped:s).then((function(t){a?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 u={key:t,arg:i,resolve:o,reject:s,next:null};r?r=r.next=u:(e=r=u,n(t,i))}))},"function"!=typeof t.return&&(this.return=void 0)}function c(t){return function(){return new a(t.apply(this,arguments))}}function p(t){return new u(t)}function f(t,e,r,n,i,o,s){try{var u=t[o](s),a=u.value}catch(t){return void r(t)}u.done?e(a):Promise.resolve(a).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,u,"next",t)}function u(t){f(o,n,i,s,u,"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.")}a.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},a.prototype.next=function(t){return this._invoke("next",t)},a.prototype.throw=function(t){return this._invoke("throw",t)},a.prototype.return=function(t){return this._invoke("return",t)};var P,k=(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 u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function a(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 u=m(s,r);if(u){if(u===p)continue;return u}}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 a=c(t,e,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===p)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.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=a;var p={};function f(){}function d(){}function l(){}var h={};u(h,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(K([])));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){u(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,u){var a=c(t[i],t,o);if("throw"!==a.type){var p=a.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,s,u)}),(function(t){n("throw",t,s,u)})):e.resolve(f).then((function(t){p.value=t,s(p)}),(function(t){return n("throw",t,s,u)}))}u(a.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 K(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:A}}function A(){return{value:void 0,done:!0}}return d.prototype=l,u(x,"constructor",l),u(l,"constructor",d),d.displayName=u(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,u(t,s,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},g(b.prototype),u(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(a(e,r,n,i),o);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},g(x),u(x,s,"Generator"),u(x,i,(function(){return this})),u(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=K,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 u=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(u&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)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:K(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)}}(P={exports:{}}),P.exports),K=Buffer.alloc(32),A=Buffer.from("0x00","hex");function E(t){return null!=t&&t.length>0}function I(t){var e=t.surjectionProof,r=t.nonce;return E(t.rangeProof)&&E(e)&&r!==A}var T,S=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}(),B=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function N(t,e){if(!B.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(B.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 O(t,e){return N(t,"liquid"===e?"zpub":"vpub")}function _(t){return N(t,"xpub")}function M(t,e){try{r.fromBase58(t,e)}catch(t){return!1}return!0}function L(t){try{o.fromMasterBlindingKey(t)}catch(t){return!1}return!0}function U(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 j(t){return t?e.networks[t]:e.networks.liquid}function F(t,e){return C.apply(this,arguments)}function C(){return(C=d(k.mark((function t(r,n){return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(I(r.prevout)){t.next=2;break}return t.abrupt("return",l({},r,{unblindData:{asset:r.prevout.asset.slice(1),value:e.confidential.confidentialValueToSatoshi(r.prevout.value).toString(10),assetBlindingFactor:K,valueBlindingFactor:K}}));case 2:return t.next=4,e.confidential.unblindOutputWithKey(r.prevout,Buffer.from(n,"hex"));case 4:return t.abrupt("return",l({},r,{unblindData:t.sent}));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function D(t,e){if(t!==e)throw new Error("Incorrect Identity type: need "+e+" and get "+t+".")}function R(t,e){if(e&&n.setDefaultWordlist(e),!n.validateMnemonic(t))throw new Error("Mnemonic is not valid.")}function W(t){try{r.fromBase58(t)}catch(e){throw new Error("invalid master public key: "+t)}}function H(t){var r;try{r=e.Psbt.fromBase64(t)}catch(t){throw new Error("Invalid pset")}return r}function X(t,e){return t.reduce((function(t,r){var n,i=e(r),o=null!=(n=t[i])?n:[];return t[i]=[].concat(o,[r]),t}),{})}function q(t){return void 0!==t.unblindData}function G(t){if(q(t))return parseInt(t.unblindData.value,10);if(!I(t.prevout))return e.confidential.confidentialValueToSatoshi(t.prevout.value);throw new Error("cannot get value for confidential output, need unblinded one")}function V(t){if(q(t))return Buffer.from(t.unblindData.asset).reverse().toString("hex");if(!I(t.prevout))return Buffer.from(t.prevout.asset).slice(1).reverse().toString("hex");throw new Error("cannot get asset for confidential output, need unblinded one")}(T=exports.IdentityType||(exports.IdentityType={}))[T.PrivateKey=1]="PrivateKey",T[T.Mnemonic=2]="Mnemonic",T[T.MasterPublicKey=3]="MasterPublicKey",T[T.Inject=4]="Inject",T[T.Ledger=5]="Ledger",T[T.Trezor=6]="Trezor",T[T.MultisigWatchOnly=7]="MultisigWatchOnly",T[T.Multisig=8]="Multisig";var z=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(k.mark((function t(r,n,i,o,s){var u,a,c,p,f,d,l,h,v,y,x,g,b,m,P;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:u=new Map,a=new Map,c=H(n),p=e.Transaction.fromHex(U(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"),a.set(l,h),t.abrupt("continue",14);case 11:v=r(p.outs[l].script).publicKey,a.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(I(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,I(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 u.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:u.set(y,t.sent);case 40:y++,t.next=17;break;case 43:return t.next=45,c.blindOutputsByIndex(u,a);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}(),Y=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=_(e.opts.masterPublicKey);if(D(e.type,exports.IdentityType.MasterPublicKey),!M(s))throw new Error("Master public key is not valid");if(!L(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(k.mark((function e(r,n,i,o){var s=this;return k.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(k.mark((function t(){var e;return k.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(k.mark((function t(){var e;return k.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(k.mark((function t(e){return k.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(k.mark((function t(){return k.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}(z);Y.INITIAL_BASE_PATH="m/84'/0'/0'",Y.INITIAL_INDEX=0;var Z=function(t){function i(i){var s;D(i.type,exports.IdentityType.Mnemonic),n.setDefaultWordlist(i.opts.language||"english"),R(i.opts.mnemonic);var u=n.mnemonicToSeedSync(i.opts.mnemonic),a=r.fromSeed(u,e.networks[i.chain]),c=a.derivePath(Y.INITIAL_BASE_PATH),p=O(e.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58(),i.chain),f=o.fromSeed(u),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=a,s.mnemonic=i.opts.mnemonic,s}h(i,t);var s=i.prototype;return s.blindPset=function(){var e=d(k.mark((function e(r,n,i,o){var s=this;return k.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(k.mark((function t(r){var n,i,o,s,u,a,c;return k.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&&(u=this.scriptToAddressCache[s.witnessUtxo.script.toString("hex")])&&(a=this.derivePath(u.address.derivationPath).privateKey,c=e.ECPair.fromPrivateKey(a),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}(Y),$=function(t){function r(r){var n;n=t.call(this,r)||this,D(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(k.mark((function e(r,n,i,o){var s=this;return k.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(k.mark((function t(){return k.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(k.mark((function t(){return k.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(k.mark((function t(e){return k.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(k.mark((function t(r){var n,i,o,s,u=this;return k.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,u.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(k.mark((function t(){return k.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}(z),J=function(t){function e(e){var r;if(r=t.call(this,e)||this,D(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}(z);function Q(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 tt(t){return t.sort(et)}function et(t,e){return t.toString("hex")<e.toString("hex")?-1:1}var rt=function(t){function i(i){var s;(s=t.call(this,i)||this).nextIndex=0,s.nextChangeIndex=0,D(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 u,a=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 _(r.fromPublicKey(o.publicKey,o.chainCode,e).toBase58())}(t,s.network)}));return a.forEach(W),s.cosigners=a.sort().map((function(t){return r.fromBase58(t)})),s.blindingKeyMasterNode=(u=function(t){for(var r,n=Buffer.from("blinding_key"),i=Buffer.alloc(32),o=w(t);!(r=o()).done;)i=Q(i,r.value);return e.crypto.sha256(Buffer.concat([n,i]))}(s.cosigners.map((function(t){return t.chainCode}))),o.fromSeed(u)),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:tt(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)),u=s.publicKey,a=s.privateKey;if(!u||!a)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:tt(t.map((function(t){return t.publicKey}))),network:i}),blindkey:u,network:i})).confidentialAddress||!o.redeem||!o.redeem.output)throw new Error("invalid payment");return{blindingPrivateKey:a.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}(z);rt.EXTERNAL_INDEX=0,rt.INTERNAL_INDEX=1;var nt=function(t){function i(i){var o;D(i.type,exports.IdentityType.Multisig),R(i.opts.signer.mnemonic);var s=n.mnemonicToSeedSync(i.opts.signer.mnemonic),u=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=u,o.scriptToPath={},o}h(i,t);var o=i.prototype;return o.getNextAddress=function(){var e=d(k.mark((function e(){var r;return k.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(k.mark((function e(){var r;return k.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(k.mark((function t(r){var n,i,o,s,u,a,c;return k.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(!(u=this.scriptToPath[s.witnessUtxo.script.toString("hex")])){t.next=13;break}if(a=this.baseNode.derivePath(u).privateKey){t.next=11;break}throw new Error("signing private key is undefined");case 11:c=e.ECPair.fromPrivateKey(a),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 _(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}(rt),it=function(t,e,r){throw new Error("not enought funds to fill "+e+"sats of "+t+" (amount selected: "+r+")")};function ot(t,e){return t.set(e.asset,(t.get(e.asset)||0)+e.value),t}function st(t){return function(e){return V(e)===t}}var ut=function(t){return function(e){var r=e.map((function(t){return{value:G(t)||0,asset:V(t)||""}}));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 u in n){var a=ct(n[u].map((function(t){return t.value}))),c=ct(i[u].map((function(t){return t.value})));if(a!==c)throw new Error("missing funds for asset "+u+" (inputs: "+a+", outputs: "+c+")")}}},ct=function(t){return t.reduce((function(t,e){return t+e}),0)},pt=function(t,e){return G(t)-G(e)};function ft(t,e){return dt.apply(this,arguments)}function dt(){return(dt=d(k.mark((function t(e,r){return k.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(k.mark((function t(e,r){return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=xt,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(k.mark((function t(e,r){return k.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",Promise.all(t.sent.data.map(yt(r))));case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var yt=function(t){return function(){var r=d(k.mark((function r(n){var i;return k.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,ft(n.txid,t);case 2:return i=e.Transaction.fromHex(r.sent).outs[n.vout],r.abrupt("return",l({},n,{prevout:i}));case 5:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()};function xt(t,e){return gt.apply(this,arguments)}function gt(){return(gt=d(k.mark((function t(r,n){var i,o,s,u,a,c,p,f,d,l;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(i=[],o=[],s=w(r.vin);!(u=s()).done;)i.push((a=u.value).txid),o.push(a.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 bt({txid:i[r],vout:o[r]},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=function(t){return{txid:r.txid,vout:t}},l=f.outs.map((function(t,e){return bt(d(e),t)})),t.abrupt("return",{txid:r.txid,vin:p,vout:l,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 17:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function bt(t,e){return l({},t,{prevout:e})}function mt(t,e,r){return t+"/tx/"+e+"#blinded="+r.map((function(t){return t.value+","+t.asset+","+t.valueBlinder+","+t.assetBlinder})).join(",")}var wt=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 Pt(t,e,r,n){return kt.apply(this,arguments)}function kt(){return(kt=c(k.mark((function t(e,r,n,i){var o,s,u,a,c,f,d,l,h,v;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=[],s=[],u=w(e);case 3:if((a=u()).done){t.next=40;break}return c=a.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(It(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(k.mark((function t(e,r,n,i){var o,s,u;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=Pt(e,r,n,i),s=[],t.next=4,o.next();case 4:u=t.sent;case 5:if(u.done){t.next=12;break}return s.push(u.value),t.next=9,o.next();case 9:u=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 Et.apply(this,arguments)}function Et(){return(Et=c(k.mark((function t(e,r,n){var i,o,s,u,a,c,f,d;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=void 0,o=[],s=0;case 3:return t.next=5,p(St(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,u=o.map((function(t){return xt(t,r)})),a=w(u);case 12:if((c=a()).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 It(t,e){return Tt.apply(this,arguments)}function Tt(){return(Tt=d(k.mark((function t(e,r){var n,i,o,s,u,a;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(n=[],i=[],o=function(t){var o=e.vin[t].prevout;o&&!q(o)&&n.push(function(){var n=d(k.mark((function n(){var s;return k.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.prevout.script.toString("hex")))){n.next=12;break}return n.prev=2,n.next=5,F(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 wt(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(u=function(t){var o=e.vout[t];q(o)||n.push(function(){var n=d(k.mark((function n(){var s;return k.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(s=r(o.prevout.script.toString("hex")))){n.next=12;break}return n.prev=2,n.next=5,F(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 wt(e.txid,t,s));case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(){return n.apply(this,arguments)}}()())},a=0;a<e.vout.length;a++)u(a);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 St(t,e,r){return Bt.apply(this,arguments)}function Bt(){return(Bt=d(k.mark((function t(e,r,n){var i;return k.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 Nt(t,e,r){return Ot.apply(this,arguments)}function Ot(){return(Ot=c(k.mark((function t(r,n,i){var o,s,u,a,c,f,d,l,h,v,y,x;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=0,s=[],u=w(r);case 3:if((a=u()).done){t.next=33;break}if(f=(c=a.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=24;break}if(x=y.value,null==i||!i(x)){t.next=19;break}return t.abrupt("continue",22);case 19:return t.next=21,Lt(x,d);case 21:o++;case 22:t.next=15;break;case 24:t.next=31;break;case 26:t.prev=26,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 31:t.next=3;break;case 33:return t.abrupt("return",{numberOfUtxos:o,errors:s});case 34:case"end":return t.stop()}}),t,null,[[5,26]])})))).apply(this,arguments)}function _t(t,e,r){return Mt.apply(this,arguments)}function Mt(){return(Mt=d(k.mark((function t(e,r,n){var i,o,s;return k.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(k.mark((function t(e,r){return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.abrupt("return",F(e,r));case 4:throw t.prev=4,t.t0=t.catch(0),new wt(e.txid,e.vout,r);case 7:case"end":return t.stop()}}),t,null,[[0,4]])})))).apply(this,arguments)}function jt(t,r,n,i,o,s){void 0===o&&(o=!1),void 0===s&&(s=Ft);var u=e.address.getNetwork(r.address),a=o&&r.asset===u.assetHash,c=Dt(n(it)(t,[r],(function(){return i})).selectedUtxos.length,2,s,u.assetHash),p=it;a&&(p=function(t,e,n){t!==r.asset?it(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 ut(l)(d),Rt(new e.Psbt({network:u}).toBase64(),d,l)}var Ft=.1;function Ct(t){var r=function(t){if(t.satsPerByte||(t.satsPerByte=Ft),t.errorHandler||(t.errorHandler=it),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,u=r.unspents,a=r.addFee,c=r.satsPerByte,p=r.errorHandler,f=i(p)(u,s,n);if(!a){var d=s.concat(f.changeOutputs);return ut(d)(f.selectedUtxos),Rt(o,f.selectedUtxos,d)}var l=function(t,r,n,i){var o=H(t);return Dt(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)(u,[].concat(s,[l]),n),v=h.selectedUtxos,y=[].concat(s,h.changeOutputs,[l]);return ut(y)(v),Rt(o,v,y)}function Dt(t,e,r,n){var i=Wt(t,e);return{asset:n,value:Math.ceil(i*r),address:""}}function Rt(t,r,n){for(var i,o=H(t),s=Buffer.from("00","hex"),u=w(n);!(i=u()).done;){var a=i.value,c=a.asset,p=a.value,f=a.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 Wt(t,e){return(3*Ht(!1,t,e,!1)+Ht(!0,t,e,!0)+3)/4}function Ht(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+Xt(r)+Xt(e)+i+o}function Xt(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}var qt=function(){function t(t,e){this.network=e,this.unspents=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 Ct({psetBase64:t,recipients:e,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:o,unspents:this.unspents})},r.sendTx=function(t,e,r,n,i){return void 0===n&&(n=!1),void 0===i&&(i=Ft),jt(this.unspents,t,e,r,n,i)},t}();function Gt(){return(Gt=d(k.mark((function t(e,r,n){return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,_t(e,r);case 2:return t.abrupt("return",Vt(t.sent,n));case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Vt(t,e){return new qt(t,j(e))}function zt(t){return t.reduce((function(t,e){return t+G(e)}),0)}function Yt(t,e){return function(){var r=d(k.mark((function r(n){var i,o,s,u,a,c,p,f,l,h;return k.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=void 0===(i=n.esploraURL)?"https://blockstream.info/liquid/api":i,u=void 0===(s=n.gapLimit)?20:s,c=(a=function(){var t=d(k.mark((function t(e){var r,n,i,s,a;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=0,n=0,i=void 0,s=k.mark((function t(){var s,a,c,p,f;return k.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s=n,t.next=3,Promise.all(Array.from(Array(u).keys()).map((function(t){return t+s})).map(e));case 3:return a=t.sent,t.next=6,Promise.all(a.map((function(t){return Zt(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!==u){t.next=19;break}return t.abrupt("return",{v:i});case 19:c++;case 20:t.next=9;break;case 22:n+=u;case 23:case"end":return t.stop()}}),t)}));case 4:if(!(r<u)){t.next=11;break}return t.delegateYield(s(),"t0",6);case 6:if("object"!=typeof(a=t.t0)){t.next=9;break}return t.abrupt("return",a.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=a((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",Jt(t)({lastUsedExternalIndex:l,lastUsedInternalIndex:h}));case 10:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()}function Zt(t,e){return $t.apply(this,arguments)}function $t(){return($t=d(k.mark((function t(e,r){return k.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 Jt(t){return function(){var e=d(k.mark((function e(r){var n,i,o,s,u,a,c;return k.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++)u=t.getNextAddress(),o.push(u);if(void 0!==i)for(a=0;a<=i;a++)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=J,exports.BufferMap=S,exports.DEFAULT_BASE_DERIVATION_PATH="m/48'/0'/0'/2'",exports.DEFAULT_SATS_PER_BYTE=Ft,exports.Identity=z,exports.MasterPublicKey=Y,exports.Mnemonic=Z,exports.Multisig=nt,exports.MultisigWatchOnly=rt,exports.PrivateKey=$,exports.Wallet=qt,exports.addToTx=Rt,exports.balances=function(t){for(var e=X(t,V),r={},n=0,i=Object.entries(e);n<i.length;n++){var o=i[n];r[o[0]]=zt(o[1])}return r},exports.checkIdentityType=D,exports.checkMasterPublicKey=W,exports.checkMnemonic=R,exports.craftMultipleRecipientsPset=Ct,exports.craftSingleRecipientPset=jt,exports.createFeeOutput=Dt,exports.decodePset=H,exports.esploraTxToTxInterface=xt,exports.estimateTxSize=Wt,exports.fetchAndUnblindTxs=function(t,e,r,n){return Kt.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=Pt,exports.fetchAndUnblindUtxos=_t,exports.fetchAndUnblindUtxosGenerator=Nt,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=O,exports.getAsset=V,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=j,exports.getSats=G,exports.getScripts=function(t){return new Set(t.map((function(t){return e.address.toOutputScript(t.confidentialAddress).toString("hex")})))},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.prevout.script.length>0&&q(s)&&n.push({value:G(s),asset:V(s),assetBlinder:i(s.unblindData.assetBlindingFactor.toString("hex")),valueBlinder:i(s.unblindData.valueBlindingFactor.toString("hex"))})}return mt(e,t.txid,n)},exports.greedyCoinSelector=function(t){return void 0===t&&(t=pt),function(e){void 0===e&&(e=it);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(st(r)).sort(t).reduce((function(t,e){return o<=n&&(t.push(e),o+=G(e)),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(st(t)).reduce((function(t,e){return t+G(e)}),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(ot,new Map)}(e),s=n(t)(o);return{selectedUtxos:s,changeOutputs:i(o)(s)}}}},exports.groupBy=X,exports.isConfidentialOutput=I,exports.isUnblindedOutput=q,exports.isValidAmount=function(t){return!(t<=0||!Number.isSafeInteger(t))},exports.isValidExtendedBlindKey=L,exports.isValidXpub=M,exports.makeUnblindURL=mt,exports.masterPubKeyRestorerFromEsplora=function(t){return Yt(t,(function(e,r){return t.getAddress(e,r).address.confidentialAddress}))},exports.masterPubKeyRestorerFromState=function(t){return Jt(t)},exports.mnemonicRestorerFromEsplora=function(t){return Yt(t,(function(e,r){return t.getAddress(e,r).address.confidentialAddress}))},exports.mnemonicRestorerFromState=function(t){return Jt(t)},exports.multisigFromEsplora=function(t){return Yt(t,(function(e,r){return t.getMultisigAddress(e?rt.INTERNAL_INDEX:rt.EXTERNAL_INDEX,r).confidentialAddress}))},exports.multisigWatchOnlyFromEsplora=function(t){return Yt(t,(function(e,r){return t.getMultisigAddress(e?rt.INTERNAL_INDEX:rt.EXTERNAL_INDEX,r).confidentialAddress}))},exports.psetToUnsignedHex=U,exports.psetToUnsignedTx=function(t){return e.Transaction.fromHex(U(t))},exports.restorerFromState=Jt,exports.toAssetHash=function(t){return t.slice(1).reverse().toString("hex")},exports.toNumber=function(t){return e.confidential.confidentialValueToSatoshi(t)},exports.toOutpoint=function(t){return{txid:t.txid,vout:t.vout}},exports.toXpub=_,exports.unblindOutput=F,exports.unblindTransaction=It,exports.utxosFromTransactions=function(t,e,r){void 0===r&&(r=[]);var n=function(t){return t||Infinity};return t.sort((function(t,e){return function(t,e){return n(t.status.blockHeight)-n(e.status.blockHeight)||0}(t,e)||function(t,e){return t.vin.map((function(t){return t.txid})).includes(e.txid)?1:-1}(t,e)})).reduce((function(t,r,n){return function(t,e,r){var n=e.vout.filter((function(t){return r.has(t.prevout.script.toString("hex"))}));return t.concat(n)}(function(t,e){for(var r,n=t,i=function(){var t=r.value;n=n.filter((function(e){return!(e.txid===t.txid&&e.vout===t.vout)}))},o=w(e);!(r=o()).done;)i();return n}(t,r.vin),r,e)}),r)},exports.walletFromAddresses=function(t,e,r){return Gt.apply(this,arguments)},exports.walletFromCoins=Vt;
//# sourceMappingURL=ldk.cjs.production.min.js.map
import { CoinSelector } from './coinselection/coinSelector';
import { UtxoInterface, ChangeAddressFromAssetGetter, RecipientInterface, CoinSelectorErrorFn } from './types';
export declare function craftSingleRecipientPset(unspents: UtxoInterface[], recipient: RecipientInterface, coinSelector: CoinSelector, changeAddress: string, substractFeeFromRecipient?: boolean, satsPerByte?: number): string;
import { ChangeAddressFromAssetGetter, RecipientInterface, UnblindedOutput, Output, CoinSelectorErrorFn } from './types';
export declare function craftSingleRecipientPset(unspents: UnblindedOutput[], recipient: RecipientInterface, coinSelector: CoinSelector, changeAddress: string, substractFeeFromRecipient?: boolean, satsPerByte?: number): string;
export interface BuildTxArgs {
psetBase64: string;
unspents: UtxoInterface[];
unspents: UnblindedOutput[];
recipients: RecipientInterface[];

@@ -23,3 +23,3 @@ coinSelector: CoinSelector;

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 addToTx(psetBase64: string, unspents: Output[], outputs: RecipientInterface[]): string;
export declare function estimateTxSize(numInputs: number, numOutputs: number): number;

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

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

@@ -37,32 +36,15 @@ /**

}
export interface UtxoInterface {
txid: string;
vout: number;
asset?: string;
value?: number;
prevout?: TxOutput;
unblindData?: confidential.UnblindOutputResult;
redeemScript?: Buffer;
witnessScript?: Buffer;
}
export interface BlindedOutputInterface {
script: string;
blindedValue: Buffer;
blindedAsset: Buffer;
nonce: Buffer;
rangeProof: Buffer;
surjectionProof: Buffer;
}
export declare function isBlindedOutputInterface(object: any): object is BlindedOutputInterface;
export interface UnblindedOutputInterface {
script: string;
value: number;
asset: string;
valueBlinder: string;
assetBlinder: string;
}
export declare type Output = Outpoint & {
prevout: TxOutput;
};
export declare type UnblindedOutput = Output & {
unblindData: confidential.UnblindOutputResult;
};
export declare function isUnblindedOutput(output: Output): output is UnblindedOutput;
export declare function getSats(output: Output | UnblindedOutput): number;
export declare function getAsset(output: Output | UnblindedOutput): string;
export interface InputInterface {
txid: string;
vout: number;
prevout?: BlindedOutputInterface | UnblindedOutputInterface;
prevout?: Output | UnblindedOutput;
isPegin: boolean;

@@ -80,5 +62,4 @@ }

vin: InputInterface[];
vout: (BlindedOutputInterface | UnblindedOutputInterface)[];
vout: (Output | UnblindedOutput)[];
}
export declare type CompareUtxoFn = (a: UtxoInterface, b: UtxoInterface) => number;
export declare type CoinSelectorErrorFn = (asset: string, need: number, has: number) => void;

@@ -85,0 +66,0 @@ export declare type MultisigPayment = AddressInterface & {

/// <reference types="node" />
import { Network, Psbt, Transaction } from 'liquidjs-lib';
import { AddressInterface, BlindedOutputInterface, Outpoint, UnblindedOutputInterface, UtxoInterface, IdentityType, NetworkString } from './types';
import { AddressInterface, Outpoint, Output, IdentityType, NetworkString, UnblindedOutput } from './types';
export declare function toAssetHash(x: Buffer): string;

@@ -28,3 +28,3 @@ export declare function fromAssetHash(x: string): Buffer;

}
export declare function fromXpub(xub: string, chain: string): string;
export declare function fromXpub(xub: string, chain: NetworkString): string;
export declare function toXpub(anyPub: string): string;

@@ -35,11 +35,10 @@ export declare function isValidXpub(xpub: string, network?: Network): boolean;

export declare function psetToUnsignedTx(ptx: string): Transaction;
export declare function toOutpoint({ txid, vout }: UtxoInterface): Outpoint;
export declare function isBlindedUtxo({ asset, value }: UtxoInterface): boolean;
export declare function toOutpoint({ txid, vout }: Output): Outpoint;
export declare function getNetwork(str?: NetworkString): Network;
/**
* take a blinded output and unblind it
* @param output blinded output
* @param BlindingPrivateKey blinding private key
* Compute the blinding data for a given output
* @param utxo blinded utxo
* @param blindPrivKey blinding private key
*/
export declare function unblindOutput(output: BlindedOutputInterface, BlindingPrivateKey: string): Promise<UnblindedOutputInterface>;
export declare function unblindOutput(utxo: Output, blindPrivKey: string): Promise<UnblindedOutput>;
export declare function getIndexFromAddress(addr: AddressInterface): number;

@@ -50,1 +49,3 @@ export declare function checkIdentityType(actual: IdentityType, expect: IdentityType): void;

export declare function decodePset(psetBase64: string): Psbt;
export declare function getScripts(addresses: AddressInterface[]): Set<string>;
export declare function groupBy<T extends Record<string, any>>(xs: T[], key: (t: T) => string): Record<string, T[]>;
import { Network } from 'liquidjs-lib';
import { CoinSelector } from './coinselection/coinSelector';
import { AddressInterface, UtxoInterface, Outpoint, RecipientInterface, ChangeAddressFromAssetGetter, NetworkString } from './types';
import { AddressInterface, RecipientInterface, ChangeAddressFromAssetGetter, NetworkString, UnblindedOutput } from './types';
/**

@@ -9,3 +9,2 @@ * Wallet abstraction.

network: Network;
cache: UtxoCacheInterface;
createTx(): string;

@@ -19,3 +18,2 @@ buildTx(psetBase64: string, recipients: RecipientInterface[], coinSelector: CoinSelector, changeAddressByAsset: ChangeAddressFromAssetGetter, addFee?: boolean, satsPerByte?: number): string;

* @member addresses list of AddressInterface.
* @member blindingPrivateKeyByScript a map scriptPubKey --> blindingPrivateKey.
* @method createTx init empty PSET.

@@ -26,4 +24,4 @@ * @method updateTx update a PSET with outputs and inputs (for Swap tx).

network: Network;
cache: UtxoCacheInterface;
constructor(cache: UtxoCacheInterface, network: Network);
unspents: UnblindedOutput[];
constructor(unspents: UnblindedOutput[], network: Network);
/**

@@ -43,14 +41,2 @@ * Returns an empty liquidjs lib Psbt instance.

export declare function walletFromAddresses(addresses: AddressInterface[], explorerUrl: string, network?: NetworkString): Promise<WalletInterface>;
export declare function walletFromCoins(coins: UtxoInterface[], network?: NetworkString): WalletInterface;
export interface UtxoCacheInterface {
push(utxos: UtxoInterface[]): void;
delete(outpoint: Outpoint): boolean;
getAll(): UtxoInterface[];
}
export declare class UtxoCache implements UtxoCacheInterface {
private utxoMap;
constructor(utxos?: UtxoInterface[]);
push(utxos: UtxoInterface[]): void;
delete(outpoint: Outpoint): boolean;
getAll(): UtxoInterface[];
}
export declare function walletFromCoins(coins: UnblindedOutput[], network?: NetworkString): WalletInterface;
{
"version": "0.3.16",
"version": "0.3.17",
"license": "MIT",

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

"marina-provider": "^1.0.0",
"slip77": "^0.1.1"
"slip77": "^0.1.1",
"tslib": "^2.3.1"
}
}

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