UNPKG

@chakrachain/btc-settlement-sdk

Version:
5 lines 170 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@chakrachain/btc-settlement-sdk"]={})}(this,(function(t){"use strict";function e(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function r(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?e(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function n(){ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof l?e:l,o=Object.create(i.prototype),s=new A(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return k()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=v(s,r);if(a){if(a===h)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,s),o}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var h={};function l(){}function p(){}function d(){}var y={};u(y,o,(function(){return this}));var w=Object.getPrototypeOf,g=w&&w(w(I([])));g&&g!==e&&r.call(g,o)&&(y=g);var E=d.prototype=l.prototype=Object.create(y);function m(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function n(i,o,s,a){var u=c(t[i],t,o);if("throw"!==u.type){var f=u.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,s,a)}),(function(t){n("throw",t,s,a)})):e.resolve(h).then((function(t){f.value=t,s(f)}),(function(t){return n("throw",t,s,a)}))}a(u.arg)}var i;this._invoke=function(t,r){function o(){return new e((function(e,i){n(t,r,e,i)}))}return i=i?i.then(o,o):o()}}function v(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,v(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function I(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=d,u(E,"constructor",d),u(d,"constructor",p),p.displayName=u(d,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,a,"GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},m(b.prototype),u(b.prototype,s,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var s=new b(f(e,r,n,i),o);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},m(E),u(E,a,"Generator"),u(E,o,(function(){return this})),u(E,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=I,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=e,o?(this.method="next",this.next=o.finallyLoc,h):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;S(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function i(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var s=t.apply(e,r);function a(t){i(s,n,o,a,u,"next",t)}function u(t){i(s,n,o,a,u,"throw",t)}a(void 0)}))}}function s(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function u(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return s=t.done,t},e:function(t){u=!0,o=t},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw o}}}}const f={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},c={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function h(t,e){const r=t.length,n=e.length;if(0===r)throw new Error("R length is zero");if(0===n)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(128&t[0])throw new Error("R value is negative");if(128&e[0])throw new Error("S value is negative");if(r>1&&0===t[0]&&!(128&t[1]))throw new Error("R value excessively padded");if(n>1&&0===e[0]&&!(128&e[1]))throw new Error("S value excessively padded");const i=new Uint8Array(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=t.length,i.set(t,4),i[4+r]=2,i[5+r]=e.length,i.set(e,6+r),i}const l={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},p={};for(const t of Object.keys(l)){p[l[t]]=t}const d="0123456789abcdefABCDEF",y=d.split("").map((t=>t.codePointAt(0))),w=Array(256).fill(!0).map(((t,e)=>{const r=String.fromCodePoint(e),n=d.indexOf(r);return n<0?void 0:n<16?n:n-6})),g=new TextEncoder,E=new TextDecoder;function m(t){const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);let n=0;for(const e of t)r.set(e,n),n+=e.length;return r}function b(t){const e=t||new Uint8Array;return e.length>512?function(t){const e=new Uint8Array(2*t.length);for(let r=0;r<t.length;++r)e[2*r]=y[t[r]>>4],e[2*r+1]=y[15&t[r]];return E.decode(e)}(e):function(t){let e="";for(let r=0;r<t.length;++r)e+=d[w[y[t[r]>>4]]],e+=d[w[y[15&t[r]]]];return e}(e)}function v(t){const e=g.encode(t||""),r=new Uint8Array(Math.floor(e.length/2));let n;for(n=0;n<r.length;n++){const t=w[e[2*n]],i=w[e[2*n+1]];if(void 0===t||void 0===i)break;r[n]=t<<4|i}return n===r.length?r:r.slice(0,n)}function _(t){const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}function S(t,e){const r=Math.min(t.length,e.length);for(let n=0;n<r;++n)if(t[n]!==e[n])return t[n]<e[n]?-1:1;return t.length===e.length?0:t.length>e.length?1:-1}function A(t,e,r){if(e+1>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`);return t[e]=r,e+1}function I(t,e,r,n){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received ${r}`);return"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255):(t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r),e+4}function k(t,e){if(e+1>t.length)throw new Error("Offset is outside the bounds of Uint8Array");return t[e]}function T(t,e,r){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+3]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e]>>>0,r}{let r=0;return r=(r<<8)+t[e]>>>0,r=(r<<8)+t[e+1]>>>0,r=(r<<8)+t[e+2]>>>0,r=(r<<8)+t[e+3]>>>0,r}}function P(t,e,r,n){if(e+4>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>2147483647||r<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${r}`);return"LE"===(n=n.toUpperCase())?(t[e]=255&r,t[e+1]=r>>8&255,t[e+2]=r>>16&255,t[e+3]=r>>24&255):(t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r),e+4}function x(t,e,r,n){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>0x7fffffffffffffffn||r<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${r}`);return"LE"===(n=n.toUpperCase())?(t[e]=Number(0xffn&r),t[e+1]=Number(r>>8n&0xffn),t[e+2]=Number(r>>16n&0xffn),t[e+3]=Number(r>>24n&0xffn),t[e+4]=Number(r>>32n&0xffn),t[e+5]=Number(r>>40n&0xffn),t[e+6]=Number(r>>48n&0xffn),t[e+7]=Number(r>>56n&0xffn)):(t[e]=Number(r>>56n&0xffn),t[e+1]=Number(r>>48n&0xffn),t[e+2]=Number(r>>40n&0xffn),t[e+3]=Number(r>>32n&0xffn),t[e+4]=Number(r>>24n&0xffn),t[e+5]=Number(r>>16n&0xffn),t[e+6]=Number(r>>8n&0xffn),t[e+7]=Number(0xffn&r)),e+8}function O(t,e,r){if(e+8>t.length)throw new Error("Offset is outside the bounds of Uint8Array");let n=0n;if("LE"===(r=r.toUpperCase()))return n=(n<<8n)+BigInt(t[e+7]),n=(n<<8n)+BigInt(t[e+6]),n=(n<<8n)+BigInt(t[e+5]),n=(n<<8n)+BigInt(t[e+4]),n=(n<<8n)+BigInt(t[e+3]),n=(n<<8n)+BigInt(t[e+2]),n=(n<<8n)+BigInt(t[e+1]),n=(n<<8n)+BigInt(t[e]),t[e+7]<=127?n:n-0x10000000000000000n;{let r=0n;return r=(r<<8n)+BigInt(t[e]),r=(r<<8n)+BigInt(t[e+1]),r=(r<<8n)+BigInt(t[e+2]),r=(r<<8n)+BigInt(t[e+3]),r=(r<<8n)+BigInt(t[e+4]),r=(r<<8n)+BigInt(t[e+5]),r=(r<<8n)+BigInt(t[e+6]),r=(r<<8n)+BigInt(t[e+7]),t[e]<=127?r:r-0x10000000000000000n}}function U(t){return t<l.OP_PUSHDATA1?1:t<=255?2:t<=65535?3:5}function N(t,e,r){const n=U(e);return 1===n?A(t,r,e):2===n?(A(t,r,l.OP_PUSHDATA1),A(t,r+1,e)):3===n?(A(t,r,l.OP_PUSHDATA2),function(t,e,r,n){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);"LE"===n?(t[e]=255&r,t[e+1]=r>>8&255):(t[e]=r>>8&255,t[e+1]=255&r)}(t,r+1,e,"LE")):(A(t,r,l.OP_PUSHDATA4),I(t,r+1,e,"LE")),n}function H(t,e){const r=k(t,e);let n,i;if(r<l.OP_PUSHDATA1)n=r,i=1;else if(r===l.OP_PUSHDATA1){if(e+2>t.length)return null;n=k(t,e+1),i=2}else if(r===l.OP_PUSHDATA2){if(e+3>t.length)return null;n=function(t,e,r){if(e+2>t.length)throw new Error("Offset is outside the bounds of Uint8Array");if("LE"===(r=r.toUpperCase())){let r=0;return r=(r<<8)+t[e+1],r=(r<<8)+t[e],r}{let r=0;return r=(r<<8)+t[e],r=(r<<8)+t[e+1],r}}(t,e+1,"LE"),i=3}else{if(e+5>t.length)return null;if(r!==l.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=T(t,e+1,"LE"),i=5}return{opcode:r,number:n,size:i}}function C(t){const e=typeof t;return"string"===e?`"${t}"`:"number"===e||"bigint"===e||"boolean"===e?`${t}`:"object"===e||"function"===e?(t&&Object.getPrototypeOf(t)?.constructor?.name)??"null":e}function R(t,e,r,n,i){const o=i&&"input"in i?i.input:r.value,s=i?.expected??t.expects??null,a=i?.received??C(o),u={kind:t.kind,type:t.type,input:o,expected:s,received:a,message:`Invalid ${e}: ${s?`Expected ${s} but r`:"R"}eceived ${a}`,requirement:t.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},f="schema"===t.kind,c=i?.message??t.message??(t.reference,void u.lang)??(f?void u.lang:null)??n.message??void u.lang;c&&(u.message="function"==typeof c?c(u):c),f&&(r.typed=!1),r.issues?r.issues.push(u):r.issues=[u]}function B(t,e){const r=[...new Set(t)];return r.length>1?`(${r.join(` ${e} `)})`:r[0]??"never"}var L=class extends Error{issues;constructor(t){super(t[0].message),this.name="ValiError",this.issues=t}};function D(t,e){return{kind:"validation",type:"every_item",reference:D,async:!1,expects:null,requirement:t,message:e,_run(t,e){return t.typed&&!t.value.every(this.requirement)&&R(this,"item",t,e),t}}}function V(t){return{kind:"validation",type:"integer",reference:V,async:!1,expects:null,requirement:Number.isInteger,message:t,_run(t,e){return t.typed&&!this.requirement(t.value)&&R(this,"integer",t,e),t}}}function K(t,e){return{kind:"validation",type:"length",reference:K,async:!1,expects:`${t}`,requirement:t,message:e,_run(t,e){return t.typed&&t.value.length!==this.requirement&&R(this,"length",t,e,{received:`${t.value.length}`}),t}}}function G(t,e){return{kind:"validation",type:"max_value",reference:G,async:!1,expects:`<=${t instanceof Date?t.toJSON():C(t)}`,requirement:t,message:e,_run(t,e){return t.typed&&t.value>this.requirement&&R(this,"value",t,e,{received:t.value instanceof Date?t.value.toJSON():C(t.value)}),t}}}function F(t,e){return{kind:"validation",type:"min_value",reference:F,async:!1,expects:`>=${t instanceof Date?t.toJSON():C(t)}`,requirement:t,message:e,_run(t,e){return t.typed&&t.value<this.requirement&&R(this,"value",t,e,{received:t.value instanceof Date?t.value.toJSON():C(t.value)}),t}}}function W(t,e,r){return"function"==typeof t.default?t.default(e,r):t.default}function M(t,e){return!t._run({typed:!1,value:e},{abortEarly:!0}).issues}function j(){return{kind:"schema",type:"any",reference:j,expects:"any",async:!1,_run:t=>(t.typed=!0,t)}}function X(t,e){return{kind:"schema",type:"array",reference:X,expects:"Array",async:!1,item:t,message:e,_run(t,e){const r=t.value;if(Array.isArray(r)){t.typed=!0,t.value=[];for(let n=0;n<r.length;n++){const i=r[n],o=this.item._run({typed:!1,value:i},e);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const e of o.issues)e.path?e.path.unshift(s):e.path=[s],t.issues?.push(e);if(t.issues||(t.issues=o.issues),e.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),t.value.push(o.value)}}else R(this,"type",t,e);return t}}}function $(t,e){return{kind:"schema",type:"custom",reference:$,expects:"unknown",async:!1,check:t,message:e,_run(t,e){return this.check(t.value)?t.typed=!0:R(this,"type",t,e),t}}}function z(t,e){return{kind:"schema",type:"instance",reference:z,expects:t.name,async:!1,class:t,message:e,_run(t,e){return t.value instanceof this.class?t.typed=!0:R(this,"type",t,e),t}}}function q(t,...e){const r={kind:"schema",type:"nullable",reference:q,expects:`(${t.expects} | null)`,async:!1,wrapped:t,_run(t,e){return null===t.value&&("default"in this&&(t.value=W(this,t,e)),null===t.value)?(t.typed=!0,t):this.wrapped._run(t,e)}};return 0 in e&&(r.default=e[0]),r}function Y(t,...e){const r={kind:"schema",type:"nullish",reference:Y,expects:`(${t.expects} | null | undefined)`,async:!1,wrapped:t,_run(t,e){return null!==t.value&&void 0!==t.value||("default"in this&&(t.value=W(this,t,e)),null!==t.value&&void 0!==t.value)?this.wrapped._run(t,e):(t.typed=!0,t)}};return 0 in e&&(r.default=e[0]),r}function Z(t){return{kind:"schema",type:"number",reference:Z,expects:"number",async:!1,message:t,_run(t,e){return"number"!=typeof t.value||isNaN(t.value)?R(this,"type",t,e):t.typed=!0,t}}}function Q(t,e){return{kind:"schema",type:"object",reference:Q,expects:"Object",async:!1,entries:t,message:e,_run(t,e){const r=t.value;if(r&&"object"==typeof r){t.typed=!0,t.value={};for(const n in this.entries){const i=r[n],o=this.entries[n]._run({typed:!1,value:i},e);if(o.issues){const s={type:"object",origin:"value",input:r,key:n,value:i};for(const e of o.issues)e.path?e.path.unshift(s):e.path=[s],t.issues?.push(e);if(t.issues||(t.issues=o.issues),e.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),(void 0!==o.value||n in r)&&(t.value[n]=o.value)}}else R(this,"type",t,e);return t}}}function J(t,...e){const r={kind:"schema",type:"optional",reference:J,expects:`(${t.expects} | undefined)`,async:!1,wrapped:t,_run(t,e){return void 0===t.value&&("default"in this&&(t.value=W(this,t,e)),void 0===t.value)?(t.typed=!0,t):this.wrapped._run(t,e)}};return 0 in e&&(r.default=e[0]),r}function tt(t){return{kind:"schema",type:"string",reference:tt,expects:"string",async:!1,message:t,_run(t,e){return"string"==typeof t.value?t.typed=!0:R(this,"type",t,e),t}}}function et(t,e){return{kind:"schema",type:"tuple",reference:et,expects:"Array",async:!1,items:t,message:e,_run(t,e){const r=t.value;if(Array.isArray(r)){t.typed=!0,t.value=[];for(let n=0;n<this.items.length;n++){const i=r[n],o=this.items[n]._run({typed:!1,value:i},e);if(o.issues){const s={type:"array",origin:"value",input:r,key:n,value:i};for(const e of o.issues)e.path?e.path.unshift(s):e.path=[s],t.issues?.push(e);if(t.issues||(t.issues=o.issues),e.abortEarly){t.typed=!1;break}}o.typed||(t.typed=!1),t.value.push(o.value)}}else R(this,"type",t,e);return t}}}function rt(t){let e;if(t)for(const r of t)e?e.push(...r.issues):e=r.issues;return e}function nt(t,e){return{kind:"schema",type:"union",reference:nt,expects:B(t.map((t=>t.expects)),"|"),async:!1,options:t,message:e,_run(t,e){let r,n,i;for(const o of this.options){const s=o._run({typed:!1,value:t.value},e);if(s.typed){if(!s.issues){r=s;break}n?n.push(s):n=[s]}else i?i.push(s):i=[s]}if(r)return r;if(n){if(1===n.length)return n[0];R(this,"type",t,e,{issues:rt(n)}),t.typed=!0}else{if(1===i?.length)return i[0];R(this,"type",t,e,{issues:rt(i)})}return t}}}function it(t,e,r){const n=t._run({typed:!1,value:e},function(t){return{lang:t?.lang??void 0,message:t?.message,abortEarly:t?.abortEarly??void 0,abortPipeEarly:t?.abortPipeEarly??void 0}}(r));if(n.issues)throw new L(n.issues);return n.value}function ot(t,e){const r={};for(const n in t.entries)r[n]=!e||e.includes(n)?J(t.entries[n]):t.entries[n];return{...t,entries:r}}function st(...t){return{...t[0],pipe:t,_run(e,r){for(const n of t)if("metadata"!==n.kind){if(e.issues&&("schema"===n.kind||"transformation"===n.kind)){e.typed=!1;break}e.issues&&(r.abortEarly||r.abortPipeEarly)||(e=n._run(e,r))}return e}}}const at=new Uint8Array(32),ut=v("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ft=t=>st(z(Uint8Array),K(t));function ct(t,e){return t.length===e.length&&t.every(((t,r)=>0===S(t,e[r])))}function ht(t){if(!(t instanceof Uint8Array))return!1;if(t.length<33)return!1;const e=t[0],r=t.slice(1,33);if(0===S(at,r))return!1;if(S(r,ut)>=0)return!1;if((2===e||3===e)&&33===t.length)return!0;const n=t.slice(33);return 0!==S(at,n)&&(!(S(n,ut)>=0)&&(4===e&&65===t.length))}const lt=254;function pt(t){return!(!t||!("output"in t))&&(t.output instanceof Uint8Array&&(void 0===t.version||(t.version&lt)===t.version))}function dt(t){return Array.isArray(t)?2===t.length&&t.every((t=>dt(t))):pt(t)}const yt=ft(32),wt=ft(20),gt=ft(32),Et=z(Uint8Array);st(tt(),function t(e,r){return{kind:"validation",type:"regex",reference:t,async:!1,expects:`${e}`,requirement:e,message:r,_run(t,e){return t.typed&&!this.requirement.test(t.value)&&R(this,"format",t,e),t}}}(/^([0-9a-f]{2})+$/i));const mt=st(Z(),V(),F(0),G(255)),bt=st(Z(),V(),F(0),G(4294967295)),vt=st(function t(e){return{kind:"schema",type:"bigint",reference:t,expects:"bigint",async:!1,message:e,_run(t,e){return"bigint"==typeof t.value?t.typed=!0:R(this,"type",t,e),t}}}(),F(0n),G(0x7fffffffffffffffn)),_t=t=>Q(Object.entries(t).reduce(((t,e)=>({...t,[e[0]]:Y(e[1])})),{})),St=new Uint8Array(1);function At(t){let e=0;for(;0===t[e];)++e;return e===t.length?St:128&(t=t.slice(e))[0]?m([St,t]):t}function It(t){0===t[0]&&(t=t.slice(1));const e=new Uint8Array(32),r=Math.max(0,32-t.length);return e.set(t,r),e}var kt=Object.freeze({__proto__:null,decode:function(t){const e=k(t,t.length-1);if(!Dt(e))throw new Error("Invalid hashType "+e);const r=function(t){if(t.length<8)throw new Error("DER sequence length is too short");if(t.length>72)throw new Error("DER sequence length is too long");if(48!==t[0])throw new Error("Expected DER sequence");if(t[1]!==t.length-2)throw new Error("DER sequence length is invalid");if(2!==t[2])throw new Error("Expected DER integer");const e=t[3];if(0===e)throw new Error("R length is zero");if(5+e>=t.length)throw new Error("R length is too long");if(2!==t[4+e])throw new Error("Expected DER integer (2)");const r=t[5+e];if(0===r)throw new Error("S length is zero");if(6+e+r!==t.length)throw new Error("S length is invalid");if(128&t[4])throw new Error("R value is negative");if(e>1&&0===t[4]&&!(128&t[5]))throw new Error("R value excessively padded");if(128&t[e+6])throw new Error("S value is negative");if(r>1&&0===t[e+6]&&!(128&t[e+7]))throw new Error("S value excessively padded");return{r:t.slice(4,4+e),s:t.slice(6+e)}}(t.subarray(0,-1));return{signature:m([It(r.r),It(r.s)]),hashType:e}},encode:function(t,e){if(it(Q({signature:ft(64),hashType:mt}),{signature:t,hashType:e}),!Dt(e))throw new Error("Invalid hashType "+e);const r=new Uint8Array(1);return A(r,0,e),m([h(At(t.slice(0,32)),At(t.slice(32,64))),r])}});const Tt=l.OP_RESERVED,Pt=X(nt([z(Uint8Array),Z()]));function xt(t){return M(Et,t)||function(t){return M(Z(),t)&&(t===l.OP_0||t>=l.OP_1&&t<=l.OP_16||t===l.OP_1NEGATE)}(t)}function Ot(t){return M(st(j(),D(xt)),t)}function Ut(t){return t.length-t.filter(xt).length}function Nt(t){return 0===t.length?l.OP_0:1===t.length?t[0]>=1&&t[0]<=16?Tt+t[0]:129===t[0]?l.OP_1NEGATE:void 0:void 0}function Ht(t){return t instanceof Uint8Array}function Ct(t){return t instanceof Uint8Array}function Rt(t){if(Ht(t))return t;it(Pt,t);const e=t.reduce(((t,e)=>Ct(e)?1===e.length&&void 0!==Nt(e)?t+1:t+U(e.length)+e.length:t+1),0),r=new Uint8Array(e);let n=0;if(t.forEach((t=>{if(Ct(t)){const e=Nt(t);if(void 0!==e)return A(r,n,e),void(n+=1);n+=N(r,t.length,n),r.set(t,n),n+=t.length}else A(r,n,t),n+=1})),n!==r.length)throw new Error("Could not decode chunks");return r}function Bt(t){if(M(Pt,t))return t;it(Et,t);const e=[];let r=0;for(;r<t.length;){const n=t[r];if(n>l.OP_0&&n<=l.OP_PUSHDATA4){const n=H(t,r);if(null===n)return null;if(r+=n.size,r+n.number>t.length)return null;const i=t.slice(r,r+n.number);r+=n.number;const o=Nt(i);void 0!==o?e.push(o):e.push(i)}else e.push(n),r+=1}return e}function Lt(t){return t=Bt(t),it($(Ot),t),t.map((t=>Ct(t)?t:t===l.OP_0?new Uint8Array(0):function(t){let e=Math.abs(t);const r=(n=e)>2147483647?5:n>8388607?4:n>32767?3:n>127?2:n>0?1:0;var n;const i=new Uint8Array(r),o=t<0;for(let t=0;t<r;++t)A(i,t,255&e),e>>=8;return 128&i[r-1]?A(i,r-1,o?128:0):o&&(i[r-1]|=128),i}(t-Tt)))}function Dt(t){const e=-129&t;return e>0&&e<4}function Vt(t){return t instanceof Uint8Array&&(!!Dt(t[t.length-1])&&function(t){if(t.length<8)return!1;if(t.length>72)return!1;if(48!==t[0])return!1;if(t[1]!==t.length-2)return!1;if(2!==t[2])return!1;const e=t[3];if(0===e)return!1;if(5+e>=t.length)return!1;if(2!==t[4+e])return!1;const r=t[5+e];return!(0===r||6+e+r!==t.length||128&t[4]||e>1&&0===t[4]&&!(128&t[5])||128&t[e+6]||r>1&&0===t[e+6]&&!(128&t[e+7]))}(t.slice(0,-1)))}const Kt=kt;function Gt(t,e,r){Object.defineProperty(t,e,{configurable:!0,enumerable:!0,get(){const t=r.call(this);return this[e]=t,t},set(t){Object.defineProperty(this,e,{configurable:!0,enumerable:!0,value:t,writable:!0})}})}function Ft(t){let e;return()=>(void 0!==e||(e=t()),e)}const Wt=l,Mt=Wt.OP_RESERVED;function jt(t,e){if(!(t.input||t.output||t.pubkeys&&void 0!==t.m||t.signatures))throw new TypeError("Not enough data");function r(t){return Vt(t)||void 0!==(e.allowIncomplete&&t===Wt.OP_0)}e=Object.assign({validate:!0},e||{}),it(ot(Q({network:Q({}),m:Z(),n:Z(),output:Et,pubkeys:X($(ht),"Received invalid pubkey"),signatures:X($(r),"Expected signature to be of type isAcceptableSignature"),input:Et})),t);const n={network:t.network||f};let i=[],o=!1;function s(t){o||(o=!0,i=Bt(t),n.m=i[0]-Mt,n.n=i[i.length-2]-Mt,n.pubkeys=i.slice(1,-2))}if(Gt(n,"output",(()=>{if(t.m&&n.n&&t.pubkeys)return Rt([].concat(Mt+t.m,t.pubkeys,Mt+n.n,Wt.OP_CHECKMULTISIG))})),Gt(n,"m",(()=>{if(n.output)return s(n.output),n.m})),Gt(n,"n",(()=>{if(n.pubkeys)return n.pubkeys.length})),Gt(n,"pubkeys",(()=>{if(t.output)return s(t.output),n.pubkeys})),Gt(n,"signatures",(()=>{if(t.input)return Bt(t.input).slice(1)})),Gt(n,"input",(()=>{if(t.signatures)return Rt([Wt.OP_0].concat(t.signatures))})),Gt(n,"witness",(()=>{if(n.input)return[]})),Gt(n,"name",(()=>{if(n.m&&n.n)return`p2ms(${n.m} of ${n.n})`})),e.validate){if(t.output){if(s(t.output),it(Z(),i[0],{message:"Output is invalid"}),it(Z(),i[i.length-2],{message:"Output is invalid"}),i[i.length-1]!==Wt.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==i.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every((t=>ht(t))))throw new TypeError("Output is invalid");if(void 0!==t.m&&t.m!==n.m)throw new TypeError("m mismatch");if(void 0!==t.n&&t.n!==n.n)throw new TypeError("n mismatch");if(t.pubkeys&&!ct(t.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(t.pubkeys){if(void 0!==t.n&&t.n!==t.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=t.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(t.signatures){if(t.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(t.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(t.input){if(t.input[0]!==Wt.OP_0)throw new TypeError("Input is invalid");if(0===n.signatures.length||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(t.signatures&&!ct(t.signatures,n.signatures))throw new TypeError("Signature mismatch");if(void 0!==t.m&&t.m!==t.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,t)}const Xt=l;function $t(t,e){if(!(t.input||t.output||t.pubkey||t.input||t.signature))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it(ot(Q({network:Q({}),output:Et,pubkey:$(ht,"invalid pubkey"),signature:$(Vt,"Expected signature to be of type isCanonicalScriptSignature"),input:Et})),t);const r=Ft((()=>Bt(t.input))),n={name:"p2pk",network:t.network||f};if(Gt(n,"output",(()=>{if(t.pubkey)return Rt([t.pubkey,Xt.OP_CHECKSIG])})),Gt(n,"pubkey",(()=>{if(t.output)return t.output.slice(1,-1)})),Gt(n,"signature",(()=>{if(t.input)return r()[0]})),Gt(n,"input",(()=>{if(t.signature)return Rt([t.signature])})),Gt(n,"witness",(()=>{if(n.input)return[]})),e.validate){if(t.output){if(t.output[t.output.length-1]!==Xt.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!ht(n.pubkey))throw new TypeError("Output pubkey is invalid");if(t.pubkey&&0!==S(t.pubkey,n.pubkey))throw new TypeError("Pubkey mismatch")}if(t.signature&&t.input&&0!==S(t.input,n.input))throw new TypeError("Signature mismatch");if(t.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!Vt(n.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(n,t)}function zt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function qt(t,...e){if(!((r=t)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function Yt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")} /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const Zt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Qt=(t,e)=>t<<32-e|t>>>e,Jt=(t,e)=>t<<e|t>>>32-e>>>0;function te(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),qt(t),t}new Uint8Array(new Uint32Array([287454020]).buffer)[0];class ee{clone(){return this._cloneInto()}}function re(t){const e=e=>t().update(te(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}const ne=(t,e,r)=>t&e^t&r^e&r;class ie extends ee{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Zt(this.buffer)}update(t){Yt(this);const{view:e,buffer:r,blockLen:n}=this,i=(t=te(t)).length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s!==n)r.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=Zt(t);for(;n<=i-o;o+=n)this.process(e,o)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){Yt(this),function(t,e){qt(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(r,0),o=0);for(let t=o;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,f=n?0:4;t.setUint32(e+u,s,n),t.setUint32(e+f,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=Zt(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<u;t++)s.setUint32(4*t,f[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=o,n%e&&t.buffer.set(r),t}}const oe=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),se=new Uint8Array(new Array(16).fill(0).map(((t,e)=>e)));let ae=[se],ue=[se.map((t=>(9*t+5)%16))];for(let t=0;t<4;t++)for(let e of[ae,ue])e.push(e[t].map((t=>oe[t])));const fe=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((t=>new Uint8Array(t))),ce=ae.map(((t,e)=>t.map((t=>fe[e][t])))),he=ue.map(((t,e)=>t.map((t=>fe[e][t])))),le=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),pe=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function de(t,e,r,n){return 0===t?e^r^n:1===t?e&r|~e&n:2===t?(e|~r)^n:3===t?e&n|r&~n:e^(r|~n)}const ye=new Uint32Array(16);class we extends ie{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:r,h3:n,h4:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.h0=0|t,this.h1=0|e,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)ye[r]=t.getUint32(e,!0);let r=0|this.h0,n=r,i=0|this.h1,o=i,s=0|this.h2,a=s,u=0|this.h3,f=u,c=0|this.h4,h=c;for(let t=0;t<5;t++){const e=4-t,l=le[t],p=pe[t],d=ae[t],y=ue[t],w=ce[t],g=he[t];for(let e=0;e<16;e++){const n=Jt(r+de(t,i,s,u)+ye[d[e]]+l,w[e])+c|0;r=c,c=u,u=0|Jt(s,10),s=i,i=n}for(let t=0;t<16;t++){const r=Jt(n+de(e,o,a,f)+ye[y[t]]+p,g[t])+h|0;n=h,h=f,f=0|Jt(a,10),a=o,o=r}}this.set(this.h1+s+f|0,this.h2+u+h|0,this.h3+c+n|0,this.h4+r+o|0,this.h0+i+a|0)}roundClean(){ye.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const ge=re((()=>new we)),Ee=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),be=new Uint32Array(64);class ve extends ie{constructor(){super(64,32,8,!1),this.A=0|me[0],this.B=0|me[1],this.C=0|me[2],this.D=0|me[3],this.E=0|me[4],this.F=0|me[5],this.G=0|me[6],this.H=0|me[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[t,e,r,n,i,o,s,a]}set(t,e,r,n,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)be[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=be[t-15],r=be[t-2],n=Qt(e,7)^Qt(e,18)^e>>>3,i=Qt(r,17)^Qt(r,19)^r>>>10;be[t]=i+be[t-7]+n+be[t-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:f}=this;for(let t=0;t<64;t++){const e=f+(Qt(s,6)^Qt(s,11)^Qt(s,25))+((c=s)&a^~c&u)+Ee[t]+be[t]|0,h=(Qt(r,2)^Qt(r,13)^Qt(r,22))+ne(r,n,i)|0;f=u,u=a,a=s,s=o+e|0,o=i,i=n,n=r,r=e+h|0}var c;r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,n,i,o,s,a,u,f)}roundClean(){be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class _e extends ve{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Se=re((()=>new ve)),Ae=re((()=>new _e));var Ie=Object.freeze({__proto__:null,SHA256:ve,sha256:Se,sha224:Ae});function ke(t){return ge(Se(t))}function Te(t){return Se(Se(t))}const Pe={"BIP0340/challenge":Uint8Array.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Uint8Array.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Uint8Array.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Uint8Array.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Uint8Array.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Uint8Array.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Uint8Array.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Uint8Array.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Uint8Array.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function xe(t,e){return Se(m([Pe[t],e]))}var Oe=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let t=0;t<e.length;t++)e[t]=255;for(let r=0;r<t.length;r++){const n=t.charAt(r),i=n.charCodeAt(0);if(255!==e[i])throw new TypeError(n+" is ambiguous");e[i]=r}const r=t.length,n=t.charAt(0),i=Math.log(r)/Math.log(256),o=Math.log(256)/Math.log(r);function s(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;let o=0,s=0,a=0;for(;t[o]===n;)s++,o++;const u=(t.length-o)*i+1>>>0,f=new Uint8Array(u);for(;t[o];){let n=e[t.charCodeAt(o)];if(255===n)return;let i=0;for(let t=u-1;(0!==n||i<a)&&-1!==t;t--,i++)n+=r*f[t]>>>0,f[t]=n%256>>>0,n=n/256>>>0;if(0!==n)throw new Error("Non-zero carry");a=i,o++}let c=u-a;for(;c!==u&&0===f[c];)c++;const h=new Uint8Array(s+(u-c));let l=s;for(;c!==u;)h[l++]=f[c++];return h}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";let i=0,s=0,a=0;const u=e.length;for(;a!==u&&0===e[a];)a++,i++;const f=(u-a)*o+1>>>0,c=new Uint8Array(f);for(;a!==u;){let t=e[a],n=0;for(let e=f-1;(0!==t||n<s)&&-1!==e;e--,n++)t+=256*c[e]>>>0,c[e]=t%r>>>0,t=t/r>>>0;if(0!==t)throw new Error("Non-zero carry");s=n,a++}let h=f-s;for(;h!==f&&0===c[h];)h++;let l=n.repeat(i);for(;h<f;++h)l+=t.charAt(c[h]);return l},decodeUnsafe:s,decode:function(t){const e=s(t);if(e)return e;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var Ue=function(t){function e(e){var r=e.slice(0,-4),n=e.slice(-4),i=t(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(e){var r=Uint8Array.from(e),n=t(r),i=r.length+4,o=new Uint8Array(i);return o.set(r,0),o.set(n.subarray(0,4),r.length),Oe.encode(o)},decode:function(t){var r=e(Oe.decode(t));if(null==r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(t){var r=Oe.decodeUnsafe(t);if(null!=r)return e(r)}}}((function(t){return Se(Se(t))}));const Ne=l;function He(t,e){if(!(t.address||t.hash||t.output||t.pubkey||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it(ot(Q({network:Q({}),address:tt(),hash:wt,output:ft(25),pubkey:$(ht),signature:$(Vt),input:Et})),t);const r=Ft((()=>{const e=Ue.decode(t.address);return{version:k(e,0),hash:e.slice(1)}})),n=Ft((()=>Bt(t.input))),i=t.network||f,o={name:"p2pkh",network:i};if(Gt(o,"address",(()=>{if(!o.hash)return;const t=new Uint8Array(21);return A(t,0,i.pubKeyHash),t.set(o.hash,1),Ue.encode(t)})),Gt(o,"hash",(()=>t.output?t.output.slice(3,23):t.address?r().hash:t.pubkey||o.pubkey?ke(t.pubkey||o.pubkey):void 0)),Gt(o,"output",(()=>{if(o.hash)return Rt([Ne.OP_DUP,Ne.OP_HASH160,o.hash,Ne.OP_EQUALVERIFY,Ne.OP_CHECKSIG])})),Gt(o,"pubkey",(()=>{if(t.input)return n()[1]})),Gt(o,"signature",(()=>{if(t.input)return n()[0]})),Gt(o,"input",(()=>{if(t.pubkey&&t.signature)return Rt([t.signature,t.pubkey])})),Gt(o,"witness",(()=>{if(o.input)return[]})),e.validate){let e=Uint8Array.from([]);if(t.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");e=r().hash}if(t.hash){if(e.length>0&&0!==S(e,t.hash))throw new TypeError("Hash mismatch");e=t.hash}if(t.output){if(25!==t.output.length||t.output[0]!==Ne.OP_DUP||t.output[1]!==Ne.OP_HASH160||20!==t.output[2]||t.output[23]!==Ne.OP_EQUALVERIFY||t.output[24]!==Ne.OP_CHECKSIG)throw new TypeError("Output is invalid");const r=t.output.slice(3,23);if(e.length>0&&0!==S(e,r))throw new TypeError("Hash mismatch");e=r}if(t.pubkey){const r=ke(t.pubkey);if(e.length>0&&0!==S(e,r))throw new TypeError("Hash mismatch");e=r}if(t.input){const r=n();if(2!==r.length)throw new TypeError("Input is invalid");if(!Vt(r[0]))throw new TypeError("Input has invalid signature");if(!ht(r[1]))throw new TypeError("Input has invalid pubkey");if(t.signature&&0!==S(t.signature,r[0]))throw new TypeError("Signature mismatch");if(t.pubkey&&0!==S(t.pubkey,r[1]))throw new TypeError("Pubkey mismatch");const i=ke(r[1]);if(e.length>0&&0!==S(e,i))throw new TypeError("Hash mismatch")}}return Object.assign(o,t)}const Ce=l;function Re(t,e){if(!(t.address||t.hash||t.output||t.redeem||t.input))throw new TypeError("Not enough data");e=Object.assign({validate:!0},e||{}),it(ot(Q({network:Q({}),address:tt(),hash:ft(20),output:ft(23),redeem:ot(Q({network:Q({}),output:Et,input:Et,witness:X(Et)})),input:Et,witness:X(Et)})),t);let r=t.network;r||(r=t.redeem&&t.redeem.network||f);const n={network:r},i=Ft((()=>{const e=Ue.decode(t.address);return{version:k(e,0),hash:e.slice(1)}})),o=Ft((()=>Bt(t.input))),s=Ft((()=>{const e=o(),n=e[e.length-1];return{network:r,output:n===Ce.OP_FALSE?Uint8Array.from([]):n,input:Rt(e.slice(0,-1)),witness:t.witness||[]}}));if(Gt(n,"address",(()=>{if(!n.hash)return;const t=new Uint8Array(21);return A(t,0,n.network.scriptHash),t.set(n.hash,1),Ue.encode(t)})),Gt(n,"hash",(()=>t.output?t.output.slice(2,22):t.address?i().hash:n.redeem&&n.redeem.output?ke(n.redeem.output):void 0)),Gt(n,"output",(()=>{if(n.hash)return Rt([Ce.OP_HASH160,n.hash,Ce.OP_EQUAL])})),Gt(n,"redeem",(()=>{if(t.input)return s()})),Gt(n,"input",(()=>{if(t.redeem&&t.redeem.input&&t.redeem.output)return Rt([].concat(Bt(t.redeem.input),t.redeem.output))})),Gt(n,"witness",(()=>n.redeem&&n.redeem.witness?n.redeem.witness:n.input?[]:void 0)),Gt(n,"name",(()=>{const t=["p2sh"];return void 0!==n.redeem&&void 0!==n.redeem.name&&t.push(n.redeem.name),t.join("-")})),e.validate){let e=Uint8Array.from([]);if(t.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==i().hash.length)throw new TypeError("Invalid address");e=i().hash}if(t.hash){if(e.length>0&&0!==S(e,t.hash))throw new TypeError("Hash mismatch");e=t.hash}if(t.output){if(23!==t.output.length||t.output[0]!==Ce.OP_HASH160||20!==t.output[1]||t.output[22]!==Ce.OP_EQUAL)throw new TypeError("Output is invalid");const r=t.output.slice(2,22);if(e.length>0&&0!==S(e,r))throw new TypeError("Hash mismatch");e=r}const n=t=>{if(t.output){const r=Bt(t.output);if(!r||r.length<1)throw new TypeError("Redeem.output too short");if(t.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(Ut(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=ke(t.output);if(e.length>0&&0!==S(e,n))throw new TypeError("Hash mismatch");e=n}if(t.input){const e=t.input.length>0,r=t.witness&&t.witness.length>0;if(!e&&!r)throw new TypeError("Empty input");if(e&&r)throw new TypeError("Input and witness provided");if(e){if(!Ot(Bt(t.input)))throw new TypeError("Non push-only scriptSig")}}};if(t.input){const t=o();if(!t||t.length<1)throw new TypeError("Input too short");if(!(s().output instanceof Uint8Array))throw new TypeError("Input is invalid");n(s())}if(t.redeem){if(t.redeem.network&&t.redeem.network!==r)throw new TypeError("Network mismatch");if(t.input){const e=s();if(t.redeem.output&&0!==S(t.redeem.output,e.output))throw new TypeError("Redeem.output mismatch");if(t.redeem.input&&0!==S(t.redeem.input,e.input))throw new TypeError("Redeem.input mismatch")}n(t.redeem)}if(t.witness&&t.redeem&&t.redeem.witness&&!ct(t.redeem.witness,t.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,t)}var Be,Le=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.bech32m=e.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<r.length;t++){const e=r.charAt(t);n[e]=t}function i(t){const e=t>>25;return(33554431&t)<<5^996825010&-(e>>0&1)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=i(e)^n>>5}e=i(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=i(e)^31&n}return e}function s(t,e,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let n=0;n<t.length;++n)for(i=i<<e|t[n],o+=e;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=e)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function a(t){return s(t,8,5,!0)}function u(t){const e=s(t,5,8,