Comparing version 0.1.3 to 0.1.4
@@ -1,8 +0,14 @@ | ||
export { networks, address } from 'liquidjs-lib'; | ||
export * from './identity'; | ||
export * from './identities/mnemonic'; | ||
export * from './identities/privatekey'; | ||
export * from './identities/masterpubkey'; | ||
export { networks, address, payments, ECPair } from 'liquidjs-lib'; | ||
export * from './identity/identity'; | ||
export * from './identity/mnemonic'; | ||
export * from './identity/privatekey'; | ||
export * from './identity/masterpubkey'; | ||
export * from './identity/identityRestorer'; | ||
export * from './coinselection/coinSelector'; | ||
export * from './coinselection/greedy'; | ||
export * from './explorer/types'; | ||
export * from './explorer/esplora'; | ||
export * from './transaction'; | ||
export * from './wallet'; | ||
export * from './identityRestorer'; | ||
export * from './utils'; | ||
export * from './types'; |
@@ -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=require("bip39"),i=require("slip77"),s=require("bip32"),o=e(require("bs58check"));function a(e){this.wrapped=e}function u(e){var t,r;function n(t,r){try{var s=e[t](r),o=s.value,u=o instanceof a;Promise.resolve(u?o.wrapped:o).then((function(e){u?n("return"===t?"return":"next",e):i(s.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(s,o){var a={key:e,arg:i,resolve:s,reject:o,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,s,o){try{var a=e[s](o),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 s=e.apply(t,r);function o(e){p(s,n,i,o,a,"next",e)}function a(e){p(s,n,i,o,a,"throw",e)}o(void 0)}))}}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=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,g=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",o=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),s=new k(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,s){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw s;return{value:void 0,done:!0}}for(r.method=i,r.arg=s;;){var o=r.delegate;if(o){var a=b(o,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,s),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 m(e,t){var n;this._invoke=function(i,s){function o(){return new t((function(n,o){!function n(i,s,o,a){var u=c(e[i],e,s);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,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(p).then((function(e){f.value=e,o(f)}),(function(e){return n("throw",e,o,a)}))}a(u.arg)}(i,s,n,o)}))}return n=n?n.then(o,o):o()}}function b(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,b(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,s=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 s.next=s}}return{next:A}}function A(){return{value:void 0,done:!0}}return d.prototype=x.constructor=h,h.constructor=d,d.displayName=a(h,o,"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,o,"GeneratorFunction")),e.prototype=Object.create(x),e},e.awrap=function(e){return{__await:e}},g(m.prototype),m.prototype[s]=function(){return this},e.AsyncIterator=m,e.async=function(t,r,n,i,s){void 0===s&&(s=Promise);var o=new m(u(t,r,n,i),s);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},g(x),a(x,o,"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 o.type="throw",o.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 s=this.tryEntries[i],o=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var a=r.call(s,"catchLoc"),u=r.call(s,"finallyLoc");if(a&&u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(a){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.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 s=i;break}}s&&("break"===e||"continue"===e)&&s.tryLoc<=t&&t<=s.finallyLoc&&(s=null);var o=s?s.completion:{};return o.type=e,o.arg=t,s?(this.method="next",this.next=s.finallyLoc,f):this.complete(o)},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)}}(x={exports:{}}),x.exports),m=function e(t){var n=this;this.esploraEndpoint=e.DEFAULT_ESPLORA_ENDPOINT,this.addressesHaveBeenUsed=function(){var e=d(g.mark((function e(t){return g.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(g.mark((function e(t){return g.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)};m.DEFAULT_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api",(y=exports.IdentityType||(exports.IdentityType={}))[y.PrivateKey=1]="PrivateKey",y[y.Mnemonic=2]="Mnemonic",y[y.MasterPublicKey=3]="MasterPublicKey",y[y.Inject=4]="Inject",y[y.Ledger=5]="Ledger",y[y.Trezor=6]="Trezor";var b=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};function w(e){return e.slice(1).reverse().toString("hex")}function P(e){return t.confidential.confidentialValueToSatoshi(e)}function k(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}b.DEFAULT_RESTORER=new m;var K=Buffer.from("0x00","hex");function A(e){return null!=e&&e.length>0}function I(e){return A(e.rangeProof)&&A(e.surjectionProof)&&e.nonce!==K}var T=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}(),E=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function B(e,t){if(!E.has(t))return"Invalid target version";e=e.trim();try{var r=o.decode(e);return r=r.slice(4),r=Buffer.concat([Buffer.from(E.get(t),"hex"),r]),o.encode(r)}catch(e){throw new Error("Invalid extended public key! Please double check that you didn't accidentally paste extra data.")}}function S(e,t){return B(e,"regtest"===t?"vpub":"zpub")}function O(e){return B(e,"xpub")}function N(e,t){try{s.fromBase58(e,t)}catch(e){return!1}return!0}function L(e){try{i.fromMasterBlindingKey(e)}catch(e){return!1}return!0}function _(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}var C=function(e){function r(o){var a;if((a=e.call(this,o)||this).baseDerivationPath=r.INITIAL_BASE_PATH,a.index=r.INITIAL_INDEX,a.changeIndex=r.INITIAL_INDEX,a.scriptToAddressCache=new T,o.type!==exports.IdentityType.Mnemonic)throw new Error("The identity arguments have not the Mnemonic type.");if(!("mnemonic"in o.value))throw new Error("The value of IdentityOpts is not valid for Mnemonic Identity.");if(n.setDefaultWordlist(o.value.language?o.value.language:"english"),!n.validateMnemonic(o.value.mnemonic))throw new Error("Mnemonic is not valid.");var u=n.mnemonicToSeedSync(o.value.mnemonic);a.masterPrivateKeyNode=s.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=S(f,o.chain),a.masterBlindingKeyNode=i.fromSeed(u),a.masterBlindingKey=a.masterBlindingKeyNode.masterKey.toString("hex"),a.isRestored=new Promise((function(){return!0})),o.initializeFromRestorer&&(a.isRestored=a.restore().catch((function(e){throw new Error("Error during restoration step: "+e)}))),a}h(r,e);var o=r.prototype;return o.isAbleToSign=function(){return!0},o.getCurrentDerivationPath=function(e){return this.baseDerivationPath+"/"+(e?1:0)},o.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}},o.getBlindingKeyPair=function(e){var t=this.masterBlindingKeyNode.derive(e);return{publicKey:t.publicKey,privateKey:t.privateKey}},o.scriptFromPublicKey=function(e){return t.payments.p2wpkh({pubkey:e,network:this.network}).output},o.createConfidentialAddress=function(e,r){return t.payments.p2wpkh({pubkey:e,blindkey:r,network:this.network}).confidentialAddress},o.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)},o.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")}},o.getNextAddress=function(){var e=this.getAddress(!1,this.index);return this.persistAddressToCache(e),this.index+=1,e.address},o.getNextChangeAddress=function(){var e=this.getAddress(!0,this.changeIndex);return this.persistAddressToCache(e),this.changeIndex+=1,e.address},o.getBlindingPrivateKey=function(e){var t=Buffer.from(e,"hex");return this.getBlindingKeyPair(t).privateKey.toString("hex")},o.signPset=function(){var e=d(g.mark((function e(r){var n,i,s,o,a,u,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],s=0;s<n.data.inputs.length;s++)(o=n.data.inputs[s]).witnessUtxo&&(a=this.scriptToAddressCache.get(o.witnessUtxo.script))&&(u=Buffer.from(a.signingPrivateKey,"hex"),c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(s,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)}}(),o.getAddresses=function(){return this.scriptToAddressCache.values().map((function(e){return e.address}))},o.generateSetOfAddresses=function(){var e=d(g.mark((function e(t,r){var n,i,s=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=function(){var e=d(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(!1,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(i.map(n)));case 3:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),o.addressToChangeAddressAsync=function(){var e=d(g.mark((function e(t){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=_(t),e.abrupt("return",this.getAddress(!0,r));case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o.checkAddressesWithRestorer=function(){var e=d(g.mark((function e(t){var r;return g.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)}}(),o.restoreAddresses=function(){var e=d(g.mark((function e(){var t,n,i,s,o,a,u,c,f,p,d,h=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=20,n=0,i=0,s=[],o=function(e){return function(t,r){!0===t?(n=0,s.push(e[r])):n+=1}};case 5:if(!(n<t)){e.next=16;break}return e.next=8,this.generateSetOfAddresses(i,t-n);case 8:return a=e.sent,e.next=11,this.checkAddressesWithRestorer(a);case 11:e.sent.forEach(o(a)),i+=t,e.next=5;break;case 16:return u=s.map(_),this.index=u.length>0?Math.max.apply(Math,u)+1:r.INITIAL_INDEX,e.next=20,Promise.all(s.map((function(e){return h.addressToChangeAddressAsync(e)})));case 20:return c=e.sent,e.next=23,this.checkAddressesWithRestorer(c);case 23:return f=e.sent,p=c.filter((function(e,t){return f[t]})),d=p.map(_),this.changeIndex=d.length>0?Math.max.apply(Math,d)+1:r.INITIAL_INDEX,s.push.apply(s,p),e.abrupt("return",s);case 29:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.restore=function(){var e=d(g.mark((function e(){var t=this;return g.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}(b);C.INITIAL_BASE_PATH="m/84'/0'/0'",C.INITIAL_INDEX=0;var M=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 s=t.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=s.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=s.output,n}h(r,e);var n=r.prototype;return 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(g.mark((function e(r){var n,i,s,o,a=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],s=0;s<n.data.inputs.length;s++)(o=n.data.inputs[s]).witnessUtxo?o.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(s):i.push(s);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}(b);function U(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}var F=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 T;var o,a=O(t.value.masterPublicKey);if(t.type!==exports.IdentityType.MasterPublicKey)throw new Error("The identity arguments have not the MasterPublicKey type.");if(!("masterPublicKey"in(o=t.value))||!("masterBlindingKey"in o))throw new Error("The value of IdentityOpts is not valid for MasterPublicKey Identity.");if(!N(a))throw new Error("Master public key is not valid");if(!L(t.value.masterBlindingKey))throw new Error("Master blinding key is not valid");return n.masterPublicKeyNode=s.fromBase58(a),n.masterBlindingKeyNode=i.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.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(g.mark((function e(t,r){var n,i,s=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=function(){var e=d(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(!1,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(i.map(n)));case 3:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),n.addressToChangeAddressAsync=function(){var e=d(g.mark((function e(t){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=U(t),e.abrupt("return",this.getAddress(!0,r));case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(g.mark((function e(t){var r;return g.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(g.mark((function e(){var t,n,i,s,o,a,u,c,f,p,d,h=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=20,n=0,i=0,s=[],o=function(e){return function(t,r){!0===t?(n=0,s.push(e[r])):n+=1}};case 5:if(!(n<t)){e.next=16;break}return e.next=8,this.generateSetOfAddresses(i,t-n);case 8:return a=e.sent,e.next=11,this.checkAddressesWithRestorer(a);case 11:e.sent.forEach(o(a)),i+=t,e.next=5;break;case 16:return u=s.map(U),this.index=u.length>0?Math.max.apply(Math,u)+1:r.INITIAL_INDEX,e.next=20,Promise.all(s.map((function(e){return h.addressToChangeAddressAsync(e)})));case 20:return c=e.sent,e.next=23,this.checkAddressesWithRestorer(c);case 23:return f=e.sent,p=c.filter((function(e,t){return f[t]})),d=p.map(U),this.changeIndex=d.length>0?Math.max.apply(Math,d)+1:r.INITIAL_INDEX,s.push.apply(s,p),e.abrupt("return",s);case 29:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(g.mark((function e(){var t=this;return g.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}(b);F.INITIAL_INDEX=0;var j=function(){function e(e){var r=this,n=e.addresses,i=e.network;this.addresses=[],this.blindingPrivateKeyByScript={},this.network=i,this.addresses=n,n.forEach((function(e){var n=t.address.toOutputScript(e.confidentialAddress,i).toString("hex");r.blindingPrivateKeyByScript[n]=Buffer.from(e.blindingPrivateKey,"hex")}))}var r=e.prototype;return r.createTx=function(){return new t.Psbt({network:this.network}).toBase64()},r.buildTx=function(e,r,n,i,s,o,a){var u=this;void 0===a&&(a=.1);var c=R(e),f=[],p=[],d=Math.ceil(ve(1,2)*a),h=d;if(s===this.network.assetHash){h+=i;var l=t.address.toOutputScript(n,this.network).toString("hex");c.addOutput({script:l,value:t.confidential.satoshiToConfidentialValue(i),asset:this.network.assetHash,nonce:Buffer.from("00","hex")}),p.push(t.address.fromConfidential(n).blindingKey)}else{var v=le(r,i,s,this.blindingPrivateKeyByScript),y=v.change;v.selectedUnspents.forEach((function(e){c.addInput({hash:e.txid,index:e.vout,witnessUtxo:e.prevout});var t=e.prevout.script.toString("hex");f.push(u.blindingPrivateKeyByScript[t])}));var x=t.address.toOutputScript(n,this.network).toString("hex");if(c.addOutput({script:x,value:t.confidential.satoshiToConfidentialValue(i),asset:s,nonce:Buffer.from("00","hex")}),p.push(t.address.fromConfidential(n).blindingKey),y>0){var g=t.address.toOutputScript(o,this.network).toString("hex");c.addOutput({script:g,value:t.confidential.satoshiToConfidentialValue(y),asset:s,nonce:Buffer.from("00","hex")}),p.push(t.address.fromConfidential(o).blindingKey)}}var m=le(r,h,this.network.assetHash,this.blindingPrivateKeyByScript),b=m.change;if(m.selectedUnspents.forEach((function(e){c.addInput({hash:e.txid,index:e.vout,witnessUtxo:e.prevout});var t=e.prevout.script.toString("hex");f.push(u.blindingPrivateKeyByScript[t])})),b>0){var w=t.address.toOutputScript(o,this.network).toString("hex");c.addOutput({script:w,value:t.confidential.satoshiToConfidentialValue(b),asset:this.network.assetHash,nonce:Buffer.from("00","hex")}),p.push(t.address.fromConfidential(o).blindingKey)}return c.addOutput({script:Buffer.alloc(0),value:t.confidential.satoshiToConfidentialValue(d),asset:this.network.assetHash,nonce:Buffer.from("00","hex")}),c.blindOutputs(f,p),c.toBase64()},r.updateTx=function(e,r,n,i,s,o,a,u){var c=this,f=R(e),p=le(r,n,s,this.blindingPrivateKeyByScript),d=p.change,h={},l={};p.selectedUnspents.forEach((function(e){f.addInput({hash:e.txid,index:e.vout,witnessUtxo:e.prevout});var t=e.prevout.script.toString("hex");h[t]=c.blindingPrivateKeyByScript[t]}));var v=t.address.toOutputScript(a.confidentialAddress,this.network).toString("hex");if(f.addOutput({script:v,value:t.confidential.satoshiToConfidentialValue(i),asset:o,nonce:Buffer.from("00","hex")}),l[v]=Buffer.from(a.blindingPrivateKey,"hex"),d>0){var y=t.address.toOutputScript(u.confidentialAddress,this.network).toString("hex");f.addOutput({script:y,value:t.confidential.satoshiToConfidentialValue(d),asset:s,nonce:Buffer.from("00","hex")}),l[y]=Buffer.from(u.blindingPrivateKey,"hex")}return{psetBase64:f.toBase64(),inputBlindingKeys:h,outputBlindingKeys:l}},e.toHex=function(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r.validateSignaturesOfAllInputs(),r.finalizeAllInputs(),r.extractTransaction().toHex()},e}();function R(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r}function D(e,t){return H.apply(this,arguments)}function H(){return(H=d(g.mark((function e(t,n){return g.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 W(e,t){return V.apply(this,arguments)}function V(){return(V=d(g.mark((function e(t,n){return g.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 X(e,t){return q.apply(this,arguments)}function q(){return(q=c(g.mark((function e(t,r){var n,i,s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=0,i=g.mark((function e(){var t,i,s,a,u,c,p;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(t=o.value).address,s=t.blindingKey,e.next=3,f(W(i,r));case 3:a=e.sent.map((function(e){return Y(e,s,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)})),s=v(t);case 3:if((o=s()).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 G(e,t){return z.apply(this,arguments)}function z(){return(z=d(g.mark((function e(t,r){var n,i,s;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=X(t,r),i=[],e.next=4,n.next();case 4:s=e.sent;case 5:if(s.done){e.next=12;break}return i.push(s.value),e.next=9,n.next();case 9:s=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 Y(e,t,r){return Z.apply(this,arguments)}function Z(){return(Z=d(g.mark((function e(t,r,n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,$(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 $(e,t,r){return J.apply(this,arguments)}function J(){return(J=d(g.mark((function e(r,n,i){var s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D(r.txid,i);case 2:return s=t.Transaction.fromHex(e.sent).outs[r.vout],o=t.confidential.unblindOutput(s.nonce,Buffer.from(n,"hex"),s.rangeProof,s.value,s.asset,s.script),e.abrupt("return",{txid:r.txid,vout:r.vout,asset:o.asset.reverse().toString("hex"),value:parseInt(o.value,10),prevout:s});case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(){return(Q=d(g.mark((function e(t,r,n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,G([{address:t,blindingKey: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){return"surjectionProof"in e&&"rangeProof"in e}function te(){return(te=d(g.mark((function e(t,r,n){var i,s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=re(t,r,n),s=[],e.next=4,i.next();case 4:o=e.sent;case 5:if(o.done){e.next=12;break}return s.push(o.value),e.next=9,i.next();case 9:o=e.sent,e.next=5;break;case 12:return e.abrupt("return",s);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function re(e,t,r){return ne.apply(this,arguments)}function ne(){return(ne=c(g.mark((function e(t,r,n){var i,s,o,a,u;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=v(t);case 1:if((s=i()).done){e.next=18;break}return o=ie(s.value,n),e.next=6,f(o.next());case 6:a=e.sent;case 7:if(a.done){e.next=16;break}return u=a.value,e.next=11,ce(u,r);case 11:return e.next=13,f(o.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 ie(e,t){return se.apply(this,arguments)}function se(){return(se=c(g.mark((function e(t,r){var n,i,s,o,a,u,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0,i=[],s=0;case 3:return e.next=5,f(de(t,r,n));case 5:s+=(i=e.sent).length,o=i.map((function(e){return oe(e,r)})),a=v(o);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",s);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oe(e,t){return ae.apply(this,arguments)}function ae(){return(ae=d(g.mark((function e(r,n){var i,s,o,a,u,c,f,p,d;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],s=[],o=v(r.vin);!(a=o()).done;)i.push((u=a.value).txid),s.push(u.vout);return e.next=5,Promise.all(i.map((function(e){return D(e,n)})));case 5:return c=e.sent.map((function(e,r){return ue(t.Transaction.fromHex(e).outs[s[r]])})),f=i.map((function(e,t){return{prevout:c[t],txid:e,vout:s[t]}})),e.next=10,D(r.txid,n);case 10:return p=t.Transaction.fromHex(e.sent),d=p.outs.map(ue),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 ue(e){return I(e)?{blindedAsset:e.asset,blindedValue:e.value,nonce:e.nonce,rangeProof:e.rangeProof,surjectionProof:e.surjectionProof,script:e.script.toString("hex")}:{asset:w(e.asset),value:P(e.value),script:e.script.toString("hex")}}function ce(e,t){return fe.apply(this,arguments)}function fe(){return(fe=d(g.mark((function e(t,r){var n,i,s,o,a;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],i=function(e){var i=t.vin[e].prevout;ee(i)&&n.push(function(){var n=d(g.mark((function n(){var s,o;return g.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(s=r(i.script))&&(o=pe(i,s),t.vin[e].prevout=o);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},s=0;s<t.vin.length;s++)i(s);for(o=function(e){var i=t.vout[e];ee(i)&&n.push(function(){var n=d(g.mark((function n(){var s,o;return g.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(s=r(i.script))&&(o=pe(i,s),t.vout[e]=o);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},a=0;a<t.vout.length;a++)o(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 pe(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 de(e,t,r){return he.apply(this,arguments)}function he(){return(he=d(g.mark((function e(t,n,i){var s;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=n+"/address/"+t+"/txs/chain",i&&(s+="/"+i),e.next=4,r.get(s);case 4:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function le(e,r,n,i){for(var s=[],o=0,a=0;a<e.length;a++){var u=e[a];try{if(I(u.prevout)){var c=k(u.prevout,i[u.prevout.script.toString("hex")]),f=c.value;if(w(c.asset)!==n)continue;if(s.push(u),(o+=f)>=r)break;continue}}catch(e){continue}if(w(u.prevout.asset)===n&&(s.push(u),(o+=t.confidential.confidentialValueToSatoshi(u.prevout.value))>=r))break}if(o<r)throw new Error("You do not have enough in your wallet");return{selectedUnspents:s,change:o-r}}function ve(e,t){return(3*ye(!1,e,t,!1)+ye(!0,e,t,!0)+3)/4}function ye(e,t,r,n){var i=function(e,t){var r=40*t;return e&&(r+=105*t),r}(e,t),s=function(e,t){var r=67*t;return e&&(r+=4273*t),r+43}(n,r);return 9+xe(r)+xe(t)+i+s}function xe(e){return e<253?1:e<=65535?3:e<=4294967295?5:9}Object.defineProperty(exports,"address",{enumerable:!0,get:function(){return t.address}}),Object.defineProperty(exports,"networks",{enumerable:!0,get:function(){return t.networks}}),exports.BufferMap=T,exports.EsploraIdentityRestorer=m,exports.MasterPublicKey=F,exports.Mnemonic=C,exports.PrivateKey=M,exports.Wallet=j,exports.coinselect=le,exports.estimateTxSize=ve,exports.fetchAndUnblindTxs=function(e,t,r){return te.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=re,exports.fetchAndUnblindUtxos=G,exports.fetchAndUnblindUtxosGenerator=X,exports.fetchBalances=function(e,t,r){return Q.apply(this,arguments)},exports.fetchTxHex=D,exports.fetchUtxos=W,exports.fromAssetHash=function(e){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(e,"hex").reverse()])},exports.fromXpub=S,exports.isBlindedOutputInterface=ee,exports.isConfidentialOutput=I,exports.isValidAmount=function(e){return!(e<=0||!Number.isSafeInteger(e))},exports.isValidExtendedBlindKey=L,exports.isValidXpub=N,exports.toAssetHash=w,exports.toNumber=P,exports.toXpub=O,exports.unblindOutput=k,exports.walletFromAddresses=function(e,r){var n=r?t.networks[r]:t.networks.liquid;try{return new j({addresses:e,network:n})}catch(e){throw new Error("fromAddress: Invalid addresses list or network")}}; | ||
"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"),s=require("slip77"),o=require("bip39");function a(e){this.wrapped=e}function u(e){var t,r;function n(t,r){try{var s=e[t](r),o=s.value,u=o instanceof a;Promise.resolve(u?o.wrapped:o).then((function(e){u?n("return"===t?"return":"next",e):i(s.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(s,o){var a={key:e,arg:i,resolve:s,reject:o,next:null};r?r=r.next=a:(t=r=a,n(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function c(e){return function(){return new u(e.apply(this,arguments))}}function p(e){return new a(e)}function f(e,t,r,n,i,s,o){try{var a=e[s](o),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 s=e.apply(t,r);function o(e){f(s,n,i,o,a,"next",e)}function a(e){f(s,n,i,o,a,"throw",e)}o(void 0)}))}}function h(){return(h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function l(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(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 y(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 v(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)?v(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 x,g=(function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",o=n.toStringTag||"@@toStringTag";function a(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=Object.create((t&&t.prototype instanceof f?t:f).prototype),s=new k(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(i,s){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw s;return{value:void 0,done:!0}}for(r.method=i,r.arg=s;;){var o=r.delegate;if(o){var a=b(o,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,s),i}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var p={};function f(){}function d(){}function h(){}var l={};l[i]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(A([])));y&&y!==t&&r.call(y,i)&&(l=y);var x=h.prototype=f.prototype=Object.create(l);function g(e){["next","throw","return"].forEach((function(t){a(e,t,(function(e){return this._invoke(t,e)}))}))}function m(e,t){var n;this._invoke=function(i,s){function o(){return new t((function(n,o){!function n(i,s,o,a){var u=c(e[i],e,s);if("throw"!==u.type){var p=u.arg,f=p.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(f).then((function(e){p.value=e,o(p)}),(function(e){return n("throw",e,o,a)}))}a(u.arg)}(i,s,n,o)}))}return n=n?n.then(o,o):o()}}function b(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,b(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function k(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function A(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,s=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 s.next=s}}return{next:K}}function K(){return{value:void 0,done:!0}}return d.prototype=x.constructor=h,h.constructor=d,d.displayName=a(h,o,"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,o,"GeneratorFunction")),e.prototype=Object.create(x),e},e.awrap=function(e){return{__await:e}},g(m.prototype),m.prototype[s]=function(){return this},e.AsyncIterator=m,e.async=function(t,r,n,i,s){void 0===s&&(s=Promise);var o=new m(u(t,r,n,i),s);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},g(x),a(x,o,"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=A,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return o.type="throw",o.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 s=this.tryEntries[i],o=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var a=r.call(s,"catchLoc"),u=r.call(s,"finallyLoc");if(a&&u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(a){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.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 s=i;break}}s&&("break"===e||"continue"===e)&&s.tryLoc<=t&&t<=s.finallyLoc&&(s=null);var o=s?s.completion:{};return o.type=e,o.arg=t,s?(this.method="next",this.next=s.finallyLoc,p):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(x={exports:{}}),x.exports),m=function e(t){var n=this;this.esploraEndpoint=e.DEFAULT_ESPLORA_ENDPOINT,this.addressesHaveBeenUsed=function(){var e=d(g.mark((function e(t){return g.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(g.mark((function e(t){return g.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 t=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),r=t.changeAddressByAsset,n=t.coinSelector,i=t.psetBase64,s=t.recipients,o=t.unspents,a=t.addFee,u=t.satsPerByte,c=n(o,s,r),p=c.selectedUtxos,f=c.changeOutputs,d=p;if(!a)return P(i,d,s.concat(f));var l=k(i),v=l.data.inputs.length+d.length,x=l.data.outputs.length+s.length+f.length,g=A(s[0].address).assetHash,m=w(v,x,u,g),b=f.findIndex((function(e){return e.asset===g})),K=-1===b?0-m.value:f[b].value-m.value;if(K>0)return f[b].value=K,P(i,d,s.concat(f).concat(m));if(b>0&&(f.splice(b,1),x-=1),0===K)return P(i,d,s.concat(f).concat(m));for(var I,E=[],T=y(o);!(I=T()).done;){var B=I.value;p.includes(B)||E.push(B)}var S=w(v+1,x,u,g);K=m.value-S.value+K;var O=n(E,[h({},m,{value:Math.abs(K)})],r);return P(i,d.concat(O.selectedUtxos),s.concat(f).concat(m).concat(O.changeOutputs))}function w(e,t,r,n){var i=K(e,t);return{asset:n,value:Math.ceil(i*r),address:""}}function P(e,r,n){for(var i,s=k(e),o=Buffer.from("00","hex"),a=y(n);!(i=a()).done;){var u=i.value,c=u.asset,p=u.value,f=u.address,d=""===f?"":t.address.toOutputScript(f,A(f));s.addOutput({asset:c,value:p,script:d,nonce:o})}for(var h,l=y(r);!(h=l()).done;){var v=h.value;s.addInput({hash:v.txid,index:v.vout,witnessUtxo:v.prevout})}return s.toBase64()}function k(e){var r;try{r=t.Psbt.fromBase64(e)}catch(e){throw new Error("Invalid pset")}return r}function A(e){try{return t.address.toOutputScript(e,t.networks.liquid),t.networks.liquid}catch(r){try{return t.address.toOutputScript(e,t.networks.regtest),t.networks.regtest}catch(t){throw new Error(e+" is an invalid address "+t)}}}function K(e,t){return(3*I(!1,e,t,!1)+I(!0,e,t,!0)+3)/4}function I(e,t,r,n){var i=function(e,t){var r=40*t;return e&&(r+=105*t),r}(e,t),s=function(e,t){var r=67*t;return e&&(r+=4273*t),r+43}(n,r);return 9+E(r)+E(t)+i+s}function E(e){return e<253?1:e<=65535?3:e<=4294967295?5:9}function T(e){return e.slice(1).reverse().toString("hex")}function B(e){return t.confidential.confidentialValueToSatoshi(e)}m.DEFAULT_ESPLORA_ENDPOINT="https://blockstream.info/liquid/api";var S=Buffer.from("0x00","hex");function O(e){return null!=e&&e.length>0}function N(e){var t=e.surjectionProof,r=e.nonce;return O(e.rangeProof)&&O(t)&&r!==S}var L,_=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}(),M=new Map([["xpub","0488b21e"],["ypub","049d7cb2"],["Ypub","0295b43f"],["zpub","04b24746"],["Zpub","02aa7ed3"],["tpub","043587cf"],["upub","044a5262"],["Upub","024289ef"],["vpub","045f1cf6"],["Vpub","02575483"]]);function C(e,t){if(!M.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(M.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 F(e,t){return C(e,"regtest"===t?"vpub":"zpub")}function U(e){return C(e,"xpub")}function j(e,t){try{i.fromBase58(e,t)}catch(e){return!1}return!0}function W(e){try{s.fromMasterBlindingKey(e)}catch(e){return!1}return!0}function R(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 D(e){return{txid:e.txid,vout:e.vout}}function H(e){return!e.asset||!e.value}function q(e){return e?t.networks[e]:t.networks.liquid}(L=exports.IdentityType||(exports.IdentityType={}))[L.PrivateKey=1]="PrivateKey",L[L.Mnemonic=2]="Mnemonic",L[L.MasterPublicKey=3]="MasterPublicKey",L[L.Inject=4]="Inject",L[L.Ledger=5]="Ledger",L[L.Trezor=6]="Trezor";var G=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(g.mark((function e(r,n,i,s,o){var a,u,c,p,f,d,h,l,v,x,m,b,w,P,A,K;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=new Map,u=new Map,c=k(n),p=t.Transaction.fromHex(R(n)),f=y(i);case 5:if((d=f()).done){e.next=16;break}if(h=d.value,!s||!s.has(h)){e.next=11;break}return l=Buffer.from(s.get(h),"hex"),u.set(h,l),e.abrupt("continue",14);case 11:v=r(p.outs[h].script).publicKey,u.set(h,v);case 14:e.next=5;break;case 16:x=0;case 17:if(!(x<c.data.inputs.length)){e.next=41;break}if(b=void 0,!(m=c.data.inputs[x]).witnessUtxo){e.next=24;break}if(N(m.witnessUtxo)){e.next=23;break}return e.abrupt("continue",38);case 23:b=m.witnessUtxo.script;case 24:if(!m.nonWitnessUtxo){e.next=30;break}if(w=p.ins[x].index,N(P=t.Transaction.fromBuffer(m.nonWitnessUtxo).outs[w])){e.next=29;break}return e.abrupt("continue",38);case 29:b=P.script;case 30:if(!o||!o.has(x)){e.next=34;break}return A=Buffer.from(o.get(x),"hex"),a.set(x,A),e.abrupt("continue",38);case 34:if(b){e.next=36;break}throw new Error("no witness script for input #"+x);case 36:K=r(b).privateKey,a.set(x,K);case 38:x++,e.next=17;break;case 41:return e.abrupt("return",c.blindOutputsByIndex(a,u).toBase64());case 42:case"end":return e.stop()}}),e)})));return function(t,r,n,i,s){return e.apply(this,arguments)}}(),e}();function X(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}G.DEFAULT_RESTORER=new m;var z=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 _,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(o.setDefaultWordlist(n.value.language?n.value.language:"english"),!o.validateMnemonic(n.value.mnemonic))throw new Error("Mnemonic is not valid.");var u=o.mnemonicToSeedSync(n.value.mnemonic);a.masterPrivateKeyNode=i.fromSeed(u,a.network);var c=a.masterPrivateKeyNode.derivePath(a.baseDerivationPath),p=t.bip32.fromPublicKey(c.publicKey,c.chainCode,c.network).toBase58();return a.masterPublicKey=F(p,n.chain),a.masterBlindingKeyNode=s.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}l(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(g.mark((function t(r,n,i,s){var o=this;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return o.getBlindingKeyPair(e)}),r,n,i,s));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(g.mark((function e(r){var n,i,s,o,a,u,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],s=0;s<n.data.inputs.length;s++)(o=n.data.inputs[s]).witnessUtxo&&(a=this.scriptToAddressCache.get(o.witnessUtxo.script))&&(u=Buffer.from(a.signingPrivateKey,"hex"),c=t.ECPair.fromPrivateKey(u),i.push(n.signInputAsync(s,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(g.mark((function e(t,r){var n,i,s=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=function(){var e=d(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(!1,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(i.map(n)));case 3:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),n.addressToChangeAddressAsync=function(){var e=d(g.mark((function e(t){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=X(t),e.abrupt("return",this.getAddress(!0,r));case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(g.mark((function e(t){var r;return g.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(g.mark((function e(){var t,n,i,s,o,a,u,c,p,f,d,h=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=20,n=0,i=0,s=[],o=function(e){return function(t,r){!0===t?(n=0,s.push(e[r])):n+=1}};case 5:if(!(n<t)){e.next=16;break}return e.next=8,this.generateSetOfAddresses(i,t-n);case 8:return a=e.sent,e.next=11,this.checkAddressesWithRestorer(a);case 11:e.sent.forEach(o(a)),i+=t,e.next=5;break;case 16:return u=s.map(X),this.index=u.length>0?Math.max.apply(Math,u)+1:r.INITIAL_INDEX,e.next=20,Promise.all(s.map((function(e){return h.addressToChangeAddressAsync(e)})));case 20:return c=e.sent,e.next=23,this.checkAddressesWithRestorer(c);case 23:return p=e.sent,f=c.filter((function(e,t){return p[t]})),d=f.map(X),this.changeIndex=d.length>0?Math.max.apply(Math,d)+1:r.INITIAL_INDEX,s.push.apply(s,f),e.abrupt("return",s);case 29:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(g.mark((function e(){var t=this;return g.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}(G);z.INITIAL_BASE_PATH="m/84'/0'/0'",z.INITIAL_INDEX=0;var V=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 s=t.payments.p2wpkh({pubkey:n.signingKeyPair.publicKey,blindkey:n.blindingKeyPair.publicKey,network:n.network});return n.confidentialAddress=s.confidentialAddress,n.blindingPrivateKey=n.blindingKeyPair.privateKey.toString("hex"),n.scriptPubKey=s.output,n}l(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(g.mark((function t(r,n,i,s){var o=this;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return o.getBlindingKeyPair(e)}),r,n,i,s));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(g.mark((function e(r){var n,i,s,o,a=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=t.Psbt.fromBase64(r),i=[],s=0;s<n.data.inputs.length;s++)(o=n.data.inputs[s]).witnessUtxo?o.witnessUtxo.script.equals(this.scriptPubKey)&&i.push(s):i.push(s);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}(G);function Y(e){var t=e.derivationPath.split("/");return parseInt(t[t.length-1])}var Z=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 _;var o,a=U(t.value.masterPublicKey);if(t.type!==exports.IdentityType.MasterPublicKey)throw new Error("The identity arguments have not the MasterPublicKey type.");if(!("masterPublicKey"in(o=t.value))||!("masterBlindingKey"in o))throw new Error("The value of IdentityOpts is not valid for MasterPublicKey Identity.");if(!j(a))throw new Error("Master public key is not valid");if(!W(t.value.masterBlindingKey))throw new Error("Master blinding key is not valid");return n.masterPublicKeyNode=i.fromBase58(a),n.masterBlindingKeyNode=s.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}l(r,e);var n=r.prototype;return n.blindPset=function(){var t=d(g.mark((function t(r,n,i,s){var o=this;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e.prototype.blindPsetWithBlindKeysGetter.call(this,(function(e){return o.getBlindingKeyPair(e)}),r,n,i,s));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(g.mark((function e(t,r){var n,i,s=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=function(){var e=d(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s.getAddress(!1,t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i=Array.from({length:r},(function(e,r){return r+t})),e.abrupt("return",Promise.all(i.map(n)));case 3:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),n.addressToChangeAddressAsync=function(){var e=d(g.mark((function e(t){var r;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=Y(t),e.abrupt("return",this.getAddress(!0,r));case 2:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.checkAddressesWithRestorer=function(){var e=d(g.mark((function e(t){var r;return g.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(g.mark((function e(){var t,n,i,s,o,a,u,c,p,f,d,h=this;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=20,n=0,i=0,s=[],o=function(e){return function(t,r){!0===t?(n=0,s.push(e[r])):n+=1}};case 5:if(!(n<t)){e.next=16;break}return e.next=8,this.generateSetOfAddresses(i,t-n);case 8:return a=e.sent,e.next=11,this.checkAddressesWithRestorer(a);case 11:e.sent.forEach(o(a)),i+=t,e.next=5;break;case 16:return u=s.map(Y),this.index=u.length>0?Math.max.apply(Math,u)+1:r.INITIAL_INDEX,e.next=20,Promise.all(s.map((function(e){return h.addressToChangeAddressAsync(e)})));case 20:return c=e.sent,e.next=23,this.checkAddressesWithRestorer(c);case 23:return p=e.sent,f=c.filter((function(e,t){return p[t]})),d=f.map(Y),this.changeIndex=d.length>0?Math.max.apply(Math,d)+1:r.INITIAL_INDEX,s.push.apply(s,f),e.abrupt("return",s);case 29:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.restore=function(){var e=d(g.mark((function e(){var t=this;return g.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}(G);Z.INITIAL_INDEX=0;var $=function(e,t){return e.value-t.value};function J(e,t,r){for(var n,i=[],s=0,o=y(e=e.sort(r));!(n=o()).done;){var a=n.value;if(H(a)||(i.push(a),s+=a.value),s>=t)return{selected:i,changeAmount:s-t}}throw new Error("not enough utxos in wallet to found: "+t)}function Q(e,t){return e.reduce((function(e,r){return(e[r[t]]=e[r[t]]||[]).push(r),e}),{})}function ee(e){return"surjectionProof"in e&&"rangeProof"in e}function te(){return(te=d(g.mark((function e(t,r,n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ce([{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 re(e,t){return ne.apply(this,arguments)}function ne(){return(ne=d(g.mark((function e(t,n){return g.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 ie(e,t){return se.apply(this,arguments)}function se(){return(se=d(g.mark((function e(t,n){return g.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 oe(){return(oe=d(g.mark((function e(t,r,n){var i,s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=fe(t,r,n),s=[],e.next=4,i.next();case 4:o=e.sent;case 5:if(o.done){e.next=12;break}return s.push(o.value),e.next=9,i.next();case 9:o=e.sent,e.next=5;break;case 12:return e.abrupt("return",s);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ae(e,t){return ue.apply(this,arguments)}function ue(){return(ue=c(g.mark((function e(t,r){var n,i,s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=0,i=g.mark((function e(){var t,i,s,a,u,c,f;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(t=o.value).confidentialAddress,s=t.blindingPrivateKey,e.next=3,p(ie(i,r));case 3:a=e.sent.map((function(e){return ke(e,s,r)})),n+=a.length,u=y(a);case 7:if((c=u()).done){e.next=13;break}return f=c.value,e.next=11,f;case 11:e.next=7;break;case 13:case"end":return e.stop()}}),e)})),s=y(t);case 3:if((o=s()).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 ce(e,t){return pe.apply(this,arguments)}function pe(){return(pe=d(g.mark((function e(t,r){var n,i,s;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=ae(t,r),i=[],e.next=4,n.next();case 4:s=e.sent;case 5:if(s.done){e.next=12;break}return i.push(s.value),e.next=9,n.next();case 9:s=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 fe(e,t,r){return de.apply(this,arguments)}function de(){return(de=c(g.mark((function e(t,r,n){var i,s,o,a,u;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=y(t);case 1:if((s=i()).done){e.next=18;break}return o=he(s.value,n),e.next=6,p(o.next());case 6:a=e.sent;case 7:if(a.done){e.next=16;break}return u=a.value,e.next=11,ye(u,r);case 11:return e.next=13,p(o.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 he(e,t){return le.apply(this,arguments)}function le(){return(le=c(g.mark((function e(t,r){var n,i,s,o,a,u,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0,i=[],s=0;case 3:return e.next=5,p(we(t,r,n));case 5:s+=(i=e.sent).length,o=i.map((function(e){return me(e,r)})),a=y(o);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",s);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ve(e){return N(e)?{blindedAsset:e.asset,blindedValue:e.value,nonce:e.nonce,rangeProof:e.rangeProof,surjectionProof:e.surjectionProof,script:e.script.toString("hex")}:{asset:T(e.asset),value:B(e.value),script:e.script.toString("hex")}}function ye(e,t){return xe.apply(this,arguments)}function xe(){return(xe=d(g.mark((function e(t,r){var n,i,s,o,a;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],i=function(e){var i=t.vin[e].prevout;ee(i)&&n.push(function(){var n=d(g.mark((function n(){var s,o;return g.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(s=r(i.script))&&(o=ge(i,s),t.vin[e].prevout=o);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},s=0;s<t.vin.length;s++)i(s);for(o=function(e){var i=t.vout[e];ee(i)&&n.push(function(){var n=d(g.mark((function n(){var s,o;return g.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:(s=r(i.script))&&(o=ge(i,s),t.vout[e]=o);case 2:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}()())},a=0;a<t.vout.length;a++)o(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 ge(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 me(e,t){return be.apply(this,arguments)}function be(){return(be=d(g.mark((function e(r,n){var i,s,o,a,u,c,p,f,d;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],s=[],o=y(r.vin);!(a=o()).done;)i.push((u=a.value).txid),s.push(u.vout);return e.next=5,Promise.all(i.map((function(e){return re(e,n)})));case 5:return c=e.sent.map((function(e,r){return ve(t.Transaction.fromHex(e).outs[s[r]])})),p=i.map((function(e,t){return{prevout:c[t],txid:e,vout:s[t]}})),e.next=10,re(r.txid,n);case 10:return f=t.Transaction.fromHex(e.sent),d=f.outs.map(ve),e.abrupt("return",{txid:r.txid,vin:p,vout:d,fee:r.fee,status:{confirmed:r.status.confirmed,blockHash:r.status.block_hash,blockHeight:r.status.block_height,blockTime:r.status.block_time}});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function we(e,t,r){return Pe.apply(this,arguments)}function Pe(){return(Pe=d(g.mark((function e(t,n,i){var s;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=n+"/address/"+t+"/txs/chain",i&&(s+="/"+i),e.next=4,r.get(s);case 4:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ke(e,t,r){return Ae.apply(this,arguments)}function Ae(){return(Ae=d(g.mark((function e(t,r,n){return g.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 Ie.apply(this,arguments)}function Ie(){return(Ie=d(g.mark((function e(r,n,i){var s,o;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,re(r.txid,i);case 2:return s=t.Transaction.fromHex(e.sent).outs[r.vout],o=t.confidential.unblindOutput(s.nonce,Buffer.from(n,"hex"),s.rangeProof,s.value,s.asset,s.script),e.abrupt("return",{txid:r.txid,vout:r.vout,asset:o.asset.reverse().toString("hex"),value:parseInt(o.value,10),prevout:s});case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ee=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,s){return b({psetBase64:e,recipients:t,coinSelector:r,changeAddressByAsset:n,addFee:i,satsPerByte:s,unspents:this.cache.getAll()})},e}();function Te(){return(Te=d(g.mark((function e(t,r,n){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ce(t,r);case 2:return e.abrupt("return",Be(e.sent,n));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Be(e,t){return new Ee(new Se(e),q(t))}var Se=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=y(e);!(t=r()).done;){var n=t.value;this.utxoMap.set(D(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=_,exports.EsploraIdentityRestorer=m,exports.MasterPublicKey=Z,exports.Mnemonic=z,exports.PrivateKey=V,exports.UtxoCache=Se,exports.Wallet=Ee,exports.addToTx=P,exports.buildTx=b,exports.createFeeOutput=w,exports.decodePset=k,exports.estimateTxSize=K,exports.fetchAndUnblindTxs=function(e,t,r){return oe.apply(this,arguments)},exports.fetchAndUnblindTxsGenerator=fe,exports.fetchAndUnblindUtxos=ce,exports.fetchAndUnblindUtxosGenerator=ae,exports.fetchBalances=function(e,t,r){return te.apply(this,arguments)},exports.fetchTxHex=re,exports.fetchUtxos=ie,exports.fromAssetHash=function(e){return Buffer.concat([Buffer.from("01","hex"),Buffer.from(e,"hex").reverse()])},exports.fromXpub=F,exports.getNetwork=q,exports.greedyCoinSelector=function(e){return void 0===e&&(e=$),function(t,r,n){return function(e,t,r,n){for(var i={selectedUtxos:[],changeOutputs:[]},s=Q(e=e.filter((function(e){return!H(e)})),"asset"),o=Q(t,"asset"),a=0,u=Object.entries(o);a<u.length;a++){var c,p=u[a],f=p[0],d=p[1],h=s[f];if(!h)throw new Error("need unspents for the asset: "+f);var l=J(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(f);if(!y)throw new Error("need change address for asset: "+f);i.changeOutputs.push({asset:f,value:v,address:y})}}return i}(t,r,n,e)}},exports.isBlindedOutputInterface=ee,exports.isBlindedUtxo=H,exports.isConfidentialOutput=N,exports.isValidAmount=function(e){return!(e<=0||!Number.isSafeInteger(e))},exports.isValidExtendedBlindKey=W,exports.isValidXpub=j,exports.psetToUnsignedHex=R,exports.toAssetHash=T,exports.toNumber=B,exports.toOutpoint=D,exports.toXpub=U,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.walletFromAddresses=function(e,t,r){return Te.apply(this,arguments)},exports.walletFromCoins=Be; | ||
//# sourceMappingURL=ldk.cjs.production.min.js.map |
@@ -0,1 +1,3 @@ | ||
/// <reference types="node" /> | ||
import { TxOutput } from 'liquidjs-lib'; | ||
/** | ||
@@ -10,1 +12,50 @@ * Defines the shape of the object returned by the getAdresses's method. | ||
} | ||
export declare type ChangeAddressFromAssetGetter = (asset: string) => string | undefined; | ||
export declare type BlindingKeyGetter = (script: string) => string | undefined; | ||
export interface RecipientInterface { | ||
value: number; | ||
asset: string; | ||
address: string; | ||
} | ||
export interface Outpoint { | ||
txid: string; | ||
vout: number; | ||
} | ||
export interface UtxoInterface { | ||
txid: string; | ||
vout: number; | ||
asset?: string; | ||
value?: number; | ||
prevout: TxOutput; | ||
} | ||
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; | ||
} | ||
export interface InputInterface { | ||
txid: string; | ||
vout: number; | ||
prevout: BlindedOutputInterface | UnblindedOutputInterface; | ||
} | ||
export interface TxInterface { | ||
txid: string; | ||
fee: number; | ||
status: { | ||
confirmed: boolean; | ||
blockHeight?: number; | ||
blockHash?: string; | ||
blockTime?: number; | ||
}; | ||
vin: Array<InputInterface>; | ||
vout: Array<BlindedOutputInterface | UnblindedOutputInterface>; | ||
} |
/// <reference types="node" /> | ||
import { UtxoInterface, Outpoint } from './types'; | ||
import { Network, TxOutput } from 'liquidjs-lib'; | ||
@@ -24,3 +25,3 @@ export declare function toAssetHash(x: Buffer): string; | ||
*/ | ||
export declare function isConfidentialOutput(output: TxOutput): boolean; | ||
export declare function isConfidentialOutput({ rangeProof, surjectionProof, nonce, }: any): boolean; | ||
export declare class BufferMap<T> { | ||
@@ -38,1 +39,5 @@ private map; | ||
export declare function isValidExtendedBlindKey(masterBlind: string): Boolean; | ||
export declare function psetToUnsignedHex(psetBase64: string): string; | ||
export declare function toOutpoint({ txid, vout }: UtxoInterface): Outpoint; | ||
export declare function isBlindedUtxo({ asset, value }: UtxoInterface): boolean; | ||
export declare function getNetwork(str?: string): Network; |
@@ -1,4 +0,4 @@ | ||
/// <reference types="node" /> | ||
import { Network, TxOutput } from 'liquidjs-lib'; | ||
import { AddressInterface } from './types'; | ||
import { CoinSelector } from './coinselection/coinSelector'; | ||
import { Network } from 'liquidjs-lib'; | ||
import { AddressInterface, UtxoInterface, Outpoint, RecipientInterface, ChangeAddressFromAssetGetter } from './types'; | ||
/** | ||
@@ -9,12 +9,6 @@ * Wallet abstraction. | ||
network: Network; | ||
addresses: AddressInterface[]; | ||
blindingPrivateKeyByScript: Record<string, Buffer>; | ||
cache: UtxoCacheInterface; | ||
createTx(): string; | ||
buildTx(psetBase64: string, unspents: Array<UtxoInterface>, recipient: string, amount: number, asset: string, changeAddress: string): string; | ||
updateTx(psetBase64: string, unspents: Array<UtxoInterface>, inputAmount: number, outputAmount: number, inputAsset: string, outputAsset: string, outputAddress: AddressInterface, changeAddress: AddressInterface): any; | ||
buildTx(psetBase64: string, recipients: RecipientInterface[], coinSelector: CoinSelector, changeAddressByAsset: ChangeAddressFromAssetGetter, addFee?: boolean, satsPerByte?: number): string; | ||
} | ||
export interface AddressWithBlindingKey { | ||
address: string; | ||
blindingKey: string; | ||
} | ||
/** | ||
@@ -30,8 +24,4 @@ * Implementation of Wallet Interface. | ||
network: Network; | ||
addresses: AddressInterface[]; | ||
blindingPrivateKeyByScript: Record<string, Buffer>; | ||
constructor({ addresses, network, }: { | ||
addresses: AddressInterface[]; | ||
network: Network; | ||
}); | ||
cache: UtxoCacheInterface; | ||
constructor(cache: UtxoCacheInterface, network: Network); | ||
/** | ||
@@ -41,25 +31,3 @@ * Returns an empty liquidjs lib Psbt instance. | ||
createTx(): string; | ||
/** | ||
* Returns an unsigned pset base64 encoded with a valid transaction that spends the given asset versus a recipient. | ||
* @param psetBase64 | ||
* @param unspents | ||
* @param recipient | ||
* @param amount | ||
* @param asset | ||
* @param changeAddress | ||
*/ | ||
buildTx(psetBase64: string, unspents: Array<UtxoInterface>, recipient: string, amount: number, asset: string, changeAddress: string, satsPerByte?: number): string; | ||
/** | ||
* | ||
* @param psetBase64 the Pset to update, base64 encoded. | ||
* @param unspents unspent that will be used to found the transaction. | ||
* @param inputAmount the amount to found with unspents. | ||
* @param outputAmount the amount to send via output. | ||
* @param inputAsset the assetHash of inputs. | ||
* @param outputAsset the asset hash of output. | ||
* @param outputAddress the address that will receive the `outputAmount` of `outputAsset`. | ||
* @param changeAddress the change address. | ||
*/ | ||
updateTx(psetBase64: string, unspents: Array<UtxoInterface>, inputAmount: number, outputAmount: number, inputAsset: string, outputAsset: string, outputAddress: AddressInterface, changeAddress: AddressInterface): any; | ||
static toHex(psetBase64: string): string; | ||
buildTx(psetBase64: string, recipients: RecipientInterface[], coinSelector: CoinSelector, changeAddressByAsset: ChangeAddressFromAssetGetter, addFee?: boolean, satsPerByte?: number): string; | ||
} | ||
@@ -69,59 +37,18 @@ /** | ||
* @param addresses a list of addressInterface. | ||
* @param explorerUrl the esplora endpoint used to fetch addresses's utxos | ||
* @param network network type | ||
*/ | ||
export declare function walletFromAddresses(addresses: AddressInterface[], network?: string): WalletInterface; | ||
export interface UtxoInterface { | ||
txid: string; | ||
vout: number; | ||
asset: string; | ||
value: number; | ||
prevout: TxOutput; | ||
export declare function walletFromAddresses(addresses: AddressInterface[], explorerUrl: string, network?: string): Promise<WalletInterface>; | ||
export declare function walletFromCoins(coins: UtxoInterface[], network?: string): WalletInterface; | ||
export interface UtxoCacheInterface { | ||
push(utxos: UtxoInterface[]): void; | ||
delete(outpoint: Outpoint): boolean; | ||
getAll(): UtxoInterface[]; | ||
} | ||
export declare function fetchTxHex(txId: string, url: string): Promise<string>; | ||
export declare function fetchUtxos(address: string, url: string): Promise<Array<UtxoInterface>>; | ||
export declare function fetchAndUnblindUtxosGenerator(addressesAndBlindingKeys: Array<AddressWithBlindingKey>, url: string): AsyncGenerator<UtxoInterface, number, undefined>; | ||
export declare function fetchAndUnblindUtxos(addressesAndBlindingKeys: Array<AddressWithBlindingKey>, url: string): Promise<UtxoInterface[]>; | ||
export declare function fetchBalances(address: string, blindPrivKey: string, url: string): Promise<any>; | ||
export interface BlindedOutputInterface { | ||
script: string; | ||
blindedValue: Buffer; | ||
blindedAsset: Buffer; | ||
nonce: Buffer; | ||
rangeProof: Buffer; | ||
surjectionProof: Buffer; | ||
export declare class UtxoCache implements UtxoCacheInterface { | ||
private utxoMap; | ||
constructor(utxos?: UtxoInterface[]); | ||
push(utxos: UtxoInterface[]): void; | ||
delete(outpoint: Outpoint): boolean; | ||
getAll(): UtxoInterface[]; | ||
} | ||
export interface UnblindedOutputInterface { | ||
script: string; | ||
value: number; | ||
asset: string; | ||
} | ||
export interface InputInterface { | ||
txid: string; | ||
vout: number; | ||
prevout: BlindedOutputInterface | UnblindedOutputInterface; | ||
} | ||
export interface TxInterface { | ||
txid: string; | ||
fee: number; | ||
status: { | ||
confirmed: boolean; | ||
blockHeight?: number; | ||
blockHash?: string; | ||
blockTime?: number; | ||
}; | ||
vin: Array<InputInterface>; | ||
vout: Array<BlindedOutputInterface | UnblindedOutputInterface>; | ||
} | ||
export declare function isBlindedOutputInterface(object: any): object is BlindedOutputInterface; | ||
export declare type BlindingKeyGetter = (script: string) => string | undefined; | ||
export declare function fetchAndUnblindTxs(addresses: string[], blindingKeyGetter: BlindingKeyGetter, explorerUrl: string): Promise<TxInterface[]>; | ||
/** | ||
* fetch all tx associated to an address and unblind the tx's outputs and prevouts. | ||
* @param explorerUrl the esplora endpoint | ||
*/ | ||
export declare function fetchAndUnblindTxsGenerator(addresses: string[], blindingKeyGetter: BlindingKeyGetter, explorerUrl: string): AsyncGenerator<TxInterface, void, undefined>; | ||
export declare function coinselect(utxos: Array<UtxoInterface>, amount: number, asset: string, inputBlindingKeys: Record<string, Buffer>): { | ||
selectedUnspents: UtxoInterface[]; | ||
change: number; | ||
}; | ||
export declare function estimateTxSize(numInputs: number, numOutputs: number): number; |
{ | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"license": "MIT", | ||
@@ -15,4 +15,4 @@ "main": "dist/index.js", | ||
"build": "tsdx build --tsconfig tsconfig.json --entry src/index.ts", | ||
"test": "tsdx test", | ||
"test:debug": "tsdx test --debug --runInBand", | ||
"test": "tsdx test --no-cache", | ||
"test:debug": "tsdx test --debug --runInBand --no-cache", | ||
"lint": "tsdx lint src test", | ||
@@ -19,0 +19,0 @@ "lint:fix": "tsdx lint src test --fix", |
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
777142
24
6856