@omnity/ree-client-ts-sdk 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +29 -29
- package/dist/index.es.js +1463 -1444
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";var rh=e=>{throw TypeError(e)};var ih=(e,t,n)=>t.has(e)||rh("Cannot "+n);var Ue=(e,t,n)=>(ih(e,t,"read from private field"),n?n.call(e):t.get(e)),Qt=(e,t,n)=>t.has(e)?rh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jt=(e,t,n,r)=>(ih(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var sh=(e,t,n,r)=>({set _(i){jt(e,t,i,n)},get _(){return Ue(e,t,r)}});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function _w(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function $p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var
|
|
1
|
+
"use strict";var rh=e=>{throw TypeError(e)};var ih=(e,t,n)=>t.has(e)||rh("Cannot "+n);var Ue=(e,t,n)=>(ih(e,t,"read from private field"),n?n.call(e):t.get(e)),Qt=(e,t,n)=>t.has(e)?rh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jt=(e,t,n,r)=>(ih(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var sh=(e,t,n,r)=>({set _(i){jt(e,t,i,n)},get _(){return Ue(e,t,r)}});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function _w(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function $p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var uu={},Fs={},oh;function Sw(){if(oh)return Fs;oh=1,Fs.byteLength=c,Fs.toByteArray=u,Fs.fromByteArray=p;for(var e=[],t=[],n=typeof Uint8Array<"u"?Uint8Array:Array,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,s=r.length;i<s;++i)e[i]=r[i],t[r.charCodeAt(i)]=i;t[45]=62,t[95]=63;function o(y){var g=y.length;if(g%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var w=y.indexOf("=");w===-1&&(w=g);var E=w===g?0:4-w%4;return[w,E]}function c(y){var g=o(y),w=g[0],E=g[1];return(w+E)*3/4-E}function a(y,g,w){return(g+w)*3/4-w}function u(y){var g,w=o(y),E=w[0],_=w[1],S=new n(a(y,E,_)),m=0,T=_>0?E-4:E,I;for(I=0;I<T;I+=4)g=t[y.charCodeAt(I)]<<18|t[y.charCodeAt(I+1)]<<12|t[y.charCodeAt(I+2)]<<6|t[y.charCodeAt(I+3)],S[m++]=g>>16&255,S[m++]=g>>8&255,S[m++]=g&255;return _===2&&(g=t[y.charCodeAt(I)]<<2|t[y.charCodeAt(I+1)]>>4,S[m++]=g&255),_===1&&(g=t[y.charCodeAt(I)]<<10|t[y.charCodeAt(I+1)]<<4|t[y.charCodeAt(I+2)]>>2,S[m++]=g>>8&255,S[m++]=g&255),S}function f(y){return e[y>>18&63]+e[y>>12&63]+e[y>>6&63]+e[y&63]}function l(y,g,w){for(var E,_=[],S=g;S<w;S+=3)E=(y[S]<<16&16711680)+(y[S+1]<<8&65280)+(y[S+2]&255),_.push(f(E));return _.join("")}function p(y){for(var g,w=y.length,E=w%3,_=[],S=16383,m=0,T=w-E;m<T;m+=S)_.push(l(y,m,m+S>T?T:m+S));return E===1?(g=y[w-1],_.push(e[g>>2]+e[g<<4&63]+"==")):E===2&&(g=(y[w-2]<<8)+y[w-1],_.push(e[g>>10]+e[g>>4&63]+e[g<<2&63]+"=")),_.join("")}return Fs}var uc={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */var ch;function Tw(){return ch||(ch=1,uc.read=function(e,t,n,r,i){var s,o,c=i*8-r-1,a=(1<<c)-1,u=a>>1,f=-7,l=n?i-1:0,p=n?-1:1,y=e[t+l];for(l+=p,s=y&(1<<-f)-1,y>>=-f,f+=c;f>0;s=s*256+e[t+l],l+=p,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=r;f>0;o=o*256+e[t+l],l+=p,f-=8);if(s===0)s=1-u;else{if(s===a)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,r),s=s-u}return(y?-1:1)*o*Math.pow(2,s-r)},uc.write=function(e,t,n,r,i,s){var o,c,a,u=s*8-i-1,f=(1<<u)-1,l=f>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=r?0:s-1,g=r?1:-1,w=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,o=f):(o=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-o))<1&&(o--,a*=2),o+l>=1?t+=p/a:t+=p*Math.pow(2,1-l),t*a>=2&&(o++,a/=2),o+l>=f?(c=0,o=f):o+l>=1?(c=(t*a-1)*Math.pow(2,i),o=o+l):(c=t*Math.pow(2,l-1)*Math.pow(2,i),o=0));i>=8;e[n+y]=c&255,y+=g,c/=256,i-=8);for(o=o<<i|c,u+=i;u>0;e[n+y]=o&255,y+=g,o/=256,u-=8);e[n+y-g]|=w*128}),uc}/*!
|
|
2
2
|
* The buffer module from node.js, for the browser.
|
|
3
3
|
*
|
|
4
4
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
5
|
* @license MIT
|
|
6
|
-
*/var ah;function Vo(){return ah||(ah=1,(function(e){const t=Sw(),n=Tw(),r=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=S,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,c.TYPED_ARRAY_SUPPORT=s(),!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const k=new Uint8Array(1),d={foo:function(){return 42}};return Object.setPrototypeOf(d,Uint8Array.prototype),Object.setPrototypeOf(k,d),k.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function o(k){if(k>i)throw new RangeError('The value "'+k+'" is invalid for option "size"');const d=new Uint8Array(k);return Object.setPrototypeOf(d,c.prototype),d}function c(k,d,h){if(typeof k=="number"){if(typeof d=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(k)}return a(k,d,h)}c.poolSize=8192;function a(k,d,h){if(typeof k=="string")return p(k,d);if(ArrayBuffer.isView(k))return g(k);if(k==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k);if(et(k,ArrayBuffer)||k&&et(k.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(et(k,SharedArrayBuffer)||k&&et(k.buffer,SharedArrayBuffer)))return w(k,d,h);if(typeof k=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const b=k.valueOf&&k.valueOf();if(b!=null&&b!==k)return c.from(b,d,h);const B=E(k);if(B)return B;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof k[Symbol.toPrimitive]=="function")return c.from(k[Symbol.toPrimitive]("string"),d,h);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k)}c.from=function(k,d,h){return a(k,d,h)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array);function u(k){if(typeof k!="number")throw new TypeError('"size" argument must be of type number');if(k<0)throw new RangeError('The value "'+k+'" is invalid for option "size"')}function f(k,d,h){return u(k),k<=0?o(k):d!==void 0?typeof h=="string"?o(k).fill(d,h):o(k).fill(d):o(k)}c.alloc=function(k,d,h){return f(k,d,h)};function l(k){return u(k),o(k<0?0:_(k)|0)}c.allocUnsafe=function(k){return l(k)},c.allocUnsafeSlow=function(k){return l(k)};function p(k,d){if((typeof d!="string"||d==="")&&(d="utf8"),!c.isEncoding(d))throw new TypeError("Unknown encoding: "+d);const h=m(k,d)|0;let b=o(h);const B=b.write(k,d);return B!==h&&(b=b.slice(0,B)),b}function y(k){const d=k.length<0?0:_(k.length)|0,h=o(d);for(let b=0;b<d;b+=1)h[b]=k[b]&255;return h}function g(k){if(et(k,Uint8Array)){const d=new Uint8Array(k);return w(d.buffer,d.byteOffset,d.byteLength)}return y(k)}function w(k,d,h){if(d<0||k.byteLength<d)throw new RangeError('"offset" is outside of buffer bounds');if(k.byteLength<d+(h||0))throw new RangeError('"length" is outside of buffer bounds');let b;return d===void 0&&h===void 0?b=new Uint8Array(k):h===void 0?b=new Uint8Array(k,d):b=new Uint8Array(k,d,h),Object.setPrototypeOf(b,c.prototype),b}function E(k){if(c.isBuffer(k)){const d=_(k.length)|0,h=o(d);return h.length===0||k.copy(h,0,0,d),h}if(k.length!==void 0)return typeof k.length!="number"||Ne(k.length)?o(0):y(k);if(k.type==="Buffer"&&Array.isArray(k.data))return y(k.data)}function _(k){if(k>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return k|0}function S(k){return+k!=k&&(k=0),c.alloc(+k)}c.isBuffer=function(d){return d!=null&&d._isBuffer===!0&&d!==c.prototype},c.compare=function(d,h){if(et(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),et(h,Uint8Array)&&(h=c.from(h,h.offset,h.byteLength)),!c.isBuffer(d)||!c.isBuffer(h))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(d===h)return 0;let b=d.length,B=h.length;for(let C=0,j=Math.min(b,B);C<j;++C)if(d[C]!==h[C]){b=d[C],B=h[C];break}return b<B?-1:B<b?1:0},c.isEncoding=function(d){switch(String(d).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(d,h){if(!Array.isArray(d))throw new TypeError('"list" argument must be an Array of Buffers');if(d.length===0)return c.alloc(0);let b;if(h===void 0)for(h=0,b=0;b<d.length;++b)h+=d[b].length;const B=c.allocUnsafe(h);let C=0;for(b=0;b<d.length;++b){let j=d[b];if(et(j,Uint8Array))C+j.length>B.length?(c.isBuffer(j)||(j=c.from(j)),j.copy(B,C)):Uint8Array.prototype.set.call(B,j,C);else if(c.isBuffer(j))j.copy(B,C);else throw new TypeError('"list" argument must be an Array of Buffers');C+=j.length}return B};function m(k,d){if(c.isBuffer(k))return k.length;if(ArrayBuffer.isView(k)||et(k,ArrayBuffer))return k.byteLength;if(typeof k!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof k);const h=k.length,b=arguments.length>2&&arguments[2]===!0;if(!b&&h===0)return 0;let B=!1;for(;;)switch(d){case"ascii":case"latin1":case"binary":return h;case"utf8":case"utf-8":return Ze(k).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return h*2;case"hex":return h>>>1;case"base64":return Ae(k).length;default:if(B)return b?-1:Ze(k).length;d=(""+d).toLowerCase(),B=!0}}c.byteLength=m;function T(k,d,h){let b=!1;if((d===void 0||d<0)&&(d=0),d>this.length||((h===void 0||h>this.length)&&(h=this.length),h<=0)||(h>>>=0,d>>>=0,h<=d))return"";for(k||(k="utf8");;)switch(k){case"hex":return O(this,d,h);case"utf8":case"utf-8":return K(this,d,h);case"ascii":return F(this,d,h);case"latin1":case"binary":return x(this,d,h);case"base64":return H(this,d,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,d,h);default:if(b)throw new TypeError("Unknown encoding: "+k);k=(k+"").toLowerCase(),b=!0}}c.prototype._isBuffer=!0;function I(k,d,h){const b=k[d];k[d]=k[h],k[h]=b}c.prototype.swap16=function(){const d=this.length;if(d%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let h=0;h<d;h+=2)I(this,h,h+1);return this},c.prototype.swap32=function(){const d=this.length;if(d%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let h=0;h<d;h+=4)I(this,h,h+3),I(this,h+1,h+2);return this},c.prototype.swap64=function(){const d=this.length;if(d%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let h=0;h<d;h+=8)I(this,h,h+7),I(this,h+1,h+6),I(this,h+2,h+5),I(this,h+3,h+4);return this},c.prototype.toString=function(){const d=this.length;return d===0?"":arguments.length===0?K(this,0,d):T.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(d){if(!c.isBuffer(d))throw new TypeError("Argument must be a Buffer");return this===d?!0:c.compare(this,d)===0},c.prototype.inspect=function(){let d="";const h=e.INSPECT_MAX_BYTES;return d=this.toString("hex",0,h).replace(/(.{2})/g,"$1 ").trim(),this.length>h&&(d+=" ... "),"<Buffer "+d+">"},r&&(c.prototype[r]=c.prototype.inspect),c.prototype.compare=function(d,h,b,B,C){if(et(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),!c.isBuffer(d))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof d);if(h===void 0&&(h=0),b===void 0&&(b=d?d.length:0),B===void 0&&(B=0),C===void 0&&(C=this.length),h<0||b>d.length||B<0||C>this.length)throw new RangeError("out of range index");if(B>=C&&h>=b)return 0;if(B>=C)return-1;if(h>=b)return 1;if(h>>>=0,b>>>=0,B>>>=0,C>>>=0,this===d)return 0;let j=C-B,D=b-h;const re=Math.min(j,D),Q=this.slice(B,C),ue=d.slice(h,b);for(let le=0;le<re;++le)if(Q[le]!==ue[le]){j=Q[le],D=ue[le];break}return j<D?-1:D<j?1:0};function A(k,d,h,b,B){if(k.length===0)return-1;if(typeof h=="string"?(b=h,h=0):h>2147483647?h=2147483647:h<-2147483648&&(h=-2147483648),h=+h,Ne(h)&&(h=B?0:k.length-1),h<0&&(h=k.length+h),h>=k.length){if(B)return-1;h=k.length-1}else if(h<0)if(B)h=0;else return-1;if(typeof d=="string"&&(d=c.from(d,b)),c.isBuffer(d))return d.length===0?-1:U(k,d,h,b,B);if(typeof d=="number")return d=d&255,typeof Uint8Array.prototype.indexOf=="function"?B?Uint8Array.prototype.indexOf.call(k,d,h):Uint8Array.prototype.lastIndexOf.call(k,d,h):U(k,[d],h,b,B);throw new TypeError("val must be string, number or Buffer")}function U(k,d,h,b,B){let C=1,j=k.length,D=d.length;if(b!==void 0&&(b=String(b).toLowerCase(),b==="ucs2"||b==="ucs-2"||b==="utf16le"||b==="utf-16le")){if(k.length<2||d.length<2)return-1;C=2,j/=2,D/=2,h/=2}function re(ue,le){return C===1?ue[le]:ue.readUInt16BE(le*C)}let Q;if(B){let ue=-1;for(Q=h;Q<j;Q++)if(re(k,Q)===re(d,ue===-1?0:Q-ue)){if(ue===-1&&(ue=Q),Q-ue+1===D)return ue*C}else ue!==-1&&(Q-=Q-ue),ue=-1}else for(h+D>j&&(h=j-D),Q=h;Q>=0;Q--){let ue=!0;for(let le=0;le<D;le++)if(re(k,Q+le)!==re(d,le)){ue=!1;break}if(ue)return Q}return-1}c.prototype.includes=function(d,h,b){return this.indexOf(d,h,b)!==-1},c.prototype.indexOf=function(d,h,b){return A(this,d,h,b,!0)},c.prototype.lastIndexOf=function(d,h,b){return A(this,d,h,b,!1)};function M(k,d,h,b){h=Number(h)||0;const B=k.length-h;b?(b=Number(b),b>B&&(b=B)):b=B;const C=d.length;b>C/2&&(b=C/2);let j;for(j=0;j<b;++j){const D=parseInt(d.substr(j*2,2),16);if(Ne(D))return j;k[h+j]=D}return j}function v(k,d,h,b){return ln(Ze(d,k.length-h),k,h,b)}function R(k,d,h,b){return ln(st(d),k,h,b)}function V(k,d,h,b){return ln(Ae(d),k,h,b)}function W(k,d,h,b){return ln(St(d,k.length-h),k,h,b)}c.prototype.write=function(d,h,b,B){if(h===void 0)B="utf8",b=this.length,h=0;else if(b===void 0&&typeof h=="string")B=h,b=this.length,h=0;else if(isFinite(h))h=h>>>0,isFinite(b)?(b=b>>>0,B===void 0&&(B="utf8")):(B=b,b=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const C=this.length-h;if((b===void 0||b>C)&&(b=C),d.length>0&&(b<0||h<0)||h>this.length)throw new RangeError("Attempt to write outside buffer bounds");B||(B="utf8");let j=!1;for(;;)switch(B){case"hex":return M(this,d,h,b);case"utf8":case"utf-8":return v(this,d,h,b);case"ascii":case"latin1":case"binary":return R(this,d,h,b);case"base64":return V(this,d,h,b);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return W(this,d,h,b);default:if(j)throw new TypeError("Unknown encoding: "+B);B=(""+B).toLowerCase(),j=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function H(k,d,h){return d===0&&h===k.length?t.fromByteArray(k):t.fromByteArray(k.slice(d,h))}function K(k,d,h){h=Math.min(k.length,h);const b=[];let B=d;for(;B<h;){const C=k[B];let j=null,D=C>239?4:C>223?3:C>191?2:1;if(B+D<=h){let re,Q,ue,le;switch(D){case 1:C<128&&(j=C);break;case 2:re=k[B+1],(re&192)===128&&(le=(C&31)<<6|re&63,le>127&&(j=le));break;case 3:re=k[B+1],Q=k[B+2],(re&192)===128&&(Q&192)===128&&(le=(C&15)<<12|(re&63)<<6|Q&63,le>2047&&(le<55296||le>57343)&&(j=le));break;case 4:re=k[B+1],Q=k[B+2],ue=k[B+3],(re&192)===128&&(Q&192)===128&&(ue&192)===128&&(le=(C&15)<<18|(re&63)<<12|(Q&63)<<6|ue&63,le>65535&&le<1114112&&(j=le))}}j===null?(j=65533,D=1):j>65535&&(j-=65536,b.push(j>>>10&1023|55296),j=56320|j&1023),b.push(j),B+=D}return L(b)}const N=4096;function L(k){const d=k.length;if(d<=N)return String.fromCharCode.apply(String,k);let h="",b=0;for(;b<d;)h+=String.fromCharCode.apply(String,k.slice(b,b+=N));return h}function F(k,d,h){let b="";h=Math.min(k.length,h);for(let B=d;B<h;++B)b+=String.fromCharCode(k[B]&127);return b}function x(k,d,h){let b="";h=Math.min(k.length,h);for(let B=d;B<h;++B)b+=String.fromCharCode(k[B]);return b}function O(k,d,h){const b=k.length;(!d||d<0)&&(d=0),(!h||h<0||h>b)&&(h=b);let B="";for(let C=d;C<h;++C)B+=se[k[C]];return B}function q(k,d,h){const b=k.slice(d,h);let B="";for(let C=0;C<b.length-1;C+=2)B+=String.fromCharCode(b[C]+b[C+1]*256);return B}c.prototype.slice=function(d,h){const b=this.length;d=~~d,h=h===void 0?b:~~h,d<0?(d+=b,d<0&&(d=0)):d>b&&(d=b),h<0?(h+=b,h<0&&(h=0)):h>b&&(h=b),h<d&&(h=d);const B=this.subarray(d,h);return Object.setPrototypeOf(B,c.prototype),B};function P(k,d,h){if(k%1!==0||k<0)throw new RangeError("offset is not uint");if(k+d>h)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d],C=1,j=0;for(;++j<h&&(C*=256);)B+=this[d+j]*C;return B},c.prototype.readUintBE=c.prototype.readUIntBE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d+--h],C=1;for(;h>0&&(C*=256);)B+=this[d+--h]*C;return B},c.prototype.readUint8=c.prototype.readUInt8=function(d,h){return d=d>>>0,h||P(d,1,this.length),this[d]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(d,h){return d=d>>>0,h||P(d,2,this.length),this[d]|this[d+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(d,h){return d=d>>>0,h||P(d,2,this.length),this[d]<<8|this[d+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(d,h){return d=d>>>0,h||P(d,4,this.length),(this[d]|this[d+1]<<8|this[d+2]<<16)+this[d+3]*16777216},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]*16777216+(this[d+1]<<16|this[d+2]<<8|this[d+3])},c.prototype.readBigUInt64LE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=h+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24,C=this[++d]+this[++d]*2**8+this[++d]*2**16+b*2**24;return BigInt(B)+(BigInt(C)<<BigInt(32))}),c.prototype.readBigUInt64BE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=h*2**24+this[++d]*2**16+this[++d]*2**8+this[++d],C=this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b;return(BigInt(B)<<BigInt(32))+BigInt(C)}),c.prototype.readIntLE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d],C=1,j=0;for(;++j<h&&(C*=256);)B+=this[d+j]*C;return C*=128,B>=C&&(B-=Math.pow(2,8*h)),B},c.prototype.readIntBE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=h,C=1,j=this[d+--B];for(;B>0&&(C*=256);)j+=this[d+--B]*C;return C*=128,j>=C&&(j-=Math.pow(2,8*h)),j},c.prototype.readInt8=function(d,h){return d=d>>>0,h||P(d,1,this.length),this[d]&128?(255-this[d]+1)*-1:this[d]},c.prototype.readInt16LE=function(d,h){d=d>>>0,h||P(d,2,this.length);const b=this[d]|this[d+1]<<8;return b&32768?b|4294901760:b},c.prototype.readInt16BE=function(d,h){d=d>>>0,h||P(d,2,this.length);const b=this[d+1]|this[d]<<8;return b&32768?b|4294901760:b},c.prototype.readInt32LE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]|this[d+1]<<8|this[d+2]<<16|this[d+3]<<24},c.prototype.readInt32BE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]<<24|this[d+1]<<16|this[d+2]<<8|this[d+3]},c.prototype.readBigInt64LE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=this[d+4]+this[d+5]*2**8+this[d+6]*2**16+(b<<24);return(BigInt(B)<<BigInt(32))+BigInt(h+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24)}),c.prototype.readBigInt64BE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=(h<<24)+this[++d]*2**16+this[++d]*2**8+this[++d];return(BigInt(B)<<BigInt(32))+BigInt(this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b)}),c.prototype.readFloatLE=function(d,h){return d=d>>>0,h||P(d,4,this.length),n.read(this,d,!0,23,4)},c.prototype.readFloatBE=function(d,h){return d=d>>>0,h||P(d,4,this.length),n.read(this,d,!1,23,4)},c.prototype.readDoubleLE=function(d,h){return d=d>>>0,h||P(d,8,this.length),n.read(this,d,!0,52,8)},c.prototype.readDoubleBE=function(d,h){return d=d>>>0,h||P(d,8,this.length),n.read(this,d,!1,52,8)};function $(k,d,h,b,B,C){if(!c.isBuffer(k))throw new TypeError('"buffer" argument must be a Buffer instance');if(d>B||d<C)throw new RangeError('"value" argument is out of bounds');if(h+b>k.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(d,h,b,B){if(d=+d,h=h>>>0,b=b>>>0,!B){const D=Math.pow(2,8*b)-1;$(this,d,h,b,D,0)}let C=1,j=0;for(this[h]=d&255;++j<b&&(C*=256);)this[h+j]=d/C&255;return h+b},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(d,h,b,B){if(d=+d,h=h>>>0,b=b>>>0,!B){const D=Math.pow(2,8*b)-1;$(this,d,h,b,D,0)}let C=b-1,j=1;for(this[h+C]=d&255;--C>=0&&(j*=256);)this[h+C]=d/j&255;return h+b},c.prototype.writeUint8=c.prototype.writeUInt8=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,1,255,0),this[h]=d&255,h+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,65535,0),this[h]=d&255,this[h+1]=d>>>8,h+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,65535,0),this[h]=d>>>8,this[h+1]=d&255,h+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,4294967295,0),this[h+3]=d>>>24,this[h+2]=d>>>16,this[h+1]=d>>>8,this[h]=d&255,h+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,4294967295,0),this[h]=d>>>24,this[h+1]=d>>>16,this[h+2]=d>>>8,this[h+3]=d&255,h+4};function G(k,d,h,b,B){pe(d,b,B,k,h,7);let C=Number(d&BigInt(4294967295));k[h++]=C,C=C>>8,k[h++]=C,C=C>>8,k[h++]=C,C=C>>8,k[h++]=C;let j=Number(d>>BigInt(32)&BigInt(4294967295));return k[h++]=j,j=j>>8,k[h++]=j,j=j>>8,k[h++]=j,j=j>>8,k[h++]=j,h}function X(k,d,h,b,B){pe(d,b,B,k,h,7);let C=Number(d&BigInt(4294967295));k[h+7]=C,C=C>>8,k[h+6]=C,C=C>>8,k[h+5]=C,C=C>>8,k[h+4]=C;let j=Number(d>>BigInt(32)&BigInt(4294967295));return k[h+3]=j,j=j>>8,k[h+2]=j,j=j>>8,k[h+1]=j,j=j>>8,k[h]=j,h+8}c.prototype.writeBigUInt64LE=te(function(d,h=0){return G(this,d,h,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=te(function(d,h=0){return X(this,d,h,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(d,h,b,B){if(d=+d,h=h>>>0,!B){const re=Math.pow(2,8*b-1);$(this,d,h,b,re-1,-re)}let C=0,j=1,D=0;for(this[h]=d&255;++C<b&&(j*=256);)d<0&&D===0&&this[h+C-1]!==0&&(D=1),this[h+C]=(d/j>>0)-D&255;return h+b},c.prototype.writeIntBE=function(d,h,b,B){if(d=+d,h=h>>>0,!B){const re=Math.pow(2,8*b-1);$(this,d,h,b,re-1,-re)}let C=b-1,j=1,D=0;for(this[h+C]=d&255;--C>=0&&(j*=256);)d<0&&D===0&&this[h+C+1]!==0&&(D=1),this[h+C]=(d/j>>0)-D&255;return h+b},c.prototype.writeInt8=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,1,127,-128),d<0&&(d=255+d+1),this[h]=d&255,h+1},c.prototype.writeInt16LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,32767,-32768),this[h]=d&255,this[h+1]=d>>>8,h+2},c.prototype.writeInt16BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,32767,-32768),this[h]=d>>>8,this[h+1]=d&255,h+2},c.prototype.writeInt32LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,2147483647,-2147483648),this[h]=d&255,this[h+1]=d>>>8,this[h+2]=d>>>16,this[h+3]=d>>>24,h+4},c.prototype.writeInt32BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,2147483647,-2147483648),d<0&&(d=4294967295+d+1),this[h]=d>>>24,this[h+1]=d>>>16,this[h+2]=d>>>8,this[h+3]=d&255,h+4},c.prototype.writeBigInt64LE=te(function(d,h=0){return G(this,d,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=te(function(d,h=0){return X(this,d,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Y(k,d,h,b,B,C){if(h+b>k.length)throw new RangeError("Index out of range");if(h<0)throw new RangeError("Index out of range")}function oe(k,d,h,b,B){return d=+d,h=h>>>0,B||Y(k,d,h,4),n.write(k,d,h,b,23,4),h+4}c.prototype.writeFloatLE=function(d,h,b){return oe(this,d,h,!0,b)},c.prototype.writeFloatBE=function(d,h,b){return oe(this,d,h,!1,b)};function ae(k,d,h,b,B){return d=+d,h=h>>>0,B||Y(k,d,h,8),n.write(k,d,h,b,52,8),h+8}c.prototype.writeDoubleLE=function(d,h,b){return ae(this,d,h,!0,b)},c.prototype.writeDoubleBE=function(d,h,b){return ae(this,d,h,!1,b)},c.prototype.copy=function(d,h,b,B){if(!c.isBuffer(d))throw new TypeError("argument should be a Buffer");if(b||(b=0),!B&&B!==0&&(B=this.length),h>=d.length&&(h=d.length),h||(h=0),B>0&&B<b&&(B=b),B===b||d.length===0||this.length===0)return 0;if(h<0)throw new RangeError("targetStart out of bounds");if(b<0||b>=this.length)throw new RangeError("Index out of range");if(B<0)throw new RangeError("sourceEnd out of bounds");B>this.length&&(B=this.length),d.length-h<B-b&&(B=d.length-h+b);const C=B-b;return this===d&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(h,b,B):Uint8Array.prototype.set.call(d,this.subarray(b,B),h),C},c.prototype.fill=function(d,h,b,B){if(typeof d=="string"){if(typeof h=="string"?(B=h,h=0,b=this.length):typeof b=="string"&&(B=b,b=this.length),B!==void 0&&typeof B!="string")throw new TypeError("encoding must be a string");if(typeof B=="string"&&!c.isEncoding(B))throw new TypeError("Unknown encoding: "+B);if(d.length===1){const j=d.charCodeAt(0);(B==="utf8"&&j<128||B==="latin1")&&(d=j)}}else typeof d=="number"?d=d&255:typeof d=="boolean"&&(d=Number(d));if(h<0||this.length<h||this.length<b)throw new RangeError("Out of range index");if(b<=h)return this;h=h>>>0,b=b===void 0?this.length:b>>>0,d||(d=0);let C;if(typeof d=="number")for(C=h;C<b;++C)this[C]=d;else{const j=c.isBuffer(d)?d:c.from(d,B),D=j.length;if(D===0)throw new TypeError('The value "'+d+'" is invalid for argument "value"');for(C=0;C<b-h;++C)this[C+h]=j[C%D]}return this};const ee={};function Z(k,d,h){ee[k]=class extends h{constructor(){super(),Object.defineProperty(this,"message",{value:d.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${k}]`,this.stack,delete this.name}get code(){return k}set code(B){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:B,writable:!0})}toString(){return`${this.name} [${k}]: ${this.message}`}}}Z("ERR_BUFFER_OUT_OF_BOUNDS",function(k){return k?`${k} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Z("ERR_INVALID_ARG_TYPE",function(k,d){return`The "${k}" argument must be of type number. Received type ${typeof d}`},TypeError),Z("ERR_OUT_OF_RANGE",function(k,d,h){let b=`The value of "${k}" is out of range.`,B=h;return Number.isInteger(h)&&Math.abs(h)>2**32?B=ce(String(h)):typeof h=="bigint"&&(B=String(h),(h>BigInt(2)**BigInt(32)||h<-(BigInt(2)**BigInt(32)))&&(B=ce(B)),B+="n"),b+=` It must be ${d}. Received ${B}`,b},RangeError);function ce(k){let d="",h=k.length;const b=k[0]==="-"?1:0;for(;h>=b+4;h-=3)d=`_${k.slice(h-3,h)}${d}`;return`${k.slice(0,h)}${d}`}function ge(k,d,h){J(d,"offset"),(k[d]===void 0||k[d+h]===void 0)&&fe(d,k.length-(h+1))}function pe(k,d,h,b,B,C){if(k>h||k<d){const j=typeof d=="bigint"?"n":"";let D;throw d===0||d===BigInt(0)?D=`>= 0${j} and < 2${j} ** ${(C+1)*8}${j}`:D=`>= -(2${j} ** ${(C+1)*8-1}${j}) and < 2 ** ${(C+1)*8-1}${j}`,new ee.ERR_OUT_OF_RANGE("value",D,k)}ge(b,B,C)}function J(k,d){if(typeof k!="number")throw new ee.ERR_INVALID_ARG_TYPE(d,"number",k)}function fe(k,d,h){throw Math.floor(k)!==k?(J(k,h),new ee.ERR_OUT_OF_RANGE("offset","an integer",k)):d<0?new ee.ERR_BUFFER_OUT_OF_BOUNDS:new ee.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${d}`,k)}const Se=/[^+/0-9A-Za-z-_]/g;function Ce(k){if(k=k.split("=")[0],k=k.trim().replace(Se,""),k.length<2)return"";for(;k.length%4!==0;)k=k+"=";return k}function Ze(k,d){d=d||1/0;let h;const b=k.length;let B=null;const C=[];for(let j=0;j<b;++j){if(h=k.charCodeAt(j),h>55295&&h<57344){if(!B){if(h>56319){(d-=3)>-1&&C.push(239,191,189);continue}else if(j+1===b){(d-=3)>-1&&C.push(239,191,189);continue}B=h;continue}if(h<56320){(d-=3)>-1&&C.push(239,191,189),B=h;continue}h=(B-55296<<10|h-56320)+65536}else B&&(d-=3)>-1&&C.push(239,191,189);if(B=null,h<128){if((d-=1)<0)break;C.push(h)}else if(h<2048){if((d-=2)<0)break;C.push(h>>6|192,h&63|128)}else if(h<65536){if((d-=3)<0)break;C.push(h>>12|224,h>>6&63|128,h&63|128)}else if(h<1114112){if((d-=4)<0)break;C.push(h>>18|240,h>>12&63|128,h>>6&63|128,h&63|128)}else throw new Error("Invalid code point")}return C}function st(k){const d=[];for(let h=0;h<k.length;++h)d.push(k.charCodeAt(h)&255);return d}function St(k,d){let h,b,B;const C=[];for(let j=0;j<k.length&&!((d-=2)<0);++j)h=k.charCodeAt(j),b=h>>8,B=h%256,C.push(B),C.push(b);return C}function Ae(k){return t.toByteArray(Ce(k))}function ln(k,d,h,b){let B;for(B=0;B<b&&!(B+h>=d.length||B>=k.length);++B)d[B+h]=k[B];return B}function et(k,d){return k instanceof d||k!=null&&k.constructor!=null&&k.constructor.name!=null&&k.constructor.name===d.name}function Ne(k){return k!==k}const se=(function(){const k="0123456789abcdef",d=new Array(256);for(let h=0;h<16;++h){const b=h*16;for(let B=0;B<16;++B)d[b+B]=k[h]+k[B]}return d})();function te(k){return typeof BigInt>"u"?ne:k}function ne(){throw new Error("BigInt not supported")}})(au)),au}var xw=Vo(),uu={exports:{}},uh;function Aw(){if(uh)return uu.exports;uh=1;var e=uu.exports={},t,n;function r(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?t=setTimeout:t=r}catch{t=r}try{typeof clearTimeout=="function"?n=clearTimeout:n=i}catch{n=i}})();function s(w){if(t===setTimeout)return setTimeout(w,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(w,0);try{return t(w,0)}catch{try{return t.call(null,w,0)}catch{return t.call(this,w,0)}}}function o(w){if(n===clearTimeout)return clearTimeout(w);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(w);try{return n(w)}catch{try{return n.call(null,w)}catch{return n.call(this,w)}}}var c=[],a=!1,u,f=-1;function l(){!a||!u||(a=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!a){var w=s(l);a=!0;for(var E=c.length;E;){for(u=c,c=[];++f<E;)u&&u[f].run();f=-1,E=c.length}u=null,a=!1,o(w)}}e.nextTick=function(w){var E=new Array(arguments.length-1);if(arguments.length>1)for(var _=1;_<arguments.length;_++)E[_-1]=arguments[_];c.push(new y(w,E)),c.length===1&&!a&&s(p)};function y(w,E){this.fun=w,this.array=E}y.prototype.run=function(){this.fun.apply(null,this.array)},e.title="browser",e.browser=!0,e.env={},e.argv=[],e.version="",e.versions={};function g(){}return e.on=g,e.addListener=g,e.once=g,e.off=g,e.removeListener=g,e.removeAllListeners=g,e.emit=g,e.prependListener=g,e.prependOnceListener=g,e.listeners=function(w){return[]},e.binding=function(w){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(w){throw new Error("process.chdir is not supported")},e.umask=function(){return 0},uu.exports}var vw=Aw();const Bw=$p(vw);typeof globalThis>"u"&&(globalThis.global=globalThis);typeof globalThis.Buffer>"u"&&(globalThis.Buffer=xw.Buffer);typeof globalThis.process>"u"&&(globalThis.process=Bw);var tt={},fu={},Le={},Rt={},lu={},Fs={},fh;function Iw(){return fh||(fh=1,Object.defineProperty(Fs,"__esModule",{value:!0}),Fs.crypto=void 0,Fs.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),Fs}var lh;function ni(){return lh||(lh=1,(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=n,e.anumber=r,e.abytes=i,e.ahash=s,e.aexists=o,e.aoutput=c,e.u8=a,e.u32=u,e.clean=f,e.createView=l,e.rotr=p,e.rotl=y,e.byteSwap=g,e.byteSwap32=w,e.bytesToHex=S,e.hexToBytes=I,e.asyncLoop=U,e.utf8ToBytes=M,e.bytesToUtf8=v,e.toBytes=R,e.kdfInputToBytes=V,e.concatBytes=W,e.checkOpts=H,e.createHasher=N,e.createOptHasher=L,e.createXOFer=F,e.randomBytes=x;const t=Iw();function n(O){return O instanceof Uint8Array||ArrayBuffer.isView(O)&&O.constructor.name==="Uint8Array"}function r(O){if(!Number.isSafeInteger(O)||O<0)throw new Error("positive integer expected, got "+O)}function i(O,...q){if(!n(O))throw new Error("Uint8Array expected");if(q.length>0&&!q.includes(O.length))throw new Error("Uint8Array expected of length "+q+", got length="+O.length)}function s(O){if(typeof O!="function"||typeof O.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r(O.outputLen),r(O.blockLen)}function o(O,q=!0){if(O.destroyed)throw new Error("Hash instance has been destroyed");if(q&&O.finished)throw new Error("Hash#digest() has already been called")}function c(O,q){i(O);const P=q.outputLen;if(O.length<P)throw new Error("digestInto() expects output buffer of length at least "+P)}function a(O){return new Uint8Array(O.buffer,O.byteOffset,O.byteLength)}function u(O){return new Uint32Array(O.buffer,O.byteOffset,Math.floor(O.byteLength/4))}function f(...O){for(let q=0;q<O.length;q++)O[q].fill(0)}function l(O){return new DataView(O.buffer,O.byteOffset,O.byteLength)}function p(O,q){return O<<32-q|O>>>q}function y(O,q){return O<<q|O>>>32-q>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function g(O){return O<<24&4278190080|O<<8&16711680|O>>>8&65280|O>>>24&255}e.swap8IfBE=e.isLE?O=>O:O=>g(O),e.byteSwapIfBE=e.swap8IfBE;function w(O){for(let q=0;q<O.length;q++)O[q]=g(O[q]);return O}e.swap32IfBE=e.isLE?O=>O:w;const E=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_=Array.from({length:256},(O,q)=>q.toString(16).padStart(2,"0"));function S(O){if(i(O),E)return O.toHex();let q="";for(let P=0;P<O.length;P++)q+=_[O[P]];return q}const m={_0:48,_9:57,A:65,F:70,a:97,f:102};function T(O){if(O>=m._0&&O<=m._9)return O-m._0;if(O>=m.A&&O<=m.F)return O-(m.A-10);if(O>=m.a&&O<=m.f)return O-(m.a-10)}function I(O){if(typeof O!="string")throw new Error("hex string expected, got "+typeof O);if(E)return Uint8Array.fromHex(O);const q=O.length,P=q/2;if(q%2)throw new Error("hex string expected, got unpadded hex of length "+q);const $=new Uint8Array(P);for(let G=0,X=0;G<P;G++,X+=2){const Y=T(O.charCodeAt(X)),oe=T(O.charCodeAt(X+1));if(Y===void 0||oe===void 0){const ae=O[X]+O[X+1];throw new Error('hex string expected, got non-hex character "'+ae+'" at index '+X)}$[G]=Y*16+oe}return $}const A=async()=>{};e.nextTick=A;async function U(O,q,P){let $=Date.now();for(let G=0;G<O;G++){P(G);const X=Date.now()-$;X>=0&&X<q||(await(0,e.nextTick)(),$+=X)}}function M(O){if(typeof O!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(O))}function v(O){return new TextDecoder().decode(O)}function R(O){return typeof O=="string"&&(O=M(O)),i(O),O}function V(O){return typeof O=="string"&&(O=M(O)),i(O),O}function W(...O){let q=0;for(let $=0;$<O.length;$++){const G=O[$];i(G),q+=G.length}const P=new Uint8Array(q);for(let $=0,G=0;$<O.length;$++){const X=O[$];P.set(X,G),G+=X.length}return P}function H(O,q){if(q!==void 0&&{}.toString.call(q)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(O,q)}class K{}e.Hash=K;function N(O){const q=$=>O().update(R($)).digest(),P=O();return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=()=>O(),q}function L(O){const q=($,G)=>O(G).update(R($)).digest(),P=O({});return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=$=>O($),q}function F(O){const q=($,G)=>O(G).update(R($)).digest(),P=O({});return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=$=>O($),q}e.wrapConstructor=N,e.wrapConstructorWithOpts=L,e.wrapXOFConstructorWithOpts=F;function x(O=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(O));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(O));throw new Error("crypto.getRandomValues must be defined")}})(lu)),lu}var hh;function Kp(){if(hh)return Rt;hh=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.SHA512_IV=Rt.SHA384_IV=Rt.SHA224_IV=Rt.SHA256_IV=Rt.HashMD=void 0,Rt.setBigUint64=t,Rt.Chi=n,Rt.Maj=r;const e=ni();function t(s,o,c,a){if(typeof s.setBigUint64=="function")return s.setBigUint64(o,c,a);const u=BigInt(32),f=BigInt(4294967295),l=Number(c>>u&f),p=Number(c&f),y=a?4:0,g=a?0:4;s.setUint32(o+y,l,a),s.setUint32(o+g,p,a)}function n(s,o,c){return s&o^~s&c}function r(s,o,c){return s&o^s&c^o&c}class i extends e.Hash{constructor(o,c,a,u){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=o,this.outputLen=c,this.padOffset=a,this.isLE=u,this.buffer=new Uint8Array(o),this.view=(0,e.createView)(this.buffer)}update(o){(0,e.aexists)(this),o=(0,e.toBytes)(o),(0,e.abytes)(o);const{view:c,buffer:a,blockLen:u}=this,f=o.length;for(let l=0;l<f;){const p=Math.min(u-this.pos,f-l);if(p===u){const y=(0,e.createView)(o);for(;u<=f-l;l+=u)this.process(y,l);continue}a.set(o.subarray(l,l+p),this.pos),this.pos+=p,l+=p,this.pos===u&&(this.process(c,0),this.pos=0)}return this.length+=o.length,this.roundClean(),this}digestInto(o){(0,e.aexists)(this),(0,e.aoutput)(o,this),this.finished=!0;const{buffer:c,view:a,blockLen:u,isLE:f}=this;let{pos:l}=this;c[l++]=128,(0,e.clean)(this.buffer.subarray(l)),this.padOffset>u-l&&(this.process(a,0),l=0);for(let E=l;E<u;E++)c[E]=0;t(a,u-8,BigInt(this.length*8),f),this.process(a,0);const p=(0,e.createView)(o),y=this.outputLen;if(y%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const g=y/4,w=this.get();if(g>w.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<g;E++)p.setUint32(4*E,w[E],f)}digest(){const{buffer:o,outputLen:c}=this;this.digestInto(o);const a=o.slice(0,c);return this.destroy(),a}_cloneInto(o){o||(o=new this.constructor),o.set(...this.get());const{blockLen:c,buffer:a,length:u,finished:f,destroyed:l,pos:p}=this;return o.destroyed=l,o.finished=f,o.length=u,o.pos=p,u%c&&o.buffer.set(a),o}clone(){return this._cloneInto()}}return Rt.HashMD=i,Rt.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Rt.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Rt.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Rt}var xe={},dh;function Ow(){if(dh)return xe;dh=1,Object.defineProperty(xe,"__esModule",{value:!0}),xe.toBig=xe.shrSL=xe.shrSH=xe.rotrSL=xe.rotrSH=xe.rotrBL=xe.rotrBH=xe.rotr32L=xe.rotr32H=xe.rotlSL=xe.rotlSH=xe.rotlBL=xe.rotlBH=xe.add5L=xe.add5H=xe.add4L=xe.add4H=xe.add3L=xe.add3H=void 0,xe.add=_,xe.fromBig=n,xe.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(v,R=!1){return R?{h:Number(v&e),l:Number(v>>t&e)}:{h:Number(v>>t&e)|0,l:Number(v&e)|0}}function r(v,R=!1){const V=v.length;let W=new Uint32Array(V),H=new Uint32Array(V);for(let K=0;K<V;K++){const{h:N,l:L}=n(v[K],R);[W[K],H[K]]=[N,L]}return[W,H]}const i=(v,R)=>BigInt(v>>>0)<<t|BigInt(R>>>0);xe.toBig=i;const s=(v,R,V)=>v>>>V;xe.shrSH=s;const o=(v,R,V)=>v<<32-V|R>>>V;xe.shrSL=o;const c=(v,R,V)=>v>>>V|R<<32-V;xe.rotrSH=c;const a=(v,R,V)=>v<<32-V|R>>>V;xe.rotrSL=a;const u=(v,R,V)=>v<<64-V|R>>>V-32;xe.rotrBH=u;const f=(v,R,V)=>v>>>V-32|R<<64-V;xe.rotrBL=f;const l=(v,R)=>R;xe.rotr32H=l;const p=(v,R)=>v;xe.rotr32L=p;const y=(v,R,V)=>v<<V|R>>>32-V;xe.rotlSH=y;const g=(v,R,V)=>R<<V|v>>>32-V;xe.rotlSL=g;const w=(v,R,V)=>R<<V-32|v>>>64-V;xe.rotlBH=w;const E=(v,R,V)=>v<<V-32|R>>>64-V;xe.rotlBL=E;function _(v,R,V,W){const H=(R>>>0)+(W>>>0);return{h:v+V+(H/2**32|0)|0,l:H|0}}const S=(v,R,V)=>(v>>>0)+(R>>>0)+(V>>>0);xe.add3L=S;const m=(v,R,V,W)=>R+V+W+(v/2**32|0)|0;xe.add3H=m;const T=(v,R,V,W)=>(v>>>0)+(R>>>0)+(V>>>0)+(W>>>0);xe.add4L=T;const I=(v,R,V,W,H)=>R+V+W+H+(v/2**32|0)|0;xe.add4H=I;const A=(v,R,V,W,H)=>(v>>>0)+(R>>>0)+(V>>>0)+(W>>>0)+(H>>>0);xe.add5L=A;const U=(v,R,V,W,H,K)=>R+V+W+H+K+(v/2**32|0)|0;xe.add5H=U;const M={fromBig:n,split:r,toBig:i,shrSH:s,shrSL:o,rotrSH:c,rotrSL:a,rotrBH:u,rotrBL:f,rotr32H:l,rotr32L:p,rotlSH:y,rotlSL:g,rotlBH:w,rotlBL:E,add:_,add3L:S,add3H:m,add4L:T,add4H:I,add5H:U,add5L:A};return xe.default=M,xe}var ph;function Lp(){if(ph)return Le;ph=1,Object.defineProperty(Le,"__esModule",{value:!0}),Le.sha512_224=Le.sha512_256=Le.sha384=Le.sha512=Le.sha224=Le.sha256=Le.SHA512_256=Le.SHA512_224=Le.SHA384=Le.SHA512=Le.SHA224=Le.SHA256=void 0;const e=Kp(),t=Ow(),n=ni(),r=Uint32Array.from([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]),i=new Uint32Array(64);class s extends e.HashMD{constructor(m=32){super(64,m,8,!1),this.A=e.SHA256_IV[0]|0,this.B=e.SHA256_IV[1]|0,this.C=e.SHA256_IV[2]|0,this.D=e.SHA256_IV[3]|0,this.E=e.SHA256_IV[4]|0,this.F=e.SHA256_IV[5]|0,this.G=e.SHA256_IV[6]|0,this.H=e.SHA256_IV[7]|0}get(){const{A:m,B:T,C:I,D:A,E:U,F:M,G:v,H:R}=this;return[m,T,I,A,U,M,v,R]}set(m,T,I,A,U,M,v,R){this.A=m|0,this.B=T|0,this.C=I|0,this.D=A|0,this.E=U|0,this.F=M|0,this.G=v|0,this.H=R|0}process(m,T){for(let H=0;H<16;H++,T+=4)i[H]=m.getUint32(T,!1);for(let H=16;H<64;H++){const K=i[H-15],N=i[H-2],L=(0,n.rotr)(K,7)^(0,n.rotr)(K,18)^K>>>3,F=(0,n.rotr)(N,17)^(0,n.rotr)(N,19)^N>>>10;i[H]=F+i[H-7]+L+i[H-16]|0}let{A:I,B:A,C:U,D:M,E:v,F:R,G:V,H:W}=this;for(let H=0;H<64;H++){const K=(0,n.rotr)(v,6)^(0,n.rotr)(v,11)^(0,n.rotr)(v,25),N=W+K+(0,e.Chi)(v,R,V)+r[H]+i[H]|0,F=((0,n.rotr)(I,2)^(0,n.rotr)(I,13)^(0,n.rotr)(I,22))+(0,e.Maj)(I,A,U)|0;W=V,V=R,R=v,v=M+N|0,M=U,U=A,A=I,I=N+F|0}I=I+this.A|0,A=A+this.B|0,U=U+this.C|0,M=M+this.D|0,v=v+this.E|0,R=R+this.F|0,V=V+this.G|0,W=W+this.H|0,this.set(I,A,U,M,v,R,V,W)}roundClean(){(0,n.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}Le.SHA256=s;class o extends s{constructor(){super(28),this.A=e.SHA224_IV[0]|0,this.B=e.SHA224_IV[1]|0,this.C=e.SHA224_IV[2]|0,this.D=e.SHA224_IV[3]|0,this.E=e.SHA224_IV[4]|0,this.F=e.SHA224_IV[5]|0,this.G=e.SHA224_IV[6]|0,this.H=e.SHA224_IV[7]|0}}Le.SHA224=o;const c=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(S=>BigInt(S))),a=c[0],u=c[1],f=new Uint32Array(80),l=new Uint32Array(80);class p extends e.HashMD{constructor(m=64){super(128,m,16,!1),this.Ah=e.SHA512_IV[0]|0,this.Al=e.SHA512_IV[1]|0,this.Bh=e.SHA512_IV[2]|0,this.Bl=e.SHA512_IV[3]|0,this.Ch=e.SHA512_IV[4]|0,this.Cl=e.SHA512_IV[5]|0,this.Dh=e.SHA512_IV[6]|0,this.Dl=e.SHA512_IV[7]|0,this.Eh=e.SHA512_IV[8]|0,this.El=e.SHA512_IV[9]|0,this.Fh=e.SHA512_IV[10]|0,this.Fl=e.SHA512_IV[11]|0,this.Gh=e.SHA512_IV[12]|0,this.Gl=e.SHA512_IV[13]|0,this.Hh=e.SHA512_IV[14]|0,this.Hl=e.SHA512_IV[15]|0}get(){const{Ah:m,Al:T,Bh:I,Bl:A,Ch:U,Cl:M,Dh:v,Dl:R,Eh:V,El:W,Fh:H,Fl:K,Gh:N,Gl:L,Hh:F,Hl:x}=this;return[m,T,I,A,U,M,v,R,V,W,H,K,N,L,F,x]}set(m,T,I,A,U,M,v,R,V,W,H,K,N,L,F,x){this.Ah=m|0,this.Al=T|0,this.Bh=I|0,this.Bl=A|0,this.Ch=U|0,this.Cl=M|0,this.Dh=v|0,this.Dl=R|0,this.Eh=V|0,this.El=W|0,this.Fh=H|0,this.Fl=K|0,this.Gh=N|0,this.Gl=L|0,this.Hh=F|0,this.Hl=x|0}process(m,T){for(let P=0;P<16;P++,T+=4)f[P]=m.getUint32(T),l[P]=m.getUint32(T+=4);for(let P=16;P<80;P++){const $=f[P-15]|0,G=l[P-15]|0,X=t.rotrSH($,G,1)^t.rotrSH($,G,8)^t.shrSH($,G,7),Y=t.rotrSL($,G,1)^t.rotrSL($,G,8)^t.shrSL($,G,7),oe=f[P-2]|0,ae=l[P-2]|0,ee=t.rotrSH(oe,ae,19)^t.rotrBH(oe,ae,61)^t.shrSH(oe,ae,6),Z=t.rotrSL(oe,ae,19)^t.rotrBL(oe,ae,61)^t.shrSL(oe,ae,6),ce=t.add4L(Y,Z,l[P-7],l[P-16]),ge=t.add4H(ce,X,ee,f[P-7],f[P-16]);f[P]=ge|0,l[P]=ce|0}let{Ah:I,Al:A,Bh:U,Bl:M,Ch:v,Cl:R,Dh:V,Dl:W,Eh:H,El:K,Fh:N,Fl:L,Gh:F,Gl:x,Hh:O,Hl:q}=this;for(let P=0;P<80;P++){const $=t.rotrSH(H,K,14)^t.rotrSH(H,K,18)^t.rotrBH(H,K,41),G=t.rotrSL(H,K,14)^t.rotrSL(H,K,18)^t.rotrBL(H,K,41),X=H&N^~H&F,Y=K&L^~K&x,oe=t.add5L(q,G,Y,u[P],l[P]),ae=t.add5H(oe,O,$,X,a[P],f[P]),ee=oe|0,Z=t.rotrSH(I,A,28)^t.rotrBH(I,A,34)^t.rotrBH(I,A,39),ce=t.rotrSL(I,A,28)^t.rotrBL(I,A,34)^t.rotrBL(I,A,39),ge=I&U^I&v^U&v,pe=A&M^A&R^M&R;O=F|0,q=x|0,F=N|0,x=L|0,N=H|0,L=K|0,{h:H,l:K}=t.add(V|0,W|0,ae|0,ee|0),V=v|0,W=R|0,v=U|0,R=M|0,U=I|0,M=A|0;const J=t.add3L(ee,ce,pe);I=t.add3H(J,ae,Z,ge),A=J|0}({h:I,l:A}=t.add(this.Ah|0,this.Al|0,I|0,A|0)),{h:U,l:M}=t.add(this.Bh|0,this.Bl|0,U|0,M|0),{h:v,l:R}=t.add(this.Ch|0,this.Cl|0,v|0,R|0),{h:V,l:W}=t.add(this.Dh|0,this.Dl|0,V|0,W|0),{h:H,l:K}=t.add(this.Eh|0,this.El|0,H|0,K|0),{h:N,l:L}=t.add(this.Fh|0,this.Fl|0,N|0,L|0),{h:F,l:x}=t.add(this.Gh|0,this.Gl|0,F|0,x|0),{h:O,l:q}=t.add(this.Hh|0,this.Hl|0,O|0,q|0),this.set(I,A,U,M,v,R,V,W,H,K,N,L,F,x,O,q)}roundClean(){(0,n.clean)(f,l)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}Le.SHA512=p;class y extends p{constructor(){super(48),this.Ah=e.SHA384_IV[0]|0,this.Al=e.SHA384_IV[1]|0,this.Bh=e.SHA384_IV[2]|0,this.Bl=e.SHA384_IV[3]|0,this.Ch=e.SHA384_IV[4]|0,this.Cl=e.SHA384_IV[5]|0,this.Dh=e.SHA384_IV[6]|0,this.Dl=e.SHA384_IV[7]|0,this.Eh=e.SHA384_IV[8]|0,this.El=e.SHA384_IV[9]|0,this.Fh=e.SHA384_IV[10]|0,this.Fl=e.SHA384_IV[11]|0,this.Gh=e.SHA384_IV[12]|0,this.Gl=e.SHA384_IV[13]|0,this.Hh=e.SHA384_IV[14]|0,this.Hl=e.SHA384_IV[15]|0}}Le.SHA384=y;const g=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),w=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class E extends p{constructor(){super(28),this.Ah=g[0]|0,this.Al=g[1]|0,this.Bh=g[2]|0,this.Bl=g[3]|0,this.Ch=g[4]|0,this.Cl=g[5]|0,this.Dh=g[6]|0,this.Dl=g[7]|0,this.Eh=g[8]|0,this.El=g[9]|0,this.Fh=g[10]|0,this.Fl=g[11]|0,this.Gh=g[12]|0,this.Gl=g[13]|0,this.Hh=g[14]|0,this.Hl=g[15]|0}}Le.SHA512_224=E;class _ extends p{constructor(){super(32),this.Ah=w[0]|0,this.Al=w[1]|0,this.Bh=w[2]|0,this.Bl=w[3]|0,this.Ch=w[4]|0,this.Cl=w[5]|0,this.Dh=w[6]|0,this.Dl=w[7]|0,this.Eh=w[8]|0,this.El=w[9]|0,this.Fh=w[10]|0,this.Fl=w[11]|0,this.Gh=w[12]|0,this.Gl=w[13]|0,this.Hh=w[14]|0,this.Hl=w[15]|0}}return Le.SHA512_256=_,Le.sha256=(0,n.createHasher)(()=>new s),Le.sha224=(0,n.createHasher)(()=>new o),Le.sha512=(0,n.createHasher)(()=>new p),Le.sha384=(0,n.createHasher)(()=>new y),Le.sha512_256=(0,n.createHasher)(()=>new _),Le.sha512_224=(0,n.createHasher)(()=>new E),Le}var Ms={},hu={},du={},yh;function Pw(){return yh||(yh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=ni();class n extends t.Hash{constructor(s,o){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(s);const c=(0,t.toBytes)(o);if(this.iHash=s.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const a=this.blockLen,u=new Uint8Array(a);u.set(c.length>a?s.create().update(c).digest():c);for(let f=0;f<u.length;f++)u[f]^=54;this.iHash.update(u),this.oHash=s.create();for(let f=0;f<u.length;f++)u[f]^=106;this.oHash.update(u),(0,t.clean)(u)}update(s){return(0,t.aexists)(this),this.iHash.update(s),this}digestInto(s){(0,t.aexists)(this),(0,t.abytes)(s,this.outputLen),this.finished=!0,this.iHash.digestInto(s),this.oHash.update(s),this.oHash.digestInto(s),this.destroy()}digest(){const s=new Uint8Array(this.oHash.outputLen);return this.digestInto(s),s}_cloneInto(s){s||(s=Object.create(Object.getPrototypeOf(this),{}));const{oHash:o,iHash:c,finished:a,destroyed:u,blockLen:f,outputLen:l}=this;return s=s,s.finished=a,s.destroyed=u,s.blockLen=f,s.outputLen=l,s.oHash=o._cloneInto(s.oHash),s.iHash=c._cloneInto(s.iHash),s}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=n;const r=(i,s,o)=>new n(i,s).update(o).digest();e.hmac=r,e.hmac.create=(i,s)=>new n(i,s)})(du)),du}var pu={},gh;function vs(){return gh||(gh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.notImplemented=e.bitMask=e.utf8ToBytes=e.randomBytes=e.isBytes=e.hexToBytes=e.concatBytes=e.bytesToUtf8=e.bytesToHex=e.anumber=e.abytes=void 0,e.abool=s,e._abool2=o,e._abytes2=c,e.numberToHexUnpadded=a,e.hexToNumber=u,e.bytesToNumberBE=f,e.bytesToNumberLE=l,e.numberToBytesBE=p,e.numberToBytesLE=y,e.numberToVarBytesBE=g,e.ensureBytes=w,e.equalBytes=E,e.copyBytes=_,e.asciiToBytes=S,e.inRange=T,e.aInRange=I,e.bitLen=A,e.bitGet=U,e.bitSet=M,e.createHmacDrbg=R,e.validateObject=W,e.isHash=H,e._validateObject=K,e.memoized=L;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=ni();var n=ni();Object.defineProperty(e,"abytes",{enumerable:!0,get:function(){return n.abytes}}),Object.defineProperty(e,"anumber",{enumerable:!0,get:function(){return n.anumber}}),Object.defineProperty(e,"bytesToHex",{enumerable:!0,get:function(){return n.bytesToHex}}),Object.defineProperty(e,"bytesToUtf8",{enumerable:!0,get:function(){return n.bytesToUtf8}}),Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return n.concatBytes}}),Object.defineProperty(e,"hexToBytes",{enumerable:!0,get:function(){return n.hexToBytes}}),Object.defineProperty(e,"isBytes",{enumerable:!0,get:function(){return n.isBytes}}),Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return n.randomBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return n.utf8ToBytes}});const r=BigInt(0),i=BigInt(1);function s(F,x){if(typeof x!="boolean")throw new Error(F+" boolean expected, got "+x)}function o(F,x=""){if(typeof F!="boolean"){const O=x&&`"${x}"`;throw new Error(O+"expected boolean, got type="+typeof F)}return F}function c(F,x,O=""){const q=(0,t.isBytes)(F),P=F?.length,$=x!==void 0;if(!q||$&&P!==x){const G=O&&`"${O}" `,X=$?` of length ${x}`:"",Y=q?`length=${P}`:`type=${typeof F}`;throw new Error(G+"expected Uint8Array"+X+", got "+Y)}return F}function a(F){const x=F.toString(16);return x.length&1?"0"+x:x}function u(F){if(typeof F!="string")throw new Error("hex string expected, got "+typeof F);return F===""?r:BigInt("0x"+F)}function f(F){return u((0,t.bytesToHex)(F))}function l(F){return(0,t.abytes)(F),u((0,t.bytesToHex)(Uint8Array.from(F).reverse()))}function p(F,x){return(0,t.hexToBytes)(F.toString(16).padStart(x*2,"0"))}function y(F,x){return p(F,x).reverse()}function g(F){return(0,t.hexToBytes)(a(F))}function w(F,x,O){let q;if(typeof x=="string")try{q=(0,t.hexToBytes)(x)}catch($){throw new Error(F+" must be hex string or Uint8Array, cause: "+$)}else if((0,t.isBytes)(x))q=Uint8Array.from(x);else throw new Error(F+" must be hex string or Uint8Array");const P=q.length;if(typeof O=="number"&&P!==O)throw new Error(F+" of length "+O+" expected, got "+P);return q}function E(F,x){if(F.length!==x.length)return!1;let O=0;for(let q=0;q<F.length;q++)O|=F[q]^x[q];return O===0}function _(F){return Uint8Array.from(F)}function S(F){return Uint8Array.from(F,(x,O)=>{const q=x.charCodeAt(0);if(x.length!==1||q>127)throw new Error(`string contains non-ASCII character "${F[O]}" with code ${q} at position ${O}`);return q})}const m=F=>typeof F=="bigint"&&r<=F;function T(F,x,O){return m(F)&&m(x)&&m(O)&&x<=F&&F<O}function I(F,x,O,q){if(!T(x,O,q))throw new Error("expected valid "+F+": "+O+" <= n < "+q+", got "+x)}function A(F){let x;for(x=0;F>r;F>>=i,x+=1);return x}function U(F,x){return F>>BigInt(x)&i}function M(F,x,O){return F|(O?i:r)<<BigInt(x)}const v=F=>(i<<BigInt(F))-i;e.bitMask=v;function R(F,x,O){if(typeof F!="number"||F<2)throw new Error("hashLen must be a number");if(typeof x!="number"||x<2)throw new Error("qByteLen must be a number");if(typeof O!="function")throw new Error("hmacFn must be a function");const q=ce=>new Uint8Array(ce),P=ce=>Uint8Array.of(ce);let $=q(F),G=q(F),X=0;const Y=()=>{$.fill(1),G.fill(0),X=0},oe=(...ce)=>O(G,$,...ce),ae=(ce=q(0))=>{G=oe(P(0),ce),$=oe(),ce.length!==0&&(G=oe(P(1),ce),$=oe())},ee=()=>{if(X++>=1e3)throw new Error("drbg: tried 1000 values");let ce=0;const ge=[];for(;ce<x;){$=oe();const pe=$.slice();ge.push(pe),ce+=$.length}return(0,t.concatBytes)(...ge)};return(ce,ge)=>{Y(),ae(ce);let pe;for(;!(pe=ge(ee()));)ae();return Y(),pe}}const V={bigint:F=>typeof F=="bigint",function:F=>typeof F=="function",boolean:F=>typeof F=="boolean",string:F=>typeof F=="string",stringOrUint8Array:F=>typeof F=="string"||(0,t.isBytes)(F),isSafeInteger:F=>Number.isSafeInteger(F),array:F=>Array.isArray(F),field:(F,x)=>x.Fp.isValid(F),hash:F=>typeof F=="function"&&Number.isSafeInteger(F.outputLen)};function W(F,x,O={}){const q=(P,$,G)=>{const X=V[$];if(typeof X!="function")throw new Error("invalid validator function");const Y=F[P];if(!(G&&Y===void 0)&&!X(Y,F))throw new Error("param "+String(P)+" is invalid. Expected "+$+", got "+Y)};for(const[P,$]of Object.entries(x))q(P,$,!1);for(const[P,$]of Object.entries(O))q(P,$,!0);return F}function H(F){return typeof F=="function"&&Number.isSafeInteger(F.outputLen)}function K(F,x,O={}){if(!F||typeof F!="object")throw new Error("expected valid options object");function q(P,$,G){const X=F[P];if(G&&X===void 0)return;const Y=typeof X;if(Y!==$||X===null)throw new Error(`param "${P}" is invalid: expected ${$}, got ${Y}`)}Object.entries(x).forEach(([P,$])=>q(P,$,!1)),Object.entries(O).forEach(([P,$])=>q(P,$,!0))}const N=()=>{throw new Error("not implemented")};e.notImplemented=N;function L(F){const x=new WeakMap;return(O,...q)=>{const P=x.get(O);if(P!==void 0)return P;const $=F(O,...q);return x.set(O,$),$}}})(pu)),pu}var gn={},Xe={},wh;function $o(){if(wh)return Xe;wh=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.isNegativeLE=void 0,Xe.mod=l,Xe.pow=p,Xe.pow2=y,Xe.invert=g,Xe.tonelliShanks=m,Xe.FpSqrt=T,Xe.validateField=U,Xe.FpPow=M,Xe.FpInvertBatch=v,Xe.FpDiv=R,Xe.FpLegendre=V,Xe.FpIsSquare=W,Xe.nLength=H,Xe.Field=K,Xe.FpSqrtOdd=N,Xe.FpSqrtEven=L,Xe.hashToPrivateScalar=F,Xe.getFieldBytesLength=x,Xe.getMinHashLength=O,Xe.mapHashToField=q;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=vs(),t=BigInt(0),n=BigInt(1),r=BigInt(2),i=BigInt(3),s=BigInt(4),o=BigInt(5),c=BigInt(7),a=BigInt(8),u=BigInt(9),f=BigInt(16);function l(P,$){const G=P%$;return G>=t?G:$+G}function p(P,$,G){return M(K(G),P,$)}function y(P,$,G){let X=P;for(;$-- >t;)X*=X,X%=G;return X}function g(P,$){if(P===t)throw new Error("invert: expected non-zero number");if($<=t)throw new Error("invert: expected positive modulus, got "+$);let G=l(P,$),X=$,Y=t,oe=n;for(;G!==t;){const ee=X/G,Z=X%G,ce=Y-oe*ee;X=G,G=Z,Y=oe,oe=ce}if(X!==n)throw new Error("invert: does not exist");return l(Y,$)}function w(P,$,G){if(!P.eql(P.sqr($),G))throw new Error("Cannot find square root")}function E(P,$){const G=(P.ORDER+n)/s,X=P.pow($,G);return w(P,X,$),X}function _(P,$){const G=(P.ORDER-o)/a,X=P.mul($,r),Y=P.pow(X,G),oe=P.mul($,Y),ae=P.mul(P.mul(oe,r),Y),ee=P.mul(oe,P.sub(ae,P.ONE));return w(P,ee,$),ee}function S(P){const $=K(P),G=m(P),X=G($,$.neg($.ONE)),Y=G($,X),oe=G($,$.neg(X)),ae=(P+c)/f;return(ee,Z)=>{let ce=ee.pow(Z,ae),ge=ee.mul(ce,X);const pe=ee.mul(ce,Y),J=ee.mul(ce,oe),fe=ee.eql(ee.sqr(ge),Z),Se=ee.eql(ee.sqr(pe),Z);ce=ee.cmov(ce,ge,fe),ge=ee.cmov(J,pe,Se);const Ce=ee.eql(ee.sqr(ge),Z),Ze=ee.cmov(ce,ge,Ce);return w(ee,Ze,Z),Ze}}function m(P){if(P<i)throw new Error("sqrt is not defined for small field");let $=P-n,G=0;for(;$%r===t;)$/=r,G++;let X=r;const Y=K(P);for(;V(Y,X)===1;)if(X++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(G===1)return E;let oe=Y.pow(X,$);const ae=($+n)/r;return function(Z,ce){if(Z.is0(ce))return ce;if(V(Z,ce)!==1)throw new Error("Cannot find square root");let ge=G,pe=Z.mul(Z.ONE,oe),J=Z.pow(ce,$),fe=Z.pow(ce,ae);for(;!Z.eql(J,Z.ONE);){if(Z.is0(J))return Z.ZERO;let Se=1,Ce=Z.sqr(J);for(;!Z.eql(Ce,Z.ONE);)if(Se++,Ce=Z.sqr(Ce),Se===ge)throw new Error("Cannot find square root");const Ze=n<<BigInt(ge-Se-1),st=Z.pow(pe,Ze);ge=Se,pe=Z.sqr(st),J=Z.mul(J,pe),fe=Z.mul(fe,st)}return fe}}function T(P){return P%s===i?E:P%a===o?_:P%f===u?S(P):m(P)}const I=(P,$)=>(l(P,$)&n)===n;Xe.isNegativeLE=I;const A=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function U(P){const $={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=A.reduce((X,Y)=>(X[Y]="function",X),$);return(0,e._validateObject)(P,G),P}function M(P,$,G){if(G<t)throw new Error("invalid exponent, negatives unsupported");if(G===t)return P.ONE;if(G===n)return $;let X=P.ONE,Y=$;for(;G>t;)G&n&&(X=P.mul(X,Y)),Y=P.sqr(Y),G>>=n;return X}function v(P,$,G=!1){const X=new Array($.length).fill(G?P.ZERO:void 0),Y=$.reduce((ae,ee,Z)=>P.is0(ee)?ae:(X[Z]=ae,P.mul(ae,ee)),P.ONE),oe=P.inv(Y);return $.reduceRight((ae,ee,Z)=>P.is0(ee)?ae:(X[Z]=P.mul(ae,X[Z]),P.mul(ae,ee)),oe),X}function R(P,$,G){return P.mul($,typeof G=="bigint"?g(G,P.ORDER):P.inv(G))}function V(P,$){const G=(P.ORDER-n)/r,X=P.pow($,G),Y=P.eql(X,P.ONE),oe=P.eql(X,P.ZERO),ae=P.eql(X,P.neg(P.ONE));if(!Y&&!oe&&!ae)throw new Error("invalid Legendre symbol result");return Y?1:oe?0:-1}function W(P,$){return V(P,$)===1}function H(P,$){$!==void 0&&(0,e.anumber)($);const G=$!==void 0?$:P.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function K(P,$,G=!1,X={}){if(P<=t)throw new Error("invalid field: expected ORDER > 0, got "+P);let Y,oe,ae=!1,ee;if(typeof $=="object"&&$!=null){if(X.sqrt||G)throw new Error("cannot specify opts in two arguments");const J=$;J.BITS&&(Y=J.BITS),J.sqrt&&(oe=J.sqrt),typeof J.isLE=="boolean"&&(G=J.isLE),typeof J.modFromBytes=="boolean"&&(ae=J.modFromBytes),ee=J.allowedLengths}else typeof $=="number"&&(Y=$),X.sqrt&&(oe=X.sqrt);const{nBitLength:Z,nByteLength:ce}=H(P,Y);if(ce>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let ge;const pe=Object.freeze({ORDER:P,isLE:G,BITS:Z,BYTES:ce,MASK:(0,e.bitMask)(Z),ZERO:t,ONE:n,allowedLengths:ee,create:J=>l(J,P),isValid:J=>{if(typeof J!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof J);return t<=J&&J<P},is0:J=>J===t,isValidNot0:J=>!pe.is0(J)&&pe.isValid(J),isOdd:J=>(J&n)===n,neg:J=>l(-J,P),eql:(J,fe)=>J===fe,sqr:J=>l(J*J,P),add:(J,fe)=>l(J+fe,P),sub:(J,fe)=>l(J-fe,P),mul:(J,fe)=>l(J*fe,P),pow:(J,fe)=>M(pe,J,fe),div:(J,fe)=>l(J*g(fe,P),P),sqrN:J=>J*J,addN:(J,fe)=>J+fe,subN:(J,fe)=>J-fe,mulN:(J,fe)=>J*fe,inv:J=>g(J,P),sqrt:oe||(J=>(ge||(ge=T(P)),ge(pe,J))),toBytes:J=>G?(0,e.numberToBytesLE)(J,ce):(0,e.numberToBytesBE)(J,ce),fromBytes:(J,fe=!0)=>{if(ee){if(!ee.includes(J.length)||J.length>ce)throw new Error("Field.fromBytes: expected "+ee+" bytes, got "+J.length);const Ce=new Uint8Array(ce);Ce.set(J,G?0:Ce.length-J.length),J=Ce}if(J.length!==ce)throw new Error("Field.fromBytes: expected "+ce+" bytes, got "+J.length);let Se=G?(0,e.bytesToNumberLE)(J):(0,e.bytesToNumberBE)(J);if(ae&&(Se=l(Se,P)),!fe&&!pe.isValid(Se))throw new Error("invalid field element: outside of range 0..ORDER");return Se},invertBatch:J=>v(pe,J),cmov:(J,fe,Se)=>Se?fe:J});return Object.freeze(pe)}function N(P,$){if(!P.isOdd)throw new Error("Field doesn't have isOdd");const G=P.sqrt($);return P.isOdd(G)?G:P.neg(G)}function L(P,$){if(!P.isOdd)throw new Error("Field doesn't have isOdd");const G=P.sqrt($);return P.isOdd(G)?P.neg(G):G}function F(P,$,G=!1){P=(0,e.ensureBytes)("privateHash",P);const X=P.length,Y=H($).nByteLength+8;if(Y<24||X<Y||X>1024)throw new Error("hashToPrivateScalar: expected "+Y+"-1024 bytes of input, got "+X);const oe=G?(0,e.bytesToNumberLE)(P):(0,e.bytesToNumberBE)(P);return l(oe,$-n)+n}function x(P){if(typeof P!="bigint")throw new Error("field order must be bigint");const $=P.toString(2).length;return Math.ceil($/8)}function O(P){const $=x(P);return $+Math.ceil($/2)}function q(P,$,G=!1){const X=P.length,Y=x($),oe=O($);if(X<16||X<oe||X>1024)throw new Error("expected "+oe+"-1024 bytes of input, got "+X);const ae=G?(0,e.bytesToNumberLE)(P):(0,e.bytesToNumberBE)(P),ee=l(ae,$-n)+n;return G?(0,e.numberToBytesLE)(ee,Y):(0,e.numberToBytesBE)(ee,Y)}return Xe}var mh;function kw(){if(mh)return gn;mh=1,Object.defineProperty(gn,"__esModule",{value:!0}),gn.wNAF=void 0,gn.negateCt=i,gn.normalizeZ=s,gn.mulEndoUnsafe=E,gn.pippenger=_,gn.precomputeMSMUnsafe=S,gn.validateBasic=m,gn._createCurveFields=I;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=vs(),t=$o(),n=BigInt(0),r=BigInt(1);function i(A,U){const M=U.negate();return A?M:U}function s(A,U){const M=(0,t.FpInvertBatch)(A.Fp,U.map(v=>v.Z));return U.map((v,R)=>A.fromAffine(v.toAffine(M[R])))}function o(A,U){if(!Number.isSafeInteger(A)||A<=0||A>U)throw new Error("invalid window size, expected [1.."+U+"], got W="+A)}function c(A,U){o(A,U);const M=Math.ceil(U/A)+1,v=2**(A-1),R=2**A,V=(0,e.bitMask)(A),W=BigInt(A);return{windows:M,windowSize:v,mask:V,maxNumber:R,shiftBy:W}}function a(A,U,M){const{windowSize:v,mask:R,maxNumber:V,shiftBy:W}=M;let H=Number(A&R),K=A>>W;H>v&&(H-=V,K+=r);const N=U*v,L=N+Math.abs(H)-1,F=H===0,x=H<0,O=U%2!==0;return{nextN:K,offset:L,isZero:F,isNeg:x,isNegF:O,offsetF:N}}function u(A,U){if(!Array.isArray(A))throw new Error("array expected");A.forEach((M,v)=>{if(!(M instanceof U))throw new Error("invalid point at index "+v)})}function f(A,U){if(!Array.isArray(A))throw new Error("array of scalars expected");A.forEach((M,v)=>{if(!U.isValid(M))throw new Error("invalid scalar at index "+v)})}const l=new WeakMap,p=new WeakMap;function y(A){return p.get(A)||1}function g(A){if(A!==n)throw new Error("invalid wNAF")}class w{constructor(U,M){this.BASE=U.BASE,this.ZERO=U.ZERO,this.Fn=U.Fn,this.bits=M}_unsafeLadder(U,M,v=this.ZERO){let R=U;for(;M>n;)M&r&&(v=v.add(R)),R=R.double(),M>>=r;return v}precomputeWindow(U,M){const{windows:v,windowSize:R}=c(M,this.bits),V=[];let W=U,H=W;for(let K=0;K<v;K++){H=W,V.push(H);for(let N=1;N<R;N++)H=H.add(W),V.push(H);W=H.double()}return V}wNAF(U,M,v){if(!this.Fn.isValid(v))throw new Error("invalid scalar");let R=this.ZERO,V=this.BASE;const W=c(U,this.bits);for(let H=0;H<W.windows;H++){const{nextN:K,offset:N,isZero:L,isNeg:F,isNegF:x,offsetF:O}=a(v,H,W);v=K,L?V=V.add(i(x,M[O])):R=R.add(i(F,M[N]))}return g(v),{p:R,f:V}}wNAFUnsafe(U,M,v,R=this.ZERO){const V=c(U,this.bits);for(let W=0;W<V.windows&&v!==n;W++){const{nextN:H,offset:K,isZero:N,isNeg:L}=a(v,W,V);if(v=H,!N){const F=M[K];R=R.add(L?F.negate():F)}}return g(v),R}getPrecomputes(U,M,v){let R=l.get(M);return R||(R=this.precomputeWindow(M,U),U!==1&&(typeof v=="function"&&(R=v(R)),l.set(M,R))),R}cached(U,M,v){const R=y(U);return this.wNAF(R,this.getPrecomputes(R,U,v),M)}unsafe(U,M,v,R){const V=y(U);return V===1?this._unsafeLadder(U,M,R):this.wNAFUnsafe(V,this.getPrecomputes(V,U,v),M,R)}createCache(U,M){o(M,this.bits),p.set(U,M),l.delete(U)}hasCache(U){return y(U)!==1}}gn.wNAF=w;function E(A,U,M,v){let R=U,V=A.ZERO,W=A.ZERO;for(;M>n||v>n;)M&r&&(V=V.add(R)),v&r&&(W=W.add(R)),R=R.double(),M>>=r,v>>=r;return{p1:V,p2:W}}function _(A,U,M,v){u(M,A),f(v,U);const R=M.length,V=v.length;if(R!==V)throw new Error("arrays of points and scalars must have equal length");const W=A.ZERO,H=(0,e.bitLen)(BigInt(R));let K=1;H>12?K=H-3:H>4?K=H-2:H>0&&(K=2);const N=(0,e.bitMask)(K),L=new Array(Number(N)+1).fill(W),F=Math.floor((U.BITS-1)/K)*K;let x=W;for(let O=F;O>=0;O-=K){L.fill(W);for(let P=0;P<V;P++){const $=v[P],G=Number($>>BigInt(O)&N);L[G]=L[G].add(M[P])}let q=W;for(let P=L.length-1,$=W;P>0;P--)$=$.add(L[P]),q=q.add($);if(x=x.add(q),O!==0)for(let P=0;P<K;P++)x=x.double()}return x}function S(A,U,M,v){o(v,U.BITS),u(M,A);const R=A.ZERO,V=2**v-1,W=Math.ceil(U.BITS/v),H=(0,e.bitMask)(v),K=M.map(N=>{const L=[];for(let F=0,x=N;F<V;F++)L.push(x),x=x.add(N);return L});return N=>{if(f(N,U),N.length>M.length)throw new Error("array of scalars must be smaller than array of points");let L=R;for(let F=0;F<W;F++){if(L!==R)for(let O=0;O<v;O++)L=L.double();const x=BigInt(W*v-(F+1)*v);for(let O=0;O<N.length;O++){const q=N[O],P=Number(q>>x&H);P&&(L=L.add(K[O][P-1]))}}return L}}function m(A){return(0,t.validateField)(A.Fp),(0,e.validateObject)(A,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(A.n,A.nBitLength),...A,p:A.Fp.ORDER})}function T(A,U,M){if(U){if(U.ORDER!==A)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(U),U}else return(0,t.Field)(A,{isLE:M})}function I(A,U,M={},v){if(v===void 0&&(v=A==="edwards"),!U||typeof U!="object")throw new Error(`expected valid ${A} CURVE object`);for(const K of["p","n","h"]){const N=U[K];if(!(typeof N=="bigint"&&N>n))throw new Error(`CURVE.${K} must be positive bigint`)}const R=T(U.p,M.Fp,v),V=T(U.n,M.Fn,v),H=["Gx","Gy","a",A==="weierstrass"?"b":"d"];for(const K of H)if(!R.isValid(U[K]))throw new Error(`CURVE.${K} must be valid field element of CURVE.Fp`);return U=Object.freeze(Object.assign({},U)),{CURVE:U,Fp:R,Fn:V}}return gn}var bh;function jp(){return bh||(bh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=c,e._normFnElement=E,e.weierstrassN=_,e.SWUFpSqrtRatio=m,e.mapToCurveSimpleSWU=T,e.ecdh=A,e.ecdsa=U,e.weierstrassPoints=M,e._legacyHelperEquat=V,e.weierstrass=K;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Pw(),n=ni(),r=vs(),i=kw(),s=$o(),o=(N,L)=>(N+(N>=0?L:-L)/y)/L;function c(N,L,F){const[[x,O],[q,P]]=L,$=o(P*N,F),G=o(-O*N,F);let X=N-$*x-G*q,Y=-$*O-G*P;const oe=X<l,ae=Y<l;oe&&(X=-X),ae&&(Y=-Y);const ee=(0,r.bitMask)(Math.ceil((0,r.bitLen)(F)/2))+p;if(X<l||X>=ee||Y<l||Y>=ee)throw new Error("splitScalar (endomorphism): failed, k="+N);return{k1neg:oe,k1:X,k2neg:ae,k2:Y}}function a(N){if(!["compact","recovered","der"].includes(N))throw new Error('Signature format must be "compact", "recovered", or "der"');return N}function u(N,L){const F={};for(let x of Object.keys(L))F[x]=N[x]===void 0?L[x]:N[x];return(0,r._abool2)(F.lowS,"lowS"),(0,r._abool2)(F.prehash,"prehash"),F.format!==void 0&&a(F.format),F}class f extends Error{constructor(L=""){super(L)}}e.DERErr=f,e.DER={Err:f,_tlv:{encode:(N,L)=>{const{Err:F}=e.DER;if(N<0||N>256)throw new F("tlv.encode: wrong tag");if(L.length&1)throw new F("tlv.encode: unpadded data");const x=L.length/2,O=(0,r.numberToHexUnpadded)(x);if(O.length/2&128)throw new F("tlv.encode: long form length too big");const q=x>127?(0,r.numberToHexUnpadded)(O.length/2|128):"";return(0,r.numberToHexUnpadded)(N)+q+O+L},decode(N,L){const{Err:F}=e.DER;let x=0;if(N<0||N>256)throw new F("tlv.encode: wrong tag");if(L.length<2||L[x++]!==N)throw new F("tlv.decode: wrong tlv");const O=L[x++],q=!!(O&128);let P=0;if(!q)P=O;else{const G=O&127;if(!G)throw new F("tlv.decode(long): indefinite length not supported");if(G>4)throw new F("tlv.decode(long): byte length is too big");const X=L.subarray(x,x+G);if(X.length!==G)throw new F("tlv.decode: length bytes not complete");if(X[0]===0)throw new F("tlv.decode(long): zero leftmost byte");for(const Y of X)P=P<<8|Y;if(x+=G,P<128)throw new F("tlv.decode(long): not minimal encoding")}const $=L.subarray(x,x+P);if($.length!==P)throw new F("tlv.decode: wrong value length");return{v:$,l:L.subarray(x+P)}}},_int:{encode(N){const{Err:L}=e.DER;if(N<l)throw new L("integer: negative integers are not allowed");let F=(0,r.numberToHexUnpadded)(N);if(Number.parseInt(F[0],16)&8&&(F="00"+F),F.length&1)throw new L("unexpected DER parsing assertion: unpadded hex");return F},decode(N){const{Err:L}=e.DER;if(N[0]&128)throw new L("invalid signature integer: negative");if(N[0]===0&&!(N[1]&128))throw new L("invalid signature integer: unnecessary leading zero");return(0,r.bytesToNumberBE)(N)}},toSig(N){const{Err:L,_int:F,_tlv:x}=e.DER,O=(0,r.ensureBytes)("signature",N),{v:q,l:P}=x.decode(48,O);if(P.length)throw new L("invalid signature: left bytes after parsing");const{v:$,l:G}=x.decode(2,q),{v:X,l:Y}=x.decode(2,G);if(Y.length)throw new L("invalid signature: left bytes after parsing");return{r:F.decode($),s:F.decode(X)}},hexFromSig(N){const{_tlv:L,_int:F}=e.DER,x=L.encode(2,F.encode(N.r)),O=L.encode(2,F.encode(N.s)),q=x+O;return L.encode(48,q)}};const l=BigInt(0),p=BigInt(1),y=BigInt(2),g=BigInt(3),w=BigInt(4);function E(N,L){const{BYTES:F}=N;let x;if(typeof L=="bigint")x=L;else{let O=(0,r.ensureBytes)("private key",L);try{x=N.fromBytes(O)}catch{throw new Error(`invalid private key: expected ui8a of size ${F}, got ${typeof L}`)}}if(!N.isValidNot0(x))throw new Error("invalid private key: out of range [1..N-1]");return x}function _(N,L={}){const F=(0,i._createCurveFields)("weierstrass",N,L),{Fp:x,Fn:O}=F;let q=F.CURVE;const{h:P,n:$}=q;(0,r._validateObject)(L,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:G}=L;if(G&&(!x.is0(q.a)||typeof G.beta!="bigint"||!Array.isArray(G.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const X=I(x,O);function Y(){if(!x.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function oe(Ne,se,te){const{x:ne,y:k}=se.toAffine(),d=x.toBytes(ne);if((0,r._abool2)(te,"isCompressed"),te){Y();const h=!x.isOdd(k);return(0,r.concatBytes)(S(h),d)}else return(0,r.concatBytes)(Uint8Array.of(4),d,x.toBytes(k))}function ae(Ne){(0,r._abytes2)(Ne,void 0,"Point");const{publicKey:se,publicKeyUncompressed:te}=X,ne=Ne.length,k=Ne[0],d=Ne.subarray(1);if(ne===se&&(k===2||k===3)){const h=x.fromBytes(d);if(!x.isValid(h))throw new Error("bad point: is not on curve, wrong x");const b=ce(h);let B;try{B=x.sqrt(b)}catch(D){const re=D instanceof Error?": "+D.message:"";throw new Error("bad point: is not on curve, sqrt error"+re)}Y();const C=x.isOdd(B);return(k&1)===1!==C&&(B=x.neg(B)),{x:h,y:B}}else if(ne===te&&k===4){const h=x.BYTES,b=x.fromBytes(d.subarray(0,h)),B=x.fromBytes(d.subarray(h,h*2));if(!ge(b,B))throw new Error("bad point: is not on curve");return{x:b,y:B}}else throw new Error(`bad point: got length ${ne}, expected compressed=${se} or uncompressed=${te}`)}const ee=L.toBytes||oe,Z=L.fromBytes||ae;function ce(Ne){const se=x.sqr(Ne),te=x.mul(se,Ne);return x.add(x.add(te,x.mul(Ne,q.a)),q.b)}function ge(Ne,se){const te=x.sqr(se),ne=ce(Ne);return x.eql(te,ne)}if(!ge(q.Gx,q.Gy))throw new Error("bad curve params: generator point");const pe=x.mul(x.pow(q.a,g),w),J=x.mul(x.sqr(q.b),BigInt(27));if(x.is0(x.add(pe,J)))throw new Error("bad curve params: a or b");function fe(Ne,se,te=!1){if(!x.isValid(se)||te&&x.is0(se))throw new Error(`bad point coordinate ${Ne}`);return se}function Se(Ne){if(!(Ne instanceof Ae))throw new Error("ProjectivePoint expected")}function Ce(Ne){if(!G||!G.basises)throw new Error("no endo");return c(Ne,G.basises,O.ORDER)}const Ze=(0,r.memoized)((Ne,se)=>{const{X:te,Y:ne,Z:k}=Ne;if(x.eql(k,x.ONE))return{x:te,y:ne};const d=Ne.is0();se==null&&(se=d?x.ONE:x.inv(k));const h=x.mul(te,se),b=x.mul(ne,se),B=x.mul(k,se);if(d)return{x:x.ZERO,y:x.ZERO};if(!x.eql(B,x.ONE))throw new Error("invZ was invalid");return{x:h,y:b}}),st=(0,r.memoized)(Ne=>{if(Ne.is0()){if(L.allowInfinityPoint&&!x.is0(Ne.Y))return;throw new Error("bad point: ZERO")}const{x:se,y:te}=Ne.toAffine();if(!x.isValid(se)||!x.isValid(te))throw new Error("bad point: x or y not field elements");if(!ge(se,te))throw new Error("bad point: equation left != right");if(!Ne.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function St(Ne,se,te,ne,k){return te=new Ae(x.mul(te.X,Ne),te.Y,te.Z),se=(0,i.negateCt)(ne,se),te=(0,i.negateCt)(k,te),se.add(te)}class Ae{constructor(se,te,ne){this.X=fe("x",se),this.Y=fe("y",te,!0),this.Z=fe("z",ne),Object.freeze(this)}static CURVE(){return q}static fromAffine(se){const{x:te,y:ne}=se||{};if(!se||!x.isValid(te)||!x.isValid(ne))throw new Error("invalid affine point");if(se instanceof Ae)throw new Error("projective point not allowed");return x.is0(te)&&x.is0(ne)?Ae.ZERO:new Ae(te,ne,x.ONE)}static fromBytes(se){const te=Ae.fromAffine(Z((0,r._abytes2)(se,void 0,"point")));return te.assertValidity(),te}static fromHex(se){return Ae.fromBytes((0,r.ensureBytes)("pointHex",se))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(se=8,te=!0){return et.createCache(this,se),te||this.multiply(g),this}assertValidity(){st(this)}hasEvenY(){const{y:se}=this.toAffine();if(!x.isOdd)throw new Error("Field doesn't support isOdd");return!x.isOdd(se)}equals(se){Se(se);const{X:te,Y:ne,Z:k}=this,{X:d,Y:h,Z:b}=se,B=x.eql(x.mul(te,b),x.mul(d,k)),C=x.eql(x.mul(ne,b),x.mul(h,k));return B&&C}negate(){return new Ae(this.X,x.neg(this.Y),this.Z)}double(){const{a:se,b:te}=q,ne=x.mul(te,g),{X:k,Y:d,Z:h}=this;let b=x.ZERO,B=x.ZERO,C=x.ZERO,j=x.mul(k,k),D=x.mul(d,d),re=x.mul(h,h),Q=x.mul(k,d);return Q=x.add(Q,Q),C=x.mul(k,h),C=x.add(C,C),b=x.mul(se,C),B=x.mul(ne,re),B=x.add(b,B),b=x.sub(D,B),B=x.add(D,B),B=x.mul(b,B),b=x.mul(Q,b),C=x.mul(ne,C),re=x.mul(se,re),Q=x.sub(j,re),Q=x.mul(se,Q),Q=x.add(Q,C),C=x.add(j,j),j=x.add(C,j),j=x.add(j,re),j=x.mul(j,Q),B=x.add(B,j),re=x.mul(d,h),re=x.add(re,re),j=x.mul(re,Q),b=x.sub(b,j),C=x.mul(re,D),C=x.add(C,C),C=x.add(C,C),new Ae(b,B,C)}add(se){Se(se);const{X:te,Y:ne,Z:k}=this,{X:d,Y:h,Z:b}=se;let B=x.ZERO,C=x.ZERO,j=x.ZERO;const D=q.a,re=x.mul(q.b,g);let Q=x.mul(te,d),ue=x.mul(ne,h),le=x.mul(k,b),Be=x.add(te,ne),Oe=x.add(d,h);Be=x.mul(Be,Oe),Oe=x.add(Q,ue),Be=x.sub(Be,Oe),Oe=x.add(te,k);let Je=x.add(d,b);return Oe=x.mul(Oe,Je),Je=x.add(Q,le),Oe=x.sub(Oe,Je),Je=x.add(ne,k),B=x.add(h,b),Je=x.mul(Je,B),B=x.add(ue,le),Je=x.sub(Je,B),j=x.mul(D,Oe),B=x.mul(re,le),j=x.add(B,j),B=x.sub(ue,j),j=x.add(ue,j),C=x.mul(B,j),ue=x.add(Q,Q),ue=x.add(ue,Q),le=x.mul(D,le),Oe=x.mul(re,Oe),ue=x.add(ue,le),le=x.sub(Q,le),le=x.mul(D,le),Oe=x.add(Oe,le),Q=x.mul(ue,Oe),C=x.add(C,Q),Q=x.mul(Je,Oe),B=x.mul(Be,B),B=x.sub(B,Q),Q=x.mul(Be,ue),j=x.mul(Je,j),j=x.add(j,Q),new Ae(B,C,j)}subtract(se){return this.add(se.negate())}is0(){return this.equals(Ae.ZERO)}multiply(se){const{endo:te}=L;if(!O.isValidNot0(se))throw new Error("invalid scalar: out of range");let ne,k;const d=h=>et.cached(this,h,b=>(0,i.normalizeZ)(Ae,b));if(te){const{k1neg:h,k1:b,k2neg:B,k2:C}=Ce(se),{p:j,f:D}=d(b),{p:re,f:Q}=d(C);k=D.add(Q),ne=St(te.beta,j,re,h,B)}else{const{p:h,f:b}=d(se);ne=h,k=b}return(0,i.normalizeZ)(Ae,[ne,k])[0]}multiplyUnsafe(se){const{endo:te}=L,ne=this;if(!O.isValid(se))throw new Error("invalid scalar: out of range");if(se===l||ne.is0())return Ae.ZERO;if(se===p)return ne;if(et.hasCache(this))return this.multiply(se);if(te){const{k1neg:k,k1:d,k2neg:h,k2:b}=Ce(se),{p1:B,p2:C}=(0,i.mulEndoUnsafe)(Ae,ne,d,b);return St(te.beta,B,C,k,h)}else return et.unsafe(ne,se)}multiplyAndAddUnsafe(se,te,ne){const k=this.multiplyUnsafe(te).add(se.multiplyUnsafe(ne));return k.is0()?void 0:k}toAffine(se){return Ze(this,se)}isTorsionFree(){const{isTorsionFree:se}=L;return P===p?!0:se?se(Ae,this):et.unsafe(this,$).is0()}clearCofactor(){const{clearCofactor:se}=L;return P===p?this:se?se(Ae,this):this.multiplyUnsafe(P)}isSmallOrder(){return this.multiplyUnsafe(P).is0()}toBytes(se=!0){return(0,r._abool2)(se,"isCompressed"),this.assertValidity(),ee(Ae,this,se)}toHex(se=!0){return(0,r.bytesToHex)(this.toBytes(se))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(se=!0){return this.toBytes(se)}_setWindowSize(se){this.precompute(se)}static normalizeZ(se){return(0,i.normalizeZ)(Ae,se)}static msm(se,te){return(0,i.pippenger)(Ae,O,se,te)}static fromPrivateKey(se){return Ae.BASE.multiply(E(O,se))}}Ae.BASE=new Ae(q.Gx,q.Gy,x.ONE),Ae.ZERO=new Ae(x.ZERO,x.ONE,x.ZERO),Ae.Fp=x,Ae.Fn=O;const ln=O.BITS,et=new i.wNAF(Ae,L.endo?Math.ceil(ln/2):ln);return Ae.BASE.precompute(8),Ae}function S(N){return Uint8Array.of(N?2:3)}function m(N,L){const F=N.ORDER;let x=l;for(let Z=F-p;Z%y===l;Z/=y)x+=p;const O=x,q=y<<O-p-p,P=q*y,$=(F-p)/P,G=($-p)/y,X=P-p,Y=q,oe=N.pow(L,$),ae=N.pow(L,($+p)/y);let ee=(Z,ce)=>{let ge=oe,pe=N.pow(ce,X),J=N.sqr(pe);J=N.mul(J,ce);let fe=N.mul(Z,J);fe=N.pow(fe,G),fe=N.mul(fe,pe),pe=N.mul(fe,ce),J=N.mul(fe,Z);let Se=N.mul(J,pe);fe=N.pow(Se,Y);let Ce=N.eql(fe,N.ONE);pe=N.mul(J,ae),fe=N.mul(Se,ge),J=N.cmov(pe,J,Ce),Se=N.cmov(fe,Se,Ce);for(let Ze=O;Ze>p;Ze--){let st=Ze-y;st=y<<st-p;let St=N.pow(Se,st);const Ae=N.eql(St,N.ONE);pe=N.mul(J,ge),ge=N.mul(ge,ge),St=N.mul(Se,ge),J=N.cmov(pe,J,Ae),Se=N.cmov(St,Se,Ae)}return{isValid:Ce,value:J}};if(N.ORDER%w===g){const Z=(N.ORDER-g)/w,ce=N.sqrt(N.neg(L));ee=(ge,pe)=>{let J=N.sqr(pe);const fe=N.mul(ge,pe);J=N.mul(J,fe);let Se=N.pow(J,Z);Se=N.mul(Se,fe);const Ce=N.mul(Se,ce),Ze=N.mul(N.sqr(Se),pe),st=N.eql(Ze,ge);let St=N.cmov(Ce,Se,st);return{isValid:st,value:St}}}return ee}function T(N,L){(0,s.validateField)(N);const{A:F,B:x,Z:O}=L;if(!N.isValid(F)||!N.isValid(x)||!N.isValid(O))throw new Error("mapToCurveSimpleSWU: invalid opts");const q=m(N,O);if(!N.isOdd)throw new Error("Field does not have .isOdd()");return P=>{let $,G,X,Y,oe,ae,ee,Z;$=N.sqr(P),$=N.mul($,O),G=N.sqr($),G=N.add(G,$),X=N.add(G,N.ONE),X=N.mul(X,x),Y=N.cmov(O,N.neg(G),!N.eql(G,N.ZERO)),Y=N.mul(Y,F),G=N.sqr(X),ae=N.sqr(Y),oe=N.mul(ae,F),G=N.add(G,oe),G=N.mul(G,X),ae=N.mul(ae,Y),oe=N.mul(ae,x),G=N.add(G,oe),ee=N.mul($,X);const{isValid:ce,value:ge}=q(G,ae);Z=N.mul($,P),Z=N.mul(Z,ge),ee=N.cmov(ee,X,ce),Z=N.cmov(Z,ge,ce);const pe=N.isOdd(P)===N.isOdd(Z);Z=N.cmov(N.neg(Z),Z,pe);const J=(0,s.FpInvertBatch)(N,[Y],!0)[0];return ee=N.mul(ee,J),{x:ee,y:Z}}}function I(N,L){return{secretKey:L.BYTES,publicKey:1+N.BYTES,publicKeyUncompressed:1+2*N.BYTES,publicKeyHasPrefix:!0,signature:2*L.BYTES}}function A(N,L={}){const{Fn:F}=N,x=L.randomBytes||r.randomBytes,O=Object.assign(I(N.Fp,F),{seed:(0,s.getMinHashLength)(F.ORDER)});function q(ee){try{return!!E(F,ee)}catch{return!1}}function P(ee,Z){const{publicKey:ce,publicKeyUncompressed:ge}=O;try{const pe=ee.length;return Z===!0&&pe!==ce||Z===!1&&pe!==ge?!1:!!N.fromBytes(ee)}catch{return!1}}function $(ee=x(O.seed)){return(0,s.mapHashToField)((0,r._abytes2)(ee,O.seed,"seed"),F.ORDER)}function G(ee,Z=!0){return N.BASE.multiply(E(F,ee)).toBytes(Z)}function X(ee){const Z=$(ee);return{secretKey:Z,publicKey:G(Z)}}function Y(ee){if(typeof ee=="bigint")return!1;if(ee instanceof N)return!0;const{secretKey:Z,publicKey:ce,publicKeyUncompressed:ge}=O;if(F.allowedLengths||Z===ce)return;const pe=(0,r.ensureBytes)("key",ee).length;return pe===ce||pe===ge}function oe(ee,Z,ce=!0){if(Y(ee)===!0)throw new Error("first arg must be private key");if(Y(Z)===!1)throw new Error("second arg must be public key");const ge=E(F,ee);return N.fromHex(Z).multiply(ge).toBytes(ce)}return Object.freeze({getPublicKey:G,getSharedSecret:oe,keygen:X,Point:N,utils:{isValidSecretKey:q,isValidPublicKey:P,randomSecretKey:$,isValidPrivateKey:q,randomPrivateKey:$,normPrivateKeyToScalar:ee=>E(F,ee),precompute(ee=8,Z=N.BASE){return Z.precompute(ee,!1)}},lengths:O})}function U(N,L,F={}){(0,n.ahash)(L),(0,r._validateObject)(F,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const x=F.randomBytes||r.randomBytes,O=F.hmac||((te,...ne)=>(0,t.hmac)(L,te,(0,r.concatBytes)(...ne))),{Fp:q,Fn:P}=N,{ORDER:$,BITS:G}=P,{keygen:X,getPublicKey:Y,getSharedSecret:oe,utils:ae,lengths:ee}=A(N,F),Z={prehash:!1,lowS:typeof F.lowS=="boolean"?F.lowS:!1,format:void 0,extraEntropy:!1},ce="compact";function ge(te){const ne=$>>p;return te>ne}function pe(te,ne){if(!P.isValidNot0(ne))throw new Error(`invalid signature ${te}: out of range 1..Point.Fn.ORDER`);return ne}function J(te,ne){a(ne);const k=ee.signature,d=ne==="compact"?k:ne==="recovered"?k+1:void 0;return(0,r._abytes2)(te,d,`${ne} signature`)}class fe{constructor(ne,k,d){this.r=pe("r",ne),this.s=pe("s",k),d!=null&&(this.recovery=d),Object.freeze(this)}static fromBytes(ne,k=ce){J(ne,k);let d;if(k==="der"){const{r:C,s:j}=e.DER.toSig((0,r._abytes2)(ne));return new fe(C,j)}k==="recovered"&&(d=ne[0],k="compact",ne=ne.subarray(1));const h=P.BYTES,b=ne.subarray(0,h),B=ne.subarray(h,h*2);return new fe(P.fromBytes(b),P.fromBytes(B),d)}static fromHex(ne,k){return this.fromBytes((0,r.hexToBytes)(ne),k)}addRecoveryBit(ne){return new fe(this.r,this.s,ne)}recoverPublicKey(ne){const k=q.ORDER,{r:d,s:h,recovery:b}=this;if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");if($*y<k&&b>1)throw new Error("recovery id is ambiguous for h>1 curve");const C=b===2||b===3?d+$:d;if(!q.isValid(C))throw new Error("recovery id 2 or 3 invalid");const j=q.toBytes(C),D=N.fromBytes((0,r.concatBytes)(S((b&1)===0),j)),re=P.inv(C),Q=Ce((0,r.ensureBytes)("msgHash",ne)),ue=P.create(-Q*re),le=P.create(h*re),Be=N.BASE.multiplyUnsafe(ue).add(D.multiplyUnsafe(le));if(Be.is0())throw new Error("point at infinify");return Be.assertValidity(),Be}hasHighS(){return ge(this.s)}toBytes(ne=ce){if(a(ne),ne==="der")return(0,r.hexToBytes)(e.DER.hexFromSig(this));const k=P.toBytes(this.r),d=P.toBytes(this.s);if(ne==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,r.concatBytes)(Uint8Array.of(this.recovery),k,d)}return(0,r.concatBytes)(k,d)}toHex(ne){return(0,r.bytesToHex)(this.toBytes(ne))}assertValidity(){}static fromCompact(ne){return fe.fromBytes((0,r.ensureBytes)("sig",ne),"compact")}static fromDER(ne){return fe.fromBytes((0,r.ensureBytes)("sig",ne),"der")}normalizeS(){return this.hasHighS()?new fe(this.r,P.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,r.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,r.bytesToHex)(this.toBytes("compact"))}}const Se=F.bits2int||function(ne){if(ne.length>8192)throw new Error("input is too large");const k=(0,r.bytesToNumberBE)(ne),d=ne.length*8-G;return d>0?k>>BigInt(d):k},Ce=F.bits2int_modN||function(ne){return P.create(Se(ne))},Ze=(0,r.bitMask)(G);function st(te){return(0,r.aInRange)("num < 2^"+G,te,l,Ze),P.toBytes(te)}function St(te,ne){return(0,r._abytes2)(te,void 0,"message"),ne?(0,r._abytes2)(L(te),void 0,"prehashed message"):te}function Ae(te,ne,k){if(["recovered","canonical"].some(ue=>ue in k))throw new Error("sign() legacy options not supported");const{lowS:d,prehash:h,extraEntropy:b}=u(k,Z);te=St(te,h);const B=Ce(te),C=E(P,ne),j=[st(C),st(B)];if(b!=null&&b!==!1){const ue=b===!0?x(ee.secretKey):b;j.push((0,r.ensureBytes)("extraEntropy",ue))}const D=(0,r.concatBytes)(...j),re=B;function Q(ue){const le=Se(ue);if(!P.isValidNot0(le))return;const Be=P.inv(le),Oe=N.BASE.multiply(le).toAffine(),Je=P.create(Oe.x);if(Je===l)return;const Ve=P.create(Be*P.create(re+Je*C));if(Ve===l)return;let $n=(Oe.x===Je?0:2)|Number(Oe.y&p),nh=Ve;return d&&ge(Ve)&&(nh=P.neg(Ve),$n^=1),new fe(Je,nh,$n)}return{seed:D,k2sig:Q}}function ln(te,ne,k={}){te=(0,r.ensureBytes)("message",te);const{seed:d,k2sig:h}=Ae(te,ne,k);return(0,r.createHmacDrbg)(L.outputLen,P.BYTES,O)(d,h)}function et(te){let ne;const k=typeof te=="string"||(0,r.isBytes)(te),d=!k&&te!==null&&typeof te=="object"&&typeof te.r=="bigint"&&typeof te.s=="bigint";if(!k&&!d)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(d)ne=new fe(te.r,te.s);else if(k){try{ne=fe.fromBytes((0,r.ensureBytes)("sig",te),"der")}catch(h){if(!(h instanceof e.DER.Err))throw h}if(!ne)try{ne=fe.fromBytes((0,r.ensureBytes)("sig",te),"compact")}catch{return!1}}return ne||!1}function Ne(te,ne,k,d={}){const{lowS:h,prehash:b,format:B}=u(d,Z);if(k=(0,r.ensureBytes)("publicKey",k),ne=St((0,r.ensureBytes)("message",ne),b),"strict"in d)throw new Error("options.strict was renamed to lowS");const C=B===void 0?et(te):fe.fromBytes((0,r.ensureBytes)("sig",te),B);if(C===!1)return!1;try{const j=N.fromBytes(k);if(h&&C.hasHighS())return!1;const{r:D,s:re}=C,Q=Ce(ne),ue=P.inv(re),le=P.create(Q*ue),Be=P.create(D*ue),Oe=N.BASE.multiplyUnsafe(le).add(j.multiplyUnsafe(Be));return Oe.is0()?!1:P.create(Oe.x)===D}catch{return!1}}function se(te,ne,k={}){const{prehash:d}=u(k,Z);return ne=St(ne,d),fe.fromBytes(te,"recovered").recoverPublicKey(ne).toBytes()}return Object.freeze({keygen:X,getPublicKey:Y,getSharedSecret:oe,utils:ae,lengths:ee,Point:N,sign:ln,verify:Ne,recoverPublicKey:se,Signature:fe,hash:L})}function M(N){const{CURVE:L,curveOpts:F}=v(N),x=_(L,F);return W(N,x)}function v(N){const L={a:N.a,b:N.b,p:N.Fp.ORDER,n:N.n,h:N.h,Gx:N.Gx,Gy:N.Gy},F=N.Fp;let x=N.allowedPrivateKeyLengths?Array.from(new Set(N.allowedPrivateKeyLengths.map(P=>Math.ceil(P/2)))):void 0;const O=(0,s.Field)(L.n,{BITS:N.nBitLength,allowedLengths:x,modFromBytes:N.wrapPrivateKey}),q={Fp:F,Fn:O,allowInfinityPoint:N.allowInfinityPoint,endo:N.endo,isTorsionFree:N.isTorsionFree,clearCofactor:N.clearCofactor,fromBytes:N.fromBytes,toBytes:N.toBytes};return{CURVE:L,curveOpts:q}}function R(N){const{CURVE:L,curveOpts:F}=v(N),x={hmac:N.hmac,randomBytes:N.randomBytes,lowS:N.lowS,bits2int:N.bits2int,bits2int_modN:N.bits2int_modN};return{CURVE:L,curveOpts:F,hash:N.hash,ecdsaOpts:x}}function V(N,L,F){function x(O){const q=N.sqr(O),P=N.mul(q,O);return N.add(N.add(P,N.mul(O,L)),F)}return x}function W(N,L){const{Fp:F,Fn:x}=L;function O(P){return(0,r.inRange)(P,p,x.ORDER)}const q=V(F,N.a,N.b);return Object.assign({},{CURVE:N,Point:L,ProjectivePoint:L,normPrivateKeyToScalar:P=>E(x,P),weierstrassEquation:q,isWithinCurveOrder:O})}function H(N,L){const F=L.Point;return Object.assign({},L,{ProjectivePoint:F,CURVE:Object.assign({},N,(0,s.nLength)(F.Fn.ORDER,F.Fn.BITS))})}function K(N){const{CURVE:L,curveOpts:F,hash:x,ecdsaOpts:O}=R(N),q=_(L,F),P=U(q,x,O);return H(N,P)}})(hu)),hu}var Eh;function Nw(){if(Eh)return Ms;Eh=1,Object.defineProperty(Ms,"__esModule",{value:!0}),Ms.getHash=t,Ms.createCurve=n;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=jp();function t(r){return{hash:r}}function n(r,i){const s=o=>(0,e.weierstrass)({...r,hash:o});return{...s(i),create:s}}return Ms}var yu={},_h;function Uw(){return _h||(_h=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=a,e.expand_message_xof=u,e.hash_to_field=f,e.isogenyMap=l,e.createHasher=p;const t=vs(),n=$o(),r=t.bytesToNumberBE;function i(y,g){if(o(y),o(g),y<0||y>=1<<8*g)throw new Error("invalid I2OSP input: "+y);const w=Array.from({length:g}).fill(0);for(let E=g-1;E>=0;E--)w[E]=y&255,y>>>=8;return new Uint8Array(w)}function s(y,g){const w=new Uint8Array(y.length);for(let E=0;E<y.length;E++)w[E]=y[E]^g[E];return w}function o(y){if(!Number.isSafeInteger(y))throw new Error("number expected")}function c(y){if(!(0,t.isBytes)(y)&&typeof y!="string")throw new Error("DST must be Uint8Array or string");return typeof y=="string"?(0,t.utf8ToBytes)(y):y}function a(y,g,w,E){(0,t.abytes)(y),o(w),g=c(g),g.length>255&&(g=E((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),g)));const{outputLen:_,blockLen:S}=E,m=Math.ceil(w/_);if(w>65535||m>255)throw new Error("expand_message_xmd: invalid lenInBytes");const T=(0,t.concatBytes)(g,i(g.length,1)),I=i(0,S),A=i(w,2),U=new Array(m),M=E((0,t.concatBytes)(I,y,A,i(0,1),T));U[0]=E((0,t.concatBytes)(M,i(1,1),T));for(let R=1;R<=m;R++){const V=[s(M,U[R-1]),i(R+1,1),T];U[R]=E((0,t.concatBytes)(...V))}return(0,t.concatBytes)(...U).slice(0,w)}function u(y,g,w,E,_){if((0,t.abytes)(y),o(w),g=c(g),g.length>255){const S=Math.ceil(2*E/8);g=_.create({dkLen:S}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(g).digest()}if(w>65535||g.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return _.create({dkLen:w}).update(y).update(i(w,2)).update(g).update(i(g.length,1)).digest()}function f(y,g,w){(0,t._validateObject)(w,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:E,k:_,m:S,hash:m,expand:T,DST:I}=w;if(!(0,t.isHash)(w.hash))throw new Error("expected valid hash");(0,t.abytes)(y),o(g);const A=E.toString(2).length,U=Math.ceil((A+_)/8),M=g*S*U;let v;if(T==="xmd")v=a(y,I,M,m);else if(T==="xof")v=u(y,I,M,_,m);else if(T==="_internal_pass")v=y;else throw new Error('expand must be "xmd" or "xof"');const R=new Array(g);for(let V=0;V<g;V++){const W=new Array(S);for(let H=0;H<S;H++){const K=U*(H+V*S),N=v.subarray(K,K+U);W[H]=(0,n.mod)(r(N),E)}R[V]=W}return R}function l(y,g){const w=g.map(E=>Array.from(E).reverse());return(E,_)=>{const[S,m,T,I]=w.map(M=>M.reduce((v,R)=>y.add(y.mul(v,E),R))),[A,U]=(0,n.FpInvertBatch)(y,[m,I],!0);return E=y.mul(S,A),_=y.mul(_,y.mul(T,U)),{x:E,y:_}}}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-");function p(y,g,w){if(typeof g!="function")throw new Error("mapToCurve() must be defined");function E(S){return y.fromAffine(g(S))}function _(S){const m=S.clearCofactor();return m.equals(y.ZERO)?y.ZERO:(m.assertValidity(),m)}return{defaults:w,hashToCurve(S,m){const T=Object.assign({},w,m),I=f(S,2,T),A=E(I[0]),U=E(I[1]);return _(A.add(U))},encodeToCurve(S,m){const T=w.encodeDST?{DST:w.encodeDST}:{},I=Object.assign({},w,T,m),A=f(S,1,I),U=E(A[0]);return _(U)},mapToCurve(S){if(!Array.isArray(S))throw new Error("expected array of bigints");for(const m of S)if(typeof m!="bigint")throw new Error("expected array of bigints");return _(E(S))},hashToScalar(S,m){const T=y.Fn.ORDER,I=Object.assign({},w,{p:T,m:1,DST:e._DST_scalar},m);return f(S,1,I)[0][0]}}}})(yu)),yu}var Sh;function Rw(){return Sh||(Sh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.secp256k1_hasher=e.schnorr=e.secp256k1=void 0;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Lp(),n=ni(),r=Nw(),i=Uw(),s=$o(),o=jp(),c=vs(),a={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},f=BigInt(0),l=BigInt(1),p=BigInt(2);function y(H){const K=a.p,N=BigInt(3),L=BigInt(6),F=BigInt(11),x=BigInt(22),O=BigInt(23),q=BigInt(44),P=BigInt(88),$=H*H*H%K,G=$*$*H%K,X=(0,s.pow2)(G,N,K)*G%K,Y=(0,s.pow2)(X,N,K)*G%K,oe=(0,s.pow2)(Y,p,K)*$%K,ae=(0,s.pow2)(oe,F,K)*oe%K,ee=(0,s.pow2)(ae,x,K)*ae%K,Z=(0,s.pow2)(ee,q,K)*ee%K,ce=(0,s.pow2)(Z,P,K)*Z%K,ge=(0,s.pow2)(ce,q,K)*ee%K,pe=(0,s.pow2)(ge,N,K)*G%K,J=(0,s.pow2)(pe,O,K)*ae%K,fe=(0,s.pow2)(J,L,K)*$%K,Se=(0,s.pow2)(fe,p,K);if(!g.eql(g.sqr(Se),H))throw new Error("Cannot find square root");return Se}const g=(0,s.Field)(a.p,{sqrt:y});e.secp256k1=(0,r.createCurve)({...a,Fp:g,lowS:!0,endo:u},t.sha256);const w={};function E(H,...K){let N=w[H];if(N===void 0){const L=(0,t.sha256)((0,c.utf8ToBytes)(H));N=(0,c.concatBytes)(L,L),w[H]=N}return(0,t.sha256)((0,c.concatBytes)(N,...K))}const _=H=>H.toBytes(!0).slice(1),S=e.secp256k1.Point,m=H=>H%p===f;function T(H){const{Fn:K,BASE:N}=S,L=(0,o._normFnElement)(K,H),F=N.multiply(L);return{scalar:m(F.y)?L:K.neg(L),bytes:_(F)}}function I(H){const K=g;if(!K.isValidNot0(H))throw new Error("invalid x: Fail if x ≥ p");const N=K.create(H*H),L=K.create(N*H+BigInt(7));let F=K.sqrt(L);m(F)||(F=K.neg(F));const x=S.fromAffine({x:H,y:F});return x.assertValidity(),x}const A=c.bytesToNumberBE;function U(...H){return S.Fn.create(A(E("BIP0340/challenge",...H)))}function M(H){return T(H).bytes}function v(H,K,N=(0,n.randomBytes)(32)){const{Fn:L}=S,F=(0,c.ensureBytes)("message",H),{bytes:x,scalar:O}=T(K),q=(0,c.ensureBytes)("auxRand",N,32),P=L.toBytes(O^A(E("BIP0340/aux",q))),$=E("BIP0340/nonce",P,x,F),{bytes:G,scalar:X}=T($),Y=U(G,x,F),oe=new Uint8Array(64);if(oe.set(G,0),oe.set(L.toBytes(L.create(X+Y*O)),32),!R(oe,F,x))throw new Error("sign: Invalid signature produced");return oe}function R(H,K,N){const{Fn:L,BASE:F}=S,x=(0,c.ensureBytes)("signature",H,64),O=(0,c.ensureBytes)("message",K),q=(0,c.ensureBytes)("publicKey",N,32);try{const P=I(A(q)),$=A(x.subarray(0,32));if(!(0,c.inRange)($,l,a.p))return!1;const G=A(x.subarray(32,64));if(!(0,c.inRange)(G,l,a.n))return!1;const X=U(L.toBytes($),_(P),O),Y=F.multiplyUnsafe(G).add(P.multiplyUnsafe(L.neg(X))),{x:oe,y:ae}=Y.toAffine();return!(Y.is0()||!m(ae)||oe!==$)}catch{return!1}}e.schnorr=(()=>{const N=(F=(0,n.randomBytes)(48))=>(0,s.mapHashToField)(F,a.n);e.secp256k1.utils.randomSecretKey;function L(F){const x=N(F);return{secretKey:x,publicKey:M(x)}}return{keygen:L,getPublicKey:M,sign:v,verify:R,Point:S,utils:{randomSecretKey:N,randomPrivateKey:N,taggedHash:E,lift_x:I,pointToBytes:_,numberToBytesBE:c.numberToBytesBE,bytesToNumberBE:c.bytesToNumberBE,mod:s.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const V=(0,i.isogenyMap)(g,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(H=>H.map(K=>BigInt(K)))),W=(0,o.mapToCurveSimpleSWU)(g,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:g.create(BigInt("-11"))});e.secp256k1_hasher=(0,i.createHasher)(e.secp256k1.Point,H=>{const{x:K,y:N}=W(g.create(H[0]));return V(K,N)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:g.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve})(fu)),fu}var de={},Th;function Cw(){if(Th)return de;Th=1,Object.defineProperty(de,"__esModule",{value:!0}),de.isHash=de.validateObject=de.memoized=de.notImplemented=de.createHmacDrbg=de.bitMask=de.bitSet=de.bitGet=de.bitLen=de.aInRange=de.inRange=de.asciiToBytes=de.copyBytes=de.equalBytes=de.ensureBytes=de.numberToVarBytesBE=de.numberToBytesLE=de.numberToBytesBE=de.bytesToNumberLE=de.bytesToNumberBE=de.hexToNumber=de.numberToHexUnpadded=de.abool=de.utf8ToBytes=de.randomBytes=de.isBytes=de.hexToBytes=de.concatBytes=de.bytesToUtf8=de.bytesToHex=de.anumber=de.abytes=void 0;const e=vs();return de.abytes=e.abytes,de.anumber=e.anumber,de.bytesToHex=e.bytesToHex,de.bytesToUtf8=e.bytesToUtf8,de.concatBytes=e.concatBytes,de.hexToBytes=e.hexToBytes,de.isBytes=e.isBytes,de.randomBytes=e.randomBytes,de.utf8ToBytes=e.utf8ToBytes,de.abool=e.abool,de.numberToHexUnpadded=e.numberToHexUnpadded,de.hexToNumber=e.hexToNumber,de.bytesToNumberBE=e.bytesToNumberBE,de.bytesToNumberLE=e.bytesToNumberLE,de.numberToBytesBE=e.numberToBytesBE,de.numberToBytesLE=e.numberToBytesLE,de.numberToVarBytesBE=e.numberToVarBytesBE,de.ensureBytes=e.ensureBytes,de.equalBytes=e.equalBytes,de.copyBytes=e.copyBytes,de.asciiToBytes=e.asciiToBytes,de.inRange=e.inRange,de.aInRange=e.aInRange,de.bitLen=e.bitLen,de.bitGet=e.bitGet,de.bitSet=e.bitSet,de.bitMask=e.bitMask,de.createHmacDrbg=e.createHmacDrbg,de.notImplemented=e.notImplemented,de.memoized=e.memoized,de.validateObject=e.validateObject,de.isHash=e.isHash,de}var xh;function Hw(){if(xh)return tt;xh=1;var e=Rw(),t=$o(),n=Cw();function r(d){var h=Object.create(null);return d&&Object.keys(d).forEach(function(b){if(b!=="default"){var B=Object.getOwnPropertyDescriptor(d,b);Object.defineProperty(h,b,B.get?B:{enumerable:!0,get:function(){return d[b]}})}}),h.default=d,Object.freeze(h)}var i=r(t),s=r(n);const o=e.secp256k1.ProjectivePoint,c="Expected Private",a="Expected Point",u="Expected Tweak",f="Expected Hash",l="Expected Signature",p="Expected Extra Data (32 bytes)",y="Expected Scalar",g="Bad Recovery Id",w=32,E=32,_=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230,175,72,160,59,191,210,94,140,208,54,65,65]),S=32,m=new Uint8Array(32),T=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,69,81,35,25,80,183,95,196,64,45,161,114,47,201,186,238]),I=BigInt(1);function A(d){return d instanceof Uint8Array}function U(d,h){for(let b=0;b<32;++b)if(d[b]!==h[b])return d[b]<h[b]?-1:1;return 0}function M(d){return U(d,m)===0}function v(d){return!(!(d instanceof Uint8Array)||d.length!==E||U(d,_)>=0)}function R(d){return d instanceof Uint8Array&&d.length===64&&U(d.subarray(0,32),_)<0&&U(d.subarray(32,64),_)<0}function V(d){return A(d)&&d.length===64&&U(d.subarray(0,32),T)<0}function W(d){return!(M(d.subarray(0,32))||M(d.subarray(32,64)))}function H(d){return d instanceof Uint8Array&&d.length===w}function K(d){return d===void 0||d instanceof Uint8Array&&d.length===S}function N(d){let h;if(typeof d=="bigint")h=d;else if(typeof d=="number"&&Number.isSafeInteger(d)&&d>=0)h=BigInt(d);else if(typeof d=="string"){if(d.length!==64)throw new Error("Expected 32 bytes of private scalar");h=s.hexToNumber(d)}else if(d instanceof Uint8Array){if(d.length!==32)throw new Error("Expected 32 bytes of private scalar");h=s.bytesToNumberBE(d)}else throw new TypeError("Expected valid private scalar");if(h<0)throw new Error("Expected private scalar >= 0");return h}function L(d){return e.secp256k1.utils.normPrivateKeyToScalar(d)}function F(d,h){const b=L(d),B=N(h),C=s.numberToBytesBE(i.mod(b+B,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(C)?C:null}function x(d,h){const b=L(d),B=N(h),C=s.numberToBytesBE(i.mod(b-B,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(C)?C:null}function O(d){const h=L(d),b=s.numberToBytesBE(e.secp256k1.CURVE.n-h,32);return e.secp256k1.utils.isValidPrivateKey(b)?b:null}function q(d,h,b){const B=Y(d),C=N(h),j=o.BASE.multiplyAndAddUnsafe(B,C,I);if(!j)throw new Error("Tweaked point at infinity");return j.toRawBytes(b)}function P(d,h,b){const B=Y(d),C=typeof h=="string"?h:s.bytesToHex(h),j=s.hexToNumber(C);return B.multiply(j).toRawBytes(b)}function $(d,h){return d===void 0?h!==void 0?ee(h):!0:!!d}function G(d){try{return d()}catch{return null}}function X(d){return e.schnorr.utils.lift_x(s.bytesToNumberBE(d))}function Y(d){return d.length===32?X(d):o.fromHex(d)}function oe(d,h){if(d.length===32!==h)return!1;try{return h?!!X(d):!!o.fromHex(d)}catch{return!1}}function ae(d){return oe(d,!1)}function ee(d){return oe(d,!1)&&d.length===33}function Z(d){return e.secp256k1.utils.isValidPrivateKey(d)}function ce(d){return oe(d,!0)}function ge(d,h){if(!ce(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>{const b=q(d,h,!0);return{parity:b[0]%2===1?1:0,xOnlyPubkey:b.slice(1)}})}function pe(d){if(!ae(d))throw new Error(a);return d.slice(1,33)}function J(d,h){if(!Z(d))throw new Error(c);return G(()=>e.secp256k1.getPublicKey(d,$(h)))}function fe(d){if(!Z(d))throw new Error(c);return pe(J(d))}function Se(d,h){if(!ae(d))throw new Error(a);return Y(d).toRawBytes($(h,d))}function Ce(d,h,b){if(!ae(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>P(d,h,$(b,d)))}function Ze(d,h,b){if(!ae(d)||!ae(h))throw new Error(a);return G(()=>{const B=Y(d),C=Y(h);return B.equals(C.negate())?null:B.add(C).toRawBytes($(b,d))})}function st(d,h,b){if(!ae(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>q(d,h,$(b,d)))}function St(d,h){if(!Z(d))throw new Error(c);if(!v(h))throw new Error(u);return G(()=>F(d,h))}function Ae(d,h){if(!Z(d))throw new Error(c);if(!v(h))throw new Error(u);return G(()=>x(d,h))}function ln(d){if(!Z(d))throw new Error(c);return O(d)}function et(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);return e.secp256k1.sign(d,h,{extraEntropy:b}).toCompactRawBytes()}function Ne(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);const B=e.secp256k1.sign(d,h,{extraEntropy:b});return{signature:B.toCompactRawBytes(),recoveryId:B.recovery}}function se(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);return e.schnorr.sign(d,h,b)}function te(d,h,b,B){if(!H(d))throw new Error(f);if(!R(h)||!W(h))throw new Error(l);if(b&2&&!V(h))throw new Error(g);if(!ce(h.subarray(0,32)))throw new Error(l);const j=e.secp256k1.Signature.fromCompact(h).addRecoveryBit(b).recoverPublicKey(d);if(!j)throw new Error(l);return j.toRawBytes($(B))}function ne(d,h,b,B){if(!ae(h))throw new Error(a);if(!R(b))throw new Error(l);if(!H(d))throw new Error(y);return e.secp256k1.verify(b,d,h,{lowS:B})}function k(d,h,b){if(!ce(h))throw new Error(a);if(!R(b))throw new Error(l);if(!H(d))throw new Error(y);return e.schnorr.verify(b,d,h)}return tt.isPoint=ae,tt.isPointCompressed=ee,tt.isPrivate=Z,tt.isXOnlyPoint=ce,tt.pointAdd=Ze,tt.pointAddScalar=st,tt.pointCompress=Se,tt.pointFromScalar=J,tt.pointMultiply=Ce,tt.privateAdd=St,tt.privateNegate=ln,tt.privateSub=Ae,tt.recover=te,tt.sign=et,tt.signRecoverable=Ne,tt.signSchnorr=se,tt.verify=ne,tt.verifySchnorr=k,tt.xOnlyPointAddTweak=ge,tt.xOnlyPointFromPoint=pe,tt.xOnlyPointFromScalar=fe,tt}var Wp=Hw();const Fw=$p(Wp),Mw=_w({__proto__:null,default:Fw},[Wp]),vn={messagePrefix:`Bitcoin Signed Message:
|
|
6
|
+
*/var ah;function Vo(){return ah||(ah=1,(function(e){const t=Sw(),n=Tw(),r=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=c,e.SlowBuffer=S,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,c.TYPED_ARRAY_SUPPORT=s(),!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const k=new Uint8Array(1),d={foo:function(){return 42}};return Object.setPrototypeOf(d,Uint8Array.prototype),Object.setPrototypeOf(k,d),k.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function o(k){if(k>i)throw new RangeError('The value "'+k+'" is invalid for option "size"');const d=new Uint8Array(k);return Object.setPrototypeOf(d,c.prototype),d}function c(k,d,h){if(typeof k=="number"){if(typeof d=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(k)}return a(k,d,h)}c.poolSize=8192;function a(k,d,h){if(typeof k=="string")return p(k,d);if(ArrayBuffer.isView(k))return g(k);if(k==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k);if(et(k,ArrayBuffer)||k&&et(k.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(et(k,SharedArrayBuffer)||k&&et(k.buffer,SharedArrayBuffer)))return w(k,d,h);if(typeof k=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const b=k.valueOf&&k.valueOf();if(b!=null&&b!==k)return c.from(b,d,h);const B=E(k);if(B)return B;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof k[Symbol.toPrimitive]=="function")return c.from(k[Symbol.toPrimitive]("string"),d,h);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k)}c.from=function(k,d,h){return a(k,d,h)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array);function u(k){if(typeof k!="number")throw new TypeError('"size" argument must be of type number');if(k<0)throw new RangeError('The value "'+k+'" is invalid for option "size"')}function f(k,d,h){return u(k),k<=0?o(k):d!==void 0?typeof h=="string"?o(k).fill(d,h):o(k).fill(d):o(k)}c.alloc=function(k,d,h){return f(k,d,h)};function l(k){return u(k),o(k<0?0:_(k)|0)}c.allocUnsafe=function(k){return l(k)},c.allocUnsafeSlow=function(k){return l(k)};function p(k,d){if((typeof d!="string"||d==="")&&(d="utf8"),!c.isEncoding(d))throw new TypeError("Unknown encoding: "+d);const h=m(k,d)|0;let b=o(h);const B=b.write(k,d);return B!==h&&(b=b.slice(0,B)),b}function y(k){const d=k.length<0?0:_(k.length)|0,h=o(d);for(let b=0;b<d;b+=1)h[b]=k[b]&255;return h}function g(k){if(et(k,Uint8Array)){const d=new Uint8Array(k);return w(d.buffer,d.byteOffset,d.byteLength)}return y(k)}function w(k,d,h){if(d<0||k.byteLength<d)throw new RangeError('"offset" is outside of buffer bounds');if(k.byteLength<d+(h||0))throw new RangeError('"length" is outside of buffer bounds');let b;return d===void 0&&h===void 0?b=new Uint8Array(k):h===void 0?b=new Uint8Array(k,d):b=new Uint8Array(k,d,h),Object.setPrototypeOf(b,c.prototype),b}function E(k){if(c.isBuffer(k)){const d=_(k.length)|0,h=o(d);return h.length===0||k.copy(h,0,0,d),h}if(k.length!==void 0)return typeof k.length!="number"||Ne(k.length)?o(0):y(k);if(k.type==="Buffer"&&Array.isArray(k.data))return y(k.data)}function _(k){if(k>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return k|0}function S(k){return+k!=k&&(k=0),c.alloc(+k)}c.isBuffer=function(d){return d!=null&&d._isBuffer===!0&&d!==c.prototype},c.compare=function(d,h){if(et(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),et(h,Uint8Array)&&(h=c.from(h,h.offset,h.byteLength)),!c.isBuffer(d)||!c.isBuffer(h))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(d===h)return 0;let b=d.length,B=h.length;for(let C=0,j=Math.min(b,B);C<j;++C)if(d[C]!==h[C]){b=d[C],B=h[C];break}return b<B?-1:B<b?1:0},c.isEncoding=function(d){switch(String(d).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(d,h){if(!Array.isArray(d))throw new TypeError('"list" argument must be an Array of Buffers');if(d.length===0)return c.alloc(0);let b;if(h===void 0)for(h=0,b=0;b<d.length;++b)h+=d[b].length;const B=c.allocUnsafe(h);let C=0;for(b=0;b<d.length;++b){let j=d[b];if(et(j,Uint8Array))C+j.length>B.length?(c.isBuffer(j)||(j=c.from(j)),j.copy(B,C)):Uint8Array.prototype.set.call(B,j,C);else if(c.isBuffer(j))j.copy(B,C);else throw new TypeError('"list" argument must be an Array of Buffers');C+=j.length}return B};function m(k,d){if(c.isBuffer(k))return k.length;if(ArrayBuffer.isView(k)||et(k,ArrayBuffer))return k.byteLength;if(typeof k!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof k);const h=k.length,b=arguments.length>2&&arguments[2]===!0;if(!b&&h===0)return 0;let B=!1;for(;;)switch(d){case"ascii":case"latin1":case"binary":return h;case"utf8":case"utf-8":return Ze(k).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return h*2;case"hex":return h>>>1;case"base64":return Ae(k).length;default:if(B)return b?-1:Ze(k).length;d=(""+d).toLowerCase(),B=!0}}c.byteLength=m;function T(k,d,h){let b=!1;if((d===void 0||d<0)&&(d=0),d>this.length||((h===void 0||h>this.length)&&(h=this.length),h<=0)||(h>>>=0,d>>>=0,h<=d))return"";for(k||(k="utf8");;)switch(k){case"hex":return O(this,d,h);case"utf8":case"utf-8":return K(this,d,h);case"ascii":return F(this,d,h);case"latin1":case"binary":return x(this,d,h);case"base64":return H(this,d,h);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,d,h);default:if(b)throw new TypeError("Unknown encoding: "+k);k=(k+"").toLowerCase(),b=!0}}c.prototype._isBuffer=!0;function I(k,d,h){const b=k[d];k[d]=k[h],k[h]=b}c.prototype.swap16=function(){const d=this.length;if(d%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let h=0;h<d;h+=2)I(this,h,h+1);return this},c.prototype.swap32=function(){const d=this.length;if(d%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let h=0;h<d;h+=4)I(this,h,h+3),I(this,h+1,h+2);return this},c.prototype.swap64=function(){const d=this.length;if(d%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let h=0;h<d;h+=8)I(this,h,h+7),I(this,h+1,h+6),I(this,h+2,h+5),I(this,h+3,h+4);return this},c.prototype.toString=function(){const d=this.length;return d===0?"":arguments.length===0?K(this,0,d):T.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(d){if(!c.isBuffer(d))throw new TypeError("Argument must be a Buffer");return this===d?!0:c.compare(this,d)===0},c.prototype.inspect=function(){let d="";const h=e.INSPECT_MAX_BYTES;return d=this.toString("hex",0,h).replace(/(.{2})/g,"$1 ").trim(),this.length>h&&(d+=" ... "),"<Buffer "+d+">"},r&&(c.prototype[r]=c.prototype.inspect),c.prototype.compare=function(d,h,b,B,C){if(et(d,Uint8Array)&&(d=c.from(d,d.offset,d.byteLength)),!c.isBuffer(d))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof d);if(h===void 0&&(h=0),b===void 0&&(b=d?d.length:0),B===void 0&&(B=0),C===void 0&&(C=this.length),h<0||b>d.length||B<0||C>this.length)throw new RangeError("out of range index");if(B>=C&&h>=b)return 0;if(B>=C)return-1;if(h>=b)return 1;if(h>>>=0,b>>>=0,B>>>=0,C>>>=0,this===d)return 0;let j=C-B,D=b-h;const re=Math.min(j,D),Q=this.slice(B,C),ue=d.slice(h,b);for(let le=0;le<re;++le)if(Q[le]!==ue[le]){j=Q[le],D=ue[le];break}return j<D?-1:D<j?1:0};function A(k,d,h,b,B){if(k.length===0)return-1;if(typeof h=="string"?(b=h,h=0):h>2147483647?h=2147483647:h<-2147483648&&(h=-2147483648),h=+h,Ne(h)&&(h=B?0:k.length-1),h<0&&(h=k.length+h),h>=k.length){if(B)return-1;h=k.length-1}else if(h<0)if(B)h=0;else return-1;if(typeof d=="string"&&(d=c.from(d,b)),c.isBuffer(d))return d.length===0?-1:U(k,d,h,b,B);if(typeof d=="number")return d=d&255,typeof Uint8Array.prototype.indexOf=="function"?B?Uint8Array.prototype.indexOf.call(k,d,h):Uint8Array.prototype.lastIndexOf.call(k,d,h):U(k,[d],h,b,B);throw new TypeError("val must be string, number or Buffer")}function U(k,d,h,b,B){let C=1,j=k.length,D=d.length;if(b!==void 0&&(b=String(b).toLowerCase(),b==="ucs2"||b==="ucs-2"||b==="utf16le"||b==="utf-16le")){if(k.length<2||d.length<2)return-1;C=2,j/=2,D/=2,h/=2}function re(ue,le){return C===1?ue[le]:ue.readUInt16BE(le*C)}let Q;if(B){let ue=-1;for(Q=h;Q<j;Q++)if(re(k,Q)===re(d,ue===-1?0:Q-ue)){if(ue===-1&&(ue=Q),Q-ue+1===D)return ue*C}else ue!==-1&&(Q-=Q-ue),ue=-1}else for(h+D>j&&(h=j-D),Q=h;Q>=0;Q--){let ue=!0;for(let le=0;le<D;le++)if(re(k,Q+le)!==re(d,le)){ue=!1;break}if(ue)return Q}return-1}c.prototype.includes=function(d,h,b){return this.indexOf(d,h,b)!==-1},c.prototype.indexOf=function(d,h,b){return A(this,d,h,b,!0)},c.prototype.lastIndexOf=function(d,h,b){return A(this,d,h,b,!1)};function M(k,d,h,b){h=Number(h)||0;const B=k.length-h;b?(b=Number(b),b>B&&(b=B)):b=B;const C=d.length;b>C/2&&(b=C/2);let j;for(j=0;j<b;++j){const D=parseInt(d.substr(j*2,2),16);if(Ne(D))return j;k[h+j]=D}return j}function v(k,d,h,b){return ln(Ze(d,k.length-h),k,h,b)}function R(k,d,h,b){return ln(st(d),k,h,b)}function V(k,d,h,b){return ln(Ae(d),k,h,b)}function W(k,d,h,b){return ln(St(d,k.length-h),k,h,b)}c.prototype.write=function(d,h,b,B){if(h===void 0)B="utf8",b=this.length,h=0;else if(b===void 0&&typeof h=="string")B=h,b=this.length,h=0;else if(isFinite(h))h=h>>>0,isFinite(b)?(b=b>>>0,B===void 0&&(B="utf8")):(B=b,b=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const C=this.length-h;if((b===void 0||b>C)&&(b=C),d.length>0&&(b<0||h<0)||h>this.length)throw new RangeError("Attempt to write outside buffer bounds");B||(B="utf8");let j=!1;for(;;)switch(B){case"hex":return M(this,d,h,b);case"utf8":case"utf-8":return v(this,d,h,b);case"ascii":case"latin1":case"binary":return R(this,d,h,b);case"base64":return V(this,d,h,b);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return W(this,d,h,b);default:if(j)throw new TypeError("Unknown encoding: "+B);B=(""+B).toLowerCase(),j=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function H(k,d,h){return d===0&&h===k.length?t.fromByteArray(k):t.fromByteArray(k.slice(d,h))}function K(k,d,h){h=Math.min(k.length,h);const b=[];let B=d;for(;B<h;){const C=k[B];let j=null,D=C>239?4:C>223?3:C>191?2:1;if(B+D<=h){let re,Q,ue,le;switch(D){case 1:C<128&&(j=C);break;case 2:re=k[B+1],(re&192)===128&&(le=(C&31)<<6|re&63,le>127&&(j=le));break;case 3:re=k[B+1],Q=k[B+2],(re&192)===128&&(Q&192)===128&&(le=(C&15)<<12|(re&63)<<6|Q&63,le>2047&&(le<55296||le>57343)&&(j=le));break;case 4:re=k[B+1],Q=k[B+2],ue=k[B+3],(re&192)===128&&(Q&192)===128&&(ue&192)===128&&(le=(C&15)<<18|(re&63)<<12|(Q&63)<<6|ue&63,le>65535&&le<1114112&&(j=le))}}j===null?(j=65533,D=1):j>65535&&(j-=65536,b.push(j>>>10&1023|55296),j=56320|j&1023),b.push(j),B+=D}return L(b)}const N=4096;function L(k){const d=k.length;if(d<=N)return String.fromCharCode.apply(String,k);let h="",b=0;for(;b<d;)h+=String.fromCharCode.apply(String,k.slice(b,b+=N));return h}function F(k,d,h){let b="";h=Math.min(k.length,h);for(let B=d;B<h;++B)b+=String.fromCharCode(k[B]&127);return b}function x(k,d,h){let b="";h=Math.min(k.length,h);for(let B=d;B<h;++B)b+=String.fromCharCode(k[B]);return b}function O(k,d,h){const b=k.length;(!d||d<0)&&(d=0),(!h||h<0||h>b)&&(h=b);let B="";for(let C=d;C<h;++C)B+=se[k[C]];return B}function q(k,d,h){const b=k.slice(d,h);let B="";for(let C=0;C<b.length-1;C+=2)B+=String.fromCharCode(b[C]+b[C+1]*256);return B}c.prototype.slice=function(d,h){const b=this.length;d=~~d,h=h===void 0?b:~~h,d<0?(d+=b,d<0&&(d=0)):d>b&&(d=b),h<0?(h+=b,h<0&&(h=0)):h>b&&(h=b),h<d&&(h=d);const B=this.subarray(d,h);return Object.setPrototypeOf(B,c.prototype),B};function P(k,d,h){if(k%1!==0||k<0)throw new RangeError("offset is not uint");if(k+d>h)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d],C=1,j=0;for(;++j<h&&(C*=256);)B+=this[d+j]*C;return B},c.prototype.readUintBE=c.prototype.readUIntBE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d+--h],C=1;for(;h>0&&(C*=256);)B+=this[d+--h]*C;return B},c.prototype.readUint8=c.prototype.readUInt8=function(d,h){return d=d>>>0,h||P(d,1,this.length),this[d]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(d,h){return d=d>>>0,h||P(d,2,this.length),this[d]|this[d+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(d,h){return d=d>>>0,h||P(d,2,this.length),this[d]<<8|this[d+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(d,h){return d=d>>>0,h||P(d,4,this.length),(this[d]|this[d+1]<<8|this[d+2]<<16)+this[d+3]*16777216},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]*16777216+(this[d+1]<<16|this[d+2]<<8|this[d+3])},c.prototype.readBigUInt64LE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=h+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24,C=this[++d]+this[++d]*2**8+this[++d]*2**16+b*2**24;return BigInt(B)+(BigInt(C)<<BigInt(32))}),c.prototype.readBigUInt64BE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=h*2**24+this[++d]*2**16+this[++d]*2**8+this[++d],C=this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b;return(BigInt(B)<<BigInt(32))+BigInt(C)}),c.prototype.readIntLE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=this[d],C=1,j=0;for(;++j<h&&(C*=256);)B+=this[d+j]*C;return C*=128,B>=C&&(B-=Math.pow(2,8*h)),B},c.prototype.readIntBE=function(d,h,b){d=d>>>0,h=h>>>0,b||P(d,h,this.length);let B=h,C=1,j=this[d+--B];for(;B>0&&(C*=256);)j+=this[d+--B]*C;return C*=128,j>=C&&(j-=Math.pow(2,8*h)),j},c.prototype.readInt8=function(d,h){return d=d>>>0,h||P(d,1,this.length),this[d]&128?(255-this[d]+1)*-1:this[d]},c.prototype.readInt16LE=function(d,h){d=d>>>0,h||P(d,2,this.length);const b=this[d]|this[d+1]<<8;return b&32768?b|4294901760:b},c.prototype.readInt16BE=function(d,h){d=d>>>0,h||P(d,2,this.length);const b=this[d+1]|this[d]<<8;return b&32768?b|4294901760:b},c.prototype.readInt32LE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]|this[d+1]<<8|this[d+2]<<16|this[d+3]<<24},c.prototype.readInt32BE=function(d,h){return d=d>>>0,h||P(d,4,this.length),this[d]<<24|this[d+1]<<16|this[d+2]<<8|this[d+3]},c.prototype.readBigInt64LE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=this[d+4]+this[d+5]*2**8+this[d+6]*2**16+(b<<24);return(BigInt(B)<<BigInt(32))+BigInt(h+this[++d]*2**8+this[++d]*2**16+this[++d]*2**24)}),c.prototype.readBigInt64BE=te(function(d){d=d>>>0,J(d,"offset");const h=this[d],b=this[d+7];(h===void 0||b===void 0)&&fe(d,this.length-8);const B=(h<<24)+this[++d]*2**16+this[++d]*2**8+this[++d];return(BigInt(B)<<BigInt(32))+BigInt(this[++d]*2**24+this[++d]*2**16+this[++d]*2**8+b)}),c.prototype.readFloatLE=function(d,h){return d=d>>>0,h||P(d,4,this.length),n.read(this,d,!0,23,4)},c.prototype.readFloatBE=function(d,h){return d=d>>>0,h||P(d,4,this.length),n.read(this,d,!1,23,4)},c.prototype.readDoubleLE=function(d,h){return d=d>>>0,h||P(d,8,this.length),n.read(this,d,!0,52,8)},c.prototype.readDoubleBE=function(d,h){return d=d>>>0,h||P(d,8,this.length),n.read(this,d,!1,52,8)};function $(k,d,h,b,B,C){if(!c.isBuffer(k))throw new TypeError('"buffer" argument must be a Buffer instance');if(d>B||d<C)throw new RangeError('"value" argument is out of bounds');if(h+b>k.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(d,h,b,B){if(d=+d,h=h>>>0,b=b>>>0,!B){const D=Math.pow(2,8*b)-1;$(this,d,h,b,D,0)}let C=1,j=0;for(this[h]=d&255;++j<b&&(C*=256);)this[h+j]=d/C&255;return h+b},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(d,h,b,B){if(d=+d,h=h>>>0,b=b>>>0,!B){const D=Math.pow(2,8*b)-1;$(this,d,h,b,D,0)}let C=b-1,j=1;for(this[h+C]=d&255;--C>=0&&(j*=256);)this[h+C]=d/j&255;return h+b},c.prototype.writeUint8=c.prototype.writeUInt8=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,1,255,0),this[h]=d&255,h+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,65535,0),this[h]=d&255,this[h+1]=d>>>8,h+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,65535,0),this[h]=d>>>8,this[h+1]=d&255,h+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,4294967295,0),this[h+3]=d>>>24,this[h+2]=d>>>16,this[h+1]=d>>>8,this[h]=d&255,h+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,4294967295,0),this[h]=d>>>24,this[h+1]=d>>>16,this[h+2]=d>>>8,this[h+3]=d&255,h+4};function G(k,d,h,b,B){pe(d,b,B,k,h,7);let C=Number(d&BigInt(4294967295));k[h++]=C,C=C>>8,k[h++]=C,C=C>>8,k[h++]=C,C=C>>8,k[h++]=C;let j=Number(d>>BigInt(32)&BigInt(4294967295));return k[h++]=j,j=j>>8,k[h++]=j,j=j>>8,k[h++]=j,j=j>>8,k[h++]=j,h}function X(k,d,h,b,B){pe(d,b,B,k,h,7);let C=Number(d&BigInt(4294967295));k[h+7]=C,C=C>>8,k[h+6]=C,C=C>>8,k[h+5]=C,C=C>>8,k[h+4]=C;let j=Number(d>>BigInt(32)&BigInt(4294967295));return k[h+3]=j,j=j>>8,k[h+2]=j,j=j>>8,k[h+1]=j,j=j>>8,k[h]=j,h+8}c.prototype.writeBigUInt64LE=te(function(d,h=0){return G(this,d,h,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=te(function(d,h=0){return X(this,d,h,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(d,h,b,B){if(d=+d,h=h>>>0,!B){const re=Math.pow(2,8*b-1);$(this,d,h,b,re-1,-re)}let C=0,j=1,D=0;for(this[h]=d&255;++C<b&&(j*=256);)d<0&&D===0&&this[h+C-1]!==0&&(D=1),this[h+C]=(d/j>>0)-D&255;return h+b},c.prototype.writeIntBE=function(d,h,b,B){if(d=+d,h=h>>>0,!B){const re=Math.pow(2,8*b-1);$(this,d,h,b,re-1,-re)}let C=b-1,j=1,D=0;for(this[h+C]=d&255;--C>=0&&(j*=256);)d<0&&D===0&&this[h+C+1]!==0&&(D=1),this[h+C]=(d/j>>0)-D&255;return h+b},c.prototype.writeInt8=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,1,127,-128),d<0&&(d=255+d+1),this[h]=d&255,h+1},c.prototype.writeInt16LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,32767,-32768),this[h]=d&255,this[h+1]=d>>>8,h+2},c.prototype.writeInt16BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,2,32767,-32768),this[h]=d>>>8,this[h+1]=d&255,h+2},c.prototype.writeInt32LE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,2147483647,-2147483648),this[h]=d&255,this[h+1]=d>>>8,this[h+2]=d>>>16,this[h+3]=d>>>24,h+4},c.prototype.writeInt32BE=function(d,h,b){return d=+d,h=h>>>0,b||$(this,d,h,4,2147483647,-2147483648),d<0&&(d=4294967295+d+1),this[h]=d>>>24,this[h+1]=d>>>16,this[h+2]=d>>>8,this[h+3]=d&255,h+4},c.prototype.writeBigInt64LE=te(function(d,h=0){return G(this,d,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=te(function(d,h=0){return X(this,d,h,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Y(k,d,h,b,B,C){if(h+b>k.length)throw new RangeError("Index out of range");if(h<0)throw new RangeError("Index out of range")}function oe(k,d,h,b,B){return d=+d,h=h>>>0,B||Y(k,d,h,4),n.write(k,d,h,b,23,4),h+4}c.prototype.writeFloatLE=function(d,h,b){return oe(this,d,h,!0,b)},c.prototype.writeFloatBE=function(d,h,b){return oe(this,d,h,!1,b)};function ae(k,d,h,b,B){return d=+d,h=h>>>0,B||Y(k,d,h,8),n.write(k,d,h,b,52,8),h+8}c.prototype.writeDoubleLE=function(d,h,b){return ae(this,d,h,!0,b)},c.prototype.writeDoubleBE=function(d,h,b){return ae(this,d,h,!1,b)},c.prototype.copy=function(d,h,b,B){if(!c.isBuffer(d))throw new TypeError("argument should be a Buffer");if(b||(b=0),!B&&B!==0&&(B=this.length),h>=d.length&&(h=d.length),h||(h=0),B>0&&B<b&&(B=b),B===b||d.length===0||this.length===0)return 0;if(h<0)throw new RangeError("targetStart out of bounds");if(b<0||b>=this.length)throw new RangeError("Index out of range");if(B<0)throw new RangeError("sourceEnd out of bounds");B>this.length&&(B=this.length),d.length-h<B-b&&(B=d.length-h+b);const C=B-b;return this===d&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(h,b,B):Uint8Array.prototype.set.call(d,this.subarray(b,B),h),C},c.prototype.fill=function(d,h,b,B){if(typeof d=="string"){if(typeof h=="string"?(B=h,h=0,b=this.length):typeof b=="string"&&(B=b,b=this.length),B!==void 0&&typeof B!="string")throw new TypeError("encoding must be a string");if(typeof B=="string"&&!c.isEncoding(B))throw new TypeError("Unknown encoding: "+B);if(d.length===1){const j=d.charCodeAt(0);(B==="utf8"&&j<128||B==="latin1")&&(d=j)}}else typeof d=="number"?d=d&255:typeof d=="boolean"&&(d=Number(d));if(h<0||this.length<h||this.length<b)throw new RangeError("Out of range index");if(b<=h)return this;h=h>>>0,b=b===void 0?this.length:b>>>0,d||(d=0);let C;if(typeof d=="number")for(C=h;C<b;++C)this[C]=d;else{const j=c.isBuffer(d)?d:c.from(d,B),D=j.length;if(D===0)throw new TypeError('The value "'+d+'" is invalid for argument "value"');for(C=0;C<b-h;++C)this[C+h]=j[C%D]}return this};const ee={};function Z(k,d,h){ee[k]=class extends h{constructor(){super(),Object.defineProperty(this,"message",{value:d.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${k}]`,this.stack,delete this.name}get code(){return k}set code(B){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:B,writable:!0})}toString(){return`${this.name} [${k}]: ${this.message}`}}}Z("ERR_BUFFER_OUT_OF_BOUNDS",function(k){return k?`${k} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Z("ERR_INVALID_ARG_TYPE",function(k,d){return`The "${k}" argument must be of type number. Received type ${typeof d}`},TypeError),Z("ERR_OUT_OF_RANGE",function(k,d,h){let b=`The value of "${k}" is out of range.`,B=h;return Number.isInteger(h)&&Math.abs(h)>2**32?B=ce(String(h)):typeof h=="bigint"&&(B=String(h),(h>BigInt(2)**BigInt(32)||h<-(BigInt(2)**BigInt(32)))&&(B=ce(B)),B+="n"),b+=` It must be ${d}. Received ${B}`,b},RangeError);function ce(k){let d="",h=k.length;const b=k[0]==="-"?1:0;for(;h>=b+4;h-=3)d=`_${k.slice(h-3,h)}${d}`;return`${k.slice(0,h)}${d}`}function ge(k,d,h){J(d,"offset"),(k[d]===void 0||k[d+h]===void 0)&&fe(d,k.length-(h+1))}function pe(k,d,h,b,B,C){if(k>h||k<d){const j=typeof d=="bigint"?"n":"";let D;throw d===0||d===BigInt(0)?D=`>= 0${j} and < 2${j} ** ${(C+1)*8}${j}`:D=`>= -(2${j} ** ${(C+1)*8-1}${j}) and < 2 ** ${(C+1)*8-1}${j}`,new ee.ERR_OUT_OF_RANGE("value",D,k)}ge(b,B,C)}function J(k,d){if(typeof k!="number")throw new ee.ERR_INVALID_ARG_TYPE(d,"number",k)}function fe(k,d,h){throw Math.floor(k)!==k?(J(k,h),new ee.ERR_OUT_OF_RANGE("offset","an integer",k)):d<0?new ee.ERR_BUFFER_OUT_OF_BOUNDS:new ee.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${d}`,k)}const Se=/[^+/0-9A-Za-z-_]/g;function Ce(k){if(k=k.split("=")[0],k=k.trim().replace(Se,""),k.length<2)return"";for(;k.length%4!==0;)k=k+"=";return k}function Ze(k,d){d=d||1/0;let h;const b=k.length;let B=null;const C=[];for(let j=0;j<b;++j){if(h=k.charCodeAt(j),h>55295&&h<57344){if(!B){if(h>56319){(d-=3)>-1&&C.push(239,191,189);continue}else if(j+1===b){(d-=3)>-1&&C.push(239,191,189);continue}B=h;continue}if(h<56320){(d-=3)>-1&&C.push(239,191,189),B=h;continue}h=(B-55296<<10|h-56320)+65536}else B&&(d-=3)>-1&&C.push(239,191,189);if(B=null,h<128){if((d-=1)<0)break;C.push(h)}else if(h<2048){if((d-=2)<0)break;C.push(h>>6|192,h&63|128)}else if(h<65536){if((d-=3)<0)break;C.push(h>>12|224,h>>6&63|128,h&63|128)}else if(h<1114112){if((d-=4)<0)break;C.push(h>>18|240,h>>12&63|128,h>>6&63|128,h&63|128)}else throw new Error("Invalid code point")}return C}function st(k){const d=[];for(let h=0;h<k.length;++h)d.push(k.charCodeAt(h)&255);return d}function St(k,d){let h,b,B;const C=[];for(let j=0;j<k.length&&!((d-=2)<0);++j)h=k.charCodeAt(j),b=h>>8,B=h%256,C.push(B),C.push(b);return C}function Ae(k){return t.toByteArray(Ce(k))}function ln(k,d,h,b){let B;for(B=0;B<b&&!(B+h>=d.length||B>=k.length);++B)d[B+h]=k[B];return B}function et(k,d){return k instanceof d||k!=null&&k.constructor!=null&&k.constructor.name!=null&&k.constructor.name===d.name}function Ne(k){return k!==k}const se=(function(){const k="0123456789abcdef",d=new Array(256);for(let h=0;h<16;++h){const b=h*16;for(let B=0;B<16;++B)d[b+B]=k[h]+k[B]}return d})();function te(k){return typeof BigInt>"u"?ne:k}function ne(){throw new Error("BigInt not supported")}})(uu)),uu}var xw=Vo(),fu={exports:{}},uh;function Aw(){if(uh)return fu.exports;uh=1;var e=fu.exports={},t,n;function r(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?t=setTimeout:t=r}catch{t=r}try{typeof clearTimeout=="function"?n=clearTimeout:n=i}catch{n=i}})();function s(w){if(t===setTimeout)return setTimeout(w,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(w,0);try{return t(w,0)}catch{try{return t.call(null,w,0)}catch{return t.call(this,w,0)}}}function o(w){if(n===clearTimeout)return clearTimeout(w);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(w);try{return n(w)}catch{try{return n.call(null,w)}catch{return n.call(this,w)}}}var c=[],a=!1,u,f=-1;function l(){!a||!u||(a=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!a){var w=s(l);a=!0;for(var E=c.length;E;){for(u=c,c=[];++f<E;)u&&u[f].run();f=-1,E=c.length}u=null,a=!1,o(w)}}e.nextTick=function(w){var E=new Array(arguments.length-1);if(arguments.length>1)for(var _=1;_<arguments.length;_++)E[_-1]=arguments[_];c.push(new y(w,E)),c.length===1&&!a&&s(p)};function y(w,E){this.fun=w,this.array=E}y.prototype.run=function(){this.fun.apply(null,this.array)},e.title="browser",e.browser=!0,e.env={},e.argv=[],e.version="",e.versions={};function g(){}return e.on=g,e.addListener=g,e.once=g,e.off=g,e.removeListener=g,e.removeAllListeners=g,e.emit=g,e.prependListener=g,e.prependOnceListener=g,e.listeners=function(w){return[]},e.binding=function(w){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(w){throw new Error("process.chdir is not supported")},e.umask=function(){return 0},fu.exports}var vw=Aw();const Bw=$p(vw);typeof globalThis>"u"&&(globalThis.global=globalThis);typeof globalThis.Buffer>"u"&&(globalThis.Buffer=xw.Buffer);typeof globalThis.process>"u"&&(globalThis.process=Bw);var tt={},lu={},Le={},Rt={},hu={},Ms={},fh;function Iw(){return fh||(fh=1,Object.defineProperty(Ms,"__esModule",{value:!0}),Ms.crypto=void 0,Ms.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0),Ms}var lh;function ni(){return lh||(lh=1,(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=n,e.anumber=r,e.abytes=i,e.ahash=s,e.aexists=o,e.aoutput=c,e.u8=a,e.u32=u,e.clean=f,e.createView=l,e.rotr=p,e.rotl=y,e.byteSwap=g,e.byteSwap32=w,e.bytesToHex=S,e.hexToBytes=I,e.asyncLoop=U,e.utf8ToBytes=M,e.bytesToUtf8=v,e.toBytes=R,e.kdfInputToBytes=V,e.concatBytes=W,e.checkOpts=H,e.createHasher=N,e.createOptHasher=L,e.createXOFer=F,e.randomBytes=x;const t=Iw();function n(O){return O instanceof Uint8Array||ArrayBuffer.isView(O)&&O.constructor.name==="Uint8Array"}function r(O){if(!Number.isSafeInteger(O)||O<0)throw new Error("positive integer expected, got "+O)}function i(O,...q){if(!n(O))throw new Error("Uint8Array expected");if(q.length>0&&!q.includes(O.length))throw new Error("Uint8Array expected of length "+q+", got length="+O.length)}function s(O){if(typeof O!="function"||typeof O.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");r(O.outputLen),r(O.blockLen)}function o(O,q=!0){if(O.destroyed)throw new Error("Hash instance has been destroyed");if(q&&O.finished)throw new Error("Hash#digest() has already been called")}function c(O,q){i(O);const P=q.outputLen;if(O.length<P)throw new Error("digestInto() expects output buffer of length at least "+P)}function a(O){return new Uint8Array(O.buffer,O.byteOffset,O.byteLength)}function u(O){return new Uint32Array(O.buffer,O.byteOffset,Math.floor(O.byteLength/4))}function f(...O){for(let q=0;q<O.length;q++)O[q].fill(0)}function l(O){return new DataView(O.buffer,O.byteOffset,O.byteLength)}function p(O,q){return O<<32-q|O>>>q}function y(O,q){return O<<q|O>>>32-q>>>0}e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function g(O){return O<<24&4278190080|O<<8&16711680|O>>>8&65280|O>>>24&255}e.swap8IfBE=e.isLE?O=>O:O=>g(O),e.byteSwapIfBE=e.swap8IfBE;function w(O){for(let q=0;q<O.length;q++)O[q]=g(O[q]);return O}e.swap32IfBE=e.isLE?O=>O:w;const E=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_=Array.from({length:256},(O,q)=>q.toString(16).padStart(2,"0"));function S(O){if(i(O),E)return O.toHex();let q="";for(let P=0;P<O.length;P++)q+=_[O[P]];return q}const m={_0:48,_9:57,A:65,F:70,a:97,f:102};function T(O){if(O>=m._0&&O<=m._9)return O-m._0;if(O>=m.A&&O<=m.F)return O-(m.A-10);if(O>=m.a&&O<=m.f)return O-(m.a-10)}function I(O){if(typeof O!="string")throw new Error("hex string expected, got "+typeof O);if(E)return Uint8Array.fromHex(O);const q=O.length,P=q/2;if(q%2)throw new Error("hex string expected, got unpadded hex of length "+q);const $=new Uint8Array(P);for(let G=0,X=0;G<P;G++,X+=2){const Y=T(O.charCodeAt(X)),oe=T(O.charCodeAt(X+1));if(Y===void 0||oe===void 0){const ae=O[X]+O[X+1];throw new Error('hex string expected, got non-hex character "'+ae+'" at index '+X)}$[G]=Y*16+oe}return $}const A=async()=>{};e.nextTick=A;async function U(O,q,P){let $=Date.now();for(let G=0;G<O;G++){P(G);const X=Date.now()-$;X>=0&&X<q||(await(0,e.nextTick)(),$+=X)}}function M(O){if(typeof O!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(O))}function v(O){return new TextDecoder().decode(O)}function R(O){return typeof O=="string"&&(O=M(O)),i(O),O}function V(O){return typeof O=="string"&&(O=M(O)),i(O),O}function W(...O){let q=0;for(let $=0;$<O.length;$++){const G=O[$];i(G),q+=G.length}const P=new Uint8Array(q);for(let $=0,G=0;$<O.length;$++){const X=O[$];P.set(X,G),G+=X.length}return P}function H(O,q){if(q!==void 0&&{}.toString.call(q)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(O,q)}class K{}e.Hash=K;function N(O){const q=$=>O().update(R($)).digest(),P=O();return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=()=>O(),q}function L(O){const q=($,G)=>O(G).update(R($)).digest(),P=O({});return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=$=>O($),q}function F(O){const q=($,G)=>O(G).update(R($)).digest(),P=O({});return q.outputLen=P.outputLen,q.blockLen=P.blockLen,q.create=$=>O($),q}e.wrapConstructor=N,e.wrapConstructorWithOpts=L,e.wrapXOFConstructorWithOpts=F;function x(O=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(O));if(t.crypto&&typeof t.crypto.randomBytes=="function")return Uint8Array.from(t.crypto.randomBytes(O));throw new Error("crypto.getRandomValues must be defined")}})(hu)),hu}var hh;function Kp(){if(hh)return Rt;hh=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.SHA512_IV=Rt.SHA384_IV=Rt.SHA224_IV=Rt.SHA256_IV=Rt.HashMD=void 0,Rt.setBigUint64=t,Rt.Chi=n,Rt.Maj=r;const e=ni();function t(s,o,c,a){if(typeof s.setBigUint64=="function")return s.setBigUint64(o,c,a);const u=BigInt(32),f=BigInt(4294967295),l=Number(c>>u&f),p=Number(c&f),y=a?4:0,g=a?0:4;s.setUint32(o+y,l,a),s.setUint32(o+g,p,a)}function n(s,o,c){return s&o^~s&c}function r(s,o,c){return s&o^s&c^o&c}class i extends e.Hash{constructor(o,c,a,u){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=o,this.outputLen=c,this.padOffset=a,this.isLE=u,this.buffer=new Uint8Array(o),this.view=(0,e.createView)(this.buffer)}update(o){(0,e.aexists)(this),o=(0,e.toBytes)(o),(0,e.abytes)(o);const{view:c,buffer:a,blockLen:u}=this,f=o.length;for(let l=0;l<f;){const p=Math.min(u-this.pos,f-l);if(p===u){const y=(0,e.createView)(o);for(;u<=f-l;l+=u)this.process(y,l);continue}a.set(o.subarray(l,l+p),this.pos),this.pos+=p,l+=p,this.pos===u&&(this.process(c,0),this.pos=0)}return this.length+=o.length,this.roundClean(),this}digestInto(o){(0,e.aexists)(this),(0,e.aoutput)(o,this),this.finished=!0;const{buffer:c,view:a,blockLen:u,isLE:f}=this;let{pos:l}=this;c[l++]=128,(0,e.clean)(this.buffer.subarray(l)),this.padOffset>u-l&&(this.process(a,0),l=0);for(let E=l;E<u;E++)c[E]=0;t(a,u-8,BigInt(this.length*8),f),this.process(a,0);const p=(0,e.createView)(o),y=this.outputLen;if(y%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const g=y/4,w=this.get();if(g>w.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<g;E++)p.setUint32(4*E,w[E],f)}digest(){const{buffer:o,outputLen:c}=this;this.digestInto(o);const a=o.slice(0,c);return this.destroy(),a}_cloneInto(o){o||(o=new this.constructor),o.set(...this.get());const{blockLen:c,buffer:a,length:u,finished:f,destroyed:l,pos:p}=this;return o.destroyed=l,o.finished=f,o.length=u,o.pos=p,u%c&&o.buffer.set(a),o}clone(){return this._cloneInto()}}return Rt.HashMD=i,Rt.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Rt.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Rt.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Rt.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Rt}var xe={},dh;function Ow(){if(dh)return xe;dh=1,Object.defineProperty(xe,"__esModule",{value:!0}),xe.toBig=xe.shrSL=xe.shrSH=xe.rotrSL=xe.rotrSH=xe.rotrBL=xe.rotrBH=xe.rotr32L=xe.rotr32H=xe.rotlSL=xe.rotlSH=xe.rotlBL=xe.rotlBH=xe.add5L=xe.add5H=xe.add4L=xe.add4H=xe.add3L=xe.add3H=void 0,xe.add=_,xe.fromBig=n,xe.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(v,R=!1){return R?{h:Number(v&e),l:Number(v>>t&e)}:{h:Number(v>>t&e)|0,l:Number(v&e)|0}}function r(v,R=!1){const V=v.length;let W=new Uint32Array(V),H=new Uint32Array(V);for(let K=0;K<V;K++){const{h:N,l:L}=n(v[K],R);[W[K],H[K]]=[N,L]}return[W,H]}const i=(v,R)=>BigInt(v>>>0)<<t|BigInt(R>>>0);xe.toBig=i;const s=(v,R,V)=>v>>>V;xe.shrSH=s;const o=(v,R,V)=>v<<32-V|R>>>V;xe.shrSL=o;const c=(v,R,V)=>v>>>V|R<<32-V;xe.rotrSH=c;const a=(v,R,V)=>v<<32-V|R>>>V;xe.rotrSL=a;const u=(v,R,V)=>v<<64-V|R>>>V-32;xe.rotrBH=u;const f=(v,R,V)=>v>>>V-32|R<<64-V;xe.rotrBL=f;const l=(v,R)=>R;xe.rotr32H=l;const p=(v,R)=>v;xe.rotr32L=p;const y=(v,R,V)=>v<<V|R>>>32-V;xe.rotlSH=y;const g=(v,R,V)=>R<<V|v>>>32-V;xe.rotlSL=g;const w=(v,R,V)=>R<<V-32|v>>>64-V;xe.rotlBH=w;const E=(v,R,V)=>v<<V-32|R>>>64-V;xe.rotlBL=E;function _(v,R,V,W){const H=(R>>>0)+(W>>>0);return{h:v+V+(H/2**32|0)|0,l:H|0}}const S=(v,R,V)=>(v>>>0)+(R>>>0)+(V>>>0);xe.add3L=S;const m=(v,R,V,W)=>R+V+W+(v/2**32|0)|0;xe.add3H=m;const T=(v,R,V,W)=>(v>>>0)+(R>>>0)+(V>>>0)+(W>>>0);xe.add4L=T;const I=(v,R,V,W,H)=>R+V+W+H+(v/2**32|0)|0;xe.add4H=I;const A=(v,R,V,W,H)=>(v>>>0)+(R>>>0)+(V>>>0)+(W>>>0)+(H>>>0);xe.add5L=A;const U=(v,R,V,W,H,K)=>R+V+W+H+K+(v/2**32|0)|0;xe.add5H=U;const M={fromBig:n,split:r,toBig:i,shrSH:s,shrSL:o,rotrSH:c,rotrSL:a,rotrBH:u,rotrBL:f,rotr32H:l,rotr32L:p,rotlSH:y,rotlSL:g,rotlBH:w,rotlBL:E,add:_,add3L:S,add3H:m,add4L:T,add4H:I,add5H:U,add5L:A};return xe.default=M,xe}var ph;function Lp(){if(ph)return Le;ph=1,Object.defineProperty(Le,"__esModule",{value:!0}),Le.sha512_224=Le.sha512_256=Le.sha384=Le.sha512=Le.sha224=Le.sha256=Le.SHA512_256=Le.SHA512_224=Le.SHA384=Le.SHA512=Le.SHA224=Le.SHA256=void 0;const e=Kp(),t=Ow(),n=ni(),r=Uint32Array.from([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]),i=new Uint32Array(64);class s extends e.HashMD{constructor(m=32){super(64,m,8,!1),this.A=e.SHA256_IV[0]|0,this.B=e.SHA256_IV[1]|0,this.C=e.SHA256_IV[2]|0,this.D=e.SHA256_IV[3]|0,this.E=e.SHA256_IV[4]|0,this.F=e.SHA256_IV[5]|0,this.G=e.SHA256_IV[6]|0,this.H=e.SHA256_IV[7]|0}get(){const{A:m,B:T,C:I,D:A,E:U,F:M,G:v,H:R}=this;return[m,T,I,A,U,M,v,R]}set(m,T,I,A,U,M,v,R){this.A=m|0,this.B=T|0,this.C=I|0,this.D=A|0,this.E=U|0,this.F=M|0,this.G=v|0,this.H=R|0}process(m,T){for(let H=0;H<16;H++,T+=4)i[H]=m.getUint32(T,!1);for(let H=16;H<64;H++){const K=i[H-15],N=i[H-2],L=(0,n.rotr)(K,7)^(0,n.rotr)(K,18)^K>>>3,F=(0,n.rotr)(N,17)^(0,n.rotr)(N,19)^N>>>10;i[H]=F+i[H-7]+L+i[H-16]|0}let{A:I,B:A,C:U,D:M,E:v,F:R,G:V,H:W}=this;for(let H=0;H<64;H++){const K=(0,n.rotr)(v,6)^(0,n.rotr)(v,11)^(0,n.rotr)(v,25),N=W+K+(0,e.Chi)(v,R,V)+r[H]+i[H]|0,F=((0,n.rotr)(I,2)^(0,n.rotr)(I,13)^(0,n.rotr)(I,22))+(0,e.Maj)(I,A,U)|0;W=V,V=R,R=v,v=M+N|0,M=U,U=A,A=I,I=N+F|0}I=I+this.A|0,A=A+this.B|0,U=U+this.C|0,M=M+this.D|0,v=v+this.E|0,R=R+this.F|0,V=V+this.G|0,W=W+this.H|0,this.set(I,A,U,M,v,R,V,W)}roundClean(){(0,n.clean)(i)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}Le.SHA256=s;class o extends s{constructor(){super(28),this.A=e.SHA224_IV[0]|0,this.B=e.SHA224_IV[1]|0,this.C=e.SHA224_IV[2]|0,this.D=e.SHA224_IV[3]|0,this.E=e.SHA224_IV[4]|0,this.F=e.SHA224_IV[5]|0,this.G=e.SHA224_IV[6]|0,this.H=e.SHA224_IV[7]|0}}Le.SHA224=o;const c=t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(S=>BigInt(S))),a=c[0],u=c[1],f=new Uint32Array(80),l=new Uint32Array(80);class p extends e.HashMD{constructor(m=64){super(128,m,16,!1),this.Ah=e.SHA512_IV[0]|0,this.Al=e.SHA512_IV[1]|0,this.Bh=e.SHA512_IV[2]|0,this.Bl=e.SHA512_IV[3]|0,this.Ch=e.SHA512_IV[4]|0,this.Cl=e.SHA512_IV[5]|0,this.Dh=e.SHA512_IV[6]|0,this.Dl=e.SHA512_IV[7]|0,this.Eh=e.SHA512_IV[8]|0,this.El=e.SHA512_IV[9]|0,this.Fh=e.SHA512_IV[10]|0,this.Fl=e.SHA512_IV[11]|0,this.Gh=e.SHA512_IV[12]|0,this.Gl=e.SHA512_IV[13]|0,this.Hh=e.SHA512_IV[14]|0,this.Hl=e.SHA512_IV[15]|0}get(){const{Ah:m,Al:T,Bh:I,Bl:A,Ch:U,Cl:M,Dh:v,Dl:R,Eh:V,El:W,Fh:H,Fl:K,Gh:N,Gl:L,Hh:F,Hl:x}=this;return[m,T,I,A,U,M,v,R,V,W,H,K,N,L,F,x]}set(m,T,I,A,U,M,v,R,V,W,H,K,N,L,F,x){this.Ah=m|0,this.Al=T|0,this.Bh=I|0,this.Bl=A|0,this.Ch=U|0,this.Cl=M|0,this.Dh=v|0,this.Dl=R|0,this.Eh=V|0,this.El=W|0,this.Fh=H|0,this.Fl=K|0,this.Gh=N|0,this.Gl=L|0,this.Hh=F|0,this.Hl=x|0}process(m,T){for(let P=0;P<16;P++,T+=4)f[P]=m.getUint32(T),l[P]=m.getUint32(T+=4);for(let P=16;P<80;P++){const $=f[P-15]|0,G=l[P-15]|0,X=t.rotrSH($,G,1)^t.rotrSH($,G,8)^t.shrSH($,G,7),Y=t.rotrSL($,G,1)^t.rotrSL($,G,8)^t.shrSL($,G,7),oe=f[P-2]|0,ae=l[P-2]|0,ee=t.rotrSH(oe,ae,19)^t.rotrBH(oe,ae,61)^t.shrSH(oe,ae,6),Z=t.rotrSL(oe,ae,19)^t.rotrBL(oe,ae,61)^t.shrSL(oe,ae,6),ce=t.add4L(Y,Z,l[P-7],l[P-16]),ge=t.add4H(ce,X,ee,f[P-7],f[P-16]);f[P]=ge|0,l[P]=ce|0}let{Ah:I,Al:A,Bh:U,Bl:M,Ch:v,Cl:R,Dh:V,Dl:W,Eh:H,El:K,Fh:N,Fl:L,Gh:F,Gl:x,Hh:O,Hl:q}=this;for(let P=0;P<80;P++){const $=t.rotrSH(H,K,14)^t.rotrSH(H,K,18)^t.rotrBH(H,K,41),G=t.rotrSL(H,K,14)^t.rotrSL(H,K,18)^t.rotrBL(H,K,41),X=H&N^~H&F,Y=K&L^~K&x,oe=t.add5L(q,G,Y,u[P],l[P]),ae=t.add5H(oe,O,$,X,a[P],f[P]),ee=oe|0,Z=t.rotrSH(I,A,28)^t.rotrBH(I,A,34)^t.rotrBH(I,A,39),ce=t.rotrSL(I,A,28)^t.rotrBL(I,A,34)^t.rotrBL(I,A,39),ge=I&U^I&v^U&v,pe=A&M^A&R^M&R;O=F|0,q=x|0,F=N|0,x=L|0,N=H|0,L=K|0,{h:H,l:K}=t.add(V|0,W|0,ae|0,ee|0),V=v|0,W=R|0,v=U|0,R=M|0,U=I|0,M=A|0;const J=t.add3L(ee,ce,pe);I=t.add3H(J,ae,Z,ge),A=J|0}({h:I,l:A}=t.add(this.Ah|0,this.Al|0,I|0,A|0)),{h:U,l:M}=t.add(this.Bh|0,this.Bl|0,U|0,M|0),{h:v,l:R}=t.add(this.Ch|0,this.Cl|0,v|0,R|0),{h:V,l:W}=t.add(this.Dh|0,this.Dl|0,V|0,W|0),{h:H,l:K}=t.add(this.Eh|0,this.El|0,H|0,K|0),{h:N,l:L}=t.add(this.Fh|0,this.Fl|0,N|0,L|0),{h:F,l:x}=t.add(this.Gh|0,this.Gl|0,F|0,x|0),{h:O,l:q}=t.add(this.Hh|0,this.Hl|0,O|0,q|0),this.set(I,A,U,M,v,R,V,W,H,K,N,L,F,x,O,q)}roundClean(){(0,n.clean)(f,l)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}Le.SHA512=p;class y extends p{constructor(){super(48),this.Ah=e.SHA384_IV[0]|0,this.Al=e.SHA384_IV[1]|0,this.Bh=e.SHA384_IV[2]|0,this.Bl=e.SHA384_IV[3]|0,this.Ch=e.SHA384_IV[4]|0,this.Cl=e.SHA384_IV[5]|0,this.Dh=e.SHA384_IV[6]|0,this.Dl=e.SHA384_IV[7]|0,this.Eh=e.SHA384_IV[8]|0,this.El=e.SHA384_IV[9]|0,this.Fh=e.SHA384_IV[10]|0,this.Fl=e.SHA384_IV[11]|0,this.Gh=e.SHA384_IV[12]|0,this.Gl=e.SHA384_IV[13]|0,this.Hh=e.SHA384_IV[14]|0,this.Hl=e.SHA384_IV[15]|0}}Le.SHA384=y;const g=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),w=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class E extends p{constructor(){super(28),this.Ah=g[0]|0,this.Al=g[1]|0,this.Bh=g[2]|0,this.Bl=g[3]|0,this.Ch=g[4]|0,this.Cl=g[5]|0,this.Dh=g[6]|0,this.Dl=g[7]|0,this.Eh=g[8]|0,this.El=g[9]|0,this.Fh=g[10]|0,this.Fl=g[11]|0,this.Gh=g[12]|0,this.Gl=g[13]|0,this.Hh=g[14]|0,this.Hl=g[15]|0}}Le.SHA512_224=E;class _ extends p{constructor(){super(32),this.Ah=w[0]|0,this.Al=w[1]|0,this.Bh=w[2]|0,this.Bl=w[3]|0,this.Ch=w[4]|0,this.Cl=w[5]|0,this.Dh=w[6]|0,this.Dl=w[7]|0,this.Eh=w[8]|0,this.El=w[9]|0,this.Fh=w[10]|0,this.Fl=w[11]|0,this.Gh=w[12]|0,this.Gl=w[13]|0,this.Hh=w[14]|0,this.Hl=w[15]|0}}return Le.SHA512_256=_,Le.sha256=(0,n.createHasher)(()=>new s),Le.sha224=(0,n.createHasher)(()=>new o),Le.sha512=(0,n.createHasher)(()=>new p),Le.sha384=(0,n.createHasher)(()=>new y),Le.sha512_256=(0,n.createHasher)(()=>new _),Le.sha512_224=(0,n.createHasher)(()=>new E),Le}var qs={},du={},pu={},yh;function Pw(){return yh||(yh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const t=ni();class n extends t.Hash{constructor(s,o){super(),this.finished=!1,this.destroyed=!1,(0,t.ahash)(s);const c=(0,t.toBytes)(o);if(this.iHash=s.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const a=this.blockLen,u=new Uint8Array(a);u.set(c.length>a?s.create().update(c).digest():c);for(let f=0;f<u.length;f++)u[f]^=54;this.iHash.update(u),this.oHash=s.create();for(let f=0;f<u.length;f++)u[f]^=106;this.oHash.update(u),(0,t.clean)(u)}update(s){return(0,t.aexists)(this),this.iHash.update(s),this}digestInto(s){(0,t.aexists)(this),(0,t.abytes)(s,this.outputLen),this.finished=!0,this.iHash.digestInto(s),this.oHash.update(s),this.oHash.digestInto(s),this.destroy()}digest(){const s=new Uint8Array(this.oHash.outputLen);return this.digestInto(s),s}_cloneInto(s){s||(s=Object.create(Object.getPrototypeOf(this),{}));const{oHash:o,iHash:c,finished:a,destroyed:u,blockLen:f,outputLen:l}=this;return s=s,s.finished=a,s.destroyed=u,s.blockLen=f,s.outputLen=l,s.oHash=o._cloneInto(s.oHash),s.iHash=c._cloneInto(s.iHash),s}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=n;const r=(i,s,o)=>new n(i,s).update(o).digest();e.hmac=r,e.hmac.create=(i,s)=>new n(i,s)})(pu)),pu}var yu={},gh;function Bs(){return gh||(gh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.notImplemented=e.bitMask=e.utf8ToBytes=e.randomBytes=e.isBytes=e.hexToBytes=e.concatBytes=e.bytesToUtf8=e.bytesToHex=e.anumber=e.abytes=void 0,e.abool=s,e._abool2=o,e._abytes2=c,e.numberToHexUnpadded=a,e.hexToNumber=u,e.bytesToNumberBE=f,e.bytesToNumberLE=l,e.numberToBytesBE=p,e.numberToBytesLE=y,e.numberToVarBytesBE=g,e.ensureBytes=w,e.equalBytes=E,e.copyBytes=_,e.asciiToBytes=S,e.inRange=T,e.aInRange=I,e.bitLen=A,e.bitGet=U,e.bitSet=M,e.createHmacDrbg=R,e.validateObject=W,e.isHash=H,e._validateObject=K,e.memoized=L;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=ni();var n=ni();Object.defineProperty(e,"abytes",{enumerable:!0,get:function(){return n.abytes}}),Object.defineProperty(e,"anumber",{enumerable:!0,get:function(){return n.anumber}}),Object.defineProperty(e,"bytesToHex",{enumerable:!0,get:function(){return n.bytesToHex}}),Object.defineProperty(e,"bytesToUtf8",{enumerable:!0,get:function(){return n.bytesToUtf8}}),Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return n.concatBytes}}),Object.defineProperty(e,"hexToBytes",{enumerable:!0,get:function(){return n.hexToBytes}}),Object.defineProperty(e,"isBytes",{enumerable:!0,get:function(){return n.isBytes}}),Object.defineProperty(e,"randomBytes",{enumerable:!0,get:function(){return n.randomBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return n.utf8ToBytes}});const r=BigInt(0),i=BigInt(1);function s(F,x){if(typeof x!="boolean")throw new Error(F+" boolean expected, got "+x)}function o(F,x=""){if(typeof F!="boolean"){const O=x&&`"${x}"`;throw new Error(O+"expected boolean, got type="+typeof F)}return F}function c(F,x,O=""){const q=(0,t.isBytes)(F),P=F?.length,$=x!==void 0;if(!q||$&&P!==x){const G=O&&`"${O}" `,X=$?` of length ${x}`:"",Y=q?`length=${P}`:`type=${typeof F}`;throw new Error(G+"expected Uint8Array"+X+", got "+Y)}return F}function a(F){const x=F.toString(16);return x.length&1?"0"+x:x}function u(F){if(typeof F!="string")throw new Error("hex string expected, got "+typeof F);return F===""?r:BigInt("0x"+F)}function f(F){return u((0,t.bytesToHex)(F))}function l(F){return(0,t.abytes)(F),u((0,t.bytesToHex)(Uint8Array.from(F).reverse()))}function p(F,x){return(0,t.hexToBytes)(F.toString(16).padStart(x*2,"0"))}function y(F,x){return p(F,x).reverse()}function g(F){return(0,t.hexToBytes)(a(F))}function w(F,x,O){let q;if(typeof x=="string")try{q=(0,t.hexToBytes)(x)}catch($){throw new Error(F+" must be hex string or Uint8Array, cause: "+$)}else if((0,t.isBytes)(x))q=Uint8Array.from(x);else throw new Error(F+" must be hex string or Uint8Array");const P=q.length;if(typeof O=="number"&&P!==O)throw new Error(F+" of length "+O+" expected, got "+P);return q}function E(F,x){if(F.length!==x.length)return!1;let O=0;for(let q=0;q<F.length;q++)O|=F[q]^x[q];return O===0}function _(F){return Uint8Array.from(F)}function S(F){return Uint8Array.from(F,(x,O)=>{const q=x.charCodeAt(0);if(x.length!==1||q>127)throw new Error(`string contains non-ASCII character "${F[O]}" with code ${q} at position ${O}`);return q})}const m=F=>typeof F=="bigint"&&r<=F;function T(F,x,O){return m(F)&&m(x)&&m(O)&&x<=F&&F<O}function I(F,x,O,q){if(!T(x,O,q))throw new Error("expected valid "+F+": "+O+" <= n < "+q+", got "+x)}function A(F){let x;for(x=0;F>r;F>>=i,x+=1);return x}function U(F,x){return F>>BigInt(x)&i}function M(F,x,O){return F|(O?i:r)<<BigInt(x)}const v=F=>(i<<BigInt(F))-i;e.bitMask=v;function R(F,x,O){if(typeof F!="number"||F<2)throw new Error("hashLen must be a number");if(typeof x!="number"||x<2)throw new Error("qByteLen must be a number");if(typeof O!="function")throw new Error("hmacFn must be a function");const q=ce=>new Uint8Array(ce),P=ce=>Uint8Array.of(ce);let $=q(F),G=q(F),X=0;const Y=()=>{$.fill(1),G.fill(0),X=0},oe=(...ce)=>O(G,$,...ce),ae=(ce=q(0))=>{G=oe(P(0),ce),$=oe(),ce.length!==0&&(G=oe(P(1),ce),$=oe())},ee=()=>{if(X++>=1e3)throw new Error("drbg: tried 1000 values");let ce=0;const ge=[];for(;ce<x;){$=oe();const pe=$.slice();ge.push(pe),ce+=$.length}return(0,t.concatBytes)(...ge)};return(ce,ge)=>{Y(),ae(ce);let pe;for(;!(pe=ge(ee()));)ae();return Y(),pe}}const V={bigint:F=>typeof F=="bigint",function:F=>typeof F=="function",boolean:F=>typeof F=="boolean",string:F=>typeof F=="string",stringOrUint8Array:F=>typeof F=="string"||(0,t.isBytes)(F),isSafeInteger:F=>Number.isSafeInteger(F),array:F=>Array.isArray(F),field:(F,x)=>x.Fp.isValid(F),hash:F=>typeof F=="function"&&Number.isSafeInteger(F.outputLen)};function W(F,x,O={}){const q=(P,$,G)=>{const X=V[$];if(typeof X!="function")throw new Error("invalid validator function");const Y=F[P];if(!(G&&Y===void 0)&&!X(Y,F))throw new Error("param "+String(P)+" is invalid. Expected "+$+", got "+Y)};for(const[P,$]of Object.entries(x))q(P,$,!1);for(const[P,$]of Object.entries(O))q(P,$,!0);return F}function H(F){return typeof F=="function"&&Number.isSafeInteger(F.outputLen)}function K(F,x,O={}){if(!F||typeof F!="object")throw new Error("expected valid options object");function q(P,$,G){const X=F[P];if(G&&X===void 0)return;const Y=typeof X;if(Y!==$||X===null)throw new Error(`param "${P}" is invalid: expected ${$}, got ${Y}`)}Object.entries(x).forEach(([P,$])=>q(P,$,!1)),Object.entries(O).forEach(([P,$])=>q(P,$,!0))}const N=()=>{throw new Error("not implemented")};e.notImplemented=N;function L(F){const x=new WeakMap;return(O,...q)=>{const P=x.get(O);if(P!==void 0)return P;const $=F(O,...q);return x.set(O,$),$}}})(yu)),yu}var gn={},Xe={},wh;function $o(){if(wh)return Xe;wh=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.isNegativeLE=void 0,Xe.mod=l,Xe.pow=p,Xe.pow2=y,Xe.invert=g,Xe.tonelliShanks=m,Xe.FpSqrt=T,Xe.validateField=U,Xe.FpPow=M,Xe.FpInvertBatch=v,Xe.FpDiv=R,Xe.FpLegendre=V,Xe.FpIsSquare=W,Xe.nLength=H,Xe.Field=K,Xe.FpSqrtOdd=N,Xe.FpSqrtEven=L,Xe.hashToPrivateScalar=F,Xe.getFieldBytesLength=x,Xe.getMinHashLength=O,Xe.mapHashToField=q;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=Bs(),t=BigInt(0),n=BigInt(1),r=BigInt(2),i=BigInt(3),s=BigInt(4),o=BigInt(5),c=BigInt(7),a=BigInt(8),u=BigInt(9),f=BigInt(16);function l(P,$){const G=P%$;return G>=t?G:$+G}function p(P,$,G){return M(K(G),P,$)}function y(P,$,G){let X=P;for(;$-- >t;)X*=X,X%=G;return X}function g(P,$){if(P===t)throw new Error("invert: expected non-zero number");if($<=t)throw new Error("invert: expected positive modulus, got "+$);let G=l(P,$),X=$,Y=t,oe=n;for(;G!==t;){const ee=X/G,Z=X%G,ce=Y-oe*ee;X=G,G=Z,Y=oe,oe=ce}if(X!==n)throw new Error("invert: does not exist");return l(Y,$)}function w(P,$,G){if(!P.eql(P.sqr($),G))throw new Error("Cannot find square root")}function E(P,$){const G=(P.ORDER+n)/s,X=P.pow($,G);return w(P,X,$),X}function _(P,$){const G=(P.ORDER-o)/a,X=P.mul($,r),Y=P.pow(X,G),oe=P.mul($,Y),ae=P.mul(P.mul(oe,r),Y),ee=P.mul(oe,P.sub(ae,P.ONE));return w(P,ee,$),ee}function S(P){const $=K(P),G=m(P),X=G($,$.neg($.ONE)),Y=G($,X),oe=G($,$.neg(X)),ae=(P+c)/f;return(ee,Z)=>{let ce=ee.pow(Z,ae),ge=ee.mul(ce,X);const pe=ee.mul(ce,Y),J=ee.mul(ce,oe),fe=ee.eql(ee.sqr(ge),Z),Se=ee.eql(ee.sqr(pe),Z);ce=ee.cmov(ce,ge,fe),ge=ee.cmov(J,pe,Se);const Ce=ee.eql(ee.sqr(ge),Z),Ze=ee.cmov(ce,ge,Ce);return w(ee,Ze,Z),Ze}}function m(P){if(P<i)throw new Error("sqrt is not defined for small field");let $=P-n,G=0;for(;$%r===t;)$/=r,G++;let X=r;const Y=K(P);for(;V(Y,X)===1;)if(X++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(G===1)return E;let oe=Y.pow(X,$);const ae=($+n)/r;return function(Z,ce){if(Z.is0(ce))return ce;if(V(Z,ce)!==1)throw new Error("Cannot find square root");let ge=G,pe=Z.mul(Z.ONE,oe),J=Z.pow(ce,$),fe=Z.pow(ce,ae);for(;!Z.eql(J,Z.ONE);){if(Z.is0(J))return Z.ZERO;let Se=1,Ce=Z.sqr(J);for(;!Z.eql(Ce,Z.ONE);)if(Se++,Ce=Z.sqr(Ce),Se===ge)throw new Error("Cannot find square root");const Ze=n<<BigInt(ge-Se-1),st=Z.pow(pe,Ze);ge=Se,pe=Z.sqr(st),J=Z.mul(J,pe),fe=Z.mul(fe,st)}return fe}}function T(P){return P%s===i?E:P%a===o?_:P%f===u?S(P):m(P)}const I=(P,$)=>(l(P,$)&n)===n;Xe.isNegativeLE=I;const A=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function U(P){const $={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=A.reduce((X,Y)=>(X[Y]="function",X),$);return(0,e._validateObject)(P,G),P}function M(P,$,G){if(G<t)throw new Error("invalid exponent, negatives unsupported");if(G===t)return P.ONE;if(G===n)return $;let X=P.ONE,Y=$;for(;G>t;)G&n&&(X=P.mul(X,Y)),Y=P.sqr(Y),G>>=n;return X}function v(P,$,G=!1){const X=new Array($.length).fill(G?P.ZERO:void 0),Y=$.reduce((ae,ee,Z)=>P.is0(ee)?ae:(X[Z]=ae,P.mul(ae,ee)),P.ONE),oe=P.inv(Y);return $.reduceRight((ae,ee,Z)=>P.is0(ee)?ae:(X[Z]=P.mul(ae,X[Z]),P.mul(ae,ee)),oe),X}function R(P,$,G){return P.mul($,typeof G=="bigint"?g(G,P.ORDER):P.inv(G))}function V(P,$){const G=(P.ORDER-n)/r,X=P.pow($,G),Y=P.eql(X,P.ONE),oe=P.eql(X,P.ZERO),ae=P.eql(X,P.neg(P.ONE));if(!Y&&!oe&&!ae)throw new Error("invalid Legendre symbol result");return Y?1:oe?0:-1}function W(P,$){return V(P,$)===1}function H(P,$){$!==void 0&&(0,e.anumber)($);const G=$!==void 0?$:P.toString(2).length,X=Math.ceil(G/8);return{nBitLength:G,nByteLength:X}}function K(P,$,G=!1,X={}){if(P<=t)throw new Error("invalid field: expected ORDER > 0, got "+P);let Y,oe,ae=!1,ee;if(typeof $=="object"&&$!=null){if(X.sqrt||G)throw new Error("cannot specify opts in two arguments");const J=$;J.BITS&&(Y=J.BITS),J.sqrt&&(oe=J.sqrt),typeof J.isLE=="boolean"&&(G=J.isLE),typeof J.modFromBytes=="boolean"&&(ae=J.modFromBytes),ee=J.allowedLengths}else typeof $=="number"&&(Y=$),X.sqrt&&(oe=X.sqrt);const{nBitLength:Z,nByteLength:ce}=H(P,Y);if(ce>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let ge;const pe=Object.freeze({ORDER:P,isLE:G,BITS:Z,BYTES:ce,MASK:(0,e.bitMask)(Z),ZERO:t,ONE:n,allowedLengths:ee,create:J=>l(J,P),isValid:J=>{if(typeof J!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof J);return t<=J&&J<P},is0:J=>J===t,isValidNot0:J=>!pe.is0(J)&&pe.isValid(J),isOdd:J=>(J&n)===n,neg:J=>l(-J,P),eql:(J,fe)=>J===fe,sqr:J=>l(J*J,P),add:(J,fe)=>l(J+fe,P),sub:(J,fe)=>l(J-fe,P),mul:(J,fe)=>l(J*fe,P),pow:(J,fe)=>M(pe,J,fe),div:(J,fe)=>l(J*g(fe,P),P),sqrN:J=>J*J,addN:(J,fe)=>J+fe,subN:(J,fe)=>J-fe,mulN:(J,fe)=>J*fe,inv:J=>g(J,P),sqrt:oe||(J=>(ge||(ge=T(P)),ge(pe,J))),toBytes:J=>G?(0,e.numberToBytesLE)(J,ce):(0,e.numberToBytesBE)(J,ce),fromBytes:(J,fe=!0)=>{if(ee){if(!ee.includes(J.length)||J.length>ce)throw new Error("Field.fromBytes: expected "+ee+" bytes, got "+J.length);const Ce=new Uint8Array(ce);Ce.set(J,G?0:Ce.length-J.length),J=Ce}if(J.length!==ce)throw new Error("Field.fromBytes: expected "+ce+" bytes, got "+J.length);let Se=G?(0,e.bytesToNumberLE)(J):(0,e.bytesToNumberBE)(J);if(ae&&(Se=l(Se,P)),!fe&&!pe.isValid(Se))throw new Error("invalid field element: outside of range 0..ORDER");return Se},invertBatch:J=>v(pe,J),cmov:(J,fe,Se)=>Se?fe:J});return Object.freeze(pe)}function N(P,$){if(!P.isOdd)throw new Error("Field doesn't have isOdd");const G=P.sqrt($);return P.isOdd(G)?G:P.neg(G)}function L(P,$){if(!P.isOdd)throw new Error("Field doesn't have isOdd");const G=P.sqrt($);return P.isOdd(G)?P.neg(G):G}function F(P,$,G=!1){P=(0,e.ensureBytes)("privateHash",P);const X=P.length,Y=H($).nByteLength+8;if(Y<24||X<Y||X>1024)throw new Error("hashToPrivateScalar: expected "+Y+"-1024 bytes of input, got "+X);const oe=G?(0,e.bytesToNumberLE)(P):(0,e.bytesToNumberBE)(P);return l(oe,$-n)+n}function x(P){if(typeof P!="bigint")throw new Error("field order must be bigint");const $=P.toString(2).length;return Math.ceil($/8)}function O(P){const $=x(P);return $+Math.ceil($/2)}function q(P,$,G=!1){const X=P.length,Y=x($),oe=O($);if(X<16||X<oe||X>1024)throw new Error("expected "+oe+"-1024 bytes of input, got "+X);const ae=G?(0,e.bytesToNumberLE)(P):(0,e.bytesToNumberBE)(P),ee=l(ae,$-n)+n;return G?(0,e.numberToBytesLE)(ee,Y):(0,e.numberToBytesBE)(ee,Y)}return Xe}var mh;function kw(){if(mh)return gn;mh=1,Object.defineProperty(gn,"__esModule",{value:!0}),gn.wNAF=void 0,gn.negateCt=i,gn.normalizeZ=s,gn.mulEndoUnsafe=E,gn.pippenger=_,gn.precomputeMSMUnsafe=S,gn.validateBasic=m,gn._createCurveFields=I;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=Bs(),t=$o(),n=BigInt(0),r=BigInt(1);function i(A,U){const M=U.negate();return A?M:U}function s(A,U){const M=(0,t.FpInvertBatch)(A.Fp,U.map(v=>v.Z));return U.map((v,R)=>A.fromAffine(v.toAffine(M[R])))}function o(A,U){if(!Number.isSafeInteger(A)||A<=0||A>U)throw new Error("invalid window size, expected [1.."+U+"], got W="+A)}function c(A,U){o(A,U);const M=Math.ceil(U/A)+1,v=2**(A-1),R=2**A,V=(0,e.bitMask)(A),W=BigInt(A);return{windows:M,windowSize:v,mask:V,maxNumber:R,shiftBy:W}}function a(A,U,M){const{windowSize:v,mask:R,maxNumber:V,shiftBy:W}=M;let H=Number(A&R),K=A>>W;H>v&&(H-=V,K+=r);const N=U*v,L=N+Math.abs(H)-1,F=H===0,x=H<0,O=U%2!==0;return{nextN:K,offset:L,isZero:F,isNeg:x,isNegF:O,offsetF:N}}function u(A,U){if(!Array.isArray(A))throw new Error("array expected");A.forEach((M,v)=>{if(!(M instanceof U))throw new Error("invalid point at index "+v)})}function f(A,U){if(!Array.isArray(A))throw new Error("array of scalars expected");A.forEach((M,v)=>{if(!U.isValid(M))throw new Error("invalid scalar at index "+v)})}const l=new WeakMap,p=new WeakMap;function y(A){return p.get(A)||1}function g(A){if(A!==n)throw new Error("invalid wNAF")}class w{constructor(U,M){this.BASE=U.BASE,this.ZERO=U.ZERO,this.Fn=U.Fn,this.bits=M}_unsafeLadder(U,M,v=this.ZERO){let R=U;for(;M>n;)M&r&&(v=v.add(R)),R=R.double(),M>>=r;return v}precomputeWindow(U,M){const{windows:v,windowSize:R}=c(M,this.bits),V=[];let W=U,H=W;for(let K=0;K<v;K++){H=W,V.push(H);for(let N=1;N<R;N++)H=H.add(W),V.push(H);W=H.double()}return V}wNAF(U,M,v){if(!this.Fn.isValid(v))throw new Error("invalid scalar");let R=this.ZERO,V=this.BASE;const W=c(U,this.bits);for(let H=0;H<W.windows;H++){const{nextN:K,offset:N,isZero:L,isNeg:F,isNegF:x,offsetF:O}=a(v,H,W);v=K,L?V=V.add(i(x,M[O])):R=R.add(i(F,M[N]))}return g(v),{p:R,f:V}}wNAFUnsafe(U,M,v,R=this.ZERO){const V=c(U,this.bits);for(let W=0;W<V.windows&&v!==n;W++){const{nextN:H,offset:K,isZero:N,isNeg:L}=a(v,W,V);if(v=H,!N){const F=M[K];R=R.add(L?F.negate():F)}}return g(v),R}getPrecomputes(U,M,v){let R=l.get(M);return R||(R=this.precomputeWindow(M,U),U!==1&&(typeof v=="function"&&(R=v(R)),l.set(M,R))),R}cached(U,M,v){const R=y(U);return this.wNAF(R,this.getPrecomputes(R,U,v),M)}unsafe(U,M,v,R){const V=y(U);return V===1?this._unsafeLadder(U,M,R):this.wNAFUnsafe(V,this.getPrecomputes(V,U,v),M,R)}createCache(U,M){o(M,this.bits),p.set(U,M),l.delete(U)}hasCache(U){return y(U)!==1}}gn.wNAF=w;function E(A,U,M,v){let R=U,V=A.ZERO,W=A.ZERO;for(;M>n||v>n;)M&r&&(V=V.add(R)),v&r&&(W=W.add(R)),R=R.double(),M>>=r,v>>=r;return{p1:V,p2:W}}function _(A,U,M,v){u(M,A),f(v,U);const R=M.length,V=v.length;if(R!==V)throw new Error("arrays of points and scalars must have equal length");const W=A.ZERO,H=(0,e.bitLen)(BigInt(R));let K=1;H>12?K=H-3:H>4?K=H-2:H>0&&(K=2);const N=(0,e.bitMask)(K),L=new Array(Number(N)+1).fill(W),F=Math.floor((U.BITS-1)/K)*K;let x=W;for(let O=F;O>=0;O-=K){L.fill(W);for(let P=0;P<V;P++){const $=v[P],G=Number($>>BigInt(O)&N);L[G]=L[G].add(M[P])}let q=W;for(let P=L.length-1,$=W;P>0;P--)$=$.add(L[P]),q=q.add($);if(x=x.add(q),O!==0)for(let P=0;P<K;P++)x=x.double()}return x}function S(A,U,M,v){o(v,U.BITS),u(M,A);const R=A.ZERO,V=2**v-1,W=Math.ceil(U.BITS/v),H=(0,e.bitMask)(v),K=M.map(N=>{const L=[];for(let F=0,x=N;F<V;F++)L.push(x),x=x.add(N);return L});return N=>{if(f(N,U),N.length>M.length)throw new Error("array of scalars must be smaller than array of points");let L=R;for(let F=0;F<W;F++){if(L!==R)for(let O=0;O<v;O++)L=L.double();const x=BigInt(W*v-(F+1)*v);for(let O=0;O<N.length;O++){const q=N[O],P=Number(q>>x&H);P&&(L=L.add(K[O][P-1]))}}return L}}function m(A){return(0,t.validateField)(A.Fp),(0,e.validateObject)(A,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,t.nLength)(A.n,A.nBitLength),...A,p:A.Fp.ORDER})}function T(A,U,M){if(U){if(U.ORDER!==A)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,t.validateField)(U),U}else return(0,t.Field)(A,{isLE:M})}function I(A,U,M={},v){if(v===void 0&&(v=A==="edwards"),!U||typeof U!="object")throw new Error(`expected valid ${A} CURVE object`);for(const K of["p","n","h"]){const N=U[K];if(!(typeof N=="bigint"&&N>n))throw new Error(`CURVE.${K} must be positive bigint`)}const R=T(U.p,M.Fp,v),V=T(U.n,M.Fn,v),H=["Gx","Gy","a",A==="weierstrass"?"b":"d"];for(const K of H)if(!R.isValid(U[K]))throw new Error(`CURVE.${K} must be valid field element of CURVE.Fp`);return U=Object.freeze(Object.assign({},U)),{CURVE:U,Fp:R,Fn:V}}return gn}var bh;function jp(){return bh||(bh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DER=e.DERErr=void 0,e._splitEndoScalar=c,e._normFnElement=E,e.weierstrassN=_,e.SWUFpSqrtRatio=m,e.mapToCurveSimpleSWU=T,e.ecdh=A,e.ecdsa=U,e.weierstrassPoints=M,e._legacyHelperEquat=V,e.weierstrass=K;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Pw(),n=ni(),r=Bs(),i=kw(),s=$o(),o=(N,L)=>(N+(N>=0?L:-L)/y)/L;function c(N,L,F){const[[x,O],[q,P]]=L,$=o(P*N,F),G=o(-O*N,F);let X=N-$*x-G*q,Y=-$*O-G*P;const oe=X<l,ae=Y<l;oe&&(X=-X),ae&&(Y=-Y);const ee=(0,r.bitMask)(Math.ceil((0,r.bitLen)(F)/2))+p;if(X<l||X>=ee||Y<l||Y>=ee)throw new Error("splitScalar (endomorphism): failed, k="+N);return{k1neg:oe,k1:X,k2neg:ae,k2:Y}}function a(N){if(!["compact","recovered","der"].includes(N))throw new Error('Signature format must be "compact", "recovered", or "der"');return N}function u(N,L){const F={};for(let x of Object.keys(L))F[x]=N[x]===void 0?L[x]:N[x];return(0,r._abool2)(F.lowS,"lowS"),(0,r._abool2)(F.prehash,"prehash"),F.format!==void 0&&a(F.format),F}class f extends Error{constructor(L=""){super(L)}}e.DERErr=f,e.DER={Err:f,_tlv:{encode:(N,L)=>{const{Err:F}=e.DER;if(N<0||N>256)throw new F("tlv.encode: wrong tag");if(L.length&1)throw new F("tlv.encode: unpadded data");const x=L.length/2,O=(0,r.numberToHexUnpadded)(x);if(O.length/2&128)throw new F("tlv.encode: long form length too big");const q=x>127?(0,r.numberToHexUnpadded)(O.length/2|128):"";return(0,r.numberToHexUnpadded)(N)+q+O+L},decode(N,L){const{Err:F}=e.DER;let x=0;if(N<0||N>256)throw new F("tlv.encode: wrong tag");if(L.length<2||L[x++]!==N)throw new F("tlv.decode: wrong tlv");const O=L[x++],q=!!(O&128);let P=0;if(!q)P=O;else{const G=O&127;if(!G)throw new F("tlv.decode(long): indefinite length not supported");if(G>4)throw new F("tlv.decode(long): byte length is too big");const X=L.subarray(x,x+G);if(X.length!==G)throw new F("tlv.decode: length bytes not complete");if(X[0]===0)throw new F("tlv.decode(long): zero leftmost byte");for(const Y of X)P=P<<8|Y;if(x+=G,P<128)throw new F("tlv.decode(long): not minimal encoding")}const $=L.subarray(x,x+P);if($.length!==P)throw new F("tlv.decode: wrong value length");return{v:$,l:L.subarray(x+P)}}},_int:{encode(N){const{Err:L}=e.DER;if(N<l)throw new L("integer: negative integers are not allowed");let F=(0,r.numberToHexUnpadded)(N);if(Number.parseInt(F[0],16)&8&&(F="00"+F),F.length&1)throw new L("unexpected DER parsing assertion: unpadded hex");return F},decode(N){const{Err:L}=e.DER;if(N[0]&128)throw new L("invalid signature integer: negative");if(N[0]===0&&!(N[1]&128))throw new L("invalid signature integer: unnecessary leading zero");return(0,r.bytesToNumberBE)(N)}},toSig(N){const{Err:L,_int:F,_tlv:x}=e.DER,O=(0,r.ensureBytes)("signature",N),{v:q,l:P}=x.decode(48,O);if(P.length)throw new L("invalid signature: left bytes after parsing");const{v:$,l:G}=x.decode(2,q),{v:X,l:Y}=x.decode(2,G);if(Y.length)throw new L("invalid signature: left bytes after parsing");return{r:F.decode($),s:F.decode(X)}},hexFromSig(N){const{_tlv:L,_int:F}=e.DER,x=L.encode(2,F.encode(N.r)),O=L.encode(2,F.encode(N.s)),q=x+O;return L.encode(48,q)}};const l=BigInt(0),p=BigInt(1),y=BigInt(2),g=BigInt(3),w=BigInt(4);function E(N,L){const{BYTES:F}=N;let x;if(typeof L=="bigint")x=L;else{let O=(0,r.ensureBytes)("private key",L);try{x=N.fromBytes(O)}catch{throw new Error(`invalid private key: expected ui8a of size ${F}, got ${typeof L}`)}}if(!N.isValidNot0(x))throw new Error("invalid private key: out of range [1..N-1]");return x}function _(N,L={}){const F=(0,i._createCurveFields)("weierstrass",N,L),{Fp:x,Fn:O}=F;let q=F.CURVE;const{h:P,n:$}=q;(0,r._validateObject)(L,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:G}=L;if(G&&(!x.is0(q.a)||typeof G.beta!="bigint"||!Array.isArray(G.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const X=I(x,O);function Y(){if(!x.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function oe(Ne,se,te){const{x:ne,y:k}=se.toAffine(),d=x.toBytes(ne);if((0,r._abool2)(te,"isCompressed"),te){Y();const h=!x.isOdd(k);return(0,r.concatBytes)(S(h),d)}else return(0,r.concatBytes)(Uint8Array.of(4),d,x.toBytes(k))}function ae(Ne){(0,r._abytes2)(Ne,void 0,"Point");const{publicKey:se,publicKeyUncompressed:te}=X,ne=Ne.length,k=Ne[0],d=Ne.subarray(1);if(ne===se&&(k===2||k===3)){const h=x.fromBytes(d);if(!x.isValid(h))throw new Error("bad point: is not on curve, wrong x");const b=ce(h);let B;try{B=x.sqrt(b)}catch(D){const re=D instanceof Error?": "+D.message:"";throw new Error("bad point: is not on curve, sqrt error"+re)}Y();const C=x.isOdd(B);return(k&1)===1!==C&&(B=x.neg(B)),{x:h,y:B}}else if(ne===te&&k===4){const h=x.BYTES,b=x.fromBytes(d.subarray(0,h)),B=x.fromBytes(d.subarray(h,h*2));if(!ge(b,B))throw new Error("bad point: is not on curve");return{x:b,y:B}}else throw new Error(`bad point: got length ${ne}, expected compressed=${se} or uncompressed=${te}`)}const ee=L.toBytes||oe,Z=L.fromBytes||ae;function ce(Ne){const se=x.sqr(Ne),te=x.mul(se,Ne);return x.add(x.add(te,x.mul(Ne,q.a)),q.b)}function ge(Ne,se){const te=x.sqr(se),ne=ce(Ne);return x.eql(te,ne)}if(!ge(q.Gx,q.Gy))throw new Error("bad curve params: generator point");const pe=x.mul(x.pow(q.a,g),w),J=x.mul(x.sqr(q.b),BigInt(27));if(x.is0(x.add(pe,J)))throw new Error("bad curve params: a or b");function fe(Ne,se,te=!1){if(!x.isValid(se)||te&&x.is0(se))throw new Error(`bad point coordinate ${Ne}`);return se}function Se(Ne){if(!(Ne instanceof Ae))throw new Error("ProjectivePoint expected")}function Ce(Ne){if(!G||!G.basises)throw new Error("no endo");return c(Ne,G.basises,O.ORDER)}const Ze=(0,r.memoized)((Ne,se)=>{const{X:te,Y:ne,Z:k}=Ne;if(x.eql(k,x.ONE))return{x:te,y:ne};const d=Ne.is0();se==null&&(se=d?x.ONE:x.inv(k));const h=x.mul(te,se),b=x.mul(ne,se),B=x.mul(k,se);if(d)return{x:x.ZERO,y:x.ZERO};if(!x.eql(B,x.ONE))throw new Error("invZ was invalid");return{x:h,y:b}}),st=(0,r.memoized)(Ne=>{if(Ne.is0()){if(L.allowInfinityPoint&&!x.is0(Ne.Y))return;throw new Error("bad point: ZERO")}const{x:se,y:te}=Ne.toAffine();if(!x.isValid(se)||!x.isValid(te))throw new Error("bad point: x or y not field elements");if(!ge(se,te))throw new Error("bad point: equation left != right");if(!Ne.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function St(Ne,se,te,ne,k){return te=new Ae(x.mul(te.X,Ne),te.Y,te.Z),se=(0,i.negateCt)(ne,se),te=(0,i.negateCt)(k,te),se.add(te)}class Ae{constructor(se,te,ne){this.X=fe("x",se),this.Y=fe("y",te,!0),this.Z=fe("z",ne),Object.freeze(this)}static CURVE(){return q}static fromAffine(se){const{x:te,y:ne}=se||{};if(!se||!x.isValid(te)||!x.isValid(ne))throw new Error("invalid affine point");if(se instanceof Ae)throw new Error("projective point not allowed");return x.is0(te)&&x.is0(ne)?Ae.ZERO:new Ae(te,ne,x.ONE)}static fromBytes(se){const te=Ae.fromAffine(Z((0,r._abytes2)(se,void 0,"point")));return te.assertValidity(),te}static fromHex(se){return Ae.fromBytes((0,r.ensureBytes)("pointHex",se))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(se=8,te=!0){return et.createCache(this,se),te||this.multiply(g),this}assertValidity(){st(this)}hasEvenY(){const{y:se}=this.toAffine();if(!x.isOdd)throw new Error("Field doesn't support isOdd");return!x.isOdd(se)}equals(se){Se(se);const{X:te,Y:ne,Z:k}=this,{X:d,Y:h,Z:b}=se,B=x.eql(x.mul(te,b),x.mul(d,k)),C=x.eql(x.mul(ne,b),x.mul(h,k));return B&&C}negate(){return new Ae(this.X,x.neg(this.Y),this.Z)}double(){const{a:se,b:te}=q,ne=x.mul(te,g),{X:k,Y:d,Z:h}=this;let b=x.ZERO,B=x.ZERO,C=x.ZERO,j=x.mul(k,k),D=x.mul(d,d),re=x.mul(h,h),Q=x.mul(k,d);return Q=x.add(Q,Q),C=x.mul(k,h),C=x.add(C,C),b=x.mul(se,C),B=x.mul(ne,re),B=x.add(b,B),b=x.sub(D,B),B=x.add(D,B),B=x.mul(b,B),b=x.mul(Q,b),C=x.mul(ne,C),re=x.mul(se,re),Q=x.sub(j,re),Q=x.mul(se,Q),Q=x.add(Q,C),C=x.add(j,j),j=x.add(C,j),j=x.add(j,re),j=x.mul(j,Q),B=x.add(B,j),re=x.mul(d,h),re=x.add(re,re),j=x.mul(re,Q),b=x.sub(b,j),C=x.mul(re,D),C=x.add(C,C),C=x.add(C,C),new Ae(b,B,C)}add(se){Se(se);const{X:te,Y:ne,Z:k}=this,{X:d,Y:h,Z:b}=se;let B=x.ZERO,C=x.ZERO,j=x.ZERO;const D=q.a,re=x.mul(q.b,g);let Q=x.mul(te,d),ue=x.mul(ne,h),le=x.mul(k,b),Be=x.add(te,ne),Oe=x.add(d,h);Be=x.mul(Be,Oe),Oe=x.add(Q,ue),Be=x.sub(Be,Oe),Oe=x.add(te,k);let Je=x.add(d,b);return Oe=x.mul(Oe,Je),Je=x.add(Q,le),Oe=x.sub(Oe,Je),Je=x.add(ne,k),B=x.add(h,b),Je=x.mul(Je,B),B=x.add(ue,le),Je=x.sub(Je,B),j=x.mul(D,Oe),B=x.mul(re,le),j=x.add(B,j),B=x.sub(ue,j),j=x.add(ue,j),C=x.mul(B,j),ue=x.add(Q,Q),ue=x.add(ue,Q),le=x.mul(D,le),Oe=x.mul(re,Oe),ue=x.add(ue,le),le=x.sub(Q,le),le=x.mul(D,le),Oe=x.add(Oe,le),Q=x.mul(ue,Oe),C=x.add(C,Q),Q=x.mul(Je,Oe),B=x.mul(Be,B),B=x.sub(B,Q),Q=x.mul(Be,ue),j=x.mul(Je,j),j=x.add(j,Q),new Ae(B,C,j)}subtract(se){return this.add(se.negate())}is0(){return this.equals(Ae.ZERO)}multiply(se){const{endo:te}=L;if(!O.isValidNot0(se))throw new Error("invalid scalar: out of range");let ne,k;const d=h=>et.cached(this,h,b=>(0,i.normalizeZ)(Ae,b));if(te){const{k1neg:h,k1:b,k2neg:B,k2:C}=Ce(se),{p:j,f:D}=d(b),{p:re,f:Q}=d(C);k=D.add(Q),ne=St(te.beta,j,re,h,B)}else{const{p:h,f:b}=d(se);ne=h,k=b}return(0,i.normalizeZ)(Ae,[ne,k])[0]}multiplyUnsafe(se){const{endo:te}=L,ne=this;if(!O.isValid(se))throw new Error("invalid scalar: out of range");if(se===l||ne.is0())return Ae.ZERO;if(se===p)return ne;if(et.hasCache(this))return this.multiply(se);if(te){const{k1neg:k,k1:d,k2neg:h,k2:b}=Ce(se),{p1:B,p2:C}=(0,i.mulEndoUnsafe)(Ae,ne,d,b);return St(te.beta,B,C,k,h)}else return et.unsafe(ne,se)}multiplyAndAddUnsafe(se,te,ne){const k=this.multiplyUnsafe(te).add(se.multiplyUnsafe(ne));return k.is0()?void 0:k}toAffine(se){return Ze(this,se)}isTorsionFree(){const{isTorsionFree:se}=L;return P===p?!0:se?se(Ae,this):et.unsafe(this,$).is0()}clearCofactor(){const{clearCofactor:se}=L;return P===p?this:se?se(Ae,this):this.multiplyUnsafe(P)}isSmallOrder(){return this.multiplyUnsafe(P).is0()}toBytes(se=!0){return(0,r._abool2)(se,"isCompressed"),this.assertValidity(),ee(Ae,this,se)}toHex(se=!0){return(0,r.bytesToHex)(this.toBytes(se))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(se=!0){return this.toBytes(se)}_setWindowSize(se){this.precompute(se)}static normalizeZ(se){return(0,i.normalizeZ)(Ae,se)}static msm(se,te){return(0,i.pippenger)(Ae,O,se,te)}static fromPrivateKey(se){return Ae.BASE.multiply(E(O,se))}}Ae.BASE=new Ae(q.Gx,q.Gy,x.ONE),Ae.ZERO=new Ae(x.ZERO,x.ONE,x.ZERO),Ae.Fp=x,Ae.Fn=O;const ln=O.BITS,et=new i.wNAF(Ae,L.endo?Math.ceil(ln/2):ln);return Ae.BASE.precompute(8),Ae}function S(N){return Uint8Array.of(N?2:3)}function m(N,L){const F=N.ORDER;let x=l;for(let Z=F-p;Z%y===l;Z/=y)x+=p;const O=x,q=y<<O-p-p,P=q*y,$=(F-p)/P,G=($-p)/y,X=P-p,Y=q,oe=N.pow(L,$),ae=N.pow(L,($+p)/y);let ee=(Z,ce)=>{let ge=oe,pe=N.pow(ce,X),J=N.sqr(pe);J=N.mul(J,ce);let fe=N.mul(Z,J);fe=N.pow(fe,G),fe=N.mul(fe,pe),pe=N.mul(fe,ce),J=N.mul(fe,Z);let Se=N.mul(J,pe);fe=N.pow(Se,Y);let Ce=N.eql(fe,N.ONE);pe=N.mul(J,ae),fe=N.mul(Se,ge),J=N.cmov(pe,J,Ce),Se=N.cmov(fe,Se,Ce);for(let Ze=O;Ze>p;Ze--){let st=Ze-y;st=y<<st-p;let St=N.pow(Se,st);const Ae=N.eql(St,N.ONE);pe=N.mul(J,ge),ge=N.mul(ge,ge),St=N.mul(Se,ge),J=N.cmov(pe,J,Ae),Se=N.cmov(St,Se,Ae)}return{isValid:Ce,value:J}};if(N.ORDER%w===g){const Z=(N.ORDER-g)/w,ce=N.sqrt(N.neg(L));ee=(ge,pe)=>{let J=N.sqr(pe);const fe=N.mul(ge,pe);J=N.mul(J,fe);let Se=N.pow(J,Z);Se=N.mul(Se,fe);const Ce=N.mul(Se,ce),Ze=N.mul(N.sqr(Se),pe),st=N.eql(Ze,ge);let St=N.cmov(Ce,Se,st);return{isValid:st,value:St}}}return ee}function T(N,L){(0,s.validateField)(N);const{A:F,B:x,Z:O}=L;if(!N.isValid(F)||!N.isValid(x)||!N.isValid(O))throw new Error("mapToCurveSimpleSWU: invalid opts");const q=m(N,O);if(!N.isOdd)throw new Error("Field does not have .isOdd()");return P=>{let $,G,X,Y,oe,ae,ee,Z;$=N.sqr(P),$=N.mul($,O),G=N.sqr($),G=N.add(G,$),X=N.add(G,N.ONE),X=N.mul(X,x),Y=N.cmov(O,N.neg(G),!N.eql(G,N.ZERO)),Y=N.mul(Y,F),G=N.sqr(X),ae=N.sqr(Y),oe=N.mul(ae,F),G=N.add(G,oe),G=N.mul(G,X),ae=N.mul(ae,Y),oe=N.mul(ae,x),G=N.add(G,oe),ee=N.mul($,X);const{isValid:ce,value:ge}=q(G,ae);Z=N.mul($,P),Z=N.mul(Z,ge),ee=N.cmov(ee,X,ce),Z=N.cmov(Z,ge,ce);const pe=N.isOdd(P)===N.isOdd(Z);Z=N.cmov(N.neg(Z),Z,pe);const J=(0,s.FpInvertBatch)(N,[Y],!0)[0];return ee=N.mul(ee,J),{x:ee,y:Z}}}function I(N,L){return{secretKey:L.BYTES,publicKey:1+N.BYTES,publicKeyUncompressed:1+2*N.BYTES,publicKeyHasPrefix:!0,signature:2*L.BYTES}}function A(N,L={}){const{Fn:F}=N,x=L.randomBytes||r.randomBytes,O=Object.assign(I(N.Fp,F),{seed:(0,s.getMinHashLength)(F.ORDER)});function q(ee){try{return!!E(F,ee)}catch{return!1}}function P(ee,Z){const{publicKey:ce,publicKeyUncompressed:ge}=O;try{const pe=ee.length;return Z===!0&&pe!==ce||Z===!1&&pe!==ge?!1:!!N.fromBytes(ee)}catch{return!1}}function $(ee=x(O.seed)){return(0,s.mapHashToField)((0,r._abytes2)(ee,O.seed,"seed"),F.ORDER)}function G(ee,Z=!0){return N.BASE.multiply(E(F,ee)).toBytes(Z)}function X(ee){const Z=$(ee);return{secretKey:Z,publicKey:G(Z)}}function Y(ee){if(typeof ee=="bigint")return!1;if(ee instanceof N)return!0;const{secretKey:Z,publicKey:ce,publicKeyUncompressed:ge}=O;if(F.allowedLengths||Z===ce)return;const pe=(0,r.ensureBytes)("key",ee).length;return pe===ce||pe===ge}function oe(ee,Z,ce=!0){if(Y(ee)===!0)throw new Error("first arg must be private key");if(Y(Z)===!1)throw new Error("second arg must be public key");const ge=E(F,ee);return N.fromHex(Z).multiply(ge).toBytes(ce)}return Object.freeze({getPublicKey:G,getSharedSecret:oe,keygen:X,Point:N,utils:{isValidSecretKey:q,isValidPublicKey:P,randomSecretKey:$,isValidPrivateKey:q,randomPrivateKey:$,normPrivateKeyToScalar:ee=>E(F,ee),precompute(ee=8,Z=N.BASE){return Z.precompute(ee,!1)}},lengths:O})}function U(N,L,F={}){(0,n.ahash)(L),(0,r._validateObject)(F,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const x=F.randomBytes||r.randomBytes,O=F.hmac||((te,...ne)=>(0,t.hmac)(L,te,(0,r.concatBytes)(...ne))),{Fp:q,Fn:P}=N,{ORDER:$,BITS:G}=P,{keygen:X,getPublicKey:Y,getSharedSecret:oe,utils:ae,lengths:ee}=A(N,F),Z={prehash:!1,lowS:typeof F.lowS=="boolean"?F.lowS:!1,format:void 0,extraEntropy:!1},ce="compact";function ge(te){const ne=$>>p;return te>ne}function pe(te,ne){if(!P.isValidNot0(ne))throw new Error(`invalid signature ${te}: out of range 1..Point.Fn.ORDER`);return ne}function J(te,ne){a(ne);const k=ee.signature,d=ne==="compact"?k:ne==="recovered"?k+1:void 0;return(0,r._abytes2)(te,d,`${ne} signature`)}class fe{constructor(ne,k,d){this.r=pe("r",ne),this.s=pe("s",k),d!=null&&(this.recovery=d),Object.freeze(this)}static fromBytes(ne,k=ce){J(ne,k);let d;if(k==="der"){const{r:C,s:j}=e.DER.toSig((0,r._abytes2)(ne));return new fe(C,j)}k==="recovered"&&(d=ne[0],k="compact",ne=ne.subarray(1));const h=P.BYTES,b=ne.subarray(0,h),B=ne.subarray(h,h*2);return new fe(P.fromBytes(b),P.fromBytes(B),d)}static fromHex(ne,k){return this.fromBytes((0,r.hexToBytes)(ne),k)}addRecoveryBit(ne){return new fe(this.r,this.s,ne)}recoverPublicKey(ne){const k=q.ORDER,{r:d,s:h,recovery:b}=this;if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");if($*y<k&&b>1)throw new Error("recovery id is ambiguous for h>1 curve");const C=b===2||b===3?d+$:d;if(!q.isValid(C))throw new Error("recovery id 2 or 3 invalid");const j=q.toBytes(C),D=N.fromBytes((0,r.concatBytes)(S((b&1)===0),j)),re=P.inv(C),Q=Ce((0,r.ensureBytes)("msgHash",ne)),ue=P.create(-Q*re),le=P.create(h*re),Be=N.BASE.multiplyUnsafe(ue).add(D.multiplyUnsafe(le));if(Be.is0())throw new Error("point at infinify");return Be.assertValidity(),Be}hasHighS(){return ge(this.s)}toBytes(ne=ce){if(a(ne),ne==="der")return(0,r.hexToBytes)(e.DER.hexFromSig(this));const k=P.toBytes(this.r),d=P.toBytes(this.s);if(ne==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,r.concatBytes)(Uint8Array.of(this.recovery),k,d)}return(0,r.concatBytes)(k,d)}toHex(ne){return(0,r.bytesToHex)(this.toBytes(ne))}assertValidity(){}static fromCompact(ne){return fe.fromBytes((0,r.ensureBytes)("sig",ne),"compact")}static fromDER(ne){return fe.fromBytes((0,r.ensureBytes)("sig",ne),"der")}normalizeS(){return this.hasHighS()?new fe(this.r,P.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,r.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,r.bytesToHex)(this.toBytes("compact"))}}const Se=F.bits2int||function(ne){if(ne.length>8192)throw new Error("input is too large");const k=(0,r.bytesToNumberBE)(ne),d=ne.length*8-G;return d>0?k>>BigInt(d):k},Ce=F.bits2int_modN||function(ne){return P.create(Se(ne))},Ze=(0,r.bitMask)(G);function st(te){return(0,r.aInRange)("num < 2^"+G,te,l,Ze),P.toBytes(te)}function St(te,ne){return(0,r._abytes2)(te,void 0,"message"),ne?(0,r._abytes2)(L(te),void 0,"prehashed message"):te}function Ae(te,ne,k){if(["recovered","canonical"].some(ue=>ue in k))throw new Error("sign() legacy options not supported");const{lowS:d,prehash:h,extraEntropy:b}=u(k,Z);te=St(te,h);const B=Ce(te),C=E(P,ne),j=[st(C),st(B)];if(b!=null&&b!==!1){const ue=b===!0?x(ee.secretKey):b;j.push((0,r.ensureBytes)("extraEntropy",ue))}const D=(0,r.concatBytes)(...j),re=B;function Q(ue){const le=Se(ue);if(!P.isValidNot0(le))return;const Be=P.inv(le),Oe=N.BASE.multiply(le).toAffine(),Je=P.create(Oe.x);if(Je===l)return;const Ve=P.create(Be*P.create(re+Je*C));if(Ve===l)return;let $n=(Oe.x===Je?0:2)|Number(Oe.y&p),nh=Ve;return d&&ge(Ve)&&(nh=P.neg(Ve),$n^=1),new fe(Je,nh,$n)}return{seed:D,k2sig:Q}}function ln(te,ne,k={}){te=(0,r.ensureBytes)("message",te);const{seed:d,k2sig:h}=Ae(te,ne,k);return(0,r.createHmacDrbg)(L.outputLen,P.BYTES,O)(d,h)}function et(te){let ne;const k=typeof te=="string"||(0,r.isBytes)(te),d=!k&&te!==null&&typeof te=="object"&&typeof te.r=="bigint"&&typeof te.s=="bigint";if(!k&&!d)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(d)ne=new fe(te.r,te.s);else if(k){try{ne=fe.fromBytes((0,r.ensureBytes)("sig",te),"der")}catch(h){if(!(h instanceof e.DER.Err))throw h}if(!ne)try{ne=fe.fromBytes((0,r.ensureBytes)("sig",te),"compact")}catch{return!1}}return ne||!1}function Ne(te,ne,k,d={}){const{lowS:h,prehash:b,format:B}=u(d,Z);if(k=(0,r.ensureBytes)("publicKey",k),ne=St((0,r.ensureBytes)("message",ne),b),"strict"in d)throw new Error("options.strict was renamed to lowS");const C=B===void 0?et(te):fe.fromBytes((0,r.ensureBytes)("sig",te),B);if(C===!1)return!1;try{const j=N.fromBytes(k);if(h&&C.hasHighS())return!1;const{r:D,s:re}=C,Q=Ce(ne),ue=P.inv(re),le=P.create(Q*ue),Be=P.create(D*ue),Oe=N.BASE.multiplyUnsafe(le).add(j.multiplyUnsafe(Be));return Oe.is0()?!1:P.create(Oe.x)===D}catch{return!1}}function se(te,ne,k={}){const{prehash:d}=u(k,Z);return ne=St(ne,d),fe.fromBytes(te,"recovered").recoverPublicKey(ne).toBytes()}return Object.freeze({keygen:X,getPublicKey:Y,getSharedSecret:oe,utils:ae,lengths:ee,Point:N,sign:ln,verify:Ne,recoverPublicKey:se,Signature:fe,hash:L})}function M(N){const{CURVE:L,curveOpts:F}=v(N),x=_(L,F);return W(N,x)}function v(N){const L={a:N.a,b:N.b,p:N.Fp.ORDER,n:N.n,h:N.h,Gx:N.Gx,Gy:N.Gy},F=N.Fp;let x=N.allowedPrivateKeyLengths?Array.from(new Set(N.allowedPrivateKeyLengths.map(P=>Math.ceil(P/2)))):void 0;const O=(0,s.Field)(L.n,{BITS:N.nBitLength,allowedLengths:x,modFromBytes:N.wrapPrivateKey}),q={Fp:F,Fn:O,allowInfinityPoint:N.allowInfinityPoint,endo:N.endo,isTorsionFree:N.isTorsionFree,clearCofactor:N.clearCofactor,fromBytes:N.fromBytes,toBytes:N.toBytes};return{CURVE:L,curveOpts:q}}function R(N){const{CURVE:L,curveOpts:F}=v(N),x={hmac:N.hmac,randomBytes:N.randomBytes,lowS:N.lowS,bits2int:N.bits2int,bits2int_modN:N.bits2int_modN};return{CURVE:L,curveOpts:F,hash:N.hash,ecdsaOpts:x}}function V(N,L,F){function x(O){const q=N.sqr(O),P=N.mul(q,O);return N.add(N.add(P,N.mul(O,L)),F)}return x}function W(N,L){const{Fp:F,Fn:x}=L;function O(P){return(0,r.inRange)(P,p,x.ORDER)}const q=V(F,N.a,N.b);return Object.assign({},{CURVE:N,Point:L,ProjectivePoint:L,normPrivateKeyToScalar:P=>E(x,P),weierstrassEquation:q,isWithinCurveOrder:O})}function H(N,L){const F=L.Point;return Object.assign({},L,{ProjectivePoint:F,CURVE:Object.assign({},N,(0,s.nLength)(F.Fn.ORDER,F.Fn.BITS))})}function K(N){const{CURVE:L,curveOpts:F,hash:x,ecdsaOpts:O}=R(N),q=_(L,F),P=U(q,x,O);return H(N,P)}})(du)),du}var Eh;function Nw(){if(Eh)return qs;Eh=1,Object.defineProperty(qs,"__esModule",{value:!0}),qs.getHash=t,qs.createCurve=n;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const e=jp();function t(r){return{hash:r}}function n(r,i){const s=o=>(0,e.weierstrass)({...r,hash:o});return{...s(i),create:s}}return qs}var gu={},_h;function Uw(){return _h||(_h=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e._DST_scalar=void 0,e.expand_message_xmd=a,e.expand_message_xof=u,e.hash_to_field=f,e.isogenyMap=l,e.createHasher=p;const t=Bs(),n=$o(),r=t.bytesToNumberBE;function i(y,g){if(o(y),o(g),y<0||y>=1<<8*g)throw new Error("invalid I2OSP input: "+y);const w=Array.from({length:g}).fill(0);for(let E=g-1;E>=0;E--)w[E]=y&255,y>>>=8;return new Uint8Array(w)}function s(y,g){const w=new Uint8Array(y.length);for(let E=0;E<y.length;E++)w[E]=y[E]^g[E];return w}function o(y){if(!Number.isSafeInteger(y))throw new Error("number expected")}function c(y){if(!(0,t.isBytes)(y)&&typeof y!="string")throw new Error("DST must be Uint8Array or string");return typeof y=="string"?(0,t.utf8ToBytes)(y):y}function a(y,g,w,E){(0,t.abytes)(y),o(w),g=c(g),g.length>255&&(g=E((0,t.concatBytes)((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-"),g)));const{outputLen:_,blockLen:S}=E,m=Math.ceil(w/_);if(w>65535||m>255)throw new Error("expand_message_xmd: invalid lenInBytes");const T=(0,t.concatBytes)(g,i(g.length,1)),I=i(0,S),A=i(w,2),U=new Array(m),M=E((0,t.concatBytes)(I,y,A,i(0,1),T));U[0]=E((0,t.concatBytes)(M,i(1,1),T));for(let R=1;R<=m;R++){const V=[s(M,U[R-1]),i(R+1,1),T];U[R]=E((0,t.concatBytes)(...V))}return(0,t.concatBytes)(...U).slice(0,w)}function u(y,g,w,E,_){if((0,t.abytes)(y),o(w),g=c(g),g.length>255){const S=Math.ceil(2*E/8);g=_.create({dkLen:S}).update((0,t.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(g).digest()}if(w>65535||g.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return _.create({dkLen:w}).update(y).update(i(w,2)).update(g).update(i(g.length,1)).digest()}function f(y,g,w){(0,t._validateObject)(w,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:E,k:_,m:S,hash:m,expand:T,DST:I}=w;if(!(0,t.isHash)(w.hash))throw new Error("expected valid hash");(0,t.abytes)(y),o(g);const A=E.toString(2).length,U=Math.ceil((A+_)/8),M=g*S*U;let v;if(T==="xmd")v=a(y,I,M,m);else if(T==="xof")v=u(y,I,M,_,m);else if(T==="_internal_pass")v=y;else throw new Error('expand must be "xmd" or "xof"');const R=new Array(g);for(let V=0;V<g;V++){const W=new Array(S);for(let H=0;H<S;H++){const K=U*(H+V*S),N=v.subarray(K,K+U);W[H]=(0,n.mod)(r(N),E)}R[V]=W}return R}function l(y,g){const w=g.map(E=>Array.from(E).reverse());return(E,_)=>{const[S,m,T,I]=w.map(M=>M.reduce((v,R)=>y.add(y.mul(v,E),R))),[A,U]=(0,n.FpInvertBatch)(y,[m,I],!0);return E=y.mul(S,A),_=y.mul(_,y.mul(T,U)),{x:E,y:_}}}e._DST_scalar=(0,t.utf8ToBytes)("HashToScalar-");function p(y,g,w){if(typeof g!="function")throw new Error("mapToCurve() must be defined");function E(S){return y.fromAffine(g(S))}function _(S){const m=S.clearCofactor();return m.equals(y.ZERO)?y.ZERO:(m.assertValidity(),m)}return{defaults:w,hashToCurve(S,m){const T=Object.assign({},w,m),I=f(S,2,T),A=E(I[0]),U=E(I[1]);return _(A.add(U))},encodeToCurve(S,m){const T=w.encodeDST?{DST:w.encodeDST}:{},I=Object.assign({},w,T,m),A=f(S,1,I),U=E(A[0]);return _(U)},mapToCurve(S){if(!Array.isArray(S))throw new Error("expected array of bigints");for(const m of S)if(typeof m!="bigint")throw new Error("expected array of bigints");return _(E(S))},hashToScalar(S,m){const T=y.Fn.ORDER,I=Object.assign({},w,{p:T,m:1,DST:e._DST_scalar},m);return f(S,1,I)[0][0]}}}})(gu)),gu}var Sh;function Rw(){return Sh||(Sh=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.secp256k1_hasher=e.schnorr=e.secp256k1=void 0;/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const t=Lp(),n=ni(),r=Nw(),i=Uw(),s=$o(),o=jp(),c=Bs(),a={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},f=BigInt(0),l=BigInt(1),p=BigInt(2);function y(H){const K=a.p,N=BigInt(3),L=BigInt(6),F=BigInt(11),x=BigInt(22),O=BigInt(23),q=BigInt(44),P=BigInt(88),$=H*H*H%K,G=$*$*H%K,X=(0,s.pow2)(G,N,K)*G%K,Y=(0,s.pow2)(X,N,K)*G%K,oe=(0,s.pow2)(Y,p,K)*$%K,ae=(0,s.pow2)(oe,F,K)*oe%K,ee=(0,s.pow2)(ae,x,K)*ae%K,Z=(0,s.pow2)(ee,q,K)*ee%K,ce=(0,s.pow2)(Z,P,K)*Z%K,ge=(0,s.pow2)(ce,q,K)*ee%K,pe=(0,s.pow2)(ge,N,K)*G%K,J=(0,s.pow2)(pe,O,K)*ae%K,fe=(0,s.pow2)(J,L,K)*$%K,Se=(0,s.pow2)(fe,p,K);if(!g.eql(g.sqr(Se),H))throw new Error("Cannot find square root");return Se}const g=(0,s.Field)(a.p,{sqrt:y});e.secp256k1=(0,r.createCurve)({...a,Fp:g,lowS:!0,endo:u},t.sha256);const w={};function E(H,...K){let N=w[H];if(N===void 0){const L=(0,t.sha256)((0,c.utf8ToBytes)(H));N=(0,c.concatBytes)(L,L),w[H]=N}return(0,t.sha256)((0,c.concatBytes)(N,...K))}const _=H=>H.toBytes(!0).slice(1),S=e.secp256k1.Point,m=H=>H%p===f;function T(H){const{Fn:K,BASE:N}=S,L=(0,o._normFnElement)(K,H),F=N.multiply(L);return{scalar:m(F.y)?L:K.neg(L),bytes:_(F)}}function I(H){const K=g;if(!K.isValidNot0(H))throw new Error("invalid x: Fail if x ≥ p");const N=K.create(H*H),L=K.create(N*H+BigInt(7));let F=K.sqrt(L);m(F)||(F=K.neg(F));const x=S.fromAffine({x:H,y:F});return x.assertValidity(),x}const A=c.bytesToNumberBE;function U(...H){return S.Fn.create(A(E("BIP0340/challenge",...H)))}function M(H){return T(H).bytes}function v(H,K,N=(0,n.randomBytes)(32)){const{Fn:L}=S,F=(0,c.ensureBytes)("message",H),{bytes:x,scalar:O}=T(K),q=(0,c.ensureBytes)("auxRand",N,32),P=L.toBytes(O^A(E("BIP0340/aux",q))),$=E("BIP0340/nonce",P,x,F),{bytes:G,scalar:X}=T($),Y=U(G,x,F),oe=new Uint8Array(64);if(oe.set(G,0),oe.set(L.toBytes(L.create(X+Y*O)),32),!R(oe,F,x))throw new Error("sign: Invalid signature produced");return oe}function R(H,K,N){const{Fn:L,BASE:F}=S,x=(0,c.ensureBytes)("signature",H,64),O=(0,c.ensureBytes)("message",K),q=(0,c.ensureBytes)("publicKey",N,32);try{const P=I(A(q)),$=A(x.subarray(0,32));if(!(0,c.inRange)($,l,a.p))return!1;const G=A(x.subarray(32,64));if(!(0,c.inRange)(G,l,a.n))return!1;const X=U(L.toBytes($),_(P),O),Y=F.multiplyUnsafe(G).add(P.multiplyUnsafe(L.neg(X))),{x:oe,y:ae}=Y.toAffine();return!(Y.is0()||!m(ae)||oe!==$)}catch{return!1}}e.schnorr=(()=>{const N=(F=(0,n.randomBytes)(48))=>(0,s.mapHashToField)(F,a.n);e.secp256k1.utils.randomSecretKey;function L(F){const x=N(F);return{secretKey:x,publicKey:M(x)}}return{keygen:L,getPublicKey:M,sign:v,verify:R,Point:S,utils:{randomSecretKey:N,randomPrivateKey:N,taggedHash:E,lift_x:I,pointToBytes:_,numberToBytesBE:c.numberToBytesBE,bytesToNumberBE:c.bytesToNumberBE,mod:s.mod},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();const V=(0,i.isogenyMap)(g,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(H=>H.map(K=>BigInt(K)))),W=(0,o.mapToCurveSimpleSWU)(g,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:g.create(BigInt("-11"))});e.secp256k1_hasher=(0,i.createHasher)(e.secp256k1.Point,H=>{const{x:K,y:N}=W(g.create(H[0]));return V(K,N)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:g.ORDER,m:1,k:128,expand:"xmd",hash:t.sha256}),e.hashToCurve=e.secp256k1_hasher.hashToCurve,e.encodeToCurve=e.secp256k1_hasher.encodeToCurve})(lu)),lu}var de={},Th;function Cw(){if(Th)return de;Th=1,Object.defineProperty(de,"__esModule",{value:!0}),de.isHash=de.validateObject=de.memoized=de.notImplemented=de.createHmacDrbg=de.bitMask=de.bitSet=de.bitGet=de.bitLen=de.aInRange=de.inRange=de.asciiToBytes=de.copyBytes=de.equalBytes=de.ensureBytes=de.numberToVarBytesBE=de.numberToBytesLE=de.numberToBytesBE=de.bytesToNumberLE=de.bytesToNumberBE=de.hexToNumber=de.numberToHexUnpadded=de.abool=de.utf8ToBytes=de.randomBytes=de.isBytes=de.hexToBytes=de.concatBytes=de.bytesToUtf8=de.bytesToHex=de.anumber=de.abytes=void 0;const e=Bs();return de.abytes=e.abytes,de.anumber=e.anumber,de.bytesToHex=e.bytesToHex,de.bytesToUtf8=e.bytesToUtf8,de.concatBytes=e.concatBytes,de.hexToBytes=e.hexToBytes,de.isBytes=e.isBytes,de.randomBytes=e.randomBytes,de.utf8ToBytes=e.utf8ToBytes,de.abool=e.abool,de.numberToHexUnpadded=e.numberToHexUnpadded,de.hexToNumber=e.hexToNumber,de.bytesToNumberBE=e.bytesToNumberBE,de.bytesToNumberLE=e.bytesToNumberLE,de.numberToBytesBE=e.numberToBytesBE,de.numberToBytesLE=e.numberToBytesLE,de.numberToVarBytesBE=e.numberToVarBytesBE,de.ensureBytes=e.ensureBytes,de.equalBytes=e.equalBytes,de.copyBytes=e.copyBytes,de.asciiToBytes=e.asciiToBytes,de.inRange=e.inRange,de.aInRange=e.aInRange,de.bitLen=e.bitLen,de.bitGet=e.bitGet,de.bitSet=e.bitSet,de.bitMask=e.bitMask,de.createHmacDrbg=e.createHmacDrbg,de.notImplemented=e.notImplemented,de.memoized=e.memoized,de.validateObject=e.validateObject,de.isHash=e.isHash,de}var xh;function Hw(){if(xh)return tt;xh=1;var e=Rw(),t=$o(),n=Cw();function r(d){var h=Object.create(null);return d&&Object.keys(d).forEach(function(b){if(b!=="default"){var B=Object.getOwnPropertyDescriptor(d,b);Object.defineProperty(h,b,B.get?B:{enumerable:!0,get:function(){return d[b]}})}}),h.default=d,Object.freeze(h)}var i=r(t),s=r(n);const o=e.secp256k1.ProjectivePoint,c="Expected Private",a="Expected Point",u="Expected Tweak",f="Expected Hash",l="Expected Signature",p="Expected Extra Data (32 bytes)",y="Expected Scalar",g="Bad Recovery Id",w=32,E=32,_=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230,175,72,160,59,191,210,94,140,208,54,65,65]),S=32,m=new Uint8Array(32),T=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,69,81,35,25,80,183,95,196,64,45,161,114,47,201,186,238]),I=BigInt(1);function A(d){return d instanceof Uint8Array}function U(d,h){for(let b=0;b<32;++b)if(d[b]!==h[b])return d[b]<h[b]?-1:1;return 0}function M(d){return U(d,m)===0}function v(d){return!(!(d instanceof Uint8Array)||d.length!==E||U(d,_)>=0)}function R(d){return d instanceof Uint8Array&&d.length===64&&U(d.subarray(0,32),_)<0&&U(d.subarray(32,64),_)<0}function V(d){return A(d)&&d.length===64&&U(d.subarray(0,32),T)<0}function W(d){return!(M(d.subarray(0,32))||M(d.subarray(32,64)))}function H(d){return d instanceof Uint8Array&&d.length===w}function K(d){return d===void 0||d instanceof Uint8Array&&d.length===S}function N(d){let h;if(typeof d=="bigint")h=d;else if(typeof d=="number"&&Number.isSafeInteger(d)&&d>=0)h=BigInt(d);else if(typeof d=="string"){if(d.length!==64)throw new Error("Expected 32 bytes of private scalar");h=s.hexToNumber(d)}else if(d instanceof Uint8Array){if(d.length!==32)throw new Error("Expected 32 bytes of private scalar");h=s.bytesToNumberBE(d)}else throw new TypeError("Expected valid private scalar");if(h<0)throw new Error("Expected private scalar >= 0");return h}function L(d){return e.secp256k1.utils.normPrivateKeyToScalar(d)}function F(d,h){const b=L(d),B=N(h),C=s.numberToBytesBE(i.mod(b+B,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(C)?C:null}function x(d,h){const b=L(d),B=N(h),C=s.numberToBytesBE(i.mod(b-B,e.secp256k1.CURVE.n),32);return e.secp256k1.utils.isValidPrivateKey(C)?C:null}function O(d){const h=L(d),b=s.numberToBytesBE(e.secp256k1.CURVE.n-h,32);return e.secp256k1.utils.isValidPrivateKey(b)?b:null}function q(d,h,b){const B=Y(d),C=N(h),j=o.BASE.multiplyAndAddUnsafe(B,C,I);if(!j)throw new Error("Tweaked point at infinity");return j.toRawBytes(b)}function P(d,h,b){const B=Y(d),C=typeof h=="string"?h:s.bytesToHex(h),j=s.hexToNumber(C);return B.multiply(j).toRawBytes(b)}function $(d,h){return d===void 0?h!==void 0?ee(h):!0:!!d}function G(d){try{return d()}catch{return null}}function X(d){return e.schnorr.utils.lift_x(s.bytesToNumberBE(d))}function Y(d){return d.length===32?X(d):o.fromHex(d)}function oe(d,h){if(d.length===32!==h)return!1;try{return h?!!X(d):!!o.fromHex(d)}catch{return!1}}function ae(d){return oe(d,!1)}function ee(d){return oe(d,!1)&&d.length===33}function Z(d){return e.secp256k1.utils.isValidPrivateKey(d)}function ce(d){return oe(d,!0)}function ge(d,h){if(!ce(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>{const b=q(d,h,!0);return{parity:b[0]%2===1?1:0,xOnlyPubkey:b.slice(1)}})}function pe(d){if(!ae(d))throw new Error(a);return d.slice(1,33)}function J(d,h){if(!Z(d))throw new Error(c);return G(()=>e.secp256k1.getPublicKey(d,$(h)))}function fe(d){if(!Z(d))throw new Error(c);return pe(J(d))}function Se(d,h){if(!ae(d))throw new Error(a);return Y(d).toRawBytes($(h,d))}function Ce(d,h,b){if(!ae(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>P(d,h,$(b,d)))}function Ze(d,h,b){if(!ae(d)||!ae(h))throw new Error(a);return G(()=>{const B=Y(d),C=Y(h);return B.equals(C.negate())?null:B.add(C).toRawBytes($(b,d))})}function st(d,h,b){if(!ae(d))throw new Error(a);if(!v(h))throw new Error(u);return G(()=>q(d,h,$(b,d)))}function St(d,h){if(!Z(d))throw new Error(c);if(!v(h))throw new Error(u);return G(()=>F(d,h))}function Ae(d,h){if(!Z(d))throw new Error(c);if(!v(h))throw new Error(u);return G(()=>x(d,h))}function ln(d){if(!Z(d))throw new Error(c);return O(d)}function et(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);return e.secp256k1.sign(d,h,{extraEntropy:b}).toCompactRawBytes()}function Ne(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);const B=e.secp256k1.sign(d,h,{extraEntropy:b});return{signature:B.toCompactRawBytes(),recoveryId:B.recovery}}function se(d,h,b){if(!Z(h))throw new Error(c);if(!H(d))throw new Error(y);if(!K(b))throw new Error(p);return e.schnorr.sign(d,h,b)}function te(d,h,b,B){if(!H(d))throw new Error(f);if(!R(h)||!W(h))throw new Error(l);if(b&2&&!V(h))throw new Error(g);if(!ce(h.subarray(0,32)))throw new Error(l);const j=e.secp256k1.Signature.fromCompact(h).addRecoveryBit(b).recoverPublicKey(d);if(!j)throw new Error(l);return j.toRawBytes($(B))}function ne(d,h,b,B){if(!ae(h))throw new Error(a);if(!R(b))throw new Error(l);if(!H(d))throw new Error(y);return e.secp256k1.verify(b,d,h,{lowS:B})}function k(d,h,b){if(!ce(h))throw new Error(a);if(!R(b))throw new Error(l);if(!H(d))throw new Error(y);return e.schnorr.verify(b,d,h)}return tt.isPoint=ae,tt.isPointCompressed=ee,tt.isPrivate=Z,tt.isXOnlyPoint=ce,tt.pointAdd=Ze,tt.pointAddScalar=st,tt.pointCompress=Se,tt.pointFromScalar=J,tt.pointMultiply=Ce,tt.privateAdd=St,tt.privateNegate=ln,tt.privateSub=Ae,tt.recover=te,tt.sign=et,tt.signRecoverable=Ne,tt.signSchnorr=se,tt.verify=ne,tt.verifySchnorr=k,tt.xOnlyPointAddTweak=ge,tt.xOnlyPointFromPoint=pe,tt.xOnlyPointFromScalar=fe,tt}var Wp=Hw();const Fw=$p(Wp),Mw=_w({__proto__:null,default:Fw},[Wp]),vn={messagePrefix:`Bitcoin Signed Message:
|
|
7
7
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},qw={messagePrefix:`Bitcoin Signed Message:
|
|
8
8
|
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},Gp={messagePrefix:`Bitcoin Signed Message:
|
|
9
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function Vw(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const n=e[5+t];return!(n===0||6+t+n!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||n>1&&e[t+6]===0&&!(e[t+7]&128))}function $w(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const n=e[5+t];if(n===0)throw new Error("S length is zero");if(6+t+n!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(n>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}function Kw(e,t){const n=e.length,r=t.length;if(n===0)throw new Error("R length is zero");if(r===0)throw new Error("S length is zero");if(n>33)throw new Error("R length is too long");if(r>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(n>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(r>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=new Uint8Array(6+n+r);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,i.set(e,4),i[4+n]=2,i[5+n]=t.length,i.set(t,6+n),i}const Ke={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},Dp={};for(const e of Object.keys(Ke)){const t=Ke[e];Dp[t]=e}const jc="0123456789abcdefABCDEF",Wc=jc.split("").map(e=>e.codePointAt(0)),Gc=Array(256).fill(!0).map((e,t)=>{const n=String.fromCodePoint(t),r=jc.indexOf(n);return r<0?void 0:r<16?r:r-6}),Xp=new TextEncoder,zp=new TextDecoder;function Lw(e){return zp.decode(e)}function jw(e){return Xp.encode(e)}function it(e){const t=e.reduce((i,s)=>i+s.length,0),n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.length;return n}function _e(e){const t=e||new Uint8Array;return t.length>512?Gw(t):Ww(t)}function Ww(e){let t="";for(let n=0;n<e.length;++n)t+=jc[Gc[Wc[e[n]>>4]]],t+=jc[Gc[Wc[e[n]&15]]];return t}function Gw(e){const t=new Uint8Array(e.length*2);for(let n=0;n<e.length;++n)t[n*2]=Wc[e[n]>>4],t[n*2+1]=Wc[e[n]&15];return zp.decode(t)}function Tr(e){const t=Xp.encode(e||""),n=new Uint8Array(Math.floor(t.length/2));let r;for(r=0;r<n.length;r++){const i=Gc[t[r*2]],s=Gc[t[r*2+1]];if(i===void 0||s===void 0)break;n[r]=i<<4|s}return r===n.length?n:n.slice(0,r)}function Dw(e){return btoa(String.fromCharCode(...e))}function Yp(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function he(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;++r)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1}function dn(e,t,n){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${n}`);return e[t]=n,t+1}function Xw(e,t,n,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${n}`);return r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255):(e[t]=n>>8&255,e[t+1]=n&255),t+2}function Ko(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${n}`);return r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255),t+4}function zw(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${n}`);return r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn)),t+8}function mr(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");return e[t]}function Yw(e,t,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}else{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}function Bs(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}else{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}function Zp(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>2147483647||n<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${n}`);return r=r.toUpperCase(),r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255),t+4}function Jp(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>0x7fffffffffffffffn||n<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${n}`);return r=r.toUpperCase(),r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn)),t+8}function Zw(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){const r=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0);return e[t+3]<=127?r:r-4294967296}else{const r=(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];return e[t]<=127?r:r-4294967296}}function Qp(e,t,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");n=n.toUpperCase();let r=0n;if(n==="LE")return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),e[t+7]<=127?r:r-0x10000000000000000n;{let i=0n;return i=(i<<8n)+BigInt(e[t]),i=(i<<8n)+BigInt(e[t+1]),i=(i<<8n)+BigInt(e[t+2]),i=(i<<8n)+BigInt(e[t+3]),i=(i<<8n)+BigInt(e[t+4]),i=(i<<8n)+BigInt(e[t+5]),i=(i<<8n)+BigInt(e[t+6]),i=(i<<8n)+BigInt(e[t+7]),e[t]<=127?i:i-0x10000000000000000n}}function ey(e){return e<Ke.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function Jw(e,t,n){const r=ey(t);return r===1?dn(e,n,t):r===2?(dn(e,n,Ke.OP_PUSHDATA1),dn(e,n+1,t)):r===3?(dn(e,n,Ke.OP_PUSHDATA2),Xw(e,n+1,t,"LE")):(dn(e,n,Ke.OP_PUSHDATA4),Ko(e,n+1,t,"LE")),r}function Qw(e,t){const n=mr(e,t);let r,i;if(n<Ke.OP_PUSHDATA1)r=n,i=1;else if(n===Ke.OP_PUSHDATA1){if(t+2>e.length)return null;r=mr(e,t+1),i=2}else if(n===Ke.OP_PUSHDATA2){if(t+3>e.length)return null;r=Yw(e,t+1,"LE"),i=3}else{if(t+5>e.length)return null;if(n!==Ke.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=Bs(e,t+1,"LE"),i=5}return{opcode:n,number:r,size:i}}function em(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function tm(e){let t=Math.abs(e);const n=em(t),r=new Uint8Array(n),i=e<0;for(let s=0;s<n;++s)dn(r,s,t&255),t>>=8;return r[n-1]&128?dn(r,n-1,i?128:0):i&&(r[n-1]|=128),r}var gu;function nm(e){return{lang:e?.lang??gu?.lang,message:e?.message,abortEarly:e?.abortEarly??gu?.abortEarly,abortPipeEarly:e?.abortPipeEarly??gu?.abortPipeEarly}}var rm;function im(e){return rm?.get(e)}var sm;function om(e){return sm?.get(e)}var cm;function am(e,t){return cm?.get(e)?.get(t)}function lo(e){const t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function $t(e,t,n,r,i){const s=i&&"input"in i?i.input:n.value,o=i?.expected??e.expects??null,c=i?.received??lo(s),a={kind:e.kind,type:e.type,input:s,expected:o,received:c,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${c}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},u=e.kind==="schema",f=i?.message??e.message??am(e.reference,a.lang)??(u?om(a.lang):null)??r.message??im(a.lang);f&&(a.message=typeof f=="function"?f(a):f),u&&(n.typed=!1),n.issues?n.issues.push(a):n.issues=[a]}function um(e,t){const n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}var fm=class extends Error{issues;constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ty(e,t){return{kind:"validation",type:"every_item",reference:ty,async:!1,expects:null,requirement:e,message:t,_run(n,r){return n.typed&&!n.value.every(this.requirement)&&$t(this,"item",n,r),n}}}function Yf(e){return{kind:"validation",type:"integer",reference:Yf,async:!1,expects:null,requirement:Number.isInteger,message:e,_run(t,n){return t.typed&&!this.requirement(t.value)&&$t(this,"integer",t,n),t}}}function ny(e,t){return{kind:"validation",type:"length",reference:ny,async:!1,expects:`${e}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value.length!==this.requirement&&$t(this,"length",n,r,{received:`${n.value.length}`}),n}}}function va(e,t){return{kind:"validation",type:"max_value",reference:va,async:!1,expects:`<=${e instanceof Date?e.toJSON():lo(e)}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value>this.requirement&&$t(this,"value",n,r,{received:n.value instanceof Date?n.value.toJSON():lo(n.value)}),n}}}function Ba(e,t){return{kind:"validation",type:"min_value",reference:Ba,async:!1,expects:`>=${e instanceof Date?e.toJSON():lo(e)}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value<this.requirement&&$t(this,"value",n,r,{received:n.value instanceof Date?n.value.toJSON():lo(n.value)}),n}}}function ry(e,t){return{kind:"validation",type:"regex",reference:ry,async:!1,expects:`${e}`,requirement:e,message:t,_run(n,r){return n.typed&&!this.requirement.test(n.value)&&$t(this,"format",n,r),n}}}function Zf(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function Ia(e,t){return!e._run({typed:!1,value:t},{abortEarly:!0}).issues}function iy(){return{kind:"schema",type:"any",reference:iy,expects:"any",async:!1,_run(e){return e.typed=!0,e}}}function cn(e,t){return{kind:"schema",type:"array",reference:cn,expects:"Array",async:!1,item:e,message:t,_run(n,r){const i=n.value;if(Array.isArray(i)){n.typed=!0,n.value=[];for(let s=0;s<i.length;s++){const o=i[s],c=this.item._run({typed:!1,value:o},r);if(c.issues){const a={type:"array",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else $t(this,"type",n,r);return n}}}function sy(e){return{kind:"schema",type:"bigint",reference:sy,expects:"bigint",async:!1,message:e,_run(t,n){return typeof t.value=="bigint"?t.typed=!0:$t(this,"type",t,n),t}}}function Mn(e,t){return{kind:"schema",type:"custom",reference:Mn,expects:"unknown",async:!1,check:e,message:t,_run(n,r){return this.check(n.value)?n.typed=!0:$t(this,"type",n,r),n}}}function Oa(e,t){return{kind:"schema",type:"instance",reference:Oa,expects:e.name,async:!1,class:e,message:t,_run(n,r){return n.value instanceof this.class?n.typed=!0:$t(this,"type",n,r),n}}}function gf(e,...t){const n={kind:"schema",type:"nullable",reference:gf,expects:`(${e.expects} | null)`,async:!1,wrapped:e,_run(r,i){return r.value===null&&("default"in this&&(r.value=Zf(this,r,i)),r.value===null)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function oy(e,...t){const n={kind:"schema",type:"nullish",reference:oy,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,_run(r,i){return(r.value===null||r.value===void 0)&&("default"in this&&(r.value=Zf(this,r,i)),r.value===null||r.value===void 0)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function sn(e){return{kind:"schema",type:"number",reference:sn,expects:"number",async:!1,message:e,_run(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:$t(this,"type",t,n),t}}}function yt(e,t){return{kind:"schema",type:"object",reference:yt,expects:"Object",async:!1,entries:e,message:t,_run(n,r){const i=n.value;if(i&&typeof i=="object"){n.typed=!0,n.value={};for(const s in this.entries){const o=i[s],c=this.entries[s]._run({typed:!1,value:o},r);if(c.issues){const a={type:"object",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),(c.value!==void 0||s in i)&&(n.value[s]=c.value)}}else $t(this,"type",n,r);return n}}}function Dc(e,...t){const n={kind:"schema",type:"optional",reference:Dc,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(r,i){return r.value===void 0&&("default"in this&&(r.value=Zf(this,r,i)),r.value===void 0)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function $i(e){return{kind:"schema",type:"string",reference:$i,expects:"string",async:!1,message:e,_run(t,n){return typeof t.value=="string"?t.typed=!0:$t(this,"type",t,n),t}}}function Gn(e,t){return{kind:"schema",type:"tuple",reference:Gn,expects:"Array",async:!1,items:e,message:t,_run(n,r){const i=n.value;if(Array.isArray(i)){n.typed=!0,n.value=[];for(let s=0;s<this.items.length;s++){const o=i[s],c=this.items[s]._run({typed:!1,value:o},r);if(c.issues){const a={type:"array",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else $t(this,"type",n,r);return n}}}function Ah(e){let t;if(e)for(const n of e)t?t.push(...n.issues):t=n.issues;return t}function Jf(e,t){return{kind:"schema",type:"union",reference:Jf,expects:um(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,_run(n,r){let i,s,o;for(const c of this.options){const a=c._run({typed:!1,value:n.value},r);if(a.typed)if(a.issues)s?s.push(a):s=[a];else{i=a;break}else o?o.push(a):o=[a]}if(i)return i;if(s){if(s.length===1)return s[0];$t(this,"type",n,r,{issues:Ah(s)}),n.typed=!0}else{if(o?.length===1)return o[0];$t(this,"type",n,r,{issues:Ah(o)})}return n}}}function rt(e,t,n){const r=e._run({typed:!1,value:t},nm(n));if(r.issues)throw new fm(r.issues);return r.value}function ri(e,t){const n={};for(const r in e.entries)n[r]=Dc(e.entries[r]);return{...e,entries:n}}function Is(...e){return{...e[0],pipe:e,_run(t,n){for(const r of e)if(r.kind!=="metadata"){if(t.issues&&(r.kind==="schema"||r.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r._run(t,n))}return t}}}const vh=new Uint8Array(32),Bh=Tr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Et=e=>Is(Oa(Uint8Array),ny(e));function ho(e,t){return e.length!==t.length?!1:e.every((n,r)=>he(n,t[r])===0)}function Hn(e){if(!(e instanceof Uint8Array)||e.length<33)return!1;const t=e[0],n=e.slice(1,33);if(he(vh,n)===0||he(n,Bh)>=0)return!1;if((t===2||t===3)&&e.length===33)return!0;const r=e.slice(33);return he(vh,r)===0||he(r,Bh)>=0?!1:t===4&&e.length===65}const Uc=254;function Qf(e){return!e||!("output"in e)||!(e.output instanceof Uint8Array)?!1:e.version!==void 0?(e.version&Uc)===e.version:!0}function cy(e){return Array.isArray(e)?e.length!==2?!1:e.every(t=>cy(t)):Qf(e)}const lm=Et(32),hm=Et(20),Ih=Et(32),qe=Oa(Uint8Array);Is($i(),ry(/^([0-9a-f]{2})+$/i));const dm=Is(sn(),Yf(),Ba(0),va(255)),ar=Is(sn(),Yf(),Ba(0),va(4294967295)),wu=Is(sy(),Ba(0n),va(0x7fffffffffffffffn)),Oh=e=>yt(Object.entries(e).reduce((t,n)=>({...t,[n[0]]:oy(n[1])}),{})),Ph=new Uint8Array(1);function kh(e){let t=0;for(;e[t]===0;)++t;return t===e.length?Ph:(e=e.slice(t),e[0]&128?it([Ph,e]):e)}function Nh(e){e[0]===0&&(e=e.slice(1));const t=new Uint8Array(32),n=Math.max(0,32-e.length);return t.set(e,n),t}function pm(e){const t=mr(e,e.length-1);if(!tl(t))throw new Error("Invalid hashType "+t);const n=$w(e.subarray(0,-1)),r=Nh(n.r),i=Nh(n.s);return{signature:it([r,i]),hashType:t}}function ym(e,t){if(rt(yt({signature:Et(64),hashType:dm}),{signature:e,hashType:t}),!tl(t))throw new Error("Invalid hashType "+t);const n=new Uint8Array(1);dn(n,0,t);const r=kh(e.slice(0,32)),i=kh(e.slice(32,64));return it([Kw(r,i),n])}const gm=Object.freeze(Object.defineProperty({__proto__:null,decode:pm,encode:ym},Symbol.toStringTag,{value:"Module"})),ay=Ke.OP_RESERVED,uy=cn(Jf([Oa(Uint8Array),sn()]));function wm(e){return Ia(sn(),e)&&(e===Ke.OP_0||e>=Ke.OP_1&&e<=Ke.OP_16||e===Ke.OP_1NEGATE)}function fy(e){return Ia(qe,e)||wm(e)}function el(e){return Ia(Is(iy(),ty(fy)),e)}function ly(e){return e.length-e.filter(fy).length}function Xc(e){if(e.length===0)return Ke.OP_0;if(e.length===1){if(e[0]>=1&&e[0]<=16)return ay+e[0];if(e[0]===129)return Ke.OP_1NEGATE}}function hy(e){return e instanceof Uint8Array}function mm(e){return Ia(uy,e)}function zc(e){return e instanceof Uint8Array}function Zt(e){if(hy(e))return e;rt(uy,e);const t=e.reduce((i,s)=>zc(s)?s.length===1&&Xc(s)!==void 0?i+1:i+ey(s.length)+s.length:i+1,0),n=new Uint8Array(t);let r=0;if(e.forEach(i=>{if(zc(i)){const s=Xc(i);if(s!==void 0){dn(n,r,s),r+=1;return}r+=Jw(n,i.length,r),n.set(i,r),r+=i.length}else dn(n,r,i),r+=1}),r!==n.length)throw new Error("Could not decode chunks");return n}function ct(e){if(mm(e))return e;rt(qe,e);const t=[];let n=0;for(;n<e.length;){const r=e[n];if(r>Ke.OP_0&&r<=Ke.OP_PUSHDATA4){const i=Qw(e,n);if(i===null||(n+=i.size,n+i.number>e.length))return null;const s=e.slice(n,n+i.number);n+=i.number;const o=Xc(s);o!==void 0?t.push(o):t.push(s)}else t.push(r),n+=1}return t}function bm(e){if(hy(e)&&(e=ct(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(t=>{if(zc(t)){const n=Xc(t);if(n===void 0)return _e(t);t=n}return Dp[t]}).join(" ")}function Em(e){return e=ct(e),rt(Mn(el),e),e.map(t=>zc(t)?t:t===Ke.OP_0?new Uint8Array(0):tm(t-ay))}function _m(e){return Hn(e)}function tl(e){const t=e&-129;return t>0&&t<4}function br(e){return!(e instanceof Uint8Array)||!tl(e[e.length-1])?!1:Vw(e.slice(0,-1))}const co=gm;function Ee(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const r=n.call(this);return this[t]=r,r},set(r){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:r,writable:!0})}})}function _n(e){let t;return()=>(t!==void 0||(t=e()),t)}const rs=Ke,uc=rs.OP_RESERVED;function Pa(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function n(a){return br(a)||(t.allowIncomplete&&a===rs.OP_0)!==void 0}rt(ri(yt({network:yt({}),m:sn(),n:sn(),output:qe,pubkeys:cn(Mn(Hn),"Received invalid pubkey"),signatures:cn(Mn(n),"Expected signature to be of type isAcceptableSignature"),input:qe})),e);const i={network:e.network||vn};let s=[],o=!1;function c(a){o||(o=!0,s=ct(a),i.m=s[0]-uc,i.n=s[s.length-2]-uc,i.pubkeys=s.slice(1,-2))}if(Ee(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Zt([].concat(uc+e.m,e.pubkeys,uc+i.n,rs.OP_CHECKMULTISIG))}),Ee(i,"m",()=>{if(i.output)return c(i.output),i.m}),Ee(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Ee(i,"pubkeys",()=>{if(e.output)return c(e.output),i.pubkeys}),Ee(i,"signatures",()=>{if(e.input)return ct(e.input).slice(1)}),Ee(i,"input",()=>{if(e.signatures)return Zt([rs.OP_0].concat(e.signatures))}),Ee(i,"witness",()=>{if(i.input)return[]}),Ee(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(c(e.output),rt(sn(),s[0],{message:"Output is invalid"}),rt(sn(),s[s.length-2],{message:"Output is invalid"}),s[s.length-1]!==rs.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(a=>Hn(a)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!ho(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==rs.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(n))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!ho(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}const Uh=Ke;function dy(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),output:qe,pubkey:Mn(Hn,"invalid pubkey"),signature:Mn(br,"Expected signature to be of type isCanonicalScriptSignature"),input:qe})),e);const n=_n(()=>ct(e.input)),i={name:"p2pk",network:e.network||vn};if(Ee(i,"output",()=>{if(e.pubkey)return Zt([e.pubkey,Uh.OP_CHECKSIG])}),Ee(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Ee(i,"signature",()=>{if(e.input)return n()[0]}),Ee(i,"input",()=>{if(e.signature)return Zt([e.signature])}),Ee(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==Uh.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!Hn(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&he(e.pubkey,i.pubkey)!==0)throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&he(e.input,i.input)!==0)throw new TypeError("Signature mismatch");if(e.input){if(n().length!==1)throw new TypeError("Input is invalid");if(!br(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}const Xi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Lo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Sm(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Sn(e,...t){if(!Lo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Rh(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Tm(e,t){Sn(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Ri(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function mu(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Kn(e,t){return e<<32-t|e>>>t}function fc(e,t){return e<<t|e>>>32-t>>>0}const py=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qe(e){if(Sn(e),py)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=xm[e[n]];return t}const Jn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ch(e){if(e>=Jn._0&&e<=Jn._9)return e-Jn._0;if(e>=Jn.A&&e<=Jn.F)return e-(Jn.A-10);if(e>=Jn.a&&e<=Jn.f)return e-(Jn.a-10)}function jo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(py)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Ch(e.charCodeAt(s)),c=Ch(e.charCodeAt(s+1));if(o===void 0||c===void 0){const a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}r[i]=o*16+c}return r}function ut(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function yy(e){return typeof e=="string"&&(e=ut(e)),Sn(e),e}function Me(...e){let t=0;for(let r=0;r<e.length;r++){const i=e[r];Sn(i),t+=i.length}const n=new Uint8Array(t);for(let r=0,i=0;r<e.length;r++){const s=e[r];n.set(s,i),i+=s.length}return n}class Am{}function ka(e){const t=r=>e().update(yy(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function gy(e=32){if(Xi&&typeof Xi.getRandomValues=="function")return Xi.getRandomValues(new Uint8Array(e));if(Xi&&typeof Xi.randomBytes=="function")return Uint8Array.from(Xi.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vm(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,u=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+u,c,r)}function Bm(e,t,n){return e&t^~e&n}function Im(e,t,n){return e&t^e&n^t&n}class nl extends Am{constructor(t,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(t),this.view=mu(this.buffer)}update(t){Rh(this),t=yy(t),Sn(t);const{view:n,buffer:r,blockLen:i}=this,s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=mu(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Rh(this),Tm(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Ri(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;vm(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=mu(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 l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%n&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const Ar=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vr=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Om=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),wy=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Pm=wy.map(e=>(9*e+5)%16),my=(()=>{const n=[[wy],[Pm]];for(let r=0;r<4;r++)for(let i of n)i.push(i[r].map(s=>Om[s]));return n})(),by=my[0],Ey=my[1],_y=[[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(e=>Uint8Array.from(e)),km=by.map((e,t)=>e.map(n=>_y[t][n])),Nm=Ey.map((e,t)=>e.map(n=>_y[t][n])),Um=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Rm=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Hh(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const lc=new Uint32Array(16);class Cm extends nl{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:n,h2:r,h3:i,h4:s}=this;return[t,n,r,i,s]}set(t,n,r,i,s){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=i|0,this.h4=s|0}process(t,n){for(let y=0;y<16;y++,n+=4)lc[y]=t.getUint32(n,!0);let r=this.h0|0,i=r,s=this.h1|0,o=s,c=this.h2|0,a=c,u=this.h3|0,f=u,l=this.h4|0,p=l;for(let y=0;y<5;y++){const g=4-y,w=Um[y],E=Rm[y],_=by[y],S=Ey[y],m=km[y],T=Nm[y];for(let I=0;I<16;I++){const A=fc(r+Hh(y,s,c,u)+lc[_[I]]+w,m[I])+l|0;r=l,l=u,u=fc(c,10)|0,c=s,s=A}for(let I=0;I<16;I++){const A=fc(i+Hh(g,o,a,f)+lc[S[I]]+E,T[I])+p|0;i=p,p=f,f=fc(a,10)|0,a=o,o=A}}this.set(this.h1+c+f|0,this.h2+u+p|0,this.h3+l+i|0,this.h4+r+o|0,this.h0+s+a|0)}roundClean(){Ri(lc)}destroy(){this.destroyed=!0,Ri(this.buffer),this.set(0,0,0,0,0)}}const Hm=ka(()=>new Cm),Fm=Hm,hc=BigInt(2**32-1),Fh=BigInt(32);function Mm(e,t=!1){return t?{h:Number(e&hc),l:Number(e>>Fh&hc)}:{h:Number(e>>Fh&hc)|0,l:Number(e&hc)|0}}function qm(e,t=!1){const n=e.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:c}=Mm(e[s],t);[r[s],i[s]]=[o,c]}return[r,i]}const Mh=(e,t,n)=>e>>>n,qh=(e,t,n)=>e<<32-n|t>>>n,zi=(e,t,n)=>e>>>n|t<<32-n,Yi=(e,t,n)=>e<<32-n|t>>>n,dc=(e,t,n)=>e<<64-n|t>>>n-32,pc=(e,t,n)=>e>>>n-32|t<<64-n;function Qn(e,t,n,r){const i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const Vm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),$m=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Km=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Lm=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,jm=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Wm=(e,t,n,r,i,s)=>t+n+r+i+s+(e/2**32|0)|0,Gm=Uint32Array.from([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]),Br=new Uint32Array(64);class Sy extends nl{constructor(t=32){super(64,t,8,!1),this.A=Ar[0]|0,this.B=Ar[1]|0,this.C=Ar[2]|0,this.D=Ar[3]|0,this.E=Ar[4]|0,this.F=Ar[5]|0,this.G=Ar[6]|0,this.H=Ar[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let l=0;l<16;l++,n+=4)Br[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const p=Br[l-15],y=Br[l-2],g=Kn(p,7)^Kn(p,18)^p>>>3,w=Kn(y,17)^Kn(y,19)^y>>>10;Br[l]=w+Br[l-7]+g+Br[l-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){const p=Kn(c,6)^Kn(c,11)^Kn(c,25),y=f+p+Bm(c,a,u)+Gm[l]+Br[l]|0,w=(Kn(r,2)^Kn(r,13)^Kn(r,22))+Im(r,i,s)|0;f=u,u=a,a=c,c=o+y|0,o=s,s=i,i=r,r=y+w|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,i,s,o,c,a,u,f)}roundClean(){Ri(Br)}destroy(){this.set(0,0,0,0,0,0,0,0),Ri(this.buffer)}}class Dm extends Sy{constructor(){super(28),this.A=vr[0]|0,this.B=vr[1]|0,this.C=vr[2]|0,this.D=vr[3]|0,this.E=vr[4]|0,this.F=vr[5]|0,this.G=vr[6]|0,this.H=vr[7]|0}}const Ty=qm(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Xm=Ty[0],zm=Ty[1],Ir=new Uint32Array(80),Or=new Uint32Array(80);class Ym extends nl{constructor(t=64){super(128,t,16,!1),this.Ah=Ct[0]|0,this.Al=Ct[1]|0,this.Bh=Ct[2]|0,this.Bl=Ct[3]|0,this.Ch=Ct[4]|0,this.Cl=Ct[5]|0,this.Dh=Ct[6]|0,this.Dl=Ct[7]|0,this.Eh=Ct[8]|0,this.El=Ct[9]|0,this.Fh=Ct[10]|0,this.Fl=Ct[11]|0,this.Gh=Ct[12]|0,this.Gl=Ct[13]|0,this.Hh=Ct[14]|0,this.Hl=Ct[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:p,Gh:y,Gl:g,Hh:w,Hl:E}=this;return[t,n,r,i,s,o,c,a,u,f,l,p,y,g,w,E]}set(t,n,r,i,s,o,c,a,u,f,l,p,y,g,w,E){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=g|0,this.Hh=w|0,this.Hl=E|0}process(t,n){for(let m=0;m<16;m++,n+=4)Ir[m]=t.getUint32(n),Or[m]=t.getUint32(n+=4);for(let m=16;m<80;m++){const T=Ir[m-15]|0,I=Or[m-15]|0,A=zi(T,I,1)^zi(T,I,8)^Mh(T,I,7),U=Yi(T,I,1)^Yi(T,I,8)^qh(T,I,7),M=Ir[m-2]|0,v=Or[m-2]|0,R=zi(M,v,19)^dc(M,v,61)^Mh(M,v,6),V=Yi(M,v,19)^pc(M,v,61)^qh(M,v,6),W=Km(U,V,Or[m-7],Or[m-16]),H=Lm(W,A,R,Ir[m-7],Ir[m-16]);Ir[m]=H|0,Or[m]=W|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:p,Fh:y,Fl:g,Gh:w,Gl:E,Hh:_,Hl:S}=this;for(let m=0;m<80;m++){const T=zi(l,p,14)^zi(l,p,18)^dc(l,p,41),I=Yi(l,p,14)^Yi(l,p,18)^pc(l,p,41),A=l&y^~l&w,U=p&g^~p&E,M=jm(S,I,U,zm[m],Or[m]),v=Wm(M,_,T,A,Xm[m],Ir[m]),R=M|0,V=zi(r,i,28)^dc(r,i,34)^dc(r,i,39),W=Yi(r,i,28)^pc(r,i,34)^pc(r,i,39),H=r&s^r&c^s&c,K=i&o^i&a^o&a;_=w|0,S=E|0,w=y|0,E=g|0,y=l|0,g=p|0,{h:l,l:p}=Qn(u|0,f|0,v|0,R|0),u=c|0,f=a|0,c=s|0,a=o|0,s=r|0,o=i|0;const N=Vm(R,W,K);r=$m(N,v,V,H),i=N|0}({h:r,l:i}=Qn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Qn(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=Qn(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Qn(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Qn(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:g}=Qn(this.Fh|0,this.Fl|0,y|0,g|0),{h:w,l:E}=Qn(this.Gh|0,this.Gl|0,w|0,E|0),{h:_,l:S}=Qn(this.Hh|0,this.Hl|0,_|0,S|0),this.set(r,i,s,o,c,a,u,f,l,p,y,g,w,E,_,S)}roundClean(){Ri(Ir,Or)}destroy(){Ri(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const pn=ka(()=>new Sy),Zm=ka(()=>new Dm),Jm=ka(()=>new Ym),zt=pn;function wr(e){return Fm(zt(e))}function li(e){return zt(zt(e))}const Qm={"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 Na(e,t){return zt(it([Qm[e],t]))}function eb(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let u=0;u<t.length;u++)t[u]=255;for(let u=0;u<e.length;u++){const f=e.charAt(u),l=f.charCodeAt(0);if(t[l]!==255)throw new TypeError(f+" is ambiguous");t[l]=u}const n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),s=Math.log(256)/Math.log(n);function o(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";let f=0,l=0,p=0;const y=u.length;for(;p!==y&&u[p]===0;)p++,f++;const g=(y-p)*s+1>>>0,w=new Uint8Array(g);for(;p!==y;){let S=u[p],m=0;for(let T=g-1;(S!==0||m<l)&&T!==-1;T--,m++)S+=256*w[T]>>>0,w[T]=S%n>>>0,S=S/n>>>0;if(S!==0)throw new Error("Non-zero carry");l=m,p++}let E=g-l;for(;E!==g&&w[E]===0;)E++;let _=r.repeat(f);for(;E<g;++E)_+=e.charAt(w[E]);return _}function c(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;let f=0,l=0,p=0;for(;u[f]===r;)l++,f++;const y=(u.length-f)*i+1>>>0,g=new Uint8Array(y);for(;f<u.length;){const S=u.charCodeAt(f);if(S>255)return;let m=t[S];if(m===255)return;let T=0;for(let I=y-1;(m!==0||T<p)&&I!==-1;I--,T++)m+=n*g[I]>>>0,g[I]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");p=T,f++}let w=y-p;for(;w!==y&&g[w]===0;)w++;const E=new Uint8Array(l+(y-w));let _=l;for(;w!==y;)E[_++]=g[w++];return E}function a(u){const f=c(u);if(f)return f;throw new Error("Non-base"+n+" character")}return{encode:o,decodeUnsafe:c,decode:a}}var tb="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";const bu=eb(tb);function nb(e){function t(s){var o=Uint8Array.from(s),c=e(o),a=o.length+4,u=new Uint8Array(a);return u.set(o,0),u.set(c.subarray(0,4),o.length),bu.encode(u)}function n(s){var o=s.slice(0,-4),c=s.slice(-4),a=e(o);if(!(c[0]^a[0]|c[1]^a[1]|c[2]^a[2]|c[3]^a[3]))return o}function r(s){var o=bu.decodeUnsafe(s);if(o!=null)return n(o)}function i(s){var o=bu.decode(s),c=n(o);if(c==null)throw new Error("Invalid checksum");return c}return{encode:t,decode:i,decodeUnsafe:r}}function rb(e){return zt(zt(e))}const po=nb(rb),Pr=Ke;function Wo(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),address:$i(),hash:hm,output:Et(25),pubkey:Mn(Hn),signature:Mn(br),input:qe})),e);const n=_n(()=>{const o=po.decode(e.address),c=mr(o,0),a=o.slice(1);return{version:c,hash:a}}),r=_n(()=>ct(e.input)),i=e.network||vn,s={name:"p2pkh",network:i};if(Ee(s,"address",()=>{if(!s.hash)return;const o=new Uint8Array(21);return dn(o,0,i.pubKeyHash),o.set(s.hash,1),po.encode(o)}),Ee(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return n().hash;if(e.pubkey||s.pubkey)return wr(e.pubkey||s.pubkey)}),Ee(s,"output",()=>{if(s.hash)return Zt([Pr.OP_DUP,Pr.OP_HASH160,s.hash,Pr.OP_EQUALVERIFY,Pr.OP_CHECKSIG])}),Ee(s,"pubkey",()=>{if(e.input)return r()[1]}),Ee(s,"signature",()=>{if(e.input)return r()[0]}),Ee(s,"input",()=>{if(e.pubkey&&e.signature)return Zt([e.signature,e.pubkey])}),Ee(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Uint8Array.from([]);if(e.address){if(n().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(n().hash.length!==20)throw new TypeError("Invalid address");o=n().hash}if(e.hash){if(o.length>0&&he(o,e.hash)!==0)throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Pr.OP_DUP||e.output[1]!==Pr.OP_HASH160||e.output[2]!==20||e.output[23]!==Pr.OP_EQUALVERIFY||e.output[24]!==Pr.OP_CHECKSIG)throw new TypeError("Output is invalid");const c=e.output.slice(3,23);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.pubkey){const c=wr(e.pubkey);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.input){const c=r();if(c.length!==2)throw new TypeError("Input is invalid");if(!br(c[0]))throw new TypeError("Input has invalid signature");if(!Hn(c[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&he(e.signature,c[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&he(e.pubkey,c[1])!==0)throw new TypeError("Pubkey mismatch");const a=wr(c[1]);if(o.length>0&&he(o,a)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}const qs=Ke;function Go(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),address:$i(),hash:Et(20),output:Et(23),redeem:ri(yt({network:yt({}),output:qe,input:qe,witness:cn(qe)})),input:qe,witness:cn(qe)})),e);let n=e.network;n||(n=e.redeem&&e.redeem.network||vn);const r={network:n},i=_n(()=>{const c=po.decode(e.address),a=mr(c,0),u=c.slice(1);return{version:a,hash:u}}),s=_n(()=>ct(e.input)),o=_n(()=>{const c=s(),a=c[c.length-1];return{network:n,output:a===qs.OP_FALSE?Uint8Array.from([]):a,input:Zt(c.slice(0,-1)),witness:e.witness||[]}});if(Ee(r,"address",()=>{if(!r.hash)return;const c=new Uint8Array(21);return dn(c,0,r.network.scriptHash),c.set(r.hash,1),po.encode(c)}),Ee(r,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(r.redeem&&r.redeem.output)return wr(r.redeem.output)}),Ee(r,"output",()=>{if(r.hash)return Zt([qs.OP_HASH160,r.hash,qs.OP_EQUAL])}),Ee(r,"redeem",()=>{if(e.input)return o()}),Ee(r,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Zt([].concat(ct(e.redeem.input),e.redeem.output))}),Ee(r,"witness",()=>{if(r.redeem&&r.redeem.witness)return r.redeem.witness;if(r.input)return[]}),Ee(r,"name",()=>{const c=["p2sh"];return r.redeem!==void 0&&r.redeem.name!==void 0&&c.push(r.redeem.name),c.join("-")}),t.validate){let c=Uint8Array.from([]);if(e.address){if(i().version!==n.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");c=i().hash}if(e.hash){if(c.length>0&&he(c,e.hash)!==0)throw new TypeError("Hash mismatch");c=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==qs.OP_HASH160||e.output[1]!==20||e.output[22]!==qs.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(c.length>0&&he(c,u)!==0)throw new TypeError("Hash mismatch");c=u}const a=u=>{if(u.output){const f=ct(u.output);if(!f||f.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ly(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const l=wr(u.output);if(c.length>0&&he(c,l)!==0)throw new TypeError("Hash mismatch");c=l}if(u.input){const f=u.input.length>0,l=u.witness&&u.witness.length>0;if(!f&&!l)throw new TypeError("Empty input");if(f&&l)throw new TypeError("Input and witness provided");if(f){const p=ct(u.input);if(!el(p))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=s();if(!u||u.length<1)throw new TypeError("Input too short");if(!(o().output instanceof Uint8Array))throw new TypeError("Input is invalid");a(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==n)throw new TypeError("Network mismatch");if(e.input){const u=o();if(e.redeem.output&&he(e.redeem.output,u.output)!==0)throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&he(e.redeem.input,u.input)!==0)throw new TypeError("Redeem.input mismatch")}a(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!ho(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(r,e)}var hi={},Vh;function Do(){if(Vh)return hi;Vh=1,Object.defineProperty(hi,"__esModule",{value:!0}),hi.bech32m=hi.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",t={};for(let u=0;u<e.length;u++){const f=e.charAt(u);t[f]=u}function n(u){const f=u>>25;return(u&33554431)<<5^-(f>>0&1)&996825010^-(f>>1&1)&642813549^-(f>>2&1)&513874426^-(f>>3&1)&1027748829^-(f>>4&1)&705979059}function r(u){let f=1;for(let l=0;l<u.length;++l){const p=u.charCodeAt(l);if(p<33||p>126)return"Invalid prefix ("+u+")";f=n(f)^p>>5}f=n(f);for(let l=0;l<u.length;++l){const p=u.charCodeAt(l);f=n(f)^p&31}return f}function i(u,f,l,p){let y=0,g=0;const w=(1<<l)-1,E=[];for(let _=0;_<u.length;++_)for(y=y<<f|u[_],g+=f;g>=l;)g-=l,E.push(y>>g&w);if(p)g>0&&E.push(y<<l-g&w);else{if(g>=f)return"Excess padding";if(y<<l-g&w)return"Non-zero padding"}return E}function s(u){return i(u,8,5,!0)}function o(u){const f=i(u,5,8,!1);if(Array.isArray(f))return f}function c(u){const f=i(u,5,8,!1);if(Array.isArray(f))return f;throw new Error(f)}function a(u){let f;u==="bech32"?f=1:f=734539939;function l(w,E,_){if(_=_||90,w.length+7+E.length>_)throw new TypeError("Exceeds length limit");w=w.toLowerCase();let S=r(w);if(typeof S=="string")throw new Error(S);let m=w+"1";for(let T=0;T<E.length;++T){const I=E[T];if(I>>5!==0)throw new Error("Non 5-bit word");S=n(S)^I,m+=e.charAt(I)}for(let T=0;T<6;++T)S=n(S);S^=f;for(let T=0;T<6;++T){const I=S>>(5-T)*5&31;m+=e.charAt(I)}return m}function p(w,E){if(E=E||90,w.length<8)return w+" too short";if(w.length>E)return"Exceeds length limit";const _=w.toLowerCase(),S=w.toUpperCase();if(w!==_&&w!==S)return"Mixed-case string "+w;w=_;const m=w.lastIndexOf("1");if(m===-1)return"No separator character for "+w;if(m===0)return"Missing prefix for "+w;const T=w.slice(0,m),I=w.slice(m+1);if(I.length<6)return"Data too short";let A=r(T);if(typeof A=="string")return A;const U=[];for(let M=0;M<I.length;++M){const v=I.charAt(M),R=t[v];if(R===void 0)return"Unknown character "+v;A=n(A)^R,!(M+6>=I.length)&&U.push(R)}return A!==f?"Invalid checksum for "+w:{prefix:T,words:U}}function y(w,E){const _=p(w,E);if(typeof _=="object")return _}function g(w,E){const _=p(w,E);if(typeof _=="object")return _;throw new Error(_)}return{decodeUnsafe:y,decode:g,encode:l,toWords:s,fromWordsUnsafe:o,fromWords:c}}return hi.bech32=a("bech32"),hi.bech32m=a("bech32m"),hi}var Vt=Do();const $h=Ke,ib=new Uint8Array(0);function Ua(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({address:$i(),hash:Et(20),input:Et(0),network:yt({}),output:Et(22),pubkey:Mn(Hn,"Not a valid pubkey"),signature:Mn(br),witness:cn(qe)})),e);const n=_n(()=>{const s=Vt.bech32.decode(e.address),o=s.words.shift(),c=Vt.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Uint8Array.from(c)}}),r=e.network||vn,i={name:"p2wpkh",network:r};if(Ee(i,"address",()=>{if(!i.hash)return;const s=Vt.bech32.toWords(i.hash);return s.unshift(0),Vt.bech32.encode(r.bech32,s)}),Ee(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return n().data;if(e.pubkey||i.pubkey)return wr(e.pubkey||i.pubkey)}),Ee(i,"output",()=>{if(i.hash)return Zt([$h.OP_0,i.hash])}),Ee(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Ee(i,"signature",()=>{if(e.witness)return e.witness[0]}),Ee(i,"input",()=>{if(i.witness)return ib}),Ee(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Uint8Array.from([]);if(e.address){if(r&&r.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==0)throw new TypeError("Invalid address version");if(n().data.length!==20)throw new TypeError("Invalid address data");s=n().data}if(e.hash){if(s.length>0&&he(s,e.hash)!==0)throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==$h.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&he(s,e.output.slice(2))!==0)throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=wr(e.pubkey);if(s.length>0&&he(s,o)!==0)throw new TypeError("Hash mismatch");if(s=o,!Hn(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!br(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!Hn(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&he(e.signature,e.witness[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&he(e.pubkey,e.witness[1])!==0)throw new TypeError("Pubkey mismatch");const o=wr(e.witness[1]);if(s.length>0&&he(s,o)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const Kh=Ke,Eu=new Uint8Array(0);function yc(e){return!!(e instanceof Uint8Array&&e.length===65&&e[0]===4&&Hn(e))}function Xo(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(Oh({network:yt({}),address:$i(),hash:lm,output:Et(34),redeem:Oh({input:qe,network:yt({}),output:qe,witness:cn(qe)}),input:Et(0),witness:cn(qe)}),e);const n=_n(()=>{const o=Vt.bech32.decode(e.address),c=o.words.shift(),a=Vt.bech32.fromWords(o.words);return{version:c,prefix:o.prefix,data:Uint8Array.from(a)}}),r=_n(()=>ct(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||vn);const s={network:i};if(Ee(s,"address",()=>{if(!s.hash)return;const o=Vt.bech32.toWords(s.hash);return o.unshift(0),Vt.bech32.encode(i.bech32,o)}),Ee(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return n().data;if(s.redeem&&s.redeem.output)return zt(s.redeem.output)}),Ee(s,"output",()=>{if(s.hash)return Zt([Kh.OP_0,s.hash])}),Ee(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:Eu,witness:e.witness.slice(0,-1)}}),Ee(s,"input",()=>{if(s.witness)return Eu}),Ee(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=Em(r());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=Eu,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ee(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Uint8Array.from([]);if(e.address){if(n().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==0)throw new TypeError("Invalid address version");if(n().data.length!==32)throw new TypeError("Invalid address data");o=n().data}if(e.hash){if(o.length>0&&he(o,e.hash)!==0)throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Kh.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const c=e.output.slice(2);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const c=ct(e.redeem.output);if(!c||c.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(ly(c)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const a=zt(e.redeem.output);if(o.length>0&&he(o,a)!==0)throw new TypeError("Hash mismatch");o=a}if(e.redeem.input&&!el(r()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!ho(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&r().some(yc)||e.redeem.output&&(ct(e.redeem.output)||[]).some(yc))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const c=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&he(e.redeem.output,c)!==0)throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(yc)||(ct(c)||[]).some(yc))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}const ao={};function sb(e){e?e!==ao.eccLib&&(ob(e),ao.eccLib=e):ao.eccLib=e}function wf(){if(!ao.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return ao.eccLib}const er=e=>Tr(e);function ob(e){wn(typeof e.isXOnlyPoint=="function"),wn(e.isXOnlyPoint(er("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),wn(e.isXOnlyPoint(er("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),wn(e.isXOnlyPoint(er("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),wn(e.isXOnlyPoint(er("0000000000000000000000000000000000000000000000000000000000000001"))),wn(!e.isXOnlyPoint(er("0000000000000000000000000000000000000000000000000000000000000000"))),wn(!e.isXOnlyPoint(er("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),wn(typeof e.xOnlyPointAddTweak=="function"),cb.forEach(t=>{const n=e.xOnlyPointAddTweak(er(t.pubkey),er(t.tweak));t.result===null?wn(n===null):(wn(n!==null),wn(n.parity===t.parity),wn(he(n.xOnlyPubkey,er(t.result))===0))})}function wn(e){if(!e)throw new Error("ecc library invalid")}const cb=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],xy="0123456789abcdefABCDEF";xy.split("").map(e=>e.codePointAt(0));Array(256).fill(!0).map((e,t)=>{const n=String.fromCodePoint(t),r=xy.indexOf(n);return r<0?void 0:r<16?r:r-6});new TextEncoder;new TextDecoder;function ab(e,t,n,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${n}`);r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255):(e[t]=n>>8&255,e[t+1]=n&255)}function ub(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${n}`);r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255)}function fb(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${n}`);r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn))}function lb(e,t,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}else{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}function hb(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}else{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}function db(e,t,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0n;return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),r}else{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),r}}const pb=e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")};function yb(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function Ay(e){typeof e=="number"?yb(e):pb(e)}function ii(e,t,n){Ay(e),n===void 0&&(n=0),t===void 0&&(t=new Uint8Array(Tn(e)));let r=0;return e<253?(t.set([Number(e)],n),r=1):e<=65535?(t.set([253],n),ab(t,n+1,Number(e),"LE"),r=3):e<=4294967295?(t.set([254],n),ub(t,n+1,Number(e),"LE"),r=5):(t.set([255],n),fb(t,n+1,BigInt(e),"LE"),r=9),{buffer:t,bytes:r}}function Os(e,t){t===void 0&&(t=0);const n=e.at(t);if(n===void 0)throw new Error("buffer too small");if(n<253)return{numberValue:n,bigintValue:BigInt(n),bytes:1};if(n===253){const r=lb(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}else if(n===254){const r=hb(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}else{const r=db(e,t+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function Tn(e){return Ay(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const gb=9007199254740991;function wb(e,t){if(typeof e!="number"&&typeof e!="bigint")throw new Error("cannot write a non-number as a number");if(e<0&&e<BigInt(0))throw new Error("specified a negative value for writing an unsigned value");if(e>t&&e>BigInt(t))throw new Error("RangeError: value out of range");if(Math.floor(Number(e))!==Number(e))throw new Error("value has a fractional component")}function rl(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e}function Lh(e){const t=new Uint8Array(e.length);return t.set(e),t}class Ft{buffer;offset;static withCapacity(t){return new Ft(new Uint8Array(t))}constructor(t,n=0){this.buffer=t,this.offset=n,rt(Gn([qe,ar]),[t,n])}writeUInt8(t){this.offset=dn(this.buffer,this.offset,t)}writeInt32(t){this.offset=Zp(this.buffer,this.offset,t,"LE")}writeInt64(t){this.offset=Jp(this.buffer,this.offset,BigInt(t),"LE")}writeUInt32(t){this.offset=Ko(this.buffer,this.offset,t,"LE")}writeUInt64(t){this.offset=zw(this.buffer,this.offset,BigInt(t),"LE")}writeVarInt(t){const{bytes:n}=ii(t,this.buffer,this.offset);this.offset+=n}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.buffer.set(t,this.offset),this.offset+=t.length}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(n=>this.writeVarSlice(n))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}class mb{buffer;offset;constructor(t,n=0){this.buffer=t,this.offset=n,rt(Gn([qe,ar]),[t,n])}readUInt8(){const t=mr(this.buffer,this.offset);return this.offset++,t}readInt32(){const t=Zw(this.buffer,this.offset,"LE");return this.offset+=4,t}readUInt32(){const t=Bs(this.buffer,this.offset,"LE");return this.offset+=4,t}readInt64(){const t=Qp(this.buffer,this.offset,"LE");return this.offset+=8,t}readVarInt(){const{bigintValue:t,bytes:n}=Os(this.buffer,this.offset);return this.offset+=n,t}readSlice(t){wb(t,gb);const n=Number(t);if(this.buffer.length<this.offset+n)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+n);return this.offset+=n,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),n=[];for(let r=0;r<t;r++)n.push(this.readVarSlice());return n}}const vy=192,bb=128,Eb=e=>"left"in e&&"right"in e;function mf(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const n=(e.length-33)/32;let r=t;for(let i=0;i<n;i++){const s=e.slice(33+32*i,65+32*i);he(r,s)<0?r=Ef(r,s):r=Ef(s,r)}return r}function bf(e){if(Qf(e))return{hash:hr(e)};const t=[bf(e[0]),bf(e[1])];t.sort((i,s)=>he(i.hash,s.hash));const[n,r]=t;return{hash:Ef(n.hash,r.hash),left:n,right:r}}function Yc(e,t){if(Eb(e)){const n=Yc(e.left,t);if(n!==void 0)return[...n,e.right.hash];const r=Yc(e.right,t);if(r!==void 0)return[...r,e.left.hash]}else if(he(e.hash,t)===0)return[]}function hr(e){const t=e.version||vy;return Na("TapLeaf",it([Uint8Array.from([t]),Sb(e.output)]))}function _b(e,t){return Na("TapTweak",it(t?[e,t]:[e]))}function gc(e,t){if(!(e instanceof Uint8Array)||e.length!==32||t&&t.length!==32)return null;const n=_b(e,t),r=wf().xOnlyPointAddTweak(e,n);return!r||r.xOnlyPubkey===null?null:{parity:r.parity,x:Uint8Array.from(r.xOnlyPubkey)}}function Ef(e,t){return Na("TapBranch",it([e,t]))}function Sb(e){const t=Tn(e.length),n=new Uint8Array(t);return ii(e.length,n),it([n,e])}const jh=Ke,Wh=1,Tb=80;function zo(e,t){if(!e.address&&!e.output&&!e.pubkey&&!e.internalPubkey&&!(e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({address:$i(),input:Et(0),network:yt({}),output:Et(34),internalPubkey:Et(32),hash:Et(32),pubkey:Et(32),signature:Jf([Et(64),Et(65)]),witness:cn(qe),scriptTree:Mn(cy,"Taptree is not of type isTaptree"),redeem:ri(yt({output:qe,redeemVersion:sn(),witness:cn(qe)})),redeemVersion:sn()})),e);const n=_n(()=>il(e.address)),r=_n(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===Tb?e.witness.slice(0,-1):e.witness.slice()}),i=_n(()=>{if(e.scriptTree)return bf(e.scriptTree);if(e.hash)return{hash:e.hash}}),s=e.network||vn,o={name:"p2tr",network:s};if(Ee(o,"address",()=>{if(!o.pubkey)return;const c=Vt.bech32m.toWords(o.pubkey);return c.unshift(Wh),Vt.bech32m.encode(s.bech32,c)}),Ee(o,"hash",()=>{const c=i();if(c)return c.hash;const a=r();if(a&&a.length>1){const u=a[a.length-1],f=u[0]&Uc,l=a[a.length-2],p=hr({output:l,version:f});return mf(u,p)}return null}),Ee(o,"output",()=>{if(o.pubkey)return Zt([jh.OP_1,o.pubkey])}),Ee(o,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:vy),Ee(o,"redeem",()=>{const c=r();if(!(!c||c.length<2))return{output:c[c.length-2],witness:c.slice(0,-2),redeemVersion:c[c.length-1][0]&Uc}}),Ee(o,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return n().data;if(o.internalPubkey){const c=gc(o.internalPubkey,o.hash);if(c)return c.x}}),Ee(o,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const c=r();if(c&&c.length>1)return c[c.length-1].slice(1,33)}),Ee(o,"signature",()=>{if(e.signature)return e.signature;const c=r();if(!(!c||c.length!==1))return c[0]}),Ee(o,"witness",()=>{if(e.witness)return e.witness;const c=i();if(c&&e.redeem&&e.redeem.output&&e.internalPubkey){const a=hr({output:e.redeem.output,version:o.redeemVersion}),u=Yc(c,a);if(!u)return;const f=gc(e.internalPubkey,c.hash);if(!f)return;const l=it([Uint8Array.from([o.redeemVersion|f.parity]),e.internalPubkey].concat(u));return[e.redeem.output,l]}if(e.signature)return[e.signature]}),t.validate){let c=Uint8Array.from([]);if(e.address){if(s&&s.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==Wh)throw new TypeError("Invalid address version");if(n().data.length!==32)throw new TypeError("Invalid address data");c=n().data}if(e.pubkey){if(c.length>0&&he(c,e.pubkey)!==0)throw new TypeError("Pubkey mismatch");c=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==jh.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(c.length>0&&he(c,e.output.slice(2))!==0)throw new TypeError("Pubkey mismatch");c=e.output.slice(2)}if(e.internalPubkey){const f=gc(e.internalPubkey,o.hash);if(c.length>0&&he(c,f.x)!==0)throw new TypeError("Pubkey mismatch");c=f.x}if(c&&c.length&&!wf().isXOnlyPoint(c))throw new TypeError("Invalid pubkey for p2tr");const a=i();if(e.hash&&a&&he(e.hash,a.hash)!==0)throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&a){const f=hr({output:e.redeem.output,version:o.redeemVersion});if(!Yc(a,f))throw new TypeError("Redeem script not in tree")}const u=r();if(e.redeem&&o.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==o.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(ct(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(o.redeem.output&&he(e.redeem.output,o.redeem.output)!==0)throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&o.redeem.witness&&!ho(e.redeem.witness,o.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(u.length===1){if(e.signature&&he(e.signature,u[0])!==0)throw new TypeError("Signature mismatch")}else{const f=u[u.length-1];if(f.length<33)throw new TypeError(`The control-block length is too small. Got ${f.length}, expected min 33.`);if((f.length-33)%32!==0)throw new TypeError(`The control-block length of ${f.length} is incorrect!`);const l=(f.length-33)/32;if(l>128)throw new TypeError(`The script path is too long. Got ${l}, expected max 128.`);const p=f.slice(1,33);if(e.internalPubkey&&he(e.internalPubkey,p)!==0)throw new TypeError("Internal pubkey mismatch");if(!wf().isXOnlyPoint(p))throw new TypeError("Invalid internalPubkey for p2tr witness");const y=f[0]&Uc,g=u[u.length-2],w=hr({output:g,version:y}),E=mf(f,w),_=gc(p,E);if(!_)throw new TypeError("Invalid outputKey for p2tr witness");if(c.length&&he(c,_.x)!==0)throw new TypeError("Pubkey mismatch for p2tr witness");if(_.parity!==(f[0]&1))throw new Error("Incorrect parity")}}return Object.assign(o,e)}const By=40,Iy=2,Oy=16,Py=2,ky=80,Ny="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function xb(e,t){const n=e.slice(2);if(n.length<Iy||n.length>By)throw new TypeError("Invalid program length for segwit address");const r=e[0]-ky;if(r<Py||r>Oy)throw new TypeError("Invalid version for segwit address");if(e[1]!==n.length)throw new TypeError("Invalid script for segwit address");return console.warn(Ny),Ab(n,r,t.bech32)}function Uy(e){const t=po.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");const n=mr(t,0),r=t.slice(1);return{version:n,hash:r}}function il(e){let t,n;try{t=Vt.bech32.decode(e)}catch{}if(t){if(n=t.words[0],n!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=Vt.bech32m.decode(e),n=t.words[0],n===0)throw new TypeError(e+" uses wrong encoding");const r=Vt.bech32.fromWords(t.words.slice(1));return{version:n,prefix:t.prefix,data:Uint8Array.from(r)}}function Ab(e,t,n){const r=Vt.bech32.toWords(e);return r.unshift(t),t===0?Vt.bech32.encode(n,r):Vt.bech32m.encode(n,r)}function vb(e,t){t=t||vn;try{return Wo({output:e,network:t}).address}catch{}try{return Go({output:e,network:t}).address}catch{}try{return Ua({output:e,network:t}).address}catch{}try{return Xo({output:e,network:t}).address}catch{}try{return zo({output:e,network:t}).address}catch{}try{return xb(e,t)}catch{}throw new Error(bm(e)+" has no matching Address")}function Ry(e,t){t=t||vn;let n,r;try{n=Uy(e)}catch{}if(n){if(n.version===t.pubKeyHash)return Wo({hash:n.hash}).output;if(n.version===t.scriptHash)return Go({hash:n.hash}).output}else{try{r=il(e)}catch{}if(r){if(r.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(r.version===0){if(r.data.length===20)return Ua({hash:r.data}).output;if(r.data.length===32)return Xo({hash:r.data}).output}else if(r.version===1){if(r.data.length===32)return zo({pubkey:r.data}).output}else if(r.version>=Py&&r.version<=Oy&&r.data.length>=Iy&&r.data.length<=By)return console.warn(Ny),Zt([r.version+ky,r.data])}}throw new Error(e+" has no matching Script")}function Wn(e){const t=e.length;return Tn(t)+t}function Bb(e){const t=e.length;return Tn(t)+e.reduce((n,r)=>n+Wn(r),0)}const Gr=new Uint8Array(0),Gh=[],_u=Tr("0000000000000000000000000000000000000000000000000000000000000000"),Dh=Tr("0000000000000000000000000000000000000000000000000000000000000001"),Ib=Tr("ffffffffffffffff"),Ob={script:Gr,valueBuffer:Ib};function Pb(e){return e.value!==void 0}let ht=class Ge{static DEFAULT_SEQUENCE=4294967295;static SIGHASH_DEFAULT=0;static SIGHASH_ALL=1;static SIGHASH_NONE=2;static SIGHASH_SINGLE=3;static SIGHASH_ANYONECANPAY=128;static SIGHASH_OUTPUT_MASK=3;static SIGHASH_INPUT_MASK=128;static ADVANCED_TRANSACTION_MARKER=0;static ADVANCED_TRANSACTION_FLAG=1;static fromBuffer(t,n){const r=new mb(t),i=new Ge;i.version=r.readInt32();const s=r.readUInt8(),o=r.readUInt8();let c=!1;s===Ge.ADVANCED_TRANSACTION_MARKER&&o===Ge.ADVANCED_TRANSACTION_FLAG?c=!0:r.offset-=2;const a=r.readVarInt();for(let f=0;f<a;++f)i.ins.push({hash:r.readSlice(32),index:r.readUInt32(),script:r.readVarSlice(),sequence:r.readUInt32(),witness:Gh});const u=r.readVarInt();for(let f=0;f<u;++f)i.outs.push({value:r.readInt64(),script:r.readVarSlice()});if(c){for(let f=0;f<a;++f)i.ins[f].witness=r.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=r.readUInt32(),n)return i;if(r.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return Ge.fromBuffer(Tr(t),!1)}static isCoinbaseHash(t){rt(Ih,t);for(let n=0;n<32;++n)if(t[n]!==0)return!1;return!0}version=1;locktime=0;ins=[];outs=[];isCoinbase(){return this.ins.length===1&&Ge.isCoinbaseHash(this.ins[0].hash)}addInput(t,n,r,i){return rt(Gn([Ih,ar,gf(Dc(ar)),gf(Dc(qe))]),[t,n,r,i]),r==null&&(r=Ge.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:n,script:i||Gr,sequence:r,witness:Gh})-1}addOutput(t,n){return rt(Gn([qe,wu]),[t,n]),this.outs.push({script:t,value:n})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),n=this.byteLength(!0);return t*3+n}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const n=t&&this.hasWitnesses();return(n?10:8)+Tn(this.ins.length)+Tn(this.outs.length)+this.ins.reduce((r,i)=>r+40+Wn(i.script),0)+this.outs.reduce((r,i)=>r+8+Wn(i.script),0)+(n?this.ins.reduce((r,i)=>r+Bb(i.witness),0):0)}clone(){const t=new Ge;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(n=>({hash:n.hash,index:n.index,script:n.script,sequence:n.sequence,witness:n.witness})),t.outs=this.outs.map(n=>({script:n.script,value:n.value})),t}hashForSignature(t,n,r){if(rt(Gn([ar,qe,sn()]),[t,n,r]),t>=this.ins.length)return Dh;const i=Zt(ct(n).filter(c=>c!==Ke.OP_CODESEPARATOR)),s=this.clone();if((r&31)===Ge.SIGHASH_NONE)s.outs=[],s.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)});else if((r&31)===Ge.SIGHASH_SINGLE){if(t>=this.outs.length)return Dh;s.outs.length=t+1;for(let c=0;c<t;c++)s.outs[c]=Ob;s.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)})}r&Ge.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(c=>{c.script=Gr}),s.ins[t].script=i);const o=new Uint8Array(s.byteLength(!1)+4);return Zp(o,o.length-4,r,"LE"),s.__toBuffer(o,0,!1),li(o)}hashForWitnessV1(t,n,r,i,s,o){if(rt(Gn([ar,cn(qe),cn(wu),ar]),[t,n,r,i]),r.length!==this.ins.length||n.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const c=i===Ge.SIGHASH_DEFAULT?Ge.SIGHASH_ALL:i&Ge.SIGHASH_OUTPUT_MASK,u=(i&Ge.SIGHASH_INPUT_MASK)===Ge.SIGHASH_ANYONECANPAY,f=c===Ge.SIGHASH_NONE,l=c===Ge.SIGHASH_SINGLE;let p=Gr,y=Gr,g=Gr,w=Gr,E=Gr;if(!u){let T=Ft.withCapacity(36*this.ins.length);this.ins.forEach(I=>{T.writeSlice(I.hash),T.writeUInt32(I.index)}),p=zt(T.end()),T=Ft.withCapacity(8*this.ins.length),r.forEach(I=>T.writeInt64(I)),y=zt(T.end()),T=Ft.withCapacity(n.map(Wn).reduce((I,A)=>I+A)),n.forEach(I=>T.writeVarSlice(I)),g=zt(T.end()),T=Ft.withCapacity(4*this.ins.length),this.ins.forEach(I=>T.writeUInt32(I.sequence)),w=zt(T.end())}if(f||l){if(l&&t<this.outs.length){const T=this.outs[t],I=Ft.withCapacity(8+Wn(T.script));I.writeInt64(T.value),I.writeVarSlice(T.script),E=zt(I.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const T=this.outs.map(A=>8+Wn(A.script)).reduce((A,U)=>A+U),I=Ft.withCapacity(T);this.outs.forEach(A=>{I.writeInt64(A.value),I.writeVarSlice(A.script)}),E=zt(I.end())}const _=(s?2:0)+(o?1:0),S=174-(u?49:0)-(f?32:0)+(o?32:0)+(s?37:0),m=Ft.withCapacity(S);if(m.writeUInt8(i),m.writeInt32(this.version),m.writeUInt32(this.locktime),m.writeSlice(p),m.writeSlice(y),m.writeSlice(g),m.writeSlice(w),f||l||m.writeSlice(E),m.writeUInt8(_),u){const T=this.ins[t];m.writeSlice(T.hash),m.writeUInt32(T.index),m.writeInt64(r[t]),m.writeVarSlice(n[t]),m.writeUInt32(T.sequence)}else m.writeUInt32(t);if(o){const T=Ft.withCapacity(Wn(o));T.writeVarSlice(o),m.writeSlice(zt(T.end()))}return l&&m.writeSlice(E),s&&(m.writeSlice(s),m.writeUInt8(0),m.writeUInt32(4294967295)),Na("TapSighash",it([Uint8Array.from([0]),m.end()]))}hashForWitnessV0(t,n,r,i){rt(Gn([ar,qe,wu,ar]),[t,n,r,i]);let s=Uint8Array.from([]),o,c=_u,a=_u,u=_u;if(i&Ge.SIGHASH_ANYONECANPAY||(s=new Uint8Array(36*this.ins.length),o=new Ft(s,0),this.ins.forEach(l=>{o.writeSlice(l.hash),o.writeUInt32(l.index)}),a=li(s)),!(i&Ge.SIGHASH_ANYONECANPAY)&&(i&31)!==Ge.SIGHASH_SINGLE&&(i&31)!==Ge.SIGHASH_NONE&&(s=new Uint8Array(4*this.ins.length),o=new Ft(s,0),this.ins.forEach(l=>{o.writeUInt32(l.sequence)}),u=li(s)),(i&31)!==Ge.SIGHASH_SINGLE&&(i&31)!==Ge.SIGHASH_NONE){const l=this.outs.reduce((p,y)=>p+8+Wn(y.script),0);s=new Uint8Array(l),o=new Ft(s,0),this.outs.forEach(p=>{o.writeInt64(p.value),o.writeVarSlice(p.script)}),c=li(s)}else if((i&31)===Ge.SIGHASH_SINGLE&&t<this.outs.length){const l=this.outs[t];s=new Uint8Array(8+Wn(l.script)),o=new Ft(s,0),o.writeInt64(l.value),o.writeVarSlice(l.script),c=li(s)}s=new Uint8Array(156+Wn(n)),o=new Ft(s,0);const f=this.ins[t];return o.writeInt32(this.version),o.writeSlice(a),o.writeSlice(u),o.writeSlice(f.hash),o.writeUInt32(f.index),o.writeVarSlice(n),o.writeInt64(r),o.writeUInt32(f.sequence),o.writeSlice(c),o.writeUInt32(this.locktime),o.writeUInt32(i),li(s)}getHash(t){return t&&this.isCoinbase()?new Uint8Array(32):li(this.__toBuffer(void 0,void 0,t))}getId(){return _e(rl(this.getHash(!1)))}toBuffer(t,n){return this.__toBuffer(t,n,!0)}toHex(){return _e(this.toBuffer(void 0,void 0))}setInputScript(t,n){rt(Gn([sn(),qe]),[t,n]),this.ins[t].script=n}setWitness(t,n){rt(Gn([sn(),cn(qe)]),[t,n]),this.ins[t].witness=n}__toBuffer(t,n,r=!1){t||(t=new Uint8Array(this.byteLength(r)));const i=new Ft(t,n||0);i.writeInt32(this.version);const s=r&&this.hasWitnesses();return s&&(i.writeUInt8(Ge.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(Ge.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{Pb(o)?i.writeInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),n!==void 0?t.slice(n,i.offset):t}};var zn;(function(e){e[e.UNSIGNED_TX=0]="UNSIGNED_TX",e[e.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(zn||(zn={}));var ye;(function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(ye||(ye={}));var ft;(function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(ft||(ft={}));const kb=e=>[...Array(e).keys()];function Nb(e){if(e.key[0]!==zn.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+_e(e.key));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+_e(e.key));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),n={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const r of kb(e.value.length/4-1)){const i=Bs(e.value,r*4+4,"LE"),s=!!(i&2147483648),o=i&2147483647;n.path+="/"+o.toString(10)+(s?"'":"")}return n}function Ub(e){const t=new Uint8Array([zn.GLOBAL_XPUB]),n=it([t,e.extendedPubkey]),r=e.path.split("/"),i=new Uint8Array(r.length*4);i.set(e.masterFingerprint,0);let s=4;return r.slice(1).forEach(o=>{const c=o.slice(-1)==="'";let a=2147483647&parseInt(c?o.slice(0,-1):o,10);c&&(a+=2147483648),Ko(i,s,a,"LE"),s+=4}),{key:n,value:i}}const Rb="{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }";function Cb(e){const t=e.extendedPubkey,n=e.masterFingerprint,r=e.path;return t instanceof Uint8Array&&t.length===78&&[2,3].indexOf(t[45])>-1&&n instanceof Uint8Array&&n.length===4&&typeof r=="string"&&!!r.match(/^m(\/\d+'?)*$/)}function Hb(e,t,n){const r=_e(t.extendedPubkey);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.extendedPubkey,t.extendedPubkey)).length===0)}const Fb=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:Hb,check:Cb,decode:Nb,encode:Ub,expected:Rb},Symbol.toStringTag,{value:"Module"}));function Mb(e){return{key:new Uint8Array([zn.UNSIGNED_TX]),value:e.toBuffer()}}const qb=Object.freeze(Object.defineProperty({__proto__:null,encode:Mb},Symbol.toStringTag,{value:"Module"}));function Vb(e){if(e.key[0]!==ye.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+_e(e.key));return e.value}function $b(e){return{key:new Uint8Array([ye.FINAL_SCRIPTSIG]),value:e}}const Kb="Uint8Array";function Lb(e){return e instanceof Uint8Array}function jb(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}const Wb=Object.freeze(Object.defineProperty({__proto__:null,canAdd:jb,check:Lb,decode:Vb,encode:$b,expected:Kb},Symbol.toStringTag,{value:"Module"}));function Gb(e){if(e.key[0]!==ye.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+_e(e.key));return e.value}function Db(e){return{key:new Uint8Array([ye.FINAL_SCRIPTWITNESS]),value:e}}const Xb="Uint8Array";function zb(e){return e instanceof Uint8Array}function Yb(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}const Zb=Object.freeze(Object.defineProperty({__proto__:null,canAdd:Yb,check:zb,decode:Gb,encode:Db,expected:Xb},Symbol.toStringTag,{value:"Module"}));function Jb(e){if(e.key[0]!==ye.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+_e(e.key));return e.value}function Qb(e){return{key:new Uint8Array([ye.NON_WITNESS_UTXO]),value:e}}const e2="Uint8Array";function t2(e){return e instanceof Uint8Array}function n2(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}const r2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:n2,check:t2,decode:Jb,encode:Qb,expected:e2},Symbol.toStringTag,{value:"Module"}));function i2(e){if(e.key[0]!==ye.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+_e(e.key));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+_e(e.key));return{pubkey:e.key.slice(1),signature:e.value}}function s2(e){const t=new Uint8Array([ye.PARTIAL_SIG]);return{key:it([t,e.pubkey]),value:e.signature}}const o2="{ pubkey: Uint8Array; signature: Uint8Array; }";function c2(e){return e.pubkey instanceof Uint8Array&&e.signature instanceof Uint8Array&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&a2(e.signature)}function a2(e){if(!(e instanceof Uint8Array)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const n=e[3+t+2];return!(n>33||n<1||e.length!==3+t+2+n+2)}function u2(e,t,n){const r=_e(t.pubkey);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.pubkey,t.pubkey)===0).length===0)}const f2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:u2,check:c2,decode:i2,encode:s2,expected:o2},Symbol.toStringTag,{value:"Module"}));function l2(e){if(e.key[0]!==ye.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+_e(e.key));return Lw(e.value)}function h2(e){return{key:new Uint8Array([ye.POR_COMMITMENT]),value:jw(e)}}const d2="string";function p2(e){return typeof e=="string"}function y2(e,t){return!!e&&!!t&&e.porCommitment===void 0}const g2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:y2,check:p2,decode:l2,encode:h2,expected:d2},Symbol.toStringTag,{value:"Module"}));function w2(e){if(e.key[0]!==ye.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+_e(e.key));return Number(Bs(e.value,0,"LE"))}function m2(e){const t=Uint8Array.from([ye.SIGHASH_TYPE]),n=new Uint8Array(4);return Ko(n,0,e,"LE"),{key:t,value:n}}const b2="number";function E2(e){return typeof e=="number"}function _2(e,t){return!!e&&!!t&&e.sighashType===void 0}const S2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:_2,check:E2,decode:w2,encode:m2,expected:b2},Symbol.toStringTag,{value:"Module"}));function T2(e){if(e.key[0]!==ye.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+_e(e.key));if(!Cy(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}function x2(e){return{key:Uint8Array.from([ye.TAP_KEY_SIG]),value:e}}const A2="Uint8Array";function Cy(e){return e instanceof Uint8Array&&(e.length===64||e.length===65)}function v2(e,t){return!!e&&!!t&&e.tapKeySig===void 0}const B2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:v2,check:Cy,decode:T2,encode:x2,expected:A2},Symbol.toStringTag,{value:"Module"}));function I2(e){if(e.key[0]!==ye.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+_e(e.key));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+_e(e.key));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+_e(e.key));const n=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:n,leafVersion:t}}function O2(e){const t=Uint8Array.from([ye.TAP_LEAF_SCRIPT]),n=Uint8Array.from([e.leafVersion]);return{key:it([t,e.controlBlock]),value:it([e.script,n])}}const P2="{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }";function k2(e){return e.controlBlock instanceof Uint8Array&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&e.script instanceof Uint8Array}function N2(e,t,n){const r=_e(t.controlBlock);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.controlBlock,t.controlBlock)===0).length===0)}const U2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:N2,check:k2,decode:I2,encode:O2,expected:P2},Symbol.toStringTag,{value:"Module"}));function R2(e){if(e.key[0]!==ye.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+_e(e.key));if(!Hy(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}function C2(e){return{key:Uint8Array.from([ye.TAP_MERKLE_ROOT]),value:e}}const H2="Uint8Array";function Hy(e){return e instanceof Uint8Array&&e.length===32}function F2(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}const M2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:F2,check:Hy,decode:R2,encode:C2,expected:H2},Symbol.toStringTag,{value:"Module"}));function q2(e){if(e.key[0]!==ye.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+_e(e.key));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+_e(e.key));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+_e(e.key));const t=e.key.slice(1,33),n=e.key.slice(33);return{pubkey:t,leafHash:n,signature:e.value}}function V2(e){const t=Uint8Array.from([ye.TAP_SCRIPT_SIG]);return{key:it([t,e.pubkey,e.leafHash]),value:e.signature}}const $2="{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }";function K2(e){return e.pubkey instanceof Uint8Array&&e.leafHash instanceof Uint8Array&&e.signature instanceof Uint8Array&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}function L2(e,t,n){const r=_e(t.pubkey)+_e(t.leafHash);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.pubkey,t.pubkey)===0&&he(i.leafHash,t.leafHash)===0).length===0)}const j2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:L2,check:K2,decode:q2,encode:V2,expected:$2},Symbol.toStringTag,{value:"Module"}));function W2(e){if(e.key[0]!==ye.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+_e(e.key));const t=Qp(e.value,0,"LE");let n=8;const{numberValue:r,bytes:i}=Os(e.value,n);n+=i;const s=e.value.slice(n);if(s.length!==r)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:s,value:t}}function G2(e){const{script:t,value:n}=e,r=Tn(t.length),i=new Uint8Array(8+r+t.length);return Jp(i,0,BigInt(n),"LE"),ii(t.length,i,8),i.set(t,8+r),{key:Uint8Array.from([ye.WITNESS_UTXO]),value:i}}const D2="{ script: Uint8Array; value: bigint; }";function X2(e){return e.script instanceof Uint8Array&&typeof e.value=="bigint"}function z2(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}const Y2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:z2,check:X2,decode:W2,encode:G2,expected:D2},Symbol.toStringTag,{value:"Module"}));function Z2(e){if(e.key[0]!==ft.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+_e(e.key));let t=0;const n=[];for(;t<e.value.length;){const r=e.value[t++],i=e.value[t++],{numberValue:s,bytes:o}=Os(e.value,t);t+=o,n.push({depth:r,leafVersion:i,script:e.value.slice(t,t+s)}),t+=s}return{leaves:n}}function J2(e){const t=Uint8Array.from([ft.TAP_TREE]),n=[].concat(...e.leaves.map(r=>[Uint8Array.of(r.depth,r.leafVersion),ii(BigInt(r.script.length)).buffer,r.script]));return{key:t,value:it(n)}}const Q2="{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }";function eE(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&t.script instanceof Uint8Array)}function tE(e,t){return!!e&&!!t&&e.tapTree===void 0}const nE=Object.freeze(Object.defineProperty({__proto__:null,canAdd:tE,check:eE,decode:Z2,encode:J2,expected:Q2},Symbol.toStringTag,{value:"Module"})),rE=e=>[...Array(e).keys()],iE=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function sl(e,t=iE){function n(c){if(c.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+_e(c.key));const a=c.key.slice(1);if(!t(a))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+_e(c.key));if(c.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const u={masterFingerprint:c.value.slice(0,4),pubkey:a,path:"m"};for(const f of rE(c.value.length/4-1)){const l=Bs(c.value,f*4+4,"LE"),p=!!(l&2147483648),y=l&2147483647;u.path+="/"+y.toString(10)+(p?"'":"")}return u}function r(c){const a=Uint8Array.from([e]),u=it([a,c.pubkey]),f=c.path.split("/"),l=new Uint8Array(f.length*4);l.set(c.masterFingerprint,0);let p=4;return f.slice(1).forEach(y=>{const g=y.slice(-1)==="'";let w=2147483647&parseInt(g?y.slice(0,-1):y,10);g&&(w+=2147483648),Ko(l,p,w,"LE"),p+=4}),{key:u,value:l}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; }";function s(c){return c.pubkey instanceof Uint8Array&&c.masterFingerprint instanceof Uint8Array&&typeof c.path=="string"&&t(c.pubkey)&&c.masterFingerprint.length===4}function o(c,a,u){const f=_e(a.pubkey);return u.has(f)?!1:(u.add(f),c.filter(l=>he(l.pubkey,a.pubkey)===0).length===0)}return{decode:n,encode:r,check:s,expected:i,canAddToArray:o}}function ol(e){return t;function t(n){let r;if(e.includes(n.key[0])&&(r=n.key.slice(1),!(r.length===33||r.length===65)||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+_e(n.key));return r}}function Fy(e){function t(o){if(o.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+_e(o.key));return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array}function s(o,c){return!!o&&!!c&&o.redeemScript===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}const sE=e=>e.length===32;function My(e){const t=sl(e,sE);function n(o){const{numberValue:c,bytes:a}=Os(o.value),u=t.decode({key:o.key,value:o.value.slice(a+Number(c)*32)}),f=new Array(Number(c));for(let l=0,p=a;l<c;l++,p+=32)f[l]=o.value.slice(p,p+32);return{...u,leafHashes:f}}function r(o){const c=t.encode(o),a=Tn(o.leafHashes.length),u=new Uint8Array(a);ii(o.leafHashes.length,u);const f=it([u,...o.leafHashes,c.value]);return{...c,value:f}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; leafHashes: Uint8Array[]; }";function s(o){return Array.isArray(o.leafHashes)&&o.leafHashes.every(c=>c instanceof Uint8Array&&c.length===32)&&t.check(o)}return{decode:n,encode:r,check:s,expected:i,canAddToArray:t.canAddToArray}}function qy(e){function t(o){if(o.key[0]!==e||o.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+_e(o.key));if(o.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array&&o.length===32}function s(o,c){return!!o&&!!c&&o.tapInternalKey===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}function Vy(e){function t(o){if(o.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+_e(o.key));return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array}function s(o,c){return!!o&&!!c&&o.witnessScript===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}const cl={unsignedTx:qb,globalXpub:Fb,checkPubkey:ol([])},gt={nonWitnessUtxo:r2,partialSig:f2,sighashType:S2,finalScriptSig:Wb,finalScriptWitness:Zb,porCommitment:g2,witnessUtxo:Y2,bip32Derivation:sl(ye.BIP32_DERIVATION),redeemScript:Fy(ye.REDEEM_SCRIPT),witnessScript:Vy(ye.WITNESS_SCRIPT),checkPubkey:ol([ye.PARTIAL_SIG,ye.BIP32_DERIVATION]),tapKeySig:B2,tapScriptSig:j2,tapLeafScript:U2,tapBip32Derivation:My(ye.TAP_BIP32_DERIVATION),tapInternalKey:qy(ye.TAP_INTERNAL_KEY),tapMerkleRoot:M2},ur={bip32Derivation:sl(ft.BIP32_DERIVATION),redeemScript:Fy(ft.REDEEM_SCRIPT),witnessScript:Vy(ft.WITNESS_SCRIPT),checkPubkey:ol([ft.BIP32_DERIVATION]),tapBip32Derivation:My(ft.TAP_BIP32_DERIVATION),tapTree:nE,tapInternalKey:qy(ft.TAP_INTERNAL_KEY)},oE=Object.freeze(Object.defineProperty({__proto__:null,globals:cl,inputs:gt,outputs:ur},Symbol.toStringTag,{value:"Module"})),Zc=e=>[...Array(e).keys()];function Xh(e){const t=e.map(cE);return t.push(Uint8Array.from([0])),it(t)}function cE(e){const t=e.key.length,n=e.value.length,r=Tn(t),i=Tn(n),s=new Uint8Array(r+t+i+n);return ii(t,s,0),s.set(e.key,r),ii(n,s,r+t),s.set(e.value,r+t+i),s}function aE(e,t){let n=0;function r(){const{numberValue:E,bytes:_}=Os(e,n);n+=_;const S=e.slice(n,n+Number(E));return n+=Number(E),S}function i(){const E=Bs(e,n,"BE");return n+=4,E}function s(){const E=mr(e,n);return n+=1,E}function o(){const E=r(),_=r();return{key:E,value:_}}function c(){if(n>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const E=mr(e,n)===0;return E&&n++,E}if(i()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(s()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const a=[],u={};for(;!c();){const E=o(),_=_e(E.key);if(u[_])throw new Error("Format Error: Keys must be unique for global keymap: key "+_);u[_]=1,a.push(E)}const f=a.filter(E=>E.key[0]===zn.UNSIGNED_TX);if(f.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const l=t(f[0].value),{inputCount:p,outputCount:y}=l.getInputOutputCounts(),g=[],w=[];for(const E of Zc(p)){const _={},S=[];for(;!c();){const m=o(),T=_e(m.key);if(_[T])throw new Error("Format Error: Keys must be unique for each input: input index "+E+" key "+T);_[T]=1,S.push(m)}g.push(S)}for(const E of Zc(y)){const _={},S=[];for(;!c();){const m=o(),T=_e(m.key);if(_[T])throw new Error("Format Error: Keys must be unique for each output: output index "+E+" key "+T);_[T]=1,S.push(m)}w.push(S)}return $y(l,{globalMapKeyVals:a,inputKeyVals:g,outputKeyVals:w})}function Ht(e,t,n){if(he(t,Uint8Array.from([n])))throw new Error(`Format Error: Invalid ${e} key: ${_e(t)}`)}function $y(e,{globalMapKeyVals:t,inputKeyVals:n,outputKeyVals:r}){const i={unsignedTx:e};let s=0;for(const f of t)switch(f.key[0]){case zn.UNSIGNED_TX:if(Ht("global",f.key,zn.UNSIGNED_TX),s>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");s++;break;case zn.GLOBAL_XPUB:i.globalXpub===void 0&&(i.globalXpub=[]),i.globalXpub.push(cl.globalXpub.decode(f));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(f)}const o=n.length,c=r.length,a=[],u=[];for(const f of Zc(o)){const l={};for(const p of n[f])switch(gt.checkPubkey(p),p.key[0]){case ye.NON_WITNESS_UTXO:if(Ht("input",p.key,ye.NON_WITNESS_UTXO),l.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");l.nonWitnessUtxo=gt.nonWitnessUtxo.decode(p);break;case ye.WITNESS_UTXO:if(Ht("input",p.key,ye.WITNESS_UTXO),l.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");l.witnessUtxo=gt.witnessUtxo.decode(p);break;case ye.PARTIAL_SIG:l.partialSig===void 0&&(l.partialSig=[]),l.partialSig.push(gt.partialSig.decode(p));break;case ye.SIGHASH_TYPE:if(Ht("input",p.key,ye.SIGHASH_TYPE),l.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");l.sighashType=gt.sighashType.decode(p);break;case ye.REDEEM_SCRIPT:if(Ht("input",p.key,ye.REDEEM_SCRIPT),l.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");l.redeemScript=gt.redeemScript.decode(p);break;case ye.WITNESS_SCRIPT:if(Ht("input",p.key,ye.WITNESS_SCRIPT),l.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");l.witnessScript=gt.witnessScript.decode(p);break;case ye.BIP32_DERIVATION:l.bip32Derivation===void 0&&(l.bip32Derivation=[]),l.bip32Derivation.push(gt.bip32Derivation.decode(p));break;case ye.FINAL_SCRIPTSIG:Ht("input",p.key,ye.FINAL_SCRIPTSIG),l.finalScriptSig=gt.finalScriptSig.decode(p);break;case ye.FINAL_SCRIPTWITNESS:Ht("input",p.key,ye.FINAL_SCRIPTWITNESS),l.finalScriptWitness=gt.finalScriptWitness.decode(p);break;case ye.POR_COMMITMENT:Ht("input",p.key,ye.POR_COMMITMENT),l.porCommitment=gt.porCommitment.decode(p);break;case ye.TAP_KEY_SIG:Ht("input",p.key,ye.TAP_KEY_SIG),l.tapKeySig=gt.tapKeySig.decode(p);break;case ye.TAP_SCRIPT_SIG:l.tapScriptSig===void 0&&(l.tapScriptSig=[]),l.tapScriptSig.push(gt.tapScriptSig.decode(p));break;case ye.TAP_LEAF_SCRIPT:l.tapLeafScript===void 0&&(l.tapLeafScript=[]),l.tapLeafScript.push(gt.tapLeafScript.decode(p));break;case ye.TAP_BIP32_DERIVATION:l.tapBip32Derivation===void 0&&(l.tapBip32Derivation=[]),l.tapBip32Derivation.push(gt.tapBip32Derivation.decode(p));break;case ye.TAP_INTERNAL_KEY:Ht("input",p.key,ye.TAP_INTERNAL_KEY),l.tapInternalKey=gt.tapInternalKey.decode(p);break;case ye.TAP_MERKLE_ROOT:Ht("input",p.key,ye.TAP_MERKLE_ROOT),l.tapMerkleRoot=gt.tapMerkleRoot.decode(p);break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(p)}a.push(l)}for(const f of Zc(c)){const l={};for(const p of r[f])switch(ur.checkPubkey(p),p.key[0]){case ft.REDEEM_SCRIPT:if(Ht("output",p.key,ft.REDEEM_SCRIPT),l.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");l.redeemScript=ur.redeemScript.decode(p);break;case ft.WITNESS_SCRIPT:if(Ht("output",p.key,ft.WITNESS_SCRIPT),l.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");l.witnessScript=ur.witnessScript.decode(p);break;case ft.BIP32_DERIVATION:l.bip32Derivation===void 0&&(l.bip32Derivation=[]),l.bip32Derivation.push(ur.bip32Derivation.decode(p));break;case ft.TAP_INTERNAL_KEY:Ht("output",p.key,ft.TAP_INTERNAL_KEY),l.tapInternalKey=ur.tapInternalKey.decode(p);break;case ft.TAP_TREE:Ht("output",p.key,ft.TAP_TREE),l.tapTree=ur.tapTree.decode(p);break;case ft.TAP_BIP32_DERIVATION:l.tapBip32Derivation===void 0&&(l.tapBip32Derivation=[]),l.tapBip32Derivation.push(ur.tapBip32Derivation.decode(p));break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(p)}u.push(l)}return{globalMap:i,inputs:a,outputs:u}}function uE({globalMap:e,inputs:t,outputs:n}){const{globalKeyVals:r,inputKeyVals:i,outputKeyVals:s}=_f({globalMap:e,inputs:t,outputs:n}),o=Xh(r),c=l=>l.length===0?[Uint8Array.from([0])]:l.map(Xh),a=c(i),u=c(s),f=new Uint8Array(5);return f.set([112,115,98,116,255],0),it([f,o].concat(a,u))}const fE=(e,t)=>he(e.key,t.key);function Su(e,t){const n=new Set,r=Object.entries(e).reduce((s,[o,c])=>{if(o==="unknownKeyVals")return s;const a=t[o];if(a===void 0)return s;const u=(Array.isArray(c)?c:[c]).map(a.encode);return u.map(l=>_e(l.key)).forEach(l=>{if(n.has(l))throw new Error("Serialize Error: Duplicate key: "+l);n.add(l)}),s.concat(u)},[]),i=e.unknownKeyVals?e.unknownKeyVals.filter(s=>!n.has(_e(s.key))):[];return r.concat(i).sort(fE)}function _f({globalMap:e,inputs:t,outputs:n}){return{globalKeyVals:Su(e,cl),inputKeyVals:t.map(r=>Su(r,gt)),outputKeyVals:n.map(r=>Su(r,ur))}}function lE(e){const t=e[0],n=_f(t),r=e.slice(1);if(r.length===0)throw new Error("Combine: Nothing to combine");const i=zh(t);if(i===void 0)throw new Error("Combine: Self missing transaction");const s=Zi(n.globalKeyVals),o=n.inputKeyVals.map(Zi),c=n.outputKeyVals.map(Zi);for(const a of r){const u=zh(a);if(u===void 0||he(u.toBuffer(),i.toBuffer())!==0)throw new Error("Combine: One of the Psbts does not have the same transaction.");const f=_f(a);Zi(f.globalKeyVals).forEach(Tu(s,n.globalKeyVals,f.globalKeyVals)),f.inputKeyVals.map(Zi).forEach((g,w)=>g.forEach(Tu(o[w],n.inputKeyVals[w],f.inputKeyVals[w]))),f.outputKeyVals.map(Zi).forEach((g,w)=>g.forEach(Tu(c[w],n.outputKeyVals[w],f.outputKeyVals[w])))}return $y(i,{globalMapKeyVals:n.globalKeyVals,inputKeyVals:n.inputKeyVals,outputKeyVals:n.outputKeyVals})}function Tu(e,t,n){return r=>{if(e.has(r))return;const i=n.filter(s=>_e(s.key)===r)[0];t.push(i),e.add(r)}}function zh(e){return e.globalMap.unsignedTx}function Zi(e){const t=new Set;return e.forEach(n=>{const r=_e(n.key);if(t.has(r))throw new Error("Combine: KeyValue Map keys should be unique");t.add(r)}),t}function It(e,t){const n=e[t];if(n===void 0)throw new Error(`No input #${t}`);return n}function yo(e,t){const n=e[t];if(n===void 0)throw new Error(`No output #${t}`);return n}function xu(e,t,n){if(e.key[0]<n)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&t.filter(r=>he(r.key,e.key)===0).length!==0)throw new Error(`Duplicate Key: ${_e(e.key)}`)}function Au(e){let t=0;return Object.keys(e).forEach(n=>{Number(isNaN(Number(n)))&&t++}),t}function hE(e,t){let n=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const r=!!t.redeemScript,i=!!t.witnessScript,s=!r||!!t.finalScriptSig,o=!i||!!t.finalScriptWitness,c=!!t.finalScriptSig||!!t.finalScriptWitness;n=s&&o&&c}if(n===!1)throw new Error(`Input #${e} has too much or too little data to clean`)}function Yh(e,t,n,r){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${n} and got ${JSON.stringify(r)}`)}function al(e){return(t,n)=>{for(const r of Object.keys(t)){const i=t[r],{canAdd:s,canAddToArray:o,check:c,expected:a}=oE[e+"s"][r]||{},u=!!o;if(c)if(u){if(!Array.isArray(i)||n[r]&&!Array.isArray(n[r]))throw new Error(`Key type ${r} must be an array`);i.every(c)||Yh(e,r,a,i);const f=n[r]||[],l=new Set;if(!i.every(p=>o(f,p,l)))throw new Error("Can not add duplicate data to array");n[r]=f.concat(i)}else{if(c(i)||Yh(e,r,a,i),!s(n,i))throw new Error(`Can not add duplicate data to ${e}`);n[r]=i}}}}const dE=al("global"),Ky=al("input"),Ly=al("output");function pE(e,t){const n=e.length-1,r=It(e,n);Ky(t,r)}function yE(e,t){const n=e.length-1,r=yo(e,n);Ly(t,r)}let Zh=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,n){const r=Yp(t);return this.fromBuffer(r,n)}static fromHex(t,n){const r=Tr(t);return this.fromBuffer(r,n)}static fromBuffer(t,n){const r=aE(t,n),i=new this(r.globalMap.unsignedTx);return Object.assign(i,r),i}toBase64(){const t=this.toBuffer();return Dw(t)}toHex(){const t=this.toBuffer();return _e(t)}toBuffer(){return uE(this)}updateGlobal(t){return dE(t,this.globalMap),this}updateInput(t,n){const r=It(this.inputs,t);return Ky(n,r),this}updateOutput(t,n){const r=yo(this.outputs,t);return Ly(n,r),this}addUnknownKeyValToGlobal(t){return xu(t,this.globalMap.unknownKeyVals,Au(zn)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,n){const r=It(this.inputs,t);return xu(n,r.unknownKeyVals,Au(ye)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(n),this}addUnknownKeyValToOutput(t,n){const r=yo(this.outputs,t);return xu(n,r.unknownKeyVals,Au(ft)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(n),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const n=t.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(n))throw new Error("unknownKeyVals must be an Array");return n.forEach(i=>this.addUnknownKeyValToInput(r,i)),pE(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const n=t.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(n))throw new Error("unknownKeyVals must be an Array");return n.forEach(i=>this.addUnknownKeyValToOutput(r,i)),yE(this.outputs,t),this}clearFinalizedInput(t){const n=It(this.inputs,t);hE(t,n);for(const r of Object.keys(n))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(r)||delete n[r];return this}combine(...t){const n=lE([this].concat(t));return Object.assign(this,n),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};function Ki(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const gE=Ki(Pa),wE=Ki(dy),mE=Ki(Wo),Ra=Ki(Ua),Jh=Ki(Xo),jy=Ki(Go),Wy=Ki(zo);function Jc(e){let t=new Uint8Array(0);function n(o){t=it([t,o])}function r(o){const c=t.length,a=Tn(o);t=it([t,new Uint8Array(a)]),ii(o,t,c)}function i(o){r(o.length),n(o)}function s(o){r(o.length),o.forEach(i)}return s(e),t}function Gy(e,t){const n=wr(e),r=e.slice(1,33),i=ct(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:he(e,s)===0||he(n,s)===0||he(r,s)===0)}function Ca(e,t){return Gy(e,t)!==-1}function bE(e,t){return EE(e).some(r=>Dy(r,co.decode,t))}function Dy(e,t,n){const{hashType:r}=t(e),i=[];switch(r&ht.SIGHASH_ANYONECANPAY&&i.push("addInput"),r&31){case ht.SIGHASH_ALL:break;case ht.SIGHASH_SINGLE:case ht.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(n)===-1}function EE(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=_E(e)}else t=e.partialSig;return t.map(n=>n.signature)}function _E(e){const t=e.finalScriptSig?ct(e.finalScriptSig)||[]:[],n=e.finalScriptWitness?ct(e.finalScriptWitness)||[]:[];return t.concat(n).filter(r=>r instanceof Uint8Array&&br(r)).map(r=>({signature:r}))}const Rc=e=>e.length===32?e:e.slice(1,33);function Qh(e,t,n){const r=CE(t,e,n);try{const s=UE(t,r).concat(r.script).concat(r.controlBlock);return{finalScriptWitness:Jc(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}function wc(e,t){const n=t?Uint8Array.from([t]):Uint8Array.from([]);return it([e,n])}function kn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&Wy(e.witnessUtxo.script))}function vu(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function ed(e,t,n){PE(e,t,n),NE(e,t,n)}function td(e,t,n){kE(e,t,n),SE(e,t)}function SE(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const n=t.tapInternalKey||e.tapInternalKey,r=t.tapTree||e.tapTree;if(n){const{script:i}=e,s=TE(n,r);if(i&&he(s,i)!==0)throw new Error("Error adding output. Script or address mismatch.")}}function TE(e,t){const n=t&&xE(t.leaves),{output:r}=zo({internalPubkey:e,scriptTree:n});return r}function xE(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:OE(e)}function AE(e,t){return BE(e).some(r=>Dy(r,vE,t))}function vE(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||ht.SIGHASH_DEFAULT}}function BE(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(n=>n.signature)),!t.length){const n=IE(e.finalScriptWitness);n&&t.push(n)}return t}function IE(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function OE(e){let t;for(const n of e)if(t=Sf(n,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Sf(e,t,n=0){if(n>bb)throw new Error("Max taptree depth exceeded.");if(e.depth===n)return t?void 0:{output:e.script,version:e.leafVersion};if(Qf(t))return;const r=Sf(e,t&&t[0],n+1);if(r)return[r,t&&t[1]];const i=Sf(e,t&&t[1],n+1);if(i)return[t&&t[0],i]}function PE(e,t,n){const r=kn(e)&&us(t),i=us(e)&&kn(t),s=e===t&&kn(t)&&us(t);if(r||i||s)throw new Error(`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`)}function kE(e,t,n){const r=vu(e)&&us(t),i=us(e)&&vu(t),s=e===t&&vu(t)&&us(t);if(r||i||s)throw new Error(`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`)}function NE(e,t,n){if(t.tapMerkleRoot){const r=(t.tapLeafScript||[]).every(s=>Bu(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Bu(s,t.tapMerkleRoot));if(!r||!i)throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>Bu(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`)}function Bu(e,t){if(!t)return!0;const n=hr({output:e.script,version:e.leafVersion}),r=mf(e.controlBlock,n);return he(r,t)===0}function UE(e,t){const n=hr({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(r=>he(r.leafHash,n)===0).map(r=>RE(t.script,r)).sort((r,i)=>i.positionInScript-r.positionInScript).map(r=>r.signature)}function RE(e,t){return Object.assign({positionInScript:Gy(t.pubkey,e)},t)}function CE(e,t,n){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const r=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>HE(i,e.tapScriptSig,n));if(!r)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return r}function HE(e,t,n){const r=hr({output:e.script,version:e.leafVersion});return(!n||he(r,n)===0)&&t.find(s=>he(s.leafHash,r)===0)!==void 0}function us(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const FE={network:vn,maximumFeeRate:5e3};class Qc{data;static fromBase64(t,n={}){const r=Yp(t);return this.fromBuffer(r,n)}static fromHex(t,n={}){const r=Tr(t);return this.fromBuffer(r,n)}static fromBuffer(t,n={}){const r=Zh.fromBuffer(t,ME),i=new Qc(n,r);return LE(i.__CACHE.__TX,i.__CACHE),i}__CACHE;opts;constructor(t={},n=new Zh(new Xy)){this.data=n,this.opts=Object.assign({},FE,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const r=(i,s,o,c)=>Object.defineProperty(i,s,{enumerable:o,writable:c});r(this,"__CACHE",!1,!0),r(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:Lh(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let n;try{n=vb(t.script,this.opts.network)}catch{}return{script:Lh(t.script),value:t.value,address:n}})}combine(...t){return this.data.combine(...t.map(n=>n.data)),this}clone(){const t=Qc.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){mc(t),this.opts.maximumFeeRate=t}setVersion(t){mc(t),Vs(this.data.inputs,"setVersion");const n=this.__CACHE;return n.__TX.version=t,n.__EXTRACTED_TX=void 0,this}setLocktime(t){mc(t),Vs(this.data.inputs,"setLocktime");const n=this.__CACHE;return n.__TX.locktime=t,n.__EXTRACTED_TX=void 0,this}setInputSequence(t,n){mc(n),Vs(this.data.inputs,"setInputSequence");const r=this.__CACHE;if(r.__TX.ins.length<=t)throw new Error("Input index too high");return r.__TX.ins[t].sequence=n,r.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(n=>this.addInput(n)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");ed(t,t,"addInput"),Vs(this.data.inputs,"addInput"),t.witnessScript&&ea(t.witnessScript);const n=this.__CACHE;this.data.addInput(t);const r=n.__TX.ins[n.__TX.ins.length-1];Zy(n,r);const i=this.data.inputs.length-1,s=this.data.inputs[i];return s.nonWitnessUtxo&&xf(this.__CACHE,s,i),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(n=>this.addOutput(n)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");Vs(this.data.inputs,"addOutput");const{address:n}=t;if(typeof n=="string"){const{network:i}=this.opts,s=Ry(n,i);t=Object.assign({},t,{script:s})}td(t,t,"addOutput");const r=this.__CACHE;return this.data.addOutput(t),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(zy))throw new Error("Not finalized");const n=this.__CACHE;if(t||VE(this,n,this.opts),n.__EXTRACTED_TX)return n.__EXTRACTED_TX;const r=n.__TX.clone();return rg(this.data.inputs,r,n,!0),r}getFeeRate(){return od("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return od("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return It(this.data.inputs,0),$s(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,n){const r=It(this.data.inputs,t);return kn(r)?this._finalizeTaprootInput(t,r,void 0,n):this._finalizeInput(t,r,n)}finalizeTaprootInput(t,n,r=Qh){const i=It(this.data.inputs,t);if(kn(i))return this._finalizeTaprootInput(t,i,n,r);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,n,r=jE){const{script:i,isP2SH:s,isP2WSH:o,isSegwit:c}=XE(t,n,this.__CACHE);if(!i)throw new Error(`No script found for input #${t}`);$E(n);const{finalScriptSig:a,finalScriptWitness:u}=r(t,n,i,c,s,o);if(a&&this.data.updateInput(t,{finalScriptSig:a}),u&&this.data.updateInput(t,{finalScriptWitness:u}),!a&&!u)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,n,r,i=Qh){if(!n.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(n.tapKeySig){const s=zo({output:n.witnessUtxo.script,signature:n.tapKeySig}),o=Jc(s.witness);this.data.updateInput(t,{finalScriptWitness:o})}else{const{finalScriptWitness:s}=i(t,n,r);this.data.updateInput(t,{finalScriptWitness:s})}return this.data.clearFinalizedInput(t),this}getInputType(t){const n=It(this.data.inputs,t),r=ig(t,n,this.__CACHE),i=Fa(r,t,"input",n.redeemScript||QE(n.finalScriptSig),n.witnessScript||e_(n.finalScriptWitness)),s=i.type==="raw"?"":i.type+"-",o=og(i.meaningfulScript);return s+o}inputHasPubkey(t,n){const r=It(this.data.inputs,t);return ZE(n,r,t,this.__CACHE)}inputHasHDKey(t,n){const r=It(this.data.inputs,t),i=rd(n);return!!r.bip32Derivation&&r.bip32Derivation.some(i)}outputHasPubkey(t,n){const r=yo(this.data.outputs,t);return JE(n,r,t,this.__CACHE)}outputHasHDKey(t,n){const r=yo(this.data.outputs,t),i=rd(n);return!!r.bip32Derivation&&r.bip32Derivation.some(i)}validateSignaturesOfAllInputs(t){return It(this.data.inputs,0),$s(this.data.inputs.length).map(r=>this.validateSignaturesOfInput(r,t)).reduce((r,i)=>i===!0&&r,!0)}validateSignaturesOfInput(t,n,r){const i=this.data.inputs[t];return kn(i)?this.validateSignaturesOfTaprootInput(t,n,r):this._validateSignaturesOfInput(t,n,r)}_validateSignaturesOfInput(t,n,r){const i=this.data.inputs[t],s=(i||{}).partialSig;if(!i||!s||s.length<1)throw new Error("No signatures to validate");if(typeof n!="function")throw new Error("Need validator function to validate signatures");const o=r?s.filter(l=>he(l.pubkey,r)===0):s;if(o.length<1)throw new Error("No signatures for this pubkey");const c=[];let a,u,f;for(const l of o){const p=co.decode(l.signature),{hash:y,script:g}=f!==p.hashType?Qy(t,Object.assign({},i,{sighashType:p.hashType}),this.__CACHE,!0):{hash:a,script:u};f=p.hashType,a=y,u=g,Yy(l.pubkey,g,"verify"),c.push(n(l.pubkey,y,p.signature))}return c.every(l=>l===!0)}validateSignaturesOfTaprootInput(t,n,r){const i=this.data.inputs[t],s=(i||{}).tapKeySig,o=(i||{}).tapScriptSig;if(!i&&!s&&!(o&&!o.length))throw new Error("No signatures to validate");if(typeof n!="function")throw new Error("Need validator function to validate signatures");r=r&&Rc(r);const c=r?Tf(t,i,this.data.inputs,r,this.__CACHE):GE(t,i,this.data.inputs,this.__CACHE);if(!c.length)throw new Error("No signatures for this pubkey");const a=c.find(f=>!f.leafHash);let u=0;if(s&&a){if(!n(a.pubkey,a.hash,ad(s)))return!1;u++}if(o)for(const f of o){const l=c.find(p=>he(p.pubkey,f.pubkey)===0);if(l){if(!n(f.pubkey,l.hash,ad(f.signature)))return!1;u++}}return u>0}signAllInputsHD(t,n=[ht.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const r=[];for(const i of $s(this.data.inputs.length))try{this.signInputHD(i,t,n),r.push(!0)}catch{r.push(!1)}if(r.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,n=[ht.SIGHASH_ALL]){return new Promise((r,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const s=[],o=[];for(const c of $s(this.data.inputs.length))o.push(this.signInputHDAsync(c,t,n).then(()=>{s.push(!0)},()=>{s.push(!1)}));return Promise.all(o).then(()=>{if(s.every(c=>c===!1))return i(new Error("No inputs were signed"));r()})})}signInputHD(t,n,r=[ht.SIGHASH_ALL]){if(!n||!n.publicKey||!n.fingerprint)throw new Error("Need HDSigner to sign input");return ud(t,this.data.inputs,n).forEach(s=>this.signInput(t,s,r)),this}signInputHDAsync(t,n,r=[ht.SIGHASH_ALL]){return new Promise((i,s)=>{if(!n||!n.publicKey||!n.fingerprint)return s(new Error("Need HDSigner to sign input"));const c=ud(t,this.data.inputs,n).map(a=>this.signInputAsync(t,a,r));return Promise.all(c).then(()=>{i()}).catch(s)})}signAllInputs(t,n){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const r=[];for(const i of $s(this.data.inputs.length))try{this.signInput(i,t,n),r.push(!0)}catch{r.push(!1)}if(r.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,n){return new Promise((r,i)=>{if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));const s=[],o=[];for(const[c]of this.data.inputs.entries())o.push(this.signInputAsync(c,t,n).then(()=>{s.push(!0)},()=>{s.push(!1)}));return Promise.all(o).then(()=>{if(s.every(c=>c===!1))return i(new Error("No inputs were signed"));r()})})}signInput(t,n,r){if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const i=It(this.data.inputs,t);return kn(i)?this._signTaprootInput(t,i,n,void 0,r):this._signInput(t,n,r)}signTaprootInput(t,n,r,i){if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const s=It(this.data.inputs,t);if(kn(s))return this._signTaprootInput(t,s,n,r,i);throw new Error(`Input #${t} is not of type Taproot.`)}_signInput(t,n,r=[ht.SIGHASH_ALL]){const{hash:i,sighashType:s}=cd(this.data.inputs,t,n.publicKey,this.__CACHE,r),o=[{pubkey:n.publicKey,signature:co.encode(n.sign(i),s)}];return this.data.updateInput(t,{partialSig:o}),this}_signTaprootInput(t,n,r,i,s=[ht.SIGHASH_DEFAULT]){const o=this.checkTaprootHashesForSig(t,n,r,i,s),c=o.filter(u=>!u.leafHash).map(u=>wc(r.signSchnorr(u.hash),n.sighashType))[0],a=o.filter(u=>!!u.leafHash).map(u=>({pubkey:Rc(r.publicKey),signature:wc(r.signSchnorr(u.hash),n.sighashType),leafHash:u.leafHash}));return c&&this.data.updateInput(t,{tapKeySig:c}),a.length&&this.data.updateInput(t,{tapScriptSig:a}),this}signInputAsync(t,n,r){return Promise.resolve().then(()=>{if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const i=It(this.data.inputs,t);return kn(i)?this._signTaprootInputAsync(t,i,n,void 0,r):this._signInputAsync(t,n,r)})}signTaprootInputAsync(t,n,r,i){return Promise.resolve().then(()=>{if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const s=It(this.data.inputs,t);if(kn(s))return this._signTaprootInputAsync(t,s,n,r,i);throw new Error(`Input #${t} is not of type Taproot.`)})}_signInputAsync(t,n,r=[ht.SIGHASH_ALL]){const{hash:i,sighashType:s}=cd(this.data.inputs,t,n.publicKey,this.__CACHE,r);return Promise.resolve(n.sign(i)).then(o=>{const c=[{pubkey:n.publicKey,signature:co.encode(o,s)}];this.data.updateInput(t,{partialSig:c})})}async _signTaprootInputAsync(t,n,r,i,s=[ht.SIGHASH_DEFAULT]){const o=this.checkTaprootHashesForSig(t,n,r,i,s),c=[],a=o.filter(f=>!f.leafHash)[0];if(a){const f=Promise.resolve(r.signSchnorr(a.hash)).then(l=>({tapKeySig:wc(l,n.sighashType)}));c.push(f)}const u=o.filter(f=>!!f.leafHash);if(u.length){const f=u.map(l=>Promise.resolve(r.signSchnorr(l.hash)).then(p=>({tapScriptSig:[{pubkey:Rc(r.publicKey),signature:wc(p,n.sighashType),leafHash:l.leafHash}]})));c.push(...f)}return Promise.all(c).then(f=>{f.forEach(l=>this.data.updateInput(t,l))})}checkTaprootHashesForSig(t,n,r,i,s){if(typeof r.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${t}.`);const o=Tf(t,n,this.data.inputs,r.publicKey,this.__CACHE,i,s);if(!o||!o.length)throw new Error(`Can not sign for input #${t} with the key ${_e(r.publicKey)}`);return o}toBuffer(){return Iu(this.__CACHE),this.data.toBuffer()}toHex(){return Iu(this.__CACHE),this.data.toHex()}toBase64(){return Iu(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,n){return n.witnessScript&&ea(n.witnessScript),ed(this.data.inputs[t],n,"updateInput"),this.data.updateInput(t,n),n.nonWitnessUtxo&&xf(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,n){const r=this.data.outputs[t];return td(r,n,"updateOutput"),this.data.updateOutput(t,n),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,n){return this.data.addUnknownKeyValToInput(t,n),this}addUnknownKeyValToOutput(t,n){return this.data.addUnknownKeyValToOutput(t,n),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}}const ME=e=>new Xy(e);class Xy{tx;constructor(t=Uint8Array.from([2,0,0,0,0,0,0,0,0,0])){this.tx=ht.fromBuffer(t),KE(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!(t.hash instanceof Uint8Array)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const n=typeof t.hash=="string"?rl(Tr(t.hash)):t.hash;this.tx.addInput(n,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!(t.script instanceof Uint8Array)||typeof t.value!="bigint")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}}function qE(e,t,n){switch(n){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return nd(1,e.partialSig);case"multisig":const r=Pa({output:t});return nd(r.m,e.partialSig,r.pubkeys);default:return!1}}function Iu(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function nd(e,t,n){if(!t)return!1;let r;if(n?r=n.map(i=>{const s=t_(i);return t.find(o=>he(o.pubkey,s)===0)}).filter(i=>!!i):r=t,r.length>e)throw new Error("Too many signatures");return r.length===e}function zy(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function rd(e){return t=>!(he(e.fingerprint,t.masterFingerprint)||he(e.derivePath(t.path).publicKey,t.pubkey))}function mc(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function VE(e,t,n){const r=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),s=r*i;if(r>=n.maximumFeeRate)throw new Error(`Warning: You are paying around ${(s/1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function Vs(e,t){e.forEach(n=>{if(kn(n)?AE(n,t):bE(n,t))throw new Error("Can not modify transaction, signatures exist.")})}function $E(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:n}=e;t.forEach(r=>{const{hashType:i}=co.decode(r.signature);if(n!==i)throw new Error("Signature sighash does not match input sighash type")})}function Yy(e,t,n){if(!Ca(e,t))throw new Error(`Can not ${n} for this input with the key ${_e(e)}`)}function KE(e){if(!e.ins.every(n=>n.script&&n.script.length===0&&n.witness&&n.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function LE(e,t){e.ins.forEach(n=>{Zy(t,n)})}function Zy(e,t){const n=_e(rl(Uint8Array.from(t.hash)))+":"+t.index;if(e.__TX_IN_CACHE[n])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[n]=1}function Jy(e,t){return(n,r,i,s)=>{const o=e({redeem:{output:i}}).output;if(he(r,o))throw new Error(`${t} for ${s} #${n} doesn't match the scriptPubKey in the prevout`)}}const id=Jy(Go,"Redeem script"),sd=Jy(Xo,"Witness script");function od(e,t,n,r){if(!n.every(zy))throw new Error(`PSBT must be finalized to calculate ${t}`);if(e==="__FEE_RATE"&&r.__FEE_RATE)return r.__FEE_RATE;if(e==="__FEE"&&r.__FEE)return r.__FEE;let i,s=!0;if(r.__EXTRACTED_TX?(i=r.__EXTRACTED_TX,s=!1):i=r.__TX.clone(),rg(n,i,r,s),e==="__FEE_RATE")return r.__FEE_RATE;if(e==="__FEE")return r.__FEE}function jE(e,t,n,r,i,s){const o=og(n);if(!qE(t,n,o))throw new Error(`Can not finalize input #${e}`);return WE(n,o,t.partialSig,r,i,s)}function WE(e,t,n,r,i,s){let o,c;const a=DE(e,t,n),u=s?Xo({redeem:a}):null,f=i?Go({redeem:u||a}):null;return r?(u?c=Jc(u.witness):c=Jc(a.witness),f&&(o=f.input)):f?o=f.input:o=a.input,{finalScriptSig:o,finalScriptWitness:c}}function cd(e,t,n,r,i){const s=It(e,t),{hash:o,sighashType:c,script:a}=Qy(t,s,r,!1,i);return Yy(n,a,"sign"),{hash:o,sighashType:c}}function Qy(e,t,n,r,i){const s=n.__TX,o=t.sighashType||ht.SIGHASH_ALL;tg(o,i);let c,a;if(t.nonWitnessUtxo){const l=Ha(n,t,e),p=s.ins[e].hash,y=l.getHash();if(he(p,y)!==0)throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const g=s.ins[e].index;a=l.outs[g]}else if(t.witnessUtxo)a=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:u,type:f}=Fa(a.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)c=s.hashForWitnessV0(e,u,a.value,o);else if(Ra(u)){const l=Wo({hash:u.slice(2)}).output;c=s.hashForWitnessV0(e,l,a.value,o)}else{if(t.nonWitnessUtxo===void 0&&n.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${_e(u)}`);!r&&n.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
9
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function Vw(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const n=e[5+t];return!(n===0||6+t+n!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||n>1&&e[t+6]===0&&!(e[t+7]&128))}function $w(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const n=e[5+t];if(n===0)throw new Error("S length is zero");if(6+t+n!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(n>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}function Kw(e,t){const n=e.length,r=t.length;if(n===0)throw new Error("R length is zero");if(r===0)throw new Error("S length is zero");if(n>33)throw new Error("R length is too long");if(r>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(n>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(r>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=new Uint8Array(6+n+r);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,i.set(e,4),i[4+n]=2,i[5+n]=t.length,i.set(t,6+n),i}const Ke={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},Dp={};for(const e of Object.keys(Ke)){const t=Ke[e];Dp[t]=e}const Wc="0123456789abcdefABCDEF",Gc=Wc.split("").map(e=>e.codePointAt(0)),Dc=Array(256).fill(!0).map((e,t)=>{const n=String.fromCodePoint(t),r=Wc.indexOf(n);return r<0?void 0:r<16?r:r-6}),Xp=new TextEncoder,zp=new TextDecoder;function Lw(e){return zp.decode(e)}function jw(e){return Xp.encode(e)}function it(e){const t=e.reduce((i,s)=>i+s.length,0),n=new Uint8Array(t);let r=0;for(const i of e)n.set(i,r),r+=i.length;return n}function _e(e){const t=e||new Uint8Array;return t.length>512?Gw(t):Ww(t)}function Ww(e){let t="";for(let n=0;n<e.length;++n)t+=Wc[Dc[Gc[e[n]>>4]]],t+=Wc[Dc[Gc[e[n]&15]]];return t}function Gw(e){const t=new Uint8Array(e.length*2);for(let n=0;n<e.length;++n)t[n*2]=Gc[e[n]>>4],t[n*2+1]=Gc[e[n]&15];return zp.decode(t)}function Tr(e){const t=Xp.encode(e||""),n=new Uint8Array(Math.floor(t.length/2));let r;for(r=0;r<n.length;r++){const i=Dc[t[r*2]],s=Dc[t[r*2+1]];if(i===void 0||s===void 0)break;n[r]=i<<4|s}return r===n.length?n:n.slice(0,r)}function Dw(e){return btoa(String.fromCharCode(...e))}function Yp(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function he(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;++r)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1}function dn(e,t,n){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${n}`);return e[t]=n,t+1}function Xw(e,t,n,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${n}`);return r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255):(e[t]=n>>8&255,e[t+1]=n&255),t+2}function Ko(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${n}`);return r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255),t+4}function zw(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${n}`);return r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn)),t+8}function mr(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");return e[t]}function Yw(e,t,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}else{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}function Is(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}else{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}function Zp(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>2147483647||n<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${n}`);return r=r.toUpperCase(),r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255),t+4}function Jp(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n>0x7fffffffffffffffn||n<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${n}`);return r=r.toUpperCase(),r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn)),t+8}function Zw(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){const r=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0);return e[t+3]<=127?r:r-4294967296}else{const r=(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];return e[t]<=127?r:r-4294967296}}function Qp(e,t,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");n=n.toUpperCase();let r=0n;if(n==="LE")return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),e[t+7]<=127?r:r-0x10000000000000000n;{let i=0n;return i=(i<<8n)+BigInt(e[t]),i=(i<<8n)+BigInt(e[t+1]),i=(i<<8n)+BigInt(e[t+2]),i=(i<<8n)+BigInt(e[t+3]),i=(i<<8n)+BigInt(e[t+4]),i=(i<<8n)+BigInt(e[t+5]),i=(i<<8n)+BigInt(e[t+6]),i=(i<<8n)+BigInt(e[t+7]),e[t]<=127?i:i-0x10000000000000000n}}function ey(e){return e<Ke.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function Jw(e,t,n){const r=ey(t);return r===1?dn(e,n,t):r===2?(dn(e,n,Ke.OP_PUSHDATA1),dn(e,n+1,t)):r===3?(dn(e,n,Ke.OP_PUSHDATA2),Xw(e,n+1,t,"LE")):(dn(e,n,Ke.OP_PUSHDATA4),Ko(e,n+1,t,"LE")),r}function Qw(e,t){const n=mr(e,t);let r,i;if(n<Ke.OP_PUSHDATA1)r=n,i=1;else if(n===Ke.OP_PUSHDATA1){if(t+2>e.length)return null;r=mr(e,t+1),i=2}else if(n===Ke.OP_PUSHDATA2){if(t+3>e.length)return null;r=Yw(e,t+1,"LE"),i=3}else{if(t+5>e.length)return null;if(n!==Ke.OP_PUSHDATA4)throw new Error("Unexpected opcode");r=Is(e,t+1,"LE"),i=5}return{opcode:n,number:r,size:i}}function em(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function tm(e){let t=Math.abs(e);const n=em(t),r=new Uint8Array(n),i=e<0;for(let s=0;s<n;++s)dn(r,s,t&255),t>>=8;return r[n-1]&128?dn(r,n-1,i?128:0):i&&(r[n-1]|=128),r}var wu;function nm(e){return{lang:e?.lang??wu?.lang,message:e?.message,abortEarly:e?.abortEarly??wu?.abortEarly,abortPipeEarly:e?.abortPipeEarly??wu?.abortPipeEarly}}var rm;function im(e){return rm?.get(e)}var sm;function om(e){return sm?.get(e)}var cm;function am(e,t){return cm?.get(e)?.get(t)}function lo(e){const t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null":t}function $t(e,t,n,r,i){const s=i&&"input"in i?i.input:n.value,o=i?.expected??e.expects??null,c=i?.received??lo(s),a={kind:e.kind,type:e.type,input:s,expected:o,received:c,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${c}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},u=e.kind==="schema",f=i?.message??e.message??am(e.reference,a.lang)??(u?om(a.lang):null)??r.message??im(a.lang);f&&(a.message=typeof f=="function"?f(a):f),u&&(n.typed=!1),n.issues?n.issues.push(a):n.issues=[a]}function um(e,t){const n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}var fm=class extends Error{issues;constructor(e){super(e[0].message),this.name="ValiError",this.issues=e}};function ty(e,t){return{kind:"validation",type:"every_item",reference:ty,async:!1,expects:null,requirement:e,message:t,_run(n,r){return n.typed&&!n.value.every(this.requirement)&&$t(this,"item",n,r),n}}}function Zf(e){return{kind:"validation",type:"integer",reference:Zf,async:!1,expects:null,requirement:Number.isInteger,message:e,_run(t,n){return t.typed&&!this.requirement(t.value)&&$t(this,"integer",t,n),t}}}function ny(e,t){return{kind:"validation",type:"length",reference:ny,async:!1,expects:`${e}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value.length!==this.requirement&&$t(this,"length",n,r,{received:`${n.value.length}`}),n}}}function Ia(e,t){return{kind:"validation",type:"max_value",reference:Ia,async:!1,expects:`<=${e instanceof Date?e.toJSON():lo(e)}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value>this.requirement&&$t(this,"value",n,r,{received:n.value instanceof Date?n.value.toJSON():lo(n.value)}),n}}}function Oa(e,t){return{kind:"validation",type:"min_value",reference:Oa,async:!1,expects:`>=${e instanceof Date?e.toJSON():lo(e)}`,requirement:e,message:t,_run(n,r){return n.typed&&n.value<this.requirement&&$t(this,"value",n,r,{received:n.value instanceof Date?n.value.toJSON():lo(n.value)}),n}}}function ry(e,t){return{kind:"validation",type:"regex",reference:ry,async:!1,expects:`${e}`,requirement:e,message:t,_run(n,r){return n.typed&&!this.requirement.test(n.value)&&$t(this,"format",n,r),n}}}function Jf(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function Pa(e,t){return!e._run({typed:!1,value:t},{abortEarly:!0}).issues}function iy(){return{kind:"schema",type:"any",reference:iy,expects:"any",async:!1,_run(e){return e.typed=!0,e}}}function cn(e,t){return{kind:"schema",type:"array",reference:cn,expects:"Array",async:!1,item:e,message:t,_run(n,r){const i=n.value;if(Array.isArray(i)){n.typed=!0,n.value=[];for(let s=0;s<i.length;s++){const o=i[s],c=this.item._run({typed:!1,value:o},r);if(c.issues){const a={type:"array",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else $t(this,"type",n,r);return n}}}function sy(e){return{kind:"schema",type:"bigint",reference:sy,expects:"bigint",async:!1,message:e,_run(t,n){return typeof t.value=="bigint"?t.typed=!0:$t(this,"type",t,n),t}}}function Mn(e,t){return{kind:"schema",type:"custom",reference:Mn,expects:"unknown",async:!1,check:e,message:t,_run(n,r){return this.check(n.value)?n.typed=!0:$t(this,"type",n,r),n}}}function ka(e,t){return{kind:"schema",type:"instance",reference:ka,expects:e.name,async:!1,class:e,message:t,_run(n,r){return n.value instanceof this.class?n.typed=!0:$t(this,"type",n,r),n}}}function wf(e,...t){const n={kind:"schema",type:"nullable",reference:wf,expects:`(${e.expects} | null)`,async:!1,wrapped:e,_run(r,i){return r.value===null&&("default"in this&&(r.value=Jf(this,r,i)),r.value===null)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function oy(e,...t){const n={kind:"schema",type:"nullish",reference:oy,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,_run(r,i){return(r.value===null||r.value===void 0)&&("default"in this&&(r.value=Jf(this,r,i)),r.value===null||r.value===void 0)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function sn(e){return{kind:"schema",type:"number",reference:sn,expects:"number",async:!1,message:e,_run(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:$t(this,"type",t,n),t}}}function yt(e,t){return{kind:"schema",type:"object",reference:yt,expects:"Object",async:!1,entries:e,message:t,_run(n,r){const i=n.value;if(i&&typeof i=="object"){n.typed=!0,n.value={};for(const s in this.entries){const o=i[s],c=this.entries[s]._run({typed:!1,value:o},r);if(c.issues){const a={type:"object",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),(c.value!==void 0||s in i)&&(n.value[s]=c.value)}}else $t(this,"type",n,r);return n}}}function Xc(e,...t){const n={kind:"schema",type:"optional",reference:Xc,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(r,i){return r.value===void 0&&("default"in this&&(r.value=Jf(this,r,i)),r.value===void 0)?(r.typed=!0,r):this.wrapped._run(r,i)}};return 0 in t&&(n.default=t[0]),n}function Ki(e){return{kind:"schema",type:"string",reference:Ki,expects:"string",async:!1,message:e,_run(t,n){return typeof t.value=="string"?t.typed=!0:$t(this,"type",t,n),t}}}function Gn(e,t){return{kind:"schema",type:"tuple",reference:Gn,expects:"Array",async:!1,items:e,message:t,_run(n,r){const i=n.value;if(Array.isArray(i)){n.typed=!0,n.value=[];for(let s=0;s<this.items.length;s++){const o=i[s],c=this.items[s]._run({typed:!1,value:o},r);if(c.issues){const a={type:"array",origin:"value",input:i,key:s,value:o};for(const u of c.issues)u.path?u.path.unshift(a):u.path=[a],n.issues?.push(u);if(n.issues||(n.issues=c.issues),r.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else $t(this,"type",n,r);return n}}}function Ah(e){let t;if(e)for(const n of e)t?t.push(...n.issues):t=n.issues;return t}function Qf(e,t){return{kind:"schema",type:"union",reference:Qf,expects:um(e.map(n=>n.expects),"|"),async:!1,options:e,message:t,_run(n,r){let i,s,o;for(const c of this.options){const a=c._run({typed:!1,value:n.value},r);if(a.typed)if(a.issues)s?s.push(a):s=[a];else{i=a;break}else o?o.push(a):o=[a]}if(i)return i;if(s){if(s.length===1)return s[0];$t(this,"type",n,r,{issues:Ah(s)}),n.typed=!0}else{if(o?.length===1)return o[0];$t(this,"type",n,r,{issues:Ah(o)})}return n}}}function rt(e,t,n){const r=e._run({typed:!1,value:t},nm(n));if(r.issues)throw new fm(r.issues);return r.value}function ri(e,t){const n={};for(const r in e.entries)n[r]=Xc(e.entries[r]);return{...e,entries:n}}function Os(...e){return{...e[0],pipe:e,_run(t,n){for(const r of e)if(r.kind!=="metadata"){if(t.issues&&(r.kind==="schema"||r.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r._run(t,n))}return t}}}const vh=new Uint8Array(32),Bh=Tr("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Et=e=>Os(ka(Uint8Array),ny(e));function ho(e,t){return e.length!==t.length?!1:e.every((n,r)=>he(n,t[r])===0)}function Hn(e){if(!(e instanceof Uint8Array)||e.length<33)return!1;const t=e[0],n=e.slice(1,33);if(he(vh,n)===0||he(n,Bh)>=0)return!1;if((t===2||t===3)&&e.length===33)return!0;const r=e.slice(33);return he(vh,r)===0||he(r,Bh)>=0?!1:t===4&&e.length===65}const Rc=254;function el(e){return!e||!("output"in e)||!(e.output instanceof Uint8Array)?!1:e.version!==void 0?(e.version&Rc)===e.version:!0}function cy(e){return Array.isArray(e)?e.length!==2?!1:e.every(t=>cy(t)):el(e)}const lm=Et(32),hm=Et(20),Ih=Et(32),qe=ka(Uint8Array);Os(Ki(),ry(/^([0-9a-f]{2})+$/i));const dm=Os(sn(),Zf(),Oa(0),Ia(255)),ar=Os(sn(),Zf(),Oa(0),Ia(4294967295)),mu=Os(sy(),Oa(0n),Ia(0x7fffffffffffffffn)),Oh=e=>yt(Object.entries(e).reduce((t,n)=>({...t,[n[0]]:oy(n[1])}),{})),Ph=new Uint8Array(1);function kh(e){let t=0;for(;e[t]===0;)++t;return t===e.length?Ph:(e=e.slice(t),e[0]&128?it([Ph,e]):e)}function Nh(e){e[0]===0&&(e=e.slice(1));const t=new Uint8Array(32),n=Math.max(0,32-e.length);return t.set(e,n),t}function pm(e){const t=mr(e,e.length-1);if(!nl(t))throw new Error("Invalid hashType "+t);const n=$w(e.subarray(0,-1)),r=Nh(n.r),i=Nh(n.s);return{signature:it([r,i]),hashType:t}}function ym(e,t){if(rt(yt({signature:Et(64),hashType:dm}),{signature:e,hashType:t}),!nl(t))throw new Error("Invalid hashType "+t);const n=new Uint8Array(1);dn(n,0,t);const r=kh(e.slice(0,32)),i=kh(e.slice(32,64));return it([Kw(r,i),n])}const gm=Object.freeze(Object.defineProperty({__proto__:null,decode:pm,encode:ym},Symbol.toStringTag,{value:"Module"})),ay=Ke.OP_RESERVED,uy=cn(Qf([ka(Uint8Array),sn()]));function wm(e){return Pa(sn(),e)&&(e===Ke.OP_0||e>=Ke.OP_1&&e<=Ke.OP_16||e===Ke.OP_1NEGATE)}function fy(e){return Pa(qe,e)||wm(e)}function tl(e){return Pa(Os(iy(),ty(fy)),e)}function ly(e){return e.length-e.filter(fy).length}function zc(e){if(e.length===0)return Ke.OP_0;if(e.length===1){if(e[0]>=1&&e[0]<=16)return ay+e[0];if(e[0]===129)return Ke.OP_1NEGATE}}function hy(e){return e instanceof Uint8Array}function mm(e){return Pa(uy,e)}function Yc(e){return e instanceof Uint8Array}function Zt(e){if(hy(e))return e;rt(uy,e);const t=e.reduce((i,s)=>Yc(s)?s.length===1&&zc(s)!==void 0?i+1:i+ey(s.length)+s.length:i+1,0),n=new Uint8Array(t);let r=0;if(e.forEach(i=>{if(Yc(i)){const s=zc(i);if(s!==void 0){dn(n,r,s),r+=1;return}r+=Jw(n,i.length,r),n.set(i,r),r+=i.length}else dn(n,r,i),r+=1}),r!==n.length)throw new Error("Could not decode chunks");return n}function ct(e){if(mm(e))return e;rt(qe,e);const t=[];let n=0;for(;n<e.length;){const r=e[n];if(r>Ke.OP_0&&r<=Ke.OP_PUSHDATA4){const i=Qw(e,n);if(i===null||(n+=i.size,n+i.number>e.length))return null;const s=e.slice(n,n+i.number);n+=i.number;const o=zc(s);o!==void 0?t.push(o):t.push(s)}else t.push(r),n+=1}return t}function bm(e){if(hy(e)&&(e=ct(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(t=>{if(Yc(t)){const n=zc(t);if(n===void 0)return _e(t);t=n}return Dp[t]}).join(" ")}function Em(e){return e=ct(e),rt(Mn(tl),e),e.map(t=>Yc(t)?t:t===Ke.OP_0?new Uint8Array(0):tm(t-ay))}function _m(e){return Hn(e)}function nl(e){const t=e&-129;return t>0&&t<4}function br(e){return!(e instanceof Uint8Array)||!nl(e[e.length-1])?!1:Vw(e.slice(0,-1))}const co=gm;function Ee(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const r=n.call(this);return this[t]=r,r},set(r){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:r,writable:!0})}})}function _n(e){let t;return()=>(t!==void 0||(t=e()),t)}const is=Ke,fc=is.OP_RESERVED;function Na(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function n(a){return br(a)||(t.allowIncomplete&&a===is.OP_0)!==void 0}rt(ri(yt({network:yt({}),m:sn(),n:sn(),output:qe,pubkeys:cn(Mn(Hn),"Received invalid pubkey"),signatures:cn(Mn(n),"Expected signature to be of type isAcceptableSignature"),input:qe})),e);const i={network:e.network||vn};let s=[],o=!1;function c(a){o||(o=!0,s=ct(a),i.m=s[0]-fc,i.n=s[s.length-2]-fc,i.pubkeys=s.slice(1,-2))}if(Ee(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Zt([].concat(fc+e.m,e.pubkeys,fc+i.n,is.OP_CHECKMULTISIG))}),Ee(i,"m",()=>{if(i.output)return c(i.output),i.m}),Ee(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Ee(i,"pubkeys",()=>{if(e.output)return c(e.output),i.pubkeys}),Ee(i,"signatures",()=>{if(e.input)return ct(e.input).slice(1)}),Ee(i,"input",()=>{if(e.signatures)return Zt([is.OP_0].concat(e.signatures))}),Ee(i,"witness",()=>{if(i.input)return[]}),Ee(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(c(e.output),rt(sn(),s[0],{message:"Output is invalid"}),rt(sn(),s[s.length-2],{message:"Output is invalid"}),s[s.length-1]!==is.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(a=>Hn(a)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!ho(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==is.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(n))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!ho(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}const Uh=Ke;function dy(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),output:qe,pubkey:Mn(Hn,"invalid pubkey"),signature:Mn(br,"Expected signature to be of type isCanonicalScriptSignature"),input:qe})),e);const n=_n(()=>ct(e.input)),i={name:"p2pk",network:e.network||vn};if(Ee(i,"output",()=>{if(e.pubkey)return Zt([e.pubkey,Uh.OP_CHECKSIG])}),Ee(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Ee(i,"signature",()=>{if(e.input)return n()[0]}),Ee(i,"input",()=>{if(e.signature)return Zt([e.signature])}),Ee(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==Uh.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!Hn(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&he(e.pubkey,i.pubkey)!==0)throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&he(e.input,i.input)!==0)throw new TypeError("Signature mismatch");if(e.input){if(n().length!==1)throw new TypeError("Input is invalid");if(!br(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}const zi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Lo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Sm(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Sn(e,...t){if(!Lo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Rh(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Tm(e,t){Sn(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Ci(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function bu(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Kn(e,t){return e<<32-t|e>>>t}function lc(e,t){return e<<t|e>>>32-t>>>0}const py=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qe(e){if(Sn(e),py)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=xm[e[n]];return t}const Jn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ch(e){if(e>=Jn._0&&e<=Jn._9)return e-Jn._0;if(e>=Jn.A&&e<=Jn.F)return e-(Jn.A-10);if(e>=Jn.a&&e<=Jn.f)return e-(Jn.a-10)}function jo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(py)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Ch(e.charCodeAt(s)),c=Ch(e.charCodeAt(s+1));if(o===void 0||c===void 0){const a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}r[i]=o*16+c}return r}function ut(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function yy(e){return typeof e=="string"&&(e=ut(e)),Sn(e),e}function Me(...e){let t=0;for(let r=0;r<e.length;r++){const i=e[r];Sn(i),t+=i.length}const n=new Uint8Array(t);for(let r=0,i=0;r<e.length;r++){const s=e[r];n.set(s,i),i+=s.length}return n}class Am{}function Ua(e){const t=r=>e().update(yy(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function gy(e=32){if(zi&&typeof zi.getRandomValues=="function")return zi.getRandomValues(new Uint8Array(e));if(zi&&typeof zi.randomBytes=="function")return Uint8Array.from(zi.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vm(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),c=Number(n&s),a=r?4:0,u=r?0:4;e.setUint32(t+a,o,r),e.setUint32(t+u,c,r)}function Bm(e,t,n){return e&t^~e&n}function Im(e,t,n){return e&t^e&n^t&n}class rl extends Am{constructor(t,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(t),this.view=bu(this.buffer)}update(t){Rh(this),t=yy(t),Sn(t);const{view:n,buffer:r,blockLen:i}=this,s=t.length;for(let o=0;o<s;){const c=Math.min(i-this.pos,s-o);if(c===i){const a=bu(t);for(;i<=s-o;o+=i)this.process(a,o);continue}r.set(t.subarray(o,o+c),this.pos),this.pos+=c,o+=c,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Rh(this),Tm(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Ci(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;vm(r,i-8,BigInt(this.length*8),s),this.process(r,0);const c=bu(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 l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:c}=this;return t.destroyed=o,t.finished=s,t.length=i,t.pos=c,i%n&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const Ar=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vr=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),Ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Om=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),wy=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Pm=wy.map(e=>(9*e+5)%16),my=(()=>{const n=[[wy],[Pm]];for(let r=0;r<4;r++)for(let i of n)i.push(i[r].map(s=>Om[s]));return n})(),by=my[0],Ey=my[1],_y=[[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(e=>Uint8Array.from(e)),km=by.map((e,t)=>e.map(n=>_y[t][n])),Nm=Ey.map((e,t)=>e.map(n=>_y[t][n])),Um=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Rm=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Hh(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const hc=new Uint32Array(16);class Cm extends rl{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:n,h2:r,h3:i,h4:s}=this;return[t,n,r,i,s]}set(t,n,r,i,s){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=i|0,this.h4=s|0}process(t,n){for(let y=0;y<16;y++,n+=4)hc[y]=t.getUint32(n,!0);let r=this.h0|0,i=r,s=this.h1|0,o=s,c=this.h2|0,a=c,u=this.h3|0,f=u,l=this.h4|0,p=l;for(let y=0;y<5;y++){const g=4-y,w=Um[y],E=Rm[y],_=by[y],S=Ey[y],m=km[y],T=Nm[y];for(let I=0;I<16;I++){const A=lc(r+Hh(y,s,c,u)+hc[_[I]]+w,m[I])+l|0;r=l,l=u,u=lc(c,10)|0,c=s,s=A}for(let I=0;I<16;I++){const A=lc(i+Hh(g,o,a,f)+hc[S[I]]+E,T[I])+p|0;i=p,p=f,f=lc(a,10)|0,a=o,o=A}}this.set(this.h1+c+f|0,this.h2+u+p|0,this.h3+l+i|0,this.h4+r+o|0,this.h0+s+a|0)}roundClean(){Ci(hc)}destroy(){this.destroyed=!0,Ci(this.buffer),this.set(0,0,0,0,0)}}const Hm=Ua(()=>new Cm),Fm=Hm,dc=BigInt(2**32-1),Fh=BigInt(32);function Mm(e,t=!1){return t?{h:Number(e&dc),l:Number(e>>Fh&dc)}:{h:Number(e>>Fh&dc)|0,l:Number(e&dc)|0}}function qm(e,t=!1){const n=e.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:c}=Mm(e[s],t);[r[s],i[s]]=[o,c]}return[r,i]}const Mh=(e,t,n)=>e>>>n,qh=(e,t,n)=>e<<32-n|t>>>n,Yi=(e,t,n)=>e>>>n|t<<32-n,Zi=(e,t,n)=>e<<32-n|t>>>n,pc=(e,t,n)=>e<<64-n|t>>>n-32,yc=(e,t,n)=>e>>>n-32|t<<64-n;function Qn(e,t,n,r){const i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const Vm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),$m=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Km=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Lm=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,jm=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Wm=(e,t,n,r,i,s)=>t+n+r+i+s+(e/2**32|0)|0,Gm=Uint32Array.from([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]),Br=new Uint32Array(64);class Sy extends rl{constructor(t=32){super(64,t,8,!1),this.A=Ar[0]|0,this.B=Ar[1]|0,this.C=Ar[2]|0,this.D=Ar[3]|0,this.E=Ar[4]|0,this.F=Ar[5]|0,this.G=Ar[6]|0,this.H=Ar[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:c,H:a}=this;return[t,n,r,i,s,o,c,a]}set(t,n,r,i,s,o,c,a){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=c|0,this.H=a|0}process(t,n){for(let l=0;l<16;l++,n+=4)Br[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const p=Br[l-15],y=Br[l-2],g=Kn(p,7)^Kn(p,18)^p>>>3,w=Kn(y,17)^Kn(y,19)^y>>>10;Br[l]=w+Br[l-7]+g+Br[l-16]|0}let{A:r,B:i,C:s,D:o,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){const p=Kn(c,6)^Kn(c,11)^Kn(c,25),y=f+p+Bm(c,a,u)+Gm[l]+Br[l]|0,w=(Kn(r,2)^Kn(r,13)^Kn(r,22))+Im(r,i,s)|0;f=u,u=a,a=c,c=o+y|0,o=s,s=i,i=r,r=y+w|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,i,s,o,c,a,u,f)}roundClean(){Ci(Br)}destroy(){this.set(0,0,0,0,0,0,0,0),Ci(this.buffer)}}class Dm extends Sy{constructor(){super(28),this.A=vr[0]|0,this.B=vr[1]|0,this.C=vr[2]|0,this.D=vr[3]|0,this.E=vr[4]|0,this.F=vr[5]|0,this.G=vr[6]|0,this.H=vr[7]|0}}const Ty=qm(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Xm=Ty[0],zm=Ty[1],Ir=new Uint32Array(80),Or=new Uint32Array(80);class Ym extends rl{constructor(t=64){super(128,t,16,!1),this.Ah=Ct[0]|0,this.Al=Ct[1]|0,this.Bh=Ct[2]|0,this.Bl=Ct[3]|0,this.Ch=Ct[4]|0,this.Cl=Ct[5]|0,this.Dh=Ct[6]|0,this.Dl=Ct[7]|0,this.Eh=Ct[8]|0,this.El=Ct[9]|0,this.Fh=Ct[10]|0,this.Fl=Ct[11]|0,this.Gh=Ct[12]|0,this.Gl=Ct[13]|0,this.Hh=Ct[14]|0,this.Hl=Ct[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:p,Gh:y,Gl:g,Hh:w,Hl:E}=this;return[t,n,r,i,s,o,c,a,u,f,l,p,y,g,w,E]}set(t,n,r,i,s,o,c,a,u,f,l,p,y,g,w,E){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=p|0,this.Gh=y|0,this.Gl=g|0,this.Hh=w|0,this.Hl=E|0}process(t,n){for(let m=0;m<16;m++,n+=4)Ir[m]=t.getUint32(n),Or[m]=t.getUint32(n+=4);for(let m=16;m<80;m++){const T=Ir[m-15]|0,I=Or[m-15]|0,A=Yi(T,I,1)^Yi(T,I,8)^Mh(T,I,7),U=Zi(T,I,1)^Zi(T,I,8)^qh(T,I,7),M=Ir[m-2]|0,v=Or[m-2]|0,R=Yi(M,v,19)^pc(M,v,61)^Mh(M,v,6),V=Zi(M,v,19)^yc(M,v,61)^qh(M,v,6),W=Km(U,V,Or[m-7],Or[m-16]),H=Lm(W,A,R,Ir[m-7],Ir[m-16]);Ir[m]=H|0,Or[m]=W|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:p,Fh:y,Fl:g,Gh:w,Gl:E,Hh:_,Hl:S}=this;for(let m=0;m<80;m++){const T=Yi(l,p,14)^Yi(l,p,18)^pc(l,p,41),I=Zi(l,p,14)^Zi(l,p,18)^yc(l,p,41),A=l&y^~l&w,U=p&g^~p&E,M=jm(S,I,U,zm[m],Or[m]),v=Wm(M,_,T,A,Xm[m],Ir[m]),R=M|0,V=Yi(r,i,28)^pc(r,i,34)^pc(r,i,39),W=Zi(r,i,28)^yc(r,i,34)^yc(r,i,39),H=r&s^r&c^s&c,K=i&o^i&a^o&a;_=w|0,S=E|0,w=y|0,E=g|0,y=l|0,g=p|0,{h:l,l:p}=Qn(u|0,f|0,v|0,R|0),u=c|0,f=a|0,c=s|0,a=o|0,s=r|0,o=i|0;const N=Vm(R,W,K);r=$m(N,v,V,H),i=N|0}({h:r,l:i}=Qn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Qn(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=Qn(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Qn(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:p}=Qn(this.Eh|0,this.El|0,l|0,p|0),{h:y,l:g}=Qn(this.Fh|0,this.Fl|0,y|0,g|0),{h:w,l:E}=Qn(this.Gh|0,this.Gl|0,w|0,E|0),{h:_,l:S}=Qn(this.Hh|0,this.Hl|0,_|0,S|0),this.set(r,i,s,o,c,a,u,f,l,p,y,g,w,E,_,S)}roundClean(){Ci(Ir,Or)}destroy(){Ci(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const pn=Ua(()=>new Sy),Zm=Ua(()=>new Dm),Jm=Ua(()=>new Ym),zt=pn;function wr(e){return Fm(zt(e))}function li(e){return zt(zt(e))}const Qm={"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 Ra(e,t){return zt(it([Qm[e],t]))}function eb(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let u=0;u<t.length;u++)t[u]=255;for(let u=0;u<e.length;u++){const f=e.charAt(u),l=f.charCodeAt(0);if(t[l]!==255)throw new TypeError(f+" is ambiguous");t[l]=u}const n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),s=Math.log(256)/Math.log(n);function o(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";let f=0,l=0,p=0;const y=u.length;for(;p!==y&&u[p]===0;)p++,f++;const g=(y-p)*s+1>>>0,w=new Uint8Array(g);for(;p!==y;){let S=u[p],m=0;for(let T=g-1;(S!==0||m<l)&&T!==-1;T--,m++)S+=256*w[T]>>>0,w[T]=S%n>>>0,S=S/n>>>0;if(S!==0)throw new Error("Non-zero carry");l=m,p++}let E=g-l;for(;E!==g&&w[E]===0;)E++;let _=r.repeat(f);for(;E<g;++E)_+=e.charAt(w[E]);return _}function c(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;let f=0,l=0,p=0;for(;u[f]===r;)l++,f++;const y=(u.length-f)*i+1>>>0,g=new Uint8Array(y);for(;f<u.length;){const S=u.charCodeAt(f);if(S>255)return;let m=t[S];if(m===255)return;let T=0;for(let I=y-1;(m!==0||T<p)&&I!==-1;I--,T++)m+=n*g[I]>>>0,g[I]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");p=T,f++}let w=y-p;for(;w!==y&&g[w]===0;)w++;const E=new Uint8Array(l+(y-w));let _=l;for(;w!==y;)E[_++]=g[w++];return E}function a(u){const f=c(u);if(f)return f;throw new Error("Non-base"+n+" character")}return{encode:o,decodeUnsafe:c,decode:a}}var tb="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";const Eu=eb(tb);function nb(e){function t(s){var o=Uint8Array.from(s),c=e(o),a=o.length+4,u=new Uint8Array(a);return u.set(o,0),u.set(c.subarray(0,4),o.length),Eu.encode(u)}function n(s){var o=s.slice(0,-4),c=s.slice(-4),a=e(o);if(!(c[0]^a[0]|c[1]^a[1]|c[2]^a[2]|c[3]^a[3]))return o}function r(s){var o=Eu.decodeUnsafe(s);if(o!=null)return n(o)}function i(s){var o=Eu.decode(s),c=n(o);if(c==null)throw new Error("Invalid checksum");return c}return{encode:t,decode:i,decodeUnsafe:r}}function rb(e){return zt(zt(e))}const po=nb(rb),Pr=Ke;function Wo(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),address:Ki(),hash:hm,output:Et(25),pubkey:Mn(Hn),signature:Mn(br),input:qe})),e);const n=_n(()=>{const o=po.decode(e.address),c=mr(o,0),a=o.slice(1);return{version:c,hash:a}}),r=_n(()=>ct(e.input)),i=e.network||vn,s={name:"p2pkh",network:i};if(Ee(s,"address",()=>{if(!s.hash)return;const o=new Uint8Array(21);return dn(o,0,i.pubKeyHash),o.set(s.hash,1),po.encode(o)}),Ee(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return n().hash;if(e.pubkey||s.pubkey)return wr(e.pubkey||s.pubkey)}),Ee(s,"output",()=>{if(s.hash)return Zt([Pr.OP_DUP,Pr.OP_HASH160,s.hash,Pr.OP_EQUALVERIFY,Pr.OP_CHECKSIG])}),Ee(s,"pubkey",()=>{if(e.input)return r()[1]}),Ee(s,"signature",()=>{if(e.input)return r()[0]}),Ee(s,"input",()=>{if(e.pubkey&&e.signature)return Zt([e.signature,e.pubkey])}),Ee(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Uint8Array.from([]);if(e.address){if(n().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(n().hash.length!==20)throw new TypeError("Invalid address");o=n().hash}if(e.hash){if(o.length>0&&he(o,e.hash)!==0)throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Pr.OP_DUP||e.output[1]!==Pr.OP_HASH160||e.output[2]!==20||e.output[23]!==Pr.OP_EQUALVERIFY||e.output[24]!==Pr.OP_CHECKSIG)throw new TypeError("Output is invalid");const c=e.output.slice(3,23);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.pubkey){const c=wr(e.pubkey);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.input){const c=r();if(c.length!==2)throw new TypeError("Input is invalid");if(!br(c[0]))throw new TypeError("Input has invalid signature");if(!Hn(c[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&he(e.signature,c[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&he(e.pubkey,c[1])!==0)throw new TypeError("Pubkey mismatch");const a=wr(c[1]);if(o.length>0&&he(o,a)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}const Vs=Ke;function Go(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({network:yt({}),address:Ki(),hash:Et(20),output:Et(23),redeem:ri(yt({network:yt({}),output:qe,input:qe,witness:cn(qe)})),input:qe,witness:cn(qe)})),e);let n=e.network;n||(n=e.redeem&&e.redeem.network||vn);const r={network:n},i=_n(()=>{const c=po.decode(e.address),a=mr(c,0),u=c.slice(1);return{version:a,hash:u}}),s=_n(()=>ct(e.input)),o=_n(()=>{const c=s(),a=c[c.length-1];return{network:n,output:a===Vs.OP_FALSE?Uint8Array.from([]):a,input:Zt(c.slice(0,-1)),witness:e.witness||[]}});if(Ee(r,"address",()=>{if(!r.hash)return;const c=new Uint8Array(21);return dn(c,0,r.network.scriptHash),c.set(r.hash,1),po.encode(c)}),Ee(r,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(r.redeem&&r.redeem.output)return wr(r.redeem.output)}),Ee(r,"output",()=>{if(r.hash)return Zt([Vs.OP_HASH160,r.hash,Vs.OP_EQUAL])}),Ee(r,"redeem",()=>{if(e.input)return o()}),Ee(r,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Zt([].concat(ct(e.redeem.input),e.redeem.output))}),Ee(r,"witness",()=>{if(r.redeem&&r.redeem.witness)return r.redeem.witness;if(r.input)return[]}),Ee(r,"name",()=>{const c=["p2sh"];return r.redeem!==void 0&&r.redeem.name!==void 0&&c.push(r.redeem.name),c.join("-")}),t.validate){let c=Uint8Array.from([]);if(e.address){if(i().version!==n.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");c=i().hash}if(e.hash){if(c.length>0&&he(c,e.hash)!==0)throw new TypeError("Hash mismatch");c=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Vs.OP_HASH160||e.output[1]!==20||e.output[22]!==Vs.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(c.length>0&&he(c,u)!==0)throw new TypeError("Hash mismatch");c=u}const a=u=>{if(u.output){const f=ct(u.output);if(!f||f.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ly(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const l=wr(u.output);if(c.length>0&&he(c,l)!==0)throw new TypeError("Hash mismatch");c=l}if(u.input){const f=u.input.length>0,l=u.witness&&u.witness.length>0;if(!f&&!l)throw new TypeError("Empty input");if(f&&l)throw new TypeError("Input and witness provided");if(f){const p=ct(u.input);if(!tl(p))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=s();if(!u||u.length<1)throw new TypeError("Input too short");if(!(o().output instanceof Uint8Array))throw new TypeError("Input is invalid");a(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==n)throw new TypeError("Network mismatch");if(e.input){const u=o();if(e.redeem.output&&he(e.redeem.output,u.output)!==0)throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&he(e.redeem.input,u.input)!==0)throw new TypeError("Redeem.input mismatch")}a(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!ho(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(r,e)}var hi={},Vh;function Do(){if(Vh)return hi;Vh=1,Object.defineProperty(hi,"__esModule",{value:!0}),hi.bech32m=hi.bech32=void 0;const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l",t={};for(let u=0;u<e.length;u++){const f=e.charAt(u);t[f]=u}function n(u){const f=u>>25;return(u&33554431)<<5^-(f>>0&1)&996825010^-(f>>1&1)&642813549^-(f>>2&1)&513874426^-(f>>3&1)&1027748829^-(f>>4&1)&705979059}function r(u){let f=1;for(let l=0;l<u.length;++l){const p=u.charCodeAt(l);if(p<33||p>126)return"Invalid prefix ("+u+")";f=n(f)^p>>5}f=n(f);for(let l=0;l<u.length;++l){const p=u.charCodeAt(l);f=n(f)^p&31}return f}function i(u,f,l,p){let y=0,g=0;const w=(1<<l)-1,E=[];for(let _=0;_<u.length;++_)for(y=y<<f|u[_],g+=f;g>=l;)g-=l,E.push(y>>g&w);if(p)g>0&&E.push(y<<l-g&w);else{if(g>=f)return"Excess padding";if(y<<l-g&w)return"Non-zero padding"}return E}function s(u){return i(u,8,5,!0)}function o(u){const f=i(u,5,8,!1);if(Array.isArray(f))return f}function c(u){const f=i(u,5,8,!1);if(Array.isArray(f))return f;throw new Error(f)}function a(u){let f;u==="bech32"?f=1:f=734539939;function l(w,E,_){if(_=_||90,w.length+7+E.length>_)throw new TypeError("Exceeds length limit");w=w.toLowerCase();let S=r(w);if(typeof S=="string")throw new Error(S);let m=w+"1";for(let T=0;T<E.length;++T){const I=E[T];if(I>>5!==0)throw new Error("Non 5-bit word");S=n(S)^I,m+=e.charAt(I)}for(let T=0;T<6;++T)S=n(S);S^=f;for(let T=0;T<6;++T){const I=S>>(5-T)*5&31;m+=e.charAt(I)}return m}function p(w,E){if(E=E||90,w.length<8)return w+" too short";if(w.length>E)return"Exceeds length limit";const _=w.toLowerCase(),S=w.toUpperCase();if(w!==_&&w!==S)return"Mixed-case string "+w;w=_;const m=w.lastIndexOf("1");if(m===-1)return"No separator character for "+w;if(m===0)return"Missing prefix for "+w;const T=w.slice(0,m),I=w.slice(m+1);if(I.length<6)return"Data too short";let A=r(T);if(typeof A=="string")return A;const U=[];for(let M=0;M<I.length;++M){const v=I.charAt(M),R=t[v];if(R===void 0)return"Unknown character "+v;A=n(A)^R,!(M+6>=I.length)&&U.push(R)}return A!==f?"Invalid checksum for "+w:{prefix:T,words:U}}function y(w,E){const _=p(w,E);if(typeof _=="object")return _}function g(w,E){const _=p(w,E);if(typeof _=="object")return _;throw new Error(_)}return{decodeUnsafe:y,decode:g,encode:l,toWords:s,fromWordsUnsafe:o,fromWords:c}}return hi.bech32=a("bech32"),hi.bech32m=a("bech32m"),hi}var Vt=Do();const $h=Ke,ib=new Uint8Array(0);function Xo(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({address:Ki(),hash:Et(20),input:Et(0),network:yt({}),output:Et(22),pubkey:Mn(Hn,"Not a valid pubkey"),signature:Mn(br),witness:cn(qe)})),e);const n=_n(()=>{const s=Vt.bech32.decode(e.address),o=s.words.shift(),c=Vt.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Uint8Array.from(c)}}),r=e.network||vn,i={name:"p2wpkh",network:r};if(Ee(i,"address",()=>{if(!i.hash)return;const s=Vt.bech32.toWords(i.hash);return s.unshift(0),Vt.bech32.encode(r.bech32,s)}),Ee(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return n().data;if(e.pubkey||i.pubkey)return wr(e.pubkey||i.pubkey)}),Ee(i,"output",()=>{if(i.hash)return Zt([$h.OP_0,i.hash])}),Ee(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Ee(i,"signature",()=>{if(e.witness)return e.witness[0]}),Ee(i,"input",()=>{if(i.witness)return ib}),Ee(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Uint8Array.from([]);if(e.address){if(r&&r.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==0)throw new TypeError("Invalid address version");if(n().data.length!==20)throw new TypeError("Invalid address data");s=n().data}if(e.hash){if(s.length>0&&he(s,e.hash)!==0)throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==$h.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&he(s,e.output.slice(2))!==0)throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=wr(e.pubkey);if(s.length>0&&he(s,o)!==0)throw new TypeError("Hash mismatch");if(s=o,!Hn(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!br(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!Hn(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&he(e.signature,e.witness[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&he(e.pubkey,e.witness[1])!==0)throw new TypeError("Pubkey mismatch");const o=wr(e.witness[1]);if(s.length>0&&he(s,o)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const Kh=Ke,_u=new Uint8Array(0);function gc(e){return!!(e instanceof Uint8Array&&e.length===65&&e[0]===4&&Hn(e))}function zo(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(Oh({network:yt({}),address:Ki(),hash:lm,output:Et(34),redeem:Oh({input:qe,network:yt({}),output:qe,witness:cn(qe)}),input:Et(0),witness:cn(qe)}),e);const n=_n(()=>{const o=Vt.bech32.decode(e.address),c=o.words.shift(),a=Vt.bech32.fromWords(o.words);return{version:c,prefix:o.prefix,data:Uint8Array.from(a)}}),r=_n(()=>ct(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||vn);const s={network:i};if(Ee(s,"address",()=>{if(!s.hash)return;const o=Vt.bech32.toWords(s.hash);return o.unshift(0),Vt.bech32.encode(i.bech32,o)}),Ee(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return n().data;if(s.redeem&&s.redeem.output)return zt(s.redeem.output)}),Ee(s,"output",()=>{if(s.hash)return Zt([Kh.OP_0,s.hash])}),Ee(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:_u,witness:e.witness.slice(0,-1)}}),Ee(s,"input",()=>{if(s.witness)return _u}),Ee(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=Em(r());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=_u,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ee(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Uint8Array.from([]);if(e.address){if(n().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==0)throw new TypeError("Invalid address version");if(n().data.length!==32)throw new TypeError("Invalid address data");o=n().data}if(e.hash){if(o.length>0&&he(o,e.hash)!==0)throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Kh.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const c=e.output.slice(2);if(o.length>0&&he(o,c)!==0)throw new TypeError("Hash mismatch");o=c}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const c=ct(e.redeem.output);if(!c||c.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(ly(c)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const a=zt(e.redeem.output);if(o.length>0&&he(o,a)!==0)throw new TypeError("Hash mismatch");o=a}if(e.redeem.input&&!tl(r()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!ho(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&r().some(gc)||e.redeem.output&&(ct(e.redeem.output)||[]).some(gc))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const c=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&he(e.redeem.output,c)!==0)throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(gc)||(ct(c)||[]).some(gc))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}const ao={};function sb(e){e?e!==ao.eccLib&&(ob(e),ao.eccLib=e):ao.eccLib=e}function mf(){if(!ao.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return ao.eccLib}const er=e=>Tr(e);function ob(e){wn(typeof e.isXOnlyPoint=="function"),wn(e.isXOnlyPoint(er("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),wn(e.isXOnlyPoint(er("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),wn(e.isXOnlyPoint(er("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),wn(e.isXOnlyPoint(er("0000000000000000000000000000000000000000000000000000000000000001"))),wn(!e.isXOnlyPoint(er("0000000000000000000000000000000000000000000000000000000000000000"))),wn(!e.isXOnlyPoint(er("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),wn(typeof e.xOnlyPointAddTweak=="function"),cb.forEach(t=>{const n=e.xOnlyPointAddTweak(er(t.pubkey),er(t.tweak));t.result===null?wn(n===null):(wn(n!==null),wn(n.parity===t.parity),wn(he(n.xOnlyPubkey,er(t.result))===0))})}function wn(e){if(!e)throw new Error("ecc library invalid")}const cb=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],xy="0123456789abcdefABCDEF";xy.split("").map(e=>e.codePointAt(0));Array(256).fill(!0).map((e,t)=>{const n=String.fromCodePoint(t),r=xy.indexOf(n);return r<0?void 0:r<16?r:r-6});new TextEncoder;new TextDecoder;function ab(e,t,n,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${n}`);r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255):(e[t]=n>>8&255,e[t+1]=n&255)}function ub(e,t,n,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${n}`);r==="LE"?(e[t]=n&255,e[t+1]=n>>8&255,e[t+2]=n>>16&255,e[t+3]=n>>24&255):(e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255)}function fb(e,t,n,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),n>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${n}`);r==="LE"?(e[t]=Number(n&0xffn),e[t+1]=Number(n>>8n&0xffn),e[t+2]=Number(n>>16n&0xffn),e[t+3]=Number(n>>24n&0xffn),e[t+4]=Number(n>>32n&0xffn),e[t+5]=Number(n>>40n&0xffn),e[t+6]=Number(n>>48n&0xffn),e[t+7]=Number(n>>56n&0xffn)):(e[t]=Number(n>>56n&0xffn),e[t+1]=Number(n>>48n&0xffn),e[t+2]=Number(n>>40n&0xffn),e[t+3]=Number(n>>32n&0xffn),e[t+4]=Number(n>>24n&0xffn),e[t+5]=Number(n>>16n&0xffn),e[t+6]=Number(n>>8n&0xffn),e[t+7]=Number(n&0xffn))}function lb(e,t,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+1],r=(r<<8)+e[t],r}else{let r=0;return r=(r<<8)+e[t],r=(r<<8)+e[t+1],r}}function hb(e,t,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0;return r=(r<<8)+e[t+3]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t]>>>0,r}else{let r=0;return r=(r<<8)+e[t]>>>0,r=(r<<8)+e[t+1]>>>0,r=(r<<8)+e[t+2]>>>0,r=(r<<8)+e[t+3]>>>0,r}}function db(e,t,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),n==="LE"){let r=0n;return r=(r<<8n)+BigInt(e[t+7]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t]),r}else{let r=0n;return r=(r<<8n)+BigInt(e[t]),r=(r<<8n)+BigInt(e[t+1]),r=(r<<8n)+BigInt(e[t+2]),r=(r<<8n)+BigInt(e[t+3]),r=(r<<8n)+BigInt(e[t+4]),r=(r<<8n)+BigInt(e[t+5]),r=(r<<8n)+BigInt(e[t+6]),r=(r<<8n)+BigInt(e[t+7]),r}}const pb=e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")};function yb(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function Ay(e){typeof e=="number"?yb(e):pb(e)}function ii(e,t,n){Ay(e),n===void 0&&(n=0),t===void 0&&(t=new Uint8Array(Tn(e)));let r=0;return e<253?(t.set([Number(e)],n),r=1):e<=65535?(t.set([253],n),ab(t,n+1,Number(e),"LE"),r=3):e<=4294967295?(t.set([254],n),ub(t,n+1,Number(e),"LE"),r=5):(t.set([255],n),fb(t,n+1,BigInt(e),"LE"),r=9),{buffer:t,bytes:r}}function Ps(e,t){t===void 0&&(t=0);const n=e.at(t);if(n===void 0)throw new Error("buffer too small");if(n<253)return{numberValue:n,bigintValue:BigInt(n),bytes:1};if(n===253){const r=lb(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:3}}else if(n===254){const r=hb(e,t+1,"LE");return{numberValue:r,bigintValue:BigInt(r),bytes:5}}else{const r=db(e,t+1,"LE");return{numberValue:r<=Number.MAX_SAFE_INTEGER?Number(r):null,bigintValue:r,bytes:9}}}function Tn(e){return Ay(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const gb=9007199254740991;function wb(e,t){if(typeof e!="number"&&typeof e!="bigint")throw new Error("cannot write a non-number as a number");if(e<0&&e<BigInt(0))throw new Error("specified a negative value for writing an unsigned value");if(e>t&&e>BigInt(t))throw new Error("RangeError: value out of range");if(Math.floor(Number(e))!==Number(e))throw new Error("value has a fractional component")}function il(e){if(e.length<1)return e;let t=e.length-1,n=0;for(let r=0;r<e.length/2;r++)n=e[r],e[r]=e[t],e[t]=n,t--;return e}function Lh(e){const t=new Uint8Array(e.length);return t.set(e),t}class Ft{buffer;offset;static withCapacity(t){return new Ft(new Uint8Array(t))}constructor(t,n=0){this.buffer=t,this.offset=n,rt(Gn([qe,ar]),[t,n])}writeUInt8(t){this.offset=dn(this.buffer,this.offset,t)}writeInt32(t){this.offset=Zp(this.buffer,this.offset,t,"LE")}writeInt64(t){this.offset=Jp(this.buffer,this.offset,BigInt(t),"LE")}writeUInt32(t){this.offset=Ko(this.buffer,this.offset,t,"LE")}writeUInt64(t){this.offset=zw(this.buffer,this.offset,BigInt(t),"LE")}writeVarInt(t){const{bytes:n}=ii(t,this.buffer,this.offset);this.offset+=n}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.buffer.set(t,this.offset),this.offset+=t.length}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(n=>this.writeVarSlice(n))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}class mb{buffer;offset;constructor(t,n=0){this.buffer=t,this.offset=n,rt(Gn([qe,ar]),[t,n])}readUInt8(){const t=mr(this.buffer,this.offset);return this.offset++,t}readInt32(){const t=Zw(this.buffer,this.offset,"LE");return this.offset+=4,t}readUInt32(){const t=Is(this.buffer,this.offset,"LE");return this.offset+=4,t}readInt64(){const t=Qp(this.buffer,this.offset,"LE");return this.offset+=8,t}readVarInt(){const{bigintValue:t,bytes:n}=Ps(this.buffer,this.offset);return this.offset+=n,t}readSlice(t){wb(t,gb);const n=Number(t);if(this.buffer.length<this.offset+n)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+n);return this.offset+=n,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),n=[];for(let r=0;r<t;r++)n.push(this.readVarSlice());return n}}const vy=192,bb=128,Eb=e=>"left"in e&&"right"in e;function bf(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const n=(e.length-33)/32;let r=t;for(let i=0;i<n;i++){const s=e.slice(33+32*i,65+32*i);he(r,s)<0?r=_f(r,s):r=_f(s,r)}return r}function Ef(e){if(el(e))return{hash:hr(e)};const t=[Ef(e[0]),Ef(e[1])];t.sort((i,s)=>he(i.hash,s.hash));const[n,r]=t;return{hash:_f(n.hash,r.hash),left:n,right:r}}function Zc(e,t){if(Eb(e)){const n=Zc(e.left,t);if(n!==void 0)return[...n,e.right.hash];const r=Zc(e.right,t);if(r!==void 0)return[...r,e.left.hash]}else if(he(e.hash,t)===0)return[]}function hr(e){const t=e.version||vy;return Ra("TapLeaf",it([Uint8Array.from([t]),Sb(e.output)]))}function _b(e,t){return Ra("TapTweak",it(t?[e,t]:[e]))}function wc(e,t){if(!(e instanceof Uint8Array)||e.length!==32||t&&t.length!==32)return null;const n=_b(e,t),r=mf().xOnlyPointAddTweak(e,n);return!r||r.xOnlyPubkey===null?null:{parity:r.parity,x:Uint8Array.from(r.xOnlyPubkey)}}function _f(e,t){return Ra("TapBranch",it([e,t]))}function Sb(e){const t=Tn(e.length),n=new Uint8Array(t);return ii(e.length,n),it([n,e])}const jh=Ke,Wh=1,Tb=80;function Yo(e,t){if(!e.address&&!e.output&&!e.pubkey&&!e.internalPubkey&&!(e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),rt(ri(yt({address:Ki(),input:Et(0),network:yt({}),output:Et(34),internalPubkey:Et(32),hash:Et(32),pubkey:Et(32),signature:Qf([Et(64),Et(65)]),witness:cn(qe),scriptTree:Mn(cy,"Taptree is not of type isTaptree"),redeem:ri(yt({output:qe,redeemVersion:sn(),witness:cn(qe)})),redeemVersion:sn()})),e);const n=_n(()=>sl(e.address)),r=_n(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===Tb?e.witness.slice(0,-1):e.witness.slice()}),i=_n(()=>{if(e.scriptTree)return Ef(e.scriptTree);if(e.hash)return{hash:e.hash}}),s=e.network||vn,o={name:"p2tr",network:s};if(Ee(o,"address",()=>{if(!o.pubkey)return;const c=Vt.bech32m.toWords(o.pubkey);return c.unshift(Wh),Vt.bech32m.encode(s.bech32,c)}),Ee(o,"hash",()=>{const c=i();if(c)return c.hash;const a=r();if(a&&a.length>1){const u=a[a.length-1],f=u[0]&Rc,l=a[a.length-2],p=hr({output:l,version:f});return bf(u,p)}return null}),Ee(o,"output",()=>{if(o.pubkey)return Zt([jh.OP_1,o.pubkey])}),Ee(o,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:vy),Ee(o,"redeem",()=>{const c=r();if(!(!c||c.length<2))return{output:c[c.length-2],witness:c.slice(0,-2),redeemVersion:c[c.length-1][0]&Rc}}),Ee(o,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return n().data;if(o.internalPubkey){const c=wc(o.internalPubkey,o.hash);if(c)return c.x}}),Ee(o,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const c=r();if(c&&c.length>1)return c[c.length-1].slice(1,33)}),Ee(o,"signature",()=>{if(e.signature)return e.signature;const c=r();if(!(!c||c.length!==1))return c[0]}),Ee(o,"witness",()=>{if(e.witness)return e.witness;const c=i();if(c&&e.redeem&&e.redeem.output&&e.internalPubkey){const a=hr({output:e.redeem.output,version:o.redeemVersion}),u=Zc(c,a);if(!u)return;const f=wc(e.internalPubkey,c.hash);if(!f)return;const l=it([Uint8Array.from([o.redeemVersion|f.parity]),e.internalPubkey].concat(u));return[e.redeem.output,l]}if(e.signature)return[e.signature]}),t.validate){let c=Uint8Array.from([]);if(e.address){if(s&&s.bech32!==n().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(n().version!==Wh)throw new TypeError("Invalid address version");if(n().data.length!==32)throw new TypeError("Invalid address data");c=n().data}if(e.pubkey){if(c.length>0&&he(c,e.pubkey)!==0)throw new TypeError("Pubkey mismatch");c=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==jh.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(c.length>0&&he(c,e.output.slice(2))!==0)throw new TypeError("Pubkey mismatch");c=e.output.slice(2)}if(e.internalPubkey){const f=wc(e.internalPubkey,o.hash);if(c.length>0&&he(c,f.x)!==0)throw new TypeError("Pubkey mismatch");c=f.x}if(c&&c.length&&!mf().isXOnlyPoint(c))throw new TypeError("Invalid pubkey for p2tr");const a=i();if(e.hash&&a&&he(e.hash,a.hash)!==0)throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&a){const f=hr({output:e.redeem.output,version:o.redeemVersion});if(!Zc(a,f))throw new TypeError("Redeem script not in tree")}const u=r();if(e.redeem&&o.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==o.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(ct(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(o.redeem.output&&he(e.redeem.output,o.redeem.output)!==0)throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&o.redeem.witness&&!ho(e.redeem.witness,o.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(u.length===1){if(e.signature&&he(e.signature,u[0])!==0)throw new TypeError("Signature mismatch")}else{const f=u[u.length-1];if(f.length<33)throw new TypeError(`The control-block length is too small. Got ${f.length}, expected min 33.`);if((f.length-33)%32!==0)throw new TypeError(`The control-block length of ${f.length} is incorrect!`);const l=(f.length-33)/32;if(l>128)throw new TypeError(`The script path is too long. Got ${l}, expected max 128.`);const p=f.slice(1,33);if(e.internalPubkey&&he(e.internalPubkey,p)!==0)throw new TypeError("Internal pubkey mismatch");if(!mf().isXOnlyPoint(p))throw new TypeError("Invalid internalPubkey for p2tr witness");const y=f[0]&Rc,g=u[u.length-2],w=hr({output:g,version:y}),E=bf(f,w),_=wc(p,E);if(!_)throw new TypeError("Invalid outputKey for p2tr witness");if(c.length&&he(c,_.x)!==0)throw new TypeError("Pubkey mismatch for p2tr witness");if(_.parity!==(f[0]&1))throw new Error("Incorrect parity")}}return Object.assign(o,e)}const By=40,Iy=2,Oy=16,Py=2,ky=80,Ny="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function xb(e,t){const n=e.slice(2);if(n.length<Iy||n.length>By)throw new TypeError("Invalid program length for segwit address");const r=e[0]-ky;if(r<Py||r>Oy)throw new TypeError("Invalid version for segwit address");if(e[1]!==n.length)throw new TypeError("Invalid script for segwit address");return console.warn(Ny),Ab(n,r,t.bech32)}function Uy(e){const t=po.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");const n=mr(t,0),r=t.slice(1);return{version:n,hash:r}}function sl(e){let t,n;try{t=Vt.bech32.decode(e)}catch{}if(t){if(n=t.words[0],n!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=Vt.bech32m.decode(e),n=t.words[0],n===0)throw new TypeError(e+" uses wrong encoding");const r=Vt.bech32.fromWords(t.words.slice(1));return{version:n,prefix:t.prefix,data:Uint8Array.from(r)}}function Ab(e,t,n){const r=Vt.bech32.toWords(e);return r.unshift(t),t===0?Vt.bech32.encode(n,r):Vt.bech32m.encode(n,r)}function vb(e,t){t=t||vn;try{return Wo({output:e,network:t}).address}catch{}try{return Go({output:e,network:t}).address}catch{}try{return Xo({output:e,network:t}).address}catch{}try{return zo({output:e,network:t}).address}catch{}try{return Yo({output:e,network:t}).address}catch{}try{return xb(e,t)}catch{}throw new Error(bm(e)+" has no matching Address")}function Ry(e,t){t=t||vn;let n,r;try{n=Uy(e)}catch{}if(n){if(n.version===t.pubKeyHash)return Wo({hash:n.hash}).output;if(n.version===t.scriptHash)return Go({hash:n.hash}).output}else{try{r=sl(e)}catch{}if(r){if(r.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(r.version===0){if(r.data.length===20)return Xo({hash:r.data}).output;if(r.data.length===32)return zo({hash:r.data}).output}else if(r.version===1){if(r.data.length===32)return Yo({pubkey:r.data}).output}else if(r.version>=Py&&r.version<=Oy&&r.data.length>=Iy&&r.data.length<=By)return console.warn(Ny),Zt([r.version+ky,r.data])}}throw new Error(e+" has no matching Script")}function Wn(e){const t=e.length;return Tn(t)+t}function Bb(e){const t=e.length;return Tn(t)+e.reduce((n,r)=>n+Wn(r),0)}const Gr=new Uint8Array(0),Gh=[],Su=Tr("0000000000000000000000000000000000000000000000000000000000000000"),Dh=Tr("0000000000000000000000000000000000000000000000000000000000000001"),Ib=Tr("ffffffffffffffff"),Ob={script:Gr,valueBuffer:Ib};function Pb(e){return e.value!==void 0}let ht=class Ge{static DEFAULT_SEQUENCE=4294967295;static SIGHASH_DEFAULT=0;static SIGHASH_ALL=1;static SIGHASH_NONE=2;static SIGHASH_SINGLE=3;static SIGHASH_ANYONECANPAY=128;static SIGHASH_OUTPUT_MASK=3;static SIGHASH_INPUT_MASK=128;static ADVANCED_TRANSACTION_MARKER=0;static ADVANCED_TRANSACTION_FLAG=1;static fromBuffer(t,n){const r=new mb(t),i=new Ge;i.version=r.readInt32();const s=r.readUInt8(),o=r.readUInt8();let c=!1;s===Ge.ADVANCED_TRANSACTION_MARKER&&o===Ge.ADVANCED_TRANSACTION_FLAG?c=!0:r.offset-=2;const a=r.readVarInt();for(let f=0;f<a;++f)i.ins.push({hash:r.readSlice(32),index:r.readUInt32(),script:r.readVarSlice(),sequence:r.readUInt32(),witness:Gh});const u=r.readVarInt();for(let f=0;f<u;++f)i.outs.push({value:r.readInt64(),script:r.readVarSlice()});if(c){for(let f=0;f<a;++f)i.ins[f].witness=r.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=r.readUInt32(),n)return i;if(r.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return Ge.fromBuffer(Tr(t),!1)}static isCoinbaseHash(t){rt(Ih,t);for(let n=0;n<32;++n)if(t[n]!==0)return!1;return!0}version=1;locktime=0;ins=[];outs=[];isCoinbase(){return this.ins.length===1&&Ge.isCoinbaseHash(this.ins[0].hash)}addInput(t,n,r,i){return rt(Gn([Ih,ar,wf(Xc(ar)),wf(Xc(qe))]),[t,n,r,i]),r==null&&(r=Ge.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:n,script:i||Gr,sequence:r,witness:Gh})-1}addOutput(t,n){return rt(Gn([qe,mu]),[t,n]),this.outs.push({script:t,value:n})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),n=this.byteLength(!0);return t*3+n}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const n=t&&this.hasWitnesses();return(n?10:8)+Tn(this.ins.length)+Tn(this.outs.length)+this.ins.reduce((r,i)=>r+40+Wn(i.script),0)+this.outs.reduce((r,i)=>r+8+Wn(i.script),0)+(n?this.ins.reduce((r,i)=>r+Bb(i.witness),0):0)}clone(){const t=new Ge;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(n=>({hash:n.hash,index:n.index,script:n.script,sequence:n.sequence,witness:n.witness})),t.outs=this.outs.map(n=>({script:n.script,value:n.value})),t}hashForSignature(t,n,r){if(rt(Gn([ar,qe,sn()]),[t,n,r]),t>=this.ins.length)return Dh;const i=Zt(ct(n).filter(c=>c!==Ke.OP_CODESEPARATOR)),s=this.clone();if((r&31)===Ge.SIGHASH_NONE)s.outs=[],s.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)});else if((r&31)===Ge.SIGHASH_SINGLE){if(t>=this.outs.length)return Dh;s.outs.length=t+1;for(let c=0;c<t;c++)s.outs[c]=Ob;s.ins.forEach((c,a)=>{a!==t&&(c.sequence=0)})}r&Ge.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(c=>{c.script=Gr}),s.ins[t].script=i);const o=new Uint8Array(s.byteLength(!1)+4);return Zp(o,o.length-4,r,"LE"),s.__toBuffer(o,0,!1),li(o)}hashForWitnessV1(t,n,r,i,s,o){if(rt(Gn([ar,cn(qe),cn(mu),ar]),[t,n,r,i]),r.length!==this.ins.length||n.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const c=i===Ge.SIGHASH_DEFAULT?Ge.SIGHASH_ALL:i&Ge.SIGHASH_OUTPUT_MASK,u=(i&Ge.SIGHASH_INPUT_MASK)===Ge.SIGHASH_ANYONECANPAY,f=c===Ge.SIGHASH_NONE,l=c===Ge.SIGHASH_SINGLE;let p=Gr,y=Gr,g=Gr,w=Gr,E=Gr;if(!u){let T=Ft.withCapacity(36*this.ins.length);this.ins.forEach(I=>{T.writeSlice(I.hash),T.writeUInt32(I.index)}),p=zt(T.end()),T=Ft.withCapacity(8*this.ins.length),r.forEach(I=>T.writeInt64(I)),y=zt(T.end()),T=Ft.withCapacity(n.map(Wn).reduce((I,A)=>I+A)),n.forEach(I=>T.writeVarSlice(I)),g=zt(T.end()),T=Ft.withCapacity(4*this.ins.length),this.ins.forEach(I=>T.writeUInt32(I.sequence)),w=zt(T.end())}if(f||l){if(l&&t<this.outs.length){const T=this.outs[t],I=Ft.withCapacity(8+Wn(T.script));I.writeInt64(T.value),I.writeVarSlice(T.script),E=zt(I.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const T=this.outs.map(A=>8+Wn(A.script)).reduce((A,U)=>A+U),I=Ft.withCapacity(T);this.outs.forEach(A=>{I.writeInt64(A.value),I.writeVarSlice(A.script)}),E=zt(I.end())}const _=(s?2:0)+(o?1:0),S=174-(u?49:0)-(f?32:0)+(o?32:0)+(s?37:0),m=Ft.withCapacity(S);if(m.writeUInt8(i),m.writeInt32(this.version),m.writeUInt32(this.locktime),m.writeSlice(p),m.writeSlice(y),m.writeSlice(g),m.writeSlice(w),f||l||m.writeSlice(E),m.writeUInt8(_),u){const T=this.ins[t];m.writeSlice(T.hash),m.writeUInt32(T.index),m.writeInt64(r[t]),m.writeVarSlice(n[t]),m.writeUInt32(T.sequence)}else m.writeUInt32(t);if(o){const T=Ft.withCapacity(Wn(o));T.writeVarSlice(o),m.writeSlice(zt(T.end()))}return l&&m.writeSlice(E),s&&(m.writeSlice(s),m.writeUInt8(0),m.writeUInt32(4294967295)),Ra("TapSighash",it([Uint8Array.from([0]),m.end()]))}hashForWitnessV0(t,n,r,i){rt(Gn([ar,qe,mu,ar]),[t,n,r,i]);let s=Uint8Array.from([]),o,c=Su,a=Su,u=Su;if(i&Ge.SIGHASH_ANYONECANPAY||(s=new Uint8Array(36*this.ins.length),o=new Ft(s,0),this.ins.forEach(l=>{o.writeSlice(l.hash),o.writeUInt32(l.index)}),a=li(s)),!(i&Ge.SIGHASH_ANYONECANPAY)&&(i&31)!==Ge.SIGHASH_SINGLE&&(i&31)!==Ge.SIGHASH_NONE&&(s=new Uint8Array(4*this.ins.length),o=new Ft(s,0),this.ins.forEach(l=>{o.writeUInt32(l.sequence)}),u=li(s)),(i&31)!==Ge.SIGHASH_SINGLE&&(i&31)!==Ge.SIGHASH_NONE){const l=this.outs.reduce((p,y)=>p+8+Wn(y.script),0);s=new Uint8Array(l),o=new Ft(s,0),this.outs.forEach(p=>{o.writeInt64(p.value),o.writeVarSlice(p.script)}),c=li(s)}else if((i&31)===Ge.SIGHASH_SINGLE&&t<this.outs.length){const l=this.outs[t];s=new Uint8Array(8+Wn(l.script)),o=new Ft(s,0),o.writeInt64(l.value),o.writeVarSlice(l.script),c=li(s)}s=new Uint8Array(156+Wn(n)),o=new Ft(s,0);const f=this.ins[t];return o.writeInt32(this.version),o.writeSlice(a),o.writeSlice(u),o.writeSlice(f.hash),o.writeUInt32(f.index),o.writeVarSlice(n),o.writeInt64(r),o.writeUInt32(f.sequence),o.writeSlice(c),o.writeUInt32(this.locktime),o.writeUInt32(i),li(s)}getHash(t){return t&&this.isCoinbase()?new Uint8Array(32):li(this.__toBuffer(void 0,void 0,t))}getId(){return _e(il(this.getHash(!1)))}toBuffer(t,n){return this.__toBuffer(t,n,!0)}toHex(){return _e(this.toBuffer(void 0,void 0))}setInputScript(t,n){rt(Gn([sn(),qe]),[t,n]),this.ins[t].script=n}setWitness(t,n){rt(Gn([sn(),cn(qe)]),[t,n]),this.ins[t].witness=n}__toBuffer(t,n,r=!1){t||(t=new Uint8Array(this.byteLength(r)));const i=new Ft(t,n||0);i.writeInt32(this.version);const s=r&&this.hasWitnesses();return s&&(i.writeUInt8(Ge.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(Ge.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{Pb(o)?i.writeInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),n!==void 0?t.slice(n,i.offset):t}};var zn;(function(e){e[e.UNSIGNED_TX=0]="UNSIGNED_TX",e[e.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(zn||(zn={}));var ye;(function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(ye||(ye={}));var ft;(function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(ft||(ft={}));const kb=e=>[...Array(e).keys()];function Nb(e){if(e.key[0]!==zn.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+_e(e.key));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+_e(e.key));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),n={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const r of kb(e.value.length/4-1)){const i=Is(e.value,r*4+4,"LE"),s=!!(i&2147483648),o=i&2147483647;n.path+="/"+o.toString(10)+(s?"'":"")}return n}function Ub(e){const t=new Uint8Array([zn.GLOBAL_XPUB]),n=it([t,e.extendedPubkey]),r=e.path.split("/"),i=new Uint8Array(r.length*4);i.set(e.masterFingerprint,0);let s=4;return r.slice(1).forEach(o=>{const c=o.slice(-1)==="'";let a=2147483647&parseInt(c?o.slice(0,-1):o,10);c&&(a+=2147483648),Ko(i,s,a,"LE"),s+=4}),{key:n,value:i}}const Rb="{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }";function Cb(e){const t=e.extendedPubkey,n=e.masterFingerprint,r=e.path;return t instanceof Uint8Array&&t.length===78&&[2,3].indexOf(t[45])>-1&&n instanceof Uint8Array&&n.length===4&&typeof r=="string"&&!!r.match(/^m(\/\d+'?)*$/)}function Hb(e,t,n){const r=_e(t.extendedPubkey);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.extendedPubkey,t.extendedPubkey)).length===0)}const Fb=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:Hb,check:Cb,decode:Nb,encode:Ub,expected:Rb},Symbol.toStringTag,{value:"Module"}));function Mb(e){return{key:new Uint8Array([zn.UNSIGNED_TX]),value:e.toBuffer()}}const qb=Object.freeze(Object.defineProperty({__proto__:null,encode:Mb},Symbol.toStringTag,{value:"Module"}));function Vb(e){if(e.key[0]!==ye.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+_e(e.key));return e.value}function $b(e){return{key:new Uint8Array([ye.FINAL_SCRIPTSIG]),value:e}}const Kb="Uint8Array";function Lb(e){return e instanceof Uint8Array}function jb(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}const Wb=Object.freeze(Object.defineProperty({__proto__:null,canAdd:jb,check:Lb,decode:Vb,encode:$b,expected:Kb},Symbol.toStringTag,{value:"Module"}));function Gb(e){if(e.key[0]!==ye.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+_e(e.key));return e.value}function Db(e){return{key:new Uint8Array([ye.FINAL_SCRIPTWITNESS]),value:e}}const Xb="Uint8Array";function zb(e){return e instanceof Uint8Array}function Yb(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}const Zb=Object.freeze(Object.defineProperty({__proto__:null,canAdd:Yb,check:zb,decode:Gb,encode:Db,expected:Xb},Symbol.toStringTag,{value:"Module"}));function Jb(e){if(e.key[0]!==ye.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+_e(e.key));return e.value}function Qb(e){return{key:new Uint8Array([ye.NON_WITNESS_UTXO]),value:e}}const e2="Uint8Array";function t2(e){return e instanceof Uint8Array}function n2(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}const r2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:n2,check:t2,decode:Jb,encode:Qb,expected:e2},Symbol.toStringTag,{value:"Module"}));function i2(e){if(e.key[0]!==ye.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+_e(e.key));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+_e(e.key));return{pubkey:e.key.slice(1),signature:e.value}}function s2(e){const t=new Uint8Array([ye.PARTIAL_SIG]);return{key:it([t,e.pubkey]),value:e.signature}}const o2="{ pubkey: Uint8Array; signature: Uint8Array; }";function c2(e){return e.pubkey instanceof Uint8Array&&e.signature instanceof Uint8Array&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&a2(e.signature)}function a2(e){if(!(e instanceof Uint8Array)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const n=e[3+t+2];return!(n>33||n<1||e.length!==3+t+2+n+2)}function u2(e,t,n){const r=_e(t.pubkey);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.pubkey,t.pubkey)===0).length===0)}const f2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:u2,check:c2,decode:i2,encode:s2,expected:o2},Symbol.toStringTag,{value:"Module"}));function l2(e){if(e.key[0]!==ye.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+_e(e.key));return Lw(e.value)}function h2(e){return{key:new Uint8Array([ye.POR_COMMITMENT]),value:jw(e)}}const d2="string";function p2(e){return typeof e=="string"}function y2(e,t){return!!e&&!!t&&e.porCommitment===void 0}const g2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:y2,check:p2,decode:l2,encode:h2,expected:d2},Symbol.toStringTag,{value:"Module"}));function w2(e){if(e.key[0]!==ye.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+_e(e.key));return Number(Is(e.value,0,"LE"))}function m2(e){const t=Uint8Array.from([ye.SIGHASH_TYPE]),n=new Uint8Array(4);return Ko(n,0,e,"LE"),{key:t,value:n}}const b2="number";function E2(e){return typeof e=="number"}function _2(e,t){return!!e&&!!t&&e.sighashType===void 0}const S2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:_2,check:E2,decode:w2,encode:m2,expected:b2},Symbol.toStringTag,{value:"Module"}));function T2(e){if(e.key[0]!==ye.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+_e(e.key));if(!Cy(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}function x2(e){return{key:Uint8Array.from([ye.TAP_KEY_SIG]),value:e}}const A2="Uint8Array";function Cy(e){return e instanceof Uint8Array&&(e.length===64||e.length===65)}function v2(e,t){return!!e&&!!t&&e.tapKeySig===void 0}const B2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:v2,check:Cy,decode:T2,encode:x2,expected:A2},Symbol.toStringTag,{value:"Module"}));function I2(e){if(e.key[0]!==ye.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+_e(e.key));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+_e(e.key));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+_e(e.key));const n=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:n,leafVersion:t}}function O2(e){const t=Uint8Array.from([ye.TAP_LEAF_SCRIPT]),n=Uint8Array.from([e.leafVersion]);return{key:it([t,e.controlBlock]),value:it([e.script,n])}}const P2="{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }";function k2(e){return e.controlBlock instanceof Uint8Array&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&e.script instanceof Uint8Array}function N2(e,t,n){const r=_e(t.controlBlock);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.controlBlock,t.controlBlock)===0).length===0)}const U2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:N2,check:k2,decode:I2,encode:O2,expected:P2},Symbol.toStringTag,{value:"Module"}));function R2(e){if(e.key[0]!==ye.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+_e(e.key));if(!Hy(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}function C2(e){return{key:Uint8Array.from([ye.TAP_MERKLE_ROOT]),value:e}}const H2="Uint8Array";function Hy(e){return e instanceof Uint8Array&&e.length===32}function F2(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}const M2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:F2,check:Hy,decode:R2,encode:C2,expected:H2},Symbol.toStringTag,{value:"Module"}));function q2(e){if(e.key[0]!==ye.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+_e(e.key));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+_e(e.key));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+_e(e.key));const t=e.key.slice(1,33),n=e.key.slice(33);return{pubkey:t,leafHash:n,signature:e.value}}function V2(e){const t=Uint8Array.from([ye.TAP_SCRIPT_SIG]);return{key:it([t,e.pubkey,e.leafHash]),value:e.signature}}const $2="{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }";function K2(e){return e.pubkey instanceof Uint8Array&&e.leafHash instanceof Uint8Array&&e.signature instanceof Uint8Array&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}function L2(e,t,n){const r=_e(t.pubkey)+_e(t.leafHash);return n.has(r)?!1:(n.add(r),e.filter(i=>he(i.pubkey,t.pubkey)===0&&he(i.leafHash,t.leafHash)===0).length===0)}const j2=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:L2,check:K2,decode:q2,encode:V2,expected:$2},Symbol.toStringTag,{value:"Module"}));function W2(e){if(e.key[0]!==ye.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+_e(e.key));const t=Qp(e.value,0,"LE");let n=8;const{numberValue:r,bytes:i}=Ps(e.value,n);n+=i;const s=e.value.slice(n);if(s.length!==r)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:s,value:t}}function G2(e){const{script:t,value:n}=e,r=Tn(t.length),i=new Uint8Array(8+r+t.length);return Jp(i,0,BigInt(n),"LE"),ii(t.length,i,8),i.set(t,8+r),{key:Uint8Array.from([ye.WITNESS_UTXO]),value:i}}const D2="{ script: Uint8Array; value: bigint; }";function X2(e){return e.script instanceof Uint8Array&&typeof e.value=="bigint"}function z2(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}const Y2=Object.freeze(Object.defineProperty({__proto__:null,canAdd:z2,check:X2,decode:W2,encode:G2,expected:D2},Symbol.toStringTag,{value:"Module"}));function Z2(e){if(e.key[0]!==ft.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+_e(e.key));let t=0;const n=[];for(;t<e.value.length;){const r=e.value[t++],i=e.value[t++],{numberValue:s,bytes:o}=Ps(e.value,t);t+=o,n.push({depth:r,leafVersion:i,script:e.value.slice(t,t+s)}),t+=s}return{leaves:n}}function J2(e){const t=Uint8Array.from([ft.TAP_TREE]),n=[].concat(...e.leaves.map(r=>[Uint8Array.of(r.depth,r.leafVersion),ii(BigInt(r.script.length)).buffer,r.script]));return{key:t,value:it(n)}}const Q2="{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }";function eE(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&t.script instanceof Uint8Array)}function tE(e,t){return!!e&&!!t&&e.tapTree===void 0}const nE=Object.freeze(Object.defineProperty({__proto__:null,canAdd:tE,check:eE,decode:Z2,encode:J2,expected:Q2},Symbol.toStringTag,{value:"Module"})),rE=e=>[...Array(e).keys()],iE=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function ol(e,t=iE){function n(c){if(c.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+_e(c.key));const a=c.key.slice(1);if(!t(a))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+_e(c.key));if(c.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const u={masterFingerprint:c.value.slice(0,4),pubkey:a,path:"m"};for(const f of rE(c.value.length/4-1)){const l=Is(c.value,f*4+4,"LE"),p=!!(l&2147483648),y=l&2147483647;u.path+="/"+y.toString(10)+(p?"'":"")}return u}function r(c){const a=Uint8Array.from([e]),u=it([a,c.pubkey]),f=c.path.split("/"),l=new Uint8Array(f.length*4);l.set(c.masterFingerprint,0);let p=4;return f.slice(1).forEach(y=>{const g=y.slice(-1)==="'";let w=2147483647&parseInt(g?y.slice(0,-1):y,10);g&&(w+=2147483648),Ko(l,p,w,"LE"),p+=4}),{key:u,value:l}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; }";function s(c){return c.pubkey instanceof Uint8Array&&c.masterFingerprint instanceof Uint8Array&&typeof c.path=="string"&&t(c.pubkey)&&c.masterFingerprint.length===4}function o(c,a,u){const f=_e(a.pubkey);return u.has(f)?!1:(u.add(f),c.filter(l=>he(l.pubkey,a.pubkey)===0).length===0)}return{decode:n,encode:r,check:s,expected:i,canAddToArray:o}}function cl(e){return t;function t(n){let r;if(e.includes(n.key[0])&&(r=n.key.slice(1),!(r.length===33||r.length===65)||![2,3,4].includes(r[0])))throw new Error("Format Error: invalid pubkey in key 0x"+_e(n.key));return r}}function Fy(e){function t(o){if(o.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+_e(o.key));return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array}function s(o,c){return!!o&&!!c&&o.redeemScript===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}const sE=e=>e.length===32;function My(e){const t=ol(e,sE);function n(o){const{numberValue:c,bytes:a}=Ps(o.value),u=t.decode({key:o.key,value:o.value.slice(a+Number(c)*32)}),f=new Array(Number(c));for(let l=0,p=a;l<c;l++,p+=32)f[l]=o.value.slice(p,p+32);return{...u,leafHashes:f}}function r(o){const c=t.encode(o),a=Tn(o.leafHashes.length),u=new Uint8Array(a);ii(o.leafHashes.length,u);const f=it([u,...o.leafHashes,c.value]);return{...c,value:f}}const i="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; leafHashes: Uint8Array[]; }";function s(o){return Array.isArray(o.leafHashes)&&o.leafHashes.every(c=>c instanceof Uint8Array&&c.length===32)&&t.check(o)}return{decode:n,encode:r,check:s,expected:i,canAddToArray:t.canAddToArray}}function qy(e){function t(o){if(o.key[0]!==e||o.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+_e(o.key));if(o.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array&&o.length===32}function s(o,c){return!!o&&!!c&&o.tapInternalKey===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}function Vy(e){function t(o){if(o.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+_e(o.key));return o.value}function n(o){return{key:Uint8Array.from([e]),value:o}}const r="Uint8Array";function i(o){return o instanceof Uint8Array}function s(o,c){return!!o&&!!c&&o.witnessScript===void 0}return{decode:t,encode:n,check:i,expected:r,canAdd:s}}const al={unsignedTx:qb,globalXpub:Fb,checkPubkey:cl([])},gt={nonWitnessUtxo:r2,partialSig:f2,sighashType:S2,finalScriptSig:Wb,finalScriptWitness:Zb,porCommitment:g2,witnessUtxo:Y2,bip32Derivation:ol(ye.BIP32_DERIVATION),redeemScript:Fy(ye.REDEEM_SCRIPT),witnessScript:Vy(ye.WITNESS_SCRIPT),checkPubkey:cl([ye.PARTIAL_SIG,ye.BIP32_DERIVATION]),tapKeySig:B2,tapScriptSig:j2,tapLeafScript:U2,tapBip32Derivation:My(ye.TAP_BIP32_DERIVATION),tapInternalKey:qy(ye.TAP_INTERNAL_KEY),tapMerkleRoot:M2},ur={bip32Derivation:ol(ft.BIP32_DERIVATION),redeemScript:Fy(ft.REDEEM_SCRIPT),witnessScript:Vy(ft.WITNESS_SCRIPT),checkPubkey:cl([ft.BIP32_DERIVATION]),tapBip32Derivation:My(ft.TAP_BIP32_DERIVATION),tapTree:nE,tapInternalKey:qy(ft.TAP_INTERNAL_KEY)},oE=Object.freeze(Object.defineProperty({__proto__:null,globals:al,inputs:gt,outputs:ur},Symbol.toStringTag,{value:"Module"})),Jc=e=>[...Array(e).keys()];function Xh(e){const t=e.map(cE);return t.push(Uint8Array.from([0])),it(t)}function cE(e){const t=e.key.length,n=e.value.length,r=Tn(t),i=Tn(n),s=new Uint8Array(r+t+i+n);return ii(t,s,0),s.set(e.key,r),ii(n,s,r+t),s.set(e.value,r+t+i),s}function aE(e,t){let n=0;function r(){const{numberValue:E,bytes:_}=Ps(e,n);n+=_;const S=e.slice(n,n+Number(E));return n+=Number(E),S}function i(){const E=Is(e,n,"BE");return n+=4,E}function s(){const E=mr(e,n);return n+=1,E}function o(){const E=r(),_=r();return{key:E,value:_}}function c(){if(n>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const E=mr(e,n)===0;return E&&n++,E}if(i()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(s()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const a=[],u={};for(;!c();){const E=o(),_=_e(E.key);if(u[_])throw new Error("Format Error: Keys must be unique for global keymap: key "+_);u[_]=1,a.push(E)}const f=a.filter(E=>E.key[0]===zn.UNSIGNED_TX);if(f.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const l=t(f[0].value),{inputCount:p,outputCount:y}=l.getInputOutputCounts(),g=[],w=[];for(const E of Jc(p)){const _={},S=[];for(;!c();){const m=o(),T=_e(m.key);if(_[T])throw new Error("Format Error: Keys must be unique for each input: input index "+E+" key "+T);_[T]=1,S.push(m)}g.push(S)}for(const E of Jc(y)){const _={},S=[];for(;!c();){const m=o(),T=_e(m.key);if(_[T])throw new Error("Format Error: Keys must be unique for each output: output index "+E+" key "+T);_[T]=1,S.push(m)}w.push(S)}return $y(l,{globalMapKeyVals:a,inputKeyVals:g,outputKeyVals:w})}function Ht(e,t,n){if(he(t,Uint8Array.from([n])))throw new Error(`Format Error: Invalid ${e} key: ${_e(t)}`)}function $y(e,{globalMapKeyVals:t,inputKeyVals:n,outputKeyVals:r}){const i={unsignedTx:e};let s=0;for(const f of t)switch(f.key[0]){case zn.UNSIGNED_TX:if(Ht("global",f.key,zn.UNSIGNED_TX),s>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");s++;break;case zn.GLOBAL_XPUB:i.globalXpub===void 0&&(i.globalXpub=[]),i.globalXpub.push(al.globalXpub.decode(f));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(f)}const o=n.length,c=r.length,a=[],u=[];for(const f of Jc(o)){const l={};for(const p of n[f])switch(gt.checkPubkey(p),p.key[0]){case ye.NON_WITNESS_UTXO:if(Ht("input",p.key,ye.NON_WITNESS_UTXO),l.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");l.nonWitnessUtxo=gt.nonWitnessUtxo.decode(p);break;case ye.WITNESS_UTXO:if(Ht("input",p.key,ye.WITNESS_UTXO),l.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");l.witnessUtxo=gt.witnessUtxo.decode(p);break;case ye.PARTIAL_SIG:l.partialSig===void 0&&(l.partialSig=[]),l.partialSig.push(gt.partialSig.decode(p));break;case ye.SIGHASH_TYPE:if(Ht("input",p.key,ye.SIGHASH_TYPE),l.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");l.sighashType=gt.sighashType.decode(p);break;case ye.REDEEM_SCRIPT:if(Ht("input",p.key,ye.REDEEM_SCRIPT),l.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");l.redeemScript=gt.redeemScript.decode(p);break;case ye.WITNESS_SCRIPT:if(Ht("input",p.key,ye.WITNESS_SCRIPT),l.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");l.witnessScript=gt.witnessScript.decode(p);break;case ye.BIP32_DERIVATION:l.bip32Derivation===void 0&&(l.bip32Derivation=[]),l.bip32Derivation.push(gt.bip32Derivation.decode(p));break;case ye.FINAL_SCRIPTSIG:Ht("input",p.key,ye.FINAL_SCRIPTSIG),l.finalScriptSig=gt.finalScriptSig.decode(p);break;case ye.FINAL_SCRIPTWITNESS:Ht("input",p.key,ye.FINAL_SCRIPTWITNESS),l.finalScriptWitness=gt.finalScriptWitness.decode(p);break;case ye.POR_COMMITMENT:Ht("input",p.key,ye.POR_COMMITMENT),l.porCommitment=gt.porCommitment.decode(p);break;case ye.TAP_KEY_SIG:Ht("input",p.key,ye.TAP_KEY_SIG),l.tapKeySig=gt.tapKeySig.decode(p);break;case ye.TAP_SCRIPT_SIG:l.tapScriptSig===void 0&&(l.tapScriptSig=[]),l.tapScriptSig.push(gt.tapScriptSig.decode(p));break;case ye.TAP_LEAF_SCRIPT:l.tapLeafScript===void 0&&(l.tapLeafScript=[]),l.tapLeafScript.push(gt.tapLeafScript.decode(p));break;case ye.TAP_BIP32_DERIVATION:l.tapBip32Derivation===void 0&&(l.tapBip32Derivation=[]),l.tapBip32Derivation.push(gt.tapBip32Derivation.decode(p));break;case ye.TAP_INTERNAL_KEY:Ht("input",p.key,ye.TAP_INTERNAL_KEY),l.tapInternalKey=gt.tapInternalKey.decode(p);break;case ye.TAP_MERKLE_ROOT:Ht("input",p.key,ye.TAP_MERKLE_ROOT),l.tapMerkleRoot=gt.tapMerkleRoot.decode(p);break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(p)}a.push(l)}for(const f of Jc(c)){const l={};for(const p of r[f])switch(ur.checkPubkey(p),p.key[0]){case ft.REDEEM_SCRIPT:if(Ht("output",p.key,ft.REDEEM_SCRIPT),l.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");l.redeemScript=ur.redeemScript.decode(p);break;case ft.WITNESS_SCRIPT:if(Ht("output",p.key,ft.WITNESS_SCRIPT),l.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");l.witnessScript=ur.witnessScript.decode(p);break;case ft.BIP32_DERIVATION:l.bip32Derivation===void 0&&(l.bip32Derivation=[]),l.bip32Derivation.push(ur.bip32Derivation.decode(p));break;case ft.TAP_INTERNAL_KEY:Ht("output",p.key,ft.TAP_INTERNAL_KEY),l.tapInternalKey=ur.tapInternalKey.decode(p);break;case ft.TAP_TREE:Ht("output",p.key,ft.TAP_TREE),l.tapTree=ur.tapTree.decode(p);break;case ft.TAP_BIP32_DERIVATION:l.tapBip32Derivation===void 0&&(l.tapBip32Derivation=[]),l.tapBip32Derivation.push(ur.tapBip32Derivation.decode(p));break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(p)}u.push(l)}return{globalMap:i,inputs:a,outputs:u}}function uE({globalMap:e,inputs:t,outputs:n}){const{globalKeyVals:r,inputKeyVals:i,outputKeyVals:s}=Sf({globalMap:e,inputs:t,outputs:n}),o=Xh(r),c=l=>l.length===0?[Uint8Array.from([0])]:l.map(Xh),a=c(i),u=c(s),f=new Uint8Array(5);return f.set([112,115,98,116,255],0),it([f,o].concat(a,u))}const fE=(e,t)=>he(e.key,t.key);function Tu(e,t){const n=new Set,r=Object.entries(e).reduce((s,[o,c])=>{if(o==="unknownKeyVals")return s;const a=t[o];if(a===void 0)return s;const u=(Array.isArray(c)?c:[c]).map(a.encode);return u.map(l=>_e(l.key)).forEach(l=>{if(n.has(l))throw new Error("Serialize Error: Duplicate key: "+l);n.add(l)}),s.concat(u)},[]),i=e.unknownKeyVals?e.unknownKeyVals.filter(s=>!n.has(_e(s.key))):[];return r.concat(i).sort(fE)}function Sf({globalMap:e,inputs:t,outputs:n}){return{globalKeyVals:Tu(e,al),inputKeyVals:t.map(r=>Tu(r,gt)),outputKeyVals:n.map(r=>Tu(r,ur))}}function lE(e){const t=e[0],n=Sf(t),r=e.slice(1);if(r.length===0)throw new Error("Combine: Nothing to combine");const i=zh(t);if(i===void 0)throw new Error("Combine: Self missing transaction");const s=Ji(n.globalKeyVals),o=n.inputKeyVals.map(Ji),c=n.outputKeyVals.map(Ji);for(const a of r){const u=zh(a);if(u===void 0||he(u.toBuffer(),i.toBuffer())!==0)throw new Error("Combine: One of the Psbts does not have the same transaction.");const f=Sf(a);Ji(f.globalKeyVals).forEach(xu(s,n.globalKeyVals,f.globalKeyVals)),f.inputKeyVals.map(Ji).forEach((g,w)=>g.forEach(xu(o[w],n.inputKeyVals[w],f.inputKeyVals[w]))),f.outputKeyVals.map(Ji).forEach((g,w)=>g.forEach(xu(c[w],n.outputKeyVals[w],f.outputKeyVals[w])))}return $y(i,{globalMapKeyVals:n.globalKeyVals,inputKeyVals:n.inputKeyVals,outputKeyVals:n.outputKeyVals})}function xu(e,t,n){return r=>{if(e.has(r))return;const i=n.filter(s=>_e(s.key)===r)[0];t.push(i),e.add(r)}}function zh(e){return e.globalMap.unsignedTx}function Ji(e){const t=new Set;return e.forEach(n=>{const r=_e(n.key);if(t.has(r))throw new Error("Combine: KeyValue Map keys should be unique");t.add(r)}),t}function It(e,t){const n=e[t];if(n===void 0)throw new Error(`No input #${t}`);return n}function yo(e,t){const n=e[t];if(n===void 0)throw new Error(`No output #${t}`);return n}function Au(e,t,n){if(e.key[0]<n)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&t.filter(r=>he(r.key,e.key)===0).length!==0)throw new Error(`Duplicate Key: ${_e(e.key)}`)}function vu(e){let t=0;return Object.keys(e).forEach(n=>{Number(isNaN(Number(n)))&&t++}),t}function hE(e,t){let n=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const r=!!t.redeemScript,i=!!t.witnessScript,s=!r||!!t.finalScriptSig,o=!i||!!t.finalScriptWitness,c=!!t.finalScriptSig||!!t.finalScriptWitness;n=s&&o&&c}if(n===!1)throw new Error(`Input #${e} has too much or too little data to clean`)}function Yh(e,t,n,r){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${n} and got ${JSON.stringify(r)}`)}function ul(e){return(t,n)=>{for(const r of Object.keys(t)){const i=t[r],{canAdd:s,canAddToArray:o,check:c,expected:a}=oE[e+"s"][r]||{},u=!!o;if(c)if(u){if(!Array.isArray(i)||n[r]&&!Array.isArray(n[r]))throw new Error(`Key type ${r} must be an array`);i.every(c)||Yh(e,r,a,i);const f=n[r]||[],l=new Set;if(!i.every(p=>o(f,p,l)))throw new Error("Can not add duplicate data to array");n[r]=f.concat(i)}else{if(c(i)||Yh(e,r,a,i),!s(n,i))throw new Error(`Can not add duplicate data to ${e}`);n[r]=i}}}}const dE=ul("global"),Ky=ul("input"),Ly=ul("output");function pE(e,t){const n=e.length-1,r=It(e,n);Ky(t,r)}function yE(e,t){const n=e.length-1,r=yo(e,n);Ly(t,r)}let Zh=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,n){const r=Yp(t);return this.fromBuffer(r,n)}static fromHex(t,n){const r=Tr(t);return this.fromBuffer(r,n)}static fromBuffer(t,n){const r=aE(t,n),i=new this(r.globalMap.unsignedTx);return Object.assign(i,r),i}toBase64(){const t=this.toBuffer();return Dw(t)}toHex(){const t=this.toBuffer();return _e(t)}toBuffer(){return uE(this)}updateGlobal(t){return dE(t,this.globalMap),this}updateInput(t,n){const r=It(this.inputs,t);return Ky(n,r),this}updateOutput(t,n){const r=yo(this.outputs,t);return Ly(n,r),this}addUnknownKeyValToGlobal(t){return Au(t,this.globalMap.unknownKeyVals,vu(zn)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,n){const r=It(this.inputs,t);return Au(n,r.unknownKeyVals,vu(ye)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(n),this}addUnknownKeyValToOutput(t,n){const r=yo(this.outputs,t);return Au(n,r.unknownKeyVals,vu(ft)),r.unknownKeyVals||(r.unknownKeyVals=[]),r.unknownKeyVals.push(n),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const n=t.unknownKeyVals||[],r=this.inputs.length-1;if(!Array.isArray(n))throw new Error("unknownKeyVals must be an Array");return n.forEach(i=>this.addUnknownKeyValToInput(r,i)),pE(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const n=t.unknownKeyVals||[],r=this.outputs.length-1;if(!Array.isArray(n))throw new Error("unknownKeyVals must be an Array");return n.forEach(i=>this.addUnknownKeyValToOutput(r,i)),yE(this.outputs,t),this}clearFinalizedInput(t){const n=It(this.inputs,t);hE(t,n);for(const r of Object.keys(n))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(r)||delete n[r];return this}combine(...t){const n=lE([this].concat(t));return Object.assign(this,n),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};function Li(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const gE=Li(Na),wE=Li(dy),mE=Li(Wo),Ca=Li(Xo),Jh=Li(zo),jy=Li(Go),Wy=Li(Yo);function Qc(e){let t=new Uint8Array(0);function n(o){t=it([t,o])}function r(o){const c=t.length,a=Tn(o);t=it([t,new Uint8Array(a)]),ii(o,t,c)}function i(o){r(o.length),n(o)}function s(o){r(o.length),o.forEach(i)}return s(e),t}function Gy(e,t){const n=wr(e),r=e.slice(1,33),i=ct(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:he(e,s)===0||he(n,s)===0||he(r,s)===0)}function Ha(e,t){return Gy(e,t)!==-1}function bE(e,t){return EE(e).some(r=>Dy(r,co.decode,t))}function Dy(e,t,n){const{hashType:r}=t(e),i=[];switch(r&ht.SIGHASH_ANYONECANPAY&&i.push("addInput"),r&31){case ht.SIGHASH_ALL:break;case ht.SIGHASH_SINGLE:case ht.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(n)===-1}function EE(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=_E(e)}else t=e.partialSig;return t.map(n=>n.signature)}function _E(e){const t=e.finalScriptSig?ct(e.finalScriptSig)||[]:[],n=e.finalScriptWitness?ct(e.finalScriptWitness)||[]:[];return t.concat(n).filter(r=>r instanceof Uint8Array&&br(r)).map(r=>({signature:r}))}const Cc=e=>e.length===32?e:e.slice(1,33);function Qh(e,t,n){const r=CE(t,e,n);try{const s=UE(t,r).concat(r.script).concat(r.controlBlock);return{finalScriptWitness:Qc(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}function mc(e,t){const n=t?Uint8Array.from([t]):Uint8Array.from([]);return it([e,n])}function kn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&Wy(e.witnessUtxo.script))}function Bu(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function ed(e,t,n){PE(e,t,n),NE(e,t,n)}function td(e,t,n){kE(e,t,n),SE(e,t)}function SE(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const n=t.tapInternalKey||e.tapInternalKey,r=t.tapTree||e.tapTree;if(n){const{script:i}=e,s=TE(n,r);if(i&&he(s,i)!==0)throw new Error("Error adding output. Script or address mismatch.")}}function TE(e,t){const n=t&&xE(t.leaves),{output:r}=Yo({internalPubkey:e,scriptTree:n});return r}function xE(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:OE(e)}function AE(e,t){return BE(e).some(r=>Dy(r,vE,t))}function vE(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||ht.SIGHASH_DEFAULT}}function BE(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(n=>n.signature)),!t.length){const n=IE(e.finalScriptWitness);n&&t.push(n)}return t}function IE(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function OE(e){let t;for(const n of e)if(t=Tf(n,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Tf(e,t,n=0){if(n>bb)throw new Error("Max taptree depth exceeded.");if(e.depth===n)return t?void 0:{output:e.script,version:e.leafVersion};if(el(t))return;const r=Tf(e,t&&t[0],n+1);if(r)return[r,t&&t[1]];const i=Tf(e,t&&t[1],n+1);if(i)return[t&&t[0],i]}function PE(e,t,n){const r=kn(e)&&fs(t),i=fs(e)&&kn(t),s=e===t&&kn(t)&&fs(t);if(r||i||s)throw new Error(`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`)}function kE(e,t,n){const r=Bu(e)&&fs(t),i=fs(e)&&Bu(t),s=e===t&&Bu(t)&&fs(t);if(r||i||s)throw new Error(`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`)}function NE(e,t,n){if(t.tapMerkleRoot){const r=(t.tapLeafScript||[]).every(s=>Iu(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Iu(s,t.tapMerkleRoot));if(!r||!i)throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>Iu(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`)}function Iu(e,t){if(!t)return!0;const n=hr({output:e.script,version:e.leafVersion}),r=bf(e.controlBlock,n);return he(r,t)===0}function UE(e,t){const n=hr({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(r=>he(r.leafHash,n)===0).map(r=>RE(t.script,r)).sort((r,i)=>i.positionInScript-r.positionInScript).map(r=>r.signature)}function RE(e,t){return Object.assign({positionInScript:Gy(t.pubkey,e)},t)}function CE(e,t,n){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const r=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>HE(i,e.tapScriptSig,n));if(!r)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return r}function HE(e,t,n){const r=hr({output:e.script,version:e.leafVersion});return(!n||he(r,n)===0)&&t.find(s=>he(s.leafHash,r)===0)!==void 0}function fs(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const FE={network:vn,maximumFeeRate:5e3};class ea{data;static fromBase64(t,n={}){const r=Yp(t);return this.fromBuffer(r,n)}static fromHex(t,n={}){const r=Tr(t);return this.fromBuffer(r,n)}static fromBuffer(t,n={}){const r=Zh.fromBuffer(t,ME),i=new ea(n,r);return LE(i.__CACHE.__TX,i.__CACHE),i}__CACHE;opts;constructor(t={},n=new Zh(new Xy)){this.data=n,this.opts=Object.assign({},FE,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const r=(i,s,o,c)=>Object.defineProperty(i,s,{enumerable:o,writable:c});r(this,"__CACHE",!1,!0),r(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:Lh(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let n;try{n=vb(t.script,this.opts.network)}catch{}return{script:Lh(t.script),value:t.value,address:n}})}combine(...t){return this.data.combine(...t.map(n=>n.data)),this}clone(){const t=ea.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){bc(t),this.opts.maximumFeeRate=t}setVersion(t){bc(t),$s(this.data.inputs,"setVersion");const n=this.__CACHE;return n.__TX.version=t,n.__EXTRACTED_TX=void 0,this}setLocktime(t){bc(t),$s(this.data.inputs,"setLocktime");const n=this.__CACHE;return n.__TX.locktime=t,n.__EXTRACTED_TX=void 0,this}setInputSequence(t,n){bc(n),$s(this.data.inputs,"setInputSequence");const r=this.__CACHE;if(r.__TX.ins.length<=t)throw new Error("Input index too high");return r.__TX.ins[t].sequence=n,r.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(n=>this.addInput(n)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");ed(t,t,"addInput"),$s(this.data.inputs,"addInput"),t.witnessScript&&ta(t.witnessScript);const n=this.__CACHE;this.data.addInput(t);const r=n.__TX.ins[n.__TX.ins.length-1];Zy(n,r);const i=this.data.inputs.length-1,s=this.data.inputs[i];return s.nonWitnessUtxo&&Af(this.__CACHE,s,i),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(n=>this.addOutput(n)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");$s(this.data.inputs,"addOutput");const{address:n}=t;if(typeof n=="string"){const{network:i}=this.opts,s=Ry(n,i);t=Object.assign({},t,{script:s})}td(t,t,"addOutput");const r=this.__CACHE;return this.data.addOutput(t),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(zy))throw new Error("Not finalized");const n=this.__CACHE;if(t||VE(this,n,this.opts),n.__EXTRACTED_TX)return n.__EXTRACTED_TX;const r=n.__TX.clone();return rg(this.data.inputs,r,n,!0),r}getFeeRate(){return od("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return od("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return It(this.data.inputs,0),Ks(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,n){const r=It(this.data.inputs,t);return kn(r)?this._finalizeTaprootInput(t,r,void 0,n):this._finalizeInput(t,r,n)}finalizeTaprootInput(t,n,r=Qh){const i=It(this.data.inputs,t);if(kn(i))return this._finalizeTaprootInput(t,i,n,r);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,n,r=jE){const{script:i,isP2SH:s,isP2WSH:o,isSegwit:c}=XE(t,n,this.__CACHE);if(!i)throw new Error(`No script found for input #${t}`);$E(n);const{finalScriptSig:a,finalScriptWitness:u}=r(t,n,i,c,s,o);if(a&&this.data.updateInput(t,{finalScriptSig:a}),u&&this.data.updateInput(t,{finalScriptWitness:u}),!a&&!u)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,n,r,i=Qh){if(!n.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(n.tapKeySig){const s=Yo({output:n.witnessUtxo.script,signature:n.tapKeySig}),o=Qc(s.witness);this.data.updateInput(t,{finalScriptWitness:o})}else{const{finalScriptWitness:s}=i(t,n,r);this.data.updateInput(t,{finalScriptWitness:s})}return this.data.clearFinalizedInput(t),this}getInputType(t){const n=It(this.data.inputs,t),r=ig(t,n,this.__CACHE),i=Ma(r,t,"input",n.redeemScript||QE(n.finalScriptSig),n.witnessScript||e_(n.finalScriptWitness)),s=i.type==="raw"?"":i.type+"-",o=og(i.meaningfulScript);return s+o}inputHasPubkey(t,n){const r=It(this.data.inputs,t);return ZE(n,r,t,this.__CACHE)}inputHasHDKey(t,n){const r=It(this.data.inputs,t),i=rd(n);return!!r.bip32Derivation&&r.bip32Derivation.some(i)}outputHasPubkey(t,n){const r=yo(this.data.outputs,t);return JE(n,r,t,this.__CACHE)}outputHasHDKey(t,n){const r=yo(this.data.outputs,t),i=rd(n);return!!r.bip32Derivation&&r.bip32Derivation.some(i)}validateSignaturesOfAllInputs(t){return It(this.data.inputs,0),Ks(this.data.inputs.length).map(r=>this.validateSignaturesOfInput(r,t)).reduce((r,i)=>i===!0&&r,!0)}validateSignaturesOfInput(t,n,r){const i=this.data.inputs[t];return kn(i)?this.validateSignaturesOfTaprootInput(t,n,r):this._validateSignaturesOfInput(t,n,r)}_validateSignaturesOfInput(t,n,r){const i=this.data.inputs[t],s=(i||{}).partialSig;if(!i||!s||s.length<1)throw new Error("No signatures to validate");if(typeof n!="function")throw new Error("Need validator function to validate signatures");const o=r?s.filter(l=>he(l.pubkey,r)===0):s;if(o.length<1)throw new Error("No signatures for this pubkey");const c=[];let a,u,f;for(const l of o){const p=co.decode(l.signature),{hash:y,script:g}=f!==p.hashType?Qy(t,Object.assign({},i,{sighashType:p.hashType}),this.__CACHE,!0):{hash:a,script:u};f=p.hashType,a=y,u=g,Yy(l.pubkey,g,"verify"),c.push(n(l.pubkey,y,p.signature))}return c.every(l=>l===!0)}validateSignaturesOfTaprootInput(t,n,r){const i=this.data.inputs[t],s=(i||{}).tapKeySig,o=(i||{}).tapScriptSig;if(!i&&!s&&!(o&&!o.length))throw new Error("No signatures to validate");if(typeof n!="function")throw new Error("Need validator function to validate signatures");r=r&&Cc(r);const c=r?xf(t,i,this.data.inputs,r,this.__CACHE):GE(t,i,this.data.inputs,this.__CACHE);if(!c.length)throw new Error("No signatures for this pubkey");const a=c.find(f=>!f.leafHash);let u=0;if(s&&a){if(!n(a.pubkey,a.hash,ad(s)))return!1;u++}if(o)for(const f of o){const l=c.find(p=>he(p.pubkey,f.pubkey)===0);if(l){if(!n(f.pubkey,l.hash,ad(f.signature)))return!1;u++}}return u>0}signAllInputsHD(t,n=[ht.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const r=[];for(const i of Ks(this.data.inputs.length))try{this.signInputHD(i,t,n),r.push(!0)}catch{r.push(!1)}if(r.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,n=[ht.SIGHASH_ALL]){return new Promise((r,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const s=[],o=[];for(const c of Ks(this.data.inputs.length))o.push(this.signInputHDAsync(c,t,n).then(()=>{s.push(!0)},()=>{s.push(!1)}));return Promise.all(o).then(()=>{if(s.every(c=>c===!1))return i(new Error("No inputs were signed"));r()})})}signInputHD(t,n,r=[ht.SIGHASH_ALL]){if(!n||!n.publicKey||!n.fingerprint)throw new Error("Need HDSigner to sign input");return ud(t,this.data.inputs,n).forEach(s=>this.signInput(t,s,r)),this}signInputHDAsync(t,n,r=[ht.SIGHASH_ALL]){return new Promise((i,s)=>{if(!n||!n.publicKey||!n.fingerprint)return s(new Error("Need HDSigner to sign input"));const c=ud(t,this.data.inputs,n).map(a=>this.signInputAsync(t,a,r));return Promise.all(c).then(()=>{i()}).catch(s)})}signAllInputs(t,n){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const r=[];for(const i of Ks(this.data.inputs.length))try{this.signInput(i,t,n),r.push(!0)}catch{r.push(!1)}if(r.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,n){return new Promise((r,i)=>{if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));const s=[],o=[];for(const[c]of this.data.inputs.entries())o.push(this.signInputAsync(c,t,n).then(()=>{s.push(!0)},()=>{s.push(!1)}));return Promise.all(o).then(()=>{if(s.every(c=>c===!1))return i(new Error("No inputs were signed"));r()})})}signInput(t,n,r){if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const i=It(this.data.inputs,t);return kn(i)?this._signTaprootInput(t,i,n,void 0,r):this._signInput(t,n,r)}signTaprootInput(t,n,r,i){if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const s=It(this.data.inputs,t);if(kn(s))return this._signTaprootInput(t,s,n,r,i);throw new Error(`Input #${t} is not of type Taproot.`)}_signInput(t,n,r=[ht.SIGHASH_ALL]){const{hash:i,sighashType:s}=cd(this.data.inputs,t,n.publicKey,this.__CACHE,r),o=[{pubkey:n.publicKey,signature:co.encode(n.sign(i),s)}];return this.data.updateInput(t,{partialSig:o}),this}_signTaprootInput(t,n,r,i,s=[ht.SIGHASH_DEFAULT]){const o=this.checkTaprootHashesForSig(t,n,r,i,s),c=o.filter(u=>!u.leafHash).map(u=>mc(r.signSchnorr(u.hash),n.sighashType))[0],a=o.filter(u=>!!u.leafHash).map(u=>({pubkey:Cc(r.publicKey),signature:mc(r.signSchnorr(u.hash),n.sighashType),leafHash:u.leafHash}));return c&&this.data.updateInput(t,{tapKeySig:c}),a.length&&this.data.updateInput(t,{tapScriptSig:a}),this}signInputAsync(t,n,r){return Promise.resolve().then(()=>{if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const i=It(this.data.inputs,t);return kn(i)?this._signTaprootInputAsync(t,i,n,void 0,r):this._signInputAsync(t,n,r)})}signTaprootInputAsync(t,n,r,i){return Promise.resolve().then(()=>{if(!n||!n.publicKey)throw new Error("Need Signer to sign input");const s=It(this.data.inputs,t);if(kn(s))return this._signTaprootInputAsync(t,s,n,r,i);throw new Error(`Input #${t} is not of type Taproot.`)})}_signInputAsync(t,n,r=[ht.SIGHASH_ALL]){const{hash:i,sighashType:s}=cd(this.data.inputs,t,n.publicKey,this.__CACHE,r);return Promise.resolve(n.sign(i)).then(o=>{const c=[{pubkey:n.publicKey,signature:co.encode(o,s)}];this.data.updateInput(t,{partialSig:c})})}async _signTaprootInputAsync(t,n,r,i,s=[ht.SIGHASH_DEFAULT]){const o=this.checkTaprootHashesForSig(t,n,r,i,s),c=[],a=o.filter(f=>!f.leafHash)[0];if(a){const f=Promise.resolve(r.signSchnorr(a.hash)).then(l=>({tapKeySig:mc(l,n.sighashType)}));c.push(f)}const u=o.filter(f=>!!f.leafHash);if(u.length){const f=u.map(l=>Promise.resolve(r.signSchnorr(l.hash)).then(p=>({tapScriptSig:[{pubkey:Cc(r.publicKey),signature:mc(p,n.sighashType),leafHash:l.leafHash}]})));c.push(...f)}return Promise.all(c).then(f=>{f.forEach(l=>this.data.updateInput(t,l))})}checkTaprootHashesForSig(t,n,r,i,s){if(typeof r.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${t}.`);const o=xf(t,n,this.data.inputs,r.publicKey,this.__CACHE,i,s);if(!o||!o.length)throw new Error(`Can not sign for input #${t} with the key ${_e(r.publicKey)}`);return o}toBuffer(){return Ou(this.__CACHE),this.data.toBuffer()}toHex(){return Ou(this.__CACHE),this.data.toHex()}toBase64(){return Ou(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,n){return n.witnessScript&&ta(n.witnessScript),ed(this.data.inputs[t],n,"updateInput"),this.data.updateInput(t,n),n.nonWitnessUtxo&&Af(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,n){const r=this.data.outputs[t];return td(r,n,"updateOutput"),this.data.updateOutput(t,n),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,n){return this.data.addUnknownKeyValToInput(t,n),this}addUnknownKeyValToOutput(t,n){return this.data.addUnknownKeyValToOutput(t,n),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}}const ME=e=>new Xy(e);class Xy{tx;constructor(t=Uint8Array.from([2,0,0,0,0,0,0,0,0,0])){this.tx=ht.fromBuffer(t),KE(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!(t.hash instanceof Uint8Array)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const n=typeof t.hash=="string"?il(Tr(t.hash)):t.hash;this.tx.addInput(n,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!(t.script instanceof Uint8Array)||typeof t.value!="bigint")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}}function qE(e,t,n){switch(n){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return nd(1,e.partialSig);case"multisig":const r=Na({output:t});return nd(r.m,e.partialSig,r.pubkeys);default:return!1}}function Ou(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function nd(e,t,n){if(!t)return!1;let r;if(n?r=n.map(i=>{const s=t_(i);return t.find(o=>he(o.pubkey,s)===0)}).filter(i=>!!i):r=t,r.length>e)throw new Error("Too many signatures");return r.length===e}function zy(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function rd(e){return t=>!(he(e.fingerprint,t.masterFingerprint)||he(e.derivePath(t.path).publicKey,t.pubkey))}function bc(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function VE(e,t,n){const r=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),s=r*i;if(r>=n.maximumFeeRate)throw new Error(`Warning: You are paying around ${(s/1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function $s(e,t){e.forEach(n=>{if(kn(n)?AE(n,t):bE(n,t))throw new Error("Can not modify transaction, signatures exist.")})}function $E(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:n}=e;t.forEach(r=>{const{hashType:i}=co.decode(r.signature);if(n!==i)throw new Error("Signature sighash does not match input sighash type")})}function Yy(e,t,n){if(!Ha(e,t))throw new Error(`Can not ${n} for this input with the key ${_e(e)}`)}function KE(e){if(!e.ins.every(n=>n.script&&n.script.length===0&&n.witness&&n.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function LE(e,t){e.ins.forEach(n=>{Zy(t,n)})}function Zy(e,t){const n=_e(il(Uint8Array.from(t.hash)))+":"+t.index;if(e.__TX_IN_CACHE[n])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[n]=1}function Jy(e,t){return(n,r,i,s)=>{const o=e({redeem:{output:i}}).output;if(he(r,o))throw new Error(`${t} for ${s} #${n} doesn't match the scriptPubKey in the prevout`)}}const id=Jy(Go,"Redeem script"),sd=Jy(zo,"Witness script");function od(e,t,n,r){if(!n.every(zy))throw new Error(`PSBT must be finalized to calculate ${t}`);if(e==="__FEE_RATE"&&r.__FEE_RATE)return r.__FEE_RATE;if(e==="__FEE"&&r.__FEE)return r.__FEE;let i,s=!0;if(r.__EXTRACTED_TX?(i=r.__EXTRACTED_TX,s=!1):i=r.__TX.clone(),rg(n,i,r,s),e==="__FEE_RATE")return r.__FEE_RATE;if(e==="__FEE")return r.__FEE}function jE(e,t,n,r,i,s){const o=og(n);if(!qE(t,n,o))throw new Error(`Can not finalize input #${e}`);return WE(n,o,t.partialSig,r,i,s)}function WE(e,t,n,r,i,s){let o,c;const a=DE(e,t,n),u=s?zo({redeem:a}):null,f=i?Go({redeem:u||a}):null;return r?(u?c=Qc(u.witness):c=Qc(a.witness),f&&(o=f.input)):f?o=f.input:o=a.input,{finalScriptSig:o,finalScriptWitness:c}}function cd(e,t,n,r,i){const s=It(e,t),{hash:o,sighashType:c,script:a}=Qy(t,s,r,!1,i);return Yy(n,a,"sign"),{hash:o,sighashType:c}}function Qy(e,t,n,r,i){const s=n.__TX,o=t.sighashType||ht.SIGHASH_ALL;tg(o,i);let c,a;if(t.nonWitnessUtxo){const l=Fa(n,t,e),p=s.ins[e].hash,y=l.getHash();if(he(p,y)!==0)throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const g=s.ins[e].index;a=l.outs[g]}else if(t.witnessUtxo)a=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:u,type:f}=Ma(a.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)c=s.hashForWitnessV0(e,u,a.value,o);else if(Ca(u)){const l=Wo({hash:u.slice(2)}).output;c=s.hashForWitnessV0(e,l,a.value,o)}else{if(t.nonWitnessUtxo===void 0&&n.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${_e(u)}`);!r&&n.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
10
10
|
*********************
|
|
11
11
|
PROCEED WITH CAUTION!
|
|
12
|
-
*********************`),c=s.hashForSignature(e,u,o)}return{script:u,sighashType:o,hash:c}}function GE(e,t,n,r){const i=[];if(t.tapInternalKey){const o=eg(e,t,r);o&&i.push(o)}if(t.tapScriptSig){const o=t.tapScriptSig.map(c=>c.pubkey);i.push(...o)}return i.map(o=>Tf(e,t,n,o,r)).flat()}function eg(e,t,n){const{script:r}=ul(e,t,n);return Wy(r)?r.subarray(2,34):null}function ad(e){return e.length===64?e:e.subarray(0,64)}function Tf(e,t,n,r,i,s,o){const c=i.__TX,a=t.sighashType||ht.SIGHASH_DEFAULT;tg(a,o);const u=n.map((g,w)=>ul(w,g,i)),f=u.map(g=>g.script),l=u.map(g=>g.value),p=[];if(t.tapInternalKey&&!s){const g=eg(e,t,i)||Uint8Array.from([]);if(he(Rc(r),g)===0){const w=c.hashForWitnessV1(e,f,l,a);p.push({pubkey:r,hash:w})}}const y=(t.tapLeafScript||[]).filter(g=>Ca(r,g.script)).map(g=>{const w=hr({output:g.script,version:g.leafVersion});return Object.assign({hash:w},g)}).filter(g=>!s||he(s,g.hash)===0).map(g=>{const w=c.hashForWitnessV1(e,f,l,a,g.hash);return{pubkey:r,hash:w,leafHash:g.hash}});return p.concat(y)}function tg(e,t){if(t&&t.indexOf(e)<0){const n=YE(e);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${n}`)}}function DE(e,t,n){let r;switch(t){case"multisig":const i=zE(e,n);r=Pa({output:e,signatures:i});break;case"pubkey":r=dy({output:e,signature:n[0].signature});break;case"pubkeyhash":r=Wo({output:e,pubkey:n[0].pubkey,signature:n[0].signature});break;case"witnesspubkeyhash":r=Ua({output:e,pubkey:n[0].pubkey,signature:n[0].signature});break}return r}function XE(e,t,n){const r=n.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const s=Ha(n,t,e),o=r.ins[e].index;i.script=s.outs[o].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||Ra(i.script))&&(i.isSegwit=!0),i}function ud(e,t,n){const r=It(t,e);if(!r.bip32Derivation||r.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const i=r.bip32Derivation.map(o=>{if(he(o.masterFingerprint,n.fingerprint)===0)return o}).filter(o=>!!o);if(i.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(o=>{const c=n.derivePath(o.path);if(he(o.pubkey,c.publicKey)!==0)throw new Error("pubkey did not match bip32Derivation");return c})}function zE(e,t){return Pa({output:e}).pubkeys.map(r=>(t.filter(i=>he(i.pubkey,r)===0)[0]||{}).signature).filter(r=>!!r)}function ng(e){let t=0;function n(o){return t+=o,e.slice(t-o,t)}function r(){const o=Os(e,t);return t+=Tn(o.bigintValue),o.numberValue}function i(){return n(r())}function s(){const o=r(),c=[];for(let a=0;a<o;a++)c.push(i());return c}return s()}function YE(e){let t=e&ht.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(e&31){case ht.SIGHASH_ALL:t+="SIGHASH_ALL";break;case ht.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case ht.SIGHASH_NONE:t+="SIGHASH_NONE";break}return t}function xf(e,t,n){e.__NON_WITNESS_UTXO_BUF_CACHE[n]=t.nonWitnessUtxo;const r=ht.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[n]=r;const i=e,s=n;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const o=i.__NON_WITNESS_UTXO_BUF_CACHE[s],c=i.__NON_WITNESS_UTXO_TX_CACHE[s];if(o!==void 0)return o;{const a=c.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[s]=a,a}},set(o){i.__NON_WITNESS_UTXO_BUF_CACHE[s]=o}})}function rg(e,t,n,r){let i=0n;e.forEach((a,u)=>{if(r&&a.finalScriptSig&&(t.ins[u].script=a.finalScriptSig),r&&a.finalScriptWitness&&(t.ins[u].witness=ng(a.finalScriptWitness)),a.witnessUtxo)i+=a.witnessUtxo.value;else if(a.nonWitnessUtxo){const f=Ha(n,a,u),l=t.ins[u].index,p=f.outs[l];i+=p.value}});const s=t.outs.reduce((a,u)=>a+u.value,0n),o=i-s;if(o<0)throw new Error("Outputs are spending more than Inputs");const c=t.virtualSize();n.__FEE=o,n.__EXTRACTED_TX=t,n.__FEE_RATE=Math.floor(Number(o/BigInt(c)))}function Ha(e,t,n){const r=e.__NON_WITNESS_UTXO_TX_CACHE;return r[n]||xf(e,t,n),r[n]}function ig(e,t,n){const{script:r}=ul(e,t,n);return r}function ul(e,t,n){if(t.witnessUtxo!==void 0)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(t.nonWitnessUtxo!==void 0){const i=Ha(n,t,e).outs[n.__TX.ins[e].index];return{script:i.script,value:i.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function ZE(e,t,n,r){const i=ig(n,t,r),{meaningfulScript:s}=Fa(i,n,"input",t.redeemScript,t.witnessScript);return Ca(e,s)}function JE(e,t,n,r){const i=r.__TX.outs[n].script,{meaningfulScript:s}=Fa(i,n,"output",t.redeemScript,t.witnessScript);return Ca(e,s)}function QE(e){if(!e)return;const t=ct(e);if(!t)return;const n=t[t.length-1];if(!(!(n instanceof Uint8Array)||sg(n)||n_(n)||!ct(n)))return n}function e_(e){if(!e)return;const t=ng(e),n=t[t.length-1];if(!(sg(n)||!ct(n)))return n}function t_(e){if(e.length===65){const t=e[64]&1,n=e.slice(0,33);return n[0]=2|t,n}return e.slice()}function sg(e){return e.length===33&&_m(e)}function n_(e){return br(e)}function Fa(e,t,n,r,i){const s=jy(e),o=s&&r&&Jh(r),c=Jh(e);if(s&&r===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((c||o)&&i===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let a;return o?(a=i,id(t,e,r,n),sd(t,r,i,n),ea(a)):c?(a=i,sd(t,e,i,n),ea(a)):s?(a=r,id(t,e,r,n)):a=e,{meaningfulScript:a,type:o?"p2sh-p2wsh":s?"p2sh":c?"p2wsh":"raw"}}function ea(e){if(Ra(e)||jy(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function og(e){return Ra(e)?"witnesspubkeyhash":mE(e)?"pubkeyhash":gE(e)?"multisig":wE(e)?"pubkey":"nonstandard"}function $s(e){return[...Array(e).keys()]}sb(Mw);const Yo={Mainnet:"mainnet",Testnet:"testnet"},ta="abcdefghijklmnopqrstuvwxyz234567",bs=Object.create(null);for(let e=0;e<ta.length;e++)bs[ta[e]]=e;bs[0]=bs.o;bs[1]=bs.i;function r_(e){let t=0,n=0,r="";function i(s){return t<0?n|=s>>-t:n=s<<t&248,t>3?(t-=8,1):(t<4&&(r+=ta[n>>3],t+=5),0)}for(let s=0;s<e.length;)s+=i(e[s]);return r+(t<0?ta[n>>3]:"")}function i_(e){let t=0,n=0;const r=new Uint8Array(e.length*4/3|0);let i=0;function s(o){let c=bs[o.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(o)}`);c<<=3,n|=c>>>t,t+=5,t>=8&&(r[i++]=n,t-=8,t>0?n=c<<5-t&255:n=0)}for(const o of e)s(o);return r.slice(0,i)}const s_=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function o_(e){let t=-1;for(let n=0;n<e.length;n++){const i=(e[n]^t)&255;t=s_[i]^t>>>8}return(t^-1)>>>0}const bc="__principal__",c_=2,fd=4,a_="aaaaa-aa";let $e=class is{static anonymous(){return new this(new Uint8Array([fd]))}static managementCanister(){return this.fromText(a_)}static selfAuthenticating(t){const n=Zm(t);return new this(new Uint8Array([...n,c_]))}static from(t){if(typeof t=="string")return is.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new is(t);if(is.isPrincipal(t))return new is(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(jo(t))}static fromText(t){let n=t;if(t.includes(bc)){const o=JSON.parse(t);bc in o&&(n=o[bc])}const r=n.toLowerCase().replace(/-/g,"");let i=i_(r);i=i.slice(4,i.length);const s=new this(i);if(s.toText()!==n)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${n}" may not be a valid Principal ID).`);return s}static fromUint8Array(t){return new this(t)}static isPrincipal(t){return t instanceof is||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===fd}toUint8Array(){return this._arr}toHex(){return Qe(this._arr).toUpperCase()}toText(){const t=new ArrayBuffer(4);new DataView(t).setUint32(0,o_(this._arr));const r=new Uint8Array(t),i=new Uint8Array([...r,...this._arr]),o=r_(i).match(/.{1,5}/g);if(!o)throw new Error;return o.join("-")}toString(){return this.toText()}toJSON(){return{[bc]:this.toText()}}compareTo(t){for(let n=0;n<Math.min(this._arr.length,t._arr.length);n++){if(this._arr[n]<t._arr[n])return"lt";if(this._arr[n]>t._arr[n])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){const n=this.compareTo(t);return n=="lt"||n=="eq"}gtEq(t){const n=this.compareTo(t);return n=="gt"||n=="eq"}};function Fe(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.byteLength,0));let n=0;for(const r of e)t.set(r,n),n+=r.byteLength;return t}class Ps{save(){return this._view}restore(t){if(!(t instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=t}constructor(t,n=t?.byteLength||0){if(t&&!(t instanceof Uint8Array))try{t=cg(t)}catch{throw new Error("Buffer must be a Uint8Array")}if(n<0||!Number.isInteger(n))throw new Error("Length must be a non-negative integer");if(t&&n>t.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=t||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,n)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(t){const n=this._view.subarray(0,t);return this._view=this._view.subarray(t),n.slice()}readUint8(){if(this._view.byteLength===0)return;const t=this._view[0];return this._view=this._view.subarray(1),t}write(t){if(!(t instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");const n=this._view.byteLength;this._view.byteOffset+this._view.byteLength+t.byteLength>=this._buffer.byteLength?this.alloc(t.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+t.byteLength),this._view.set(t,n)}get end(){return this._view.byteLength===0}alloc(t){if(t<=0||!Number.isInteger(t))throw new Error("Amount must be a positive integer");const n=new Uint8Array((this._buffer.byteLength+t)*1.2|0),r=new Uint8Array(n.buffer,0,this._view.byteLength+t);r.set(this._view),this._buffer=n,this._view=r}}function cg(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?cg(e.buffer):new Uint8Array(e)}function u_(e,t){if(e.byteLength!==t.byteLength)return e.byteLength-t.byteLength;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]-t[n];return 0}function f_(e){if(!(e instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(e.buffer,e.byteOffset,e.byteLength)}function l_(e){const n=new TextEncoder().encode(e);let r=0;for(const i of n)r=(r*223+i)%2**32;return r}function tn(e){if(/^_\d+_$/.test(e)||/^_0x[0-9a-fA-F]+_$/.test(e)){const t=+e.slice(1,-1);if(Number.isSafeInteger(t)&&t>=0&&t<2**32)return t}return l_(e)}function ag(e){const t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function Af(e){const t=BigInt(e);if(e<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<t}function ug(){throw new Error("unexpected end of buffer")}function Ci(e,t){return e.byteLength<t&&ug(),e.read(t)}function Hi(e){const t=e.readUint8();return t===void 0&&ug(),t}function ot(e){if(typeof e=="number"&&(e=BigInt(e)),e<BigInt(0))throw new Error("Cannot leb encode negative values.");const t=(e===BigInt(0)?0:ag(e))+1,n=new Ps(new Uint8Array(t),0);for(;;){const r=Number(e&BigInt(127));if(e/=BigInt(128),e===BigInt(0)){n.write(new Uint8Array([r]));break}else n.write(new Uint8Array([r|128]))}return n.buffer}function xt(e){let t=BigInt(1),n=BigInt(0),r;do r=Hi(e),n+=BigInt(r&127).valueOf()*t,t*=BigInt(128);while(r>=128);return n}function _t(e){typeof e=="number"&&(e=BigInt(e));const t=e<BigInt(0);t&&(e=-e-BigInt(1));const n=(e===BigInt(0)?0:ag(e))+1,r=new Ps(new Uint8Array(n),0);for(;;){const s=i(e);if(e/=BigInt(128),t&&e===BigInt(0)&&(s&64)!==0||!t&&e===BigInt(0)&&(s&64)===0){r.write(new Uint8Array([s]));break}else r.write(new Uint8Array([s|128]))}function i(s){const o=s%BigInt(128);return Number(t?BigInt(128)-o-BigInt(1):o)}return r.buffer}function Dr(e){const t=new Uint8Array(e.buffer);let n=0;for(;n<t.byteLength;n++)if(t[n]<128){if((t[n]&64)===0)return xt(e);break}const r=new Uint8Array(Ci(e,n+1));let i=BigInt(0);for(let s=r.byteLength-1;s>=0;s--)i=i*BigInt(128)+BigInt(128-(r[s]&127)-1);return-i-BigInt(1)}function h_(e,t){if(BigInt(e)<BigInt(0))throw new Error("Cannot write negative values.");return fg(e,t)}function fg(e,t){e=BigInt(e);const n=new Ps(new Uint8Array(Math.min(1,t)),0);let r=0,i=BigInt(256),s=BigInt(0),o=Number(e%i);for(n.write(new Uint8Array([o]));++r<t;)e<0&&s===BigInt(0)&&o!==0&&(s=BigInt(1)),o=Number((e/i-s)%BigInt(256)),n.write(new Uint8Array([o])),i*=BigInt(256);return n.buffer}function lg(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=BigInt(Hi(e)),r=BigInt(1),i=0;for(;++i<t;){r*=BigInt(256);const s=BigInt(Hi(e));n=n+r*s}return n}function d_(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=lg(e,t);const r=BigInt(2)**(BigInt(8)*BigInt(t-1)+BigInt(7));return n>=r&&(n-=r*BigInt(2)),n}var He;(function(e){e[e.Null=-1]="Null",e[e.Bool=-2]="Bool",e[e.Nat=-3]="Nat",e[e.Int=-4]="Int",e[e.Float32=-13]="Float32",e[e.Float64=-14]="Float64",e[e.Text=-15]="Text",e[e.Reserved=-16]="Reserved",e[e.Empty=-17]="Empty",e[e.Opt=-18]="Opt",e[e.Vector=-19]="Vector",e[e.Record=-20]="Record",e[e.Variant=-21]="Variant",e[e.Func=-22]="Func",e[e.Service=-23]="Service",e[e.Principal=-24]="Principal"})(He||(He={}));const Cc="DIDL",ld=400;function go(e,t,n){return e.map((r,i)=>n(r,t[i]))}class p_{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(t){return this._idx.has(t.name)}add(t,n){const r=this._typs.length;this._idx.set(t.name,r),this._idxRefCount.set(r,1),this._typs.push(n)}merge(t,n){const r=this._idx.get(t.name),i=this._idx.get(n);if(r===void 0)throw new Error("Missing type index for "+t);if(i===void 0)throw new Error("Missing type index for "+n);this._typs[r]=this._typs[i];const s=this._getIdxRefCount(i);this._idxRefCount.set(i,s-1),this._idx.delete(n),this._compactFromEnd()}_getIdxRefCount(t){return this._idxRefCount.get(t)||0}_compactFromEnd(){for(;this._typs.length>0;){const t=this._typs.length-1;if(this._getIdxRefCount(t)>0)break;this._typs.pop(),this._idxRefCount.delete(t)}}encode(){const t=ot(this._typs.length),n=Fe(...this._typs);return Fe(t,n)}indexOf(t){if(!this._idx.has(t))throw new Error("Missing type index for "+t);return _t(this._idx.get(t)||0)}}class y_{visitType(t,n){throw new Error("Not implemented")}visitPrimitive(t,n){return this.visitType(t,n)}visitEmpty(t,n){return this.visitPrimitive(t,n)}visitBool(t,n){return this.visitPrimitive(t,n)}visitNull(t,n){return this.visitPrimitive(t,n)}visitReserved(t,n){return this.visitPrimitive(t,n)}visitText(t,n){return this.visitPrimitive(t,n)}visitNumber(t,n){return this.visitPrimitive(t,n)}visitInt(t,n){return this.visitNumber(t,n)}visitNat(t,n){return this.visitNumber(t,n)}visitFloat(t,n){return this.visitPrimitive(t,n)}visitFixedInt(t,n){return this.visitNumber(t,n)}visitFixedNat(t,n){return this.visitNumber(t,n)}visitPrincipal(t,n){return this.visitPrimitive(t,n)}visitConstruct(t,n){return this.visitType(t,n)}visitVec(t,n,r){return this.visitConstruct(t,r)}visitOpt(t,n,r){return this.visitConstruct(t,r)}visitRecord(t,n,r){return this.visitConstruct(t,r)}visitTuple(t,n,r){const i=n.map((s,o)=>[`_${o}_`,s]);return this.visitRecord(t,i,r)}visitVariant(t,n,r){return this.visitConstruct(t,r)}visitRec(t,n,r){return this.visitConstruct(n,r)}visitFunc(t,n){return this.visitConstruct(t,n)}visitService(t,n){return this.visitConstruct(t,n)}}var ve;(function(e){e.EmptyClass="__IDL_EmptyClass__",e.UnknownClass="__IDL_UnknownClass__",e.BoolClass="__IDL_BoolClass__",e.NullClass="__IDL_NullClass__",e.ReservedClass="__IDL_ReservedClass__",e.TextClass="__IDL_TextClass__",e.IntClass="__IDL_IntClass__",e.NatClass="__IDL_NatClass__",e.FloatClass="__IDL_FloatClass__",e.FixedIntClass="__IDL_FixedIntClass__",e.FixedNatClass="__IDL_FixedNatClass__",e.VecClass="__IDL_VecClass__",e.OptClass="__IDL_OptClass__",e.RecordClass="__IDL_RecordClass__",e.TupleClass="__IDL_TupleClass__",e.VariantClass="__IDL_VariantClass__",e.RecClass="__IDL_RecClass__",e.PrincipalClass="__IDL_PrincipalClass__",e.FuncClass="__IDL_FuncClass__",e.ServiceClass="__IDL_ServiceClass__"})(ve||(ve={}));class Ma{display(){return this.name}valueToString(t){return pt(t)}buildTypeTable(t){t.has(this)||this._buildTypeTableImpl(t)}}class Bn extends Ma{checkType(t){if(this.name!==t.name)throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);return t}_buildTypeTableImpl(t){}}class ci extends Ma{checkType(t){if(t instanceof xn){const n=t.getType();if(typeof n>"u")throw new Error("type mismatch with uninitialized type");return n}throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`)}encodeType(t){return t.indexOf(this.name)}}class fl extends Bn{get typeName(){return ve.EmptyClass}static[Symbol.hasInstance](t){return t.typeName===ve.EmptyClass}accept(t,n){return t.visitEmpty(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return _t(He.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}}class hg extends Ma{get typeName(){return ve.UnknownClass}static[Symbol.hasInstance](t){return t.typeName===ve.UnknownClass}checkType(t){throw new Error("Method not implemented for unknown.")}accept(t,n){throw t.visitType(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(t,n){let r=n.decodeValue(t,n);Object(r)!==r&&(r=Object(r));let i;return n instanceof xn?i=()=>n.getType():i=()=>n,Object.defineProperty(r,"type",{value:i,writable:!0,enumerable:!1,configurable:!0}),r}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}}class dg extends Bn{get typeName(){return ve.BoolClass}static[Symbol.hasInstance](t){return t.typeName===ve.BoolClass}accept(t,n){return t.visitBool(this,n)}covariant(t){if(typeof t=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return new Uint8Array([t?1:0])}encodeType(){return _t(He.Bool)}decodeValue(t,n){switch(this.checkType(n),Hi(t)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}}class wo extends Bn{get typeName(){return ve.NullClass}static[Symbol.hasInstance](t){return t.typeName===ve.NullClass}accept(t,n){return t.visitNull(this,n)}covariant(t){if(t===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return _t(He.Null)}decodeValue(t,n){return this.checkType(n),null}get name(){return"null"}}class si extends Bn{get typeName(){return ve.ReservedClass}static[Symbol.hasInstance](t){return t.typeName===ve.ReservedClass}accept(t,n){return t.visitReserved(this,n)}covariant(t){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return _t(He.Reserved)}decodeValue(t,n){return n.name!==this.name&&n.decodeValue(t,n),null}get name(){return"reserved"}}class pg extends Bn{get typeName(){return ve.TextClass}static[Symbol.hasInstance](t){return t.typeName===ve.TextClass}accept(t,n){return t.visitText(this,n)}covariant(t){if(typeof t=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=new TextEncoder().encode(t),r=ot(n.byteLength);return Fe(r,n)}encodeType(){return _t(He.Text)}decodeValue(t,n){this.checkType(n);const r=xt(t),i=Ci(t,Number(r));return new TextDecoder("utf8",{fatal:!0}).decode(i)}get name(){return"text"}valueToString(t){return'"'+t+'"'}}class ll extends Bn{get typeName(){return ve.IntClass}static[Symbol.hasInstance](t){return t.typeName===ve.IntClass}accept(t,n){return t.visitInt(this,n)}covariant(t){if(typeof t=="bigint"||Number.isInteger(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return _t(t)}encodeType(){return _t(He.Int)}decodeValue(t,n){return this.checkType(n),Dr(t)}get name(){return"int"}valueToString(t){return t.toString()}}class hl extends Bn{get typeName(){return ve.NatClass}static[Symbol.hasInstance](t){return t.typeName===ve.NatClass}accept(t,n){return t.visitNat(this,n)}covariant(t){if(typeof t=="bigint"&&t>=BigInt(0)||Number.isInteger(t)&&t>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return ot(t)}encodeType(){return _t(He.Nat)}decodeValue(t,n){return this.checkType(n),xt(t)}get name(){return"nat"}valueToString(t){return t.toString()}}class dl extends Bn{get typeName(){return ve.FloatClass}static[Symbol.hasInstance](t){return t.typeName===ve.FloatClass}constructor(t){if(super(),this._bits=t,t!==32&&t!==64)throw new Error("not a valid float type")}accept(t,n){return t.visitFloat(this,n)}covariant(t){if(typeof t=="number"||t instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=new ArrayBuffer(this._bits/8),r=new DataView(n);return this._bits===32?r.setFloat32(0,t,!0):r.setFloat64(0,t,!0),new Uint8Array(n)}encodeType(){const t=this._bits===32?He.Float32:He.Float64;return _t(t)}decodeValue(t,n){this.checkType(n);const r=Ci(t,this._bits/8),i=f_(r);return this._bits===32?i.getFloat32(0,!0):i.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(t){return t.toString()}}class Fi extends Bn{get typeName(){return ve.FixedIntClass}static[Symbol.hasInstance](t){return t.typeName===ve.FixedIntClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedInt(this,n)}covariant(t){const n=Af(this._bits-1)*BigInt(-1),r=Af(this._bits-1)-BigInt(1);let i=!1;if(typeof t=="bigint")i=t>=n&&t<=r;else if(Number.isInteger(t)){const s=BigInt(t);i=s>=n&&s<=r}else i=!1;if(i)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return fg(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return _t(-9-t)}decodeValue(t,n){this.checkType(n);const r=d_(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`int${this._bits}`}valueToString(t){return t.toString()}}class ti extends Bn{get typeName(){return ve.FixedNatClass}static[Symbol.hasInstance](t){return t.typeName===ve.FixedNatClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedNat(this,n)}covariant(t){const n=Af(this._bits);let r=!1;if(typeof t=="bigint"&&t>=BigInt(0)?r=t<n:Number.isInteger(t)&&t>=0?r=BigInt(t)<n:r=!1,r)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return h_(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return _t(-5-t)}decodeValue(t,n){this.checkType(n);const r=lg(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`nat${this._bits}`}valueToString(t){return t.toString()}}class Es extends ci{get typeName(){return ve.VecClass}static[Symbol.hasInstance](t){return t.typeName===ve.VecClass}constructor(t){super(),this._type=t,this._blobOptimization=!1,t instanceof ti&&t._bits===8&&(this._blobOptimization=!0)}accept(t,n){return t.visitVec(this,this._type,n)}covariant(t){const n=this._type instanceof ti?this._type._bits:this._type instanceof Fi?this._type._bits:0;if(ArrayBuffer.isView(t)&&n==t.BYTES_PER_ELEMENT*8||Array.isArray(t)&&t.every((r,i)=>{try{return this._type.covariant(r)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
12
|
+
*********************`),c=s.hashForSignature(e,u,o)}return{script:u,sighashType:o,hash:c}}function GE(e,t,n,r){const i=[];if(t.tapInternalKey){const o=eg(e,t,r);o&&i.push(o)}if(t.tapScriptSig){const o=t.tapScriptSig.map(c=>c.pubkey);i.push(...o)}return i.map(o=>xf(e,t,n,o,r)).flat()}function eg(e,t,n){const{script:r}=fl(e,t,n);return Wy(r)?r.subarray(2,34):null}function ad(e){return e.length===64?e:e.subarray(0,64)}function xf(e,t,n,r,i,s,o){const c=i.__TX,a=t.sighashType||ht.SIGHASH_DEFAULT;tg(a,o);const u=n.map((g,w)=>fl(w,g,i)),f=u.map(g=>g.script),l=u.map(g=>g.value),p=[];if(t.tapInternalKey&&!s){const g=eg(e,t,i)||Uint8Array.from([]);if(he(Cc(r),g)===0){const w=c.hashForWitnessV1(e,f,l,a);p.push({pubkey:r,hash:w})}}const y=(t.tapLeafScript||[]).filter(g=>Ha(r,g.script)).map(g=>{const w=hr({output:g.script,version:g.leafVersion});return Object.assign({hash:w},g)}).filter(g=>!s||he(s,g.hash)===0).map(g=>{const w=c.hashForWitnessV1(e,f,l,a,g.hash);return{pubkey:r,hash:w,leafHash:g.hash}});return p.concat(y)}function tg(e,t){if(t&&t.indexOf(e)<0){const n=YE(e);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${n}`)}}function DE(e,t,n){let r;switch(t){case"multisig":const i=zE(e,n);r=Na({output:e,signatures:i});break;case"pubkey":r=dy({output:e,signature:n[0].signature});break;case"pubkeyhash":r=Wo({output:e,pubkey:n[0].pubkey,signature:n[0].signature});break;case"witnesspubkeyhash":r=Xo({output:e,pubkey:n[0].pubkey,signature:n[0].signature});break}return r}function XE(e,t,n){const r=n.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const s=Fa(n,t,e),o=r.ins[e].index;i.script=s.outs[o].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||Ca(i.script))&&(i.isSegwit=!0),i}function ud(e,t,n){const r=It(t,e);if(!r.bip32Derivation||r.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const i=r.bip32Derivation.map(o=>{if(he(o.masterFingerprint,n.fingerprint)===0)return o}).filter(o=>!!o);if(i.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(o=>{const c=n.derivePath(o.path);if(he(o.pubkey,c.publicKey)!==0)throw new Error("pubkey did not match bip32Derivation");return c})}function zE(e,t){return Na({output:e}).pubkeys.map(r=>(t.filter(i=>he(i.pubkey,r)===0)[0]||{}).signature).filter(r=>!!r)}function ng(e){let t=0;function n(o){return t+=o,e.slice(t-o,t)}function r(){const o=Ps(e,t);return t+=Tn(o.bigintValue),o.numberValue}function i(){return n(r())}function s(){const o=r(),c=[];for(let a=0;a<o;a++)c.push(i());return c}return s()}function YE(e){let t=e&ht.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(e&31){case ht.SIGHASH_ALL:t+="SIGHASH_ALL";break;case ht.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case ht.SIGHASH_NONE:t+="SIGHASH_NONE";break}return t}function Af(e,t,n){e.__NON_WITNESS_UTXO_BUF_CACHE[n]=t.nonWitnessUtxo;const r=ht.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[n]=r;const i=e,s=n;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const o=i.__NON_WITNESS_UTXO_BUF_CACHE[s],c=i.__NON_WITNESS_UTXO_TX_CACHE[s];if(o!==void 0)return o;{const a=c.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[s]=a,a}},set(o){i.__NON_WITNESS_UTXO_BUF_CACHE[s]=o}})}function rg(e,t,n,r){let i=0n;e.forEach((a,u)=>{if(r&&a.finalScriptSig&&(t.ins[u].script=a.finalScriptSig),r&&a.finalScriptWitness&&(t.ins[u].witness=ng(a.finalScriptWitness)),a.witnessUtxo)i+=a.witnessUtxo.value;else if(a.nonWitnessUtxo){const f=Fa(n,a,u),l=t.ins[u].index,p=f.outs[l];i+=p.value}});const s=t.outs.reduce((a,u)=>a+u.value,0n),o=i-s;if(o<0)throw new Error("Outputs are spending more than Inputs");const c=t.virtualSize();n.__FEE=o,n.__EXTRACTED_TX=t,n.__FEE_RATE=Math.floor(Number(o/BigInt(c)))}function Fa(e,t,n){const r=e.__NON_WITNESS_UTXO_TX_CACHE;return r[n]||Af(e,t,n),r[n]}function ig(e,t,n){const{script:r}=fl(e,t,n);return r}function fl(e,t,n){if(t.witnessUtxo!==void 0)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(t.nonWitnessUtxo!==void 0){const i=Fa(n,t,e).outs[n.__TX.ins[e].index];return{script:i.script,value:i.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function ZE(e,t,n,r){const i=ig(n,t,r),{meaningfulScript:s}=Ma(i,n,"input",t.redeemScript,t.witnessScript);return Ha(e,s)}function JE(e,t,n,r){const i=r.__TX.outs[n].script,{meaningfulScript:s}=Ma(i,n,"output",t.redeemScript,t.witnessScript);return Ha(e,s)}function QE(e){if(!e)return;const t=ct(e);if(!t)return;const n=t[t.length-1];if(!(!(n instanceof Uint8Array)||sg(n)||n_(n)||!ct(n)))return n}function e_(e){if(!e)return;const t=ng(e),n=t[t.length-1];if(!(sg(n)||!ct(n)))return n}function t_(e){if(e.length===65){const t=e[64]&1,n=e.slice(0,33);return n[0]=2|t,n}return e.slice()}function sg(e){return e.length===33&&_m(e)}function n_(e){return br(e)}function Ma(e,t,n,r,i){const s=jy(e),o=s&&r&&Jh(r),c=Jh(e);if(s&&r===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((c||o)&&i===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let a;return o?(a=i,id(t,e,r,n),sd(t,r,i,n),ta(a)):c?(a=i,sd(t,e,i,n),ta(a)):s?(a=r,id(t,e,r,n)):a=e,{meaningfulScript:a,type:o?"p2sh-p2wsh":s?"p2sh":c?"p2wsh":"raw"}}function ta(e){if(Ca(e)||jy(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function og(e){return Ca(e)?"witnesspubkeyhash":mE(e)?"pubkeyhash":gE(e)?"multisig":wE(e)?"pubkey":"nonstandard"}function Ks(e){return[...Array(e).keys()]}sb(Mw);const Zo={Mainnet:"mainnet",Testnet:"testnet"},na="abcdefghijklmnopqrstuvwxyz234567",Es=Object.create(null);for(let e=0;e<na.length;e++)Es[na[e]]=e;Es[0]=Es.o;Es[1]=Es.i;function r_(e){let t=0,n=0,r="";function i(s){return t<0?n|=s>>-t:n=s<<t&248,t>3?(t-=8,1):(t<4&&(r+=na[n>>3],t+=5),0)}for(let s=0;s<e.length;)s+=i(e[s]);return r+(t<0?na[n>>3]:"")}function i_(e){let t=0,n=0;const r=new Uint8Array(e.length*4/3|0);let i=0;function s(o){let c=Es[o.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(o)}`);c<<=3,n|=c>>>t,t+=5,t>=8&&(r[i++]=n,t-=8,t>0?n=c<<5-t&255:n=0)}for(const o of e)s(o);return r.slice(0,i)}const s_=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function o_(e){let t=-1;for(let n=0;n<e.length;n++){const i=(e[n]^t)&255;t=s_[i]^t>>>8}return(t^-1)>>>0}const Ec="__principal__",c_=2,fd=4,a_="aaaaa-aa";let $e=class ss{static anonymous(){return new this(new Uint8Array([fd]))}static managementCanister(){return this.fromText(a_)}static selfAuthenticating(t){const n=Zm(t);return new this(new Uint8Array([...n,c_]))}static from(t){if(typeof t=="string")return ss.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new ss(t);if(ss.isPrincipal(t))return new ss(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(jo(t))}static fromText(t){let n=t;if(t.includes(Ec)){const o=JSON.parse(t);Ec in o&&(n=o[Ec])}const r=n.toLowerCase().replace(/-/g,"");let i=i_(r);i=i.slice(4,i.length);const s=new this(i);if(s.toText()!==n)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${n}" may not be a valid Principal ID).`);return s}static fromUint8Array(t){return new this(t)}static isPrincipal(t){return t instanceof ss||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===fd}toUint8Array(){return this._arr}toHex(){return Qe(this._arr).toUpperCase()}toText(){const t=new ArrayBuffer(4);new DataView(t).setUint32(0,o_(this._arr));const r=new Uint8Array(t),i=new Uint8Array([...r,...this._arr]),o=r_(i).match(/.{1,5}/g);if(!o)throw new Error;return o.join("-")}toString(){return this.toText()}toJSON(){return{[Ec]:this.toText()}}compareTo(t){for(let n=0;n<Math.min(this._arr.length,t._arr.length);n++){if(this._arr[n]<t._arr[n])return"lt";if(this._arr[n]>t._arr[n])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){const n=this.compareTo(t);return n=="lt"||n=="eq"}gtEq(t){const n=this.compareTo(t);return n=="gt"||n=="eq"}};function Fe(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.byteLength,0));let n=0;for(const r of e)t.set(r,n),n+=r.byteLength;return t}class ks{save(){return this._view}restore(t){if(!(t instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=t}constructor(t,n=t?.byteLength||0){if(t&&!(t instanceof Uint8Array))try{t=cg(t)}catch{throw new Error("Buffer must be a Uint8Array")}if(n<0||!Number.isInteger(n))throw new Error("Length must be a non-negative integer");if(t&&n>t.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=t||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,n)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(t){const n=this._view.subarray(0,t);return this._view=this._view.subarray(t),n.slice()}readUint8(){if(this._view.byteLength===0)return;const t=this._view[0];return this._view=this._view.subarray(1),t}write(t){if(!(t instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");const n=this._view.byteLength;this._view.byteOffset+this._view.byteLength+t.byteLength>=this._buffer.byteLength?this.alloc(t.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+t.byteLength),this._view.set(t,n)}get end(){return this._view.byteLength===0}alloc(t){if(t<=0||!Number.isInteger(t))throw new Error("Amount must be a positive integer");const n=new Uint8Array((this._buffer.byteLength+t)*1.2|0),r=new Uint8Array(n.buffer,0,this._view.byteLength+t);r.set(this._view),this._buffer=n,this._view=r}}function cg(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?cg(e.buffer):new Uint8Array(e)}function u_(e,t){if(e.byteLength!==t.byteLength)return e.byteLength-t.byteLength;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]-t[n];return 0}function f_(e){if(!(e instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(e.buffer,e.byteOffset,e.byteLength)}function l_(e){const n=new TextEncoder().encode(e);let r=0;for(const i of n)r=(r*223+i)%2**32;return r}function tn(e){if(/^_\d+_$/.test(e)||/^_0x[0-9a-fA-F]+_$/.test(e)){const t=+e.slice(1,-1);if(Number.isSafeInteger(t)&&t>=0&&t<2**32)return t}return l_(e)}function ag(e){const t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function vf(e){const t=BigInt(e);if(e<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<t}function ug(){throw new Error("unexpected end of buffer")}function Hi(e,t){return e.byteLength<t&&ug(),e.read(t)}function Fi(e){const t=e.readUint8();return t===void 0&&ug(),t}function ot(e){if(typeof e=="number"&&(e=BigInt(e)),e<BigInt(0))throw new Error("Cannot leb encode negative values.");const t=(e===BigInt(0)?0:ag(e))+1,n=new ks(new Uint8Array(t),0);for(;;){const r=Number(e&BigInt(127));if(e/=BigInt(128),e===BigInt(0)){n.write(new Uint8Array([r]));break}else n.write(new Uint8Array([r|128]))}return n.buffer}function xt(e){let t=BigInt(1),n=BigInt(0),r;do r=Fi(e),n+=BigInt(r&127).valueOf()*t,t*=BigInt(128);while(r>=128);return n}function _t(e){typeof e=="number"&&(e=BigInt(e));const t=e<BigInt(0);t&&(e=-e-BigInt(1));const n=(e===BigInt(0)?0:ag(e))+1,r=new ks(new Uint8Array(n),0);for(;;){const s=i(e);if(e/=BigInt(128),t&&e===BigInt(0)&&(s&64)!==0||!t&&e===BigInt(0)&&(s&64)===0){r.write(new Uint8Array([s]));break}else r.write(new Uint8Array([s|128]))}function i(s){const o=s%BigInt(128);return Number(t?BigInt(128)-o-BigInt(1):o)}return r.buffer}function Dr(e){const t=new Uint8Array(e.buffer);let n=0;for(;n<t.byteLength;n++)if(t[n]<128){if((t[n]&64)===0)return xt(e);break}const r=new Uint8Array(Hi(e,n+1));let i=BigInt(0);for(let s=r.byteLength-1;s>=0;s--)i=i*BigInt(128)+BigInt(128-(r[s]&127)-1);return-i-BigInt(1)}function h_(e,t){if(BigInt(e)<BigInt(0))throw new Error("Cannot write negative values.");return fg(e,t)}function fg(e,t){e=BigInt(e);const n=new ks(new Uint8Array(Math.min(1,t)),0);let r=0,i=BigInt(256),s=BigInt(0),o=Number(e%i);for(n.write(new Uint8Array([o]));++r<t;)e<0&&s===BigInt(0)&&o!==0&&(s=BigInt(1)),o=Number((e/i-s)%BigInt(256)),n.write(new Uint8Array([o])),i*=BigInt(256);return n.buffer}function lg(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=BigInt(Fi(e)),r=BigInt(1),i=0;for(;++i<t;){r*=BigInt(256);const s=BigInt(Fi(e));n=n+r*s}return n}function d_(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let n=lg(e,t);const r=BigInt(2)**(BigInt(8)*BigInt(t-1)+BigInt(7));return n>=r&&(n-=r*BigInt(2)),n}var He;(function(e){e[e.Null=-1]="Null",e[e.Bool=-2]="Bool",e[e.Nat=-3]="Nat",e[e.Int=-4]="Int",e[e.Float32=-13]="Float32",e[e.Float64=-14]="Float64",e[e.Text=-15]="Text",e[e.Reserved=-16]="Reserved",e[e.Empty=-17]="Empty",e[e.Opt=-18]="Opt",e[e.Vector=-19]="Vector",e[e.Record=-20]="Record",e[e.Variant=-21]="Variant",e[e.Func=-22]="Func",e[e.Service=-23]="Service",e[e.Principal=-24]="Principal"})(He||(He={}));const Hc="DIDL",ld=400;function go(e,t,n){return e.map((r,i)=>n(r,t[i]))}class p_{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(t){return this._idx.has(t.name)}add(t,n){const r=this._typs.length;this._idx.set(t.name,r),this._idxRefCount.set(r,1),this._typs.push(n)}merge(t,n){const r=this._idx.get(t.name),i=this._idx.get(n);if(r===void 0)throw new Error("Missing type index for "+t);if(i===void 0)throw new Error("Missing type index for "+n);this._typs[r]=this._typs[i];const s=this._getIdxRefCount(i);this._idxRefCount.set(i,s-1),this._idx.delete(n),this._compactFromEnd()}_getIdxRefCount(t){return this._idxRefCount.get(t)||0}_compactFromEnd(){for(;this._typs.length>0;){const t=this._typs.length-1;if(this._getIdxRefCount(t)>0)break;this._typs.pop(),this._idxRefCount.delete(t)}}encode(){const t=ot(this._typs.length),n=Fe(...this._typs);return Fe(t,n)}indexOf(t){if(!this._idx.has(t))throw new Error("Missing type index for "+t);return _t(this._idx.get(t)||0)}}class y_{visitType(t,n){throw new Error("Not implemented")}visitPrimitive(t,n){return this.visitType(t,n)}visitEmpty(t,n){return this.visitPrimitive(t,n)}visitBool(t,n){return this.visitPrimitive(t,n)}visitNull(t,n){return this.visitPrimitive(t,n)}visitReserved(t,n){return this.visitPrimitive(t,n)}visitText(t,n){return this.visitPrimitive(t,n)}visitNumber(t,n){return this.visitPrimitive(t,n)}visitInt(t,n){return this.visitNumber(t,n)}visitNat(t,n){return this.visitNumber(t,n)}visitFloat(t,n){return this.visitPrimitive(t,n)}visitFixedInt(t,n){return this.visitNumber(t,n)}visitFixedNat(t,n){return this.visitNumber(t,n)}visitPrincipal(t,n){return this.visitPrimitive(t,n)}visitConstruct(t,n){return this.visitType(t,n)}visitVec(t,n,r){return this.visitConstruct(t,r)}visitOpt(t,n,r){return this.visitConstruct(t,r)}visitRecord(t,n,r){return this.visitConstruct(t,r)}visitTuple(t,n,r){const i=n.map((s,o)=>[`_${o}_`,s]);return this.visitRecord(t,i,r)}visitVariant(t,n,r){return this.visitConstruct(t,r)}visitRec(t,n,r){return this.visitConstruct(n,r)}visitFunc(t,n){return this.visitConstruct(t,n)}visitService(t,n){return this.visitConstruct(t,n)}}var ve;(function(e){e.EmptyClass="__IDL_EmptyClass__",e.UnknownClass="__IDL_UnknownClass__",e.BoolClass="__IDL_BoolClass__",e.NullClass="__IDL_NullClass__",e.ReservedClass="__IDL_ReservedClass__",e.TextClass="__IDL_TextClass__",e.IntClass="__IDL_IntClass__",e.NatClass="__IDL_NatClass__",e.FloatClass="__IDL_FloatClass__",e.FixedIntClass="__IDL_FixedIntClass__",e.FixedNatClass="__IDL_FixedNatClass__",e.VecClass="__IDL_VecClass__",e.OptClass="__IDL_OptClass__",e.RecordClass="__IDL_RecordClass__",e.TupleClass="__IDL_TupleClass__",e.VariantClass="__IDL_VariantClass__",e.RecClass="__IDL_RecClass__",e.PrincipalClass="__IDL_PrincipalClass__",e.FuncClass="__IDL_FuncClass__",e.ServiceClass="__IDL_ServiceClass__"})(ve||(ve={}));class qa{display(){return this.name}valueToString(t){return pt(t)}buildTypeTable(t){t.has(this)||this._buildTypeTableImpl(t)}}class Bn extends qa{checkType(t){if(this.name!==t.name)throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);return t}_buildTypeTableImpl(t){}}class ci extends qa{checkType(t){if(t instanceof xn){const n=t.getType();if(typeof n>"u")throw new Error("type mismatch with uninitialized type");return n}throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`)}encodeType(t){return t.indexOf(this.name)}}class ll extends Bn{get typeName(){return ve.EmptyClass}static[Symbol.hasInstance](t){return t.typeName===ve.EmptyClass}accept(t,n){return t.visitEmpty(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return _t(He.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}}class hg extends qa{get typeName(){return ve.UnknownClass}static[Symbol.hasInstance](t){return t.typeName===ve.UnknownClass}checkType(t){throw new Error("Method not implemented for unknown.")}accept(t,n){throw t.visitType(this,n)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(t,n){let r=n.decodeValue(t,n);Object(r)!==r&&(r=Object(r));let i;return n instanceof xn?i=()=>n.getType():i=()=>n,Object.defineProperty(r,"type",{value:i,writable:!0,enumerable:!1,configurable:!0}),r}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}}class dg extends Bn{get typeName(){return ve.BoolClass}static[Symbol.hasInstance](t){return t.typeName===ve.BoolClass}accept(t,n){return t.visitBool(this,n)}covariant(t){if(typeof t=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return new Uint8Array([t?1:0])}encodeType(){return _t(He.Bool)}decodeValue(t,n){switch(this.checkType(n),Fi(t)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}}class wo extends Bn{get typeName(){return ve.NullClass}static[Symbol.hasInstance](t){return t.typeName===ve.NullClass}accept(t,n){return t.visitNull(this,n)}covariant(t){if(t===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return _t(He.Null)}decodeValue(t,n){return this.checkType(n),null}get name(){return"null"}}class si extends Bn{get typeName(){return ve.ReservedClass}static[Symbol.hasInstance](t){return t.typeName===ve.ReservedClass}accept(t,n){return t.visitReserved(this,n)}covariant(t){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return _t(He.Reserved)}decodeValue(t,n){return n.name!==this.name&&n.decodeValue(t,n),null}get name(){return"reserved"}}class pg extends Bn{get typeName(){return ve.TextClass}static[Symbol.hasInstance](t){return t.typeName===ve.TextClass}accept(t,n){return t.visitText(this,n)}covariant(t){if(typeof t=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=new TextEncoder().encode(t),r=ot(n.byteLength);return Fe(r,n)}encodeType(){return _t(He.Text)}decodeValue(t,n){this.checkType(n);const r=xt(t),i=Hi(t,Number(r));return new TextDecoder("utf8",{fatal:!0}).decode(i)}get name(){return"text"}valueToString(t){return'"'+t+'"'}}class hl extends Bn{get typeName(){return ve.IntClass}static[Symbol.hasInstance](t){return t.typeName===ve.IntClass}accept(t,n){return t.visitInt(this,n)}covariant(t){if(typeof t=="bigint"||Number.isInteger(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return _t(t)}encodeType(){return _t(He.Int)}decodeValue(t,n){return this.checkType(n),Dr(t)}get name(){return"int"}valueToString(t){return t.toString()}}class dl extends Bn{get typeName(){return ve.NatClass}static[Symbol.hasInstance](t){return t.typeName===ve.NatClass}accept(t,n){return t.visitNat(this,n)}covariant(t){if(typeof t=="bigint"&&t>=BigInt(0)||Number.isInteger(t)&&t>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return ot(t)}encodeType(){return _t(He.Nat)}decodeValue(t,n){return this.checkType(n),xt(t)}get name(){return"nat"}valueToString(t){return t.toString()}}class pl extends Bn{get typeName(){return ve.FloatClass}static[Symbol.hasInstance](t){return t.typeName===ve.FloatClass}constructor(t){if(super(),this._bits=t,t!==32&&t!==64)throw new Error("not a valid float type")}accept(t,n){return t.visitFloat(this,n)}covariant(t){if(typeof t=="number"||t instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=new ArrayBuffer(this._bits/8),r=new DataView(n);return this._bits===32?r.setFloat32(0,t,!0):r.setFloat64(0,t,!0),new Uint8Array(n)}encodeType(){const t=this._bits===32?He.Float32:He.Float64;return _t(t)}decodeValue(t,n){this.checkType(n);const r=Hi(t,this._bits/8),i=f_(r);return this._bits===32?i.getFloat32(0,!0):i.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(t){return t.toString()}}class Mi extends Bn{get typeName(){return ve.FixedIntClass}static[Symbol.hasInstance](t){return t.typeName===ve.FixedIntClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedInt(this,n)}covariant(t){const n=vf(this._bits-1)*BigInt(-1),r=vf(this._bits-1)-BigInt(1);let i=!1;if(typeof t=="bigint")i=t>=n&&t<=r;else if(Number.isInteger(t)){const s=BigInt(t);i=s>=n&&s<=r}else i=!1;if(i)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return fg(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return _t(-9-t)}decodeValue(t,n){this.checkType(n);const r=d_(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`int${this._bits}`}valueToString(t){return t.toString()}}class ti extends Bn{get typeName(){return ve.FixedNatClass}static[Symbol.hasInstance](t){return t.typeName===ve.FixedNatClass}constructor(t){super(),this._bits=t}accept(t,n){return t.visitFixedNat(this,n)}covariant(t){const n=vf(this._bits);let r=!1;if(typeof t=="bigint"&&t>=BigInt(0)?r=t<n:Number.isInteger(t)&&t>=0?r=BigInt(t)<n:r=!1,r)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return h_(t,this._bits/8)}encodeType(){const t=Math.log2(this._bits)-3;return _t(-5-t)}decodeValue(t,n){this.checkType(n);const r=lg(t,this._bits/8);return this._bits<=32?Number(r):r}get name(){return`nat${this._bits}`}valueToString(t){return t.toString()}}class _s extends ci{get typeName(){return ve.VecClass}static[Symbol.hasInstance](t){return t.typeName===ve.VecClass}constructor(t){super(),this._type=t,this._blobOptimization=!1,t instanceof ti&&t._bits===8&&(this._blobOptimization=!0)}accept(t,n){return t.visitVec(this,this._type,n)}covariant(t){const n=this._type instanceof ti?this._type._bits:this._type instanceof Mi?this._type._bits:0;if(ArrayBuffer.isView(t)&&n==t.BYTES_PER_ELEMENT*8||Array.isArray(t)&&t.every((r,i)=>{try{return this._type.covariant(r)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
13
13
|
|
|
14
|
-
index ${i} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=ot(t.length);if(this._blobOptimization)return Fe(n,new Uint8Array(t));if(ArrayBuffer.isView(t))if(t instanceof Int16Array||t instanceof Uint16Array){const i=new DataView(new ArrayBuffer(t.length*2));for(let s=0;s<t.length;s++)t instanceof Int16Array?i.setInt16(s*2,t[s],!0):i.setUint16(s*2,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else if(t instanceof Int32Array||t instanceof Uint32Array){const i=new DataView(new ArrayBuffer(t.length*4));for(let s=0;s<t.length;s++)t instanceof Int32Array?i.setInt32(s*4,t[s],!0):i.setUint32(s*4,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else if(t instanceof BigInt64Array||t instanceof BigUint64Array){const i=new DataView(new ArrayBuffer(t.length*8));for(let s=0;s<t.length;s++)t instanceof BigInt64Array?i.setBigInt64(s*8,t[s],!0):i.setBigUint64(s*8,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else return Fe(n,new Uint8Array(t.buffer,t.byteOffset,t.byteLength));const r=new
|
|
14
|
+
index ${i} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=ot(t.length);if(this._blobOptimization)return Fe(n,new Uint8Array(t));if(ArrayBuffer.isView(t))if(t instanceof Int16Array||t instanceof Uint16Array){const i=new DataView(new ArrayBuffer(t.length*2));for(let s=0;s<t.length;s++)t instanceof Int16Array?i.setInt16(s*2,t[s],!0):i.setUint16(s*2,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else if(t instanceof Int32Array||t instanceof Uint32Array){const i=new DataView(new ArrayBuffer(t.length*4));for(let s=0;s<t.length;s++)t instanceof Int32Array?i.setInt32(s*4,t[s],!0):i.setUint32(s*4,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else if(t instanceof BigInt64Array||t instanceof BigUint64Array){const i=new DataView(new ArrayBuffer(t.length*8));for(let s=0;s<t.length;s++)t instanceof BigInt64Array?i.setBigInt64(s*8,t[s],!0):i.setBigUint64(s*8,t[s],!0);return Fe(n,new Uint8Array(i.buffer))}else return Fe(n,new Uint8Array(t.buffer,t.byteOffset,t.byteLength));const r=new ks(new Uint8Array(n.byteLength+t.length),0);r.write(n);for(const i of t){const s=this._type.encodeValue(i);r.write(new Uint8Array(s))}return r.buffer}_buildTypeTableImpl(t){this._type.buildTypeTable(t);const n=_t(He.Vector),r=this._type.encodeType(t);t.add(this,Fe(n,r))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof _s))throw new Error("Not a vector type");const i=Number(xt(t));if(this._type instanceof ti){if(this._type._bits==8)return new Uint8Array(t.read(i));if(this._type._bits==16){const o=t.read(i*2);return new Uint16Array(o.buffer,o.byteOffset,i)}if(this._type._bits==32){const o=t.read(i*4);return new Uint32Array(o.buffer,o.byteOffset,i)}if(this._type._bits==64)return new BigUint64Array(t.read(i*8).buffer)}if(this._type instanceof Mi){if(this._type._bits==8)return new Int8Array(t.read(i));if(this._type._bits==16){const o=t.read(i*2),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new Int16Array(i);for(let u=0;u<i;u++)a[u]=c.getInt16(u*2,!0);return a}if(this._type._bits==32){const o=t.read(i*4),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new Int32Array(i);for(let u=0;u<i;u++)a[u]=c.getInt32(u*4,!0);return a}if(this._type._bits==64){const o=t.read(i*8),c=new DataView(o.buffer,o.byteOffset,o.byteLength),a=new BigInt64Array(i);for(let u=0;u<i;u++)a[u]=c.getBigInt64(u*8,!0);return a}}const s=[];for(let o=0;o<i;o++)s.push(this._type.decodeValue(t,r._type));return s}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(t){return"vec {"+t.map(r=>this._type.valueToString(r)).join("; ")+"}"}}class Er extends ci{get typeName(){return ve.OptClass}static[Symbol.hasInstance](t){return t.typeName===ve.OptClass}constructor(t){super(),this._type=t}accept(t,n){return t.visitOpt(this,this._type,n)}covariant(t){try{if(Array.isArray(t)&&(t.length===0||t.length===1&&this._type.covariant(t[0])))return!0}catch(n){throw new Error(`Invalid ${this.display()} argument: ${pt(t)}
|
|
15
15
|
|
|
16
|
-
-> ${n.message}`)}throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return t.length===0?new Uint8Array([0]):Fe(new Uint8Array([1]),this._type.encodeValue(t[0]))}_buildTypeTableImpl(t){this._type.buildTypeTable(t);const n=_t(He.Opt),r=this._type.encodeType(t);t.add(this,Fe(n,r))}decodeValue(t,n){if(n instanceof wo)return[];if(n instanceof si)return[];let r=n;if(n instanceof xn){const i=n.getType();if(typeof i>"u")throw new Error("type mismatch with uninitialized type");r=i}if(r instanceof Er)switch(
|
|
16
|
+
-> ${n.message}`)}throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){return t.length===0?new Uint8Array([0]):Fe(new Uint8Array([1]),this._type.encodeValue(t[0]))}_buildTypeTableImpl(t){this._type.buildTypeTable(t);const n=_t(He.Opt),r=this._type.encodeType(t);t.add(this,Fe(n,r))}decodeValue(t,n){if(n instanceof wo)return[];if(n instanceof si)return[];let r=n;if(n instanceof xn){const i=n.getType();if(typeof i>"u")throw new Error("type mismatch with uninitialized type");r=i}if(r instanceof Er)switch(Fi(t)){case 0:return[];case 1:{const i=t.save();try{return[this._type.decodeValue(t,r._type)]}catch{return t.restore(i),r._type.decodeValue(t,r._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof wo||this._type instanceof Er||this._type instanceof si)return r.decodeValue(t,r),[];{const i=t.save();try{return[this._type.decodeValue(t,n)]}catch{return t.restore(i),r.decodeValue(t,n),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(t){return t.length===0?"null":`opt ${this._type.valueToString(t[0])}`}}class qi extends ci{get typeName(){return ve.RecordClass}static[Symbol.hasInstance](t){return t.typeName===ve.RecordClass||t.typeName===ve.TupleClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((n,r)=>tn(n[0])-tn(r[0]))}accept(t,n){return t.visitRecord(this,this._fields,n)}tryAsTuple(){const t=[];for(let n=0;n<this._fields.length;n++){const[r,i]=this._fields[n];if(r!==`_${n}_`)return null;t.push(i)}return t}covariant(t){if(typeof t=="object"&&this._fields.every(([n,r])=>{if(!t.hasOwnProperty(n))throw new Error(`Record is missing key "${n}".`);try{return r.covariant(t[n])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
17
17
|
|
|
18
|
-
field ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=this._fields.map(([i])=>t[i]),r=go(this._fields,n,([,i],s)=>i.encodeValue(s));return Fe(...r)}_buildTypeTableImpl(t){this._fields.forEach(([s,o])=>o.buildTypeTable(t));const n=_t(He.Record),r=ot(this._fields.length),i=this._fields.map(([s,o])=>Fe(ot(tn(s)),o.encodeType(t)));t.add(this,Fe(n,r,Fe(...i)))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof
|
|
18
|
+
field ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=this._fields.map(([i])=>t[i]),r=go(this._fields,n,([,i],s)=>i.encodeValue(s));return Fe(...r)}_buildTypeTableImpl(t){this._fields.forEach(([s,o])=>o.buildTypeTable(t));const n=_t(He.Record),r=ot(this._fields.length),i=this._fields.map(([s,o])=>Fe(ot(tn(s)),o.encodeType(t)));t.add(this,Fe(n,r,Fe(...i)))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof qi))throw new Error("Not a record type");const i={};let s=0,o=0;for(;o<r._fields.length;){const[c,a]=r._fields[o];if(s>=this._fields.length){a.decodeValue(t,a),o++;continue}const[u,f]=this._fields[s],l=tn(this._fields[s][0]),p=tn(c);if(l===p)i[u]=f.decodeValue(t,a),s++,o++;else if(p>l)if(f instanceof Er||f instanceof si)i[u]=[],s++;else throw new Error("Cannot find required field "+u);else a.decodeValue(t,a),o++}for(const[c,a]of this._fields.slice(s))if(a instanceof Er||a instanceof si)i[c]=[];else throw new Error("Cannot find required field "+c);return i}get fieldsAsObject(){const t={};for(const[n,r]of this._fields)t[tn(n)]=r;return t}get name(){return`record {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}display(){return`record {${this._fields.map(([n,r])=>n+":"+r.display()).join("; ")}}`}valueToString(t){const n=this._fields.map(([i])=>t[i]);return`record {${go(this._fields,n,([i,s],o)=>i+"="+s.valueToString(o)).join("; ")}}`}}class Va extends qi{get typeName(){return ve.TupleClass}static[Symbol.hasInstance](t){return t.typeName===ve.TupleClass}constructor(t){const n={};t.forEach((r,i)=>n["_"+i+"_"]=r),super(n),this._components=t}accept(t,n){return t.visitTuple(this,this._components,n)}covariant(t){if(Array.isArray(t)&&t.length>=this._fields.length&&this._components.every((n,r)=>{try{return n.covariant(t[r])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
19
19
|
|
|
20
|
-
index ${r} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=go(this._components,t,(r,i)=>r.encodeValue(i));return Fe(...n)}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof
|
|
20
|
+
index ${r} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=go(this._components,t,(r,i)=>r.encodeValue(i));return Fe(...n)}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof Va))throw new Error("not a tuple type");if(r._components.length<this._components.length)throw new Error("tuple mismatch");const i=[];for(const[s,o]of r._components.entries())s>=this._components.length?o.decodeValue(t,o):i.push(this._components[s].decodeValue(t,o));return i}display(){return`record {${this._components.map(n=>n.display()).join("; ")}}`}valueToString(t){return`record {${go(this._components,t,(r,i)=>r.valueToString(i)).join("; ")}}`}}class Ss extends ci{get typeName(){return ve.VariantClass}static[Symbol.hasInstance](t){return t.typeName===ve.VariantClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((n,r)=>tn(n[0])-tn(r[0]))}accept(t,n){return t.visitVariant(this,this._fields,n)}covariant(t){if(typeof t=="object"&&Object.entries(t).length===1&&this._fields.every(([n,r])=>{try{return!t.hasOwnProperty(n)||r.covariant(t[n])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
21
21
|
|
|
22
|
-
variant ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){for(let n=0;n<this._fields.length;n++){const[r,i]=this._fields[n];if(t.hasOwnProperty(r)){const s=ot(n),o=i.encodeValue(t[r]);return Fe(s,o)}}throw Error("Variant has no data: "+t)}_buildTypeTableImpl(t){this._fields.forEach(([,s])=>{s.buildTypeTable(t)});const n=_t(He.Variant),r=ot(this._fields.length),i=this._fields.map(([s,o])=>Fe(ot(tn(s)),o.encodeType(t)));t.add(this,Fe(n,r,...i))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof
|
|
22
|
+
variant ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){for(let n=0;n<this._fields.length;n++){const[r,i]=this._fields[n];if(t.hasOwnProperty(r)){const s=ot(n),o=i.encodeValue(t[r]);return Fe(s,o)}}throw Error("Variant has no data: "+t)}_buildTypeTableImpl(t){this._fields.forEach(([,s])=>{s.buildTypeTable(t)});const n=_t(He.Variant),r=ot(this._fields.length),i=this._fields.map(([s,o])=>Fe(ot(tn(s)),o.encodeType(t)));t.add(this,Fe(n,r,...i))}decodeValue(t,n){const r=this.checkType(n);if(!(r instanceof Ss))throw new Error("Not a variant type");const i=Number(xt(t));if(i>=r._fields.length)throw Error("Invalid variant index: "+i);const[s,o]=r._fields[i];for(const[c,a]of this._fields)if(tn(s)===tn(c)){const u=a.decodeValue(t,o);return{[c]:u}}throw new Error("Cannot find field hash "+s)}get name(){return`variant {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}display(){return`variant {${this._fields.map(([n,r])=>n+(r.name==="null"?"":`:${r.display()}`)).join("; ")}}`}valueToString(t){for(const[n,r]of this._fields)if(t.hasOwnProperty(n)){const i=r.valueToString(t[n]);return i==="null"?`variant {${n}}`:`variant {${n}=${i}}`}throw new Error("Variant has no data: "+t)}get alternativesAsObject(){const t={};for(const[n,r]of this._fields)t[tn(n)]=r;return t}}const va=class va extends ci{constructor(){super(...arguments),this._id=va._counter++}get typeName(){return ve.RecClass}static[Symbol.hasInstance](t){return t.typeName===ve.RecClass}accept(t,n){if(!this._type)throw Error("Recursive type uninitialized.");return t.visitRec(this,this._type,n)}fill(t){this._type=t}getType(){return this._type}covariant(t){if(this._type&&this._type.covariant(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(t)}_buildTypeTableImpl(t){if(!this._type)throw Error("Recursive type uninitialized.");t.add(this,new Uint8Array([])),this._type.buildTypeTable(t),t.merge(this,this._type.name)}decodeValue(t,n){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(t,n)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`μ${this.name}.${this._type.name}`}valueToString(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(t)}};va._counter=0;let xn=va;function yl(e){if(Fi(e)!==1)throw new Error("Cannot decode principal");const n=Number(xt(e));return $e.fromUint8Array(new Uint8Array(Hi(e,n)))}class yg extends Bn{get typeName(){return ve.PrincipalClass}static[Symbol.hasInstance](t){return t.typeName===ve.PrincipalClass}accept(t,n){return t.visitPrincipal(this,n)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=t.toUint8Array(),r=ot(n.byteLength);return Fe(new Uint8Array([1]),r,n)}encodeType(){return _t(He.Principal)}decodeValue(t,n){return this.checkType(n),yl(t)}get name(){return"principal"}valueToString(t){return`${this.name} "${t.toText()}"`}}class mo extends ci{get typeName(){return ve.FuncClass}static[Symbol.hasInstance](t){return t.typeName===ve.FuncClass}static argsToString(t,n){if(t.length!==n.length)throw new Error("arity mismatch");return"("+t.map((r,i)=>r.valueToString(n[i])).join(", ")+")"}constructor(t,n,r=[]){super(),this.argTypes=t,this.retTypes=n,this.annotations=r}accept(t,n){return t.visitFunc(this,n)}covariant(t){if(Array.isArray(t)&&t.length===2&&t[0]&&t[0]._isPrincipal&&typeof t[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue([t,n]){const r=t.toUint8Array(),i=ot(r.byteLength),s=Fe(new Uint8Array([1]),i,r),o=new TextEncoder().encode(n),c=ot(o.byteLength);return Fe(new Uint8Array([1]),s,c,o)}_buildTypeTableImpl(t){this.argTypes.forEach(u=>u.buildTypeTable(t)),this.retTypes.forEach(u=>u.buildTypeTable(t));const n=_t(He.Func),r=ot(this.argTypes.length),i=Fe(...this.argTypes.map(u=>u.encodeType(t))),s=ot(this.retTypes.length),o=Fe(...this.retTypes.map(u=>u.encodeType(t))),c=ot(this.annotations.length),a=Fe(...this.annotations.map(u=>this.encodeAnnotation(u)));t.add(this,Fe(n,r,i,s,o,c,a))}decodeValue(t,n){const r=n instanceof xn?n.getType()??n:n;if(!gl(r,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${r.display()}`);if(Fi(t)!==1)throw new Error("Cannot decode function reference");const s=yl(t),o=Number(xt(t)),c=Hi(t,o),u=new TextDecoder("utf8",{fatal:!0}).decode(c);return[s,u]}get name(){const t=this.argTypes.map(i=>i.name).join(", "),n=this.retTypes.map(i=>i.name).join(", "),r=" "+this.annotations.join(" ");return`(${t}) -> (${n})${r}`}valueToString([t,n]){return`func "${t.toText()}".${n}`}display(){const t=this.argTypes.map(i=>i.display()).join(", "),n=this.retTypes.map(i=>i.display()).join(", "),r=" "+this.annotations.join(" ");return`(${t}) → (${n})${r}`}encodeAnnotation(t){if(t==="query")return new Uint8Array([1]);if(t==="oneway")return new Uint8Array([2]);if(t==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}}class ra extends ci{get typeName(){return ve.ServiceClass}static[Symbol.hasInstance](t){return t.typeName===ve.ServiceClass}constructor(t){super(),this._fields=Object.entries(t).sort((n,r)=>n[0]<r[0]?-1:n[0]>r[0]?1:0)}accept(t,n){return t.visitService(this,n)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${pt(t)}`)}encodeValue(t){const n=t.toUint8Array(),r=ot(n.length);return Fe(new Uint8Array([1]),r,n)}_buildTypeTableImpl(t){this._fields.forEach(([s,o])=>o.buildTypeTable(t));const n=_t(He.Service),r=ot(this._fields.length),i=this._fields.map(([s,o])=>{const c=new TextEncoder().encode(s),a=ot(c.length);return Fe(a,c,o.encodeType(t))});t.add(this,Fe(n,r,...i))}decodeValue(t,n){const r=n instanceof xn?n.getType()??n:n;if(!gl(r,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${r.display()}`);return yl(t)}get name(){return`service {${this._fields.map(([n,r])=>n+":"+r.name).join("; ")}}`}valueToString(t){return`service "${t.toText()}"`}fieldsAsObject(){const t={};for(const[n,r]of this._fields)t[n]=r;return t}}function pt(e){const t=JSON.stringify(e,(n,r)=>typeof r=="bigint"?`BigInt(${r})`:r);return t&&t.length>ld?t.substring(0,ld-3)+"...":t}function Bf(e,t){if(t.length<e.length)throw Error("Wrong number of message arguments");const n=new p_;e.forEach(a=>a.buildTypeTable(n));const r=new TextEncoder().encode(Hc),i=n.encode(),s=ot(t.length),o=Fe(...e.map(a=>a.encodeType(n))),c=Fe(...go(e,t,(a,u)=>{try{a.covariant(u)}catch(f){throw new Error(f.message+`
|
|
23
23
|
|
|
24
|
-
`)}return a.encodeValue(u)}));return Fe(r,i,s,o,c)}function gg(e,t){const n=new
|
|
25
|
-
`;return t}addNames(t,n,r){const i=this.rels.get(t);if(i==null){const s=new Map;s.set(n,r),this.rels.set(t,s)}else i.set(n,r)}}let Hc=new Va;function Bf(){Hc=new Va}function w_(e,t){const n=new Set(e.annotations),r=new Set(t.annotations);if(n.size!==r.size)return!1;for(const i of n)if(!r.has(i))return!1;return!0}function Ou(e){return e instanceof Er||e instanceof wo||e instanceof si}function yl(e,t){const n=Hc.copy(),r=or(n,e,t);return r?Hc.add(e,t):Hc.addNegative(e,t),r}function or(e,t,n){if(t.name===n.name)return!0;const r=e.known(t,n);if(r!==void 0)return r;if(e.add(t,n),n instanceof si||t instanceof fl||t instanceof hl&&n instanceof ll)return!0;if(t instanceof Es&&n instanceof Es)return or(e,t._type,n._type);if(n instanceof Er)return!0;if(t instanceof Mi&&n instanceof Mi){const i=t.fieldsAsObject;for(const[s,o]of n._fields){const c=i[tn(s)];if(c){if(!or(e,c,o))return!1}else if(!Ou(o))return!1}return!0}if(t instanceof mo&&n instanceof mo){if(!w_(t,n))return!1;for(let i=0;i<t.argTypes.length;i++){const s=t.argTypes[i];if(i<n.argTypes.length){if(!or(e,n.argTypes[i],s))return!1}else if(!Ou(s))return!1}for(let i=0;i<n.retTypes.length;i++){const s=n.retTypes[i];if(i<t.retTypes.length){if(!or(e,t.retTypes[i],s))return!1}else if(!Ou(s))return!1}return!0}if(t instanceof _s&&n instanceof _s){const i=n.alternativesAsObject;for(const[s,o]of t._fields){const c=i[tn(s)];if(!c||!or(e,o,c))return!1}return!0}if(t instanceof na&&n instanceof na){const i=t.fieldsAsObject();for(const[s,o]of n._fields){const c=i[s];if(!c||!or(e,c,o))return!1}return!0}return t instanceof xn?or(e,t.getType(),n):n instanceof xn?or(e,t,n.getType()):!1}const m_=Object.freeze(Object.defineProperty({__proto__:null,Bool:bg,BoolClass:dg,ConstructType:ci,Empty:wg,EmptyClass:fl,FixedIntClass:Fi,FixedNatClass:ti,Float32:xg,Float64:Ag,FloatClass:dl,Func:$g,FuncClass:mo,Int:Sg,Int16:Bg,Int32:Ig,Int64:Og,Int8:vg,IntClass:ll,Nat:Tg,Nat16:kg,Nat32:Ng,Nat64:Ug,Nat8:Pg,NatClass:hl,Null:Eg,NullClass:wo,Opt:Fg,OptClass:Er,PrimitiveType:Bn,Principal:Rg,PrincipalClass:yg,Rec:Vg,RecClass:xn,Record:Mg,RecordClass:Mi,Reserved:mg,ReservedClass:si,Service:Kg,ServiceClass:na,Text:_g,TextClass:pg,Tuple:Cg,TupleClass:qa,Type:Ma,Unknown:g_,UnknownClass:hg,Variant:qg,VariantClass:_s,Vec:Hg,VecClass:Es,Visitor:y_,decode:gg,encode:vf,resetSubtypeCache:Bf,subtype:yl},Symbol.toStringTag,{value:"Module"}));function Lg(e,t){return function(){return e.apply(t,arguments)}}const{toString:b_}=Object.prototype,{getPrototypeOf:gl}=Object,{iterator:$a,toStringTag:jg}=Symbol,Ka=(e=>t=>{const n=b_.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),qn=e=>(e=e.toLowerCase(),t=>Ka(t)===e),La=e=>t=>typeof t===e,{isArray:ks}=Array,bo=La("undefined");function Zo(e){return e!==null&&!bo(e)&&e.constructor!==null&&!bo(e.constructor)&&an(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Wg=qn("ArrayBuffer");function E_(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Wg(e.buffer),t}const __=La("string"),an=La("function"),Gg=La("number"),Jo=e=>e!==null&&typeof e=="object",S_=e=>e===!0||e===!1,Fc=e=>{if(Ka(e)!=="object")return!1;const t=gl(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(jg in e)&&!($a in e)},T_=e=>{if(!Jo(e)||Zo(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},x_=qn("Date"),A_=qn("File"),v_=qn("Blob"),B_=qn("FileList"),I_=e=>Jo(e)&&an(e.pipe),O_=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||an(e.append)&&((t=Ka(e))==="formdata"||t==="object"&&an(e.toString)&&e.toString()==="[object FormData]"))},P_=qn("URLSearchParams"),[k_,N_,U_,R_]=["ReadableStream","Request","Response","Headers"].map(qn),C_=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Qo(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,i;if(typeof e!="object"&&(e=[e]),ks(e))for(r=0,i=e.length;r<i;r++)t.call(null,e[r],r,e);else{if(Zo(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),o=s.length;let c;for(r=0;r<o;r++)c=s[r],t.call(null,e[c],c,e)}}function Dg(e,t){if(Zo(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,i;for(;r-- >0;)if(i=n[r],t===i.toLowerCase())return i;return null}const vi=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:globalThis,Xg=e=>!bo(e)&&e!==vi;function If(){const{caseless:e}=Xg(this)&&this||{},t={},n=(r,i)=>{const s=e&&Dg(t,i)||i;Fc(t[s])&&Fc(r)?t[s]=If(t[s],r):Fc(r)?t[s]=If({},r):ks(r)?t[s]=r.slice():t[s]=r};for(let r=0,i=arguments.length;r<i;r++)arguments[r]&&Qo(arguments[r],n);return t}const H_=(e,t,n,{allOwnKeys:r}={})=>(Qo(t,(i,s)=>{n&&an(i)?e[s]=Lg(i,n):e[s]=i},{allOwnKeys:r}),e),F_=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),M_=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},q_=(e,t,n,r)=>{let i,s,o;const c={};if(t=t||{},e==null)return t;do{for(i=Object.getOwnPropertyNames(e),s=i.length;s-- >0;)o=i[s],(!r||r(o,e,t))&&!c[o]&&(t[o]=e[o],c[o]=!0);e=n!==!1&&gl(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},V_=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},$_=e=>{if(!e)return null;if(ks(e))return e;let t=e.length;if(!Gg(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},K_=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&gl(Uint8Array)),L_=(e,t)=>{const r=(e&&e[$a]).call(e);let i;for(;(i=r.next())&&!i.done;){const s=i.value;t.call(e,s[0],s[1])}},j_=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},W_=qn("HTMLFormElement"),G_=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,i){return r.toUpperCase()+i}),hd=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),D_=qn("RegExp"),zg=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Qo(n,(i,s)=>{let o;(o=t(i,s,e))!==!1&&(r[s]=o||i)}),Object.defineProperties(e,r)},X_=e=>{zg(e,(t,n)=>{if(an(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(an(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},z_=(e,t)=>{const n={},r=i=>{i.forEach(s=>{n[s]=!0})};return ks(e)?r(e):r(String(e).split(t)),n},Y_=()=>{},Z_=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function J_(e){return!!(e&&an(e.append)&&e[jg]==="FormData"&&e[$a])}const Q_=e=>{const t=new Array(10),n=(r,i)=>{if(Jo(r)){if(t.indexOf(r)>=0)return;if(Zo(r))return r;if(!("toJSON"in r)){t[i]=r;const s=ks(r)?[]:{};return Qo(r,(o,c)=>{const a=n(o,i+1);!bo(a)&&(s[c]=a)}),t[i]=void 0,s}}return r};return n(e,0)},eS=qn("AsyncFunction"),tS=e=>e&&(Jo(e)||an(e))&&an(e.then)&&an(e.catch),Yg=((e,t)=>e?setImmediate:t?((n,r)=>(vi.addEventListener("message",({source:i,data:s})=>{i===vi&&s===n&&r.length&&r.shift()()},!1),i=>{r.push(i),vi.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",an(vi.postMessage)),nS=typeof queueMicrotask<"u"?queueMicrotask.bind(vi):typeof process<"u"&&process.nextTick||Yg,rS=e=>e!=null&&an(e[$a]),z={isArray:ks,isArrayBuffer:Wg,isBuffer:Zo,isFormData:O_,isArrayBufferView:E_,isString:__,isNumber:Gg,isBoolean:S_,isObject:Jo,isPlainObject:Fc,isEmptyObject:T_,isReadableStream:k_,isRequest:N_,isResponse:U_,isHeaders:R_,isUndefined:bo,isDate:x_,isFile:A_,isBlob:v_,isRegExp:D_,isFunction:an,isStream:I_,isURLSearchParams:P_,isTypedArray:K_,isFileList:B_,forEach:Qo,merge:If,extend:H_,trim:C_,stripBOM:F_,inherits:M_,toFlatObject:q_,kindOf:Ka,kindOfTest:qn,endsWith:V_,toArray:$_,forEachEntry:L_,matchAll:j_,isHTMLForm:W_,hasOwnProperty:hd,hasOwnProp:hd,reduceDescriptors:zg,freezeMethods:X_,toObjectSet:z_,toCamelCase:G_,noop:Y_,toFiniteNumber:Z_,findKey:Dg,global:vi,isContextDefined:Xg,isSpecCompliantForm:J_,toJSONObject:Q_,isAsyncFn:eS,isThenable:tS,setImmediate:Yg,asap:nS,isIterable:rS};function Ie(e,t,n,r,i){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),i&&(this.response=i,this.status=i.status?i.status:null)}z.inherits(Ie,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:z.toJSONObject(this.config),code:this.code,status:this.status}}});const Zg=Ie.prototype,Jg={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Jg[e]={value:e}});Object.defineProperties(Ie,Jg);Object.defineProperty(Zg,"isAxiosError",{value:!0});Ie.from=(e,t,n,r,i,s)=>{const o=Object.create(Zg);return z.toFlatObject(e,o,function(a){return a!==Error.prototype},c=>c!=="isAxiosError"),Ie.call(o,e.message,t,n,r,i),o.cause=e,o.name=e.name,s&&Object.assign(o,s),o};const iS=null;function Of(e){return z.isPlainObject(e)||z.isArray(e)}function Qg(e){return z.endsWith(e,"[]")?e.slice(0,-2):e}function dd(e,t,n){return e?e.concat(t).map(function(i,s){return i=Qg(i),!n&&s?"["+i+"]":i}).join(n?".":""):t}function sS(e){return z.isArray(e)&&!e.some(Of)}const oS=z.toFlatObject(z,{},null,function(t){return/^is[A-Z]/.test(t)});function ja(e,t,n){if(!z.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=z.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(w,E){return!z.isUndefined(E[w])});const r=n.metaTokens,i=n.visitor||f,s=n.dots,o=n.indexes,a=(n.Blob||typeof Blob<"u"&&Blob)&&z.isSpecCompliantForm(t);if(!z.isFunction(i))throw new TypeError("visitor must be a function");function u(g){if(g===null)return"";if(z.isDate(g))return g.toISOString();if(z.isBoolean(g))return g.toString();if(!a&&z.isBlob(g))throw new Ie("Blob is not supported. Use a Buffer instead.");return z.isArrayBuffer(g)||z.isTypedArray(g)?a&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function f(g,w,E){let _=g;if(g&&!E&&typeof g=="object"){if(z.endsWith(w,"{}"))w=r?w:w.slice(0,-2),g=JSON.stringify(g);else if(z.isArray(g)&&sS(g)||(z.isFileList(g)||z.endsWith(w,"[]"))&&(_=z.toArray(g)))return w=Qg(w),_.forEach(function(m,T){!(z.isUndefined(m)||m===null)&&t.append(o===!0?dd([w],T,s):o===null?w:w+"[]",u(m))}),!1}return Of(g)?!0:(t.append(dd(E,w,s),u(g)),!1)}const l=[],p=Object.assign(oS,{defaultVisitor:f,convertValue:u,isVisitable:Of});function y(g,w){if(!z.isUndefined(g)){if(l.indexOf(g)!==-1)throw Error("Circular reference detected in "+w.join("."));l.push(g),z.forEach(g,function(_,S){(!(z.isUndefined(_)||_===null)&&i.call(t,_,z.isString(S)?S.trim():S,w,p))===!0&&y(_,w?w.concat(S):[S])}),l.pop()}}if(!z.isObject(e))throw new TypeError("data must be an object");return y(e),t}function pd(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function wl(e,t){this._pairs=[],e&&ja(e,this,t)}const e1=wl.prototype;e1.append=function(t,n){this._pairs.push([t,n])};e1.toString=function(t){const n=t?function(r){return t.call(this,r,pd)}:pd;return this._pairs.map(function(i){return n(i[0])+"="+n(i[1])},"").join("&")};function cS(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function t1(e,t,n){if(!t)return e;const r=n&&n.encode||cS;z.isFunction(n)&&(n={serialize:n});const i=n&&n.serialize;let s;if(i?s=i(t,n):s=z.isURLSearchParams(t)?t.toString():new wl(t,n).toString(r),s){const o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class yd{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){z.forEach(this.handlers,function(r){r!==null&&t(r)})}}const n1={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},aS=typeof URLSearchParams<"u"?URLSearchParams:wl,uS=typeof FormData<"u"?FormData:null,fS=typeof Blob<"u"?Blob:null,lS={isBrowser:!0,classes:{URLSearchParams:aS,FormData:uS,Blob:fS},protocols:["http","https","file","blob","url","data"]},ml=typeof window<"u"&&typeof document<"u",Pf=typeof navigator=="object"&&navigator||void 0,hS=ml&&(!Pf||["ReactNative","NativeScript","NS"].indexOf(Pf.product)<0),dS=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",pS=ml&&window.location.href||"http://localhost",yS=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ml,hasStandardBrowserEnv:hS,hasStandardBrowserWebWorkerEnv:dS,navigator:Pf,origin:pS},Symbol.toStringTag,{value:"Module"})),Mt={...yS,...lS};function gS(e,t){return ja(e,new Mt.classes.URLSearchParams,{visitor:function(n,r,i,s){return Mt.isNode&&z.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function wS(e){return z.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function mS(e){const t={},n=Object.keys(e);let r;const i=n.length;let s;for(r=0;r<i;r++)s=n[r],t[s]=e[s];return t}function r1(e){function t(n,r,i,s){let o=n[s++];if(o==="__proto__")return!0;const c=Number.isFinite(+o),a=s>=n.length;return o=!o&&z.isArray(i)?i.length:o,a?(z.hasOwnProp(i,o)?i[o]=[i[o],r]:i[o]=r,!c):((!i[o]||!z.isObject(i[o]))&&(i[o]=[]),t(n,r,i[o],s)&&z.isArray(i[o])&&(i[o]=mS(i[o])),!c)}if(z.isFormData(e)&&z.isFunction(e.entries)){const n={};return z.forEachEntry(e,(r,i)=>{t(wS(r),i,n,0)}),n}return null}function bS(e,t,n){if(z.isString(e))try{return(t||JSON.parse)(e),z.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const ec={transitional:n1,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",i=r.indexOf("application/json")>-1,s=z.isObject(t);if(s&&z.isHTMLForm(t)&&(t=new FormData(t)),z.isFormData(t))return i?JSON.stringify(r1(t)):t;if(z.isArrayBuffer(t)||z.isBuffer(t)||z.isStream(t)||z.isFile(t)||z.isBlob(t)||z.isReadableStream(t))return t;if(z.isArrayBufferView(t))return t.buffer;if(z.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return gS(t,this.formSerializer).toString();if((c=z.isFileList(t))||r.indexOf("multipart/form-data")>-1){const a=this.env&&this.env.FormData;return ja(c?{"files[]":t}:t,a&&new a,this.formSerializer)}}return s||i?(n.setContentType("application/json",!1),bS(t)):t}],transformResponse:[function(t){const n=this.transitional||ec.transitional,r=n&&n.forcedJSONParsing,i=this.responseType==="json";if(z.isResponse(t)||z.isReadableStream(t))return t;if(t&&z.isString(t)&&(r&&!this.responseType||i)){const o=!(n&&n.silentJSONParsing)&&i;try{return JSON.parse(t)}catch(c){if(o)throw c.name==="SyntaxError"?Ie.from(c,Ie.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Mt.classes.FormData,Blob:Mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};z.forEach(["delete","get","head","post","put","patch"],e=>{ec.headers[e]={}});const ES=z.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),_S=e=>{const t={};let n,r,i;return e&&e.split(`
|
|
26
|
-
`).forEach(function(o){i=o.indexOf(":"),n=o.substring(0,i).trim().toLowerCase(),r=o.substring(i+1).trim(),!(!n||t[n]&&ES[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},gd=Symbol("internals");function
|
|
27
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[gd]=this[gd]={accessors:{}}).accessors,i=this.prototype;function s(o){const c=Ks(o);r[c]||(AS(i,o),r[c]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};un.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);z.reduceDescriptors(un.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});z.freezeMethods(un);function ku(e,t){const n=this||ec,r=t||n,i=un.from(r.headers);let s=r.data;return z.forEach(e,function(c){s=c.call(n,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function i1(e){return!!(e&&e.__CANCEL__)}function Ns(e,t,n){Ie.call(this,e??"canceled",Ie.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(Ns,Ie,{__CANCEL__:!0});function s1(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ie("Request failed with status code "+n.status,[Ie.ERR_BAD_REQUEST,Ie.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function vS(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function BS(e,t){e=e||10;const n=new Array(e),r=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(a){const u=Date.now(),f=r[s];o||(o=u),n[i]=a,r[i]=u;let l=s,p=0;for(;l!==i;)p+=n[l++],l=l%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const y=f&&u-f;return y?Math.round(p*1e3/y):void 0}}function IS(e,t){let n=0,r=1e3/t,i,s;const o=(u,f=Date.now())=>{n=f,i=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const f=Date.now(),l=f-n;l>=r?o(u,f):(i=u,s||(s=setTimeout(()=>{s=null,o(i)},r-l)))},()=>i&&o(i)]}const ra=(e,t,n=3)=>{let r=0;const i=BS(50,250);return IS(s=>{const o=s.loaded,c=s.lengthComputable?s.total:void 0,a=o-r,u=i(a),f=o<=c;r=o;const l={loaded:o,total:c,progress:c?o/c:void 0,bytes:a,rate:u||void 0,estimated:u&&c&&f?(c-o)/u:void 0,event:s,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(l)},n)},wd=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},md=e=>(...t)=>z.asap(()=>e(...t)),OS=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,PS=Mt.hasStandardBrowserEnv?{write(e,t,n,r,i,s){const o=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),z.isString(r)&&o.push("path="+r),z.isString(i)&&o.push("domain="+i),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function kS(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function NS(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function o1(e,t,n){let r=!kS(t);return e&&(r||n==!1)?NS(e,t):t}const bd=e=>e instanceof un?{...e}:e;function qi(e,t){t=t||{};const n={};function r(u,f,l,p){return z.isPlainObject(u)&&z.isPlainObject(f)?z.merge.call({caseless:p},u,f):z.isPlainObject(f)?z.merge({},f):z.isArray(f)?f.slice():f}function i(u,f,l,p){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u,l,p)}else return r(u,f,l,p)}function s(u,f){if(!z.isUndefined(f))return r(void 0,f)}function o(u,f){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u)}else return r(void 0,f)}function c(u,f,l){if(l in t)return r(u,f);if(l in e)return r(void 0,u)}const a={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c,headers:(u,f,l)=>i(bd(u),bd(f),l,!0)};return z.forEach(Object.keys({...e,...t}),function(f){const l=a[f]||i,p=l(e[f],t[f],f);z.isUndefined(p)&&l!==c||(n[f]=p)}),n}const c1=e=>{const t=qi({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:c}=t;t.headers=o=un.from(o),t.url=t1(o1(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&o.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let a;if(z.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((a=o.getContentType())!==!1){const[u,...f]=a?a.split(";").map(l=>l.trim()).filter(Boolean):[];o.setContentType([u||"multipart/form-data",...f].join("; "))}}if(Mt.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&OS(t.url))){const u=i&&s&&PS.read(s);u&&o.set(i,u)}return t},US=typeof XMLHttpRequest<"u",RS=US&&function(e){return new Promise(function(n,r){const i=c1(e);let s=i.data;const o=un.from(i.headers).normalize();let{responseType:c,onUploadProgress:a,onDownloadProgress:u}=i,f,l,p,y,g;function w(){y&&y(),g&&g(),i.cancelToken&&i.cancelToken.unsubscribe(f),i.signal&&i.signal.removeEventListener("abort",f)}let E=new XMLHttpRequest;E.open(i.method.toUpperCase(),i.url,!0),E.timeout=i.timeout;function _(){if(!E)return;const m=un.from("getAllResponseHeaders"in E&&E.getAllResponseHeaders()),I={data:!c||c==="text"||c==="json"?E.responseText:E.response,status:E.status,statusText:E.statusText,headers:m,config:e,request:E};s1(function(U){n(U),w()},function(U){r(U),w()},I),E=null}"onloadend"in E?E.onloadend=_:E.onreadystatechange=function(){!E||E.readyState!==4||E.status===0&&!(E.responseURL&&E.responseURL.indexOf("file:")===0)||setTimeout(_)},E.onabort=function(){E&&(r(new Ie("Request aborted",Ie.ECONNABORTED,e,E)),E=null)},E.onerror=function(){r(new Ie("Network Error",Ie.ERR_NETWORK,e,E)),E=null},E.ontimeout=function(){let T=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const I=i.transitional||n1;i.timeoutErrorMessage&&(T=i.timeoutErrorMessage),r(new Ie(T,I.clarifyTimeoutError?Ie.ETIMEDOUT:Ie.ECONNABORTED,e,E)),E=null},s===void 0&&o.setContentType(null),"setRequestHeader"in E&&z.forEach(o.toJSON(),function(T,I){E.setRequestHeader(I,T)}),z.isUndefined(i.withCredentials)||(E.withCredentials=!!i.withCredentials),c&&c!=="json"&&(E.responseType=i.responseType),u&&([p,g]=ra(u,!0),E.addEventListener("progress",p)),a&&E.upload&&([l,y]=ra(a),E.upload.addEventListener("progress",l),E.upload.addEventListener("loadend",y)),(i.cancelToken||i.signal)&&(f=m=>{E&&(r(!m||m.type?new Ns(null,e,E):m),E.abort(),E=null)},i.cancelToken&&i.cancelToken.subscribe(f),i.signal&&(i.signal.aborted?f():i.signal.addEventListener("abort",f)));const S=vS(i.url);if(S&&Mt.protocols.indexOf(S)===-1){r(new Ie("Unsupported protocol "+S+":",Ie.ERR_BAD_REQUEST,e));return}E.send(s||null)})},CS=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,i;const s=function(u){if(!i){i=!0,c();const f=u instanceof Error?u:this.reason;r.abort(f instanceof Ie?f:new Ns(f instanceof Error?f.message:f))}};let o=t&&setTimeout(()=>{o=null,s(new Ie(`timeout ${t} of ms exceeded`,Ie.ETIMEDOUT))},t);const c=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:a}=r;return a.unsubscribe=()=>z.asap(c),a}},HS=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,i;for(;r<n;)i=r+t,yield e.slice(r,i),r=i},FS=async function*(e,t){for await(const n of MS(e))yield*HS(n,t)},MS=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Ed=(e,t,n,r)=>{const i=FS(e,t);let s=0,o,c=a=>{o||(o=!0,r&&r(a))};return new ReadableStream({async pull(a){try{const{done:u,value:f}=await i.next();if(u){c(),a.close();return}let l=f.byteLength;if(n){let p=s+=l;n(p)}a.enqueue(new Uint8Array(f))}catch(u){throw c(u),u}},cancel(a){return c(a),i.return()}},{highWaterMark:2})},Wa=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",a1=Wa&&typeof ReadableStream=="function",qS=Wa&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),u1=(e,...t)=>{try{return!!e(...t)}catch{return!1}},VS=a1&&u1(()=>{let e=!1;const t=new Request(Mt.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),_d=64*1024,kf=a1&&u1(()=>z.isReadableStream(new Response("").body)),ia={stream:kf&&(e=>e.body)};Wa&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!ia[t]&&(ia[t]=z.isFunction(e[t])?n=>n[t]():(n,r)=>{throw new Ie(`Response type '${t}' is not supported`,Ie.ERR_NOT_SUPPORT,r)})})})(new Response);const $S=async e=>{if(e==null)return 0;if(z.isBlob(e))return e.size;if(z.isSpecCompliantForm(e))return(await new Request(Mt.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(z.isArrayBufferView(e)||z.isArrayBuffer(e))return e.byteLength;if(z.isURLSearchParams(e)&&(e=e+""),z.isString(e))return(await qS(e)).byteLength},KS=async(e,t)=>{const n=z.toFiniteNumber(e.getContentLength());return n??$S(t)},LS=Wa&&(async e=>{let{url:t,method:n,data:r,signal:i,cancelToken:s,timeout:o,onDownloadProgress:c,onUploadProgress:a,responseType:u,headers:f,withCredentials:l="same-origin",fetchOptions:p}=c1(e);u=u?(u+"").toLowerCase():"text";let y=CS([i,s&&s.toAbortSignal()],o),g;const w=y&&y.unsubscribe&&(()=>{y.unsubscribe()});let E;try{if(a&&VS&&n!=="get"&&n!=="head"&&(E=await KS(f,r))!==0){let I=new Request(t,{method:"POST",body:r,duplex:"half"}),A;if(z.isFormData(r)&&(A=I.headers.get("content-type"))&&f.setContentType(A),I.body){const[U,M]=wd(E,ra(md(a)));r=Ed(I.body,_d,U,M)}}z.isString(l)||(l=l?"include":"omit");const _="credentials"in Request.prototype;g=new Request(t,{...p,signal:y,method:n.toUpperCase(),headers:f.normalize().toJSON(),body:r,duplex:"half",credentials:_?l:void 0});let S=await fetch(g,p);const m=kf&&(u==="stream"||u==="response");if(kf&&(c||m&&w)){const I={};["status","statusText","headers"].forEach(v=>{I[v]=S[v]});const A=z.toFiniteNumber(S.headers.get("content-length")),[U,M]=c&&wd(A,ra(md(c),!0))||[];S=new Response(Ed(S.body,_d,U,()=>{M&&M(),w&&w()}),I)}u=u||"text";let T=await ia[z.findKey(ia,u)||"text"](S,e);return!m&&w&&w(),await new Promise((I,A)=>{s1(I,A,{data:T,headers:un.from(S.headers),status:S.status,statusText:S.statusText,config:e,request:g})})}catch(_){throw w&&w(),_&&_.name==="TypeError"&&/Load failed|fetch/i.test(_.message)?Object.assign(new Ie("Network Error",Ie.ERR_NETWORK,e,g),{cause:_.cause||_}):Ie.from(_,_&&_.code,e,g)}}),Nf={http:iS,xhr:RS,fetch:LS};z.forEach(Nf,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Sd=e=>`- ${e}`,jS=e=>z.isFunction(e)||e===null||e===!1,f1={getAdapter:e=>{e=z.isArray(e)?e:[e];const{length:t}=e;let n,r;const i={};for(let s=0;s<t;s++){n=e[s];let o;if(r=n,!jS(n)&&(r=Nf[(o=String(n)).toLowerCase()],r===void 0))throw new Ie(`Unknown adapter '${o}'`);if(r)break;i[o||"#"+s]=r}if(!r){const s=Object.entries(i).map(([c,a])=>`adapter ${c} `+(a===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since :
|
|
24
|
+
`)}return a.encodeValue(u)}));return Fe(r,i,s,o,c)}function gg(e,t){const n=new ks(t);if(t.byteLength<Hc.length)throw new Error("Message length smaller than magic number");const r=Hi(n,Hc.length),i=new TextDecoder().decode(r);if(i!==Hc)throw new Error("Wrong magic number: "+JSON.stringify(i));function s(p){const y=[],g=Number(xt(p));for(let _=0;_<g;_++){const S=Number(Dr(p));switch(S){case He.Opt:case He.Vector:{const m=Number(Dr(p));y.push([S,m]);break}case He.Record:case He.Variant:{const m=[];let T=Number(xt(p)),I;for(;T--;){const A=Number(xt(p));if(A>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof I=="number"&&I>=A)throw new Error("field id collision or not sorted");I=A;const U=Number(Dr(p));m.push([A,U])}y.push([S,m]);break}case He.Func:{const m=[];let T=Number(xt(p));for(;T--;)m.push(Number(Dr(p)));const I=[];let A=Number(xt(p));for(;A--;)I.push(Number(Dr(p)));const U=[];let M=Number(xt(p));for(;M--;)switch(Number(xt(p))){case 1:{U.push("query");break}case 2:{U.push("oneway");break}case 3:{U.push("composite_query");break}default:throw new Error("unknown annotation")}y.push([S,[m,I,U]]);break}case He.Service:{let m=Number(xt(p));const T=[];for(;m--;){const I=Number(xt(p)),A=new TextDecoder().decode(Hi(p,I)),U=Dr(p);T.push([A,U])}y.push([S,T]);break}default:throw new Error("Illegal op_code: "+S)}}const w=[],E=Number(xt(p));for(let _=0;_<E;_++)w.push(Number(Dr(p)));return[y,w]}const[o,c]=s(n);if(c.length<e.length)throw new Error("Wrong number of return values");const a=o.map(p=>Vg());function u(p){if(p<-24)throw new Error("future value not supported");if(p<0)switch(p){case-1:return Eg;case-2:return bg;case-3:return Tg;case-4:return Sg;case-5:return Pg;case-6:return kg;case-7:return Ng;case-8:return Ug;case-9:return vg;case-10:return Bg;case-11:return Ig;case-12:return Og;case-13:return xg;case-14:return Ag;case-15:return _g;case-16:return mg;case-17:return wg;case-24:return Rg;default:throw new Error("Illegal op_code: "+p)}if(p>=o.length)throw new Error("type index out of range");return a[p]}function f(p){switch(p[0]){case He.Vector:{const y=u(p[1]);return Hg(y)}case He.Opt:{const y=u(p[1]);return Fg(y)}case He.Record:{const y={};for(const[E,_]of p[1]){const S=`_${E}_`;y[S]=u(_)}const g=Mg(y),w=g.tryAsTuple();return Array.isArray(w)?Cg(...w):g}case He.Variant:{const y={};for(const[g,w]of p[1]){const E=`_${g}_`;y[E]=u(w)}return qg(y)}case He.Func:{const[y,g,w]=p[1];return $g(y.map(E=>u(E)),g.map(E=>u(E)),w)}case He.Service:{const y={},g=p[1];for(const[w,E]of g){let _=u(E);if(_ instanceof xn&&(_=_.getType()),!(_ instanceof mo))throw new Error("Illegal service definition: services can only contain functions");y[w]=_}return Kg(y)}default:throw new Error("Illegal op_code: "+p[0])}}o.forEach((p,y)=>{if(p[0]===He.Func){const g=f(p);a[y].fill(g)}}),o.forEach((p,y)=>{if(p[0]!==He.Func){const g=f(p);a[y].fill(g)}}),If();const l=c.map(p=>u(p));try{const p=e.map((y,g)=>y.decodeValue(n,l[g]));for(let y=e.length;y<l.length;y++)l[y].decodeValue(n,l[y]);if(n.byteLength>0)throw new Error("decode: Left-over bytes");return p}finally{If()}}const wg=new ll,mg=new si,g_=new hg,bg=new dg,Eg=new wo,_g=new pg,Sg=new hl,Tg=new dl,xg=new pl(32),Ag=new pl(64),vg=new Mi(8),Bg=new Mi(16),Ig=new Mi(32),Og=new Mi(64),Pg=new ti(8),kg=new ti(16),Ng=new ti(32),Ug=new ti(64),Rg=new yg;function Cg(...e){return new Va(e)}function Hg(e){return new _s(e)}function Fg(e){return new Er(e)}function Mg(e){return new qi(e)}function qg(e){return new Ss(e)}function Vg(){return new xn}function $g(e,t,n=[]){return new mo(e,t,n)}function Kg(e){return new ra(e)}class $a{constructor(t=new Map){this.rels=t}copy(){const t=new Map;for(const[n,r]of this.rels.entries()){const i=new Map(r);t.set(n,i)}return new $a(t)}known(t,n){return this.rels.get(t.name)?.get(n.name)}addNegative(t,n){this.addNames(t.name,n.name,!1)}add(t,n){this.addNames(t.name,n.name,!0)}display(){let t="";for(const[n,r]of this.rels)for(const[i,s]of r)t+=`${n} ${s?":<":"!<:"} ${i}
|
|
25
|
+
`;return t}addNames(t,n,r){const i=this.rels.get(t);if(i==null){const s=new Map;s.set(n,r),this.rels.set(t,s)}else i.set(n,r)}}let Fc=new $a;function If(){Fc=new $a}function w_(e,t){const n=new Set(e.annotations),r=new Set(t.annotations);if(n.size!==r.size)return!1;for(const i of n)if(!r.has(i))return!1;return!0}function Pu(e){return e instanceof Er||e instanceof wo||e instanceof si}function gl(e,t){const n=Fc.copy(),r=or(n,e,t);return r?Fc.add(e,t):Fc.addNegative(e,t),r}function or(e,t,n){if(t.name===n.name)return!0;const r=e.known(t,n);if(r!==void 0)return r;if(e.add(t,n),n instanceof si||t instanceof ll||t instanceof dl&&n instanceof hl)return!0;if(t instanceof _s&&n instanceof _s)return or(e,t._type,n._type);if(n instanceof Er)return!0;if(t instanceof qi&&n instanceof qi){const i=t.fieldsAsObject;for(const[s,o]of n._fields){const c=i[tn(s)];if(c){if(!or(e,c,o))return!1}else if(!Pu(o))return!1}return!0}if(t instanceof mo&&n instanceof mo){if(!w_(t,n))return!1;for(let i=0;i<t.argTypes.length;i++){const s=t.argTypes[i];if(i<n.argTypes.length){if(!or(e,n.argTypes[i],s))return!1}else if(!Pu(s))return!1}for(let i=0;i<n.retTypes.length;i++){const s=n.retTypes[i];if(i<t.retTypes.length){if(!or(e,t.retTypes[i],s))return!1}else if(!Pu(s))return!1}return!0}if(t instanceof Ss&&n instanceof Ss){const i=n.alternativesAsObject;for(const[s,o]of t._fields){const c=i[tn(s)];if(!c||!or(e,o,c))return!1}return!0}if(t instanceof ra&&n instanceof ra){const i=t.fieldsAsObject();for(const[s,o]of n._fields){const c=i[s];if(!c||!or(e,c,o))return!1}return!0}return t instanceof xn?or(e,t.getType(),n):n instanceof xn?or(e,t,n.getType()):!1}const m_=Object.freeze(Object.defineProperty({__proto__:null,Bool:bg,BoolClass:dg,ConstructType:ci,Empty:wg,EmptyClass:ll,FixedIntClass:Mi,FixedNatClass:ti,Float32:xg,Float64:Ag,FloatClass:pl,Func:$g,FuncClass:mo,Int:Sg,Int16:Bg,Int32:Ig,Int64:Og,Int8:vg,IntClass:hl,Nat:Tg,Nat16:kg,Nat32:Ng,Nat64:Ug,Nat8:Pg,NatClass:dl,Null:Eg,NullClass:wo,Opt:Fg,OptClass:Er,PrimitiveType:Bn,Principal:Rg,PrincipalClass:yg,Rec:Vg,RecClass:xn,Record:Mg,RecordClass:qi,Reserved:mg,ReservedClass:si,Service:Kg,ServiceClass:ra,Text:_g,TextClass:pg,Tuple:Cg,TupleClass:Va,Type:qa,Unknown:g_,UnknownClass:hg,Variant:qg,VariantClass:Ss,Vec:Hg,VecClass:_s,Visitor:y_,decode:gg,encode:Bf,resetSubtypeCache:If,subtype:gl},Symbol.toStringTag,{value:"Module"}));function Lg(e,t){return function(){return e.apply(t,arguments)}}const{toString:b_}=Object.prototype,{getPrototypeOf:wl}=Object,{iterator:Ka,toStringTag:jg}=Symbol,La=(e=>t=>{const n=b_.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),qn=e=>(e=e.toLowerCase(),t=>La(t)===e),ja=e=>t=>typeof t===e,{isArray:Ns}=Array,bo=ja("undefined");function Jo(e){return e!==null&&!bo(e)&&e.constructor!==null&&!bo(e.constructor)&&an(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Wg=qn("ArrayBuffer");function E_(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Wg(e.buffer),t}const __=ja("string"),an=ja("function"),Gg=ja("number"),Qo=e=>e!==null&&typeof e=="object",S_=e=>e===!0||e===!1,Mc=e=>{if(La(e)!=="object")return!1;const t=wl(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(jg in e)&&!(Ka in e)},T_=e=>{if(!Qo(e)||Jo(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},x_=qn("Date"),A_=qn("File"),v_=qn("Blob"),B_=qn("FileList"),I_=e=>Qo(e)&&an(e.pipe),O_=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||an(e.append)&&((t=La(e))==="formdata"||t==="object"&&an(e.toString)&&e.toString()==="[object FormData]"))},P_=qn("URLSearchParams"),[k_,N_,U_,R_]=["ReadableStream","Request","Response","Headers"].map(qn),C_=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function ec(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,i;if(typeof e!="object"&&(e=[e]),Ns(e))for(r=0,i=e.length;r<i;r++)t.call(null,e[r],r,e);else{if(Jo(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),o=s.length;let c;for(r=0;r<o;r++)c=s[r],t.call(null,e[c],c,e)}}function Dg(e,t){if(Jo(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,i;for(;r-- >0;)if(i=n[r],t===i.toLowerCase())return i;return null}const Bi=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:globalThis,Xg=e=>!bo(e)&&e!==Bi;function Of(){const{caseless:e}=Xg(this)&&this||{},t={},n=(r,i)=>{const s=e&&Dg(t,i)||i;Mc(t[s])&&Mc(r)?t[s]=Of(t[s],r):Mc(r)?t[s]=Of({},r):Ns(r)?t[s]=r.slice():t[s]=r};for(let r=0,i=arguments.length;r<i;r++)arguments[r]&&ec(arguments[r],n);return t}const H_=(e,t,n,{allOwnKeys:r}={})=>(ec(t,(i,s)=>{n&&an(i)?e[s]=Lg(i,n):e[s]=i},{allOwnKeys:r}),e),F_=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),M_=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},q_=(e,t,n,r)=>{let i,s,o;const c={};if(t=t||{},e==null)return t;do{for(i=Object.getOwnPropertyNames(e),s=i.length;s-- >0;)o=i[s],(!r||r(o,e,t))&&!c[o]&&(t[o]=e[o],c[o]=!0);e=n!==!1&&wl(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},V_=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},$_=e=>{if(!e)return null;if(Ns(e))return e;let t=e.length;if(!Gg(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},K_=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&wl(Uint8Array)),L_=(e,t)=>{const r=(e&&e[Ka]).call(e);let i;for(;(i=r.next())&&!i.done;){const s=i.value;t.call(e,s[0],s[1])}},j_=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},W_=qn("HTMLFormElement"),G_=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,i){return r.toUpperCase()+i}),hd=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),D_=qn("RegExp"),zg=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};ec(n,(i,s)=>{let o;(o=t(i,s,e))!==!1&&(r[s]=o||i)}),Object.defineProperties(e,r)},X_=e=>{zg(e,(t,n)=>{if(an(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(an(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},z_=(e,t)=>{const n={},r=i=>{i.forEach(s=>{n[s]=!0})};return Ns(e)?r(e):r(String(e).split(t)),n},Y_=()=>{},Z_=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function J_(e){return!!(e&&an(e.append)&&e[jg]==="FormData"&&e[Ka])}const Q_=e=>{const t=new Array(10),n=(r,i)=>{if(Qo(r)){if(t.indexOf(r)>=0)return;if(Jo(r))return r;if(!("toJSON"in r)){t[i]=r;const s=Ns(r)?[]:{};return ec(r,(o,c)=>{const a=n(o,i+1);!bo(a)&&(s[c]=a)}),t[i]=void 0,s}}return r};return n(e,0)},eS=qn("AsyncFunction"),tS=e=>e&&(Qo(e)||an(e))&&an(e.then)&&an(e.catch),Yg=((e,t)=>e?setImmediate:t?((n,r)=>(Bi.addEventListener("message",({source:i,data:s})=>{i===Bi&&s===n&&r.length&&r.shift()()},!1),i=>{r.push(i),Bi.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",an(Bi.postMessage)),nS=typeof queueMicrotask<"u"?queueMicrotask.bind(Bi):typeof process<"u"&&process.nextTick||Yg,rS=e=>e!=null&&an(e[Ka]),z={isArray:Ns,isArrayBuffer:Wg,isBuffer:Jo,isFormData:O_,isArrayBufferView:E_,isString:__,isNumber:Gg,isBoolean:S_,isObject:Qo,isPlainObject:Mc,isEmptyObject:T_,isReadableStream:k_,isRequest:N_,isResponse:U_,isHeaders:R_,isUndefined:bo,isDate:x_,isFile:A_,isBlob:v_,isRegExp:D_,isFunction:an,isStream:I_,isURLSearchParams:P_,isTypedArray:K_,isFileList:B_,forEach:ec,merge:Of,extend:H_,trim:C_,stripBOM:F_,inherits:M_,toFlatObject:q_,kindOf:La,kindOfTest:qn,endsWith:V_,toArray:$_,forEachEntry:L_,matchAll:j_,isHTMLForm:W_,hasOwnProperty:hd,hasOwnProp:hd,reduceDescriptors:zg,freezeMethods:X_,toObjectSet:z_,toCamelCase:G_,noop:Y_,toFiniteNumber:Z_,findKey:Dg,global:Bi,isContextDefined:Xg,isSpecCompliantForm:J_,toJSONObject:Q_,isAsyncFn:eS,isThenable:tS,setImmediate:Yg,asap:nS,isIterable:rS};function Ie(e,t,n,r,i){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),i&&(this.response=i,this.status=i.status?i.status:null)}z.inherits(Ie,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:z.toJSONObject(this.config),code:this.code,status:this.status}}});const Zg=Ie.prototype,Jg={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Jg[e]={value:e}});Object.defineProperties(Ie,Jg);Object.defineProperty(Zg,"isAxiosError",{value:!0});Ie.from=(e,t,n,r,i,s)=>{const o=Object.create(Zg);return z.toFlatObject(e,o,function(a){return a!==Error.prototype},c=>c!=="isAxiosError"),Ie.call(o,e.message,t,n,r,i),o.cause=e,o.name=e.name,s&&Object.assign(o,s),o};const iS=null;function Pf(e){return z.isPlainObject(e)||z.isArray(e)}function Qg(e){return z.endsWith(e,"[]")?e.slice(0,-2):e}function dd(e,t,n){return e?e.concat(t).map(function(i,s){return i=Qg(i),!n&&s?"["+i+"]":i}).join(n?".":""):t}function sS(e){return z.isArray(e)&&!e.some(Pf)}const oS=z.toFlatObject(z,{},null,function(t){return/^is[A-Z]/.test(t)});function Wa(e,t,n){if(!z.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=z.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(w,E){return!z.isUndefined(E[w])});const r=n.metaTokens,i=n.visitor||f,s=n.dots,o=n.indexes,a=(n.Blob||typeof Blob<"u"&&Blob)&&z.isSpecCompliantForm(t);if(!z.isFunction(i))throw new TypeError("visitor must be a function");function u(g){if(g===null)return"";if(z.isDate(g))return g.toISOString();if(z.isBoolean(g))return g.toString();if(!a&&z.isBlob(g))throw new Ie("Blob is not supported. Use a Buffer instead.");return z.isArrayBuffer(g)||z.isTypedArray(g)?a&&typeof Blob=="function"?new Blob([g]):Buffer.from(g):g}function f(g,w,E){let _=g;if(g&&!E&&typeof g=="object"){if(z.endsWith(w,"{}"))w=r?w:w.slice(0,-2),g=JSON.stringify(g);else if(z.isArray(g)&&sS(g)||(z.isFileList(g)||z.endsWith(w,"[]"))&&(_=z.toArray(g)))return w=Qg(w),_.forEach(function(m,T){!(z.isUndefined(m)||m===null)&&t.append(o===!0?dd([w],T,s):o===null?w:w+"[]",u(m))}),!1}return Pf(g)?!0:(t.append(dd(E,w,s),u(g)),!1)}const l=[],p=Object.assign(oS,{defaultVisitor:f,convertValue:u,isVisitable:Pf});function y(g,w){if(!z.isUndefined(g)){if(l.indexOf(g)!==-1)throw Error("Circular reference detected in "+w.join("."));l.push(g),z.forEach(g,function(_,S){(!(z.isUndefined(_)||_===null)&&i.call(t,_,z.isString(S)?S.trim():S,w,p))===!0&&y(_,w?w.concat(S):[S])}),l.pop()}}if(!z.isObject(e))throw new TypeError("data must be an object");return y(e),t}function pd(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function ml(e,t){this._pairs=[],e&&Wa(e,this,t)}const e1=ml.prototype;e1.append=function(t,n){this._pairs.push([t,n])};e1.toString=function(t){const n=t?function(r){return t.call(this,r,pd)}:pd;return this._pairs.map(function(i){return n(i[0])+"="+n(i[1])},"").join("&")};function cS(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function t1(e,t,n){if(!t)return e;const r=n&&n.encode||cS;z.isFunction(n)&&(n={serialize:n});const i=n&&n.serialize;let s;if(i?s=i(t,n):s=z.isURLSearchParams(t)?t.toString():new ml(t,n).toString(r),s){const o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class yd{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){z.forEach(this.handlers,function(r){r!==null&&t(r)})}}const n1={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},aS=typeof URLSearchParams<"u"?URLSearchParams:ml,uS=typeof FormData<"u"?FormData:null,fS=typeof Blob<"u"?Blob:null,lS={isBrowser:!0,classes:{URLSearchParams:aS,FormData:uS,Blob:fS},protocols:["http","https","file","blob","url","data"]},bl=typeof window<"u"&&typeof document<"u",kf=typeof navigator=="object"&&navigator||void 0,hS=bl&&(!kf||["ReactNative","NativeScript","NS"].indexOf(kf.product)<0),dS=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",pS=bl&&window.location.href||"http://localhost",yS=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:bl,hasStandardBrowserEnv:hS,hasStandardBrowserWebWorkerEnv:dS,navigator:kf,origin:pS},Symbol.toStringTag,{value:"Module"})),Mt={...yS,...lS};function gS(e,t){return Wa(e,new Mt.classes.URLSearchParams,{visitor:function(n,r,i,s){return Mt.isNode&&z.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function wS(e){return z.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function mS(e){const t={},n=Object.keys(e);let r;const i=n.length;let s;for(r=0;r<i;r++)s=n[r],t[s]=e[s];return t}function r1(e){function t(n,r,i,s){let o=n[s++];if(o==="__proto__")return!0;const c=Number.isFinite(+o),a=s>=n.length;return o=!o&&z.isArray(i)?i.length:o,a?(z.hasOwnProp(i,o)?i[o]=[i[o],r]:i[o]=r,!c):((!i[o]||!z.isObject(i[o]))&&(i[o]=[]),t(n,r,i[o],s)&&z.isArray(i[o])&&(i[o]=mS(i[o])),!c)}if(z.isFormData(e)&&z.isFunction(e.entries)){const n={};return z.forEachEntry(e,(r,i)=>{t(wS(r),i,n,0)}),n}return null}function bS(e,t,n){if(z.isString(e))try{return(t||JSON.parse)(e),z.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const tc={transitional:n1,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",i=r.indexOf("application/json")>-1,s=z.isObject(t);if(s&&z.isHTMLForm(t)&&(t=new FormData(t)),z.isFormData(t))return i?JSON.stringify(r1(t)):t;if(z.isArrayBuffer(t)||z.isBuffer(t)||z.isStream(t)||z.isFile(t)||z.isBlob(t)||z.isReadableStream(t))return t;if(z.isArrayBufferView(t))return t.buffer;if(z.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return gS(t,this.formSerializer).toString();if((c=z.isFileList(t))||r.indexOf("multipart/form-data")>-1){const a=this.env&&this.env.FormData;return Wa(c?{"files[]":t}:t,a&&new a,this.formSerializer)}}return s||i?(n.setContentType("application/json",!1),bS(t)):t}],transformResponse:[function(t){const n=this.transitional||tc.transitional,r=n&&n.forcedJSONParsing,i=this.responseType==="json";if(z.isResponse(t)||z.isReadableStream(t))return t;if(t&&z.isString(t)&&(r&&!this.responseType||i)){const o=!(n&&n.silentJSONParsing)&&i;try{return JSON.parse(t)}catch(c){if(o)throw c.name==="SyntaxError"?Ie.from(c,Ie.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Mt.classes.FormData,Blob:Mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};z.forEach(["delete","get","head","post","put","patch"],e=>{tc.headers[e]={}});const ES=z.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),_S=e=>{const t={};let n,r,i;return e&&e.split(`
|
|
26
|
+
`).forEach(function(o){i=o.indexOf(":"),n=o.substring(0,i).trim().toLowerCase(),r=o.substring(i+1).trim(),!(!n||t[n]&&ES[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},gd=Symbol("internals");function Ls(e){return e&&String(e).trim().toLowerCase()}function qc(e){return e===!1||e==null?e:z.isArray(e)?e.map(qc):String(e)}function SS(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const TS=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ku(e,t,n,r,i){if(z.isFunction(r))return r.call(this,t,n);if(i&&(t=n),!!z.isString(t)){if(z.isString(r))return t.indexOf(r)!==-1;if(z.isRegExp(r))return r.test(t)}}function xS(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function AS(e,t){const n=z.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(i,s,o){return this[r].call(this,t,i,s,o)},configurable:!0})})}let un=class{constructor(t){t&&this.set(t)}set(t,n,r){const i=this;function s(c,a,u){const f=Ls(a);if(!f)throw new Error("header name must be a non-empty string");const l=z.findKey(i,f);(!l||i[l]===void 0||u===!0||u===void 0&&i[l]!==!1)&&(i[l||a]=qc(c))}const o=(c,a)=>z.forEach(c,(u,f)=>s(u,f,a));if(z.isPlainObject(t)||t instanceof this.constructor)o(t,n);else if(z.isString(t)&&(t=t.trim())&&!TS(t))o(_S(t),n);else if(z.isObject(t)&&z.isIterable(t)){let c={},a,u;for(const f of t){if(!z.isArray(f))throw TypeError("Object iterator must return a key-value pair");c[u=f[0]]=(a=c[u])?z.isArray(a)?[...a,f[1]]:[a,f[1]]:f[1]}o(c,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Ls(t),t){const r=z.findKey(this,t);if(r){const i=this[r];if(!n)return i;if(n===!0)return SS(i);if(z.isFunction(n))return n.call(this,i,r);if(z.isRegExp(n))return n.exec(i);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Ls(t),t){const r=z.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||ku(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let i=!1;function s(o){if(o=Ls(o),o){const c=z.findKey(r,o);c&&(!n||ku(r,r[c],c,n))&&(delete r[c],i=!0)}}return z.isArray(t)?t.forEach(s):s(t),i}clear(t){const n=Object.keys(this);let r=n.length,i=!1;for(;r--;){const s=n[r];(!t||ku(this,this[s],s,t,!0))&&(delete this[s],i=!0)}return i}normalize(t){const n=this,r={};return z.forEach(this,(i,s)=>{const o=z.findKey(r,s);if(o){n[o]=qc(i),delete n[s];return}const c=t?xS(s):String(s).trim();c!==s&&delete n[s],n[c]=qc(i),r[c]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return z.forEach(this,(r,i)=>{r!=null&&r!==!1&&(n[i]=t&&z.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
27
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[gd]=this[gd]={accessors:{}}).accessors,i=this.prototype;function s(o){const c=Ls(o);r[c]||(AS(i,o),r[c]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};un.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);z.reduceDescriptors(un.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});z.freezeMethods(un);function Nu(e,t){const n=this||tc,r=t||n,i=un.from(r.headers);let s=r.data;return z.forEach(e,function(c){s=c.call(n,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function i1(e){return!!(e&&e.__CANCEL__)}function Us(e,t,n){Ie.call(this,e??"canceled",Ie.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(Us,Ie,{__CANCEL__:!0});function s1(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ie("Request failed with status code "+n.status,[Ie.ERR_BAD_REQUEST,Ie.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function vS(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function BS(e,t){e=e||10;const n=new Array(e),r=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(a){const u=Date.now(),f=r[s];o||(o=u),n[i]=a,r[i]=u;let l=s,p=0;for(;l!==i;)p+=n[l++],l=l%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const y=f&&u-f;return y?Math.round(p*1e3/y):void 0}}function IS(e,t){let n=0,r=1e3/t,i,s;const o=(u,f=Date.now())=>{n=f,i=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const f=Date.now(),l=f-n;l>=r?o(u,f):(i=u,s||(s=setTimeout(()=>{s=null,o(i)},r-l)))},()=>i&&o(i)]}const ia=(e,t,n=3)=>{let r=0;const i=BS(50,250);return IS(s=>{const o=s.loaded,c=s.lengthComputable?s.total:void 0,a=o-r,u=i(a),f=o<=c;r=o;const l={loaded:o,total:c,progress:c?o/c:void 0,bytes:a,rate:u||void 0,estimated:u&&c&&f?(c-o)/u:void 0,event:s,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(l)},n)},wd=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},md=e=>(...t)=>z.asap(()=>e(...t)),OS=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,PS=Mt.hasStandardBrowserEnv?{write(e,t,n,r,i,s){const o=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),z.isString(r)&&o.push("path="+r),z.isString(i)&&o.push("domain="+i),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function kS(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function NS(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function o1(e,t,n){let r=!kS(t);return e&&(r||n==!1)?NS(e,t):t}const bd=e=>e instanceof un?{...e}:e;function Vi(e,t){t=t||{};const n={};function r(u,f,l,p){return z.isPlainObject(u)&&z.isPlainObject(f)?z.merge.call({caseless:p},u,f):z.isPlainObject(f)?z.merge({},f):z.isArray(f)?f.slice():f}function i(u,f,l,p){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u,l,p)}else return r(u,f,l,p)}function s(u,f){if(!z.isUndefined(f))return r(void 0,f)}function o(u,f){if(z.isUndefined(f)){if(!z.isUndefined(u))return r(void 0,u)}else return r(void 0,f)}function c(u,f,l){if(l in t)return r(u,f);if(l in e)return r(void 0,u)}const a={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c,headers:(u,f,l)=>i(bd(u),bd(f),l,!0)};return z.forEach(Object.keys({...e,...t}),function(f){const l=a[f]||i,p=l(e[f],t[f],f);z.isUndefined(p)&&l!==c||(n[f]=p)}),n}const c1=e=>{const t=Vi({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:c}=t;t.headers=o=un.from(o),t.url=t1(o1(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&o.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let a;if(z.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((a=o.getContentType())!==!1){const[u,...f]=a?a.split(";").map(l=>l.trim()).filter(Boolean):[];o.setContentType([u||"multipart/form-data",...f].join("; "))}}if(Mt.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&OS(t.url))){const u=i&&s&&PS.read(s);u&&o.set(i,u)}return t},US=typeof XMLHttpRequest<"u",RS=US&&function(e){return new Promise(function(n,r){const i=c1(e);let s=i.data;const o=un.from(i.headers).normalize();let{responseType:c,onUploadProgress:a,onDownloadProgress:u}=i,f,l,p,y,g;function w(){y&&y(),g&&g(),i.cancelToken&&i.cancelToken.unsubscribe(f),i.signal&&i.signal.removeEventListener("abort",f)}let E=new XMLHttpRequest;E.open(i.method.toUpperCase(),i.url,!0),E.timeout=i.timeout;function _(){if(!E)return;const m=un.from("getAllResponseHeaders"in E&&E.getAllResponseHeaders()),I={data:!c||c==="text"||c==="json"?E.responseText:E.response,status:E.status,statusText:E.statusText,headers:m,config:e,request:E};s1(function(U){n(U),w()},function(U){r(U),w()},I),E=null}"onloadend"in E?E.onloadend=_:E.onreadystatechange=function(){!E||E.readyState!==4||E.status===0&&!(E.responseURL&&E.responseURL.indexOf("file:")===0)||setTimeout(_)},E.onabort=function(){E&&(r(new Ie("Request aborted",Ie.ECONNABORTED,e,E)),E=null)},E.onerror=function(){r(new Ie("Network Error",Ie.ERR_NETWORK,e,E)),E=null},E.ontimeout=function(){let T=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const I=i.transitional||n1;i.timeoutErrorMessage&&(T=i.timeoutErrorMessage),r(new Ie(T,I.clarifyTimeoutError?Ie.ETIMEDOUT:Ie.ECONNABORTED,e,E)),E=null},s===void 0&&o.setContentType(null),"setRequestHeader"in E&&z.forEach(o.toJSON(),function(T,I){E.setRequestHeader(I,T)}),z.isUndefined(i.withCredentials)||(E.withCredentials=!!i.withCredentials),c&&c!=="json"&&(E.responseType=i.responseType),u&&([p,g]=ia(u,!0),E.addEventListener("progress",p)),a&&E.upload&&([l,y]=ia(a),E.upload.addEventListener("progress",l),E.upload.addEventListener("loadend",y)),(i.cancelToken||i.signal)&&(f=m=>{E&&(r(!m||m.type?new Us(null,e,E):m),E.abort(),E=null)},i.cancelToken&&i.cancelToken.subscribe(f),i.signal&&(i.signal.aborted?f():i.signal.addEventListener("abort",f)));const S=vS(i.url);if(S&&Mt.protocols.indexOf(S)===-1){r(new Ie("Unsupported protocol "+S+":",Ie.ERR_BAD_REQUEST,e));return}E.send(s||null)})},CS=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,i;const s=function(u){if(!i){i=!0,c();const f=u instanceof Error?u:this.reason;r.abort(f instanceof Ie?f:new Us(f instanceof Error?f.message:f))}};let o=t&&setTimeout(()=>{o=null,s(new Ie(`timeout ${t} of ms exceeded`,Ie.ETIMEDOUT))},t);const c=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:a}=r;return a.unsubscribe=()=>z.asap(c),a}},HS=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,i;for(;r<n;)i=r+t,yield e.slice(r,i),r=i},FS=async function*(e,t){for await(const n of MS(e))yield*HS(n,t)},MS=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Ed=(e,t,n,r)=>{const i=FS(e,t);let s=0,o,c=a=>{o||(o=!0,r&&r(a))};return new ReadableStream({async pull(a){try{const{done:u,value:f}=await i.next();if(u){c(),a.close();return}let l=f.byteLength;if(n){let p=s+=l;n(p)}a.enqueue(new Uint8Array(f))}catch(u){throw c(u),u}},cancel(a){return c(a),i.return()}},{highWaterMark:2})},Ga=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",a1=Ga&&typeof ReadableStream=="function",qS=Ga&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),u1=(e,...t)=>{try{return!!e(...t)}catch{return!1}},VS=a1&&u1(()=>{let e=!1;const t=new Request(Mt.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),_d=64*1024,Nf=a1&&u1(()=>z.isReadableStream(new Response("").body)),sa={stream:Nf&&(e=>e.body)};Ga&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!sa[t]&&(sa[t]=z.isFunction(e[t])?n=>n[t]():(n,r)=>{throw new Ie(`Response type '${t}' is not supported`,Ie.ERR_NOT_SUPPORT,r)})})})(new Response);const $S=async e=>{if(e==null)return 0;if(z.isBlob(e))return e.size;if(z.isSpecCompliantForm(e))return(await new Request(Mt.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(z.isArrayBufferView(e)||z.isArrayBuffer(e))return e.byteLength;if(z.isURLSearchParams(e)&&(e=e+""),z.isString(e))return(await qS(e)).byteLength},KS=async(e,t)=>{const n=z.toFiniteNumber(e.getContentLength());return n??$S(t)},LS=Ga&&(async e=>{let{url:t,method:n,data:r,signal:i,cancelToken:s,timeout:o,onDownloadProgress:c,onUploadProgress:a,responseType:u,headers:f,withCredentials:l="same-origin",fetchOptions:p}=c1(e);u=u?(u+"").toLowerCase():"text";let y=CS([i,s&&s.toAbortSignal()],o),g;const w=y&&y.unsubscribe&&(()=>{y.unsubscribe()});let E;try{if(a&&VS&&n!=="get"&&n!=="head"&&(E=await KS(f,r))!==0){let I=new Request(t,{method:"POST",body:r,duplex:"half"}),A;if(z.isFormData(r)&&(A=I.headers.get("content-type"))&&f.setContentType(A),I.body){const[U,M]=wd(E,ia(md(a)));r=Ed(I.body,_d,U,M)}}z.isString(l)||(l=l?"include":"omit");const _="credentials"in Request.prototype;g=new Request(t,{...p,signal:y,method:n.toUpperCase(),headers:f.normalize().toJSON(),body:r,duplex:"half",credentials:_?l:void 0});let S=await fetch(g,p);const m=Nf&&(u==="stream"||u==="response");if(Nf&&(c||m&&w)){const I={};["status","statusText","headers"].forEach(v=>{I[v]=S[v]});const A=z.toFiniteNumber(S.headers.get("content-length")),[U,M]=c&&wd(A,ia(md(c),!0))||[];S=new Response(Ed(S.body,_d,U,()=>{M&&M(),w&&w()}),I)}u=u||"text";let T=await sa[z.findKey(sa,u)||"text"](S,e);return!m&&w&&w(),await new Promise((I,A)=>{s1(I,A,{data:T,headers:un.from(S.headers),status:S.status,statusText:S.statusText,config:e,request:g})})}catch(_){throw w&&w(),_&&_.name==="TypeError"&&/Load failed|fetch/i.test(_.message)?Object.assign(new Ie("Network Error",Ie.ERR_NETWORK,e,g),{cause:_.cause||_}):Ie.from(_,_&&_.code,e,g)}}),Uf={http:iS,xhr:RS,fetch:LS};z.forEach(Uf,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Sd=e=>`- ${e}`,jS=e=>z.isFunction(e)||e===null||e===!1,f1={getAdapter:e=>{e=z.isArray(e)?e:[e];const{length:t}=e;let n,r;const i={};for(let s=0;s<t;s++){n=e[s];let o;if(r=n,!jS(n)&&(r=Uf[(o=String(n)).toLowerCase()],r===void 0))throw new Ie(`Unknown adapter '${o}'`);if(r)break;i[o||"#"+s]=r}if(!r){const s=Object.entries(i).map(([c,a])=>`adapter ${c} `+(a===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since :
|
|
28
28
|
`+s.map(Sd).join(`
|
|
29
|
-
`):" "+Sd(s[0]):"as no adapter specified";throw new Ie("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:
|
|
30
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=
|
|
29
|
+
`):" "+Sd(s[0]):"as no adapter specified";throw new Ie("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:Uf};function Uu(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Us(null,e)}function Td(e){return Uu(e),e.headers=un.from(e.headers),e.data=Nu.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),f1.getAdapter(e.adapter||tc.adapter)(e).then(function(r){return Uu(e),r.data=Nu.call(e,e.transformResponse,r),r.headers=un.from(r.headers),r},function(r){return i1(r)||(Uu(e),r&&r.response&&(r.response.data=Nu.call(e,e.transformResponse,r.response),r.response.headers=un.from(r.response.headers))),Promise.reject(r)})}const l1="1.11.0",Da={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Da[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const xd={};Da.transitional=function(t,n,r){function i(s,o){return"[Axios v"+l1+"] Transitional option '"+s+"'"+o+(r?". "+r:"")}return(s,o,c)=>{if(t===!1)throw new Ie(i(o," has been removed"+(n?" in "+n:"")),Ie.ERR_DEPRECATED);return n&&!xd[o]&&(xd[o]=!0,console.warn(i(o," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,o,c):!0}};Da.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function WS(e,t,n){if(typeof e!="object")throw new Ie("options must be an object",Ie.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let i=r.length;for(;i-- >0;){const s=r[i],o=t[s];if(o){const c=e[s],a=c===void 0||o(c,s,e);if(a!==!0)throw new Ie("option "+s+" must be "+a,Ie.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ie("Unknown option "+s,Ie.ERR_BAD_OPTION)}}const Vc={assertOptions:WS,validators:Da},Ln=Vc.validators;let Ni=class{constructor(t){this.defaults=t||{},this.interceptors={request:new yd,response:new yd}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
30
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Vi(this.defaults,n);const{transitional:r,paramsSerializer:i,headers:s}=n;r!==void 0&&Vc.assertOptions(r,{silentJSONParsing:Ln.transitional(Ln.boolean),forcedJSONParsing:Ln.transitional(Ln.boolean),clarifyTimeoutError:Ln.transitional(Ln.boolean)},!1),i!=null&&(z.isFunction(i)?n.paramsSerializer={serialize:i}:Vc.assertOptions(i,{encode:Ln.function,serialize:Ln.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Vc.assertOptions(n,{baseUrl:Ln.spelling("baseURL"),withXsrfToken:Ln.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=un.concat(o,s);const c=[];let a=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(n)===!1||(a=a&&w.synchronous,c.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let f,l=0,p;if(!a){const g=[Td.bind(this),void 0];for(g.unshift(...c),g.push(...u),p=g.length,f=Promise.resolve(n);l<p;)f=f.then(g[l++],g[l++]);return f}p=c.length;let y=n;for(l=0;l<p;){const g=c[l++],w=c[l++];try{y=g(y)}catch(E){w.call(this,E);break}}try{f=Td.call(this,y)}catch(g){return Promise.reject(g)}for(l=0,p=u.length;l<p;)f=f.then(u[l++],u[l++]);return f}getUri(t){t=Vi(this.defaults,t);const n=o1(t.baseURL,t.url,t.allowAbsoluteUrls);return t1(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Ni.prototype[t]=function(n,r){return this.request(Vi(r||{},{method:t,url:n,data:(r||{}).data}))}});z.forEach(["post","put","patch"],function(t){function n(r){return function(s,o,c){return this.request(Vi(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Ni.prototype[t]=n(),Ni.prototype[t+"Form"]=n(!0)});let GS=class h1{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(i=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](i);r._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(c=>{r.subscribe(c),s=c}).then(i);return o.cancel=function(){r.unsubscribe(s)},o},t(function(s,o,c){r.reason||(r.reason=new Us(s,o,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new h1(function(i){t=i}),cancel:t}}};function DS(e){return function(n){return e.apply(null,n)}}function XS(e){return z.isObject(e)&&e.isAxiosError===!0}const Rf={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Rf).forEach(([e,t])=>{Rf[t]=e});function d1(e){const t=new Ni(e),n=Lg(Ni.prototype.request,t);return z.extend(n,Ni.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(i){return d1(Vi(e,i))},n}const at=d1(tc);at.Axios=Ni;at.CanceledError=Us;at.CancelToken=GS;at.isCancel=i1;at.VERSION=l1;at.toFormData=Wa;at.AxiosError=Ie;at.Cancel=at.CanceledError;at.all=function(t){return Promise.all(t)};at.spread=DS;at.isAxiosError=XS;at.mergeConfig=Vi;at.AxiosHeaders=un;at.formToJSON=e=>r1(z.isHTMLForm(e)?new FormData(e):e);at.getAdapter=f1.getAdapter;at.HttpStatusCode=Rf;at.default=at;const{Axios:F6,AxiosError:M6,CanceledError:q6,isCancel:V6,CancelToken:$6,VERSION:K6,all:L6,Cancel:j6,isAxiosError:W6,spread:G6,toFormData:D6,AxiosHeaders:X6,HttpStatusCode:z6,formToJSON:Y6,getAdapter:Z6,mergeConfig:J6}=at;class zS{axios;constructor(t){this.axios=at.create({baseURL:t.baseUrl,headers:{Accept:"application/json","Content-Type":"application/json","x-api-key":`${t.apiKey}`}})}async utxosByAddress(t,n=0,r=5e3){return await this.axios.get(`/v2/bitcoin/address/${t}/utxo?offset=${n}&limit=${r}`).then(s=>s.data)}async runeUtxosByAddress(t,n,r=0,i=5e3){return await this.axios.get(`/v1/runes/address/${t}/utxo?runeId=${n}&includeUnconfirmed=false&offset=${r}&limit=${i}`).then(o=>o.data)}}var Ad;(function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"})(Ad||(Ad={}));var Ts;(function(e){e.Replied="replied",e.Rejected="rejected"})(Ts||(Ts={}));function YS(e){return e!=null&&"reject_code"in e}function ZS(e){return e!=null&&"certificate"in e}var _r;(function(e){e.Trust="Trust",e.Protocol="Protocol",e.Reject="Reject",e.Transport="Transport",e.External="External",e.Limit="Limit",e.Input="Input",e.Unknown="Unknown"})(_r||(_r={}));class ke{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
|
|
31
31
|
Request context:
|
|
32
32
|
Request ID (hex): ${this.requestContext.requestId?Qe(this.requestContext.requestId):"undefined"}
|
|
33
33
|
Sender pubkey (hex): ${Qe(this.requestContext.senderPubKey)}
|
|
@@ -36,47 +36,47 @@ Request context:
|
|
|
36
36
|
Call context:
|
|
37
37
|
Canister ID: ${this.callContext.canisterId.toText()}
|
|
38
38
|
Method name: ${this.callContext.methodName}
|
|
39
|
-
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}}class lr extends Error{get code(){return this.cause.code}set code(t){this.cause.code=t}get kind(){return this.cause.kind}set kind(t){this.cause.kind=t}get isCertified(){return this.code.isCertified}constructor(t,n){super(t.toString()),this.name="AgentError",this.cause={code:t,kind:n},Object.setPrototypeOf(this,lr.prototype)}hasCode(t){return this.code instanceof t}toString(){return`${this.name} (${this.kind}): ${this.message}`}}class
|
|
39
|
+
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}}class lr extends Error{get code(){return this.cause.code}set code(t){this.cause.code=t}get kind(){return this.cause.kind}set kind(t){this.cause.kind=t}get isCertified(){return this.code.isCertified}constructor(t,n){super(t.toString()),this.name="AgentError",this.cause={code:t,kind:n},Object.setPrototypeOf(this,lr.prototype)}hasCode(t){return this.code instanceof t}toString(){return`${this.name} (${this.kind}): ${this.message}`}}class ji extends lr{static fromCode(t){return new this(t)}}class bn extends ji{constructor(t){super(t,_r.Trust),this.name="TrustError",Object.setPrototypeOf(this,bn.prototype)}}class lt extends ji{constructor(t){super(t,_r.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,lt.prototype)}}class ls extends ji{constructor(t){super(t,_r.Reject),this.name="RejectError",Object.setPrototypeOf(this,ls.prototype)}}class oa extends ji{constructor(t){super(t,_r.Transport),this.name="TransportError",Object.setPrototypeOf(this,oa.prototype)}}class nn extends ji{constructor(t){super(t,_r.External),this.name="ExternalError",Object.setPrototypeOf(this,nn.prototype)}}class Ye extends ji{constructor(t){super(t,_r.Input),this.name="InputError",Object.setPrototypeOf(this,Ye.prototype)}}class rn extends ji{constructor(t){super(t,_r.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,rn.prototype)}}class hs extends ke{constructor(t,n){super(),this.reason=t,this.error=n,this.name="CertificateVerificationErrorCode",Object.setPrototypeOf(this,hs.prototype)}toErrorMessage(){let t=this.reason;return this.error&&(t+=`: ${rc(this.error)}`),`Certificate verification error: "${t}"`}}class Eo extends ke{constructor(t,n,r,i,s){super(),this.maxAgeInMinutes=t,this.certificateTime=n,this.currentTime=r,this.timeDiffMsecs=i,this.ageType=s,this.name="CertificateTimeErrorCode",Object.setPrototypeOf(this,Eo.prototype)}toErrorMessage(){return`Certificate is signed more than ${this.maxAgeInMinutes} minutes in the ${this.ageType}. Certificate time: ${this.certificateTime.toISOString()} Current time: ${this.currentTime.toISOString()} Clock drift: ${this.timeDiffMsecs}ms`}}class El extends ke{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,El.prototype)}toErrorMessage(){return"Certificate has too many delegations"}}class Xa extends ke{constructor(t,n){super(),this.canisterId=t,this.subnetId=n,this.name="CertificateNotAuthorizedErrorCode",Object.setPrototypeOf(this,Xa.prototype)}toErrorMessage(){return`The certificate contains a delegation that does not include the canister ${this.canisterId.toText()} in the canister_ranges field. Subnet ID: ${this.subnetId.toText()}`}}class xs extends ke{constructor(t,n){super(),this.message=t,this.lookupStatus=n,this.name="LookupErrorCode",Object.setPrototypeOf(this,xs.prototype)}toErrorMessage(){return`${this.message}. Lookup status: ${this.lookupStatus}`}}class za extends ke{constructor(t){super(),this.message=t,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,za.prototype)}toErrorMessage(){return this.message}}class _l extends ke{constructor(t){super(),this.message=t,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,_l.prototype)}toErrorMessage(){return this.message}}class Ya extends ke{constructor(t,n){super(),this.expectedLength=t,this.actualLength=n,this.name="DerKeyLengthMismatchErrorCode",Object.setPrototypeOf(this,Ya.prototype)}toErrorMessage(){return`BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`}}class Sl extends ke{constructor(t,n){super(),this.expectedPrefix=t,this.actualPrefix=n,this.name="DerPrefixMismatchErrorCode",Object.setPrototypeOf(this,Sl.prototype)}toErrorMessage(){return`BLS DER-encoded public key is invalid. Expected the following prefix: ${Qe(this.expectedPrefix)}, but got ${Qe(this.actualPrefix)}`}}class Tl extends ke{constructor(t,n){super(),this.expectedLength=t,this.actualLength=n,this.name="DerDecodeLengthMismatchErrorCode",Object.setPrototypeOf(this,Tl.prototype)}toErrorMessage(){return`DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`}}class Sr extends ke{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,Sr.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}}class Za extends ke{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,Za.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}}class xl extends ke{constructor(t,n){super(),this.error=t,this.input=n,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,xl.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${rc(this.error)}, input: ${Qe(this.input)}`}}class Al extends ke{constructor(t,n){super(),this.error=t,this.value=n,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,Al.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${rc(this.error)}, input: ${this.value}`}}class _o extends ke{constructor(t,n,r){super(),this.message=t,this.requestId=n,this.status=r,this.name="TimeoutWaitingForResponseErrorCode",Object.setPrototypeOf(this,_o.prototype)}toErrorMessage(){let t=`${this.message}
|
|
40
40
|
`;return this.requestId&&(t+=` Request ID: ${Qe(this.requestId)}
|
|
41
41
|
`),this.status&&(t+=` Request status: ${this.status}
|
|
42
|
-
`),t}}class
|
|
42
|
+
`),t}}class vl extends ke{constructor(t,n,r){super(),this.maxIngressExpiryInMinutes=t,this.requestId=n,this.retryTimes=r,this.name="CertificateOutdatedErrorCode",Object.setPrototypeOf(this,vl.prototype)}toErrorMessage(){let t=`Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
|
|
43
43
|
Request ID: ${Qe(this.requestId)}
|
|
44
|
-
`;return this.retryTimes!==void 0&&(t+=` Retried ${this.retryTimes} times.`),t}}class
|
|
44
|
+
`;return this.retryTimes!==void 0&&(t+=` Retried ${this.retryTimes} times.`),t}}class Ja extends ke{constructor(t,n,r,i){super(!0),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,Ja.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
45
45
|
Request ID: ${Qe(this.requestId)}
|
|
46
46
|
Reject code: ${this.rejectCode}
|
|
47
47
|
Reject text: ${this.rejectMessage}
|
|
48
48
|
Error code: ${this.rejectErrorCode}
|
|
49
|
-
`}}class
|
|
49
|
+
`}}class Bl extends ke{constructor(t,n,r,i,s){super(),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.signatures=s,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,Bl.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
50
50
|
Request ID: ${Qe(this.requestId)}
|
|
51
51
|
Reject code: ${this.rejectCode}
|
|
52
52
|
Reject text: ${this.rejectMessage}
|
|
53
53
|
Error code: ${this.rejectErrorCode}
|
|
54
|
-
`}}class
|
|
54
|
+
`}}class Il extends ke{constructor(t,n,r,i){super(),this.requestId=t,this.rejectCode=n,this.rejectMessage=r,this.rejectErrorCode=i,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,Il.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
55
55
|
Request ID: ${Qe(this.requestId)}
|
|
56
56
|
Reject code: ${this.rejectCode}
|
|
57
57
|
Reject text: ${this.rejectMessage}
|
|
58
58
|
Error code: ${this.rejectErrorCode}
|
|
59
|
-
`}}class
|
|
59
|
+
`}}class Ol extends ke{constructor(t){super(),this.requestId=t,this.name="RequestStatusDoneNoReplyErrorCode",Object.setPrototypeOf(this,Ol.prototype)}toErrorMessage(){return`Call was marked as done but we never saw the reply:
|
|
60
60
|
Request ID: ${Qe(this.requestId)}
|
|
61
|
-
`}}class
|
|
61
|
+
`}}class Rs extends ke{constructor(t){super(),this.shouldFetchRootKey=t,this.name="MissingRootKeyErrorCode",Object.setPrototypeOf(this,Rs.prototype)}toErrorMessage(){return this.shouldFetchRootKey===void 0?"Agent is missing root key":`Agent is missing root key and the shouldFetchRootKey value is set to ${this.shouldFetchRootKey}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`}}class Pl extends ke{constructor(t){super(),this.value=t,this.name="HashValueErrorCode",Object.setPrototypeOf(this,Pl.prototype)}toErrorMessage(){return`Attempt to hash a value of unsupported type: ${this.value}`}}class uo extends ke{constructor(t){super(),this.error=t,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,uo.prototype)}toErrorMessage(){return this.error}}class Ai extends ke{constructor(){super(),this.name="IdentityInvalidErrorCode",Object.setPrototypeOf(this,Ai.prototype)}toErrorMessage(){return"This identity has expired due this application's security policy. Please refresh your authentication."}}class os extends ke{constructor(t,n){super(),this.message=t,this.providedIngressExpiryInMinutes=n,this.name="IngressExpiryInvalidErrorCode",Object.setPrototypeOf(this,os.prototype)}toErrorMessage(){return`${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`}}class kl extends ke{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,kl.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}}class Nl extends ke{constructor(t){super(),this.error=t,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,Nl.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}}class Ul extends ke{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,Ul.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}}class Rl extends ke{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,Rl.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}}class Cl extends ke{constructor(t){super(),this.nodeId=t,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,Cl.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}}class Un extends ke{constructor(t){super(),this.error=t,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,Un.prototype)}toErrorMessage(){return`Unexpected error: ${rc(this.error)}`}}class nc extends ke{constructor(t){super(),this.error=t,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,nc.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}}class ca extends ke{constructor(t,n,r,i){super(),this.status=t,this.statusText=n,this.headers=r,this.bodyText=i,this.name="HttpErrorCode",Object.setPrototypeOf(this,ca.prototype)}toErrorMessage(){let t=`HTTP request failed:
|
|
62
62
|
Status: ${this.status} (${this.statusText})
|
|
63
63
|
Headers: ${JSON.stringify(this.headers)}
|
|
64
64
|
`;return this.bodyText&&(t+=` Body: ${this.bodyText}
|
|
65
|
-
`),t}}class
|
|
66
|
-
ic-request`);const JS=new TextEncoder().encode("\vic-response");new TextEncoder().encode("ic-request-auth-delegation");class vd{getPrincipal(){return $e.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}}class ji extends Error{constructor(t){super(t),this.name="DecodingError"}}const y1=55799,g1=Symbol("CBOR_STOP_CODE");var Rn=(e=>(e[e.False=20]="False",e[e.True=21]="True",e[e.Null=22]="Null",e[e.Undefined=23]="Undefined",e[e.Break=31]="Break",e))(Rn||{}),mt=(e=>(e[e.UnsignedInteger=0]="UnsignedInteger",e[e.NegativeInteger=1]="NegativeInteger",e[e.ByteString=2]="ByteString",e[e.TextString=3]="TextString",e[e.Array=4]="Array",e[e.Map=5]="Map",e[e.Tag=6]="Tag",e[e.Simple=7]="Simple",e))(mt||{});const QS=23,e3=255,t3=65535,n3=4294967295,r3=BigInt("0xffffffffffffffff");var Nn=(e=>(e[e.Value=23]="Value",e[e.OneByte=24]="OneByte",e[e.TwoBytes=25]="TwoBytes",e[e.FourBytes=26]="FourBytes",e[e.EightBytes=27]="EightBytes",e[e.Indefinite=31]="Indefinite",e))(Nn||{});const ds=!1;function i3(e){return e==null}function w1(e,t){const n=new Uint8Array(t);return n.set(e),n}const s3=new TextDecoder;function o3(e){return(e&224)>>5}function c3(e){return e&31}let So=new Uint8Array,Ls,Cn=0;function a3(e,t){So=e,Cn=0;const n=Ni();return t?.(n)??n}function Ni(e){const[t,n]=Vc();switch(t){case mt.UnsignedInteger:return Rs(n);case mt.NegativeInteger:return h3(n);case mt.ByteString:return m1(n);case mt.TextString:return Cf(n);case mt.Array:return u3(n);case mt.Map:return l3(n);case mt.Tag:return d3(n);case mt.Simple:return f3(n)}throw new ji(`Unsupported major type: ${t}`)}function Vc(){const e=So.at(Cn);if(i3(e))throw new ji("Provided CBOR data is empty");const t=o3(e),n=c3(e);return Cn++,[t,n]}function u3(e,t){const n=Rs(e);if(n===1/0){const i=[];let s=Ni();for(;s!==g1;)i.push(s),s=Ni();return i}const r=new Array(n);for(let i=0;i<n;i++){const s=Ni();r[i]=s}return r}function f3(e){switch(e){case Rn.False:return!1;case Rn.True:return!0;case Rn.Null:return null;case Rn.Undefined:return;case Rn.Break:return g1}throw new ji(`Unrecognized simple type: ${e.toString(2)}`)}function l3(e,t){const n=Rs(e),r={};if(n===1/0){let[i,s]=Vc();for(;i!==mt.Simple&&s!==Rn.Break;){const o=Cf(s),c=Ni();r[o]=c,[i,s]=Vc()}return r}for(let i=0;i<n;i++){const[s,o]=Vc();if(s!==mt.TextString)throw new ji("Map keys must be text strings");const c=Cf(o),a=Ni();r[c]=a}return r}function Rs(e){if(e<=Nn.Value)return e;switch(Ls=new DataView(So.buffer,So.byteOffset+Cn),e){case Nn.OneByte:return Cn++,Ls.getUint8(0);case Nn.TwoBytes:return Cn+=2,Ls.getUint16(0,ds);case Nn.FourBytes:return Cn+=4,Ls.getUint32(0,ds);case Nn.EightBytes:return Cn+=8,Ls.getBigUint64(0,ds);case Nn.Indefinite:return 1/0;default:throw new ji(`Unsupported integer info: ${e.toString(2)}`)}}function h3(e){const t=Rs(e);return typeof t=="number"?-1-t:-1n-t}function m1(e){const t=Rs(e);if(t>Number.MAX_SAFE_INTEGER)throw new ji("Byte length is too large");const n=Number(t);return Cn+=n,So.slice(Cn-n,Cn)}function Cf(e){const t=m1(e);return s3.decode(t)}function d3(e,t){const n=Rs(e);if(n===y1)return Ni();throw new ji(`Unsupported tag: ${n}.`)}class Hl extends Error{constructor(t){super(t),this.name="SerializationError"}}const p3=2*1024,y3=100,g3=new TextEncoder;function js(e){return e<<5}let hn=new Uint8Array(p3),On=new DataView(hn.buffer),wt=0,Ru=[];function w3(e,t){wt=0;const n=t?.(e)??e;return A3(y1,n,t),hn.slice(0,wt)}function Fl(e,t){if(wt>hn.length-y3&&(hn=w1(hn,hn.length*2),On=new DataView(hn.buffer)),e===!1||e===!0||e===null||e===void 0){E3(e);return}if(typeof e=="number"||typeof e=="bigint"){x3(e);return}if(typeof e=="string"){_1(e);return}if(e instanceof Uint8Array){Bd(e);return}if(e instanceof ArrayBuffer){Bd(new Uint8Array(e));return}if(Array.isArray(e)){m3(e,t);return}if(typeof e=="object"){b3(e,t);return}throw new Hl(`Unsupported type: ${typeof e}`)}function m3(e,t){Cs(mt.Array,e.length),e.forEach((n,r)=>{Fl(t?.(n,r.toString())??n,t)})}function b3(e,t){Ru=Object.entries(e),Cs(mt.Map,Ru.length),Ru.forEach(([n,r])=>{_1(n),Fl(t?.(r,n)??r,t)})}function Cs(e,t){if(t<=QS){On.setUint8(wt++,js(e)|Number(t));return}if(t<=e3){On.setUint8(wt++,js(e)|Nn.OneByte),On.setUint8(wt,Number(t)),wt+=1;return}if(t<=t3){On.setUint8(wt++,js(e)|Nn.TwoBytes),On.setUint16(wt,Number(t),ds),wt+=2;return}if(t<=n3){On.setUint8(wt++,js(e)|Nn.FourBytes),On.setUint32(wt,Number(t),ds),wt+=4;return}if(t<=r3){On.setUint8(wt++,js(e)|Nn.EightBytes),On.setBigUint64(wt,BigInt(t),ds),wt+=8;return}throw new Hl(`Value too large to encode: ${t}`)}function E3(e){Cs(mt.Simple,_3(e))}function _3(e){if(e===!1)return Rn.False;if(e===!0)return Rn.True;if(e===null)return Rn.Null;if(e===void 0)return Rn.Undefined;throw new Hl(`Unrecognized simple value: ${e.toString()}`)}function b1(e,t){Cs(e,t.length),wt>hn.length-t.length&&(hn=w1(hn,hn.length+t.length),On=new DataView(hn.buffer)),hn.set(t,wt),wt+=t.length}function E1(e,t){Cs(e,t)}function S3(e){E1(mt.UnsignedInteger,e)}function T3(e){E1(mt.NegativeInteger,typeof e=="bigint"?-1n-e:-1-e)}function x3(e){e>=0?S3(e):T3(e)}function _1(e){b1(mt.TextString,g3.encode(e))}function Bd(e){b1(mt.ByteString,e)}function A3(e,t,n){Cs(mt.Tag,e),Fl(t,n)}function v3(e){return typeof e=="object"&&e!==null&&"toCborValue"in e}function Cu(e){try{return w3(e,t=>$e.isPrincipal(t)?t.toUint8Array():ps.isExpiry(t)?t.toBigInt():v3(t)?t.toCborValue():t)}catch(t){throw Ye.fromCode(new xl(t,e))}}function Dn(e){try{return a3(e)}catch(t){throw Ye.fromCode(new Tl(t,e))}}const Ec=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){const e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if(typeof crypto<"u"&&crypto.getRandomValues){const e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Bi;(function(e){e.Query="read",e.ReadState="read_state",e.Call="call"})(Bi||(Bi={}));var Hf;(function(e){e.Call="call"})(Hf||(Hf={}));var To;(function(e){e.Query="query",e.ReadState="read_state"})(To||(To={}));function Ff(){const e=new ArrayBuffer(16),t=new DataView(e),n=Ec(),r=Ec(),i=Ec(),s=Ec();return t.setUint32(0,n),t.setUint32(4,r),t.setUint32(8,i),t.setUint32(12,s),Object.assign(new Uint8Array(e),{__nonce__:void 0})}const _c="__expiry__",Ml=BigInt(1e3),B3=BigInt(1e6),S1=BigInt(60),I3=BigInt(90)*Ml;function T1(e){return e/Ml}function O3(e){return T1(e)/S1}class ps{constructor(t){this.__expiry__=t,this._isExpiry=!0}static fromDeltaInMilliseconds(t,n=0){const r=BigInt(t),i=BigInt(Date.now())+r+BigInt(n);let s;return r<I3?s=T1(i):s=O3(i)*S1,new ps(s*Ml*B3)}toBigInt(){return this.__expiry__}toHash(){return ot(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[_c]:this.toString()}}static fromJSON(t){const n=JSON.parse(t);if(n[_c])try{const r=BigInt(n[_c]);return new ps(r)}catch(r){throw new Ye(new fa(`Not a valid BigInt: ${r}`))}throw new Ye(new fa(`The input does not contain the key ${_c}`))}static isExpiry(t){return t instanceof ps||typeof t=="object"&&t!==null&&"_isExpiry"in t&&t._isExpiry===!0&&"__expiry__"in t&&typeof t.__expiry__=="bigint"}}function Id(e=Ff){return async t=>{const n=t.request.headers;t.request.headers=n,t.endpoint===Bi.Call&&(t.body.nonce=e())}}function Hu(e){const t=[];return e.forEach((n,r)=>{t.push([r,n])}),t}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ql=BigInt(0),da=BigInt(1);function xo(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function ys(e,t,n=""){const r=Lo(e),i=e?.length,s=t!==void 0;if(!r||s&&i!==t){const o=n&&`"${n}" `,c=s?` of length ${t}`:"",a=r?`length=${i}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+c+", got "+a)}return e}function x1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ql:BigInt("0x"+e)}function Yn(e){return x1(Qe(e))}function Ao(e){return Sn(e),x1(Qe(Uint8Array.from(e).reverse()))}function Ot(e,t){return jo(e.toString(16).padStart(t*2,"0"))}function A1(e,t){return Ot(e,t).reverse()}function en(e,t,n){let r;if(typeof t=="string")try{r=jo(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Lo(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}function Od(e){return Uint8Array.from(e)}const Fu=e=>typeof e=="bigint"&&ql<=e;function v1(e,t,n){return Fu(e)&&Fu(t)&&Fu(n)&&t<=e&&e<n}function Pd(e,t,n,r){if(!v1(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function vo(e){let t;for(t=0;e>ql;e>>=da,t+=1);return t}function P3(e,t){return e>>BigInt(t)&da}const Wi=e=>(da<<BigInt(e))-da;function k3(e){return typeof e=="function"&&Number.isSafeInteger(e.outputLen)}function rc(e,t,n={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function r(i,s,o){const c=e[i];if(o&&c===void 0)return;const a=typeof c;if(a!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}const B1=()=>{throw new Error("not implemented")};function Bo(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(i!==void 0)return i;const s=e(n,...r);return t.set(n,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const on=BigInt(0),Nt=BigInt(1),Ii=BigInt(2),I1=BigInt(3),O1=BigInt(4),P1=BigInt(5),N3=BigInt(7),k1=BigInt(8),U3=BigInt(9),N1=BigInt(16);function dt(e,t){const n=e%t;return n>=on?n:t+n}function jn(e,t,n){let r=e;for(;t-- >on;)r*=r,r%=n;return r}function kd(e,t){if(e===on)throw new Error("invert: expected non-zero number");if(t<=on)throw new Error("invert: expected positive modulus, got "+t);let n=dt(e,t),r=t,i=on,s=Nt;for(;n!==on;){const c=r/n,a=r%n,u=i-s*c;r=n,n=a,i=s,s=u}if(r!==Nt)throw new Error("invert: does not exist");return dt(i,t)}function Vl(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function U1(e,t){const n=(e.ORDER+Nt)/O1,r=e.pow(t,n);return Vl(e,r,t),r}function R3(e,t){const n=(e.ORDER-P1)/k1,r=e.mul(t,Ii),i=e.pow(r,n),s=e.mul(t,i),o=e.mul(e.mul(s,Ii),i),c=e.mul(s,e.sub(o,e.ONE));return Vl(e,c,t),c}function C3(e){const t=ai(e),n=R1(e),r=n(t,t.neg(t.ONE)),i=n(t,r),s=n(t,t.neg(r)),o=(e+N3)/N1;return(c,a)=>{let u=c.pow(a,o),f=c.mul(u,r);const l=c.mul(u,i),p=c.mul(u,s),y=c.eql(c.sqr(f),a),g=c.eql(c.sqr(l),a);u=c.cmov(u,f,y),f=c.cmov(p,l,g);const w=c.eql(c.sqr(f),a),E=c.cmov(u,f,w);return Vl(c,E,a),E}}function R1(e){if(e<I1)throw new Error("sqrt is not defined for small field");let t=e-Nt,n=0;for(;t%Ii===on;)t/=Ii,n++;let r=Ii;const i=ai(e);for(;pa(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return U1;let s=i.pow(r,t);const o=(t+Nt)/Ii;return function(a,u){if(a.is0(u))return u;if(pa(a,u)!==1)throw new Error("Cannot find square root");let f=n,l=a.mul(a.ONE,s),p=a.pow(u,t),y=a.pow(u,o);for(;!a.eql(p,a.ONE);){if(a.is0(p))return a.ZERO;let g=1,w=a.sqr(p);for(;!a.eql(w,a.ONE);)if(g++,w=a.sqr(w),g===f)throw new Error("Cannot find square root");const E=Nt<<BigInt(f-g-1),_=a.pow(l,E);f=g,l=a.sqr(_),p=a.mul(p,l),y=a.mul(y,_)}return y}}function H3(e){return e%O1===I1?U1:e%k1===P1?R3:e%N1===U3?C3(e):R1(e)}const F3=(e,t)=>(dt(e,t)&Nt)===Nt,M3=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function C1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=M3.reduce((r,i)=>(r[i]="function",r),t);return rc(e,n),e}function Qa(e,t,n){if(n<on)throw new Error("invalid exponent, negatives unsupported");if(n===on)return e.ONE;if(n===Nt)return t;let r=e.ONE,i=t;for(;n>on;)n&Nt&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Nt;return r}function Gi(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((o,c,a)=>e.is0(c)?o:(r[a]=o,e.mul(o,c)),e.ONE),s=e.inv(i);return t.reduceRight((o,c,a)=>e.is0(c)?o:(r[a]=e.mul(o,r[a]),e.mul(o,c)),s),r}function pa(e,t){const n=(e.ORDER-Nt)/Ii,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function q3(e,t){t!==void 0&&Sm(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ai(e,t,n=!1,r={}){if(e<=on)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s,o=!1,c;if(typeof t=="object"&&t!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const p=t;p.BITS&&(i=p.BITS),p.sqrt&&(s=p.sqrt),typeof p.isLE=="boolean"&&(n=p.isLE),typeof p.modFromBytes=="boolean"&&(o=p.modFromBytes),c=p.allowedLengths}else typeof t=="number"&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:a,nByteLength:u}=q3(e,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const l=Object.freeze({ORDER:e,isLE:n,BITS:a,BYTES:u,MASK:Wi(a),ZERO:on,ONE:Nt,allowedLengths:c,create:p=>dt(p,e),isValid:p=>{if(typeof p!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof p);return on<=p&&p<e},is0:p=>p===on,isValidNot0:p=>!l.is0(p)&&l.isValid(p),isOdd:p=>(p&Nt)===Nt,neg:p=>dt(-p,e),eql:(p,y)=>p===y,sqr:p=>dt(p*p,e),add:(p,y)=>dt(p+y,e),sub:(p,y)=>dt(p-y,e),mul:(p,y)=>dt(p*y,e),pow:(p,y)=>Qa(l,p,y),div:(p,y)=>dt(p*kd(y,e),e),sqrN:p=>p*p,addN:(p,y)=>p+y,subN:(p,y)=>p-y,mulN:(p,y)=>p*y,inv:p=>kd(p,e),sqrt:s||(p=>(f||(f=H3(e)),f(l,p))),toBytes:p=>n?A1(p,u):Ot(p,u),fromBytes:(p,y=!0)=>{if(c){if(!c.includes(p.length)||p.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+p.length);const w=new Uint8Array(u);w.set(p,n?0:w.length-p.length),p=w}if(p.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+p.length);let g=n?Ao(p):Yn(p);if(o&&(g=dt(g,e)),!y&&!l.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:p=>Gi(l,p),cmov:(p,y,g)=>g?y:p});return Object.freeze(l)}function H1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function F1(e){const t=H1(e);return t+Math.ceil(t/2)}function V3(e,t,n=!1){const r=e.length,i=H1(t),s=F1(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Ao(e):Yn(e),c=dt(o,t-Nt)+Nt;return n?A1(c,i):Ot(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const xs=BigInt(0),Oi=BigInt(1);function ya(e,t){const n=t.negate();return e?n:t}function dr(e,t){const n=Gi(e.Fp,t.map(r=>r.Z));return t.map((r,i)=>e.fromAffine(r.toAffine(n[i])))}function M1(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Mu(e,t){M1(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e,s=Wi(e),o=BigInt(e);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function Nd(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let c=Number(e&i),a=e>>o;c>r&&(c-=s,a+=Oi);const u=t*r,f=u+Math.abs(c)-1,l=c===0,p=c<0,y=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:p,isNegF:y,offsetF:u}}function $3(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function K3(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,r)=>{if(!t.isValid(n))throw new Error("invalid scalar at index "+r)})}const qu=new WeakMap,q1=new WeakMap;function Vu(e){return q1.get(e)||1}function Ud(e){if(e!==xs)throw new Error("invalid wNAF")}class V1{constructor(t,n){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}_unsafeLadder(t,n,r=this.ZERO){let i=t;for(;n>xs;)n&Oi&&(r=r.add(i)),i=i.double(),n>>=Oi;return r}precomputeWindow(t,n){const{windows:r,windowSize:i}=Mu(n,this.bits),s=[];let o=t,c=o;for(let a=0;a<r;a++){c=o,s.push(c);for(let u=1;u<i;u++)c=c.add(o),s.push(c);o=c.double()}return s}wNAF(t,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=Mu(t,this.bits);for(let c=0;c<o.windows;c++){const{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:p,offsetF:y}=Nd(r,c,o);r=a,f?s=s.add(ya(p,n[y])):i=i.add(ya(l,n[u]))}return Ud(r),{p:i,f:s}}wNAFUnsafe(t,n,r,i=this.ZERO){const s=Mu(t,this.bits);for(let o=0;o<s.windows&&r!==xs;o++){const{nextN:c,offset:a,isZero:u,isNeg:f}=Nd(r,o,s);if(r=c,!u){const l=n[a];i=i.add(f?l.negate():l)}}return Ud(r),i}getPrecomputes(t,n,r){let i=qu.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof r=="function"&&(i=r(i)),qu.set(n,i))),i}cached(t,n,r){const i=Vu(t);return this.wNAF(i,this.getPrecomputes(i,t,r),n)}unsafe(t,n,r,i){const s=Vu(t);return s===1?this._unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,r),n,i)}createCache(t,n){M1(n,this.bits),q1.set(t,n),qu.delete(t)}hasCache(t){return Vu(t)!==1}}function L3(e,t,n,r){let i=t,s=e.ZERO,o=e.ZERO;for(;n>xs||r>xs;)n&Oi&&(s=s.add(i)),r&Oi&&(o=o.add(i)),i=i.double(),n>>=Oi,r>>=Oi;return{p1:s,p2:o}}function $1(e,t,n,r){$3(n,e),K3(r,t);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,c=vo(BigInt(i));let a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);const u=Wi(a),f=new Array(Number(u)+1).fill(o),l=Math.floor((t.BITS-1)/a)*a;let p=o;for(let y=l;y>=0;y-=a){f.fill(o);for(let w=0;w<s;w++){const E=r[w],_=Number(E>>BigInt(y)&u);f[_]=f[_].add(n[w])}let g=o;for(let w=f.length-1,E=o;w>0;w--)E=E.add(f[w]),g=g.add(E);if(p=p.add(g),y!==0)for(let w=0;w<a;w++)p=p.double()}return p}function Rd(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return C1(t),t}else return ai(e,{isLE:n})}function K1(e,t,n={},r){if(r===void 0&&(r=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const u=t[a];if(!(typeof u=="bigint"&&u>xs))throw new Error(`CURVE.${a} must be positive bigint`)}const i=Rd(t.p,n.Fp,r),s=Rd(t.n,n.Fn,r),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(const a of c)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:s}}const j3=Yn;function Xr(e,t){if(Io(e),Io(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function W3(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r];return n}function Io(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function L1(e){if(!Lo(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or string");return typeof e=="string"?ut(e):e}function G3(e,t,n,r){Sn(e),Io(n),t=L1(t),t.length>255&&(t=r(Me(ut("H2C-OVERSIZE-DST-"),t)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const c=Me(t,Xr(t.length,1)),a=Xr(0,s),u=Xr(n,2),f=new Array(o),l=r(Me(a,e,u,Xr(0,1),c));f[0]=r(Me(l,Xr(1,1),c));for(let y=1;y<=o;y++){const g=[W3(l,f[y-1]),Xr(y+1,1),c];f[y]=r(Me(...g))}return Me(...f).slice(0,n)}function D3(e,t,n,r,i){if(Sn(e),Io(n),t=L1(t),t.length>255){const s=Math.ceil(2*r/8);t=i.create({dkLen:s}).update(ut("H2C-OVERSIZE-DST-")).update(t).digest()}if(n>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(e).update(Xr(n,2)).update(t).update(Xr(t.length,1)).digest()}function $u(e,t,n){rc(n,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:r,k:i,m:s,hash:o,expand:c,DST:a}=n;if(!k3(n.hash))throw new Error("expected valid hash");Sn(e),Io(t);const u=r.toString(2).length,f=Math.ceil((u+i)/8),l=t*s*f;let p;if(c==="xmd")p=G3(e,a,l,o);else if(c==="xof")p=D3(e,a,l,i,o);else if(c==="_internal_pass")p=e;else throw new Error('expand must be "xmd" or "xof"');const y=new Array(t);for(let g=0;g<t;g++){const w=new Array(s);for(let E=0;E<s;E++){const _=f*(E+g*s),S=p.subarray(_,_+f);w[E]=dt(j3(S),r)}y[g]=w}return y}function j1(e,t){const n=t.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,c,a]=n.map(l=>l.reduce((p,y)=>e.add(e.mul(p,r),y))),[u,f]=Gi(e,[o,a],!0);return r=e.mul(s,u),i=e.mul(i,e.mul(c,f)),{x:r,y:i}}}const X3=ut("HashToScalar-");function Cd(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");function r(s){return e.fromAffine(t(s))}function i(s){const o=s.clearCofactor();return o.equals(e.ZERO)?e.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const c=Object.assign({},n,o),a=$u(s,2,c),u=r(a[0]),f=r(a[1]);return i(u.add(f))},encodeToCurve(s,o){const c=n.encodeDST?{DST:n.encodeDST}:{},a=Object.assign({},n,c,o),u=$u(s,1,a),f=r(u[0]);return i(f)},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))},hashToScalar(s,o){const c=e.Fn.ORDER,a=Object.assign({},n,{p:c,m:1,DST:X3},o);return $u(s,1,a)[0][0]}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Hd=(e,t)=>(e+(e>=0?t:-t)/cr)/t;function z3(e,t,n){const[[r,i],[s,o]]=t,c=Hd(o*e,n),a=Hd(-i*e,n);let u=e-c*r-a*s,f=-c*i-a*o;const l=u<Pi,p=f<Pi;l&&(u=-u),p&&(f=-f);const y=Wi(Math.ceil(vo(n)/2))+Xt;if(u<Pi||u>=y||f<Pi||f>=y)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:p,k2:f}}const Pi=BigInt(0),Xt=BigInt(1),cr=BigInt(2),os=BigInt(3),Mf=BigInt(4);function ga(e,t){const{BYTES:n}=e;let r;if(typeof t=="bigint")r=t;else{let i=en("private key",t);try{r=e.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Y3(e,t={}){const n=K1("weierstrass",e,t),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:c}=s;rc(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:a}=t;if(a&&(!r.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Q3(r,i);function f(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(W,H,K){const{x:N,y:L}=H.toAffine(),F=r.toBytes(N);if(xo(K,"isCompressed"),K){f();const x=!r.isOdd(L);return Me(Z3(x),F)}else return Me(Uint8Array.of(4),F,r.toBytes(L))}function p(W){ys(W,void 0,"Point");const{publicKey:H,publicKeyUncompressed:K}=u,N=W.length,L=W[0],F=W.subarray(1);if(N===H&&(L===2||L===3)){const x=r.fromBytes(F);if(!r.isValid(x))throw new Error("bad point: is not on curve, wrong x");const O=w(x);let q;try{q=r.sqrt(O)}catch(G){const X=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}f();const P=r.isOdd(q);return(L&1)===1!==P&&(q=r.neg(q)),{x,y:q}}else if(N===K&&L===4){const x=r.BYTES,O=r.fromBytes(F.subarray(0,x)),q=r.fromBytes(F.subarray(x,x*2));if(!E(O,q))throw new Error("bad point: is not on curve");return{x:O,y:q}}else throw new Error(`bad point: got length ${N}, expected compressed=${H} or uncompressed=${K}`)}const y=t.toBytes||l,g=t.fromBytes||p;function w(W){const H=r.sqr(W),K=r.mul(H,W);return r.add(r.add(K,r.mul(W,s.a)),s.b)}function E(W,H){const K=r.sqr(H),N=w(W);return r.eql(K,N)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const _=r.mul(r.pow(s.a,os),Mf),S=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(_,S)))throw new Error("bad curve params: a or b");function m(W,H,K=!1){if(!r.isValid(H)||K&&r.is0(H))throw new Error(`bad point coordinate ${W}`);return H}function T(W){if(!(W instanceof v))throw new Error("ProjectivePoint expected")}function I(W){if(!a||!a.basises)throw new Error("no endo");return z3(W,a.basises,i.ORDER)}const A=Bo((W,H)=>{const{X:K,Y:N,Z:L}=W;if(r.eql(L,r.ONE))return{x:K,y:N};const F=W.is0();H==null&&(H=F?r.ONE:r.inv(L));const x=r.mul(K,H),O=r.mul(N,H),q=r.mul(L,H);if(F)return{x:r.ZERO,y:r.ZERO};if(!r.eql(q,r.ONE))throw new Error("invZ was invalid");return{x,y:O}}),U=Bo(W=>{if(W.is0()){if(t.allowInfinityPoint&&!r.is0(W.Y))return;throw new Error("bad point: ZERO")}const{x:H,y:K}=W.toAffine();if(!r.isValid(H)||!r.isValid(K))throw new Error("bad point: x or y not field elements");if(!E(H,K))throw new Error("bad point: equation left != right");if(!W.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(W,H,K,N,L){return K=new v(r.mul(K.X,W),K.Y,K.Z),H=ya(N,H),K=ya(L,K),H.add(K)}class v{constructor(H,K,N){this.X=m("x",H),this.Y=m("y",K,!0),this.Z=m("z",N),Object.freeze(this)}static CURVE(){return s}static fromAffine(H){const{x:K,y:N}=H||{};if(!H||!r.isValid(K)||!r.isValid(N))throw new Error("invalid affine point");if(H instanceof v)throw new Error("projective point not allowed");return r.is0(K)&&r.is0(N)?v.ZERO:new v(K,N,r.ONE)}static fromBytes(H){const K=v.fromAffine(g(ys(H,void 0,"point")));return K.assertValidity(),K}static fromHex(H){return v.fromBytes(en("pointHex",H))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(H=8,K=!0){return V.createCache(this,H),K||this.multiply(os),this}assertValidity(){U(this)}hasEvenY(){const{y:H}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(H)}equals(H){T(H);const{X:K,Y:N,Z:L}=this,{X:F,Y:x,Z:O}=H,q=r.eql(r.mul(K,O),r.mul(F,L)),P=r.eql(r.mul(N,O),r.mul(x,L));return q&&P}negate(){return new v(this.X,r.neg(this.Y),this.Z)}double(){const{a:H,b:K}=s,N=r.mul(K,os),{X:L,Y:F,Z:x}=this;let O=r.ZERO,q=r.ZERO,P=r.ZERO,$=r.mul(L,L),G=r.mul(F,F),X=r.mul(x,x),Y=r.mul(L,F);return Y=r.add(Y,Y),P=r.mul(L,x),P=r.add(P,P),O=r.mul(H,P),q=r.mul(N,X),q=r.add(O,q),O=r.sub(G,q),q=r.add(G,q),q=r.mul(O,q),O=r.mul(Y,O),P=r.mul(N,P),X=r.mul(H,X),Y=r.sub($,X),Y=r.mul(H,Y),Y=r.add(Y,P),P=r.add($,$),$=r.add(P,$),$=r.add($,X),$=r.mul($,Y),q=r.add(q,$),X=r.mul(F,x),X=r.add(X,X),$=r.mul(X,Y),O=r.sub(O,$),P=r.mul(X,G),P=r.add(P,P),P=r.add(P,P),new v(O,q,P)}add(H){T(H);const{X:K,Y:N,Z:L}=this,{X:F,Y:x,Z:O}=H;let q=r.ZERO,P=r.ZERO,$=r.ZERO;const G=s.a,X=r.mul(s.b,os);let Y=r.mul(K,F),oe=r.mul(N,x),ae=r.mul(L,O),ee=r.add(K,N),Z=r.add(F,x);ee=r.mul(ee,Z),Z=r.add(Y,oe),ee=r.sub(ee,Z),Z=r.add(K,L);let ce=r.add(F,O);return Z=r.mul(Z,ce),ce=r.add(Y,ae),Z=r.sub(Z,ce),ce=r.add(N,L),q=r.add(x,O),ce=r.mul(ce,q),q=r.add(oe,ae),ce=r.sub(ce,q),$=r.mul(G,Z),q=r.mul(X,ae),$=r.add(q,$),q=r.sub(oe,$),$=r.add(oe,$),P=r.mul(q,$),oe=r.add(Y,Y),oe=r.add(oe,Y),ae=r.mul(G,ae),Z=r.mul(X,Z),oe=r.add(oe,ae),ae=r.sub(Y,ae),ae=r.mul(G,ae),Z=r.add(Z,ae),Y=r.mul(oe,Z),P=r.add(P,Y),Y=r.mul(ce,Z),q=r.mul(ee,q),q=r.sub(q,Y),Y=r.mul(ee,oe),$=r.mul(ce,$),$=r.add($,Y),new v(q,P,$)}subtract(H){return this.add(H.negate())}is0(){return this.equals(v.ZERO)}multiply(H){const{endo:K}=t;if(!i.isValidNot0(H))throw new Error("invalid scalar: out of range");let N,L;const F=x=>V.cached(this,x,O=>dr(v,O));if(K){const{k1neg:x,k1:O,k2neg:q,k2:P}=I(H),{p:$,f:G}=F(O),{p:X,f:Y}=F(P);L=G.add(Y),N=M(K.beta,$,X,x,q)}else{const{p:x,f:O}=F(H);N=x,L=O}return dr(v,[N,L])[0]}multiplyUnsafe(H){const{endo:K}=t,N=this;if(!i.isValid(H))throw new Error("invalid scalar: out of range");if(H===Pi||N.is0())return v.ZERO;if(H===Xt)return N;if(V.hasCache(this))return this.multiply(H);if(K){const{k1neg:L,k1:F,k2neg:x,k2:O}=I(H),{p1:q,p2:P}=L3(v,N,F,O);return M(K.beta,q,P,L,x)}else return V.unsafe(N,H)}multiplyAndAddUnsafe(H,K,N){const L=this.multiplyUnsafe(K).add(H.multiplyUnsafe(N));return L.is0()?void 0:L}toAffine(H){return A(this,H)}isTorsionFree(){const{isTorsionFree:H}=t;return o===Xt?!0:H?H(v,this):V.unsafe(this,c).is0()}clearCofactor(){const{clearCofactor:H}=t;return o===Xt?this:H?H(v,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(H=!0){return xo(H,"isCompressed"),this.assertValidity(),y(v,this,H)}toHex(H=!0){return Qe(this.toBytes(H))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(H=!0){return this.toBytes(H)}_setWindowSize(H){this.precompute(H)}static normalizeZ(H){return dr(v,H)}static msm(H,K){return $1(v,i,H,K)}static fromPrivateKey(H){return v.BASE.multiply(ga(i,H))}}v.BASE=new v(s.Gx,s.Gy,r.ONE),v.ZERO=new v(r.ZERO,r.ONE,r.ZERO),v.Fp=r,v.Fn=i;const R=i.BITS,V=new V1(v,t.endo?Math.ceil(R/2):R);return v.BASE.precompute(8),v}function Z3(e){return Uint8Array.of(e?2:3)}function J3(e,t){const n=e.ORDER;let r=Pi;for(let g=n-Xt;g%cr===Pi;g/=cr)r+=Xt;const i=r,s=cr<<i-Xt-Xt,o=s*cr,c=(n-Xt)/o,a=(c-Xt)/cr,u=o-Xt,f=s,l=e.pow(t,c),p=e.pow(t,(c+Xt)/cr);let y=(g,w)=>{let E=l,_=e.pow(w,u),S=e.sqr(_);S=e.mul(S,w);let m=e.mul(g,S);m=e.pow(m,a),m=e.mul(m,_),_=e.mul(m,w),S=e.mul(m,g);let T=e.mul(S,_);m=e.pow(T,f);let I=e.eql(m,e.ONE);_=e.mul(S,p),m=e.mul(T,E),S=e.cmov(_,S,I),T=e.cmov(m,T,I);for(let A=i;A>Xt;A--){let U=A-cr;U=cr<<U-Xt;let M=e.pow(T,U);const v=e.eql(M,e.ONE);_=e.mul(S,E),E=e.mul(E,E),M=e.mul(T,E),S=e.cmov(_,S,v),T=e.cmov(M,T,v)}return{isValid:I,value:S}};if(e.ORDER%Mf===os){const g=(e.ORDER-os)/Mf,w=e.sqrt(e.neg(t));y=(E,_)=>{let S=e.sqr(_);const m=e.mul(E,_);S=e.mul(S,m);let T=e.pow(S,g);T=e.mul(T,m);const I=e.mul(T,w),A=e.mul(e.sqr(T),_),U=e.eql(A,E);let M=e.cmov(I,T,U);return{isValid:U,value:M}}}return y}function W1(e,t){C1(e);const{A:n,B:r,Z:i}=t;if(!e.isValid(n)||!e.isValid(r)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");const s=J3(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return o=>{let c,a,u,f,l,p,y,g;c=e.sqr(o),c=e.mul(c,i),a=e.sqr(c),a=e.add(a,c),u=e.add(a,e.ONE),u=e.mul(u,r),f=e.cmov(i,e.neg(a),!e.eql(a,e.ZERO)),f=e.mul(f,n),a=e.sqr(u),p=e.sqr(f),l=e.mul(p,n),a=e.add(a,l),a=e.mul(a,u),p=e.mul(p,f),l=e.mul(p,r),a=e.add(a,l),y=e.mul(c,u);const{isValid:w,value:E}=s(a,p);g=e.mul(c,o),g=e.mul(g,E),y=e.cmov(y,u,w),g=e.cmov(g,E,w);const _=e.isOdd(o)===e.isOdd(g);g=e.cmov(e.neg(g),g,_);const S=Gi(e,[f],!0)[0];return y=e.mul(y,S),{x:y,y:g}}}function Q3(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Fd(e){const{CURVE:t,curveOpts:n}=eT(e),r=Y3(t,n);return nT(e,r)}function eT(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=ai(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function tT(e,t,n){function r(i){const s=e.sqr(i),o=e.mul(s,i);return e.add(e.add(o,e.mul(i,t)),n)}return r}function nT(e,t){const{Fp:n,Fn:r}=t;function i(o){return v1(o,Xt,r.ORDER)}const s=tT(n,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:o=>ga(r,o),weierstrassEquation:s,isWithinCurveOrder:i})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rT=BigInt(0),Sc=BigInt(1),Md=BigInt(2),cs=BigInt(3);function iT(e){const t=[];for(;e>Sc;e>>=Sc)(e&Sc)===rT?t.unshift(0):(e&cs)===cs?(t.unshift(-1),e+=Sc):t.unshift(1);return t}function Ku(e){if(!Array.isArray(e)||e.length===0)throw new Error("expected non-empty array")}function sT(e,t,n,r){const{Fp2:i,Fp12:s}=e,{twistType:o,ateLoopSize:c,xNegative:a,postPrecompute:u}=r;let f;if(o==="multiplicative")f=(m,T,I,A,U,M)=>s.mul014(A,m,i.mul(T,U),i.mul(I,M));else if(o==="divisive")f=(m,T,I,A,U,M)=>s.mul034(A,i.mul(I,M),i.mul(T,U),m);else throw new Error("bls: unknown twist type");const l=i.div(i.ONE,i.mul(i.ONE,Md));function p(m,T,I,A){const U=i.sqr(I),M=i.sqr(A),v=i.mulByB(i.mul(M,cs)),R=i.mul(v,cs),V=i.sub(i.sub(i.sqr(i.add(I,A)),M),U),W=i.sub(v,U),H=i.mul(i.sqr(T),cs),K=i.neg(V);return m.push([W,H,K]),T=i.mul(i.mul(i.mul(i.sub(U,R),T),I),l),I=i.sub(i.sqr(i.mul(i.add(U,R),l)),i.mul(i.sqr(v),cs)),A=i.mul(U,V),{Rx:T,Ry:I,Rz:A}}function y(m,T,I,A,U,M){const v=i.sub(I,i.mul(M,A)),R=i.sub(T,i.mul(U,A)),V=i.sub(i.mul(v,U),i.mul(R,M)),W=i.neg(v),H=R;m.push([V,W,H]);const K=i.sqr(R),N=i.mul(K,R),L=i.mul(K,T),F=i.add(i.sub(N,i.mul(L,Md)),i.mul(i.sqr(v),A));return T=i.mul(R,F),I=i.sub(i.mul(i.sub(L,F),v),i.mul(N,I)),A=i.mul(A,N),{Rx:T,Ry:I,Rz:A}}const g=iT(c),w=Bo(m=>{const T=m,{x:I,y:A}=T.toAffine(),U=I,M=A,v=i.neg(A);let R=U,V=M,W=i.ONE;const H=[];for(const K of g){const N=[];({Rx:R,Ry:V,Rz:W}=p(N,R,V,W)),K&&({Rx:R,Ry:V,Rz:W}=y(N,R,V,W,U,K===-1?v:M)),H.push(N)}if(u){const K=H[H.length-1];u(R,V,W,U,M,y.bind(null,K))}return H});function E(m,T=!1){let I=s.ONE;if(m.length){const A=m[0][0].length;for(let U=0;U<A;U++){I=s.sqr(I);for(const[M,v,R]of m)for(const[V,W,H]of M[U])I=f(V,W,H,I,v,R)}}return a&&(I=s.conjugate(I)),T?s.finalExponentiate(I):I}function _(m,T=!0){const I=[];dr(t,m.map(({g1:A})=>A)),dr(n,m.map(({g2:A})=>A));for(const{g1:A,g2:U}of m){if(A.is0()||U.is0())throw new Error("pairing is not available for ZERO point");A.assertValidity(),U.assertValidity();const M=A.toAffine();I.push([w(U),M.x,M.y])}return E(I,T)}function S(m,T,I=!0){return _([{g1:m,g2:T}],I)}return{Fp12:s,millerLoopBatch:E,pairing:S,pairingBatch:_,calcPairingPrecomputes:w}}function qd(e,t,n,r,i){const{Fp12:s,pairingBatch:o}=e;function c(l){return l instanceof t.Point?l:t.Point.fromHex(l)}function a(l){return l instanceof n.Point?l:n.Point.fromHex(l)}function u(l){if(!(l instanceof n.Point))throw new Error(`expected valid message hashed to ${i?"G1":"G2"} curve`);return l}const f=i?(l,p)=>({g1:p,g2:l}):(l,p)=>({g1:l,g2:p});return{getPublicKey(l){const p=ga(t.Point.Fn,l);return t.Point.BASE.multiply(p)},sign(l,p,y){if(y!=null)throw new Error("sign() expects 2 arguments");const g=ga(t.Point.Fn,p);return u(l).assertValidity(),l.multiply(g)},verify(l,p,y,g){if(g!=null)throw new Error("verify() expects 3 arguments");l=a(l),y=c(y);const w=y.negate(),E=t.Point.BASE,_=u(p),S=l,m=o([f(w,_),f(E,S)]);return s.eql(m,s.ONE)},verifyBatch(l,p,y){if(Ku(p),y.length!==p.length)throw new Error("amount of public keys and messages should be equal");const g=a(l),w=p,E=y.map(c),_=new Map;for(let T=0;T<E.length;T++){const I=E[T],A=w[T];let U=_.get(A);U===void 0&&(U=[],_.set(A,U)),U.push(I)}const S=[],m=t.Point.BASE;try{for(const[T,I]of _){const A=I.reduce((U,M)=>U.add(M));S.push(f(A,T))}return S.push(f(m.negate(),g)),s.eql(o(S),s.ONE)}catch{return!1}},aggregatePublicKeys(l){Ku(l),l=l.map(y=>c(y));const p=l.reduce((y,g)=>y.add(g),t.Point.ZERO);return p.assertValidity(),p},aggregateSignatures(l){Ku(l),l=l.map(y=>a(y));const p=l.reduce((y,g)=>y.add(g),n.Point.ZERO);return p.assertValidity(),p},hash(l,p){Sn(l);const y=p?{DST:p}:void 0;return n.hashToCurve(l,y)},Signature:r}}function oT(e){const{Fp:t,Fr:n,Fp2:r,Fp6:i,Fp12:s}=e.fields,o=Fd(e.G1),c=Object.assign(o,Cd(o.Point,e.G1.mapToCurve,{...e.htfDefaults,...e.G1.htfDefaults})),a=Fd(e.G2),u=Object.assign(a,Cd(a.Point,e.G2.mapToCurve,{...e.htfDefaults,...e.G2.htfDefaults})),f=sT(e.fields,c.Point,u.Point,{...e.params,postPrecompute:e.postPrecompute}),{millerLoopBatch:l,pairing:p,pairingBatch:y,calcPairingPrecomputes:g}=f,w=qd(f,c,u,e.G2.Signature,!1),E=qd(f,u,c,e.G1.ShortSignature,!0),_=e.randomBytes||gy,S=()=>{const x=F1(n.ORDER);return V3(_(x),n.ORDER)},m={randomSecretKey:S,randomPrivateKey:S,calcPairingPrecomputes:g},{ShortSignature:T}=e.G1,{Signature:I}=e.G2;function A(x,O){return x instanceof c.Point?x:E.hash(en("point",x),O?.DST)}function U(x,O){return x instanceof u.Point?x:w.hash(en("point",x),O?.DST)}function M(x){return w.getPublicKey(x).toBytes(!0)}function v(x){return E.getPublicKey(x).toBytes(!0)}function R(x,O,q){const P=U(x,q),$=w.sign(P,O);return x instanceof u.Point?$:I.toBytes($)}function V(x,O,q){const P=A(x,q),$=E.sign(P,O);return x instanceof c.Point?$:T.toBytes($)}function W(x,O,q,P){const $=U(O,P);return w.verify(x,$,q)}function H(x,O,q,P){const $=A(O,P);return E.verify(x,$,q)}function K(x){const O=w.aggregatePublicKeys(x);return x[0]instanceof c.Point?O:O.toBytes(!0)}function N(x){const O=w.aggregateSignatures(x);return x[0]instanceof u.Point?O:I.toBytes(O)}function L(x){const O=E.aggregateSignatures(x);return x[0]instanceof c.Point?O:T.toBytes(O)}function F(x,O,q,P){const $=O.map(G=>U(G,P));return w.verifyBatch(x,$,q)}return c.Point.BASE.precompute(4),{longSignatures:w,shortSignatures:E,millerLoopBatch:l,pairing:p,pairingBatch:y,verifyBatch:F,fields:{Fr:n,Fp:t,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:e.params.ateLoopSize,twistType:e.params.twistType,r:e.params.r,G1b:e.G1.b,G2b:e.G2.b},utils:m,getPublicKey:M,getPublicKeyForShortSignatures:v,sign:R,signShortSignature:V,verify:W,verifyShortSignature:H,aggregatePublicKeys:K,aggregateSignatures:N,aggregateShortSignatures:L,G1:c,G2:u,Signature:I,ShortSignature:T}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Vd=BigInt(0),pr=BigInt(1),Yt=BigInt(2),$d=BigInt(3);function $l(e,t,n,r,i=1,s){const o=BigInt(s===void 0?r:s),c=n**BigInt(r),a=[];for(let u=0;u<i;u++){const f=BigInt(u+1),l=[];for(let p=0,y=pr;p<r;p++){const g=(f*y-f)/o%c;l.push(e.pow(t,g)),y*=n}a.push(l)}return a}function cT(e,t,n){const r=t.pow(n,(e.ORDER-pr)/$d),i=t.pow(n,(e.ORDER-pr)/Yt);function s(p,y){const g=t.mul(t.frobeniusMap(p,1),r),w=t.mul(t.frobeniusMap(y,1),i);return[g,w]}const o=t.pow(n,(e.ORDER**Yt-pr)/$d),c=t.pow(n,(e.ORDER**Yt-pr)/Yt);if(!t.eql(c,t.neg(t.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function a(p,y){return[t.mul(p,o),t.neg(y)]}const u=p=>(y,g)=>{const w=g.toAffine(),E=p(w.x,w.y);return y.fromAffine({x:E[0],y:E[1]})},f=u(s),l=u(a);return{psi:s,psi2:a,G2psi:f,G2psi2:l,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:c}}const Kd=(e,t)=>{if(t.length!==2)throw new Error("invalid tuple");const n=t.map(r=>e.create(r));return{c0:n[0],c1:n[1]}};class aT{constructor(t,n={}){this.MASK=pr;const r=t.ORDER,i=r*r;this.Fp=t,this.ORDER=i,this.BITS=vo(i),this.BYTES=Math.ceil(vo(i)/8),this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.Fp_NONRESIDUE=t.create(n.NONRESIDUE||BigInt(-1)),this.Fp_div2=t.div(t.ONE,Yt),this.NONRESIDUE=Kd(t,n.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=$l(t,this.Fp_NONRESIDUE,t.ORDER,2)[0],this.mulByB=n.Fp2mulByB,Object.seal(this)}fromBigTuple(t){return Kd(this.Fp,t)}create(t){return t}isValid({c0:t,c1:n}){function r(i,s){return typeof i=="bigint"&&Vd<=i&&i<s}return r(t,this.ORDER)&&r(n,this.ORDER)}is0({c0:t,c1:n}){return this.Fp.is0(t)&&this.Fp.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}eql({c0:t,c1:n},{c0:r,c1:i}){return this.Fp.eql(t,r)&&this.Fp.eql(n,i)}neg({c0:t,c1:n}){return{c0:this.Fp.neg(t),c1:this.Fp.neg(n)}}pow(t,n){return Qa(this,t,n)}invertBatch(t){return Gi(this,t)}add(t,n){const{c0:r,c1:i}=t,{c0:s,c1:o}=n;return{c0:this.Fp.add(r,s),c1:this.Fp.add(i,o)}}sub({c0:t,c1:n},{c0:r,c1:i}){return{c0:this.Fp.sub(t,r),c1:this.Fp.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};const{c0:s,c1:o}=r;let c=i.mul(t,s),a=i.mul(n,o);const u=i.sub(c,a),f=i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a));return{c0:u,c1:f}}sqr({c0:t,c1:n}){const{Fp:r}=this,i=r.add(t,n),s=r.sub(t,n),o=r.add(t,t);return{c0:r.mul(i,s),c1:r.mul(o,n)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}div(t,n){const{Fp:r}=this;return this.mul(t,typeof n=="bigint"?r.inv(r.create(n)):this.inv(n))}inv({c0:t,c1:n}){const{Fp:r}=this,i=r.inv(r.create(t*t+n*n));return{c0:r.mul(i,r.create(t)),c1:r.mul(i,r.create(-n))}}sqrt(t){const{Fp:n}=this,r=this,{c0:i,c1:s}=t;if(n.is0(s))return pa(n,i)===1?r.create({c0:n.sqrt(i),c1:n.ZERO}):r.create({c0:n.ZERO,c1:n.sqrt(n.div(i,this.Fp_NONRESIDUE))});const o=n.sqrt(n.sub(n.sqr(i),n.mul(n.sqr(s),this.Fp_NONRESIDUE)));let c=n.mul(n.add(o,i),this.Fp_div2);pa(n,c)===-1&&(c=n.sub(c,o));const u=n.sqrt(c),f=r.create({c0:u,c1:n.div(n.mul(s,this.Fp_div2),u)});if(!r.eql(r.sqr(f),t))throw new Error("Cannot find square root");const l=f,p=r.neg(l),{re:y,im:g}=r.reim(l),{re:w,im:E}=r.reim(p);return g>E||g===E&&y>w?l:p}isOdd(t){const{re:n,im:r}=this.reim(t),i=n%Yt,s=n===Vd,o=r%Yt;return BigInt(i||s&&o)==pr}fromBytes(t){const{Fp:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){return Me(this.Fp.toBytes(t),this.Fp.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){return{c0:this.Fp.cmov(t,r,s),c1:this.Fp.cmov(n,i,s)}}reim({c0:t,c1:n}){return{re:t,im:n}}Fp4Square(t,n){const r=this,i=r.sqr(t),s=r.sqr(n);return{first:r.add(r.mulByNonresidue(s),i),second:r.sub(r.sub(r.sqr(r.add(t,n)),i),s)}}mulByNonresidue({c0:t,c1:n}){return this.mul({c0:t,c1:n},this.NONRESIDUE)}frobeniusMap({c0:t,c1:n},r){return{c0:t,c1:this.Fp.mul(n,this.FROBENIUS_COEFFICIENTS[r%2])}}}class uT{constructor(t){this.MASK=pr,this.Fp2=t,this.ORDER=t.ORDER,this.BITS=3*t.BITS,this.BYTES=3*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO,c2:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO,c2:t.ZERO};const{Fp:n}=t,r=$l(t,t.NONRESIDUE,n.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=r[0],this.FROBENIUS_COEFFICIENTS_2=r[1],Object.seal(this)}add({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.add(t,i),c1:c.add(n,s),c2:c.add(r,o)}}sub({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.sub(t,i),c1:c.sub(n,s),c2:c.sub(r,o)}}mul({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;if(typeof i=="bigint")return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)};const{c0:o,c1:c,c2:a}=i,u=s.mul(t,o),f=s.mul(n,c),l=s.mul(r,a);return{c0:s.add(u,s.mulByNonresidue(s.sub(s.mul(s.add(n,r),s.add(c,a)),s.add(f,l)))),c1:s.add(s.sub(s.mul(s.add(t,n),s.add(o,c)),s.add(u,f)),s.mulByNonresidue(l)),c2:s.sub(s.add(f,s.mul(s.add(t,r),s.add(o,a))),s.add(u,l))}}sqr({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sqr(t),o=i.mul(i.mul(t,n),Yt),c=i.mul(i.mul(n,r),Yt),a=i.sqr(r);return{c0:i.add(i.mulByNonresidue(c),s),c1:i.add(i.mulByNonresidue(a),o),c2:i.sub(i.sub(i.add(i.add(o,i.sqr(i.add(i.sub(t,n),r))),c),s),a)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}create(t){return t}isValid({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.isValid(t)&&i.isValid(n)&&i.isValid(r)}is0({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.is0(t)&&i.is0(n)&&i.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.neg(t),c1:i.neg(n),c2:i.neg(r)}}eql({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return c.eql(t,i)&&c.eql(n,s)&&c.eql(r,o)}sqrt(t){return B1()}div(t,n){const{Fp2:r}=this,{Fp:i}=r;return this.mul(t,typeof n=="bigint"?i.inv(i.create(n)):this.inv(n))}pow(t,n){return Qa(this,t,n)}invertBatch(t){return Gi(this,t)}inv({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sub(i.sqr(t),i.mulByNonresidue(i.mul(r,n))),o=i.sub(i.mulByNonresidue(i.sqr(r)),i.mul(t,n)),c=i.sub(i.sqr(n),i.mul(t,r)),a=i.inv(i.add(i.mulByNonresidue(i.add(i.mul(r,o),i.mul(n,c))),i.mul(t,s)));return{c0:i.mul(a,s),c1:i.mul(a,o),c2:i.mul(a,c)}}fromBytes(t){const{Fp2:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);const r=n.BYTES;return{c0:n.fromBytes(t.subarray(0,r)),c1:n.fromBytes(t.subarray(r,r*2)),c2:n.fromBytes(t.subarray(2*r))}}toBytes({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return Me(i.toBytes(t),i.toBytes(n),i.toBytes(r))}cmov({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o},c){const{Fp2:a}=this;return{c0:a.cmov(t,i,c),c1:a.cmov(n,s,c),c2:a.cmov(r,o,c)}}fromBigSix(t){const{Fp2:n}=this;if(!Array.isArray(t)||t.length!==6)throw new Error("invalid Fp6 usage");return{c0:n.fromBigTuple(t.slice(0,2)),c1:n.fromBigTuple(t.slice(2,4)),c2:n.fromBigTuple(t.slice(4,6))}}frobeniusMap({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.frobeniusMap(t,i),c1:s.mul(s.frobeniusMap(n,i),this.FROBENIUS_COEFFICIENTS_1[i%6]),c2:s.mul(s.frobeniusMap(r,i),this.FROBENIUS_COEFFICIENTS_2[i%6])}}mulByFp2({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)}}mulByNonresidue({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.mulByNonresidue(r),c1:t,c2:n}}mul1({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mulByNonresidue(s.mul(r,i)),c1:s.mul(t,i),c2:s.mul(n,i)}}mul01({c0:t,c1:n,c2:r},i,s){const{Fp2:o}=this;let c=o.mul(t,i),a=o.mul(n,s);return{c0:o.add(o.mulByNonresidue(o.sub(o.mul(o.add(n,r),s),a)),c),c1:o.sub(o.sub(o.mul(o.add(i,s),o.add(t,n)),c),a),c2:o.add(o.sub(o.mul(o.add(t,r),i),c),a)}}}class fT{constructor(t,n){this.MASK=pr;const{Fp2:r}=t,{Fp:i}=r;this.Fp6=t,this.ORDER=r.ORDER,this.BITS=2*t.BITS,this.BYTES=2*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.FROBENIUS_COEFFICIENTS=$l(r,r.NONRESIDUE,i.ORDER,12,1,6)[0],this.X_LEN=n.X_LEN,this.finalExponentiate=n.Fp12finalExponentiate}create(t){return t}isValid({c0:t,c1:n}){const{Fp6:r}=this;return r.isValid(t)&&r.isValid(n)}is0({c0:t,c1:n}){const{Fp6:r}=this;return r.is0(t)&&r.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n}){const{Fp6:r}=this;return{c0:r.neg(t),c1:r.neg(n)}}eql({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return s.eql(t,r)&&s.eql(n,i)}sqrt(t){B1()}inv({c0:t,c1:n}){const{Fp6:r}=this;let i=r.inv(r.sub(r.sqr(t),r.mulByNonresidue(r.sqr(n))));return{c0:r.mul(t,i),c1:r.neg(r.mul(n,i))}}div(t,n){const{Fp6:r}=this,{Fp2:i}=r,{Fp:s}=i;return this.mul(t,typeof n=="bigint"?s.inv(s.create(n)):this.inv(n))}pow(t,n){return Qa(this,t,n)}invertBatch(t){return Gi(this,t)}add({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.add(t,r),c1:s.add(n,i)}}sub({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.sub(t,r),c1:s.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp6:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};let{c0:s,c1:o}=r,c=i.mul(t,s),a=i.mul(n,o);return{c0:i.add(c,i.mulByNonresidue(a)),c1:i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a))}}sqr({c0:t,c1:n}){const{Fp6:r}=this;let i=r.mul(t,n);return{c0:r.sub(r.sub(r.mul(r.add(r.mulByNonresidue(n),t),r.add(t,n)),i),r.mulByNonresidue(i)),c1:r.add(i,i)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}fromBytes(t){const{Fp6:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){const{Fp6:r}=this;return Me(r.toBytes(t),r.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){const{Fp6:o}=this;return{c0:o.cmov(t,r,s),c1:o.cmov(n,i,s)}}fromBigTwelve(t){const{Fp6:n}=this;return{c0:n.fromBigSix(t.slice(0,6)),c1:n.fromBigSix(t.slice(6,12))}}frobeniusMap(t,n){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=r.frobeniusMap(t.c1,n),a=this.FROBENIUS_COEFFICIENTS[n%12];return{c0:r.frobeniusMap(t.c0,n),c1:r.create({c0:i.mul(s,a),c1:i.mul(o,a),c2:i.mul(c,a)})}}mulByFp2({c0:t,c1:n},r){const{Fp6:i}=this;return{c0:i.mulByFp2(t,r),c1:i.mulByFp2(n,r)}}conjugate({c0:t,c1:n}){return{c0:t,c1:this.Fp6.neg(n)}}mul014({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o;let a=o.mul01(t,r,i),u=o.mul1(n,s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(o.sub(o.mul01(o.add(n,t),r,c.add(i,s)),a),u)}}mul034({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o,a=o.create({c0:c.mul(t.c0,r),c1:c.mul(t.c1,r),c2:c.mul(t.c2,r)}),u=o.mul01(n,i,s),f=o.mul01(o.add(t,n),c.add(r,i),s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(f,o.add(a,u))}}_cyclotomicSquare({c0:t,c1:n}){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=t,{c0:a,c1:u,c2:f}=n,{first:l,second:p}=i.Fp4Square(s,u),{first:y,second:g}=i.Fp4Square(a,c),{first:w,second:E}=i.Fp4Square(o,f),_=i.mulByNonresidue(E);return{c0:r.create({c0:i.add(i.mul(i.sub(l,s),Yt),l),c1:i.add(i.mul(i.sub(y,o),Yt),y),c2:i.add(i.mul(i.sub(w,c),Yt),w)}),c1:r.create({c0:i.add(i.mul(i.add(_,a),Yt),_),c1:i.add(i.mul(i.add(p,u),Yt),p),c2:i.add(i.mul(i.add(g,f),Yt),g)})}}_cyclotomicExp(t,n){let r=this.ONE;for(let i=this.X_LEN-1;i>=0;i--)r=this._cyclotomicSquare(r),P3(n,i)&&(r=this.mul(r,t));return r}}function lT(e){const t=ai(e.ORDER),n=new aT(t,e),r=new uT(n),i=new fT(r,e);return{Fp:t,Fp2:n,Fp6:r,Fp12:i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const qt=BigInt(0),wa=BigInt(1),An=BigInt(2),eu=BigInt(3),Oo=BigInt(4),zr=BigInt("0xd201000000010000"),hT=vo(zr),Vi={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:qt,b:Oo,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},dT=ai(Vi.n,{modFromBytes:!0,isLE:!0}),{Fp:me,Fp2:Pe,Fp6:pT,Fp12:Re}=lT({ORDER:Vi.p,X_LEN:hT,FP2_NONRESIDUE:[wa,wa],Fp2mulByB:({c0:e,c1:t})=>{const n=me.mul(e,Oo),r=me.mul(t,Oo);return{c0:me.sub(n,r),c1:me.add(n,r)}},Fp12finalExponentiate:e=>{const t=zr,n=Re.div(Re.frobeniusMap(e,6),e),r=Re.mul(Re.frobeniusMap(n,2),n),i=Re.conjugate(Re._cyclotomicExp(r,t)),s=Re.mul(Re.conjugate(Re._cyclotomicSquare(r)),i),o=Re.conjugate(Re._cyclotomicExp(s,t)),c=Re.conjugate(Re._cyclotomicExp(o,t)),a=Re.mul(Re.conjugate(Re._cyclotomicExp(c,t)),Re._cyclotomicSquare(i)),u=Re.conjugate(Re._cyclotomicExp(a,t)),f=Re.frobeniusMap(Re.mul(i,c),2),l=Re.frobeniusMap(Re.mul(o,r),3),p=Re.frobeniusMap(Re.mul(a,Re.conjugate(r)),1),y=Re.mul(Re.mul(u,Re.conjugate(s)),r);return Re.mul(Re.mul(Re.mul(f,l),p),y)}}),{G2psi:Ld,G2psi2:yT}=cT(me,Pe,Pe.div(Pe.ONE,Pe.NONRESIDUE)),Lu=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:me.ORDER,m:2,k:128,expand:"xmd",hash:pn}),Kl={p:Pe.ORDER,n:Vi.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:Pe.ZERO,b:Pe.fromBigTuple([Oo,Oo]),Gx:Pe.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:Pe.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},tu=ic(me.toBytes(qt),{infinity:!0,compressed:!0});function nu(e){e=e.slice();const t=e[0]&224,n=!!(t>>7&1),r=!!(t>>6&1),i=!!(t>>5&1);return e[0]&=31,{compressed:n,infinity:r,sort:i,value:e}}function ic(e,t){if(e[0]&224)throw new Error("setMask: non-empty mask");return t.compressed&&(e[0]|=128),t.infinity&&(e[0]|=64),t.sort&&(e[0]|=32),e}function gT(e,t,n){const{BYTES:r,ORDER:i}=me,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return tu.slice();const a=!!(c*An/i);return ic(Ot(o,r),{compressed:!0,sort:a})}else return s?Me(Uint8Array.of(64),new Uint8Array(2*r-1)):Me(Ot(o,r),Ot(c,r))}function ju(e){e.assertValidity();const{BYTES:t,ORDER:n}=me,{x:r,y:i}=e.toAffine();if(e.is0())return tu.slice();const s=!!(i*An/n);return ic(Ot(r,t),{compressed:!0,sort:s})}function wT(e){const{compressed:t,infinity:n,sort:r,value:i}=nu(e),{BYTES:s,ORDER:o}=me;if(i.length===48&&t){const c=Yn(i),a=me.create(c&Wi(me.BITS));if(n){if(a!==qt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:qt,y:qt}}const u=me.add(me.pow(a,eu),me.create(Vi.b));let f=me.sqrt(u);if(!f)throw new Error("invalid G1 point: compressed point");return f*An/o!==BigInt(r)&&(f=me.neg(f)),{x:me.create(a),y:me.create(f)}}else if(i.length===96&&!t){const c=Yn(i.subarray(0,s)),a=Yn(i.subarray(s));if(n){if(c!==qt||a!==qt)throw new Error("G1: non-empty point at infinity");return ru.G1.Point.ZERO.toAffine()}return{x:me.create(c),y:me.create(a)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function jd(e){const{infinity:t,sort:n,value:r}=nu(en("signatureHex",e,48)),i=me.ORDER,s=ru.G1.Point,o=Yn(r);if(t)return s.ZERO;const c=me.create(o&Wi(me.BITS)),a=me.add(me.pow(c,eu),me.create(Vi.b));let u=me.sqrt(a);if(!u)throw new Error("invalid G1 point: compressed");const f=BigInt(n);u*An/i!==f&&(u=me.neg(u));const l=s.fromAffine({x:c,y:u});return l.assertValidity(),l}function mT(e,t,n){const{BYTES:r,ORDER:i}=me,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return Me(tu,Ot(qt,r));const a=!!(c.c1===qt?c.c0*An/i:c.c1*An/i);return Me(ic(Ot(o.c1,r),{compressed:!0,sort:a}),Ot(o.c0,r))}else{if(s)return Me(Uint8Array.of(64),new Uint8Array(4*r-1));const{re:a,im:u}=Pe.reim(o),{re:f,im:l}=Pe.reim(c);return Me(Ot(u,r),Ot(a,r),Ot(l,r),Ot(f,r))}}function Wu(e){e.assertValidity();const{BYTES:t}=me;if(e.is0())return Me(tu,Ot(qt,t));const{x:n,y:r}=e.toAffine(),{re:i,im:s}=Pe.reim(n),{re:o,im:c}=Pe.reim(r),u=!!((c>qt?c*An:o*An)/me.ORDER&wa),f=i;return Me(ic(Ot(s,t),{sort:u,compressed:!0}),Ot(f,t))}function bT(e){const{BYTES:t,ORDER:n}=me,{compressed:r,infinity:i,sort:s,value:o}=nu(e);if(!r&&!i&&s||!r&&i&&s||s&&i&&r)throw new Error("invalid encoding flag: "+(e[0]&224));const c=(a,u,f)=>Yn(a.slice(u,f));if(o.length===96&&r){if(i){if(o.reduce((g,w)=>g!==0?w+1:w,0)>0)throw new Error("invalid G2 point: compressed");return{x:Pe.ZERO,y:Pe.ZERO}}const a=c(o,0,t),u=c(o,t,2*t),f=Pe.create({c0:me.create(u),c1:me.create(a)}),l=Pe.add(Pe.pow(f,eu),Kl.b);let p=Pe.sqrt(l);const y=p.c1===qt?p.c0*An/n:p.c1*An/n?wa:qt;return p=s&&y>0?p:Pe.neg(p),{x:f,y:p}}else if(o.length===192&&!r){if(i){if(o.reduce((p,y)=>p!==0?y+1:y,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:Pe.ZERO,y:Pe.ZERO}}const a=c(o,0*t,1*t),u=c(o,1*t,2*t),f=c(o,2*t,3*t),l=c(o,3*t,4*t);return{x:Pe.fromBigTuple([u,a]),y:Pe.fromBigTuple([l,f])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function Wd(e){const{ORDER:t}=me,{infinity:n,sort:r,value:i}=nu(en("signatureHex",e)),s=ru.G2.Point,o=i.length/2;if(o!==48&&o!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");const c=Yn(i.slice(0,o)),a=Yn(i.slice(o));if(n)return s.ZERO;const u=me.create(c&Wi(me.BITS)),f=me.create(a),l=Pe.create({c0:f,c1:u}),p=Pe.add(Pe.pow(l,eu),Kl.b);let y=Pe.sqrt(p);if(!y)throw new Error("Failed to find a square root");const{re:g,im:w}=Pe.reim(y),E=BigInt(r),_=w>qt&&w*An/t!==E,S=w===qt&&g*An/t!==E;(_||S)&&(y=Pe.neg(y));const m=s.fromAffine({x:l,y});return m.assertValidity(),m}const ru=oT({fields:{Fp:me,Fp2:Pe,Fp6:pT,Fp12:Re,Fr:dT},G1:{...Vi,Fp:me,htfDefaults:{...Lu,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(e,t)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new e(me.mul(t.X,n),t.Y,t.Z);return t.multiplyUnsafe(zr).negate().multiplyUnsafe(zr).equals(r)},clearCofactor:(e,t)=>t.multiplyUnsafe(zr).add(t),mapToCurve:xT,fromBytes:wT,toBytes:gT,ShortSignature:{fromBytes(e){return Sn(e),jd(e)},fromHex(e){return jd(e)},toBytes(e){return ju(e)},toRawBytes(e){return ju(e)},toHex(e){return Qe(ju(e))}}},G2:{...Kl,Fp:Pe,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Lu},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:AT,isTorsionFree:(e,t)=>t.multiplyUnsafe(zr).negate().equals(Ld(e,t)),clearCofactor:(e,t)=>{const n=zr;let r=t.multiplyUnsafe(n).negate(),i=Ld(e,t),s=t.double();return s=yT(e,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(t)},fromBytes:bT,toBytes:mT,Signature:{fromBytes(e){return Sn(e),Wd(e)},fromHex(e){return Wd(e)},toBytes(e){return Wu(e)},toRawBytes(e){return Wu(e)},toHex(e){return Qe(Wu(e))}}},params:{ateLoopSize:zr,r:Vi.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:Lu}),ET=j1(Pe,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(e=>e.map(t=>Pe.fromBigTuple(t.map(BigInt))))),_T=j1(me,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),ST=W1(me,{A:me.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:me.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:me.create(BigInt(11))}),TT=W1(Pe,{A:Pe.create({c0:me.create(qt),c1:me.create(BigInt(240))}),B:Pe.create({c0:me.create(BigInt(1012)),c1:me.create(BigInt(1012))}),Z:Pe.create({c0:me.create(BigInt(-2)),c1:me.create(BigInt(-1))})});function xT(e){const{x:t,y:n}=ST(me.create(e[0]));return _T(t,n)}function AT(e){const{x:t,y:n}=TT(Pe.fromBigTuple(e));return ET(t,n)}function vT(e,t,n){const r=typeof e=="string"?e:Qe(e),i=typeof t=="string"?t:Qe(t),s=typeof n=="string"?n:Qe(n);return ru.verifyShortSignature(i,s,r)}const BT=BigInt(1e6),G1=e=>xt(new Ps(e)),Ll=e=>{const n=G1(e)/BT;return new Date(Number(n))},Gd=60*1e3,IT=60,OT=24,PT=OT*IT,kT=5,NT=5,UT=30*PT;var Pt;(function(e){e[e.Empty=0]="Empty",e[e.Fork=1]="Fork",e[e.Labeled=2]="Labeled",e[e.Leaf=3]="Leaf",e[e.Pruned=4]="Pruned"})(Pt||(Pt={}));function RT(e,t){for(let n=0;n<e.length;n++)if(e[n]>t[n])return!0;return!1}class Ui{#t=!1;#e=void 0;static async create(t){const n=Ui.createUnverified(t);return await n.verify(),n}static createUnverified(t){return new Ui(t.certificate,t.rootKey,t.canisterId,t.blsVerify??vT,t.maxAgeInMinutes,t.disableTimeVerification,t.agent)}constructor(t,n,r,i,s=kT,o=!1,c){this._rootKey=n,this._canisterId=r,this._blsVerify=i,this._maxAgeInMinutes=s,this.#t=o,this.cert=Dn(t),c&&"getTimeDiffMsecs"in c&&"hasSyncedTime"in c&&"syncTime"in c&&(this.#e=c)}lookup_path(t){return sc(t,this.cert.tree)}lookup_subtree(t){return jl(t,this.cert.tree)}async verify(){const t=await $c(this.cert.tree),n=await this._checkDelegationAndGetKey(this.cert.delegation),r=this.cert.signature,i=HT(n),s=Me(so("ic-state-root"),t),o=yn(this.lookup_path(["time"]));if(!o)throw lt.fromCode(new ls("Certificate does not contain a time"));if(!this.#t){const c=this.#e?.getTimeDiffMsecs()??0,a=this._maxAgeInMinutes*Gd,u=new Date,f=u.getTime()+c,l=f-a,p=f+NT*Gd,y=Ll(o),g=y.getTime()<l,w=y.getTime()>p;if((g||w)&&this.#e&&!this.#e.hasSyncedTime())return await this.#e.syncTime(this._canisterId),await this.verify();if(g)throw bn.fromCode(new Eo(this._maxAgeInMinutes,y,u,c,"past"));if(w)throw this.#e?.hasSyncedTime()?rn.fromCode(new Un("System time has been synced with the IC network, but certificate is still too far in the future.")):bn.fromCode(new Eo(5,y,u,c,"future"))}try{if(!await this._blsVerify(i,r,s))throw bn.fromCode(new ls("Invalid signature"))}catch(c){throw bn.fromCode(new ls("Signature verification failed",c))}}async _checkDelegationAndGetKey(t){if(!t)return this._rootKey;const n=Ui.createUnverified({certificate:t.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#t,maxAgeInMinutes:UT,agent:this.#e});if(n.cert.delegation)throw lt.fromCode(new bl);await n.verify();const r=t.subnet_id,i=$e.fromUint8Array(r);if(!X1({canisterId:this._canisterId,subnetId:i,tree:n.cert.tree}))throw bn.fromCode(new Da(this._canisterId,i));const o=yn(n.lookup_path(["subnet",r,"public_key"]));if(!o)throw bn.fromCode(new El(`Could not find subnet key for subnet ID ${i.toText()}`));return o}}const Ws=jo("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),CT=96;function HT(e){const t=Ws.byteLength+CT;if(e.byteLength!==t)throw lt.fromCode(new za(t,e.byteLength));const n=e.slice(0,Ws.byteLength);if(!Ja(n,Ws))throw lt.fromCode(new _l(Ws,n));return e.slice(Ws.byteLength)}function yn(e){if(e.status===En.Found&&e.value instanceof Uint8Array)return e.value}async function $c(e){switch(e[0]){case Pt.Empty:return pn(so("ic-hashtree-empty"));case Pt.Pruned:return e[1];case Pt.Leaf:return pn(Me(so("ic-hashtree-leaf"),e[1]));case Pt.Labeled:return pn(Me(so("ic-hashtree-labeled"),e[1],await $c(e[2])));case Pt.Fork:return pn(Me(so("ic-hashtree-fork"),await $c(e[1]),await $c(e[2])));default:throw hs}}function so(e){const t=new Uint8Array([e.length]),n=new TextEncoder().encode(e);return Me(t,n)}function D1(e){return typeof e[0]=="string"?ut(e[0]):e[0]}var En;(function(e){e.Unknown="Unknown",e.Absent="Absent",e.Found="Found",e.Error="Error"})(En||(En={}));var gs;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found"})(gs||(gs={}));var nt;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found",e.Less="Less",e.Greater="Greater"})(nt||(nt={}));function sc(e,t){if(e.length===0)switch(t[0]){case Pt.Empty:return{status:En.Absent};case Pt.Leaf:{if(!t[1])throw rn.fromCode(new tc("Invalid tree structure for leaf"));if(t[1]instanceof Uint8Array)return{status:En.Found,value:t[1].slice(t[1].byteOffset,t[1].byteLength+t[1].byteOffset)};throw hs}case Pt.Pruned:return{status:En.Unknown};case Pt.Labeled:case Pt.Fork:return{status:En.Error};default:throw hs}const n=D1(e),r=fo(n,t);switch(r.status){case nt.Found:return sc(e.slice(1),r.value);case nt.Absent:case nt.Greater:case nt.Less:return{status:En.Absent};case nt.Unknown:return{status:En.Unknown};default:throw hs}}function jl(e,t){if(e.length===0)return{status:gs.Found,value:t};const n=D1(e),r=fo(n,t);switch(r.status){case nt.Found:return jl(e.slice(1),r.value);case nt.Unknown:return{status:gs.Unknown};case nt.Absent:case nt.Greater:case nt.Less:return{status:gs.Absent};default:throw hs}}function qf(e){switch(e[0]){case Pt.Empty:return[];case Pt.Fork:return qf(e[1]).concat(qf(e[2]));default:return[e]}}function fo(e,t){switch(t[0]){case Pt.Labeled:return RT(e,t[1])?{status:nt.Greater}:Ja(e,t[1])?{status:nt.Found,value:t[2]}:{status:nt.Less};case Pt.Fork:{const n=fo(e,t[1]);switch(n.status){case nt.Greater:{const r=fo(e,t[2]);return r.status===nt.Less?{status:nt.Absent}:r}case nt.Unknown:{const r=fo(e,t[2]);return r.status===nt.Less?{status:nt.Unknown}:r}default:return n}}case Pt.Pruned:return{status:nt.Unknown};default:return{status:nt.Absent}}}function X1(e){const{canisterId:t,subnetId:n,tree:r}=e,i=sc(["subnet",n.toUint8Array(),"canister_ranges"],r);if(i.status!==En.Found)throw lt.fromCode(new Ts(`Could not find canister ranges for subnet ${n.toText()}`,i.status));if(!(i.value instanceof Uint8Array))throw lt.fromCode(new Xa(`Could not find canister ranges for subnet ${n.toText()}`));return Dn(i.value).map(a=>[$e.fromUint8Array(a[0]),$e.fromUint8Array(a[1])]).some(a=>a[0].ltEq(t)&&a[1].gtEq(t))}const Dd=async e=>{const{agent:t,paths:n,disableCertificateTimeVerification:r=!1}=e,i=$e.from(e.canisterId),s=[...new Set(n)],o=new Map,c=s.map((a,u)=>{const f=MT(a,i);return(async()=>{try{if(t.rootKey===null)throw nn.fromCode(new Us);const l=t.rootKey,p=await t.readState(i,{paths:[f]}),y=await Ui.create({certificate:p.certificate,rootKey:l,canisterId:i,disableTimeVerification:r,agent:t}),g=(_,S)=>{if(S==="subnet"){const m=FT(p.certificate,i,l);return{path:S,data:m}}else return{path:S,data:yn(_.lookup_path(f))}},{path:w,data:E}=g(y,s[u]);if(!E)console.warn(`Expected to find result for path ${w}, but instead found nothing.`),typeof w=="string"?o.set(w,null):o.set(w.key,null);else switch(w){case"time":{o.set(w,Ll(E));break}case"controllers":{o.set(w,qT(E));break}case"module_hash":{o.set(w,Qe(E));break}case"subnet":{o.set(w,E);break}case"candid":{o.set(w,new TextDecoder().decode(E));break}default:if(typeof w!="string"&&"key"in w&&"path"in w)switch(w.decodeStrategy){case"raw":o.set(w.key,E);break;case"leb128":{o.set(w.key,G1(E));break}case"cbor":{o.set(w.key,Dn(E));break}case"hex":{o.set(w.key,Qe(E));break}case"utf-8":o.set(w.key,new TextDecoder().decode(E))}}}catch(l){if(l instanceof lr&&(l.hasCode(ls)||l.hasCode(Eo)))throw l;typeof a!="string"&&"key"in a&&"path"in a?o.set(a.key,null):o.set(a,null),console.group(),console.warn(`Expected to find result for path ${a}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(c),o},FT=(e,t,n)=>{if(!t._isPrincipal)throw Ye.fromCode(new Un("Invalid canisterId"));const r=Dn(e),i=r.tree;let s=r.delegation,o;if(s&&s.subnet_id?o=$e.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof n<"u"?(o=$e.selfAuthenticating(new Uint8Array(n)),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}):(o=$e.selfAuthenticating($e.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}),!X1({canisterId:t,subnetId:o,tree:i}))throw bn.fromCode(new Da(t,o));const a=jl(["subnet",s.subnet_id,"node"],i);if(a.status!==gs.Found)throw lt.fromCode(new Ts("Node not found",a.status));if(a.value instanceof Uint8Array)throw rn.fromCode(new tc("Invalid node tree"));const u=qf(a.value),f=new Map;return u.forEach(l=>{const p=$e.from(l[1]).toText(),y=sc(["public_key"],l[2]);if(y.status!==En.Found)throw lt.fromCode(new Ts("Public key not found",y.status));const g=y.value;if(g.byteLength!==44)throw lt.fromCode(new za(44,g.byteLength));f.set(p,g)}),{subnetId:$e.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:f}},MT=(e,t)=>{const n=t.toUint8Array();switch(e){case"time":return[ut("time")];case"controllers":return[ut("canister"),n,ut("controllers")];case"module_hash":return[ut("canister"),n,ut("module_hash")];case"subnet":return[ut("subnet")];case"candid":return[ut("canister"),n,ut("metadata"),ut("candid:service")];default:if("key"in e&&"path"in e)if(typeof e.path=="string"||e.path instanceof Uint8Array){const r=e.path,i=typeof r=="string"?ut(r):r;return[ut("canister"),n,ut("metadata"),i]}else return e.path}throw rn.fromCode(new Un(`Error while encoding your path for canister status. Please ensure that your path ${e} was formatted correctly.`))},qT=e=>Dn(e).map(n=>$e.fromUint8Array(n));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const kr=BigInt(0),Tt=BigInt(1),Gu=BigInt(2),VT=BigInt(8);function $T(e,t,n,r){const i=e.sqr(n),s=e.sqr(r),o=e.add(e.mul(t.a,i),s),c=e.add(e.ONE,e.mul(t.d,e.mul(i,s)));return e.eql(o,c)}function KT(e,t={}){const n=K1("edwards",e,t,t.FpFnLE),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o}=s;rc(t,{},{uvRatio:"function"});const c=Gu<<BigInt(i.BYTES*8)-Tt,a=E=>r.create(E),u=t.uvRatio||((E,_)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,_))}}catch{return{isValid:!1,value:kr}}});if(!$T(r,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(E,_,S=!1){const m=S?Tt:kr;return Pd("coordinate "+E,_,m,c),_}function l(E){if(!(E instanceof g))throw new Error("ExtendedPoint expected")}const p=Bo((E,_)=>{const{X:S,Y:m,Z:T}=E,I=E.is0();_==null&&(_=I?VT:r.inv(T));const A=a(S*_),U=a(m*_),M=r.mul(T,_);if(I)return{x:kr,y:Tt};if(M!==Tt)throw new Error("invZ was invalid");return{x:A,y:U}}),y=Bo(E=>{const{a:_,d:S}=s;if(E.is0())throw new Error("bad point: ZERO");const{X:m,Y:T,Z:I,T:A}=E,U=a(m*m),M=a(T*T),v=a(I*I),R=a(v*v),V=a(U*_),W=a(v*a(V+M)),H=a(R+a(S*a(U*M)));if(W!==H)throw new Error("bad point: equation left != right (1)");const K=a(m*T),N=a(I*A);if(K!==N)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(_,S,m,T){this.X=f("x",_),this.Y=f("y",S),this.Z=f("z",m,!0),this.T=f("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(_){if(_ instanceof g)throw new Error("extended point not allowed");const{x:S,y:m}=_||{};return f("x",S),f("y",m),new g(S,m,Tt,a(S*m))}static fromBytes(_,S=!1){const m=r.BYTES,{a:T,d:I}=s;_=Od(ys(_,m,"point")),xo(S,"zip215");const A=Od(_),U=_[m-1];A[m-1]=U&-129;const M=Ao(A),v=S?c:r.ORDER;Pd("point.y",M,kr,v);const R=a(M*M),V=a(R-Tt),W=a(I*R-T);let{isValid:H,value:K}=u(V,W);if(!H)throw new Error("bad point: invalid y coordinate");const N=(K&Tt)===Tt,L=(U&128)!==0;if(!S&&K===kr&&L)throw new Error("bad point: x=0 and x_0=1");return L!==N&&(K=a(-K)),g.fromAffine({x:K,y:M})}static fromHex(_,S=!1){return g.fromBytes(en("point",_),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,S=!0){return w.createCache(this,_),S||this.multiply(Gu),this}assertValidity(){y(this)}equals(_){l(_);const{X:S,Y:m,Z:T}=this,{X:I,Y:A,Z:U}=_,M=a(S*U),v=a(I*T),R=a(m*U),V=a(A*T);return M===v&&R===V}is0(){return this.equals(g.ZERO)}negate(){return new g(a(-this.X),this.Y,this.Z,a(-this.T))}double(){const{a:_}=s,{X:S,Y:m,Z:T}=this,I=a(S*S),A=a(m*m),U=a(Gu*a(T*T)),M=a(_*I),v=S+m,R=a(a(v*v)-I-A),V=M+A,W=V-U,H=M-A,K=a(R*W),N=a(V*H),L=a(R*H),F=a(W*V);return new g(K,N,F,L)}add(_){l(_);const{a:S,d:m}=s,{X:T,Y:I,Z:A,T:U}=this,{X:M,Y:v,Z:R,T:V}=_,W=a(T*M),H=a(I*v),K=a(U*m*V),N=a(A*R),L=a((T+I)*(M+v)-W-H),F=N-K,x=N+K,O=a(H-S*W),q=a(L*F),P=a(x*O),$=a(L*O),G=a(F*x);return new g(q,P,G,$)}subtract(_){return this.add(_.negate())}multiply(_){if(!i.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:S,f:m}=w.cached(this,_,T=>dr(g,T));return dr(g,[S,m])[0]}multiplyUnsafe(_,S=g.ZERO){if(!i.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===kr?g.ZERO:this.is0()||_===Tt?this:w.unsafe(this,_,m=>dr(g,m),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return w.unsafe(this,s.n).is0()}toAffine(_){return p(this,_)}clearCofactor(){return o===Tt?this:this.multiplyUnsafe(o)}toBytes(){const{x:_,y:S}=this.toAffine(),m=r.toBytes(S);return m[m.length-1]|=_&Tt?128:0,m}toHex(){return Qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(_){return dr(g,_)}static msm(_,S){return $1(g,i,_,S)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}g.BASE=new g(s.Gx,s.Gy,Tt,a(s.Gx*s.Gy)),g.ZERO=new g(kr,Tt,Tt,kr),g.Fp=r,g.Fn=i;const w=new V1(g,i.BITS);return g.BASE.precompute(8),g}function LT(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');rc(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=n,{BASE:i,Fp:s,Fn:o}=e,c=n.randomBytes||gy,a=n.adjustScalarBytes||(v=>v),u=n.domain||((v,R,V)=>{if(xo(V,"phflag"),R.length||V)throw new Error("Contexts/pre-hash are not supported");return v});function f(v){return o.create(Ao(v))}function l(v){const R=m.secretKey;v=en("private key",v,R);const V=en("hashed private key",t(v),2*R),W=a(V.slice(0,R)),H=V.slice(R,2*R),K=f(W);return{head:W,prefix:H,scalar:K}}function p(v){const{head:R,prefix:V,scalar:W}=l(v),H=i.multiply(W),K=H.toBytes();return{head:R,prefix:V,scalar:W,point:H,pointBytes:K}}function y(v){return p(v).pointBytes}function g(v=Uint8Array.of(),...R){const V=Me(...R);return f(t(u(V,en("context",v),!!r)))}function w(v,R,V={}){v=en("message",v),r&&(v=r(v));const{prefix:W,scalar:H,pointBytes:K}=p(R),N=g(V.context,W,v),L=i.multiply(N).toBytes(),F=g(V.context,L,K,v),x=o.create(N+F*H);if(!o.isValid(x))throw new Error("sign failed: invalid s");const O=Me(L,o.toBytes(x));return ys(O,m.signature,"result")}const E={zip215:!0};function _(v,R,V,W=E){const{context:H,zip215:K}=W,N=m.signature;v=en("signature",v,N),R=en("message",R),V=en("publicKey",V,m.publicKey),K!==void 0&&xo(K,"zip215"),r&&(R=r(R));const L=N/2,F=v.subarray(0,L),x=Ao(v.subarray(L,N));let O,q,P;try{O=e.fromBytes(V,K),q=e.fromBytes(F,K),P=i.multiplyUnsafe(x)}catch{return!1}if(!K&&O.isSmallOrder())return!1;const $=g(H,q.toBytes(),O.toBytes(),R);return q.add(O.multiplyUnsafe($)).subtract(P).clearCofactor().is0()}const S=s.BYTES,m={secretKey:S,publicKey:S,signature:2*S,seed:S};function T(v=c(m.seed)){return ys(v,m.seed,"seed")}function I(v){const R=M.randomSecretKey(v);return{secretKey:R,publicKey:y(R)}}function A(v){return Lo(v)&&v.length===o.BYTES}function U(v,R){try{return!!e.fromBytes(v,R)}catch{return!1}}const M={getExtendedPublicKey:p,randomSecretKey:T,isValidSecretKey:A,isValidPublicKey:U,toMontgomery(v){const{y:R}=e.fromBytes(v),V=m.publicKey,W=V===32;if(!W&&V!==57)throw new Error("only defined for 25519 and 448");const H=W?s.div(Tt+R,Tt-R):s.div(R-Tt,R+Tt);return s.toBytes(H)},toMontgomerySecret(v){const R=m.secretKey;ys(v,R);const V=t(v.subarray(0,R));return a(V).subarray(0,R)},randomPrivateKey:T,precompute(v=8,R=e.BASE){return R.precompute(v,!1)}};return Object.freeze({keygen:I,getPublicKey:y,sign:w,verify:_,utils:M,Point:e,lengths:m})}function jT(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=ai(t.n,e.nBitLength,!0),i={Fp:n,Fn:r,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:i,hash:e.hash,eddsaOpts:s}}function WT(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function GT(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:i}=jT(e),s=KT(t,n),o=LT(s,r,i);return WT(e,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const DT=BigInt(1),Xd=BigInt(2);BigInt(3);const XT=BigInt(5),zT=BigInt(8),Wl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),z1={p:Wl,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:zT,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function YT(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Wl,c=e*e%s*e%s,a=jn(c,Xd,s)*c%s,u=jn(a,DT,s)*e%s,f=jn(u,XT,s)*u%s,l=jn(f,t,s)*f%s,p=jn(l,n,s)*l%s,y=jn(p,r,s)*p%s,g=jn(y,i,s)*y%s,w=jn(g,i,s)*y%s,E=jn(w,t,s)*f%s;return{pow_p_5_8:jn(E,Xd,s)*e%s,b2:c}}function ZT(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const zd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function JT(e,t){const n=Wl,r=dt(t*t*t,n),i=dt(r*r*t,n),s=YT(e*i).pow_p_5_8;let o=dt(e*r*s,n);const c=dt(t*o*o,n),a=o,u=dt(o*zd,n),f=c===e,l=c===dt(-e,n),p=c===dt(-e*zd,n);return f&&(o=a),(l||p)&&(o=u),F3(o,n)&&(o=dt(-o,n)),{isValid:f||l,value:o}}const QT=ai(z1.p,{isLE:!0}),e8={...z1,Fp:QT,hash:Jm,adjustScalarBytes:ZT,uvRatio:JT},t8=GT(e8);var Yd,Zd,Bt,ws;class n8{constructor(t={}){Qt(this,Bt);Qt(this,ws);this[Yd]=this.entries.bind(this),this[Zd]="ExpirableMap";const{source:n=[],expirationTime:r=600*1e3}=t,i=Date.now();jt(this,Bt,new Map([...n].map(([s,o])=>[s,{value:o,timestamp:i}]))),jt(this,ws,r)}prune(){const t=Date.now();for(const[n,r]of Ue(this,Bt).entries())t-r.timestamp>Ue(this,ws)&&Ue(this,Bt).delete(n);return this}set(t,n){this.prune();const r={value:n,timestamp:Date.now()};return Ue(this,Bt).set(t,r),this}get(t){const n=Ue(this,Bt).get(t);if(n!==void 0){if(Date.now()-n.timestamp>Ue(this,ws)){Ue(this,Bt).delete(t);return}return n.value}}clear(){Ue(this,Bt).clear()}entries(){const t=Ue(this,Bt).entries();return function*(){for(const[r,i]of t)yield[r,i.value]}()}values(){const t=Ue(this,Bt).values();return function*(){for(const r of t)yield r.value}()}keys(){return Ue(this,Bt).keys()}forEach(t,n){for(const[r,i]of Ue(this,Bt).entries())t.call(n,i.value,r,this)}has(t){return Ue(this,Bt).has(t)}delete(t){return Ue(this,Bt).delete(t)}get size(){return Ue(this,Bt).size}}Bt=new WeakMap,ws=new WeakMap,Yd=Symbol.iterator,Zd=Symbol.toStringTag;const Jd=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw Ye.fromCode(new Ya("Length too long (> 4 bytes)"))},Qd=(e,t,n)=>{if(n<=127)return e[t]=n,1;if(n<=255)return e[t]=129,e[t+1]=n,2;if(n<=65535)return e[t]=130,e[t+1]=n>>8,e[t+2]=n,3;if(n<=16777215)return e[t]=131,e[t+1]=n>>16,e[t+2]=n>>8,e[t+3]=n,4;throw Ye.fromCode(new Ya("Length too long (> 4 bytes)"))},Vf=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw Ye.fromCode(new Sr("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw Ye.fromCode(new Sr("Length too long (> 4 bytes)"))},r8=(e,t)=>{const n=Vf(e,t);if(n===1)return e[t];if(n===2)return e[t+1];if(n===3)return(e[t+1]<<8)+e[t+2];if(n===4)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw Ye.fromCode(new Sr("Length too long (> 4 bytes)"))};Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]);const e0=Uint8Array.from([48,5,6,3,43,101,112]);Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);Uint8Array.from([48,29,6,13,43,6,1,4,1,130,220,124,5,3,1,2,1,6,12,43,6,1,4,1,130,220,124,5,3,2,1]);function i8(e,t){const n=2+Jd(e.byteLength+1),r=t.byteLength+n+e.byteLength;let i=0;const s=new Uint8Array(1+Jd(r)+r);return s[i++]=48,i+=Qd(s,i,r),s.set(t,i),i+=t.byteLength,s[i++]=3,i+=Qd(s,i,e.byteLength+1),s[i++]=0,s.set(new Uint8Array(e),i),s}const s8=(e,t)=>{let n=0;const r=(c,a)=>{if(i[n++]!==c)throw Ye.fromCode(new Sr(`Expected ${a} at offset ${n}`))},i=new Uint8Array(e);if(r(48,"sequence"),n+=Vf(i,n),!Ja(i.slice(n,n+t.byteLength),t))throw Ye.fromCode(new Sr("Not the expected OID."));n+=t.byteLength,r(3,"bit string");const s=r8(i,n)-1;n+=Vf(i,n),r(0,"0 padding");const o=i.slice(n);if(s!==o.length)throw Ye.fromCode(new Sl(s,o.length));return o};var ko,No;const Ai=class Ai{constructor(t){Qt(this,ko);Qt(this,No);if(t.byteLength!==Ai.RAW_KEY_LENGTH)throw Ye.fromCode(new Sr("An Ed25519 public key must be exactly 32 bytes long"));jt(this,ko,t),jt(this,No,Ai.derEncode(t))}static from(t){return this.fromDer(t.toDer())}static fromRaw(t){return new Ai(t)}static fromDer(t){return new Ai(this.derDecode(t))}static derEncode(t){return i8(t,e0)}static derDecode(t){const n=s8(t,e0);if(n.length!==this.RAW_KEY_LENGTH)throw Ye.fromCode(new Sr("An Ed25519 public key must be exactly 32 bytes long"));return n}get rawKey(){return Ue(this,ko)}get derKey(){return Ue(this,No)}toDer(){return this.derKey}toRaw(){return this.rawKey}};ko=new WeakMap,No=new WeakMap,Ai.RAW_KEY_LENGTH=32;let $f=Ai;class o8{constructor(){this.observers=[]}subscribe(t){this.observers.push(t)}unsubscribe(t){this.observers=this.observers.filter(n=>n!==t)}notify(t,...n){this.observers.forEach(r=>r(t,...n))}}class c8 extends o8{constructor(){super()}print(t,...n){this.notify({message:t,level:"info"},...n)}warn(t,...n){this.notify({message:t,level:"warn"},...n)}error(t,n,...r){this.notify({message:t,level:"error",error:n},...r)}}const t0=.5,n0=1.5,r0=500,i0=6e4,s0=9e5,o0=10;var Pn,Uo,Ro,Co,Ho,Fo,Mo,qo,ms;const Aa=class Aa{constructor(t=Aa.default){Qt(this,Pn);Qt(this,Uo);Qt(this,Ro);Qt(this,Co);Qt(this,Ho);Qt(this,Fo);Qt(this,Mo);Qt(this,qo);Qt(this,ms,0);const{initialInterval:n=r0,randomizationFactor:r=t0,multiplier:i=n0,maxInterval:s=i0,maxElapsedTime:o=s0,maxIterations:c=o0,date:a=Date}=t;jt(this,Pn,n),jt(this,Uo,r),jt(this,Ro,i),jt(this,Co,s),jt(this,qo,a),jt(this,Ho,a.now()),jt(this,Fo,o),jt(this,Mo,c)}get ellapsedTimeInMsec(){return Ue(this,qo).now()-Ue(this,Ho)}get currentInterval(){return Ue(this,Pn)}get count(){return Ue(this,ms)}get randomValueFromInterval(){const t=Ue(this,Uo)*Ue(this,Pn),n=Ue(this,Pn)-t,r=Ue(this,Pn)+t;return Math.random()*(r-n)+n}incrementCurrentInterval(){return jt(this,Pn,Math.min(Ue(this,Pn)*Ue(this,Ro),Ue(this,Co))),sh(this,ms)._++,Ue(this,Pn)}next(){return this.ellapsedTimeInMsec>=Ue(this,Fo)||Ue(this,ms)>=Ue(this,Mo)?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};Pn=new WeakMap,Uo=new WeakMap,Ro=new WeakMap,Co=new WeakMap,Ho=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,qo=new WeakMap,ms=new WeakMap,Aa.default={initialInterval:r0,randomizationFactor:t0,multiplier:n0,maxInterval:i0,maxElapsedTime:s0,maxIterations:o0,date:Date};let Kf=Aa;var fr;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(fr||(fr={}));const Lf=60*1e3,a8=1e6,u8=0,f8="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",l8="ic0.app",h8=".ic0.app",d8="icp0.io",p8=".icp0.io",y8="icp-api.io",g8=".icp-api.io",Du=200,w8=202,m8=404;function b8(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw nn.fromCode(new uo("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof globalThis<"u")if(globalThis.fetch)e=globalThis.fetch.bind(globalThis);else throw nn.fromCode(new uo("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(e=self.fetch.bind(self));if(e)return e;throw nn.fromCode(new uo("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function E8(e){let t;if(e!==void 0)!e.match(/^[a-z]+:/)&&typeof window<"u"?t=new URL(window.location.protocol+"//"+e):t=new URL(e);else{const n=["ic0.app","icp0.io","127.0.0.1","localhost"],r=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,s=i?.hostname;let o;s&&typeof s=="string"&&(r.some(c=>s.endsWith(c))?o=s:o=n.find(c=>s.endsWith(c))),i&&o?t=new URL(`${i.protocol}//${o}${i.port?":"+i.port:""}`):t=new URL("https://icp-api.io")}return t.toString()}class yr{#t;#e;#i;#g;#a;#m;#n;#s;#w;#b;#r;#c;#u;#o;get#T(){return this.#o*Lf}#f;#l;#h;#d;constructor(t={}){this.#t=null,this.#e=!1,this.#i=u8,this.#g=!1,this.#a=null,this.#m=!1,this._isAgent=!0,this.config={},this.log=new c8,this.#f=[],this.#l=[],this.#h=new n8({expirationTime:5*Lf}),this.#d=!0,this.#_=(i,s)=>{if(this.#d===!1)return i;const{status:o,signatures:c=[],requestId:a}=i;for(const u of c){const{timestamp:f,identity:l}=u,p=$e.fromUint8Array(l).toText();let y;if(o===Ss.Replied){const{reply:S}=i;y=ha({status:o,reply:S,timestamp:BigInt(f),request_id:a})}else if(o===Ss.Rejected){const{reject_code:S,reject_message:m,error_code:T}=i;y=ha({status:o,reject_code:S,reject_message:m,error_code:T,timestamp:BigInt(f),request_id:a})}else throw rn.fromCode(new Un(`Unknown status: ${o}`));const g=Me(JS,y),w=s.nodeKeys.get(p);if(!w)throw lt.fromCode(new Ul);const E=$f.fromDer(w).rawKey;if(t8.verify(u.signature,g,E))return i;throw bn.fromCode(new Rl(p))}return i},this.config=t,this.#s=t.fetch||b8()||fetch.bind(globalThis),this.#w=t.fetchOptions,this.#b=t.callOptions,this.#e=t.shouldFetchRootKey??!1,this.#m=t.shouldSyncTime??!1,t.rootKey?this.rootKey=t.rootKey:this.#e?this.rootKey=null:this.rootKey=jo(f8);const n=E8(t.host);this.host=new URL(n),t.verifyQuerySignatures!==void 0&&(this.#d=t.verifyQuerySignatures),this.#c=t.retryTimes??3;const r=()=>new Kf({maxIterations:this.#c});if(this.#u=t.backoffStrategy||r,this.host.hostname.endsWith(h8)?this.host.hostname=l8:this.host.hostname.endsWith(p8)?this.host.hostname=d8:this.host.hostname.endsWith(g8)&&(this.host.hostname=y8),t.credentials){const{name:i,password:s}=t.credentials;this.#r=`${i}${s?":"+s:""}`}if(this.#n=Promise.resolve(t.identity||new vd),t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes>5)throw Ye.fromCode(new ss("The maximum ingress expiry time is 5 minutes.",t.ingressExpiryInMinutes));if(t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes<=0)throw Ye.fromCode(new ss("Ingress expiry time must be greater than 0.",t.ingressExpiryInMinutes));this.#o=t.ingressExpiryInMinutes||5,this.addTransform("update",Id(Ff)),t.useQueryNonces&&this.addTransform("query",Id(Ff)),t.logToConsole&&this.log.subscribe(i=>{i.level==="error"?console.error(i.message):i.level==="warn"?console.warn(i.message):console.log(i.message)})}static createSync(t={}){return new this({...t})}static async create(t={}){const n=yr.createSync(t);return await n.#y(),n}static async from(t){try{return"config"in t?await yr.create(t.config):await yr.create({fetch:t._fetch,fetchOptions:t._fetchOptions,callOptions:t._callOptions,host:t._host.toString(),identity:t._identity??void 0})}catch{throw Ye.fromCode(new Pl)}}isLocal(){const t=this.host.hostname;return t==="127.0.0.1"||t.endsWith("127.0.0.1")}addTransform(t,n,r=n.priority||0){if(t==="update"){const i=this.#l.findIndex(s=>(s.priority||0)<r);this.#l.splice(i>=0?i:this.#l.length,0,Object.assign(n,{priority:r}))}else if(t==="query"){const i=this.#f.findIndex(s=>(s.priority||0)<r);this.#f.splice(i>=0?i:this.#f.length,0,Object.assign(n,{priority:r}))}}async getPrincipal(){if(!this.#n)throw nn.fromCode(new xi);return(await this.#n).getPrincipal()}async call(t,n,r){const i=n.callSync??!0,s=await(r??this.#n);if(!s)throw nn.fromCode(new xi);const o=$e.from(t),c=n.effectiveCanisterId?$e.from(n.effectiveCanisterId):o;await this.#y(c);const a=s.getPrincipal(),u=Xu(this.#o,this.#i),f={request_type:Hf.Call,canister_id:o,method_name:n.methodName,arg:n.arg,sender:a,ingress_expiry:u};let l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Bi.Call,body:f}),p;n?.nonce?p=y(n.nonce):l.body.nonce?p=y(l.body.nonce):p=void 0,f.nonce=p;function y(_){return Object.assign(_,{__nonce__:void 0})}l=await s.transformRequest(l);const g=Cu(l.body),w=this.#u(),E=Uu(f);try{const m=i?()=>(this.log.print(`fetching "/api/v3/canister/${c.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v3/canister/${c.toText()}/call`,this.host),{...this.#b,...l.request,body:g})):()=>(this.log.print(`fetching "/api/v2/canister/${c.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v2/canister/${c.toText()}/call`,this.host),{...this.#b,...l.request,body:g})),{responseBodyBytes:T,...I}=await this.#p({requestFn:m,backoff:w,tries:0}),A=T.byteLength>0?Dn(T):null;return{requestId:E,response:{...I,body:A},requestDetails:f}}catch(_){let S;if(_ instanceof lr){if(_.hasCode(ca))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(t,{...n,callSync:!1},r);if(_.hasCode(ss)&&!this.#g)return await this.syncTime(o),this.call(o,n,r);_.code.requestContext={requestId:E,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},S=_}else S=rn.fromCode(new Un(_));throw this.log.error(`Error while making call: ${S.message}`,S),S}}async#E(t){const{ecid:n,transformedRequest:r,body:i,requestId:s,backoff:o,tries:c}=t,a=c===0?0:o.next();if(this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with tries:`,{tries:c,backoff:o,delay:a}),a===null)throw rn.fromCode(new _o(`Backoff strategy exhausted after ${c} attempts.`,s));a>0&&await new Promise(y=>setTimeout(y,a));let u;try{this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with request:`,r);const y=await this.#s(""+new URL(`/api/v2/canister/${n.toString()}/query`,this.host),{...this.#w,...r.request,body:i});if(y.status===Du)u={...Dn(la(await y.arrayBuffer())),httpDetails:{ok:y.ok,status:y.status,statusText:y.statusText,headers:Hu(y.headers)},requestId:s};else throw lt.fromCode(new oa(y.status,y.statusText,Hu(y.headers),await y.text()))}catch(y){if(c<this.#c)return this.log.warn(`Caught exception while attempting to make query:
|
|
65
|
+
`),t}}class aa extends ke{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,aa.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}}class ua extends ke{constructor(t){super(),this.error=t,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,ua.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${rc(this.error)}`}}class fa extends ke{constructor(t){super(),this.receivedCanisterId=t,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,fa.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}}class Hl extends ke{constructor(t){super(),this.request=t,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,Hl.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}}class la extends ke{constructor(t){super(),this.error=t,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,la.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}}function rc(e){if(e instanceof Error)return e.stack??e.message;try{return JSON.stringify(e)}catch{return String(e)}}const ds=new Error("unreachable");function ha(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?ha(e.buffer):new Uint8Array(e)}function Qa(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Cf(e){if(typeof e=="string")return p1(e);if(typeof e=="number")return pn(ot(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return pn(ha(e));if(Array.isArray(e)){const t=e.map(Cf);return pn(Me(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return pn(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return Cf(e.toHash());if(typeof e=="object")return da(e);if(typeof e=="bigint")return pn(ot(e))}throw Ye.fromCode(new Pl(e))}const p1=e=>{const t=new TextEncoder().encode(e);return pn(t)};function Ru(e){return da(e)}function da(e){const r=Object.entries(e).filter(([,o])=>o!==void 0).map(([o,c])=>{const a=p1(o),u=Cf(c);return[a,u]}).sort(([o],[c])=>u_(o,c)),i=Me(...r.map(o=>Me(...o)));return pn(i)}new TextEncoder().encode(`
|
|
66
|
+
ic-request`);const JS=new TextEncoder().encode("\vic-response");new TextEncoder().encode("ic-request-auth-delegation");class vd{getPrincipal(){return $e.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}}class Wi extends Error{constructor(t){super(t),this.name="DecodingError"}}const y1=55799,g1=Symbol("CBOR_STOP_CODE");var Rn=(e=>(e[e.False=20]="False",e[e.True=21]="True",e[e.Null=22]="Null",e[e.Undefined=23]="Undefined",e[e.Break=31]="Break",e))(Rn||{}),mt=(e=>(e[e.UnsignedInteger=0]="UnsignedInteger",e[e.NegativeInteger=1]="NegativeInteger",e[e.ByteString=2]="ByteString",e[e.TextString=3]="TextString",e[e.Array=4]="Array",e[e.Map=5]="Map",e[e.Tag=6]="Tag",e[e.Simple=7]="Simple",e))(mt||{});const QS=23,e3=255,t3=65535,n3=4294967295,r3=BigInt("0xffffffffffffffff");var Nn=(e=>(e[e.Value=23]="Value",e[e.OneByte=24]="OneByte",e[e.TwoBytes=25]="TwoBytes",e[e.FourBytes=26]="FourBytes",e[e.EightBytes=27]="EightBytes",e[e.Indefinite=31]="Indefinite",e))(Nn||{});const ps=!1;function i3(e){return e==null}function w1(e,t){const n=new Uint8Array(t);return n.set(e),n}const s3=new TextDecoder;function o3(e){return(e&224)>>5}function c3(e){return e&31}let So=new Uint8Array,js,Cn=0;function a3(e,t){So=e,Cn=0;const n=Ui();return t?.(n)??n}function Ui(e){const[t,n]=$c();switch(t){case mt.UnsignedInteger:return Cs(n);case mt.NegativeInteger:return h3(n);case mt.ByteString:return m1(n);case mt.TextString:return Hf(n);case mt.Array:return u3(n);case mt.Map:return l3(n);case mt.Tag:return d3(n);case mt.Simple:return f3(n)}throw new Wi(`Unsupported major type: ${t}`)}function $c(){const e=So.at(Cn);if(i3(e))throw new Wi("Provided CBOR data is empty");const t=o3(e),n=c3(e);return Cn++,[t,n]}function u3(e,t){const n=Cs(e);if(n===1/0){const i=[];let s=Ui();for(;s!==g1;)i.push(s),s=Ui();return i}const r=new Array(n);for(let i=0;i<n;i++){const s=Ui();r[i]=s}return r}function f3(e){switch(e){case Rn.False:return!1;case Rn.True:return!0;case Rn.Null:return null;case Rn.Undefined:return;case Rn.Break:return g1}throw new Wi(`Unrecognized simple type: ${e.toString(2)}`)}function l3(e,t){const n=Cs(e),r={};if(n===1/0){let[i,s]=$c();for(;i!==mt.Simple&&s!==Rn.Break;){const o=Hf(s),c=Ui();r[o]=c,[i,s]=$c()}return r}for(let i=0;i<n;i++){const[s,o]=$c();if(s!==mt.TextString)throw new Wi("Map keys must be text strings");const c=Hf(o),a=Ui();r[c]=a}return r}function Cs(e){if(e<=Nn.Value)return e;switch(js=new DataView(So.buffer,So.byteOffset+Cn),e){case Nn.OneByte:return Cn++,js.getUint8(0);case Nn.TwoBytes:return Cn+=2,js.getUint16(0,ps);case Nn.FourBytes:return Cn+=4,js.getUint32(0,ps);case Nn.EightBytes:return Cn+=8,js.getBigUint64(0,ps);case Nn.Indefinite:return 1/0;default:throw new Wi(`Unsupported integer info: ${e.toString(2)}`)}}function h3(e){const t=Cs(e);return typeof t=="number"?-1-t:-1n-t}function m1(e){const t=Cs(e);if(t>Number.MAX_SAFE_INTEGER)throw new Wi("Byte length is too large");const n=Number(t);return Cn+=n,So.slice(Cn-n,Cn)}function Hf(e){const t=m1(e);return s3.decode(t)}function d3(e,t){const n=Cs(e);if(n===y1)return Ui();throw new Wi(`Unsupported tag: ${n}.`)}class Fl extends Error{constructor(t){super(t),this.name="SerializationError"}}const p3=2*1024,y3=100,g3=new TextEncoder;function Ws(e){return e<<5}let hn=new Uint8Array(p3),On=new DataView(hn.buffer),wt=0,Cu=[];function w3(e,t){wt=0;const n=t?.(e)??e;return A3(y1,n,t),hn.slice(0,wt)}function Ml(e,t){if(wt>hn.length-y3&&(hn=w1(hn,hn.length*2),On=new DataView(hn.buffer)),e===!1||e===!0||e===null||e===void 0){E3(e);return}if(typeof e=="number"||typeof e=="bigint"){x3(e);return}if(typeof e=="string"){_1(e);return}if(e instanceof Uint8Array){Bd(e);return}if(e instanceof ArrayBuffer){Bd(new Uint8Array(e));return}if(Array.isArray(e)){m3(e,t);return}if(typeof e=="object"){b3(e,t);return}throw new Fl(`Unsupported type: ${typeof e}`)}function m3(e,t){Hs(mt.Array,e.length),e.forEach((n,r)=>{Ml(t?.(n,r.toString())??n,t)})}function b3(e,t){Cu=Object.entries(e),Hs(mt.Map,Cu.length),Cu.forEach(([n,r])=>{_1(n),Ml(t?.(r,n)??r,t)})}function Hs(e,t){if(t<=QS){On.setUint8(wt++,Ws(e)|Number(t));return}if(t<=e3){On.setUint8(wt++,Ws(e)|Nn.OneByte),On.setUint8(wt,Number(t)),wt+=1;return}if(t<=t3){On.setUint8(wt++,Ws(e)|Nn.TwoBytes),On.setUint16(wt,Number(t),ps),wt+=2;return}if(t<=n3){On.setUint8(wt++,Ws(e)|Nn.FourBytes),On.setUint32(wt,Number(t),ps),wt+=4;return}if(t<=r3){On.setUint8(wt++,Ws(e)|Nn.EightBytes),On.setBigUint64(wt,BigInt(t),ps),wt+=8;return}throw new Fl(`Value too large to encode: ${t}`)}function E3(e){Hs(mt.Simple,_3(e))}function _3(e){if(e===!1)return Rn.False;if(e===!0)return Rn.True;if(e===null)return Rn.Null;if(e===void 0)return Rn.Undefined;throw new Fl(`Unrecognized simple value: ${e.toString()}`)}function b1(e,t){Hs(e,t.length),wt>hn.length-t.length&&(hn=w1(hn,hn.length+t.length),On=new DataView(hn.buffer)),hn.set(t,wt),wt+=t.length}function E1(e,t){Hs(e,t)}function S3(e){E1(mt.UnsignedInteger,e)}function T3(e){E1(mt.NegativeInteger,typeof e=="bigint"?-1n-e:-1-e)}function x3(e){e>=0?S3(e):T3(e)}function _1(e){b1(mt.TextString,g3.encode(e))}function Bd(e){b1(mt.ByteString,e)}function A3(e,t,n){Hs(mt.Tag,e),Ml(t,n)}function v3(e){return typeof e=="object"&&e!==null&&"toCborValue"in e}function Hu(e){try{return w3(e,t=>$e.isPrincipal(t)?t.toUint8Array():ys.isExpiry(t)?t.toBigInt():v3(t)?t.toCborValue():t)}catch(t){throw Ye.fromCode(new Al(t,e))}}function Dn(e){try{return a3(e)}catch(t){throw Ye.fromCode(new xl(t,e))}}const _c=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){const e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if(typeof crypto<"u"&&crypto.getRandomValues){const e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Ii;(function(e){e.Query="read",e.ReadState="read_state",e.Call="call"})(Ii||(Ii={}));var Ff;(function(e){e.Call="call"})(Ff||(Ff={}));var To;(function(e){e.Query="query",e.ReadState="read_state"})(To||(To={}));function Mf(){const e=new ArrayBuffer(16),t=new DataView(e),n=_c(),r=_c(),i=_c(),s=_c();return t.setUint32(0,n),t.setUint32(4,r),t.setUint32(8,i),t.setUint32(12,s),Object.assign(new Uint8Array(e),{__nonce__:void 0})}const Sc="__expiry__",ql=BigInt(1e3),B3=BigInt(1e6),S1=BigInt(60),I3=BigInt(90)*ql;function T1(e){return e/ql}function O3(e){return T1(e)/S1}class ys{constructor(t){this.__expiry__=t,this._isExpiry=!0}static fromDeltaInMilliseconds(t,n=0){const r=BigInt(t),i=BigInt(Date.now())+r+BigInt(n);let s;return r<I3?s=T1(i):s=O3(i)*S1,new ys(s*ql*B3)}toBigInt(){return this.__expiry__}toHash(){return ot(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[Sc]:this.toString()}}static fromJSON(t){const n=JSON.parse(t);if(n[Sc])try{const r=BigInt(n[Sc]);return new ys(r)}catch(r){throw new Ye(new la(`Not a valid BigInt: ${r}`))}throw new Ye(new la(`The input does not contain the key ${Sc}`))}static isExpiry(t){return t instanceof ys||typeof t=="object"&&t!==null&&"_isExpiry"in t&&t._isExpiry===!0&&"__expiry__"in t&&typeof t.__expiry__=="bigint"}}function Id(e=Mf){return async t=>{const n=t.request.headers;t.request.headers=n,t.endpoint===Ii.Call&&(t.body.nonce=e())}}function Fu(e){const t=[];return e.forEach((n,r)=>{t.push([r,n])}),t}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Vl=BigInt(0),pa=BigInt(1);function xo(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function gs(e,t,n=""){const r=Lo(e),i=e?.length,s=t!==void 0;if(!r||s&&i!==t){const o=n&&`"${n}" `,c=s?` of length ${t}`:"",a=r?`length=${i}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+c+", got "+a)}return e}function x1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Vl:BigInt("0x"+e)}function Yn(e){return x1(Qe(e))}function Ao(e){return Sn(e),x1(Qe(Uint8Array.from(e).reverse()))}function Ot(e,t){return jo(e.toString(16).padStart(t*2,"0"))}function A1(e,t){return Ot(e,t).reverse()}function en(e,t,n){let r;if(typeof t=="string")try{r=jo(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Lo(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}function Od(e){return Uint8Array.from(e)}const Mu=e=>typeof e=="bigint"&&Vl<=e;function v1(e,t,n){return Mu(e)&&Mu(t)&&Mu(n)&&t<=e&&e<n}function Pd(e,t,n,r){if(!v1(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function vo(e){let t;for(t=0;e>Vl;e>>=pa,t+=1);return t}function P3(e,t){return e>>BigInt(t)&pa}const Gi=e=>(pa<<BigInt(e))-pa;function k3(e){return typeof e=="function"&&Number.isSafeInteger(e.outputLen)}function ic(e,t,n={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function r(i,s,o){const c=e[i];if(o&&c===void 0)return;const a=typeof c;if(a!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}const B1=()=>{throw new Error("not implemented")};function Bo(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(i!==void 0)return i;const s=e(n,...r);return t.set(n,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const on=BigInt(0),Nt=BigInt(1),Oi=BigInt(2),I1=BigInt(3),O1=BigInt(4),P1=BigInt(5),N3=BigInt(7),k1=BigInt(8),U3=BigInt(9),N1=BigInt(16);function dt(e,t){const n=e%t;return n>=on?n:t+n}function jn(e,t,n){let r=e;for(;t-- >on;)r*=r,r%=n;return r}function kd(e,t){if(e===on)throw new Error("invert: expected non-zero number");if(t<=on)throw new Error("invert: expected positive modulus, got "+t);let n=dt(e,t),r=t,i=on,s=Nt;for(;n!==on;){const c=r/n,a=r%n,u=i-s*c;r=n,n=a,i=s,s=u}if(r!==Nt)throw new Error("invert: does not exist");return dt(i,t)}function $l(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function U1(e,t){const n=(e.ORDER+Nt)/O1,r=e.pow(t,n);return $l(e,r,t),r}function R3(e,t){const n=(e.ORDER-P1)/k1,r=e.mul(t,Oi),i=e.pow(r,n),s=e.mul(t,i),o=e.mul(e.mul(s,Oi),i),c=e.mul(s,e.sub(o,e.ONE));return $l(e,c,t),c}function C3(e){const t=ai(e),n=R1(e),r=n(t,t.neg(t.ONE)),i=n(t,r),s=n(t,t.neg(r)),o=(e+N3)/N1;return(c,a)=>{let u=c.pow(a,o),f=c.mul(u,r);const l=c.mul(u,i),p=c.mul(u,s),y=c.eql(c.sqr(f),a),g=c.eql(c.sqr(l),a);u=c.cmov(u,f,y),f=c.cmov(p,l,g);const w=c.eql(c.sqr(f),a),E=c.cmov(u,f,w);return $l(c,E,a),E}}function R1(e){if(e<I1)throw new Error("sqrt is not defined for small field");let t=e-Nt,n=0;for(;t%Oi===on;)t/=Oi,n++;let r=Oi;const i=ai(e);for(;ya(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return U1;let s=i.pow(r,t);const o=(t+Nt)/Oi;return function(a,u){if(a.is0(u))return u;if(ya(a,u)!==1)throw new Error("Cannot find square root");let f=n,l=a.mul(a.ONE,s),p=a.pow(u,t),y=a.pow(u,o);for(;!a.eql(p,a.ONE);){if(a.is0(p))return a.ZERO;let g=1,w=a.sqr(p);for(;!a.eql(w,a.ONE);)if(g++,w=a.sqr(w),g===f)throw new Error("Cannot find square root");const E=Nt<<BigInt(f-g-1),_=a.pow(l,E);f=g,l=a.sqr(_),p=a.mul(p,l),y=a.mul(y,_)}return y}}function H3(e){return e%O1===I1?U1:e%k1===P1?R3:e%N1===U3?C3(e):R1(e)}const F3=(e,t)=>(dt(e,t)&Nt)===Nt,M3=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function C1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=M3.reduce((r,i)=>(r[i]="function",r),t);return ic(e,n),e}function eu(e,t,n){if(n<on)throw new Error("invalid exponent, negatives unsupported");if(n===on)return e.ONE;if(n===Nt)return t;let r=e.ONE,i=t;for(;n>on;)n&Nt&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Nt;return r}function Di(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((o,c,a)=>e.is0(c)?o:(r[a]=o,e.mul(o,c)),e.ONE),s=e.inv(i);return t.reduceRight((o,c,a)=>e.is0(c)?o:(r[a]=e.mul(o,r[a]),e.mul(o,c)),s),r}function ya(e,t){const n=(e.ORDER-Nt)/Oi,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function q3(e,t){t!==void 0&&Sm(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ai(e,t,n=!1,r={}){if(e<=on)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s,o=!1,c;if(typeof t=="object"&&t!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const p=t;p.BITS&&(i=p.BITS),p.sqrt&&(s=p.sqrt),typeof p.isLE=="boolean"&&(n=p.isLE),typeof p.modFromBytes=="boolean"&&(o=p.modFromBytes),c=p.allowedLengths}else typeof t=="number"&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:a,nByteLength:u}=q3(e,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const l=Object.freeze({ORDER:e,isLE:n,BITS:a,BYTES:u,MASK:Gi(a),ZERO:on,ONE:Nt,allowedLengths:c,create:p=>dt(p,e),isValid:p=>{if(typeof p!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof p);return on<=p&&p<e},is0:p=>p===on,isValidNot0:p=>!l.is0(p)&&l.isValid(p),isOdd:p=>(p&Nt)===Nt,neg:p=>dt(-p,e),eql:(p,y)=>p===y,sqr:p=>dt(p*p,e),add:(p,y)=>dt(p+y,e),sub:(p,y)=>dt(p-y,e),mul:(p,y)=>dt(p*y,e),pow:(p,y)=>eu(l,p,y),div:(p,y)=>dt(p*kd(y,e),e),sqrN:p=>p*p,addN:(p,y)=>p+y,subN:(p,y)=>p-y,mulN:(p,y)=>p*y,inv:p=>kd(p,e),sqrt:s||(p=>(f||(f=H3(e)),f(l,p))),toBytes:p=>n?A1(p,u):Ot(p,u),fromBytes:(p,y=!0)=>{if(c){if(!c.includes(p.length)||p.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+p.length);const w=new Uint8Array(u);w.set(p,n?0:w.length-p.length),p=w}if(p.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+p.length);let g=n?Ao(p):Yn(p);if(o&&(g=dt(g,e)),!y&&!l.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:p=>Di(l,p),cmov:(p,y,g)=>g?y:p});return Object.freeze(l)}function H1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function F1(e){const t=H1(e);return t+Math.ceil(t/2)}function V3(e,t,n=!1){const r=e.length,i=H1(t),s=F1(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Ao(e):Yn(e),c=dt(o,t-Nt)+Nt;return n?A1(c,i):Ot(c,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const As=BigInt(0),Pi=BigInt(1);function ga(e,t){const n=t.negate();return e?n:t}function dr(e,t){const n=Di(e.Fp,t.map(r=>r.Z));return t.map((r,i)=>e.fromAffine(r.toAffine(n[i])))}function M1(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function qu(e,t){M1(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e,s=Gi(e),o=BigInt(e);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function Nd(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let c=Number(e&i),a=e>>o;c>r&&(c-=s,a+=Pi);const u=t*r,f=u+Math.abs(c)-1,l=c===0,p=c<0,y=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:p,isNegF:y,offsetF:u}}function $3(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function K3(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,r)=>{if(!t.isValid(n))throw new Error("invalid scalar at index "+r)})}const Vu=new WeakMap,q1=new WeakMap;function $u(e){return q1.get(e)||1}function Ud(e){if(e!==As)throw new Error("invalid wNAF")}class V1{constructor(t,n){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}_unsafeLadder(t,n,r=this.ZERO){let i=t;for(;n>As;)n&Pi&&(r=r.add(i)),i=i.double(),n>>=Pi;return r}precomputeWindow(t,n){const{windows:r,windowSize:i}=qu(n,this.bits),s=[];let o=t,c=o;for(let a=0;a<r;a++){c=o,s.push(c);for(let u=1;u<i;u++)c=c.add(o),s.push(c);o=c.double()}return s}wNAF(t,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=qu(t,this.bits);for(let c=0;c<o.windows;c++){const{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:p,offsetF:y}=Nd(r,c,o);r=a,f?s=s.add(ga(p,n[y])):i=i.add(ga(l,n[u]))}return Ud(r),{p:i,f:s}}wNAFUnsafe(t,n,r,i=this.ZERO){const s=qu(t,this.bits);for(let o=0;o<s.windows&&r!==As;o++){const{nextN:c,offset:a,isZero:u,isNeg:f}=Nd(r,o,s);if(r=c,!u){const l=n[a];i=i.add(f?l.negate():l)}}return Ud(r),i}getPrecomputes(t,n,r){let i=Vu.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof r=="function"&&(i=r(i)),Vu.set(n,i))),i}cached(t,n,r){const i=$u(t);return this.wNAF(i,this.getPrecomputes(i,t,r),n)}unsafe(t,n,r,i){const s=$u(t);return s===1?this._unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,r),n,i)}createCache(t,n){M1(n,this.bits),q1.set(t,n),Vu.delete(t)}hasCache(t){return $u(t)!==1}}function L3(e,t,n,r){let i=t,s=e.ZERO,o=e.ZERO;for(;n>As||r>As;)n&Pi&&(s=s.add(i)),r&Pi&&(o=o.add(i)),i=i.double(),n>>=Pi,r>>=Pi;return{p1:s,p2:o}}function $1(e,t,n,r){$3(n,e),K3(r,t);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,c=vo(BigInt(i));let a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);const u=Gi(a),f=new Array(Number(u)+1).fill(o),l=Math.floor((t.BITS-1)/a)*a;let p=o;for(let y=l;y>=0;y-=a){f.fill(o);for(let w=0;w<s;w++){const E=r[w],_=Number(E>>BigInt(y)&u);f[_]=f[_].add(n[w])}let g=o;for(let w=f.length-1,E=o;w>0;w--)E=E.add(f[w]),g=g.add(E);if(p=p.add(g),y!==0)for(let w=0;w<a;w++)p=p.double()}return p}function Rd(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return C1(t),t}else return ai(e,{isLE:n})}function K1(e,t,n={},r){if(r===void 0&&(r=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const u=t[a];if(!(typeof u=="bigint"&&u>As))throw new Error(`CURVE.${a} must be positive bigint`)}const i=Rd(t.p,n.Fp,r),s=Rd(t.n,n.Fn,r),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(const a of c)if(!i.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:s}}const j3=Yn;function Xr(e,t){if(Io(e),Io(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);const n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function W3(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r];return n}function Io(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function L1(e){if(!Lo(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or string");return typeof e=="string"?ut(e):e}function G3(e,t,n,r){Sn(e),Io(n),t=L1(t),t.length>255&&(t=r(Me(ut("H2C-OVERSIZE-DST-"),t)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const c=Me(t,Xr(t.length,1)),a=Xr(0,s),u=Xr(n,2),f=new Array(o),l=r(Me(a,e,u,Xr(0,1),c));f[0]=r(Me(l,Xr(1,1),c));for(let y=1;y<=o;y++){const g=[W3(l,f[y-1]),Xr(y+1,1),c];f[y]=r(Me(...g))}return Me(...f).slice(0,n)}function D3(e,t,n,r,i){if(Sn(e),Io(n),t=L1(t),t.length>255){const s=Math.ceil(2*r/8);t=i.create({dkLen:s}).update(ut("H2C-OVERSIZE-DST-")).update(t).digest()}if(n>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(e).update(Xr(n,2)).update(t).update(Xr(t.length,1)).digest()}function Ku(e,t,n){ic(n,{p:"bigint",m:"number",k:"number",hash:"function"});const{p:r,k:i,m:s,hash:o,expand:c,DST:a}=n;if(!k3(n.hash))throw new Error("expected valid hash");Sn(e),Io(t);const u=r.toString(2).length,f=Math.ceil((u+i)/8),l=t*s*f;let p;if(c==="xmd")p=G3(e,a,l,o);else if(c==="xof")p=D3(e,a,l,i,o);else if(c==="_internal_pass")p=e;else throw new Error('expand must be "xmd" or "xof"');const y=new Array(t);for(let g=0;g<t;g++){const w=new Array(s);for(let E=0;E<s;E++){const _=f*(E+g*s),S=p.subarray(_,_+f);w[E]=dt(j3(S),r)}y[g]=w}return y}function j1(e,t){const n=t.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,c,a]=n.map(l=>l.reduce((p,y)=>e.add(e.mul(p,r),y))),[u,f]=Di(e,[o,a],!0);return r=e.mul(s,u),i=e.mul(i,e.mul(c,f)),{x:r,y:i}}}const X3=ut("HashToScalar-");function Cd(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");function r(s){return e.fromAffine(t(s))}function i(s){const o=s.clearCofactor();return o.equals(e.ZERO)?e.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const c=Object.assign({},n,o),a=Ku(s,2,c),u=r(a[0]),f=r(a[1]);return i(u.add(f))},encodeToCurve(s,o){const c=n.encodeDST?{DST:n.encodeDST}:{},a=Object.assign({},n,c,o),u=Ku(s,1,a),f=r(u[0]);return i(f)},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))},hashToScalar(s,o){const c=e.Fn.ORDER,a=Object.assign({},n,{p:c,m:1,DST:X3},o);return Ku(s,1,a)[0][0]}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Hd=(e,t)=>(e+(e>=0?t:-t)/cr)/t;function z3(e,t,n){const[[r,i],[s,o]]=t,c=Hd(o*e,n),a=Hd(-i*e,n);let u=e-c*r-a*s,f=-c*i-a*o;const l=u<ki,p=f<ki;l&&(u=-u),p&&(f=-f);const y=Gi(Math.ceil(vo(n)/2))+Xt;if(u<ki||u>=y||f<ki||f>=y)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:p,k2:f}}const ki=BigInt(0),Xt=BigInt(1),cr=BigInt(2),cs=BigInt(3),qf=BigInt(4);function wa(e,t){const{BYTES:n}=e;let r;if(typeof t=="bigint")r=t;else{let i=en("private key",t);try{r=e.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Y3(e,t={}){const n=K1("weierstrass",e,t),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:c}=s;ic(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:a}=t;if(a&&(!r.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Q3(r,i);function f(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(W,H,K){const{x:N,y:L}=H.toAffine(),F=r.toBytes(N);if(xo(K,"isCompressed"),K){f();const x=!r.isOdd(L);return Me(Z3(x),F)}else return Me(Uint8Array.of(4),F,r.toBytes(L))}function p(W){gs(W,void 0,"Point");const{publicKey:H,publicKeyUncompressed:K}=u,N=W.length,L=W[0],F=W.subarray(1);if(N===H&&(L===2||L===3)){const x=r.fromBytes(F);if(!r.isValid(x))throw new Error("bad point: is not on curve, wrong x");const O=w(x);let q;try{q=r.sqrt(O)}catch(G){const X=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}f();const P=r.isOdd(q);return(L&1)===1!==P&&(q=r.neg(q)),{x,y:q}}else if(N===K&&L===4){const x=r.BYTES,O=r.fromBytes(F.subarray(0,x)),q=r.fromBytes(F.subarray(x,x*2));if(!E(O,q))throw new Error("bad point: is not on curve");return{x:O,y:q}}else throw new Error(`bad point: got length ${N}, expected compressed=${H} or uncompressed=${K}`)}const y=t.toBytes||l,g=t.fromBytes||p;function w(W){const H=r.sqr(W),K=r.mul(H,W);return r.add(r.add(K,r.mul(W,s.a)),s.b)}function E(W,H){const K=r.sqr(H),N=w(W);return r.eql(K,N)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const _=r.mul(r.pow(s.a,cs),qf),S=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(_,S)))throw new Error("bad curve params: a or b");function m(W,H,K=!1){if(!r.isValid(H)||K&&r.is0(H))throw new Error(`bad point coordinate ${W}`);return H}function T(W){if(!(W instanceof v))throw new Error("ProjectivePoint expected")}function I(W){if(!a||!a.basises)throw new Error("no endo");return z3(W,a.basises,i.ORDER)}const A=Bo((W,H)=>{const{X:K,Y:N,Z:L}=W;if(r.eql(L,r.ONE))return{x:K,y:N};const F=W.is0();H==null&&(H=F?r.ONE:r.inv(L));const x=r.mul(K,H),O=r.mul(N,H),q=r.mul(L,H);if(F)return{x:r.ZERO,y:r.ZERO};if(!r.eql(q,r.ONE))throw new Error("invZ was invalid");return{x,y:O}}),U=Bo(W=>{if(W.is0()){if(t.allowInfinityPoint&&!r.is0(W.Y))return;throw new Error("bad point: ZERO")}const{x:H,y:K}=W.toAffine();if(!r.isValid(H)||!r.isValid(K))throw new Error("bad point: x or y not field elements");if(!E(H,K))throw new Error("bad point: equation left != right");if(!W.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(W,H,K,N,L){return K=new v(r.mul(K.X,W),K.Y,K.Z),H=ga(N,H),K=ga(L,K),H.add(K)}class v{constructor(H,K,N){this.X=m("x",H),this.Y=m("y",K,!0),this.Z=m("z",N),Object.freeze(this)}static CURVE(){return s}static fromAffine(H){const{x:K,y:N}=H||{};if(!H||!r.isValid(K)||!r.isValid(N))throw new Error("invalid affine point");if(H instanceof v)throw new Error("projective point not allowed");return r.is0(K)&&r.is0(N)?v.ZERO:new v(K,N,r.ONE)}static fromBytes(H){const K=v.fromAffine(g(gs(H,void 0,"point")));return K.assertValidity(),K}static fromHex(H){return v.fromBytes(en("pointHex",H))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(H=8,K=!0){return V.createCache(this,H),K||this.multiply(cs),this}assertValidity(){U(this)}hasEvenY(){const{y:H}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(H)}equals(H){T(H);const{X:K,Y:N,Z:L}=this,{X:F,Y:x,Z:O}=H,q=r.eql(r.mul(K,O),r.mul(F,L)),P=r.eql(r.mul(N,O),r.mul(x,L));return q&&P}negate(){return new v(this.X,r.neg(this.Y),this.Z)}double(){const{a:H,b:K}=s,N=r.mul(K,cs),{X:L,Y:F,Z:x}=this;let O=r.ZERO,q=r.ZERO,P=r.ZERO,$=r.mul(L,L),G=r.mul(F,F),X=r.mul(x,x),Y=r.mul(L,F);return Y=r.add(Y,Y),P=r.mul(L,x),P=r.add(P,P),O=r.mul(H,P),q=r.mul(N,X),q=r.add(O,q),O=r.sub(G,q),q=r.add(G,q),q=r.mul(O,q),O=r.mul(Y,O),P=r.mul(N,P),X=r.mul(H,X),Y=r.sub($,X),Y=r.mul(H,Y),Y=r.add(Y,P),P=r.add($,$),$=r.add(P,$),$=r.add($,X),$=r.mul($,Y),q=r.add(q,$),X=r.mul(F,x),X=r.add(X,X),$=r.mul(X,Y),O=r.sub(O,$),P=r.mul(X,G),P=r.add(P,P),P=r.add(P,P),new v(O,q,P)}add(H){T(H);const{X:K,Y:N,Z:L}=this,{X:F,Y:x,Z:O}=H;let q=r.ZERO,P=r.ZERO,$=r.ZERO;const G=s.a,X=r.mul(s.b,cs);let Y=r.mul(K,F),oe=r.mul(N,x),ae=r.mul(L,O),ee=r.add(K,N),Z=r.add(F,x);ee=r.mul(ee,Z),Z=r.add(Y,oe),ee=r.sub(ee,Z),Z=r.add(K,L);let ce=r.add(F,O);return Z=r.mul(Z,ce),ce=r.add(Y,ae),Z=r.sub(Z,ce),ce=r.add(N,L),q=r.add(x,O),ce=r.mul(ce,q),q=r.add(oe,ae),ce=r.sub(ce,q),$=r.mul(G,Z),q=r.mul(X,ae),$=r.add(q,$),q=r.sub(oe,$),$=r.add(oe,$),P=r.mul(q,$),oe=r.add(Y,Y),oe=r.add(oe,Y),ae=r.mul(G,ae),Z=r.mul(X,Z),oe=r.add(oe,ae),ae=r.sub(Y,ae),ae=r.mul(G,ae),Z=r.add(Z,ae),Y=r.mul(oe,Z),P=r.add(P,Y),Y=r.mul(ce,Z),q=r.mul(ee,q),q=r.sub(q,Y),Y=r.mul(ee,oe),$=r.mul(ce,$),$=r.add($,Y),new v(q,P,$)}subtract(H){return this.add(H.negate())}is0(){return this.equals(v.ZERO)}multiply(H){const{endo:K}=t;if(!i.isValidNot0(H))throw new Error("invalid scalar: out of range");let N,L;const F=x=>V.cached(this,x,O=>dr(v,O));if(K){const{k1neg:x,k1:O,k2neg:q,k2:P}=I(H),{p:$,f:G}=F(O),{p:X,f:Y}=F(P);L=G.add(Y),N=M(K.beta,$,X,x,q)}else{const{p:x,f:O}=F(H);N=x,L=O}return dr(v,[N,L])[0]}multiplyUnsafe(H){const{endo:K}=t,N=this;if(!i.isValid(H))throw new Error("invalid scalar: out of range");if(H===ki||N.is0())return v.ZERO;if(H===Xt)return N;if(V.hasCache(this))return this.multiply(H);if(K){const{k1neg:L,k1:F,k2neg:x,k2:O}=I(H),{p1:q,p2:P}=L3(v,N,F,O);return M(K.beta,q,P,L,x)}else return V.unsafe(N,H)}multiplyAndAddUnsafe(H,K,N){const L=this.multiplyUnsafe(K).add(H.multiplyUnsafe(N));return L.is0()?void 0:L}toAffine(H){return A(this,H)}isTorsionFree(){const{isTorsionFree:H}=t;return o===Xt?!0:H?H(v,this):V.unsafe(this,c).is0()}clearCofactor(){const{clearCofactor:H}=t;return o===Xt?this:H?H(v,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(H=!0){return xo(H,"isCompressed"),this.assertValidity(),y(v,this,H)}toHex(H=!0){return Qe(this.toBytes(H))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(H=!0){return this.toBytes(H)}_setWindowSize(H){this.precompute(H)}static normalizeZ(H){return dr(v,H)}static msm(H,K){return $1(v,i,H,K)}static fromPrivateKey(H){return v.BASE.multiply(wa(i,H))}}v.BASE=new v(s.Gx,s.Gy,r.ONE),v.ZERO=new v(r.ZERO,r.ONE,r.ZERO),v.Fp=r,v.Fn=i;const R=i.BITS,V=new V1(v,t.endo?Math.ceil(R/2):R);return v.BASE.precompute(8),v}function Z3(e){return Uint8Array.of(e?2:3)}function J3(e,t){const n=e.ORDER;let r=ki;for(let g=n-Xt;g%cr===ki;g/=cr)r+=Xt;const i=r,s=cr<<i-Xt-Xt,o=s*cr,c=(n-Xt)/o,a=(c-Xt)/cr,u=o-Xt,f=s,l=e.pow(t,c),p=e.pow(t,(c+Xt)/cr);let y=(g,w)=>{let E=l,_=e.pow(w,u),S=e.sqr(_);S=e.mul(S,w);let m=e.mul(g,S);m=e.pow(m,a),m=e.mul(m,_),_=e.mul(m,w),S=e.mul(m,g);let T=e.mul(S,_);m=e.pow(T,f);let I=e.eql(m,e.ONE);_=e.mul(S,p),m=e.mul(T,E),S=e.cmov(_,S,I),T=e.cmov(m,T,I);for(let A=i;A>Xt;A--){let U=A-cr;U=cr<<U-Xt;let M=e.pow(T,U);const v=e.eql(M,e.ONE);_=e.mul(S,E),E=e.mul(E,E),M=e.mul(T,E),S=e.cmov(_,S,v),T=e.cmov(M,T,v)}return{isValid:I,value:S}};if(e.ORDER%qf===cs){const g=(e.ORDER-cs)/qf,w=e.sqrt(e.neg(t));y=(E,_)=>{let S=e.sqr(_);const m=e.mul(E,_);S=e.mul(S,m);let T=e.pow(S,g);T=e.mul(T,m);const I=e.mul(T,w),A=e.mul(e.sqr(T),_),U=e.eql(A,E);let M=e.cmov(I,T,U);return{isValid:U,value:M}}}return y}function W1(e,t){C1(e);const{A:n,B:r,Z:i}=t;if(!e.isValid(n)||!e.isValid(r)||!e.isValid(i))throw new Error("mapToCurveSimpleSWU: invalid opts");const s=J3(e,i);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return o=>{let c,a,u,f,l,p,y,g;c=e.sqr(o),c=e.mul(c,i),a=e.sqr(c),a=e.add(a,c),u=e.add(a,e.ONE),u=e.mul(u,r),f=e.cmov(i,e.neg(a),!e.eql(a,e.ZERO)),f=e.mul(f,n),a=e.sqr(u),p=e.sqr(f),l=e.mul(p,n),a=e.add(a,l),a=e.mul(a,u),p=e.mul(p,f),l=e.mul(p,r),a=e.add(a,l),y=e.mul(c,u);const{isValid:w,value:E}=s(a,p);g=e.mul(c,o),g=e.mul(g,E),y=e.cmov(y,u,w),g=e.cmov(g,E,w);const _=e.isOdd(o)===e.isOdd(g);g=e.cmov(e.neg(g),g,_);const S=Di(e,[f],!0)[0];return y=e.mul(y,S),{x:y,y:g}}}function Q3(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Fd(e){const{CURVE:t,curveOpts:n}=eT(e),r=Y3(t,n);return nT(e,r)}function eT(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=ai(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function tT(e,t,n){function r(i){const s=e.sqr(i),o=e.mul(s,i);return e.add(e.add(o,e.mul(i,t)),n)}return r}function nT(e,t){const{Fp:n,Fn:r}=t;function i(o){return v1(o,Xt,r.ORDER)}const s=tT(n,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:o=>wa(r,o),weierstrassEquation:s,isWithinCurveOrder:i})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rT=BigInt(0),Tc=BigInt(1),Md=BigInt(2),as=BigInt(3);function iT(e){const t=[];for(;e>Tc;e>>=Tc)(e&Tc)===rT?t.unshift(0):(e&as)===as?(t.unshift(-1),e+=Tc):t.unshift(1);return t}function Lu(e){if(!Array.isArray(e)||e.length===0)throw new Error("expected non-empty array")}function sT(e,t,n,r){const{Fp2:i,Fp12:s}=e,{twistType:o,ateLoopSize:c,xNegative:a,postPrecompute:u}=r;let f;if(o==="multiplicative")f=(m,T,I,A,U,M)=>s.mul014(A,m,i.mul(T,U),i.mul(I,M));else if(o==="divisive")f=(m,T,I,A,U,M)=>s.mul034(A,i.mul(I,M),i.mul(T,U),m);else throw new Error("bls: unknown twist type");const l=i.div(i.ONE,i.mul(i.ONE,Md));function p(m,T,I,A){const U=i.sqr(I),M=i.sqr(A),v=i.mulByB(i.mul(M,as)),R=i.mul(v,as),V=i.sub(i.sub(i.sqr(i.add(I,A)),M),U),W=i.sub(v,U),H=i.mul(i.sqr(T),as),K=i.neg(V);return m.push([W,H,K]),T=i.mul(i.mul(i.mul(i.sub(U,R),T),I),l),I=i.sub(i.sqr(i.mul(i.add(U,R),l)),i.mul(i.sqr(v),as)),A=i.mul(U,V),{Rx:T,Ry:I,Rz:A}}function y(m,T,I,A,U,M){const v=i.sub(I,i.mul(M,A)),R=i.sub(T,i.mul(U,A)),V=i.sub(i.mul(v,U),i.mul(R,M)),W=i.neg(v),H=R;m.push([V,W,H]);const K=i.sqr(R),N=i.mul(K,R),L=i.mul(K,T),F=i.add(i.sub(N,i.mul(L,Md)),i.mul(i.sqr(v),A));return T=i.mul(R,F),I=i.sub(i.mul(i.sub(L,F),v),i.mul(N,I)),A=i.mul(A,N),{Rx:T,Ry:I,Rz:A}}const g=iT(c),w=Bo(m=>{const T=m,{x:I,y:A}=T.toAffine(),U=I,M=A,v=i.neg(A);let R=U,V=M,W=i.ONE;const H=[];for(const K of g){const N=[];({Rx:R,Ry:V,Rz:W}=p(N,R,V,W)),K&&({Rx:R,Ry:V,Rz:W}=y(N,R,V,W,U,K===-1?v:M)),H.push(N)}if(u){const K=H[H.length-1];u(R,V,W,U,M,y.bind(null,K))}return H});function E(m,T=!1){let I=s.ONE;if(m.length){const A=m[0][0].length;for(let U=0;U<A;U++){I=s.sqr(I);for(const[M,v,R]of m)for(const[V,W,H]of M[U])I=f(V,W,H,I,v,R)}}return a&&(I=s.conjugate(I)),T?s.finalExponentiate(I):I}function _(m,T=!0){const I=[];dr(t,m.map(({g1:A})=>A)),dr(n,m.map(({g2:A})=>A));for(const{g1:A,g2:U}of m){if(A.is0()||U.is0())throw new Error("pairing is not available for ZERO point");A.assertValidity(),U.assertValidity();const M=A.toAffine();I.push([w(U),M.x,M.y])}return E(I,T)}function S(m,T,I=!0){return _([{g1:m,g2:T}],I)}return{Fp12:s,millerLoopBatch:E,pairing:S,pairingBatch:_,calcPairingPrecomputes:w}}function qd(e,t,n,r,i){const{Fp12:s,pairingBatch:o}=e;function c(l){return l instanceof t.Point?l:t.Point.fromHex(l)}function a(l){return l instanceof n.Point?l:n.Point.fromHex(l)}function u(l){if(!(l instanceof n.Point))throw new Error(`expected valid message hashed to ${i?"G1":"G2"} curve`);return l}const f=i?(l,p)=>({g1:p,g2:l}):(l,p)=>({g1:l,g2:p});return{getPublicKey(l){const p=wa(t.Point.Fn,l);return t.Point.BASE.multiply(p)},sign(l,p,y){if(y!=null)throw new Error("sign() expects 2 arguments");const g=wa(t.Point.Fn,p);return u(l).assertValidity(),l.multiply(g)},verify(l,p,y,g){if(g!=null)throw new Error("verify() expects 3 arguments");l=a(l),y=c(y);const w=y.negate(),E=t.Point.BASE,_=u(p),S=l,m=o([f(w,_),f(E,S)]);return s.eql(m,s.ONE)},verifyBatch(l,p,y){if(Lu(p),y.length!==p.length)throw new Error("amount of public keys and messages should be equal");const g=a(l),w=p,E=y.map(c),_=new Map;for(let T=0;T<E.length;T++){const I=E[T],A=w[T];let U=_.get(A);U===void 0&&(U=[],_.set(A,U)),U.push(I)}const S=[],m=t.Point.BASE;try{for(const[T,I]of _){const A=I.reduce((U,M)=>U.add(M));S.push(f(A,T))}return S.push(f(m.negate(),g)),s.eql(o(S),s.ONE)}catch{return!1}},aggregatePublicKeys(l){Lu(l),l=l.map(y=>c(y));const p=l.reduce((y,g)=>y.add(g),t.Point.ZERO);return p.assertValidity(),p},aggregateSignatures(l){Lu(l),l=l.map(y=>a(y));const p=l.reduce((y,g)=>y.add(g),n.Point.ZERO);return p.assertValidity(),p},hash(l,p){Sn(l);const y=p?{DST:p}:void 0;return n.hashToCurve(l,y)},Signature:r}}function oT(e){const{Fp:t,Fr:n,Fp2:r,Fp6:i,Fp12:s}=e.fields,o=Fd(e.G1),c=Object.assign(o,Cd(o.Point,e.G1.mapToCurve,{...e.htfDefaults,...e.G1.htfDefaults})),a=Fd(e.G2),u=Object.assign(a,Cd(a.Point,e.G2.mapToCurve,{...e.htfDefaults,...e.G2.htfDefaults})),f=sT(e.fields,c.Point,u.Point,{...e.params,postPrecompute:e.postPrecompute}),{millerLoopBatch:l,pairing:p,pairingBatch:y,calcPairingPrecomputes:g}=f,w=qd(f,c,u,e.G2.Signature,!1),E=qd(f,u,c,e.G1.ShortSignature,!0),_=e.randomBytes||gy,S=()=>{const x=F1(n.ORDER);return V3(_(x),n.ORDER)},m={randomSecretKey:S,randomPrivateKey:S,calcPairingPrecomputes:g},{ShortSignature:T}=e.G1,{Signature:I}=e.G2;function A(x,O){return x instanceof c.Point?x:E.hash(en("point",x),O?.DST)}function U(x,O){return x instanceof u.Point?x:w.hash(en("point",x),O?.DST)}function M(x){return w.getPublicKey(x).toBytes(!0)}function v(x){return E.getPublicKey(x).toBytes(!0)}function R(x,O,q){const P=U(x,q),$=w.sign(P,O);return x instanceof u.Point?$:I.toBytes($)}function V(x,O,q){const P=A(x,q),$=E.sign(P,O);return x instanceof c.Point?$:T.toBytes($)}function W(x,O,q,P){const $=U(O,P);return w.verify(x,$,q)}function H(x,O,q,P){const $=A(O,P);return E.verify(x,$,q)}function K(x){const O=w.aggregatePublicKeys(x);return x[0]instanceof c.Point?O:O.toBytes(!0)}function N(x){const O=w.aggregateSignatures(x);return x[0]instanceof u.Point?O:I.toBytes(O)}function L(x){const O=E.aggregateSignatures(x);return x[0]instanceof c.Point?O:T.toBytes(O)}function F(x,O,q,P){const $=O.map(G=>U(G,P));return w.verifyBatch(x,$,q)}return c.Point.BASE.precompute(4),{longSignatures:w,shortSignatures:E,millerLoopBatch:l,pairing:p,pairingBatch:y,verifyBatch:F,fields:{Fr:n,Fp:t,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:e.params.ateLoopSize,twistType:e.params.twistType,r:e.params.r,G1b:e.G1.b,G2b:e.G2.b},utils:m,getPublicKey:M,getPublicKeyForShortSignatures:v,sign:R,signShortSignature:V,verify:W,verifyShortSignature:H,aggregatePublicKeys:K,aggregateSignatures:N,aggregateShortSignatures:L,G1:c,G2:u,Signature:I,ShortSignature:T}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Vd=BigInt(0),pr=BigInt(1),Yt=BigInt(2),$d=BigInt(3);function Kl(e,t,n,r,i=1,s){const o=BigInt(s===void 0?r:s),c=n**BigInt(r),a=[];for(let u=0;u<i;u++){const f=BigInt(u+1),l=[];for(let p=0,y=pr;p<r;p++){const g=(f*y-f)/o%c;l.push(e.pow(t,g)),y*=n}a.push(l)}return a}function cT(e,t,n){const r=t.pow(n,(e.ORDER-pr)/$d),i=t.pow(n,(e.ORDER-pr)/Yt);function s(p,y){const g=t.mul(t.frobeniusMap(p,1),r),w=t.mul(t.frobeniusMap(y,1),i);return[g,w]}const o=t.pow(n,(e.ORDER**Yt-pr)/$d),c=t.pow(n,(e.ORDER**Yt-pr)/Yt);if(!t.eql(c,t.neg(t.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function a(p,y){return[t.mul(p,o),t.neg(y)]}const u=p=>(y,g)=>{const w=g.toAffine(),E=p(w.x,w.y);return y.fromAffine({x:E[0],y:E[1]})},f=u(s),l=u(a);return{psi:s,psi2:a,G2psi:f,G2psi2:l,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:c}}const Kd=(e,t)=>{if(t.length!==2)throw new Error("invalid tuple");const n=t.map(r=>e.create(r));return{c0:n[0],c1:n[1]}};class aT{constructor(t,n={}){this.MASK=pr;const r=t.ORDER,i=r*r;this.Fp=t,this.ORDER=i,this.BITS=vo(i),this.BYTES=Math.ceil(vo(i)/8),this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.Fp_NONRESIDUE=t.create(n.NONRESIDUE||BigInt(-1)),this.Fp_div2=t.div(t.ONE,Yt),this.NONRESIDUE=Kd(t,n.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Kl(t,this.Fp_NONRESIDUE,t.ORDER,2)[0],this.mulByB=n.Fp2mulByB,Object.seal(this)}fromBigTuple(t){return Kd(this.Fp,t)}create(t){return t}isValid({c0:t,c1:n}){function r(i,s){return typeof i=="bigint"&&Vd<=i&&i<s}return r(t,this.ORDER)&&r(n,this.ORDER)}is0({c0:t,c1:n}){return this.Fp.is0(t)&&this.Fp.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}eql({c0:t,c1:n},{c0:r,c1:i}){return this.Fp.eql(t,r)&&this.Fp.eql(n,i)}neg({c0:t,c1:n}){return{c0:this.Fp.neg(t),c1:this.Fp.neg(n)}}pow(t,n){return eu(this,t,n)}invertBatch(t){return Di(this,t)}add(t,n){const{c0:r,c1:i}=t,{c0:s,c1:o}=n;return{c0:this.Fp.add(r,s),c1:this.Fp.add(i,o)}}sub({c0:t,c1:n},{c0:r,c1:i}){return{c0:this.Fp.sub(t,r),c1:this.Fp.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};const{c0:s,c1:o}=r;let c=i.mul(t,s),a=i.mul(n,o);const u=i.sub(c,a),f=i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a));return{c0:u,c1:f}}sqr({c0:t,c1:n}){const{Fp:r}=this,i=r.add(t,n),s=r.sub(t,n),o=r.add(t,t);return{c0:r.mul(i,s),c1:r.mul(o,n)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}div(t,n){const{Fp:r}=this;return this.mul(t,typeof n=="bigint"?r.inv(r.create(n)):this.inv(n))}inv({c0:t,c1:n}){const{Fp:r}=this,i=r.inv(r.create(t*t+n*n));return{c0:r.mul(i,r.create(t)),c1:r.mul(i,r.create(-n))}}sqrt(t){const{Fp:n}=this,r=this,{c0:i,c1:s}=t;if(n.is0(s))return ya(n,i)===1?r.create({c0:n.sqrt(i),c1:n.ZERO}):r.create({c0:n.ZERO,c1:n.sqrt(n.div(i,this.Fp_NONRESIDUE))});const o=n.sqrt(n.sub(n.sqr(i),n.mul(n.sqr(s),this.Fp_NONRESIDUE)));let c=n.mul(n.add(o,i),this.Fp_div2);ya(n,c)===-1&&(c=n.sub(c,o));const u=n.sqrt(c),f=r.create({c0:u,c1:n.div(n.mul(s,this.Fp_div2),u)});if(!r.eql(r.sqr(f),t))throw new Error("Cannot find square root");const l=f,p=r.neg(l),{re:y,im:g}=r.reim(l),{re:w,im:E}=r.reim(p);return g>E||g===E&&y>w?l:p}isOdd(t){const{re:n,im:r}=this.reim(t),i=n%Yt,s=n===Vd,o=r%Yt;return BigInt(i||s&&o)==pr}fromBytes(t){const{Fp:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){return Me(this.Fp.toBytes(t),this.Fp.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){return{c0:this.Fp.cmov(t,r,s),c1:this.Fp.cmov(n,i,s)}}reim({c0:t,c1:n}){return{re:t,im:n}}Fp4Square(t,n){const r=this,i=r.sqr(t),s=r.sqr(n);return{first:r.add(r.mulByNonresidue(s),i),second:r.sub(r.sub(r.sqr(r.add(t,n)),i),s)}}mulByNonresidue({c0:t,c1:n}){return this.mul({c0:t,c1:n},this.NONRESIDUE)}frobeniusMap({c0:t,c1:n},r){return{c0:t,c1:this.Fp.mul(n,this.FROBENIUS_COEFFICIENTS[r%2])}}}class uT{constructor(t){this.MASK=pr,this.Fp2=t,this.ORDER=t.ORDER,this.BITS=3*t.BITS,this.BYTES=3*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO,c2:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO,c2:t.ZERO};const{Fp:n}=t,r=Kl(t,t.NONRESIDUE,n.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=r[0],this.FROBENIUS_COEFFICIENTS_2=r[1],Object.seal(this)}add({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.add(t,i),c1:c.add(n,s),c2:c.add(r,o)}}sub({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return{c0:c.sub(t,i),c1:c.sub(n,s),c2:c.sub(r,o)}}mul({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;if(typeof i=="bigint")return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)};const{c0:o,c1:c,c2:a}=i,u=s.mul(t,o),f=s.mul(n,c),l=s.mul(r,a);return{c0:s.add(u,s.mulByNonresidue(s.sub(s.mul(s.add(n,r),s.add(c,a)),s.add(f,l)))),c1:s.add(s.sub(s.mul(s.add(t,n),s.add(o,c)),s.add(u,f)),s.mulByNonresidue(l)),c2:s.sub(s.add(f,s.mul(s.add(t,r),s.add(o,a))),s.add(u,l))}}sqr({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sqr(t),o=i.mul(i.mul(t,n),Yt),c=i.mul(i.mul(n,r),Yt),a=i.sqr(r);return{c0:i.add(i.mulByNonresidue(c),s),c1:i.add(i.mulByNonresidue(a),o),c2:i.sub(i.sub(i.add(i.add(o,i.sqr(i.add(i.sub(t,n),r))),c),s),a)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}create(t){return t}isValid({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.isValid(t)&&i.isValid(n)&&i.isValid(r)}is0({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return i.is0(t)&&i.is0(n)&&i.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.neg(t),c1:i.neg(n),c2:i.neg(r)}}eql({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o}){const{Fp2:c}=this;return c.eql(t,i)&&c.eql(n,s)&&c.eql(r,o)}sqrt(t){return B1()}div(t,n){const{Fp2:r}=this,{Fp:i}=r;return this.mul(t,typeof n=="bigint"?i.inv(i.create(n)):this.inv(n))}pow(t,n){return eu(this,t,n)}invertBatch(t){return Di(this,t)}inv({c0:t,c1:n,c2:r}){const{Fp2:i}=this;let s=i.sub(i.sqr(t),i.mulByNonresidue(i.mul(r,n))),o=i.sub(i.mulByNonresidue(i.sqr(r)),i.mul(t,n)),c=i.sub(i.sqr(n),i.mul(t,r)),a=i.inv(i.add(i.mulByNonresidue(i.add(i.mul(r,o),i.mul(n,c))),i.mul(t,s)));return{c0:i.mul(a,s),c1:i.mul(a,o),c2:i.mul(a,c)}}fromBytes(t){const{Fp2:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);const r=n.BYTES;return{c0:n.fromBytes(t.subarray(0,r)),c1:n.fromBytes(t.subarray(r,r*2)),c2:n.fromBytes(t.subarray(2*r))}}toBytes({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return Me(i.toBytes(t),i.toBytes(n),i.toBytes(r))}cmov({c0:t,c1:n,c2:r},{c0:i,c1:s,c2:o},c){const{Fp2:a}=this;return{c0:a.cmov(t,i,c),c1:a.cmov(n,s,c),c2:a.cmov(r,o,c)}}fromBigSix(t){const{Fp2:n}=this;if(!Array.isArray(t)||t.length!==6)throw new Error("invalid Fp6 usage");return{c0:n.fromBigTuple(t.slice(0,2)),c1:n.fromBigTuple(t.slice(2,4)),c2:n.fromBigTuple(t.slice(4,6))}}frobeniusMap({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.frobeniusMap(t,i),c1:s.mul(s.frobeniusMap(n,i),this.FROBENIUS_COEFFICIENTS_1[i%6]),c2:s.mul(s.frobeniusMap(r,i),this.FROBENIUS_COEFFICIENTS_2[i%6])}}mulByFp2({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mul(t,i),c1:s.mul(n,i),c2:s.mul(r,i)}}mulByNonresidue({c0:t,c1:n,c2:r}){const{Fp2:i}=this;return{c0:i.mulByNonresidue(r),c1:t,c2:n}}mul1({c0:t,c1:n,c2:r},i){const{Fp2:s}=this;return{c0:s.mulByNonresidue(s.mul(r,i)),c1:s.mul(t,i),c2:s.mul(n,i)}}mul01({c0:t,c1:n,c2:r},i,s){const{Fp2:o}=this;let c=o.mul(t,i),a=o.mul(n,s);return{c0:o.add(o.mulByNonresidue(o.sub(o.mul(o.add(n,r),s),a)),c),c1:o.sub(o.sub(o.mul(o.add(i,s),o.add(t,n)),c),a),c2:o.add(o.sub(o.mul(o.add(t,r),i),c),a)}}}class fT{constructor(t,n){this.MASK=pr;const{Fp2:r}=t,{Fp:i}=r;this.Fp6=t,this.ORDER=r.ORDER,this.BITS=2*t.BITS,this.BYTES=2*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.FROBENIUS_COEFFICIENTS=Kl(r,r.NONRESIDUE,i.ORDER,12,1,6)[0],this.X_LEN=n.X_LEN,this.finalExponentiate=n.Fp12finalExponentiate}create(t){return t}isValid({c0:t,c1:n}){const{Fp6:r}=this;return r.isValid(t)&&r.isValid(n)}is0({c0:t,c1:n}){const{Fp6:r}=this;return r.is0(t)&&r.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:n}){const{Fp6:r}=this;return{c0:r.neg(t),c1:r.neg(n)}}eql({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return s.eql(t,r)&&s.eql(n,i)}sqrt(t){B1()}inv({c0:t,c1:n}){const{Fp6:r}=this;let i=r.inv(r.sub(r.sqr(t),r.mulByNonresidue(r.sqr(n))));return{c0:r.mul(t,i),c1:r.neg(r.mul(n,i))}}div(t,n){const{Fp6:r}=this,{Fp2:i}=r,{Fp:s}=i;return this.mul(t,typeof n=="bigint"?s.inv(s.create(n)):this.inv(n))}pow(t,n){return eu(this,t,n)}invertBatch(t){return Di(this,t)}add({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.add(t,r),c1:s.add(n,i)}}sub({c0:t,c1:n},{c0:r,c1:i}){const{Fp6:s}=this;return{c0:s.sub(t,r),c1:s.sub(n,i)}}mul({c0:t,c1:n},r){const{Fp6:i}=this;if(typeof r=="bigint")return{c0:i.mul(t,r),c1:i.mul(n,r)};let{c0:s,c1:o}=r,c=i.mul(t,s),a=i.mul(n,o);return{c0:i.add(c,i.mulByNonresidue(a)),c1:i.sub(i.mul(i.add(t,n),i.add(s,o)),i.add(c,a))}}sqr({c0:t,c1:n}){const{Fp6:r}=this;let i=r.mul(t,n);return{c0:r.sub(r.sub(r.mul(r.add(r.mulByNonresidue(n),t),r.add(t,n)),i),r.mulByNonresidue(i)),c1:r.add(i,i)}}addN(t,n){return this.add(t,n)}subN(t,n){return this.sub(t,n)}mulN(t,n){return this.mul(t,n)}sqrN(t){return this.sqr(t)}fromBytes(t){const{Fp6:n}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:n.fromBytes(t.subarray(0,n.BYTES)),c1:n.fromBytes(t.subarray(n.BYTES))}}toBytes({c0:t,c1:n}){const{Fp6:r}=this;return Me(r.toBytes(t),r.toBytes(n))}cmov({c0:t,c1:n},{c0:r,c1:i},s){const{Fp6:o}=this;return{c0:o.cmov(t,r,s),c1:o.cmov(n,i,s)}}fromBigTwelve(t){const{Fp6:n}=this;return{c0:n.fromBigSix(t.slice(0,6)),c1:n.fromBigSix(t.slice(6,12))}}frobeniusMap(t,n){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=r.frobeniusMap(t.c1,n),a=this.FROBENIUS_COEFFICIENTS[n%12];return{c0:r.frobeniusMap(t.c0,n),c1:r.create({c0:i.mul(s,a),c1:i.mul(o,a),c2:i.mul(c,a)})}}mulByFp2({c0:t,c1:n},r){const{Fp6:i}=this;return{c0:i.mulByFp2(t,r),c1:i.mulByFp2(n,r)}}conjugate({c0:t,c1:n}){return{c0:t,c1:this.Fp6.neg(n)}}mul014({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o;let a=o.mul01(t,r,i),u=o.mul1(n,s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(o.sub(o.mul01(o.add(n,t),r,c.add(i,s)),a),u)}}mul034({c0:t,c1:n},r,i,s){const{Fp6:o}=this,{Fp2:c}=o,a=o.create({c0:c.mul(t.c0,r),c1:c.mul(t.c1,r),c2:c.mul(t.c2,r)}),u=o.mul01(n,i,s),f=o.mul01(o.add(t,n),c.add(r,i),s);return{c0:o.add(o.mulByNonresidue(u),a),c1:o.sub(f,o.add(a,u))}}_cyclotomicSquare({c0:t,c1:n}){const{Fp6:r}=this,{Fp2:i}=r,{c0:s,c1:o,c2:c}=t,{c0:a,c1:u,c2:f}=n,{first:l,second:p}=i.Fp4Square(s,u),{first:y,second:g}=i.Fp4Square(a,c),{first:w,second:E}=i.Fp4Square(o,f),_=i.mulByNonresidue(E);return{c0:r.create({c0:i.add(i.mul(i.sub(l,s),Yt),l),c1:i.add(i.mul(i.sub(y,o),Yt),y),c2:i.add(i.mul(i.sub(w,c),Yt),w)}),c1:r.create({c0:i.add(i.mul(i.add(_,a),Yt),_),c1:i.add(i.mul(i.add(p,u),Yt),p),c2:i.add(i.mul(i.add(g,f),Yt),g)})}}_cyclotomicExp(t,n){let r=this.ONE;for(let i=this.X_LEN-1;i>=0;i--)r=this._cyclotomicSquare(r),P3(n,i)&&(r=this.mul(r,t));return r}}function lT(e){const t=ai(e.ORDER),n=new aT(t,e),r=new uT(n),i=new fT(r,e);return{Fp:t,Fp2:n,Fp6:r,Fp12:i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const qt=BigInt(0),ma=BigInt(1),An=BigInt(2),tu=BigInt(3),Oo=BigInt(4),zr=BigInt("0xd201000000010000"),hT=vo(zr),$i={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:qt,b:Oo,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},dT=ai($i.n,{modFromBytes:!0,isLE:!0}),{Fp:me,Fp2:Pe,Fp6:pT,Fp12:Re}=lT({ORDER:$i.p,X_LEN:hT,FP2_NONRESIDUE:[ma,ma],Fp2mulByB:({c0:e,c1:t})=>{const n=me.mul(e,Oo),r=me.mul(t,Oo);return{c0:me.sub(n,r),c1:me.add(n,r)}},Fp12finalExponentiate:e=>{const t=zr,n=Re.div(Re.frobeniusMap(e,6),e),r=Re.mul(Re.frobeniusMap(n,2),n),i=Re.conjugate(Re._cyclotomicExp(r,t)),s=Re.mul(Re.conjugate(Re._cyclotomicSquare(r)),i),o=Re.conjugate(Re._cyclotomicExp(s,t)),c=Re.conjugate(Re._cyclotomicExp(o,t)),a=Re.mul(Re.conjugate(Re._cyclotomicExp(c,t)),Re._cyclotomicSquare(i)),u=Re.conjugate(Re._cyclotomicExp(a,t)),f=Re.frobeniusMap(Re.mul(i,c),2),l=Re.frobeniusMap(Re.mul(o,r),3),p=Re.frobeniusMap(Re.mul(a,Re.conjugate(r)),1),y=Re.mul(Re.mul(u,Re.conjugate(s)),r);return Re.mul(Re.mul(Re.mul(f,l),p),y)}}),{G2psi:Ld,G2psi2:yT}=cT(me,Pe,Pe.div(Pe.ONE,Pe.NONRESIDUE)),ju=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:me.ORDER,m:2,k:128,expand:"xmd",hash:pn}),Ll={p:Pe.ORDER,n:$i.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:Pe.ZERO,b:Pe.fromBigTuple([Oo,Oo]),Gx:Pe.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:Pe.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},nu=sc(me.toBytes(qt),{infinity:!0,compressed:!0});function ru(e){e=e.slice();const t=e[0]&224,n=!!(t>>7&1),r=!!(t>>6&1),i=!!(t>>5&1);return e[0]&=31,{compressed:n,infinity:r,sort:i,value:e}}function sc(e,t){if(e[0]&224)throw new Error("setMask: non-empty mask");return t.compressed&&(e[0]|=128),t.infinity&&(e[0]|=64),t.sort&&(e[0]|=32),e}function gT(e,t,n){const{BYTES:r,ORDER:i}=me,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return nu.slice();const a=!!(c*An/i);return sc(Ot(o,r),{compressed:!0,sort:a})}else return s?Me(Uint8Array.of(64),new Uint8Array(2*r-1)):Me(Ot(o,r),Ot(c,r))}function Wu(e){e.assertValidity();const{BYTES:t,ORDER:n}=me,{x:r,y:i}=e.toAffine();if(e.is0())return nu.slice();const s=!!(i*An/n);return sc(Ot(r,t),{compressed:!0,sort:s})}function wT(e){const{compressed:t,infinity:n,sort:r,value:i}=ru(e),{BYTES:s,ORDER:o}=me;if(i.length===48&&t){const c=Yn(i),a=me.create(c&Gi(me.BITS));if(n){if(a!==qt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:qt,y:qt}}const u=me.add(me.pow(a,tu),me.create($i.b));let f=me.sqrt(u);if(!f)throw new Error("invalid G1 point: compressed point");return f*An/o!==BigInt(r)&&(f=me.neg(f)),{x:me.create(a),y:me.create(f)}}else if(i.length===96&&!t){const c=Yn(i.subarray(0,s)),a=Yn(i.subarray(s));if(n){if(c!==qt||a!==qt)throw new Error("G1: non-empty point at infinity");return iu.G1.Point.ZERO.toAffine()}return{x:me.create(c),y:me.create(a)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function jd(e){const{infinity:t,sort:n,value:r}=ru(en("signatureHex",e,48)),i=me.ORDER,s=iu.G1.Point,o=Yn(r);if(t)return s.ZERO;const c=me.create(o&Gi(me.BITS)),a=me.add(me.pow(c,tu),me.create($i.b));let u=me.sqrt(a);if(!u)throw new Error("invalid G1 point: compressed");const f=BigInt(n);u*An/i!==f&&(u=me.neg(u));const l=s.fromAffine({x:c,y:u});return l.assertValidity(),l}function mT(e,t,n){const{BYTES:r,ORDER:i}=me,s=t.is0(),{x:o,y:c}=t.toAffine();if(n){if(s)return Me(nu,Ot(qt,r));const a=!!(c.c1===qt?c.c0*An/i:c.c1*An/i);return Me(sc(Ot(o.c1,r),{compressed:!0,sort:a}),Ot(o.c0,r))}else{if(s)return Me(Uint8Array.of(64),new Uint8Array(4*r-1));const{re:a,im:u}=Pe.reim(o),{re:f,im:l}=Pe.reim(c);return Me(Ot(u,r),Ot(a,r),Ot(l,r),Ot(f,r))}}function Gu(e){e.assertValidity();const{BYTES:t}=me;if(e.is0())return Me(nu,Ot(qt,t));const{x:n,y:r}=e.toAffine(),{re:i,im:s}=Pe.reim(n),{re:o,im:c}=Pe.reim(r),u=!!((c>qt?c*An:o*An)/me.ORDER&ma),f=i;return Me(sc(Ot(s,t),{sort:u,compressed:!0}),Ot(f,t))}function bT(e){const{BYTES:t,ORDER:n}=me,{compressed:r,infinity:i,sort:s,value:o}=ru(e);if(!r&&!i&&s||!r&&i&&s||s&&i&&r)throw new Error("invalid encoding flag: "+(e[0]&224));const c=(a,u,f)=>Yn(a.slice(u,f));if(o.length===96&&r){if(i){if(o.reduce((g,w)=>g!==0?w+1:w,0)>0)throw new Error("invalid G2 point: compressed");return{x:Pe.ZERO,y:Pe.ZERO}}const a=c(o,0,t),u=c(o,t,2*t),f=Pe.create({c0:me.create(u),c1:me.create(a)}),l=Pe.add(Pe.pow(f,tu),Ll.b);let p=Pe.sqrt(l);const y=p.c1===qt?p.c0*An/n:p.c1*An/n?ma:qt;return p=s&&y>0?p:Pe.neg(p),{x:f,y:p}}else if(o.length===192&&!r){if(i){if(o.reduce((p,y)=>p!==0?y+1:y,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:Pe.ZERO,y:Pe.ZERO}}const a=c(o,0*t,1*t),u=c(o,1*t,2*t),f=c(o,2*t,3*t),l=c(o,3*t,4*t);return{x:Pe.fromBigTuple([u,a]),y:Pe.fromBigTuple([l,f])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function Wd(e){const{ORDER:t}=me,{infinity:n,sort:r,value:i}=ru(en("signatureHex",e)),s=iu.G2.Point,o=i.length/2;if(o!==48&&o!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");const c=Yn(i.slice(0,o)),a=Yn(i.slice(o));if(n)return s.ZERO;const u=me.create(c&Gi(me.BITS)),f=me.create(a),l=Pe.create({c0:f,c1:u}),p=Pe.add(Pe.pow(l,tu),Ll.b);let y=Pe.sqrt(p);if(!y)throw new Error("Failed to find a square root");const{re:g,im:w}=Pe.reim(y),E=BigInt(r),_=w>qt&&w*An/t!==E,S=w===qt&&g*An/t!==E;(_||S)&&(y=Pe.neg(y));const m=s.fromAffine({x:l,y});return m.assertValidity(),m}const iu=oT({fields:{Fp:me,Fp2:Pe,Fp6:pT,Fp12:Re,Fr:dT},G1:{...$i,Fp:me,htfDefaults:{...ju,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(e,t)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new e(me.mul(t.X,n),t.Y,t.Z);return t.multiplyUnsafe(zr).negate().multiplyUnsafe(zr).equals(r)},clearCofactor:(e,t)=>t.multiplyUnsafe(zr).add(t),mapToCurve:xT,fromBytes:wT,toBytes:gT,ShortSignature:{fromBytes(e){return Sn(e),jd(e)},fromHex(e){return jd(e)},toBytes(e){return Wu(e)},toRawBytes(e){return Wu(e)},toHex(e){return Qe(Wu(e))}}},G2:{...Ll,Fp:Pe,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...ju},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:AT,isTorsionFree:(e,t)=>t.multiplyUnsafe(zr).negate().equals(Ld(e,t)),clearCofactor:(e,t)=>{const n=zr;let r=t.multiplyUnsafe(n).negate(),i=Ld(e,t),s=t.double();return s=yT(e,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(t)},fromBytes:bT,toBytes:mT,Signature:{fromBytes(e){return Sn(e),Wd(e)},fromHex(e){return Wd(e)},toBytes(e){return Gu(e)},toRawBytes(e){return Gu(e)},toHex(e){return Qe(Gu(e))}}},params:{ateLoopSize:zr,r:$i.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:ju}),ET=j1(Pe,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(e=>e.map(t=>Pe.fromBigTuple(t.map(BigInt))))),_T=j1(me,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),ST=W1(me,{A:me.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:me.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:me.create(BigInt(11))}),TT=W1(Pe,{A:Pe.create({c0:me.create(qt),c1:me.create(BigInt(240))}),B:Pe.create({c0:me.create(BigInt(1012)),c1:me.create(BigInt(1012))}),Z:Pe.create({c0:me.create(BigInt(-2)),c1:me.create(BigInt(-1))})});function xT(e){const{x:t,y:n}=ST(me.create(e[0]));return _T(t,n)}function AT(e){const{x:t,y:n}=TT(Pe.fromBigTuple(e));return ET(t,n)}function vT(e,t,n){const r=typeof e=="string"?e:Qe(e),i=typeof t=="string"?t:Qe(t),s=typeof n=="string"?n:Qe(n);return iu.verifyShortSignature(i,s,r)}const BT=BigInt(1e6),G1=e=>xt(new ks(e)),jl=e=>{const n=G1(e)/BT;return new Date(Number(n))},Gd=60*1e3,IT=60,OT=24,PT=OT*IT,kT=5,NT=5,UT=30*PT;var Pt;(function(e){e[e.Empty=0]="Empty",e[e.Fork=1]="Fork",e[e.Labeled=2]="Labeled",e[e.Leaf=3]="Leaf",e[e.Pruned=4]="Pruned"})(Pt||(Pt={}));function RT(e,t){for(let n=0;n<e.length;n++)if(e[n]>t[n])return!0;return!1}class Ri{#t=!1;#e=void 0;static async create(t){const n=Ri.createUnverified(t);return await n.verify(),n}static createUnverified(t){return new Ri(t.certificate,t.rootKey,t.canisterId,t.blsVerify??vT,t.maxAgeInMinutes,t.disableTimeVerification,t.agent)}constructor(t,n,r,i,s=kT,o=!1,c){this._rootKey=n,this._canisterId=r,this._blsVerify=i,this._maxAgeInMinutes=s,this.#t=o,this.cert=Dn(t),c&&"getTimeDiffMsecs"in c&&"hasSyncedTime"in c&&"syncTime"in c&&(this.#e=c)}lookup_path(t){return oc(t,this.cert.tree)}lookup_subtree(t){return Wl(t,this.cert.tree)}async verify(){const t=await Kc(this.cert.tree),n=await this._checkDelegationAndGetKey(this.cert.delegation),r=this.cert.signature,i=HT(n),s=Me(oo("ic-state-root"),t),o=yn(this.lookup_path(["time"]));if(!o)throw lt.fromCode(new hs("Certificate does not contain a time"));if(!this.#t){const c=this.#e?.getTimeDiffMsecs()??0,a=this._maxAgeInMinutes*Gd,u=new Date,f=u.getTime()+c,l=f-a,p=f+NT*Gd,y=jl(o),g=y.getTime()<l,w=y.getTime()>p;if((g||w)&&this.#e&&!this.#e.hasSyncedTime())return await this.#e.syncTime(this._canisterId),await this.verify();if(g)throw bn.fromCode(new Eo(this._maxAgeInMinutes,y,u,c,"past"));if(w)throw this.#e?.hasSyncedTime()?rn.fromCode(new Un("System time has been synced with the IC network, but certificate is still too far in the future.")):bn.fromCode(new Eo(5,y,u,c,"future"))}try{if(!await this._blsVerify(i,r,s))throw bn.fromCode(new hs("Invalid signature"))}catch(c){throw bn.fromCode(new hs("Signature verification failed",c))}}async _checkDelegationAndGetKey(t){if(!t)return this._rootKey;const n=Ri.createUnverified({certificate:t.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#t,maxAgeInMinutes:UT,agent:this.#e});if(n.cert.delegation)throw lt.fromCode(new El);await n.verify();const r=t.subnet_id,i=$e.fromUint8Array(r);if(!X1({canisterId:this._canisterId,subnetId:i,tree:n.cert.tree}))throw bn.fromCode(new Xa(this._canisterId,i));const o=yn(n.lookup_path(["subnet",r,"public_key"]));if(!o)throw bn.fromCode(new _l(`Could not find subnet key for subnet ID ${i.toText()}`));return o}}const Gs=jo("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),CT=96;function HT(e){const t=Gs.byteLength+CT;if(e.byteLength!==t)throw lt.fromCode(new Ya(t,e.byteLength));const n=e.slice(0,Gs.byteLength);if(!Qa(n,Gs))throw lt.fromCode(new Sl(Gs,n));return e.slice(Gs.byteLength)}function yn(e){if(e.status===En.Found&&e.value instanceof Uint8Array)return e.value}async function Kc(e){switch(e[0]){case Pt.Empty:return pn(oo("ic-hashtree-empty"));case Pt.Pruned:return e[1];case Pt.Leaf:return pn(Me(oo("ic-hashtree-leaf"),e[1]));case Pt.Labeled:return pn(Me(oo("ic-hashtree-labeled"),e[1],await Kc(e[2])));case Pt.Fork:return pn(Me(oo("ic-hashtree-fork"),await Kc(e[1]),await Kc(e[2])));default:throw ds}}function oo(e){const t=new Uint8Array([e.length]),n=new TextEncoder().encode(e);return Me(t,n)}function D1(e){return typeof e[0]=="string"?ut(e[0]):e[0]}var En;(function(e){e.Unknown="Unknown",e.Absent="Absent",e.Found="Found",e.Error="Error"})(En||(En={}));var ws;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found"})(ws||(ws={}));var nt;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found",e.Less="Less",e.Greater="Greater"})(nt||(nt={}));function oc(e,t){if(e.length===0)switch(t[0]){case Pt.Empty:return{status:En.Absent};case Pt.Leaf:{if(!t[1])throw rn.fromCode(new nc("Invalid tree structure for leaf"));if(t[1]instanceof Uint8Array)return{status:En.Found,value:t[1].slice(t[1].byteOffset,t[1].byteLength+t[1].byteOffset)};throw ds}case Pt.Pruned:return{status:En.Unknown};case Pt.Labeled:case Pt.Fork:return{status:En.Error};default:throw ds}const n=D1(e),r=fo(n,t);switch(r.status){case nt.Found:return oc(e.slice(1),r.value);case nt.Absent:case nt.Greater:case nt.Less:return{status:En.Absent};case nt.Unknown:return{status:En.Unknown};default:throw ds}}function Wl(e,t){if(e.length===0)return{status:ws.Found,value:t};const n=D1(e),r=fo(n,t);switch(r.status){case nt.Found:return Wl(e.slice(1),r.value);case nt.Unknown:return{status:ws.Unknown};case nt.Absent:case nt.Greater:case nt.Less:return{status:ws.Absent};default:throw ds}}function Vf(e){switch(e[0]){case Pt.Empty:return[];case Pt.Fork:return Vf(e[1]).concat(Vf(e[2]));default:return[e]}}function fo(e,t){switch(t[0]){case Pt.Labeled:return RT(e,t[1])?{status:nt.Greater}:Qa(e,t[1])?{status:nt.Found,value:t[2]}:{status:nt.Less};case Pt.Fork:{const n=fo(e,t[1]);switch(n.status){case nt.Greater:{const r=fo(e,t[2]);return r.status===nt.Less?{status:nt.Absent}:r}case nt.Unknown:{const r=fo(e,t[2]);return r.status===nt.Less?{status:nt.Unknown}:r}default:return n}}case Pt.Pruned:return{status:nt.Unknown};default:return{status:nt.Absent}}}function X1(e){const{canisterId:t,subnetId:n,tree:r}=e,i=oc(["subnet",n.toUint8Array(),"canister_ranges"],r);if(i.status!==En.Found)throw lt.fromCode(new xs(`Could not find canister ranges for subnet ${n.toText()}`,i.status));if(!(i.value instanceof Uint8Array))throw lt.fromCode(new za(`Could not find canister ranges for subnet ${n.toText()}`));return Dn(i.value).map(a=>[$e.fromUint8Array(a[0]),$e.fromUint8Array(a[1])]).some(a=>a[0].ltEq(t)&&a[1].gtEq(t))}const Dd=async e=>{const{agent:t,paths:n,disableCertificateTimeVerification:r=!1}=e,i=$e.from(e.canisterId),s=[...new Set(n)],o=new Map,c=s.map((a,u)=>{const f=MT(a,i);return(async()=>{try{if(t.rootKey===null)throw nn.fromCode(new Rs);const l=t.rootKey,p=await t.readState(i,{paths:[f]}),y=await Ri.create({certificate:p.certificate,rootKey:l,canisterId:i,disableTimeVerification:r,agent:t}),g=(_,S)=>{if(S==="subnet"){const m=FT(p.certificate,i,l);return{path:S,data:m}}else return{path:S,data:yn(_.lookup_path(f))}},{path:w,data:E}=g(y,s[u]);if(!E)console.warn(`Expected to find result for path ${w}, but instead found nothing.`),typeof w=="string"?o.set(w,null):o.set(w.key,null);else switch(w){case"time":{o.set(w,jl(E));break}case"controllers":{o.set(w,qT(E));break}case"module_hash":{o.set(w,Qe(E));break}case"subnet":{o.set(w,E);break}case"candid":{o.set(w,new TextDecoder().decode(E));break}default:if(typeof w!="string"&&"key"in w&&"path"in w)switch(w.decodeStrategy){case"raw":o.set(w.key,E);break;case"leb128":{o.set(w.key,G1(E));break}case"cbor":{o.set(w.key,Dn(E));break}case"hex":{o.set(w.key,Qe(E));break}case"utf-8":o.set(w.key,new TextDecoder().decode(E))}}}catch(l){if(l instanceof lr&&(l.hasCode(hs)||l.hasCode(Eo)))throw l;typeof a!="string"&&"key"in a&&"path"in a?o.set(a.key,null):o.set(a,null),console.group(),console.warn(`Expected to find result for path ${a}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(c),o},FT=(e,t,n)=>{if(!t._isPrincipal)throw Ye.fromCode(new Un("Invalid canisterId"));const r=Dn(e),i=r.tree;let s=r.delegation,o;if(s&&s.subnet_id?o=$e.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof n<"u"?(o=$e.selfAuthenticating(new Uint8Array(n)),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}):(o=$e.selfAuthenticating($e.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:o.toUint8Array(),certificate:new Uint8Array(0)}),!X1({canisterId:t,subnetId:o,tree:i}))throw bn.fromCode(new Xa(t,o));const a=Wl(["subnet",s.subnet_id,"node"],i);if(a.status!==ws.Found)throw lt.fromCode(new xs("Node not found",a.status));if(a.value instanceof Uint8Array)throw rn.fromCode(new nc("Invalid node tree"));const u=Vf(a.value),f=new Map;return u.forEach(l=>{const p=$e.from(l[1]).toText(),y=oc(["public_key"],l[2]);if(y.status!==En.Found)throw lt.fromCode(new xs("Public key not found",y.status));const g=y.value;if(g.byteLength!==44)throw lt.fromCode(new Ya(44,g.byteLength));f.set(p,g)}),{subnetId:$e.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:f}},MT=(e,t)=>{const n=t.toUint8Array();switch(e){case"time":return[ut("time")];case"controllers":return[ut("canister"),n,ut("controllers")];case"module_hash":return[ut("canister"),n,ut("module_hash")];case"subnet":return[ut("subnet")];case"candid":return[ut("canister"),n,ut("metadata"),ut("candid:service")];default:if("key"in e&&"path"in e)if(typeof e.path=="string"||e.path instanceof Uint8Array){const r=e.path,i=typeof r=="string"?ut(r):r;return[ut("canister"),n,ut("metadata"),i]}else return e.path}throw rn.fromCode(new Un(`Error while encoding your path for canister status. Please ensure that your path ${e} was formatted correctly.`))},qT=e=>Dn(e).map(n=>$e.fromUint8Array(n));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const kr=BigInt(0),Tt=BigInt(1),Du=BigInt(2),VT=BigInt(8);function $T(e,t,n,r){const i=e.sqr(n),s=e.sqr(r),o=e.add(e.mul(t.a,i),s),c=e.add(e.ONE,e.mul(t.d,e.mul(i,s)));return e.eql(o,c)}function KT(e,t={}){const n=K1("edwards",e,t,t.FpFnLE),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o}=s;ic(t,{},{uvRatio:"function"});const c=Du<<BigInt(i.BYTES*8)-Tt,a=E=>r.create(E),u=t.uvRatio||((E,_)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,_))}}catch{return{isValid:!1,value:kr}}});if(!$T(r,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(E,_,S=!1){const m=S?Tt:kr;return Pd("coordinate "+E,_,m,c),_}function l(E){if(!(E instanceof g))throw new Error("ExtendedPoint expected")}const p=Bo((E,_)=>{const{X:S,Y:m,Z:T}=E,I=E.is0();_==null&&(_=I?VT:r.inv(T));const A=a(S*_),U=a(m*_),M=r.mul(T,_);if(I)return{x:kr,y:Tt};if(M!==Tt)throw new Error("invZ was invalid");return{x:A,y:U}}),y=Bo(E=>{const{a:_,d:S}=s;if(E.is0())throw new Error("bad point: ZERO");const{X:m,Y:T,Z:I,T:A}=E,U=a(m*m),M=a(T*T),v=a(I*I),R=a(v*v),V=a(U*_),W=a(v*a(V+M)),H=a(R+a(S*a(U*M)));if(W!==H)throw new Error("bad point: equation left != right (1)");const K=a(m*T),N=a(I*A);if(K!==N)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(_,S,m,T){this.X=f("x",_),this.Y=f("y",S),this.Z=f("z",m,!0),this.T=f("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(_){if(_ instanceof g)throw new Error("extended point not allowed");const{x:S,y:m}=_||{};return f("x",S),f("y",m),new g(S,m,Tt,a(S*m))}static fromBytes(_,S=!1){const m=r.BYTES,{a:T,d:I}=s;_=Od(gs(_,m,"point")),xo(S,"zip215");const A=Od(_),U=_[m-1];A[m-1]=U&-129;const M=Ao(A),v=S?c:r.ORDER;Pd("point.y",M,kr,v);const R=a(M*M),V=a(R-Tt),W=a(I*R-T);let{isValid:H,value:K}=u(V,W);if(!H)throw new Error("bad point: invalid y coordinate");const N=(K&Tt)===Tt,L=(U&128)!==0;if(!S&&K===kr&&L)throw new Error("bad point: x=0 and x_0=1");return L!==N&&(K=a(-K)),g.fromAffine({x:K,y:M})}static fromHex(_,S=!1){return g.fromBytes(en("point",_),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,S=!0){return w.createCache(this,_),S||this.multiply(Du),this}assertValidity(){y(this)}equals(_){l(_);const{X:S,Y:m,Z:T}=this,{X:I,Y:A,Z:U}=_,M=a(S*U),v=a(I*T),R=a(m*U),V=a(A*T);return M===v&&R===V}is0(){return this.equals(g.ZERO)}negate(){return new g(a(-this.X),this.Y,this.Z,a(-this.T))}double(){const{a:_}=s,{X:S,Y:m,Z:T}=this,I=a(S*S),A=a(m*m),U=a(Du*a(T*T)),M=a(_*I),v=S+m,R=a(a(v*v)-I-A),V=M+A,W=V-U,H=M-A,K=a(R*W),N=a(V*H),L=a(R*H),F=a(W*V);return new g(K,N,F,L)}add(_){l(_);const{a:S,d:m}=s,{X:T,Y:I,Z:A,T:U}=this,{X:M,Y:v,Z:R,T:V}=_,W=a(T*M),H=a(I*v),K=a(U*m*V),N=a(A*R),L=a((T+I)*(M+v)-W-H),F=N-K,x=N+K,O=a(H-S*W),q=a(L*F),P=a(x*O),$=a(L*O),G=a(F*x);return new g(q,P,G,$)}subtract(_){return this.add(_.negate())}multiply(_){if(!i.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:S,f:m}=w.cached(this,_,T=>dr(g,T));return dr(g,[S,m])[0]}multiplyUnsafe(_,S=g.ZERO){if(!i.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===kr?g.ZERO:this.is0()||_===Tt?this:w.unsafe(this,_,m=>dr(g,m),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return w.unsafe(this,s.n).is0()}toAffine(_){return p(this,_)}clearCofactor(){return o===Tt?this:this.multiplyUnsafe(o)}toBytes(){const{x:_,y:S}=this.toAffine(),m=r.toBytes(S);return m[m.length-1]|=_&Tt?128:0,m}toHex(){return Qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(_){return dr(g,_)}static msm(_,S){return $1(g,i,_,S)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}g.BASE=new g(s.Gx,s.Gy,Tt,a(s.Gx*s.Gy)),g.ZERO=new g(kr,Tt,Tt,kr),g.Fp=r,g.Fn=i;const w=new V1(g,i.BITS);return g.BASE.precompute(8),g}function LT(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');ic(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=n,{BASE:i,Fp:s,Fn:o}=e,c=n.randomBytes||gy,a=n.adjustScalarBytes||(v=>v),u=n.domain||((v,R,V)=>{if(xo(V,"phflag"),R.length||V)throw new Error("Contexts/pre-hash are not supported");return v});function f(v){return o.create(Ao(v))}function l(v){const R=m.secretKey;v=en("private key",v,R);const V=en("hashed private key",t(v),2*R),W=a(V.slice(0,R)),H=V.slice(R,2*R),K=f(W);return{head:W,prefix:H,scalar:K}}function p(v){const{head:R,prefix:V,scalar:W}=l(v),H=i.multiply(W),K=H.toBytes();return{head:R,prefix:V,scalar:W,point:H,pointBytes:K}}function y(v){return p(v).pointBytes}function g(v=Uint8Array.of(),...R){const V=Me(...R);return f(t(u(V,en("context",v),!!r)))}function w(v,R,V={}){v=en("message",v),r&&(v=r(v));const{prefix:W,scalar:H,pointBytes:K}=p(R),N=g(V.context,W,v),L=i.multiply(N).toBytes(),F=g(V.context,L,K,v),x=o.create(N+F*H);if(!o.isValid(x))throw new Error("sign failed: invalid s");const O=Me(L,o.toBytes(x));return gs(O,m.signature,"result")}const E={zip215:!0};function _(v,R,V,W=E){const{context:H,zip215:K}=W,N=m.signature;v=en("signature",v,N),R=en("message",R),V=en("publicKey",V,m.publicKey),K!==void 0&&xo(K,"zip215"),r&&(R=r(R));const L=N/2,F=v.subarray(0,L),x=Ao(v.subarray(L,N));let O,q,P;try{O=e.fromBytes(V,K),q=e.fromBytes(F,K),P=i.multiplyUnsafe(x)}catch{return!1}if(!K&&O.isSmallOrder())return!1;const $=g(H,q.toBytes(),O.toBytes(),R);return q.add(O.multiplyUnsafe($)).subtract(P).clearCofactor().is0()}const S=s.BYTES,m={secretKey:S,publicKey:S,signature:2*S,seed:S};function T(v=c(m.seed)){return gs(v,m.seed,"seed")}function I(v){const R=M.randomSecretKey(v);return{secretKey:R,publicKey:y(R)}}function A(v){return Lo(v)&&v.length===o.BYTES}function U(v,R){try{return!!e.fromBytes(v,R)}catch{return!1}}const M={getExtendedPublicKey:p,randomSecretKey:T,isValidSecretKey:A,isValidPublicKey:U,toMontgomery(v){const{y:R}=e.fromBytes(v),V=m.publicKey,W=V===32;if(!W&&V!==57)throw new Error("only defined for 25519 and 448");const H=W?s.div(Tt+R,Tt-R):s.div(R-Tt,R+Tt);return s.toBytes(H)},toMontgomerySecret(v){const R=m.secretKey;gs(v,R);const V=t(v.subarray(0,R));return a(V).subarray(0,R)},randomPrivateKey:T,precompute(v=8,R=e.BASE){return R.precompute(v,!1)}};return Object.freeze({keygen:I,getPublicKey:y,sign:w,verify:_,utils:M,Point:e,lengths:m})}function jT(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=ai(t.n,e.nBitLength,!0),i={Fp:n,Fn:r,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:i,hash:e.hash,eddsaOpts:s}}function WT(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function GT(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:i}=jT(e),s=KT(t,n),o=LT(s,r,i);return WT(e,o)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const DT=BigInt(1),Xd=BigInt(2);BigInt(3);const XT=BigInt(5),zT=BigInt(8),Gl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),z1={p:Gl,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:zT,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function YT(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Gl,c=e*e%s*e%s,a=jn(c,Xd,s)*c%s,u=jn(a,DT,s)*e%s,f=jn(u,XT,s)*u%s,l=jn(f,t,s)*f%s,p=jn(l,n,s)*l%s,y=jn(p,r,s)*p%s,g=jn(y,i,s)*y%s,w=jn(g,i,s)*y%s,E=jn(w,t,s)*f%s;return{pow_p_5_8:jn(E,Xd,s)*e%s,b2:c}}function ZT(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const zd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function JT(e,t){const n=Gl,r=dt(t*t*t,n),i=dt(r*r*t,n),s=YT(e*i).pow_p_5_8;let o=dt(e*r*s,n);const c=dt(t*o*o,n),a=o,u=dt(o*zd,n),f=c===e,l=c===dt(-e,n),p=c===dt(-e*zd,n);return f&&(o=a),(l||p)&&(o=u),F3(o,n)&&(o=dt(-o,n)),{isValid:f||l,value:o}}const QT=ai(z1.p,{isLE:!0}),e8={...z1,Fp:QT,hash:Jm,adjustScalarBytes:ZT,uvRatio:JT},t8=GT(e8);var Yd,Zd,Bt,ms;class n8{constructor(t={}){Qt(this,Bt);Qt(this,ms);this[Yd]=this.entries.bind(this),this[Zd]="ExpirableMap";const{source:n=[],expirationTime:r=600*1e3}=t,i=Date.now();jt(this,Bt,new Map([...n].map(([s,o])=>[s,{value:o,timestamp:i}]))),jt(this,ms,r)}prune(){const t=Date.now();for(const[n,r]of Ue(this,Bt).entries())t-r.timestamp>Ue(this,ms)&&Ue(this,Bt).delete(n);return this}set(t,n){this.prune();const r={value:n,timestamp:Date.now()};return Ue(this,Bt).set(t,r),this}get(t){const n=Ue(this,Bt).get(t);if(n!==void 0){if(Date.now()-n.timestamp>Ue(this,ms)){Ue(this,Bt).delete(t);return}return n.value}}clear(){Ue(this,Bt).clear()}entries(){const t=Ue(this,Bt).entries();return function*(){for(const[r,i]of t)yield[r,i.value]}()}values(){const t=Ue(this,Bt).values();return function*(){for(const r of t)yield r.value}()}keys(){return Ue(this,Bt).keys()}forEach(t,n){for(const[r,i]of Ue(this,Bt).entries())t.call(n,i.value,r,this)}has(t){return Ue(this,Bt).has(t)}delete(t){return Ue(this,Bt).delete(t)}get size(){return Ue(this,Bt).size}}Bt=new WeakMap,ms=new WeakMap,Yd=Symbol.iterator,Zd=Symbol.toStringTag;const Jd=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw Ye.fromCode(new Za("Length too long (> 4 bytes)"))},Qd=(e,t,n)=>{if(n<=127)return e[t]=n,1;if(n<=255)return e[t]=129,e[t+1]=n,2;if(n<=65535)return e[t]=130,e[t+1]=n>>8,e[t+2]=n,3;if(n<=16777215)return e[t]=131,e[t+1]=n>>16,e[t+2]=n>>8,e[t+3]=n,4;throw Ye.fromCode(new Za("Length too long (> 4 bytes)"))},$f=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw Ye.fromCode(new Sr("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw Ye.fromCode(new Sr("Length too long (> 4 bytes)"))},r8=(e,t)=>{const n=$f(e,t);if(n===1)return e[t];if(n===2)return e[t+1];if(n===3)return(e[t+1]<<8)+e[t+2];if(n===4)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw Ye.fromCode(new Sr("Length too long (> 4 bytes)"))};Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]);const e0=Uint8Array.from([48,5,6,3,43,101,112]);Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);Uint8Array.from([48,29,6,13,43,6,1,4,1,130,220,124,5,3,1,2,1,6,12,43,6,1,4,1,130,220,124,5,3,2,1]);function i8(e,t){const n=2+Jd(e.byteLength+1),r=t.byteLength+n+e.byteLength;let i=0;const s=new Uint8Array(1+Jd(r)+r);return s[i++]=48,i+=Qd(s,i,r),s.set(t,i),i+=t.byteLength,s[i++]=3,i+=Qd(s,i,e.byteLength+1),s[i++]=0,s.set(new Uint8Array(e),i),s}const s8=(e,t)=>{let n=0;const r=(c,a)=>{if(i[n++]!==c)throw Ye.fromCode(new Sr(`Expected ${a} at offset ${n}`))},i=new Uint8Array(e);if(r(48,"sequence"),n+=$f(i,n),!Qa(i.slice(n,n+t.byteLength),t))throw Ye.fromCode(new Sr("Not the expected OID."));n+=t.byteLength,r(3,"bit string");const s=r8(i,n)-1;n+=$f(i,n),r(0,"0 padding");const o=i.slice(n);if(s!==o.length)throw Ye.fromCode(new Tl(s,o.length));return o};var ko,No;const vi=class vi{constructor(t){Qt(this,ko);Qt(this,No);if(t.byteLength!==vi.RAW_KEY_LENGTH)throw Ye.fromCode(new Sr("An Ed25519 public key must be exactly 32 bytes long"));jt(this,ko,t),jt(this,No,vi.derEncode(t))}static from(t){return this.fromDer(t.toDer())}static fromRaw(t){return new vi(t)}static fromDer(t){return new vi(this.derDecode(t))}static derEncode(t){return i8(t,e0)}static derDecode(t){const n=s8(t,e0);if(n.length!==this.RAW_KEY_LENGTH)throw Ye.fromCode(new Sr("An Ed25519 public key must be exactly 32 bytes long"));return n}get rawKey(){return Ue(this,ko)}get derKey(){return Ue(this,No)}toDer(){return this.derKey}toRaw(){return this.rawKey}};ko=new WeakMap,No=new WeakMap,vi.RAW_KEY_LENGTH=32;let Kf=vi;class o8{constructor(){this.observers=[]}subscribe(t){this.observers.push(t)}unsubscribe(t){this.observers=this.observers.filter(n=>n!==t)}notify(t,...n){this.observers.forEach(r=>r(t,...n))}}class c8 extends o8{constructor(){super()}print(t,...n){this.notify({message:t,level:"info"},...n)}warn(t,...n){this.notify({message:t,level:"warn"},...n)}error(t,n,...r){this.notify({message:t,level:"error",error:n},...r)}}const t0=.5,n0=1.5,r0=500,i0=6e4,s0=9e5,o0=10;var Pn,Uo,Ro,Co,Ho,Fo,Mo,qo,bs;const Ba=class Ba{constructor(t=Ba.default){Qt(this,Pn);Qt(this,Uo);Qt(this,Ro);Qt(this,Co);Qt(this,Ho);Qt(this,Fo);Qt(this,Mo);Qt(this,qo);Qt(this,bs,0);const{initialInterval:n=r0,randomizationFactor:r=t0,multiplier:i=n0,maxInterval:s=i0,maxElapsedTime:o=s0,maxIterations:c=o0,date:a=Date}=t;jt(this,Pn,n),jt(this,Uo,r),jt(this,Ro,i),jt(this,Co,s),jt(this,qo,a),jt(this,Ho,a.now()),jt(this,Fo,o),jt(this,Mo,c)}get ellapsedTimeInMsec(){return Ue(this,qo).now()-Ue(this,Ho)}get currentInterval(){return Ue(this,Pn)}get count(){return Ue(this,bs)}get randomValueFromInterval(){const t=Ue(this,Uo)*Ue(this,Pn),n=Ue(this,Pn)-t,r=Ue(this,Pn)+t;return Math.random()*(r-n)+n}incrementCurrentInterval(){return jt(this,Pn,Math.min(Ue(this,Pn)*Ue(this,Ro),Ue(this,Co))),sh(this,bs)._++,Ue(this,Pn)}next(){return this.ellapsedTimeInMsec>=Ue(this,Fo)||Ue(this,bs)>=Ue(this,Mo)?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};Pn=new WeakMap,Uo=new WeakMap,Ro=new WeakMap,Co=new WeakMap,Ho=new WeakMap,Fo=new WeakMap,Mo=new WeakMap,qo=new WeakMap,bs=new WeakMap,Ba.default={initialInterval:r0,randomizationFactor:t0,multiplier:n0,maxInterval:i0,maxElapsedTime:s0,maxIterations:o0,date:Date};let Lf=Ba;var fr;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(fr||(fr={}));const jf=60*1e3,a8=1e6,u8=0,f8="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",l8="ic0.app",h8=".ic0.app",d8="icp0.io",p8=".icp0.io",y8="icp-api.io",g8=".icp-api.io",Xu=200,w8=202,m8=404;function b8(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw nn.fromCode(new uo("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof globalThis<"u")if(globalThis.fetch)e=globalThis.fetch.bind(globalThis);else throw nn.fromCode(new uo("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(e=self.fetch.bind(self));if(e)return e;throw nn.fromCode(new uo("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function E8(e){let t;if(e!==void 0)!e.match(/^[a-z]+:/)&&typeof window<"u"?t=new URL(window.location.protocol+"//"+e):t=new URL(e);else{const n=["ic0.app","icp0.io","127.0.0.1","localhost"],r=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,s=i?.hostname;let o;s&&typeof s=="string"&&(r.some(c=>s.endsWith(c))?o=s:o=n.find(c=>s.endsWith(c))),i&&o?t=new URL(`${i.protocol}//${o}${i.port?":"+i.port:""}`):t=new URL("https://icp-api.io")}return t.toString()}class yr{#t;#e;#i;#g;#a;#m;#n;#s;#w;#b;#r;#c;#u;#o;get#T(){return this.#o*jf}#f;#l;#h;#d;constructor(t={}){this.#t=null,this.#e=!1,this.#i=u8,this.#g=!1,this.#a=null,this.#m=!1,this._isAgent=!0,this.config={},this.log=new c8,this.#f=[],this.#l=[],this.#h=new n8({expirationTime:5*jf}),this.#d=!0,this.#_=(i,s)=>{if(this.#d===!1)return i;const{status:o,signatures:c=[],requestId:a}=i;for(const u of c){const{timestamp:f,identity:l}=u,p=$e.fromUint8Array(l).toText();let y;if(o===Ts.Replied){const{reply:S}=i;y=da({status:o,reply:S,timestamp:BigInt(f),request_id:a})}else if(o===Ts.Rejected){const{reject_code:S,reject_message:m,error_code:T}=i;y=da({status:o,reject_code:S,reject_message:m,error_code:T,timestamp:BigInt(f),request_id:a})}else throw rn.fromCode(new Un(`Unknown status: ${o}`));const g=Me(JS,y),w=s.nodeKeys.get(p);if(!w)throw lt.fromCode(new Rl);const E=Kf.fromDer(w).rawKey;if(t8.verify(u.signature,g,E))return i;throw bn.fromCode(new Cl(p))}return i},this.config=t,this.#s=t.fetch||b8()||fetch.bind(globalThis),this.#w=t.fetchOptions,this.#b=t.callOptions,this.#e=t.shouldFetchRootKey??!1,this.#m=t.shouldSyncTime??!1,t.rootKey?this.rootKey=t.rootKey:this.#e?this.rootKey=null:this.rootKey=jo(f8);const n=E8(t.host);this.host=new URL(n),t.verifyQuerySignatures!==void 0&&(this.#d=t.verifyQuerySignatures),this.#c=t.retryTimes??3;const r=()=>new Lf({maxIterations:this.#c});if(this.#u=t.backoffStrategy||r,this.host.hostname.endsWith(h8)?this.host.hostname=l8:this.host.hostname.endsWith(p8)?this.host.hostname=d8:this.host.hostname.endsWith(g8)&&(this.host.hostname=y8),t.credentials){const{name:i,password:s}=t.credentials;this.#r=`${i}${s?":"+s:""}`}if(this.#n=Promise.resolve(t.identity||new vd),t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes>5)throw Ye.fromCode(new os("The maximum ingress expiry time is 5 minutes.",t.ingressExpiryInMinutes));if(t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes<=0)throw Ye.fromCode(new os("Ingress expiry time must be greater than 0.",t.ingressExpiryInMinutes));this.#o=t.ingressExpiryInMinutes||5,this.addTransform("update",Id(Mf)),t.useQueryNonces&&this.addTransform("query",Id(Mf)),t.logToConsole&&this.log.subscribe(i=>{i.level==="error"?console.error(i.message):i.level==="warn"?console.warn(i.message):console.log(i.message)})}static createSync(t={}){return new this({...t})}static async create(t={}){const n=yr.createSync(t);return await n.#y(),n}static async from(t){try{return"config"in t?await yr.create(t.config):await yr.create({fetch:t._fetch,fetchOptions:t._fetchOptions,callOptions:t._callOptions,host:t._host.toString(),identity:t._identity??void 0})}catch{throw Ye.fromCode(new kl)}}isLocal(){const t=this.host.hostname;return t==="127.0.0.1"||t.endsWith("127.0.0.1")}addTransform(t,n,r=n.priority||0){if(t==="update"){const i=this.#l.findIndex(s=>(s.priority||0)<r);this.#l.splice(i>=0?i:this.#l.length,0,Object.assign(n,{priority:r}))}else if(t==="query"){const i=this.#f.findIndex(s=>(s.priority||0)<r);this.#f.splice(i>=0?i:this.#f.length,0,Object.assign(n,{priority:r}))}}async getPrincipal(){if(!this.#n)throw nn.fromCode(new Ai);return(await this.#n).getPrincipal()}async call(t,n,r){const i=n.callSync??!0,s=await(r??this.#n);if(!s)throw nn.fromCode(new Ai);const o=$e.from(t),c=n.effectiveCanisterId?$e.from(n.effectiveCanisterId):o;await this.#y(c);const a=s.getPrincipal(),u=zu(this.#o,this.#i),f={request_type:Ff.Call,canister_id:o,method_name:n.methodName,arg:n.arg,sender:a,ingress_expiry:u};let l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Ii.Call,body:f}),p;n?.nonce?p=y(n.nonce):l.body.nonce?p=y(l.body.nonce):p=void 0,f.nonce=p;function y(_){return Object.assign(_,{__nonce__:void 0})}l=await s.transformRequest(l);const g=Hu(l.body),w=this.#u(),E=Ru(f);try{const m=i?()=>(this.log.print(`fetching "/api/v3/canister/${c.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v3/canister/${c.toText()}/call`,this.host),{...this.#b,...l.request,body:g})):()=>(this.log.print(`fetching "/api/v2/canister/${c.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v2/canister/${c.toText()}/call`,this.host),{...this.#b,...l.request,body:g})),{responseBodyBytes:T,...I}=await this.#p({requestFn:m,backoff:w,tries:0}),A=T.byteLength>0?Dn(T):null;return{requestId:E,response:{...I,body:A},requestDetails:f}}catch(_){let S;if(_ instanceof lr){if(_.hasCode(aa))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(t,{...n,callSync:!1},r);if(_.hasCode(os)&&!this.#g)return await this.syncTime(o),this.call(o,n,r);_.code.requestContext={requestId:E,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},S=_}else S=rn.fromCode(new Un(_));throw this.log.error(`Error while making call: ${S.message}`,S),S}}async#E(t){const{ecid:n,transformedRequest:r,body:i,requestId:s,backoff:o,tries:c}=t,a=c===0?0:o.next();if(this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with tries:`,{tries:c,backoff:o,delay:a}),a===null)throw rn.fromCode(new _o(`Backoff strategy exhausted after ${c} attempts.`,s));a>0&&await new Promise(y=>setTimeout(y,a));let u;try{this.log.print(`fetching "/api/v2/canister/${n.toString()}/query" with request:`,r);const y=await this.#s(""+new URL(`/api/v2/canister/${n.toString()}/query`,this.host),{...this.#w,...r.request,body:i});if(y.status===Xu)u={...Dn(ha(await y.arrayBuffer())),httpDetails:{ok:y.ok,status:y.status,statusText:y.statusText,headers:Fu(y.headers)},requestId:s};else throw lt.fromCode(new ca(y.status,y.statusText,Fu(y.headers),await y.text()))}catch(y){if(c<this.#c)return this.log.warn(`Caught exception while attempting to make query:
|
|
67
67
|
${y}
|
|
68
|
-
Retrying query.`),await this.#E({...t,tries:c+1});throw y instanceof lr?y:
|
|
68
|
+
Retrying query.`),await this.#E({...t,tries:c+1});throw y instanceof lr?y:oa.fromCode(new ua(y))}if(!this.#d)return u;const f=u.signatures?.[0]?.timestamp;if(!f)throw lt.fromCode(new Nl("Timestamp not found in query response. This suggests a malformed or malicious response."));const l=Number(BigInt(f)/BigInt(a8));if(Date.now()+this.#i-l>this.#T){if(c<this.#c)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:s,signatureTimestampMs:l}),await this.#E({...t,tries:c+1});throw bn.fromCode(new vl(this.#o,s,c))}return u}async#p(t){const{requestFn:n,backoff:r,tries:i}=t,s=i===0?0:r.next();if(s===null)throw lt.fromCode(new _o(`Retry strategy exhausted after ${i} attempts.`));s>0&&await new Promise(f=>setTimeout(f,s));let o,c=new Uint8Array;try{o=await n(),o.status===Xu&&(c=ha(await o.clone().arrayBuffer()))}catch(f){if(i<this.#c)return this.log.warn(`Caught exception while attempting to make request:
|
|
69
69
|
${f}
|
|
70
|
-
Retrying request.`),await this.#p({requestFn:n,backoff:r,tries:i+1});throw sa.fromCode(new aa(f))}const a=Hu(o.headers);if(o.status===Du||o.status===w8)return{ok:o.ok,status:o.status,statusText:o.statusText,responseBodyBytes:c,headers:a};const u=await o.text();if(o.status===m8&&o.url.includes("api/v3"))throw lt.fromCode(new ca);if(u.startsWith("Invalid request expiry: "))throw Ye.fromCode(new ss(u,this.#o));if(i<this.#c)return await this.#p({requestFn:n,backoff:r,tries:i+1});throw lt.fromCode(new oa(o.status,o.statusText,a,u))}async query(t,n,r){const i=this.#u(),s=n.effectiveCanisterId?$e.from(n.effectiveCanisterId):$e.from(t);await this.#y(s),this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${t.toString()}`);let o;const c=await(r??this.#n);if(!c)throw nn.fromCode(new xi);const a=$e.from(t),u=c.getPrincipal(),f=Xu(this.#o,this.#i),l={request_type:To.Query,canister_id:a,method_name:n.methodName,arg:n.arg,sender:u,ingress_expiry:f},p=Uu(l);o=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Bi.Query,body:l}),o=await c.transformRequest(o);const y=Cu(o.body),g={canister:a.toText(),ecid:s,transformedRequest:o,body:y,requestId:p,backoff:i,tries:0},w=async()=>{const _=await this.#E(g);return{requestDetails:l,..._}},E=async()=>{const _=this.#h.get(s.toString());if(_)return _;await this.fetchSubnetKeys(s.toString());const S=this.#h.get(s.toString());if(!S)throw bn.fromCode(new Nl);return S};try{if(!this.#d)return await w();const[_,S]=await Promise.all([w(),E()]);try{return this.#_(_,S)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#h.delete(s.toString());const m=await E();return this.#_(_,m)}}catch(_){let S;throw _ instanceof lr?(_.code.requestContext={requestId:p,senderPubKey:o.body.sender_pubkey,senderSignature:o.body.sender_sig,ingressExpiry:o.body.content.ingress_expiry},S=_):S=rn.fromCode(new Un(_)),this.log.error(`Error while making query: ${S.message}`,S),S}}#_;async createReadStateRequest(t,n){await this.#y();const r=await(n??this.#n);if(!r)throw nn.fromCode(new xi);const i=r.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Bi.ReadState,body:{request_type:To.ReadState,paths:t.paths,sender:i,ingress_expiry:Xu(this.#o,this.#i)}});return r.transformRequest(s)}async readState(t,n,r,i){await this.#S();const s=$e.from(t);function o(f){for(const l of f.paths){const[p,y]=l,g=new TextEncoder().encode("request_status");if(Ja(p,g))return y}}let c,a;if(i)c=i,a=Uu(c);else{a=o(n);const f=await this.#n;if(!f)throw nn.fromCode(new xi);c=await this.createReadStateRequest(n,f)}this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,c);const u=this.#u();try{const{responseBodyBytes:f}=await this.#p({requestFn:()=>this.#s(""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),{...this.#w,...c.request,body:Cu(c.body)}),backoff:u,tries:0}),l=Dn(f);return this.log.print("Read state response:",l),l}catch(f){let l;throw f instanceof lr?(f.code.requestContext={requestId:a,senderPubKey:c.body.sender_pubkey,senderSignature:c.body.sender_sig,ingressExpiry:c.body.content.ingress_expiry},l=f):l=rn.fromCode(new Un(f)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(t){let n;if(t.certificate){const r=Dn(t.certificate);if(r&&"tree"in r)n=r.tree;else throw lt.fromCode(new tc("Could not decode time from response"));const i=sc(["time"],n);if(i.status!==En.Found)throw lt.fromCode(new Ts("Time was not found in the response or was not in its expected format.",i.status));if(!(i.value instanceof Uint8Array)&&!ArrayBuffer.isView(i))throw lt.fromCode(new Xa("Time was not in its expected format."));const s=Ll(i.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(t){this.#a=this.#a??(async()=>{await this.#S();const n=Date.now();try{t||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");const r=t??$e.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),i=yr.createSync({identity:new vd,host:this.host.toString(),fetch:this.#s,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),o=(await Promise.all(Array(3).fill(null).map(async()=>{const a=(await Dd({canisterId:r,agent:i,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(a instanceof Date)return a.getTime()},[]))).reduce((c,a)=>typeof a=="number"&&a>c?a:c,0);o>0&&(this.#i=o-n,this.#g=!0,this.log.notify({message:`Syncing time: offset of ${this.#i}`,level:"info"}))}catch(r){const i=r instanceof lr?r:rn.fromCode(new Un(r));throw this.log.error("Caught exception while attempting to sync time",i),i}})(),await this.#a.finally(()=>{this.#a=null})}async status(){const t=this.#r?{Authorization:"Basic "+btoa(this.#r)}:{};this.log.print('fetching "/api/v2/status"');const n=this.#u(),{responseBodyBytes:r}=await this.#p({backoff:n,requestFn:()=>this.#s(""+new URL("/api/v2/status",this.host),{headers:t,...this.#w}),tries:0});return Dn(r)}async fetchRootKey(){return this.#t=this.#t??(async()=>{const t=await this.status();return this.rootKey=t.root_key,this.rootKey})(),await this.#t.finally(()=>{this.#t=null})}async#y(t){await Promise.all([this.#S(),this.#x(t)])}async#S(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#e)await this.fetchRootKey();else throw nn.fromCode(new Us(this.#e))}async#x(t){this.#m&&!this.hasSyncedTime()&&await this.syncTime(t)}invalidateIdentity(){this.#n=null}replaceIdentity(t){this.#n=Promise.resolve(t)}async fetchSubnetKeys(t){const n=$e.from(t);await this.#y(n);const i=(await Dd({canisterId:n,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return this.#h.set(n.toText(),i),i}_transform(t){let n=Promise.resolve(t);if(t.endpoint===Bi.Call)for(const r of this.#l)n=n.then(i=>r(i).then(s=>s||i));else for(const r of this.#f)n=n.then(i=>r(i).then(s=>s||i));return n}getTimeDiffMsecs(){return this.#i}hasSyncedTime(){return this.#g}}function Xu(e,t){const n=e*Lf;return ps.fromDeltaInMilliseconds(n,t)}const _8=300*1e3;function S8(){return B8(x8(T8(),1e3),v8(1e3,1.2),A8(_8))}function T8(){let e=!0;return async()=>e?(e=!1,!0):!1}function x8(e,t){return async(n,r,i)=>{if(await e(n,r,i))return new Promise(s=>setTimeout(s,t))}}function A8(e){const t=Date.now()+e;return async(n,r,i)=>{if(Date.now()>t)throw lt.fromCode(new _o(`Request timed out after ${e} msec`,r,i))}}function v8(e,t){let n=e;return()=>new Promise(r=>setTimeout(()=>{n*=t,r()},n))}function B8(...e){return async(t,n,r)=>{for(const i of e)await i(t,n,r)}}const I8={preSignReadStateRequest:!1};function Y1(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function zu(e,t){return e!==null&&typeof e=="object"&&Y1(e,t)}function O8(e,t){return Y1(e,t)&&typeof e[t]=="function"}function c0(e){return zu(e,"body")&&zu(e.body,"content")&&e.body.content.request_type===To.ReadState&&zu(e.body.content,"ingress_expiry")&&typeof e.body.content.ingress_expiry=="object"&&e.body.content.ingress_expiry!==null&&O8(e.body.content.ingress_expiry,"toHash")}async function Z1(e,t,n,r={}){const i=[ut("request_status"),n];let s,o;if(r.preSignReadStateRequest??!1?(o=await P8({paths:[i],agent:e,pollingOptions:r}),s=await e.readState(t,{paths:[i]},void 0,o)):s=await e.readState(t,{paths:[i]}),e.rootKey==null)throw nn.fromCode(new Us);const a=await Ui.create({certificate:s.certificate,rootKey:e.rootKey,canisterId:t,blsVerify:r.blsVerify,agent:e}),u=yn(a.lookup_path([...i,ut("status")]));let f;switch(typeof u>"u"?f=fr.Unknown:f=new TextDecoder().decode(u),f){case fr.Replied:return{reply:yn(a.lookup_path([...i,"reply"])),certificate:a};case fr.Received:case fr.Unknown:case fr.Processing:{const l=r.strategy??S8();return await l(t,n,f),Z1(e,t,n,{...r,strategy:l,request:o})}case fr.Rejected:{const l=new Uint8Array(yn(a.lookup_path([...i,"reject_code"])))[0],p=new TextDecoder().decode(yn(a.lookup_path([...i,"reject_message"]))),y=yn(a.lookup_path([...i,"error_code"])),g=y?new TextDecoder().decode(y):void 0;throw fs.fromCode(new Za(n,l,p,g))}case fr.Done:throw rn.fromCode(new Il(n))}throw hs}async function P8(e){const{paths:t,agent:n,pollingOptions:r}=e;if(r.request&&c0(r.request))return r.request;const i=await n.createReadStateRequest?.({paths:t},void 0);if(!c0(i))throw Ye.fromCode(new Cl(i));return i}const mn=Symbol.for("ic-agent-metadata");class ma{static agentOf(t){return t[mn].config.agent}static interfaceOf(t){return t[mn].service}static canisterIdOf(t){return $e.from(t[mn].config.canisterId)}static createActorClass(t,n){const r=t({IDL:m_});class i extends ma{constructor(o){if(!o.canisterId)throw Ye.fromCode(new ua(o.canisterId));const c=typeof o.canisterId=="string"?$e.fromText(o.canisterId):o.canisterId;super({config:{...J1,...o,canisterId:c},service:r});for(const[a,u]of r._fields)n?.httpDetails&&u.annotations.push(jf),n?.certificate&&u.annotations.push(Q1),this[a]=k8(this,a,u,o.blsVerify)}}return i}static createActor(t,n){if(!n.canisterId)throw Ye.fromCode(new ua(n.canisterId));return new(this.createActorClass(t))(n)}static createActorWithHttpDetails(t,n){return new(this.createActorClass(t,{httpDetails:!0}))(n)}static createActorWithExtendedDetails(t,n,r={httpDetails:!0,certificate:!0}){return new(this.createActorClass(t,r))(n)}constructor(t){this[mn]=Object.freeze(t)}}function Ji(e,t){const n=gg(e,t);switch(n.length){case 0:return;case 1:return n[0];default:return n}}const J1={pollingOptions:I8},jf="http-details",Q1="certificate";function k8(e,t,n,r){let i;n.annotations.includes("query")||n.annotations.includes("composite_query")?i=async(o,...c)=>{o={...o,...e[mn].config.queryTransform?.(t,c,{...e[mn].config,...o})};const a=o.agent||e[mn].config.agent||new yr,u=$e.from(o.canisterId||e[mn].config.canisterId),f=vf(n.argTypes,c),l=await a.query(u,{methodName:t,arg:f,effectiveCanisterId:o.effectiveCanisterId}),p={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case Ss.Rejected:{const y=new vl(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw y.callContext={canisterId:u,methodName:t,httpDetails:p},fs.fromCode(y)}case Ss.Replied:return n.annotations.includes(jf)?{httpDetails:p,result:Ji(n.retTypes,l.reply.arg)}:Ji(n.retTypes,l.reply.arg)}}:i=async(o,...c)=>{o={...o,...e[mn].config.callTransform?.(t,c,{...e[mn].config,...o})};const a=o.agent||e[mn].config.agent||yr.createSync(),{canisterId:u,effectiveCanisterId:f,pollingOptions:l}={...J1,...e[mn].config,...o},p=$e.from(u),y=f!==void 0?$e.from(f):p,g=vf(n.argTypes,c),{requestId:w,response:E,requestDetails:_}=await a.call(p,{methodName:t,arg:g,effectiveCanisterId:y,nonce:o.nonce});let S,m;if(ZS(E.body)){if(a.rootKey==null)throw nn.fromCode(new Us);const U=E.body.certificate;m=await Ui.create({certificate:U,rootKey:a.rootKey,canisterId:y,blsVerify:r,agent:a});const M=[ut("request_status"),w];switch(new TextDecoder().decode(yn(m.lookup_path([...M,"status"])))){case"replied":S=yn(m.lookup_path([...M,"reply"]));break;case"rejected":{const R=new Uint8Array(yn(m.lookup_path([...M,"reject_code"])))[0],V=new TextDecoder().decode(yn(m.lookup_path([...M,"reject_message"]))),W=yn(m.lookup_path([...M,"error_code"])),H=W?new TextDecoder().decode(W):void 0,K=new Za(w,R,V,H);throw K.callContext={canisterId:p,methodName:t,httpDetails:E},fs.fromCode(K)}}}else if(YS(E.body)){const{reject_code:U,reject_message:M,error_code:v}=E.body,R=new Bl(w,U,M,v);throw R.callContext={canisterId:p,methodName:t,httpDetails:E},fs.fromCode(R)}if(E.status===202){const U={...l,blsVerify:r},M=await Z1(a,y,w,U);m=M.certificate,S=M.reply}const T=n.annotations.includes(jf),I=n.annotations.includes(Q1),A={...E,requestDetails:_};if(S!==void 0)return T&&I?{httpDetails:A,certificate:m,result:Ji(n.retTypes,S)}:I?{certificate:m,result:Ji(n.retTypes,S)}:T?{httpDetails:A,result:Ji(n.retTypes,S)}:Ji(n.retTypes,S);{const U=new Un(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${n.retTypes.map(M=>M.display()).join(",")}].`);throw U.callContext={canisterId:p,methodName:t,httpDetails:A},rn.fromCode(U)}};const s=(...o)=>i({},...o);return s.withOptions=o=>(...c)=>i(o,...c),s}const Dt={P2PKH:{P2PKH:null},P2SH_P2WPKH:{P2SH_P2WPKH:null},P2WPKH:{P2WPKH:null},P2WSH:{P2WSH:null},P2SH:{P2SH:null},P2TR:{P2TR:null},UNKNOWN:{UNKNOWN:null}};var di={},je={},Yu={},Wt={},tr={},a0;function Vn(){return a0||(a0=1,Object.defineProperty(tr,"__esModule",{value:!0}),tr.testnet=tr.regtest=tr.bitcoin=void 0,tr.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
70
|
+
Retrying request.`),await this.#p({requestFn:n,backoff:r,tries:i+1});throw oa.fromCode(new ua(f))}const a=Fu(o.headers);if(o.status===Xu||o.status===w8)return{ok:o.ok,status:o.status,statusText:o.statusText,responseBodyBytes:c,headers:a};const u=await o.text();if(o.status===m8&&o.url.includes("api/v3"))throw lt.fromCode(new aa);if(u.startsWith("Invalid request expiry: "))throw Ye.fromCode(new os(u,this.#o));if(i<this.#c)return await this.#p({requestFn:n,backoff:r,tries:i+1});throw lt.fromCode(new ca(o.status,o.statusText,a,u))}async query(t,n,r){const i=this.#u(),s=n.effectiveCanisterId?$e.from(n.effectiveCanisterId):$e.from(t);await this.#y(s),this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${t.toString()}`);let o;const c=await(r??this.#n);if(!c)throw nn.fromCode(new Ai);const a=$e.from(t),u=c.getPrincipal(),f=zu(this.#o,this.#i),l={request_type:To.Query,canister_id:a,method_name:n.methodName,arg:n.arg,sender:u,ingress_expiry:f},p=Ru(l);o=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Ii.Query,body:l}),o=await c.transformRequest(o);const y=Hu(o.body),g={canister:a.toText(),ecid:s,transformedRequest:o,body:y,requestId:p,backoff:i,tries:0},w=async()=>{const _=await this.#E(g);return{requestDetails:l,..._}},E=async()=>{const _=this.#h.get(s.toString());if(_)return _;await this.fetchSubnetKeys(s.toString());const S=this.#h.get(s.toString());if(!S)throw bn.fromCode(new Ul);return S};try{if(!this.#d)return await w();const[_,S]=await Promise.all([w(),E()]);try{return this.#_(_,S)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#h.delete(s.toString());const m=await E();return this.#_(_,m)}}catch(_){let S;throw _ instanceof lr?(_.code.requestContext={requestId:p,senderPubKey:o.body.sender_pubkey,senderSignature:o.body.sender_sig,ingressExpiry:o.body.content.ingress_expiry},S=_):S=rn.fromCode(new Un(_)),this.log.error(`Error while making query: ${S.message}`,S),S}}#_;async createReadStateRequest(t,n){await this.#y();const r=await(n??this.#n);if(!r)throw nn.fromCode(new Ai);const i=r.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#r?{Authorization:"Basic "+btoa(this.#r)}:{}}},endpoint:Ii.ReadState,body:{request_type:To.ReadState,paths:t.paths,sender:i,ingress_expiry:zu(this.#o,this.#i)}});return r.transformRequest(s)}async readState(t,n,r,i){await this.#S();const s=$e.from(t);function o(f){for(const l of f.paths){const[p,y]=l,g=new TextEncoder().encode("request_status");if(Qa(p,g))return y}}let c,a;if(i)c=i,a=Ru(c);else{a=o(n);const f=await this.#n;if(!f)throw nn.fromCode(new Ai);c=await this.createReadStateRequest(n,f)}this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,c);const u=this.#u();try{const{responseBodyBytes:f}=await this.#p({requestFn:()=>this.#s(""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),{...this.#w,...c.request,body:Hu(c.body)}),backoff:u,tries:0}),l=Dn(f);return this.log.print("Read state response:",l),l}catch(f){let l;throw f instanceof lr?(f.code.requestContext={requestId:a,senderPubKey:c.body.sender_pubkey,senderSignature:c.body.sender_sig,ingressExpiry:c.body.content.ingress_expiry},l=f):l=rn.fromCode(new Un(f)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(t){let n;if(t.certificate){const r=Dn(t.certificate);if(r&&"tree"in r)n=r.tree;else throw lt.fromCode(new nc("Could not decode time from response"));const i=oc(["time"],n);if(i.status!==En.Found)throw lt.fromCode(new xs("Time was not found in the response or was not in its expected format.",i.status));if(!(i.value instanceof Uint8Array)&&!ArrayBuffer.isView(i))throw lt.fromCode(new za("Time was not in its expected format."));const s=jl(i.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(t){this.#a=this.#a??(async()=>{await this.#S();const n=Date.now();try{t||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");const r=t??$e.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),i=yr.createSync({identity:new vd,host:this.host.toString(),fetch:this.#s,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),o=(await Promise.all(Array(3).fill(null).map(async()=>{const a=(await Dd({canisterId:r,agent:i,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(a instanceof Date)return a.getTime()},[]))).reduce((c,a)=>typeof a=="number"&&a>c?a:c,0);o>0&&(this.#i=o-n,this.#g=!0,this.log.notify({message:`Syncing time: offset of ${this.#i}`,level:"info"}))}catch(r){const i=r instanceof lr?r:rn.fromCode(new Un(r));throw this.log.error("Caught exception while attempting to sync time",i),i}})(),await this.#a.finally(()=>{this.#a=null})}async status(){const t=this.#r?{Authorization:"Basic "+btoa(this.#r)}:{};this.log.print('fetching "/api/v2/status"');const n=this.#u(),{responseBodyBytes:r}=await this.#p({backoff:n,requestFn:()=>this.#s(""+new URL("/api/v2/status",this.host),{headers:t,...this.#w}),tries:0});return Dn(r)}async fetchRootKey(){return this.#t=this.#t??(async()=>{const t=await this.status();return this.rootKey=t.root_key,this.rootKey})(),await this.#t.finally(()=>{this.#t=null})}async#y(t){await Promise.all([this.#S(),this.#x(t)])}async#S(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#e)await this.fetchRootKey();else throw nn.fromCode(new Rs(this.#e))}async#x(t){this.#m&&!this.hasSyncedTime()&&await this.syncTime(t)}invalidateIdentity(){this.#n=null}replaceIdentity(t){this.#n=Promise.resolve(t)}async fetchSubnetKeys(t){const n=$e.from(t);await this.#y(n);const i=(await Dd({canisterId:n,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return this.#h.set(n.toText(),i),i}_transform(t){let n=Promise.resolve(t);if(t.endpoint===Ii.Call)for(const r of this.#l)n=n.then(i=>r(i).then(s=>s||i));else for(const r of this.#f)n=n.then(i=>r(i).then(s=>s||i));return n}getTimeDiffMsecs(){return this.#i}hasSyncedTime(){return this.#g}}function zu(e,t){const n=e*jf;return ys.fromDeltaInMilliseconds(n,t)}const _8=300*1e3;function S8(){return B8(x8(T8(),1e3),v8(1e3,1.2),A8(_8))}function T8(){let e=!0;return async()=>e?(e=!1,!0):!1}function x8(e,t){return async(n,r,i)=>{if(await e(n,r,i))return new Promise(s=>setTimeout(s,t))}}function A8(e){const t=Date.now()+e;return async(n,r,i)=>{if(Date.now()>t)throw lt.fromCode(new _o(`Request timed out after ${e} msec`,r,i))}}function v8(e,t){let n=e;return()=>new Promise(r=>setTimeout(()=>{n*=t,r()},n))}function B8(...e){return async(t,n,r)=>{for(const i of e)await i(t,n,r)}}const I8={preSignReadStateRequest:!1};function Y1(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Yu(e,t){return e!==null&&typeof e=="object"&&Y1(e,t)}function O8(e,t){return Y1(e,t)&&typeof e[t]=="function"}function c0(e){return Yu(e,"body")&&Yu(e.body,"content")&&e.body.content.request_type===To.ReadState&&Yu(e.body.content,"ingress_expiry")&&typeof e.body.content.ingress_expiry=="object"&&e.body.content.ingress_expiry!==null&&O8(e.body.content.ingress_expiry,"toHash")}async function Z1(e,t,n,r={}){const i=[ut("request_status"),n];let s,o;if(r.preSignReadStateRequest??!1?(o=await P8({paths:[i],agent:e,pollingOptions:r}),s=await e.readState(t,{paths:[i]},void 0,o)):s=await e.readState(t,{paths:[i]}),e.rootKey==null)throw nn.fromCode(new Rs);const a=await Ri.create({certificate:s.certificate,rootKey:e.rootKey,canisterId:t,blsVerify:r.blsVerify,agent:e}),u=yn(a.lookup_path([...i,ut("status")]));let f;switch(typeof u>"u"?f=fr.Unknown:f=new TextDecoder().decode(u),f){case fr.Replied:return{reply:yn(a.lookup_path([...i,"reply"])),certificate:a};case fr.Received:case fr.Unknown:case fr.Processing:{const l=r.strategy??S8();return await l(t,n,f),Z1(e,t,n,{...r,strategy:l,request:o})}case fr.Rejected:{const l=new Uint8Array(yn(a.lookup_path([...i,"reject_code"])))[0],p=new TextDecoder().decode(yn(a.lookup_path([...i,"reject_message"]))),y=yn(a.lookup_path([...i,"error_code"])),g=y?new TextDecoder().decode(y):void 0;throw ls.fromCode(new Ja(n,l,p,g))}case fr.Done:throw rn.fromCode(new Ol(n))}throw ds}async function P8(e){const{paths:t,agent:n,pollingOptions:r}=e;if(r.request&&c0(r.request))return r.request;const i=await n.createReadStateRequest?.({paths:t},void 0);if(!c0(i))throw Ye.fromCode(new Hl(i));return i}const mn=Symbol.for("ic-agent-metadata");class ba{static agentOf(t){return t[mn].config.agent}static interfaceOf(t){return t[mn].service}static canisterIdOf(t){return $e.from(t[mn].config.canisterId)}static createActorClass(t,n){const r=t({IDL:m_});class i extends ba{constructor(o){if(!o.canisterId)throw Ye.fromCode(new fa(o.canisterId));const c=typeof o.canisterId=="string"?$e.fromText(o.canisterId):o.canisterId;super({config:{...J1,...o,canisterId:c},service:r});for(const[a,u]of r._fields)n?.httpDetails&&u.annotations.push(Wf),n?.certificate&&u.annotations.push(Q1),this[a]=k8(this,a,u,o.blsVerify)}}return i}static createActor(t,n){if(!n.canisterId)throw Ye.fromCode(new fa(n.canisterId));return new(this.createActorClass(t))(n)}static createActorWithHttpDetails(t,n){return new(this.createActorClass(t,{httpDetails:!0}))(n)}static createActorWithExtendedDetails(t,n,r={httpDetails:!0,certificate:!0}){return new(this.createActorClass(t,r))(n)}constructor(t){this[mn]=Object.freeze(t)}}function Qi(e,t){const n=gg(e,t);switch(n.length){case 0:return;case 1:return n[0];default:return n}}const J1={pollingOptions:I8},Wf="http-details",Q1="certificate";function k8(e,t,n,r){let i;n.annotations.includes("query")||n.annotations.includes("composite_query")?i=async(o,...c)=>{o={...o,...e[mn].config.queryTransform?.(t,c,{...e[mn].config,...o})};const a=o.agent||e[mn].config.agent||new yr,u=$e.from(o.canisterId||e[mn].config.canisterId),f=Bf(n.argTypes,c),l=await a.query(u,{methodName:t,arg:f,effectiveCanisterId:o.effectiveCanisterId}),p={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case Ts.Rejected:{const y=new Bl(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw y.callContext={canisterId:u,methodName:t,httpDetails:p},ls.fromCode(y)}case Ts.Replied:return n.annotations.includes(Wf)?{httpDetails:p,result:Qi(n.retTypes,l.reply.arg)}:Qi(n.retTypes,l.reply.arg)}}:i=async(o,...c)=>{o={...o,...e[mn].config.callTransform?.(t,c,{...e[mn].config,...o})};const a=o.agent||e[mn].config.agent||yr.createSync(),{canisterId:u,effectiveCanisterId:f,pollingOptions:l}={...J1,...e[mn].config,...o},p=$e.from(u),y=f!==void 0?$e.from(f):p,g=Bf(n.argTypes,c),{requestId:w,response:E,requestDetails:_}=await a.call(p,{methodName:t,arg:g,effectiveCanisterId:y,nonce:o.nonce});let S,m;if(ZS(E.body)){if(a.rootKey==null)throw nn.fromCode(new Rs);const U=E.body.certificate;m=await Ri.create({certificate:U,rootKey:a.rootKey,canisterId:y,blsVerify:r,agent:a});const M=[ut("request_status"),w];switch(new TextDecoder().decode(yn(m.lookup_path([...M,"status"])))){case"replied":S=yn(m.lookup_path([...M,"reply"]));break;case"rejected":{const R=new Uint8Array(yn(m.lookup_path([...M,"reject_code"])))[0],V=new TextDecoder().decode(yn(m.lookup_path([...M,"reject_message"]))),W=yn(m.lookup_path([...M,"error_code"])),H=W?new TextDecoder().decode(W):void 0,K=new Ja(w,R,V,H);throw K.callContext={canisterId:p,methodName:t,httpDetails:E},ls.fromCode(K)}}}else if(YS(E.body)){const{reject_code:U,reject_message:M,error_code:v}=E.body,R=new Il(w,U,M,v);throw R.callContext={canisterId:p,methodName:t,httpDetails:E},ls.fromCode(R)}if(E.status===202){const U={...l,blsVerify:r},M=await Z1(a,y,w,U);m=M.certificate,S=M.reply}const T=n.annotations.includes(Wf),I=n.annotations.includes(Q1),A={...E,requestDetails:_};if(S!==void 0)return T&&I?{httpDetails:A,certificate:m,result:Qi(n.retTypes,S)}:I?{certificate:m,result:Qi(n.retTypes,S)}:T?{httpDetails:A,result:Qi(n.retTypes,S)}:Qi(n.retTypes,S);{const U=new Un(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${n.retTypes.map(M=>M.display()).join(",")}].`);throw U.callContext={canisterId:p,methodName:t,httpDetails:A},rn.fromCode(U)}};const s=(...o)=>i({},...o);return s.withOptions=o=>(...c)=>i(o,...c),s}const Dt={P2PKH:{P2PKH:null},P2SH_P2WPKH:{P2SH_P2WPKH:null},P2WPKH:{P2WPKH:null},P2WSH:{P2WSH:null},P2SH:{P2SH:null},P2TR:{P2TR:null},UNKNOWN:{UNKNOWN:null}};var di={},je={},Zu={},Wt={},tr={},a0;function Vn(){return a0||(a0=1,Object.defineProperty(tr,"__esModule",{value:!0}),tr.testnet=tr.regtest=tr.bitcoin=void 0,tr.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
71
71
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},tr.regtest={messagePrefix:`Bitcoin Signed Message:
|
|
72
72
|
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},tr.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
73
|
-
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),tr}var Zu={},Gs={},Ju={},nr={},u0;function ew(){if(u0)return nr;u0=1,Object.defineProperty(nr,"__esModule",{value:!0}),nr.encode=nr.decode=nr.check=void 0;function e(r){if(r.length<8||r.length>72||r[0]!==48||r[1]!==r.length-2||r[2]!==2)return!1;const i=r[3];if(i===0||5+i>=r.length||r[4+i]!==2)return!1;const s=r[5+i];return!(s===0||6+i+s!==r.length||r[4]&128||i>1&&r[4]===0&&!(r[5]&128)||r[i+6]&128||s>1&&r[i+6]===0&&!(r[i+7]&128))}nr.check=e;function t(r){if(r.length<8)throw new Error("DER sequence length is too short");if(r.length>72)throw new Error("DER sequence length is too long");if(r[0]!==48)throw new Error("Expected DER sequence");if(r[1]!==r.length-2)throw new Error("DER sequence length is invalid");if(r[2]!==2)throw new Error("Expected DER integer");const i=r[3];if(i===0)throw new Error("R length is zero");if(5+i>=r.length)throw new Error("R length is too long");if(r[4+i]!==2)throw new Error("Expected DER integer (2)");const s=r[5+i];if(s===0)throw new Error("S length is zero");if(6+i+s!==r.length)throw new Error("S length is invalid");if(r[4]&128)throw new Error("R value is negative");if(i>1&&r[4]===0&&!(r[5]&128))throw new Error("R value excessively padded");if(r[i+6]&128)throw new Error("S value is negative");if(s>1&&r[i+6]===0&&!(r[i+7]&128))throw new Error("S value excessively padded");return{r:r.slice(4,4+i),s:r.slice(6+i)}}nr.decode=t;function n(r,i){const s=r.length,o=i.length;if(s===0)throw new Error("R length is zero");if(o===0)throw new Error("S length is zero");if(s>33)throw new Error("R length is too long");if(o>33)throw new Error("S length is too long");if(r[0]&128)throw new Error("R value is negative");if(i[0]&128)throw new Error("S value is negative");if(s>1&&r[0]===0&&!(r[1]&128))throw new Error("R value excessively padded");if(o>1&&i[0]===0&&!(i[1]&128))throw new Error("S value excessively padded");const c=Buffer.allocUnsafe(6+s+o);return c[0]=48,c[1]=c.length-2,c[2]=2,c[3]=r.length,r.copy(c,4),c[4+s]=2,c[5+s]=i.length,i.copy(c,6+s),c}return nr.encode=n,nr}var pi={},f0;function Gl(){if(f0)return pi;f0=1,Object.defineProperty(pi,"__esModule",{value:!0}),pi.REVERSE_OPS=pi.OPS=void 0;const e={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};pi.OPS=e;const t={};pi.REVERSE_OPS=t;for(const n of Object.keys(e)){const r=e[n];t[r]=n}return pi}var rr={},l0;function N8(){if(l0)return rr;l0=1,Object.defineProperty(rr,"__esModule",{value:!0}),rr.decode=rr.encode=rr.encodingLength=void 0;const e=Gl();function t(i){return i<e.OPS.OP_PUSHDATA1?1:i<=255?2:i<=65535?3:5}rr.encodingLength=t;function n(i,s,o){const c=t(s);return c===1?i.writeUInt8(s,o):c===2?(i.writeUInt8(e.OPS.OP_PUSHDATA1,o),i.writeUInt8(s,o+1)):c===3?(i.writeUInt8(e.OPS.OP_PUSHDATA2,o),i.writeUInt16LE(s,o+1)):(i.writeUInt8(e.OPS.OP_PUSHDATA4,o),i.writeUInt32LE(s,o+1)),c}rr.encode=n;function r(i,s){const o=i.readUInt8(s);let c,a;if(o<e.OPS.OP_PUSHDATA1)c=o,a=1;else if(o===e.OPS.OP_PUSHDATA1){if(s+2>i.length)return null;c=i.readUInt8(s+1),a=2}else if(o===e.OPS.OP_PUSHDATA2){if(s+3>i.length)return null;c=i.readUInt16LE(s+1),a=3}else{if(s+5>i.length)return null;if(o!==e.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");c=i.readUInt32LE(s+1),a=5}return{opcode:o,number:c,size:a}}return rr.decode=r,rr}var yi={},h0;function U8(){if(h0)return yi;h0=1,Object.defineProperty(yi,"__esModule",{value:!0}),yi.encode=yi.decode=void 0;function e(r,i,s){i=i||4,s=s===void 0?!0:s;const o=r.length;if(o===0)return 0;if(o>i)throw new TypeError("Script number overflow");if(s&&(r[o-1]&127)===0&&(o<=1||(r[o-2]&128)===0))throw new Error("Non-minimally encoded script number");if(o===5){const a=r.readUInt32LE(0),u=r.readUInt8(4);return u&128?-((u&-129)*4294967296+a):u*4294967296+a}let c=0;for(let a=0;a<o;++a)c|=r[a]<<8*a;return r[o-1]&128?-(c&~(128<<8*(o-1))):c}yi.decode=e;function t(r){return r>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0}function n(r){let i=Math.abs(r);const s=t(i),o=Buffer.allocUnsafe(s),c=r<0;for(let a=0;a<s;++a)o.writeUInt8(i&255,a),i>>=8;return o[s-1]&128?o.writeUInt8(c?128:0,s-1):c&&(o[s-1]|=128),o}return yi.encode=n,yi}var gi={},Qu={},ef,d0;function Dl(){if(d0)return ef;d0=1;var e={Array:function(n){return n!=null&&n.constructor===Array},Boolean:function(n){return typeof n=="boolean"},Function:function(n){return typeof n=="function"},Nil:function(n){return n==null},Number:function(n){return typeof n=="number"},Object:function(n){return typeof n=="object"},String:function(n){return typeof n=="string"},"":function(){return!0}};e.Null=e.Nil;for(var t in e)e[t].toJSON=(function(n){return n}).bind(null,t);return ef=e,ef}var tf,p0;function tw(){if(p0)return tf;p0=1;var e=Dl();function t(p){return p.name||p.toString().match(/function (.*?)\s*\(/)[1]}function n(p){return e.Nil(p)?"":t(p.constructor)}function r(p){return e.Function(p)?"":e.String(p)?JSON.stringify(p):p&&e.Object(p)?"":p}function i(p,y){Error.captureStackTrace&&Error.captureStackTrace(p,y)}function s(p){return e.Function(p)?p.toJSON?p.toJSON():t(p):e.Array(p)?"Array":p&&e.Object(p)?"Object":p!==void 0?p:""}function o(p,y,g){var w=r(y);return"Expected "+s(p)+", got"+(g!==""?" "+g:"")+(w!==""?" "+w:"")}function c(p,y,g){g=g||n(y),this.message=o(p,y,g),i(this,c),this.__type=p,this.__value=y,this.__valueTypeName=g}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c;function a(p,y,g,w,E){var _='" of type ';return y==="key"&&(_='" with key type '),o('property "'+s(g)+_+s(p),w,E)}function u(p,y,g,w,E){p?(E=E||n(w),this.message=a(p,g,y,w,E)):this.message='Unexpected property "'+y+'"',i(this,c),this.__label=g,this.__property=y,this.__type=p,this.__value=w,this.__valueTypeName=E}u.prototype=Object.create(Error.prototype),u.prototype.constructor=c;function f(p,y){return new c(p,{},y)}function l(p,y,g){return p instanceof u?(y=y+"."+p.__property,p=new u(p.__type,y,p.__label,p.__value,p.__valueTypeName)):p instanceof c&&(p=new u(p.__type,y,g,p.__value,p.__valueTypeName)),i(p),p}return tf={TfTypeError:c,TfPropertyTypeError:u,tfCustomError:f,tfSubError:l,tfJSON:s,getValueTypeName:n},tf}var nf,y0;function R8(){if(y0)return nf;y0=1;var e=Dl(),t=tw();function n(A){return Buffer.isBuffer(A)}function r(A){return typeof A=="string"&&/^([0-9a-f]{2})+$/i.test(A)}function i(A,U){var M=A.toJSON();function v(R){if(!A(R))return!1;if(R.length===U)return!0;throw t.tfCustomError(M+"(Length: "+U+")",M+"(Length: "+R.length+")")}return v.toJSON=function(){return M},v}var s=i.bind(null,e.Array),o=i.bind(null,n),c=i.bind(null,r),a=i.bind(null,e.String);function u(A,U,M){M=M||e.Number;function v(R,V){return M(R,V)&&R>A&&R<U}return v.toJSON=function(){return`${M.toJSON()} between [${A}, ${U}]`},v}var f=Math.pow(2,53)-1;function l(A){return typeof A=="number"&&isFinite(A)}function p(A){return A<<24>>24===A}function y(A){return A<<16>>16===A}function g(A){return(A|0)===A}function w(A){return typeof A=="number"&&A>=-f&&A<=f&&Math.floor(A)===A}function E(A){return(A&255)===A}function _(A){return(A&65535)===A}function S(A){return A>>>0===A}function m(A){return typeof A=="number"&&A>=0&&A<=f&&Math.floor(A)===A}var T={ArrayN:s,Buffer:n,BufferN:o,Finite:l,Hex:r,HexN:c,Int8:p,Int16:y,Int32:g,Int53:w,Range:u,StringN:a,UInt8:E,UInt16:_,UInt32:S,UInt53:m};for(var I in T)T[I].toJSON=(function(A){return A}).bind(null,I);return nf=T,nf}var rf,g0;function C8(){if(g0)return rf;g0=1;var e=tw(),t=Dl(),n=e.tfJSON,r=e.TfTypeError,i=e.TfPropertyTypeError,s=e.tfSubError,o=e.getValueTypeName,c={arrayOf:function(y,g){y=a(y),g=g||{};function w(E,_){return!t.Array(E)||t.Nil(E)||g.minLength!==void 0&&E.length<g.minLength||g.maxLength!==void 0&&E.length>g.maxLength||g.length!==void 0&&E.length!==g.length?!1:E.every(function(S,m){try{return u(y,S,_)}catch(T){throw s(T,m)}})}return w.toJSON=function(){var E="["+n(y)+"]";return g.length!==void 0?E+="{"+g.length+"}":(g.minLength!==void 0||g.maxLength!==void 0)&&(E+="{"+(g.minLength===void 0?0:g.minLength)+","+(g.maxLength===void 0?1/0:g.maxLength)+"}"),E},w},maybe:function p(y){y=a(y);function g(w,E){return t.Nil(w)||y(w,E,p)}return g.toJSON=function(){return"?"+n(y)},g},map:function(y,g){y=a(y),g&&(g=a(g));function w(E,_){if(!t.Object(E)||t.Nil(E))return!1;for(var S in E){try{g&&u(g,S,_)}catch(T){throw s(T,S,"key")}try{var m=E[S];u(y,m,_)}catch(T){throw s(T,S)}}return!0}return g?w.toJSON=function(){return"{"+n(g)+": "+n(y)+"}"}:w.toJSON=function(){return"{"+n(y)+"}"},w},object:function(y){var g={};for(var w in y)g[w]=a(y[w]);function E(_,S){if(!t.Object(_)||t.Nil(_))return!1;var m;try{for(m in g){var T=g[m],I=_[m];u(T,I,S)}}catch(A){throw s(A,m)}if(S){for(m in _)if(!g[m])throw new i(void 0,m)}return!0}return E.toJSON=function(){return n(g)},E},anyOf:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return y.some(function(_){try{return u(_,w,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join("|")},g},allOf:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return y.every(function(_){try{return u(_,w,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join(" & ")},g},quacksLike:function(y){function g(w){return y===o(w)}return g.toJSON=function(){return y},g},tuple:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return t.Nil(w)||t.Nil(w.length)||E&&w.length!==y.length?!1:y.every(function(_,S){try{return u(_,w[S],E)}catch(m){throw s(m,S)}})}return g.toJSON=function(){return"("+y.map(n).join(", ")+")"},g},value:function(y){function g(w){return w===y}return g.toJSON=function(){return y},g}};c.oneOf=c.anyOf;function a(p){if(t.String(p))return p[0]==="?"?c.maybe(p.slice(1)):t[p]||c.quacksLike(p);if(p&&t.Object(p)){if(t.Array(p)){if(p.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(p[0])}return c.object(p)}else if(t.Function(p))return p;return c.value(p)}function u(p,y,g,w){if(t.Function(p)){if(p(y,g))return!0;throw new r(w||p,y)}return u(a(p),y,g)}for(var f in t)u[f]=t[f];for(f in c)u[f]=c[f];var l=R8();for(f in l)u[f]=l[f];return u.compile=a,u.TfTypeError=r,u.TfPropertyTypeError=i,rf=u,rf}var w0;function Lt(){return w0||(w0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Vo();e.typeforce=C8();const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,l){return f.length!==l.length?!1:f.every((p,y)=>p.equals(l[y]))}e.stacksEqual=i;function s(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const l=f[0],p=f.slice(1,33);if(p.compare(n)===0||p.compare(r)>=0)return!1;if((l===2||l===3)&&f.length===33)return!0;const y=f.slice(33);return y.compare(n)===0||y.compare(r)>=0?!1:l===4&&f.length===65}e.isPoint=s;const o=21*1e14;function c(f){return e.typeforce.UInt53(f)&&f<=o}e.Satoshi=c,e.TAPLEAF_VERSION_MASK=254;function a(f){return!f||!("output"in f)||!t.Buffer.isBuffer(f.output)?!1:f.version!==void 0?(f.version&e.TAPLEAF_VERSION_MASK)===f.version:!0}e.isTapleaf=a;function u(f){return(0,e.Array)(f)?f.length!==2?!1:f.every(l=>u(l)):a(f)}e.isTaptree=u,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Qu)),Qu}var m0;function H8(){if(m0)return gi;m0=1,Object.defineProperty(gi,"__esModule",{value:!0}),gi.encode=gi.decode=void 0;const e=ew(),t=Jt(),n=Lt(),{typeforce:r}=n,i=Buffer.alloc(1,0);function s(u){let f=0;for(;u[f]===0;)++f;return f===u.length?i:(u=u.slice(f),u[0]&128?Buffer.concat([i,u],1+u.length):u)}function o(u){u[0]===0&&(u=u.slice(1));const f=Buffer.alloc(32,0),l=Math.max(0,32-u.length);return u.copy(f,l),f}function c(u){const f=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=e.decode(u.slice(0,-1)),p=o(l.r),y=o(l.s);return{signature:Buffer.concat([p,y],64),hashType:f}}gi.decode=c;function a(u,f){if(r({signature:n.BufferN(64),hashType:n.UInt8},{signature:u,hashType:f}),!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=Buffer.allocUnsafe(1);l.writeUInt8(f,0);const p=s(u.slice(0,32)),y=s(u.slice(32,64));return Buffer.concat([e.encode(p,y),l])}return gi.encode=a,gi}var b0;function Jt(){return b0||(b0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=ew(),n=Gl();Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=N8(),i=U8(),s=H8(),o=Lt(),{typeforce:c}=o,a=n.OPS.OP_RESERVED;function u(v){return o.Number(v)&&(v===n.OPS.OP_0||v>=n.OPS.OP_1&&v<=n.OPS.OP_16||v===n.OPS.OP_1NEGATE)}function f(v){return o.Buffer(v)||u(v)}function l(v){return o.Array(v)&&v.every(f)}e.isPushOnly=l;function p(v){return v.length-v.filter(f).length}e.countNonPushOnlyOPs=p;function y(v){if(v.length===0)return n.OPS.OP_0;if(v.length===1){if(v[0]>=1&&v[0]<=16)return a+v[0];if(v[0]===129)return n.OPS.OP_1NEGATE}}function g(v){return Buffer.isBuffer(v)}function w(v){return o.Array(v)}function E(v){return Buffer.isBuffer(v)}function _(v){if(g(v))return v;c(o.Array,v);const R=v.reduce((H,K)=>E(K)?K.length===1&&y(K)!==void 0?H+1:H+r.encodingLength(K.length)+K.length:H+1,0),V=Buffer.allocUnsafe(R);let W=0;if(v.forEach(H=>{if(E(H)){const K=y(H);if(K!==void 0){V.writeUInt8(K,W),W+=1;return}W+=r.encode(V,H.length,W),H.copy(V,W),W+=H.length}else V.writeUInt8(H,W),W+=1}),W!==V.length)throw new Error("Could not decode chunks");return V}e.compile=_;function S(v){if(w(v))return v;c(o.Buffer,v);const R=[];let V=0;for(;V<v.length;){const W=v[V];if(W>n.OPS.OP_0&&W<=n.OPS.OP_PUSHDATA4){const H=r.decode(v,V);if(H===null||(V+=H.size,V+H.number>v.length))return null;const K=v.slice(V,V+H.number);V+=H.number;const N=y(K);N!==void 0?R.push(N):R.push(K)}else R.push(W),V+=1}return R}e.decompile=S;function m(v){if(g(v)&&(v=S(v)),!v)throw new Error("Could not convert invalid chunks to ASM");return v.map(R=>{if(E(R)){const V=y(R);if(V===void 0)return R.toString("hex");R=V}return n.REVERSE_OPS[R]}).join(" ")}e.toASM=m;function T(v){return c(o.String,v),_(v.split(" ").map(R=>n.OPS[R]!==void 0?n.OPS[R]:(c(o.Hex,R),Buffer.from(R,"hex"))))}e.fromASM=T;function I(v){return v=S(v),c(l,v),v.map(R=>E(R)?R:R===n.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(R-a))}e.toStack=I;function A(v){return o.isPoint(v)}e.isCanonicalPubKey=A;function U(v){const R=v&-129;return R>0&&R<4}e.isDefinedHashType=U;function M(v){return!Buffer.isBuffer(v)||!U(v[v.length-1])?!1:t.check(v.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s})(Ju)),Ju}var wi={},E0;function ui(){if(E0)return wi;E0=1,Object.defineProperty(wi,"__esModule",{value:!0}),wi.value=wi.prop=void 0;function e(n,r,i){Object.defineProperty(n,r,{configurable:!0,enumerable:!0,get(){const s=i.call(this);return this[r]=s,s},set(s){Object.defineProperty(this,r,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}wi.prop=e;function t(n){let r;return()=>(r!==void 0||(r=n()),r)}return wi.value=t,wi}var _0;function F8(){if(_0)return Gs;_0=1,Object.defineProperty(Gs,"__esModule",{value:!0}),Gs.p2data=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS;function s(o,c){if(!o.data&&!o.output)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),data:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))},o);const u={name:"embed",network:o.network||e.bitcoin};if(r.prop(u,"output",()=>{if(o.data)return t.compile([i.OP_RETURN].concat(o.data))}),r.prop(u,"data",()=>{if(o.output)return t.decompile(o.output).slice(1)}),c.validate&&o.output){const f=t.decompile(o.output);if(f[0]!==i.OP_RETURN)throw new TypeError("Output is invalid");if(!f.slice(1).every(n.typeforce.Buffer))throw new TypeError("Output is invalid");if(o.data&&!(0,n.stacksEqual)(o.data,u.data))throw new TypeError("Data mismatch")}return Object.assign(u,o)}return Gs.p2data=s,Gs}var Ds={},S0;function M8(){if(S0)return Ds;S0=1,Object.defineProperty(Ds,"__esModule",{value:!0}),Ds.p2ms=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS,s=i.OP_RESERVED;function o(c,a){if(!c.input&&!c.output&&!(c.pubkeys&&c.m!==void 0)&&!c.signatures)throw new TypeError("Not enough data");a=Object.assign({validate:!0},a||{});function u(w){return t.isCanonicalScriptSignature(w)||(a.allowIncomplete&&w===i.OP_0)!==void 0}(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),m:n.typeforce.maybe(n.typeforce.Number),n:n.typeforce.maybe(n.typeforce.Number),output:n.typeforce.maybe(n.typeforce.Buffer),pubkeys:n.typeforce.maybe(n.typeforce.arrayOf(n.isPoint)),signatures:n.typeforce.maybe(n.typeforce.arrayOf(u)),input:n.typeforce.maybe(n.typeforce.Buffer)},c);const l={network:c.network||e.bitcoin};let p=[],y=!1;function g(w){y||(y=!0,p=t.decompile(w),l.m=p[0]-s,l.n=p[p.length-2]-s,l.pubkeys=p.slice(1,-2))}if(r.prop(l,"output",()=>{if(c.m&&l.n&&c.pubkeys)return t.compile([].concat(s+c.m,c.pubkeys,s+l.n,i.OP_CHECKMULTISIG))}),r.prop(l,"m",()=>{if(l.output)return g(l.output),l.m}),r.prop(l,"n",()=>{if(l.pubkeys)return l.pubkeys.length}),r.prop(l,"pubkeys",()=>{if(c.output)return g(c.output),l.pubkeys}),r.prop(l,"signatures",()=>{if(c.input)return t.decompile(c.input).slice(1)}),r.prop(l,"input",()=>{if(c.signatures)return t.compile([i.OP_0].concat(c.signatures))}),r.prop(l,"witness",()=>{if(l.input)return[]}),r.prop(l,"name",()=>{if(!(!l.m||!l.n))return`p2ms(${l.m} of ${l.n})`}),a.validate){if(c.output){if(g(c.output),!n.typeforce.Number(p[0]))throw new TypeError("Output is invalid");if(!n.typeforce.Number(p[p.length-2]))throw new TypeError("Output is invalid");if(p[p.length-1]!==i.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(l.m<=0||l.n>16||l.m>l.n||l.n!==p.length-3)throw new TypeError("Output is invalid");if(!l.pubkeys.every(w=>(0,n.isPoint)(w)))throw new TypeError("Output is invalid");if(c.m!==void 0&&c.m!==l.m)throw new TypeError("m mismatch");if(c.n!==void 0&&c.n!==l.n)throw new TypeError("n mismatch");if(c.pubkeys&&!(0,n.stacksEqual)(c.pubkeys,l.pubkeys))throw new TypeError("Pubkeys mismatch")}if(c.pubkeys){if(c.n!==void 0&&c.n!==c.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(l.n=c.pubkeys.length,l.n<l.m)throw new TypeError("Pubkey count cannot be less than m")}if(c.signatures){if(c.signatures.length<l.m)throw new TypeError("Not enough signatures provided");if(c.signatures.length>l.m)throw new TypeError("Too many signatures provided")}if(c.input){if(c.input[0]!==i.OP_0)throw new TypeError("Input is invalid");if(l.signatures.length===0||!l.signatures.every(u))throw new TypeError("Input has invalid signature(s)");if(c.signatures&&!(0,n.stacksEqual)(c.signatures,l.signatures))throw new TypeError("Signature mismatch");if(c.m!==void 0&&c.m!==c.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(l,c)}return Ds.p2ms=o,Ds}var Xs={},T0;function q8(){if(T0)return Xs;T0=1,Object.defineProperty(Xs,"__esModule",{value:!0}),Xs.p2pk=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS;function s(o,c){if(!o.input&&!o.output&&!o.pubkey&&!o.input&&!o.signature)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),pubkey:n.typeforce.maybe(n.isPoint),signature:n.typeforce.maybe(t.isCanonicalScriptSignature),input:n.typeforce.maybe(n.typeforce.Buffer)},o);const a=r.value(()=>t.decompile(o.input)),f={name:"p2pk",network:o.network||e.bitcoin};if(r.prop(f,"output",()=>{if(o.pubkey)return t.compile([o.pubkey,i.OP_CHECKSIG])}),r.prop(f,"pubkey",()=>{if(o.output)return o.output.slice(1,-1)}),r.prop(f,"signature",()=>{if(o.input)return a()[0]}),r.prop(f,"input",()=>{if(o.signature)return t.compile([o.signature])}),r.prop(f,"witness",()=>{if(f.input)return[]}),c.validate){if(o.output){if(o.output[o.output.length-1]!==i.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,n.isPoint)(f.pubkey))throw new TypeError("Output pubkey is invalid");if(o.pubkey&&!o.pubkey.equals(f.pubkey))throw new TypeError("Pubkey mismatch")}if(o.signature&&o.input&&!o.input.equals(f.input))throw new TypeError("Signature mismatch");if(o.input){if(a().length!==1)throw new TypeError("Input is invalid");if(!t.isCanonicalScriptSignature(f.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(f,o)}return Xs.p2pk=s,Xs}var zs={},sf={},mi={},Gt={},x0;function nw(){if(x0)return Gt;x0=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.ripemd160=Gt.RIPEMD160=Gt.md5=Gt.MD5=Gt.sha1=Gt.SHA1=void 0;const e=Kp(),t=ni(),n=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),r=new Uint32Array(80);class i extends e.HashMD{constructor(){super(64,20,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0}get(){const{A:v,B:R,C:V,D:W,E:H}=this;return[v,R,V,W,H]}set(v,R,V,W,H){this.A=v|0,this.B=R|0,this.C=V|0,this.D=W|0,this.E=H|0}process(v,R){for(let L=0;L<16;L++,R+=4)r[L]=v.getUint32(R,!1);for(let L=16;L<80;L++)r[L]=(0,t.rotl)(r[L-3]^r[L-8]^r[L-14]^r[L-16],1);let{A:V,B:W,C:H,D:K,E:N}=this;for(let L=0;L<80;L++){let F,x;L<20?(F=(0,e.Chi)(W,H,K),x=1518500249):L<40?(F=W^H^K,x=1859775393):L<60?(F=(0,e.Maj)(W,H,K),x=2400959708):(F=W^H^K,x=3395469782);const O=(0,t.rotl)(V,5)+F+N+x+r[L]|0;N=K,K=H,H=(0,t.rotl)(W,30),W=V,V=O}V=V+this.A|0,W=W+this.B|0,H=H+this.C|0,K=K+this.D|0,N=N+this.E|0,this.set(V,W,H,K,N)}roundClean(){(0,t.clean)(r)}destroy(){this.set(0,0,0,0,0),(0,t.clean)(this.buffer)}}Gt.SHA1=i,Gt.sha1=(0,t.createHasher)(()=>new i);const s=Math.pow(2,32),o=Array.from({length:64},(M,v)=>Math.floor(s*Math.abs(Math.sin(v+1)))),c=n.slice(0,4),a=new Uint32Array(16);class u extends e.HashMD{constructor(){super(64,16,8,!0),this.A=c[0]|0,this.B=c[1]|0,this.C=c[2]|0,this.D=c[3]|0}get(){const{A:v,B:R,C:V,D:W}=this;return[v,R,V,W]}set(v,R,V,W){this.A=v|0,this.B=R|0,this.C=V|0,this.D=W|0}process(v,R){for(let N=0;N<16;N++,R+=4)a[N]=v.getUint32(R,!0);let{A:V,B:W,C:H,D:K}=this;for(let N=0;N<64;N++){let L,F,x;N<16?(L=(0,e.Chi)(W,H,K),F=N,x=[7,12,17,22]):N<32?(L=(0,e.Chi)(K,W,H),F=(5*N+1)%16,x=[5,9,14,20]):N<48?(L=W^H^K,F=(3*N+5)%16,x=[4,11,16,23]):(L=H^(W|~K),F=7*N%16,x=[6,10,15,21]),L=L+V+o[N]+a[F],V=K,K=H,H=W,W=W+(0,t.rotl)(L,x[N%4])}V=V+this.A|0,W=W+this.B|0,H=H+this.C|0,K=K+this.D|0,this.set(V,W,H,K)}roundClean(){(0,t.clean)(a)}destroy(){this.set(0,0,0,0),(0,t.clean)(this.buffer)}}Gt.MD5=u,Gt.md5=(0,t.createHasher)(()=>new u);const f=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),l=Uint8Array.from(new Array(16).fill(0).map((M,v)=>v)),p=l.map(M=>(9*M+5)%16),y=(()=>{const R=[[l],[p]];for(let V=0;V<4;V++)for(let W of R)W.push(W[V].map(H=>f[H]));return R})(),g=y[0],w=y[1],E=[[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(M=>Uint8Array.from(M)),_=g.map((M,v)=>M.map(R=>E[v][R])),S=w.map((M,v)=>M.map(R=>E[v][R])),m=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),T=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function I(M,v,R,V){return M===0?v^R^V:M===1?v&R|~v&V:M===2?(v|~R)^V:M===3?v&V|R&~V:v^(R|~V)}const A=new Uint32Array(16);class U extends e.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:v,h1:R,h2:V,h3:W,h4:H}=this;return[v,R,V,W,H]}set(v,R,V,W,H){this.h0=v|0,this.h1=R|0,this.h2=V|0,this.h3=W|0,this.h4=H|0}process(v,R){for(let P=0;P<16;P++,R+=4)A[P]=v.getUint32(R,!0);let V=this.h0|0,W=V,H=this.h1|0,K=H,N=this.h2|0,L=N,F=this.h3|0,x=F,O=this.h4|0,q=O;for(let P=0;P<5;P++){const $=4-P,G=m[P],X=T[P],Y=g[P],oe=w[P],ae=_[P],ee=S[P];for(let Z=0;Z<16;Z++){const ce=(0,t.rotl)(V+I(P,H,N,F)+A[Y[Z]]+G,ae[Z])+O|0;V=O,O=F,F=(0,t.rotl)(N,10)|0,N=H,H=ce}for(let Z=0;Z<16;Z++){const ce=(0,t.rotl)(W+I($,K,L,x)+A[oe[Z]]+X,ee[Z])+q|0;W=q,q=x,x=(0,t.rotl)(L,10)|0,L=K,K=ce}}this.set(this.h1+N+x|0,this.h2+F+q|0,this.h3+O+W|0,this.h4+V+K|0,this.h0+H+L|0)}roundClean(){(0,t.clean)(A)}destroy(){this.destroyed=!0,(0,t.clean)(this.buffer),this.set(0,0,0,0,0)}}return Gt.RIPEMD160=U,Gt.ripemd160=(0,t.createHasher)(()=>new U),Gt}var A0;function V8(){if(A0)return mi;A0=1,Object.defineProperty(mi,"__esModule",{value:!0}),mi.ripemd160=mi.RIPEMD160=void 0;const e=nw();return mi.RIPEMD160=e.RIPEMD160,mi.ripemd160=e.ripemd160,mi}var bi={},v0;function $8(){if(v0)return bi;v0=1,Object.defineProperty(bi,"__esModule",{value:!0}),bi.sha1=bi.SHA1=void 0;const e=nw();return bi.SHA1=e.SHA1,bi.sha1=e.sha1,bi}var In={},B0;function rw(){if(B0)return In;B0=1,Object.defineProperty(In,"__esModule",{value:!0}),In.sha224=In.SHA224=In.sha256=In.SHA256=void 0;const e=Lp();return In.SHA256=e.SHA256,In.sha256=e.sha256,In.SHA224=e.SHA224,In.sha224=e.sha224,In}var I0;function xr(){return I0||(I0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=V8(),n=$8(),r=rw();function i(f){return Buffer.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function s(f){return Buffer.from((0,n.sha1)(Uint8Array.from(f)))}e.sha1=s;function o(f){return Buffer.from((0,r.sha256)(Uint8Array.from(f)))}e.sha256=o;function c(f){return Buffer.from((0,t.ripemd160)((0,r.sha256)(Uint8Array.from(f))))}e.hash160=c;function a(f){return Buffer.from((0,r.sha256)((0,r.sha256)(Uint8Array.from(f))))}e.hash256=a,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.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":Buffer.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":Buffer.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:Buffer.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:Buffer.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:Buffer.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:Buffer.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":Buffer.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":Buffer.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 u(f,l){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[f],l]))}e.taggedHash=u})(sf)),sf}var of,O0;function K8(){if(O0)return of;O0=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,E=0,_=0,S=g.length;_!==S&&g[_]===0;)_++,w++;for(var m=(S-_)*f+1>>>0,T=new Uint8Array(m);_!==S;){for(var I=g[_],A=0,U=m-1;(I!==0||A<E)&&U!==-1;U--,A++)I+=256*T[U]>>>0,T[U]=I%c>>>0,I=I/c>>>0;if(I!==0)throw new Error("Non-zero carry");E=A,_++}for(var M=m-E;M!==m&&T[M]===0;)M++;for(var v=a.repeat(w);M<m;++M)v+=t.charAt(T[M]);return v}function p(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;for(var w=0,E=0,_=0;g[w]===a;)E++,w++;for(var S=(g.length-w)*u+1>>>0,m=new Uint8Array(S);g[w];){var T=g.charCodeAt(w);if(T>255)return;var I=n[T];if(I===255)return;for(var A=0,U=S-1;(I!==0||A<_)&&U!==-1;U--,A++)I+=c*m[U]>>>0,m[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");_=A,w++}for(var M=S-_;M!==S&&m[M]===0;)M++;for(var v=new Uint8Array(E+(S-M)),R=E;M!==S;)v[R++]=m[M++];return v}function y(g){var w=p(g);if(w)return w;throw new Error("Non-base"+c+" character")}return{encode:l,decodeUnsafe:p,decode:y}}return of=e,of}var cf,P0;function L8(){return P0||(P0=1,cf=K8()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),cf}var af,k0;function j8(){if(k0)return af;k0=1;var e=L8();return af=function(t){function n(o){var c=Uint8Array.from(o),a=t(c),u=c.length+4,f=new Uint8Array(u);return f.set(c,0),f.set(a.subarray(0,4),c.length),e.encode(f,u)}function r(o){var c=o.slice(0,-4),a=o.slice(-4),u=t(c);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return c}function i(o){var c=e.decodeUnsafe(o);if(c)return r(c)}function s(o){var c=e.decode(o),a=r(c);if(!a)throw new Error("Invalid checksum");return a}return{encode:n,decode:s,decodeUnsafe:i}},af}var uf,N0;function Xl(){if(N0)return uf;N0=1;var{sha256:e}=rw(),t=j8();function n(r){return e(e(r))}return uf=t(n),uf}var U0;function W8(){if(U0)return zs;U0=1,Object.defineProperty(zs,"__esModule",{value:!0}),zs.p2pkh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Xl(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.pubkey&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(25)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),input:r.typeforce.maybe(r.typeforce.Buffer)},a);const f=i.value(()=>{const g=Buffer.from(s.decode(a.address)),w=g.readUInt8(0),E=g.slice(1);return{version:w,hash:E}}),l=i.value(()=>n.decompile(a.input)),p=a.network||t.bitcoin,y={name:"p2pkh",network:p};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=Buffer.allocUnsafe(21);return g.writeUInt8(p.pubKeyHash,0),y.hash.copy(g,1),s.encode(g)}),i.prop(y,"hash",()=>{if(a.output)return a.output.slice(3,23);if(a.address)return f().hash;if(a.pubkey||y.pubkey)return e.hash160(a.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_DUP,o.OP_HASH160,y.hash,o.OP_EQUALVERIFY,o.OP_CHECKSIG])}),i.prop(y,"pubkey",()=>{if(a.input)return l()[1]}),i.prop(y,"signature",()=>{if(a.input)return l()[0]}),i.prop(y,"input",()=>{if(a.pubkey&&a.signature)return n.compile([a.signature,a.pubkey])}),i.prop(y,"witness",()=>{if(y.input)return[]}),u.validate){let g=Buffer.from([]);if(a.address){if(f().version!==p.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(f().hash.length!==20)throw new TypeError("Invalid address");g=f().hash}if(a.hash){if(g.length>0&&!g.equals(a.hash))throw new TypeError("Hash mismatch");g=a.hash}if(a.output){if(a.output.length!==25||a.output[0]!==o.OP_DUP||a.output[1]!==o.OP_HASH160||a.output[2]!==20||a.output[23]!==o.OP_EQUALVERIFY||a.output[24]!==o.OP_CHECKSIG)throw new TypeError("Output is invalid");const w=a.output.slice(3,23);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");g=w}if(a.pubkey){const w=e.hash160(a.pubkey);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");g=w}if(a.input){const w=l();if(w.length!==2)throw new TypeError("Input is invalid");if(!n.isCanonicalScriptSignature(w[0]))throw new TypeError("Input has invalid signature");if(!(0,r.isPoint)(w[1]))throw new TypeError("Input has invalid pubkey");if(a.signature&&!a.signature.equals(w[0]))throw new TypeError("Signature mismatch");if(a.pubkey&&!a.pubkey.equals(w[1]))throw new TypeError("Pubkey mismatch");const E=e.hash160(w[1]);if(g.length>0&&!g.equals(E))throw new TypeError("Hash mismatch")}}return Object.assign(y,a)}return zs.p2pkh=c,zs}var Ys={},R0;function G8(){if(R0)return Ys;R0=1,Object.defineProperty(Ys,"__esModule",{value:!0}),Ys.p2sh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Xl(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.redeem&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(23)),redeem:r.typeforce.maybe({network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},a);let f=a.network;f||(f=a.redeem&&a.redeem.network||t.bitcoin);const l={network:f},p=i.value(()=>{const w=Buffer.from(s.decode(a.address)),E=w.readUInt8(0),_=w.slice(1);return{version:E,hash:_}}),y=i.value(()=>n.decompile(a.input)),g=i.value(()=>{const w=y(),E=w[w.length-1];return{network:f,output:E===o.OP_FALSE?Buffer.from([]):E,input:n.compile(w.slice(0,-1)),witness:a.witness||[]}});if(i.prop(l,"address",()=>{if(!l.hash)return;const w=Buffer.allocUnsafe(21);return w.writeUInt8(l.network.scriptHash,0),l.hash.copy(w,1),s.encode(w)}),i.prop(l,"hash",()=>{if(a.output)return a.output.slice(2,22);if(a.address)return p().hash;if(l.redeem&&l.redeem.output)return e.hash160(l.redeem.output)}),i.prop(l,"output",()=>{if(l.hash)return n.compile([o.OP_HASH160,l.hash,o.OP_EQUAL])}),i.prop(l,"redeem",()=>{if(a.input)return g()}),i.prop(l,"input",()=>{if(!(!a.redeem||!a.redeem.input||!a.redeem.output))return n.compile([].concat(n.decompile(a.redeem.input),a.redeem.output))}),i.prop(l,"witness",()=>{if(l.redeem&&l.redeem.witness)return l.redeem.witness;if(l.input)return[]}),i.prop(l,"name",()=>{const w=["p2sh"];return l.redeem!==void 0&&l.redeem.name!==void 0&&w.push(l.redeem.name),w.join("-")}),u.validate){let w=Buffer.from([]);if(a.address){if(p().version!==f.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(p().hash.length!==20)throw new TypeError("Invalid address");w=p().hash}if(a.hash){if(w.length>0&&!w.equals(a.hash))throw new TypeError("Hash mismatch");w=a.hash}if(a.output){if(a.output.length!==23||a.output[0]!==o.OP_HASH160||a.output[1]!==20||a.output[22]!==o.OP_EQUAL)throw new TypeError("Output is invalid");const _=a.output.slice(2,22);if(w.length>0&&!w.equals(_))throw new TypeError("Hash mismatch");w=_}const E=_=>{if(_.output){const S=n.decompile(_.output);if(!S||S.length<1)throw new TypeError("Redeem.output too short");if(_.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(n.countNonPushOnlyOPs(S)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const m=e.hash160(_.output);if(w.length>0&&!w.equals(m))throw new TypeError("Hash mismatch");w=m}if(_.input){const S=_.input.length>0,m=_.witness&&_.witness.length>0;if(!S&&!m)throw new TypeError("Empty input");if(S&&m)throw new TypeError("Input and witness provided");if(S){const T=n.decompile(_.input);if(!n.isPushOnly(T))throw new TypeError("Non push-only scriptSig")}}};if(a.input){const _=y();if(!_||_.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(g().output))throw new TypeError("Input is invalid");E(g())}if(a.redeem){if(a.redeem.network&&a.redeem.network!==f)throw new TypeError("Network mismatch");if(a.input){const _=g();if(a.redeem.output&&!a.redeem.output.equals(_.output))throw new TypeError("Redeem.output mismatch");if(a.redeem.input&&!a.redeem.input.equals(_.input))throw new TypeError("Redeem.input mismatch")}E(a.redeem)}if(a.witness&&a.redeem&&a.redeem.witness&&!(0,r.stacksEqual)(a.redeem.witness,a.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(l,a)}return Ys.p2sh=c,Ys}var Zs={},C0;function D8(){if(C0)return Zs;C0=1,Object.defineProperty(Zs,"__esModule",{value:!0}),Zs.p2wpkh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Do(),o=n.OPS,c=Buffer.alloc(0);function a(u,f){if(!u.address&&!u.hash&&!u.output&&!u.pubkey&&!u.witness)throw new TypeError("Not enough data");f=Object.assign({validate:!0},f||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(22)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},u);const l=i.value(()=>{const g=s.bech32.decode(u.address),w=g.words.shift(),E=s.bech32.fromWords(g.words);return{version:w,prefix:g.prefix,data:Buffer.from(E)}}),p=u.network||t.bitcoin,y={name:"p2wpkh",network:p};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=s.bech32.toWords(y.hash);return g.unshift(0),s.bech32.encode(p.bech32,g)}),i.prop(y,"hash",()=>{if(u.output)return u.output.slice(2,22);if(u.address)return l().data;if(u.pubkey||y.pubkey)return e.hash160(u.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_0,y.hash])}),i.prop(y,"pubkey",()=>{if(u.pubkey)return u.pubkey;if(u.witness)return u.witness[1]}),i.prop(y,"signature",()=>{if(u.witness)return u.witness[0]}),i.prop(y,"input",()=>{if(y.witness)return c}),i.prop(y,"witness",()=>{if(u.pubkey&&u.signature)return[u.signature,u.pubkey]}),f.validate){let g=Buffer.from([]);if(u.address){if(p&&p.bech32!==l().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(l().version!==0)throw new TypeError("Invalid address version");if(l().data.length!==20)throw new TypeError("Invalid address data");g=l().data}if(u.hash){if(g.length>0&&!g.equals(u.hash))throw new TypeError("Hash mismatch");g=u.hash}if(u.output){if(u.output.length!==22||u.output[0]!==o.OP_0||u.output[1]!==20)throw new TypeError("Output is invalid");if(g.length>0&&!g.equals(u.output.slice(2)))throw new TypeError("Hash mismatch");g=u.output.slice(2)}if(u.pubkey){const w=e.hash160(u.pubkey);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");if(g=w,!(0,r.isPoint)(u.pubkey)||u.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(u.witness){if(u.witness.length!==2)throw new TypeError("Witness is invalid");if(!n.isCanonicalScriptSignature(u.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,r.isPoint)(u.witness[1])||u.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(u.signature&&!u.signature.equals(u.witness[0]))throw new TypeError("Signature mismatch");if(u.pubkey&&!u.pubkey.equals(u.witness[1]))throw new TypeError("Pubkey mismatch");const w=e.hash160(u.witness[1]);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch")}}return Object.assign(y,u)}return Zs.p2wpkh=a,Zs}var Js={},H0;function X8(){if(H0)return Js;H0=1,Object.defineProperty(Js,"__esModule",{value:!0}),Js.p2wsh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Do(),o=n.OPS,c=Buffer.alloc(0);function a(f){return!!(Buffer.isBuffer(f)&&f.length===65&&f[0]===4&&(0,r.isPoint)(f))}function u(f,l){if(!f.address&&!f.hash&&!f.output&&!f.redeem&&!f.witness)throw new TypeError("Not enough data");l=Object.assign({validate:!0},l||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),output:r.typeforce.maybe(r.typeforce.BufferN(34)),redeem:r.typeforce.maybe({input:r.typeforce.maybe(r.typeforce.Buffer),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.BufferN(0)),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},f);const p=i.value(()=>{const E=s.bech32.decode(f.address),_=E.words.shift(),S=s.bech32.fromWords(E.words);return{version:_,prefix:E.prefix,data:Buffer.from(S)}}),y=i.value(()=>n.decompile(f.redeem.input));let g=f.network;g||(g=f.redeem&&f.redeem.network||t.bitcoin);const w={network:g};if(i.prop(w,"address",()=>{if(!w.hash)return;const E=s.bech32.toWords(w.hash);return E.unshift(0),s.bech32.encode(g.bech32,E)}),i.prop(w,"hash",()=>{if(f.output)return f.output.slice(2);if(f.address)return p().data;if(w.redeem&&w.redeem.output)return e.sha256(w.redeem.output)}),i.prop(w,"output",()=>{if(w.hash)return n.compile([o.OP_0,w.hash])}),i.prop(w,"redeem",()=>{if(f.witness)return{output:f.witness[f.witness.length-1],input:c,witness:f.witness.slice(0,-1)}}),i.prop(w,"input",()=>{if(w.witness)return c}),i.prop(w,"witness",()=>{if(f.redeem&&f.redeem.input&&f.redeem.input.length>0&&f.redeem.output&&f.redeem.output.length>0){const E=n.toStack(y());return w.redeem=Object.assign({witness:E},f.redeem),w.redeem.input=c,[].concat(E,f.redeem.output)}if(f.redeem&&f.redeem.output&&f.redeem.witness)return[].concat(f.redeem.witness,f.redeem.output)}),i.prop(w,"name",()=>{const E=["p2wsh"];return w.redeem!==void 0&&w.redeem.name!==void 0&&E.push(w.redeem.name),E.join("-")}),l.validate){let E=Buffer.from([]);if(f.address){if(p().prefix!==g.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(p().version!==0)throw new TypeError("Invalid address version");if(p().data.length!==32)throw new TypeError("Invalid address data");E=p().data}if(f.hash){if(E.length>0&&!E.equals(f.hash))throw new TypeError("Hash mismatch");E=f.hash}if(f.output){if(f.output.length!==34||f.output[0]!==o.OP_0||f.output[1]!==32)throw new TypeError("Output is invalid");const _=f.output.slice(2);if(E.length>0&&!E.equals(_))throw new TypeError("Hash mismatch");E=_}if(f.redeem){if(f.redeem.network&&f.redeem.network!==g)throw new TypeError("Network mismatch");if(f.redeem.input&&f.redeem.input.length>0&&f.redeem.witness&&f.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(f.redeem.output){const _=n.decompile(f.redeem.output);if(!_||_.length<1)throw new TypeError("Redeem.output is invalid");if(f.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(n.countNonPushOnlyOPs(_)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const S=e.sha256(f.redeem.output);if(E.length>0&&!E.equals(S))throw new TypeError("Hash mismatch");E=S}if(f.redeem.input&&!n.isPushOnly(y()))throw new TypeError("Non push-only scriptSig");if(f.witness&&f.redeem.witness&&!(0,r.stacksEqual)(f.witness,f.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(f.redeem.input&&y().some(a)||f.redeem.output&&(n.decompile(f.redeem.output)||[]).some(a))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(f.witness&&f.witness.length>0){const _=f.witness[f.witness.length-1];if(f.redeem&&f.redeem.output&&!f.redeem.output.equals(_))throw new TypeError("Witness and redeem.output mismatch");if(f.witness.some(a)||(n.decompile(_)||[]).some(a))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(w,f)}return Js.p2wsh=u,Js}var Qs={},Ei={},F0;function zl(){if(F0)return Ei;F0=1,Object.defineProperty(Ei,"__esModule",{value:!0}),Ei.getEccLib=Ei.initEccLib=void 0;const e={};function t(c,a){c?c!==e.eccLib&&(a?.DANGER_DO_NOT_VERIFY_ECCLIB||i(c),e.eccLib=c):e.eccLib=c}Ei.initEccLib=t;function n(){if(!e.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return e.eccLib}Ei.getEccLib=n;const r=c=>Buffer.from(c,"hex");function i(c){s(typeof c.isXOnlyPoint=="function"),s(c.isXOnlyPoint(r("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(c.isXOnlyPoint(r("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000001"))),s(!c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000000"))),s(!c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s(typeof c.xOnlyPointAddTweak=="function"),o.forEach(a=>{const u=c.xOnlyPointAddTweak(r(a.pubkey),r(a.tweak));a.result===null?s(u===null):(s(u!==null),s(u.parity===a.parity),s(Buffer.from(u.xOnlyPubkey).equals(r(a.result))))})}function s(c){if(!c)throw new Error("ecc library invalid")}const o=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];return Ei}var ff={},At={},Tc={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var M0;function z8(){return M0||(M0=1,(function(e,t){var n=Vo(),r=n.Buffer;function i(o,c){for(var a in o)c[a]=o[a]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(i(n,t),t.Buffer=s);function s(o,c,a){return r(o,c,a)}s.prototype=Object.create(r.prototype),i(r,s),s.from=function(o,c,a){if(typeof o=="number")throw new TypeError("Argument must not be a number");return r(o,c,a)},s.alloc=function(o,c,a){if(typeof o!="number")throw new TypeError("Argument must be a number");var u=r(o);return c!==void 0?typeof a=="string"?u.fill(c,a):u.fill(c):u.fill(0),u},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n.SlowBuffer(o)}})(Tc,Tc.exports)),Tc.exports}var lf,q0;function Y8(){if(q0)return lf;q0=1;var e=z8().Buffer,t=9007199254740991;function n(o){if(o<0||o>t||o%1!==0)throw new RangeError("value out of range")}function r(o,c,a){if(n(o),c||(c=e.allocUnsafe(s(o))),!e.isBuffer(c))throw new TypeError("buffer must be a Buffer instance");return a||(a=0),o<253?(c.writeUInt8(o,a),r.bytes=1):o<=65535?(c.writeUInt8(253,a),c.writeUInt16LE(o,a+1),r.bytes=3):o<=4294967295?(c.writeUInt8(254,a),c.writeUInt32LE(o,a+1),r.bytes=5):(c.writeUInt8(255,a),c.writeUInt32LE(o>>>0,a+1),c.writeUInt32LE(o/4294967296|0,a+5),r.bytes=9),c}function i(o,c){if(!e.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");c||(c=0);var a=o.readUInt8(c);if(a<253)return i.bytes=1,a;if(a===253)return i.bytes=3,o.readUInt16LE(c+1);if(a===254)return i.bytes=5,o.readUInt32LE(c+1);i.bytes=9;var u=o.readUInt32LE(c+1),f=o.readUInt32LE(c+5),l=f*4294967296+u;return n(l),l}function s(o){return n(o),o<253?1:o<=65535?3:o<=4294967295?5:9}return lf={encode:r,decode:i,encodingLength:s},lf}var V0;function iu(){if(V0)return At;V0=1,Object.defineProperty(At,"__esModule",{value:!0}),At.BufferReader=At.BufferWriter=At.cloneBuffer=At.reverseBuffer=At.writeUInt64LE=At.readUInt64LE=At.varuint=void 0;const e=Lt(),{typeforce:t}=e,n=Y8();At.varuint=n;function r(f,l){if(typeof f!="number")throw new Error("cannot write a non-number as a number");if(f<0)throw new Error("specified a negative value for writing an unsigned value");if(f>l)throw new Error("RangeError: value out of range");if(Math.floor(f)!==f)throw new Error("value has a fractional component")}function i(f,l){const p=f.readUInt32LE(l);let y=f.readUInt32LE(l+4);return y*=4294967296,r(y+p,9007199254740991),y+p}At.readUInt64LE=i;function s(f,l,p){return r(l,9007199254740991),f.writeInt32LE(l&-1,p),f.writeUInt32LE(Math.floor(l/4294967296),p+4),p+8}At.writeUInt64LE=s;function o(f){if(f.length<1)return f;let l=f.length-1,p=0;for(let y=0;y<f.length/2;y++)p=f[y],f[y]=f[l],f[l]=p,l--;return f}At.reverseBuffer=o;function c(f){const l=Buffer.allocUnsafe(f.length);return f.copy(l),l}At.cloneBuffer=c;class a{static withCapacity(l){return new a(Buffer.alloc(l))}constructor(l,p=0){this.buffer=l,this.offset=p,t(e.tuple(e.Buffer,e.UInt32),[l,p])}writeUInt8(l){this.offset=this.buffer.writeUInt8(l,this.offset)}writeInt32(l){this.offset=this.buffer.writeInt32LE(l,this.offset)}writeUInt32(l){this.offset=this.buffer.writeUInt32LE(l,this.offset)}writeUInt64(l){this.offset=s(this.buffer,l,this.offset)}writeVarInt(l){n.encode(l,this.buffer,this.offset),this.offset+=n.encode.bytes}writeSlice(l){if(this.buffer.length<this.offset+l.length)throw new Error("Cannot write slice out of bounds");this.offset+=l.copy(this.buffer,this.offset)}writeVarSlice(l){this.writeVarInt(l.length),this.writeSlice(l)}writeVector(l){this.writeVarInt(l.length),l.forEach(p=>this.writeVarSlice(p))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}At.BufferWriter=a;class u{constructor(l,p=0){this.buffer=l,this.offset=p,t(e.tuple(e.Buffer,e.UInt32),[l,p])}readUInt8(){const l=this.buffer.readUInt8(this.offset);return this.offset++,l}readInt32(){const l=this.buffer.readInt32LE(this.offset);return this.offset+=4,l}readUInt32(){const l=this.buffer.readUInt32LE(this.offset);return this.offset+=4,l}readUInt64(){const l=i(this.buffer,this.offset);return this.offset+=8,l}readVarInt(){const l=n.decode(this.buffer,this.offset);return this.offset+=n.decode.bytes,l}readSlice(l){if(this.buffer.length<this.offset+l)throw new Error("Cannot read slice out of bounds");const p=this.buffer.slice(this.offset,this.offset+l);return this.offset+=l,p}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const l=this.readVarInt(),p=[];for(let y=0;y<l;y++)p.push(this.readVarSlice());return p}}return At.BufferReader=u,At}var $0;function Yl(){return $0||($0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Vo(),n=zl(),r=xr(),i=iu(),s=Lt();e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=w=>"left"in w&&"right"in w;function c(w,E){if(w.length<33)throw new TypeError(`The control-block length is too small. Got ${w.length}, expected min 33.`);const _=(w.length-33)/32;let S=E;for(let m=0;m<_;m++){const T=w.slice(33+32*m,65+32*m);S.compare(T)<0?S=y(S,T):S=y(T,S)}return S}e.rootHashFromPath=c;function a(w){if((0,s.isTapleaf)(w))return{hash:f(w)};const E=[a(w[0]),a(w[1])];E.sort((m,T)=>m.hash.compare(T.hash));const[_,S]=E;return{hash:y(_.hash,S.hash),left:_,right:S}}e.toHashTree=a;function u(w,E){if(o(w)){const _=u(w.left,E);if(_!==void 0)return[..._,w.right.hash];const S=u(w.right,E);if(S!==void 0)return[...S,w.left.hash]}else if(w.hash.equals(E))return[]}e.findScriptPath=u;function f(w){const E=w.version||e.LEAF_VERSION_TAPSCRIPT;return r.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([E]),g(w.output)]))}e.tapleafHash=f;function l(w,E){return r.taggedHash("TapTweak",t.Buffer.concat(E?[w,E]:[w]))}e.tapTweakHash=l;function p(w,E){if(!t.Buffer.isBuffer(w)||w.length!==32||E&&E.length!==32)return null;const _=l(w,E),S=(0,n.getEccLib)().xOnlyPointAddTweak(w,_);return!S||S.xOnlyPubkey===null?null:{parity:S.parity,x:t.Buffer.from(S.xOnlyPubkey)}}e.tweakKey=p;function y(w,E){return r.taggedHash("TapBranch",t.Buffer.concat([w,E]))}function g(w){const E=i.varuint.encodingLength(w.length),_=t.Buffer.allocUnsafe(E);return i.varuint.encode(w.length,_),t.Buffer.concat([_,w])}})(ff)),ff}var K0;function Z8(){if(K0)return Qs;K0=1,Object.defineProperty(Qs,"__esModule",{value:!0}),Qs.p2tr=void 0;const e=Vo(),t=Vn(),n=Jt(),r=Lt(),i=zl(),s=Yl(),o=ui(),c=Do(),a=Zl(),u=n.OPS,f=1,l=80;function p(y,g){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");g=Object.assign({validate:!0},g||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(34)),internalPubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),pubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),signature:r.typeforce.maybe(r.typeforce.anyOf(r.typeforce.BufferN(64),r.typeforce.BufferN(65))),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer)),scriptTree:r.typeforce.maybe(r.isTaptree),redeem:r.typeforce.maybe({output:r.typeforce.maybe(r.typeforce.Buffer),redeemVersion:r.typeforce.maybe(r.typeforce.Number),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),redeemVersion:r.typeforce.maybe(r.typeforce.Number)},y);const w=o.value(()=>(0,a.fromBech32)(y.address)),E=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===l?y.witness.slice(0,-1):y.witness.slice()}),_=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),S=y.network||t.bitcoin,m={name:"p2tr",network:S};if(o.prop(m,"address",()=>{if(!m.pubkey)return;const T=c.bech32m.toWords(m.pubkey);return T.unshift(f),c.bech32m.encode(S.bech32,T)}),o.prop(m,"hash",()=>{const T=_();if(T)return T.hash;const I=E();if(I&&I.length>1){const A=I[I.length-1],U=A[0]&r.TAPLEAF_VERSION_MASK,M=I[I.length-2],v=(0,s.tapleafHash)({output:M,version:U});return(0,s.rootHashFromPath)(A,v)}return null}),o.prop(m,"output",()=>{if(m.pubkey)return n.compile([u.OP_1,m.pubkey])}),o.prop(m,"redeemVersion",()=>y.redeemVersion?y.redeemVersion:y.redeem&&y.redeem.redeemVersion!==void 0&&y.redeem.redeemVersion!==null?y.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(m,"redeem",()=>{const T=E();if(!(!T||T.length<2))return{output:T[T.length-2],witness:T.slice(0,-2),redeemVersion:T[T.length-1][0]&r.TAPLEAF_VERSION_MASK}}),o.prop(m,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return w().data;if(m.internalPubkey){const T=(0,s.tweakKey)(m.internalPubkey,m.hash);if(T)return T.x}}),o.prop(m,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const T=E();if(T&&T.length>1)return T[T.length-1].slice(1,33)}),o.prop(m,"signature",()=>{if(y.signature)return y.signature;const T=E();if(!(!T||T.length!==1))return T[0]}),o.prop(m,"witness",()=>{if(y.witness)return y.witness;const T=_();if(T&&y.redeem&&y.redeem.output&&y.internalPubkey){const I=(0,s.tapleafHash)({output:y.redeem.output,version:m.redeemVersion}),A=(0,s.findScriptPath)(T,I);if(!A)return;const U=(0,s.tweakKey)(y.internalPubkey,T.hash);if(!U)return;const M=e.Buffer.concat([e.Buffer.from([m.redeemVersion|U.parity]),y.internalPubkey].concat(A));return[y.redeem.output,M]}if(y.signature)return[y.signature]}),g.validate){let T=e.Buffer.from([]);if(y.address){if(S&&S.bech32!==w().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(w().version!==f)throw new TypeError("Invalid address version");if(w().data.length!==32)throw new TypeError("Invalid address data");T=w().data}if(y.pubkey){if(T.length>0&&!T.equals(y.pubkey))throw new TypeError("Pubkey mismatch");T=y.pubkey}if(y.output){if(y.output.length!==34||y.output[0]!==u.OP_1||y.output[1]!==32)throw new TypeError("Output is invalid");if(T.length>0&&!T.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");T=y.output.slice(2)}if(y.internalPubkey){const U=(0,s.tweakKey)(y.internalPubkey,m.hash);if(T.length>0&&!T.equals(U.x))throw new TypeError("Pubkey mismatch");T=U.x}if(T&&T.length&&!(0,i.getEccLib)().isXOnlyPoint(T))throw new TypeError("Invalid pubkey for p2tr");const I=_();if(y.hash&&I&&!y.hash.equals(I.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&I){const U=(0,s.tapleafHash)({output:y.redeem.output,version:m.redeemVersion});if(!(0,s.findScriptPath)(I,U))throw new TypeError("Redeem script not in tree")}const A=E();if(y.redeem&&m.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==m.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(y.redeem.output){if(n.decompile(y.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(m.redeem.output&&!y.redeem.output.equals(m.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&m.redeem.witness&&!(0,r.stacksEqual)(y.redeem.witness,m.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(A&&A.length)if(A.length===1){if(y.signature&&!y.signature.equals(A[0]))throw new TypeError("Signature mismatch")}else{const U=A[A.length-1];if(U.length<33)throw new TypeError(`The control-block length is too small. Got ${U.length}, expected min 33.`);if((U.length-33)%32!==0)throw new TypeError(`The control-block length of ${U.length} is incorrect!`);const M=(U.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const v=U.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(v))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid internalPubkey for p2tr witness");const R=U[0]&r.TAPLEAF_VERSION_MASK,V=A[A.length-2],W=(0,s.tapleafHash)({output:V,version:R}),H=(0,s.rootHashFromPath)(U,W),K=(0,s.tweakKey)(v,H);if(!K)throw new TypeError("Invalid outputKey for p2tr witness");if(T.length&&!T.equals(K.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(K.parity!==(U[0]&1))throw new Error("Incorrect parity")}}return Object.assign(m,y)}return Qs.p2tr=p,Qs}var L0;function oc(){return L0||(L0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=F8();Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=M8();Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=q8();Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=W8();Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=G8();Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=D8();Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const c=X8();Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return c.p2wsh}});const a=Z8();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return a.p2tr}})})(Zu)),Zu}var j0;function Zl(){if(j0)return Wt;j0=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.toOutputScript=Wt.fromOutputScript=Wt.toBech32=Wt.toBase58Check=Wt.fromBech32=Wt.fromBase58Check=void 0;const e=Vn(),t=oc(),n=Jt(),r=Lt(),i=Do(),s=Xl(),o=40,c=2,a=16,u=2,f=80,l="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function p(m,T){const I=m.slice(2);if(I.length<c||I.length>o)throw new TypeError("Invalid program length for segwit address");const A=m[0]-f;if(A<u||A>a)throw new TypeError("Invalid version for segwit address");if(m[1]!==I.length)throw new TypeError("Invalid script for segwit address");return console.warn(l),E(I,A,T.bech32)}function y(m){const T=Buffer.from(s.decode(m));if(T.length<21)throw new TypeError(m+" is too short");if(T.length>21)throw new TypeError(m+" is too long");const I=T.readUInt8(0),A=T.slice(1);return{version:I,hash:A}}Wt.fromBase58Check=y;function g(m){let T,I;try{T=i.bech32.decode(m)}catch{}if(T){if(I=T.words[0],I!==0)throw new TypeError(m+" uses wrong encoding")}else if(T=i.bech32m.decode(m),I=T.words[0],I===0)throw new TypeError(m+" uses wrong encoding");const A=i.bech32.fromWords(T.words.slice(1));return{version:I,prefix:T.prefix,data:Buffer.from(A)}}Wt.fromBech32=g;function w(m,T){(0,r.typeforce)((0,r.tuple)(r.Hash160bit,r.UInt8),arguments);const I=Buffer.allocUnsafe(21);return I.writeUInt8(T,0),m.copy(I,1),s.encode(I)}Wt.toBase58Check=w;function E(m,T,I){const A=i.bech32.toWords(m);return A.unshift(T),T===0?i.bech32.encode(I,A):i.bech32m.encode(I,A)}Wt.toBech32=E;function _(m,T){T=T||e.bitcoin;try{return t.p2pkh({output:m,network:T}).address}catch{}try{return t.p2sh({output:m,network:T}).address}catch{}try{return t.p2wpkh({output:m,network:T}).address}catch{}try{return t.p2wsh({output:m,network:T}).address}catch{}try{return t.p2tr({output:m,network:T}).address}catch{}try{return p(m,T)}catch{}throw new Error(n.toASM(m)+" has no matching Address")}Wt.fromOutputScript=_;function S(m,T){T=T||e.bitcoin;let I,A;try{I=y(m)}catch{}if(I){if(I.version===T.pubKeyHash)return t.p2pkh({hash:I.hash}).output;if(I.version===T.scriptHash)return t.p2sh({hash:I.hash}).output}else{try{A=g(m)}catch{}if(A){if(A.prefix!==T.bech32)throw new Error(m+" has an invalid prefix");if(A.version===0){if(A.data.length===20)return t.p2wpkh({hash:A.data}).output;if(A.data.length===32)return t.p2wsh({hash:A.data}).output}else if(A.version===1){if(A.data.length===32)return t.p2tr({pubkey:A.data}).output}else if(A.version>=u&&A.version<=a&&A.data.length>=c&&A.data.length<=o)return console.warn(l),n.compile([A.version+f,A.data])}}throw new Error(m+" has no matching Script")}return Wt.toOutputScript=S,Wt}var eo={},to={},W0;function J8(){if(W0)return to;W0=1,Object.defineProperty(to,"__esModule",{value:!0}),to.fastMerkleRoot=void 0;function e(t,n){if(!Array.isArray(t))throw TypeError("Expected values Array");if(typeof n!="function")throw TypeError("Expected digest Function");let r=t.length;const i=t.concat();for(;r>1;){let s=0;for(let o=0;o<r;o+=2,++s){const c=i[o],a=o+1===r?c:i[o+1],u=Buffer.concat([c,a]);i[s]=n(u)}r=s}return i[0]}return to.fastMerkleRoot=e,to}var no={},G0;function cc(){if(G0)return no;G0=1,Object.defineProperty(no,"__esModule",{value:!0}),no.Transaction=void 0;const e=iu(),t=xr(),n=Jt(),r=Jt(),i=Lt(),{typeforce:s}=i;function o(E){const _=E.length;return e.varuint.encodingLength(_)+_}function c(E){const _=E.length;return e.varuint.encodingLength(_)+E.reduce((S,m)=>S+o(m),0)}const a=Buffer.allocUnsafe(0),u=[],f=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),l=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),p=Buffer.from("ffffffffffffffff","hex"),y={script:a,valueBuffer:p};function g(E){return E.value!==void 0}class w{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(_,S){const m=new e.BufferReader(_),T=new w;T.version=m.readInt32();const I=m.readUInt8(),A=m.readUInt8();let U=!1;I===w.ADVANCED_TRANSACTION_MARKER&&A===w.ADVANCED_TRANSACTION_FLAG?U=!0:m.offset-=2;const M=m.readVarInt();for(let R=0;R<M;++R)T.ins.push({hash:m.readSlice(32),index:m.readUInt32(),script:m.readVarSlice(),sequence:m.readUInt32(),witness:u});const v=m.readVarInt();for(let R=0;R<v;++R)T.outs.push({value:m.readUInt64(),script:m.readVarSlice()});if(U){for(let R=0;R<M;++R)T.ins[R].witness=m.readVector();if(!T.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(T.locktime=m.readUInt32(),S)return T;if(m.offset!==_.length)throw new Error("Transaction has unexpected data");return T}static fromHex(_){return w.fromBuffer(Buffer.from(_,"hex"),!1)}static isCoinbaseHash(_){s(i.Hash256bit,_);for(let S=0;S<32;++S)if(_[S]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&w.isCoinbaseHash(this.ins[0].hash)}addInput(_,S,m,T){return s(i.tuple(i.Hash256bit,i.UInt32,i.maybe(i.UInt32),i.maybe(i.Buffer)),arguments),i.Null(m)&&(m=w.DEFAULT_SEQUENCE),this.ins.push({hash:_,index:S,script:T||a,sequence:m,witness:u})-1}addOutput(_,S){return s(i.tuple(i.Buffer,i.Satoshi),arguments),this.outs.push({script:_,value:S})-1}hasWitnesses(){return this.ins.some(_=>_.witness.length!==0)}stripWitnesses(){this.ins.forEach(_=>{_.witness=u})}weight(){const _=this.byteLength(!1),S=this.byteLength(!0);return _*3+S}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(_=!0){const S=_&&this.hasWitnesses();return(S?10:8)+e.varuint.encodingLength(this.ins.length)+e.varuint.encodingLength(this.outs.length)+this.ins.reduce((m,T)=>m+40+o(T.script),0)+this.outs.reduce((m,T)=>m+8+o(T.script),0)+(S?this.ins.reduce((m,T)=>m+c(T.witness),0):0)}clone(){const _=new w;return _.version=this.version,_.locktime=this.locktime,_.ins=this.ins.map(S=>({hash:S.hash,index:S.index,script:S.script,sequence:S.sequence,witness:S.witness})),_.outs=this.outs.map(S=>({script:S.script,value:S.value})),_}hashForSignature(_,S,m){if(s(i.tuple(i.UInt32,i.Buffer,i.Number),arguments),_>=this.ins.length)return l;const T=n.compile(n.decompile(S).filter(U=>U!==r.OPS.OP_CODESEPARATOR)),I=this.clone();if((m&31)===w.SIGHASH_NONE)I.outs=[],I.ins.forEach((U,M)=>{M!==_&&(U.sequence=0)});else if((m&31)===w.SIGHASH_SINGLE){if(_>=this.outs.length)return l;I.outs.length=_+1;for(let U=0;U<_;U++)I.outs[U]=y;I.ins.forEach((U,M)=>{M!==_&&(U.sequence=0)})}m&w.SIGHASH_ANYONECANPAY?(I.ins=[I.ins[_]],I.ins[0].script=T):(I.ins.forEach(U=>{U.script=a}),I.ins[_].script=T);const A=Buffer.allocUnsafe(I.byteLength(!1)+4);return A.writeInt32LE(m,A.length-4),I.__toBuffer(A,0,!1),t.hash256(A)}hashForWitnessV1(_,S,m,T,I,A){if(s(i.tuple(i.UInt32,s.arrayOf(i.Buffer),s.arrayOf(i.Satoshi),i.UInt32),arguments),m.length!==this.ins.length||S.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const U=T===w.SIGHASH_DEFAULT?w.SIGHASH_ALL:T&w.SIGHASH_OUTPUT_MASK,v=(T&w.SIGHASH_INPUT_MASK)===w.SIGHASH_ANYONECANPAY,R=U===w.SIGHASH_NONE,V=U===w.SIGHASH_SINGLE;let W=a,H=a,K=a,N=a,L=a;if(!v){let q=e.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(P=>{q.writeSlice(P.hash),q.writeUInt32(P.index)}),W=t.sha256(q.end()),q=e.BufferWriter.withCapacity(8*this.ins.length),m.forEach(P=>q.writeUInt64(P)),H=t.sha256(q.end()),q=e.BufferWriter.withCapacity(S.map(o).reduce((P,$)=>P+$)),S.forEach(P=>q.writeVarSlice(P)),K=t.sha256(q.end()),q=e.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(P=>q.writeUInt32(P.sequence)),N=t.sha256(q.end())}if(R||V){if(V&&_<this.outs.length){const q=this.outs[_],P=e.BufferWriter.withCapacity(8+o(q.script));P.writeUInt64(q.value),P.writeVarSlice(q.script),L=t.sha256(P.end())}}else{const q=this.outs.map($=>8+o($.script)).reduce(($,G)=>$+G),P=e.BufferWriter.withCapacity(q);this.outs.forEach($=>{P.writeUInt64($.value),P.writeVarSlice($.script)}),L=t.sha256(P.end())}const F=(I?2:0)+(A?1:0),x=174-(v?49:0)-(R?32:0)+(A?32:0)+(I?37:0),O=e.BufferWriter.withCapacity(x);if(O.writeUInt8(T),O.writeInt32(this.version),O.writeUInt32(this.locktime),O.writeSlice(W),O.writeSlice(H),O.writeSlice(K),O.writeSlice(N),R||V||O.writeSlice(L),O.writeUInt8(F),v){const q=this.ins[_];O.writeSlice(q.hash),O.writeUInt32(q.index),O.writeUInt64(m[_]),O.writeVarSlice(S[_]),O.writeUInt32(q.sequence)}else O.writeUInt32(_);if(A){const q=e.BufferWriter.withCapacity(o(A));q.writeVarSlice(A),O.writeSlice(t.sha256(q.end()))}return V&&O.writeSlice(L),I&&(O.writeSlice(I),O.writeUInt8(0),O.writeUInt32(4294967295)),t.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),O.end()]))}hashForWitnessV0(_,S,m,T){s(i.tuple(i.UInt32,i.Buffer,i.Satoshi,i.UInt32),arguments);let I=Buffer.from([]),A,U=f,M=f,v=f;if(T&w.SIGHASH_ANYONECANPAY||(I=Buffer.allocUnsafe(36*this.ins.length),A=new e.BufferWriter(I,0),this.ins.forEach(V=>{A.writeSlice(V.hash),A.writeUInt32(V.index)}),M=t.hash256(I)),!(T&w.SIGHASH_ANYONECANPAY)&&(T&31)!==w.SIGHASH_SINGLE&&(T&31)!==w.SIGHASH_NONE&&(I=Buffer.allocUnsafe(4*this.ins.length),A=new e.BufferWriter(I,0),this.ins.forEach(V=>{A.writeUInt32(V.sequence)}),v=t.hash256(I)),(T&31)!==w.SIGHASH_SINGLE&&(T&31)!==w.SIGHASH_NONE){const V=this.outs.reduce((W,H)=>W+8+o(H.script),0);I=Buffer.allocUnsafe(V),A=new e.BufferWriter(I,0),this.outs.forEach(W=>{A.writeUInt64(W.value),A.writeVarSlice(W.script)}),U=t.hash256(I)}else if((T&31)===w.SIGHASH_SINGLE&&_<this.outs.length){const V=this.outs[_];I=Buffer.allocUnsafe(8+o(V.script)),A=new e.BufferWriter(I,0),A.writeUInt64(V.value),A.writeVarSlice(V.script),U=t.hash256(I)}I=Buffer.allocUnsafe(156+o(S)),A=new e.BufferWriter(I,0);const R=this.ins[_];return A.writeInt32(this.version),A.writeSlice(M),A.writeSlice(v),A.writeSlice(R.hash),A.writeUInt32(R.index),A.writeVarSlice(S),A.writeUInt64(m),A.writeUInt32(R.sequence),A.writeSlice(U),A.writeUInt32(this.locktime),A.writeUInt32(T),t.hash256(I)}getHash(_){return _&&this.isCoinbase()?Buffer.alloc(32,0):t.hash256(this.__toBuffer(void 0,void 0,_))}getId(){return(0,e.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(_,S){return this.__toBuffer(_,S,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(_,S){s(i.tuple(i.Number,i.Buffer),arguments),this.ins[_].script=S}setWitness(_,S){s(i.tuple(i.Number,[i.Buffer]),arguments),this.ins[_].witness=S}__toBuffer(_,S,m=!1){_||(_=Buffer.allocUnsafe(this.byteLength(m)));const T=new e.BufferWriter(_,S||0);T.writeInt32(this.version);const I=m&&this.hasWitnesses();return I&&(T.writeUInt8(w.ADVANCED_TRANSACTION_MARKER),T.writeUInt8(w.ADVANCED_TRANSACTION_FLAG)),T.writeVarInt(this.ins.length),this.ins.forEach(A=>{T.writeSlice(A.hash),T.writeUInt32(A.index),T.writeVarSlice(A.script),T.writeUInt32(A.sequence)}),T.writeVarInt(this.outs.length),this.outs.forEach(A=>{g(A)?T.writeUInt64(A.value):T.writeSlice(A.valueBuffer),T.writeVarSlice(A.script)}),I&&this.ins.forEach(A=>{T.writeVector(A.witness)}),T.writeUInt32(this.locktime),S!==void 0?_.slice(S,T.offset):_}}return no.Transaction=w,w.DEFAULT_SEQUENCE=4294967295,w.SIGHASH_DEFAULT=0,w.SIGHASH_ALL=1,w.SIGHASH_NONE=2,w.SIGHASH_SINGLE=3,w.SIGHASH_ANYONECANPAY=128,w.SIGHASH_OUTPUT_MASK=3,w.SIGHASH_INPUT_MASK=128,w.ADVANCED_TRANSACTION_MARKER=0,w.ADVANCED_TRANSACTION_FLAG=1,no}var D0;function Q8(){if(D0)return eo;D0=1,Object.defineProperty(eo,"__esModule",{value:!0}),eo.Block=void 0;const e=iu(),t=xr(),n=J8(),r=cc(),i=Lt(),{typeforce:s}=i,o=new TypeError("Cannot compute merkle root for zero transactions"),c=new TypeError("Cannot compute witness commit for non-segwit block");class a{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(p){if(p.length<80)throw new Error("Buffer too small (< 80 bytes)");const y=new e.BufferReader(p),g=new a;if(g.version=y.readInt32(),g.prevHash=y.readSlice(32),g.merkleRoot=y.readSlice(32),g.timestamp=y.readUInt32(),g.bits=y.readUInt32(),g.nonce=y.readUInt32(),p.length===80)return g;const w=()=>{const S=r.Transaction.fromBuffer(y.buffer.slice(y.offset),!0);return y.offset+=S.byteLength(),S},E=y.readVarInt();g.transactions=[];for(let S=0;S<E;++S){const m=w();g.transactions.push(m)}const _=g.getWitnessCommit();return _&&(g.witnessCommit=_),g}static fromHex(p){return a.fromBuffer(Buffer.from(p,"hex"))}static calculateTarget(p){const y=((p&4278190080)>>24)-3,g=p&8388607,w=Buffer.alloc(32,0);return w.writeUIntBE(g,29-y,3),w}static calculateMerkleRoot(p,y){if(s([{getHash:i.Function}],p),p.length===0)throw o;if(y&&!u(p))throw c;const g=p.map(E=>E.getHash(y)),w=(0,n.fastMerkleRoot)(g,t.hash256);return y?t.hash256(Buffer.concat([w,p[0].ins[0].witness[0]])):w}getWitnessCommit(){if(!u(this.transactions))return null;const p=this.transactions[0].outs.filter(g=>g.script.slice(0,6).equals(Buffer.from("6a24aa21a9ed","hex"))).map(g=>g.script.slice(6,38));if(p.length===0)return null;const y=p[p.length-1];return y instanceof Buffer&&y.length===32?y:null}hasWitnessCommit(){return this.witnessCommit instanceof Buffer&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return f(this.transactions)}weight(){const p=this.byteLength(!1,!1),y=this.byteLength(!1,!0);return p*3+y}byteLength(p,y=!0){return p||!this.transactions?80:80+e.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((g,w)=>g+w.byteLength(y),0)}getHash(){return t.hash256(this.toBuffer(!0))}getId(){return(0,e.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const p=new Date(0);return p.setUTCSeconds(this.timestamp),p}toBuffer(p){const y=Buffer.allocUnsafe(this.byteLength(p)),g=new e.BufferWriter(y);return g.writeInt32(this.version),g.writeSlice(this.prevHash),g.writeSlice(this.merkleRoot),g.writeUInt32(this.timestamp),g.writeUInt32(this.bits),g.writeUInt32(this.nonce),p||!this.transactions||(e.varuint.encode(this.transactions.length,y,g.offset),g.offset+=e.varuint.encode.bytes,this.transactions.forEach(w=>{const E=w.byteLength();w.toBuffer(y,g.offset),g.offset+=E})),y}toHex(p){return this.toBuffer(p).toString("hex")}checkTxRoots(){const p=this.hasWitnessCommit();return!p&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(p?this.__checkWitnessCommit():!0)}checkProofOfWork(){const p=(0,e.reverseBuffer)(this.getHash()),y=a.calculateTarget(this.bits);return p.compare(y)<=0}__checkMerkleRoot(){if(!this.transactions)throw o;const p=a.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(p)===0}__checkWitnessCommit(){if(!this.transactions)throw o;if(!this.hasWitnessCommit())throw c;const p=a.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(p)===0}}eo.Block=a;function u(l){return l instanceof Array&&l[0]&&l[0].ins&&l[0].ins instanceof Array&&l[0].ins[0]&&l[0].ins[0].witness&&l[0].ins[0].witness instanceof Array&&l[0].ins[0].witness.length>0}function f(l){return l instanceof Array&&l.some(p=>typeof p=="object"&&p.ins instanceof Array&&p.ins.some(y=>typeof y=="object"&&y.witness instanceof Array&&y.witness.length>0))}return eo}var ro={},xc={},Ac={},hf={},Qi={},es={},df={},X0;function Ut(){return X0||(X0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),(function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(df)),df}var Nr={},z0;function ex(){if(z0)return Nr;z0=1,Object.defineProperty(Nr,"__esModule",{value:!0});const e=Ut(),t=o=>[...Array(o).keys()];function n(o){if(o.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+o.key.toString("hex"));if(o.key.length!==79||![2,3].includes(o.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+o.key.toString("hex"));if(o.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const c=o.key.slice(1),a={masterFingerprint:o.value.slice(0,4),extendedPubkey:c,path:"m"};for(const u of t(o.value.length/4-1)){const f=o.value.readUInt32LE(u*4+4),l=!!(f&2147483648),p=f&2147483647;a.path+="/"+p.toString(10)+(l?"'":"")}return a}Nr.decode=n;function r(o){const c=Buffer.from([e.GlobalTypes.GLOBAL_XPUB]),a=Buffer.concat([c,o.extendedPubkey]),u=o.path.split("/"),f=Buffer.allocUnsafe(u.length*4);o.masterFingerprint.copy(f,0);let l=4;return u.slice(1).forEach(p=>{const y=p.slice(-1)==="'";let g=2147483647&parseInt(y?p.slice(0,-1):p,10);y&&(g+=2147483648),f.writeUInt32LE(g,l),l+=4}),{key:a,value:f}}Nr.encode=r,Nr.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function i(o){const c=o.extendedPubkey,a=o.masterFingerprint,u=o.path;return Buffer.isBuffer(c)&&c.length===78&&[2,3].indexOf(c[45])>-1&&Buffer.isBuffer(a)&&a.length===4&&typeof u=="string"&&!!u.match(/^m(\/\d+'?)*$/)}Nr.check=i;function s(o,c,a){const u=c.extendedPubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.extendedPubkey.equals(c.extendedPubkey)).length===0)}return Nr.canAddToArray=s,Nr}var vc={},Y0;function tx(){if(Y0)return vc;Y0=1,Object.defineProperty(vc,"__esModule",{value:!0});const e=Ut();function t(n){return{key:Buffer.from([e.GlobalTypes.UNSIGNED_TX]),value:n.toBuffer()}}return vc.encode=t,vc}var Ur={},Z0;function nx(){if(Z0)return Ur;Z0=1,Object.defineProperty(Ur,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+s.key.toString("hex"));return s.value}Ur.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTSIG]),value:s}}Ur.encode=n,Ur.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Ur.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptSig===void 0}return Ur.canAdd=i,Ur}var Rr={},J0;function rx(){if(J0)return Rr;J0=1,Object.defineProperty(Rr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+s.key.toString("hex"));return s.value}Rr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:s}}Rr.encode=n,Rr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Rr.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptWitness===void 0}return Rr.canAdd=i,Rr}var Cr={},Q0;function ix(){if(Q0)return Cr;Q0=1,Object.defineProperty(Cr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+s.key.toString("hex"));return s.value}Cr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.NON_WITNESS_UTXO]),value:s}}Cr.encode=n,Cr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Cr.check=r;function i(s,o){return!!s&&!!o&&s.nonWitnessUtxo===void 0}return Cr.canAdd=i,Cr}var Hr={},ep;function sx(){if(ep)return Hr;ep=1,Object.defineProperty(Hr,"__esModule",{value:!0});const e=Ut();function t(o){if(o.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+o.key.toString("hex"));if(!(o.key.length===34||o.key.length===66)||![2,3,4].includes(o.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+o.key.toString("hex"));return{pubkey:o.key.slice(1),signature:o.value}}Hr.decode=t;function n(o){const c=Buffer.from([e.InputTypes.PARTIAL_SIG]);return{key:Buffer.concat([c,o.pubkey]),value:o.signature}}Hr.encode=n,Hr.expected="{ pubkey: Buffer; signature: Buffer; }";function r(o){return Buffer.isBuffer(o.pubkey)&&Buffer.isBuffer(o.signature)&&[33,65].includes(o.pubkey.length)&&[2,3,4].includes(o.pubkey[0])&&i(o.signature)}Hr.check=r;function i(o){if(!Buffer.isBuffer(o)||o.length<9||o[0]!==48||o.length!==o[1]+3||o[2]!==2)return!1;const c=o[3];if(c>33||c<1||o[3+c+1]!==2)return!1;const a=o[3+c+2];return!(a>33||a<1||o.length!==3+c+2+a+2)}function s(o,c,a){const u=c.pubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.pubkey.equals(c.pubkey)).length===0)}return Hr.canAddToArray=s,Hr}var Fr={},tp;function ox(){if(tp)return Fr;tp=1,Object.defineProperty(Fr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+s.key.toString("hex"));return s.value.toString("utf8")}Fr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.POR_COMMITMENT]),value:Buffer.from(s,"utf8")}}Fr.encode=n,Fr.expected="string";function r(s){return typeof s=="string"}Fr.check=r;function i(s,o){return!!s&&!!o&&s.porCommitment===void 0}return Fr.canAdd=i,Fr}var Mr={},np;function cx(){if(np)return Mr;np=1,Object.defineProperty(Mr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+s.key.toString("hex"));return s.value.readUInt32LE(0)}Mr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.SIGHASH_TYPE]),c=Buffer.allocUnsafe(4);return c.writeUInt32LE(s,0),{key:o,value:c}}Mr.encode=n,Mr.expected="number";function r(s){return typeof s=="number"}Mr.check=r;function i(s,o){return!!s&&!!o&&s.sighashType===void 0}return Mr.canAdd=i,Mr}var qr={},rp;function ax(){if(rp)return qr;rp=1,Object.defineProperty(qr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_KEY_SIG||s.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return s.value}qr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_KEY_SIG]),value:s}}qr.encode=n,qr.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&(s.length===64||s.length===65)}qr.check=r;function i(s,o){return!!s&&!!o&&s.tapKeySig===void 0}return qr.canAdd=i,qr}var Vr={},ip;function ux(){if(ip)return Vr;ip=1,Object.defineProperty(Vr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+s.key.toString("hex"));if((s.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+s.key.toString("hex"));const o=s.value[s.value.length-1];if((s.key[1]&254)!==o)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+s.key.toString("hex"));const c=s.value.slice(0,-1);return{controlBlock:s.key.slice(1),script:c,leafVersion:o}}Vr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_LEAF_SCRIPT]),c=Buffer.from([s.leafVersion]);return{key:Buffer.concat([o,s.controlBlock]),value:Buffer.concat([s.script,c])}}Vr.encode=n,Vr.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function r(s){return Buffer.isBuffer(s.controlBlock)&&(s.controlBlock.length-1)%32===0&&(s.controlBlock[0]&254)===s.leafVersion&&Buffer.isBuffer(s.script)}Vr.check=r;function i(s,o,c){const a=o.controlBlock.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.controlBlock.equals(o.controlBlock)).length===0)}return Vr.canAddToArray=i,Vr}var $r={},sp;function fx(){if(sp)return $r;sp=1,Object.defineProperty($r,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||s.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return s.value}$r.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_MERKLE_ROOT]),value:s}}$r.encode=n,$r.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&s.length===32}$r.check=r;function i(s,o){return!!s&&!!o&&s.tapMerkleRoot===void 0}return $r.canAdd=i,$r}var Kr={},op;function lx(){if(op)return Kr;op=1,Object.defineProperty(Kr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+s.key.toString("hex"));if(s.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+s.key.toString("hex"));if(s.value.length!==64&&s.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+s.key.toString("hex"));const o=s.key.slice(1,33),c=s.key.slice(33);return{pubkey:o,leafHash:c,signature:s.value}}Kr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:Buffer.concat([o,s.pubkey,s.leafHash]),value:s.signature}}Kr.encode=n,Kr.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function r(s){return Buffer.isBuffer(s.pubkey)&&Buffer.isBuffer(s.leafHash)&&Buffer.isBuffer(s.signature)&&s.pubkey.length===32&&s.leafHash.length===32&&(s.signature.length===64||s.signature.length===65)}Kr.check=r;function i(s,o,c){const a=o.pubkey.toString("hex")+o.leafHash.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.pubkey.equals(o.pubkey)&&u.leafHash.equals(o.leafHash)).length===0)}return Kr.canAddToArray=i,Kr}var Lr={},ir={},ts={},cp;function Di(){if(cp)return ts;cp=1,Object.defineProperty(ts,"__esModule",{value:!0});const e=9007199254740991;function t(s){if(s<0||s>e||s%1!==0)throw new RangeError("value out of range")}function n(s,o,c){if(t(s),o||(o=Buffer.allocUnsafe(i(s))),!Buffer.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");return c||(c=0),s<253?(o.writeUInt8(s,c),Object.assign(n,{bytes:1})):s<=65535?(o.writeUInt8(253,c),o.writeUInt16LE(s,c+1),Object.assign(n,{bytes:3})):s<=4294967295?(o.writeUInt8(254,c),o.writeUInt32LE(s,c+1),Object.assign(n,{bytes:5})):(o.writeUInt8(255,c),o.writeUInt32LE(s>>>0,c+1),o.writeUInt32LE(s/4294967296|0,c+5),Object.assign(n,{bytes:9})),o}ts.encode=n;function r(s,o){if(!Buffer.isBuffer(s))throw new TypeError("buffer must be a Buffer instance");o||(o=0);const c=s.readUInt8(o);if(c<253)return Object.assign(r,{bytes:1}),c;if(c===253)return Object.assign(r,{bytes:3}),s.readUInt16LE(o+1);if(c===254)return Object.assign(r,{bytes:5}),s.readUInt32LE(o+1);{Object.assign(r,{bytes:9});const a=s.readUInt32LE(o+1),f=s.readUInt32LE(o+5)*4294967296+a;return t(f),f}}ts.decode=r;function i(s){return t(s),s<253?1:s<=65535?3:s<=4294967295?5:9}return ts.encodingLength=i,ts}var ap;function Jl(){if(ap)return ir;ap=1,Object.defineProperty(ir,"__esModule",{value:!0});const e=Di();ir.range=c=>[...Array(c).keys()];function t(c){if(c.length<1)return c;let a=c.length-1,u=0;for(let f=0;f<c.length/2;f++)u=c[f],c[f]=c[a],c[a]=u,a--;return c}ir.reverseBuffer=t;function n(c){const a=c.map(r);return a.push(Buffer.from([0])),Buffer.concat(a)}ir.keyValsToBuffer=n;function r(c){const a=c.key.length,u=c.value.length,f=e.encodingLength(a),l=e.encodingLength(u),p=Buffer.allocUnsafe(f+a+l+u);return e.encode(a,p,0),c.key.copy(p,f),e.encode(u,p,f+a),c.value.copy(p,f+a+l),p}ir.keyValToBuffer=r;function i(c,a){if(typeof c!="number")throw new Error("cannot write a non-number as a number");if(c<0)throw new Error("specified a negative value for writing an unsigned value");if(c>a)throw new Error("RangeError: value out of range");if(Math.floor(c)!==c)throw new Error("value has a fractional component")}function s(c,a){const u=c.readUInt32LE(a);let f=c.readUInt32LE(a+4);return f*=4294967296,i(f+u,9007199254740991),f+u}ir.readUInt64LE=s;function o(c,a,u){return i(a,9007199254740991),c.writeInt32LE(a&-1,u),c.writeUInt32LE(Math.floor(a/4294967296),u+4),u+8}return ir.writeUInt64LE=o,ir}var up;function hx(){if(up)return Lr;up=1,Object.defineProperty(Lr,"__esModule",{value:!0});const e=Ut(),t=Jl(),n=Di();function r(c){if(c.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+c.key.toString("hex"));const a=t.readUInt64LE(c.value,0);let u=8;const f=n.decode(c.value,u);u+=n.encodingLength(f);const l=c.value.slice(u);if(l.length!==f)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:l,value:a}}Lr.decode=r;function i(c){const{script:a,value:u}=c,f=n.encodingLength(a.length),l=Buffer.allocUnsafe(8+f+a.length);return t.writeUInt64LE(l,u,0),n.encode(a.length,l,8),a.copy(l,8+f),{key:Buffer.from([e.InputTypes.WITNESS_UTXO]),value:l}}Lr.encode=i,Lr.expected="{ script: Buffer; value: number; }";function s(c){return Buffer.isBuffer(c.script)&&typeof c.value=="number"}Lr.check=s;function o(c,a){return!!c&&!!a&&c.witnessUtxo===void 0}return Lr.canAdd=o,Lr}var jr={},fp;function dx(){if(fp)return jr;fp=1,Object.defineProperty(jr,"__esModule",{value:!0});const e=Ut(),t=Di();function n(o){if(o.key[0]!==e.OutputTypes.TAP_TREE||o.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+o.key.toString("hex"));let c=0;const a=[];for(;c<o.value.length;){const u=o.value[c++],f=o.value[c++],l=t.decode(o.value,c);c+=t.encodingLength(l),a.push({depth:u,leafVersion:f,script:o.value.slice(c,c+l)}),c+=l}return{leaves:a}}jr.decode=n;function r(o){const c=Buffer.from([e.OutputTypes.TAP_TREE]),a=[].concat(...o.leaves.map(u=>[Buffer.of(u.depth,u.leafVersion),t.encode(u.script.length),u.script]));return{key:c,value:Buffer.concat(a)}}jr.encode=r,jr.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function i(o){return Array.isArray(o.leaves)&&o.leaves.every(c=>c.depth>=0&&c.depth<=128&&(c.leafVersion&254)===c.leafVersion&&Buffer.isBuffer(c.script))}jr.check=i;function s(o,c){return!!o&&!!c&&o.tapTree===void 0}return jr.canAdd=s,jr}var Bc={},lp;function iw(){if(lp)return Bc;lp=1,Object.defineProperty(Bc,"__esModule",{value:!0});const e=r=>[...Array(r).keys()],t=r=>r.length===33&&[2,3].includes(r[0])||r.length===65&&r[0]===4;function n(r,i=t){function s(f){if(f.key[0]!==r)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+f.key.toString("hex"));const l=f.key.slice(1);if(!i(l))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+f.key.toString("hex"));if(f.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const p={masterFingerprint:f.value.slice(0,4),pubkey:l,path:"m"};for(const y of e(f.value.length/4-1)){const g=f.value.readUInt32LE(y*4+4),w=!!(g&2147483648),E=g&2147483647;p.path+="/"+E.toString(10)+(w?"'":"")}return p}function o(f){const l=Buffer.from([r]),p=Buffer.concat([l,f.pubkey]),y=f.path.split("/"),g=Buffer.allocUnsafe(y.length*4);f.masterFingerprint.copy(g,0);let w=4;return y.slice(1).forEach(E=>{const _=E.slice(-1)==="'";let S=2147483647&parseInt(_?E.slice(0,-1):E,10);_&&(S+=2147483648),g.writeUInt32LE(S,w),w+=4}),{key:p,value:g}}const c="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function a(f){return Buffer.isBuffer(f.pubkey)&&Buffer.isBuffer(f.masterFingerprint)&&typeof f.path=="string"&&i(f.pubkey)&&f.masterFingerprint.length===4}function u(f,l,p){const y=l.pubkey.toString("hex");return p.has(y)?!1:(p.add(y),f.filter(g=>g.pubkey.equals(l.pubkey)).length===0)}return{decode:s,encode:o,check:a,expected:c,canAddToArray:u}}return Bc.makeConverter=n,Bc}var Ic={},hp;function px(){if(hp)return Ic;hp=1,Object.defineProperty(Ic,"__esModule",{value:!0});function e(t){return n;function n(r){let i;if(t.includes(r.key[0])&&(i=r.key.slice(1),!(i.length===33||i.length===65)||![2,3,4].includes(i[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return i}}return Ic.makeChecker=e,Ic}var Oc={},dp;function yx(){if(dp)return Oc;dp=1,Object.defineProperty(Oc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.redeemScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Oc.makeConverter=e,Oc}var Pc={},pp;function gx(){if(pp)return Pc;pp=1,Object.defineProperty(Pc,"__esModule",{value:!0});const e=Di(),t=iw(),n=i=>i.length===32;function r(i){const s=t.makeConverter(i,n);function o(f){const l=e.decode(f.value),p=e.encodingLength(l),y=s.decode({key:f.key,value:f.value.slice(p+l*32)}),g=new Array(l);for(let w=0,E=p;w<l;w++,E+=32)g[w]=f.value.slice(E,E+32);return Object.assign({},y,{leafHashes:g})}function c(f){const l=s.encode(f),p=e.encodingLength(f.leafHashes.length),y=Buffer.allocUnsafe(p);e.encode(f.leafHashes.length,y);const g=Buffer.concat([y,...f.leafHashes,l.value]);return Object.assign({},l,{value:g})}const a="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function u(f){return Array.isArray(f.leafHashes)&&f.leafHashes.every(l=>Buffer.isBuffer(l)&&l.length===32)&&s.check(f)}return{decode:o,encode:c,check:u,expected:a,canAddToArray:s.canAddToArray}}return Pc.makeConverter=r,Pc}var kc={},yp;function wx(){if(yp)return kc;yp=1,Object.defineProperty(kc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t||c.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+c.key.toString("hex"));if(c.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)&&c.length===32}function o(c,a){return!!c&&!!a&&c.tapInternalKey===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return kc.makeConverter=e,kc}var Nc={},gp;function mx(){if(gp)return Nc;gp=1,Object.defineProperty(Nc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.witnessScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Nc.makeConverter=e,Nc}var wp;function Ql(){if(wp)return es;wp=1,Object.defineProperty(es,"__esModule",{value:!0});const e=Ut(),t=ex(),n=tx(),r=nx(),i=rx(),s=ix(),o=sx(),c=ox(),a=cx(),u=ax(),f=ux(),l=fx(),p=lx(),y=hx(),g=dx(),w=iw(),E=px(),_=yx(),S=gx(),m=wx(),T=mx(),I={unsignedTx:n,globalXpub:t,checkPubkey:E.makeChecker([])};es.globals=I;const A={nonWitnessUtxo:s,partialSig:o,sighashType:a,finalScriptSig:r,finalScriptWitness:i,porCommitment:c,witnessUtxo:y,bip32Derivation:w.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:u,tapScriptSig:p,tapLeafScript:f,tapBip32Derivation:S.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:m.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:l};es.inputs=A;const U={bip32Derivation:w.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:S.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:g,tapInternalKey:m.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return es.outputs=U,es}var mp;function bx(){if(mp)return Qi;mp=1,Object.defineProperty(Qi,"__esModule",{value:!0});const e=Ql(),t=Jl(),n=Di(),r=Ut();function i(c,a){let u=0;function f(){const U=n.decode(c,u);u+=n.encodingLength(U);const M=c.slice(u,u+U);return u+=U,M}function l(){const U=c.readUInt32BE(u);return u+=4,U}function p(){const U=c.readUInt8(u);return u+=1,U}function y(){const U=f(),M=f();return{key:U,value:M}}function g(){if(u>=c.length)throw new Error("Format Error: Unexpected End of PSBT");const U=c.readUInt8(u)===0;return U&&u++,U}if(l()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(p()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const w=[],E={};for(;!g();){const U=y(),M=U.key.toString("hex");if(E[M])throw new Error("Format Error: Keys must be unique for global keymap: key "+M);E[M]=1,w.push(U)}const _=w.filter(U=>U.key[0]===r.GlobalTypes.UNSIGNED_TX);if(_.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const S=a(_[0].value),{inputCount:m,outputCount:T}=S.getInputOutputCounts(),I=[],A=[];for(const U of t.range(m)){const M={},v=[];for(;!g();){const R=y(),V=R.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each input: input index "+U+" key "+V);M[V]=1,v.push(R)}I.push(v)}for(const U of t.range(T)){const M={},v=[];for(;!g();){const R=y(),V=R.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each output: output index "+U+" key "+V);M[V]=1,v.push(R)}A.push(v)}return o(S,{globalMapKeyVals:w,inputKeyVals:I,outputKeyVals:A})}Qi.psbtFromBuffer=i;function s(c,a,u){if(!a.equals(Buffer.from([u])))throw new Error(`Format Error: Invalid ${c} key: ${a.toString("hex")}`)}Qi.checkKeyBuffer=s;function o(c,{globalMapKeyVals:a,inputKeyVals:u,outputKeyVals:f}){const l={unsignedTx:c};let p=0;for(const _ of a)switch(_.key[0]){case r.GlobalTypes.UNSIGNED_TX:if(s("global",_.key,r.GlobalTypes.UNSIGNED_TX),p>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");p++;break;case r.GlobalTypes.GLOBAL_XPUB:l.globalXpub===void 0&&(l.globalXpub=[]),l.globalXpub.push(e.globals.globalXpub.decode(_));break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(_)}const y=u.length,g=f.length,w=[],E=[];for(const _ of t.range(y)){const S={};for(const m of u[_])switch(e.inputs.checkPubkey(m),m.key[0]){case r.InputTypes.NON_WITNESS_UTXO:if(s("input",m.key,r.InputTypes.NON_WITNESS_UTXO),S.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");S.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(m);break;case r.InputTypes.WITNESS_UTXO:if(s("input",m.key,r.InputTypes.WITNESS_UTXO),S.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");S.witnessUtxo=e.inputs.witnessUtxo.decode(m);break;case r.InputTypes.PARTIAL_SIG:S.partialSig===void 0&&(S.partialSig=[]),S.partialSig.push(e.inputs.partialSig.decode(m));break;case r.InputTypes.SIGHASH_TYPE:if(s("input",m.key,r.InputTypes.SIGHASH_TYPE),S.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");S.sighashType=e.inputs.sighashType.decode(m);break;case r.InputTypes.REDEEM_SCRIPT:if(s("input",m.key,r.InputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");S.redeemScript=e.inputs.redeemScript.decode(m);break;case r.InputTypes.WITNESS_SCRIPT:if(s("input",m.key,r.InputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");S.witnessScript=e.inputs.witnessScript.decode(m);break;case r.InputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.inputs.bip32Derivation.decode(m));break;case r.InputTypes.FINAL_SCRIPTSIG:s("input",m.key,r.InputTypes.FINAL_SCRIPTSIG),S.finalScriptSig=e.inputs.finalScriptSig.decode(m);break;case r.InputTypes.FINAL_SCRIPTWITNESS:s("input",m.key,r.InputTypes.FINAL_SCRIPTWITNESS),S.finalScriptWitness=e.inputs.finalScriptWitness.decode(m);break;case r.InputTypes.POR_COMMITMENT:s("input",m.key,r.InputTypes.POR_COMMITMENT),S.porCommitment=e.inputs.porCommitment.decode(m);break;case r.InputTypes.TAP_KEY_SIG:s("input",m.key,r.InputTypes.TAP_KEY_SIG),S.tapKeySig=e.inputs.tapKeySig.decode(m);break;case r.InputTypes.TAP_SCRIPT_SIG:S.tapScriptSig===void 0&&(S.tapScriptSig=[]),S.tapScriptSig.push(e.inputs.tapScriptSig.decode(m));break;case r.InputTypes.TAP_LEAF_SCRIPT:S.tapLeafScript===void 0&&(S.tapLeafScript=[]),S.tapLeafScript.push(e.inputs.tapLeafScript.decode(m));break;case r.InputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(m));break;case r.InputTypes.TAP_INTERNAL_KEY:s("input",m.key,r.InputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.inputs.tapInternalKey.decode(m);break;case r.InputTypes.TAP_MERKLE_ROOT:s("input",m.key,r.InputTypes.TAP_MERKLE_ROOT),S.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(m);break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(m)}w.push(S)}for(const _ of t.range(g)){const S={};for(const m of f[_])switch(e.outputs.checkPubkey(m),m.key[0]){case r.OutputTypes.REDEEM_SCRIPT:if(s("output",m.key,r.OutputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");S.redeemScript=e.outputs.redeemScript.decode(m);break;case r.OutputTypes.WITNESS_SCRIPT:if(s("output",m.key,r.OutputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");S.witnessScript=e.outputs.witnessScript.decode(m);break;case r.OutputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.outputs.bip32Derivation.decode(m));break;case r.OutputTypes.TAP_INTERNAL_KEY:s("output",m.key,r.OutputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.outputs.tapInternalKey.decode(m);break;case r.OutputTypes.TAP_TREE:s("output",m.key,r.OutputTypes.TAP_TREE),S.tapTree=e.outputs.tapTree.decode(m);break;case r.OutputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(m));break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(m)}E.push(S)}return{globalMap:l,inputs:w,outputs:E}}return Qi.psbtFromKeyVals=o,Qi}var io={},bp;function Ex(){if(bp)return io;bp=1,Object.defineProperty(io,"__esModule",{value:!0});const e=Ql(),t=Jl();function n({globalMap:o,inputs:c,outputs:a}){const{globalKeyVals:u,inputKeyVals:f,outputKeyVals:l}=s({globalMap:o,inputs:c,outputs:a}),p=t.keyValsToBuffer(u),y=_=>_.length===0?[Buffer.from([0])]:_.map(t.keyValsToBuffer),g=y(f),w=y(l),E=Buffer.allocUnsafe(5);return E.writeUIntBE(482972169471,0,5),Buffer.concat([E,p].concat(g,w))}io.psbtToBuffer=n;const r=(o,c)=>o.key.compare(c.key);function i(o,c){const a=new Set,u=Object.entries(o).reduce((l,[p,y])=>{if(p==="unknownKeyVals")return l;const g=c[p];if(g===void 0)return l;const w=(Array.isArray(y)?y:[y]).map(g.encode);return w.map(_=>_.key.toString("hex")).forEach(_=>{if(a.has(_))throw new Error("Serialize Error: Duplicate key: "+_);a.add(_)}),l.concat(w)},[]),f=o.unknownKeyVals?o.unknownKeyVals.filter(l=>!a.has(l.key.toString("hex"))):[];return u.concat(f).sort(r)}function s({globalMap:o,inputs:c,outputs:a}){return{globalKeyVals:i(o,e.globals),inputKeyVals:c.map(u=>i(u,e.inputs)),outputKeyVals:a.map(u=>i(u,e.outputs))}}return io.psbtToKeyVals=s,io}var Ep;function sw(){return Ep||(Ep=1,(function(e){function t(n){for(var r in n)e.hasOwnProperty(r)||(e[r]=n[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(bx()),t(Ex())})(hf)),hf}var _p;function _x(){if(_p)return Ac;_p=1,Object.defineProperty(Ac,"__esModule",{value:!0});const e=sw();function t(s){const o=s[0],c=e.psbtToKeyVals(o),a=s.slice(1);if(a.length===0)throw new Error("Combine: Nothing to combine");const u=r(o);if(u===void 0)throw new Error("Combine: Self missing transaction");const f=i(c.globalKeyVals),l=c.inputKeyVals.map(i),p=c.outputKeyVals.map(i);for(const y of a){const g=r(y);if(g===void 0||!g.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const w=e.psbtToKeyVals(y);i(w.globalKeyVals).forEach(n(f,c.globalKeyVals,w.globalKeyVals)),w.inputKeyVals.map(i).forEach((m,T)=>m.forEach(n(l[T],c.inputKeyVals[T],w.inputKeyVals[T]))),w.outputKeyVals.map(i).forEach((m,T)=>m.forEach(n(p[T],c.outputKeyVals[T],w.outputKeyVals[T])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:c.globalKeyVals,inputKeyVals:c.inputKeyVals,outputKeyVals:c.outputKeyVals})}Ac.combine=t;function n(s,o,c){return a=>{if(s.has(a))return;const u=c.filter(f=>f.key.toString("hex")===a)[0];o.push(u),s.add(a)}}function r(s){return s.globalMap.unsignedTx}function i(s){const o=new Set;return s.forEach(c=>{const a=c.key.toString("hex");if(o.has(a))throw new Error("Combine: KeyValue Map keys should be unique");o.add(a)}),o}return Ac}var pf={},Sp;function ow(){return Sp||(Sp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=Ql();function n(y,g){const w=y[g];if(w===void 0)throw new Error(`No input #${g}`);return w}e.checkForInput=n;function r(y,g){const w=y[g];if(w===void 0)throw new Error(`No output #${g}`);return w}e.checkForOutput=r;function i(y,g,w){if(y.key[0]<w)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(g&&g.filter(E=>E.key.equals(y.key)).length!==0)throw new Error(`Duplicate Key: ${y.key.toString("hex")}`)}e.checkHasKey=i;function s(y){let g=0;return Object.keys(y).forEach(w=>{Number(isNaN(Number(w)))&&g++}),g}e.getEnumLength=s;function o(y,g){let w=!1;if(g.nonWitnessUtxo||g.witnessUtxo){const E=!!g.redeemScript,_=!!g.witnessScript,S=!E||!!g.finalScriptSig,m=!_||!!g.finalScriptWitness,T=!!g.finalScriptSig||!!g.finalScriptWitness;w=S&&m&&T}if(w===!1)throw new Error(`Input #${y} has too much or too little data to clean`)}e.inputCheckUncleanFinalized=o;function c(y,g,w,E){throw new Error(`Data for ${y} key ${g} is incorrect: Expected ${w} and got ${JSON.stringify(E)}`)}function a(y){return(g,w)=>{for(const E of Object.keys(g)){const _=g[E],{canAdd:S,canAddToArray:m,check:T,expected:I}=t[y+"s"][E]||{},A=!!m;if(T)if(A){if(!Array.isArray(_)||w[E]&&!Array.isArray(w[E]))throw new Error(`Key type ${E} must be an array`);_.every(T)||c(y,E,I,_);const U=w[E]||[],M=new Set;if(!_.every(v=>m(U,v,M)))throw new Error("Can not add duplicate data to array");w[E]=U.concat(_)}else{if(T(_)||c(y,E,I,_),!S(w,_))throw new Error(`Can not add duplicate data to ${y}`);w[E]=_}}}}e.updateGlobal=a("global"),e.updateInput=a("input"),e.updateOutput=a("output");function u(y,g){const w=y.length-1,E=n(y,w);e.updateInput(g,E)}e.addInputAttributes=u;function f(y,g){const w=y.length-1,E=r(y,w);e.updateOutput(g,E)}e.addOutputAttributes=f;function l(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Version: Invalid Transaction");return g.writeUInt32LE(y,0),g}e.defaultVersionSetter=l;function p(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Locktime: Invalid Transaction");return g.writeUInt32LE(y,g.length-4),g}e.defaultLocktimeSetter=p})(pf)),pf}var Tp;function Sx(){if(Tp)return xc;Tp=1,Object.defineProperty(xc,"__esModule",{value:!0});const e=_x(),t=sw(),n=Ut(),r=ow();class i{constructor(o){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:o}}static fromBase64(o,c){const a=Buffer.from(o,"base64");return this.fromBuffer(a,c)}static fromHex(o,c){const a=Buffer.from(o,"hex");return this.fromBuffer(a,c)}static fromBuffer(o,c){const a=t.psbtFromBuffer(o,c),u=new this(a.globalMap.unsignedTx);return Object.assign(u,a),u}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(o){return r.updateGlobal(o,this.globalMap),this}updateInput(o,c){const a=r.checkForInput(this.inputs,o);return r.updateInput(c,a),this}updateOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.updateOutput(c,a),this}addUnknownKeyValToGlobal(o){return r.checkHasKey(o,this.globalMap.unknownKeyVals,r.getEnumLength(n.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(o),this}addUnknownKeyValToInput(o,c){const a=r.checkForInput(this.inputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.InputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addUnknownKeyValToOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.OutputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addInput(o){this.globalMap.unsignedTx.addInput(o),this.inputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.inputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToInput(a,u)),r.addInputAttributes(this.inputs,o),this}addOutput(o){this.globalMap.unsignedTx.addOutput(o),this.outputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.outputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToOutput(a,u)),r.addOutputAttributes(this.outputs,o),this}clearFinalizedInput(o){const c=r.checkForInput(this.inputs,o);r.inputCheckUncleanFinalized(o,c);for(const a of Object.keys(c))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(a)||delete c[a];return this}combine(...o){const c=e.combine([this].concat(o));return Object.assign(this,c),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}return xc.Psbt=i,xc}var ze={},We={},xp;function Wf(){if(xp)return We;xp=1,Object.defineProperty(We,"__esModule",{value:!0}),We.signatureBlocksAction=We.checkInputForSig=We.pubkeyInScript=We.pubkeyPositionInScript=We.witnessStackToScriptWitness=We.isP2TR=We.isP2SHScript=We.isP2WSHScript=We.isP2WPKH=We.isP2PKH=We.isP2PK=We.isP2MS=void 0;const e=Di(),t=Jt(),n=cc(),r=xr(),i=oc();function s(y){return g=>{try{return y({output:g}),!0}catch{return!1}}}We.isP2MS=s(i.p2ms),We.isP2PK=s(i.p2pk),We.isP2PKH=s(i.p2pkh),We.isP2WPKH=s(i.p2wpkh),We.isP2WSHScript=s(i.p2wsh),We.isP2SHScript=s(i.p2sh),We.isP2TR=s(i.p2tr);function o(y){let g=Buffer.allocUnsafe(0);function w(m){g=Buffer.concat([g,Buffer.from(m)])}function E(m){const T=g.length,I=e.encodingLength(m);g=Buffer.concat([g,Buffer.allocUnsafe(I)]),e.encode(m,g,T)}function _(m){E(m.length),w(m)}function S(m){E(m.length),m.forEach(_)}return S(y),g}We.witnessStackToScriptWitness=o;function c(y,g){const w=(0,r.hash160)(y),E=y.slice(1,33),_=t.decompile(g);if(_===null)throw new Error("Unknown script error");return _.findIndex(S=>typeof S=="number"?!1:S.equals(y)||S.equals(w)||S.equals(E))}We.pubkeyPositionInScript=c;function a(y,g){return c(y,g)!==-1}We.pubkeyInScript=a;function u(y,g){return l(y).some(E=>f(E,t.signature.decode,g))}We.checkInputForSig=u;function f(y,g,w){const{hashType:E}=g(y),_=[];switch(E&n.Transaction.SIGHASH_ANYONECANPAY&&_.push("addInput"),E&31){case n.Transaction.SIGHASH_ALL:break;case n.Transaction.SIGHASH_SINGLE:case n.Transaction.SIGHASH_NONE:_.push("addOutput"),_.push("setInputSequence");break}return _.indexOf(w)===-1}We.signatureBlocksAction=f;function l(y){let g=[];if((y.partialSig||[]).length===0){if(!y.finalScriptSig&&!y.finalScriptWitness)return[];g=p(y)}else g=y.partialSig;return g.map(w=>w.signature)}function p(y){const g=y.finalScriptSig?t.decompile(y.finalScriptSig)||[]:[],w=y.finalScriptWitness?t.decompile(y.finalScriptWitness)||[]:[];return g.concat(w).filter(E=>Buffer.isBuffer(E)&&t.isCanonicalScriptSignature(E)).map(E=>({signature:E}))}return We}var Ap;function Tx(){if(Ap)return ze;Ap=1,Object.defineProperty(ze,"__esModule",{value:!0}),ze.checkTaprootInputForSigs=ze.tapTreeFromList=ze.tapTreeToList=ze.tweakInternalPubKey=ze.checkTaprootOutputFields=ze.checkTaprootInputFields=ze.isTaprootOutput=ze.isTaprootInput=ze.serializeTaprootSignature=ze.tapScriptFinalizer=ze.toXOnly=void 0;const e=Lt(),t=cc(),n=Wf(),r=Yl(),i=oc(),s=Wf(),o=x=>x.length===32?x:x.slice(1,33);ze.toXOnly=o;function c(x,O,q){const P=N(O,x,q);try{const G=H(O,P).concat(P.script).concat(P.controlBlock);return{finalScriptWitness:(0,n.witnessStackToScriptWitness)(G)}}catch($){throw new Error(`Can not finalize taproot input #${x}: ${$}`)}}ze.tapScriptFinalizer=c;function a(x,O){const q=O?Buffer.from([O]):Buffer.from([]);return Buffer.concat([x,q])}ze.serializeTaprootSignature=a;function u(x){return x&&!!(x.tapInternalKey||x.tapMerkleRoot||x.tapLeafScript&&x.tapLeafScript.length||x.tapBip32Derivation&&x.tapBip32Derivation.length||x.witnessUtxo&&(0,n.isP2TR)(x.witnessUtxo.script))}ze.isTaprootInput=u;function f(x,O){return x&&!!(x.tapInternalKey||x.tapTree||x.tapBip32Derivation&&x.tapBip32Derivation.length||O&&(0,n.isP2TR)(O))}ze.isTaprootOutput=f;function l(x,O,q){v(x,O,q),V(x,O,q)}ze.checkTaprootInputFields=l;function p(x,O,q){R(x,O,q),y(x,O)}ze.checkTaprootOutputFields=p;function y(x,O){if(!O.tapTree&&!O.tapInternalKey)return;const q=O.tapInternalKey||x.tapInternalKey,P=O.tapTree||x.tapTree;if(q){const{script:$}=x,G=g(q,P);if($&&!$.equals(G))throw new Error("Error adding output. Script or address missmatch.")}}function g(x,O){const q=O&&_(O.leaves),{output:P}=(0,i.p2tr)({internalPubkey:x,scriptTree:q});return P}function w(x,O){const q=O.tapInternalKey,P=q&&(0,r.tweakKey)(q,O.tapMerkleRoot);if(!P)throw new Error(`Cannot tweak tap internal key for input #${x}. Public key: ${q&&q.toString("hex")}`);return P.x}ze.tweakInternalPubKey=w;function E(x){if(!(0,e.isTaptree)(x))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return A(x)}ze.tapTreeToList=E;function _(x=[]){return x.length===1&&x[0].depth===0?{output:x[0].script,version:x[0].leafVersion}:U(x)}ze.tapTreeFromList=_;function S(x,O){return T(x).some(P=>(0,s.signatureBlocksAction)(P,m,O))}ze.checkTaprootInputForSigs=S;function m(x){return{signature:x.slice(0,64),hashType:x.slice(64)[0]||t.Transaction.SIGHASH_DEFAULT}}function T(x){const O=[];if(x.tapKeySig&&O.push(x.tapKeySig),x.tapScriptSig&&O.push(...x.tapScriptSig.map(q=>q.signature)),!O.length){const q=I(x.finalScriptWitness);q&&O.push(q)}return O}function I(x){if(!x)return;const O=x.slice(2);if(O.length===64||O.length===65)return O}function A(x,O=[],q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return x?(0,e.isTapleaf)(x)?(O.push({depth:q,leafVersion:x.version||r.LEAF_VERSION_TAPSCRIPT,script:x.output}),O):(x[0]&&A(x[0],O,q+1),x[1]&&A(x[1],O,q+1),O):[]}function U(x){let O;for(const q of x)if(O=M(q,O),!O)throw new Error("No room left to insert tapleaf in tree");return O}function M(x,O,q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(x.depth===q)return O?void 0:{output:x.script,version:x.leafVersion};if((0,e.isTapleaf)(O))return;const P=M(x,O&&O[0],q+1);if(P)return[P,O&&O[1]];const $=M(x,O&&O[1],q+1);if($)return[O&&O[0],$]}function v(x,O,q){const P=u(x)&&F(O),$=F(x)&&u(O),G=x===O&&u(O)&&F(O);if(P||$||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function R(x,O,q){const P=f(x)&&F(O),$=F(x)&&f(O),G=x===O&&f(O)&&F(O);if(P||$||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function V(x,O,q){if(O.tapMerkleRoot){const P=(O.tapLeafScript||[]).every(G=>W(G,O.tapMerkleRoot)),$=(x.tapLeafScript||[]).every(G=>W(G,O.tapMerkleRoot));if(!P||!$)throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}else if(x.tapMerkleRoot&&!(O.tapLeafScript||[]).every($=>W($,x.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}function W(x,O){if(!O)return!0;const q=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(0,r.rootHashFromPath)(x.controlBlock,q).equals(O)}function H(x,O){const q=(0,r.tapleafHash)({output:O.script,version:O.leafVersion});return(x.tapScriptSig||[]).filter(P=>P.leafHash.equals(q)).map(P=>K(O.script,P)).sort((P,$)=>$.positionInScript-P.positionInScript).map(P=>P.signature)}function K(x,O){return Object.assign({positionInScript:(0,n.pubkeyPositionInScript)(O.pubkey,x)},O)}function N(x,O,q){if(!x.tapScriptSig||!x.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${O}. No tapleaf script signature provided.`);const P=(x.tapLeafScript||[]).sort(($,G)=>$.controlBlock.length-G.controlBlock.length).find($=>L($,x.tapScriptSig,q));if(!P)throw new Error(`Can not finalize taproot input #${O}. Signature for tapleaf script not found.`);return P}function L(x,O,q){const P=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(!q||q.equals(P))&&O.find(G=>G.leafHash.equals(P))!==void 0}function F(x){return x&&!!(x.redeemScript||x.witnessScript||x.bip32Derivation&&x.bip32Derivation.length)}return ze}var vp;function xx(){if(vp)return ro;vp=1,Object.defineProperty(ro,"__esModule",{value:!0}),ro.Psbt=void 0;const e=Sx(),t=Di(),n=ow(),r=Zl(),i=iu(),s=Vn(),o=oc(),c=Yl(),a=Jt(),u=cc(),f=Tx(),l=Wf(),p={network:s.bitcoin,maximumFeeRate:5e3};class y{static fromBase64(h,b={}){const B=Buffer.from(h,"base64");return this.fromBuffer(B,b)}static fromHex(h,b={}){const B=Buffer.from(h,"hex");return this.fromBuffer(B,b)}static fromBuffer(h,b={}){const B=e.Psbt.fromBuffer(h,g),C=new y(b,B);return V(C.__CACHE.__TX,C.__CACHE),C}constructor(h={},b=new e.Psbt(new w)){this.data=b,this.opts=Object.assign({},p,h),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const B=(C,j,D,re)=>Object.defineProperty(C,j,{enumerable:D,writable:re});B(this,"__CACHE",!1,!0),B(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(h){this.setVersion(h)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(h){this.setLocktime(h)}get txInputs(){return this.__CACHE.__TX.ins.map(h=>({hash:(0,i.cloneBuffer)(h.hash),index:h.index,sequence:h.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(h=>{let b;try{b=(0,r.fromOutputScript)(h.script,this.opts.network)}catch{}return{script:(0,i.cloneBuffer)(h.script),value:h.value,address:b}})}combine(...h){return this.data.combine(...h.map(b=>b.data)),this}clone(){const h=y.fromBuffer(this.data.toBuffer());return h.opts=JSON.parse(JSON.stringify(this.opts)),h}setMaximumFeeRate(h){I(h),this.opts.maximumFeeRate=h}setVersion(h){I(h),U(this.data.inputs,"setVersion");const b=this.__CACHE;return b.__TX.version=h,b.__EXTRACTED_TX=void 0,this}setLocktime(h){I(h),U(this.data.inputs,"setLocktime");const b=this.__CACHE;return b.__TX.locktime=h,b.__EXTRACTED_TX=void 0,this}setInputSequence(h,b){I(b),U(this.data.inputs,"setInputSequence");const B=this.__CACHE;if(B.__TX.ins.length<=h)throw new Error("Input index too high");return B.__TX.ins[h].sequence=b,B.__EXTRACTED_TX=void 0,this}addInputs(h){return h.forEach(b=>this.addInput(b)),this}addInput(h){if(arguments.length>1||!h||h.hash===void 0||h.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,f.checkTaprootInputFields)(h,h,"addInput"),U(this.data.inputs,"addInput"),h.witnessScript&&te(h.witnessScript);const b=this.__CACHE;this.data.addInput(h);const B=b.__TX.ins[b.__TX.ins.length-1];W(b,B);const C=this.data.inputs.length-1,j=this.data.inputs[C];return j.nonWitnessUtxo&&pe(this.__CACHE,j,C),b.__FEE=void 0,b.__FEE_RATE=void 0,b.__EXTRACTED_TX=void 0,this}addOutputs(h){return h.forEach(b=>this.addOutput(b)),this}addOutput(h){if(arguments.length>1||!h||h.value===void 0||h.address===void 0&&h.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");U(this.data.inputs,"addOutput");const{address:b}=h;if(typeof b=="string"){const{network:C}=this.opts,j=(0,r.toOutputScript)(b,C);h=Object.assign({},h,{script:j})}(0,f.checkTaprootOutputFields)(h,h,"addOutput");const B=this.__CACHE;return this.data.addOutput(h),B.__FEE=void 0,B.__FEE_RATE=void 0,B.__EXTRACTED_TX=void 0,this}extractTransaction(h){if(!this.data.inputs.every(m))throw new Error("Not finalized");const b=this.__CACHE;if(h||A(this,b,this.opts),b.__EXTRACTED_TX)return b.__EXTRACTED_TX;const B=b.__TX.clone();return J(this.data.inputs,B,b,!0),B}getFeeRate(){return L("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return L("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).forEach(h=>this.finalizeInput(h)),this}finalizeInput(h,b){const B=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(B)?this._finalizeTaprootInput(h,B,void 0,b):this._finalizeInput(h,B,b)}finalizeTaprootInput(h,b,B=f.tapScriptFinalizer){const C=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(C))return this._finalizeTaprootInput(h,C,b,B);throw new Error(`Cannot finalize input #${h}. Not Taproot.`)}_finalizeInput(h,b,B=F){const{script:C,isP2SH:j,isP2WSH:D,isSegwit:re}=ae(h,b,this.__CACHE);if(!C)throw new Error(`No script found for input #${h}`);M(b);const{finalScriptSig:Q,finalScriptWitness:ue}=B(h,b,C,re,j,D);if(Q&&this.data.updateInput(h,{finalScriptSig:Q}),ue&&this.data.updateInput(h,{finalScriptWitness:ue}),!Q&&!ue)throw new Error(`Unknown error finalizing input #${h}`);return this.data.clearFinalizedInput(h),this}_finalizeTaprootInput(h,b,B,C=f.tapScriptFinalizer){if(!b.witnessUtxo)throw new Error(`Cannot finalize input #${h}. Missing withness utxo.`);if(b.tapKeySig){const j=o.p2tr({output:b.witnessUtxo.script,signature:b.tapKeySig}),D=(0,l.witnessStackToScriptWitness)(j.witness);this.data.updateInput(h,{finalScriptWitness:D})}else{const{finalScriptWitness:j}=C(h,b,B);this.data.updateInput(h,{finalScriptWitness:j})}return this.data.clearFinalizedInput(h),this}getInputType(h){const b=(0,n.checkForInput)(this.data.inputs,h),B=Se(h,b,this.__CACHE),C=se(B,h,"input",b.redeemScript||St(b.finalScriptSig),b.witnessScript||Ae(b.finalScriptWitness)),j=C.type==="raw"?"":C.type+"-",D=ne(C.meaningfulScript);return j+D}inputHasPubkey(h,b){const B=(0,n.checkForInput)(this.data.inputs,h);return Ze(b,B,h,this.__CACHE)}inputHasHDKey(h,b){const B=(0,n.checkForInput)(this.data.inputs,h),C=T(b);return!!B.bip32Derivation&&B.bip32Derivation.some(C)}outputHasPubkey(h,b){const B=(0,n.checkForOutput)(this.data.outputs,h);return st(b,B,h,this.__CACHE)}outputHasHDKey(h,b){const B=(0,n.checkForOutput)(this.data.outputs,h),C=T(b);return!!B.bip32Derivation&&B.bip32Derivation.some(C)}validateSignaturesOfAllInputs(h){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).map(B=>this.validateSignaturesOfInput(B,h)).reduce((B,C)=>C===!0&&B,!0)}validateSignaturesOfInput(h,b,B){const C=this.data.inputs[h];return(0,f.isTaprootInput)(C)?this.validateSignaturesOfTaprootInput(h,b,B):this._validateSignaturesOfInput(h,b,B)}_validateSignaturesOfInput(h,b,B){const C=this.data.inputs[h],j=(C||{}).partialSig;if(!C||!j||j.length<1)throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");const D=B?j.filter(Be=>Be.pubkey.equals(B)):j;if(D.length<1)throw new Error("No signatures for this pubkey");const re=[];let Q,ue,le;for(const Be of D){const Oe=a.signature.decode(Be.signature),{hash:Je,script:Ve}=le!==Oe.hashType?q(h,Object.assign({},C,{sighashType:Oe.hashType}),this.__CACHE,!0):{hash:Q,script:ue};le=Oe.hashType,Q=Je,ue=Ve,v(Be.pubkey,Ve,"verify"),re.push(b(Be.pubkey,Je,Oe.signature))}return re.every(Be=>Be===!0)}validateSignaturesOfTaprootInput(h,b,B){const C=this.data.inputs[h],j=(C||{}).tapKeySig,D=(C||{}).tapScriptSig;if(!C&&!j&&!(D&&!D.length))throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");B=B&&(0,f.toXOnly)(B);const re=B?X(h,C,this.data.inputs,B,this.__CACHE):P(h,C,this.data.inputs,this.__CACHE);if(!re.length)throw new Error("No signatures for this pubkey");const Q=re.find(le=>!le.leafHash);let ue=0;if(j&&Q){if(!b(Q.pubkey,Q.hash,G(j)))return!1;ue++}if(D)for(const le of D){const Be=re.find(Oe=>le.pubkey.equals(Oe.pubkey));if(Be){if(!b(le.pubkey,Be.hash,G(le.signature)))return!1;ue++}}return ue>0}signAllInputsHD(h,b=[u.Transaction.SIGHASH_ALL]){if(!h||!h.publicKey||!h.fingerprint)throw new Error("Need HDSigner to sign input");const B=[];for(const C of k(this.data.inputs.length))try{this.signInputHD(C,h,b),B.push(!0)}catch{B.push(!1)}if(B.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(h,b=[u.Transaction.SIGHASH_ALL]){return new Promise((B,C)=>{if(!h||!h.publicKey||!h.fingerprint)return C(new Error("Need HDSigner to sign input"));const j=[],D=[];for(const re of k(this.data.inputs.length))D.push(this.signInputHDAsync(re,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(D).then(()=>{if(j.every(re=>re===!1))return C(new Error("No inputs were signed"));B()})})}signInputHD(h,b,B=[u.Transaction.SIGHASH_ALL]){if(!b||!b.publicKey||!b.fingerprint)throw new Error("Need HDSigner to sign input");return ee(h,this.data.inputs,b).forEach(j=>this.signInput(h,j,B)),this}signInputHDAsync(h,b,B=[u.Transaction.SIGHASH_ALL]){return new Promise((C,j)=>{if(!b||!b.publicKey||!b.fingerprint)return j(new Error("Need HDSigner to sign input"));const re=ee(h,this.data.inputs,b).map(Q=>this.signInputAsync(h,Q,B));return Promise.all(re).then(()=>{C()}).catch(j)})}signAllInputs(h,b){if(!h||!h.publicKey)throw new Error("Need Signer to sign input");const B=[];for(const C of k(this.data.inputs.length))try{this.signInput(C,h,b),B.push(!0)}catch{B.push(!1)}if(B.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(h,b){return new Promise((B,C)=>{if(!h||!h.publicKey)return C(new Error("Need Signer to sign input"));const j=[],D=[];for(const[re]of this.data.inputs.entries())D.push(this.signInputAsync(re,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(D).then(()=>{if(j.every(re=>re===!1))return C(new Error("No inputs were signed"));B()})})}signInput(h,b,B){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInput(h,C,b,void 0,B):this._signInput(h,b,B)}signTaprootInput(h,b,B,C){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInput(h,j,b,B,C);throw new Error(`Input #${h} is not of type Taproot.`)}_signInput(h,b,B=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=O(this.data.inputs,h,b.publicKey,this.__CACHE,B),D=[{pubkey:b.publicKey,signature:a.signature.encode(b.sign(C),j)}];return this.data.updateInput(h,{partialSig:D}),this}_signTaprootInput(h,b,B,C,j=[u.Transaction.SIGHASH_DEFAULT]){const D=this.checkTaprootHashesForSig(h,b,B,C,j),re=D.filter(ue=>!ue.leafHash).map(ue=>(0,f.serializeTaprootSignature)(B.signSchnorr(ue.hash),b.sighashType))[0],Q=D.filter(ue=>!!ue.leafHash).map(ue=>({pubkey:(0,f.toXOnly)(B.publicKey),signature:(0,f.serializeTaprootSignature)(B.signSchnorr(ue.hash),b.sighashType),leafHash:ue.leafHash}));return re&&this.data.updateInput(h,{tapKeySig:re}),Q.length&&this.data.updateInput(h,{tapScriptSig:Q}),this}signInputAsync(h,b,B){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInputAsync(h,C,b,void 0,B):this._signInputAsync(h,b,B)})}signTaprootInputAsync(h,b,B,C){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInputAsync(h,j,b,B,C);throw new Error(`Input #${h} is not of type Taproot.`)})}_signInputAsync(h,b,B=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=O(this.data.inputs,h,b.publicKey,this.__CACHE,B);return Promise.resolve(b.sign(C)).then(D=>{const re=[{pubkey:b.publicKey,signature:a.signature.encode(D,j)}];this.data.updateInput(h,{partialSig:re})})}async _signTaprootInputAsync(h,b,B,C,j=[u.Transaction.SIGHASH_DEFAULT]){const D=this.checkTaprootHashesForSig(h,b,B,C,j),re=[],Q=D.filter(le=>!le.leafHash)[0];if(Q){const le=Promise.resolve(B.signSchnorr(Q.hash)).then(Be=>({tapKeySig:(0,f.serializeTaprootSignature)(Be,b.sighashType)}));re.push(le)}const ue=D.filter(le=>!!le.leafHash);if(ue.length){const le=ue.map(Be=>Promise.resolve(B.signSchnorr(Be.hash)).then(Oe=>({tapScriptSig:[{pubkey:(0,f.toXOnly)(B.publicKey),signature:(0,f.serializeTaprootSignature)(Oe,b.sighashType),leafHash:Be.leafHash}]})));re.push(...le)}return Promise.all(re).then(le=>{le.forEach(Be=>this.data.updateInput(h,Be))})}checkTaprootHashesForSig(h,b,B,C,j){if(typeof B.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${h}.`);const D=X(h,b,this.data.inputs,B.publicKey,this.__CACHE,C,j);if(!D||!D.length)throw new Error(`Can not sign for input #${h} with the key ${B.publicKey.toString("hex")}`);return D}toBuffer(){return _(this.__CACHE),this.data.toBuffer()}toHex(){return _(this.__CACHE),this.data.toHex()}toBase64(){return _(this.__CACHE),this.data.toBase64()}updateGlobal(h){return this.data.updateGlobal(h),this}updateInput(h,b){return b.witnessScript&&te(b.witnessScript),(0,f.checkTaprootInputFields)(this.data.inputs[h],b,"updateInput"),this.data.updateInput(h,b),b.nonWitnessUtxo&&pe(this.__CACHE,this.data.inputs[h],h),this}updateOutput(h,b){const B=this.data.outputs[h];return(0,f.checkTaprootOutputFields)(B,b,"updateOutput"),this.data.updateOutput(h,b),this}addUnknownKeyValToGlobal(h){return this.data.addUnknownKeyValToGlobal(h),this}addUnknownKeyValToInput(h,b){return this.data.addUnknownKeyValToInput(h,b),this}addUnknownKeyValToOutput(h,b){return this.data.addUnknownKeyValToOutput(h,b),this}clearFinalizedInput(h){return this.data.clearFinalizedInput(h),this}}ro.Psbt=y;const g=d=>new w(d);class w{constructor(h=Buffer.from([2,0,0,0,0,0,0,0,0,0])){this.tx=u.Transaction.fromBuffer(h),R(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(h){if(h.hash===void 0||h.index===void 0||!Buffer.isBuffer(h.hash)&&typeof h.hash!="string"||typeof h.index!="number")throw new Error("Error adding input.");const b=typeof h.hash=="string"?(0,i.reverseBuffer)(Buffer.from(h.hash,"hex")):h.hash;this.tx.addInput(b,h.index,h.sequence)}addOutput(h){if(h.script===void 0||h.value===void 0||!Buffer.isBuffer(h.script)||typeof h.value!="number")throw new Error("Error adding output.");this.tx.addOutput(h.script,h.value)}toBuffer(){return this.tx.toBuffer()}}function E(d,h,b){switch(b){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return S(1,d.partialSig);case"multisig":const B=o.p2ms({output:h});return S(B.m,d.partialSig,B.pubkeys);default:return!1}}function _(d){if(d.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function S(d,h,b){if(!h)return!1;let B;if(b?B=b.map(C=>{const j=ln(C);return h.find(D=>D.pubkey.equals(j))}).filter(C=>!!C):B=h,B.length>d)throw new Error("Too many signatures");return B.length===d}function m(d){return!!d.finalScriptSig||!!d.finalScriptWitness}function T(d){return h=>!(!h.masterFingerprint.equals(d.fingerprint)||!d.derivePath(h.path).publicKey.equals(h.pubkey))}function I(d){if(typeof d!="number"||d!==Math.floor(d)||d>4294967295||d<0)throw new Error("Invalid 32 bit integer")}function A(d,h,b){const B=h.__FEE_RATE||d.getFeeRate(),C=h.__EXTRACTED_TX.virtualSize(),j=B*C;if(B>=b.maximumFeeRate)throw new Error(`Warning: You are paying around ${(j/1e8).toFixed(8)} in fees, which is ${B} satoshi per byte for a transaction with a VSize of ${C} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function U(d,h){d.forEach(b=>{if((0,f.isTaprootInput)(b)?(0,f.checkTaprootInputForSigs)(b,h):(0,l.checkInputForSig)(b,h))throw new Error("Can not modify transaction, signatures exist.")})}function M(d){if(!d.sighashType||!d.partialSig)return;const{partialSig:h,sighashType:b}=d;h.forEach(B=>{const{hashType:C}=a.signature.decode(B.signature);if(b!==C)throw new Error("Signature sighash does not match input sighash type")})}function v(d,h,b){if(!(0,l.pubkeyInScript)(d,h))throw new Error(`Can not ${b} for this input with the key ${d.toString("hex")}`)}function R(d){if(!d.ins.every(b=>b.script&&b.script.length===0&&b.witness&&b.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function V(d,h){d.ins.forEach(b=>{W(h,b)})}function W(d,h){const b=(0,i.reverseBuffer)(Buffer.from(h.hash)).toString("hex")+":"+h.index;if(d.__TX_IN_CACHE[b])throw new Error("Duplicate input detected.");d.__TX_IN_CACHE[b]=1}function H(d,h){return(b,B,C,j)=>{const D=d({redeem:{output:C}}).output;if(!B.equals(D))throw new Error(`${h} for ${j} #${b} doesn't match the scriptPubKey in the prevout`)}}const K=H(o.p2sh,"Redeem script"),N=H(o.p2wsh,"Witness script");function L(d,h,b,B){if(!b.every(m))throw new Error(`PSBT must be finalized to calculate ${h}`);if(d==="__FEE_RATE"&&B.__FEE_RATE)return B.__FEE_RATE;if(d==="__FEE"&&B.__FEE)return B.__FEE;let C,j=!0;if(B.__EXTRACTED_TX?(C=B.__EXTRACTED_TX,j=!1):C=B.__TX.clone(),J(b,C,B,j),d==="__FEE_RATE")return B.__FEE_RATE;if(d==="__FEE")return B.__FEE}function F(d,h,b,B,C,j){const D=ne(b);if(!E(h,b,D))throw new Error(`Can not finalize input #${d}`);return x(b,D,h.partialSig,B,C,j)}function x(d,h,b,B,C,j){let D,re;const Q=oe(d,h,b),ue=j?o.p2wsh({redeem:Q}):null,le=C?o.p2sh({redeem:ue||Q}):null;return B?(ue?re=(0,l.witnessStackToScriptWitness)(ue.witness):re=(0,l.witnessStackToScriptWitness)(Q.witness),le&&(D=le.input)):le?D=le.input:D=Q.input,{finalScriptSig:D,finalScriptWitness:re}}function O(d,h,b,B,C){const j=(0,n.checkForInput)(d,h),{hash:D,sighashType:re,script:Q}=q(h,j,B,!1,C);return v(b,Q,"sign"),{hash:D,sighashType:re}}function q(d,h,b,B,C){const j=b.__TX,D=h.sighashType||u.Transaction.SIGHASH_ALL;Y(D,C);let re,Q;if(h.nonWitnessUtxo){const Be=fe(b,h,d),Oe=j.ins[d].hash,Je=Be.getHash();if(!Oe.equals(Je))throw new Error(`Non-witness UTXO hash for input #${d} doesn't match the hash specified in the prevout`);const Ve=j.ins[d].index;Q=Be.outs[Ve]}else if(h.witnessUtxo)Q=h.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:ue,type:le}=se(Q.script,d,"input",h.redeemScript,h.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(le)>=0)re=j.hashForWitnessV0(d,ue,Q.value,D);else if((0,l.isP2WPKH)(ue)){const Be=o.p2pkh({hash:ue.slice(2)}).output;re=j.hashForWitnessV0(d,Be,Q.value,D)}else{if(h.nonWitnessUtxo===void 0&&b.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${d} has witnessUtxo but non-segwit script: ${ue.toString("hex")}`);!B&&b.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
73
|
+
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}),tr}var Ju={},Ds={},Qu={},nr={},u0;function ew(){if(u0)return nr;u0=1,Object.defineProperty(nr,"__esModule",{value:!0}),nr.encode=nr.decode=nr.check=void 0;function e(r){if(r.length<8||r.length>72||r[0]!==48||r[1]!==r.length-2||r[2]!==2)return!1;const i=r[3];if(i===0||5+i>=r.length||r[4+i]!==2)return!1;const s=r[5+i];return!(s===0||6+i+s!==r.length||r[4]&128||i>1&&r[4]===0&&!(r[5]&128)||r[i+6]&128||s>1&&r[i+6]===0&&!(r[i+7]&128))}nr.check=e;function t(r){if(r.length<8)throw new Error("DER sequence length is too short");if(r.length>72)throw new Error("DER sequence length is too long");if(r[0]!==48)throw new Error("Expected DER sequence");if(r[1]!==r.length-2)throw new Error("DER sequence length is invalid");if(r[2]!==2)throw new Error("Expected DER integer");const i=r[3];if(i===0)throw new Error("R length is zero");if(5+i>=r.length)throw new Error("R length is too long");if(r[4+i]!==2)throw new Error("Expected DER integer (2)");const s=r[5+i];if(s===0)throw new Error("S length is zero");if(6+i+s!==r.length)throw new Error("S length is invalid");if(r[4]&128)throw new Error("R value is negative");if(i>1&&r[4]===0&&!(r[5]&128))throw new Error("R value excessively padded");if(r[i+6]&128)throw new Error("S value is negative");if(s>1&&r[i+6]===0&&!(r[i+7]&128))throw new Error("S value excessively padded");return{r:r.slice(4,4+i),s:r.slice(6+i)}}nr.decode=t;function n(r,i){const s=r.length,o=i.length;if(s===0)throw new Error("R length is zero");if(o===0)throw new Error("S length is zero");if(s>33)throw new Error("R length is too long");if(o>33)throw new Error("S length is too long");if(r[0]&128)throw new Error("R value is negative");if(i[0]&128)throw new Error("S value is negative");if(s>1&&r[0]===0&&!(r[1]&128))throw new Error("R value excessively padded");if(o>1&&i[0]===0&&!(i[1]&128))throw new Error("S value excessively padded");const c=Buffer.allocUnsafe(6+s+o);return c[0]=48,c[1]=c.length-2,c[2]=2,c[3]=r.length,r.copy(c,4),c[4+s]=2,c[5+s]=i.length,i.copy(c,6+s),c}return nr.encode=n,nr}var pi={},f0;function Dl(){if(f0)return pi;f0=1,Object.defineProperty(pi,"__esModule",{value:!0}),pi.REVERSE_OPS=pi.OPS=void 0;const e={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};pi.OPS=e;const t={};pi.REVERSE_OPS=t;for(const n of Object.keys(e)){const r=e[n];t[r]=n}return pi}var rr={},l0;function N8(){if(l0)return rr;l0=1,Object.defineProperty(rr,"__esModule",{value:!0}),rr.decode=rr.encode=rr.encodingLength=void 0;const e=Dl();function t(i){return i<e.OPS.OP_PUSHDATA1?1:i<=255?2:i<=65535?3:5}rr.encodingLength=t;function n(i,s,o){const c=t(s);return c===1?i.writeUInt8(s,o):c===2?(i.writeUInt8(e.OPS.OP_PUSHDATA1,o),i.writeUInt8(s,o+1)):c===3?(i.writeUInt8(e.OPS.OP_PUSHDATA2,o),i.writeUInt16LE(s,o+1)):(i.writeUInt8(e.OPS.OP_PUSHDATA4,o),i.writeUInt32LE(s,o+1)),c}rr.encode=n;function r(i,s){const o=i.readUInt8(s);let c,a;if(o<e.OPS.OP_PUSHDATA1)c=o,a=1;else if(o===e.OPS.OP_PUSHDATA1){if(s+2>i.length)return null;c=i.readUInt8(s+1),a=2}else if(o===e.OPS.OP_PUSHDATA2){if(s+3>i.length)return null;c=i.readUInt16LE(s+1),a=3}else{if(s+5>i.length)return null;if(o!==e.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");c=i.readUInt32LE(s+1),a=5}return{opcode:o,number:c,size:a}}return rr.decode=r,rr}var yi={},h0;function U8(){if(h0)return yi;h0=1,Object.defineProperty(yi,"__esModule",{value:!0}),yi.encode=yi.decode=void 0;function e(r,i,s){i=i||4,s=s===void 0?!0:s;const o=r.length;if(o===0)return 0;if(o>i)throw new TypeError("Script number overflow");if(s&&(r[o-1]&127)===0&&(o<=1||(r[o-2]&128)===0))throw new Error("Non-minimally encoded script number");if(o===5){const a=r.readUInt32LE(0),u=r.readUInt8(4);return u&128?-((u&-129)*4294967296+a):u*4294967296+a}let c=0;for(let a=0;a<o;++a)c|=r[a]<<8*a;return r[o-1]&128?-(c&~(128<<8*(o-1))):c}yi.decode=e;function t(r){return r>2147483647?5:r>8388607?4:r>32767?3:r>127?2:r>0?1:0}function n(r){let i=Math.abs(r);const s=t(i),o=Buffer.allocUnsafe(s),c=r<0;for(let a=0;a<s;++a)o.writeUInt8(i&255,a),i>>=8;return o[s-1]&128?o.writeUInt8(c?128:0,s-1):c&&(o[s-1]|=128),o}return yi.encode=n,yi}var gi={},ef={},tf,d0;function Xl(){if(d0)return tf;d0=1;var e={Array:function(n){return n!=null&&n.constructor===Array},Boolean:function(n){return typeof n=="boolean"},Function:function(n){return typeof n=="function"},Nil:function(n){return n==null},Number:function(n){return typeof n=="number"},Object:function(n){return typeof n=="object"},String:function(n){return typeof n=="string"},"":function(){return!0}};e.Null=e.Nil;for(var t in e)e[t].toJSON=(function(n){return n}).bind(null,t);return tf=e,tf}var nf,p0;function tw(){if(p0)return nf;p0=1;var e=Xl();function t(p){return p.name||p.toString().match(/function (.*?)\s*\(/)[1]}function n(p){return e.Nil(p)?"":t(p.constructor)}function r(p){return e.Function(p)?"":e.String(p)?JSON.stringify(p):p&&e.Object(p)?"":p}function i(p,y){Error.captureStackTrace&&Error.captureStackTrace(p,y)}function s(p){return e.Function(p)?p.toJSON?p.toJSON():t(p):e.Array(p)?"Array":p&&e.Object(p)?"Object":p!==void 0?p:""}function o(p,y,g){var w=r(y);return"Expected "+s(p)+", got"+(g!==""?" "+g:"")+(w!==""?" "+w:"")}function c(p,y,g){g=g||n(y),this.message=o(p,y,g),i(this,c),this.__type=p,this.__value=y,this.__valueTypeName=g}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c;function a(p,y,g,w,E){var _='" of type ';return y==="key"&&(_='" with key type '),o('property "'+s(g)+_+s(p),w,E)}function u(p,y,g,w,E){p?(E=E||n(w),this.message=a(p,g,y,w,E)):this.message='Unexpected property "'+y+'"',i(this,c),this.__label=g,this.__property=y,this.__type=p,this.__value=w,this.__valueTypeName=E}u.prototype=Object.create(Error.prototype),u.prototype.constructor=c;function f(p,y){return new c(p,{},y)}function l(p,y,g){return p instanceof u?(y=y+"."+p.__property,p=new u(p.__type,y,p.__label,p.__value,p.__valueTypeName)):p instanceof c&&(p=new u(p.__type,y,g,p.__value,p.__valueTypeName)),i(p),p}return nf={TfTypeError:c,TfPropertyTypeError:u,tfCustomError:f,tfSubError:l,tfJSON:s,getValueTypeName:n},nf}var rf,y0;function R8(){if(y0)return rf;y0=1;var e=Xl(),t=tw();function n(A){return Buffer.isBuffer(A)}function r(A){return typeof A=="string"&&/^([0-9a-f]{2})+$/i.test(A)}function i(A,U){var M=A.toJSON();function v(R){if(!A(R))return!1;if(R.length===U)return!0;throw t.tfCustomError(M+"(Length: "+U+")",M+"(Length: "+R.length+")")}return v.toJSON=function(){return M},v}var s=i.bind(null,e.Array),o=i.bind(null,n),c=i.bind(null,r),a=i.bind(null,e.String);function u(A,U,M){M=M||e.Number;function v(R,V){return M(R,V)&&R>A&&R<U}return v.toJSON=function(){return`${M.toJSON()} between [${A}, ${U}]`},v}var f=Math.pow(2,53)-1;function l(A){return typeof A=="number"&&isFinite(A)}function p(A){return A<<24>>24===A}function y(A){return A<<16>>16===A}function g(A){return(A|0)===A}function w(A){return typeof A=="number"&&A>=-f&&A<=f&&Math.floor(A)===A}function E(A){return(A&255)===A}function _(A){return(A&65535)===A}function S(A){return A>>>0===A}function m(A){return typeof A=="number"&&A>=0&&A<=f&&Math.floor(A)===A}var T={ArrayN:s,Buffer:n,BufferN:o,Finite:l,Hex:r,HexN:c,Int8:p,Int16:y,Int32:g,Int53:w,Range:u,StringN:a,UInt8:E,UInt16:_,UInt32:S,UInt53:m};for(var I in T)T[I].toJSON=(function(A){return A}).bind(null,I);return rf=T,rf}var sf,g0;function C8(){if(g0)return sf;g0=1;var e=tw(),t=Xl(),n=e.tfJSON,r=e.TfTypeError,i=e.TfPropertyTypeError,s=e.tfSubError,o=e.getValueTypeName,c={arrayOf:function(y,g){y=a(y),g=g||{};function w(E,_){return!t.Array(E)||t.Nil(E)||g.minLength!==void 0&&E.length<g.minLength||g.maxLength!==void 0&&E.length>g.maxLength||g.length!==void 0&&E.length!==g.length?!1:E.every(function(S,m){try{return u(y,S,_)}catch(T){throw s(T,m)}})}return w.toJSON=function(){var E="["+n(y)+"]";return g.length!==void 0?E+="{"+g.length+"}":(g.minLength!==void 0||g.maxLength!==void 0)&&(E+="{"+(g.minLength===void 0?0:g.minLength)+","+(g.maxLength===void 0?1/0:g.maxLength)+"}"),E},w},maybe:function p(y){y=a(y);function g(w,E){return t.Nil(w)||y(w,E,p)}return g.toJSON=function(){return"?"+n(y)},g},map:function(y,g){y=a(y),g&&(g=a(g));function w(E,_){if(!t.Object(E)||t.Nil(E))return!1;for(var S in E){try{g&&u(g,S,_)}catch(T){throw s(T,S,"key")}try{var m=E[S];u(y,m,_)}catch(T){throw s(T,S)}}return!0}return g?w.toJSON=function(){return"{"+n(g)+": "+n(y)+"}"}:w.toJSON=function(){return"{"+n(y)+"}"},w},object:function(y){var g={};for(var w in y)g[w]=a(y[w]);function E(_,S){if(!t.Object(_)||t.Nil(_))return!1;var m;try{for(m in g){var T=g[m],I=_[m];u(T,I,S)}}catch(A){throw s(A,m)}if(S){for(m in _)if(!g[m])throw new i(void 0,m)}return!0}return E.toJSON=function(){return n(g)},E},anyOf:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return y.some(function(_){try{return u(_,w,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join("|")},g},allOf:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return y.every(function(_){try{return u(_,w,E)}catch{return!1}})}return g.toJSON=function(){return y.map(n).join(" & ")},g},quacksLike:function(y){function g(w){return y===o(w)}return g.toJSON=function(){return y},g},tuple:function(){var y=[].slice.call(arguments).map(a);function g(w,E){return t.Nil(w)||t.Nil(w.length)||E&&w.length!==y.length?!1:y.every(function(_,S){try{return u(_,w[S],E)}catch(m){throw s(m,S)}})}return g.toJSON=function(){return"("+y.map(n).join(", ")+")"},g},value:function(y){function g(w){return w===y}return g.toJSON=function(){return y},g}};c.oneOf=c.anyOf;function a(p){if(t.String(p))return p[0]==="?"?c.maybe(p.slice(1)):t[p]||c.quacksLike(p);if(p&&t.Object(p)){if(t.Array(p)){if(p.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(p[0])}return c.object(p)}else if(t.Function(p))return p;return c.value(p)}function u(p,y,g,w){if(t.Function(p)){if(p(y,g))return!0;throw new r(w||p,y)}return u(a(p),y,g)}for(var f in t)u[f]=t[f];for(f in c)u[f]=c[f];var l=R8();for(f in l)u[f]=l[f];return u.compile=a,u.TfTypeError=r,u.TfPropertyTypeError=i,sf=u,sf}var w0;function Lt(){return w0||(w0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Vo();e.typeforce=C8();const n=t.Buffer.alloc(32,0),r=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,l){return f.length!==l.length?!1:f.every((p,y)=>p.equals(l[y]))}e.stacksEqual=i;function s(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const l=f[0],p=f.slice(1,33);if(p.compare(n)===0||p.compare(r)>=0)return!1;if((l===2||l===3)&&f.length===33)return!0;const y=f.slice(33);return y.compare(n)===0||y.compare(r)>=0?!1:l===4&&f.length===65}e.isPoint=s;const o=21*1e14;function c(f){return e.typeforce.UInt53(f)&&f<=o}e.Satoshi=c,e.TAPLEAF_VERSION_MASK=254;function a(f){return!f||!("output"in f)||!t.Buffer.isBuffer(f.output)?!1:f.version!==void 0?(f.version&e.TAPLEAF_VERSION_MASK)===f.version:!0}e.isTapleaf=a;function u(f){return(0,e.Array)(f)?f.length!==2?!1:f.every(l=>u(l)):a(f)}e.isTaptree=u,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(ef)),ef}var m0;function H8(){if(m0)return gi;m0=1,Object.defineProperty(gi,"__esModule",{value:!0}),gi.encode=gi.decode=void 0;const e=ew(),t=Jt(),n=Lt(),{typeforce:r}=n,i=Buffer.alloc(1,0);function s(u){let f=0;for(;u[f]===0;)++f;return f===u.length?i:(u=u.slice(f),u[0]&128?Buffer.concat([i,u],1+u.length):u)}function o(u){u[0]===0&&(u=u.slice(1));const f=Buffer.alloc(32,0),l=Math.max(0,32-u.length);return u.copy(f,l),f}function c(u){const f=u.readUInt8(u.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=e.decode(u.slice(0,-1)),p=o(l.r),y=o(l.s);return{signature:Buffer.concat([p,y],64),hashType:f}}gi.decode=c;function a(u,f){if(r({signature:n.BufferN(64),hashType:n.UInt8},{signature:u,hashType:f}),!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const l=Buffer.allocUnsafe(1);l.writeUInt8(f,0);const p=s(u.slice(0,32)),y=s(u.slice(32,64));return Buffer.concat([e.encode(p,y),l])}return gi.encode=a,gi}var b0;function Jt(){return b0||(b0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=ew(),n=Dl();Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return n.OPS}});const r=N8(),i=U8(),s=H8(),o=Lt(),{typeforce:c}=o,a=n.OPS.OP_RESERVED;function u(v){return o.Number(v)&&(v===n.OPS.OP_0||v>=n.OPS.OP_1&&v<=n.OPS.OP_16||v===n.OPS.OP_1NEGATE)}function f(v){return o.Buffer(v)||u(v)}function l(v){return o.Array(v)&&v.every(f)}e.isPushOnly=l;function p(v){return v.length-v.filter(f).length}e.countNonPushOnlyOPs=p;function y(v){if(v.length===0)return n.OPS.OP_0;if(v.length===1){if(v[0]>=1&&v[0]<=16)return a+v[0];if(v[0]===129)return n.OPS.OP_1NEGATE}}function g(v){return Buffer.isBuffer(v)}function w(v){return o.Array(v)}function E(v){return Buffer.isBuffer(v)}function _(v){if(g(v))return v;c(o.Array,v);const R=v.reduce((H,K)=>E(K)?K.length===1&&y(K)!==void 0?H+1:H+r.encodingLength(K.length)+K.length:H+1,0),V=Buffer.allocUnsafe(R);let W=0;if(v.forEach(H=>{if(E(H)){const K=y(H);if(K!==void 0){V.writeUInt8(K,W),W+=1;return}W+=r.encode(V,H.length,W),H.copy(V,W),W+=H.length}else V.writeUInt8(H,W),W+=1}),W!==V.length)throw new Error("Could not decode chunks");return V}e.compile=_;function S(v){if(w(v))return v;c(o.Buffer,v);const R=[];let V=0;for(;V<v.length;){const W=v[V];if(W>n.OPS.OP_0&&W<=n.OPS.OP_PUSHDATA4){const H=r.decode(v,V);if(H===null||(V+=H.size,V+H.number>v.length))return null;const K=v.slice(V,V+H.number);V+=H.number;const N=y(K);N!==void 0?R.push(N):R.push(K)}else R.push(W),V+=1}return R}e.decompile=S;function m(v){if(g(v)&&(v=S(v)),!v)throw new Error("Could not convert invalid chunks to ASM");return v.map(R=>{if(E(R)){const V=y(R);if(V===void 0)return R.toString("hex");R=V}return n.REVERSE_OPS[R]}).join(" ")}e.toASM=m;function T(v){return c(o.String,v),_(v.split(" ").map(R=>n.OPS[R]!==void 0?n.OPS[R]:(c(o.Hex,R),Buffer.from(R,"hex"))))}e.fromASM=T;function I(v){return v=S(v),c(l,v),v.map(R=>E(R)?R:R===n.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(R-a))}e.toStack=I;function A(v){return o.isPoint(v)}e.isCanonicalPubKey=A;function U(v){const R=v&-129;return R>0&&R<4}e.isDefinedHashType=U;function M(v){return!Buffer.isBuffer(v)||!U(v[v.length-1])?!1:t.check(v.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=s})(Qu)),Qu}var wi={},E0;function ui(){if(E0)return wi;E0=1,Object.defineProperty(wi,"__esModule",{value:!0}),wi.value=wi.prop=void 0;function e(n,r,i){Object.defineProperty(n,r,{configurable:!0,enumerable:!0,get(){const s=i.call(this);return this[r]=s,s},set(s){Object.defineProperty(this,r,{configurable:!0,enumerable:!0,value:s,writable:!0})}})}wi.prop=e;function t(n){let r;return()=>(r!==void 0||(r=n()),r)}return wi.value=t,wi}var _0;function F8(){if(_0)return Ds;_0=1,Object.defineProperty(Ds,"__esModule",{value:!0}),Ds.p2data=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS;function s(o,c){if(!o.data&&!o.output)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),data:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))},o);const u={name:"embed",network:o.network||e.bitcoin};if(r.prop(u,"output",()=>{if(o.data)return t.compile([i.OP_RETURN].concat(o.data))}),r.prop(u,"data",()=>{if(o.output)return t.decompile(o.output).slice(1)}),c.validate&&o.output){const f=t.decompile(o.output);if(f[0]!==i.OP_RETURN)throw new TypeError("Output is invalid");if(!f.slice(1).every(n.typeforce.Buffer))throw new TypeError("Output is invalid");if(o.data&&!(0,n.stacksEqual)(o.data,u.data))throw new TypeError("Data mismatch")}return Object.assign(u,o)}return Ds.p2data=s,Ds}var Xs={},S0;function M8(){if(S0)return Xs;S0=1,Object.defineProperty(Xs,"__esModule",{value:!0}),Xs.p2ms=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS,s=i.OP_RESERVED;function o(c,a){if(!c.input&&!c.output&&!(c.pubkeys&&c.m!==void 0)&&!c.signatures)throw new TypeError("Not enough data");a=Object.assign({validate:!0},a||{});function u(w){return t.isCanonicalScriptSignature(w)||(a.allowIncomplete&&w===i.OP_0)!==void 0}(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),m:n.typeforce.maybe(n.typeforce.Number),n:n.typeforce.maybe(n.typeforce.Number),output:n.typeforce.maybe(n.typeforce.Buffer),pubkeys:n.typeforce.maybe(n.typeforce.arrayOf(n.isPoint)),signatures:n.typeforce.maybe(n.typeforce.arrayOf(u)),input:n.typeforce.maybe(n.typeforce.Buffer)},c);const l={network:c.network||e.bitcoin};let p=[],y=!1;function g(w){y||(y=!0,p=t.decompile(w),l.m=p[0]-s,l.n=p[p.length-2]-s,l.pubkeys=p.slice(1,-2))}if(r.prop(l,"output",()=>{if(c.m&&l.n&&c.pubkeys)return t.compile([].concat(s+c.m,c.pubkeys,s+l.n,i.OP_CHECKMULTISIG))}),r.prop(l,"m",()=>{if(l.output)return g(l.output),l.m}),r.prop(l,"n",()=>{if(l.pubkeys)return l.pubkeys.length}),r.prop(l,"pubkeys",()=>{if(c.output)return g(c.output),l.pubkeys}),r.prop(l,"signatures",()=>{if(c.input)return t.decompile(c.input).slice(1)}),r.prop(l,"input",()=>{if(c.signatures)return t.compile([i.OP_0].concat(c.signatures))}),r.prop(l,"witness",()=>{if(l.input)return[]}),r.prop(l,"name",()=>{if(!(!l.m||!l.n))return`p2ms(${l.m} of ${l.n})`}),a.validate){if(c.output){if(g(c.output),!n.typeforce.Number(p[0]))throw new TypeError("Output is invalid");if(!n.typeforce.Number(p[p.length-2]))throw new TypeError("Output is invalid");if(p[p.length-1]!==i.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(l.m<=0||l.n>16||l.m>l.n||l.n!==p.length-3)throw new TypeError("Output is invalid");if(!l.pubkeys.every(w=>(0,n.isPoint)(w)))throw new TypeError("Output is invalid");if(c.m!==void 0&&c.m!==l.m)throw new TypeError("m mismatch");if(c.n!==void 0&&c.n!==l.n)throw new TypeError("n mismatch");if(c.pubkeys&&!(0,n.stacksEqual)(c.pubkeys,l.pubkeys))throw new TypeError("Pubkeys mismatch")}if(c.pubkeys){if(c.n!==void 0&&c.n!==c.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(l.n=c.pubkeys.length,l.n<l.m)throw new TypeError("Pubkey count cannot be less than m")}if(c.signatures){if(c.signatures.length<l.m)throw new TypeError("Not enough signatures provided");if(c.signatures.length>l.m)throw new TypeError("Too many signatures provided")}if(c.input){if(c.input[0]!==i.OP_0)throw new TypeError("Input is invalid");if(l.signatures.length===0||!l.signatures.every(u))throw new TypeError("Input has invalid signature(s)");if(c.signatures&&!(0,n.stacksEqual)(c.signatures,l.signatures))throw new TypeError("Signature mismatch");if(c.m!==void 0&&c.m!==c.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(l,c)}return Xs.p2ms=o,Xs}var zs={},T0;function q8(){if(T0)return zs;T0=1,Object.defineProperty(zs,"__esModule",{value:!0}),zs.p2pk=void 0;const e=Vn(),t=Jt(),n=Lt(),r=ui(),i=t.OPS;function s(o,c){if(!o.input&&!o.output&&!o.pubkey&&!o.input&&!o.signature)throw new TypeError("Not enough data");c=Object.assign({validate:!0},c||{}),(0,n.typeforce)({network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.Buffer),pubkey:n.typeforce.maybe(n.isPoint),signature:n.typeforce.maybe(t.isCanonicalScriptSignature),input:n.typeforce.maybe(n.typeforce.Buffer)},o);const a=r.value(()=>t.decompile(o.input)),f={name:"p2pk",network:o.network||e.bitcoin};if(r.prop(f,"output",()=>{if(o.pubkey)return t.compile([o.pubkey,i.OP_CHECKSIG])}),r.prop(f,"pubkey",()=>{if(o.output)return o.output.slice(1,-1)}),r.prop(f,"signature",()=>{if(o.input)return a()[0]}),r.prop(f,"input",()=>{if(o.signature)return t.compile([o.signature])}),r.prop(f,"witness",()=>{if(f.input)return[]}),c.validate){if(o.output){if(o.output[o.output.length-1]!==i.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,n.isPoint)(f.pubkey))throw new TypeError("Output pubkey is invalid");if(o.pubkey&&!o.pubkey.equals(f.pubkey))throw new TypeError("Pubkey mismatch")}if(o.signature&&o.input&&!o.input.equals(f.input))throw new TypeError("Signature mismatch");if(o.input){if(a().length!==1)throw new TypeError("Input is invalid");if(!t.isCanonicalScriptSignature(f.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(f,o)}return zs.p2pk=s,zs}var Ys={},of={},mi={},Gt={},x0;function nw(){if(x0)return Gt;x0=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.ripemd160=Gt.RIPEMD160=Gt.md5=Gt.MD5=Gt.sha1=Gt.SHA1=void 0;const e=Kp(),t=ni(),n=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),r=new Uint32Array(80);class i extends e.HashMD{constructor(){super(64,20,8,!1),this.A=n[0]|0,this.B=n[1]|0,this.C=n[2]|0,this.D=n[3]|0,this.E=n[4]|0}get(){const{A:v,B:R,C:V,D:W,E:H}=this;return[v,R,V,W,H]}set(v,R,V,W,H){this.A=v|0,this.B=R|0,this.C=V|0,this.D=W|0,this.E=H|0}process(v,R){for(let L=0;L<16;L++,R+=4)r[L]=v.getUint32(R,!1);for(let L=16;L<80;L++)r[L]=(0,t.rotl)(r[L-3]^r[L-8]^r[L-14]^r[L-16],1);let{A:V,B:W,C:H,D:K,E:N}=this;for(let L=0;L<80;L++){let F,x;L<20?(F=(0,e.Chi)(W,H,K),x=1518500249):L<40?(F=W^H^K,x=1859775393):L<60?(F=(0,e.Maj)(W,H,K),x=2400959708):(F=W^H^K,x=3395469782);const O=(0,t.rotl)(V,5)+F+N+x+r[L]|0;N=K,K=H,H=(0,t.rotl)(W,30),W=V,V=O}V=V+this.A|0,W=W+this.B|0,H=H+this.C|0,K=K+this.D|0,N=N+this.E|0,this.set(V,W,H,K,N)}roundClean(){(0,t.clean)(r)}destroy(){this.set(0,0,0,0,0),(0,t.clean)(this.buffer)}}Gt.SHA1=i,Gt.sha1=(0,t.createHasher)(()=>new i);const s=Math.pow(2,32),o=Array.from({length:64},(M,v)=>Math.floor(s*Math.abs(Math.sin(v+1)))),c=n.slice(0,4),a=new Uint32Array(16);class u extends e.HashMD{constructor(){super(64,16,8,!0),this.A=c[0]|0,this.B=c[1]|0,this.C=c[2]|0,this.D=c[3]|0}get(){const{A:v,B:R,C:V,D:W}=this;return[v,R,V,W]}set(v,R,V,W){this.A=v|0,this.B=R|0,this.C=V|0,this.D=W|0}process(v,R){for(let N=0;N<16;N++,R+=4)a[N]=v.getUint32(R,!0);let{A:V,B:W,C:H,D:K}=this;for(let N=0;N<64;N++){let L,F,x;N<16?(L=(0,e.Chi)(W,H,K),F=N,x=[7,12,17,22]):N<32?(L=(0,e.Chi)(K,W,H),F=(5*N+1)%16,x=[5,9,14,20]):N<48?(L=W^H^K,F=(3*N+5)%16,x=[4,11,16,23]):(L=H^(W|~K),F=7*N%16,x=[6,10,15,21]),L=L+V+o[N]+a[F],V=K,K=H,H=W,W=W+(0,t.rotl)(L,x[N%4])}V=V+this.A|0,W=W+this.B|0,H=H+this.C|0,K=K+this.D|0,this.set(V,W,H,K)}roundClean(){(0,t.clean)(a)}destroy(){this.set(0,0,0,0),(0,t.clean)(this.buffer)}}Gt.MD5=u,Gt.md5=(0,t.createHasher)(()=>new u);const f=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),l=Uint8Array.from(new Array(16).fill(0).map((M,v)=>v)),p=l.map(M=>(9*M+5)%16),y=(()=>{const R=[[l],[p]];for(let V=0;V<4;V++)for(let W of R)W.push(W[V].map(H=>f[H]));return R})(),g=y[0],w=y[1],E=[[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(M=>Uint8Array.from(M)),_=g.map((M,v)=>M.map(R=>E[v][R])),S=w.map((M,v)=>M.map(R=>E[v][R])),m=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),T=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function I(M,v,R,V){return M===0?v^R^V:M===1?v&R|~v&V:M===2?(v|~R)^V:M===3?v&V|R&~V:v^(R|~V)}const A=new Uint32Array(16);class U extends e.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:v,h1:R,h2:V,h3:W,h4:H}=this;return[v,R,V,W,H]}set(v,R,V,W,H){this.h0=v|0,this.h1=R|0,this.h2=V|0,this.h3=W|0,this.h4=H|0}process(v,R){for(let P=0;P<16;P++,R+=4)A[P]=v.getUint32(R,!0);let V=this.h0|0,W=V,H=this.h1|0,K=H,N=this.h2|0,L=N,F=this.h3|0,x=F,O=this.h4|0,q=O;for(let P=0;P<5;P++){const $=4-P,G=m[P],X=T[P],Y=g[P],oe=w[P],ae=_[P],ee=S[P];for(let Z=0;Z<16;Z++){const ce=(0,t.rotl)(V+I(P,H,N,F)+A[Y[Z]]+G,ae[Z])+O|0;V=O,O=F,F=(0,t.rotl)(N,10)|0,N=H,H=ce}for(let Z=0;Z<16;Z++){const ce=(0,t.rotl)(W+I($,K,L,x)+A[oe[Z]]+X,ee[Z])+q|0;W=q,q=x,x=(0,t.rotl)(L,10)|0,L=K,K=ce}}this.set(this.h1+N+x|0,this.h2+F+q|0,this.h3+O+W|0,this.h4+V+K|0,this.h0+H+L|0)}roundClean(){(0,t.clean)(A)}destroy(){this.destroyed=!0,(0,t.clean)(this.buffer),this.set(0,0,0,0,0)}}return Gt.RIPEMD160=U,Gt.ripemd160=(0,t.createHasher)(()=>new U),Gt}var A0;function V8(){if(A0)return mi;A0=1,Object.defineProperty(mi,"__esModule",{value:!0}),mi.ripemd160=mi.RIPEMD160=void 0;const e=nw();return mi.RIPEMD160=e.RIPEMD160,mi.ripemd160=e.ripemd160,mi}var bi={},v0;function $8(){if(v0)return bi;v0=1,Object.defineProperty(bi,"__esModule",{value:!0}),bi.sha1=bi.SHA1=void 0;const e=nw();return bi.SHA1=e.SHA1,bi.sha1=e.sha1,bi}var In={},B0;function rw(){if(B0)return In;B0=1,Object.defineProperty(In,"__esModule",{value:!0}),In.sha224=In.SHA224=In.sha256=In.SHA256=void 0;const e=Lp();return In.SHA256=e.SHA256,In.sha256=e.sha256,In.SHA224=e.SHA224,In.sha224=e.sha224,In}var I0;function xr(){return I0||(I0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=V8(),n=$8(),r=rw();function i(f){return Buffer.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function s(f){return Buffer.from((0,n.sha1)(Uint8Array.from(f)))}e.sha1=s;function o(f){return Buffer.from((0,r.sha256)(Uint8Array.from(f)))}e.sha256=o;function c(f){return Buffer.from((0,t.ripemd160)((0,r.sha256)(Uint8Array.from(f))))}e.hash160=c;function a(f){return Buffer.from((0,r.sha256)((0,r.sha256)(Uint8Array.from(f))))}e.hash256=a,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.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":Buffer.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":Buffer.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:Buffer.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:Buffer.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:Buffer.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:Buffer.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":Buffer.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":Buffer.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 u(f,l){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[f],l]))}e.taggedHash=u})(of)),of}var cf,O0;function K8(){if(O0)return cf;O0=1;function e(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,E=0,_=0,S=g.length;_!==S&&g[_]===0;)_++,w++;for(var m=(S-_)*f+1>>>0,T=new Uint8Array(m);_!==S;){for(var I=g[_],A=0,U=m-1;(I!==0||A<E)&&U!==-1;U--,A++)I+=256*T[U]>>>0,T[U]=I%c>>>0,I=I/c>>>0;if(I!==0)throw new Error("Non-zero carry");E=A,_++}for(var M=m-E;M!==m&&T[M]===0;)M++;for(var v=a.repeat(w);M<m;++M)v+=t.charAt(T[M]);return v}function p(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;for(var w=0,E=0,_=0;g[w]===a;)E++,w++;for(var S=(g.length-w)*u+1>>>0,m=new Uint8Array(S);g[w];){var T=g.charCodeAt(w);if(T>255)return;var I=n[T];if(I===255)return;for(var A=0,U=S-1;(I!==0||A<_)&&U!==-1;U--,A++)I+=c*m[U]>>>0,m[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");_=A,w++}for(var M=S-_;M!==S&&m[M]===0;)M++;for(var v=new Uint8Array(E+(S-M)),R=E;M!==S;)v[R++]=m[M++];return v}function y(g){var w=p(g);if(w)return w;throw new Error("Non-base"+c+" character")}return{encode:l,decodeUnsafe:p,decode:y}}return cf=e,cf}var af,P0;function L8(){return P0||(P0=1,af=K8()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")),af}var uf,k0;function j8(){if(k0)return uf;k0=1;var e=L8();return uf=function(t){function n(o){var c=Uint8Array.from(o),a=t(c),u=c.length+4,f=new Uint8Array(u);return f.set(c,0),f.set(a.subarray(0,4),c.length),e.encode(f,u)}function r(o){var c=o.slice(0,-4),a=o.slice(-4),u=t(c);if(!(a[0]^u[0]|a[1]^u[1]|a[2]^u[2]|a[3]^u[3]))return c}function i(o){var c=e.decodeUnsafe(o);if(c)return r(c)}function s(o){var c=e.decode(o),a=r(c);if(!a)throw new Error("Invalid checksum");return a}return{encode:n,decode:s,decodeUnsafe:i}},uf}var ff,N0;function zl(){if(N0)return ff;N0=1;var{sha256:e}=rw(),t=j8();function n(r){return e(e(r))}return ff=t(n),ff}var U0;function W8(){if(U0)return Ys;U0=1,Object.defineProperty(Ys,"__esModule",{value:!0}),Ys.p2pkh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=zl(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.pubkey&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(25)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),input:r.typeforce.maybe(r.typeforce.Buffer)},a);const f=i.value(()=>{const g=Buffer.from(s.decode(a.address)),w=g.readUInt8(0),E=g.slice(1);return{version:w,hash:E}}),l=i.value(()=>n.decompile(a.input)),p=a.network||t.bitcoin,y={name:"p2pkh",network:p};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=Buffer.allocUnsafe(21);return g.writeUInt8(p.pubKeyHash,0),y.hash.copy(g,1),s.encode(g)}),i.prop(y,"hash",()=>{if(a.output)return a.output.slice(3,23);if(a.address)return f().hash;if(a.pubkey||y.pubkey)return e.hash160(a.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_DUP,o.OP_HASH160,y.hash,o.OP_EQUALVERIFY,o.OP_CHECKSIG])}),i.prop(y,"pubkey",()=>{if(a.input)return l()[1]}),i.prop(y,"signature",()=>{if(a.input)return l()[0]}),i.prop(y,"input",()=>{if(a.pubkey&&a.signature)return n.compile([a.signature,a.pubkey])}),i.prop(y,"witness",()=>{if(y.input)return[]}),u.validate){let g=Buffer.from([]);if(a.address){if(f().version!==p.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(f().hash.length!==20)throw new TypeError("Invalid address");g=f().hash}if(a.hash){if(g.length>0&&!g.equals(a.hash))throw new TypeError("Hash mismatch");g=a.hash}if(a.output){if(a.output.length!==25||a.output[0]!==o.OP_DUP||a.output[1]!==o.OP_HASH160||a.output[2]!==20||a.output[23]!==o.OP_EQUALVERIFY||a.output[24]!==o.OP_CHECKSIG)throw new TypeError("Output is invalid");const w=a.output.slice(3,23);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");g=w}if(a.pubkey){const w=e.hash160(a.pubkey);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");g=w}if(a.input){const w=l();if(w.length!==2)throw new TypeError("Input is invalid");if(!n.isCanonicalScriptSignature(w[0]))throw new TypeError("Input has invalid signature");if(!(0,r.isPoint)(w[1]))throw new TypeError("Input has invalid pubkey");if(a.signature&&!a.signature.equals(w[0]))throw new TypeError("Signature mismatch");if(a.pubkey&&!a.pubkey.equals(w[1]))throw new TypeError("Pubkey mismatch");const E=e.hash160(w[1]);if(g.length>0&&!g.equals(E))throw new TypeError("Hash mismatch")}}return Object.assign(y,a)}return Ys.p2pkh=c,Ys}var Zs={},R0;function G8(){if(R0)return Zs;R0=1,Object.defineProperty(Zs,"__esModule",{value:!0}),Zs.p2sh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=zl(),o=n.OPS;function c(a,u){if(!a.address&&!a.hash&&!a.output&&!a.redeem&&!a.input)throw new TypeError("Not enough data");u=Object.assign({validate:!0},u||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),output:r.typeforce.maybe(r.typeforce.BufferN(23)),redeem:r.typeforce.maybe({network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},a);let f=a.network;f||(f=a.redeem&&a.redeem.network||t.bitcoin);const l={network:f},p=i.value(()=>{const w=Buffer.from(s.decode(a.address)),E=w.readUInt8(0),_=w.slice(1);return{version:E,hash:_}}),y=i.value(()=>n.decompile(a.input)),g=i.value(()=>{const w=y(),E=w[w.length-1];return{network:f,output:E===o.OP_FALSE?Buffer.from([]):E,input:n.compile(w.slice(0,-1)),witness:a.witness||[]}});if(i.prop(l,"address",()=>{if(!l.hash)return;const w=Buffer.allocUnsafe(21);return w.writeUInt8(l.network.scriptHash,0),l.hash.copy(w,1),s.encode(w)}),i.prop(l,"hash",()=>{if(a.output)return a.output.slice(2,22);if(a.address)return p().hash;if(l.redeem&&l.redeem.output)return e.hash160(l.redeem.output)}),i.prop(l,"output",()=>{if(l.hash)return n.compile([o.OP_HASH160,l.hash,o.OP_EQUAL])}),i.prop(l,"redeem",()=>{if(a.input)return g()}),i.prop(l,"input",()=>{if(!(!a.redeem||!a.redeem.input||!a.redeem.output))return n.compile([].concat(n.decompile(a.redeem.input),a.redeem.output))}),i.prop(l,"witness",()=>{if(l.redeem&&l.redeem.witness)return l.redeem.witness;if(l.input)return[]}),i.prop(l,"name",()=>{const w=["p2sh"];return l.redeem!==void 0&&l.redeem.name!==void 0&&w.push(l.redeem.name),w.join("-")}),u.validate){let w=Buffer.from([]);if(a.address){if(p().version!==f.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(p().hash.length!==20)throw new TypeError("Invalid address");w=p().hash}if(a.hash){if(w.length>0&&!w.equals(a.hash))throw new TypeError("Hash mismatch");w=a.hash}if(a.output){if(a.output.length!==23||a.output[0]!==o.OP_HASH160||a.output[1]!==20||a.output[22]!==o.OP_EQUAL)throw new TypeError("Output is invalid");const _=a.output.slice(2,22);if(w.length>0&&!w.equals(_))throw new TypeError("Hash mismatch");w=_}const E=_=>{if(_.output){const S=n.decompile(_.output);if(!S||S.length<1)throw new TypeError("Redeem.output too short");if(_.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(n.countNonPushOnlyOPs(S)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const m=e.hash160(_.output);if(w.length>0&&!w.equals(m))throw new TypeError("Hash mismatch");w=m}if(_.input){const S=_.input.length>0,m=_.witness&&_.witness.length>0;if(!S&&!m)throw new TypeError("Empty input");if(S&&m)throw new TypeError("Input and witness provided");if(S){const T=n.decompile(_.input);if(!n.isPushOnly(T))throw new TypeError("Non push-only scriptSig")}}};if(a.input){const _=y();if(!_||_.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(g().output))throw new TypeError("Input is invalid");E(g())}if(a.redeem){if(a.redeem.network&&a.redeem.network!==f)throw new TypeError("Network mismatch");if(a.input){const _=g();if(a.redeem.output&&!a.redeem.output.equals(_.output))throw new TypeError("Redeem.output mismatch");if(a.redeem.input&&!a.redeem.input.equals(_.input))throw new TypeError("Redeem.input mismatch")}E(a.redeem)}if(a.witness&&a.redeem&&a.redeem.witness&&!(0,r.stacksEqual)(a.redeem.witness,a.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(l,a)}return Zs.p2sh=c,Zs}var Js={},C0;function D8(){if(C0)return Js;C0=1,Object.defineProperty(Js,"__esModule",{value:!0}),Js.p2wpkh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Do(),o=n.OPS,c=Buffer.alloc(0);function a(u,f){if(!u.address&&!u.hash&&!u.output&&!u.pubkey&&!u.witness)throw new TypeError("Not enough data");f=Object.assign({validate:!0},f||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(20)),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(22)),pubkey:r.typeforce.maybe(r.isPoint),signature:r.typeforce.maybe(n.isCanonicalScriptSignature),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},u);const l=i.value(()=>{const g=s.bech32.decode(u.address),w=g.words.shift(),E=s.bech32.fromWords(g.words);return{version:w,prefix:g.prefix,data:Buffer.from(E)}}),p=u.network||t.bitcoin,y={name:"p2wpkh",network:p};if(i.prop(y,"address",()=>{if(!y.hash)return;const g=s.bech32.toWords(y.hash);return g.unshift(0),s.bech32.encode(p.bech32,g)}),i.prop(y,"hash",()=>{if(u.output)return u.output.slice(2,22);if(u.address)return l().data;if(u.pubkey||y.pubkey)return e.hash160(u.pubkey||y.pubkey)}),i.prop(y,"output",()=>{if(y.hash)return n.compile([o.OP_0,y.hash])}),i.prop(y,"pubkey",()=>{if(u.pubkey)return u.pubkey;if(u.witness)return u.witness[1]}),i.prop(y,"signature",()=>{if(u.witness)return u.witness[0]}),i.prop(y,"input",()=>{if(y.witness)return c}),i.prop(y,"witness",()=>{if(u.pubkey&&u.signature)return[u.signature,u.pubkey]}),f.validate){let g=Buffer.from([]);if(u.address){if(p&&p.bech32!==l().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(l().version!==0)throw new TypeError("Invalid address version");if(l().data.length!==20)throw new TypeError("Invalid address data");g=l().data}if(u.hash){if(g.length>0&&!g.equals(u.hash))throw new TypeError("Hash mismatch");g=u.hash}if(u.output){if(u.output.length!==22||u.output[0]!==o.OP_0||u.output[1]!==20)throw new TypeError("Output is invalid");if(g.length>0&&!g.equals(u.output.slice(2)))throw new TypeError("Hash mismatch");g=u.output.slice(2)}if(u.pubkey){const w=e.hash160(u.pubkey);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch");if(g=w,!(0,r.isPoint)(u.pubkey)||u.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(u.witness){if(u.witness.length!==2)throw new TypeError("Witness is invalid");if(!n.isCanonicalScriptSignature(u.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,r.isPoint)(u.witness[1])||u.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(u.signature&&!u.signature.equals(u.witness[0]))throw new TypeError("Signature mismatch");if(u.pubkey&&!u.pubkey.equals(u.witness[1]))throw new TypeError("Pubkey mismatch");const w=e.hash160(u.witness[1]);if(g.length>0&&!g.equals(w))throw new TypeError("Hash mismatch")}}return Object.assign(y,u)}return Js.p2wpkh=a,Js}var Qs={},H0;function X8(){if(H0)return Qs;H0=1,Object.defineProperty(Qs,"__esModule",{value:!0}),Qs.p2wsh=void 0;const e=xr(),t=Vn(),n=Jt(),r=Lt(),i=ui(),s=Do(),o=n.OPS,c=Buffer.alloc(0);function a(f){return!!(Buffer.isBuffer(f)&&f.length===65&&f[0]===4&&(0,r.isPoint)(f))}function u(f,l){if(!f.address&&!f.hash&&!f.output&&!f.redeem&&!f.witness)throw new TypeError("Not enough data");l=Object.assign({validate:!0},l||{}),(0,r.typeforce)({network:r.typeforce.maybe(r.typeforce.Object),address:r.typeforce.maybe(r.typeforce.String),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),output:r.typeforce.maybe(r.typeforce.BufferN(34)),redeem:r.typeforce.maybe({input:r.typeforce.maybe(r.typeforce.Buffer),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.Buffer),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),input:r.typeforce.maybe(r.typeforce.BufferN(0)),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))},f);const p=i.value(()=>{const E=s.bech32.decode(f.address),_=E.words.shift(),S=s.bech32.fromWords(E.words);return{version:_,prefix:E.prefix,data:Buffer.from(S)}}),y=i.value(()=>n.decompile(f.redeem.input));let g=f.network;g||(g=f.redeem&&f.redeem.network||t.bitcoin);const w={network:g};if(i.prop(w,"address",()=>{if(!w.hash)return;const E=s.bech32.toWords(w.hash);return E.unshift(0),s.bech32.encode(g.bech32,E)}),i.prop(w,"hash",()=>{if(f.output)return f.output.slice(2);if(f.address)return p().data;if(w.redeem&&w.redeem.output)return e.sha256(w.redeem.output)}),i.prop(w,"output",()=>{if(w.hash)return n.compile([o.OP_0,w.hash])}),i.prop(w,"redeem",()=>{if(f.witness)return{output:f.witness[f.witness.length-1],input:c,witness:f.witness.slice(0,-1)}}),i.prop(w,"input",()=>{if(w.witness)return c}),i.prop(w,"witness",()=>{if(f.redeem&&f.redeem.input&&f.redeem.input.length>0&&f.redeem.output&&f.redeem.output.length>0){const E=n.toStack(y());return w.redeem=Object.assign({witness:E},f.redeem),w.redeem.input=c,[].concat(E,f.redeem.output)}if(f.redeem&&f.redeem.output&&f.redeem.witness)return[].concat(f.redeem.witness,f.redeem.output)}),i.prop(w,"name",()=>{const E=["p2wsh"];return w.redeem!==void 0&&w.redeem.name!==void 0&&E.push(w.redeem.name),E.join("-")}),l.validate){let E=Buffer.from([]);if(f.address){if(p().prefix!==g.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(p().version!==0)throw new TypeError("Invalid address version");if(p().data.length!==32)throw new TypeError("Invalid address data");E=p().data}if(f.hash){if(E.length>0&&!E.equals(f.hash))throw new TypeError("Hash mismatch");E=f.hash}if(f.output){if(f.output.length!==34||f.output[0]!==o.OP_0||f.output[1]!==32)throw new TypeError("Output is invalid");const _=f.output.slice(2);if(E.length>0&&!E.equals(_))throw new TypeError("Hash mismatch");E=_}if(f.redeem){if(f.redeem.network&&f.redeem.network!==g)throw new TypeError("Network mismatch");if(f.redeem.input&&f.redeem.input.length>0&&f.redeem.witness&&f.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(f.redeem.output){const _=n.decompile(f.redeem.output);if(!_||_.length<1)throw new TypeError("Redeem.output is invalid");if(f.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(n.countNonPushOnlyOPs(_)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const S=e.sha256(f.redeem.output);if(E.length>0&&!E.equals(S))throw new TypeError("Hash mismatch");E=S}if(f.redeem.input&&!n.isPushOnly(y()))throw new TypeError("Non push-only scriptSig");if(f.witness&&f.redeem.witness&&!(0,r.stacksEqual)(f.witness,f.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(f.redeem.input&&y().some(a)||f.redeem.output&&(n.decompile(f.redeem.output)||[]).some(a))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(f.witness&&f.witness.length>0){const _=f.witness[f.witness.length-1];if(f.redeem&&f.redeem.output&&!f.redeem.output.equals(_))throw new TypeError("Witness and redeem.output mismatch");if(f.witness.some(a)||(n.decompile(_)||[]).some(a))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(w,f)}return Qs.p2wsh=u,Qs}var eo={},Ei={},F0;function Yl(){if(F0)return Ei;F0=1,Object.defineProperty(Ei,"__esModule",{value:!0}),Ei.getEccLib=Ei.initEccLib=void 0;const e={};function t(c,a){c?c!==e.eccLib&&(a?.DANGER_DO_NOT_VERIFY_ECCLIB||i(c),e.eccLib=c):e.eccLib=c}Ei.initEccLib=t;function n(){if(!e.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return e.eccLib}Ei.getEccLib=n;const r=c=>Buffer.from(c,"hex");function i(c){s(typeof c.isXOnlyPoint=="function"),s(c.isXOnlyPoint(r("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(c.isXOnlyPoint(r("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000001"))),s(!c.isXOnlyPoint(r("0000000000000000000000000000000000000000000000000000000000000000"))),s(!c.isXOnlyPoint(r("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s(typeof c.xOnlyPointAddTweak=="function"),o.forEach(a=>{const u=c.xOnlyPointAddTweak(r(a.pubkey),r(a.tweak));a.result===null?s(u===null):(s(u!==null),s(u.parity===a.parity),s(Buffer.from(u.xOnlyPubkey).equals(r(a.result))))})}function s(c){if(!c)throw new Error("ecc library invalid")}const o=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];return Ei}var lf={},At={},xc={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var M0;function z8(){return M0||(M0=1,(function(e,t){var n=Vo(),r=n.Buffer;function i(o,c){for(var a in o)c[a]=o[a]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(i(n,t),t.Buffer=s);function s(o,c,a){return r(o,c,a)}s.prototype=Object.create(r.prototype),i(r,s),s.from=function(o,c,a){if(typeof o=="number")throw new TypeError("Argument must not be a number");return r(o,c,a)},s.alloc=function(o,c,a){if(typeof o!="number")throw new TypeError("Argument must be a number");var u=r(o);return c!==void 0?typeof a=="string"?u.fill(c,a):u.fill(c):u.fill(0),u},s.allocUnsafe=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return r(o)},s.allocUnsafeSlow=function(o){if(typeof o!="number")throw new TypeError("Argument must be a number");return n.SlowBuffer(o)}})(xc,xc.exports)),xc.exports}var hf,q0;function Y8(){if(q0)return hf;q0=1;var e=z8().Buffer,t=9007199254740991;function n(o){if(o<0||o>t||o%1!==0)throw new RangeError("value out of range")}function r(o,c,a){if(n(o),c||(c=e.allocUnsafe(s(o))),!e.isBuffer(c))throw new TypeError("buffer must be a Buffer instance");return a||(a=0),o<253?(c.writeUInt8(o,a),r.bytes=1):o<=65535?(c.writeUInt8(253,a),c.writeUInt16LE(o,a+1),r.bytes=3):o<=4294967295?(c.writeUInt8(254,a),c.writeUInt32LE(o,a+1),r.bytes=5):(c.writeUInt8(255,a),c.writeUInt32LE(o>>>0,a+1),c.writeUInt32LE(o/4294967296|0,a+5),r.bytes=9),c}function i(o,c){if(!e.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");c||(c=0);var a=o.readUInt8(c);if(a<253)return i.bytes=1,a;if(a===253)return i.bytes=3,o.readUInt16LE(c+1);if(a===254)return i.bytes=5,o.readUInt32LE(c+1);i.bytes=9;var u=o.readUInt32LE(c+1),f=o.readUInt32LE(c+5),l=f*4294967296+u;return n(l),l}function s(o){return n(o),o<253?1:o<=65535?3:o<=4294967295?5:9}return hf={encode:r,decode:i,encodingLength:s},hf}var V0;function su(){if(V0)return At;V0=1,Object.defineProperty(At,"__esModule",{value:!0}),At.BufferReader=At.BufferWriter=At.cloneBuffer=At.reverseBuffer=At.writeUInt64LE=At.readUInt64LE=At.varuint=void 0;const e=Lt(),{typeforce:t}=e,n=Y8();At.varuint=n;function r(f,l){if(typeof f!="number")throw new Error("cannot write a non-number as a number");if(f<0)throw new Error("specified a negative value for writing an unsigned value");if(f>l)throw new Error("RangeError: value out of range");if(Math.floor(f)!==f)throw new Error("value has a fractional component")}function i(f,l){const p=f.readUInt32LE(l);let y=f.readUInt32LE(l+4);return y*=4294967296,r(y+p,9007199254740991),y+p}At.readUInt64LE=i;function s(f,l,p){return r(l,9007199254740991),f.writeInt32LE(l&-1,p),f.writeUInt32LE(Math.floor(l/4294967296),p+4),p+8}At.writeUInt64LE=s;function o(f){if(f.length<1)return f;let l=f.length-1,p=0;for(let y=0;y<f.length/2;y++)p=f[y],f[y]=f[l],f[l]=p,l--;return f}At.reverseBuffer=o;function c(f){const l=Buffer.allocUnsafe(f.length);return f.copy(l),l}At.cloneBuffer=c;class a{static withCapacity(l){return new a(Buffer.alloc(l))}constructor(l,p=0){this.buffer=l,this.offset=p,t(e.tuple(e.Buffer,e.UInt32),[l,p])}writeUInt8(l){this.offset=this.buffer.writeUInt8(l,this.offset)}writeInt32(l){this.offset=this.buffer.writeInt32LE(l,this.offset)}writeUInt32(l){this.offset=this.buffer.writeUInt32LE(l,this.offset)}writeUInt64(l){this.offset=s(this.buffer,l,this.offset)}writeVarInt(l){n.encode(l,this.buffer,this.offset),this.offset+=n.encode.bytes}writeSlice(l){if(this.buffer.length<this.offset+l.length)throw new Error("Cannot write slice out of bounds");this.offset+=l.copy(this.buffer,this.offset)}writeVarSlice(l){this.writeVarInt(l.length),this.writeSlice(l)}writeVector(l){this.writeVarInt(l.length),l.forEach(p=>this.writeVarSlice(p))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}At.BufferWriter=a;class u{constructor(l,p=0){this.buffer=l,this.offset=p,t(e.tuple(e.Buffer,e.UInt32),[l,p])}readUInt8(){const l=this.buffer.readUInt8(this.offset);return this.offset++,l}readInt32(){const l=this.buffer.readInt32LE(this.offset);return this.offset+=4,l}readUInt32(){const l=this.buffer.readUInt32LE(this.offset);return this.offset+=4,l}readUInt64(){const l=i(this.buffer,this.offset);return this.offset+=8,l}readVarInt(){const l=n.decode(this.buffer,this.offset);return this.offset+=n.decode.bytes,l}readSlice(l){if(this.buffer.length<this.offset+l)throw new Error("Cannot read slice out of bounds");const p=this.buffer.slice(this.offset,this.offset+l);return this.offset+=l,p}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const l=this.readVarInt(),p=[];for(let y=0;y<l;y++)p.push(this.readVarSlice());return p}}return At.BufferReader=u,At}var $0;function Zl(){return $0||($0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Vo(),n=Yl(),r=xr(),i=su(),s=Lt();e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=w=>"left"in w&&"right"in w;function c(w,E){if(w.length<33)throw new TypeError(`The control-block length is too small. Got ${w.length}, expected min 33.`);const _=(w.length-33)/32;let S=E;for(let m=0;m<_;m++){const T=w.slice(33+32*m,65+32*m);S.compare(T)<0?S=y(S,T):S=y(T,S)}return S}e.rootHashFromPath=c;function a(w){if((0,s.isTapleaf)(w))return{hash:f(w)};const E=[a(w[0]),a(w[1])];E.sort((m,T)=>m.hash.compare(T.hash));const[_,S]=E;return{hash:y(_.hash,S.hash),left:_,right:S}}e.toHashTree=a;function u(w,E){if(o(w)){const _=u(w.left,E);if(_!==void 0)return[..._,w.right.hash];const S=u(w.right,E);if(S!==void 0)return[...S,w.left.hash]}else if(w.hash.equals(E))return[]}e.findScriptPath=u;function f(w){const E=w.version||e.LEAF_VERSION_TAPSCRIPT;return r.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([E]),g(w.output)]))}e.tapleafHash=f;function l(w,E){return r.taggedHash("TapTweak",t.Buffer.concat(E?[w,E]:[w]))}e.tapTweakHash=l;function p(w,E){if(!t.Buffer.isBuffer(w)||w.length!==32||E&&E.length!==32)return null;const _=l(w,E),S=(0,n.getEccLib)().xOnlyPointAddTweak(w,_);return!S||S.xOnlyPubkey===null?null:{parity:S.parity,x:t.Buffer.from(S.xOnlyPubkey)}}e.tweakKey=p;function y(w,E){return r.taggedHash("TapBranch",t.Buffer.concat([w,E]))}function g(w){const E=i.varuint.encodingLength(w.length),_=t.Buffer.allocUnsafe(E);return i.varuint.encode(w.length,_),t.Buffer.concat([_,w])}})(lf)),lf}var K0;function Z8(){if(K0)return eo;K0=1,Object.defineProperty(eo,"__esModule",{value:!0}),eo.p2tr=void 0;const e=Vo(),t=Vn(),n=Jt(),r=Lt(),i=Yl(),s=Zl(),o=ui(),c=Do(),a=Jl(),u=n.OPS,f=1,l=80;function p(y,g){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");g=Object.assign({validate:!0},g||{}),(0,r.typeforce)({address:r.typeforce.maybe(r.typeforce.String),input:r.typeforce.maybe(r.typeforce.BufferN(0)),network:r.typeforce.maybe(r.typeforce.Object),output:r.typeforce.maybe(r.typeforce.BufferN(34)),internalPubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),hash:r.typeforce.maybe(r.typeforce.BufferN(32)),pubkey:r.typeforce.maybe(r.typeforce.BufferN(32)),signature:r.typeforce.maybe(r.typeforce.anyOf(r.typeforce.BufferN(64),r.typeforce.BufferN(65))),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer)),scriptTree:r.typeforce.maybe(r.isTaptree),redeem:r.typeforce.maybe({output:r.typeforce.maybe(r.typeforce.Buffer),redeemVersion:r.typeforce.maybe(r.typeforce.Number),witness:r.typeforce.maybe(r.typeforce.arrayOf(r.typeforce.Buffer))}),redeemVersion:r.typeforce.maybe(r.typeforce.Number)},y);const w=o.value(()=>(0,a.fromBech32)(y.address)),E=o.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===l?y.witness.slice(0,-1):y.witness.slice()}),_=o.value(()=>{if(y.scriptTree)return(0,s.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),S=y.network||t.bitcoin,m={name:"p2tr",network:S};if(o.prop(m,"address",()=>{if(!m.pubkey)return;const T=c.bech32m.toWords(m.pubkey);return T.unshift(f),c.bech32m.encode(S.bech32,T)}),o.prop(m,"hash",()=>{const T=_();if(T)return T.hash;const I=E();if(I&&I.length>1){const A=I[I.length-1],U=A[0]&r.TAPLEAF_VERSION_MASK,M=I[I.length-2],v=(0,s.tapleafHash)({output:M,version:U});return(0,s.rootHashFromPath)(A,v)}return null}),o.prop(m,"output",()=>{if(m.pubkey)return n.compile([u.OP_1,m.pubkey])}),o.prop(m,"redeemVersion",()=>y.redeemVersion?y.redeemVersion:y.redeem&&y.redeem.redeemVersion!==void 0&&y.redeem.redeemVersion!==null?y.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(m,"redeem",()=>{const T=E();if(!(!T||T.length<2))return{output:T[T.length-2],witness:T.slice(0,-2),redeemVersion:T[T.length-1][0]&r.TAPLEAF_VERSION_MASK}}),o.prop(m,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return w().data;if(m.internalPubkey){const T=(0,s.tweakKey)(m.internalPubkey,m.hash);if(T)return T.x}}),o.prop(m,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const T=E();if(T&&T.length>1)return T[T.length-1].slice(1,33)}),o.prop(m,"signature",()=>{if(y.signature)return y.signature;const T=E();if(!(!T||T.length!==1))return T[0]}),o.prop(m,"witness",()=>{if(y.witness)return y.witness;const T=_();if(T&&y.redeem&&y.redeem.output&&y.internalPubkey){const I=(0,s.tapleafHash)({output:y.redeem.output,version:m.redeemVersion}),A=(0,s.findScriptPath)(T,I);if(!A)return;const U=(0,s.tweakKey)(y.internalPubkey,T.hash);if(!U)return;const M=e.Buffer.concat([e.Buffer.from([m.redeemVersion|U.parity]),y.internalPubkey].concat(A));return[y.redeem.output,M]}if(y.signature)return[y.signature]}),g.validate){let T=e.Buffer.from([]);if(y.address){if(S&&S.bech32!==w().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(w().version!==f)throw new TypeError("Invalid address version");if(w().data.length!==32)throw new TypeError("Invalid address data");T=w().data}if(y.pubkey){if(T.length>0&&!T.equals(y.pubkey))throw new TypeError("Pubkey mismatch");T=y.pubkey}if(y.output){if(y.output.length!==34||y.output[0]!==u.OP_1||y.output[1]!==32)throw new TypeError("Output is invalid");if(T.length>0&&!T.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");T=y.output.slice(2)}if(y.internalPubkey){const U=(0,s.tweakKey)(y.internalPubkey,m.hash);if(T.length>0&&!T.equals(U.x))throw new TypeError("Pubkey mismatch");T=U.x}if(T&&T.length&&!(0,i.getEccLib)().isXOnlyPoint(T))throw new TypeError("Invalid pubkey for p2tr");const I=_();if(y.hash&&I&&!y.hash.equals(I.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&I){const U=(0,s.tapleafHash)({output:y.redeem.output,version:m.redeemVersion});if(!(0,s.findScriptPath)(I,U))throw new TypeError("Redeem script not in tree")}const A=E();if(y.redeem&&m.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==m.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(y.redeem.output){if(n.decompile(y.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(m.redeem.output&&!y.redeem.output.equals(m.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&m.redeem.witness&&!(0,r.stacksEqual)(y.redeem.witness,m.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(A&&A.length)if(A.length===1){if(y.signature&&!y.signature.equals(A[0]))throw new TypeError("Signature mismatch")}else{const U=A[A.length-1];if(U.length<33)throw new TypeError(`The control-block length is too small. Got ${U.length}, expected min 33.`);if((U.length-33)%32!==0)throw new TypeError(`The control-block length of ${U.length} is incorrect!`);const M=(U.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const v=U.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(v))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(v))throw new TypeError("Invalid internalPubkey for p2tr witness");const R=U[0]&r.TAPLEAF_VERSION_MASK,V=A[A.length-2],W=(0,s.tapleafHash)({output:V,version:R}),H=(0,s.rootHashFromPath)(U,W),K=(0,s.tweakKey)(v,H);if(!K)throw new TypeError("Invalid outputKey for p2tr witness");if(T.length&&!T.equals(K.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(K.parity!==(U[0]&1))throw new Error("Incorrect parity")}}return Object.assign(m,y)}return eo.p2tr=p,eo}var L0;function cc(){return L0||(L0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=F8();Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const n=M8();Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return n.p2ms}});const r=q8();Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return r.p2pk}});const i=W8();Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=G8();Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=D8();Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const c=X8();Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return c.p2wsh}});const a=Z8();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return a.p2tr}})})(Ju)),Ju}var j0;function Jl(){if(j0)return Wt;j0=1,Object.defineProperty(Wt,"__esModule",{value:!0}),Wt.toOutputScript=Wt.fromOutputScript=Wt.toBech32=Wt.toBase58Check=Wt.fromBech32=Wt.fromBase58Check=void 0;const e=Vn(),t=cc(),n=Jt(),r=Lt(),i=Do(),s=zl(),o=40,c=2,a=16,u=2,f=80,l="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function p(m,T){const I=m.slice(2);if(I.length<c||I.length>o)throw new TypeError("Invalid program length for segwit address");const A=m[0]-f;if(A<u||A>a)throw new TypeError("Invalid version for segwit address");if(m[1]!==I.length)throw new TypeError("Invalid script for segwit address");return console.warn(l),E(I,A,T.bech32)}function y(m){const T=Buffer.from(s.decode(m));if(T.length<21)throw new TypeError(m+" is too short");if(T.length>21)throw new TypeError(m+" is too long");const I=T.readUInt8(0),A=T.slice(1);return{version:I,hash:A}}Wt.fromBase58Check=y;function g(m){let T,I;try{T=i.bech32.decode(m)}catch{}if(T){if(I=T.words[0],I!==0)throw new TypeError(m+" uses wrong encoding")}else if(T=i.bech32m.decode(m),I=T.words[0],I===0)throw new TypeError(m+" uses wrong encoding");const A=i.bech32.fromWords(T.words.slice(1));return{version:I,prefix:T.prefix,data:Buffer.from(A)}}Wt.fromBech32=g;function w(m,T){(0,r.typeforce)((0,r.tuple)(r.Hash160bit,r.UInt8),arguments);const I=Buffer.allocUnsafe(21);return I.writeUInt8(T,0),m.copy(I,1),s.encode(I)}Wt.toBase58Check=w;function E(m,T,I){const A=i.bech32.toWords(m);return A.unshift(T),T===0?i.bech32.encode(I,A):i.bech32m.encode(I,A)}Wt.toBech32=E;function _(m,T){T=T||e.bitcoin;try{return t.p2pkh({output:m,network:T}).address}catch{}try{return t.p2sh({output:m,network:T}).address}catch{}try{return t.p2wpkh({output:m,network:T}).address}catch{}try{return t.p2wsh({output:m,network:T}).address}catch{}try{return t.p2tr({output:m,network:T}).address}catch{}try{return p(m,T)}catch{}throw new Error(n.toASM(m)+" has no matching Address")}Wt.fromOutputScript=_;function S(m,T){T=T||e.bitcoin;let I,A;try{I=y(m)}catch{}if(I){if(I.version===T.pubKeyHash)return t.p2pkh({hash:I.hash}).output;if(I.version===T.scriptHash)return t.p2sh({hash:I.hash}).output}else{try{A=g(m)}catch{}if(A){if(A.prefix!==T.bech32)throw new Error(m+" has an invalid prefix");if(A.version===0){if(A.data.length===20)return t.p2wpkh({hash:A.data}).output;if(A.data.length===32)return t.p2wsh({hash:A.data}).output}else if(A.version===1){if(A.data.length===32)return t.p2tr({pubkey:A.data}).output}else if(A.version>=u&&A.version<=a&&A.data.length>=c&&A.data.length<=o)return console.warn(l),n.compile([A.version+f,A.data])}}throw new Error(m+" has no matching Script")}return Wt.toOutputScript=S,Wt}var to={},no={},W0;function J8(){if(W0)return no;W0=1,Object.defineProperty(no,"__esModule",{value:!0}),no.fastMerkleRoot=void 0;function e(t,n){if(!Array.isArray(t))throw TypeError("Expected values Array");if(typeof n!="function")throw TypeError("Expected digest Function");let r=t.length;const i=t.concat();for(;r>1;){let s=0;for(let o=0;o<r;o+=2,++s){const c=i[o],a=o+1===r?c:i[o+1],u=Buffer.concat([c,a]);i[s]=n(u)}r=s}return i[0]}return no.fastMerkleRoot=e,no}var ro={},G0;function ac(){if(G0)return ro;G0=1,Object.defineProperty(ro,"__esModule",{value:!0}),ro.Transaction=void 0;const e=su(),t=xr(),n=Jt(),r=Jt(),i=Lt(),{typeforce:s}=i;function o(E){const _=E.length;return e.varuint.encodingLength(_)+_}function c(E){const _=E.length;return e.varuint.encodingLength(_)+E.reduce((S,m)=>S+o(m),0)}const a=Buffer.allocUnsafe(0),u=[],f=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),l=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),p=Buffer.from("ffffffffffffffff","hex"),y={script:a,valueBuffer:p};function g(E){return E.value!==void 0}class w{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(_,S){const m=new e.BufferReader(_),T=new w;T.version=m.readInt32();const I=m.readUInt8(),A=m.readUInt8();let U=!1;I===w.ADVANCED_TRANSACTION_MARKER&&A===w.ADVANCED_TRANSACTION_FLAG?U=!0:m.offset-=2;const M=m.readVarInt();for(let R=0;R<M;++R)T.ins.push({hash:m.readSlice(32),index:m.readUInt32(),script:m.readVarSlice(),sequence:m.readUInt32(),witness:u});const v=m.readVarInt();for(let R=0;R<v;++R)T.outs.push({value:m.readUInt64(),script:m.readVarSlice()});if(U){for(let R=0;R<M;++R)T.ins[R].witness=m.readVector();if(!T.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(T.locktime=m.readUInt32(),S)return T;if(m.offset!==_.length)throw new Error("Transaction has unexpected data");return T}static fromHex(_){return w.fromBuffer(Buffer.from(_,"hex"),!1)}static isCoinbaseHash(_){s(i.Hash256bit,_);for(let S=0;S<32;++S)if(_[S]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&w.isCoinbaseHash(this.ins[0].hash)}addInput(_,S,m,T){return s(i.tuple(i.Hash256bit,i.UInt32,i.maybe(i.UInt32),i.maybe(i.Buffer)),arguments),i.Null(m)&&(m=w.DEFAULT_SEQUENCE),this.ins.push({hash:_,index:S,script:T||a,sequence:m,witness:u})-1}addOutput(_,S){return s(i.tuple(i.Buffer,i.Satoshi),arguments),this.outs.push({script:_,value:S})-1}hasWitnesses(){return this.ins.some(_=>_.witness.length!==0)}stripWitnesses(){this.ins.forEach(_=>{_.witness=u})}weight(){const _=this.byteLength(!1),S=this.byteLength(!0);return _*3+S}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(_=!0){const S=_&&this.hasWitnesses();return(S?10:8)+e.varuint.encodingLength(this.ins.length)+e.varuint.encodingLength(this.outs.length)+this.ins.reduce((m,T)=>m+40+o(T.script),0)+this.outs.reduce((m,T)=>m+8+o(T.script),0)+(S?this.ins.reduce((m,T)=>m+c(T.witness),0):0)}clone(){const _=new w;return _.version=this.version,_.locktime=this.locktime,_.ins=this.ins.map(S=>({hash:S.hash,index:S.index,script:S.script,sequence:S.sequence,witness:S.witness})),_.outs=this.outs.map(S=>({script:S.script,value:S.value})),_}hashForSignature(_,S,m){if(s(i.tuple(i.UInt32,i.Buffer,i.Number),arguments),_>=this.ins.length)return l;const T=n.compile(n.decompile(S).filter(U=>U!==r.OPS.OP_CODESEPARATOR)),I=this.clone();if((m&31)===w.SIGHASH_NONE)I.outs=[],I.ins.forEach((U,M)=>{M!==_&&(U.sequence=0)});else if((m&31)===w.SIGHASH_SINGLE){if(_>=this.outs.length)return l;I.outs.length=_+1;for(let U=0;U<_;U++)I.outs[U]=y;I.ins.forEach((U,M)=>{M!==_&&(U.sequence=0)})}m&w.SIGHASH_ANYONECANPAY?(I.ins=[I.ins[_]],I.ins[0].script=T):(I.ins.forEach(U=>{U.script=a}),I.ins[_].script=T);const A=Buffer.allocUnsafe(I.byteLength(!1)+4);return A.writeInt32LE(m,A.length-4),I.__toBuffer(A,0,!1),t.hash256(A)}hashForWitnessV1(_,S,m,T,I,A){if(s(i.tuple(i.UInt32,s.arrayOf(i.Buffer),s.arrayOf(i.Satoshi),i.UInt32),arguments),m.length!==this.ins.length||S.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const U=T===w.SIGHASH_DEFAULT?w.SIGHASH_ALL:T&w.SIGHASH_OUTPUT_MASK,v=(T&w.SIGHASH_INPUT_MASK)===w.SIGHASH_ANYONECANPAY,R=U===w.SIGHASH_NONE,V=U===w.SIGHASH_SINGLE;let W=a,H=a,K=a,N=a,L=a;if(!v){let q=e.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(P=>{q.writeSlice(P.hash),q.writeUInt32(P.index)}),W=t.sha256(q.end()),q=e.BufferWriter.withCapacity(8*this.ins.length),m.forEach(P=>q.writeUInt64(P)),H=t.sha256(q.end()),q=e.BufferWriter.withCapacity(S.map(o).reduce((P,$)=>P+$)),S.forEach(P=>q.writeVarSlice(P)),K=t.sha256(q.end()),q=e.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(P=>q.writeUInt32(P.sequence)),N=t.sha256(q.end())}if(R||V){if(V&&_<this.outs.length){const q=this.outs[_],P=e.BufferWriter.withCapacity(8+o(q.script));P.writeUInt64(q.value),P.writeVarSlice(q.script),L=t.sha256(P.end())}}else{const q=this.outs.map($=>8+o($.script)).reduce(($,G)=>$+G),P=e.BufferWriter.withCapacity(q);this.outs.forEach($=>{P.writeUInt64($.value),P.writeVarSlice($.script)}),L=t.sha256(P.end())}const F=(I?2:0)+(A?1:0),x=174-(v?49:0)-(R?32:0)+(A?32:0)+(I?37:0),O=e.BufferWriter.withCapacity(x);if(O.writeUInt8(T),O.writeInt32(this.version),O.writeUInt32(this.locktime),O.writeSlice(W),O.writeSlice(H),O.writeSlice(K),O.writeSlice(N),R||V||O.writeSlice(L),O.writeUInt8(F),v){const q=this.ins[_];O.writeSlice(q.hash),O.writeUInt32(q.index),O.writeUInt64(m[_]),O.writeVarSlice(S[_]),O.writeUInt32(q.sequence)}else O.writeUInt32(_);if(A){const q=e.BufferWriter.withCapacity(o(A));q.writeVarSlice(A),O.writeSlice(t.sha256(q.end()))}return V&&O.writeSlice(L),I&&(O.writeSlice(I),O.writeUInt8(0),O.writeUInt32(4294967295)),t.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),O.end()]))}hashForWitnessV0(_,S,m,T){s(i.tuple(i.UInt32,i.Buffer,i.Satoshi,i.UInt32),arguments);let I=Buffer.from([]),A,U=f,M=f,v=f;if(T&w.SIGHASH_ANYONECANPAY||(I=Buffer.allocUnsafe(36*this.ins.length),A=new e.BufferWriter(I,0),this.ins.forEach(V=>{A.writeSlice(V.hash),A.writeUInt32(V.index)}),M=t.hash256(I)),!(T&w.SIGHASH_ANYONECANPAY)&&(T&31)!==w.SIGHASH_SINGLE&&(T&31)!==w.SIGHASH_NONE&&(I=Buffer.allocUnsafe(4*this.ins.length),A=new e.BufferWriter(I,0),this.ins.forEach(V=>{A.writeUInt32(V.sequence)}),v=t.hash256(I)),(T&31)!==w.SIGHASH_SINGLE&&(T&31)!==w.SIGHASH_NONE){const V=this.outs.reduce((W,H)=>W+8+o(H.script),0);I=Buffer.allocUnsafe(V),A=new e.BufferWriter(I,0),this.outs.forEach(W=>{A.writeUInt64(W.value),A.writeVarSlice(W.script)}),U=t.hash256(I)}else if((T&31)===w.SIGHASH_SINGLE&&_<this.outs.length){const V=this.outs[_];I=Buffer.allocUnsafe(8+o(V.script)),A=new e.BufferWriter(I,0),A.writeUInt64(V.value),A.writeVarSlice(V.script),U=t.hash256(I)}I=Buffer.allocUnsafe(156+o(S)),A=new e.BufferWriter(I,0);const R=this.ins[_];return A.writeInt32(this.version),A.writeSlice(M),A.writeSlice(v),A.writeSlice(R.hash),A.writeUInt32(R.index),A.writeVarSlice(S),A.writeUInt64(m),A.writeUInt32(R.sequence),A.writeSlice(U),A.writeUInt32(this.locktime),A.writeUInt32(T),t.hash256(I)}getHash(_){return _&&this.isCoinbase()?Buffer.alloc(32,0):t.hash256(this.__toBuffer(void 0,void 0,_))}getId(){return(0,e.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(_,S){return this.__toBuffer(_,S,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(_,S){s(i.tuple(i.Number,i.Buffer),arguments),this.ins[_].script=S}setWitness(_,S){s(i.tuple(i.Number,[i.Buffer]),arguments),this.ins[_].witness=S}__toBuffer(_,S,m=!1){_||(_=Buffer.allocUnsafe(this.byteLength(m)));const T=new e.BufferWriter(_,S||0);T.writeInt32(this.version);const I=m&&this.hasWitnesses();return I&&(T.writeUInt8(w.ADVANCED_TRANSACTION_MARKER),T.writeUInt8(w.ADVANCED_TRANSACTION_FLAG)),T.writeVarInt(this.ins.length),this.ins.forEach(A=>{T.writeSlice(A.hash),T.writeUInt32(A.index),T.writeVarSlice(A.script),T.writeUInt32(A.sequence)}),T.writeVarInt(this.outs.length),this.outs.forEach(A=>{g(A)?T.writeUInt64(A.value):T.writeSlice(A.valueBuffer),T.writeVarSlice(A.script)}),I&&this.ins.forEach(A=>{T.writeVector(A.witness)}),T.writeUInt32(this.locktime),S!==void 0?_.slice(S,T.offset):_}}return ro.Transaction=w,w.DEFAULT_SEQUENCE=4294967295,w.SIGHASH_DEFAULT=0,w.SIGHASH_ALL=1,w.SIGHASH_NONE=2,w.SIGHASH_SINGLE=3,w.SIGHASH_ANYONECANPAY=128,w.SIGHASH_OUTPUT_MASK=3,w.SIGHASH_INPUT_MASK=128,w.ADVANCED_TRANSACTION_MARKER=0,w.ADVANCED_TRANSACTION_FLAG=1,ro}var D0;function Q8(){if(D0)return to;D0=1,Object.defineProperty(to,"__esModule",{value:!0}),to.Block=void 0;const e=su(),t=xr(),n=J8(),r=ac(),i=Lt(),{typeforce:s}=i,o=new TypeError("Cannot compute merkle root for zero transactions"),c=new TypeError("Cannot compute witness commit for non-segwit block");class a{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(p){if(p.length<80)throw new Error("Buffer too small (< 80 bytes)");const y=new e.BufferReader(p),g=new a;if(g.version=y.readInt32(),g.prevHash=y.readSlice(32),g.merkleRoot=y.readSlice(32),g.timestamp=y.readUInt32(),g.bits=y.readUInt32(),g.nonce=y.readUInt32(),p.length===80)return g;const w=()=>{const S=r.Transaction.fromBuffer(y.buffer.slice(y.offset),!0);return y.offset+=S.byteLength(),S},E=y.readVarInt();g.transactions=[];for(let S=0;S<E;++S){const m=w();g.transactions.push(m)}const _=g.getWitnessCommit();return _&&(g.witnessCommit=_),g}static fromHex(p){return a.fromBuffer(Buffer.from(p,"hex"))}static calculateTarget(p){const y=((p&4278190080)>>24)-3,g=p&8388607,w=Buffer.alloc(32,0);return w.writeUIntBE(g,29-y,3),w}static calculateMerkleRoot(p,y){if(s([{getHash:i.Function}],p),p.length===0)throw o;if(y&&!u(p))throw c;const g=p.map(E=>E.getHash(y)),w=(0,n.fastMerkleRoot)(g,t.hash256);return y?t.hash256(Buffer.concat([w,p[0].ins[0].witness[0]])):w}getWitnessCommit(){if(!u(this.transactions))return null;const p=this.transactions[0].outs.filter(g=>g.script.slice(0,6).equals(Buffer.from("6a24aa21a9ed","hex"))).map(g=>g.script.slice(6,38));if(p.length===0)return null;const y=p[p.length-1];return y instanceof Buffer&&y.length===32?y:null}hasWitnessCommit(){return this.witnessCommit instanceof Buffer&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return f(this.transactions)}weight(){const p=this.byteLength(!1,!1),y=this.byteLength(!1,!0);return p*3+y}byteLength(p,y=!0){return p||!this.transactions?80:80+e.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((g,w)=>g+w.byteLength(y),0)}getHash(){return t.hash256(this.toBuffer(!0))}getId(){return(0,e.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const p=new Date(0);return p.setUTCSeconds(this.timestamp),p}toBuffer(p){const y=Buffer.allocUnsafe(this.byteLength(p)),g=new e.BufferWriter(y);return g.writeInt32(this.version),g.writeSlice(this.prevHash),g.writeSlice(this.merkleRoot),g.writeUInt32(this.timestamp),g.writeUInt32(this.bits),g.writeUInt32(this.nonce),p||!this.transactions||(e.varuint.encode(this.transactions.length,y,g.offset),g.offset+=e.varuint.encode.bytes,this.transactions.forEach(w=>{const E=w.byteLength();w.toBuffer(y,g.offset),g.offset+=E})),y}toHex(p){return this.toBuffer(p).toString("hex")}checkTxRoots(){const p=this.hasWitnessCommit();return!p&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(p?this.__checkWitnessCommit():!0)}checkProofOfWork(){const p=(0,e.reverseBuffer)(this.getHash()),y=a.calculateTarget(this.bits);return p.compare(y)<=0}__checkMerkleRoot(){if(!this.transactions)throw o;const p=a.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(p)===0}__checkWitnessCommit(){if(!this.transactions)throw o;if(!this.hasWitnessCommit())throw c;const p=a.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(p)===0}}to.Block=a;function u(l){return l instanceof Array&&l[0]&&l[0].ins&&l[0].ins instanceof Array&&l[0].ins[0]&&l[0].ins[0].witness&&l[0].ins[0].witness instanceof Array&&l[0].ins[0].witness.length>0}function f(l){return l instanceof Array&&l.some(p=>typeof p=="object"&&p.ins instanceof Array&&p.ins.some(y=>typeof y=="object"&&y.witness instanceof Array&&y.witness.length>0))}return to}var io={},Ac={},vc={},df={},es={},ts={},pf={},X0;function Ut(){return X0||(X0=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),(function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],(function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],(function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(pf)),pf}var Nr={},z0;function ex(){if(z0)return Nr;z0=1,Object.defineProperty(Nr,"__esModule",{value:!0});const e=Ut(),t=o=>[...Array(o).keys()];function n(o){if(o.key[0]!==e.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+o.key.toString("hex"));if(o.key.length!==79||![2,3].includes(o.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+o.key.toString("hex"));if(o.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const c=o.key.slice(1),a={masterFingerprint:o.value.slice(0,4),extendedPubkey:c,path:"m"};for(const u of t(o.value.length/4-1)){const f=o.value.readUInt32LE(u*4+4),l=!!(f&2147483648),p=f&2147483647;a.path+="/"+p.toString(10)+(l?"'":"")}return a}Nr.decode=n;function r(o){const c=Buffer.from([e.GlobalTypes.GLOBAL_XPUB]),a=Buffer.concat([c,o.extendedPubkey]),u=o.path.split("/"),f=Buffer.allocUnsafe(u.length*4);o.masterFingerprint.copy(f,0);let l=4;return u.slice(1).forEach(p=>{const y=p.slice(-1)==="'";let g=2147483647&parseInt(y?p.slice(0,-1):p,10);y&&(g+=2147483648),f.writeUInt32LE(g,l),l+=4}),{key:a,value:f}}Nr.encode=r,Nr.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function i(o){const c=o.extendedPubkey,a=o.masterFingerprint,u=o.path;return Buffer.isBuffer(c)&&c.length===78&&[2,3].indexOf(c[45])>-1&&Buffer.isBuffer(a)&&a.length===4&&typeof u=="string"&&!!u.match(/^m(\/\d+'?)*$/)}Nr.check=i;function s(o,c,a){const u=c.extendedPubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.extendedPubkey.equals(c.extendedPubkey)).length===0)}return Nr.canAddToArray=s,Nr}var Bc={},Y0;function tx(){if(Y0)return Bc;Y0=1,Object.defineProperty(Bc,"__esModule",{value:!0});const e=Ut();function t(n){return{key:Buffer.from([e.GlobalTypes.UNSIGNED_TX]),value:n.toBuffer()}}return Bc.encode=t,Bc}var Ur={},Z0;function nx(){if(Z0)return Ur;Z0=1,Object.defineProperty(Ur,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+s.key.toString("hex"));return s.value}Ur.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTSIG]),value:s}}Ur.encode=n,Ur.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Ur.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptSig===void 0}return Ur.canAdd=i,Ur}var Rr={},J0;function rx(){if(J0)return Rr;J0=1,Object.defineProperty(Rr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+s.key.toString("hex"));return s.value}Rr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.FINAL_SCRIPTWITNESS]),value:s}}Rr.encode=n,Rr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Rr.check=r;function i(s,o){return!!s&&!!o&&s.finalScriptWitness===void 0}return Rr.canAdd=i,Rr}var Cr={},Q0;function ix(){if(Q0)return Cr;Q0=1,Object.defineProperty(Cr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+s.key.toString("hex"));return s.value}Cr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.NON_WITNESS_UTXO]),value:s}}Cr.encode=n,Cr.expected="Buffer";function r(s){return Buffer.isBuffer(s)}Cr.check=r;function i(s,o){return!!s&&!!o&&s.nonWitnessUtxo===void 0}return Cr.canAdd=i,Cr}var Hr={},ep;function sx(){if(ep)return Hr;ep=1,Object.defineProperty(Hr,"__esModule",{value:!0});const e=Ut();function t(o){if(o.key[0]!==e.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+o.key.toString("hex"));if(!(o.key.length===34||o.key.length===66)||![2,3,4].includes(o.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+o.key.toString("hex"));return{pubkey:o.key.slice(1),signature:o.value}}Hr.decode=t;function n(o){const c=Buffer.from([e.InputTypes.PARTIAL_SIG]);return{key:Buffer.concat([c,o.pubkey]),value:o.signature}}Hr.encode=n,Hr.expected="{ pubkey: Buffer; signature: Buffer; }";function r(o){return Buffer.isBuffer(o.pubkey)&&Buffer.isBuffer(o.signature)&&[33,65].includes(o.pubkey.length)&&[2,3,4].includes(o.pubkey[0])&&i(o.signature)}Hr.check=r;function i(o){if(!Buffer.isBuffer(o)||o.length<9||o[0]!==48||o.length!==o[1]+3||o[2]!==2)return!1;const c=o[3];if(c>33||c<1||o[3+c+1]!==2)return!1;const a=o[3+c+2];return!(a>33||a<1||o.length!==3+c+2+a+2)}function s(o,c,a){const u=c.pubkey.toString("hex");return a.has(u)?!1:(a.add(u),o.filter(f=>f.pubkey.equals(c.pubkey)).length===0)}return Hr.canAddToArray=s,Hr}var Fr={},tp;function ox(){if(tp)return Fr;tp=1,Object.defineProperty(Fr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+s.key.toString("hex"));return s.value.toString("utf8")}Fr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.POR_COMMITMENT]),value:Buffer.from(s,"utf8")}}Fr.encode=n,Fr.expected="string";function r(s){return typeof s=="string"}Fr.check=r;function i(s,o){return!!s&&!!o&&s.porCommitment===void 0}return Fr.canAdd=i,Fr}var Mr={},np;function cx(){if(np)return Mr;np=1,Object.defineProperty(Mr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+s.key.toString("hex"));return s.value.readUInt32LE(0)}Mr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.SIGHASH_TYPE]),c=Buffer.allocUnsafe(4);return c.writeUInt32LE(s,0),{key:o,value:c}}Mr.encode=n,Mr.expected="number";function r(s){return typeof s=="number"}Mr.check=r;function i(s,o){return!!s&&!!o&&s.sighashType===void 0}return Mr.canAdd=i,Mr}var qr={},rp;function ax(){if(rp)return qr;rp=1,Object.defineProperty(qr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_KEY_SIG||s.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return s.value}qr.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_KEY_SIG]),value:s}}qr.encode=n,qr.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&(s.length===64||s.length===65)}qr.check=r;function i(s,o){return!!s&&!!o&&s.tapKeySig===void 0}return qr.canAdd=i,qr}var Vr={},ip;function ux(){if(ip)return Vr;ip=1,Object.defineProperty(Vr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+s.key.toString("hex"));if((s.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+s.key.toString("hex"));const o=s.value[s.value.length-1];if((s.key[1]&254)!==o)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+s.key.toString("hex"));const c=s.value.slice(0,-1);return{controlBlock:s.key.slice(1),script:c,leafVersion:o}}Vr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_LEAF_SCRIPT]),c=Buffer.from([s.leafVersion]);return{key:Buffer.concat([o,s.controlBlock]),value:Buffer.concat([s.script,c])}}Vr.encode=n,Vr.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function r(s){return Buffer.isBuffer(s.controlBlock)&&(s.controlBlock.length-1)%32===0&&(s.controlBlock[0]&254)===s.leafVersion&&Buffer.isBuffer(s.script)}Vr.check=r;function i(s,o,c){const a=o.controlBlock.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.controlBlock.equals(o.controlBlock)).length===0)}return Vr.canAddToArray=i,Vr}var $r={},sp;function fx(){if(sp)return $r;sp=1,Object.defineProperty($r,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_MERKLE_ROOT||s.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+s.key.toString("hex"));if(!r(s.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return s.value}$r.decode=t;function n(s){return{key:Buffer.from([e.InputTypes.TAP_MERKLE_ROOT]),value:s}}$r.encode=n,$r.expected="Buffer";function r(s){return Buffer.isBuffer(s)&&s.length===32}$r.check=r;function i(s,o){return!!s&&!!o&&s.tapMerkleRoot===void 0}return $r.canAdd=i,$r}var Kr={},op;function lx(){if(op)return Kr;op=1,Object.defineProperty(Kr,"__esModule",{value:!0});const e=Ut();function t(s){if(s.key[0]!==e.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+s.key.toString("hex"));if(s.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+s.key.toString("hex"));if(s.value.length!==64&&s.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+s.key.toString("hex"));const o=s.key.slice(1,33),c=s.key.slice(33);return{pubkey:o,leafHash:c,signature:s.value}}Kr.decode=t;function n(s){const o=Buffer.from([e.InputTypes.TAP_SCRIPT_SIG]);return{key:Buffer.concat([o,s.pubkey,s.leafHash]),value:s.signature}}Kr.encode=n,Kr.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function r(s){return Buffer.isBuffer(s.pubkey)&&Buffer.isBuffer(s.leafHash)&&Buffer.isBuffer(s.signature)&&s.pubkey.length===32&&s.leafHash.length===32&&(s.signature.length===64||s.signature.length===65)}Kr.check=r;function i(s,o,c){const a=o.pubkey.toString("hex")+o.leafHash.toString("hex");return c.has(a)?!1:(c.add(a),s.filter(u=>u.pubkey.equals(o.pubkey)&&u.leafHash.equals(o.leafHash)).length===0)}return Kr.canAddToArray=i,Kr}var Lr={},ir={},ns={},cp;function Xi(){if(cp)return ns;cp=1,Object.defineProperty(ns,"__esModule",{value:!0});const e=9007199254740991;function t(s){if(s<0||s>e||s%1!==0)throw new RangeError("value out of range")}function n(s,o,c){if(t(s),o||(o=Buffer.allocUnsafe(i(s))),!Buffer.isBuffer(o))throw new TypeError("buffer must be a Buffer instance");return c||(c=0),s<253?(o.writeUInt8(s,c),Object.assign(n,{bytes:1})):s<=65535?(o.writeUInt8(253,c),o.writeUInt16LE(s,c+1),Object.assign(n,{bytes:3})):s<=4294967295?(o.writeUInt8(254,c),o.writeUInt32LE(s,c+1),Object.assign(n,{bytes:5})):(o.writeUInt8(255,c),o.writeUInt32LE(s>>>0,c+1),o.writeUInt32LE(s/4294967296|0,c+5),Object.assign(n,{bytes:9})),o}ns.encode=n;function r(s,o){if(!Buffer.isBuffer(s))throw new TypeError("buffer must be a Buffer instance");o||(o=0);const c=s.readUInt8(o);if(c<253)return Object.assign(r,{bytes:1}),c;if(c===253)return Object.assign(r,{bytes:3}),s.readUInt16LE(o+1);if(c===254)return Object.assign(r,{bytes:5}),s.readUInt32LE(o+1);{Object.assign(r,{bytes:9});const a=s.readUInt32LE(o+1),f=s.readUInt32LE(o+5)*4294967296+a;return t(f),f}}ns.decode=r;function i(s){return t(s),s<253?1:s<=65535?3:s<=4294967295?5:9}return ns.encodingLength=i,ns}var ap;function Ql(){if(ap)return ir;ap=1,Object.defineProperty(ir,"__esModule",{value:!0});const e=Xi();ir.range=c=>[...Array(c).keys()];function t(c){if(c.length<1)return c;let a=c.length-1,u=0;for(let f=0;f<c.length/2;f++)u=c[f],c[f]=c[a],c[a]=u,a--;return c}ir.reverseBuffer=t;function n(c){const a=c.map(r);return a.push(Buffer.from([0])),Buffer.concat(a)}ir.keyValsToBuffer=n;function r(c){const a=c.key.length,u=c.value.length,f=e.encodingLength(a),l=e.encodingLength(u),p=Buffer.allocUnsafe(f+a+l+u);return e.encode(a,p,0),c.key.copy(p,f),e.encode(u,p,f+a),c.value.copy(p,f+a+l),p}ir.keyValToBuffer=r;function i(c,a){if(typeof c!="number")throw new Error("cannot write a non-number as a number");if(c<0)throw new Error("specified a negative value for writing an unsigned value");if(c>a)throw new Error("RangeError: value out of range");if(Math.floor(c)!==c)throw new Error("value has a fractional component")}function s(c,a){const u=c.readUInt32LE(a);let f=c.readUInt32LE(a+4);return f*=4294967296,i(f+u,9007199254740991),f+u}ir.readUInt64LE=s;function o(c,a,u){return i(a,9007199254740991),c.writeInt32LE(a&-1,u),c.writeUInt32LE(Math.floor(a/4294967296),u+4),u+8}return ir.writeUInt64LE=o,ir}var up;function hx(){if(up)return Lr;up=1,Object.defineProperty(Lr,"__esModule",{value:!0});const e=Ut(),t=Ql(),n=Xi();function r(c){if(c.key[0]!==e.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+c.key.toString("hex"));const a=t.readUInt64LE(c.value,0);let u=8;const f=n.decode(c.value,u);u+=n.encodingLength(f);const l=c.value.slice(u);if(l.length!==f)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:l,value:a}}Lr.decode=r;function i(c){const{script:a,value:u}=c,f=n.encodingLength(a.length),l=Buffer.allocUnsafe(8+f+a.length);return t.writeUInt64LE(l,u,0),n.encode(a.length,l,8),a.copy(l,8+f),{key:Buffer.from([e.InputTypes.WITNESS_UTXO]),value:l}}Lr.encode=i,Lr.expected="{ script: Buffer; value: number; }";function s(c){return Buffer.isBuffer(c.script)&&typeof c.value=="number"}Lr.check=s;function o(c,a){return!!c&&!!a&&c.witnessUtxo===void 0}return Lr.canAdd=o,Lr}var jr={},fp;function dx(){if(fp)return jr;fp=1,Object.defineProperty(jr,"__esModule",{value:!0});const e=Ut(),t=Xi();function n(o){if(o.key[0]!==e.OutputTypes.TAP_TREE||o.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+o.key.toString("hex"));let c=0;const a=[];for(;c<o.value.length;){const u=o.value[c++],f=o.value[c++],l=t.decode(o.value,c);c+=t.encodingLength(l),a.push({depth:u,leafVersion:f,script:o.value.slice(c,c+l)}),c+=l}return{leaves:a}}jr.decode=n;function r(o){const c=Buffer.from([e.OutputTypes.TAP_TREE]),a=[].concat(...o.leaves.map(u=>[Buffer.of(u.depth,u.leafVersion),t.encode(u.script.length),u.script]));return{key:c,value:Buffer.concat(a)}}jr.encode=r,jr.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function i(o){return Array.isArray(o.leaves)&&o.leaves.every(c=>c.depth>=0&&c.depth<=128&&(c.leafVersion&254)===c.leafVersion&&Buffer.isBuffer(c.script))}jr.check=i;function s(o,c){return!!o&&!!c&&o.tapTree===void 0}return jr.canAdd=s,jr}var Ic={},lp;function iw(){if(lp)return Ic;lp=1,Object.defineProperty(Ic,"__esModule",{value:!0});const e=r=>[...Array(r).keys()],t=r=>r.length===33&&[2,3].includes(r[0])||r.length===65&&r[0]===4;function n(r,i=t){function s(f){if(f.key[0]!==r)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+f.key.toString("hex"));const l=f.key.slice(1);if(!i(l))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+f.key.toString("hex"));if(f.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const p={masterFingerprint:f.value.slice(0,4),pubkey:l,path:"m"};for(const y of e(f.value.length/4-1)){const g=f.value.readUInt32LE(y*4+4),w=!!(g&2147483648),E=g&2147483647;p.path+="/"+E.toString(10)+(w?"'":"")}return p}function o(f){const l=Buffer.from([r]),p=Buffer.concat([l,f.pubkey]),y=f.path.split("/"),g=Buffer.allocUnsafe(y.length*4);f.masterFingerprint.copy(g,0);let w=4;return y.slice(1).forEach(E=>{const _=E.slice(-1)==="'";let S=2147483647&parseInt(_?E.slice(0,-1):E,10);_&&(S+=2147483648),g.writeUInt32LE(S,w),w+=4}),{key:p,value:g}}const c="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function a(f){return Buffer.isBuffer(f.pubkey)&&Buffer.isBuffer(f.masterFingerprint)&&typeof f.path=="string"&&i(f.pubkey)&&f.masterFingerprint.length===4}function u(f,l,p){const y=l.pubkey.toString("hex");return p.has(y)?!1:(p.add(y),f.filter(g=>g.pubkey.equals(l.pubkey)).length===0)}return{decode:s,encode:o,check:a,expected:c,canAddToArray:u}}return Ic.makeConverter=n,Ic}var Oc={},hp;function px(){if(hp)return Oc;hp=1,Object.defineProperty(Oc,"__esModule",{value:!0});function e(t){return n;function n(r){let i;if(t.includes(r.key[0])&&(i=r.key.slice(1),!(i.length===33||i.length===65)||![2,3,4].includes(i[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return i}}return Oc.makeChecker=e,Oc}var Pc={},dp;function yx(){if(dp)return Pc;dp=1,Object.defineProperty(Pc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode redeemScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.redeemScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Pc.makeConverter=e,Pc}var kc={},pp;function gx(){if(pp)return kc;pp=1,Object.defineProperty(kc,"__esModule",{value:!0});const e=Xi(),t=iw(),n=i=>i.length===32;function r(i){const s=t.makeConverter(i,n);function o(f){const l=e.decode(f.value),p=e.encodingLength(l),y=s.decode({key:f.key,value:f.value.slice(p+l*32)}),g=new Array(l);for(let w=0,E=p;w<l;w++,E+=32)g[w]=f.value.slice(E,E+32);return Object.assign({},y,{leafHashes:g})}function c(f){const l=s.encode(f),p=e.encodingLength(f.leafHashes.length),y=Buffer.allocUnsafe(p);e.encode(f.leafHashes.length,y);const g=Buffer.concat([y,...f.leafHashes,l.value]);return Object.assign({},l,{value:g})}const a="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function u(f){return Array.isArray(f.leafHashes)&&f.leafHashes.every(l=>Buffer.isBuffer(l)&&l.length===32)&&s.check(f)}return{decode:o,encode:c,check:u,expected:a,canAddToArray:s.canAddToArray}}return kc.makeConverter=r,kc}var Nc={},yp;function wx(){if(yp)return Nc;yp=1,Object.defineProperty(Nc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t||c.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+c.key.toString("hex"));if(c.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)&&c.length===32}function o(c,a){return!!c&&!!a&&c.tapInternalKey===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Nc.makeConverter=e,Nc}var Uc={},gp;function mx(){if(gp)return Uc;gp=1,Object.defineProperty(Uc,"__esModule",{value:!0});function e(t){function n(c){if(c.key[0]!==t)throw new Error("Decode Error: could not decode witnessScript with key 0x"+c.key.toString("hex"));return c.value}function r(c){return{key:Buffer.from([t]),value:c}}const i="Buffer";function s(c){return Buffer.isBuffer(c)}function o(c,a){return!!c&&!!a&&c.witnessScript===void 0}return{decode:n,encode:r,check:s,expected:i,canAdd:o}}return Uc.makeConverter=e,Uc}var wp;function eh(){if(wp)return ts;wp=1,Object.defineProperty(ts,"__esModule",{value:!0});const e=Ut(),t=ex(),n=tx(),r=nx(),i=rx(),s=ix(),o=sx(),c=ox(),a=cx(),u=ax(),f=ux(),l=fx(),p=lx(),y=hx(),g=dx(),w=iw(),E=px(),_=yx(),S=gx(),m=wx(),T=mx(),I={unsignedTx:n,globalXpub:t,checkPubkey:E.makeChecker([])};ts.globals=I;const A={nonWitnessUtxo:s,partialSig:o,sighashType:a,finalScriptSig:r,finalScriptWitness:i,porCommitment:c,witnessUtxo:y,bip32Derivation:w.makeConverter(e.InputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.InputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.InputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.InputTypes.PARTIAL_SIG,e.InputTypes.BIP32_DERIVATION]),tapKeySig:u,tapScriptSig:p,tapLeafScript:f,tapBip32Derivation:S.makeConverter(e.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:m.makeConverter(e.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:l};ts.inputs=A;const U={bip32Derivation:w.makeConverter(e.OutputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(e.OutputTypes.REDEEM_SCRIPT),witnessScript:T.makeConverter(e.OutputTypes.WITNESS_SCRIPT),checkPubkey:E.makeChecker([e.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:S.makeConverter(e.OutputTypes.TAP_BIP32_DERIVATION),tapTree:g,tapInternalKey:m.makeConverter(e.OutputTypes.TAP_INTERNAL_KEY)};return ts.outputs=U,ts}var mp;function bx(){if(mp)return es;mp=1,Object.defineProperty(es,"__esModule",{value:!0});const e=eh(),t=Ql(),n=Xi(),r=Ut();function i(c,a){let u=0;function f(){const U=n.decode(c,u);u+=n.encodingLength(U);const M=c.slice(u,u+U);return u+=U,M}function l(){const U=c.readUInt32BE(u);return u+=4,U}function p(){const U=c.readUInt8(u);return u+=1,U}function y(){const U=f(),M=f();return{key:U,value:M}}function g(){if(u>=c.length)throw new Error("Format Error: Unexpected End of PSBT");const U=c.readUInt8(u)===0;return U&&u++,U}if(l()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(p()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const w=[],E={};for(;!g();){const U=y(),M=U.key.toString("hex");if(E[M])throw new Error("Format Error: Keys must be unique for global keymap: key "+M);E[M]=1,w.push(U)}const _=w.filter(U=>U.key[0]===r.GlobalTypes.UNSIGNED_TX);if(_.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const S=a(_[0].value),{inputCount:m,outputCount:T}=S.getInputOutputCounts(),I=[],A=[];for(const U of t.range(m)){const M={},v=[];for(;!g();){const R=y(),V=R.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each input: input index "+U+" key "+V);M[V]=1,v.push(R)}I.push(v)}for(const U of t.range(T)){const M={},v=[];for(;!g();){const R=y(),V=R.key.toString("hex");if(M[V])throw new Error("Format Error: Keys must be unique for each output: output index "+U+" key "+V);M[V]=1,v.push(R)}A.push(v)}return o(S,{globalMapKeyVals:w,inputKeyVals:I,outputKeyVals:A})}es.psbtFromBuffer=i;function s(c,a,u){if(!a.equals(Buffer.from([u])))throw new Error(`Format Error: Invalid ${c} key: ${a.toString("hex")}`)}es.checkKeyBuffer=s;function o(c,{globalMapKeyVals:a,inputKeyVals:u,outputKeyVals:f}){const l={unsignedTx:c};let p=0;for(const _ of a)switch(_.key[0]){case r.GlobalTypes.UNSIGNED_TX:if(s("global",_.key,r.GlobalTypes.UNSIGNED_TX),p>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");p++;break;case r.GlobalTypes.GLOBAL_XPUB:l.globalXpub===void 0&&(l.globalXpub=[]),l.globalXpub.push(e.globals.globalXpub.decode(_));break;default:l.unknownKeyVals||(l.unknownKeyVals=[]),l.unknownKeyVals.push(_)}const y=u.length,g=f.length,w=[],E=[];for(const _ of t.range(y)){const S={};for(const m of u[_])switch(e.inputs.checkPubkey(m),m.key[0]){case r.InputTypes.NON_WITNESS_UTXO:if(s("input",m.key,r.InputTypes.NON_WITNESS_UTXO),S.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");S.nonWitnessUtxo=e.inputs.nonWitnessUtxo.decode(m);break;case r.InputTypes.WITNESS_UTXO:if(s("input",m.key,r.InputTypes.WITNESS_UTXO),S.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");S.witnessUtxo=e.inputs.witnessUtxo.decode(m);break;case r.InputTypes.PARTIAL_SIG:S.partialSig===void 0&&(S.partialSig=[]),S.partialSig.push(e.inputs.partialSig.decode(m));break;case r.InputTypes.SIGHASH_TYPE:if(s("input",m.key,r.InputTypes.SIGHASH_TYPE),S.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");S.sighashType=e.inputs.sighashType.decode(m);break;case r.InputTypes.REDEEM_SCRIPT:if(s("input",m.key,r.InputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");S.redeemScript=e.inputs.redeemScript.decode(m);break;case r.InputTypes.WITNESS_SCRIPT:if(s("input",m.key,r.InputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");S.witnessScript=e.inputs.witnessScript.decode(m);break;case r.InputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.inputs.bip32Derivation.decode(m));break;case r.InputTypes.FINAL_SCRIPTSIG:s("input",m.key,r.InputTypes.FINAL_SCRIPTSIG),S.finalScriptSig=e.inputs.finalScriptSig.decode(m);break;case r.InputTypes.FINAL_SCRIPTWITNESS:s("input",m.key,r.InputTypes.FINAL_SCRIPTWITNESS),S.finalScriptWitness=e.inputs.finalScriptWitness.decode(m);break;case r.InputTypes.POR_COMMITMENT:s("input",m.key,r.InputTypes.POR_COMMITMENT),S.porCommitment=e.inputs.porCommitment.decode(m);break;case r.InputTypes.TAP_KEY_SIG:s("input",m.key,r.InputTypes.TAP_KEY_SIG),S.tapKeySig=e.inputs.tapKeySig.decode(m);break;case r.InputTypes.TAP_SCRIPT_SIG:S.tapScriptSig===void 0&&(S.tapScriptSig=[]),S.tapScriptSig.push(e.inputs.tapScriptSig.decode(m));break;case r.InputTypes.TAP_LEAF_SCRIPT:S.tapLeafScript===void 0&&(S.tapLeafScript=[]),S.tapLeafScript.push(e.inputs.tapLeafScript.decode(m));break;case r.InputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.inputs.tapBip32Derivation.decode(m));break;case r.InputTypes.TAP_INTERNAL_KEY:s("input",m.key,r.InputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.inputs.tapInternalKey.decode(m);break;case r.InputTypes.TAP_MERKLE_ROOT:s("input",m.key,r.InputTypes.TAP_MERKLE_ROOT),S.tapMerkleRoot=e.inputs.tapMerkleRoot.decode(m);break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(m)}w.push(S)}for(const _ of t.range(g)){const S={};for(const m of f[_])switch(e.outputs.checkPubkey(m),m.key[0]){case r.OutputTypes.REDEEM_SCRIPT:if(s("output",m.key,r.OutputTypes.REDEEM_SCRIPT),S.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");S.redeemScript=e.outputs.redeemScript.decode(m);break;case r.OutputTypes.WITNESS_SCRIPT:if(s("output",m.key,r.OutputTypes.WITNESS_SCRIPT),S.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");S.witnessScript=e.outputs.witnessScript.decode(m);break;case r.OutputTypes.BIP32_DERIVATION:S.bip32Derivation===void 0&&(S.bip32Derivation=[]),S.bip32Derivation.push(e.outputs.bip32Derivation.decode(m));break;case r.OutputTypes.TAP_INTERNAL_KEY:s("output",m.key,r.OutputTypes.TAP_INTERNAL_KEY),S.tapInternalKey=e.outputs.tapInternalKey.decode(m);break;case r.OutputTypes.TAP_TREE:s("output",m.key,r.OutputTypes.TAP_TREE),S.tapTree=e.outputs.tapTree.decode(m);break;case r.OutputTypes.TAP_BIP32_DERIVATION:S.tapBip32Derivation===void 0&&(S.tapBip32Derivation=[]),S.tapBip32Derivation.push(e.outputs.tapBip32Derivation.decode(m));break;default:S.unknownKeyVals||(S.unknownKeyVals=[]),S.unknownKeyVals.push(m)}E.push(S)}return{globalMap:l,inputs:w,outputs:E}}return es.psbtFromKeyVals=o,es}var so={},bp;function Ex(){if(bp)return so;bp=1,Object.defineProperty(so,"__esModule",{value:!0});const e=eh(),t=Ql();function n({globalMap:o,inputs:c,outputs:a}){const{globalKeyVals:u,inputKeyVals:f,outputKeyVals:l}=s({globalMap:o,inputs:c,outputs:a}),p=t.keyValsToBuffer(u),y=_=>_.length===0?[Buffer.from([0])]:_.map(t.keyValsToBuffer),g=y(f),w=y(l),E=Buffer.allocUnsafe(5);return E.writeUIntBE(482972169471,0,5),Buffer.concat([E,p].concat(g,w))}so.psbtToBuffer=n;const r=(o,c)=>o.key.compare(c.key);function i(o,c){const a=new Set,u=Object.entries(o).reduce((l,[p,y])=>{if(p==="unknownKeyVals")return l;const g=c[p];if(g===void 0)return l;const w=(Array.isArray(y)?y:[y]).map(g.encode);return w.map(_=>_.key.toString("hex")).forEach(_=>{if(a.has(_))throw new Error("Serialize Error: Duplicate key: "+_);a.add(_)}),l.concat(w)},[]),f=o.unknownKeyVals?o.unknownKeyVals.filter(l=>!a.has(l.key.toString("hex"))):[];return u.concat(f).sort(r)}function s({globalMap:o,inputs:c,outputs:a}){return{globalKeyVals:i(o,e.globals),inputKeyVals:c.map(u=>i(u,e.inputs)),outputKeyVals:a.map(u=>i(u,e.outputs))}}return so.psbtToKeyVals=s,so}var Ep;function sw(){return Ep||(Ep=1,(function(e){function t(n){for(var r in n)e.hasOwnProperty(r)||(e[r]=n[r])}Object.defineProperty(e,"__esModule",{value:!0}),t(bx()),t(Ex())})(df)),df}var _p;function _x(){if(_p)return vc;_p=1,Object.defineProperty(vc,"__esModule",{value:!0});const e=sw();function t(s){const o=s[0],c=e.psbtToKeyVals(o),a=s.slice(1);if(a.length===0)throw new Error("Combine: Nothing to combine");const u=r(o);if(u===void 0)throw new Error("Combine: Self missing transaction");const f=i(c.globalKeyVals),l=c.inputKeyVals.map(i),p=c.outputKeyVals.map(i);for(const y of a){const g=r(y);if(g===void 0||!g.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const w=e.psbtToKeyVals(y);i(w.globalKeyVals).forEach(n(f,c.globalKeyVals,w.globalKeyVals)),w.inputKeyVals.map(i).forEach((m,T)=>m.forEach(n(l[T],c.inputKeyVals[T],w.inputKeyVals[T]))),w.outputKeyVals.map(i).forEach((m,T)=>m.forEach(n(p[T],c.outputKeyVals[T],w.outputKeyVals[T])))}return e.psbtFromKeyVals(u,{globalMapKeyVals:c.globalKeyVals,inputKeyVals:c.inputKeyVals,outputKeyVals:c.outputKeyVals})}vc.combine=t;function n(s,o,c){return a=>{if(s.has(a))return;const u=c.filter(f=>f.key.toString("hex")===a)[0];o.push(u),s.add(a)}}function r(s){return s.globalMap.unsignedTx}function i(s){const o=new Set;return s.forEach(c=>{const a=c.key.toString("hex");if(o.has(a))throw new Error("Combine: KeyValue Map keys should be unique");o.add(a)}),o}return vc}var yf={},Sp;function ow(){return Sp||(Sp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=eh();function n(y,g){const w=y[g];if(w===void 0)throw new Error(`No input #${g}`);return w}e.checkForInput=n;function r(y,g){const w=y[g];if(w===void 0)throw new Error(`No output #${g}`);return w}e.checkForOutput=r;function i(y,g,w){if(y.key[0]<w)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(g&&g.filter(E=>E.key.equals(y.key)).length!==0)throw new Error(`Duplicate Key: ${y.key.toString("hex")}`)}e.checkHasKey=i;function s(y){let g=0;return Object.keys(y).forEach(w=>{Number(isNaN(Number(w)))&&g++}),g}e.getEnumLength=s;function o(y,g){let w=!1;if(g.nonWitnessUtxo||g.witnessUtxo){const E=!!g.redeemScript,_=!!g.witnessScript,S=!E||!!g.finalScriptSig,m=!_||!!g.finalScriptWitness,T=!!g.finalScriptSig||!!g.finalScriptWitness;w=S&&m&&T}if(w===!1)throw new Error(`Input #${y} has too much or too little data to clean`)}e.inputCheckUncleanFinalized=o;function c(y,g,w,E){throw new Error(`Data for ${y} key ${g} is incorrect: Expected ${w} and got ${JSON.stringify(E)}`)}function a(y){return(g,w)=>{for(const E of Object.keys(g)){const _=g[E],{canAdd:S,canAddToArray:m,check:T,expected:I}=t[y+"s"][E]||{},A=!!m;if(T)if(A){if(!Array.isArray(_)||w[E]&&!Array.isArray(w[E]))throw new Error(`Key type ${E} must be an array`);_.every(T)||c(y,E,I,_);const U=w[E]||[],M=new Set;if(!_.every(v=>m(U,v,M)))throw new Error("Can not add duplicate data to array");w[E]=U.concat(_)}else{if(T(_)||c(y,E,I,_),!S(w,_))throw new Error(`Can not add duplicate data to ${y}`);w[E]=_}}}}e.updateGlobal=a("global"),e.updateInput=a("input"),e.updateOutput=a("output");function u(y,g){const w=y.length-1,E=n(y,w);e.updateInput(g,E)}e.addInputAttributes=u;function f(y,g){const w=y.length-1,E=r(y,w);e.updateOutput(g,E)}e.addOutputAttributes=f;function l(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Version: Invalid Transaction");return g.writeUInt32LE(y,0),g}e.defaultVersionSetter=l;function p(y,g){if(!Buffer.isBuffer(g)||g.length<4)throw new Error("Set Locktime: Invalid Transaction");return g.writeUInt32LE(y,g.length-4),g}e.defaultLocktimeSetter=p})(yf)),yf}var Tp;function Sx(){if(Tp)return Ac;Tp=1,Object.defineProperty(Ac,"__esModule",{value:!0});const e=_x(),t=sw(),n=Ut(),r=ow();class i{constructor(o){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:o}}static fromBase64(o,c){const a=Buffer.from(o,"base64");return this.fromBuffer(a,c)}static fromHex(o,c){const a=Buffer.from(o,"hex");return this.fromBuffer(a,c)}static fromBuffer(o,c){const a=t.psbtFromBuffer(o,c),u=new this(a.globalMap.unsignedTx);return Object.assign(u,a),u}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return t.psbtToBuffer(this)}updateGlobal(o){return r.updateGlobal(o,this.globalMap),this}updateInput(o,c){const a=r.checkForInput(this.inputs,o);return r.updateInput(c,a),this}updateOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.updateOutput(c,a),this}addUnknownKeyValToGlobal(o){return r.checkHasKey(o,this.globalMap.unknownKeyVals,r.getEnumLength(n.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(o),this}addUnknownKeyValToInput(o,c){const a=r.checkForInput(this.inputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.InputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addUnknownKeyValToOutput(o,c){const a=r.checkForOutput(this.outputs,o);return r.checkHasKey(c,a.unknownKeyVals,r.getEnumLength(n.OutputTypes)),a.unknownKeyVals||(a.unknownKeyVals=[]),a.unknownKeyVals.push(c),this}addInput(o){this.globalMap.unsignedTx.addInput(o),this.inputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.inputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToInput(a,u)),r.addInputAttributes(this.inputs,o),this}addOutput(o){this.globalMap.unsignedTx.addOutput(o),this.outputs.push({unknownKeyVals:[]});const c=o.unknownKeyVals||[],a=this.outputs.length-1;if(!Array.isArray(c))throw new Error("unknownKeyVals must be an Array");return c.forEach(u=>this.addUnknownKeyValToOutput(a,u)),r.addOutputAttributes(this.outputs,o),this}clearFinalizedInput(o){const c=r.checkForInput(this.inputs,o);r.inputCheckUncleanFinalized(o,c);for(const a of Object.keys(c))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(a)||delete c[a];return this}combine(...o){const c=e.combine([this].concat(o));return Object.assign(this,c),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}}return Ac.Psbt=i,Ac}var ze={},We={},xp;function Gf(){if(xp)return We;xp=1,Object.defineProperty(We,"__esModule",{value:!0}),We.signatureBlocksAction=We.checkInputForSig=We.pubkeyInScript=We.pubkeyPositionInScript=We.witnessStackToScriptWitness=We.isP2TR=We.isP2SHScript=We.isP2WSHScript=We.isP2WPKH=We.isP2PKH=We.isP2PK=We.isP2MS=void 0;const e=Xi(),t=Jt(),n=ac(),r=xr(),i=cc();function s(y){return g=>{try{return y({output:g}),!0}catch{return!1}}}We.isP2MS=s(i.p2ms),We.isP2PK=s(i.p2pk),We.isP2PKH=s(i.p2pkh),We.isP2WPKH=s(i.p2wpkh),We.isP2WSHScript=s(i.p2wsh),We.isP2SHScript=s(i.p2sh),We.isP2TR=s(i.p2tr);function o(y){let g=Buffer.allocUnsafe(0);function w(m){g=Buffer.concat([g,Buffer.from(m)])}function E(m){const T=g.length,I=e.encodingLength(m);g=Buffer.concat([g,Buffer.allocUnsafe(I)]),e.encode(m,g,T)}function _(m){E(m.length),w(m)}function S(m){E(m.length),m.forEach(_)}return S(y),g}We.witnessStackToScriptWitness=o;function c(y,g){const w=(0,r.hash160)(y),E=y.slice(1,33),_=t.decompile(g);if(_===null)throw new Error("Unknown script error");return _.findIndex(S=>typeof S=="number"?!1:S.equals(y)||S.equals(w)||S.equals(E))}We.pubkeyPositionInScript=c;function a(y,g){return c(y,g)!==-1}We.pubkeyInScript=a;function u(y,g){return l(y).some(E=>f(E,t.signature.decode,g))}We.checkInputForSig=u;function f(y,g,w){const{hashType:E}=g(y),_=[];switch(E&n.Transaction.SIGHASH_ANYONECANPAY&&_.push("addInput"),E&31){case n.Transaction.SIGHASH_ALL:break;case n.Transaction.SIGHASH_SINGLE:case n.Transaction.SIGHASH_NONE:_.push("addOutput"),_.push("setInputSequence");break}return _.indexOf(w)===-1}We.signatureBlocksAction=f;function l(y){let g=[];if((y.partialSig||[]).length===0){if(!y.finalScriptSig&&!y.finalScriptWitness)return[];g=p(y)}else g=y.partialSig;return g.map(w=>w.signature)}function p(y){const g=y.finalScriptSig?t.decompile(y.finalScriptSig)||[]:[],w=y.finalScriptWitness?t.decompile(y.finalScriptWitness)||[]:[];return g.concat(w).filter(E=>Buffer.isBuffer(E)&&t.isCanonicalScriptSignature(E)).map(E=>({signature:E}))}return We}var Ap;function Tx(){if(Ap)return ze;Ap=1,Object.defineProperty(ze,"__esModule",{value:!0}),ze.checkTaprootInputForSigs=ze.tapTreeFromList=ze.tapTreeToList=ze.tweakInternalPubKey=ze.checkTaprootOutputFields=ze.checkTaprootInputFields=ze.isTaprootOutput=ze.isTaprootInput=ze.serializeTaprootSignature=ze.tapScriptFinalizer=ze.toXOnly=void 0;const e=Lt(),t=ac(),n=Gf(),r=Zl(),i=cc(),s=Gf(),o=x=>x.length===32?x:x.slice(1,33);ze.toXOnly=o;function c(x,O,q){const P=N(O,x,q);try{const G=H(O,P).concat(P.script).concat(P.controlBlock);return{finalScriptWitness:(0,n.witnessStackToScriptWitness)(G)}}catch($){throw new Error(`Can not finalize taproot input #${x}: ${$}`)}}ze.tapScriptFinalizer=c;function a(x,O){const q=O?Buffer.from([O]):Buffer.from([]);return Buffer.concat([x,q])}ze.serializeTaprootSignature=a;function u(x){return x&&!!(x.tapInternalKey||x.tapMerkleRoot||x.tapLeafScript&&x.tapLeafScript.length||x.tapBip32Derivation&&x.tapBip32Derivation.length||x.witnessUtxo&&(0,n.isP2TR)(x.witnessUtxo.script))}ze.isTaprootInput=u;function f(x,O){return x&&!!(x.tapInternalKey||x.tapTree||x.tapBip32Derivation&&x.tapBip32Derivation.length||O&&(0,n.isP2TR)(O))}ze.isTaprootOutput=f;function l(x,O,q){v(x,O,q),V(x,O,q)}ze.checkTaprootInputFields=l;function p(x,O,q){R(x,O,q),y(x,O)}ze.checkTaprootOutputFields=p;function y(x,O){if(!O.tapTree&&!O.tapInternalKey)return;const q=O.tapInternalKey||x.tapInternalKey,P=O.tapTree||x.tapTree;if(q){const{script:$}=x,G=g(q,P);if($&&!$.equals(G))throw new Error("Error adding output. Script or address missmatch.")}}function g(x,O){const q=O&&_(O.leaves),{output:P}=(0,i.p2tr)({internalPubkey:x,scriptTree:q});return P}function w(x,O){const q=O.tapInternalKey,P=q&&(0,r.tweakKey)(q,O.tapMerkleRoot);if(!P)throw new Error(`Cannot tweak tap internal key for input #${x}. Public key: ${q&&q.toString("hex")}`);return P.x}ze.tweakInternalPubKey=w;function E(x){if(!(0,e.isTaptree)(x))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return A(x)}ze.tapTreeToList=E;function _(x=[]){return x.length===1&&x[0].depth===0?{output:x[0].script,version:x[0].leafVersion}:U(x)}ze.tapTreeFromList=_;function S(x,O){return T(x).some(P=>(0,s.signatureBlocksAction)(P,m,O))}ze.checkTaprootInputForSigs=S;function m(x){return{signature:x.slice(0,64),hashType:x.slice(64)[0]||t.Transaction.SIGHASH_DEFAULT}}function T(x){const O=[];if(x.tapKeySig&&O.push(x.tapKeySig),x.tapScriptSig&&O.push(...x.tapScriptSig.map(q=>q.signature)),!O.length){const q=I(x.finalScriptWitness);q&&O.push(q)}return O}function I(x){if(!x)return;const O=x.slice(2);if(O.length===64||O.length===65)return O}function A(x,O=[],q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return x?(0,e.isTapleaf)(x)?(O.push({depth:q,leafVersion:x.version||r.LEAF_VERSION_TAPSCRIPT,script:x.output}),O):(x[0]&&A(x[0],O,q+1),x[1]&&A(x[1],O,q+1),O):[]}function U(x){let O;for(const q of x)if(O=M(q,O),!O)throw new Error("No room left to insert tapleaf in tree");return O}function M(x,O,q=0){if(q>r.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(x.depth===q)return O?void 0:{output:x.script,version:x.leafVersion};if((0,e.isTapleaf)(O))return;const P=M(x,O&&O[0],q+1);if(P)return[P,O&&O[1]];const $=M(x,O&&O[1],q+1);if($)return[O&&O[0],$]}function v(x,O,q){const P=u(x)&&F(O),$=F(x)&&u(O),G=x===O&&u(O)&&F(O);if(P||$||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function R(x,O,q){const P=f(x)&&F(O),$=F(x)&&f(O),G=x===O&&f(O)&&F(O);if(P||$||G)throw new Error(`Invalid arguments for Psbt.${q}. Cannot use both taproot and non-taproot fields.`)}function V(x,O,q){if(O.tapMerkleRoot){const P=(O.tapLeafScript||[]).every(G=>W(G,O.tapMerkleRoot)),$=(x.tapLeafScript||[]).every(G=>W(G,O.tapMerkleRoot));if(!P||!$)throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}else if(x.tapMerkleRoot&&!(O.tapLeafScript||[]).every($=>W($,x.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${q}. Tapleaf not part of taptree.`)}function W(x,O){if(!O)return!0;const q=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(0,r.rootHashFromPath)(x.controlBlock,q).equals(O)}function H(x,O){const q=(0,r.tapleafHash)({output:O.script,version:O.leafVersion});return(x.tapScriptSig||[]).filter(P=>P.leafHash.equals(q)).map(P=>K(O.script,P)).sort((P,$)=>$.positionInScript-P.positionInScript).map(P=>P.signature)}function K(x,O){return Object.assign({positionInScript:(0,n.pubkeyPositionInScript)(O.pubkey,x)},O)}function N(x,O,q){if(!x.tapScriptSig||!x.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${O}. No tapleaf script signature provided.`);const P=(x.tapLeafScript||[]).sort(($,G)=>$.controlBlock.length-G.controlBlock.length).find($=>L($,x.tapScriptSig,q));if(!P)throw new Error(`Can not finalize taproot input #${O}. Signature for tapleaf script not found.`);return P}function L(x,O,q){const P=(0,r.tapleafHash)({output:x.script,version:x.leafVersion});return(!q||q.equals(P))&&O.find(G=>G.leafHash.equals(P))!==void 0}function F(x){return x&&!!(x.redeemScript||x.witnessScript||x.bip32Derivation&&x.bip32Derivation.length)}return ze}var vp;function xx(){if(vp)return io;vp=1,Object.defineProperty(io,"__esModule",{value:!0}),io.Psbt=void 0;const e=Sx(),t=Xi(),n=ow(),r=Jl(),i=su(),s=Vn(),o=cc(),c=Zl(),a=Jt(),u=ac(),f=Tx(),l=Gf(),p={network:s.bitcoin,maximumFeeRate:5e3};class y{static fromBase64(h,b={}){const B=Buffer.from(h,"base64");return this.fromBuffer(B,b)}static fromHex(h,b={}){const B=Buffer.from(h,"hex");return this.fromBuffer(B,b)}static fromBuffer(h,b={}){const B=e.Psbt.fromBuffer(h,g),C=new y(b,B);return V(C.__CACHE.__TX,C.__CACHE),C}constructor(h={},b=new e.Psbt(new w)){this.data=b,this.opts=Object.assign({},p,h),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const B=(C,j,D,re)=>Object.defineProperty(C,j,{enumerable:D,writable:re});B(this,"__CACHE",!1,!0),B(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(h){this.setVersion(h)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(h){this.setLocktime(h)}get txInputs(){return this.__CACHE.__TX.ins.map(h=>({hash:(0,i.cloneBuffer)(h.hash),index:h.index,sequence:h.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(h=>{let b;try{b=(0,r.fromOutputScript)(h.script,this.opts.network)}catch{}return{script:(0,i.cloneBuffer)(h.script),value:h.value,address:b}})}combine(...h){return this.data.combine(...h.map(b=>b.data)),this}clone(){const h=y.fromBuffer(this.data.toBuffer());return h.opts=JSON.parse(JSON.stringify(this.opts)),h}setMaximumFeeRate(h){I(h),this.opts.maximumFeeRate=h}setVersion(h){I(h),U(this.data.inputs,"setVersion");const b=this.__CACHE;return b.__TX.version=h,b.__EXTRACTED_TX=void 0,this}setLocktime(h){I(h),U(this.data.inputs,"setLocktime");const b=this.__CACHE;return b.__TX.locktime=h,b.__EXTRACTED_TX=void 0,this}setInputSequence(h,b){I(b),U(this.data.inputs,"setInputSequence");const B=this.__CACHE;if(B.__TX.ins.length<=h)throw new Error("Input index too high");return B.__TX.ins[h].sequence=b,B.__EXTRACTED_TX=void 0,this}addInputs(h){return h.forEach(b=>this.addInput(b)),this}addInput(h){if(arguments.length>1||!h||h.hash===void 0||h.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,f.checkTaprootInputFields)(h,h,"addInput"),U(this.data.inputs,"addInput"),h.witnessScript&&te(h.witnessScript);const b=this.__CACHE;this.data.addInput(h);const B=b.__TX.ins[b.__TX.ins.length-1];W(b,B);const C=this.data.inputs.length-1,j=this.data.inputs[C];return j.nonWitnessUtxo&&pe(this.__CACHE,j,C),b.__FEE=void 0,b.__FEE_RATE=void 0,b.__EXTRACTED_TX=void 0,this}addOutputs(h){return h.forEach(b=>this.addOutput(b)),this}addOutput(h){if(arguments.length>1||!h||h.value===void 0||h.address===void 0&&h.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");U(this.data.inputs,"addOutput");const{address:b}=h;if(typeof b=="string"){const{network:C}=this.opts,j=(0,r.toOutputScript)(b,C);h=Object.assign({},h,{script:j})}(0,f.checkTaprootOutputFields)(h,h,"addOutput");const B=this.__CACHE;return this.data.addOutput(h),B.__FEE=void 0,B.__FEE_RATE=void 0,B.__EXTRACTED_TX=void 0,this}extractTransaction(h){if(!this.data.inputs.every(m))throw new Error("Not finalized");const b=this.__CACHE;if(h||A(this,b,this.opts),b.__EXTRACTED_TX)return b.__EXTRACTED_TX;const B=b.__TX.clone();return J(this.data.inputs,B,b,!0),B}getFeeRate(){return L("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return L("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).forEach(h=>this.finalizeInput(h)),this}finalizeInput(h,b){const B=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(B)?this._finalizeTaprootInput(h,B,void 0,b):this._finalizeInput(h,B,b)}finalizeTaprootInput(h,b,B=f.tapScriptFinalizer){const C=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(C))return this._finalizeTaprootInput(h,C,b,B);throw new Error(`Cannot finalize input #${h}. Not Taproot.`)}_finalizeInput(h,b,B=F){const{script:C,isP2SH:j,isP2WSH:D,isSegwit:re}=ae(h,b,this.__CACHE);if(!C)throw new Error(`No script found for input #${h}`);M(b);const{finalScriptSig:Q,finalScriptWitness:ue}=B(h,b,C,re,j,D);if(Q&&this.data.updateInput(h,{finalScriptSig:Q}),ue&&this.data.updateInput(h,{finalScriptWitness:ue}),!Q&&!ue)throw new Error(`Unknown error finalizing input #${h}`);return this.data.clearFinalizedInput(h),this}_finalizeTaprootInput(h,b,B,C=f.tapScriptFinalizer){if(!b.witnessUtxo)throw new Error(`Cannot finalize input #${h}. Missing withness utxo.`);if(b.tapKeySig){const j=o.p2tr({output:b.witnessUtxo.script,signature:b.tapKeySig}),D=(0,l.witnessStackToScriptWitness)(j.witness);this.data.updateInput(h,{finalScriptWitness:D})}else{const{finalScriptWitness:j}=C(h,b,B);this.data.updateInput(h,{finalScriptWitness:j})}return this.data.clearFinalizedInput(h),this}getInputType(h){const b=(0,n.checkForInput)(this.data.inputs,h),B=Se(h,b,this.__CACHE),C=se(B,h,"input",b.redeemScript||St(b.finalScriptSig),b.witnessScript||Ae(b.finalScriptWitness)),j=C.type==="raw"?"":C.type+"-",D=ne(C.meaningfulScript);return j+D}inputHasPubkey(h,b){const B=(0,n.checkForInput)(this.data.inputs,h);return Ze(b,B,h,this.__CACHE)}inputHasHDKey(h,b){const B=(0,n.checkForInput)(this.data.inputs,h),C=T(b);return!!B.bip32Derivation&&B.bip32Derivation.some(C)}outputHasPubkey(h,b){const B=(0,n.checkForOutput)(this.data.outputs,h);return st(b,B,h,this.__CACHE)}outputHasHDKey(h,b){const B=(0,n.checkForOutput)(this.data.outputs,h),C=T(b);return!!B.bip32Derivation&&B.bip32Derivation.some(C)}validateSignaturesOfAllInputs(h){return(0,n.checkForInput)(this.data.inputs,0),k(this.data.inputs.length).map(B=>this.validateSignaturesOfInput(B,h)).reduce((B,C)=>C===!0&&B,!0)}validateSignaturesOfInput(h,b,B){const C=this.data.inputs[h];return(0,f.isTaprootInput)(C)?this.validateSignaturesOfTaprootInput(h,b,B):this._validateSignaturesOfInput(h,b,B)}_validateSignaturesOfInput(h,b,B){const C=this.data.inputs[h],j=(C||{}).partialSig;if(!C||!j||j.length<1)throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");const D=B?j.filter(Be=>Be.pubkey.equals(B)):j;if(D.length<1)throw new Error("No signatures for this pubkey");const re=[];let Q,ue,le;for(const Be of D){const Oe=a.signature.decode(Be.signature),{hash:Je,script:Ve}=le!==Oe.hashType?q(h,Object.assign({},C,{sighashType:Oe.hashType}),this.__CACHE,!0):{hash:Q,script:ue};le=Oe.hashType,Q=Je,ue=Ve,v(Be.pubkey,Ve,"verify"),re.push(b(Be.pubkey,Je,Oe.signature))}return re.every(Be=>Be===!0)}validateSignaturesOfTaprootInput(h,b,B){const C=this.data.inputs[h],j=(C||{}).tapKeySig,D=(C||{}).tapScriptSig;if(!C&&!j&&!(D&&!D.length))throw new Error("No signatures to validate");if(typeof b!="function")throw new Error("Need validator function to validate signatures");B=B&&(0,f.toXOnly)(B);const re=B?X(h,C,this.data.inputs,B,this.__CACHE):P(h,C,this.data.inputs,this.__CACHE);if(!re.length)throw new Error("No signatures for this pubkey");const Q=re.find(le=>!le.leafHash);let ue=0;if(j&&Q){if(!b(Q.pubkey,Q.hash,G(j)))return!1;ue++}if(D)for(const le of D){const Be=re.find(Oe=>le.pubkey.equals(Oe.pubkey));if(Be){if(!b(le.pubkey,Be.hash,G(le.signature)))return!1;ue++}}return ue>0}signAllInputsHD(h,b=[u.Transaction.SIGHASH_ALL]){if(!h||!h.publicKey||!h.fingerprint)throw new Error("Need HDSigner to sign input");const B=[];for(const C of k(this.data.inputs.length))try{this.signInputHD(C,h,b),B.push(!0)}catch{B.push(!1)}if(B.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(h,b=[u.Transaction.SIGHASH_ALL]){return new Promise((B,C)=>{if(!h||!h.publicKey||!h.fingerprint)return C(new Error("Need HDSigner to sign input"));const j=[],D=[];for(const re of k(this.data.inputs.length))D.push(this.signInputHDAsync(re,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(D).then(()=>{if(j.every(re=>re===!1))return C(new Error("No inputs were signed"));B()})})}signInputHD(h,b,B=[u.Transaction.SIGHASH_ALL]){if(!b||!b.publicKey||!b.fingerprint)throw new Error("Need HDSigner to sign input");return ee(h,this.data.inputs,b).forEach(j=>this.signInput(h,j,B)),this}signInputHDAsync(h,b,B=[u.Transaction.SIGHASH_ALL]){return new Promise((C,j)=>{if(!b||!b.publicKey||!b.fingerprint)return j(new Error("Need HDSigner to sign input"));const re=ee(h,this.data.inputs,b).map(Q=>this.signInputAsync(h,Q,B));return Promise.all(re).then(()=>{C()}).catch(j)})}signAllInputs(h,b){if(!h||!h.publicKey)throw new Error("Need Signer to sign input");const B=[];for(const C of k(this.data.inputs.length))try{this.signInput(C,h,b),B.push(!0)}catch{B.push(!1)}if(B.every(C=>C===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(h,b){return new Promise((B,C)=>{if(!h||!h.publicKey)return C(new Error("Need Signer to sign input"));const j=[],D=[];for(const[re]of this.data.inputs.entries())D.push(this.signInputAsync(re,h,b).then(()=>{j.push(!0)},()=>{j.push(!1)}));return Promise.all(D).then(()=>{if(j.every(re=>re===!1))return C(new Error("No inputs were signed"));B()})})}signInput(h,b,B){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInput(h,C,b,void 0,B):this._signInput(h,b,B)}signTaprootInput(h,b,B,C){if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInput(h,j,b,B,C);throw new Error(`Input #${h} is not of type Taproot.`)}_signInput(h,b,B=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=O(this.data.inputs,h,b.publicKey,this.__CACHE,B),D=[{pubkey:b.publicKey,signature:a.signature.encode(b.sign(C),j)}];return this.data.updateInput(h,{partialSig:D}),this}_signTaprootInput(h,b,B,C,j=[u.Transaction.SIGHASH_DEFAULT]){const D=this.checkTaprootHashesForSig(h,b,B,C,j),re=D.filter(ue=>!ue.leafHash).map(ue=>(0,f.serializeTaprootSignature)(B.signSchnorr(ue.hash),b.sighashType))[0],Q=D.filter(ue=>!!ue.leafHash).map(ue=>({pubkey:(0,f.toXOnly)(B.publicKey),signature:(0,f.serializeTaprootSignature)(B.signSchnorr(ue.hash),b.sighashType),leafHash:ue.leafHash}));return re&&this.data.updateInput(h,{tapKeySig:re}),Q.length&&this.data.updateInput(h,{tapScriptSig:Q}),this}signInputAsync(h,b,B){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const C=(0,n.checkForInput)(this.data.inputs,h);return(0,f.isTaprootInput)(C)?this._signTaprootInputAsync(h,C,b,void 0,B):this._signInputAsync(h,b,B)})}signTaprootInputAsync(h,b,B,C){return Promise.resolve().then(()=>{if(!b||!b.publicKey)throw new Error("Need Signer to sign input");const j=(0,n.checkForInput)(this.data.inputs,h);if((0,f.isTaprootInput)(j))return this._signTaprootInputAsync(h,j,b,B,C);throw new Error(`Input #${h} is not of type Taproot.`)})}_signInputAsync(h,b,B=[u.Transaction.SIGHASH_ALL]){const{hash:C,sighashType:j}=O(this.data.inputs,h,b.publicKey,this.__CACHE,B);return Promise.resolve(b.sign(C)).then(D=>{const re=[{pubkey:b.publicKey,signature:a.signature.encode(D,j)}];this.data.updateInput(h,{partialSig:re})})}async _signTaprootInputAsync(h,b,B,C,j=[u.Transaction.SIGHASH_DEFAULT]){const D=this.checkTaprootHashesForSig(h,b,B,C,j),re=[],Q=D.filter(le=>!le.leafHash)[0];if(Q){const le=Promise.resolve(B.signSchnorr(Q.hash)).then(Be=>({tapKeySig:(0,f.serializeTaprootSignature)(Be,b.sighashType)}));re.push(le)}const ue=D.filter(le=>!!le.leafHash);if(ue.length){const le=ue.map(Be=>Promise.resolve(B.signSchnorr(Be.hash)).then(Oe=>({tapScriptSig:[{pubkey:(0,f.toXOnly)(B.publicKey),signature:(0,f.serializeTaprootSignature)(Oe,b.sighashType),leafHash:Be.leafHash}]})));re.push(...le)}return Promise.all(re).then(le=>{le.forEach(Be=>this.data.updateInput(h,Be))})}checkTaprootHashesForSig(h,b,B,C,j){if(typeof B.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${h}.`);const D=X(h,b,this.data.inputs,B.publicKey,this.__CACHE,C,j);if(!D||!D.length)throw new Error(`Can not sign for input #${h} with the key ${B.publicKey.toString("hex")}`);return D}toBuffer(){return _(this.__CACHE),this.data.toBuffer()}toHex(){return _(this.__CACHE),this.data.toHex()}toBase64(){return _(this.__CACHE),this.data.toBase64()}updateGlobal(h){return this.data.updateGlobal(h),this}updateInput(h,b){return b.witnessScript&&te(b.witnessScript),(0,f.checkTaprootInputFields)(this.data.inputs[h],b,"updateInput"),this.data.updateInput(h,b),b.nonWitnessUtxo&&pe(this.__CACHE,this.data.inputs[h],h),this}updateOutput(h,b){const B=this.data.outputs[h];return(0,f.checkTaprootOutputFields)(B,b,"updateOutput"),this.data.updateOutput(h,b),this}addUnknownKeyValToGlobal(h){return this.data.addUnknownKeyValToGlobal(h),this}addUnknownKeyValToInput(h,b){return this.data.addUnknownKeyValToInput(h,b),this}addUnknownKeyValToOutput(h,b){return this.data.addUnknownKeyValToOutput(h,b),this}clearFinalizedInput(h){return this.data.clearFinalizedInput(h),this}}io.Psbt=y;const g=d=>new w(d);class w{constructor(h=Buffer.from([2,0,0,0,0,0,0,0,0,0])){this.tx=u.Transaction.fromBuffer(h),R(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(h){if(h.hash===void 0||h.index===void 0||!Buffer.isBuffer(h.hash)&&typeof h.hash!="string"||typeof h.index!="number")throw new Error("Error adding input.");const b=typeof h.hash=="string"?(0,i.reverseBuffer)(Buffer.from(h.hash,"hex")):h.hash;this.tx.addInput(b,h.index,h.sequence)}addOutput(h){if(h.script===void 0||h.value===void 0||!Buffer.isBuffer(h.script)||typeof h.value!="number")throw new Error("Error adding output.");this.tx.addOutput(h.script,h.value)}toBuffer(){return this.tx.toBuffer()}}function E(d,h,b){switch(b){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return S(1,d.partialSig);case"multisig":const B=o.p2ms({output:h});return S(B.m,d.partialSig,B.pubkeys);default:return!1}}function _(d){if(d.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function S(d,h,b){if(!h)return!1;let B;if(b?B=b.map(C=>{const j=ln(C);return h.find(D=>D.pubkey.equals(j))}).filter(C=>!!C):B=h,B.length>d)throw new Error("Too many signatures");return B.length===d}function m(d){return!!d.finalScriptSig||!!d.finalScriptWitness}function T(d){return h=>!(!h.masterFingerprint.equals(d.fingerprint)||!d.derivePath(h.path).publicKey.equals(h.pubkey))}function I(d){if(typeof d!="number"||d!==Math.floor(d)||d>4294967295||d<0)throw new Error("Invalid 32 bit integer")}function A(d,h,b){const B=h.__FEE_RATE||d.getFeeRate(),C=h.__EXTRACTED_TX.virtualSize(),j=B*C;if(B>=b.maximumFeeRate)throw new Error(`Warning: You are paying around ${(j/1e8).toFixed(8)} in fees, which is ${B} satoshi per byte for a transaction with a VSize of ${C} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function U(d,h){d.forEach(b=>{if((0,f.isTaprootInput)(b)?(0,f.checkTaprootInputForSigs)(b,h):(0,l.checkInputForSig)(b,h))throw new Error("Can not modify transaction, signatures exist.")})}function M(d){if(!d.sighashType||!d.partialSig)return;const{partialSig:h,sighashType:b}=d;h.forEach(B=>{const{hashType:C}=a.signature.decode(B.signature);if(b!==C)throw new Error("Signature sighash does not match input sighash type")})}function v(d,h,b){if(!(0,l.pubkeyInScript)(d,h))throw new Error(`Can not ${b} for this input with the key ${d.toString("hex")}`)}function R(d){if(!d.ins.every(b=>b.script&&b.script.length===0&&b.witness&&b.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function V(d,h){d.ins.forEach(b=>{W(h,b)})}function W(d,h){const b=(0,i.reverseBuffer)(Buffer.from(h.hash)).toString("hex")+":"+h.index;if(d.__TX_IN_CACHE[b])throw new Error("Duplicate input detected.");d.__TX_IN_CACHE[b]=1}function H(d,h){return(b,B,C,j)=>{const D=d({redeem:{output:C}}).output;if(!B.equals(D))throw new Error(`${h} for ${j} #${b} doesn't match the scriptPubKey in the prevout`)}}const K=H(o.p2sh,"Redeem script"),N=H(o.p2wsh,"Witness script");function L(d,h,b,B){if(!b.every(m))throw new Error(`PSBT must be finalized to calculate ${h}`);if(d==="__FEE_RATE"&&B.__FEE_RATE)return B.__FEE_RATE;if(d==="__FEE"&&B.__FEE)return B.__FEE;let C,j=!0;if(B.__EXTRACTED_TX?(C=B.__EXTRACTED_TX,j=!1):C=B.__TX.clone(),J(b,C,B,j),d==="__FEE_RATE")return B.__FEE_RATE;if(d==="__FEE")return B.__FEE}function F(d,h,b,B,C,j){const D=ne(b);if(!E(h,b,D))throw new Error(`Can not finalize input #${d}`);return x(b,D,h.partialSig,B,C,j)}function x(d,h,b,B,C,j){let D,re;const Q=oe(d,h,b),ue=j?o.p2wsh({redeem:Q}):null,le=C?o.p2sh({redeem:ue||Q}):null;return B?(ue?re=(0,l.witnessStackToScriptWitness)(ue.witness):re=(0,l.witnessStackToScriptWitness)(Q.witness),le&&(D=le.input)):le?D=le.input:D=Q.input,{finalScriptSig:D,finalScriptWitness:re}}function O(d,h,b,B,C){const j=(0,n.checkForInput)(d,h),{hash:D,sighashType:re,script:Q}=q(h,j,B,!1,C);return v(b,Q,"sign"),{hash:D,sighashType:re}}function q(d,h,b,B,C){const j=b.__TX,D=h.sighashType||u.Transaction.SIGHASH_ALL;Y(D,C);let re,Q;if(h.nonWitnessUtxo){const Be=fe(b,h,d),Oe=j.ins[d].hash,Je=Be.getHash();if(!Oe.equals(Je))throw new Error(`Non-witness UTXO hash for input #${d} doesn't match the hash specified in the prevout`);const Ve=j.ins[d].index;Q=Be.outs[Ve]}else if(h.witnessUtxo)Q=h.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:ue,type:le}=se(Q.script,d,"input",h.redeemScript,h.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(le)>=0)re=j.hashForWitnessV0(d,ue,Q.value,D);else if((0,l.isP2WPKH)(ue)){const Be=o.p2pkh({hash:ue.slice(2)}).output;re=j.hashForWitnessV0(d,Be,Q.value,D)}else{if(h.nonWitnessUtxo===void 0&&b.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${d} has witnessUtxo but non-segwit script: ${ue.toString("hex")}`);!B&&b.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
74
74
|
*********************
|
|
75
75
|
PROCEED WITH CAUTION!
|
|
76
|
-
*********************`),re=j.hashForSignature(d,ue,D)}return{script:ue,sighashType:D,hash:re}}function P(d,h,b,B){const C=[];if(h.tapInternalKey){const D=$(d,h,B);D&&C.push(D)}if(h.tapScriptSig){const D=h.tapScriptSig.map(re=>re.pubkey);C.push(...D)}return C.map(D=>X(d,h,b,D,B)).flat()}function $(d,h,b){const{script:B}=Ce(d,h,b);return(0,l.isP2TR)(B)?B.subarray(2,34):null}function G(d){return d.length===64?d:d.subarray(0,64)}function X(d,h,b,B,C,j,D){const re=C.__TX,Q=h.sighashType||u.Transaction.SIGHASH_DEFAULT;Y(Q,D);const ue=b.map((Ve,$n)=>Ce($n,Ve,C)),le=ue.map(Ve=>Ve.script),Be=ue.map(Ve=>Ve.value),Oe=[];if(h.tapInternalKey&&!j){const Ve=$(d,h,C)||Buffer.from([]);if((0,f.toXOnly)(B).equals(Ve)){const $n=re.hashForWitnessV1(d,le,Be,Q);Oe.push({pubkey:B,hash:$n})}}const Je=(h.tapLeafScript||[]).filter(Ve=>(0,l.pubkeyInScript)(B,Ve.script)).map(Ve=>{const $n=(0,c.tapleafHash)({output:Ve.script,version:Ve.leafVersion});return Object.assign({hash:$n},Ve)}).filter(Ve=>!j||j.equals(Ve.hash)).map(Ve=>{const $n=re.hashForWitnessV1(d,le,Be,Q,Ve.hash);return{pubkey:B,hash:$n,leafHash:Ve.hash}});return Oe.concat(Je)}function Y(d,h){if(h&&h.indexOf(d)<0){const b=ge(d);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${b}`)}}function oe(d,h,b){let B;switch(h){case"multisig":const C=Z(d,b);B=o.p2ms({output:d,signatures:C});break;case"pubkey":B=o.p2pk({output:d,signature:b[0].signature});break;case"pubkeyhash":B=o.p2pkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break;case"witnesspubkeyhash":B=o.p2wpkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break}return B}function ae(d,h,b){const B=b.__TX,C={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(C.isP2SH=!!h.redeemScript,C.isP2WSH=!!h.witnessScript,h.witnessScript)C.script=h.witnessScript;else if(h.redeemScript)C.script=h.redeemScript;else if(h.nonWitnessUtxo){const j=fe(b,h,d),D=B.ins[d].index;C.script=j.outs[D].script}else h.witnessUtxo&&(C.script=h.witnessUtxo.script);return(h.witnessScript||(0,l.isP2WPKH)(C.script))&&(C.isSegwit=!0),C}function ee(d,h,b){const B=(0,n.checkForInput)(h,d);if(!B.bip32Derivation||B.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const C=B.bip32Derivation.map(D=>{if(D.masterFingerprint.equals(b.fingerprint))return D}).filter(D=>!!D);if(C.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return C.map(D=>{const re=b.derivePath(D.path);if(!D.pubkey.equals(re.publicKey))throw new Error("pubkey did not match bip32Derivation");return re})}function Z(d,h){return o.p2ms({output:d}).pubkeys.map(B=>(h.filter(C=>C.pubkey.equals(B))[0]||{}).signature).filter(B=>!!B)}function ce(d){let h=0;function b(D){return h+=D,d.slice(h-D,h)}function B(){const D=t.decode(d,h);return h+=t.decode.bytes,D}function C(){return b(B())}function j(){const D=B(),re=[];for(let Q=0;Q<D;Q++)re.push(C());return re}return j()}function ge(d){let h=d&u.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(d&31){case u.Transaction.SIGHASH_ALL:h+="SIGHASH_ALL";break;case u.Transaction.SIGHASH_SINGLE:h+="SIGHASH_SINGLE";break;case u.Transaction.SIGHASH_NONE:h+="SIGHASH_NONE";break}return h}function pe(d,h,b){d.__NON_WITNESS_UTXO_BUF_CACHE[b]=h.nonWitnessUtxo;const B=u.Transaction.fromBuffer(h.nonWitnessUtxo);d.__NON_WITNESS_UTXO_TX_CACHE[b]=B;const C=d,j=b;delete h.nonWitnessUtxo,Object.defineProperty(h,"nonWitnessUtxo",{enumerable:!0,get(){const D=C.__NON_WITNESS_UTXO_BUF_CACHE[j],re=C.__NON_WITNESS_UTXO_TX_CACHE[j];if(D!==void 0)return D;{const Q=re.toBuffer();return C.__NON_WITNESS_UTXO_BUF_CACHE[j]=Q,Q}},set(D){C.__NON_WITNESS_UTXO_BUF_CACHE[j]=D}})}function J(d,h,b,B){let C=0;d.forEach((Q,ue)=>{if(B&&Q.finalScriptSig&&(h.ins[ue].script=Q.finalScriptSig),B&&Q.finalScriptWitness&&(h.ins[ue].witness=ce(Q.finalScriptWitness)),Q.witnessUtxo)C+=Q.witnessUtxo.value;else if(Q.nonWitnessUtxo){const le=fe(b,Q,ue),Be=h.ins[ue].index,Oe=le.outs[Be];C+=Oe.value}});const j=h.outs.reduce((Q,ue)=>Q+ue.value,0),D=C-j;if(D<0)throw new Error("Outputs are spending more than Inputs");const re=h.virtualSize();b.__FEE=D,b.__EXTRACTED_TX=h,b.__FEE_RATE=Math.floor(D/re)}function fe(d,h,b){const B=d.__NON_WITNESS_UTXO_TX_CACHE;return B[b]||pe(d,h,b),B[b]}function Se(d,h,b){const{script:B}=Ce(d,h,b);return B}function Ce(d,h,b){if(h.witnessUtxo!==void 0)return{script:h.witnessUtxo.script,value:h.witnessUtxo.value};if(h.nonWitnessUtxo!==void 0){const C=fe(b,h,d).outs[b.__TX.ins[d].index];return{script:C.script,value:C.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function Ze(d,h,b,B){const C=Se(b,h,B),{meaningfulScript:j}=se(C,b,"input",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(d,j)}function st(d,h,b,B){const C=B.__TX.outs[b].script,{meaningfulScript:j}=se(C,b,"output",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(d,j)}function St(d){if(!d)return;const h=a.decompile(d);if(!h)return;const b=h[h.length-1];if(!(!Buffer.isBuffer(b)||et(b)||Ne(b)||!a.decompile(b)))return b}function Ae(d){if(!d)return;const h=ce(d),b=h[h.length-1];if(!(et(b)||!a.decompile(b)))return b}function ln(d){if(d.length===65){const h=d[64]&1,b=d.slice(0,33);return b[0]=2|h,b}return d.slice()}function et(d){return d.length===33&&a.isCanonicalPubKey(d)}function Ne(d){return a.isCanonicalScriptSignature(d)}function se(d,h,b,B,C){const j=(0,l.isP2SHScript)(d),D=j&&B&&(0,l.isP2WSHScript)(B),re=(0,l.isP2WSHScript)(d);if(j&&B===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((re||D)&&C===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let Q;return D?(Q=C,K(h,d,B,b),N(h,B,C,b),te(Q)):re?(Q=C,N(h,d,C,b),te(Q)):j?(Q=B,K(h,d,B,b)):Q=d,{meaningfulScript:Q,type:D?"p2sh-p2wsh":j?"p2sh":re?"p2wsh":"raw"}}function te(d){if((0,l.isP2WPKH)(d)||(0,l.isP2SHScript)(d))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function ne(d){return(0,l.isP2WPKH)(d)?"witnesspubkeyhash":(0,l.isP2PKH)(d)?"pubkeyhash":(0,l.isP2MS)(d)?"multisig":(0,l.isP2PK)(d)?"pubkey":"nonstandard"}function k(d){return[...Array(d).keys()]}return ro}var Bp;function Ax(){return Bp||(Bp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=Zl();e.address=t;const n=xr();e.crypto=n;const r=Vn();e.networks=r;const i=oc();e.payments=i;const s=Jt();e.script=s;var o=Q8();Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return o.Block}});var c=xx();Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=Gl();Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var u=cc();Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}});var f=zl();Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(Yu)),Yu}var _i={},Ip;function vx(){if(Ip)return _i;Ip=1,Object.defineProperty(_i,"__esModule",{value:!0}),_i.base26Decode=_i.base26Encode=void 0;function e(n){let r=0n;for(let i=0;i<n.length;i++){const s=BigInt(n.charCodeAt(i)-65),o=BigInt(n.length)-1n-BigInt(i);if(o==0n)r+=s;else{const c=26n**o;r+=c*(s+1n)}}return r}_i.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let r=[];for(;n>0;){const i=(n-1n)%26n;r.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(i))),n=(n-1n)/26n}return r.reverse().join("")}return _i.base26Decode=t,_i}var Si={},Op;function cw(){if(Op)return Si;Op=1,Object.defineProperty(Si,"__esModule",{value:!0}),Si.none=Si.some=void 0;class e{constructor(){}isSome(){return!1}map(s){return new e}value(){return null}}class t{constructor(s){this._value=s}isSome(){return!0}map(s){return new t(s(this.value()))}value(){return this._value}}function n(i){return new t(i)}Si.some=n;function r(){return new e}return Si.none=r,Si}var Ti={},Pp;function Bx(){if(Pp)return Ti;Pp=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.decodeLEB128=Ti.encodeLEB128=void 0;function e(n){const r=[];let i=!0;for(;i;){let s=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?i=!1:s|=128,r.push(s)}return r}Ti.encodeLEB128=e;function t(n){let r=BigInt(0);for(let i=0;i<n.length;i++){const s=BigInt(n[i]);if(i>18)throw new Error("Overlong");let o=s&BigInt(127);if(i==18&&(o&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(r|=o<<BigInt(7)*BigInt(i),(s&BigInt(128))==BigInt(0))return{n:r,len:i+1}}throw new Error("Unterminated")}return Ti.decodeLEB128=t,Ti}var yf={},kp;function Ix(){return kp||(kp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=s=>s.length%2===1?"0"+s:s;e.zero2=t;const n=s=>{let o="";for(let c=0;c<s.length;c++)o+=(0,e.zero2)(s[c].toString(16));return o};e.toHex=n;function r(s,o){const c=[];let a=0;for(;a<s.length;){const u=s.slice(a,a+o);c.push(u),a+=o}return c}e.chunks=r;function i(s){const o=[],c=s.length;if(c<76){const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=255){o.push(Buffer.from("4c","hex"));const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=65535){o.push(Buffer.from("4d","hex"));const a=Buffer.alloc(2);a.writeUInt16LE(c),o.push(a)}else{o.push(Buffer.from("4e","hex"));const a=Buffer.alloc(4);a.writeUInt32LE(c),o.push(a)}return o.push(s),Buffer.concat(o)}e.toPushData=i})(yf)),yf}var sr={},Np;function aw(){if(Np)return sr;Np=1,Object.defineProperty(sr,"__esModule",{value:!0}),sr.removeSpacers=sr.getSpacersVal=sr.applySpacers=void 0;function e(r,i){let s="";for(let o=0;o<r.length;o++)s+=r.charAt(o),i>0&&((i&1)===1&&(s+="•"),i>>=1);return s}sr.applySpacers=e;function t(r){let i=0,s=0;for(let o=0;o<r.length;o++)r.charAt(o)==="•"&&(i+=1<<o-1-s,s++);return i}sr.getSpacersVal=t;function n(r){return r.replace(/[•]+/g,"")}return sr.removeSpacers=n,sr}var Up;function Ox(){if(Up)return je;Up=1,Object.defineProperty(je,"__esModule",{value:!0}),je.EtchInscription=je.Message=je.Runestone=je.Etching=je.Rune=je.Terms=je.Range=je.Flaw=je.Tag=je.Flag=je.Edict=je.RuneId=void 0;const e=Ax(),t=vx(),n=cw(),r=Bx(),i=Ix(),s=aw();class o{constructor(m,T){this.block=m,this.idx=T}next(m,T){if(m>BigInt(Number.MAX_SAFE_INTEGER)||T>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let I=BigInt(this.block)+m;if(I>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let A=m===0n?BigInt(this.idx)+T:T;return A>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new o(Number(I),Number(A)))}}je.RuneId=o;class c{constructor(m,T,I){this.id=m,this.amount=T,this.output=I}static from_integers(m,T,I,A){return A>4294967295n||A<0n||Number(A)>m.outs.length?(0,n.none)():(0,n.some)(new c(T,I,Number(A)))}}je.Edict=c;var a;(function(S){S[S.Etching=0]="Etching",S[S.Terms=1]="Terms",S[S.Turbo=2]="Turbo",S[S.Cenotaph=127]="Cenotaph"})(a||(je.Flag=a={}));var u;(function(S){S[S.Body=0]="Body",S[S.Flags=2]="Flags",S[S.Rune=4]="Rune",S[S.Premine=6]="Premine",S[S.Cap=8]="Cap",S[S.Amount=10]="Amount",S[S.HeightStart=12]="HeightStart",S[S.HeightEnd=14]="HeightEnd",S[S.OffsetStart=16]="OffsetStart",S[S.OffsetEnd=18]="OffsetEnd",S[S.Mint=20]="Mint",S[S.Pointer=22]="Pointer",S[S.Cenotaph=126]="Cenotaph",S[S.Divisibility=1]="Divisibility",S[S.Spacers=3]="Spacers",S[S.Symbol=5]="Symbol",S[S.Nop=127]="Nop"})(u||(je.Tag=u={}));var f;(function(S){S[S.EdictOutput=0]="EdictOutput",S[S.EdictRuneId=1]="EdictRuneId",S[S.InvalidScript=2]="InvalidScript",S[S.Opcode=3]="Opcode",S[S.SupplyOverflow=4]="SupplyOverflow",S[S.TrailingIntegers=5]="TrailingIntegers",S[S.TruncatedField=6]="TruncatedField",S[S.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",S[S.UnrecognizedFlag=8]="UnrecognizedFlag",S[S.Varint=9]="Varint"})(f||(je.Flaw=f={}));class l{constructor(m,T){this.start=m,this.end=T}}je.Range=l;class p{constructor(m,T,I,A){this.amount=m,this.cap=T,this.height=I,this.offset=A}}je.Terms=p;class y{constructor(m){this.value=m}get name(){return y.toName(this.value)}static toName(m){return(0,t.base26Decode)(m)}static fromName(m){return new y((0,t.base26Encode)((0,s.removeSpacers)(m)))}toString(){return this.name}}je.Rune=y;class g{constructor(m,T,I,A,U,M,v){this.divisibility=m,this.premine=T,this.rune=I,this.spacers=A,this.symbol=U,this.terms=M,this.turbo=v}}je.Etching=g,g.MAX_DIVISIBILITY=38,g.MAX_SPACERS=134217727;class w{constructor(m=[],T,I,A){this.edicts=m,this.etching=T,this.mint=I,this.pointer=A}static create(m,T="etch"){if(T==="etch"){m=m;const I=y.fromName(m.name),A=new p(m.amount,m.cap,new l(m.startHeight?(0,n.some)(m.startHeight):(0,n.none)(),m.endHeight?(0,n.some)(m.endHeight):(0,n.none)()),new l(m.startOffset?(0,n.some)(m.startOffset):(0,n.none)(),m.endOffset?(0,n.some)(m.endOffset):(0,n.none)())),U=m.divisibility?(0,n.some)(m.divisibility):(0,n.none)(),M=m.premine?(0,n.some)(m.premine):(0,n.none)(),v=m.name.indexOf("•")>-1?(0,n.some)((0,s.getSpacersVal)(m.name)):(0,n.none)(),R=m.symbol?(0,n.some)(m.symbol):(0,n.none)(),V=typeof m.pointer=="number"?(0,n.some)(m.pointer):(0,n.none)(),W=new g(U,M,(0,n.some)(I),v,R,(0,n.some)(A),!0);return new w([],(0,n.some)(W),(0,n.none)(),V)}else if(T==="mint"){m=m;const I=typeof m.pointer=="number"?(0,n.some)(m.pointer):(0,n.none)();return new w([],(0,n.none)(),(0,n.some)(new o(m.block,m.txIdx)),I)}else throw new Error(`not ${T} support now`)}static decipher(m){const T=e.Transaction.fromHex(m),I=w.payload(T);if(I.isSome()){const A=w.integers(I.value()),U=E.from_integers(T,A.value()),M=U.getEtching(),v=U.getMint(),R=U.getPointer();return(0,n.some)(new w(U.edicts,M,v,R))}return(0,n.none)()}encipher(){const T=this.toMessage().toBuffer(),I=Buffer.from("6a5d","hex");let A;if(T.length<76)A=Buffer.alloc(1),A.writeUInt8(T.length);else if(T.length<256)A=Buffer.alloc(2),A.writeUInt8(76),A.writeUInt8(T.length);else if(T.length<65536)A=Buffer.alloc(3),A.writeUInt8(77),A.writeUInt16LE(T.length);else if(T.length<4294967296)A=Buffer.alloc(5),A.writeUInt8(78),A.writeUInt32LE(T.length);else throw new Error("runestone too big!");return Buffer.concat([I,A,T])}static payload(m){for(const T of m.outs){const I=e.script.decompile(T.script);if(I[0]===e.script.OPS.OP_RETURN&&I[1]===w.MAGIC_NUMBER){for(let A=2;A<I.length;A++){const U=I[A];return U instanceof Uint8Array?(0,n.some)(Array.from(U)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(m){let T=[],I=0;for(;I<m.length;){let{n:A,len:U}=(0,r.decodeLEB128)(m.slice(I));T.push(A),I+=U}return(0,n.some)(T)}toMessage(){let m=new Map;const T=this.etching.value();if(T){let U=1;if(T.terms.isSome()){let K=1<<a.Terms;U|=K}if(T.turbo){let K=1<<a.Turbo;U|=K}m.set(u.Flags,[BigInt(U)]);const M=T.rune.value();M!==null&&m.set(u.Rune,[BigInt(M.value)]);const v=T.divisibility.value();v!==null&&m.set(u.Divisibility,[BigInt(v)]);const R=T.spacers.value();R!==null&&m.set(u.Spacers,[BigInt(R)]);const V=T.symbol.value();V!==null&&m.set(u.Symbol,[BigInt(V.charCodeAt(0))]);const W=T.premine.value();W!==null&&m.set(u.Premine,[BigInt(W)]);const H=T.terms.value();if(H!==null){m.set(u.Amount,[BigInt(H.amount)]),m.set(u.Cap,[BigInt(H.cap)]);const K=H.height.start.value();K&&m.set(u.HeightStart,[BigInt(K)]);const N=H.height.end.value();N&&m.set(u.HeightEnd,[BigInt(N)]);const L=H.offset.start.value();L&&m.set(u.OffsetStart,[BigInt(L)]);const F=H.offset.end.value();F&&m.set(u.OffsetEnd,[BigInt(F)])}}const I=this.mint.value();I!==null&&m.set(u.Mint,[BigInt(I.block),BigInt(I.idx)]);const A=this.pointer.value();return A!==null&&m.set(u.Pointer,[BigInt(A)]),new E(m,this.edicts,0)}}je.Runestone=w,w.MAGIC_NUMBER=93;class E{constructor(m=new Map,T=[],I=0){this.fields=m,this.edicts=T,this.flaws=I}static from_integers(m,T){let I=new Map,A=[],U=0,M=!1;for(let v=0;v<T.length;){let R=T[v];if(Number(R)===u.Body){M=!0,v+=1;continue}if(M){let V=new o(0,0);for(const W of(0,i.chunks)(T.slice(v),4)){if(W.length!=4){U|=f.TrailingIntegers;break}let H=V.next(W[0],W[1]);if(!H.isSome()){U|=f.EdictRuneId;break}const K=c.from_integers(m,H.value(),W[2],W[3]);if(!K.isSome()){U|=f.EdictOutput;break}V=H.value(),A.push(K.value())}v+=4}else{let V=T[v+1];const W=I.get(Number(R))||[];W.push(V),I.set(Number(R),W),v+=2}}return new E(I,A,U)}addFieldVal(m,T){const I=this.fields.get(Number(m))||[];I.push(T),this.fields.set(Number(m),I)}addEdict(m){this.edicts.push(m)}toBuffer(){const m=[];for(const[T,I]of this.fields)for(const A of I){const U=Buffer.alloc(1);U.writeUInt8(T),m.push(U),m.push(Buffer.from((0,r.encodeLEB128)(A)))}if(this.edicts.length>0){m.push(Buffer.from("00","hex")),this.edicts.sort((A,U)=>A.id.block==U.id.block?A.id.idx-U.id.idx:A.id.block-U.id.block);let T=0n,I=0n;for(let A=0;A<this.edicts.length;A++){const U=this.edicts[A];if(A==0)T=BigInt(U.id.block),I=BigInt(U.id.idx),m.push(Buffer.from((0,r.encodeLEB128)(T))),m.push(Buffer.from((0,r.encodeLEB128)(I)));else{const M=BigInt(U.id.block),v=BigInt(U.id.idx);if(M==T){const R=v-I;I=v,m.push(Buffer.from((0,r.encodeLEB128)(0n))),m.push(Buffer.from((0,r.encodeLEB128)(R)))}else{const R=M-T;T=M,I=v,m.push(Buffer.from((0,r.encodeLEB128)(R))),m.push(Buffer.from((0,r.encodeLEB128)(v)))}}m.push(Buffer.from((0,r.encodeLEB128)(BigInt(U.amount)))),m.push(Buffer.from((0,r.encodeLEB128)(BigInt(U.output))))}}return Buffer.concat(m)}getFlags(){return Number(this.fields.get(u.Flags))}hasFlags(m){const T=this.getFlags(),I=1<<m;return(T&I)!=0}getMint(){if(!this.fields.has(u.Mint))return(0,n.none)();const[m,T]=this.fields.get(u.Mint);return(0,n.some)(new o(Number(m),Number(T)))}getEtching(){if(!this.hasFlags(a.Etching))return(0,n.none)();const m=this.getDivisibility(),T=this.getPremine(),I=this.getRune(),A=this.getSpacers(),U=this.getSymbol(),M=this.getTerms(),v=this.hasFlags(a.Turbo);return(0,n.some)(new g(m,T,I,A,U,M,v))}getDivisibility(){if(!this.fields.has(u.Divisibility))return(0,n.none)();const[m]=this.fields.get(u.Divisibility);if(m>g.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(m))}getPremine(){if(!this.fields.has(u.Premine))return(0,n.none)();const[m]=this.fields.get(u.Premine);return(0,n.some)(Number(m))}getRune(){if(!this.fields.has(u.Rune))return(0,n.none)();const[m]=this.fields.get(u.Rune);return(0,n.some)(new y(m))}getSpacers(){if(!this.fields.has(u.Spacers))return(0,n.none)();const[m]=this.fields.get(u.Spacers);if(m>g.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(m))}getHeightStart(){if(!this.fields.has(u.HeightStart))return(0,n.none)();const[m]=this.fields.get(u.HeightStart);return(0,n.some)(Number(m))}getHeightEnd(){if(!this.fields.has(u.HeightEnd))return(0,n.none)();const[m]=this.fields.get(u.HeightEnd);return(0,n.some)(Number(m))}getOffsetStart(){if(!this.fields.has(u.OffsetStart))return(0,n.none)();const[m]=this.fields.get(u.OffsetStart);return(0,n.some)(Number(m))}getOffsetEnd(){if(!this.fields.has(u.OffsetEnd))return(0,n.none)();const[m]=this.fields.get(u.OffsetEnd);return(0,n.some)(Number(m))}getCap(){if(!this.fields.has(u.Cap))return(0,n.none)();const[m]=this.fields.get(u.Cap);return(0,n.some)(Number(m))}getAmount(){if(!this.fields.has(u.Amount))return(0,n.none)();const[m]=this.fields.get(u.Amount);return(0,n.some)(Number(m))}getSymbol(){if(!this.fields.has(u.Symbol))return(0,n.none)();const[m]=this.fields.get(u.Symbol);return(0,n.some)(String.fromCharCode(Number(m)))}getTerms(){if(!this.hasFlags(a.Terms))return(0,n.none)();const m=this.getCap();if(!m.isSome())throw new Error("no cap field");const T=this.getAmount();if(!T.isSome())throw new Error("no amount field");const I=this.getHeightStart(),A=this.getHeightEnd(),U=this.getOffsetStart(),M=this.getOffsetEnd(),v=new l(I,A),R=new l(U,M);return(0,n.some)(new p(T.value(),m.value(),v,R))}getPointer(){if(!this.fields.has(u.Pointer))return(0,n.none)();const[m]=this.fields.get(u.Pointer);return(0,n.some)(Number(m))}}je.Message=E;class _{constructor(m=new Map,T=Buffer.alloc(0)){this.fields=m,this.data=T}setContent(m,T){this.fields.set(1,Buffer.from(m,"utf8")),this.data=T}setRune(m){let I=(0,t.base26Encode)((0,s.removeSpacers)(m)).toString(16);I.length%2===1&&(I="0"+I),this.setField(_.Tag.RUNE,Buffer.from(I,"hex").reverse())}setField(m,T){this.fields.set(m,T)}static decipher(m,T){const U=e.Transaction.fromHex(m).ins[T].witness[1],M=e.script.decompile(U),v=new Map,R=[];let V=!1;for(let W=5;W<M.length-1;){const H=M[W];if(H===0){V=!0,W++;continue}else if(V)R.push(H),W++;else{const K=H-80,N=M[W+1];if(typeof N=="number"){const L=Buffer.alloc(1);L.writeUInt8(N),v.set(K,L)}else v.set(K,N);W+=2}}return new _(v,Buffer.concat(R))}encipher(){const m=[];if(this.data&&this.data.length>0){m.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((I,A)=>I[0]-A[0]).forEach(([I,A])=>{const U=Buffer.alloc(1);U.writeUInt8(I),m.push(Buffer.from("01","hex")),m.push(U),A.length!=1||A[0]!=0?m.push((0,i.toPushData)(A)):m.push(A)}),m.push(Buffer.from("00","hex"));const T=(0,i.chunks)(Array.from(this.data),520);for(const I of T)m.push((0,i.toPushData)(Buffer.from(I)))}else{m.push(Buffer.from("0063","hex"));const T=this.fields.get(_.Tag.RUNE);if(!T)throw new Error("No rune found!");m.push((0,i.toPushData)(T))}return m.push(Buffer.from("68","hex")),Buffer.concat(m)}}return je.EtchInscription=_,_.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},je}var Rp;function Px(){return Rp||(Rp=1,(function(e){var t=di&&di.__createBinding||(Object.create?(function(s,o,c,a){a===void 0&&(a=c);var u=Object.getOwnPropertyDescriptor(o,c);(!u||("get"in u?!o.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return o[c]}}),Object.defineProperty(s,a,u)}):(function(s,o,c,a){a===void 0&&(a=c),s[a]=o[c]})),n=di&&di.__exportStar||function(s,o){for(var c in s)c!=="default"&&!Object.prototype.hasOwnProperty.call(o,c)&&t(o,s,c)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(Ox(),e);var r=cw();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return r.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return r.some}});var i=aw();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return i.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return i.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return i.removeSpacers}})})(di)),di}var ns=Px();function oo(e){if(e.length%2!==0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function ba(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function eh(e){return e===Yo.Mainnet?vn:Gp}function Ea(e,t=Yo.Testnet){const n=eh(t);return Ry(e,n)}function Zr(e){const t=vn,n=Gp,r=qw;let i,s,o=Dt.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return s=il(e),s.version===0?s.data.length===20?o=Dt.P2WPKH:o=Dt.P2WSH:o=Dt.P2TR,o}catch{return Dt.UNKNOWN}else try{return i=Uy(e),i.version===t.pubKeyHash||i.version===n.pubKeyHash||i.version===r.pubKeyHash?o=Dt.P2PKH:(i.version===t.scriptHash||(i.version,n.scriptHash),o=Dt.P2SH_P2WPKH),o}catch{return Dt.UNKNOWN}}function kx(e,t,n){const r=Ea(e,n),i=t.coins?.[0];return{txid:t.txid,vout:t.vout,satoshis:t.sats.toString(),height:void 0,runes:i?[{id:i.id,amount:i.value.toString()}]:[],address:e,scriptPk:ba(r)}}async function uw(e,t){try{const n=t===Yo.Mainnet?"https://mpc.omnity.network/utxo-status":"https://mpc.omnity.network/testnet4/utxo-status",r=await at.post(n,e).then(c=>c.data);if(!r)return null;const i=JSON.stringify(r),o=new TextEncoder().encode(i);return Array.from(o)}catch{return null}}const Nx=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:ba,formatPoolUtxo:kx,getAddressType:Zr,getScriptByAddress:Ea,getUtxoProof:uw,hexToBytes:oo,toBitcoinNetwork:eh},Symbol.toStringTag,{value:"Module"})),Ux="kqs64-paaaa-aaaar-qamza-cai",Rx="hvyp5-5yaaa-aaaao-qjxha-cai",Wr=BigInt(546),vt="0:0",Cp={P2PKH:148,P2SH_P2WPKH:91,P2WPKH:68,P2WSH:140,P2SH:108,P2TR:58,UNKNOWN:110},Hp={P2PKH:34,P2SH_P2WPKH:32,P2WPKH:31,P2WSH:43,P2SH:32,P2TR:43,UNKNOWN:34},Cx=new Set(["P2WPKH","P2WSH","P2SH_P2WPKH","P2TR"]),Hx=2;function Fp(e){return"P2SH_P2WPKH"in e?{P2SH:null}:"P2PKH"in e?{P2WPKH:null}:"P2WSH"in e?{P2WPKH:null}:"UNKNOWN"in e?{P2WPKH:null}:e}class Jr{psbt;client;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new Qc({network:eh(t.network)}),this.client=n}addInput(t){if(this.inputUtxos.findIndex(i=>i.txid===t.txid&&i.vout===t.vout)>=0)return;const{address:n}=t;if(Zr(n)===Dt.P2TR){let i=t.pubkey;i||t.address===this.config.address&&this.config.publicKey&&(i=this.config.publicKey);const s=i?i.length===66?i.slice(2):i:void 0;s?this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:oo(t.scriptPk)},tapInternalKey:oo(s)}):this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:oo(t.scriptPk)}})}else this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:oo(t.scriptPk)}});this.inputAddressTypes.push(Zr(n)),this.inputUtxos.push(t),(n===this.config.address||n===this.config.paymentAddress)&&t.runes.length!==0&&(this.userInputUtxoDusts+=BigInt(t.satoshis))}addOutput(t,n){this.psbt.addOutput({address:t,value:n}),this.outputAddressTypes.push(Zr(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:BigInt(0)}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,r){const i=[];if(r==BigInt(0))return i;for(const s of t)if(s.runes.length){const o=s.runes.find(c=>c.id==n);if(o&&BigInt(o.amount)==r){i.push(s);break}}if(i.length==0){let s=BigInt(0);for(const o of t)if(o.runes.forEach(c=>{c.id==n&&(s=s+BigInt(c.amount))}),i.push(o),s>=r)break;if(s<r)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return i}selectBtcUtxos(t,n,r=!1){const i=[];if(n<=BigInt(0))return i;let s=BigInt(0);for(const o of t)if(!(o.runes.length&&!r)&&(s+=BigInt(o.satoshis),i.push(o),s>=n))break;if(s<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${s}`);return i}async addBtcAndFees(t,n){const r=this.config.paymentAddress,i=this.additionalDustNeeded,s=Zr(r),o=this.userInputUtxoDusts,c=this.config.feeRate;let a=BigInt(0),u=BigInt(0);if(this.config.manualBuild){a=this.inputUtxos.reduce((m,T)=>m+BigInt(T.satoshis),BigInt(0));for(const m of this.psbt.txOutputs)u+=BigInt(m.value)}this.outputAddressTypes.push(s);let f=!0,l=BigInt(0),p=BigInt(0),y=[],g=BigInt(0),w=BigInt(0);const E=[...this.inputAddressTypes];do{if(l=p,c!==void 0){const m=Jr.estimateTxVirtualSize(this.inputAddressTypes,this.outputAddressTypes);p=BigInt(Math.round(c*m))}else p=(await this.client.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes.map(Fp),pool_address:this.intentions.map(T=>T.poolAddress),output_types:this.outputAddressTypes.map(Fp)}).catch(T=>{throw console.error("estimate_min_tx_fee failed:",T),T})).Ok;if(this.config.manualBuild?g=u+p+i-a:g=n+p+i-o,p>l&&g>0){const m=this.selectBtcUtxos(t,g);if(m.length===0)throw new Error(`INSUFFICIENT_BTC_UTXOs: need ${g} more sats (inputs=${a}, outputs=${u}, fee=${p}, dust=${i})`);this.inputAddressTypes=E.concat(m.map(()=>s));const T=m.reduce((I,A)=>I+BigInt(A.satoshis),BigInt(0));T-g>0&&T-g>Wr||(this.outputAddressTypes.pop(),f=!1),y=m}}while(p>l&&g>0);this.inputAddressTypes=[...E],f&&this.outputAddressTypes.pop();let _=BigInt(0);y.forEach(m=>{this.addInput(m),_+=BigInt(m.satoshis)});let S;if(this.config.manualBuild?S=a+_-u-p-i:S=_-g,S<0)throw new Error(`Insufficient UTXO(s): shortage=${-S} sats (inputs=${this.config.manualBuild?a+_:_}, outputs=${this.config.manualBuild?u:n}, fee=${p}, dust=${i})`);S>Wr?this.addOutput(r,S):S>BigInt(0)&&(w=S),this.txFee=w+p}async getInvolvedAddressUtxos(){const t={},n={},r=new Map;r.set(this.config.paymentAddress,{needBtc:!0,runeIds:new Set});const i=s=>{const o=s.trim();return r.has(o)||r.set(o,{needBtc:!1,runeIds:new Set}),r.get(o)};for(const s of this.intentions){for(const a of s.inputCoins){const u=i(a.from);a.coin.id===vt?u.needBtc=!0:u.runeIds.add(a.coin.id)}for(const a of s.outputCoins){const u=i(a.to);a.coin.id===vt?u.needBtc=!0:u.runeIds.add(a.coin.id)}const o=i(s.poolAddress),c=[...s.inputCoins.map(a=>a.coin.id),...s.outputCoins.map(a=>a.coin.id)];for(const a of c)a===vt?o.needBtc=!0:o.runeIds.add(a)}return await Promise.all(Array.from(r.entries()).map(async([s,o])=>{if(o.needBtc)try{t[s]=await this.client.getBtcUtxos(s),console.log(`[REE-SDK] getBtcUtxos for ${s}: ${t[s].length} utxos, total=${t[s].reduce((c,a)=>c+BigInt(a.satoshis),BigInt(0))} sats`)}catch(c){console.warn(`[REE-SDK] getBtcUtxos FAILED for ${s}:`,c),t[s]=[]}o.runeIds.size>0&&(n[s]={},await Promise.all(Array.from(o.runeIds).map(async c=>{try{n[s][c]=await this.client.getRuneUtxos(s,c),console.log(`[REE-SDK] getRuneUtxos for ${s}, runeId=${c}: ${n[s][c].length} utxos`)}catch(a){console.warn(`[REE-SDK] getRuneUtxos FAILED for ${s}, runeId=${c}:`,a),n[s][c]=[]}})))})),{btc:t,rune:n}}addInputsAndCalculateOutputs(t){if(!this.intentions.length)throw new Error("No intentions added");const n=this.intentions.map(a=>a.poolAddress),r={},i={};let s=BigInt(0);const o=new Map,c=new Set;this.intentions.forEach(({poolAddress:a,inputCoins:u,outputCoins:f,poolUtxos:l})=>{const p=[...u.filter(({from:g})=>!n.includes(g))],y=[...f];if(p.forEach(({coin:g,from:w})=>{!f.find(E=>E.coin.id===g.id)&&!(n.includes(w)&&w!==a)&&y.push({coin:g,to:a})}),y.forEach(({coin:g})=>{u.find(w=>w.coin.id===g.id)||p.push({coin:g,from:a})}),p.length===0&&y.length===0&&l?.length){const g=o.get(a);o.set(a,g?g.concat(l):[...l]),c.add(a);return}p.forEach(({coin:g,from:w})=>{r[w]??={},r[w][g.id]=(r[w][g.id]??BigInt(0))+BigInt(g.value)}),y.forEach(({coin:g,to:w})=>{i[w]??={},i[w][g.id]=(i[w][g.id]??BigInt(0))+BigInt(g.value)})});for(const[a,u]of o.entries()){if(!u.length)continue;i[a]??={};const f=i[a];u.forEach(l=>{this.addInput(l),f[vt]=(f[vt]??BigInt(0))+BigInt(l.satoshis),l.runes.forEach(p=>{f[p.id]=(f[p.id]??BigInt(0))+BigInt(p.amount)})})}for(const[a,u]of Object.entries(r))for(const[f,l]of Object.entries(u))if(f===vt){if(a===this.config.paymentAddress){s+=l;continue}const p=t.btc[a]||[],y=this.selectBtcUtxos(p,l,n.includes(a)),w=y.reduce((E,_)=>E+BigInt(_.satoshis),BigInt(0))-l;w>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+w),y.forEach(E=>{this.addInput(E),n.includes(a)&&E.runes.forEach(_=>{(r[a]?.[_.id]??BigInt(0))>BigInt(0)||(i[a]??={},i[a][_.id]=(i[a][_.id]??BigInt(0))+BigInt(_.amount))})})}else{const p=t.rune[a]?.[f]||[];console.log(`[REE-SDK] selectRuneUtxos: address=${a}, coinId=${f}, requiredAmount=${l}, runeUtxos=${p.length}`,p.map(_=>({txid:_.txid,vout:_.vout,runes:_.runes})));const y=this.selectRuneUtxos(p,f,l),g=y.reduce((_,S)=>{const m=S.runes.find(T=>T.id===f);return _+BigInt(m?.amount??0)},BigInt(0)),w=y.reduce((_,S)=>_+BigInt(S.satoshis),BigInt(0)),E=g-l;if(n.includes(a)){i[a]??={};const _=i[a],S=(r[a]?.[vt]??BigInt(0))>BigInt(0);w>BigInt(0)&&!S&&(_[vt]=(_[vt]??BigInt(0))+w),E>BigInt(0)&&(_[f]=(_[f]??BigInt(0))+E)}else E>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+E);y.forEach(_=>this.addInput(_))}for(const[a,u]of Object.entries(i)){if(r[a]||!n.includes(a)||c.has(a))continue;const f=new Set;if(u[vt]!==void 0){const l=t.btc[a]||[],p=l.reduce((y,g)=>y+BigInt(g.satoshis),BigInt(0));i[a]??={},i[a][vt]=(i[a][vt]??BigInt(0))+p,l.forEach(y=>{this.addInput(y),f.add(`${y.txid}:${y.vout}`),y.runes.forEach(g=>{i[a]??={},i[a][g.id]=(i[a][g.id]??BigInt(0))+BigInt(g.amount)})})}for(const[l]of Object.entries(u)){if(l===vt)continue;const y=(t.rune[a]?.[l]||[]).filter(w=>!f.has(`${w.txid}:${w.vout}`)),g=y.reduce((w,E)=>{const _=E.runes.find(S=>S.id===l);return w+BigInt(_?.amount??0)},BigInt(0));i[a]??={},i[a][l]=(i[a][l]??BigInt(0))+g,y.forEach(w=>{this.addInput(w),f.add(`${w.txid}:${w.vout}`)})}}return{addressOutputCoinAmounts:i,paymentBtcRequired:s}}addOutputs(t){const n=this.config.mergeSelfRuneBtcOutputs===!0,r=new Set;for(const[,s]of Object.entries(t))for(const o of Object.keys(s))o!==vt&&r.add(o);const i=Array.from(r);if(i.length>0){const s=[],o=[];let c=1;i.forEach(u=>{const f=new ns.RuneId(Number(u.split(":")[0]),Number(u.split(":")[1]));for(const[l,p]of Object.entries(t)){const y=p[u]??BigInt(0);y>BigInt(0)&&(s.push(new ns.Edict(f,y,c)),o.push(l),c++)}});const a=new ns.Runestone(s,ns.none(),ns.none(),ns.none());this.addScriptOutput(new Uint8Array(a.encipher())),o.forEach(u=>{const f=t[u]?.[vt]??BigInt(0),l=u===this.config.address,p=f>BigInt(0)&&(!l||n),y=p&&f>Wr?f:Wr;this.addOutput(u,y),p?(f<Wr&&(this.additionalDustNeeded+=Wr-f),delete t[u][vt]):this.additionalDustNeeded+=Wr})}for(const[s,o]of Object.entries(t)){const c=o[vt]??BigInt(0);c>BigInt(0)&&this.addOutput(s,c)}}addIntention(t){this.intentions.push(t)}async build(){console.log(`[REE-SDK] build() — address=${this.config.address}, paymentAddress=${this.config.paymentAddress}, publicKey=${this.config.publicKey}, paymentPublicKey=${this.config.paymentPublicKey}`);const t=await this.getInvolvedAddressUtxos(),n=this.config.paymentAddress;let r=t.btc[n]??[];if(console.log(`[REE-SDK] build() — userBtcUtxos from paymentAddress: ${r.length} utxos`),this.config.manualBuild)await this.addBtcAndFees(r,BigInt(0));else{for(const f of this.intentions){const l=f.poolUtxos;if(!l)continue;t.btc[f.poolAddress]=l,t.rune[f.poolAddress]={};const p=t.rune[f.poolAddress];for(const y of l)for(const g of y.runes)(p[g.id]??=[]).push(y)}const{addressOutputCoinAmounts:a,paymentBtcRequired:u}=this.addInputsAndCalculateOutputs(t);this.addOutputs(a),await this.addBtcAndFees(r,u)}const s=this.psbt.__CACHE.__TX.clone(),o=[];for(let a=0;a<this.inputUtxos.length;a++){const u=this.inputUtxos[a],f=u.address;if(f!==this.config.paymentAddress&&f!==this.config.address)continue;const l=this.psbt.data.inputs[a]?.redeemScript,p=Zr(f);let y=u.pubkey;if(!y&&f===this.config.paymentAddress&&(y=this.config.paymentPublicKey),!y&&f===this.config.address&&(y=this.config.publicKey),o.push({index:a,...p===Dt.P2TR?{address:f,disableTweakSigner:!1}:{publicKey:y,disableTweakSigner:!0}}),l&&p===Dt.P2SH_P2WPKH){const g=Zt([l]);s.setInputScript(a,g)}}const c=s.getId();return{psbt:this.psbt,txid:c,fee:this.txFee,toSignInputs:o}}static estimateTxVirtualSize(t,n){const r=t.length,i=n.length;let s=8+Jr.varIntSize(r)+Jr.varIntSize(i),o=!1;for(const c of t){const a=Jr.parseAddressType(c);if(a.key==="OpReturn")continue;const u=Cp[a.key]??Cp.UNKNOWN;s+=u,Cx.has(a.key)&&(o=!0)}for(const c of n){const a=Jr.parseAddressType(c);if(a.key==="OpReturn"){const f=Math.max(0,a.opReturnLength??0);s+=11+f;continue}const u=Hp[a.key]??Hp.UNKNOWN;s+=u}return o&&(s+=1),s+Hx}static parseAddressType(t){if("OpReturn"in t){const r=t.OpReturn!==void 0?Number(t.OpReturn):0;return{key:"OpReturn",opReturnLength:Number.isFinite(r)?r:0}}const n=["P2PKH","P2SH_P2WPKH","P2WPKH","P2WSH","P2SH","P2TR"];for(const r of n)if(r in t)return{key:r};return{key:"UNKNOWN"}}static varIntSize(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}async getToSpendUtxos(){return this.inputUtxos.filter(t=>t.address===this.config.paymentAddress||t.address===this.config.address)}async getUtxoProof(){const t=await this.getToSpendUtxos(),n=await uw(t,this.config.network);if(!n)throw new Error("Failed to get utxo proof");return n}async getInvokeArgs(t){const n=await this.getUtxoProof();return{intention_set:{tx_fee_in_sats:Number(this.txFee),initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:r,actionParams:i,poolAddress:s,inputCoins:o,outputCoins:c,exchangeId:a,nonce:u})=>({exchange_id:a??this.config.exchangeId,input_coins:o.filter(f=>f.from!==s),output_coins:c,pool_address:s,action:r,action_params:i??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:Number(u)}))},initiator_utxo_proof:n,psbt_hex:t,client_info:[this.config.clientInfo??""]}}async send(t){if(!this.intentions.length)throw new Error("No itentions added");const n=await this.getInvokeArgs(t);return this.client.orchestrator.invoke(n).then(r=>{if(r?.Ok)return r.Ok;{const i=r?.Err??{},s=Object.keys(i)[0],o=i[s];throw new Error(o?s==="ErrorOccurredDuringExecution"?`${s}: ${o.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(r)}`:`Invoke Error: ${JSON.stringify(r)}`)}})}}/*!
|
|
76
|
+
*********************`),re=j.hashForSignature(d,ue,D)}return{script:ue,sighashType:D,hash:re}}function P(d,h,b,B){const C=[];if(h.tapInternalKey){const D=$(d,h,B);D&&C.push(D)}if(h.tapScriptSig){const D=h.tapScriptSig.map(re=>re.pubkey);C.push(...D)}return C.map(D=>X(d,h,b,D,B)).flat()}function $(d,h,b){const{script:B}=Ce(d,h,b);return(0,l.isP2TR)(B)?B.subarray(2,34):null}function G(d){return d.length===64?d:d.subarray(0,64)}function X(d,h,b,B,C,j,D){const re=C.__TX,Q=h.sighashType||u.Transaction.SIGHASH_DEFAULT;Y(Q,D);const ue=b.map((Ve,$n)=>Ce($n,Ve,C)),le=ue.map(Ve=>Ve.script),Be=ue.map(Ve=>Ve.value),Oe=[];if(h.tapInternalKey&&!j){const Ve=$(d,h,C)||Buffer.from([]);if((0,f.toXOnly)(B).equals(Ve)){const $n=re.hashForWitnessV1(d,le,Be,Q);Oe.push({pubkey:B,hash:$n})}}const Je=(h.tapLeafScript||[]).filter(Ve=>(0,l.pubkeyInScript)(B,Ve.script)).map(Ve=>{const $n=(0,c.tapleafHash)({output:Ve.script,version:Ve.leafVersion});return Object.assign({hash:$n},Ve)}).filter(Ve=>!j||j.equals(Ve.hash)).map(Ve=>{const $n=re.hashForWitnessV1(d,le,Be,Q,Ve.hash);return{pubkey:B,hash:$n,leafHash:Ve.hash}});return Oe.concat(Je)}function Y(d,h){if(h&&h.indexOf(d)<0){const b=ge(d);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${b}`)}}function oe(d,h,b){let B;switch(h){case"multisig":const C=Z(d,b);B=o.p2ms({output:d,signatures:C});break;case"pubkey":B=o.p2pk({output:d,signature:b[0].signature});break;case"pubkeyhash":B=o.p2pkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break;case"witnesspubkeyhash":B=o.p2wpkh({output:d,pubkey:b[0].pubkey,signature:b[0].signature});break}return B}function ae(d,h,b){const B=b.__TX,C={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(C.isP2SH=!!h.redeemScript,C.isP2WSH=!!h.witnessScript,h.witnessScript)C.script=h.witnessScript;else if(h.redeemScript)C.script=h.redeemScript;else if(h.nonWitnessUtxo){const j=fe(b,h,d),D=B.ins[d].index;C.script=j.outs[D].script}else h.witnessUtxo&&(C.script=h.witnessUtxo.script);return(h.witnessScript||(0,l.isP2WPKH)(C.script))&&(C.isSegwit=!0),C}function ee(d,h,b){const B=(0,n.checkForInput)(h,d);if(!B.bip32Derivation||B.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const C=B.bip32Derivation.map(D=>{if(D.masterFingerprint.equals(b.fingerprint))return D}).filter(D=>!!D);if(C.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return C.map(D=>{const re=b.derivePath(D.path);if(!D.pubkey.equals(re.publicKey))throw new Error("pubkey did not match bip32Derivation");return re})}function Z(d,h){return o.p2ms({output:d}).pubkeys.map(B=>(h.filter(C=>C.pubkey.equals(B))[0]||{}).signature).filter(B=>!!B)}function ce(d){let h=0;function b(D){return h+=D,d.slice(h-D,h)}function B(){const D=t.decode(d,h);return h+=t.decode.bytes,D}function C(){return b(B())}function j(){const D=B(),re=[];for(let Q=0;Q<D;Q++)re.push(C());return re}return j()}function ge(d){let h=d&u.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(d&31){case u.Transaction.SIGHASH_ALL:h+="SIGHASH_ALL";break;case u.Transaction.SIGHASH_SINGLE:h+="SIGHASH_SINGLE";break;case u.Transaction.SIGHASH_NONE:h+="SIGHASH_NONE";break}return h}function pe(d,h,b){d.__NON_WITNESS_UTXO_BUF_CACHE[b]=h.nonWitnessUtxo;const B=u.Transaction.fromBuffer(h.nonWitnessUtxo);d.__NON_WITNESS_UTXO_TX_CACHE[b]=B;const C=d,j=b;delete h.nonWitnessUtxo,Object.defineProperty(h,"nonWitnessUtxo",{enumerable:!0,get(){const D=C.__NON_WITNESS_UTXO_BUF_CACHE[j],re=C.__NON_WITNESS_UTXO_TX_CACHE[j];if(D!==void 0)return D;{const Q=re.toBuffer();return C.__NON_WITNESS_UTXO_BUF_CACHE[j]=Q,Q}},set(D){C.__NON_WITNESS_UTXO_BUF_CACHE[j]=D}})}function J(d,h,b,B){let C=0;d.forEach((Q,ue)=>{if(B&&Q.finalScriptSig&&(h.ins[ue].script=Q.finalScriptSig),B&&Q.finalScriptWitness&&(h.ins[ue].witness=ce(Q.finalScriptWitness)),Q.witnessUtxo)C+=Q.witnessUtxo.value;else if(Q.nonWitnessUtxo){const le=fe(b,Q,ue),Be=h.ins[ue].index,Oe=le.outs[Be];C+=Oe.value}});const j=h.outs.reduce((Q,ue)=>Q+ue.value,0),D=C-j;if(D<0)throw new Error("Outputs are spending more than Inputs");const re=h.virtualSize();b.__FEE=D,b.__EXTRACTED_TX=h,b.__FEE_RATE=Math.floor(D/re)}function fe(d,h,b){const B=d.__NON_WITNESS_UTXO_TX_CACHE;return B[b]||pe(d,h,b),B[b]}function Se(d,h,b){const{script:B}=Ce(d,h,b);return B}function Ce(d,h,b){if(h.witnessUtxo!==void 0)return{script:h.witnessUtxo.script,value:h.witnessUtxo.value};if(h.nonWitnessUtxo!==void 0){const C=fe(b,h,d).outs[b.__TX.ins[d].index];return{script:C.script,value:C.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function Ze(d,h,b,B){const C=Se(b,h,B),{meaningfulScript:j}=se(C,b,"input",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(d,j)}function st(d,h,b,B){const C=B.__TX.outs[b].script,{meaningfulScript:j}=se(C,b,"output",h.redeemScript,h.witnessScript);return(0,l.pubkeyInScript)(d,j)}function St(d){if(!d)return;const h=a.decompile(d);if(!h)return;const b=h[h.length-1];if(!(!Buffer.isBuffer(b)||et(b)||Ne(b)||!a.decompile(b)))return b}function Ae(d){if(!d)return;const h=ce(d),b=h[h.length-1];if(!(et(b)||!a.decompile(b)))return b}function ln(d){if(d.length===65){const h=d[64]&1,b=d.slice(0,33);return b[0]=2|h,b}return d.slice()}function et(d){return d.length===33&&a.isCanonicalPubKey(d)}function Ne(d){return a.isCanonicalScriptSignature(d)}function se(d,h,b,B,C){const j=(0,l.isP2SHScript)(d),D=j&&B&&(0,l.isP2WSHScript)(B),re=(0,l.isP2WSHScript)(d);if(j&&B===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((re||D)&&C===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let Q;return D?(Q=C,K(h,d,B,b),N(h,B,C,b),te(Q)):re?(Q=C,N(h,d,C,b),te(Q)):j?(Q=B,K(h,d,B,b)):Q=d,{meaningfulScript:Q,type:D?"p2sh-p2wsh":j?"p2sh":re?"p2wsh":"raw"}}function te(d){if((0,l.isP2WPKH)(d)||(0,l.isP2SHScript)(d))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function ne(d){return(0,l.isP2WPKH)(d)?"witnesspubkeyhash":(0,l.isP2PKH)(d)?"pubkeyhash":(0,l.isP2MS)(d)?"multisig":(0,l.isP2PK)(d)?"pubkey":"nonstandard"}function k(d){return[...Array(d).keys()]}return io}var Bp;function Ax(){return Bp||(Bp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=Jl();e.address=t;const n=xr();e.crypto=n;const r=Vn();e.networks=r;const i=cc();e.payments=i;const s=Jt();e.script=s;var o=Q8();Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return o.Block}});var c=xx();Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return c.Psbt}});var a=Dl();Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return a.OPS}});var u=ac();Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return u.Transaction}});var f=Yl();Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(Zu)),Zu}var _i={},Ip;function vx(){if(Ip)return _i;Ip=1,Object.defineProperty(_i,"__esModule",{value:!0}),_i.base26Decode=_i.base26Encode=void 0;function e(n){let r=0n;for(let i=0;i<n.length;i++){const s=BigInt(n.charCodeAt(i)-65),o=BigInt(n.length)-1n-BigInt(i);if(o==0n)r+=s;else{const c=26n**o;r+=c*(s+1n)}}return r}_i.base26Encode=e;function t(n){if(n===340282366920938463463374607431768211455n)return"BCGDENLQRQWDSLRUGSNLBTMFIJAV";n+=1n;let r=[];for(;n>0;){const i=(n-1n)%26n;r.push("ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Number(i))),n=(n-1n)/26n}return r.reverse().join("")}return _i.base26Decode=t,_i}var Si={},Op;function cw(){if(Op)return Si;Op=1,Object.defineProperty(Si,"__esModule",{value:!0}),Si.none=Si.some=void 0;class e{constructor(){}isSome(){return!1}map(s){return new e}value(){return null}}class t{constructor(s){this._value=s}isSome(){return!0}map(s){return new t(s(this.value()))}value(){return this._value}}function n(i){return new t(i)}Si.some=n;function r(){return new e}return Si.none=r,Si}var Ti={},Pp;function Bx(){if(Pp)return Ti;Pp=1,Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.decodeLEB128=Ti.encodeLEB128=void 0;function e(n){const r=[];let i=!0;for(;i;){let s=Number(n&BigInt(127));n>>=BigInt(7),n===BigInt(0)?i=!1:s|=128,r.push(s)}return r}Ti.encodeLEB128=e;function t(n){let r=BigInt(0);for(let i=0;i<n.length;i++){const s=BigInt(n[i]);if(i>18)throw new Error("Overlong");let o=s&BigInt(127);if(i==18&&(o&BigInt(124))!=BigInt(0))throw new Error("Overflow");if(r|=o<<BigInt(7)*BigInt(i),(s&BigInt(128))==BigInt(0))return{n:r,len:i+1}}throw new Error("Unterminated")}return Ti.decodeLEB128=t,Ti}var gf={},kp;function Ix(){return kp||(kp=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.toPushData=e.chunks=e.toHex=e.zero2=void 0;const t=s=>s.length%2===1?"0"+s:s;e.zero2=t;const n=s=>{let o="";for(let c=0;c<s.length;c++)o+=(0,e.zero2)(s[c].toString(16));return o};e.toHex=n;function r(s,o){const c=[];let a=0;for(;a<s.length;){const u=s.slice(a,a+o);c.push(u),a+=o}return c}e.chunks=r;function i(s){const o=[],c=s.length;if(c<76){const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=255){o.push(Buffer.from("4c","hex"));const a=Buffer.alloc(1);a.writeUInt8(c),o.push(a)}else if(c<=65535){o.push(Buffer.from("4d","hex"));const a=Buffer.alloc(2);a.writeUInt16LE(c),o.push(a)}else{o.push(Buffer.from("4e","hex"));const a=Buffer.alloc(4);a.writeUInt32LE(c),o.push(a)}return o.push(s),Buffer.concat(o)}e.toPushData=i})(gf)),gf}var sr={},Np;function aw(){if(Np)return sr;Np=1,Object.defineProperty(sr,"__esModule",{value:!0}),sr.removeSpacers=sr.getSpacersVal=sr.applySpacers=void 0;function e(r,i){let s="";for(let o=0;o<r.length;o++)s+=r.charAt(o),i>0&&((i&1)===1&&(s+="•"),i>>=1);return s}sr.applySpacers=e;function t(r){let i=0,s=0;for(let o=0;o<r.length;o++)r.charAt(o)==="•"&&(i+=1<<o-1-s,s++);return i}sr.getSpacersVal=t;function n(r){return r.replace(/[•]+/g,"")}return sr.removeSpacers=n,sr}var Up;function Ox(){if(Up)return je;Up=1,Object.defineProperty(je,"__esModule",{value:!0}),je.EtchInscription=je.Message=je.Runestone=je.Etching=je.Rune=je.Terms=je.Range=je.Flaw=je.Tag=je.Flag=je.Edict=je.RuneId=void 0;const e=Ax(),t=vx(),n=cw(),r=Bx(),i=Ix(),s=aw();class o{constructor(m,T){this.block=m,this.idx=T}next(m,T){if(m>BigInt(Number.MAX_SAFE_INTEGER)||T>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let I=BigInt(this.block)+m;if(I>BigInt(Number.MAX_SAFE_INTEGER))return(0,n.none)();let A=m===0n?BigInt(this.idx)+T:T;return A>BigInt(Number.MAX_SAFE_INTEGER)?(0,n.none)():(0,n.some)(new o(Number(I),Number(A)))}}je.RuneId=o;class c{constructor(m,T,I){this.id=m,this.amount=T,this.output=I}static from_integers(m,T,I,A){return A>4294967295n||A<0n||Number(A)>m.outs.length?(0,n.none)():(0,n.some)(new c(T,I,Number(A)))}}je.Edict=c;var a;(function(S){S[S.Etching=0]="Etching",S[S.Terms=1]="Terms",S[S.Turbo=2]="Turbo",S[S.Cenotaph=127]="Cenotaph"})(a||(je.Flag=a={}));var u;(function(S){S[S.Body=0]="Body",S[S.Flags=2]="Flags",S[S.Rune=4]="Rune",S[S.Premine=6]="Premine",S[S.Cap=8]="Cap",S[S.Amount=10]="Amount",S[S.HeightStart=12]="HeightStart",S[S.HeightEnd=14]="HeightEnd",S[S.OffsetStart=16]="OffsetStart",S[S.OffsetEnd=18]="OffsetEnd",S[S.Mint=20]="Mint",S[S.Pointer=22]="Pointer",S[S.Cenotaph=126]="Cenotaph",S[S.Divisibility=1]="Divisibility",S[S.Spacers=3]="Spacers",S[S.Symbol=5]="Symbol",S[S.Nop=127]="Nop"})(u||(je.Tag=u={}));var f;(function(S){S[S.EdictOutput=0]="EdictOutput",S[S.EdictRuneId=1]="EdictRuneId",S[S.InvalidScript=2]="InvalidScript",S[S.Opcode=3]="Opcode",S[S.SupplyOverflow=4]="SupplyOverflow",S[S.TrailingIntegers=5]="TrailingIntegers",S[S.TruncatedField=6]="TruncatedField",S[S.UnrecognizedEvenTag=7]="UnrecognizedEvenTag",S[S.UnrecognizedFlag=8]="UnrecognizedFlag",S[S.Varint=9]="Varint"})(f||(je.Flaw=f={}));class l{constructor(m,T){this.start=m,this.end=T}}je.Range=l;class p{constructor(m,T,I,A){this.amount=m,this.cap=T,this.height=I,this.offset=A}}je.Terms=p;class y{constructor(m){this.value=m}get name(){return y.toName(this.value)}static toName(m){return(0,t.base26Decode)(m)}static fromName(m){return new y((0,t.base26Encode)((0,s.removeSpacers)(m)))}toString(){return this.name}}je.Rune=y;class g{constructor(m,T,I,A,U,M,v){this.divisibility=m,this.premine=T,this.rune=I,this.spacers=A,this.symbol=U,this.terms=M,this.turbo=v}}je.Etching=g,g.MAX_DIVISIBILITY=38,g.MAX_SPACERS=134217727;class w{constructor(m=[],T,I,A){this.edicts=m,this.etching=T,this.mint=I,this.pointer=A}static create(m,T="etch"){if(T==="etch"){m=m;const I=y.fromName(m.name),A=new p(m.amount,m.cap,new l(m.startHeight?(0,n.some)(m.startHeight):(0,n.none)(),m.endHeight?(0,n.some)(m.endHeight):(0,n.none)()),new l(m.startOffset?(0,n.some)(m.startOffset):(0,n.none)(),m.endOffset?(0,n.some)(m.endOffset):(0,n.none)())),U=m.divisibility?(0,n.some)(m.divisibility):(0,n.none)(),M=m.premine?(0,n.some)(m.premine):(0,n.none)(),v=m.name.indexOf("•")>-1?(0,n.some)((0,s.getSpacersVal)(m.name)):(0,n.none)(),R=m.symbol?(0,n.some)(m.symbol):(0,n.none)(),V=typeof m.pointer=="number"?(0,n.some)(m.pointer):(0,n.none)(),W=new g(U,M,(0,n.some)(I),v,R,(0,n.some)(A),!0);return new w([],(0,n.some)(W),(0,n.none)(),V)}else if(T==="mint"){m=m;const I=typeof m.pointer=="number"?(0,n.some)(m.pointer):(0,n.none)();return new w([],(0,n.none)(),(0,n.some)(new o(m.block,m.txIdx)),I)}else throw new Error(`not ${T} support now`)}static decipher(m){const T=e.Transaction.fromHex(m),I=w.payload(T);if(I.isSome()){const A=w.integers(I.value()),U=E.from_integers(T,A.value()),M=U.getEtching(),v=U.getMint(),R=U.getPointer();return(0,n.some)(new w(U.edicts,M,v,R))}return(0,n.none)()}encipher(){const T=this.toMessage().toBuffer(),I=Buffer.from("6a5d","hex");let A;if(T.length<76)A=Buffer.alloc(1),A.writeUInt8(T.length);else if(T.length<256)A=Buffer.alloc(2),A.writeUInt8(76),A.writeUInt8(T.length);else if(T.length<65536)A=Buffer.alloc(3),A.writeUInt8(77),A.writeUInt16LE(T.length);else if(T.length<4294967296)A=Buffer.alloc(5),A.writeUInt8(78),A.writeUInt32LE(T.length);else throw new Error("runestone too big!");return Buffer.concat([I,A,T])}static payload(m){for(const T of m.outs){const I=e.script.decompile(T.script);if(I[0]===e.script.OPS.OP_RETURN&&I[1]===w.MAGIC_NUMBER){for(let A=2;A<I.length;A++){const U=I[A];return U instanceof Uint8Array?(0,n.some)(Array.from(U)):(0,n.none)()}return(0,n.none)()}}return(0,n.none)()}static integers(m){let T=[],I=0;for(;I<m.length;){let{n:A,len:U}=(0,r.decodeLEB128)(m.slice(I));T.push(A),I+=U}return(0,n.some)(T)}toMessage(){let m=new Map;const T=this.etching.value();if(T){let U=1;if(T.terms.isSome()){let K=1<<a.Terms;U|=K}if(T.turbo){let K=1<<a.Turbo;U|=K}m.set(u.Flags,[BigInt(U)]);const M=T.rune.value();M!==null&&m.set(u.Rune,[BigInt(M.value)]);const v=T.divisibility.value();v!==null&&m.set(u.Divisibility,[BigInt(v)]);const R=T.spacers.value();R!==null&&m.set(u.Spacers,[BigInt(R)]);const V=T.symbol.value();V!==null&&m.set(u.Symbol,[BigInt(V.charCodeAt(0))]);const W=T.premine.value();W!==null&&m.set(u.Premine,[BigInt(W)]);const H=T.terms.value();if(H!==null){m.set(u.Amount,[BigInt(H.amount)]),m.set(u.Cap,[BigInt(H.cap)]);const K=H.height.start.value();K&&m.set(u.HeightStart,[BigInt(K)]);const N=H.height.end.value();N&&m.set(u.HeightEnd,[BigInt(N)]);const L=H.offset.start.value();L&&m.set(u.OffsetStart,[BigInt(L)]);const F=H.offset.end.value();F&&m.set(u.OffsetEnd,[BigInt(F)])}}const I=this.mint.value();I!==null&&m.set(u.Mint,[BigInt(I.block),BigInt(I.idx)]);const A=this.pointer.value();return A!==null&&m.set(u.Pointer,[BigInt(A)]),new E(m,this.edicts,0)}}je.Runestone=w,w.MAGIC_NUMBER=93;class E{constructor(m=new Map,T=[],I=0){this.fields=m,this.edicts=T,this.flaws=I}static from_integers(m,T){let I=new Map,A=[],U=0,M=!1;for(let v=0;v<T.length;){let R=T[v];if(Number(R)===u.Body){M=!0,v+=1;continue}if(M){let V=new o(0,0);for(const W of(0,i.chunks)(T.slice(v),4)){if(W.length!=4){U|=f.TrailingIntegers;break}let H=V.next(W[0],W[1]);if(!H.isSome()){U|=f.EdictRuneId;break}const K=c.from_integers(m,H.value(),W[2],W[3]);if(!K.isSome()){U|=f.EdictOutput;break}V=H.value(),A.push(K.value())}v+=4}else{let V=T[v+1];const W=I.get(Number(R))||[];W.push(V),I.set(Number(R),W),v+=2}}return new E(I,A,U)}addFieldVal(m,T){const I=this.fields.get(Number(m))||[];I.push(T),this.fields.set(Number(m),I)}addEdict(m){this.edicts.push(m)}toBuffer(){const m=[];for(const[T,I]of this.fields)for(const A of I){const U=Buffer.alloc(1);U.writeUInt8(T),m.push(U),m.push(Buffer.from((0,r.encodeLEB128)(A)))}if(this.edicts.length>0){m.push(Buffer.from("00","hex")),this.edicts.sort((A,U)=>A.id.block==U.id.block?A.id.idx-U.id.idx:A.id.block-U.id.block);let T=0n,I=0n;for(let A=0;A<this.edicts.length;A++){const U=this.edicts[A];if(A==0)T=BigInt(U.id.block),I=BigInt(U.id.idx),m.push(Buffer.from((0,r.encodeLEB128)(T))),m.push(Buffer.from((0,r.encodeLEB128)(I)));else{const M=BigInt(U.id.block),v=BigInt(U.id.idx);if(M==T){const R=v-I;I=v,m.push(Buffer.from((0,r.encodeLEB128)(0n))),m.push(Buffer.from((0,r.encodeLEB128)(R)))}else{const R=M-T;T=M,I=v,m.push(Buffer.from((0,r.encodeLEB128)(R))),m.push(Buffer.from((0,r.encodeLEB128)(v)))}}m.push(Buffer.from((0,r.encodeLEB128)(BigInt(U.amount)))),m.push(Buffer.from((0,r.encodeLEB128)(BigInt(U.output))))}}return Buffer.concat(m)}getFlags(){return Number(this.fields.get(u.Flags))}hasFlags(m){const T=this.getFlags(),I=1<<m;return(T&I)!=0}getMint(){if(!this.fields.has(u.Mint))return(0,n.none)();const[m,T]=this.fields.get(u.Mint);return(0,n.some)(new o(Number(m),Number(T)))}getEtching(){if(!this.hasFlags(a.Etching))return(0,n.none)();const m=this.getDivisibility(),T=this.getPremine(),I=this.getRune(),A=this.getSpacers(),U=this.getSymbol(),M=this.getTerms(),v=this.hasFlags(a.Turbo);return(0,n.some)(new g(m,T,I,A,U,M,v))}getDivisibility(){if(!this.fields.has(u.Divisibility))return(0,n.none)();const[m]=this.fields.get(u.Divisibility);if(m>g.MAX_DIVISIBILITY)throw new Error("invalid divisibility");return(0,n.some)(Number(m))}getPremine(){if(!this.fields.has(u.Premine))return(0,n.none)();const[m]=this.fields.get(u.Premine);return(0,n.some)(Number(m))}getRune(){if(!this.fields.has(u.Rune))return(0,n.none)();const[m]=this.fields.get(u.Rune);return(0,n.some)(new y(m))}getSpacers(){if(!this.fields.has(u.Spacers))return(0,n.none)();const[m]=this.fields.get(u.Spacers);if(m>g.MAX_SPACERS)throw new Error("invalid spacers");return(0,n.some)(Number(m))}getHeightStart(){if(!this.fields.has(u.HeightStart))return(0,n.none)();const[m]=this.fields.get(u.HeightStart);return(0,n.some)(Number(m))}getHeightEnd(){if(!this.fields.has(u.HeightEnd))return(0,n.none)();const[m]=this.fields.get(u.HeightEnd);return(0,n.some)(Number(m))}getOffsetStart(){if(!this.fields.has(u.OffsetStart))return(0,n.none)();const[m]=this.fields.get(u.OffsetStart);return(0,n.some)(Number(m))}getOffsetEnd(){if(!this.fields.has(u.OffsetEnd))return(0,n.none)();const[m]=this.fields.get(u.OffsetEnd);return(0,n.some)(Number(m))}getCap(){if(!this.fields.has(u.Cap))return(0,n.none)();const[m]=this.fields.get(u.Cap);return(0,n.some)(Number(m))}getAmount(){if(!this.fields.has(u.Amount))return(0,n.none)();const[m]=this.fields.get(u.Amount);return(0,n.some)(Number(m))}getSymbol(){if(!this.fields.has(u.Symbol))return(0,n.none)();const[m]=this.fields.get(u.Symbol);return(0,n.some)(String.fromCharCode(Number(m)))}getTerms(){if(!this.hasFlags(a.Terms))return(0,n.none)();const m=this.getCap();if(!m.isSome())throw new Error("no cap field");const T=this.getAmount();if(!T.isSome())throw new Error("no amount field");const I=this.getHeightStart(),A=this.getHeightEnd(),U=this.getOffsetStart(),M=this.getOffsetEnd(),v=new l(I,A),R=new l(U,M);return(0,n.some)(new p(T.value(),m.value(),v,R))}getPointer(){if(!this.fields.has(u.Pointer))return(0,n.none)();const[m]=this.fields.get(u.Pointer);return(0,n.some)(Number(m))}}je.Message=E;class _{constructor(m=new Map,T=Buffer.alloc(0)){this.fields=m,this.data=T}setContent(m,T){this.fields.set(1,Buffer.from(m,"utf8")),this.data=T}setRune(m){let I=(0,t.base26Encode)((0,s.removeSpacers)(m)).toString(16);I.length%2===1&&(I="0"+I),this.setField(_.Tag.RUNE,Buffer.from(I,"hex").reverse())}setField(m,T){this.fields.set(m,T)}static decipher(m,T){const U=e.Transaction.fromHex(m).ins[T].witness[1],M=e.script.decompile(U),v=new Map,R=[];let V=!1;for(let W=5;W<M.length-1;){const H=M[W];if(H===0){V=!0,W++;continue}else if(V)R.push(H),W++;else{const K=H-80,N=M[W+1];if(typeof N=="number"){const L=Buffer.alloc(1);L.writeUInt8(N),v.set(K,L)}else v.set(K,N);W+=2}}return new _(v,Buffer.concat(R))}encipher(){const m=[];if(this.data&&this.data.length>0){m.push(Buffer.from("0063036f7264","hex")),Array.from(this.fields.entries()).sort((I,A)=>I[0]-A[0]).forEach(([I,A])=>{const U=Buffer.alloc(1);U.writeUInt8(I),m.push(Buffer.from("01","hex")),m.push(U),A.length!=1||A[0]!=0?m.push((0,i.toPushData)(A)):m.push(A)}),m.push(Buffer.from("00","hex"));const T=(0,i.chunks)(Array.from(this.data),520);for(const I of T)m.push((0,i.toPushData)(Buffer.from(I)))}else{m.push(Buffer.from("0063","hex"));const T=this.fields.get(_.Tag.RUNE);if(!T)throw new Error("No rune found!");m.push((0,i.toPushData)(T))}return m.push(Buffer.from("68","hex")),Buffer.concat(m)}}return je.EtchInscription=_,_.Tag={CONTENT_TYPE:1,POINTER:2,PARENT:3,METADATA:5,METAPROTOCOL:7,CONTENT_ENCODING:9,DELEGATE:11,RUNE:13},je}var Rp;function Px(){return Rp||(Rp=1,(function(e){var t=di&&di.__createBinding||(Object.create?(function(s,o,c,a){a===void 0&&(a=c);var u=Object.getOwnPropertyDescriptor(o,c);(!u||("get"in u?!o.__esModule:u.writable||u.configurable))&&(u={enumerable:!0,get:function(){return o[c]}}),Object.defineProperty(s,a,u)}):(function(s,o,c,a){a===void 0&&(a=c),s[a]=o[c]})),n=di&&di.__exportStar||function(s,o){for(var c in s)c!=="default"&&!Object.prototype.hasOwnProperty.call(o,c)&&t(o,s,c)};Object.defineProperty(e,"__esModule",{value:!0}),e.removeSpacers=e.getSpacersVal=e.applySpacers=e.some=e.none=void 0,n(Ox(),e);var r=cw();Object.defineProperty(e,"none",{enumerable:!0,get:function(){return r.none}}),Object.defineProperty(e,"some",{enumerable:!0,get:function(){return r.some}});var i=aw();Object.defineProperty(e,"applySpacers",{enumerable:!0,get:function(){return i.applySpacers}}),Object.defineProperty(e,"getSpacersVal",{enumerable:!0,get:function(){return i.getSpacersVal}}),Object.defineProperty(e,"removeSpacers",{enumerable:!0,get:function(){return i.removeSpacers}})})(di)),di}var rs=Px();function xi(e){if(e.length%2!==0)throw new Error("Hex string must have even length");const t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function Ea(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function _a(e){return e===Zo.Mainnet?vn:Gp}function Sa(e,t=Zo.Testnet){const n=_a(t);return Ry(e,n)}function Zr(e){const t=vn,n=Gp,r=qw;let i,s,o=Dt.UNKNOWN;if(e.startsWith("bc1")||e.startsWith("tb1")||e.startsWith("bcrt1"))try{return s=sl(e),s.version===0?s.data.length===20?o=Dt.P2WPKH:o=Dt.P2WSH:o=Dt.P2TR,o}catch{return Dt.UNKNOWN}else try{return i=Uy(e),i.version===t.pubKeyHash||i.version===n.pubKeyHash||i.version===r.pubKeyHash?o=Dt.P2PKH:(i.version===t.scriptHash||(i.version,n.scriptHash),o=Dt.P2SH_P2WPKH),o}catch{return Dt.UNKNOWN}}function kx(e,t,n){const r=Sa(e,n),i=t.coins?.[0];return{txid:t.txid,vout:t.vout,satoshis:t.sats.toString(),height:void 0,runes:i?[{id:i.id,amount:i.value.toString()}]:[],address:e,scriptPk:Ea(r)}}async function uw(e,t){try{const n=t===Zo.Mainnet?"https://mpc.omnity.network/utxo-status":"https://mpc.omnity.network/testnet4/utxo-status",r=await at.post(n,e).then(c=>c.data);if(!r)return null;const i=JSON.stringify(r),o=new TextEncoder().encode(i);return Array.from(o)}catch{return null}}const Nx=Object.freeze(Object.defineProperty({__proto__:null,bytesToHex:Ea,formatPoolUtxo:kx,getAddressType:Zr,getScriptByAddress:Sa,getUtxoProof:uw,hexToBytes:xi,toBitcoinNetwork:_a},Symbol.toStringTag,{value:"Module"})),Ux="kqs64-paaaa-aaaar-qamza-cai",Rx="hvyp5-5yaaa-aaaao-qjxha-cai",Wr=BigInt(546),vt="0:0",Cp={P2PKH:148,P2SH_P2WPKH:91,P2WPKH:68,P2WSH:140,P2SH:108,P2TR:58,UNKNOWN:110},Hp={P2PKH:34,P2SH_P2WPKH:32,P2WPKH:31,P2WSH:43,P2SH:32,P2TR:43,UNKNOWN:34},Cx=new Set(["P2WPKH","P2WSH","P2SH_P2WPKH","P2TR"]),Hx=2;function Fp(e){return"P2SH_P2WPKH"in e?{P2SH:null}:"P2PKH"in e?{P2WPKH:null}:"P2WSH"in e?{P2WPKH:null}:"UNKNOWN"in e?{P2WPKH:null}:e}class Jr{psbt;client;inputAddressTypes=[];outputAddressTypes=[];config;userInputUtxoDusts=BigInt(0);intentions=[];txFee=BigInt(0);additionalDustNeeded=BigInt(0);inputUtxos=[];constructor(t,n){this.config=t,this.psbt=new ea({network:_a(t.network)}),this.client=n}addInput(t){if(this.inputUtxos.findIndex(i=>i.txid===t.txid&&i.vout===t.vout)>=0)return;const{address:n}=t,r=Zr(n);if(r===Dt.P2TR){let i=t.pubkey;i||t.address===this.config.address&&this.config.publicKey&&(i=this.config.publicKey);const s=i?i.length===66?i.slice(2):i:void 0;s?this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:xi(t.scriptPk)},tapInternalKey:xi(s)}):this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:xi(t.scriptPk)}})}else if("P2SH_P2WPKH"in r||"P2SH"in r){let i=t.pubkey;!i&&n===this.config.paymentAddress&&(i=this.config.paymentPublicKey),!i&&n===this.config.address&&(i=this.config.publicKey);const s={hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:xi(t.scriptPk)}};if(i){const o=xi(i),c=Xo({pubkey:o,network:_a(this.config.network)});c.output&&(s.redeemScript=c.output)}this.psbt.data.addInput(s)}else this.psbt.data.addInput({hash:t.txid,index:t.vout,witnessUtxo:{value:BigInt(t.satoshis),script:xi(t.scriptPk)}});this.inputAddressTypes.push(Zr(n)),this.inputUtxos.push(t),(n===this.config.address||n===this.config.paymentAddress)&&t.runes.length!==0&&(this.userInputUtxoDusts+=BigInt(t.satoshis))}addOutput(t,n){this.psbt.addOutput({address:t,value:n}),this.outputAddressTypes.push(Zr(t))}addScriptOutput(t){this.psbt.addOutput({script:t,value:BigInt(0)}),this.outputAddressTypes.push({OpReturn:BigInt(t.length)})}selectRuneUtxos(t,n,r){const i=[];if(r==BigInt(0))return i;for(const s of t)if(s.runes.length){const o=s.runes.find(c=>c.id==n);if(o&&BigInt(o.amount)==r){i.push(s);break}}if(i.length==0){let s=BigInt(0);for(const o of t)if(o.runes.forEach(c=>{c.id==n&&(s=s+BigInt(c.amount))}),i.push(o),s>=r)break;if(s<r)throw new Error("INSUFFICIENT_RUNE_UTXOs")}return i}selectBtcUtxos(t,n,r=!1){const i=[];if(n<=BigInt(0))return i;let s=BigInt(0);for(const o of t)if(!(o.runes.length&&!r)&&(s+=BigInt(o.satoshis),i.push(o),s>=n))break;if(s<n)throw new Error(`Insufficient BTC UTXOs: need ${n}, have ${s}`);return i}async addBtcAndFees(t,n){const r=this.config.paymentAddress,i=this.additionalDustNeeded,s=Zr(r),o=this.userInputUtxoDusts,c=this.config.feeRate;let a=BigInt(0),u=BigInt(0);if(this.config.manualBuild){a=this.inputUtxos.reduce((m,T)=>m+BigInt(T.satoshis),BigInt(0));for(const m of this.psbt.txOutputs)u+=BigInt(m.value)}this.outputAddressTypes.push(s);let f=!0,l=BigInt(0),p=BigInt(0),y=[],g=BigInt(0),w=BigInt(0);const E=[...this.inputAddressTypes];do{if(l=p,c!==void 0){const m=Jr.estimateTxVirtualSize(this.inputAddressTypes,this.outputAddressTypes);p=BigInt(Math.round(c*m))}else p=(await this.client.orchestrator.estimate_min_tx_fee({input_types:this.inputAddressTypes.map(Fp),pool_address:this.intentions.map(T=>T.poolAddress),output_types:this.outputAddressTypes.map(Fp)}).catch(T=>{throw console.error("estimate_min_tx_fee failed:",T),T})).Ok;if(this.config.manualBuild?g=u+p+i-a:g=n+p+i-o,p>l&&g>0){const m=this.selectBtcUtxos(t,g);if(m.length===0)throw new Error(`INSUFFICIENT_BTC_UTXOs: need ${g} more sats (inputs=${a}, outputs=${u}, fee=${p}, dust=${i})`);this.inputAddressTypes=E.concat(m.map(()=>s));const T=m.reduce((I,A)=>I+BigInt(A.satoshis),BigInt(0));T-g>0&&T-g>Wr||(this.outputAddressTypes.pop(),f=!1),y=m}}while(p>l&&g>0);this.inputAddressTypes=[...E],f&&this.outputAddressTypes.pop();let _=BigInt(0);y.forEach(m=>{this.addInput(m),_+=BigInt(m.satoshis)});let S;if(this.config.manualBuild?S=a+_-u-p-i:S=_-g,S<0)throw new Error(`Insufficient UTXO(s): shortage=${-S} sats (inputs=${this.config.manualBuild?a+_:_}, outputs=${this.config.manualBuild?u:n}, fee=${p}, dust=${i})`);S>Wr?this.addOutput(r,S):S>BigInt(0)&&(w=S),this.txFee=w+p}async getInvolvedAddressUtxos(){const t={},n={},r=new Map;r.set(this.config.paymentAddress,{needBtc:!0,runeIds:new Set});const i=s=>{const o=s.trim();return r.has(o)||r.set(o,{needBtc:!1,runeIds:new Set}),r.get(o)};for(const s of this.intentions){for(const a of s.inputCoins){const u=i(a.from);a.coin.id===vt?u.needBtc=!0:u.runeIds.add(a.coin.id)}for(const a of s.outputCoins){const u=i(a.to);a.coin.id===vt?u.needBtc=!0:u.runeIds.add(a.coin.id)}const o=i(s.poolAddress),c=[...s.inputCoins.map(a=>a.coin.id),...s.outputCoins.map(a=>a.coin.id)];for(const a of c)a===vt?o.needBtc=!0:o.runeIds.add(a)}return await Promise.all(Array.from(r.entries()).map(async([s,o])=>{if(o.needBtc)try{t[s]=await this.client.getBtcUtxos(s),console.log(`[REE-SDK] getBtcUtxos for ${s}: ${t[s].length} utxos, total=${t[s].reduce((c,a)=>c+BigInt(a.satoshis),BigInt(0))} sats`)}catch(c){console.warn(`[REE-SDK] getBtcUtxos FAILED for ${s}:`,c),t[s]=[]}o.runeIds.size>0&&(n[s]={},await Promise.all(Array.from(o.runeIds).map(async c=>{try{n[s][c]=await this.client.getRuneUtxos(s,c),console.log(`[REE-SDK] getRuneUtxos for ${s}, runeId=${c}: ${n[s][c].length} utxos`)}catch(a){console.warn(`[REE-SDK] getRuneUtxos FAILED for ${s}, runeId=${c}:`,a),n[s][c]=[]}})))})),{btc:t,rune:n}}addInputsAndCalculateOutputs(t){if(!this.intentions.length)throw new Error("No intentions added");const n=this.intentions.map(a=>a.poolAddress),r={},i={};let s=BigInt(0);const o=new Map,c=new Set;this.intentions.forEach(({poolAddress:a,inputCoins:u,outputCoins:f,poolUtxos:l})=>{const p=[...u.filter(({from:g})=>!n.includes(g))],y=[...f];if(p.forEach(({coin:g,from:w})=>{!f.find(E=>E.coin.id===g.id)&&!(n.includes(w)&&w!==a)&&y.push({coin:g,to:a})}),y.forEach(({coin:g})=>{u.find(w=>w.coin.id===g.id)||p.push({coin:g,from:a})}),p.length===0&&y.length===0&&l?.length){const g=o.get(a);o.set(a,g?g.concat(l):[...l]),c.add(a);return}p.forEach(({coin:g,from:w})=>{r[w]??={},r[w][g.id]=(r[w][g.id]??BigInt(0))+BigInt(g.value)}),y.forEach(({coin:g,to:w})=>{i[w]??={},i[w][g.id]=(i[w][g.id]??BigInt(0))+BigInt(g.value)})});for(const[a,u]of o.entries()){if(!u.length)continue;i[a]??={};const f=i[a];u.forEach(l=>{this.addInput(l),f[vt]=(f[vt]??BigInt(0))+BigInt(l.satoshis),l.runes.forEach(p=>{f[p.id]=(f[p.id]??BigInt(0))+BigInt(p.amount)})})}for(const[a,u]of Object.entries(r))for(const[f,l]of Object.entries(u))if(f===vt){if(a===this.config.paymentAddress){s+=l;continue}const p=t.btc[a]||[],y=this.selectBtcUtxos(p,l,n.includes(a)),w=y.reduce((E,_)=>E+BigInt(_.satoshis),BigInt(0))-l;w>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+w),y.forEach(E=>{this.addInput(E),n.includes(a)&&E.runes.forEach(_=>{(r[a]?.[_.id]??BigInt(0))>BigInt(0)||(i[a]??={},i[a][_.id]=(i[a][_.id]??BigInt(0))+BigInt(_.amount))})})}else{const p=t.rune[a]?.[f]||[];console.log(`[REE-SDK] selectRuneUtxos: address=${a}, coinId=${f}, requiredAmount=${l}, runeUtxos=${p.length}`,p.map(_=>({txid:_.txid,vout:_.vout,runes:_.runes})));const y=this.selectRuneUtxos(p,f,l),g=y.reduce((_,S)=>{const m=S.runes.find(T=>T.id===f);return _+BigInt(m?.amount??0)},BigInt(0)),w=y.reduce((_,S)=>_+BigInt(S.satoshis),BigInt(0)),E=g-l;if(n.includes(a)){i[a]??={};const _=i[a],S=(r[a]?.[vt]??BigInt(0))>BigInt(0);w>BigInt(0)&&!S&&(_[vt]=(_[vt]??BigInt(0))+w),E>BigInt(0)&&(_[f]=(_[f]??BigInt(0))+E)}else E>BigInt(0)&&(i[a]??={},i[a][f]=(i[a][f]??BigInt(0))+E);y.forEach(_=>this.addInput(_))}for(const[a,u]of Object.entries(i)){if(r[a]||!n.includes(a)||c.has(a))continue;const f=new Set;if(u[vt]!==void 0){const l=t.btc[a]||[],p=l.reduce((y,g)=>y+BigInt(g.satoshis),BigInt(0));i[a]??={},i[a][vt]=(i[a][vt]??BigInt(0))+p,l.forEach(y=>{this.addInput(y),f.add(`${y.txid}:${y.vout}`),y.runes.forEach(g=>{i[a]??={},i[a][g.id]=(i[a][g.id]??BigInt(0))+BigInt(g.amount)})})}for(const[l]of Object.entries(u)){if(l===vt)continue;const y=(t.rune[a]?.[l]||[]).filter(w=>!f.has(`${w.txid}:${w.vout}`)),g=y.reduce((w,E)=>{const _=E.runes.find(S=>S.id===l);return w+BigInt(_?.amount??0)},BigInt(0));i[a]??={},i[a][l]=(i[a][l]??BigInt(0))+g,y.forEach(w=>{this.addInput(w),f.add(`${w.txid}:${w.vout}`)})}}return{addressOutputCoinAmounts:i,paymentBtcRequired:s}}addOutputs(t){const n=this.config.mergeSelfRuneBtcOutputs===!0,r=new Set;for(const[,s]of Object.entries(t))for(const o of Object.keys(s))o!==vt&&r.add(o);const i=Array.from(r);if(i.length>0){const s=[],o=[];let c=1;i.forEach(u=>{const f=new rs.RuneId(Number(u.split(":")[0]),Number(u.split(":")[1]));for(const[l,p]of Object.entries(t)){const y=p[u]??BigInt(0);y>BigInt(0)&&(s.push(new rs.Edict(f,y,c)),o.push(l),c++)}});const a=new rs.Runestone(s,rs.none(),rs.none(),rs.none());this.addScriptOutput(new Uint8Array(a.encipher())),o.forEach(u=>{const f=t[u]?.[vt]??BigInt(0),l=u===this.config.address,p=f>BigInt(0)&&(!l||n),y=p&&f>Wr?f:Wr;this.addOutput(u,y),p?(f<Wr&&(this.additionalDustNeeded+=Wr-f),delete t[u][vt]):this.additionalDustNeeded+=Wr})}for(const[s,o]of Object.entries(t)){const c=o[vt]??BigInt(0);c>BigInt(0)&&this.addOutput(s,c)}}addIntention(t){this.intentions.push(t)}async build(){console.log(`[REE-SDK] build() — address=${this.config.address}, paymentAddress=${this.config.paymentAddress}, publicKey=${this.config.publicKey}, paymentPublicKey=${this.config.paymentPublicKey}`);const t=await this.getInvolvedAddressUtxos(),n=this.config.paymentAddress;let r=t.btc[n]??[];if(console.log(`[REE-SDK] build() — userBtcUtxos from paymentAddress: ${r.length} utxos`),this.config.manualBuild)await this.addBtcAndFees(r,BigInt(0));else{for(const f of this.intentions){const l=f.poolUtxos;if(!l)continue;t.btc[f.poolAddress]=l,t.rune[f.poolAddress]={};const p=t.rune[f.poolAddress];for(const y of l)for(const g of y.runes)(p[g.id]??=[]).push(y)}const{addressOutputCoinAmounts:a,paymentBtcRequired:u}=this.addInputsAndCalculateOutputs(t);this.addOutputs(a),await this.addBtcAndFees(r,u)}const s=this.psbt.__CACHE.__TX.clone(),o=[];for(let a=0;a<this.inputUtxos.length;a++){const u=this.inputUtxos[a],f=u.address;if(f!==this.config.paymentAddress&&f!==this.config.address)continue;const l=this.psbt.data.inputs[a]?.redeemScript,p=Zr(f);let y=u.pubkey;if(!y&&f===this.config.paymentAddress&&(y=this.config.paymentPublicKey),!y&&f===this.config.address&&(y=this.config.publicKey),o.push({index:a,...p===Dt.P2TR?{address:f,disableTweakSigner:!1}:{publicKey:y,disableTweakSigner:!0}}),l&&p===Dt.P2SH_P2WPKH){const g=Zt([l]);s.setInputScript(a,g)}}const c=s.getId();return{psbt:this.psbt,txid:c,fee:this.txFee,toSignInputs:o}}static estimateTxVirtualSize(t,n){const r=t.length,i=n.length;let s=8+Jr.varIntSize(r)+Jr.varIntSize(i),o=!1;for(const c of t){const a=Jr.parseAddressType(c);if(a.key==="OpReturn")continue;const u=Cp[a.key]??Cp.UNKNOWN;s+=u,Cx.has(a.key)&&(o=!0)}for(const c of n){const a=Jr.parseAddressType(c);if(a.key==="OpReturn"){const f=Math.max(0,a.opReturnLength??0);s+=11+f;continue}const u=Hp[a.key]??Hp.UNKNOWN;s+=u}return o&&(s+=1),s+Hx}static parseAddressType(t){if("OpReturn"in t){const r=t.OpReturn!==void 0?Number(t.OpReturn):0;return{key:"OpReturn",opReturnLength:Number.isFinite(r)?r:0}}const n=["P2PKH","P2SH_P2WPKH","P2WPKH","P2WSH","P2SH","P2TR"];for(const r of n)if(r in t)return{key:r};return{key:"UNKNOWN"}}static varIntSize(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}async getToSpendUtxos(){return this.inputUtxos.filter(t=>t.address===this.config.paymentAddress||t.address===this.config.address)}async getUtxoProof(){const t=await this.getToSpendUtxos(),n=await uw(t,this.config.network);if(!n)throw new Error("Failed to get utxo proof");return n}async getInvokeArgs(t){const n=await this.getUtxoProof();return{intention_set:{tx_fee_in_sats:Number(this.txFee),initiator_address:this.config.paymentAddress,intentions:this.intentions.map(({action:r,actionParams:i,poolAddress:s,inputCoins:o,outputCoins:c,exchangeId:a,nonce:u})=>({exchange_id:a??this.config.exchangeId,input_coins:o.filter(f=>f.from!==s),output_coins:c,pool_address:s,action:r,action_params:i??"",pool_utxo_spent:[],pool_utxo_received:[],nonce:Number(u)}))},initiator_utxo_proof:n,psbt_hex:t,client_info:[this.config.clientInfo??""]}}async send(t){if(!this.intentions.length)throw new Error("No itentions added");const n=await this.getInvokeArgs(t);return this.client.orchestrator.invoke(n).then(r=>{if(r?.Ok)return r.Ok;{const i=r?.Err??{},s=Object.keys(i)[0],o=i[s];throw new Error(o?s==="ErrorOccurredDuringExecution"?`${s}: ${o.execution_steps?.[0]?.result?.Err??"Unknown Error"}`:`Invoke Error: ${JSON.stringify(r)}`:`Invoke Error: ${JSON.stringify(r)}`)}})}}/*!
|
|
77
77
|
* decimal.js v10.6.0
|
|
78
78
|
* An arbitrary-precision Decimal type for JavaScript.
|
|
79
79
|
* https://github.com/MikeMcl/decimal.js
|
|
80
80
|
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
81
81
|
* MIT Licence
|
|
82
|
-
*/var as=9e15,fi=1e9,Gf="0123456789abcdef",_a="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Sa="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Df={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-as,maxE:as,crypto:!1},fw,gr,Te=!0,su="[DecimalError] ",oi=su+"Invalid argument: ",lw=su+"Precision limit exceeded",hw=su+"crypto unavailable",dw="[object Decimal]",Kt=Math.floor,bt=Math.pow,Fx=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Mx=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,qx=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,pw=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Fn=1e7,be=7,Vx=9007199254740991,$x=_a.length-1,Xf=Sa.length-1,ie={toStringTag:dw};ie.absoluteValue=ie.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),we(e)};ie.ceil=function(){return we(new this.constructor(this),this.e+1,2)};ie.clampedTo=ie.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(oi+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)};ie.comparedTo=ie.cmp=function(e){var t,n,r,i,s=this,o=s.d,c=(e=new s.constructor(e)).d,a=s.s,u=e.s;if(!o||!c)return!a||!u?NaN:a!==u?a:o===c?0:!o^a<0?1:-1;if(!o[0]||!c[0])return o[0]?a:c[0]?-u:0;if(a!==u)return a;if(s.e!==e.e)return s.e>e.e^a<0?1:-1;for(r=o.length,i=c.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==c[t])return o[t]>c[t]^a<0?1:-1;return r===i?0:r>i^a<0?1:-1};ie.cosine=ie.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=Kx(r,bw(r,n)),r.precision=e,r.rounding=t,we(gr==2||gr==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};ie.cubeRoot=ie.cbrt=function(){var e,t,n,r,i,s,o,c,a,u,f=this,l=f.constructor;if(!f.isFinite()||f.isZero())return new l(f);for(Te=!1,s=f.s*bt(f.s*f,1/3),!s||Math.abs(s)==1/0?(n=kt(f.d),e=f.e,(s=(e-n.length+1)%3)&&(n+=s==1||s==-2?"0":"00"),s=bt(n,1/3),e=Kt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?n="5e"+e:(n=s.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=f.s):r=new l(s.toString()),o=(e=l.precision)+3;;)if(c=r,a=c.times(c).times(c),u=a.plus(f),r=De(u.plus(f).times(c),u.plus(a),o+2,1),kt(c.d).slice(0,o)===(n=kt(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n=="9999"||!i&&n=="4999"){if(!i&&(we(c,e+1,0),c.times(c).times(c).eq(f))){r=c;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(we(r,e+1,1),t=!r.times(r).times(r).eq(f));break}return Te=!0,we(r,e,l.rounding,t)};ie.decimalPlaces=ie.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Kt(this.e/be))*be,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};ie.dividedBy=ie.div=function(e){return De(this,new this.constructor(e))};ie.dividedToIntegerBy=ie.divToInt=function(e){var t=this,n=t.constructor;return we(De(t,new n(e),0,1,1),n.precision,n.rounding)};ie.equals=ie.eq=function(e){return this.cmp(e)===0};ie.floor=function(){return we(new this.constructor(this),this.e+1,3)};ie.greaterThan=ie.gt=function(e){return this.cmp(e)>0};ie.greaterThanOrEqualTo=ie.gte=function(e){var t=this.cmp(e);return t==1||t===0};ie.hyperbolicCosine=ie.cosh=function(){var e,t,n,r,i,s=this,o=s.constructor,c=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return c;n=o.precision,r=o.rounding,o.precision=n+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(e=Math.ceil(i/3),t=(1/cu(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=As(o,1,s.times(t),new o(1),!0);for(var a,u=e,f=new o(8);u--;)a=s.times(s),s=c.minus(a.times(f.minus(a.times(f))));return we(s,o.precision=n,o.rounding=r,!0)};ie.hyperbolicSine=ie.sinh=function(){var e,t,n,r,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(t=s.precision,n=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,r=i.d.length,r<3)i=As(s,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/cu(5,e)),i=As(s,2,i,i,!0);for(var o,c=new s(5),a=new s(16),u=new s(20);e--;)o=i.times(i),i=i.times(c.plus(o.times(a.times(o).plus(u))))}return s.precision=t,s.rounding=n,we(i,t,n,!0)};ie.hyperbolicTangent=ie.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,De(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};ie.inverseCosine=ie.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?Xn(t,r,i):new t(0):new t(NaN):e.isZero()?Xn(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2))};ie.inverseHyperbolicCosine=ie.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,Te=!1,n=n.times(n).minus(1).sqrt().plus(n),Te=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};ie.inverseHyperbolicSine=ie.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,Te=!1,n=n.times(n).plus(1).sqrt().plus(n),Te=!0,r.precision=e,r.rounding=t,n.ln())};ie.inverseHyperbolicTangent=ie.atanh=function(){var e,t,n,r,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=s.precision,t=s.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?we(new s(i),e,t,!0):(s.precision=n=r-i.e,i=De(i.plus(1),new s(1).minus(i),n+e,1),s.precision=e+4,s.rounding=1,i=i.ln(),s.precision=e,s.rounding=t,i.times(.5))):new s(NaN)};ie.inverseSine=ie.asin=function(){var e,t,n,r,i=this,s=i.constructor;return i.isZero()?new s(i):(t=i.abs().cmp(1),n=s.precision,r=s.rounding,t!==-1?t===0?(e=Xn(s,n+4,r).times(.5),e.s=i.s,e):new s(NaN):(s.precision=n+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=n,s.rounding=r,i.times(2)))};ie.inverseTangent=ie.atan=function(){var e,t,n,r,i,s,o,c,a,u=this,f=u.constructor,l=f.precision,p=f.rounding;if(u.isFinite()){if(u.isZero())return new f(u);if(u.abs().eq(1)&&l+4<=Xf)return o=Xn(f,l+4,p).times(.25),o.s=u.s,o}else{if(!u.s)return new f(NaN);if(l+4<=Xf)return o=Xn(f,l+4,p).times(.5),o.s=u.s,o}for(f.precision=c=l+10,f.rounding=1,n=Math.min(28,c/be+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(Te=!1,t=Math.ceil(c/be),r=1,a=u.times(u),o=new f(u),i=u;e!==-1;)if(i=i.times(a),s=o.minus(i.div(r+=2)),i=i.times(a),o=s.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===s.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),Te=!0,we(o,f.precision=l,f.rounding=p,!0)};ie.isFinite=function(){return!!this.d};ie.isInteger=ie.isInt=function(){return!!this.d&&Kt(this.e/be)>this.d.length-2};ie.isNaN=function(){return!this.s};ie.isNegative=ie.isNeg=function(){return this.s<0};ie.isPositive=ie.isPos=function(){return this.s>0};ie.isZero=function(){return!!this.d&&this.d[0]===0};ie.lessThan=ie.lt=function(e){return this.cmp(e)<0};ie.lessThanOrEqualTo=ie.lte=function(e){return this.cmp(e)<1};ie.logarithm=ie.log=function(e){var t,n,r,i,s,o,c,a,u=this,f=u.constructor,l=f.precision,p=f.rounding,y=5;if(e==null)e=new f(10),t=!0;else{if(e=new f(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new f(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new f(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)s=!0;else{for(i=n[0];i%10===0;)i/=10;s=i!==1}if(Te=!1,c=l+y,o=Qr(u,c),r=t?Ta(f,c+10):Qr(e,c),a=De(o,r,c,1),Po(a.d,i=l,p))do if(c+=10,o=Qr(u,c),r=t?Ta(f,c+10):Qr(e,c),a=De(o,r,c,1),!s){+kt(a.d).slice(i+1,i+15)+1==1e14&&(a=we(a,l+1,0));break}while(Po(a.d,i+=10,p));return Te=!0,we(a,l,p)};ie.minus=ie.sub=function(e){var t,n,r,i,s,o,c,a,u,f,l,p,y=this,g=y.constructor;if(e=new g(e),!y.d||!e.d)return!y.s||!e.s?e=new g(NaN):y.d?e.s=-e.s:e=new g(e.d||y.s!==e.s?y:NaN),e;if(y.s!=e.s)return e.s=-e.s,y.plus(e);if(u=y.d,p=e.d,c=g.precision,a=g.rounding,!u[0]||!p[0]){if(p[0])e.s=-e.s;else if(u[0])e=new g(y);else return new g(a===3?-0:0);return Te?we(e,c,a):e}if(n=Kt(e.e/be),f=Kt(y.e/be),u=u.slice(),s=f-n,s){for(l=s<0,l?(t=u,s=-s,o=p.length):(t=p,n=f,o=u.length),r=Math.max(Math.ceil(c/be),o)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=u.length,o=p.length,l=r<o,l&&(o=r),r=0;r<o;r++)if(u[r]!=p[r]){l=u[r]<p[r];break}s=0}for(l&&(t=u,u=p,p=t,e.s=-e.s),o=u.length,r=p.length-o;r>0;--r)u[o++]=0;for(r=p.length;r>s;){if(u[--r]<p[r]){for(i=r;i&&u[--i]===0;)u[i]=Fn-1;--u[i],u[r]+=Fn}u[r]-=p[r]}for(;u[--o]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=ou(u,n),Te?we(e,c,a):e):new g(a===3?-0:0)};ie.modulo=ie.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?we(new r(n),r.precision,r.rounding):(Te=!1,r.modulo==9?(t=De(n,e.abs(),0,3,1),t.s*=e.s):t=De(n,e,0,r.modulo,1),t=t.times(e),Te=!0,n.minus(t))};ie.naturalExponential=ie.exp=function(){return zf(this)};ie.naturalLogarithm=ie.ln=function(){return Qr(this)};ie.negated=ie.neg=function(){var e=new this.constructor(this);return e.s=-e.s,we(e)};ie.plus=ie.add=function(e){var t,n,r,i,s,o,c,a,u,f,l=this,p=l.constructor;if(e=new p(e),!l.d||!e.d)return!l.s||!e.s?e=new p(NaN):l.d||(e=new p(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(u=l.d,f=e.d,c=p.precision,a=p.rounding,!u[0]||!f[0])return f[0]||(e=new p(l)),Te?we(e,c,a):e;if(s=Kt(l.e/be),r=Kt(e.e/be),u=u.slice(),i=s-r,i){for(i<0?(n=u,i=-i,o=f.length):(n=f,r=s,o=u.length),s=Math.ceil(c/be),o=s>o?s+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=u.length,i=f.length,o-i<0&&(i=o,n=f,f=u,u=n),t=0;i;)t=(u[--i]=u[i]+f[i]+t)/Fn|0,u[i]%=Fn;for(t&&(u.unshift(t),++r),o=u.length;u[--o]==0;)u.pop();return e.d=u,e.e=ou(u,r),Te?we(e,c,a):e};ie.precision=ie.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(oi+e);return n.d?(t=yw(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};ie.round=function(){var e=this,t=e.constructor;return we(new t(e),e.e+1,t.rounding)};ie.sine=ie.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=jx(r,bw(r,n)),r.precision=e,r.rounding=t,we(gr>2?n.neg():n,e,t,!0)):new r(NaN)};ie.squareRoot=ie.sqrt=function(){var e,t,n,r,i,s,o=this,c=o.d,a=o.e,u=o.s,f=o.constructor;if(u!==1||!c||!c[0])return new f(!u||u<0&&(!c||c[0])?NaN:c?o:1/0);for(Te=!1,u=Math.sqrt(+o),u==0||u==1/0?(t=kt(c),(t.length+a)%2==0&&(t+="0"),u=Math.sqrt(t),a=Kt((a+1)/2)-(a<0||a%2),u==1/0?t="5e"+a:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+a),r=new f(t)):r=new f(u.toString()),n=(a=f.precision)+3;;)if(s=r,r=s.plus(De(o,s,n+2,1)).times(.5),kt(s.d).slice(0,n)===(t=kt(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!i&&t=="4999"){if(!i&&(we(s,a+1,0),s.times(s).eq(o))){r=s;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(we(r,a+1,1),e=!r.times(r).eq(o));break}return Te=!0,we(r,a,f.rounding,e)};ie.tangent=ie.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=De(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,we(gr==2||gr==4?n.neg():n,e,t,!0)):new r(NaN)};ie.times=ie.mul=function(e){var t,n,r,i,s,o,c,a,u,f=this,l=f.constructor,p=f.d,y=(e=new l(e)).d;if(e.s*=f.s,!p||!p[0]||!y||!y[0])return new l(!e.s||p&&!p[0]&&!y||y&&!y[0]&&!p?NaN:!p||!y?e.s/0:e.s*0);for(n=Kt(f.e/be)+Kt(e.e/be),a=p.length,u=y.length,a<u&&(s=p,p=y,y=s,o=a,a=u,u=o),s=[],o=a+u,r=o;r--;)s.push(0);for(r=u;--r>=0;){for(t=0,i=a+r;i>r;)c=s[i]+y[r]*p[i-r-1]+t,s[i--]=c%Fn|0,t=c/Fn|0;s[i]=(s[i]+t)%Fn|0}for(;!s[--o];)s.pop();return t?++n:s.shift(),e.d=s,e.e=ou(s,n),Te?we(e,l.precision,l.rounding):e};ie.toBinary=function(e,t){return th(this,2,e,t)};ie.toDecimalPlaces=ie.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(fn(e,0,fi),t===void 0?t=r.rounding:fn(t,0,8),we(n,e+n.e+1,t))};ie.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Zn(r,!0):(fn(e,0,fi),t===void 0?t=i.rounding:fn(t,0,8),r=we(new i(r),e+1,t),n=Zn(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};ie.toFixed=function(e,t){var n,r,i=this,s=i.constructor;return e===void 0?n=Zn(i):(fn(e,0,fi),t===void 0?t=s.rounding:fn(t,0,8),r=we(new s(i),e+i.e+1,t),n=Zn(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};ie.toFraction=function(e){var t,n,r,i,s,o,c,a,u,f,l,p,y=this,g=y.d,w=y.constructor;if(!g)return new w(y);if(u=n=new w(1),r=a=new w(0),t=new w(r),s=t.e=yw(g)-y.e-1,o=s%be,t.d[0]=bt(10,o<0?be+o:o),e==null)e=s>0?t:u;else{if(c=new w(e),!c.isInt()||c.lt(u))throw Error(oi+c);e=c.gt(t)?s>0?t:u:c}for(Te=!1,c=new w(kt(g)),f=w.precision,w.precision=s=g.length*be*2;l=De(c,t,0,1,1),i=n.plus(l.times(r)),i.cmp(e)!=1;)n=r,r=i,i=u,u=a.plus(l.times(i)),a=i,i=t,t=c.minus(l.times(i)),c=i;return i=De(e.minus(n),r,0,1,1),a=a.plus(i.times(u)),n=n.plus(i.times(r)),a.s=u.s=y.s,p=De(u,r,s,1).minus(y).abs().cmp(De(a,n,s,1).minus(y).abs())<1?[u,r]:[a,n],w.precision=f,Te=!0,p};ie.toHexadecimal=ie.toHex=function(e,t){return th(this,16,e,t)};ie.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:fn(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(Te=!1,n=De(n,e,0,t,1).times(e),Te=!0,we(n)):(e.s=n.s,n=e),n};ie.toNumber=function(){return+this};ie.toOctal=function(e,t){return th(this,8,e,t)};ie.toPower=ie.pow=function(e){var t,n,r,i,s,o,c=this,a=c.constructor,u=+(e=new a(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new a(bt(+c,u));if(c=new a(c),c.eq(1))return c;if(r=a.precision,s=a.rounding,e.eq(1))return we(c,r,s);if(t=Kt(e.e/be),t>=e.d.length-1&&(n=u<0?-u:u)<=Vx)return i=gw(a,c,n,r),e.s<0?new a(1).div(i):we(i,r,s);if(o=c.s,o<0){if(t<e.d.length-1)return new a(NaN);if((e.d[t]&1)==0&&(o=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=o,c}return n=bt(+c,u),t=n==0||!isFinite(n)?Kt(u*(Math.log("0."+kt(c.d))/Math.LN10+c.e+1)):new a(n+"").e,t>a.maxE+1||t<a.minE-1?new a(t>0?o/0:0):(Te=!1,a.rounding=c.s=1,n=Math.min(12,(t+"").length),i=zf(e.times(Qr(c,r+n)),r),i.d&&(i=we(i,r+5,1),Po(i.d,r,s)&&(t=r+10,i=we(zf(e.times(Qr(c,t+n)),t),t+5,1),+kt(i.d).slice(r+1,r+15)+1==1e14&&(i=we(i,r+1,0)))),i.s=o,Te=!0,a.rounding=s,we(i,r,s))};ie.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Zn(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(fn(e,1,fi),t===void 0?t=i.rounding:fn(t,0,8),r=we(new i(r),e,t),n=Zn(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};ie.toSignificantDigits=ie.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(fn(e,1,fi),t===void 0?t=r.rounding:fn(t,0,8)),we(new r(n),e,t)};ie.toString=function(){var e=this,t=e.constructor,n=Zn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};ie.truncated=ie.trunc=function(){return we(new this.constructor(this),this.e+1,1)};ie.valueOf=ie.toJSON=function(){var e=this,t=e.constructor,n=Zn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function kt(e){var t,n,r,i=e.length-1,s="",o=e[0];if(i>0){for(s+=o,t=1;t<i;t++)r=e[t]+"",n=be-r.length,n&&(s+=Yr(n)),s+=r;o=e[t],r=o+"",n=be-r.length,n&&(s+=Yr(n))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function fn(e,t,n){if(e!==~~e||e<t||e>n)throw Error(oi+e)}function Po(e,t,n,r){var i,s,o,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=be,i=0):(i=Math.ceil((t+1)/be),t%=be),s=bt(10,be-t),c=e[i]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),o=n<4&&c==99999||n>3&&c==49999||c==5e4||c==0):o=(n<4&&c+1==s||n>3&&c+1==s/2)&&(e[i+1]/s/100|0)==bt(10,t-2)-1||(c==s/2||c==0)&&(e[i+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),o=(r||n<4)&&c==9999||!r&&n>3&&c==4999):o=((r||n<4)&&c+1==s||!r&&n>3&&c+1==s/2)&&(e[i+1]/s/1e3|0)==bt(10,t-3)-1,o}function Kc(e,t,n){for(var r,i=[0],s,o=0,c=e.length;o<c;){for(s=i.length;s--;)i[s]*=t;for(i[0]+=Gf.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function Kx(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/cu(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),e.precision+=n,t=As(e,1,t.times(i),new e(1));for(var s=n;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var De=(function(){function e(r,i,s){var o,c=0,a=r.length;for(r=r.slice();a--;)o=r[a]*i+c,r[a]=o%s|0,c=o/s|0;return c&&r.unshift(c),r}function t(r,i,s,o){var c,a;if(s!=o)a=s>o?1:-1;else for(c=a=0;c<s;c++)if(r[c]!=i[c]){a=r[c]>i[c]?1:-1;break}return a}function n(r,i,s,o){for(var c=0;s--;)r[s]-=c,c=r[s]<i[s]?1:0,r[s]=c*o+r[s]-i[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,s,o,c,a){var u,f,l,p,y,g,w,E,_,S,m,T,I,A,U,M,v,R,V,W,H=r.constructor,K=r.s==i.s?1:-1,N=r.d,L=i.d;if(!N||!N[0]||!L||!L[0])return new H(!r.s||!i.s||(N?L&&N[0]==L[0]:!L)?NaN:N&&N[0]==0||!L?K*0:K/0);for(a?(y=1,f=r.e-i.e):(a=Fn,y=be,f=Kt(r.e/y)-Kt(i.e/y)),V=L.length,v=N.length,_=new H(K),S=_.d=[],l=0;L[l]==(N[l]||0);l++);if(L[l]>(N[l]||0)&&f--,s==null?(A=s=H.precision,o=H.rounding):c?A=s+(r.e-i.e)+1:A=s,A<0)S.push(1),g=!0;else{if(A=A/y+2|0,l=0,V==1){for(p=0,L=L[0],A++;(l<v||p)&&A--;l++)U=p*a+(N[l]||0),S[l]=U/L|0,p=U%L|0;g=p||l<v}else{for(p=a/(L[0]+1)|0,p>1&&(L=e(L,p,a),N=e(N,p,a),V=L.length,v=N.length),M=V,m=N.slice(0,V),T=m.length;T<V;)m[T++]=0;W=L.slice(),W.unshift(0),R=L[0],L[1]>=a/2&&++R;do p=0,u=t(L,m,V,T),u<0?(I=m[0],V!=T&&(I=I*a+(m[1]||0)),p=I/R|0,p>1?(p>=a&&(p=a-1),w=e(L,p,a),E=w.length,T=m.length,u=t(w,m,E,T),u==1&&(p--,n(w,V<E?W:L,E,a))):(p==0&&(u=p=1),w=L.slice()),E=w.length,E<T&&w.unshift(0),n(m,w,T,a),u==-1&&(T=m.length,u=t(L,m,V,T),u<1&&(p++,n(m,V<T?W:L,T,a))),T=m.length):u===0&&(p++,m=[0]),S[l++]=p,u&&m[0]?m[T++]=N[M]||0:(m=[N[M]],T=1);while((M++<v||m[0]!==void 0)&&A--);g=m[0]!==void 0}S[0]||S.shift()}if(y==1)_.e=f,fw=g;else{for(l=1,p=S[0];p>=10;p/=10)l++;_.e=l+f*y-1,we(_,c?s+_.e+1:s,o,g)}return _}})();function we(e,t,n,r){var i,s,o,c,a,u,f,l,p,y=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(i=1,c=l[0];c>=10;c/=10)i++;if(s=t-i,s<0)s+=be,o=t,f=l[p=0],a=f/bt(10,i-o-1)%10|0;else if(p=Math.ceil((s+1)/be),c=l.length,p>=c)if(r){for(;c++<=p;)l.push(0);f=a=0,i=1,s%=be,o=s-be+1}else break e;else{for(f=c=l[p],i=1;c>=10;c/=10)i++;s%=be,o=s-be+i,a=o<0?0:f/bt(10,i-o-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(o<0?f:f%bt(10,i-o-1)),u=n<4?(a||r)&&(n==0||n==(e.s<0?3:2)):a>5||a==5&&(n==4||r||n==6&&(s>0?o>0?f/bt(10,i-o):0:l[p-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,u?(t-=e.e+1,l[0]=bt(10,(be-t%be)%be),e.e=-t||0):l[0]=e.e=0,e;if(s==0?(l.length=p,c=1,p--):(l.length=p+1,c=bt(10,be-s),l[p]=o>0?(f/bt(10,i-o)%bt(10,o)|0)*c:0),u)for(;;)if(p==0){for(s=1,o=l[0];o>=10;o/=10)s++;for(o=l[0]+=c,c=1;o>=10;o/=10)c++;s!=c&&(e.e++,l[0]==Fn&&(l[0]=1));break}else{if(l[p]+=c,l[p]!=Fn)break;l[p--]=0,c=1}for(s=l.length;l[--s]===0;)l.pop()}return Te&&(e.e>y.maxE?(e.d=null,e.e=NaN):e.e<y.minE&&(e.e=0,e.d=[0])),e}function Zn(e,t,n){if(!e.isFinite())return mw(e);var r,i=e.e,s=kt(e.d),o=s.length;return t?(n&&(r=n-o)>0?s=s.charAt(0)+"."+s.slice(1)+Yr(r):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):i<0?(s="0."+Yr(-i-1)+s,n&&(r=n-o)>0&&(s+=Yr(r))):i>=o?(s+=Yr(i+1-o),n&&(r=n-i-1)>0&&(s=s+"."+Yr(r))):((r=i+1)<o&&(s=s.slice(0,r)+"."+s.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(s+="."),s+=Yr(r))),s}function ou(e,t){var n=e[0];for(t*=be;n>=10;n/=10)t++;return t}function Ta(e,t,n){if(t>$x)throw Te=!0,n&&(e.precision=n),Error(lw);return we(new e(_a),t,1,!0)}function Xn(e,t,n){if(t>Xf)throw Error(lw);return we(new e(Sa),t,n,!0)}function yw(e){var t=e.length-1,n=t*be+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function Yr(e){for(var t="";e--;)t+="0";return t}function gw(e,t,n,r){var i,s=new e(1),o=Math.ceil(r/be+4);for(Te=!1;;){if(n%2&&(s=s.times(t),qp(s.d,o)&&(i=!0)),n=Kt(n/2),n===0){n=s.d.length-1,i&&s.d[n]===0&&++s.d[n];break}t=t.times(t),qp(t.d,o)}return Te=!0,s}function Mp(e){return e.d[e.d.length-1]&1}function ww(e,t,n){for(var r,i,s=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){s=i;break}r=s.cmp(i),(r===n||r===0&&s.s===n)&&(s=i)}return s}function zf(e,t){var n,r,i,s,o,c,a,u=0,f=0,l=0,p=e.constructor,y=p.rounding,g=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(Te=!1,a=g):a=t,c=new p(.03125);e.e>-2;)e=e.times(c),l+=5;for(r=Math.log(bt(2,l))/Math.LN10*2+5|0,a+=r,n=s=o=new p(1),p.precision=a;;){if(s=we(s.times(e),a,1),n=n.times(++f),c=o.plus(De(s,n,a,1)),kt(c.d).slice(0,a)===kt(o.d).slice(0,a)){for(i=l;i--;)o=we(o.times(o),a,1);if(t==null)if(u<3&&Po(o.d,a-r,y,u))p.precision=a+=10,n=s=c=new p(1),f=0,u++;else return we(o,p.precision=g,y,Te=!0);else return p.precision=g,o}o=c}}function Qr(e,t){var n,r,i,s,o,c,a,u,f,l,p,y=1,g=10,w=e,E=w.d,_=w.constructor,S=_.rounding,m=_.precision;if(w.s<0||!E||!E[0]||!w.e&&E[0]==1&&E.length==1)return new _(E&&!E[0]?-1/0:w.s!=1?NaN:E?0:w);if(t==null?(Te=!1,f=m):f=t,_.precision=f+=g,n=kt(E),r=n.charAt(0),Math.abs(s=w.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)w=w.times(e),n=kt(w.d),r=n.charAt(0),y++;s=w.e,r>1?(w=new _("0."+n),s++):w=new _(r+"."+n.slice(1))}else return u=Ta(_,f+2,m).times(s+""),w=Qr(new _(r+"."+n.slice(1)),f-g).plus(u),_.precision=m,t==null?we(w,m,S,Te=!0):w;for(l=w,a=o=w=De(w.minus(1),w.plus(1),f,1),p=we(w.times(w),f,1),i=3;;){if(o=we(o.times(p),f,1),u=a.plus(De(o,new _(i),f,1)),kt(u.d).slice(0,f)===kt(a.d).slice(0,f))if(a=a.times(2),s!==0&&(a=a.plus(Ta(_,f+2,m).times(s+""))),a=De(a,new _(y),f,1),t==null)if(Po(a.d,f-g,S,c))_.precision=f+=g,u=o=w=De(l.minus(1),l.plus(1),f,1),p=we(w.times(w),f,1),i=c=1;else return we(a,_.precision=m,S,Te=!0);else return _.precision=m,a;a=u,i+=2}}function mw(e){return String(e.s*e.s/0)}function Lc(e,t){var n,r,i;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%be,n<0&&(r+=be),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=be;r<i;)e.d.push(+t.slice(r,r+=be));t=t.slice(r),r=be-t.length}else r-=i;for(;r--;)t+="0";e.d.push(+t),Te&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Lx(e,t){var n,r,i,s,o,c,a,u,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),pw.test(t))return Lc(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Mx.test(t))n=16,t=t.toLowerCase();else if(Fx.test(t))n=2;else if(qx.test(t))n=8;else throw Error(oi+t);for(s=t.search(/p/i),s>0?(a=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),o=s>=0,r=e.constructor,o&&(t=t.replace(".",""),c=t.length,s=c-s,i=gw(r,new r(n),s,s*2)),u=Kc(t,n,Fn),f=u.length-1,s=f;u[s]===0;--s)u.pop();return s<0?new r(e.s*0):(e.e=ou(u,f),e.d=u,Te=!1,o&&(e=De(e,i,c*4)),a&&(e=e.times(Math.abs(a)<54?bt(2,a):ei.pow(2,a))),Te=!0,e)}function jx(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:As(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/cu(5,n)),t=As(e,2,t,t);for(var i,s=new e(5),o=new e(16),c=new e(20);n--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(c))));return t}function As(e,t,n,r,i){var s,o,c,a,u=e.precision,f=Math.ceil(u/be);for(Te=!1,a=n.times(n),c=new e(r);;){if(o=De(c.times(a),new e(t++*t++),u,1),c=i?r.plus(o):r.minus(o),r=De(o.times(a),new e(t++*t++),u,1),o=c.plus(r),o.d[f]!==void 0){for(s=f;o.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=o,o=s}return Te=!0,o.d.length=f+1,o}function cu(e,t){for(var n=e;--t;)n*=e;return n}function bw(e,t){var n,r=t.s<0,i=Xn(e,e.precision,1),s=i.times(.5);if(t=t.abs(),t.lte(s))return gr=r?4:1,t;if(n=t.divToInt(i),n.isZero())gr=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(s))return gr=Mp(n)?r?2:3:r?4:1,t;gr=Mp(n)?r?1:4:r?3:2}return t.minus(i).abs()}function th(e,t,n,r){var i,s,o,c,a,u,f,l,p,y=e.constructor,g=n!==void 0;if(g?(fn(n,1,fi),r===void 0?r=y.rounding:fn(r,0,8)):(n=y.precision,r=y.rounding),!e.isFinite())f=mw(e);else{for(f=Zn(e),o=f.indexOf("."),g?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(f=f.replace(".",""),p=new y(1),p.e=f.length-o,p.d=Kc(Zn(p),10,i),p.e=p.d.length),l=Kc(f,10,i),s=a=l.length;l[--a]==0;)l.pop();if(!l[0])f=g?"0p+0":"0";else{if(o<0?s--:(e=new y(e),e.d=l,e.e=s,e=De(e,p,n,r,0,i),l=e.d,s=e.e,u=fw),o=l[n],c=i/2,u=u||l[n+1]!==void 0,u=r<4?(o!==void 0||u)&&(r===0||r===(e.s<0?3:2)):o>c||o===c&&(r===4||u||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,u)for(;++l[--n]>i-1;)l[n]=0,n||(++s,l.unshift(1));for(a=l.length;!l[a-1];--a);for(o=0,f="";o<a;o++)f+=Gf.charAt(l[o]);if(g){if(a>1)if(t==16||t==8){for(o=t==16?4:3,--a;a%o;a++)f+="0";for(l=Kc(f,i,t),a=l.length;!l[a-1];--a);for(o=1,f="1.";o<a;o++)f+=Gf.charAt(l[o])}else f=f.charAt(0)+"."+f.slice(1);f=f+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)f="0"+f;f="0."+f}else if(++s>a)for(s-=a;s--;)f+="0";else s<a&&(f=f.slice(0,s)+"."+f.slice(s))}f=(t==16?"0x":t==2?"0b":t==8?"0o":"")+f}return e.s<0?"-"+f:f}function qp(e,t){if(e.length>t)return e.length=t,!0}function Wx(e){return new this(e).abs()}function Gx(e){return new this(e).acos()}function Dx(e){return new this(e).acosh()}function Xx(e,t){return new this(e).plus(t)}function zx(e){return new this(e).asin()}function Yx(e){return new this(e).asinh()}function Zx(e){return new this(e).atan()}function Jx(e){return new this(e).atanh()}function Qx(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,s=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Xn(this,s,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Xn(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Xn(this,s,1).times(.5),n.s=e.s):t.s<0?(this.precision=s,this.rounding=1,n=this.atan(De(e,t,s,1)),t=Xn(this,s,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(De(e,t,s,1)),n}function e6(e){return new this(e).cbrt()}function t6(e){return we(e=new this(e),e.e+1,2)}function n6(e,t,n){return new this(e).clamp(t,n)}function r6(e){if(!e||typeof e!="object")throw Error(su+"Object expected");var t,n,r,i=e.defaults===!0,s=["precision",1,fi,"rounding",0,8,"toExpNeg",-as,0,"toExpPos",0,as,"maxE",0,as,"minE",-as,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(n=s[t],i&&(this[n]=Df[n]),(r=e[n])!==void 0)if(Kt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[n]=r;else throw Error(oi+n+": "+r);if(n="crypto",i&&(this[n]=Df[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(hw);else this[n]=!1;else throw Error(oi+n+": "+r);return this}function i6(e){return new this(e).cos()}function s6(e){return new this(e).cosh()}function Ew(e){var t,n,r;function i(s){var o,c,a,u=this;if(!(u instanceof i))return new i(s);if(u.constructor=i,Vp(s)){u.s=s.s,Te?!s.d||s.e>i.maxE?(u.e=NaN,u.d=null):s.e<i.minE?(u.e=0,u.d=[0]):(u.e=s.e,u.d=s.d.slice()):(u.e=s.e,u.d=s.d?s.d.slice():s.d);return}if(a=typeof s,a==="number"){if(s===0){u.s=1/s<0?-1:1,u.e=0,u.d=[0];return}if(s<0?(s=-s,u.s=-1):u.s=1,s===~~s&&s<1e7){for(o=0,c=s;c>=10;c/=10)o++;Te?o>i.maxE?(u.e=NaN,u.d=null):o<i.minE?(u.e=0,u.d=[0]):(u.e=o,u.d=[s]):(u.e=o,u.d=[s]);return}if(s*0!==0){s||(u.s=NaN),u.e=NaN,u.d=null;return}return Lc(u,s.toString())}if(a==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),u.s=-1):(c===43&&(s=s.slice(1)),u.s=1),pw.test(s)?Lc(u,s):Lx(u,s);if(a==="bigint")return s<0?(s=-s,u.s=-1):u.s=1,Lc(u,s.toString());throw Error(oi+s)}if(i.prototype=ie,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=r6,i.clone=Ew,i.isDecimal=Vp,i.abs=Wx,i.acos=Gx,i.acosh=Dx,i.add=Xx,i.asin=zx,i.asinh=Yx,i.atan=Zx,i.atanh=Jx,i.atan2=Qx,i.cbrt=e6,i.ceil=t6,i.clamp=n6,i.cos=i6,i.cosh=s6,i.div=o6,i.exp=c6,i.floor=a6,i.hypot=u6,i.ln=f6,i.log=l6,i.log10=d6,i.log2=h6,i.max=p6,i.min=y6,i.mod=g6,i.mul=w6,i.pow=m6,i.random=b6,i.round=E6,i.sign=_6,i.sin=S6,i.sinh=T6,i.sqrt=x6,i.sub=A6,i.sum=v6,i.tan=B6,i.tanh=I6,i.trunc=O6,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function o6(e,t){return new this(e).div(t)}function c6(e){return new this(e).exp()}function a6(e){return we(e=new this(e),e.e+1,3)}function u6(){var e,t,n=new this(0);for(Te=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return Te=!0,new this(1/0);n=t}return Te=!0,n.sqrt()}function Vp(e){return e instanceof ei||e&&e.toStringTag===dw||!1}function f6(e){return new this(e).ln()}function l6(e,t){return new this(e).log(t)}function h6(e){return new this(e).log(2)}function d6(e){return new this(e).log(10)}function p6(){return ww(this,arguments,-1)}function y6(){return ww(this,arguments,1)}function g6(e,t){return new this(e).mod(t)}function w6(e,t){return new this(e).mul(t)}function m6(e,t){return new this(e).pow(t)}function b6(e){var t,n,r,i,s=0,o=new this(1),c=[];if(e===void 0?e=this.precision:fn(e,1,fi),r=Math.ceil(e/be),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)i=t[s],i>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)i=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(i%1e7),s+=4);s=r/4}else throw Error(hw);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=be,r&&e&&(i=bt(10,be-e),c[s]=(r/i|0)*i);c[s]===0;s--)c.pop();if(s<0)n=0,c=[0];else{for(n=-1;c[0]===0;n-=be)c.shift();for(r=1,i=c[0];i>=10;i/=10)r++;r<be&&(n-=be-r)}return o.e=n,o.d=c,o}function E6(e){return we(e=new this(e),e.e+1,this.rounding)}function _6(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function S6(e){return new this(e).sin()}function T6(e){return new this(e).sinh()}function x6(e){return new this(e).sqrt()}function A6(e,t){return new this(e).sub(t)}function v6(){var e=0,t=arguments,n=new this(t[e]);for(Te=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Te=!0,we(n,this.precision,this.rounding)}function B6(e){return new this(e).tan()}function I6(e){return new this(e).tanh()}function O6(e){return we(e=new this(e),e.e+1,1)}ie[Symbol.for("nodejs.util.inspect.custom")]=ie.toString;ie[Symbol.toStringTag]="Decimal";var ei=ie.constructor=Ew(Df);_a=new ei(_a);Sa=new ei(Sa);const P6=({IDL:e})=>{const t=e.Record({exchange_id:e.Text,reason:e.Text}),n=e.Variant({Ok:e.Null,Err:e.Text}),r=e.Variant({P2WPKH:e.Null,OpReturn:e.Nat64,P2SH:e.Null,P2TR:e.Null}),i=e.Record({input_types:e.Vec(r),pool_address:e.Vec(e.Text),output_types:e.Vec(r)}),s=e.Variant({Ok:e.Nat64,Err:e.Text}),o=e.Record({user_id:e.Principal}),c=e.Record({canister_version:e.Opt(e.Nat64),canister_id:e.Principal}),a=e.Variant({from_user:o,from_canister:c}),u=e.Record({controllers:e.Vec(e.Principal)}),f=e.Variant({reinstall:e.Null,upgrade:e.Null,install:e.Null}),l=e.Record({mode:f,module_hash:e.Vec(e.Nat8)}),p=e.Record({canister_version:e.Nat64,taken_at_timestamp:e.Nat64,snapshot_id:e.Vec(e.Nat8)}),y=e.Variant({creation:u,code_deployment:l,load_snapshot:p,controllers_change:u,code_uninstall:e.Null}),g=e.Record({timestamp_nanos:e.Nat64,canister_version:e.Nat64,origin:a,details:y}),w=e.Record({controllers:e.Vec(e.Principal),module_hash:e.Opt(e.Vec(e.Nat8)),recent_changes:e.Vec(g),total_num_changes:e.Nat64}),E=e.Variant({Ok:w,Err:e.Text}),_=e.Record({exchange_id:e.Text,pool_address:e.Text,pool_key:e.Text}),S=e.Variant({All:e.Null,ByTxid:e.Text,ByStatusCode:e.Text,ByAddress:e.Text,BySecondsPassed:e.Nat64}),m=e.Variant({Ok:e.Text,Err:e.Text}),T=e.Record({result:m,exchange_id:e.Text,maybe_return_time:e.Opt(e.Text),calling_method:e.Text,calling_args:e.Text,pool_address:e.Text,calling_time:e.Text}),I=e.Record({rollback_results:e.Vec(e.Text),invoke_args:e.Text,invoke_time:e.Text,finalized_time:e.Opt(e.Text),confirmed_time:e.Opt(e.Text),execution_steps:e.Vec(T),processing_result:m,broadcasted_time:e.Opt(e.Text)}),A=e.Record({block_hash:e.Text,block_height:e.Nat32}),U=e.Record({processing_results:e.Vec(e.Text),block_basic:A,txids:e.Vec(e.Text),block_time:e.Text,received_time:e.Text}),M=e.Variant({Abandoned:e.Record({reason:e.Text}),Active:e.Null,Halted:e.Record({reason:e.Text})}),v=e.Record({status:M,exchange_id:e.Text,canister_id:e.Principal,utxo_proof_enabled:e.Bool,client_canisters:e.Vec(e.Principal)}),R=e.Record({rollback_results:e.Vec(e.Text),txid:e.Text,received_time:e.Text,reason:e.Text}),V=e.Variant({mainnet:e.Null,regtest:e.Null,testnet:e.Null}),W=e.Record({min_seconds_of_unconfirmed_tx_in_pool_for_raising_fee_rate:e.Nat32,exchange_registry_principal:e.Principal,max_input_count_of_psbt:e.Nat32,min_tx_confirmations:e.Nat32,mempool_connector_principal:e.Principal,max_unconfirmed_tx_count_in_pool:e.Nat32,min_btc_amount_for_utxo:e.Nat64,rune_indexer_principal:e.Principal,max_intentions_per_invoke:e.Nat32,mempool_connector_public_key:e.Text,max_received_blocks_count:e.Nat32,min_unconfirmed_tx_count_in_pool_for_raising_fee_rate:e.Nat32,bitcoin_network:V}),H=e.Record({low:e.Nat64,high:e.Nat64,update_time:e.Text,medium:e.Nat64}),K=e.Record({last_block:e.Opt(A),pending_tx_count:e.Nat64,mempool_tx_fee_rate:H,invoke_paused:e.Bool,concurrent_invoke_status:e.Text,last_block_time:e.Opt(e.Tuple(e.Nat64,e.Text)),failed_new_block_height:e.Opt(e.Tuple(e.Nat32,e.Text))}),N=e.Variant({Error:e.Null,AvailableUnconfirmed:e.Null,InvalidTxid:e.Null,InvalidVout:e.Null,SpentInMempool:e.Null,SpentOnChain:e.Null,AvailableConfirmed:e.Null}),L=e.Record({status:N,value:e.Opt(e.Text),txid:e.Text,vout:e.Nat32,ancestors:e.Opt(e.Nat32),address:e.Opt(e.Text)}),F=e.Record({id:e.Text,value:e.Nat}),x=e.Record({coins:e.Vec(F),sats:e.Nat64,txid:e.Text,vout:e.Nat32}),O=e.Record({status:e.Opt(L),coins:e.Vec(F),utxo:x,is_signed:e.Bool,owner_pubkey:e.Opt(e.Text),owner_address:e.Text}),q=e.Record({coins_in_inputs:e.Vec(O),txid:e.Text,signed_address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F))),address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F)))}),P=e.Record({is_op_return:e.Bool,utxo:x,owner_address:e.Opt(e.Text)}),$=e.Record({burned_coins:e.Vec(F),coins_in_outputs:e.Vec(P),address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F)))}),G=e.Record({coin:F,from:e.Text}),X=e.Record({to:e.Text,coin:F}),Y=e.Record({input_coins:e.Vec(G),output_coins:e.Vec(X),action:e.Text,exchange_id:e.Text,pool_utxo_spent:e.Vec(e.Text),action_params:e.Text,nonce:e.Nat64,pool_address:e.Text,pool_utxo_received:e.Vec(x)}),oe=e.Record({tx_fee_in_sats:e.Nat64,initiator_address:e.Text,intentions:e.Vec(Y)}),ae=e.Record({applied_fee_rate:e.Nat64,pool_addresses:e.Vec(e.Text),coins_in_inputs:q,txid:e.Text,estimated_min_tx_fee:e.Nat64,actual_tx_fee:e.Nat64,coins_in_outputs:$,tx_vsize:e.Nat64,intention_set:oe,user_coins_in_inputs:e.Vec(F),initially_signed_addresses:e.Vec(e.Text)}),ee=e.Variant({Confirmed:e.Nat32,Rejected:e.Text,Pending:e.Null}),Z=e.Record({status:e.Opt(ee),invoke_log:I,included_block:e.Opt(A),sent_tx_hex:e.Text}),ce=e.Variant({Failed:I,NotFound:e.Null,Succeeded:Z}),ge=e.Record({maybe_rune:e.Opt(F),value:e.Nat64,script_pubkey_hex:e.Text,outpoint:e.Text}),pe=e.Record({client_info:e.Opt(e.Text),intention_set:oe,initiator_utxo_proof:e.Vec(e.Nat8),psbt_hex:e.Text}),J=e.Record({block_hash:e.Text,block_timestamp:e.Nat64,tx_ids:e.Vec(e.Text),block_height:e.Nat32}),fe=e.Variant({Ok:e.Vec(e.Text),Err:e.Text}),Se=e.Record({exchange_canister:e.Principal,exchange_id:e.Text,utxo_proof_enabled:e.Bool,client_canisters:e.Vec(e.Principal)}),Ce=e.Record({txid:e.Text,reason_code:e.Text,reason:e.Text}),Ze=e.Record({txid:e.Text,timestamp:e.Nat64,block:A}),st=e.Record({low:e.Nat64,high:e.Nat64,medium:e.Nat64});return e.Service({abandon_exchange:e.Func([t],[n],[]),clear_exchange_pools:e.Func([],[n],[]),clear_failed_invoke_logs:e.Func([e.Opt(e.Nat64),e.Vec(e.Text)],[n],[]),clear_last_block:e.Func([],[n],[]),clear_rejected_txs:e.Func([],[n],[]),clear_txs_with_min_confirmations:e.Func([e.Nat32],[n],[]),delete_tx_detail:e.Func([e.Text],[n],[]),delete_used_outpoints:e.Func([e.Text],[n],[]),estimate_min_tx_fee:e.Func([i],[s],["query"]),get_canister_info:e.Func([e.Nat64],[E],[]),get_exchange_pools:e.Func([e.Opt(e.Text)],[e.Vec(_)],["query"]),get_failed_invoke_logs:e.Func([S],[e.Vec(e.Tuple(e.Text,I))],["query"]),get_last_sent_txs:e.Func([],[e.Vec(e.Tuple(e.Text,e.Text,e.Opt(e.Nat32)))],["query"]),get_received_blocks:e.Func([e.Opt(e.Bool)],[e.Vec(U)],["query"]),get_registered_exchanges:e.Func([e.Opt(M)],[e.Vec(v)],["query"]),get_rejected_txs:e.Func([],[e.Vec(R)],["query"]),get_settings:e.Func([],[W],["query"]),get_status:e.Func([],[K],["query"]),get_tx_execution_context_view:e.Func([e.Text],[e.Opt(ae)],["query"]),get_tx_execution_result:e.Func([e.Text],[ce],["query"]),get_tx_for_outpoint:e.Func([e.Text],[e.Opt(Z)],["query"]),get_tx_queue_of_pool:e.Func([e.Text],[e.Vec(e.Tuple(e.Text,e.Opt(e.Nat32)))],["query"]),get_tx_sent:e.Func([e.Text],[e.Opt(Z)],["query"]),get_used_outpoints:e.Func([e.Opt(e.Text)],[e.Vec(e.Tuple(e.Text,e.Text))],["query"]),get_zero_confirmed_tx_count_of_pool:e.Func([e.Text],[e.Nat32],["query"]),get_zero_confirmed_txs:e.Func([e.Opt(e.Text)],[e.Vec(e.Text)],["query"]),get_zero_confirmed_utxos_of_address:e.Func([e.Text],[e.Vec(ge)],["query"]),init_status_code_message:e.Func([],[n],[]),inspect_status_code:e.Func([e.Text],[e.Text],["query"]),invoke:e.Func([pe],[m],[]),new_block_detected:e.Func([J],[n],[]),notify_exchange_for_blocks_from_height:e.Func([e.Text,e.Nat32],[fe],[]),notify_exchanges_for_block:e.Func([e.Vec(e.Text),A,e.Nat64,e.Vec(e.Text)],[fe],[]),pause_invoke:e.Func([],[n],[]),reapply_tx:e.Func([e.Text],[n],[]),register_exchange:e.Func([Se],[n],[]),reject_tx:e.Func([Ce],[n],[]),resume_invoke:e.Func([],[n],[]),rollback_tx:e.Func([e.Text],[fe],[]),save_included_block_for_tx:e.Func([Ze],[n],[]),set_bitcoin_network:e.Func([V],[n],[]),set_exchange_registry_principal:e.Func([e.Principal],[n],[]),set_max_input_count_of_psbt:e.Func([e.Nat32],[n],[]),set_max_intentions_per_invoke:e.Func([e.Nat32],[n],[]),set_max_received_blocks_count:e.Func([e.Nat32],[n],[]),set_max_unconfirmed_tx_count_in_pool:e.Func([e.Nat32],[n],[]),set_mempool_connector_principal:e.Func([e.Principal],[n],[]),set_mempool_connector_public_key:e.Func([e.Text],[n],[]),set_min_btc_amount_for_utxo:e.Func([e.Nat64],[n],[]),set_min_tx_confirmations:e.Func([e.Nat32],[n],[]),set_rune_indexer_principal:e.Func([e.Principal],[n],[]),set_tx_fee_per_vbyte:e.Func([st],[n],[]),unhalt_exchange:e.Func([e.Text],[n],[]),version:e.Func([],[e.Text],["query"])})};class k6{xverse;config;exchange;orchestrator;constructor(t){this.config=t;const n=t.network===Yo.Testnet,r=n?"https://api-testnet4.secretkeylabs.io":"https://api.secretkeylabs.io";this.xverse=new zS({baseUrl:r,apiKey:t.xverseApiKey});const i="https://icp0.io";this.exchange=ma.createActor(t.exchangeIdlFactory,{agent:yr.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:t.exchangeCanisterId}),this.orchestrator=ma.createActor(P6,{agent:yr.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:n?Rx:Ux})}async filterSpentUtxos(t,n){const r=await this.orchestrator.get_used_outpoints([t]);console.log(`[REE-SDK] filterSpentUtxos: address=${t}, utxos=${n.length}, usedOutpoints=${r.length}`,r.map(([s,o])=>`${s} (tx:${o})`));const i=n.filter(({txid:s,vout:o})=>r.findIndex(([c])=>`${s}:${o}`===c)<0);return i.length<n.length&&console.warn(`[REE-SDK] filterSpentUtxos: filtered out ${n.length-i.length} utxos`),i}async getPendingBtcUtxos(t){const n=await this.orchestrator.get_zero_confirmed_utxos_of_address(t),r=Zr(t);return n.filter(({maybe_rune:i})=>!i.length).map(({value:i,script_pubkey_hex:s,outpoint:o})=>{const[c,a]=o.split(":");return{txid:c,vout:Number(a),satoshis:i.toString(),scriptPk:s,addressType:r,address:t,runes:[]}})}async getPendingRuneUtxos(t,n){const r=await this.orchestrator.get_zero_confirmed_utxos_of_address(t),i=Zr(t);return r.filter(({maybe_rune:s})=>s.length).map(({value:s,script_pubkey_hex:o,outpoint:c,maybe_rune:a})=>{const[u,f]=c.split(":"),l=a[0];return{txid:u,vout:Number(f),satoshis:s.toString(),scriptPk:o,addressType:i,address:t,runes:l?[{id:l.id,amount:l.value.toString()}]:[],pubkey:n}})}async getBtcUtxos(t){let n=0;const r=60,i=[],s=await this.getPendingBtcUtxos(t);let o=!0;for(;o;){const u=await this.xverse.utxosByAddress(t,n,r);i.push(...u.items),o=u.hasMore,n+=r}const c=Ea(t,this.config.network),a=i.map(({txid:u,vout:f,value:l})=>({txid:u,vout:f,address:t,runes:[],satoshis:l.toString(),scriptPk:ba(c)})).filter(u=>Number(u.satoshis)>546);return this.filterSpentUtxos(t,a.concat(s))}async getRuneUtxos(t,n,r){let i=0;const s=60,o=[],c=await this.getPendingRuneUtxos(t,r);console.log(`[REE-SDK] getRuneUtxos: address=${t}, runeId=${n}, pendingUtxos=${c.length}`);let a=!0;for(;a;){const p=await this.xverse.runeUtxosByAddress(t,n,i,s);console.log(`[REE-SDK] xverse.runeUtxosByAddress response: items=${p.items?.length}, hasMore=${p.hasMore}`),o.push(...p.items),a=p.hasMore,i+=s}const u=Ea(t,this.config.network),f=o.map(({txid:p,vout:y,runes:g,amount:w})=>({txid:p,vout:y,address:t,runes:g.map(({runeId:E,amount:_})=>{const S=new ei(_).toFixed(0);return{id:E,amount:S}}),satoshis:w.toString(),scriptPk:ba(u),pubkey:r}));console.log(`[REE-SDK] getRuneUtxos: before filter=${f.length} xverse + ${c.length} pending`);const l=await this.filterSpentUtxos(t,f.concat(c));return console.log(`[REE-SDK] getRuneUtxos: after filterSpentUtxos=${l.length}`),l}async getBtcBalance(t){const r=(await this.getBtcUtxos(t)).reduce((i,s)=>i+BigInt(s.satoshis),BigInt(0));return new ei(r.toString()).div(1e8).toNumber()}async getRuneBalance(t,n,r){const i=await this.getRuneUtxos(t,n,r);if(!i)return;let s=new ei(0);for(const o of i)s=s.add(new ei(o.runes.find(c=>c.id===n)?.amount??0));return s.toNumber()}async getPoolList(){try{return await this.exchange.get_pool_list()??[]}catch(t){throw console.error("get pool list failed:",t),t}}async getPoolInfo(t){try{const n=await this.exchange.get_pool_info({pool_address:t});if(n.length===0)throw new Error("Pool not found");return n[0]}catch(n){throw console.error("get pool data failed:",n),n}}async createTransaction({address:t,paymentAddress:n,publicKey:r,paymentPublicKey:i,feeRate:s,mergeSelfRuneBtcOutputs:o,clientInfo:c,manualBuild:a}){return new Jr({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,publicKey:r,paymentPublicKey:i,feeRate:s,mergeSelfRuneBtcOutputs:o,clientInfo:c,manualBuild:a},this)}async getRecommendedFeeRate(){const t=await this.orchestrator.get_status();return{min:Number(t.mempool_tx_fee_rate.medium),max:Number(t.mempool_tx_fee_rate.medium)*3}}}exports.Network=Yo;exports.ReeClient=k6;exports.Transaction=Jr;exports.utils=Nx;
|
|
82
|
+
*/var us=9e15,fi=1e9,Df="0123456789abcdef",Ta="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",xa="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Xf={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-us,maxE:us,crypto:!1},fw,gr,Te=!0,ou="[DecimalError] ",oi=ou+"Invalid argument: ",lw=ou+"Precision limit exceeded",hw=ou+"crypto unavailable",dw="[object Decimal]",Kt=Math.floor,bt=Math.pow,Fx=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Mx=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,qx=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,pw=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Fn=1e7,be=7,Vx=9007199254740991,$x=Ta.length-1,zf=xa.length-1,ie={toStringTag:dw};ie.absoluteValue=ie.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),we(e)};ie.ceil=function(){return we(new this.constructor(this),this.e+1,2)};ie.clampedTo=ie.clamp=function(e,t){var n,r=this,i=r.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(oi+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new i(r)};ie.comparedTo=ie.cmp=function(e){var t,n,r,i,s=this,o=s.d,c=(e=new s.constructor(e)).d,a=s.s,u=e.s;if(!o||!c)return!a||!u?NaN:a!==u?a:o===c?0:!o^a<0?1:-1;if(!o[0]||!c[0])return o[0]?a:c[0]?-u:0;if(a!==u)return a;if(s.e!==e.e)return s.e>e.e^a<0?1:-1;for(r=o.length,i=c.length,t=0,n=r<i?r:i;t<n;++t)if(o[t]!==c[t])return o[t]>c[t]^a<0?1:-1;return r===i?0:r>i^a<0?1:-1};ie.cosine=ie.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=Kx(r,bw(r,n)),r.precision=e,r.rounding=t,we(gr==2||gr==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};ie.cubeRoot=ie.cbrt=function(){var e,t,n,r,i,s,o,c,a,u,f=this,l=f.constructor;if(!f.isFinite()||f.isZero())return new l(f);for(Te=!1,s=f.s*bt(f.s*f,1/3),!s||Math.abs(s)==1/0?(n=kt(f.d),e=f.e,(s=(e-n.length+1)%3)&&(n+=s==1||s==-2?"0":"00"),s=bt(n,1/3),e=Kt((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?n="5e"+e:(n=s.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new l(n),r.s=f.s):r=new l(s.toString()),o=(e=l.precision)+3;;)if(c=r,a=c.times(c).times(c),u=a.plus(f),r=De(u.plus(f).times(c),u.plus(a),o+2,1),kt(c.d).slice(0,o)===(n=kt(r.d)).slice(0,o))if(n=n.slice(o-3,o+1),n=="9999"||!i&&n=="4999"){if(!i&&(we(c,e+1,0),c.times(c).times(c).eq(f))){r=c;break}o+=4,i=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(we(r,e+1,1),t=!r.times(r).times(r).eq(f));break}return Te=!0,we(r,e,l.rounding,t)};ie.decimalPlaces=ie.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-Kt(this.e/be))*be,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};ie.dividedBy=ie.div=function(e){return De(this,new this.constructor(e))};ie.dividedToIntegerBy=ie.divToInt=function(e){var t=this,n=t.constructor;return we(De(t,new n(e),0,1,1),n.precision,n.rounding)};ie.equals=ie.eq=function(e){return this.cmp(e)===0};ie.floor=function(){return we(new this.constructor(this),this.e+1,3)};ie.greaterThan=ie.gt=function(e){return this.cmp(e)>0};ie.greaterThanOrEqualTo=ie.gte=function(e){var t=this.cmp(e);return t==1||t===0};ie.hyperbolicCosine=ie.cosh=function(){var e,t,n,r,i,s=this,o=s.constructor,c=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return c;n=o.precision,r=o.rounding,o.precision=n+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(e=Math.ceil(i/3),t=(1/au(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=vs(o,1,s.times(t),new o(1),!0);for(var a,u=e,f=new o(8);u--;)a=s.times(s),s=c.minus(a.times(f.minus(a.times(f))));return we(s,o.precision=n,o.rounding=r,!0)};ie.hyperbolicSine=ie.sinh=function(){var e,t,n,r,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(t=s.precision,n=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,r=i.d.length,r<3)i=vs(s,2,i,i,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,i=i.times(1/au(5,e)),i=vs(s,2,i,i,!0);for(var o,c=new s(5),a=new s(16),u=new s(20);e--;)o=i.times(i),i=i.times(c.plus(o.times(a.times(o).plus(u))))}return s.precision=t,s.rounding=n,we(i,t,n,!0)};ie.hyperbolicTangent=ie.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,De(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};ie.inverseCosine=ie.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,i=t.rounding;return n!==-1?n===0?e.isNeg()?Xn(t,r,i):new t(0):new t(NaN):e.isZero()?Xn(t,r+4,i).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=i,e.times(2))};ie.inverseHyperbolicCosine=ie.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,Te=!1,n=n.times(n).minus(1).sqrt().plus(n),Te=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};ie.inverseHyperbolicSine=ie.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,Te=!1,n=n.times(n).plus(1).sqrt().plus(n),Te=!0,r.precision=e,r.rounding=t,n.ln())};ie.inverseHyperbolicTangent=ie.atanh=function(){var e,t,n,r,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=s.precision,t=s.rounding,r=i.sd(),Math.max(r,e)<2*-i.e-1?we(new s(i),e,t,!0):(s.precision=n=r-i.e,i=De(i.plus(1),new s(1).minus(i),n+e,1),s.precision=e+4,s.rounding=1,i=i.ln(),s.precision=e,s.rounding=t,i.times(.5))):new s(NaN)};ie.inverseSine=ie.asin=function(){var e,t,n,r,i=this,s=i.constructor;return i.isZero()?new s(i):(t=i.abs().cmp(1),n=s.precision,r=s.rounding,t!==-1?t===0?(e=Xn(s,n+4,r).times(.5),e.s=i.s,e):new s(NaN):(s.precision=n+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=n,s.rounding=r,i.times(2)))};ie.inverseTangent=ie.atan=function(){var e,t,n,r,i,s,o,c,a,u=this,f=u.constructor,l=f.precision,p=f.rounding;if(u.isFinite()){if(u.isZero())return new f(u);if(u.abs().eq(1)&&l+4<=zf)return o=Xn(f,l+4,p).times(.25),o.s=u.s,o}else{if(!u.s)return new f(NaN);if(l+4<=zf)return o=Xn(f,l+4,p).times(.5),o.s=u.s,o}for(f.precision=c=l+10,f.rounding=1,n=Math.min(28,c/be+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(Te=!1,t=Math.ceil(c/be),r=1,a=u.times(u),o=new f(u),i=u;e!==-1;)if(i=i.times(a),s=o.minus(i.div(r+=2)),i=i.times(a),o=s.plus(i.div(r+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===s.d[e]&&e--;);return n&&(o=o.times(2<<n-1)),Te=!0,we(o,f.precision=l,f.rounding=p,!0)};ie.isFinite=function(){return!!this.d};ie.isInteger=ie.isInt=function(){return!!this.d&&Kt(this.e/be)>this.d.length-2};ie.isNaN=function(){return!this.s};ie.isNegative=ie.isNeg=function(){return this.s<0};ie.isPositive=ie.isPos=function(){return this.s>0};ie.isZero=function(){return!!this.d&&this.d[0]===0};ie.lessThan=ie.lt=function(e){return this.cmp(e)<0};ie.lessThanOrEqualTo=ie.lte=function(e){return this.cmp(e)<1};ie.logarithm=ie.log=function(e){var t,n,r,i,s,o,c,a,u=this,f=u.constructor,l=f.precision,p=f.rounding,y=5;if(e==null)e=new f(10),t=!0;else{if(e=new f(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new f(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new f(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)s=!0;else{for(i=n[0];i%10===0;)i/=10;s=i!==1}if(Te=!1,c=l+y,o=Qr(u,c),r=t?Aa(f,c+10):Qr(e,c),a=De(o,r,c,1),Po(a.d,i=l,p))do if(c+=10,o=Qr(u,c),r=t?Aa(f,c+10):Qr(e,c),a=De(o,r,c,1),!s){+kt(a.d).slice(i+1,i+15)+1==1e14&&(a=we(a,l+1,0));break}while(Po(a.d,i+=10,p));return Te=!0,we(a,l,p)};ie.minus=ie.sub=function(e){var t,n,r,i,s,o,c,a,u,f,l,p,y=this,g=y.constructor;if(e=new g(e),!y.d||!e.d)return!y.s||!e.s?e=new g(NaN):y.d?e.s=-e.s:e=new g(e.d||y.s!==e.s?y:NaN),e;if(y.s!=e.s)return e.s=-e.s,y.plus(e);if(u=y.d,p=e.d,c=g.precision,a=g.rounding,!u[0]||!p[0]){if(p[0])e.s=-e.s;else if(u[0])e=new g(y);else return new g(a===3?-0:0);return Te?we(e,c,a):e}if(n=Kt(e.e/be),f=Kt(y.e/be),u=u.slice(),s=f-n,s){for(l=s<0,l?(t=u,s=-s,o=p.length):(t=p,n=f,o=u.length),r=Math.max(Math.ceil(c/be),o)+2,s>r&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for(r=u.length,o=p.length,l=r<o,l&&(o=r),r=0;r<o;r++)if(u[r]!=p[r]){l=u[r]<p[r];break}s=0}for(l&&(t=u,u=p,p=t,e.s=-e.s),o=u.length,r=p.length-o;r>0;--r)u[o++]=0;for(r=p.length;r>s;){if(u[--r]<p[r]){for(i=r;i&&u[--i]===0;)u[i]=Fn-1;--u[i],u[r]+=Fn}u[r]-=p[r]}for(;u[--o]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=cu(u,n),Te?we(e,c,a):e):new g(a===3?-0:0)};ie.modulo=ie.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?we(new r(n),r.precision,r.rounding):(Te=!1,r.modulo==9?(t=De(n,e.abs(),0,3,1),t.s*=e.s):t=De(n,e,0,r.modulo,1),t=t.times(e),Te=!0,n.minus(t))};ie.naturalExponential=ie.exp=function(){return Yf(this)};ie.naturalLogarithm=ie.ln=function(){return Qr(this)};ie.negated=ie.neg=function(){var e=new this.constructor(this);return e.s=-e.s,we(e)};ie.plus=ie.add=function(e){var t,n,r,i,s,o,c,a,u,f,l=this,p=l.constructor;if(e=new p(e),!l.d||!e.d)return!l.s||!e.s?e=new p(NaN):l.d||(e=new p(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(u=l.d,f=e.d,c=p.precision,a=p.rounding,!u[0]||!f[0])return f[0]||(e=new p(l)),Te?we(e,c,a):e;if(s=Kt(l.e/be),r=Kt(e.e/be),u=u.slice(),i=s-r,i){for(i<0?(n=u,i=-i,o=f.length):(n=f,r=s,o=u.length),s=Math.ceil(c/be),o=s>o?s+1:o+1,i>o&&(i=o,n.length=1),n.reverse();i--;)n.push(0);n.reverse()}for(o=u.length,i=f.length,o-i<0&&(i=o,n=f,f=u,u=n),t=0;i;)t=(u[--i]=u[i]+f[i]+t)/Fn|0,u[i]%=Fn;for(t&&(u.unshift(t),++r),o=u.length;u[--o]==0;)u.pop();return e.d=u,e.e=cu(u,r),Te?we(e,c,a):e};ie.precision=ie.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(oi+e);return n.d?(t=yw(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};ie.round=function(){var e=this,t=e.constructor;return we(new t(e),e.e+1,t.rounding)};ie.sine=ie.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+be,r.rounding=1,n=jx(r,bw(r,n)),r.precision=e,r.rounding=t,we(gr>2?n.neg():n,e,t,!0)):new r(NaN)};ie.squareRoot=ie.sqrt=function(){var e,t,n,r,i,s,o=this,c=o.d,a=o.e,u=o.s,f=o.constructor;if(u!==1||!c||!c[0])return new f(!u||u<0&&(!c||c[0])?NaN:c?o:1/0);for(Te=!1,u=Math.sqrt(+o),u==0||u==1/0?(t=kt(c),(t.length+a)%2==0&&(t+="0"),u=Math.sqrt(t),a=Kt((a+1)/2)-(a<0||a%2),u==1/0?t="5e"+a:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+a),r=new f(t)):r=new f(u.toString()),n=(a=f.precision)+3;;)if(s=r,r=s.plus(De(o,s,n+2,1)).times(.5),kt(s.d).slice(0,n)===(t=kt(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!i&&t=="4999"){if(!i&&(we(s,a+1,0),s.times(s).eq(o))){r=s;break}n+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(we(r,a+1,1),e=!r.times(r).eq(o));break}return Te=!0,we(r,a,f.rounding,e)};ie.tangent=ie.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=De(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,we(gr==2||gr==4?n.neg():n,e,t,!0)):new r(NaN)};ie.times=ie.mul=function(e){var t,n,r,i,s,o,c,a,u,f=this,l=f.constructor,p=f.d,y=(e=new l(e)).d;if(e.s*=f.s,!p||!p[0]||!y||!y[0])return new l(!e.s||p&&!p[0]&&!y||y&&!y[0]&&!p?NaN:!p||!y?e.s/0:e.s*0);for(n=Kt(f.e/be)+Kt(e.e/be),a=p.length,u=y.length,a<u&&(s=p,p=y,y=s,o=a,a=u,u=o),s=[],o=a+u,r=o;r--;)s.push(0);for(r=u;--r>=0;){for(t=0,i=a+r;i>r;)c=s[i]+y[r]*p[i-r-1]+t,s[i--]=c%Fn|0,t=c/Fn|0;s[i]=(s[i]+t)%Fn|0}for(;!s[--o];)s.pop();return t?++n:s.shift(),e.d=s,e.e=cu(s,n),Te?we(e,l.precision,l.rounding):e};ie.toBinary=function(e,t){return th(this,2,e,t)};ie.toDecimalPlaces=ie.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(fn(e,0,fi),t===void 0?t=r.rounding:fn(t,0,8),we(n,e+n.e+1,t))};ie.toExponential=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Zn(r,!0):(fn(e,0,fi),t===void 0?t=i.rounding:fn(t,0,8),r=we(new i(r),e+1,t),n=Zn(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};ie.toFixed=function(e,t){var n,r,i=this,s=i.constructor;return e===void 0?n=Zn(i):(fn(e,0,fi),t===void 0?t=s.rounding:fn(t,0,8),r=we(new s(i),e+i.e+1,t),n=Zn(r,!1,e+r.e+1)),i.isNeg()&&!i.isZero()?"-"+n:n};ie.toFraction=function(e){var t,n,r,i,s,o,c,a,u,f,l,p,y=this,g=y.d,w=y.constructor;if(!g)return new w(y);if(u=n=new w(1),r=a=new w(0),t=new w(r),s=t.e=yw(g)-y.e-1,o=s%be,t.d[0]=bt(10,o<0?be+o:o),e==null)e=s>0?t:u;else{if(c=new w(e),!c.isInt()||c.lt(u))throw Error(oi+c);e=c.gt(t)?s>0?t:u:c}for(Te=!1,c=new w(kt(g)),f=w.precision,w.precision=s=g.length*be*2;l=De(c,t,0,1,1),i=n.plus(l.times(r)),i.cmp(e)!=1;)n=r,r=i,i=u,u=a.plus(l.times(i)),a=i,i=t,t=c.minus(l.times(i)),c=i;return i=De(e.minus(n),r,0,1,1),a=a.plus(i.times(u)),n=n.plus(i.times(r)),a.s=u.s=y.s,p=De(u,r,s,1).minus(y).abs().cmp(De(a,n,s,1).minus(y).abs())<1?[u,r]:[a,n],w.precision=f,Te=!0,p};ie.toHexadecimal=ie.toHex=function(e,t){return th(this,16,e,t)};ie.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:fn(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(Te=!1,n=De(n,e,0,t,1).times(e),Te=!0,we(n)):(e.s=n.s,n=e),n};ie.toNumber=function(){return+this};ie.toOctal=function(e,t){return th(this,8,e,t)};ie.toPower=ie.pow=function(e){var t,n,r,i,s,o,c=this,a=c.constructor,u=+(e=new a(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new a(bt(+c,u));if(c=new a(c),c.eq(1))return c;if(r=a.precision,s=a.rounding,e.eq(1))return we(c,r,s);if(t=Kt(e.e/be),t>=e.d.length-1&&(n=u<0?-u:u)<=Vx)return i=gw(a,c,n,r),e.s<0?new a(1).div(i):we(i,r,s);if(o=c.s,o<0){if(t<e.d.length-1)return new a(NaN);if((e.d[t]&1)==0&&(o=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=o,c}return n=bt(+c,u),t=n==0||!isFinite(n)?Kt(u*(Math.log("0."+kt(c.d))/Math.LN10+c.e+1)):new a(n+"").e,t>a.maxE+1||t<a.minE-1?new a(t>0?o/0:0):(Te=!1,a.rounding=c.s=1,n=Math.min(12,(t+"").length),i=Yf(e.times(Qr(c,r+n)),r),i.d&&(i=we(i,r+5,1),Po(i.d,r,s)&&(t=r+10,i=we(Yf(e.times(Qr(c,t+n)),t),t+5,1),+kt(i.d).slice(r+1,r+15)+1==1e14&&(i=we(i,r+1,0)))),i.s=o,Te=!0,a.rounding=s,we(i,r,s))};ie.toPrecision=function(e,t){var n,r=this,i=r.constructor;return e===void 0?n=Zn(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(fn(e,1,fi),t===void 0?t=i.rounding:fn(t,0,8),r=we(new i(r),e,t),n=Zn(r,e<=r.e||r.e<=i.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};ie.toSignificantDigits=ie.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(fn(e,1,fi),t===void 0?t=r.rounding:fn(t,0,8)),we(new r(n),e,t)};ie.toString=function(){var e=this,t=e.constructor,n=Zn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};ie.truncated=ie.trunc=function(){return we(new this.constructor(this),this.e+1,1)};ie.valueOf=ie.toJSON=function(){var e=this,t=e.constructor,n=Zn(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function kt(e){var t,n,r,i=e.length-1,s="",o=e[0];if(i>0){for(s+=o,t=1;t<i;t++)r=e[t]+"",n=be-r.length,n&&(s+=Yr(n)),s+=r;o=e[t],r=o+"",n=be-r.length,n&&(s+=Yr(n))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function fn(e,t,n){if(e!==~~e||e<t||e>n)throw Error(oi+e)}function Po(e,t,n,r){var i,s,o,c;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=be,i=0):(i=Math.ceil((t+1)/be),t%=be),s=bt(10,be-t),c=e[i]%s|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),o=n<4&&c==99999||n>3&&c==49999||c==5e4||c==0):o=(n<4&&c+1==s||n>3&&c+1==s/2)&&(e[i+1]/s/100|0)==bt(10,t-2)-1||(c==s/2||c==0)&&(e[i+1]/s/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),o=(r||n<4)&&c==9999||!r&&n>3&&c==4999):o=((r||n<4)&&c+1==s||!r&&n>3&&c+1==s/2)&&(e[i+1]/s/1e3|0)==bt(10,t-3)-1,o}function Lc(e,t,n){for(var r,i=[0],s,o=0,c=e.length;o<c;){for(s=i.length;s--;)i[s]*=t;for(i[0]+=Df.indexOf(e.charAt(o++)),r=0;r<i.length;r++)i[r]>n-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function Kx(e,t){var n,r,i;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),i=(1/au(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),e.precision+=n,t=vs(e,1,t.times(i),new e(1));for(var s=n;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=n,t}var De=(function(){function e(r,i,s){var o,c=0,a=r.length;for(r=r.slice();a--;)o=r[a]*i+c,r[a]=o%s|0,c=o/s|0;return c&&r.unshift(c),r}function t(r,i,s,o){var c,a;if(s!=o)a=s>o?1:-1;else for(c=a=0;c<s;c++)if(r[c]!=i[c]){a=r[c]>i[c]?1:-1;break}return a}function n(r,i,s,o){for(var c=0;s--;)r[s]-=c,c=r[s]<i[s]?1:0,r[s]=c*o+r[s]-i[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,s,o,c,a){var u,f,l,p,y,g,w,E,_,S,m,T,I,A,U,M,v,R,V,W,H=r.constructor,K=r.s==i.s?1:-1,N=r.d,L=i.d;if(!N||!N[0]||!L||!L[0])return new H(!r.s||!i.s||(N?L&&N[0]==L[0]:!L)?NaN:N&&N[0]==0||!L?K*0:K/0);for(a?(y=1,f=r.e-i.e):(a=Fn,y=be,f=Kt(r.e/y)-Kt(i.e/y)),V=L.length,v=N.length,_=new H(K),S=_.d=[],l=0;L[l]==(N[l]||0);l++);if(L[l]>(N[l]||0)&&f--,s==null?(A=s=H.precision,o=H.rounding):c?A=s+(r.e-i.e)+1:A=s,A<0)S.push(1),g=!0;else{if(A=A/y+2|0,l=0,V==1){for(p=0,L=L[0],A++;(l<v||p)&&A--;l++)U=p*a+(N[l]||0),S[l]=U/L|0,p=U%L|0;g=p||l<v}else{for(p=a/(L[0]+1)|0,p>1&&(L=e(L,p,a),N=e(N,p,a),V=L.length,v=N.length),M=V,m=N.slice(0,V),T=m.length;T<V;)m[T++]=0;W=L.slice(),W.unshift(0),R=L[0],L[1]>=a/2&&++R;do p=0,u=t(L,m,V,T),u<0?(I=m[0],V!=T&&(I=I*a+(m[1]||0)),p=I/R|0,p>1?(p>=a&&(p=a-1),w=e(L,p,a),E=w.length,T=m.length,u=t(w,m,E,T),u==1&&(p--,n(w,V<E?W:L,E,a))):(p==0&&(u=p=1),w=L.slice()),E=w.length,E<T&&w.unshift(0),n(m,w,T,a),u==-1&&(T=m.length,u=t(L,m,V,T),u<1&&(p++,n(m,V<T?W:L,T,a))),T=m.length):u===0&&(p++,m=[0]),S[l++]=p,u&&m[0]?m[T++]=N[M]||0:(m=[N[M]],T=1);while((M++<v||m[0]!==void 0)&&A--);g=m[0]!==void 0}S[0]||S.shift()}if(y==1)_.e=f,fw=g;else{for(l=1,p=S[0];p>=10;p/=10)l++;_.e=l+f*y-1,we(_,c?s+_.e+1:s,o,g)}return _}})();function we(e,t,n,r){var i,s,o,c,a,u,f,l,p,y=e.constructor;e:if(t!=null){if(l=e.d,!l)return e;for(i=1,c=l[0];c>=10;c/=10)i++;if(s=t-i,s<0)s+=be,o=t,f=l[p=0],a=f/bt(10,i-o-1)%10|0;else if(p=Math.ceil((s+1)/be),c=l.length,p>=c)if(r){for(;c++<=p;)l.push(0);f=a=0,i=1,s%=be,o=s-be+1}else break e;else{for(f=c=l[p],i=1;c>=10;c/=10)i++;s%=be,o=s-be+i,a=o<0?0:f/bt(10,i-o-1)%10|0}if(r=r||t<0||l[p+1]!==void 0||(o<0?f:f%bt(10,i-o-1)),u=n<4?(a||r)&&(n==0||n==(e.s<0?3:2)):a>5||a==5&&(n==4||r||n==6&&(s>0?o>0?f/bt(10,i-o):0:l[p-1])%10&1||n==(e.s<0?8:7)),t<1||!l[0])return l.length=0,u?(t-=e.e+1,l[0]=bt(10,(be-t%be)%be),e.e=-t||0):l[0]=e.e=0,e;if(s==0?(l.length=p,c=1,p--):(l.length=p+1,c=bt(10,be-s),l[p]=o>0?(f/bt(10,i-o)%bt(10,o)|0)*c:0),u)for(;;)if(p==0){for(s=1,o=l[0];o>=10;o/=10)s++;for(o=l[0]+=c,c=1;o>=10;o/=10)c++;s!=c&&(e.e++,l[0]==Fn&&(l[0]=1));break}else{if(l[p]+=c,l[p]!=Fn)break;l[p--]=0,c=1}for(s=l.length;l[--s]===0;)l.pop()}return Te&&(e.e>y.maxE?(e.d=null,e.e=NaN):e.e<y.minE&&(e.e=0,e.d=[0])),e}function Zn(e,t,n){if(!e.isFinite())return mw(e);var r,i=e.e,s=kt(e.d),o=s.length;return t?(n&&(r=n-o)>0?s=s.charAt(0)+"."+s.slice(1)+Yr(r):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):i<0?(s="0."+Yr(-i-1)+s,n&&(r=n-o)>0&&(s+=Yr(r))):i>=o?(s+=Yr(i+1-o),n&&(r=n-i-1)>0&&(s=s+"."+Yr(r))):((r=i+1)<o&&(s=s.slice(0,r)+"."+s.slice(r)),n&&(r=n-o)>0&&(i+1===o&&(s+="."),s+=Yr(r))),s}function cu(e,t){var n=e[0];for(t*=be;n>=10;n/=10)t++;return t}function Aa(e,t,n){if(t>$x)throw Te=!0,n&&(e.precision=n),Error(lw);return we(new e(Ta),t,1,!0)}function Xn(e,t,n){if(t>zf)throw Error(lw);return we(new e(xa),t,n,!0)}function yw(e){var t=e.length-1,n=t*be+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function Yr(e){for(var t="";e--;)t+="0";return t}function gw(e,t,n,r){var i,s=new e(1),o=Math.ceil(r/be+4);for(Te=!1;;){if(n%2&&(s=s.times(t),qp(s.d,o)&&(i=!0)),n=Kt(n/2),n===0){n=s.d.length-1,i&&s.d[n]===0&&++s.d[n];break}t=t.times(t),qp(t.d,o)}return Te=!0,s}function Mp(e){return e.d[e.d.length-1]&1}function ww(e,t,n){for(var r,i,s=new e(t[0]),o=0;++o<t.length;){if(i=new e(t[o]),!i.s){s=i;break}r=s.cmp(i),(r===n||r===0&&s.s===n)&&(s=i)}return s}function Yf(e,t){var n,r,i,s,o,c,a,u=0,f=0,l=0,p=e.constructor,y=p.rounding,g=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(t==null?(Te=!1,a=g):a=t,c=new p(.03125);e.e>-2;)e=e.times(c),l+=5;for(r=Math.log(bt(2,l))/Math.LN10*2+5|0,a+=r,n=s=o=new p(1),p.precision=a;;){if(s=we(s.times(e),a,1),n=n.times(++f),c=o.plus(De(s,n,a,1)),kt(c.d).slice(0,a)===kt(o.d).slice(0,a)){for(i=l;i--;)o=we(o.times(o),a,1);if(t==null)if(u<3&&Po(o.d,a-r,y,u))p.precision=a+=10,n=s=c=new p(1),f=0,u++;else return we(o,p.precision=g,y,Te=!0);else return p.precision=g,o}o=c}}function Qr(e,t){var n,r,i,s,o,c,a,u,f,l,p,y=1,g=10,w=e,E=w.d,_=w.constructor,S=_.rounding,m=_.precision;if(w.s<0||!E||!E[0]||!w.e&&E[0]==1&&E.length==1)return new _(E&&!E[0]?-1/0:w.s!=1?NaN:E?0:w);if(t==null?(Te=!1,f=m):f=t,_.precision=f+=g,n=kt(E),r=n.charAt(0),Math.abs(s=w.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)w=w.times(e),n=kt(w.d),r=n.charAt(0),y++;s=w.e,r>1?(w=new _("0."+n),s++):w=new _(r+"."+n.slice(1))}else return u=Aa(_,f+2,m).times(s+""),w=Qr(new _(r+"."+n.slice(1)),f-g).plus(u),_.precision=m,t==null?we(w,m,S,Te=!0):w;for(l=w,a=o=w=De(w.minus(1),w.plus(1),f,1),p=we(w.times(w),f,1),i=3;;){if(o=we(o.times(p),f,1),u=a.plus(De(o,new _(i),f,1)),kt(u.d).slice(0,f)===kt(a.d).slice(0,f))if(a=a.times(2),s!==0&&(a=a.plus(Aa(_,f+2,m).times(s+""))),a=De(a,new _(y),f,1),t==null)if(Po(a.d,f-g,S,c))_.precision=f+=g,u=o=w=De(l.minus(1),l.plus(1),f,1),p=we(w.times(w),f,1),i=c=1;else return we(a,_.precision=m,S,Te=!0);else return _.precision=m,a;a=u,i+=2}}function mw(e){return String(e.s*e.s/0)}function jc(e,t){var n,r,i;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(r,i),t){if(i-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%be,n<0&&(r+=be),r<i){for(r&&e.d.push(+t.slice(0,r)),i-=be;r<i;)e.d.push(+t.slice(r,r+=be));t=t.slice(r),r=be-t.length}else r-=i;for(;r--;)t+="0";e.d.push(+t),Te&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Lx(e,t){var n,r,i,s,o,c,a,u,f;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),pw.test(t))return jc(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Mx.test(t))n=16,t=t.toLowerCase();else if(Fx.test(t))n=2;else if(qx.test(t))n=8;else throw Error(oi+t);for(s=t.search(/p/i),s>0?(a=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),o=s>=0,r=e.constructor,o&&(t=t.replace(".",""),c=t.length,s=c-s,i=gw(r,new r(n),s,s*2)),u=Lc(t,n,Fn),f=u.length-1,s=f;u[s]===0;--s)u.pop();return s<0?new r(e.s*0):(e.e=cu(u,f),e.d=u,Te=!1,o&&(e=De(e,i,c*4)),a&&(e=e.times(Math.abs(a)<54?bt(2,a):ei.pow(2,a))),Te=!0,e)}function jx(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:vs(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/au(5,n)),t=vs(e,2,t,t);for(var i,s=new e(5),o=new e(16),c=new e(20);n--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(c))));return t}function vs(e,t,n,r,i){var s,o,c,a,u=e.precision,f=Math.ceil(u/be);for(Te=!1,a=n.times(n),c=new e(r);;){if(o=De(c.times(a),new e(t++*t++),u,1),c=i?r.plus(o):r.minus(o),r=De(o.times(a),new e(t++*t++),u,1),o=c.plus(r),o.d[f]!==void 0){for(s=f;o.d[s]===c.d[s]&&s--;);if(s==-1)break}s=c,c=r,r=o,o=s}return Te=!0,o.d.length=f+1,o}function au(e,t){for(var n=e;--t;)n*=e;return n}function bw(e,t){var n,r=t.s<0,i=Xn(e,e.precision,1),s=i.times(.5);if(t=t.abs(),t.lte(s))return gr=r?4:1,t;if(n=t.divToInt(i),n.isZero())gr=r?3:2;else{if(t=t.minus(n.times(i)),t.lte(s))return gr=Mp(n)?r?2:3:r?4:1,t;gr=Mp(n)?r?1:4:r?3:2}return t.minus(i).abs()}function th(e,t,n,r){var i,s,o,c,a,u,f,l,p,y=e.constructor,g=n!==void 0;if(g?(fn(n,1,fi),r===void 0?r=y.rounding:fn(r,0,8)):(n=y.precision,r=y.rounding),!e.isFinite())f=mw(e);else{for(f=Zn(e),o=f.indexOf("."),g?(i=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):i=t,o>=0&&(f=f.replace(".",""),p=new y(1),p.e=f.length-o,p.d=Lc(Zn(p),10,i),p.e=p.d.length),l=Lc(f,10,i),s=a=l.length;l[--a]==0;)l.pop();if(!l[0])f=g?"0p+0":"0";else{if(o<0?s--:(e=new y(e),e.d=l,e.e=s,e=De(e,p,n,r,0,i),l=e.d,s=e.e,u=fw),o=l[n],c=i/2,u=u||l[n+1]!==void 0,u=r<4?(o!==void 0||u)&&(r===0||r===(e.s<0?3:2)):o>c||o===c&&(r===4||u||r===6&&l[n-1]&1||r===(e.s<0?8:7)),l.length=n,u)for(;++l[--n]>i-1;)l[n]=0,n||(++s,l.unshift(1));for(a=l.length;!l[a-1];--a);for(o=0,f="";o<a;o++)f+=Df.charAt(l[o]);if(g){if(a>1)if(t==16||t==8){for(o=t==16?4:3,--a;a%o;a++)f+="0";for(l=Lc(f,i,t),a=l.length;!l[a-1];--a);for(o=1,f="1.";o<a;o++)f+=Df.charAt(l[o])}else f=f.charAt(0)+"."+f.slice(1);f=f+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)f="0"+f;f="0."+f}else if(++s>a)for(s-=a;s--;)f+="0";else s<a&&(f=f.slice(0,s)+"."+f.slice(s))}f=(t==16?"0x":t==2?"0b":t==8?"0o":"")+f}return e.s<0?"-"+f:f}function qp(e,t){if(e.length>t)return e.length=t,!0}function Wx(e){return new this(e).abs()}function Gx(e){return new this(e).acos()}function Dx(e){return new this(e).acosh()}function Xx(e,t){return new this(e).plus(t)}function zx(e){return new this(e).asin()}function Yx(e){return new this(e).asinh()}function Zx(e){return new this(e).atan()}function Jx(e){return new this(e).atanh()}function Qx(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,s=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=Xn(this,s,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Xn(this,r,i):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Xn(this,s,1).times(.5),n.s=e.s):t.s<0?(this.precision=s,this.rounding=1,n=this.atan(De(e,t,s,1)),t=Xn(this,s,1),this.precision=r,this.rounding=i,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(De(e,t,s,1)),n}function e6(e){return new this(e).cbrt()}function t6(e){return we(e=new this(e),e.e+1,2)}function n6(e,t,n){return new this(e).clamp(t,n)}function r6(e){if(!e||typeof e!="object")throw Error(ou+"Object expected");var t,n,r,i=e.defaults===!0,s=["precision",1,fi,"rounding",0,8,"toExpNeg",-us,0,"toExpPos",0,us,"maxE",0,us,"minE",-us,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(n=s[t],i&&(this[n]=Xf[n]),(r=e[n])!==void 0)if(Kt(r)===r&&r>=s[t+1]&&r<=s[t+2])this[n]=r;else throw Error(oi+n+": "+r);if(n="crypto",i&&(this[n]=Xf[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(hw);else this[n]=!1;else throw Error(oi+n+": "+r);return this}function i6(e){return new this(e).cos()}function s6(e){return new this(e).cosh()}function Ew(e){var t,n,r;function i(s){var o,c,a,u=this;if(!(u instanceof i))return new i(s);if(u.constructor=i,Vp(s)){u.s=s.s,Te?!s.d||s.e>i.maxE?(u.e=NaN,u.d=null):s.e<i.minE?(u.e=0,u.d=[0]):(u.e=s.e,u.d=s.d.slice()):(u.e=s.e,u.d=s.d?s.d.slice():s.d);return}if(a=typeof s,a==="number"){if(s===0){u.s=1/s<0?-1:1,u.e=0,u.d=[0];return}if(s<0?(s=-s,u.s=-1):u.s=1,s===~~s&&s<1e7){for(o=0,c=s;c>=10;c/=10)o++;Te?o>i.maxE?(u.e=NaN,u.d=null):o<i.minE?(u.e=0,u.d=[0]):(u.e=o,u.d=[s]):(u.e=o,u.d=[s]);return}if(s*0!==0){s||(u.s=NaN),u.e=NaN,u.d=null;return}return jc(u,s.toString())}if(a==="string")return(c=s.charCodeAt(0))===45?(s=s.slice(1),u.s=-1):(c===43&&(s=s.slice(1)),u.s=1),pw.test(s)?jc(u,s):Lx(u,s);if(a==="bigint")return s<0?(s=-s,u.s=-1):u.s=1,jc(u,s.toString());throw Error(oi+s)}if(i.prototype=ie,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=r6,i.clone=Ew,i.isDecimal=Vp,i.abs=Wx,i.acos=Gx,i.acosh=Dx,i.add=Xx,i.asin=zx,i.asinh=Yx,i.atan=Zx,i.atanh=Jx,i.atan2=Qx,i.cbrt=e6,i.ceil=t6,i.clamp=n6,i.cos=i6,i.cosh=s6,i.div=o6,i.exp=c6,i.floor=a6,i.hypot=u6,i.ln=f6,i.log=l6,i.log10=d6,i.log2=h6,i.max=p6,i.min=y6,i.mod=g6,i.mul=w6,i.pow=m6,i.random=b6,i.round=E6,i.sign=_6,i.sin=S6,i.sinh=T6,i.sqrt=x6,i.sub=A6,i.sum=v6,i.tan=B6,i.tanh=I6,i.trunc=O6,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return i.config(e),i}function o6(e,t){return new this(e).div(t)}function c6(e){return new this(e).exp()}function a6(e){return we(e=new this(e),e.e+1,3)}function u6(){var e,t,n=new this(0);for(Te=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return Te=!0,new this(1/0);n=t}return Te=!0,n.sqrt()}function Vp(e){return e instanceof ei||e&&e.toStringTag===dw||!1}function f6(e){return new this(e).ln()}function l6(e,t){return new this(e).log(t)}function h6(e){return new this(e).log(2)}function d6(e){return new this(e).log(10)}function p6(){return ww(this,arguments,-1)}function y6(){return ww(this,arguments,1)}function g6(e,t){return new this(e).mod(t)}function w6(e,t){return new this(e).mul(t)}function m6(e,t){return new this(e).pow(t)}function b6(e){var t,n,r,i,s=0,o=new this(1),c=[];if(e===void 0?e=this.precision:fn(e,1,fi),r=Math.ceil(e/be),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));s<r;)i=t[s],i>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:c[s++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);s<r;)i=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,s):(c.push(i%1e7),s+=4);s=r/4}else throw Error(hw);else for(;s<r;)c[s++]=Math.random()*1e7|0;for(r=c[--s],e%=be,r&&e&&(i=bt(10,be-e),c[s]=(r/i|0)*i);c[s]===0;s--)c.pop();if(s<0)n=0,c=[0];else{for(n=-1;c[0]===0;n-=be)c.shift();for(r=1,i=c[0];i>=10;i/=10)r++;r<be&&(n-=be-r)}return o.e=n,o.d=c,o}function E6(e){return we(e=new this(e),e.e+1,this.rounding)}function _6(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function S6(e){return new this(e).sin()}function T6(e){return new this(e).sinh()}function x6(e){return new this(e).sqrt()}function A6(e,t){return new this(e).sub(t)}function v6(){var e=0,t=arguments,n=new this(t[e]);for(Te=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return Te=!0,we(n,this.precision,this.rounding)}function B6(e){return new this(e).tan()}function I6(e){return new this(e).tanh()}function O6(e){return we(e=new this(e),e.e+1,1)}ie[Symbol.for("nodejs.util.inspect.custom")]=ie.toString;ie[Symbol.toStringTag]="Decimal";var ei=ie.constructor=Ew(Xf);Ta=new ei(Ta);xa=new ei(xa);const P6=({IDL:e})=>{const t=e.Record({exchange_id:e.Text,reason:e.Text}),n=e.Variant({Ok:e.Null,Err:e.Text}),r=e.Variant({P2WPKH:e.Null,OpReturn:e.Nat64,P2SH:e.Null,P2TR:e.Null}),i=e.Record({input_types:e.Vec(r),pool_address:e.Vec(e.Text),output_types:e.Vec(r)}),s=e.Variant({Ok:e.Nat64,Err:e.Text}),o=e.Record({user_id:e.Principal}),c=e.Record({canister_version:e.Opt(e.Nat64),canister_id:e.Principal}),a=e.Variant({from_user:o,from_canister:c}),u=e.Record({controllers:e.Vec(e.Principal)}),f=e.Variant({reinstall:e.Null,upgrade:e.Null,install:e.Null}),l=e.Record({mode:f,module_hash:e.Vec(e.Nat8)}),p=e.Record({canister_version:e.Nat64,taken_at_timestamp:e.Nat64,snapshot_id:e.Vec(e.Nat8)}),y=e.Variant({creation:u,code_deployment:l,load_snapshot:p,controllers_change:u,code_uninstall:e.Null}),g=e.Record({timestamp_nanos:e.Nat64,canister_version:e.Nat64,origin:a,details:y}),w=e.Record({controllers:e.Vec(e.Principal),module_hash:e.Opt(e.Vec(e.Nat8)),recent_changes:e.Vec(g),total_num_changes:e.Nat64}),E=e.Variant({Ok:w,Err:e.Text}),_=e.Record({exchange_id:e.Text,pool_address:e.Text,pool_key:e.Text}),S=e.Variant({All:e.Null,ByTxid:e.Text,ByStatusCode:e.Text,ByAddress:e.Text,BySecondsPassed:e.Nat64}),m=e.Variant({Ok:e.Text,Err:e.Text}),T=e.Record({result:m,exchange_id:e.Text,maybe_return_time:e.Opt(e.Text),calling_method:e.Text,calling_args:e.Text,pool_address:e.Text,calling_time:e.Text}),I=e.Record({rollback_results:e.Vec(e.Text),invoke_args:e.Text,invoke_time:e.Text,finalized_time:e.Opt(e.Text),confirmed_time:e.Opt(e.Text),execution_steps:e.Vec(T),processing_result:m,broadcasted_time:e.Opt(e.Text)}),A=e.Record({block_hash:e.Text,block_height:e.Nat32}),U=e.Record({processing_results:e.Vec(e.Text),block_basic:A,txids:e.Vec(e.Text),block_time:e.Text,received_time:e.Text}),M=e.Variant({Abandoned:e.Record({reason:e.Text}),Active:e.Null,Halted:e.Record({reason:e.Text})}),v=e.Record({status:M,exchange_id:e.Text,canister_id:e.Principal,utxo_proof_enabled:e.Bool,client_canisters:e.Vec(e.Principal)}),R=e.Record({rollback_results:e.Vec(e.Text),txid:e.Text,received_time:e.Text,reason:e.Text}),V=e.Variant({mainnet:e.Null,regtest:e.Null,testnet:e.Null}),W=e.Record({min_seconds_of_unconfirmed_tx_in_pool_for_raising_fee_rate:e.Nat32,exchange_registry_principal:e.Principal,max_input_count_of_psbt:e.Nat32,min_tx_confirmations:e.Nat32,mempool_connector_principal:e.Principal,max_unconfirmed_tx_count_in_pool:e.Nat32,min_btc_amount_for_utxo:e.Nat64,rune_indexer_principal:e.Principal,max_intentions_per_invoke:e.Nat32,mempool_connector_public_key:e.Text,max_received_blocks_count:e.Nat32,min_unconfirmed_tx_count_in_pool_for_raising_fee_rate:e.Nat32,bitcoin_network:V}),H=e.Record({low:e.Nat64,high:e.Nat64,update_time:e.Text,medium:e.Nat64}),K=e.Record({last_block:e.Opt(A),pending_tx_count:e.Nat64,mempool_tx_fee_rate:H,invoke_paused:e.Bool,concurrent_invoke_status:e.Text,last_block_time:e.Opt(e.Tuple(e.Nat64,e.Text)),failed_new_block_height:e.Opt(e.Tuple(e.Nat32,e.Text))}),N=e.Variant({Error:e.Null,AvailableUnconfirmed:e.Null,InvalidTxid:e.Null,InvalidVout:e.Null,SpentInMempool:e.Null,SpentOnChain:e.Null,AvailableConfirmed:e.Null}),L=e.Record({status:N,value:e.Opt(e.Text),txid:e.Text,vout:e.Nat32,ancestors:e.Opt(e.Nat32),address:e.Opt(e.Text)}),F=e.Record({id:e.Text,value:e.Nat}),x=e.Record({coins:e.Vec(F),sats:e.Nat64,txid:e.Text,vout:e.Nat32}),O=e.Record({status:e.Opt(L),coins:e.Vec(F),utxo:x,is_signed:e.Bool,owner_pubkey:e.Opt(e.Text),owner_address:e.Text}),q=e.Record({coins_in_inputs:e.Vec(O),txid:e.Text,signed_address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F))),address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F)))}),P=e.Record({is_op_return:e.Bool,utxo:x,owner_address:e.Opt(e.Text)}),$=e.Record({burned_coins:e.Vec(F),coins_in_outputs:e.Vec(P),address_coins:e.Vec(e.Tuple(e.Text,e.Vec(F)))}),G=e.Record({coin:F,from:e.Text}),X=e.Record({to:e.Text,coin:F}),Y=e.Record({input_coins:e.Vec(G),output_coins:e.Vec(X),action:e.Text,exchange_id:e.Text,pool_utxo_spent:e.Vec(e.Text),action_params:e.Text,nonce:e.Nat64,pool_address:e.Text,pool_utxo_received:e.Vec(x)}),oe=e.Record({tx_fee_in_sats:e.Nat64,initiator_address:e.Text,intentions:e.Vec(Y)}),ae=e.Record({applied_fee_rate:e.Nat64,pool_addresses:e.Vec(e.Text),coins_in_inputs:q,txid:e.Text,estimated_min_tx_fee:e.Nat64,actual_tx_fee:e.Nat64,coins_in_outputs:$,tx_vsize:e.Nat64,intention_set:oe,user_coins_in_inputs:e.Vec(F),initially_signed_addresses:e.Vec(e.Text)}),ee=e.Variant({Confirmed:e.Nat32,Rejected:e.Text,Pending:e.Null}),Z=e.Record({status:e.Opt(ee),invoke_log:I,included_block:e.Opt(A),sent_tx_hex:e.Text}),ce=e.Variant({Failed:I,NotFound:e.Null,Succeeded:Z}),ge=e.Record({maybe_rune:e.Opt(F),value:e.Nat64,script_pubkey_hex:e.Text,outpoint:e.Text}),pe=e.Record({client_info:e.Opt(e.Text),intention_set:oe,initiator_utxo_proof:e.Vec(e.Nat8),psbt_hex:e.Text}),J=e.Record({block_hash:e.Text,block_timestamp:e.Nat64,tx_ids:e.Vec(e.Text),block_height:e.Nat32}),fe=e.Variant({Ok:e.Vec(e.Text),Err:e.Text}),Se=e.Record({exchange_canister:e.Principal,exchange_id:e.Text,utxo_proof_enabled:e.Bool,client_canisters:e.Vec(e.Principal)}),Ce=e.Record({txid:e.Text,reason_code:e.Text,reason:e.Text}),Ze=e.Record({txid:e.Text,timestamp:e.Nat64,block:A}),st=e.Record({low:e.Nat64,high:e.Nat64,medium:e.Nat64});return e.Service({abandon_exchange:e.Func([t],[n],[]),clear_exchange_pools:e.Func([],[n],[]),clear_failed_invoke_logs:e.Func([e.Opt(e.Nat64),e.Vec(e.Text)],[n],[]),clear_last_block:e.Func([],[n],[]),clear_rejected_txs:e.Func([],[n],[]),clear_txs_with_min_confirmations:e.Func([e.Nat32],[n],[]),delete_tx_detail:e.Func([e.Text],[n],[]),delete_used_outpoints:e.Func([e.Text],[n],[]),estimate_min_tx_fee:e.Func([i],[s],["query"]),get_canister_info:e.Func([e.Nat64],[E],[]),get_exchange_pools:e.Func([e.Opt(e.Text)],[e.Vec(_)],["query"]),get_failed_invoke_logs:e.Func([S],[e.Vec(e.Tuple(e.Text,I))],["query"]),get_last_sent_txs:e.Func([],[e.Vec(e.Tuple(e.Text,e.Text,e.Opt(e.Nat32)))],["query"]),get_received_blocks:e.Func([e.Opt(e.Bool)],[e.Vec(U)],["query"]),get_registered_exchanges:e.Func([e.Opt(M)],[e.Vec(v)],["query"]),get_rejected_txs:e.Func([],[e.Vec(R)],["query"]),get_settings:e.Func([],[W],["query"]),get_status:e.Func([],[K],["query"]),get_tx_execution_context_view:e.Func([e.Text],[e.Opt(ae)],["query"]),get_tx_execution_result:e.Func([e.Text],[ce],["query"]),get_tx_for_outpoint:e.Func([e.Text],[e.Opt(Z)],["query"]),get_tx_queue_of_pool:e.Func([e.Text],[e.Vec(e.Tuple(e.Text,e.Opt(e.Nat32)))],["query"]),get_tx_sent:e.Func([e.Text],[e.Opt(Z)],["query"]),get_used_outpoints:e.Func([e.Opt(e.Text)],[e.Vec(e.Tuple(e.Text,e.Text))],["query"]),get_zero_confirmed_tx_count_of_pool:e.Func([e.Text],[e.Nat32],["query"]),get_zero_confirmed_txs:e.Func([e.Opt(e.Text)],[e.Vec(e.Text)],["query"]),get_zero_confirmed_utxos_of_address:e.Func([e.Text],[e.Vec(ge)],["query"]),init_status_code_message:e.Func([],[n],[]),inspect_status_code:e.Func([e.Text],[e.Text],["query"]),invoke:e.Func([pe],[m],[]),new_block_detected:e.Func([J],[n],[]),notify_exchange_for_blocks_from_height:e.Func([e.Text,e.Nat32],[fe],[]),notify_exchanges_for_block:e.Func([e.Vec(e.Text),A,e.Nat64,e.Vec(e.Text)],[fe],[]),pause_invoke:e.Func([],[n],[]),reapply_tx:e.Func([e.Text],[n],[]),register_exchange:e.Func([Se],[n],[]),reject_tx:e.Func([Ce],[n],[]),resume_invoke:e.Func([],[n],[]),rollback_tx:e.Func([e.Text],[fe],[]),save_included_block_for_tx:e.Func([Ze],[n],[]),set_bitcoin_network:e.Func([V],[n],[]),set_exchange_registry_principal:e.Func([e.Principal],[n],[]),set_max_input_count_of_psbt:e.Func([e.Nat32],[n],[]),set_max_intentions_per_invoke:e.Func([e.Nat32],[n],[]),set_max_received_blocks_count:e.Func([e.Nat32],[n],[]),set_max_unconfirmed_tx_count_in_pool:e.Func([e.Nat32],[n],[]),set_mempool_connector_principal:e.Func([e.Principal],[n],[]),set_mempool_connector_public_key:e.Func([e.Text],[n],[]),set_min_btc_amount_for_utxo:e.Func([e.Nat64],[n],[]),set_min_tx_confirmations:e.Func([e.Nat32],[n],[]),set_rune_indexer_principal:e.Func([e.Principal],[n],[]),set_tx_fee_per_vbyte:e.Func([st],[n],[]),unhalt_exchange:e.Func([e.Text],[n],[]),version:e.Func([],[e.Text],["query"])})};class k6{xverse;config;exchange;orchestrator;constructor(t){this.config=t;const n=t.network===Zo.Testnet,r=n?"https://api-testnet4.secretkeylabs.io":"https://api.secretkeylabs.io";this.xverse=new zS({baseUrl:r,apiKey:t.xverseApiKey});const i="https://icp0.io";this.exchange=ba.createActor(t.exchangeIdlFactory,{agent:yr.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:t.exchangeCanisterId}),this.orchestrator=ba.createActor(P6,{agent:yr.createSync({host:i,retryTimes:50,verifyQuerySignatures:!1}),canisterId:n?Rx:Ux})}async filterSpentUtxos(t,n){const r=await this.orchestrator.get_used_outpoints([t]);console.log(`[REE-SDK] filterSpentUtxos: address=${t}, utxos=${n.length}, usedOutpoints=${r.length}`,r.map(([s,o])=>`${s} (tx:${o})`));const i=n.filter(({txid:s,vout:o})=>r.findIndex(([c])=>`${s}:${o}`===c)<0);return i.length<n.length&&console.warn(`[REE-SDK] filterSpentUtxos: filtered out ${n.length-i.length} utxos`),i}async getPendingBtcUtxos(t){const n=await this.orchestrator.get_zero_confirmed_utxos_of_address(t),r=Zr(t);return n.filter(({maybe_rune:i})=>!i.length).map(({value:i,script_pubkey_hex:s,outpoint:o})=>{const[c,a]=o.split(":");return{txid:c,vout:Number(a),satoshis:i.toString(),scriptPk:s,addressType:r,address:t,runes:[]}})}async getPendingRuneUtxos(t,n){const r=await this.orchestrator.get_zero_confirmed_utxos_of_address(t),i=Zr(t);return r.filter(({maybe_rune:s})=>s.length).map(({value:s,script_pubkey_hex:o,outpoint:c,maybe_rune:a})=>{const[u,f]=c.split(":"),l=a[0];return{txid:u,vout:Number(f),satoshis:s.toString(),scriptPk:o,addressType:i,address:t,runes:l?[{id:l.id,amount:l.value.toString()}]:[],pubkey:n}})}async getBtcUtxos(t){let n=0;const r=60,i=[],s=await this.getPendingBtcUtxos(t);let o=!0;for(;o;){const u=await this.xverse.utxosByAddress(t,n,r);i.push(...u.items),o=u.hasMore,n+=r}const c=Sa(t,this.config.network),a=i.map(({txid:u,vout:f,value:l})=>({txid:u,vout:f,address:t,runes:[],satoshis:l.toString(),scriptPk:Ea(c)})).filter(u=>Number(u.satoshis)>546);return this.filterSpentUtxos(t,a.concat(s))}async getRuneUtxos(t,n,r){let i=0;const s=60,o=[],c=await this.getPendingRuneUtxos(t,r);console.log(`[REE-SDK] getRuneUtxos: address=${t}, runeId=${n}, pendingUtxos=${c.length}`);let a=!0;for(;a;){const p=await this.xverse.runeUtxosByAddress(t,n,i,s);console.log(`[REE-SDK] xverse.runeUtxosByAddress response: items=${p.items?.length}, hasMore=${p.hasMore}`),o.push(...p.items),a=p.hasMore,i+=s}const u=Sa(t,this.config.network),f=o.map(({txid:p,vout:y,runes:g,amount:w})=>({txid:p,vout:y,address:t,runes:g.map(({runeId:E,amount:_})=>{const S=new ei(_).toFixed(0);return{id:E,amount:S}}),satoshis:w.toString(),scriptPk:Ea(u),pubkey:r}));console.log(`[REE-SDK] getRuneUtxos: before filter=${f.length} xverse + ${c.length} pending`);const l=await this.filterSpentUtxos(t,f.concat(c));return console.log(`[REE-SDK] getRuneUtxos: after filterSpentUtxos=${l.length}`),l}async getBtcBalance(t){const r=(await this.getBtcUtxos(t)).reduce((i,s)=>i+BigInt(s.satoshis),BigInt(0));return new ei(r.toString()).div(1e8).toNumber()}async getRuneBalance(t,n,r){const i=await this.getRuneUtxos(t,n,r);if(!i)return;let s=new ei(0);for(const o of i)s=s.add(new ei(o.runes.find(c=>c.id===n)?.amount??0));return s.toNumber()}async getPoolList(){try{return await this.exchange.get_pool_list()??[]}catch(t){throw console.error("get pool list failed:",t),t}}async getPoolInfo(t){try{const n=await this.exchange.get_pool_info({pool_address:t});if(n.length===0)throw new Error("Pool not found");return n[0]}catch(n){throw console.error("get pool data failed:",n),n}}async createTransaction({address:t,paymentAddress:n,publicKey:r,paymentPublicKey:i,feeRate:s,mergeSelfRuneBtcOutputs:o,clientInfo:c,manualBuild:a}){return new Jr({network:this.config.network,exchangeId:this.config.exchangeId,address:t,paymentAddress:n,publicKey:r,paymentPublicKey:i,feeRate:s,mergeSelfRuneBtcOutputs:o,clientInfo:c,manualBuild:a},this)}async getRecommendedFeeRate(){const t=await this.orchestrator.get_status();return{min:Number(t.mempool_tx_fee_rate.medium),max:Number(t.mempool_tx_fee_rate.medium)*3}}}exports.Network=Zo;exports.ReeClient=k6;exports.Transaction=Jr;exports.utils=Nx;
|