Comparing version 0.1.7 to 0.2.0
@@ -1,2 +0,2 @@ | ||
import { AddressInterface, UtxoInterface, TxInterface, BlindingKeyGetter, BlindedOutputInterface, UnblindedOutputInterface } from '../types'; | ||
import { AddressInterface, BlindedOutputInterface, BlindingKeyGetter, TxInterface, UnblindedOutputInterface, UtxoInterface } from '../types'; | ||
export declare function fetchBalances(address: string, blindPrivKey: string, url: string): Promise<any>; | ||
@@ -13,4 +13,4 @@ export declare function fetchTxHex(txId: string, url: string): Promise<string>; | ||
export declare function fetchAndUnblindTxsGenerator(addresses: string[], blindingKeyGetter: BlindingKeyGetter, explorerUrl: string): AsyncGenerator<TxInterface, void, undefined>; | ||
export declare function tryToUnblindOutput(output: BlindedOutputInterface, BlindingPrivateKey: string): UnblindedOutputInterface; | ||
export declare function unblindOutput(output: BlindedOutputInterface, BlindingPrivateKey: string): Promise<UnblindedOutputInterface>; | ||
export declare function tryToUnblindUtxo(utxo: UtxoInterface, blindPrivKey: string, url: string): Promise<UtxoInterface>; | ||
export declare function unblindUtxo(utxo: UtxoInterface, blindPrivKey: string, url: string): Promise<UtxoInterface>; |
@@ -1,5 +0,5 @@ | ||
import { AddressInterface } from '../types'; | ||
import { BIP32Interface } from 'bip32'; | ||
import Identity, { IdentityInterface, IdentityOpts } from './identity'; | ||
import { BIP32Interface } from 'bip32'; | ||
import { Slip77Interface } from 'slip77'; | ||
import { AddressInterface } from '../types'; | ||
export interface MasterPublicKeyOptsValue { | ||
@@ -6,0 +6,0 @@ masterPublicKey: string; |
@@ -1,4 +0,4 @@ | ||
import { Slip77Interface } from 'slip77'; | ||
import { BIP32Interface } from 'bip32'; | ||
import Identity, { IdentityInterface, IdentityOpts } from './identity'; | ||
import { Slip77Interface } from 'slip77'; | ||
import { AddressInterface } from '../types'; | ||
@@ -5,0 +5,0 @@ export interface MnemonicOptsValue { |
@@ -0,3 +1,3 @@ | ||
import Identity, { IdentityInterface, IdentityOpts } from './identity'; | ||
import { AddressInterface } from '../types'; | ||
import Identity, { IdentityInterface, IdentityOpts } from './identity'; | ||
/** | ||
@@ -13,3 +13,3 @@ * This interface describes the shape of the value arguments used in contructor. | ||
/** | ||
* The PrivateKey Identity take WIF and modelize a user using his private key. | ||
* The PrivateKey Identity takes a WIF and modelize a user using his private key. | ||
* @member signingKeyPair private, the key pair used to sign inputs. | ||
@@ -16,0 +16,0 @@ * @member blindingKeyPair private, the key pair used to blind outputs. |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("liquidjs-lib"),r=e(require("axios")),n=e(require("bs58check")),i=require("bip32"),o=require("slip77"),a=require("bip39");function s(e){this.wrapped=e}function u(e){var t,r;function n(t,r){try{var o=e[t](r),a=o.value,u=a instanceof s;Promise.resolve(u?a.wrapped:a).then((function(e){u?n("return"===t?"return":"next",e):i(o.done?"return":"normal",e)}),(function(e){n("throw",e)}))}catch(e){i("throw",e)}}function i(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?n(t.key,t.arg):r=null}this._invoke=function(e,i){return new Promise((function(o,a){var s={key:e,arg:i,resolve:o,reject:a,next:null};r?r=r.next=s:(t=r=s,n(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function c(e){return function(){return new u(e.apply(this,arguments))}}function f(e){return new s(e)}function p(e,t,r,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function d(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){p(o,n,i,a,s,"next",e)}function s(e){p(o,n,i,a,s,"throw",e)}a(void 0)}))}}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}"function"==typeof Symbol&&Symbol.asyncIterator&&(u.prototype[Symbol.asyncIterator]=function(){return this}),u.prototype.next=function(e){return this._invoke("next",e)},u.prototype.throw=function(e){return this._invoke("throw",e)},u.prototype.return=function(e){return this._invoke("return",e)};var y,x=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=Object.create((t&&t.prototype instanceof p?t:p).prototype),o=new k(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=m(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,o),i}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function p(){}function d(){}function h(){}var l={};l[i]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(K([])));y&&y!==t&&r.call(y,i)&&(l=y);var x=h.prototype=p.prototype=Object.create(l);function g(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(i,o){function a(){return new t((function(n,a){!function n(i,o,a,s){var u=c(e[i],e,o);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(p).then((function(e){f.value=e,a(f)}),(function(e){return n("throw",e,a,s)}))}s(u.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function m(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return f;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,f;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function K(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:A}}function A(){return{value:void 0,done:!0}}return d.prototype=x.constructor=h,h.constructor=d,d.displayName=s(h,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,s(e,a,"GeneratorFunction")),e.prototype=Object.create(x),e},e.awrap=function(e){return{__await:e}},g(b.prototype),b.prototype[o]=function(){return this},e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new b(u(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(x),s(x,a,"Generator"),x[i]=function(){return this},x.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=K,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:K(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(y={exports:{}}),y.exports),g=function e(t){var n=this;this.esploraEndpoint=e.DEFAULT_ESPLORA_ENDPOINT,this.addressesHaveBeenUsed=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.all(t.map(n.addressHasBeenUsed)));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),this.addressHasBeenUsed=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.get(n.esploraEndpoint+"/address/"+t+"/txs").then((function(e){return e.data.length>0}),(function(e){return!1})).catch((function(){return!1})));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t&&(this.esploraEndpoint=t)};function b(e){var r=function(e){if(e.satsPerByte||(e.satsPerByte=.1),e.addFee||(e.addFee=!1),e.addFee&&e.satsPerByte<.1)throw new Error("satsPerByte minimum value is 0.1");if(0===e.recipients.length)throw new Error("need a least one recipient output to build the transaction");if(0===e.unspents.length)throw new Error("need at least one unspent to fund the transaction");return e}(e),n=r.changeAddressByAsset,i=r.coinSelector,o=r.psetBase64,a=r.recipients,s=r.unspents,u=r.addFee,c=r.satsPerByte,f=i(s,a,n),p=f.selectedUtxos,d=f.changeOutputs,h=p;if(!u)return w(o,h,a.concat(d));var l=P(o),y=l.data.inputs.length+h.length,x=l.data.outputs.length+a.length+d.length,g=t.address.getNetwork(a[0].address).assetHash,b=m(y,x,c,g),k=d.findIndex((function(e){return e.asset===g})),K=-1===k?0-b.value:d[k].value-b.value;if(K>0)return d[k].value=K,w(o,h,a.concat(d).concat(b));if(0===K)return w(o,h,a.concat(b));for(var A,I=[],E=v(s);!(A=E()).done;){var T=A.value;p.includes(T)||I.push(T)}var B=m(y+1,x+1,c,g),S=i(I,[B],n);return w(o,h.concat(S.selectedUtxos),a.concat(d).concat(S.changeOutputs).concat(B))}function m(e,t,r,n){var i=k(e,t);return{asset:n,value:Math.ceil(i*r),address:""}}function w(e,r,n){for(var i,o=P(e),a=Buffer.from("00","hex"),s=v(n);!(i=s()).done;){var u=i.value,c=u.asset,f=u.value,p=u.address,d=""===p?"":t.address.toOutputScript(p);o.addOutput({asset:c,value:f,script:d,nonce:a})}for(var h,l=v(r);!(h=l()).done;){var y=h.value;o.addInput({hash:y.txid,index:y.vout,witnessUtxo:y.prevout})}return o.toBase64()}function P(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r}function k(e,t){return(3*K(!1,e,t,!1)+K(!0,e,t,!0)+3)/4}function K(e,t,r,n){var i=function(e,t){var r=40*t;return e&&(r+=105*t),r}(e,t),o=function(e,t){var r=67*t;return e&&(r+=4273*t),r+43}(n,r);return 9+A(r)+A(t)+i+o}function A(e){return e<253?1:e<=65535?3:e<=4294967295?5:9}function I(e){return e.slice(1).reverse().toString("hex")}function E(e){return t.confidential.confidentialValueToSatoshi(e)}g.DEFAULT_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api";var T=Buffer.from("0x00","hex");function B(e){return null!=e&&e.length>0}function S(e){var t=e.surjectionProof,r=e.nonce;return B(e.rangeProof)&&B(t)&&r!==T}var N,O=function(){function e(){this.map=new Map}var t=e.prototype;return t.bufferToStringPrimitive=function(e){return e.toString("hex").valueOf()},t.get=function(e){return this.map.get(this.bufferToStringPrimitive(e))},t.set=function(e,t){return this.map.set(this.bufferToStringPrimitive(e),t),this},t.values=function(){return Array.from(this.map.values())},e}(),L=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function _(e,t){if(!L.has(t))return"Invalid target version";e=e.trim();try{var r=n.decode(e);return r=r.slice(4),r=Buffer.concat([Buffer.from(L.get(t),"hex"),r]),n.encode(r)}catch(e){throw new Error("Invalid extended public key! Please double check that you didn't accidentally paste extra data.")}}function M(e,t){return _(e,"regtest"===t?"vpub":"zpub")}function U(e){return _(e,"xpub")}function C(e,t){try{i.fromBase58(e,t)}catch(e){return!1}return!0}function F(e){try{o.fromMasterBlindingKey(e)}catch(e){return!1}return!0}function j(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r.data.globalMap.unsignedTx.toBuffer().toString("hex")}function W(e){return{txid:e.txid,vout:e.vout}}function D(e){return!e.asset||!e.value}function R(e){return e?t.networks[e]:t.networks.liquid}(N=exports.IdentityType||(exports.IdentityType={}))[N.PrivateKey=1]="PrivateKey",N[N.Mnemonic=2]="Mnemonic",N[N.MasterPublicKey=3]="MasterPublicKey",N[N.Inject=4]="Inject",N[N.Ledger=5]="Ledger",N[N.Trezor=6]="Trezor";var H=function(){function e(r){if(!r.chain||!t.networks.hasOwnProperty(r.chain))throw new Error("Network is missing or not valid");if(!r.type||!(r.type in exports.IdentityType))throw new Error("Type is missing or not valid");this.network=t.networks[r.chain],this.type=r.type,this.restorer=r.restorer?r.restorer:e.DEFAULT_RESTORER}return e.prototype.blindPsetWithBlindKeysGetter=function(){var e=d(x.mark((function e(r,n,i,o,a){var s,u,c,f,p,d,h,l,y,g,b,m,w,k,K,A;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:s=new Map,u=new Map,c=P(n),f=t.Transaction.fromHex(j(n)),p=v(i);case 5:if((d=p()).done){e.next=16;break}if(h=d.value,!o||!o.has(h)){e.next=11;break}return l=Buffer.from(o.get(h),"hex"),u.set(h,l),e.abrupt("continue",14);case 11:y=r(f.outs[h].script).publicKey,u.set(h,y);case 14:e.next=5;break;case 16:g=0;case 17:if(!(g<c.data.inputs.length)){e.next=41;break}if(m=void 0,!(b=c.data.inputs[g]).witnessUtxo){e.next=24;break}if(S(b.witnessUtxo)){e.next=23;break}return e.abrupt("continue",38);case 23:m=b.witnessUtxo.script;case 24:if(!b.nonWitnessUtxo){e.next=30;break}if(w=f.ins[g].index,S(k=t.Transaction.fromBuffer(b.nonWitnessUtxo).outs[w])){e.next=29;break}return e.abrupt("continue",38);case 29:m=k.script;case 30:if(!a||!a.has(g)){e.next=34;break}return K=Buffer.from(a.get(g),"hex"),s.set(g,K),e.abrupt("continue",38);case 34:if(m){e.next=36;break}throw new Error("no witness script for input #"+g);case 36:A=r(m).privateKey,s.set(g,A);case 38:g++,e.next=17;break;case 41:return e.abrupt("return",c.blindOutputsByIndex(s,u).toBase64());case 42:case"end":return e.stop()}}),e)})));return function(t,r,n,i,o){return e.apply(this,arguments)}}(),e}();function G(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}H.DEFAULT_RESTORER=new g;var X=function(e){function r(n){var s;if((s=e.call(this,n)||this).baseDerivationPath=r.INITIAL_BASE_PATH,s.index=r.INITIAL_INDEX,s.changeIndex=r.INITIAL_INDEX,s.scriptToAddressCache=new O,n.type!==exports.IdentityType.Mnemonic)throw new Error("The identity arguments have not the Mnemonic type.");if(!("mnemonic"in n.value))throw new Error("The value of IdentityOpts is not valid for Mnemonic Identity.");if(a.setDefaultWordlist(n.value.language?n.value.language:"english"),!a.validateMnemonic(n.value.mnemonic))throw new Error("Mnemonic is not valid.");var u=a.mnemonicToSeedSync(n.value.mnemonic);s.masterPrivateKeyNode=i.fromSeed(u,s.network);var c=s.masterPrivateKeyNode.derivePath(s.baseDerivationPath),f=t.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58();return s.masterPublicKey=M(f,n.chain),s.masterBlindingKeyNode=o.fromSeed(u),s.masterBlindingKey=s.masterBlindingKeyNode.masterKey.toString("hex"),s.isRestored=new Promise((function(){return!0})),n.initializeFromRestorer&&(s.isRestored=s.restore().catch((function(e){throw new Error("Error during restoration step: "+e)}))),s}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var a=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return a.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.isAbleToSign=function(){return!0},n.getCurrentDerivationPath=function(e){return this.baseDerivationPath+"/"+(e?1:0)},n.deriveKeyWithIndex=function(e,r){var n=this.masterPrivateKeyNode.derivePath(this.getCurrentDerivationPath(e)).derive(r).toWIF(),i=t.ECPair.fromWIF(n,this.network);return{publicKey:i.publicKey,privateKey:i.privateKey}},n.getBlindingKeyPair=function(e){var t=this.masterBlindingKeyNode.derive(e);return{publicKey:t.publicKey,privateKey:t.privateKey}},n.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output},n.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},n.persistAddressToCache=function(e){var r=Buffer.from(e.signingPrivateKey,"hex"),n=t.ECPair.fromPrivateKey(r,{network:this.network}).publicKey,i=this.scriptFromPublicKey(n);this.scriptToAddressCache.set(i,e)},n.getAddress=function(e,t){var r=this.deriveKeyWithIndex(e,t),n=this.scriptFromPublicKey(r.publicKey),i=this.getBlindingKeyPair(n);return{address:{confidentialAddress:this.createConfidentialAddress(r.publicKey,i.publicKey),blindingPrivateKey:i.privateKey.toString("hex")},derivationPath:this.baseDerivationPath+"/"+t,signingPrivateKey:r.privateKey.toString("hex")}},n.getNextAddress=function(){var e=this.getAddress(!1,this.index);return this.persistAddressToCache(e),this.index+=1,e.address},n.getNextChangeAddress=function(){var e=this.getAddress(!0,this.changeIndex);return this.persistAddressToCache(e),this.changeIndex+=1,e.address},n.getBlindingPrivateKey=function(e){var t=Buffer.from(e,"hex");return this.getBlindingKeyPair(t).privateKey.toString("hex")},n.signPset=function(){var e=d(x.mark((function e(r){var n,i,o,a,s,u,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(a=n.data.inputs[o]).witnessUtxo&&(s=this.scriptToAddressCache.get(a.witnessUtxo.script))&&(u=Buffer.from(s.signingPrivateKey,"hex"),c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c)));return e.next=5,Promise.all(i);case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getAddresses=function(){return this.scriptToAddressCache.values().map((function(e){return e.address}))},n.generateSetOfAddresses=function(){var e=d(x.mark((function e(t,r,n){var i,o,a=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",a.getAddress(n,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),o=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(o.map(i)));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(x.mark((function e(t){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.map((function(e){return e.address.confidentialAddress})),e.next=3,this.restorer.addressesHaveBeenUsed(r);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.restoreAddresses=function(){var e=d(x.mark((function e(){var t,n,i,o=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=x.mark((function e(n){var i,a,s,u,c,f,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=1===n,a=0,s=0,u=[],c=function(e){return function(t,r){a++,t&&(a=0,u.push(e[r]))}};case 5:if(!(a<20)){e.next=16;break}return e.next=8,o.generateSetOfAddresses(s,20-a,i);case 8:return f=e.sent,e.next=11,o.checkAddressesWithRestorer(f);case 11:e.sent.forEach(c(f)),s+=20,e.next=5;break;case 16:p=u.map(G),i?o.changeIndex=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX:o.index=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX,t=t.concat(u);case 19:case"end":return e.stop()}}),e)})),i=0;case 4:if(!(i<2)){e.next=9;break}return e.delegateYield(n(i),"t0",6);case 6:i++,e.next=4;break;case 9:return e.abrupt("return",t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(x.mark((function e(){var t=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.restoreAddresses();case 2:return e.sent.forEach((function(e){return t.persistAddressToCache(e)})),e.abrupt("return",!0);case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r}(H);X.INITIAL_BASE_PATH="m/84'/0'/0'",X.INITIAL_INDEX=0;var q=function(e){function r(r){var n,i;if((n=e.call(this,r)||this).isRestored=new Promise((function(){return!0})),r.type!==exports.IdentityType.PrivateKey)throw new Error("The identity arguments have not the PrivateKey type.");if(!("signingKeyWIF"in(i=r.value))||!("blindingKeyWIF"in i))throw new Error("The value of IdentityOpts is not valid for PrivateKey Identity.");n.signingKeyPair=n.decodeFromWif(r.value.signingKeyWIF),n.blindingKeyPair=n.decodeFromWif(r.value.blindingKeyWIF);var o=t.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=o.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=o.output,n}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var a=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return a.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.getBlindingKeyPair=function(e){if(!e.equals(this.scriptPubKey))throw new Error(e+" is unknown by the PrivateKey Identity");return{publicKey:this.blindingKeyPair.publicKey,privateKey:this.blindingKeyPair.privateKey}},n.isAbleToSign=function(){return!0},n.decodeFromWif=function(e){return t.ECPair.fromWIF(e,this.network)},n.getAddress=function(){return{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey}},n.getNextAddress=function(){return this.getAddress()},n.getNextChangeAddress=function(){return this.getAddress()},n.getBlindingPrivateKey=function(e){if(!Buffer.from(e,"hex").equals(this.scriptPubKey))throw new Error("The script is not PrivateKey.scriptPubKey.");return this.blindingPrivateKey},n.signPset=function(){var e=d(x.mark((function e(r){var n,i,o,a,s=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(a=n.data.inputs[o]).witnessUtxo?a.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(o):i.push(o);return e.next=5,Promise.all(i.map((function(e){return n.signInputAsync(e,s.signingKeyPair)})));case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getAddresses=function(){return[{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey}]},r}(H);function z(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}var V=function(e){function r(t){var n;(n=e.call(this,t)||this).index=r.INITIAL_INDEX,n.changeIndex=r.INITIAL_INDEX,n.scriptToAddressCache=new O;var a,s=U(t.value.masterPublicKey);if(t.type!==exports.IdentityType.MasterPublicKey)throw new Error("The identity arguments have not the MasterPublicKey type.");if(!("masterPublicKey"in(a=t.value))||!("masterBlindingKey"in a))throw new Error("The value of IdentityOpts is not valid for MasterPublicKey Identity.");if(!C(s))throw new Error("Master public key is not valid");if(!F(t.value.masterBlindingKey))throw new Error("Master blinding key is not valid");return n.masterPublicKeyNode=i.fromBase58(s),n.masterBlindingKeyNode=o.fromMasterBlindingKey(t.value.masterBlindingKey),n.isRestored=new Promise((function(){return!0})),t.initializeFromRestorer&&(n.isRestored=n.restore().catch((function(e){throw new Error("Error during restoration step: "+e)}))),n}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var a=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return a.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.isAbleToSign=function(){return!1},n.derivePublicKeyWithIndex=function(e,t){return this.masterPublicKeyNode.derive(e?1:0).derive(t).publicKey},n.getBlindingKeyPair=function(e){var t=this.masterBlindingKeyNode.derive(e);return{publicKey:t.publicKey,privateKey:t.privateKey}},n.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output},n.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},n.persistAddressToCache=function(e){var t=Buffer.from(e.publicKey,"hex"),r=this.scriptFromPublicKey(t);this.scriptToAddressCache.set(r,e)},n.getAddress=function(e,t){var r=this.derivePublicKeyWithIndex(e,t),n=this.scriptFromPublicKey(r),i=this.getBlindingKeyPair(n);return{address:{confidentialAddress:this.createConfidentialAddress(r,i.publicKey),blindingPrivateKey:i.privateKey.toString("hex")},derivationPath:(e?1:0)+"/"+t,publicKey:r.toString("hex")}},n.getNextAddress=function(){var e=this.getAddress(!1,this.index);return this.persistAddressToCache(e),this.index+=1,e.address},n.getNextChangeAddress=function(){var e=this.getAddress(!0,this.changeIndex);return this.persistAddressToCache(e),this.changeIndex+=1,e.address},n.getBlindingPrivateKey=function(e){var t=Buffer.from(e,"hex");return this.getBlindingKeyPair(t).privateKey.toString("hex")},n.signPset=function(e){throw new Error("MasterPublicKey is a watch only identity. Use Mnemonic to sign transactions")},n.getAddresses=function(){return this.scriptToAddressCache.values().map((function(e){return e.address}))},n.generateSetOfAddresses=function(){var e=d(x.mark((function e(t,r,n){var i,o,a=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",a.getAddress(n,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),o=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(o.map(i)));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(x.mark((function e(t){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.map((function(e){return e.address.confidentialAddress})),e.next=3,this.restorer.addressesHaveBeenUsed(r);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.restoreAddresses=function(){var e=d(x.mark((function e(){var t,n,i,o=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=x.mark((function e(n){var i,a,s,u,c,f,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=1===n,a=0,s=0,u=[],c=function(e){return function(t,r){a++,t&&(a=0,u.push(e[r]))}};case 5:if(!(a<20)){e.next=16;break}return e.next=8,o.generateSetOfAddresses(s,20-a,i);case 8:return f=e.sent,e.next=11,o.checkAddressesWithRestorer(f);case 11:e.sent.forEach(c(f)),s+=20,e.next=5;break;case 16:p=u.map(z),i?o.changeIndex=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX:o.index=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX,t=t.concat(u);case 19:case"end":return e.stop()}}),e)})),i=0;case 4:if(!(i<2)){e.next=9;break}return e.delegateYield(n(i),"t0",6);case 6:i++,e.next=4;break;case 9:return e.abrupt("return",t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(x.mark((function e(){var t=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.restoreAddresses();case 2:return e.sent.forEach((function(e){return t.persistAddressToCache(e)})),e.abrupt("return",!0);case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r}(H);V.INITIAL_INDEX=0;var Y=function(e,t){return e.value-t.value};function Z(e,t,r){for(var n,i=[],o=0,a=v(e=e.sort(r));!(n=a()).done;){var s=n.value;if(D(s)||(i.push(s),o+=s.value),o>=t)return{selected:i,changeAmount:o-t}}throw new Error("not enough utxos in wallet to found: "+t)}function $(e,t){return e.reduce((function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e}),{})}function J(e){return"surjectionProof"in e&&"rangeProof"in e}function Q(){return(Q=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,se([{confidentialAddress:t,blindingPrivateKey:r}],n);case 2:return e.abrupt("return",e.sent.reduce((function(e,t){var r=t.asset;return e[r]=e[r]||0,e[r]+=t.value,e}),{}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ee(e,t){return te.apply(this,arguments)}function te(){return(te=d(x.mark((function e(t,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.get(n+"/tx/"+t+"/hex");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function re(e,t){return ne.apply(this,arguments)}function ne(){return(ne=d(x.mark((function e(t,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.get(n+"/address/"+t+"/utxo");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ie(){return(ie=d(x.mark((function e(t,r,n){var i,o,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=ce(t,r,n),o=[],e.next=4,i.next();case 4:a=e.sent;case 5:if(a.done){e.next=12;break}return o.push(a.value),e.next=9,i.next();case 9:a=e.sent,e.next=5;break;case 12:return e.abrupt("return",o);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oe(e,t){return ae.apply(this,arguments)}function ae(){return(ae=c(x.mark((function e(t,r){var n,i,o,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=0,i=x.mark((function e(){var t,i,o,s,u,c,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(t=a.value).confidentialAddress,o=t.blindingPrivateKey,e.next=3,f(re(i,r));case 3:s=e.sent.map((function(e){return we(e,o,r)})),n+=s.length,u=v(s);case 7:if((c=u()).done){e.next=13;break}return p=c.value,e.next=11,p;case 11:e.next=7;break;case 13:case"end":return e.stop()}}),e)})),o=v(t);case 3:if((a=o()).done){e.next=7;break}return e.delegateYield(i(),"t0",5);case 5:e.next=3;break;case 7:return e.abrupt("return",n);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function se(e,t){return ue.apply(this,arguments)}function ue(){return(ue=d(x.mark((function e(t,r){var n,i,o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=oe(t,r),i=[],e.next=4,n.next();case 4:o=e.sent;case 5:if(o.done){e.next=12;break}return i.push(o.value),e.next=9,n.next();case 9:o=e.sent,e.next=5;break;case 12:return e.abrupt("return",i);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ce(e,t,r){return fe.apply(this,arguments)}function fe(){return(fe=c(x.mark((function e(t,r,n){var i,o,a,s,u;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=v(t);case 1:if((o=i()).done){e.next=18;break}return a=pe(o.value,n),e.next=6,f(a.next());case 6:s=e.sent;case 7:if(s.done){e.next=16;break}return u=s.value,e.next=11,le(u,r);case 11:return e.next=13,f(a.next());case 13:s=e.sent,e.next=7;break;case 16:e.next=1;break;case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function pe(e,t){return de.apply(this,arguments)}function de(){return(de=c(x.mark((function e(t,r){var n,i,o,a,s,u,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0,i=[],o=0;case 3:return e.next=5,f(be(t,r,n));case 5:o+=(i=e.sent).length,a=i.map((function(e){return xe(e,r)})),s=v(a);case 9:if((u=s()).done){e.next=15;break}return c=u.value,e.next=13,c;case 13:e.next=9;break;case 15:if(i.length<25){e.next=3;break}case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function he(e){return S(e)?{blindedAsset:e.asset,blindedValue:e.value,nonce:e.nonce,rangeProof:e.rangeProof,surjectionProof:e.surjectionProof,script:e.script.toString("hex")}:{asset:I(e.asset),value:E(e.value),script:e.script.toString("hex")}}function le(e,t){return ve.apply(this,arguments)}function ve(){return(ve=d(x.mark((function e(t,r){var n,i,o,a,s;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],i=function(e){var i=t.vin[e].prevout;J(i)&&n.push(function(){var n=d(x.mark((function n(){var o,a;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(o=r(i.script))&&(a=ye(i,o),t.vin[e].prevout=a);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},o=0;o<t.vin.length;o++)i(o);for(a=function(e){var i=t.vout[e];J(i)&&n.push(function(){var n=d(x.mark((function n(){var o,a;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(o=r(i.script))&&(a=ye(i,o),t.vout[e]=a);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},s=0;s<t.vout.length;s++)a(s);return e.next=7,Promise.all(n);case 7:return e.abrupt("return",t);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ye(e,r){var n=Buffer.from(r,"hex"),i=t.confidential.unblindOutput(e.nonce,n,e.rangeProof,e.blindedValue,e.blindedAsset,Buffer.from(e.script,"hex"));return{asset:Buffer.from(i.asset.reverse()).toString("hex"),value:parseInt(i.value,10),script:e.script}}function xe(e,t){return ge.apply(this,arguments)}function ge(){return(ge=d(x.mark((function e(r,n){var i,o,a,s,u,c,f,p,d;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],o=[],a=v(r.vin);!(s=a()).done;)i.push((u=s.value).txid),o.push(u.vout);return e.next=5,Promise.all(i.map((function(e){return ee(e,n)})));case 5:return c=e.sent.map((function(e,r){return he(t.Transaction.fromHex(e).outs[o[r]])})),f=i.map((function(e,t){return{prevout:c[t],txid:e,vout:o[t]}})),e.next=10,ee(r.txid,n);case 10:return p=t.Transaction.fromHex(e.sent),d=p.outs.map(he),e.abrupt("return",{txid:r.txid,vin:f,vout:d,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function be(e,t,r){return me.apply(this,arguments)}function me(){return(me=d(x.mark((function e(t,n,i){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n+"/address/"+t+"/txs/chain",i&&(o+="/"+i),e.next=4,r.get(o);case 4:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function we(e,t,r){return Pe.apply(this,arguments)}function Pe(){return(Pe=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,ke(t,r,n);case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",t);case 10:case"end":return e.stop()}}),e,null,[[0,7]])})))).apply(this,arguments)}function ke(e,t,r){return Ke.apply(this,arguments)}function Ke(){return(Ke=d(x.mark((function e(r,n,i){var o,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ee(r.txid,i);case 2:return o=t.Transaction.fromHex(e.sent).outs[r.vout],a=t.confidential.unblindOutput(o.nonce,Buffer.from(n,"hex"),o.rangeProof,o.value,o.asset,o.script),e.abrupt("return",{txid:r.txid,vout:r.vout,asset:a.asset.reverse().toString("hex"),value:parseInt(a.value,10),prevout:o});case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ae=function(){function e(e,t){this.network=t,this.cache=e}var r=e.prototype;return r.createTx=function(){return new t.Psbt({network:this.network}).toBase64()},r.buildTx=function(e,t,r,n,i,o){return b({psetBase64:e,recipients:t,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:o,unspents:this.cache.getAll()})},e}();function Ie(){return(Ie=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,se(t,r);case 2:return e.abrupt("return",Ee(e.sent,n));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ee(e,t){return new Ae(new Te(e),R(t))}var Te=function(){function e(e){this.utxoMap=new Map,e&&this.push(e)}var t=e.prototype;return t.push=function(e){for(var t,r=v(e);!(t=r()).done;){var n=t.value;this.utxoMap.set(W(n),n)}},t.delete=function(e){return this.utxoMap.delete(e)},t.getAll=function(){return Array.from(this.utxoMap.values())},e}();Object.defineProperty(exports,"ECPair",{enumerable:!0,get:function(){return t.ECPair}}),Object.defineProperty(exports,"address",{enumerable:!0,get:function(){return t.address}}),Object.defineProperty(exports,"networks",{enumerable:!0,get:function(){return t.networks}}),Object.defineProperty(exports,"payments",{enumerable:!0,get:function(){return t.payments}}),exports.BufferMap=O,exports.EsploraIdentityRestorer=g,exports.MasterPublicKey=V,exports.Mnemonic=X,exports.PrivateKey=q,exports.UtxoCache=Te,exports.Wallet=Ae,exports.addToTx=w,exports.buildTx=b,exports.createFeeOutput=m,exports.decodePset=P,exports.estimateTxSize=k,exports.fetchAndUnblindTxs=function(e,t,r){return ie.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=ce,exports.fetchAndUnblindUtxos=se,exports.fetchAndUnblindUtxosGenerator=oe,exports.fetchBalances=function(e,t,r){return Q.apply(this,arguments)},exports.fetchTxHex=ee,exports.fetchUtxos=re,exports.fromAssetHash=function(e){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(e,"hex").reverse()])},exports.fromXpub=M,exports.getNetwork=R,exports.greedyCoinSelector=function(e){return void 0===e&&(e=Y),function(t,r,n){return function(e,t,r,n){for(var i={selectedUtxos:[],changeOutputs:[]},o=$(e=e.filter((function(e){return!D(e)})),"asset"),a=$(t,"asset"),s=0,u=Object.entries(a);s<u.length;s++){var c,f=u[s],p=f[0],d=f[1],h=o[p];if(!h)throw new Error("need unspents for the asset: "+p);var l=Z(h,d.reduce((function(e,t){return e+t.value}),0),n),v=l.changeAmount;if((c=i.selectedUtxos).push.apply(c,l.selected),v>0){var y=r(p);if(!y)throw new Error("need change address for asset: "+p);i.changeOutputs.push({asset:p,value:v,address:y})}}return i}(t,r,n,e)}},exports.isBlindedOutputInterface=J,exports.isBlindedUtxo=D,exports.isConfidentialOutput=S,exports.isValidAmount=function(e){return!(e<=0||!Number.isSafeInteger(e))},exports.isValidExtendedBlindKey=F,exports.isValidXpub=C,exports.psetToUnsignedHex=j,exports.psetToUnsignedTx=function(e){return t.Transaction.fromHex(j(e))},exports.toAssetHash=I,exports.toNumber=E,exports.toOutpoint=W,exports.toXpub=U,exports.tryToUnblindOutput=ye,exports.tryToUnblindUtxo=we,exports.unblindOutput=function(e,r){var n={asset:Buffer.alloc(0),value:0};if(!e.rangeProof)throw new Error("The output does not contain rangeProof.");var i=t.confidential.unblindOutput(e.nonce,r,e.rangeProof,e.value,e.asset,e.script);return n.asset=Buffer.concat([Buffer.alloc(1,10),i.asset]),n.value=parseInt(i.value,10),n},exports.unblindUtxo=ke,exports.walletFromAddresses=function(e,t,r){return Ie.apply(this,arguments)},exports.walletFromCoins=Ee; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("liquidjs-lib"),r=e(require("axios")),n=e(require("bs58check")),i=require("bip32"),o=require("slip77"),s=require("bip39");function a(e){this.wrapped=e}function u(e){var t,r;function n(t,r){try{var o=e[t](r),s=o.value,u=s instanceof a;Promise.resolve(u?s.wrapped:s).then((function(e){u?n("return"===t?"return":"next",e):i(o.done?"return":"normal",e)}),(function(e){n("throw",e)}))}catch(e){i("throw",e)}}function i(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?n(t.key,t.arg):r=null}this._invoke=function(e,i){return new Promise((function(o,s){var a={key:e,arg:i,resolve:o,reject:s,next:null};r?r=r.next=a:(t=r=a,n(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function c(e){return function(){return new u(e.apply(this,arguments))}}function f(e){return new a(e)}function p(e,t,r,n,i,o,s){try{var a=e[o](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,i)}function d(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function s(e){p(o,n,i,s,a,"next",e)}function a(e){p(o,n,i,s,a,"throw",e)}s(void 0)}))}}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return l(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}"function"==typeof Symbol&&Symbol.asyncIterator&&(u.prototype[Symbol.asyncIterator]=function(){return this}),u.prototype.next=function(e){return this._invoke("next",e)},u.prototype.throw=function(e){return this._invoke("throw",e)},u.prototype.return=function(e){return this._invoke("return",e)};var y,x=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=Object.create((t&&t.prototype instanceof p?t:p).prototype),o=new k(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=m(s,r);if(a){if(a===f)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,o),i}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f={};function p(){}function d(){}function h(){}var l={};l[i]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(K([])));y&&y!==t&&r.call(y,i)&&(l=y);var x=h.prototype=p.prototype=Object.create(l);function g(e){["next","throw","return"].forEach((function(t){a(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(i,o){function s(){return new t((function(n,s){!function n(i,o,s,a){var u=c(e[i],e,o);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==typeof p&&r.call(p,"__await")?t.resolve(p.__await).then((function(e){n("next",e,s,a)}),(function(e){n("throw",e,s,a)})):t.resolve(p).then((function(e){f.value=e,s(f)}),(function(e){return n("throw",e,s,a)}))}a(u.arg)}(i,o,n,s)}))}return n=n?n.then(s,s):s()}}function m(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,m(e,t),"throw"===t.method))return f;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,f;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function K(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:A}}function A(){return{value:void 0,done:!0}}return d.prototype=x.constructor=h,h.constructor=d,d.displayName=a(h,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,a(e,s,"GeneratorFunction")),e.prototype=Object.create(x),e},e.awrap=function(e){return{__await:e}},g(b.prototype),b.prototype[o]=function(){return this},e.AsyncIterator=b,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var s=new b(u(t,r,n,i),o);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},g(x),a(x,s,"Generator"),x[i]=function(){return this},x.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=K,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:K(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(y={exports:{}}),y.exports),g=function e(t){var n=this;this.esploraEndpoint=e.DEFAULT_ESPLORA_ENDPOINT,this.addressesHaveBeenUsed=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.all(t.map(n.addressHasBeenUsed)));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),this.addressHasBeenUsed=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",r.get(n.esploraEndpoint+"/address/"+t+"/txs").then((function(e){return e.data.length>0}),(function(e){return!1})).catch((function(){return!1})));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t&&(this.esploraEndpoint=t)};function b(e){return e.slice(1).reverse().toString("hex")}function m(e){return t.confidential.confidentialValueToSatoshi(e)}g.DEFAULT_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api";var w=Buffer.from("0x00","hex");function P(e){return null!=e&&e.length>0}function k(e){var t=e.surjectionProof,r=e.nonce;return P(e.rangeProof)&&P(t)&&r!==w}var K,A=function(){function e(){this.map=new Map}var t=e.prototype;return t.bufferToStringPrimitive=function(e){return e.toString("hex").valueOf()},t.get=function(e){return this.map.get(this.bufferToStringPrimitive(e))},t.set=function(e,t){return this.map.set(this.bufferToStringPrimitive(e),t),this},t.values=function(){return Array.from(this.map.values())},e}(),I=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function E(e,t){if(!I.has(t))return"Invalid target version";e=e.trim();try{var r=n.decode(e);return r=r.slice(4),r=Buffer.concat([Buffer.from(I.get(t),"hex"),r]),n.encode(r)}catch(e){throw new Error("Invalid extended public key! Please double check that you didn't accidentally paste extra data.")}}function T(e,t){return E(e,"regtest"===t?"vpub":"zpub")}function B(e){return E(e,"xpub")}function S(e,t){try{i.fromBase58(e,t)}catch(e){return!1}return!0}function N(e){try{o.fromMasterBlindingKey(e)}catch(e){return!1}return!0}function O(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r.data.globalMap.unsignedTx.toBuffer().toString("hex")}function L(e){return{txid:e.txid,vout:e.vout}}function _(e){return!e.asset||!e.value}function M(e){return e?t.networks[e]:t.networks.liquid}function U(e){var r=function(e){if(e.satsPerByte||(e.satsPerByte=.1),e.addFee||(e.addFee=!1),e.addFee&&e.satsPerByte<.1)throw new Error("satsPerByte minimum value is 0.1");if(0===e.recipients.length)throw new Error("need a least one recipient output to build the transaction");if(0===e.unspents.length)throw new Error("need at least one unspent to fund the transaction");return e}(e),n=r.changeAddressByAsset,i=r.coinSelector,o=r.psetBase64,s=r.recipients,a=r.unspents,u=r.addFee,c=r.satsPerByte,f=i(a,s,n),p=f.selectedUtxos,d=f.changeOutputs,h=p;if(!u)return F(o,h,s.concat(d));var l=j(o),y=l.data.inputs.length+h.length,x=l.data.outputs.length+s.length+d.length,g=t.address.getNetwork(s[0].address).assetHash,b=C(y,x,c,g),m=d.findIndex((function(e){return e.asset===g})),w=-1===m?0-b.value:d[m].value-b.value;if(w>0)return d[m].value=w,F(o,h,s.concat(d).concat(b));if(0===w)return F(o,h,s.concat(b));for(var P,k=[],K=v(a);!(P=K()).done;){var A=P.value;p.includes(A)||k.push(A)}var I=C(y+1,x+1,c,g),E=i(k,[I],n);return F(o,h.concat(E.selectedUtxos),s.concat(d).concat(E.changeOutputs).concat(I))}function C(e,t,r,n){var i=W(e,t);return{asset:n,value:Math.ceil(i*r),address:""}}function F(e,r,n){for(var i,o=j(e),s=Buffer.from("00","hex"),a=v(n);!(i=a()).done;){var u=i.value,c=u.asset,f=u.value,p=u.address,d=""===p?"":t.address.toOutputScript(p);o.addOutput({asset:c,value:f,script:d,nonce:s})}for(var h,l=v(r);!(h=l()).done;){var y=h.value;o.addInput({hash:y.txid,index:y.vout,witnessUtxo:y.prevout})}return o.toBase64()}function j(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r}function W(e,t){return(3*D(!1,e,t,!1)+D(!0,e,t,!0)+3)/4}function D(e,t,r,n){var i=function(e,t){var r=40*t;return e&&(r+=105*t),r}(e,t),o=function(e,t){var r=67*t;return e&&(r+=4273*t),r+43}(n,r);return 9+R(r)+R(t)+i+o}function R(e){return e<253?1:e<=65535?3:e<=4294967295?5:9}(K=exports.IdentityType||(exports.IdentityType={}))[K.PrivateKey=1]="PrivateKey",K[K.Mnemonic=2]="Mnemonic",K[K.MasterPublicKey=3]="MasterPublicKey",K[K.Inject=4]="Inject",K[K.Ledger=5]="Ledger",K[K.Trezor=6]="Trezor";var H=function(){function e(r){if(!r.chain||!t.networks.hasOwnProperty(r.chain))throw new Error("Network is missing or not valid");if(!r.type||!(r.type in exports.IdentityType))throw new Error("Type is missing or not valid");this.network=t.networks[r.chain],this.type=r.type,this.restorer=r.restorer?r.restorer:e.DEFAULT_RESTORER}return e.prototype.blindPsetWithBlindKeysGetter=function(){var e=d(x.mark((function e(r,n,i,o,s){var a,u,c,f,p,d,h,l,y,g,b,m,w,P,K,A;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=new Map,u=new Map,c=j(n),f=t.Transaction.fromHex(O(n)),p=v(i);case 5:if((d=p()).done){e.next=16;break}if(h=d.value,!o||!o.has(h)){e.next=11;break}return l=Buffer.from(o.get(h),"hex"),u.set(h,l),e.abrupt("continue",14);case 11:y=r(f.outs[h].script).publicKey,u.set(h,y);case 14:e.next=5;break;case 16:g=0;case 17:if(!(g<c.data.inputs.length)){e.next=41;break}if(m=void 0,!(b=c.data.inputs[g]).witnessUtxo){e.next=24;break}if(k(b.witnessUtxo)){e.next=23;break}return e.abrupt("continue",38);case 23:m=b.witnessUtxo.script;case 24:if(!b.nonWitnessUtxo){e.next=30;break}if(w=f.ins[g].index,k(P=t.Transaction.fromBuffer(b.nonWitnessUtxo).outs[w])){e.next=29;break}return e.abrupt("continue",38);case 29:m=P.script;case 30:if(!s||!s.has(g)){e.next=34;break}return K=Buffer.from(s.get(g),"hex"),a.set(g,K),e.abrupt("continue",38);case 34:if(m){e.next=36;break}throw new Error("no witness script for input #"+g);case 36:A=r(m).privateKey,a.set(g,A);case 38:g++,e.next=17;break;case 41:return e.next=43,c.blindOutputsByIndex(a,u);case 43:return e.abrupt("return",e.sent.toBase64());case 45:case"end":return e.stop()}}),e)})));return function(t,r,n,i,o){return e.apply(this,arguments)}}(),e}();function G(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}H.DEFAULT_RESTORER=new g;var X=function(e){function r(n){var a;if((a=e.call(this,n)||this).baseDerivationPath=r.INITIAL_BASE_PATH,a.index=r.INITIAL_INDEX,a.changeIndex=r.INITIAL_INDEX,a.scriptToAddressCache=new A,n.type!==exports.IdentityType.Mnemonic)throw new Error("The identity arguments have not the Mnemonic type.");if(!("mnemonic"in n.value))throw new Error("The value of IdentityOpts is not valid for Mnemonic Identity.");if(s.setDefaultWordlist(n.value.language?n.value.language:"english"),!s.validateMnemonic(n.value.mnemonic))throw new Error("Mnemonic is not valid.");var u=s.mnemonicToSeedSync(n.value.mnemonic);a.masterPrivateKeyNode=i.fromSeed(u,a.network);var c=a.masterPrivateKeyNode.derivePath(a.baseDerivationPath),f=t.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58();return a.masterPublicKey=T(f,n.chain),a.masterBlindingKeyNode=o.fromSeed(u),a.masterBlindingKey=a.masterBlindingKeyNode.masterKey.toString("hex"),a.isRestored=new Promise((function(){return!0})),n.initializeFromRestorer&&(a.isRestored=a.restore().catch((function(e){throw new Error("Error during restoration step: "+e)}))),a}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var s=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return s.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.isAbleToSign=function(){return!0},n.getCurrentDerivationPath=function(e){return this.baseDerivationPath+"/"+(e?1:0)},n.deriveKeyWithIndex=function(e,r){var n=this.masterPrivateKeyNode.derivePath(this.getCurrentDerivationPath(e)).derive(r).toWIF(),i=t.ECPair.fromWIF(n,this.network);return{publicKey:i.publicKey,privateKey:i.privateKey}},n.getBlindingKeyPair=function(e){var t=this.masterBlindingKeyNode.derive(e);return{publicKey:t.publicKey,privateKey:t.privateKey}},n.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output},n.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},n.persistAddressToCache=function(e){var r=Buffer.from(e.signingPrivateKey,"hex"),n=t.ECPair.fromPrivateKey(r,{network:this.network}).publicKey,i=this.scriptFromPublicKey(n);this.scriptToAddressCache.set(i,e)},n.getAddress=function(e,t){var r=this.deriveKeyWithIndex(e,t),n=this.scriptFromPublicKey(r.publicKey),i=this.getBlindingKeyPair(n);return{address:{confidentialAddress:this.createConfidentialAddress(r.publicKey,i.publicKey),blindingPrivateKey:i.privateKey.toString("hex")},derivationPath:this.baseDerivationPath+"/"+t,signingPrivateKey:r.privateKey.toString("hex")}},n.getNextAddress=function(){var e=this.getAddress(!1,this.index);return this.persistAddressToCache(e),this.index+=1,e.address},n.getNextChangeAddress=function(){var e=this.getAddress(!0,this.changeIndex);return this.persistAddressToCache(e),this.changeIndex+=1,e.address},n.getBlindingPrivateKey=function(e){var t=Buffer.from(e,"hex");return this.getBlindingKeyPair(t).privateKey.toString("hex")},n.signPset=function(){var e=d(x.mark((function e(r){var n,i,o,s,a,u,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo&&(a=this.scriptToAddressCache.get(s.witnessUtxo.script))&&(u=Buffer.from(a.signingPrivateKey,"hex"),c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(o,c)));return e.next=5,Promise.all(i);case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getAddresses=function(){return this.scriptToAddressCache.values().map((function(e){return e.address}))},n.generateSetOfAddresses=function(){var e=d(x.mark((function e(t,r,n){var i,o,s=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(n,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),o=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(o.map(i)));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(x.mark((function e(t){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.map((function(e){return e.address.confidentialAddress})),e.next=3,this.restorer.addressesHaveBeenUsed(r);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.restoreAddresses=function(){var e=d(x.mark((function e(){var t,n,i,o=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=x.mark((function e(n){var i,s,a,u,c,f,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=1===n,s=0,a=0,u=[],c=function(e){return function(t,r){s++,t&&(s=0,u.push(e[r]))}};case 5:if(!(s<20)){e.next=16;break}return e.next=8,o.generateSetOfAddresses(a,20-s,i);case 8:return f=e.sent,e.next=11,o.checkAddressesWithRestorer(f);case 11:e.sent.forEach(c(f)),a+=20,e.next=5;break;case 16:p=u.map(G),i?o.changeIndex=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX:o.index=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX,t=t.concat(u);case 19:case"end":return e.stop()}}),e)})),i=0;case 4:if(!(i<2)){e.next=9;break}return e.delegateYield(n(i),"t0",6);case 6:i++,e.next=4;break;case 9:return e.abrupt("return",t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(x.mark((function e(){var t=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.restoreAddresses();case 2:return e.sent.forEach((function(e){return t.persistAddressToCache(e)})),e.abrupt("return",!0);case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r}(H);X.INITIAL_BASE_PATH="m/84'/0'/0'",X.INITIAL_INDEX=0;var q=function(e){function r(r){var n,i;if((n=e.call(this,r)||this).isRestored=new Promise((function(){return!0})),r.type!==exports.IdentityType.PrivateKey)throw new Error("The identity arguments have not the PrivateKey type.");if(!("signingKeyWIF"in(i=r.value))||!("blindingKeyWIF"in i))throw new Error("The value of IdentityOpts is not valid for PrivateKey Identity.");n.signingKeyPair=n.decodeFromWif(r.value.signingKeyWIF),n.blindingKeyPair=n.decodeFromWif(r.value.blindingKeyWIF);var o=t.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=o.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=o.output,n}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var s=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return s.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.getBlindingKeyPair=function(e){if(!e.equals(this.scriptPubKey))throw new Error(e+" is unknown by the PrivateKey Identity");return{publicKey:this.blindingKeyPair.publicKey,privateKey:this.blindingKeyPair.privateKey}},n.isAbleToSign=function(){return!0},n.decodeFromWif=function(e){return t.ECPair.fromWIF(e,this.network)},n.getAddress=function(){return{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey}},n.getNextAddress=function(){return this.getAddress()},n.getNextChangeAddress=function(){return this.getAddress()},n.getBlindingPrivateKey=function(e){if(!Buffer.from(e,"hex").equals(this.scriptPubKey))throw new Error("The script is not PrivateKey.scriptPubKey.");return this.blindingPrivateKey},n.signPset=function(){var e=d(x.mark((function e(r){var n,i,o,s,a=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],o=0;o<n.data.inputs.length;o++)(s=n.data.inputs[o]).witnessUtxo?s.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(o):i.push(o);return e.next=5,Promise.all(i.map((function(e){return n.signInputAsync(e,a.signingKeyPair)})));case 5:return e.abrupt("return",n.toBase64());case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getAddresses=function(){return[{confidentialAddress:this.confidentialAddress,blindingPrivateKey:this.blindingPrivateKey}]},r}(H);function z(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}var V=function(e){function r(t){var n;(n=e.call(this,t)||this).index=r.INITIAL_INDEX,n.changeIndex=r.INITIAL_INDEX,n.scriptToAddressCache=new A;var s,a=B(t.value.masterPublicKey);if(t.type!==exports.IdentityType.MasterPublicKey)throw new Error("The identity arguments have not the MasterPublicKey type.");if(!("masterPublicKey"in(s=t.value))||!("masterBlindingKey"in s))throw new Error("The value of IdentityOpts is not valid for MasterPublicKey Identity.");if(!S(a))throw new Error("Master public key is not valid");if(!N(t.value.masterBlindingKey))throw new Error("Master blinding key is not valid");return n.masterPublicKeyNode=i.fromBase58(a),n.masterBlindingKeyNode=o.fromMasterBlindingKey(t.value.masterBlindingKey),n.isRestored=new Promise((function(){return!0})),t.initializeFromRestorer&&(n.isRestored=n.restore().catch((function(e){throw new Error("Error during restoration step: "+e)}))),n}h(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(x.mark((function t(r,n,i,o){var s=this;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return s.getBlindingKeyPair(e)}),r,n,i,o));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r,n,i){return t.apply(this,arguments)}}(),n.isAbleToSign=function(){return!1},n.derivePublicKeyWithIndex=function(e,t){return this.masterPublicKeyNode.derive(e?1:0).derive(t).publicKey},n.getBlindingKeyPair=function(e){var t=this.masterBlindingKeyNode.derive(e);return{publicKey:t.publicKey,privateKey:t.privateKey}},n.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output},n.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},n.persistAddressToCache=function(e){var t=Buffer.from(e.publicKey,"hex"),r=this.scriptFromPublicKey(t);this.scriptToAddressCache.set(r,e)},n.getAddress=function(e,t){var r=this.derivePublicKeyWithIndex(e,t),n=this.scriptFromPublicKey(r),i=this.getBlindingKeyPair(n);return{address:{confidentialAddress:this.createConfidentialAddress(r,i.publicKey),blindingPrivateKey:i.privateKey.toString("hex")},derivationPath:(e?1:0)+"/"+t,publicKey:r.toString("hex")}},n.getNextAddress=function(){var e=this.getAddress(!1,this.index);return this.persistAddressToCache(e),this.index+=1,e.address},n.getNextChangeAddress=function(){var e=this.getAddress(!0,this.changeIndex);return this.persistAddressToCache(e),this.changeIndex+=1,e.address},n.getBlindingPrivateKey=function(e){var t=Buffer.from(e,"hex");return this.getBlindingKeyPair(t).privateKey.toString("hex")},n.signPset=function(e){throw new Error("MasterPublicKey is a watch only identity. Use Mnemonic to sign transactions")},n.getAddresses=function(){return this.scriptToAddressCache.values().map((function(e){return e.address}))},n.generateSetOfAddresses=function(){var e=d(x.mark((function e(t,r,n){var i,o,s=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=d(x.mark((function e(t){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(n,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),o=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(o.map(i)));case 3:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(x.mark((function e(t){var r;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.map((function(e){return e.address.confidentialAddress})),e.next=3,this.restorer.addressesHaveBeenUsed(r);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.restoreAddresses=function(){var e=d(x.mark((function e(){var t,n,i,o=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=x.mark((function e(n){var i,s,a,u,c,f,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=1===n,s=0,a=0,u=[],c=function(e){return function(t,r){s++,t&&(s=0,u.push(e[r]))}};case 5:if(!(s<20)){e.next=16;break}return e.next=8,o.generateSetOfAddresses(a,20-s,i);case 8:return f=e.sent,e.next=11,o.checkAddressesWithRestorer(f);case 11:e.sent.forEach(c(f)),a+=20,e.next=5;break;case 16:p=u.map(z),i?o.changeIndex=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX:o.index=p.length>0?Math.max.apply(Math,p)+1:r.INITIAL_INDEX,t=t.concat(u);case 19:case"end":return e.stop()}}),e)})),i=0;case 4:if(!(i<2)){e.next=9;break}return e.delegateYield(n(i),"t0",6);case 6:i++,e.next=4;break;case 9:return e.abrupt("return",t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(x.mark((function e(){var t=this;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.restoreAddresses();case 2:return e.sent.forEach((function(e){return t.persistAddressToCache(e)})),e.abrupt("return",!0);case 5:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r}(H);V.INITIAL_INDEX=0;var Y=function(e,t){return e.value-t.value};function Z(e,t,r){for(var n,i=[],o=0,s=v(e=e.sort(r));!(n=s()).done;){var a=n.value;if(_(a)||(i.push(a),o+=a.value),o>=t)return{selected:i,changeAmount:o-t}}throw new Error("not enough utxos in wallet to found: "+t)}function $(e,t){return e.reduce((function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e}),{})}function J(e){return"surjectionProof"in e&&"rangeProof"in e}function Q(){return(Q=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ae([{confidentialAddress:t,blindingPrivateKey:r}],n);case 2:return e.abrupt("return",e.sent.reduce((function(e,t){var r=t.asset;return e[r]=e[r]||0,e[r]+=t.value,e}),{}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ee(e,t){return te.apply(this,arguments)}function te(){return(te=d(x.mark((function e(t,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.get(n+"/tx/"+t+"/hex");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function re(e,t){return ne.apply(this,arguments)}function ne(){return(ne=d(x.mark((function e(t,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.get(n+"/address/"+t+"/utxo");case 2:return e.abrupt("return",e.sent.data);case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ie(){return(ie=d(x.mark((function e(t,r,n){var i,o,s;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=ce(t,r,n),o=[],e.next=4,i.next();case 4:s=e.sent;case 5:if(s.done){e.next=12;break}return o.push(s.value),e.next=9,i.next();case 9:s=e.sent,e.next=5;break;case 12:return e.abrupt("return",o);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oe(e,t){return se.apply(this,arguments)}function se(){return(se=c(x.mark((function e(t,r){var n,i,o,s;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=0,i=x.mark((function e(){var t,i,o,a,u,c,p;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(t=s.value).confidentialAddress,o=t.blindingPrivateKey,e.next=3,f(re(i,r));case 3:a=e.sent.map((function(e){return Pe(e,o,r)})),n+=a.length,u=v(a);case 7:if((c=u()).done){e.next=13;break}return p=c.value,e.next=11,p;case 11:e.next=7;break;case 13:case"end":return e.stop()}}),e)})),o=v(t);case 3:if((s=o()).done){e.next=7;break}return e.delegateYield(i(),"t0",5);case 5:e.next=3;break;case 7:return e.abrupt("return",n);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ae(e,t){return ue.apply(this,arguments)}function ue(){return(ue=d(x.mark((function e(t,r){var n,i,o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=oe(t,r),i=[],e.next=4,n.next();case 4:o=e.sent;case 5:if(o.done){e.next=12;break}return i.push(o.value),e.next=9,n.next();case 9:o=e.sent,e.next=5;break;case 12:return e.abrupt("return",i);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ce(e,t,r){return fe.apply(this,arguments)}function fe(){return(fe=c(x.mark((function e(t,r,n){var i,o,s,a,u;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=v(t);case 1:if((o=i()).done){e.next=18;break}return s=pe(o.value,n),e.next=6,f(s.next());case 6:a=e.sent;case 7:if(a.done){e.next=16;break}return u=a.value,e.next=11,le(u,r);case 11:return e.next=13,f(s.next());case 13:a=e.sent,e.next=7;break;case 16:e.next=1;break;case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function pe(e,t){return de.apply(this,arguments)}function de(){return(de=c(x.mark((function e(t,r){var n,i,o,s,a,u,c;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0,i=[],o=0;case 3:return e.next=5,f(me(t,r,n));case 5:o+=(i=e.sent).length,s=i.map((function(e){return ge(e,r)})),a=v(s);case 9:if((u=a()).done){e.next=15;break}return c=u.value,e.next=13,c;case 13:e.next=9;break;case 15:if(i.length<25){e.next=3;break}case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function he(e){return k(e)?{blindedAsset:e.asset,blindedValue:e.value,nonce:e.nonce,rangeProof:e.rangeProof,surjectionProof:e.surjectionProof,script:e.script.toString("hex")}:{asset:b(e.asset),value:m(e.value),script:e.script.toString("hex")}}function le(e,t){return ve.apply(this,arguments)}function ve(){return(ve=d(x.mark((function e(t,r){var n,i,o,s,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],i=function(e){var i=t.vin[e].prevout;J(i)&&n.push(function(){var n=d(x.mark((function n(){var o;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(o=r(i.script))){n.next=6;break}return n.next=4,ye(i,o);case 4:t.vin[e].prevout=n.sent;case 6:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},o=0;o<t.vin.length;o++)i(o);for(s=function(e){var i=t.vout[e];J(i)&&n.push(function(){var n=d(x.mark((function n(){var o;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!(o=r(i.script))){n.next=6;break}return n.next=4,ye(i,o);case 4:t.vout[e]=n.sent;case 6:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},a=0;a<t.vout.length;a++)s(a);return e.next=7,Promise.all(n);case 7:return e.abrupt("return",t);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ye(e,t){return xe.apply(this,arguments)}function xe(){return(xe=d(x.mark((function e(r,n){var i,o,s,a;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={asset:r.blindedAsset,value:r.blindedValue,rangeProof:r.rangeProof,surjectionProof:r.surjectionProof,nonce:r.nonce,script:Buffer.from(r.script,"hex")},o=Buffer.from(n,"hex"),e.next=4,t.confidential.unblindOutputWithKey(i,o);case 4:return s=e.sent,a={asset:Buffer.from(s.asset.reverse()).toString("hex"),value:parseInt(s.value,10),script:r.script},e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ge(e,t){return be.apply(this,arguments)}function be(){return(be=d(x.mark((function e(r,n){var i,o,s,a,u,c,f,p,d;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],o=[],s=v(r.vin);!(a=s()).done;)i.push((u=a.value).txid),o.push(u.vout);return e.next=5,Promise.all(i.map((function(e){return ee(e,n)})));case 5:return c=e.sent.map((function(e,r){return he(t.Transaction.fromHex(e).outs[o[r]])})),f=i.map((function(e,t){return{prevout:c[t],txid:e,vout:o[t]}})),e.next=10,ee(r.txid,n);case 10:return p=t.Transaction.fromHex(e.sent),d=p.outs.map(he),e.abrupt("return",{txid:r.txid,vin:f,vout:d,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function me(e,t,r){return we.apply(this,arguments)}function we(){return(we=d(x.mark((function e(t,n,i){var o;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n+"/address/"+t+"/txs/chain",i&&(o+="/"+i),e.next=4,r.get(o);case 4:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pe(e,t,r){return ke.apply(this,arguments)}function ke(){return(ke=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Ke(t,r,n);case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",t);case 10:case"end":return e.stop()}}),e,null,[[0,7]])})))).apply(this,arguments)}function Ke(e,t,r){return Ae.apply(this,arguments)}function Ae(){return(Ae=d(x.mark((function e(r,n,i){var o,s;return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ee(r.txid,i);case 2:return o=t.Transaction.fromHex(e.sent).outs[r.vout],e.next=6,t.confidential.unblindOutputWithKey(o,Buffer.from(n,"hex"));case 6:return e.abrupt("return",{txid:r.txid,vout:r.vout,asset:(s=e.sent).asset.reverse().toString("hex"),value:parseInt(s.value,10),prevout:o});case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ie=function(){function e(e,t){this.network=t,this.cache=e}var r=e.prototype;return r.createTx=function(){return new t.Psbt({network:this.network}).toBase64()},r.buildTx=function(e,t,r,n,i,o){return U({psetBase64:e,recipients:t,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:o,unspents:this.cache.getAll()})},e}();function Ee(){return(Ee=d(x.mark((function e(t,r,n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ae(t,r);case 2:return e.abrupt("return",Te(e.sent,n));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Te(e,t){return new Ie(new Be(e),M(t))}var Be=function(){function e(e){this.utxoMap=new Map,e&&this.push(e)}var t=e.prototype;return t.push=function(e){for(var t,r=v(e);!(t=r()).done;){var n=t.value;this.utxoMap.set(L(n),n)}},t.delete=function(e){return this.utxoMap.delete(e)},t.getAll=function(){return Array.from(this.utxoMap.values())},e}();Object.defineProperty(exports,"ECPair",{enumerable:!0,get:function(){return t.ECPair}}),Object.defineProperty(exports,"address",{enumerable:!0,get:function(){return t.address}}),Object.defineProperty(exports,"networks",{enumerable:!0,get:function(){return t.networks}}),Object.defineProperty(exports,"payments",{enumerable:!0,get:function(){return t.payments}}),exports.BufferMap=A,exports.EsploraIdentityRestorer=g,exports.MasterPublicKey=V,exports.Mnemonic=X,exports.PrivateKey=q,exports.UtxoCache=Be,exports.Wallet=Ie,exports.addToTx=F,exports.buildTx=U,exports.createFeeOutput=C,exports.decodePset=j,exports.estimateTxSize=W,exports.fetchAndUnblindTxs=function(e,t,r){return ie.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=ce,exports.fetchAndUnblindUtxos=ae,exports.fetchAndUnblindUtxosGenerator=oe,exports.fetchBalances=function(e,t,r){return Q.apply(this,arguments)},exports.fetchTxHex=ee,exports.fetchUtxos=re,exports.fromAssetHash=function(e){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(e,"hex").reverse()])},exports.fromXpub=T,exports.getNetwork=M,exports.greedyCoinSelector=function(e){return void 0===e&&(e=Y),function(t,r,n){return function(e,t,r,n){for(var i={selectedUtxos:[],changeOutputs:[]},o=$(e=e.filter((function(e){return!_(e)})),"asset"),s=$(t,"asset"),a=0,u=Object.entries(s);a<u.length;a++){var c,f=u[a],p=f[0],d=f[1],h=o[p];if(!h)throw new Error("need unspents for the asset: "+p);var l=Z(h,d.reduce((function(e,t){return e+t.value}),0),n),v=l.changeAmount;if((c=i.selectedUtxos).push.apply(c,l.selected),v>0){var y=r(p);if(!y)throw new Error("need change address for asset: "+p);i.changeOutputs.push({asset:p,value:v,address:y})}}return i}(t,r,n,e)}},exports.isBlindedOutputInterface=J,exports.isBlindedUtxo=_,exports.isConfidentialOutput=k,exports.isValidAmount=function(e){return!(e<=0||!Number.isSafeInteger(e))},exports.isValidExtendedBlindKey=N,exports.isValidXpub=S,exports.psetToUnsignedHex=O,exports.psetToUnsignedTx=function(e){return t.Transaction.fromHex(O(e))},exports.toAssetHash=b,exports.toNumber=m,exports.toOutpoint=L,exports.toXpub=B,exports.tryToUnblindUtxo=Pe,exports.unblindOutput=ye,exports.unblindUtxo=Ke,exports.walletFromAddresses=function(e,t,r){return Ee.apply(this,arguments)},exports.walletFromCoins=Te; | ||
//# sourceMappingURL=ldk.cjs.production.min.js.map |
/// <reference types="node" /> | ||
import { UtxoInterface, Outpoint } from './types'; | ||
import { Network, TxOutput, Transaction } from 'liquidjs-lib'; | ||
import { Network, Transaction } from 'liquidjs-lib'; | ||
import { Outpoint, UtxoInterface } from './types'; | ||
export declare function toAssetHash(x: Buffer): string; | ||
@@ -16,8 +16,2 @@ export declare function fromAssetHash(x: string): Buffer; | ||
/** | ||
* Unblind an output using confidential.unblindOutput function from liquidjs-lib. | ||
* @param output the output to unblind. | ||
* @param blindKey the private blinding key. | ||
*/ | ||
export declare function unblindOutput(output: TxOutput, blindKey: Buffer): UnblindResult; | ||
/** | ||
* Checks if a given output is a confidential one. | ||
@@ -24,0 +18,0 @@ * @param output the ouput to check. |
{ | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -84,5 +84,5 @@ "main": "dist/index.js", | ||
"bs58check": "^2.1.2", | ||
"liquidjs-lib": "vulpemventures/liquidjs-lib", | ||
"slip77": "vulpemventures/slip77" | ||
"liquidjs-lib": "^5.1.6", | ||
"slip77": "^0.1.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 2 instances in 1 package
6828
0
762909
+ Added@types/node@13.13.52(transitive)
+ Added@vulpemventures/secp256k1-zkp@2.2.0(transitive)
+ Addedbech32@1.1.4(transitive)
+ Addedbip174-liquid@1.0.3(transitive)
+ Addedbip66@1.1.5(transitive)
+ Addedbitcoin-ops@1.4.1(transitive)
+ Addedblech32@1.1.2(transitive)
+ Addedliquidjs-lib@5.2.3(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedmerkle-lib@2.0.10(transitive)
+ Addedpushdata-bitcoin@1.0.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedslip77@0.1.1(transitive)
+ Addedvaruint-bitcoin@1.1.2(transitive)
Updatedliquidjs-lib@^5.1.6
Updatedslip77@^0.1.1