@did-btcr2/method 0.62.0 → 0.64.0
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/README.md +14 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +3 -3
- package/dist/browser.mjs +3 -3
- package/dist/cjs/index.js +1269 -986
- package/dist/esm/core/beacon/signal-discovery.js +34 -1
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
- package/dist/esm/core/btcr2-update.js +11 -0
- package/dist/esm/core/btcr2-update.js.map +1 -1
- package/dist/esm/core/resolver.js +345 -252
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/esm/core/updater.js +33 -3
- package/dist/esm/core/updater.js.map +1 -1
- package/dist/esm/did-btcr2.js +53 -20
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/appendix.js +39 -2
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/error-cause.js +16 -0
- package/dist/esm/utils/error-cause.js.map +1 -0
- package/dist/types/core/beacon/interfaces.d.ts +9 -1
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +12 -0
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
- package/dist/types/core/btcr2-update.d.ts +15 -8
- package/dist/types/core/btcr2-update.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +16 -5
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolver.d.ts +37 -23
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +24 -3
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +24 -0
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/error-cause.d.ts +16 -0
- package/dist/types/utils/error-cause.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/core/beacon/interfaces.ts +10 -1
- package/src/core/beacon/signal-discovery.ts +44 -1
- package/src/core/btcr2-update.ts +20 -8
- package/src/core/interfaces.ts +16 -5
- package/src/core/resolver.ts +420 -315
- package/src/core/updater.ts +41 -3
- package/src/did-btcr2.ts +70 -25
- package/src/utils/appendix.ts +48 -2
- package/src/utils/error-cause.ts +23 -0
package/dist/browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var uB=Object.create;var ny=Object.defineProperty;var dB=Object.getOwnPropertyDescriptor;var fB=Object.getOwnPropertyNames;var lB=Object.getPrototypeOf,hB=Object.prototype.hasOwnProperty;var pB=(t,e)=>()=>(t&&(e=t(t=0)),e);var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Tf=(t,e)=>{for(var r in e)ny(t,r,{get:e[r],enumerable:!0})},yB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fB(e))!hB.call(t,i)&&i!==r&&ny(t,i,{get:()=>e[i],enumerable:!(n=dB(e,i))||n.enumerable});return t};var Mn=(t,e,r)=>(r=t!=null?uB(lB(t)):{},yB(e||!t||!t.__esModule?ny(r,"default",{value:t,enumerable:!0}):r,t));var cx=oe(_f=>{"use strict";l();_f.byteLength=mB;_f.toByteArray=bB;_f.fromByteArray=vB;var Kn=[],Gr=[],gB=typeof Uint8Array<"u"?Uint8Array:Array,iy="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ys=0,ox=iy.length;ys<ox;++ys)Kn[ys]=iy[ys],Gr[iy.charCodeAt(ys)]=ys;var ys,ox;Gr[45]=62;Gr[95]=63;function sx(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function mB(t){var e=sx(t),r=e[0],n=e[1];return(r+n)*3/4-n}function wB(t,e,r){return(e+r)*3/4-r}function bB(t){var e,r=sx(t),n=r[0],i=r[1],o=new gB(wB(t,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)e=Gr[t.charCodeAt(a)]<<18|Gr[t.charCodeAt(a+1)]<<12|Gr[t.charCodeAt(a+2)]<<6|Gr[t.charCodeAt(a+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Gr[t.charCodeAt(a)]<<2|Gr[t.charCodeAt(a+1)]>>4,o[s++]=e&255),i===1&&(e=Gr[t.charCodeAt(a)]<<10|Gr[t.charCodeAt(a+1)]<<4|Gr[t.charCodeAt(a+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function xB(t){return Kn[t>>18&63]+Kn[t>>12&63]+Kn[t>>6&63]+Kn[t&63]}function EB(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(xB(n));return i.join("")}function vB(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,c=r-n;s<c;s+=o)i.push(EB(t,s,s+o>c?c:s+o));return n===1?(e=t[r-1],i.push(Kn[e>>2]+Kn[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Kn[e>>10]+Kn[e>>4&63]+Kn[e<<2&63]+"=")),i.join("")}});var ax=oe(oy=>{l();oy.read=function(t,e,r,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,u=a>>1,d=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,o=p&(1<<-d)-1,p>>=-d,d+=c;d>0;o=o*256+t[e+f],f+=h,d-=8);for(s=o&(1<<-d)-1,o>>=-d,d+=n;d>0;s=s*256+t[e+f],f+=h,d-=8);if(o===0)o=1-u;else{if(o===a)return s?NaN:(p?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(p?-1:1)*s*Math.pow(2,o-n)};oy.write=function(t,e,r,n,i,o){var s,c,a,u=o*8-i-1,d=(1<<u)-1,f=d>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,g=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=d):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+f>=1?e+=h/a:e+=h*Math.pow(2,1-f),e*a>=2&&(s++,a/=2),s+f>=d?(c=0,s=d):s+f>=1?(c=(e*a-1)*Math.pow(2,i),s=s+f):(c=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=c&255,p+=g,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;t[r+p]=s&255,p+=g,s/=256,u-=8);t[r+p-g]|=y*128}});var Tr=oe(Oc=>{"use strict";l();var sy=cx(),Uc=ax(),ux=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Oc.Buffer=F;Oc.SlowBuffer=BB;Oc.INSPECT_MAX_BYTES=50;var If=2147483647;Oc.kMaxLength=If;F.TYPED_ARRAY_SUPPORT=SB();!F.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 SB(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(F.prototype,"parent",{enumerable:!0,get:function(){if(F.isBuffer(this))return this.buffer}});Object.defineProperty(F.prototype,"offset",{enumerable:!0,get:function(){if(F.isBuffer(this))return this.byteOffset}});function wi(t){if(t>If)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,F.prototype),e}function F(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return dy(t)}return lx(t,e,r)}F.poolSize=8192;function lx(t,e,r){if(typeof t=="string")return TB(t,e);if(ArrayBuffer.isView(t))return _B(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if($n(t,ArrayBuffer)||t&&$n(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&($n(t,SharedArrayBuffer)||t&&$n(t.buffer,SharedArrayBuffer)))return ay(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return F.from(n,e,r);var i=IB(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return F.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}F.from=function(t,e,r){return lx(t,e,r)};Object.setPrototypeOf(F.prototype,Uint8Array.prototype);Object.setPrototypeOf(F,Uint8Array);function hx(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function AB(t,e,r){return hx(t),t<=0?wi(t):e!==void 0?typeof r=="string"?wi(t).fill(e,r):wi(t).fill(e):wi(t)}F.alloc=function(t,e,r){return AB(t,e,r)};function dy(t){return hx(t),wi(t<0?0:fy(t)|0)}F.allocUnsafe=function(t){return dy(t)};F.allocUnsafeSlow=function(t){return dy(t)};function TB(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!F.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=px(t,e)|0,n=wi(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function cy(t){for(var e=t.length<0?0:fy(t.length)|0,r=wi(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function _B(t){if($n(t,Uint8Array)){var e=new Uint8Array(t);return ay(e.buffer,e.byteOffset,e.byteLength)}return cy(t)}function ay(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,F.prototype),n}function IB(t){if(F.isBuffer(t)){var e=fy(t.length)|0,r=wi(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||ly(t.length)?wi(0):cy(t);if(t.type==="Buffer"&&Array.isArray(t.data))return cy(t.data)}function fy(t){if(t>=If)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+If.toString(16)+" bytes");return t|0}function BB(t){return+t!=t&&(t=0),F.alloc(+t)}F.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==F.prototype};F.compare=function(e,r){if($n(e,Uint8Array)&&(e=F.from(e,e.offset,e.byteLength)),$n(r,Uint8Array)&&(r=F.from(r,r.offset,r.byteLength)),!F.isBuffer(e)||!F.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,i=r.length,o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};F.isEncoding=function(e){switch(String(e).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}};F.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return F.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var i=F.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){var s=e[n];if($n(s,Uint8Array))o+s.length>i.length?F.from(s).copy(i,o):Uint8Array.prototype.set.call(i,s,o);else if(F.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function px(t,e){if(F.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||$n(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return uy(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return xx(t).length;default:if(i)return n?-1:uy(t).length;e=(""+e).toLowerCase(),i=!0}}F.byteLength=px;function RB(t,e,r){var n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return KB(this,e,r);case"utf8":case"utf-8":return gx(this,e,r);case"ascii":return PB(this,e,r);case"latin1":case"binary":return MB(this,e,r);case"base64":return CB(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $B(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}F.prototype._isBuffer=!0;function gs(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}F.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<e;r+=2)gs(this,r,r+1);return this};F.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<e;r+=4)gs(this,r,r+3),gs(this,r+1,r+2);return this};F.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<e;r+=8)gs(this,r,r+7),gs(this,r+1,r+6),gs(this,r+2,r+5),gs(this,r+3,r+4);return this};F.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?gx(this,0,e):RB.apply(this,arguments)};F.prototype.toLocaleString=F.prototype.toString;F.prototype.equals=function(e){if(!F.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:F.compare(this,e)===0};F.prototype.inspect=function(){var e="",r=Oc.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};ux&&(F.prototype[ux]=F.prototype.inspect);F.prototype.compare=function(e,r,n,i,o){if($n(e,Uint8Array)&&(e=F.from(e,e.offset,e.byteLength)),!F.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;for(var s=o-i,c=n-r,a=Math.min(s,c),u=this.slice(i,o),d=e.slice(r,n),f=0;f<a;++f)if(u[f]!==d[f]){s=u[f],c=d[f];break}return s<c?-1:c<s?1:0};function yx(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,ly(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=F.from(e,n)),F.isBuffer(e))return e.length===0?-1:dx(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):dx(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function dx(t,e,r,n,i){var o=1,s=t.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,c/=2,r/=2}function a(p,g){return o===1?p[g]:p.readUInt16BE(g*o)}var u;if(i){var d=-1;for(u=r;u<s;u++)if(a(t,u)===a(e,d===-1?0:u-d)){if(d===-1&&(d=u),u-d+1===c)return d*o}else d!==-1&&(u-=u-d),d=-1}else for(r+c>s&&(r=s-c),u=r;u>=0;u--){for(var f=!0,h=0;h<c;h++)if(a(t,u+h)!==a(e,h)){f=!1;break}if(f)return u}return-1}F.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};F.prototype.indexOf=function(e,r,n){return yx(this,e,r,n,!0)};F.prototype.lastIndexOf=function(e,r,n){return yx(this,e,r,n,!1)};function UB(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var c=parseInt(e.substr(s*2,2),16);if(ly(c))return s;t[r+s]=c}return s}function OB(t,e,r,n){return Bf(uy(e,t.length-r),t,r,n)}function DB(t,e,r,n){return Bf(qB(e),t,r,n)}function kB(t,e,r,n){return Bf(xx(e),t,r,n)}function NB(t,e,r,n){return Bf(FB(e,t.length-r),t,r,n)}F.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return UB(this,e,r,n);case"utf8":case"utf-8":return OB(this,e,r,n);case"ascii":case"latin1":case"binary":return DB(this,e,r,n);case"base64":return kB(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return NB(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};F.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function CB(t,e,r){return e===0&&r===t.length?sy.fromByteArray(t):sy.fromByteArray(t.slice(e,r))}function gx(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o=t[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=r){var a,u,d,f;switch(c){case 1:o<128&&(s=o);break;case 2:a=t[i+1],(a&192)===128&&(f=(o&31)<<6|a&63,f>127&&(s=f));break;case 3:a=t[i+1],u=t[i+2],(a&192)===128&&(u&192)===128&&(f=(o&15)<<12|(a&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:a=t[i+1],u=t[i+2],d=t[i+3],(a&192)===128&&(u&192)===128&&(d&192)===128&&(f=(o&15)<<18|(a&63)<<12|(u&63)<<6|d&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return LB(n)}var fx=4096;function LB(t){var e=t.length;if(e<=fx)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=fx));return r}function PB(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function MB(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function KB(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=jB[t[o]];return i}function $B(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}F.prototype.slice=function(e,r){var n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);var i=this.subarray(e,r);return Object.setPrototypeOf(i,F.prototype),i};function Ot(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}F.prototype.readUintLE=F.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e],o=1,s=0;++s<r&&(o*=256);)i+=this[e+s]*o;return i};F.prototype.readUintBE=F.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e+--r],o=1;r>0&&(o*=256);)i+=this[e+--r]*o;return i};F.prototype.readUint8=F.prototype.readUInt8=function(e,r){return e=e>>>0,r||Ot(e,1,this.length),this[e]};F.prototype.readUint16LE=F.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||Ot(e,2,this.length),this[e]|this[e+1]<<8};F.prototype.readUint16BE=F.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||Ot(e,2,this.length),this[e]<<8|this[e+1]};F.prototype.readUint32LE=F.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};F.prototype.readUint32BE=F.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};F.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e],o=1,s=0;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};F.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=r,o=1,s=this[e+--i];i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};F.prototype.readInt8=function(e,r){return e=e>>>0,r||Ot(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};F.prototype.readInt16LE=function(e,r){e=e>>>0,r||Ot(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};F.prototype.readInt16BE=function(e,r){e=e>>>0,r||Ot(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};F.prototype.readInt32LE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};F.prototype.readInt32BE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};F.prototype.readFloatLE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),Uc.read(this,e,!0,23,4)};F.prototype.readFloatBE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),Uc.read(this,e,!1,23,4)};F.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||Ot(e,8,this.length),Uc.read(this,e,!0,52,8)};F.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||Ot(e,8,this.length),Uc.read(this,e,!1,52,8)};function fr(t,e,r,n,i,o){if(!F.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}F.prototype.writeUintLE=F.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;fr(this,e,r,n,o,0)}var s=1,c=0;for(this[r]=e&255;++c<n&&(s*=256);)this[r+c]=e/s&255;return r+n};F.prototype.writeUintBE=F.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;fr(this,e,r,n,o,0)}var s=n-1,c=1;for(this[r+s]=e&255;--s>=0&&(c*=256);)this[r+s]=e/c&255;return r+n};F.prototype.writeUint8=F.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,1,255,0),this[r]=e&255,r+1};F.prototype.writeUint16LE=F.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};F.prototype.writeUint16BE=F.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};F.prototype.writeUint32LE=F.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};F.prototype.writeUint32BE=F.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};F.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);fr(this,e,r,n,o-1,-o)}var s=0,c=1,a=0;for(this[r]=e&255;++s<n&&(c*=256);)e<0&&a===0&&this[r+s-1]!==0&&(a=1),this[r+s]=(e/c>>0)-a&255;return r+n};F.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);fr(this,e,r,n,o-1,-o)}var s=n-1,c=1,a=0;for(this[r+s]=e&255;--s>=0&&(c*=256);)e<0&&a===0&&this[r+s+1]!==0&&(a=1),this[r+s]=(e/c>>0)-a&255;return r+n};F.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};F.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};F.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};F.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};F.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function mx(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function wx(t,e,r,n,i){return e=+e,r=r>>>0,i||mx(t,e,r,4,34028234663852886e22,-34028234663852886e22),Uc.write(t,e,r,n,23,4),r+4}F.prototype.writeFloatLE=function(e,r,n){return wx(this,e,r,!0,n)};F.prototype.writeFloatBE=function(e,r,n){return wx(this,e,r,!1,n)};function bx(t,e,r,n,i){return e=+e,r=r>>>0,i||mx(t,e,r,8,17976931348623157e292,-17976931348623157e292),Uc.write(t,e,r,n,52,8),r+8}F.prototype.writeDoubleLE=function(e,r,n){return bx(this,e,r,!0,n)};F.prototype.writeDoubleBE=function(e,r,n){return bx(this,e,r,!1,n)};F.prototype.copy=function(e,r,n,i){if(!F.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);var o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};F.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!F.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){var o=e.charCodeAt(0);(i==="utf8"&&o<128||i==="latin1")&&(e=o)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if(typeof e=="number")for(s=r;s<n;++s)this[s]=e;else{var c=F.isBuffer(e)?e:F.from(e,i),a=c.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=c[s%a]}return this};var HB=/[^+/0-9A-Za-z-_]/g;function VB(t){if(t=t.split("=")[0],t=t.trim().replace(HB,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function uy(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function qB(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function FB(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function xx(t){return sy.toByteArray(VB(t))}function Bf(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function $n(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function ly(t){return t!==t}var jB=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=r*16,i=0;i<16;++i)e[n+i]=t[r]+t[i];return e}()});var Ei=oe((YL,Ax)=>{l();var ft=Ax.exports={},Hn,Vn;function hy(){throw new Error("setTimeout has not been defined")}function py(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Hn=setTimeout:Hn=hy}catch{Hn=hy}try{typeof clearTimeout=="function"?Vn=clearTimeout:Vn=py}catch{Vn=py}})();function Ex(t){if(Hn===setTimeout)return setTimeout(t,0);if((Hn===hy||!Hn)&&setTimeout)return Hn=setTimeout,setTimeout(t,0);try{return Hn(t,0)}catch{try{return Hn.call(null,t,0)}catch{return Hn.call(this,t,0)}}}function WB(t){if(Vn===clearTimeout)return clearTimeout(t);if((Vn===py||!Vn)&&clearTimeout)return Vn=clearTimeout,clearTimeout(t);try{return Vn(t)}catch{try{return Vn.call(null,t)}catch{return Vn.call(this,t)}}}var bi=[],Dc=!1,ms,Rf=-1;function GB(){!Dc||!ms||(Dc=!1,ms.length?bi=ms.concat(bi):Rf=-1,bi.length&&vx())}function vx(){if(!Dc){var t=Ex(GB);Dc=!0;for(var e=bi.length;e;){for(ms=bi,bi=[];++Rf<e;)ms&&ms[Rf].run();Rf=-1,e=bi.length}ms=null,Dc=!1,WB(t)}}ft.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];bi.push(new Sx(t,e)),bi.length===1&&!Dc&&Ex(vx)};function Sx(t,e){this.fun=t,this.array=e}Sx.prototype.run=function(){this.fun.apply(null,this.array)};ft.title="browser";ft.browser=!0;ft.env={};ft.argv=[];ft.version="";ft.versions={};function xi(){}ft.on=xi;ft.addListener=xi;ft.once=xi;ft.off=xi;ft.removeListener=xi;ft.removeAllListeners=xi;ft.emit=xi;ft.prependListener=xi;ft.prependOnceListener=xi;ft.listeners=function(t){return[]};ft.binding=function(t){throw new Error("process.binding is not supported")};ft.cwd=function(){return"/"};ft.chdir=function(t){throw new Error("process.chdir is not supported")};ft.umask=function(){return 0}});var b,w,XL,l=pB(()=>{b=Mn(Tr()),w=Mn(Ei()),XL=function(t){function e(){var n=this||self;return delete t.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();t.defineProperty(t.prototype,"__magic__",{configurable:!0,get:e});var r=__magic__;return r}(Object)});var Jv=oe((DH,Yv)=>{l();var c6=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Ml=()=>c6.now(),a6=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),j0=t=>t===1/0||a6(t),W0=class t{constructor({max:e=1/0,ttl:r,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:o=!1,dispose:s,noDisposeOnSet:c=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,r!==void 0&&!j0(r))throw new TypeError("ttl must be positive integer or Infinity if set");if(!j0(e))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=r,this.max=e,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!o,this.noDisposeOnSet=!!c,s!==void 0){if(typeof s!="function")throw new TypeError("dispose must be function if set");this.dispose=s}this.timer=void 0,this.timerExpiration=void 0}setTimer(e,r){if(this.timerExpiration<e)return;this.timer&&clearTimeout(this.timer);let n=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let i in this.expirations){this.setTimer(i,i-Ml());break}},r);n.unref&&n.unref(),this.timerExpiration=e,this.timer=n}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return w.default.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let e=this.dispose!==t.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[r,n]of e)this.dispose(n,r,"delete")}setTTL(e,r=this.ttl){let n=this.expirationMap.get(e);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==e)}if(r!==1/0){let i=Math.floor(Ml()+r);this.expirationMap.set(e,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,r)),this.expirations[i].push(e)}else this.expirationMap.set(e,1/0)}set(e,r,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!j0(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(e)){i||this.setTTL(e,n);let s=this.data.get(e);s!==r&&(this.data.set(e,r),o||this.dispose(s,e,"set"))}else this.setTTL(e,n),this.data.set(e,r);for(;this.size>this.max;)this.purgeToCapacity();return this}has(e){return this.data.has(e)}getRemainingTTL(e){let r=this.expirationMap.get(e);return r===1/0?r:r!==void 0?Math.max(0,Math.ceil(r-Ml())):0}get(e,{updateAgeOnGet:r=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(e);if(i&&this.getRemainingTTL(e)===0){this.delete(e);return}return r&&this.setTTL(e,n),o}dispose(e,r){}delete(e){let r=this.expirationMap.get(e);if(r!==void 0){let n=this.data.get(e);this.data.delete(e),this.expirationMap.delete(e);let i=this.expirations[r];return i&&(i.length<=1?delete this.expirations[r]:this.expirations[r]=i.filter(o=>o!==e)),this.dispose(n,e,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let e in this.expirations){let r=this.expirations[e];if(this.size-r.length>=this.max){delete this.expirations[e];let n=[];for(let i of r)n.push([i,this.data.get(i)]),this.data.delete(i),this.expirationMap.delete(i);for(let[i,o]of n)this.dispose(o,i,"evict")}else{let n=this.size-this.max,i=[];for(let o of r.splice(0,n))i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"evict");return}}}get size(){return this.data.size}purgeStale(){let e=Math.ceil(Ml());for(let r in this.expirations){if(r==="Infinity"||r>e)return;let n=[...this.expirations[r]||[]],i=[];delete this.expirations[r];for(let o of n)i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let e in this.expirations)for(let r of this.expirations[e])yield[r,this.data.get(r)]}*keys(){for(let e in this.expirations)for(let r of this.expirations[e])yield r}*values(){for(let e in this.expirations)for(let r of this.expirations[e])yield this.data.get(r)}[Symbol.iterator](){return this.entries()}};Yv.exports=W0});var h1=oe(l1=>{"use strict";l();l1.supports=function(...e){let r=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(r,{snapshots:r.snapshots||!1,permanence:r.permanence||!1,seek:r.seek||!1,clear:r.clear||!1,getMany:r.getMany||!1,keyIterator:r.keyIterator||!1,valueIterator:r.valueIterator||!1,iteratorNextv:r.iteratorNextv||!1,iteratorAll:r.iteratorAll||!1,status:r.status||!1,createIfMissing:r.createIfMissing||!1,errorIfExists:r.errorIfExists||!1,deferredOpen:r.deferredOpen||!1,promises:r.promises||!1,streams:r.streams||!1,encodings:Object.assign({},r.encodings),events:Object.assign({},r.events),additionalMethods:Object.assign({},r.additionalMethods)})}});var vn=oe((rq,p1)=>{"use strict";l();p1.exports=class extends Error{constructor(e,r){super(e||""),typeof r=="object"&&r!==null&&(r.code&&(this.code=String(r.code)),r.expected&&(this.expected=!0),r.transient&&(this.transient=!0),r.cause&&(this.cause=r.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var cg=oe((iq,y1)=>{"use strict";l();var sg=null;y1.exports=function(){return sg===null&&(sg={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),sg}});var dg=oe(g1=>{"use strict";l();var ag=vn(),H6=new Set(["buffer","view","utf8"]),ug=class{constructor(e){if(this.encode=e.encode||this.encode,this.decode=e.decode||this.decode,this.name=e.name||this.name,this.format=e.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!H6.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");e.createViewTranscoder&&(this.createViewTranscoder=e.createViewTranscoder),e.createBufferTranscoder&&(this.createBufferTranscoder=e.createBufferTranscoder),e.createUTF8Transcoder&&(this.createUTF8Transcoder=e.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new ag(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new ag(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new ag(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};g1.Encoding=ug});var pg=oe($l=>{"use strict";l();var{Buffer:lg}=Tr()||{},{Encoding:hg}=dg(),V6=cg(),id=class extends hg{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new od({encode:this.encode,decode:e=>this.decode(lg.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},od=class extends hg{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new id({encode:e=>{let r=this.encode(e);return lg.from(r.buffer,r.byteOffset,r.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},fg=class extends hg{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new id({encode:e=>lg.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:r}=V6();return new od({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(r.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};$l.BufferFormat=id;$l.ViewFormat=od;$l.UTF8Format=fg});var x1=oe(Hs=>{"use strict";l();var{Buffer:Jt}=Tr()||{Buffer:{isBuffer:()=>!1}},{textEncoder:w1,textDecoder:m1}=cg()(),{BufferFormat:sd,ViewFormat:yg,UTF8Format:b1}=pg(),Hl=t=>t;Hs.utf8=new b1({encode:function(t){return Jt.isBuffer(t)?t.toString("utf8"):ArrayBuffer.isView(t)?m1.decode(t):String(t)},decode:Hl,name:"utf8",createViewTranscoder(){return new yg({encode:function(t){return ArrayBuffer.isView(t)?t:w1.encode(t)},decode:function(t){return m1.decode(t)},name:`${this.name}+view`})},createBufferTranscoder(){return new sd({encode:function(t){return Jt.isBuffer(t)?t:ArrayBuffer.isView(t)?Jt.from(t.buffer,t.byteOffset,t.byteLength):Jt.from(String(t),"utf8")},decode:function(t){return t.toString("utf8")},name:`${this.name}+buffer`})}});Hs.json=new b1({encode:JSON.stringify,decode:JSON.parse,name:"json"});Hs.buffer=new sd({encode:function(t){return Jt.isBuffer(t)?t:ArrayBuffer.isView(t)?Jt.from(t.buffer,t.byteOffset,t.byteLength):Jt.from(String(t),"utf8")},decode:Hl,name:"buffer",createViewTranscoder(){return new yg({encode:function(t){return ArrayBuffer.isView(t)?t:Jt.from(String(t),"utf8")},decode:function(t){return Jt.from(t.buffer,t.byteOffset,t.byteLength)},name:`${this.name}+view`})}});Hs.view=new yg({encode:function(t){return ArrayBuffer.isView(t)?t:w1.encode(t)},decode:Hl,name:"view",createBufferTranscoder(){return new sd({encode:function(t){return Jt.isBuffer(t)?t:ArrayBuffer.isView(t)?Jt.from(t.buffer,t.byteOffset,t.byteLength):Jt.from(String(t),"utf8")},decode:Hl,name:`${this.name}+buffer`})}});Hs.hex=new sd({encode:function(t){return Jt.isBuffer(t)?t:Jt.from(String(t),"hex")},decode:function(t){return t.toString("hex")},name:"hex"});Hs.base64=new sd({encode:function(t){return Jt.isBuffer(t)?t:Jt.from(String(t),"base64")},decode:function(t){return t.toString("base64")},name:"base64"})});var S1=oe(v1=>{"use strict";l();var E1=vn(),ql=x1(),{Encoding:q6}=dg(),{BufferFormat:F6,ViewFormat:j6,UTF8Format:W6}=pg(),cd=Symbol("formats"),Vl=Symbol("encodings"),G6=new Set(["buffer","view","utf8"]),gg=class{constructor(e){if(Array.isArray(e)){if(!e.every(r=>G6.has(r)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[Vl]=new Map,this[cd]=new Set(e);for(let r in ql)try{this.encoding(r)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Vl].values()))}encoding(e){let r=this[Vl].get(e);if(r===void 0){if(typeof e=="string"&&e!==""){if(r=X6[e],!r)throw new E1(`Encoding '${e}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof e!="object"||e===null)throw new TypeError("First argument 'encoding' must be a string or object");r=z6(e)}let{name:n,format:i}=r;if(!this[cd].has(i))if(this[cd].has("view"))r=r.createViewTranscoder();else if(this[cd].has("buffer"))r=r.createBufferTranscoder();else if(this[cd].has("utf8"))r=r.createUTF8Transcoder();else throw new E1(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,r.name,r.commonName])this[Vl].set(o,r)}return r}};v1.Transcoder=gg;function z6(t){if(t instanceof q6)return t;let e="type"in t&&typeof t.type=="string"?t.type:void 0,r=t.name||e||`anonymous-${Z6++}`;switch(Y6(t)){case"view":return new j6({...t,name:r});case"utf8":return new W6({...t,name:r});case"buffer":return new F6({...t,name:r});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function Y6(t){return"format"in t&&t.format!==void 0?t.format:"buffer"in t&&typeof t.buffer=="boolean"?t.buffer?"buffer":"utf8":"code"in t&&Number.isInteger(t.code)?"view":"buffer"}var J6={binary:ql.buffer,"utf-8":ql.utf8},X6={...ql,...J6},Z6=0});var da=oe((pq,mg)=>{"use strict";l();var ua=typeof Reflect=="object"?Reflect:null,A1=ua&&typeof ua.apply=="function"?ua.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Fl;ua&&typeof ua.ownKeys=="function"?Fl=ua.ownKeys:Object.getOwnPropertySymbols?Fl=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Fl=function(e){return Object.getOwnPropertyNames(e)};function Q6(t){console&&console.warn&&console.warn(t)}var _1=Number.isNaN||function(e){return e!==e};function Pe(){Pe.init.call(this)}mg.exports=Pe;mg.exports.once=nU;Pe.EventEmitter=Pe;Pe.prototype._events=void 0;Pe.prototype._eventsCount=0;Pe.prototype._maxListeners=void 0;var T1=10;function jl(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(Pe,"defaultMaxListeners",{enumerable:!0,get:function(){return T1},set:function(t){if(typeof t!="number"||t<0||_1(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");T1=t}});Pe.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};Pe.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||_1(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function I1(t){return t._maxListeners===void 0?Pe.defaultMaxListeners:t._maxListeners}Pe.prototype.getMaxListeners=function(){return I1(this)};Pe.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=e==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var a=o[e];if(a===void 0)return!1;if(typeof a=="function")A1(a,this,r);else for(var u=a.length,d=D1(a,u),n=0;n<u;++n)A1(d[n],this,r);return!0};function B1(t,e,r,n){var i,o,s;if(jl(r),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]),s===void 0)s=o[e]=r,++t._eventsCount;else if(typeof s=="function"?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=I1(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,Q6(c)}return t}Pe.prototype.addListener=function(e,r){return B1(this,e,r,!1)};Pe.prototype.on=Pe.prototype.addListener;Pe.prototype.prependListener=function(e,r){return B1(this,e,r,!0)};function eU(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function R1(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=eU.bind(n);return i.listener=r,n.wrapFn=i,i}Pe.prototype.once=function(e,r){return jl(r),this.on(e,R1(this,e,r)),this};Pe.prototype.prependOnceListener=function(e,r){return jl(r),this.prependListener(e,R1(this,e,r)),this};Pe.prototype.removeListener=function(e,r){var n,i,o,s,c;if(jl(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():tU(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};Pe.prototype.off=Pe.prototype.removeListener;Pe.prototype.removeAllListeners=function(e){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(e,r[i]);return this};function U1(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?rU(i):D1(i,i.length)}Pe.prototype.listeners=function(e){return U1(this,e,!0)};Pe.prototype.rawListeners=function(e){return U1(this,e,!1)};Pe.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):O1.call(t,e)};Pe.prototype.listenerCount=O1;function O1(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}Pe.prototype.eventNames=function(){return this._eventsCount>0?Fl(this._events):[]};function D1(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function tU(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function rU(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function nU(t,e){return new Promise(function(r,n){function i(s){t.removeListener(e,o),n(s)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),r([].slice.call(arguments))}k1(t,e,o,{once:!0}),e!=="error"&&iU(t,i,{once:!0})})}function iU(t,e,r){typeof t.on=="function"&&k1(t,"error",e,r)}function k1(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(o){n.once&&t.removeEventListener(e,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var C1=oe((gq,N1)=>{l();N1.exports=typeof queueMicrotask=="function"?queueMicrotask:t=>Promise.resolve().then(t)});var ad=oe(wg=>{"use strict";l();var L1=C1();wg.fromCallback=function(t,e){if(t===void 0){var r=new Promise(function(n,i){t=function(o,s){o?i(o):n(s)}});t[e!==void 0?e:"promise"]=r}else if(typeof t!="function")throw new TypeError("Callback must be a function");return t};wg.fromPromise=function(t,e){if(e===void 0)return t;t.then(function(r){L1(()=>e(null,r))}).catch(function(r){L1(()=>e(r))})}});var Wl=oe(bg=>{"use strict";l();bg.getCallback=function(t,e){return typeof t=="function"?t:e};bg.getOptions=function(t,e){return typeof t=="object"&&t!==null?t:e!==void 0?e:{}}});var Ko=oe(Jl=>{"use strict";l();var{fromCallback:xg}=ad(),kr=vn(),{getOptions:Eg,getCallback:P1}=Wl(),Vs=Symbol("promise"),fa=Symbol("callback"),Zn=Symbol("working"),qs=Symbol("handleOne"),Ki=Symbol("handleMany"),vg=Symbol("autoClose"),Po=Symbol("finishWork"),Qn=Symbol("returnMany"),No=Symbol("closing"),ud=Symbol("handleClose"),Gl=Symbol("closed"),dd=Symbol("closeCallbacks"),Lo=Symbol("keyEncoding"),Fs=Symbol("valueEncoding"),Sg=Symbol("abortOnClose"),zl=Symbol("legacy"),Ag=Symbol("keys"),Tg=Symbol("values"),Co=Symbol("limit"),Qr=Symbol("count"),Yl=Object.freeze({}),oU=()=>{},M1=!1,fd=class{constructor(e,r,n){if(typeof e!="object"||e===null){let i=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof r!="object"||r===null)throw new TypeError("The second argument must be an options object");this[Gl]=!1,this[dd]=[],this[Zn]=!1,this[No]=!1,this[vg]=!1,this[fa]=null,this[qs]=this[qs].bind(this),this[Ki]=this[Ki].bind(this),this[ud]=this[ud].bind(this),this[Lo]=r[Lo],this[Fs]=r[Fs],this[zl]=n,this[Co]=Number.isInteger(r.limit)&&r.limit>=0?r.limit:1/0,this[Qr]=0,this[Sg]=!!r.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Qr]}get limit(){return this[Co]}next(e){let r;if(e===void 0)r=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[zl]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof e!="function")throw new TypeError("Callback must be a function");return this[No]?this.nextTick(e,new kr("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Zn]?this.nextTick(e,new kr("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Zn]=!0,this[fa]=e,this[Qr]>=this[Co]?this.nextTick(this[qs],null):this._next(this[qs])),r}_next(e){this.nextTick(e)}nextv(e,r,n){return n=P1(r,n),n=xg(n,Vs),r=Eg(r,Yl),Number.isInteger(e)?(this[No]?this.nextTick(n,new kr("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Zn]?this.nextTick(n,new kr("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[Co]<1/0&&(e=Math.min(e,this[Co]-this[Qr])),this[Zn]=!0,this[fa]=n,e<=0?this.nextTick(this[Ki],null,[]):this._nextv(e,r,this[Ki])),n[Vs]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[Vs])}_nextv(e,r,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[zl]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[zl]?[c,a]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,r){return r=P1(e,r),r=xg(r,Vs),e=Eg(e,Yl),this[No]?this.nextTick(r,new kr("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Zn]?this.nextTick(r,new kr("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Zn]=!0,this[fa]=r,this[vg]=!0,this[Qr]>=this[Co]?this.nextTick(this[Ki],null,[]):this._all(e,this[Ki])),r[Vs]}_all(e,r){let n=this[Qr],i=[],o=()=>{let c=this[Co]<1/0?Math.min(1e3,this[Co]-n):1e3;c<=0?this.nextTick(r,null,i):this._nextv(c,Yl,s)},s=(c,a)=>{c?r(c):a.length===0?r(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[Po](){let e=this[fa];return this[Sg]&&e===null?oU:(this[Zn]=!1,this[fa]=null,this[No]&&this._close(this[ud]),e)}[Qn](e,r,n){this[vg]?this.close(e.bind(null,r,n)):e(r,n)}seek(e,r){if(r=Eg(r,Yl),!this[No]){if(this[Zn])throw new kr("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(r.keyEncoding||this[Lo]),i=n.format;r.keyEncoding!==i&&(r={...r,keyEncoding:i});let o=this.db.prefixKey(n.encode(e),i);this._seek(o,r)}}}_seek(e,r){throw new kr("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=xg(e,Vs),this[Gl]?this.nextTick(e):this[No]?this[dd].push(e):(this[No]=!0,this[dd].push(e),this[Zn]?this[Sg]&&this[Po]()(new kr("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[ud])),e[Vs]}_close(e){this.nextTick(e)}[ud](){this[Gl]=!0,this.db.detachResource(this);let e=this[dd];this[dd]=[];for(let r of e)r()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Gl]||await this.close()}}},la=class extends fd{constructor(e,r){super(e,r,!0),this[Ag]=r.keys!==!1,this[Tg]=r.values!==!1}[qs](e,r,n){let i=this[Po]();if(e)return i(e);try{r=this[Ag]&&r!==void 0?this[Lo].decode(r):void 0,n=this[Tg]&&n!==void 0?this[Fs].decode(n):void 0}catch(o){return i(new Mo("entry",o))}r===void 0&&n===void 0||this[Qr]++,i(null,r,n)}[Ki](e,r){let n=this[Po]();if(e)return this[Qn](n,e);try{for(let i of r){let o=i[0],s=i[1];i[0]=this[Ag]&&o!==void 0?this[Lo].decode(o):void 0,i[1]=this[Tg]&&s!==void 0?this[Fs].decode(s):void 0}}catch(i){return this[Qn](n,new Mo("entries",i))}this[Qr]+=r.length,this[Qn](n,null,r)}end(e){return!M1&&typeof console<"u"&&(M1=!0,console.warn(new kr("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(e)}},_g=class extends fd{constructor(e,r){super(e,r,!1)}[qs](e,r){let n=this[Po]();if(e)return n(e);try{r=r!==void 0?this[Lo].decode(r):void 0}catch(i){return n(new Mo("key",i))}r!==void 0&&this[Qr]++,n(null,r)}[Ki](e,r){let n=this[Po]();if(e)return this[Qn](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[Lo].decode(o):void 0}}catch(i){return this[Qn](n,new Mo("keys",i))}this[Qr]+=r.length,this[Qn](n,null,r)}},Ig=class extends fd{constructor(e,r){super(e,r,!1)}[qs](e,r){let n=this[Po]();if(e)return n(e);try{r=r!==void 0?this[Fs].decode(r):void 0}catch(i){return n(new Mo("value",i))}r!==void 0&&this[Qr]++,n(null,r)}[Ki](e,r){let n=this[Po]();if(e)return this[Qn](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[Fs].decode(o):void 0}}catch(i){return this[Qn](n,new Mo("values",i))}this[Qr]+=r.length,this[Qn](n,null,r)}},Mo=class extends kr{constructor(e,r){super(`Iterator could not decode ${e}`,{code:"LEVEL_DECODE_ERROR",cause:r})}};for(let t of["_ended property","_nexting property","_end method"])Object.defineProperty(la.prototype,t.split(" ")[0],{get(){throw new kr(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new kr(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})}});la.keyEncoding=Lo;la.valueEncoding=Fs;Jl.AbstractIterator=la;Jl.AbstractKeyIterator=_g;Jl.AbstractValueIterator=Ig});var K1=oe(Bg=>{"use strict";l();var{AbstractKeyIterator:sU,AbstractValueIterator:cU}=Ko(),js=Symbol("iterator"),ld=Symbol("callback"),ha=Symbol("handleOne"),Ws=Symbol("handleMany"),hd=class extends sU{constructor(e,r){super(e,r),this[js]=e.iterator({...r,keys:!0,values:!1}),this[ha]=this[ha].bind(this),this[Ws]=this[Ws].bind(this)}},Xl=class extends cU{constructor(e,r){super(e,r),this[js]=e.iterator({...r,keys:!1,values:!0}),this[ha]=this[ha].bind(this),this[Ws]=this[Ws].bind(this)}};for(let t of[hd,Xl]){let e=t===hd,r=e?n=>n[0]:n=>n[1];t.prototype._next=function(n){this[ld]=n,this[js].next(this[ha])},t.prototype[ha]=function(n,i,o){let s=this[ld];n?s(n):s(null,e?i:o)},t.prototype._nextv=function(n,i,o){this[ld]=o,this[js].nextv(n,i,this[Ws])},t.prototype._all=function(n,i){this[ld]=i,this[js].all(n,this[Ws])},t.prototype[Ws]=function(n,i){let o=this[ld];n?o(n):o(null,i.map(r))},t.prototype._seek=function(n,i){this[js].seek(n,i)},t.prototype._close=function(n){this[js].close(n)}}Bg.DefaultKeyIterator=hd;Bg.DefaultValueIterator=Xl});var $1=oe(nh=>{"use strict";l();var{AbstractIterator:aU,AbstractKeyIterator:uU,AbstractValueIterator:dU}=Ko(),Rg=vn(),yr=Symbol("nut"),th=Symbol("undefer"),rh=Symbol("factory"),Zl=class extends aU{constructor(e,r){super(e,r),this[yr]=null,this[rh]=()=>e.iterator(r),this.db.defer(()=>this[th]())}},Ql=class extends uU{constructor(e,r){super(e,r),this[yr]=null,this[rh]=()=>e.keys(r),this.db.defer(()=>this[th]())}},eh=class extends dU{constructor(e,r){super(e,r),this[yr]=null,this[rh]=()=>e.values(r),this.db.defer(()=>this[th]())}};for(let t of[Zl,Ql,eh])t.prototype[th]=function(){this.db.status==="open"&&(this[yr]=this[rh]())},t.prototype._next=function(e){this[yr]!==null?this[yr].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new Rg("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._nextv=function(e,r,n){this[yr]!==null?this[yr].nextv(e,r,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,r,n)):this.nextTick(n,new Rg("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._all=function(e,r){this[yr]!==null?this[yr].all(r):this.db.status==="opening"?this.db.defer(()=>this._all(e,r)):this.nextTick(r,new Rg("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._seek=function(e,r){this[yr]!==null?this[yr]._seek(e,r):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,r))},t.prototype._close=function(e){this[yr]!==null?this[yr].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};nh.DeferredIterator=Zl;nh.DeferredKeyIterator=Ql;nh.DeferredValueIterator=eh});var Og=oe(V1=>{"use strict";l();var{fromCallback:H1}=ad(),ih=vn(),{getCallback:fU,getOptions:lU}=Wl(),oh=Symbol("promise"),en=Symbol("status"),pa=Symbol("operations"),pd=Symbol("finishClose"),ya=Symbol("closeCallbacks"),Ug=class{constructor(e){if(typeof e!="object"||e===null){let r=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${r}`)}this[pa]=[],this[ya]=[],this[en]="open",this[pd]=this[pd].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[pa].length}put(e,r,n){if(this[en]!=="open")throw new ih("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(e)||this.db._checkValue(r);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),a=o.valueEncoding(n&&n.valueEncoding),u=c.format;n={...n,keyEncoding:u,valueEncoding:a.format},o!==this.db&&(n.sublevel=null);let d=o.prefixKey(c.encode(e),u),f=a.encode(r);return this._put(d,f,n),this[pa].push({...s,type:"put",key:e,value:r}),this}_put(e,r,n){}del(e,r){if(this[en]!=="open")throw new ih("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(e);if(n)throw n;let i=r&&r.sublevel!=null?r.sublevel:this.db,o=r,s=i.keyEncoding(r&&r.keyEncoding),c=s.format;return r={...r,keyEncoding:c},i!==this.db&&(r.sublevel=null),this._del(i.prefixKey(s.encode(e),c),r),this[pa].push({...o,type:"del",key:e}),this}_del(e,r){}clear(){if(this[en]!=="open")throw new ih("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[pa]=[],this}_clear(){}write(e,r){return r=fU(e,r),r=H1(r,oh),e=lU(e),this[en]!=="open"?this.nextTick(r,new ih("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(r):(this[en]="writing",this._write(e,n=>{this[en]="closing",this[ya].push(()=>r(n)),n||this.db.emit("batch",this[pa]),this._close(this[pd])})),r[oh]}_write(e,r){}close(e){return e=H1(e,oh),this[en]==="closing"?this[ya].push(e):this[en]==="closed"?this.nextTick(e):(this[ya].push(e),this[en]!=="writing"&&(this[en]="closing",this._close(this[pd]))),e[oh]}_close(e){this.nextTick(e)}[pd](){this[en]="closed",this.db.detachResource(this);let e=this[ya];this[ya]=[];for(let r of e)r()}};V1.AbstractChainedBatch=Ug});var F1=oe(q1=>{"use strict";l();var{AbstractChainedBatch:hU}=Og(),pU=vn(),ga=Symbol("encoded"),Dg=class extends hU{constructor(e){super(e),this[ga]=[]}_put(e,r,n){this[ga].push({...n,type:"put",key:e,value:r})}_del(e,r){this[ga].push({...r,type:"del",key:e})}_clear(){this[ga]=[]}_write(e,r){this.db.status==="opening"?this.db.defer(()=>this._write(e,r)):this.db.status==="open"?this[ga].length===0?this.nextTick(r):this.db._batch(this[ga],e,r):this.nextTick(r,new pU("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};q1.DefaultChainedBatch=Dg});var G1=oe((Dq,W1)=>{"use strict";l();var j1=vn(),yU=Object.prototype.hasOwnProperty,gU=new Set(["lt","lte","gt","gte"]);W1.exports=function(t,e){let r={};for(let n in t)if(yU.call(t,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new j1(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new j1("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});gU.has(n)?r[n]=e.encode(t[n]):r[n]=t[n]}return r.reverse=!!r.reverse,r.limit=Number.isInteger(r.limit)&&r.limit>=0?r.limit:-1,r}});var kg=oe((Nq,Y1)=>{l();var z1;Y1.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):t=>(z1||(z1=Promise.resolve())).then(t).catch(e=>setTimeout(()=>{throw e},0))});var Z1=oe((Lq,X1)=>{"use strict";l();var J1=kg();X1.exports=function(t,...e){e.length===0?J1(t):J1(()=>t(...e))}});var Q1=oe(sh=>{"use strict";l();var{AbstractIterator:mU,AbstractKeyIterator:wU,AbstractValueIterator:bU}=Ko(),ma=Symbol("unfix"),Sn=Symbol("iterator"),Gs=Symbol("handleOne"),$o=Symbol("handleMany"),$i=Symbol("callback"),yd=class extends mU{constructor(e,r,n,i){super(e,r),this[Sn]=n,this[ma]=i,this[Gs]=this[Gs].bind(this),this[$o]=this[$o].bind(this),this[$i]=null}[Gs](e,r,n){let i=this[$i];if(e)return i(e);r!==void 0&&(r=this[ma](r)),i(e,r,n)}[$o](e,r){let n=this[$i];if(e)return n(e);for(let i of r){let o=i[0];o!==void 0&&(i[0]=this[ma](o))}n(e,r)}},gd=class extends wU{constructor(e,r,n,i){super(e,r),this[Sn]=n,this[ma]=i,this[Gs]=this[Gs].bind(this),this[$o]=this[$o].bind(this),this[$i]=null}[Gs](e,r){let n=this[$i];if(e)return n(e);r!==void 0&&(r=this[ma](r)),n(e,r)}[$o](e,r){let n=this[$i];if(e)return n(e);for(let i=0;i<r.length;i++){let o=r[i];o!==void 0&&(r[i]=this[ma](o))}n(e,r)}},md=class extends bU{constructor(e,r,n){super(e,r),this[Sn]=n}};for(let t of[yd,gd])t.prototype._next=function(e){this[$i]=e,this[Sn].next(this[Gs])},t.prototype._nextv=function(e,r,n){this[$i]=n,this[Sn].nextv(e,r,this[$o])},t.prototype._all=function(e,r){this[$i]=r,this[Sn].all(e,this[$o])};for(let t of[md])t.prototype._next=function(e){this[Sn].next(e)},t.prototype._nextv=function(e,r,n){this[Sn].nextv(e,r,n)},t.prototype._all=function(e,r){this[Sn].all(e,r)};for(let t of[yd,gd,md])t.prototype._seek=function(e,r){this[Sn].seek(e,r)},t.prototype._close=function(e){this[Sn].close(e)};sh.AbstractSublevelIterator=yd;sh.AbstractSublevelKeyIterator=gd;sh.AbstractSublevelValueIterator=md});var n2=oe(($q,r2)=>{"use strict";l();var Ng=vn(),{Buffer:Pg}=Tr()||{},{AbstractSublevelIterator:xU,AbstractSublevelKeyIterator:EU,AbstractSublevelValueIterator:vU}=Q1(),Hi=Symbol("prefix"),e2=Symbol("upperBound"),wd=Symbol("prefixRange"),Nr=Symbol("parent"),Cg=Symbol("unfix"),t2=new TextEncoder,SU={separator:"!"};r2.exports=function({AbstractLevel:t}){class e extends t{static defaults(n){if(typeof n=="string")throw new Ng("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new Ng("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?SU:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=e.defaults(o);i=TU(i,s);let u=s.charCodeAt(0)+1,d=n[Nr]||n;if(!t2.encode(i).every(p=>p>u&&p<127))throw new Ng(`Prefix must use bytes > ${u} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(AU(d,c),a);let f=(n.prefix||"")+s+i+s,h=f.slice(0,-1)+String.fromCharCode(u);this[Nr]=d,this[Hi]=new ch(f),this[e2]=new ch(h),this[Cg]=new Mg,this.nextTick=d.nextTick}prefixKey(n,i){if(i==="utf8")return this[Hi].utf8+n;if(n.byteLength===0)return this[Hi][i];if(i==="view"){let o=this[Hi].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Hi].buffer;return Pg.concat([o,n],o.byteLength+n.byteLength)}}[wd](n,i){n.gte!==void 0?n.gte=this.prefixKey(n.gte,i):n.gt!==void 0?n.gt=this.prefixKey(n.gt,i):n.gte=this[Hi][i],n.lte!==void 0?n.lte=this.prefixKey(n.lte,i):n.lt!==void 0?n.lt=this.prefixKey(n.lt,i):n.lte=this[e2][i]}get prefix(){return this[Hi].utf8}get db(){return this[Nr]}_open(n,i){this[Nr].open({passive:!0},i)}_put(n,i,o,s){this[Nr].put(n,i,o,s)}_get(n,i,o){this[Nr].get(n,i,o)}_getMany(n,i,o){this[Nr].getMany(n,i,o)}_del(n,i,o){this[Nr].del(n,i,o)}_batch(n,i,o){this[Nr].batch(n,i,o)}_clear(n,i){this[wd](n,n.keyEncoding),this[Nr].clear(n,i)}_iterator(n){this[wd](n,n.keyEncoding);let i=this[Nr].iterator(n),o=this[Cg].get(this[Hi].utf8.length,n.keyEncoding);return new xU(this,n,i,o)}_keys(n){this[wd](n,n.keyEncoding);let i=this[Nr].keys(n),o=this[Cg].get(this[Hi].utf8.length,n.keyEncoding);return new EU(this,n,i,o)}_values(n){this[wd](n,n.keyEncoding);let i=this[Nr].values(n);return new vU(this,n,i)}}return{AbstractSublevel:e}};var AU=function(t,e){return{...t.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:Lg(t,"utf8"),buffer:Lg(t,"buffer"),view:Lg(t,"view")}}},Lg=function(t,e){return t.supports.encodings[e]?t.keyEncoding(e).name===e:!1},ch=class{constructor(e){this.utf8=e,this.view=t2.encode(e),this.buffer=Pg?Pg.from(this.view.buffer,0,this.view.byteLength):{}}},Mg=class{constructor(){this.cache=new Map}get(e,r){let n=this.cache.get(r);return n===void 0&&(r==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,e):n=(function(i,o){return o.slice(i)}).bind(null,e),this.cache.set(r,n)),n}},TU=function(t,e){let r=0,n=t.length;for(;r<n&&t[r]===e;)r++;for(;n>r&&t[n-1]===e;)n--;return t.slice(r,n)}});var qg=oe(Vg=>{"use strict";l();var{supports:_U}=h1(),{Transcoder:IU}=S1(),{EventEmitter:BU}=da(),{fromCallback:Ho}=ad(),An=vn(),{AbstractIterator:zs}=Ko(),{DefaultKeyIterator:RU,DefaultValueIterator:UU}=K1(),{DeferredIterator:OU,DeferredKeyIterator:DU,DeferredValueIterator:kU}=$1(),{DefaultChainedBatch:i2}=F1(),{getCallback:Ys,getOptions:Vo}=Wl(),ah=G1(),pe=Symbol("promise"),Vi=Symbol("landed"),Js=Symbol("resources"),Kg=Symbol("closeResources"),bd=Symbol("operations"),xd=Symbol("undefer"),uh=Symbol("deferOpen"),o2=Symbol("options"),be=Symbol("status"),Xs=Symbol("defaultOptions"),wa=Symbol("transcoder"),dh=Symbol("keyEncoding"),$g=Symbol("valueEncoding"),NU=()=>{},Ed=class extends BU{constructor(e,r){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");r=Vo(r);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=r;this[Js]=new Set,this[bd]=[],this[uh]=!0,this[o2]=s,this[be]="opening",this.supports=_U(e,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:e.snapshots!==!1,permanence:e.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:e.encodings||{},events:Object.assign({},e.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[wa]=new IU(CU(this)),this[dh]=this[wa].encoding(n||"utf8"),this[$g]=this[wa].encoding(i||"utf8");for(let c of this[wa].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Xs]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[dh].commonName,valueEncoding:this[$g].commonName}),key:Object.freeze({keyEncoding:this[dh].commonName})},this.nextTick(()=>{this[uh]&&this.open({passive:!1},NU)})}get status(){return this[be]}keyEncoding(e){return this[wa].encoding(e??this[dh])}valueEncoding(e){return this[wa].encoding(e??this[$g])}open(e,r){r=Ys(e,r),r=Ho(r,pe),e={...this[o2],...Vo(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[be]==="closing"||this[be]==="opening"?this.once(Vi,i?()=>n(i):n):this[be]!=="open"?r(new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):r()};return e.passive?this[be]==="opening"?this.once(Vi,n):this.nextTick(n):this[be]==="closed"||this[uh]?(this[uh]=!1,this[be]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[be]="closed",this[Kg](()=>{this.emit(Vi),n(i)}),this[xd]();return}this[be]="open",this[xd](),this.emit(Vi),this[be]==="open"&&this.emit("open"),this[be]==="open"&&this.emit("ready"),n()})):this[be]==="open"?this.nextTick(n):this.once(Vi,()=>this.open(e,r)),r[pe]}_open(e,r){this.nextTick(r)}close(e){e=Ho(e,pe);let r=n=>{this[be]==="opening"||this[be]==="closing"?this.once(Vi,n?r(n):r):this[be]!=="closed"?e(new An("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[be]==="open"){this[be]="closing",this.emit("closing");let n=i=>{this[be]="open",this[xd](),this.emit(Vi),r(i)};this[Kg](()=>{this._close(i=>{if(i)return n(i);this[be]="closed",this[xd](),this.emit(Vi),this[be]==="closed"&&this.emit("closed"),r()})})}else this[be]==="closed"?this.nextTick(r):this.once(Vi,()=>this.close(e));return e[pe]}[Kg](e){if(this[Js].size===0)return this.nextTick(e);let r=this[Js].size,n=!0,i=()=>{--r===0&&(n?this.nextTick(e):e())};for(let o of this[Js])o.close(i);n=!1,this[Js].clear()}_close(e){this.nextTick(e)}get(e,r,n){if(n=Ys(r,n),n=Ho(n,pe),r=Vo(r,this[Xs].entry),this[be]==="opening")return this.defer(()=>this.get(e,r,n)),n[pe];if(ba(this,n))return n[pe];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[pe];let o=this.keyEncoding(r.keyEncoding),s=this.valueEncoding(r.valueEncoding),c=o.format,a=s.format;return(r.keyEncoding!==c||r.valueEncoding!==a)&&(r=Object.assign({},r,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(e),c),r,(u,d)=>{if(u)return(u.code==="LEVEL_NOT_FOUND"||u.notFound||/NotFound/i.test(u))&&(u.code||(u.code="LEVEL_NOT_FOUND"),u.notFound||(u.notFound=!0),u.status||(u.status=404)),n(u);try{d=s.decode(d)}catch(f){return n(new An("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:f}))}n(null,d)}),n[pe]}_get(e,r,n){this.nextTick(n,new Error("NotFound"))}getMany(e,r,n){if(n=Ys(r,n),n=Ho(n,pe),r=Vo(r,this[Xs].entry),this[be]==="opening")return this.defer(()=>this.getMany(e,r,n)),n[pe];if(ba(this,n))return n[pe];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[pe];if(e.length===0)return this.nextTick(n,null,[]),n[pe];let i=this.keyEncoding(r.keyEncoding),o=this.valueEncoding(r.valueEncoding),s=i.format,c=o.format;(r.keyEncoding!==s||r.valueEncoding!==c)&&(r=Object.assign({},r,{keyEncoding:s,valueEncoding:c}));let a=new Array(e.length);for(let u=0;u<e.length;u++){let d=e[u],f=this._checkKey(d);if(f)return this.nextTick(n,f),n[pe];a[u]=this.prefixKey(i.encode(d),s)}return this._getMany(a,r,(u,d)=>{if(u)return n(u);try{for(let f=0;f<d.length;f++)d[f]!==void 0&&(d[f]=o.decode(d[f]))}catch(f){return n(new An(`Could not decode one or more of ${d.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:f}))}n(null,d)}),n[pe]}_getMany(e,r,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,r,n,i){if(i=Ys(n,i),i=Ho(i,pe),n=Vo(n,this[Xs].entry),this[be]==="opening")return this.defer(()=>this.put(e,r,n,i)),i[pe];if(ba(this,i))return i[pe];let o=this._checkKey(e)||this._checkValue(r);if(o)return this.nextTick(i,o),i[pe];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),a=s.format,u=c.format;(n.keyEncoding!==a||n.valueEncoding!==u)&&(n=Object.assign({},n,{keyEncoding:a,valueEncoding:u}));let d=this.prefixKey(s.encode(e),a),f=c.encode(r);return this._put(d,f,n,h=>{if(h)return i(h);this.emit("put",e,r),i()}),i[pe]}_put(e,r,n,i){this.nextTick(i)}del(e,r,n){if(n=Ys(r,n),n=Ho(n,pe),r=Vo(r,this[Xs].key),this[be]==="opening")return this.defer(()=>this.del(e,r,n)),n[pe];if(ba(this,n))return n[pe];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[pe];let o=this.keyEncoding(r.keyEncoding),s=o.format;return r.keyEncoding!==s&&(r=Object.assign({},r,{keyEncoding:s})),this._del(this.prefixKey(o.encode(e),s),r,c=>{if(c)return n(c);this.emit("del",e),n()}),n[pe]}_del(e,r,n){this.nextTick(n)}batch(e,r,n){if(!arguments.length){if(this[be]==="opening")return new i2(this);if(this[be]!=="open")throw new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=Ys(r,n),n=Ho(n,pe),r=Vo(r,this[Xs].empty),this[be]==="opening")return this.defer(()=>this.batch(e,r,n)),n[pe];if(ba(this,n))return n[pe];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[pe];if(e.length===0)return this.nextTick(n),n[pe];let i=new Array(e.length),{keyEncoding:o,valueEncoding:s,...c}=r;for(let a=0;a<e.length;a++){if(typeof e[a]!="object"||e[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[pe];let u=Object.assign({},e[a]);if(u.type!=="put"&&u.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[pe];let d=this._checkKey(u.key);if(d)return this.nextTick(n,d),n[pe];let f=u.sublevel!=null?u.sublevel:this,h=f.keyEncoding(u.keyEncoding||o),p=h.format;if(u.key=f.prefixKey(h.encode(u.key),p),u.keyEncoding=p,u.type==="put"){let g=this._checkValue(u.value);if(g)return this.nextTick(n,g),n[pe];let y=f.valueEncoding(u.valueEncoding||s);u.value=y.encode(u.value),u.valueEncoding=y.format}f!==this&&(u.sublevel=null),i[a]=u}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",e),n()}),n[pe]}_batch(e,r,n){this.nextTick(n)}sublevel(e,r){return this._sublevel(e,Hg.defaults(r))}_sublevel(e,r){return new Hg(this,e,r)}prefixKey(e,r){return e}clear(e,r){if(r=Ys(e,r),r=Ho(r,pe),e=Vo(e,this[Xs].empty),this[be]==="opening")return this.defer(()=>this.clear(e,r)),r[pe];if(ba(this,r))return r[pe];let n=e,i=this.keyEncoding(e.keyEncoding);return e=ah(e,i),e.keyEncoding=i.format,e.limit===0?this.nextTick(r):this._clear(e,o=>{if(o)return r(o);this.emit("clear",n),r()}),r[pe]}_clear(e,r){this.nextTick(r)}iterator(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=ah(e,r),e.keys=e.keys!==!1,e.values=e.values!==!1,e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[be]==="opening")return new OU(this,e);if(this[be]!=="open")throw new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new zs(this,e)}keys(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=ah(e,r),e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[be]==="opening")return new DU(this,e);if(this[be]!=="open")throw new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new RU(this,e)}values(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=ah(e,r),e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[be]==="opening")return new kU(this,e);if(this[be]!=="open")throw new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new UU(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[bd].push(e)}[xd](){if(this[bd].length===0)return;let e=this[bd];this[bd]=[];for(let r of e)r()}attachResource(e){if(typeof e!="object"||e===null||typeof e.close!="function")throw new TypeError("The first argument must be a resource object");this[Js].add(e)}detachResource(e){this[Js].delete(e)}_chainedBatch(){return new i2(this)}_checkKey(e){if(e==null)return new An("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new An("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Ed.prototype.nextTick=Z1();var{AbstractSublevel:Hg}=n2()({AbstractLevel:Ed});Vg.AbstractLevel=Ed;Vg.AbstractSublevel=Hg;var ba=function(t,e){return t[be]!=="open"?(t.nextTick(e,new An("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},CU=function(t){return Object.keys(t.supports.encodings).filter(e=>!!t.supports.encodings[e])}});var Fg=oe(Zs=>{"use strict";l();Zs.AbstractLevel=qg().AbstractLevel;Zs.AbstractSublevel=qg().AbstractSublevel;Zs.AbstractIterator=Ko().AbstractIterator;Zs.AbstractKeyIterator=Ko().AbstractKeyIterator;Zs.AbstractValueIterator=Ko().AbstractValueIterator;Zs.AbstractChainedBatch=Og().AbstractChainedBatch});var c2=oe((Wq,s2)=>{l();s2.exports=PU;var LU=kg();function PU(t,e,r){if(typeof e!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,a=!0,u;Array.isArray(t)?(n=[],o=i=t.length):(s=Object.keys(t),n={},o=i=s.length);function d(h){function p(){r&&r(h,n),r=null}a?LU(p):p()}function f(h,p,g){if(n[h]=g,p&&(c=!0),--o===0||p)d(p);else if(!c&&u<i){let y;s?(y=s[u],u+=1,t[y](function(x,S){f(y,x,S)})):(y=u,u+=1,t[y](function(x,S){f(y,x,S)}))}}u=e,o?s?s.some(function(h,p){return t[h](function(g,y){f(h,g,y)}),p===e-1}):t.some(function(h,p){return h(function(g,y){f(p,g,y)}),p===e-1}):d(null),a=!1}});var jg=oe((zq,a2)=>{"use strict";l();a2.exports=function(e){let r=e.gte!==void 0?e.gte:e.gt!==void 0?e.gt:void 0,n=e.lte!==void 0?e.lte:e.lt!==void 0?e.lt:void 0,i=e.gte===void 0,o=e.lte===void 0;return r!==void 0&&n!==void 0?IDBKeyRange.bound(r,n,i,o):r!==void 0?IDBKeyRange.lowerBound(r,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var Wg=oe((Jq,u2)=>{"use strict";l();var MU=new TextEncoder;u2.exports=function(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):MU.encode(t)}});var p2=oe(h2=>{"use strict";l();var{AbstractIterator:KU}=Fg(),d2=jg(),fh=Wg(),ei=Symbol("cache"),qi=Symbol("finished"),Cr=Symbol("options"),Fi=Symbol("currentOptions"),Qs=Symbol("position"),Gg=Symbol("location"),xa=Symbol("first"),f2={},zg=class extends KU{constructor(e,r,n){super(e,n),this[ei]=[],this[qi]=this.limit===0,this[Cr]=n,this[Fi]={...n},this[Qs]=void 0,this[Gg]=r,this[xa]=!0}_nextv(e,r,n){if(this[xa]=!1,this[qi])return this.nextTick(n,null,[]);if(this[ei].length>0)return e=Math.min(e,this[ei].length),this.nextTick(n,null,this[ei].splice(0,e));this[Qs]!==void 0&&(this[Cr].reverse?(this[Fi].lt=this[Qs],this[Fi].lte=void 0):(this[Fi].gt=this[Qs],this[Fi].gte=void 0));let i;try{i=d2(this[Fi])}catch{return this[qi]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Gg]],"readonly"),s=o.objectStore(this[Gg]),c=[];if(this[Cr].reverse){let a=!this[Cr].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=u=>{let d=u.target.result;if(d){let{key:f,value:h}=d;this[Qs]=f,c.push([this[Cr].keys&&f!==void 0?fh(f):void 0,this[Cr].values&&h!==void 0?fh(h):void 0]),c.length<e?d.continue():l2(o)}else this[qi]=!0}}else{let a,u,d=()=>{if(a===void 0||u===void 0)return;let f=Math.max(a.length,u.length);f===0||e===1/0?this[qi]=!0:this[Qs]=a[f-1],c.length=f;for(let h=0;h<f;h++){let p=a[h],g=u[h];c[h]=[this[Cr].keys&&p!==void 0?fh(p):void 0,this[Cr].values&&g!==void 0?fh(g):void 0]}l2(o)};this[Cr].keys||e<1/0?s.getAllKeys(i,e<1/0?e:void 0).onsuccess=f=>{a=f.target.result,d()}:(a=[],this.nextTick(d)),this[Cr].values?s.getAll(i,e<1/0?e:void 0).onsuccess=f=>{u=f.target.result,d()}:(u=[],this.nextTick(d))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(e){if(this[ei].length>0){let[r,n]=this[ei].shift();this.nextTick(e,null,r,n)}else if(this[qi])this.nextTick(e);else{let r=Math.min(100,this.limit-this.count);this[xa]&&(this[xa]=!1,r=1),this._nextv(r,f2,(n,i)=>{if(n)return e(n);this[ei]=i,this._next(e)})}}_all(e,r){this[xa]=!1;let n=this[ei].splice(0,this[ei].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(r,null,n);this._nextv(i,f2,(o,s)=>{if(o)return r(o);n.length>0&&(s=n.concat(s)),r(null,s)})}_seek(e,r){this[xa]=!0,this[ei]=[],this[qi]=!1,this[Qs]=void 0,this[Fi]={...this[Cr]};let n;try{n=d2(this[Cr])}catch{this[qi]=!0;return}n!==null&&!n.includes(e)?this[qi]=!0:this[Cr].reverse?this[Fi].lte=e:this[Fi].gte=e}};h2.Iterator=zg;function l2(t){typeof t.commit=="function"&&t.commit()}});var g2=oe((eF,y2)=>{"use strict";l();y2.exports=function(e,r,n,i,o){if(i.limit===0)return e.nextTick(o);let s=e.db.transaction([r],"readwrite"),c=s.objectStore(r),a=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let u=c.openKeyCursor?"openKeyCursor":"openCursor",d=i.reverse?"prev":"next";c[u](n,d).onsuccess=function(f){let h=f.target.result;h&&(c.delete(h.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&h.continue()})}}});var v2=oe(E2=>{"use strict";l();var{AbstractLevel:$U}=Fg(),m2=vn(),HU=c2(),{fromCallback:VU}=ad(),{Iterator:qU}=p2(),w2=Wg(),FU=g2(),jU=jg(),x2="level-js-",vd=Symbol("idb"),Yg=Symbol("namePrefix"),ji=Symbol("location"),Jg=Symbol("version"),ec=Symbol("store"),Sd=Symbol("onComplete"),b2=Symbol("promise"),lh=class extends $U{constructor(e,r,n){if(typeof r=="function"||typeof n=="function")throw new m2("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=r||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof e!="string")throw new Error("constructor requires a location string argument");this[ji]=e,this[Yg]=i??x2,this[Jg]=parseInt(o||1,10),this[vd]=null}get location(){return this[ji]}get namePrefix(){return this[Yg]}get version(){return this[Jg]}get db(){return this[vd]}get type(){return"browser-level"}_open(e,r){let n=indexedDB.open(this[Yg]+this[ji],this[Jg]);n.onerror=function(){r(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[vd]=n.result,r()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[ji])||o.createObjectStore(this[ji])}}[ec](e){return this[vd].transaction([this[ji]],e).objectStore(this[ji])}[Sd](e,r){let n=e.transaction;n.onabort=function(){r(n.error||new Error("aborted by user"))},n.oncomplete=function(){r(null,e.result)}}_get(e,r,n){let i=this[ec]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Sd](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new m2("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,w2(c))})}_getMany(e,r,n){let i=this[ec]("readonly"),o=e.map(s=>c=>{let a;try{a=i.get(s)}catch(u){return c(u)}a.onsuccess=()=>{let u=a.result;c(null,u===void 0?u:w2(u))},a.onerror=u=>{u.stopPropagation(),c(a.error)}});HU(o,16,n)}_del(e,r,n){let i=this[ec]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Sd](o,n)}_put(e,r,n,i){let o=this[ec]("readwrite"),s;try{s=o.put(r,e)}catch(c){return this.nextTick(i,c)}this[Sd](s,i)}_iterator(e){return new qU(this,this[ji],e)}_batch(e,r,n){let i=this[ec]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let u=e[s++],d=u.key,f;try{f=u.type==="del"?i.delete(d):i.put(u.value,d)}catch(h){c=h,o.abort();return}s<e.length?f.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(e,r){let n,i;try{n=jU(e)}catch{return this.nextTick(r)}if(e.limit>=0)return FU(this,this[ji],n,e,r);try{let o=this[ec]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(r,o)}this[Sd](i,r)}_close(e){this[vd].close(),this.nextTick(e)}};lh.destroy=function(t,e,r){typeof e=="function"&&(r=e,e=x2),r=VU(r,b2);let n=indexedDB.deleteDatabase(e+t);return n.onsuccess=function(){r()},n.onerror=function(i){r(i)},r[b2]};E2.BrowserLevel=lh});var Xg=oe(S2=>{l();S2.Level=v2().BrowserLevel});var nt=oe((fF,A2)=>{"use strict";l();A2.exports={ArrayIsArray(t){return Array.isArray(t)},ArrayPrototypeIncludes(t,e){return t.includes(e)},ArrayPrototypeIndexOf(t,e){return t.indexOf(e)},ArrayPrototypeJoin(t,e){return t.join(e)},ArrayPrototypeMap(t,e){return t.map(e)},ArrayPrototypePop(t,e){return t.pop(e)},ArrayPrototypePush(t,e){return t.push(e)},ArrayPrototypeSlice(t,e,r){return t.slice(e,r)},Error,FunctionPrototypeCall(t,e,...r){return t.call(e,...r)},FunctionPrototypeSymbolHasInstance(t,e){return Function.prototype[Symbol.hasInstance].call(t,e)},MathFloor:Math.floor,Number,NumberIsInteger:Number.isInteger,NumberIsNaN:Number.isNaN,NumberMAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,NumberMIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,NumberParseInt:Number.parseInt,ObjectDefineProperties(t,e){return Object.defineProperties(t,e)},ObjectDefineProperty(t,e,r){return Object.defineProperty(t,e,r)},ObjectGetOwnPropertyDescriptor(t,e){return Object.getOwnPropertyDescriptor(t,e)},ObjectKeys(t){return Object.keys(t)},ObjectSetPrototypeOf(t,e){return Object.setPrototypeOf(t,e)},Promise,PromisePrototypeCatch(t,e){return t.catch(e)},PromisePrototypeThen(t,e,r){return t.then(e,r)},PromiseReject(t){return Promise.reject(t)},PromiseResolve(t){return Promise.resolve(t)},ReflectApply:Reflect.apply,RegExpPrototypeTest(t,e){return t.test(e)},SafeSet:Set,String,StringPrototypeSlice(t,e,r){return t.slice(e,r)},StringPrototypeToLowerCase(t){return t.toLowerCase()},StringPrototypeToUpperCase(t){return t.toUpperCase()},StringPrototypeTrim(t){return t.trim()},Symbol,SymbolFor:Symbol.for,SymbolAsyncIterator:Symbol.asyncIterator,SymbolHasInstance:Symbol.hasInstance,SymbolIterator:Symbol.iterator,SymbolDispose:Symbol.dispose||Symbol("Symbol.dispose"),SymbolAsyncDispose:Symbol.asyncDispose||Symbol("Symbol.asyncDispose"),TypedArrayPrototypeSet(t,e,r){return t.set(e,r)},Boolean,Uint8Array}});var Ea=oe((hF,ph)=>{"use strict";l();var{AbortController:T2,AbortSignal:GU}=typeof self<"u"?self:typeof window<"u"?window:void 0;ph.exports=T2;ph.exports.AbortSignal=GU;ph.exports.default=T2});var Xt=oe((yF,Qg)=>{"use strict";l();var zU=Tr(),{kResistStopPropagation:YU,SymbolDispose:JU}=nt(),XU=globalThis.AbortSignal||Ea().AbortSignal,ZU=globalThis.AbortController||Ea().AbortController,QU=Object.getPrototypeOf(async function(){}).constructor,_2=globalThis.Blob||zU.Blob,eO=typeof _2<"u"?function(e){return e instanceof _2}:function(e){return!1},I2=(t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new ERR_INVALID_ARG_TYPE(e,"AbortSignal",t)},tO=(t,e)=>{if(typeof t!="function")throw new ERR_INVALID_ARG_TYPE(e,"Function",t)},Zg=class extends Error{constructor(e){if(!Array.isArray(e))throw new TypeError(`Expected input to be an Array, got ${typeof e}`);let r="";for(let n=0;n<e.length;n++)r+=` ${e[n].stack}
|
|
2
|
-
`;super(r),this.name="AggregateError",this.errors=e}};Qg.exports={AggregateError:Zg,kEmptyObject:Object.freeze({}),once(t){let e=!1;return function(...r){e||(e=!0,t.apply(this,r))}},createDeferredPromise:function(){let t,e;return{promise:new Promise((n,i)=>{t=n,e=i}),resolve:t,reject:e}},promisify(t){return new Promise((e,r)=>{t((n,...i)=>n?r(n):e(...i))})},debuglog(){return function(){}},format(t,...e){return t.replace(/%([sdifj])/g,function(...[r,n]){let i=e.shift();return n==="f"?i.toFixed(6):n==="j"?JSON.stringify(i):n==="s"&&typeof i=="object"?`${i.constructor!==Object?i.constructor.name:""} {}`.trim():i.toString()})},inspect(t){switch(typeof t){case"string":if(t.includes("'"))if(t.includes('"')){if(!t.includes("`")&&!t.includes("${"))return`\`${t}\``}else return`"${t}"`;return`'${t}'`;case"number":return isNaN(t)?"NaN":Object.is(t,-0)?String(t):t;case"bigint":return`${String(t)}n`;case"boolean":case"undefined":return String(t);case"object":return"{}"}},types:{isAsyncFunction(t){return t instanceof QU},isArrayBufferView(t){return ArrayBuffer.isView(t)}},isBlob:eO,deprecate(t,e){return t},addAbortListener:da().addAbortListener||function(e,r){if(e===void 0)throw new ERR_INVALID_ARG_TYPE("signal","AbortSignal",e);I2(e,"signal"),tO(r,"listener");let n;return e.aborted?queueMicrotask(()=>r()):(e.addEventListener("abort",r,{__proto__:null,once:!0,[YU]:!0}),n=()=>{e.removeEventListener("abort",r)}),{__proto__:null,[JU](){var i;(i=n)===null||i===void 0||i()}}},AbortSignalAny:XU.any||function(e){if(e.length===1)return e[0];let r=new ZU,n=()=>r.abort();return e.forEach(i=>{I2(i,"signals"),i.addEventListener("abort",n,{once:!0})}),r.signal.addEventListener("abort",()=>{e.forEach(i=>i.removeEventListener("abort",n))},{once:!0}),r.signal}};Qg.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")});var or=oe((mF,U2)=>{"use strict";l();var{format:rO,inspect:yh,AggregateError:nO}=Xt(),iO=globalThis.AggregateError||nO,oO=Symbol("kIsNodeError"),sO=["string","function","number","object","Function","Object","boolean","bigint","symbol"],cO=/^([A-Z][a-z0-9]*)+$/,aO="__node_internal_",gh={};function rc(t,e){if(!t)throw new gh.ERR_INTERNAL_ASSERTION(e)}function B2(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function uO(t,e,r){if(typeof e=="function")return rc(e.length<=r.length,`Code: ${t}; The provided arguments length (${r.length}) does not match the required ones (${e.length}).`),e(...r);let n=(e.match(/%[dfijoOs]/g)||[]).length;return rc(n===r.length,`Code: ${t}; The provided arguments length (${r.length}) does not match the required ones (${n}).`),r.length===0?e:rO(e,...r)}function Kt(t,e,r){r||(r=Error);class n extends r{constructor(...o){super(uO(t,e,o))}toString(){return`${this.name} [${t}]: ${this.message}`}}Object.defineProperties(n.prototype,{name:{value:r.name,writable:!0,enumerable:!1,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},writable:!0,enumerable:!1,configurable:!0}}),n.prototype.code=t,n.prototype[oO]=!0,gh[t]=n}function R2(t){let e=aO+t.name;return Object.defineProperty(t,"name",{value:e}),t}function dO(t,e){if(t&&e&&t!==e){if(Array.isArray(e.errors))return e.errors.push(t),e;let r=new iO([e,t],e.message);return r.code=e.code,r}return t||e}var em=class extends Error{constructor(e="The operation was aborted",r=void 0){if(r!==void 0&&typeof r!="object")throw new gh.ERR_INVALID_ARG_TYPE("options","Object",r);super(e,r),this.code="ABORT_ERR",this.name="AbortError"}};Kt("ERR_ASSERTION","%s",Error);Kt("ERR_INVALID_ARG_TYPE",(t,e,r)=>{rc(typeof t=="string","'name' must be a string"),Array.isArray(e)||(e=[e]);let n="The ";t.endsWith(" argument")?n+=`${t} `:n+=`"${t}" ${t.includes(".")?"property":"argument"} `,n+="must be ";let i=[],o=[],s=[];for(let a of e)rc(typeof a=="string","All expected entries have to be of type string"),sO.includes(a)?i.push(a.toLowerCase()):cO.test(a)?o.push(a):(rc(a!=="object",'The value "object" should be written as "Object"'),s.push(a));if(o.length>0){let a=i.indexOf("object");a!==-1&&(i.splice(i,a,1),o.push("Object"))}if(i.length>0){switch(i.length){case 1:n+=`of type ${i[0]}`;break;case 2:n+=`one of type ${i[0]} or ${i[1]}`;break;default:{let a=i.pop();n+=`one of type ${i.join(", ")}, or ${a}`}}(o.length>0||s.length>0)&&(n+=" or ")}if(o.length>0){switch(o.length){case 1:n+=`an instance of ${o[0]}`;break;case 2:n+=`an instance of ${o[0]} or ${o[1]}`;break;default:{let a=o.pop();n+=`an instance of ${o.join(", ")}, or ${a}`}}s.length>0&&(n+=" or ")}switch(s.length){case 0:break;case 1:s[0].toLowerCase()!==s[0]&&(n+="an "),n+=`${s[0]}`;break;case 2:n+=`one of ${s[0]} or ${s[1]}`;break;default:{let a=s.pop();n+=`one of ${s.join(", ")}, or ${a}`}}if(r==null)n+=`. Received ${r}`;else if(typeof r=="function"&&r.name)n+=`. Received function ${r.name}`;else if(typeof r=="object"){var c;if((c=r.constructor)!==null&&c!==void 0&&c.name)n+=`. Received an instance of ${r.constructor.name}`;else{let a=yh(r,{depth:-1});n+=`. Received ${a}`}}else{let a=yh(r,{colors:!1});a.length>25&&(a=`${a.slice(0,25)}...`),n+=`. Received type ${typeof r} (${a})`}return n},TypeError);Kt("ERR_INVALID_ARG_VALUE",(t,e,r="is invalid")=>{let n=yh(e);return n.length>128&&(n=n.slice(0,128)+"..."),`The ${t.includes(".")?"property":"argument"} '${t}' ${r}. Received ${n}`},TypeError);Kt("ERR_INVALID_RETURN_VALUE",(t,e,r)=>{var n;let i=r!=null&&(n=r.constructor)!==null&&n!==void 0&&n.name?`instance of ${r.constructor.name}`:`type ${typeof r}`;return`Expected ${t} to be returned from the "${e}" function but got ${i}.`},TypeError);Kt("ERR_MISSING_ARGS",(...t)=>{rc(t.length>0,"At least one arg needs to be specified");let e,r=t.length;switch(t=(Array.isArray(t)?t:[t]).map(n=>`"${n}"`).join(" or "),r){case 1:e+=`The ${t[0]} argument`;break;case 2:e+=`The ${t[0]} and ${t[1]} arguments`;break;default:{let n=t.pop();e+=`The ${t.join(", ")}, and ${n} arguments`}break}return`${e} must be specified`},TypeError);Kt("ERR_OUT_OF_RANGE",(t,e,r)=>{rc(e,'Missing "range" argument');let n;return Number.isInteger(r)&&Math.abs(r)>2**32?n=B2(String(r)):typeof r=="bigint"?(n=String(r),(r>2n**32n||r<-(2n**32n))&&(n=B2(n)),n+="n"):n=yh(r),`The value of "${t}" is out of range. It must be ${e}. Received ${n}`},RangeError);Kt("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error);Kt("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error);Kt("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error);Kt("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error);Kt("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error);Kt("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Kt("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error);Kt("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error);Kt("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error);Kt("ERR_STREAM_WRITE_AFTER_END","write after end",Error);Kt("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError);U2.exports={AbortError:em,aggregateTwoErrors:R2(dO),hideStackFrames:R2,codes:gh}});var Sa=oe((bF,$2)=>{"use strict";l();var{ArrayIsArray:rm,ArrayPrototypeIncludes:N2,ArrayPrototypeJoin:C2,ArrayPrototypeMap:fO,NumberIsInteger:nm,NumberIsNaN:lO,NumberMAX_SAFE_INTEGER:hO,NumberMIN_SAFE_INTEGER:pO,NumberParseInt:yO,ObjectPrototypeHasOwnProperty:gO,RegExpPrototypeExec:L2,String:mO,StringPrototypeToUpperCase:wO,StringPrototypeTrim:bO}=nt(),{hideStackFrames:tn,codes:{ERR_SOCKET_BAD_PORT:xO,ERR_INVALID_ARG_TYPE:Zt,ERR_INVALID_ARG_VALUE:va,ERR_OUT_OF_RANGE:nc,ERR_UNKNOWN_SIGNAL:O2}}=or(),{normalizeEncoding:EO}=Xt(),{isAsyncFunction:vO,isArrayBufferView:SO}=Xt().types,D2={};function AO(t){return t===(t|0)}function TO(t){return t===t>>>0}var _O=/^[0-7]+$/,IO="must be a 32-bit unsigned integer or an octal string";function BO(t,e,r){if(typeof t>"u"&&(t=r),typeof t=="string"){if(L2(_O,t)===null)throw new va(e,t,IO);t=yO(t,8)}return P2(t,e),t}var RO=tn((t,e,r=pO,n=hO)=>{if(typeof t!="number")throw new Zt(e,"number",t);if(!nm(t))throw new nc(e,"an integer",t);if(t<r||t>n)throw new nc(e,`>= ${r} && <= ${n}`,t)}),UO=tn((t,e,r=-2147483648,n=2147483647)=>{if(typeof t!="number")throw new Zt(e,"number",t);if(!nm(t))throw new nc(e,"an integer",t);if(t<r||t>n)throw new nc(e,`>= ${r} && <= ${n}`,t)}),P2=tn((t,e,r=!1)=>{if(typeof t!="number")throw new Zt(e,"number",t);if(!nm(t))throw new nc(e,"an integer",t);let n=r?1:0,i=4294967295;if(t<n||t>i)throw new nc(e,`>= ${n} && <= ${i}`,t)});function im(t,e){if(typeof t!="string")throw new Zt(e,"string",t)}function OO(t,e,r=void 0,n){if(typeof t!="number")throw new Zt(e,"number",t);if(r!=null&&t<r||n!=null&&t>n||(r!=null||n!=null)&&lO(t))throw new nc(e,`${r!=null?`>= ${r}`:""}${r!=null&&n!=null?" && ":""}${n!=null?`<= ${n}`:""}`,t)}var DO=tn((t,e,r)=>{if(!N2(r,t)){let i="must be one of: "+C2(fO(r,o=>typeof o=="string"?`'${o}'`:mO(o)),", ");throw new va(e,t,i)}});function M2(t,e){if(typeof t!="boolean")throw new Zt(e,"boolean",t)}function tm(t,e,r){return t==null||!gO(t,e)?r:t[e]}var kO=tn((t,e,r=null)=>{let n=tm(r,"allowArray",!1),i=tm(r,"allowFunction",!1);if(!tm(r,"nullable",!1)&&t===null||!n&&rm(t)||typeof t!="object"&&(!i||typeof t!="function"))throw new Zt(e,"Object",t)}),NO=tn((t,e)=>{if(t!=null&&typeof t!="object"&&typeof t!="function")throw new Zt(e,"a dictionary",t)}),mh=tn((t,e,r=0)=>{if(!rm(t))throw new Zt(e,"Array",t);if(t.length<r){let n=`must be longer than ${r}`;throw new va(e,t,n)}});function CO(t,e){mh(t,e);for(let r=0;r<t.length;r++)im(t[r],`${e}[${r}]`)}function LO(t,e){mh(t,e);for(let r=0;r<t.length;r++)M2(t[r],`${e}[${r}]`)}function PO(t,e){mh(t,e);for(let r=0;r<t.length;r++){let n=t[r],i=`${e}[${r}]`;if(n==null)throw new Zt(i,"AbortSignal",n);K2(n,i)}}function MO(t,e="signal"){if(im(t,e),D2[t]===void 0)throw D2[wO(t)]!==void 0?new O2(t+" (signals must use all capital letters)"):new O2(t)}var KO=tn((t,e="buffer")=>{if(!SO(t))throw new Zt(e,["Buffer","TypedArray","DataView"],t)});function $O(t,e){let r=EO(e),n=t.length;if(r==="hex"&&n%2!==0)throw new va("encoding",e,`is invalid for data of length ${n}`)}function HO(t,e="Port",r=!0){if(typeof t!="number"&&typeof t!="string"||typeof t=="string"&&bO(t).length===0||+t!==+t>>>0||t>65535||t===0&&!r)throw new xO(e,t,r);return t|0}var K2=tn((t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new Zt(e,"AbortSignal",t)}),VO=tn((t,e)=>{if(typeof t!="function")throw new Zt(e,"Function",t)}),qO=tn((t,e)=>{if(typeof t!="function"||vO(t))throw new Zt(e,"Function",t)}),FO=tn((t,e)=>{if(t!==void 0)throw new Zt(e,"undefined",t)});function jO(t,e,r){if(!N2(r,t))throw new Zt(e,`('${C2(r,"|")}')`,t)}var WO=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function k2(t,e){if(typeof t>"u"||!L2(WO,t))throw new va(e,t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}function GO(t){if(typeof t=="string")return k2(t,"hints"),t;if(rm(t)){let e=t.length,r="";if(e===0)return r;for(let n=0;n<e;n++){let i=t[n];k2(i,"hints"),r+=i,n!==e-1&&(r+=", ")}return r}throw new va("hints",t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}$2.exports={isInt32:AO,isUint32:TO,parseFileMode:BO,validateArray:mh,validateStringArray:CO,validateBooleanArray:LO,validateAbortSignalArray:PO,validateBoolean:M2,validateBuffer:KO,validateDictionary:NO,validateEncoding:$O,validateFunction:VO,validateInt32:UO,validateInteger:RO,validateNumber:OO,validateObject:kO,validateOneOf:DO,validatePlainFunction:qO,validatePort:HO,validateSignalName:MO,validateString:im,validateUint32:P2,validateUndefined:FO,validateUnion:jO,validateAbortSignal:K2,validateLinkHeaderValue:GO}});var ri=oe((EF,tS)=>{"use strict";l();var{SymbolAsyncIterator:H2,SymbolIterator:V2,SymbolFor:ic}=nt(),q2=ic("nodejs.stream.destroyed"),F2=ic("nodejs.stream.errored"),om=ic("nodejs.stream.readable"),sm=ic("nodejs.stream.writable"),j2=ic("nodejs.stream.disturbed"),zO=ic("nodejs.webstream.isClosedPromise"),YO=ic("nodejs.webstream.controllerErrorFunction");function wh(t,e=!1){var r;return!!(t&&typeof t.pipe=="function"&&typeof t.on=="function"&&(!e||typeof t.pause=="function"&&typeof t.resume=="function")&&(!t._writableState||((r=t._readableState)===null||r===void 0?void 0:r.readable)!==!1)&&(!t._writableState||t._readableState))}function bh(t){var e;return!!(t&&typeof t.write=="function"&&typeof t.on=="function"&&(!t._readableState||((e=t._writableState)===null||e===void 0?void 0:e.writable)!==!1))}function JO(t){return!!(t&&typeof t.pipe=="function"&&t._readableState&&typeof t.on=="function"&&typeof t.write=="function")}function ti(t){return t&&(t._readableState||t._writableState||typeof t.write=="function"&&typeof t.on=="function"||typeof t.pipe=="function"&&typeof t.on=="function")}function W2(t){return!!(t&&!ti(t)&&typeof t.pipeThrough=="function"&&typeof t.getReader=="function"&&typeof t.cancel=="function")}function G2(t){return!!(t&&!ti(t)&&typeof t.getWriter=="function"&&typeof t.abort=="function")}function z2(t){return!!(t&&!ti(t)&&typeof t.readable=="object"&&typeof t.writable=="object")}function XO(t){return W2(t)||G2(t)||z2(t)}function ZO(t,e){return t==null?!1:e===!0?typeof t[H2]=="function":e===!1?typeof t[V2]=="function":typeof t[H2]=="function"||typeof t[V2]=="function"}function xh(t){if(!ti(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!!(t.destroyed||t[q2]||n!=null&&n.destroyed)}function Y2(t){if(!bh(t))return null;if(t.writableEnded===!0)return!0;let e=t._writableState;return e!=null&&e.errored?!1:typeof e?.ended!="boolean"?null:e.ended}function QO(t,e){if(!bh(t))return null;if(t.writableFinished===!0)return!0;let r=t._writableState;return r!=null&&r.errored?!1:typeof r?.finished!="boolean"?null:!!(r.finished||e===!1&&r.ended===!0&&r.length===0)}function e5(t){if(!wh(t))return null;if(t.readableEnded===!0)return!0;let e=t._readableState;return!e||e.errored?!1:typeof e?.ended!="boolean"?null:e.ended}function J2(t,e){if(!wh(t))return null;let r=t._readableState;return r!=null&&r.errored?!1:typeof r?.endEmitted!="boolean"?null:!!(r.endEmitted||e===!1&&r.ended===!0&&r.length===0)}function X2(t){return t&&t[om]!=null?t[om]:typeof t?.readable!="boolean"?null:xh(t)?!1:wh(t)&&t.readable&&!J2(t)}function Z2(t){return t&&t[sm]!=null?t[sm]:typeof t?.writable!="boolean"?null:xh(t)?!1:bh(t)&&t.writable&&!Y2(t)}function t5(t,e){return ti(t)?xh(t)?!0:!(e?.readable!==!1&&X2(t)||e?.writable!==!1&&Z2(t)):null}function r5(t){var e,r;return ti(t)?t.writableErrored?t.writableErrored:(e=(r=t._writableState)===null||r===void 0?void 0:r.errored)!==null&&e!==void 0?e:null:null}function n5(t){var e,r;return ti(t)?t.readableErrored?t.readableErrored:(e=(r=t._readableState)===null||r===void 0?void 0:r.errored)!==null&&e!==void 0?e:null:null}function i5(t){if(!ti(t))return null;if(typeof t.closed=="boolean")return t.closed;let e=t._writableState,r=t._readableState;return typeof e?.closed=="boolean"||typeof r?.closed=="boolean"?e?.closed||r?.closed:typeof t._closed=="boolean"&&Q2(t)?t._closed:null}function Q2(t){return typeof t._closed=="boolean"&&typeof t._defaultKeepAlive=="boolean"&&typeof t._removedConnection=="boolean"&&typeof t._removedContLen=="boolean"}function eS(t){return typeof t._sent100=="boolean"&&Q2(t)}function o5(t){var e;return typeof t._consuming=="boolean"&&typeof t._dumped=="boolean"&&((e=t.req)===null||e===void 0?void 0:e.upgradeOrConnect)===void 0}function s5(t){if(!ti(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!n&&eS(t)||!!(n&&n.autoDestroy&&n.emitClose&&n.closed===!1)}function c5(t){var e;return!!(t&&((e=t[j2])!==null&&e!==void 0?e:t.readableDidRead||t.readableAborted))}function a5(t){var e,r,n,i,o,s,c,a,u,d;return!!(t&&((e=(r=(n=(i=(o=(s=t[F2])!==null&&s!==void 0?s:t.readableErrored)!==null&&o!==void 0?o:t.writableErrored)!==null&&i!==void 0?i:(c=t._readableState)===null||c===void 0?void 0:c.errorEmitted)!==null&&n!==void 0?n:(a=t._writableState)===null||a===void 0?void 0:a.errorEmitted)!==null&&r!==void 0?r:(u=t._readableState)===null||u===void 0?void 0:u.errored)!==null&&e!==void 0?e:!((d=t._writableState)===null||d===void 0)&&d.errored))}tS.exports={isDestroyed:xh,kIsDestroyed:q2,isDisturbed:c5,kIsDisturbed:j2,isErrored:a5,kIsErrored:F2,isReadable:X2,kIsReadable:om,kIsClosedPromise:zO,kControllerErrorFunction:YO,kIsWritable:sm,isClosed:i5,isDuplexNodeStream:JO,isFinished:t5,isIterable:ZO,isReadableNodeStream:wh,isReadableStream:W2,isReadableEnded:e5,isReadableFinished:J2,isReadableErrored:n5,isNodeStream:ti,isWebStream:XO,isWritable:Z2,isWritableNodeStream:bh,isWritableStream:G2,isWritableEnded:Y2,isWritableFinished:QO,isWritableErrored:r5,isServerRequest:o5,isServerResponse:eS,willEmitClose:s5,isTransformStream:z2}});var Wi=oe((SF,fm)=>{l();var qo=Ei(),{AbortError:dS,codes:u5}=or(),{ERR_INVALID_ARG_TYPE:d5,ERR_STREAM_PREMATURE_CLOSE:rS}=u5,{kEmptyObject:am,once:um}=Xt(),{validateAbortSignal:f5,validateFunction:l5,validateObject:h5,validateBoolean:p5}=Sa(),{Promise:y5,PromisePrototypeThen:g5,SymbolDispose:fS}=nt(),{isClosed:m5,isReadable:nS,isReadableNodeStream:cm,isReadableStream:w5,isReadableFinished:iS,isReadableErrored:oS,isWritable:sS,isWritableNodeStream:cS,isWritableStream:b5,isWritableFinished:aS,isWritableErrored:uS,isNodeStream:x5,willEmitClose:E5,kIsClosedPromise:v5}=ri(),Aa;function S5(t){return t.setHeader&&typeof t.abort=="function"}var dm=()=>{};function lS(t,e,r){var n,i;if(arguments.length===2?(r=e,e=am):e==null?e=am:h5(e,"options"),l5(r,"callback"),f5(e.signal,"options.signal"),r=um(r),w5(t)||b5(t))return A5(t,e,r);if(!x5(t))throw new d5("stream",["ReadableStream","WritableStream","Stream"],t);let o=(n=e.readable)!==null&&n!==void 0?n:cm(t),s=(i=e.writable)!==null&&i!==void 0?i:cS(t),c=t._writableState,a=t._readableState,u=()=>{t.writable||h()},d=E5(t)&&cm(t)===o&&cS(t)===s,f=aS(t,!1),h=()=>{f=!0,t.destroyed&&(d=!1),!(d&&(!t.readable||o))&&(!o||p)&&r.call(t)},p=iS(t,!1),g=()=>{p=!0,t.destroyed&&(d=!1),!(d&&(!t.writable||s))&&(!s||f)&&r.call(t)},y=T=>{r.call(t,T)},x=m5(t),S=()=>{x=!0;let T=uS(t)||oS(t);if(T&&typeof T!="boolean")return r.call(t,T);if(o&&!p&&cm(t,!0)&&!iS(t,!1))return r.call(t,new rS);if(s&&!f&&!aS(t,!1))return r.call(t,new rS);r.call(t)},_=()=>{x=!0;let T=uS(t)||oS(t);if(T&&typeof T!="boolean")return r.call(t,T);r.call(t)},A=()=>{t.req.on("finish",h)};S5(t)?(t.on("complete",h),d||t.on("abort",S),t.req?A():t.on("request",A)):s&&!c&&(t.on("end",u),t.on("close",u)),!d&&typeof t.aborted=="boolean"&&t.on("aborted",S),t.on("end",g),t.on("finish",h),e.error!==!1&&t.on("error",y),t.on("close",S),x?qo.nextTick(S):c!=null&&c.errorEmitted||a!=null&&a.errorEmitted?d||qo.nextTick(_):(!o&&(!d||nS(t))&&(f||sS(t)===!1)||!s&&(!d||sS(t))&&(p||nS(t)===!1)||a&&t.req&&t.aborted)&&qo.nextTick(_);let O=()=>{r=dm,t.removeListener("aborted",S),t.removeListener("complete",h),t.removeListener("abort",S),t.removeListener("request",A),t.req&&t.req.removeListener("finish",h),t.removeListener("end",u),t.removeListener("close",u),t.removeListener("finish",h),t.removeListener("end",g),t.removeListener("error",y),t.removeListener("close",S)};if(e.signal&&!x){let T=()=>{let M=r;O(),M.call(t,new dS(void 0,{cause:e.signal.reason}))};if(e.signal.aborted)qo.nextTick(T);else{Aa=Aa||Xt().addAbortListener;let M=Aa(e.signal,T),q=r;r=um((...j)=>{M[fS](),q.apply(t,j)})}}return O}function A5(t,e,r){let n=!1,i=dm;if(e.signal)if(i=()=>{n=!0,r.call(t,new dS(void 0,{cause:e.signal.reason}))},e.signal.aborted)qo.nextTick(i);else{Aa=Aa||Xt().addAbortListener;let s=Aa(e.signal,i),c=r;r=um((...a)=>{s[fS](),c.apply(t,a)})}let o=(...s)=>{n||qo.nextTick(()=>r.apply(t,s))};return g5(t[v5].promise,o,o),dm}function T5(t,e){var r;let n=!1;return e===null&&(e=am),(r=e)!==null&&r!==void 0&&r.cleanup&&(p5(e.cleanup,"cleanup"),n=e.cleanup),new y5((i,o)=>{let s=lS(t,e,c=>{n&&s(),c?o(c):i()})})}fm.exports=lS;fm.exports.finished=T5});var oc=oe((TF,xS)=>{"use strict";l();var ni=Ei(),{aggregateTwoErrors:_5,codes:{ERR_MULTIPLE_CALLBACK:I5},AbortError:B5}=or(),{Symbol:yS}=nt(),{kIsDestroyed:R5,isDestroyed:U5,isFinished:O5,isServerRequest:D5}=ri(),gS=yS("kDestroy"),lm=yS("kConstruct");function mS(t,e,r){t&&(t.stack,e&&!e.errored&&(e.errored=t),r&&!r.errored&&(r.errored=t))}function k5(t,e){let r=this._readableState,n=this._writableState,i=n||r;return n!=null&&n.destroyed||r!=null&&r.destroyed?(typeof e=="function"&&e(),this):(mS(t,n,r),n&&(n.destroyed=!0),r&&(r.destroyed=!0),i.constructed?hS(this,t,e):this.once(gS,function(o){hS(this,_5(o,t),e)}),this)}function hS(t,e,r){let n=!1;function i(o){if(n)return;n=!0;let s=t._readableState,c=t._writableState;mS(o,c,s),c&&(c.closed=!0),s&&(s.closed=!0),typeof r=="function"&&r(o),o?ni.nextTick(N5,t,o):ni.nextTick(wS,t)}try{t._destroy(e||null,i)}catch(o){i(o)}}function N5(t,e){hm(t,e),wS(t)}function wS(t){let e=t._readableState,r=t._writableState;r&&(r.closeEmitted=!0),e&&(e.closeEmitted=!0),(r!=null&&r.emitClose||e!=null&&e.emitClose)&&t.emit("close")}function hm(t,e){let r=t._readableState,n=t._writableState;n!=null&&n.errorEmitted||r!=null&&r.errorEmitted||(n&&(n.errorEmitted=!0),r&&(r.errorEmitted=!0),t.emit("error",e))}function C5(){let t=this._readableState,e=this._writableState;t&&(t.constructed=!0,t.closed=!1,t.closeEmitted=!1,t.destroyed=!1,t.errored=null,t.errorEmitted=!1,t.reading=!1,t.ended=t.readable===!1,t.endEmitted=t.readable===!1),e&&(e.constructed=!0,e.destroyed=!1,e.closed=!1,e.closeEmitted=!1,e.errored=null,e.errorEmitted=!1,e.finalCalled=!1,e.prefinished=!1,e.ended=e.writable===!1,e.ending=e.writable===!1,e.finished=e.writable===!1)}function pm(t,e,r){let n=t._readableState,i=t._writableState;if(i!=null&&i.destroyed||n!=null&&n.destroyed)return this;n!=null&&n.autoDestroy||i!=null&&i.autoDestroy?t.destroy(e):e&&(e.stack,i&&!i.errored&&(i.errored=e),n&&!n.errored&&(n.errored=e),r?ni.nextTick(hm,t,e):hm(t,e))}function L5(t,e){if(typeof t._construct!="function")return;let r=t._readableState,n=t._writableState;r&&(r.constructed=!1),n&&(n.constructed=!1),t.once(lm,e),!(t.listenerCount(lm)>1)&&ni.nextTick(P5,t)}function P5(t){let e=!1;function r(n){if(e){pm(t,n??new I5);return}e=!0;let i=t._readableState,o=t._writableState,s=o||i;i&&(i.constructed=!0),o&&(o.constructed=!0),s.destroyed?t.emit(gS,n):n?pm(t,n,!0):ni.nextTick(M5,t)}try{t._construct(n=>{ni.nextTick(r,n)})}catch(n){ni.nextTick(r,n)}}function M5(t){t.emit(lm)}function pS(t){return t?.setHeader&&typeof t.abort=="function"}function bS(t){t.emit("close")}function K5(t,e){t.emit("error",e),ni.nextTick(bS,t)}function $5(t,e){!t||U5(t)||(!e&&!O5(t)&&(e=new B5),D5(t)?(t.socket=null,t.destroy(e)):pS(t)?t.abort():pS(t.req)?t.req.abort():typeof t.destroy=="function"?t.destroy(e):typeof t.close=="function"?t.close():e?ni.nextTick(K5,t,e):ni.nextTick(bS,t),t.destroyed||(t[R5]=!0))}xS.exports={construct:L5,destroyer:$5,destroy:k5,undestroy:C5,errorOrDestroy:pm}});var Sh=oe((IF,vS)=>{"use strict";l();var{ArrayIsArray:H5,ObjectSetPrototypeOf:ES}=nt(),{EventEmitter:Eh}=da();function vh(t){Eh.call(this,t)}ES(vh.prototype,Eh.prototype);ES(vh,Eh);vh.prototype.pipe=function(t,e){let r=this;function n(d){t.writable&&t.write(d)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}t.on("drain",i),!t._isStdio&&(!e||e.end!==!1)&&(r.on("end",s),r.on("close",c));let o=!1;function s(){o||(o=!0,t.end())}function c(){o||(o=!0,typeof t.destroy=="function"&&t.destroy())}function a(d){u(),Eh.listenerCount(this,"error")===0&&this.emit("error",d)}ym(r,"error",a),ym(t,"error",a);function u(){r.removeListener("data",n),t.removeListener("drain",i),r.removeListener("end",s),r.removeListener("close",c),r.removeListener("error",a),t.removeListener("error",a),r.removeListener("end",u),r.removeListener("close",u),t.removeListener("close",u)}return r.on("end",u),r.on("close",u),t.on("close",u),t.emit("pipe",r),t};function ym(t,e,r){if(typeof t.prependListener=="function")return t.prependListener(e,r);!t._events||!t._events[e]?t.on(e,r):H5(t._events[e])?t._events[e].unshift(r):t._events[e]=[r,t._events[e]]}vS.exports={Stream:vh,prependListener:ym}});var Ad=oe((RF,Ah)=>{"use strict";l();var{SymbolDispose:V5}=nt(),{AbortError:SS,codes:q5}=or(),{isNodeStream:AS,isWebStream:F5,kControllerErrorFunction:j5}=ri(),W5=Wi(),{ERR_INVALID_ARG_TYPE:TS}=q5,gm,G5=(t,e)=>{if(typeof t!="object"||!("aborted"in t))throw new TS(e,"AbortSignal",t)};Ah.exports.addAbortSignal=function(e,r){if(G5(e,"signal"),!AS(r)&&!F5(r))throw new TS("stream",["ReadableStream","WritableStream","Stream"],r);return Ah.exports.addAbortSignalNoValidate(e,r)};Ah.exports.addAbortSignalNoValidate=function(t,e){if(typeof t!="object"||!("aborted"in t))return e;let r=AS(e)?()=>{e.destroy(new SS(void 0,{cause:t.reason}))}:()=>{e[j5](new SS(void 0,{cause:t.reason}))};if(t.aborted)r();else{gm=gm||Xt().addAbortListener;let n=gm(t,r);W5(e,n[V5])}return e}});var BS=oe((DF,IS)=>{"use strict";l();var{StringPrototypeSlice:_S,SymbolIterator:z5,TypedArrayPrototypeSet:Th,Uint8Array:Y5}=nt(),{Buffer:mm}=Tr(),{inspect:J5}=Xt();IS.exports=class{constructor(){this.head=null,this.tail=null,this.length=0}push(e){let r={data:e,next:null};this.length>0?this.tail.next=r:this.head=r,this.tail=r,++this.length}unshift(e){let r={data:e,next:this.head};this.length===0&&(this.tail=r),this.head=r,++this.length}shift(){if(this.length===0)return;let e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}clear(){this.head=this.tail=null,this.length=0}join(e){if(this.length===0)return"";let r=this.head,n=""+r.data;for(;(r=r.next)!==null;)n+=e+r.data;return n}concat(e){if(this.length===0)return mm.alloc(0);let r=mm.allocUnsafe(e>>>0),n=this.head,i=0;for(;n;)Th(r,n.data,i),i+=n.data.length,n=n.next;return r}consume(e,r){let n=this.head.data;if(e<n.length){let i=n.slice(0,e);return this.head.data=n.slice(e),i}return e===n.length?this.shift():r?this._getString(e):this._getBuffer(e)}first(){return this.head.data}*[z5](){for(let e=this.head;e;e=e.next)yield e.data}_getString(e){let r="",n=this.head,i=0;do{let o=n.data;if(e>o.length)r+=o,e-=o.length;else{e===o.length?(r+=o,++i,n.next?this.head=n.next:this.head=this.tail=null):(r+=_S(o,0,e),this.head=n,n.data=_S(o,e));break}++i}while((n=n.next)!==null);return this.length-=i,r}_getBuffer(e){let r=mm.allocUnsafe(e),n=e,i=this.head,o=0;do{let s=i.data;if(e>s.length)Th(r,s,n-e),e-=s.length;else{e===s.length?(Th(r,s,n-e),++o,i.next?this.head=i.next:this.head=this.tail=null):(Th(r,new Y5(s.buffer,s.byteOffset,e),n-e),this.head=i,i.data=s.slice(e));break}++o}while((i=i.next)!==null);return this.length-=o,r}[Symbol.for("nodejs.util.inspect.custom")](e,r){return J5(this,{...r,depth:0,customInspect:!1})}}});var Td=oe((NF,DS)=>{"use strict";l();var{MathFloor:X5,NumberIsInteger:Z5}=nt(),{validateInteger:Q5}=Sa(),{ERR_INVALID_ARG_VALUE:e3}=or().codes,RS=16*1024,US=16;function t3(t,e,r){return t.highWaterMark!=null?t.highWaterMark:e?t[r]:null}function OS(t){return t?US:RS}function r3(t,e){Q5(e,"value",0),t?US=e:RS=e}function n3(t,e,r,n){let i=t3(e,n,r);if(i!=null){if(!Z5(i)||i<0){let o=n?`options.${r}`:"options.highWaterMark";throw new e3(o,i)}return X5(i)}return OS(t.objectMode)}DS.exports={getHighWaterMark:n3,getDefaultHighWaterMark:OS,setDefaultHighWaterMark:r3}});var CS=oe((wm,NS)=>{l();var _h=Tr(),ii=_h.Buffer;function kS(t,e){for(var r in t)e[r]=t[r]}ii.from&&ii.alloc&&ii.allocUnsafe&&ii.allocUnsafeSlow?NS.exports=_h:(kS(_h,wm),wm.Buffer=sc);function sc(t,e,r){return ii(t,e,r)}sc.prototype=Object.create(ii.prototype);kS(ii,sc);sc.from=function(t,e,r){if(typeof t=="number")throw new TypeError("Argument must not be a number");return ii(t,e,r)};sc.alloc=function(t,e,r){if(typeof t!="number")throw new TypeError("Argument must be a number");var n=ii(t);return e!==void 0?typeof r=="string"?n.fill(e,r):n.fill(e):n.fill(0),n};sc.allocUnsafe=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return ii(t)};sc.allocUnsafeSlow=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return _h.SlowBuffer(t)}});var MS=oe(PS=>{"use strict";l();var xm=CS().Buffer,LS=xm.isEncoding||function(t){switch(t=""+t,t&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function i3(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}function o3(t){var e=i3(t);if(typeof e!="string"&&(xm.isEncoding===LS||!LS(t)))throw new Error("Unknown encoding: "+t);return e||t}PS.StringDecoder=_d;function _d(t){this.encoding=o3(t);var e;switch(this.encoding){case"utf16le":this.text=f3,this.end=l3,e=4;break;case"utf8":this.fillLast=a3,e=4;break;case"base64":this.text=h3,this.end=p3,e=3;break;default:this.write=y3,this.end=g3;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=xm.allocUnsafe(e)}_d.prototype.write=function(t){if(t.length===0)return"";var e,r;if(this.lastNeed){if(e=this.fillLast(t),e===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<t.length?e?e+this.text(t,r):this.text(t,r):e||""};_d.prototype.end=d3;_d.prototype.text=u3;_d.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length};function bm(t){return t<=127?0:t>>5===6?2:t>>4===14?3:t>>3===30?4:t>>6===2?-1:-2}function s3(t,e,r){var n=e.length-1;if(n<r)return 0;var i=bm(e[n]);return i>=0?(i>0&&(t.lastNeed=i-1),i):--n<r||i===-2?0:(i=bm(e[n]),i>=0?(i>0&&(t.lastNeed=i-2),i):--n<r||i===-2?0:(i=bm(e[n]),i>=0?(i>0&&(i===2?i=0:t.lastNeed=i-3),i):0))}function c3(t,e,r){if((e[0]&192)!==128)return t.lastNeed=0,"\uFFFD";if(t.lastNeed>1&&e.length>1){if((e[1]&192)!==128)return t.lastNeed=1,"\uFFFD";if(t.lastNeed>2&&e.length>2&&(e[2]&192)!==128)return t.lastNeed=2,"\uFFFD"}}function a3(t){var e=this.lastTotal-this.lastNeed,r=c3(this,t,e);if(r!==void 0)return r;if(this.lastNeed<=t.length)return t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,e,0,t.length),this.lastNeed-=t.length}function u3(t,e){var r=s3(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=r;var n=t.length-(r-this.lastNeed);return t.copy(this.lastChar,0,n),t.toString("utf8",e,n)}function d3(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"\uFFFD":e}function f3(t,e){if((t.length-e)%2===0){var r=t.toString("utf16le",e);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function l3(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,r)}return e}function h3(t,e){var r=(t.length-e)%3;return r===0?t.toString("base64",e):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-r))}function p3(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function y3(t){return t.toString(this.encoding)}function g3(t){return t&&t.length?this.write(t):""}});var Em=oe((KF,VS)=>{"use strict";l();var KS=Ei(),{PromisePrototypeThen:m3,SymbolAsyncIterator:$S,SymbolIterator:HS}=nt(),{Buffer:w3}=Tr(),{ERR_INVALID_ARG_TYPE:b3,ERR_STREAM_NULL_VALUES:x3}=or().codes;function E3(t,e,r){let n;if(typeof e=="string"||e instanceof w3)return new t({objectMode:!0,...r,read(){this.push(e),this.push(null)}});let i;if(e&&e[$S])i=!0,n=e[$S]();else if(e&&e[HS])i=!1,n=e[HS]();else throw new b3("iterable",["Iterable"],e);let o=new t({objectMode:!0,highWaterMark:1,...r}),s=!1;o._read=function(){s||(s=!0,a())},o._destroy=function(u,d){m3(c(u),()=>KS.nextTick(d,u),f=>KS.nextTick(d,f||u))};async function c(u){let d=u!=null,f=typeof n.throw=="function";if(d&&f){let{value:h,done:p}=await n.throw(u);if(await h,p)return}if(typeof n.return=="function"){let{value:h}=await n.return();await h}}async function a(){for(;;){try{let{value:u,done:d}=i?await n.next():n.next();if(d)o.push(null);else{let f=u&&typeof u.then=="function"?await u:u;if(f===null)throw s=!1,new x3;if(o.push(f))continue;s=!1}}catch(u){o.destroy(u)}break}}return o}VS.exports=E3});var Bd=oe((HF,sA)=>{l();var Tn=Ei(),{ArrayPrototypeIndexOf:v3,NumberIsInteger:S3,NumberIsNaN:A3,NumberParseInt:T3,ObjectDefineProperties:Rm,ObjectKeys:_3,ObjectSetPrototypeOf:jS,Promise:WS,SafeSet:I3,SymbolAsyncDispose:B3,SymbolAsyncIterator:R3,Symbol:U3}=nt();sA.exports=ye;ye.ReadableState=Uh;var{EventEmitter:O3}=da(),{Stream:Fo,prependListener:D3}=Sh(),{Buffer:vm}=Tr(),{addAbortSignal:k3}=Ad(),GS=Wi(),Ee=Xt().debuglog("stream",t=>{Ee=t}),N3=BS(),Ia=oc(),{getHighWaterMark:C3,getDefaultHighWaterMark:L3}=Td(),{aggregateTwoErrors:qS,codes:{ERR_INVALID_ARG_TYPE:P3,ERR_METHOD_NOT_IMPLEMENTED:M3,ERR_OUT_OF_RANGE:K3,ERR_STREAM_PUSH_AFTER_EOF:$3,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:H3},AbortError:V3}=or(),{validateObject:q3}=Sa(),cc=U3("kPaused"),{StringDecoder:zS}=MS(),F3=Em();jS(ye.prototype,Fo.prototype);jS(ye,Fo);var Sm=()=>{},{errorOrDestroy:Ta}=Ia,_a=1,j3=2,YS=4,Id=8,JS=16,Ih=32,Bh=64,XS=128,W3=256,G3=512,z3=1024,Im=2048,Bm=4096,Y3=8192,J3=16384,X3=32768,ZS=65536,Z3=1<<17,Q3=1<<18;function Tt(t){return{enumerable:!1,get(){return(this.state&t)!==0},set(e){e?this.state|=t:this.state&=~t}}}Rm(Uh.prototype,{objectMode:Tt(_a),ended:Tt(j3),endEmitted:Tt(YS),reading:Tt(Id),constructed:Tt(JS),sync:Tt(Ih),needReadable:Tt(Bh),emittedReadable:Tt(XS),readableListening:Tt(W3),resumeScheduled:Tt(G3),errorEmitted:Tt(z3),emitClose:Tt(Im),autoDestroy:Tt(Bm),destroyed:Tt(Y3),closed:Tt(J3),closeEmitted:Tt(X3),multiAwaitDrain:Tt(ZS),readingMore:Tt(Z3),dataEmitted:Tt(Q3)});function Uh(t,e,r){typeof r!="boolean"&&(r=e instanceof oi()),this.state=Im|Bm|JS|Ih,t&&t.objectMode&&(this.state|=_a),r&&t&&t.readableObjectMode&&(this.state|=_a),this.highWaterMark=t?C3(this,t,"readableHighWaterMark",r):L3(!1),this.buffer=new N3,this.length=0,this.pipes=[],this.flowing=null,this[cc]=null,t&&t.emitClose===!1&&(this.state&=~Im),t&&t.autoDestroy===!1&&(this.state&=~Bm),this.errored=null,this.defaultEncoding=t&&t.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,t&&t.encoding&&(this.decoder=new zS(t.encoding),this.encoding=t.encoding)}function ye(t){if(!(this instanceof ye))return new ye(t);let e=this instanceof oi();this._readableState=new Uh(t,this,e),t&&(typeof t.read=="function"&&(this._read=t.read),typeof t.destroy=="function"&&(this._destroy=t.destroy),typeof t.construct=="function"&&(this._construct=t.construct),t.signal&&!e&&k3(t.signal,this)),Fo.call(this,t),Ia.construct(this,()=>{this._readableState.needReadable&&Rh(this,this._readableState)})}ye.prototype.destroy=Ia.destroy;ye.prototype._undestroy=Ia.undestroy;ye.prototype._destroy=function(t,e){e(t)};ye.prototype[O3.captureRejectionSymbol]=function(t){this.destroy(t)};ye.prototype[B3]=function(){let t;return this.destroyed||(t=this.readableEnded?null:new V3,this.destroy(t)),new WS((e,r)=>GS(this,n=>n&&n!==t?r(n):e(null)))};ye.prototype.push=function(t,e){return QS(this,t,e,!1)};ye.prototype.unshift=function(t,e){return QS(this,t,e,!0)};function QS(t,e,r,n){Ee("readableAddChunk",e);let i=t._readableState,o;if(i.state&_a||(typeof e=="string"?(r=r||i.defaultEncoding,i.encoding!==r&&(n&&i.encoding?e=vm.from(e,r).toString(i.encoding):(e=vm.from(e,r),r=""))):e instanceof vm?r="":Fo._isUint8Array(e)?(e=Fo._uint8ArrayToBuffer(e),r=""):e!=null&&(o=new P3("chunk",["string","Buffer","Uint8Array"],e))),o)Ta(t,o);else if(e===null)i.state&=~Id,rD(t,i);else if(i.state&_a||e&&e.length>0)if(n)if(i.state&YS)Ta(t,new H3);else{if(i.destroyed||i.errored)return!1;Am(t,i,e,!0)}else if(i.ended)Ta(t,new $3);else{if(i.destroyed||i.errored)return!1;i.state&=~Id,i.decoder&&!r?(e=i.decoder.write(e),i.objectMode||e.length!==0?Am(t,i,e,!1):Rh(t,i)):Am(t,i,e,!1)}else n||(i.state&=~Id,Rh(t,i));return!i.ended&&(i.length<i.highWaterMark||i.length===0)}function Am(t,e,r,n){e.flowing&&e.length===0&&!e.sync&&t.listenerCount("data")>0?(e.state&ZS?e.awaitDrainWriters.clear():e.awaitDrainWriters=null,e.dataEmitted=!0,t.emit("data",r)):(e.length+=e.objectMode?1:r.length,n?e.buffer.unshift(r):e.buffer.push(r),e.state&Bh&&Oh(t)),Rh(t,e)}ye.prototype.isPaused=function(){let t=this._readableState;return t[cc]===!0||t.flowing===!1};ye.prototype.setEncoding=function(t){let e=new zS(t);this._readableState.decoder=e,this._readableState.encoding=this._readableState.decoder.encoding;let r=this._readableState.buffer,n="";for(let i of r)n+=e.write(i);return r.clear(),n!==""&&r.push(n),this._readableState.length=n.length,this};var eD=1073741824;function tD(t){if(t>eD)throw new K3("size","<= 1GiB",t);return t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++,t}function FS(t,e){return t<=0||e.length===0&&e.ended?0:e.state&_a?1:A3(t)?e.flowing&&e.length?e.buffer.first().length:e.length:t<=e.length?t:e.ended?e.length:0}ye.prototype.read=function(t){Ee("read",t),t===void 0?t=NaN:S3(t)||(t=T3(t,10));let e=this._readableState,r=t;if(t>e.highWaterMark&&(e.highWaterMark=tD(t)),t!==0&&(e.state&=~XS),t===0&&e.needReadable&&((e.highWaterMark!==0?e.length>=e.highWaterMark:e.length>0)||e.ended))return Ee("read: emitReadable",e.length,e.ended),e.length===0&&e.ended?Tm(this):Oh(this),null;if(t=FS(t,e),t===0&&e.ended)return e.length===0&&Tm(this),null;let n=(e.state&Bh)!==0;if(Ee("need readable",n),(e.length===0||e.length-t<e.highWaterMark)&&(n=!0,Ee("length less than watermark",n)),e.ended||e.reading||e.destroyed||e.errored||!e.constructed)n=!1,Ee("reading, ended or constructing",n);else if(n){Ee("do read"),e.state|=Id|Ih,e.length===0&&(e.state|=Bh);try{this._read(e.highWaterMark)}catch(o){Ta(this,o)}e.state&=~Ih,e.reading||(t=FS(r,e))}let i;return t>0?i=iA(t,e):i=null,i===null?(e.needReadable=e.length<=e.highWaterMark,t=0):(e.length-=t,e.multiAwaitDrain?e.awaitDrainWriters.clear():e.awaitDrainWriters=null),e.length===0&&(e.ended||(e.needReadable=!0),r!==t&&e.ended&&Tm(this)),i!==null&&!e.errorEmitted&&!e.closeEmitted&&(e.dataEmitted=!0,this.emit("data",i)),i};function rD(t,e){if(Ee("onEofChunk"),!e.ended){if(e.decoder){let r=e.decoder.end();r&&r.length&&(e.buffer.push(r),e.length+=e.objectMode?1:r.length)}e.ended=!0,e.sync?Oh(t):(e.needReadable=!1,e.emittedReadable=!0,eA(t))}}function Oh(t){let e=t._readableState;Ee("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(Ee("emitReadable",e.flowing),e.emittedReadable=!0,Tn.nextTick(eA,t))}function eA(t){let e=t._readableState;Ee("emitReadable_",e.destroyed,e.length,e.ended),!e.destroyed&&!e.errored&&(e.length||e.ended)&&(t.emit("readable"),e.emittedReadable=!1),e.needReadable=!e.flowing&&!e.ended&&e.length<=e.highWaterMark,rA(t)}function Rh(t,e){!e.readingMore&&e.constructed&&(e.readingMore=!0,Tn.nextTick(nD,t,e))}function nD(t,e){for(;!e.reading&&!e.ended&&(e.length<e.highWaterMark||e.flowing&&e.length===0);){let r=e.length;if(Ee("maybeReadMore read 0"),t.read(0),r===e.length)break}e.readingMore=!1}ye.prototype._read=function(t){throw new M3("_read()")};ye.prototype.pipe=function(t,e){let r=this,n=this._readableState;n.pipes.length===1&&(n.multiAwaitDrain||(n.multiAwaitDrain=!0,n.awaitDrainWriters=new I3(n.awaitDrainWriters?[n.awaitDrainWriters]:[]))),n.pipes.push(t),Ee("pipe count=%d opts=%j",n.pipes.length,e);let o=(!e||e.end!==!1)&&t!==Tn.stdout&&t!==Tn.stderr?c:x;n.endEmitted?Tn.nextTick(o):r.once("end",o),t.on("unpipe",s);function s(S,_){Ee("onunpipe"),S===r&&_&&_.hasUnpiped===!1&&(_.hasUnpiped=!0,d())}function c(){Ee("onend"),t.end()}let a,u=!1;function d(){Ee("cleanup"),t.removeListener("close",g),t.removeListener("finish",y),a&&t.removeListener("drain",a),t.removeListener("error",p),t.removeListener("unpipe",s),r.removeListener("end",c),r.removeListener("end",x),r.removeListener("data",h),u=!0,a&&n.awaitDrainWriters&&(!t._writableState||t._writableState.needDrain)&&a()}function f(){u||(n.pipes.length===1&&n.pipes[0]===t?(Ee("false write response, pause",0),n.awaitDrainWriters=t,n.multiAwaitDrain=!1):n.pipes.length>1&&n.pipes.includes(t)&&(Ee("false write response, pause",n.awaitDrainWriters.size),n.awaitDrainWriters.add(t)),r.pause()),a||(a=iD(r,t),t.on("drain",a))}r.on("data",h);function h(S){Ee("ondata");let _=t.write(S);Ee("dest.write",_),_===!1&&f()}function p(S){if(Ee("onerror",S),x(),t.removeListener("error",p),t.listenerCount("error")===0){let _=t._writableState||t._readableState;_&&!_.errorEmitted?Ta(t,S):t.emit("error",S)}}D3(t,"error",p);function g(){t.removeListener("finish",y),x()}t.once("close",g);function y(){Ee("onfinish"),t.removeListener("close",g),x()}t.once("finish",y);function x(){Ee("unpipe"),r.unpipe(t)}return t.emit("pipe",r),t.writableNeedDrain===!0?f():n.flowing||(Ee("pipe resume"),r.resume()),t};function iD(t,e){return function(){let n=t._readableState;n.awaitDrainWriters===e?(Ee("pipeOnDrain",1),n.awaitDrainWriters=null):n.multiAwaitDrain&&(Ee("pipeOnDrain",n.awaitDrainWriters.size),n.awaitDrainWriters.delete(e)),(!n.awaitDrainWriters||n.awaitDrainWriters.size===0)&&t.listenerCount("data")&&t.resume()}}ye.prototype.unpipe=function(t){let e=this._readableState,r={hasUnpiped:!1};if(e.pipes.length===0)return this;if(!t){let i=e.pipes;e.pipes=[],this.pause();for(let o=0;o<i.length;o++)i[o].emit("unpipe",this,{hasUnpiped:!1});return this}let n=v3(e.pipes,t);return n===-1?this:(e.pipes.splice(n,1),e.pipes.length===0&&this.pause(),t.emit("unpipe",this,r),this)};ye.prototype.on=function(t,e){let r=Fo.prototype.on.call(this,t,e),n=this._readableState;return t==="data"?(n.readableListening=this.listenerCount("readable")>0,n.flowing!==!1&&this.resume()):t==="readable"&&!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.flowing=!1,n.emittedReadable=!1,Ee("on readable",n.length,n.reading),n.length?Oh(this):n.reading||Tn.nextTick(oD,this)),r};ye.prototype.addListener=ye.prototype.on;ye.prototype.removeListener=function(t,e){let r=Fo.prototype.removeListener.call(this,t,e);return t==="readable"&&Tn.nextTick(tA,this),r};ye.prototype.off=ye.prototype.removeListener;ye.prototype.removeAllListeners=function(t){let e=Fo.prototype.removeAllListeners.apply(this,arguments);return(t==="readable"||t===void 0)&&Tn.nextTick(tA,this),e};function tA(t){let e=t._readableState;e.readableListening=t.listenerCount("readable")>0,e.resumeScheduled&&e[cc]===!1?e.flowing=!0:t.listenerCount("data")>0?t.resume():e.readableListening||(e.flowing=null)}function oD(t){Ee("readable nexttick read 0"),t.read(0)}ye.prototype.resume=function(){let t=this._readableState;return t.flowing||(Ee("resume"),t.flowing=!t.readableListening,sD(this,t)),t[cc]=!1,this};function sD(t,e){e.resumeScheduled||(e.resumeScheduled=!0,Tn.nextTick(cD,t,e))}function cD(t,e){Ee("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),rA(t),e.flowing&&!e.reading&&t.read(0)}ye.prototype.pause=function(){return Ee("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(Ee("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState[cc]=!0,this};function rA(t){let e=t._readableState;for(Ee("flow",e.flowing);e.flowing&&t.read()!==null;);}ye.prototype.wrap=function(t){let e=!1;t.on("data",n=>{!this.push(n)&&t.pause&&(e=!0,t.pause())}),t.on("end",()=>{this.push(null)}),t.on("error",n=>{Ta(this,n)}),t.on("close",()=>{this.destroy()}),t.on("destroy",()=>{this.destroy()}),this._read=()=>{e&&t.resume&&(e=!1,t.resume())};let r=_3(t);for(let n=1;n<r.length;n++){let i=r[n];this[i]===void 0&&typeof t[i]=="function"&&(this[i]=t[i].bind(t))}return this};ye.prototype[R3]=function(){return nA(this)};ye.prototype.iterator=function(t){return t!==void 0&&q3(t,"options"),nA(this,t)};function nA(t,e){typeof t.read!="function"&&(t=ye.wrap(t,{objectMode:!0}));let r=aD(t,e);return r.stream=t,r}async function*aD(t,e){let r=Sm;function n(s){this===t?(r(),r=Sm):r=s}t.on("readable",n);let i,o=GS(t,{writable:!1},s=>{i=s?qS(i,s):null,r(),r=Sm});try{for(;;){let s=t.destroyed?null:t.read();if(s!==null)yield s;else{if(i)throw i;if(i===null)return;await new WS(n)}}}catch(s){throw i=qS(i,s),i}finally{(i||e?.destroyOnReturn!==!1)&&(i===void 0||t._readableState.autoDestroy)?Ia.destroyer(t,null):(t.off("readable",n),o())}}Rm(ye.prototype,{readable:{__proto__:null,get(){let t=this._readableState;return!!t&&t.readable!==!1&&!t.destroyed&&!t.errorEmitted&&!t.endEmitted},set(t){this._readableState&&(this._readableState.readable=!!t)}},readableDidRead:{__proto__:null,enumerable:!1,get:function(){return this._readableState.dataEmitted}},readableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._readableState.readable!==!1&&(this._readableState.destroyed||this._readableState.errored)&&!this._readableState.endEmitted)}},readableHighWaterMark:{__proto__:null,enumerable:!1,get:function(){return this._readableState.highWaterMark}},readableBuffer:{__proto__:null,enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}},readableFlowing:{__proto__:null,enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}},readableLength:{__proto__:null,enumerable:!1,get(){return this._readableState.length}},readableObjectMode:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.objectMode:!1}},readableEncoding:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.encoding:null}},errored:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.errored:null}},closed:{__proto__:null,get(){return this._readableState?this._readableState.closed:!1}},destroyed:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.destroyed:!1},set(t){this._readableState&&(this._readableState.destroyed=t)}},readableEnded:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.endEmitted:!1}}});Rm(Uh.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return this[cc]!==!1},set(t){this[cc]=!!t}}});ye._fromList=iA;function iA(t,e){if(e.length===0)return null;let r;return e.objectMode?r=e.buffer.shift():!t||t>=e.length?(e.decoder?r=e.buffer.join(""):e.buffer.length===1?r=e.buffer.first():r=e.buffer.concat(e.length),e.buffer.clear()):r=e.buffer.consume(t,e.decoder),r}function Tm(t){let e=t._readableState;Ee("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,Tn.nextTick(uD,e,t))}function uD(t,e){if(Ee("endReadableNT",t.endEmitted,t.length),!t.errored&&!t.closeEmitted&&!t.endEmitted&&t.length===0){if(t.endEmitted=!0,e.emit("end"),e.writable&&e.allowHalfOpen===!1)Tn.nextTick(dD,e);else if(t.autoDestroy){let r=e._writableState;(!r||r.autoDestroy&&(r.finished||r.writable===!1))&&e.destroy()}}}function dD(t){t.writable&&!t.writableEnded&&!t.destroyed&&t.end()}ye.from=function(t,e){return F3(ye,t,e)};var _m;function oA(){return _m===void 0&&(_m={}),_m}ye.fromWeb=function(t,e){return oA().newStreamReadableFromReadableStream(t,e)};ye.toWeb=function(t,e){return oA().newReadableStreamFromStreamReadable(t,e)};ye.wrap=function(t,e){var r,n;return new ye({objectMode:(r=(n=t.readableObjectMode)!==null&&n!==void 0?n:t.objectMode)!==null&&r!==void 0?r:!0,...e,destroy(i,o){Ia.destroyer(t,i),o(i)}}).wrap(t)}});var Lh=oe((qF,wA)=>{l();var ac=Ei(),{ArrayPrototypeSlice:uA,Error:fD,FunctionPrototypeSymbolHasInstance:dA,ObjectDefineProperty:fA,ObjectDefineProperties:lD,ObjectSetPrototypeOf:lA,StringPrototypeToLowerCase:hD,Symbol:pD,SymbolHasInstance:yD}=nt();wA.exports=it;it.WritableState=Od;var{EventEmitter:gD}=da(),Rd=Sh().Stream,{Buffer:Dh}=Tr(),Ch=oc(),{addAbortSignal:mD}=Ad(),{getHighWaterMark:wD,getDefaultHighWaterMark:bD}=Td(),{ERR_INVALID_ARG_TYPE:xD,ERR_METHOD_NOT_IMPLEMENTED:ED,ERR_MULTIPLE_CALLBACK:hA,ERR_STREAM_CANNOT_PIPE:vD,ERR_STREAM_DESTROYED:Ud,ERR_STREAM_ALREADY_FINISHED:SD,ERR_STREAM_NULL_VALUES:AD,ERR_STREAM_WRITE_AFTER_END:TD,ERR_UNKNOWN_ENCODING:pA}=or().codes,{errorOrDestroy:Ba}=Ch;lA(it.prototype,Rd.prototype);lA(it,Rd);function Dm(){}var Ra=pD("kOnFinished");function Od(t,e,r){typeof r!="boolean"&&(r=e instanceof oi()),this.objectMode=!!(t&&t.objectMode),r&&(this.objectMode=this.objectMode||!!(t&&t.writableObjectMode)),this.highWaterMark=t?wD(this,t,"writableHighWaterMark",r):bD(!1),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;let n=!!(t&&t.decodeStrings===!1);this.decodeStrings=!n,this.defaultEncoding=t&&t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=ID.bind(void 0,e),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,Nh(this),this.pendingcb=0,this.constructed=!0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!t||t.emitClose!==!1,this.autoDestroy=!t||t.autoDestroy!==!1,this.errored=null,this.closed=!1,this.closeEmitted=!1,this[Ra]=[]}function Nh(t){t.buffered=[],t.bufferedIndex=0,t.allBuffers=!0,t.allNoop=!0}Od.prototype.getBuffer=function(){return uA(this.buffered,this.bufferedIndex)};fA(Od.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}});function it(t){let e=this instanceof oi();if(!e&&!dA(it,this))return new it(t);this._writableState=new Od(t,this,e),t&&(typeof t.write=="function"&&(this._write=t.write),typeof t.writev=="function"&&(this._writev=t.writev),typeof t.destroy=="function"&&(this._destroy=t.destroy),typeof t.final=="function"&&(this._final=t.final),typeof t.construct=="function"&&(this._construct=t.construct),t.signal&&mD(t.signal,this)),Rd.call(this,t),Ch.construct(this,()=>{let r=this._writableState;r.writing||Nm(this,r),Cm(this,r)})}fA(it,yD,{__proto__:null,value:function(t){return dA(this,t)?!0:this!==it?!1:t&&t._writableState instanceof Od}});it.prototype.pipe=function(){Ba(this,new vD)};function yA(t,e,r,n){let i=t._writableState;if(typeof r=="function")n=r,r=i.defaultEncoding;else{if(!r)r=i.defaultEncoding;else if(r!=="buffer"&&!Dh.isEncoding(r))throw new pA(r);typeof n!="function"&&(n=Dm)}if(e===null)throw new AD;if(!i.objectMode)if(typeof e=="string")i.decodeStrings!==!1&&(e=Dh.from(e,r),r="buffer");else if(e instanceof Dh)r="buffer";else if(Rd._isUint8Array(e))e=Rd._uint8ArrayToBuffer(e),r="buffer";else throw new xD("chunk",["string","Buffer","Uint8Array"],e);let o;return i.ending?o=new TD:i.destroyed&&(o=new Ud("write")),o?(ac.nextTick(n,o),Ba(t,o,!0),o):(i.pendingcb++,_D(t,i,e,r,n))}it.prototype.write=function(t,e,r){return yA(this,t,e,r)===!0};it.prototype.cork=function(){this._writableState.corked++};it.prototype.uncork=function(){let t=this._writableState;t.corked&&(t.corked--,t.writing||Nm(this,t))};it.prototype.setDefaultEncoding=function(e){if(typeof e=="string"&&(e=hD(e)),!Dh.isEncoding(e))throw new pA(e);return this._writableState.defaultEncoding=e,this};function _D(t,e,r,n,i){let o=e.objectMode?1:r.length;e.length+=o;let s=e.length<e.highWaterMark;return s||(e.needDrain=!0),e.writing||e.corked||e.errored||!e.constructed?(e.buffered.push({chunk:r,encoding:n,callback:i}),e.allBuffers&&n!=="buffer"&&(e.allBuffers=!1),e.allNoop&&i!==Dm&&(e.allNoop=!1)):(e.writelen=o,e.writecb=i,e.writing=!0,e.sync=!0,t._write(r,n,e.onwrite),e.sync=!1),s&&!e.errored&&!e.destroyed}function cA(t,e,r,n,i,o,s){e.writelen=n,e.writecb=s,e.writing=!0,e.sync=!0,e.destroyed?e.onwrite(new Ud("write")):r?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function aA(t,e,r,n){--e.pendingcb,n(r),km(e),Ba(t,r)}function ID(t,e){let r=t._writableState,n=r.sync,i=r.writecb;if(typeof i!="function"){Ba(t,new hA);return}r.writing=!1,r.writecb=null,r.length-=r.writelen,r.writelen=0,e?(e.stack,r.errored||(r.errored=e),t._readableState&&!t._readableState.errored&&(t._readableState.errored=e),n?ac.nextTick(aA,t,r,e,i):aA(t,r,e,i)):(r.buffered.length>r.bufferedIndex&&Nm(t,r),n?r.afterWriteTickInfo!==null&&r.afterWriteTickInfo.cb===i?r.afterWriteTickInfo.count++:(r.afterWriteTickInfo={count:1,cb:i,stream:t,state:r},ac.nextTick(BD,r.afterWriteTickInfo)):gA(t,r,1,i))}function BD({stream:t,state:e,count:r,cb:n}){return e.afterWriteTickInfo=null,gA(t,e,r,n)}function gA(t,e,r,n){for(!e.ending&&!t.destroyed&&e.length===0&&e.needDrain&&(e.needDrain=!1,t.emit("drain"));r-- >0;)e.pendingcb--,n();e.destroyed&&km(e),Cm(t,e)}function km(t){if(t.writing)return;for(let i=t.bufferedIndex;i<t.buffered.length;++i){var e;let{chunk:o,callback:s}=t.buffered[i],c=t.objectMode?1:o.length;t.length-=c,s((e=t.errored)!==null&&e!==void 0?e:new Ud("write"))}let r=t[Ra].splice(0);for(let i=0;i<r.length;i++){var n;r[i]((n=t.errored)!==null&&n!==void 0?n:new Ud("end"))}Nh(t)}function Nm(t,e){if(e.corked||e.bufferProcessing||e.destroyed||!e.constructed)return;let{buffered:r,bufferedIndex:n,objectMode:i}=e,o=r.length-n;if(!o)return;let s=n;if(e.bufferProcessing=!0,o>1&&t._writev){e.pendingcb-=o-1;let c=e.allNoop?Dm:u=>{for(let d=s;d<r.length;++d)r[d].callback(u)},a=e.allNoop&&s===0?r:uA(r,s);a.allBuffers=e.allBuffers,cA(t,e,!0,e.length,a,"",c),Nh(e)}else{do{let{chunk:c,encoding:a,callback:u}=r[s];r[s++]=null;let d=i?1:c.length;cA(t,e,!1,d,c,a,u)}while(s<r.length&&!e.writing);s===r.length?Nh(e):s>256?(r.splice(0,s),e.bufferedIndex=0):e.bufferedIndex=s}e.bufferProcessing=!1}it.prototype._write=function(t,e,r){if(this._writev)this._writev([{chunk:t,encoding:e}],r);else throw new ED("_write()")};it.prototype._writev=null;it.prototype.end=function(t,e,r){let n=this._writableState;typeof t=="function"?(r=t,t=null,e=null):typeof e=="function"&&(r=e,e=null);let i;if(t!=null){let o=yA(this,t,e);o instanceof fD&&(i=o)}return n.corked&&(n.corked=1,this.uncork()),i||(!n.errored&&!n.ending?(n.ending=!0,Cm(this,n,!0),n.ended=!0):n.finished?i=new SD("end"):n.destroyed&&(i=new Ud("end"))),typeof r=="function"&&(i||n.finished?ac.nextTick(r,i):n[Ra].push(r)),this};function kh(t){return t.ending&&!t.destroyed&&t.constructed&&t.length===0&&!t.errored&&t.buffered.length===0&&!t.finished&&!t.writing&&!t.errorEmitted&&!t.closeEmitted}function RD(t,e){let r=!1;function n(i){if(r){Ba(t,i??hA());return}if(r=!0,e.pendingcb--,i){let o=e[Ra].splice(0);for(let s=0;s<o.length;s++)o[s](i);Ba(t,i,e.sync)}else kh(e)&&(e.prefinished=!0,t.emit("prefinish"),e.pendingcb++,ac.nextTick(Om,t,e))}e.sync=!0,e.pendingcb++;try{t._final(n)}catch(i){n(i)}e.sync=!1}function UD(t,e){!e.prefinished&&!e.finalCalled&&(typeof t._final=="function"&&!e.destroyed?(e.finalCalled=!0,RD(t,e)):(e.prefinished=!0,t.emit("prefinish")))}function Cm(t,e,r){kh(e)&&(UD(t,e),e.pendingcb===0&&(r?(e.pendingcb++,ac.nextTick((n,i)=>{kh(i)?Om(n,i):i.pendingcb--},t,e)):kh(e)&&(e.pendingcb++,Om(t,e))))}function Om(t,e){e.pendingcb--,e.finished=!0;let r=e[Ra].splice(0);for(let n=0;n<r.length;n++)r[n]();if(t.emit("finish"),e.autoDestroy){let n=t._readableState;(!n||n.autoDestroy&&(n.endEmitted||n.readable===!1))&&t.destroy()}}lD(it.prototype,{closed:{__proto__:null,get(){return this._writableState?this._writableState.closed:!1}},destroyed:{__proto__:null,get(){return this._writableState?this._writableState.destroyed:!1},set(t){this._writableState&&(this._writableState.destroyed=t)}},writable:{__proto__:null,get(){let t=this._writableState;return!!t&&t.writable!==!1&&!t.destroyed&&!t.errored&&!t.ending&&!t.ended},set(t){this._writableState&&(this._writableState.writable=!!t)}},writableFinished:{__proto__:null,get(){return this._writableState?this._writableState.finished:!1}},writableObjectMode:{__proto__:null,get(){return this._writableState?this._writableState.objectMode:!1}},writableBuffer:{__proto__:null,get(){return this._writableState&&this._writableState.getBuffer()}},writableEnded:{__proto__:null,get(){return this._writableState?this._writableState.ending:!1}},writableNeedDrain:{__proto__:null,get(){let t=this._writableState;return t?!t.destroyed&&!t.ending&&t.needDrain:!1}},writableHighWaterMark:{__proto__:null,get(){return this._writableState&&this._writableState.highWaterMark}},writableCorked:{__proto__:null,get(){return this._writableState?this._writableState.corked:0}},writableLength:{__proto__:null,get(){return this._writableState&&this._writableState.length}},errored:{__proto__:null,enumerable:!1,get(){return this._writableState?this._writableState.errored:null}},writableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._writableState.writable!==!1&&(this._writableState.destroyed||this._writableState.errored)&&!this._writableState.finished)}}});var OD=Ch.destroy;it.prototype.destroy=function(t,e){let r=this._writableState;return!r.destroyed&&(r.bufferedIndex<r.buffered.length||r[Ra].length)&&ac.nextTick(km,r),OD.call(this,t,e),this};it.prototype._undestroy=Ch.undestroy;it.prototype._destroy=function(t,e){e(t)};it.prototype[gD.captureRejectionSymbol]=function(t){this.destroy(t)};var Um;function mA(){return Um===void 0&&(Um={}),Um}it.fromWeb=function(t,e){return mA().newStreamWritableFromWritableStream(t,e)};it.toWeb=function(t){return mA().newWritableStreamFromStreamWritable(t)}});var kA=oe((jF,DA)=>{l();var Lm=Ei(),DD=Tr(),{isReadable:kD,isWritable:ND,isIterable:bA,isNodeStream:CD,isReadableNodeStream:xA,isWritableNodeStream:EA,isDuplexNodeStream:LD,isReadableStream:vA,isWritableStream:SA}=ri(),AA=Wi(),{AbortError:UA,codes:{ERR_INVALID_ARG_TYPE:PD,ERR_INVALID_RETURN_VALUE:TA}}=or(),{destroyer:Oa}=oc(),MD=oi(),OA=Bd(),KD=Lh(),{createDeferredPromise:_A}=Xt(),IA=Em(),BA=globalThis.Blob||DD.Blob,$D=typeof BA<"u"?function(e){return e instanceof BA}:function(e){return!1},HD=globalThis.AbortController||Ea().AbortController,{FunctionPrototypeCall:RA}=nt(),jo=class extends MD{constructor(e){super(e),e?.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),e?.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)}};DA.exports=function t(e,r){if(LD(e))return e;if(xA(e))return Ua({readable:e});if(EA(e))return Ua({writable:e});if(CD(e))return Ua({writable:!1,readable:!1});if(vA(e))return Ua({readable:OA.fromWeb(e)});if(SA(e))return Ua({writable:KD.fromWeb(e)});if(typeof e=="function"){let{value:i,write:o,final:s,destroy:c}=VD(e);if(bA(i))return IA(jo,i,{objectMode:!0,write:o,final:s,destroy:c});let a=i?.then;if(typeof a=="function"){let u,d=RA(a,i,f=>{if(f!=null)throw new TA("nully","body",f)},f=>{Oa(u,f)});return u=new jo({objectMode:!0,readable:!1,write:o,final(f){s(async()=>{try{await d,Lm.nextTick(f,null)}catch(h){Lm.nextTick(f,h)}})},destroy:c})}throw new TA("Iterable, AsyncIterable or AsyncFunction",r,i)}if($D(e))return t(e.arrayBuffer());if(bA(e))return IA(jo,e,{objectMode:!0,writable:!1});if(vA(e?.readable)&&SA(e?.writable))return jo.fromWeb(e);if(typeof e?.writable=="object"||typeof e?.readable=="object"){let i=e!=null&&e.readable?xA(e?.readable)?e?.readable:t(e.readable):void 0,o=e!=null&&e.writable?EA(e?.writable)?e?.writable:t(e.writable):void 0;return Ua({readable:i,writable:o})}let n=e?.then;if(typeof n=="function"){let i;return RA(n,e,o=>{o!=null&&i.push(o),i.push(null)},o=>{Oa(i,o)}),i=new jo({objectMode:!0,writable:!1,read(){}})}throw new PD(r,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],e)};function VD(t){let{promise:e,resolve:r}=_A(),n=new HD,i=n.signal;return{value:t(async function*(){for(;;){let s=e;e=null;let{chunk:c,done:a,cb:u}=await s;if(Lm.nextTick(u),a)return;if(i.aborted)throw new UA(void 0,{cause:i.reason});({promise:e,resolve:r}=_A()),yield c}}(),{signal:i}),write(s,c,a){let u=r;r=null,u({chunk:s,done:!1,cb:a})},final(s){let c=r;r=null,c({done:!0,cb:s})},destroy(s,c){n.abort(),c(s)}}}function Ua(t){let e=t.readable&&typeof t.readable.read!="function"?OA.wrap(t.readable):t.readable,r=t.writable,n=!!kD(e),i=!!ND(r),o,s,c,a,u;function d(f){let h=a;a=null,h?h(f):f&&u.destroy(f)}return u=new jo({readableObjectMode:!!(e!=null&&e.readableObjectMode),writableObjectMode:!!(r!=null&&r.writableObjectMode),readable:n,writable:i}),i&&(AA(r,f=>{i=!1,f&&Oa(e,f),d(f)}),u._write=function(f,h,p){r.write(f,h)?p():o=p},u._final=function(f){r.end(),s=f},r.on("drain",function(){if(o){let f=o;o=null,f()}}),r.on("finish",function(){if(s){let f=s;s=null,f()}})),n&&(AA(e,f=>{n=!1,f&&Oa(e,f),d(f)}),e.on("readable",function(){if(c){let f=c;c=null,f()}}),e.on("end",function(){u.push(null)}),u._read=function(){for(;;){let f=e.read();if(f===null){c=u._read;return}if(!u.push(f))return}}),u._destroy=function(f,h){!f&&a!==null&&(f=new UA),c=null,o=null,s=null,a===null?h(f):(a=h,Oa(r,f),Oa(e,f))},u}});var oi=oe((GF,LA)=>{"use strict";l();var{ObjectDefineProperties:qD,ObjectGetOwnPropertyDescriptor:Gi,ObjectKeys:FD,ObjectSetPrototypeOf:NA}=nt();LA.exports=_n;var Km=Bd(),rn=Lh();NA(_n.prototype,Km.prototype);NA(_n,Km);{let t=FD(rn.prototype);for(let e=0;e<t.length;e++){let r=t[e];_n.prototype[r]||(_n.prototype[r]=rn.prototype[r])}}function _n(t){if(!(this instanceof _n))return new _n(t);Km.call(this,t),rn.call(this,t),t?(this.allowHalfOpen=t.allowHalfOpen!==!1,t.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),t.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)):this.allowHalfOpen=!0}qD(_n.prototype,{writable:{__proto__:null,...Gi(rn.prototype,"writable")},writableHighWaterMark:{__proto__:null,...Gi(rn.prototype,"writableHighWaterMark")},writableObjectMode:{__proto__:null,...Gi(rn.prototype,"writableObjectMode")},writableBuffer:{__proto__:null,...Gi(rn.prototype,"writableBuffer")},writableLength:{__proto__:null,...Gi(rn.prototype,"writableLength")},writableFinished:{__proto__:null,...Gi(rn.prototype,"writableFinished")},writableCorked:{__proto__:null,...Gi(rn.prototype,"writableCorked")},writableEnded:{__proto__:null,...Gi(rn.prototype,"writableEnded")},writableNeedDrain:{__proto__:null,...Gi(rn.prototype,"writableNeedDrain")},destroyed:{__proto__:null,get(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set(t){this._readableState&&this._writableState&&(this._readableState.destroyed=t,this._writableState.destroyed=t)}}});var Pm;function CA(){return Pm===void 0&&(Pm={}),Pm}_n.fromWeb=function(t,e){return CA().newStreamDuplexFromReadableWritablePair(t,e)};_n.toWeb=function(t){return CA().newReadableWritablePairFromDuplex(t)};var Mm;_n.from=function(t){return Mm||(Mm=kA()),Mm(t,"body")}});var Vm=oe((YF,MA)=>{"use strict";l();var{ObjectSetPrototypeOf:PA,Symbol:jD}=nt();MA.exports=zi;var{ERR_METHOD_NOT_IMPLEMENTED:WD}=or().codes,Hm=oi(),{getHighWaterMark:GD}=Td();PA(zi.prototype,Hm.prototype);PA(zi,Hm);var Dd=jD("kCallback");function zi(t){if(!(this instanceof zi))return new zi(t);let e=t?GD(this,t,"readableHighWaterMark",!0):null;e===0&&(t={...t,highWaterMark:null,readableHighWaterMark:e,writableHighWaterMark:t.writableHighWaterMark||0}),Hm.call(this,t),this._readableState.sync=!1,this[Dd]=null,t&&(typeof t.transform=="function"&&(this._transform=t.transform),typeof t.flush=="function"&&(this._flush=t.flush)),this.on("prefinish",zD)}function $m(t){typeof this._flush=="function"&&!this.destroyed?this._flush((e,r)=>{if(e){t?t(e):this.destroy(e);return}r!=null&&this.push(r),this.push(null),t&&t()}):(this.push(null),t&&t())}function zD(){this._final!==$m&&$m.call(this)}zi.prototype._final=$m;zi.prototype._transform=function(t,e,r){throw new WD("_transform()")};zi.prototype._write=function(t,e,r){let n=this._readableState,i=this._writableState,o=n.length;this._transform(t,e,(s,c)=>{if(s){r(s);return}c!=null&&this.push(c),i.ended||o===n.length||n.length<n.highWaterMark?r():this[Dd]=r})};zi.prototype._read=function(){if(this[Dd]){let t=this[Dd];this[Dd]=null,t()}}});var Fm=oe((XF,$A)=>{"use strict";l();var{ObjectSetPrototypeOf:KA}=nt();$A.exports=Da;var qm=Vm();KA(Da.prototype,qm.prototype);KA(Da,qm);function Da(t){if(!(this instanceof Da))return new Da(t);qm.call(this,t)}Da.prototype._transform=function(t,e,r){r(null,t)}});var $h=oe((QF,jA)=>{l();var kd=Ei(),{ArrayIsArray:YD,Promise:JD,SymbolAsyncIterator:XD,SymbolDispose:ZD}=nt(),Kh=Wi(),{once:QD}=Xt(),ek=oc(),HA=oi(),{aggregateTwoErrors:tk,codes:{ERR_INVALID_ARG_TYPE:Qm,ERR_INVALID_RETURN_VALUE:jm,ERR_MISSING_ARGS:rk,ERR_STREAM_DESTROYED:nk,ERR_STREAM_PREMATURE_CLOSE:ik},AbortError:ok}=or(),{validateFunction:sk,validateAbortSignal:ck}=Sa(),{isIterable:uc,isReadable:Wm,isReadableNodeStream:Mh,isNodeStream:VA,isTransformStream:ka,isWebStream:ak,isReadableStream:Gm,isReadableFinished:uk}=ri(),dk=globalThis.AbortController||Ea().AbortController,zm,Ym,Jm;function qA(t,e,r){let n=!1;t.on("close",()=>{n=!0});let i=Kh(t,{readable:e,writable:r},o=>{n=!o});return{destroy:o=>{n||(n=!0,ek.destroyer(t,o||new nk("pipe")))},cleanup:i}}function fk(t){return sk(t[t.length-1],"streams[stream.length - 1]"),t.pop()}function Xm(t){if(uc(t))return t;if(Mh(t))return lk(t);throw new Qm("val",["Readable","Iterable","AsyncIterable"],t)}async function*lk(t){Ym||(Ym=Bd()),yield*Ym.prototype[XD].call(t)}async function Ph(t,e,r,{end:n}){let i,o=null,s=u=>{if(u&&(i=u),o){let d=o;o=null,d()}},c=()=>new JD((u,d)=>{i?d(i):o=()=>{i?d(i):u()}});e.on("drain",s);let a=Kh(e,{readable:!1},s);try{e.writableNeedDrain&&await c();for await(let u of t)e.write(u)||await c();n&&(e.end(),await c()),r()}catch(u){r(i!==u?tk(i,u):u)}finally{a(),e.off("drain",s)}}async function Zm(t,e,r,{end:n}){ka(e)&&(e=e.writable);let i=e.getWriter();try{for await(let o of t)await i.ready,i.write(o).catch(()=>{});await i.ready,n&&await i.close(),r()}catch(o){try{await i.abort(o),r(o)}catch(s){r(s)}}}function hk(...t){return FA(t,QD(fk(t)))}function FA(t,e,r){if(t.length===1&&YD(t[0])&&(t=t[0]),t.length<2)throw new rk("streams");let n=new dk,i=n.signal,o=r?.signal,s=[];ck(o,"options.signal");function c(){g(new ok)}Jm=Jm||Xt().addAbortListener;let a;o&&(a=Jm(o,c));let u,d,f=[],h=0;function p(A){g(A,--h===0)}function g(A,O){var T;if(A&&(!u||u.code==="ERR_STREAM_PREMATURE_CLOSE")&&(u=A),!(!u&&!O)){for(;f.length;)f.shift()(u);(T=a)===null||T===void 0||T[ZD](),n.abort(),O&&(u||s.forEach(M=>M()),kd.nextTick(e,u,d))}}let y;for(let A=0;A<t.length;A++){let O=t[A],T=A<t.length-1,M=A>0,q=T||r?.end!==!1,j=A===t.length-1;if(VA(O)){let $=function(Z){Z&&Z.name!=="AbortError"&&Z.code!=="ERR_STREAM_PREMATURE_CLOSE"&&p(Z)};var _=$;if(q){let{destroy:Z,cleanup:Q}=qA(O,T,M);f.push(Z),Wm(O)&&j&&s.push(Q)}O.on("error",$),Wm(O)&&j&&s.push(()=>{O.removeListener("error",$)})}if(A===0)if(typeof O=="function"){if(y=O({signal:i}),!uc(y))throw new jm("Iterable, AsyncIterable or Stream","source",y)}else uc(O)||Mh(O)||ka(O)?y=O:y=HA.from(O);else if(typeof O=="function"){if(ka(y)){var x;y=Xm((x=y)===null||x===void 0?void 0:x.readable)}else y=Xm(y);if(y=O(y,{signal:i}),T){if(!uc(y,!0))throw new jm("AsyncIterable",`transform[${A-1}]`,y)}else{var S;zm||(zm=Fm());let $=new zm({objectMode:!0}),Z=(S=y)===null||S===void 0?void 0:S.then;if(typeof Z=="function")h++,Z.call(y,I=>{d=I,I!=null&&$.write(I),q&&$.end(),kd.nextTick(p)},I=>{$.destroy(I),kd.nextTick(p,I)});else if(uc(y,!0))h++,Ph(y,$,p,{end:q});else if(Gm(y)||ka(y)){let I=y.readable||y;h++,Ph(I,$,p,{end:q})}else throw new jm("AsyncIterable or Promise","destination",y);y=$;let{destroy:Q,cleanup:G}=qA(y,!1,!0);f.push(Q),j&&s.push(G)}}else if(VA(O)){if(Mh(y)){h+=2;let $=pk(y,O,p,{end:q});Wm(O)&&j&&s.push($)}else if(ka(y)||Gm(y)){let $=y.readable||y;h++,Ph($,O,p,{end:q})}else if(uc(y))h++,Ph(y,O,p,{end:q});else throw new Qm("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=O}else if(ak(O)){if(Mh(y))h++,Zm(Xm(y),O,p,{end:q});else if(Gm(y)||uc(y))h++,Zm(y,O,p,{end:q});else if(ka(y))h++,Zm(y.readable,O,p,{end:q});else throw new Qm("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=O}else y=HA.from(O)}return(i!=null&&i.aborted||o!=null&&o.aborted)&&kd.nextTick(c),y}function pk(t,e,r,{end:n}){let i=!1;if(e.on("close",()=>{i||r(new ik)}),t.pipe(e,{end:!1}),n){let s=function(){i=!0,e.end()};var o=s;uk(t)?kd.nextTick(s):t.once("end",s)}else r();return Kh(t,{readable:!0,writable:!1},s=>{let c=t._readableState;s&&s.code==="ERR_STREAM_PREMATURE_CLOSE"&&c&&c.ended&&!c.errored&&!c.errorEmitted?t.once("end",r).once("error",r):r(s)}),Kh(e,{readable:!1,writable:!0},r)}jA.exports={pipelineImpl:FA,pipeline:hk}});var tw=oe((tj,XA)=>{"use strict";l();var{pipeline:yk}=$h(),Hh=oi(),{destroyer:gk}=oc(),{isNodeStream:Vh,isReadable:WA,isWritable:GA,isWebStream:ew,isTransformStream:dc,isWritableStream:zA,isReadableStream:YA}=ri(),{AbortError:mk,codes:{ERR_INVALID_ARG_VALUE:JA,ERR_MISSING_ARGS:wk}}=or(),bk=Wi();XA.exports=function(...e){if(e.length===0)throw new wk("streams");if(e.length===1)return Hh.from(e[0]);let r=[...e];if(typeof e[0]=="function"&&(e[0]=Hh.from(e[0])),typeof e[e.length-1]=="function"){let p=e.length-1;e[p]=Hh.from(e[p])}for(let p=0;p<e.length;++p)if(!(!Vh(e[p])&&!ew(e[p]))){if(p<e.length-1&&!(WA(e[p])||YA(e[p])||dc(e[p])))throw new JA(`streams[${p}]`,r[p],"must be readable");if(p>0&&!(GA(e[p])||zA(e[p])||dc(e[p])))throw new JA(`streams[${p}]`,r[p],"must be writable")}let n,i,o,s,c;function a(p){let g=s;s=null,g?g(p):p?c.destroy(p):!h&&!f&&c.destroy()}let u=e[0],d=yk(e,a),f=!!(GA(u)||zA(u)||dc(u)),h=!!(WA(d)||YA(d)||dc(d));if(c=new Hh({writableObjectMode:!!(u!=null&&u.writableObjectMode),readableObjectMode:!!(d!=null&&d.readableObjectMode),writable:f,readable:h}),f){if(Vh(u))c._write=function(g,y,x){u.write(g,y)?x():n=x},c._final=function(g){u.end(),i=g},u.on("drain",function(){if(n){let g=n;n=null,g()}});else if(ew(u)){let y=(dc(u)?u.writable:u).getWriter();c._write=async function(x,S,_){try{await y.ready,y.write(x).catch(()=>{}),_()}catch(A){_(A)}},c._final=async function(x){try{await y.ready,y.close().catch(()=>{}),i=x}catch(S){x(S)}}}let p=dc(d)?d.readable:d;bk(p,()=>{if(i){let g=i;i=null,g()}})}if(h){if(Vh(d))d.on("readable",function(){if(o){let p=o;o=null,p()}}),d.on("end",function(){c.push(null)}),c._read=function(){for(;;){let p=d.read();if(p===null){o=c._read;return}if(!c.push(p))return}};else if(ew(d)){let g=(dc(d)?d.readable:d).getReader();c._read=async function(){for(;;)try{let{value:y,done:x}=await g.read();if(!c.push(y))return;if(x){c.push(null);return}}catch{return}}}}return c._destroy=function(p,g){!p&&s!==null&&(p=new mk),o=null,n=null,i=null,s===null?g(p):(s=g,Vh(d)&&gk(d,p))},c}});var cT=oe((nj,iw)=>{"use strict";l();var xk=globalThis.AbortController||Ea().AbortController,{codes:{ERR_INVALID_ARG_VALUE:Ek,ERR_INVALID_ARG_TYPE:Nd,ERR_MISSING_ARGS:vk,ERR_OUT_OF_RANGE:Sk},AbortError:si}=or(),{validateAbortSignal:fc,validateInteger:ZA,validateObject:lc}=Sa(),Ak=nt().Symbol("kWeak"),Tk=nt().Symbol("kResistStopPropagation"),{finished:_k}=Wi(),Ik=tw(),{addAbortSignalNoValidate:Bk}=Ad(),{isWritable:Rk,isNodeStream:Uk}=ri(),{deprecate:Ok}=Xt(),{ArrayPrototypePush:Dk,Boolean:kk,MathFloor:QA,Number:Nk,NumberIsNaN:Ck,Promise:eT,PromiseReject:tT,PromiseResolve:Lk,PromisePrototypeThen:rT,Symbol:iT}=nt(),qh=iT("kEmpty"),nT=iT("kEof");function Pk(t,e){if(e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),Uk(t)&&!Rk(t))throw new Ek("stream",t,"must be writable");let r=Ik(this,t);return e!=null&&e.signal&&Bk(e.signal,r),r}function Fh(t,e){if(typeof t!="function")throw new Nd("fn",["Function","AsyncFunction"],t);e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal");let r=1;e?.concurrency!=null&&(r=QA(e.concurrency));let n=r-1;return e?.highWaterMark!=null&&(n=QA(e.highWaterMark)),ZA(r,"options.concurrency",1),ZA(n,"options.highWaterMark",0),n+=r,(async function*(){let o=Xt().AbortSignalAny([e?.signal].filter(kk)),s=this,c=[],a={signal:o},u,d,f=!1,h=0;function p(){f=!0,g()}function g(){h-=1,y()}function y(){d&&!f&&h<r&&c.length<n&&(d(),d=null)}async function x(){try{for await(let S of s){if(f)return;if(o.aborted)throw new si;try{if(S=t(S,a),S===qh)continue;S=Lk(S)}catch(_){S=tT(_)}h+=1,rT(S,g,p),c.push(S),u&&(u(),u=null),!f&&(c.length>=n||h>=r)&&await new eT(_=>{d=_})}c.push(nT)}catch(S){let _=tT(S);rT(_,g,p),c.push(_)}finally{f=!0,u&&(u(),u=null)}}x();try{for(;;){for(;c.length>0;){let S=await c[0];if(S===nT)return;if(o.aborted)throw new si;S!==qh&&(yield S),c.shift(),y()}await new eT(S=>{u=S})}}finally{f=!0,d&&(d(),d=null)}}).call(this)}function Mk(t=void 0){return t!=null&&lc(t,"options"),t?.signal!=null&&fc(t.signal,"options.signal"),(async function*(){let r=0;for await(let i of this){var n;if(t!=null&&(n=t.signal)!==null&&n!==void 0&&n.aborted)throw new si({cause:t.signal.reason});yield[r++,i]}}).call(this)}async function oT(t,e=void 0){for await(let r of nw.call(this,t,e))return!0;return!1}async function Kk(t,e=void 0){if(typeof t!="function")throw new Nd("fn",["Function","AsyncFunction"],t);return!await oT.call(this,async(...r)=>!await t(...r),e)}async function $k(t,e){for await(let r of nw.call(this,t,e))return r}async function Hk(t,e){if(typeof t!="function")throw new Nd("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i),qh}for await(let n of Fh.call(this,r,e));}function nw(t,e){if(typeof t!="function")throw new Nd("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i)?n:qh}return Fh.call(this,r,e)}var rw=class extends vk{constructor(){super("reduce"),this.message="Reduce of an empty stream requires an initial value"}};async function Vk(t,e,r){var n;if(typeof t!="function")throw new Nd("reducer",["Function","AsyncFunction"],t);r!=null&&lc(r,"options"),r?.signal!=null&&fc(r.signal,"options.signal");let i=arguments.length>1;if(r!=null&&(n=r.signal)!==null&&n!==void 0&&n.aborted){let u=new si(void 0,{cause:r.signal.reason});throw this.once("error",()=>{}),await _k(this.destroy(u)),u}let o=new xk,s=o.signal;if(r!=null&&r.signal){let u={once:!0,[Ak]:this,[Tk]:!0};r.signal.addEventListener("abort",()=>o.abort(),u)}let c=!1;try{for await(let u of this){var a;if(c=!0,r!=null&&(a=r.signal)!==null&&a!==void 0&&a.aborted)throw new si;i?e=await t(e,u,{signal:s}):(e=u,i=!0)}if(!c&&!i)throw new rw}finally{o.abort()}return e}async function qk(t){t!=null&&lc(t,"options"),t?.signal!=null&&fc(t.signal,"options.signal");let e=[];for await(let n of this){var r;if(t!=null&&(r=t.signal)!==null&&r!==void 0&&r.aborted)throw new si(void 0,{cause:t.signal.reason});Dk(e,n)}return e}function Fk(t,e){let r=Fh.call(this,t,e);return(async function*(){for await(let i of r)yield*i}).call(this)}function sT(t){if(t=Nk(t),Ck(t))return 0;if(t<0)throw new Sk("number",">= 0",t);return t}function jk(t,e=void 0){return e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),t=sT(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new si;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new si;t--<=0&&(yield o)}}).call(this)}function Wk(t,e=void 0){return e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),t=sT(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new si;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new si;if(t-- >0&&(yield o),t<=0)return}}).call(this)}iw.exports.streamReturningOperators={asIndexedPairs:Ok(Mk,"readable.asIndexedPairs will be removed in a future version."),drop:jk,filter:nw,flatMap:Fk,map:Fh,take:Wk,compose:Pk};iw.exports.promiseReturningOperators={every:Kk,forEach:Hk,reduce:Vk,toArray:qk,some:oT,find:$k}});var ow=oe((oj,aT)=>{"use strict";l();var{ArrayPrototypePop:Gk,Promise:zk}=nt(),{isIterable:Yk,isNodeStream:Jk,isWebStream:Xk}=ri(),{pipelineImpl:Zk}=$h(),{finished:Qk}=Wi();sw();function e4(...t){return new zk((e,r)=>{let n,i,o=t[t.length-1];if(o&&typeof o=="object"&&!Jk(o)&&!Yk(o)&&!Xk(o)){let s=Gk(t);n=s.signal,i=s.end}Zk(t,(s,c)=>{s?r(s):e(c)},{signal:n,end:i})})}aT.exports={finished:Qk,pipeline:e4}});var sw=oe((cj,mT)=>{l();var{Buffer:t4}=Tr(),{ObjectDefineProperty:Yi,ObjectKeys:fT,ReflectApply:lT}=nt(),{promisify:{custom:hT}}=Xt(),{streamReturningOperators:uT,promiseReturningOperators:dT}=cT(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:pT}}=or(),r4=tw(),{setDefaultHighWaterMark:n4,getDefaultHighWaterMark:i4}=Td(),{pipeline:yT}=$h(),{destroyer:o4}=oc(),gT=Wi(),cw=ow(),Cd=ri(),We=mT.exports=Sh().Stream;We.isDestroyed=Cd.isDestroyed;We.isDisturbed=Cd.isDisturbed;We.isErrored=Cd.isErrored;We.isReadable=Cd.isReadable;We.isWritable=Cd.isWritable;We.Readable=Bd();for(let t of fT(uT)){let r=function(...n){if(new.target)throw pT();return We.Readable.from(lT(e,this,n))};aw=r;let e=uT[t];Yi(r,"name",{__proto__:null,value:e.name}),Yi(r,"length",{__proto__:null,value:e.length}),Yi(We.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var aw;for(let t of fT(dT)){let r=function(...i){if(new.target)throw pT();return lT(e,this,i)};aw=r;let e=dT[t];Yi(r,"name",{__proto__:null,value:e.name}),Yi(r,"length",{__proto__:null,value:e.length}),Yi(We.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var aw;We.Writable=Lh();We.Duplex=oi();We.Transform=Vm();We.PassThrough=Fm();We.pipeline=yT;var{addAbortSignal:s4}=Ad();We.addAbortSignal=s4;We.finished=gT;We.destroy=o4;We.compose=r4;We.setDefaultHighWaterMark=n4;We.getDefaultHighWaterMark=i4;Yi(We,"promises",{__proto__:null,configurable:!0,enumerable:!0,get(){return cw}});Yi(yT,hT,{__proto__:null,enumerable:!0,get(){return cw.pipeline}});Yi(gT,hT,{__proto__:null,enumerable:!0,get(){return cw.finished}});We.Stream=We;We._isUint8Array=function(e){return e instanceof Uint8Array};We._uint8ArrayToBuffer=function(e){return t4.from(e.buffer,e.byteOffset,e.byteLength)}});var uw=oe((uj,gt)=>{"use strict";l();var _t=sw(),c4=ow(),a4=_t.Readable.destroy;gt.exports=_t.Readable;gt.exports._uint8ArrayToBuffer=_t._uint8ArrayToBuffer;gt.exports._isUint8Array=_t._isUint8Array;gt.exports.isDisturbed=_t.isDisturbed;gt.exports.isErrored=_t.isErrored;gt.exports.isReadable=_t.isReadable;gt.exports.Readable=_t.Readable;gt.exports.Writable=_t.Writable;gt.exports.Duplex=_t.Duplex;gt.exports.Transform=_t.Transform;gt.exports.PassThrough=_t.PassThrough;gt.exports.addAbortSignal=_t.addAbortSignal;gt.exports.finished=_t.finished;gt.exports.destroy=_t.destroy;gt.exports.destroy=a4;gt.exports.pipeline=_t.pipeline;gt.exports.compose=_t.compose;Object.defineProperty(_t,"promises",{configurable:!0,enumerable:!0,get(){return c4}});gt.exports.Stream=_t.Stream;gt.exports.default=gt.exports});var K_=oe((Dp,M_)=>{l();(function(t,e){typeof Dp=="object"&&typeof M_<"u"?e(Dp):typeof define=="function"&&define.amd?define(["exports"],e):e(t.URI=t.URI||{})})(Dp,function(t){"use strict";function e(){for(var B=arguments.length,v=Array(B),k=0;k<B;k++)v[k]=arguments[k];if(v.length>1){v[0]=v[0].slice(0,-1);for(var K=v.length-1,H=1;H<K;++H)v[H]=v[H].slice(1,-1);return v[K]=v[K].slice(1),v.join("")}else return v[0]}function r(B){return"(?:"+B+")"}function n(B){return B===void 0?"undefined":B===null?"null":Object.prototype.toString.call(B).split(" ").pop().split("]").shift().toLowerCase()}function i(B){return B.toUpperCase()}function o(B){return B!=null?B instanceof Array?B:typeof B.length!="number"||B.split||B.setInterval||B.call?[B]:Array.prototype.slice.call(B):[]}function s(B,v){var k=B;if(v)for(var K in v)k[K]=v[K];return k}function c(B){var v="[A-Za-z]",k="[\\x0D]",K="[0-9]",H="[\\x22]",te=e(K,"[A-Fa-f]"),fe="[\\x0A]",Se="[\\x20]",Oe=r(r("%[EFef]"+te+"%"+te+te+"%"+te+te)+"|"+r("%[89A-Fa-f]"+te+"%"+te+te)+"|"+r("%"+te+te)),mt="[\\:\\/\\?\\#\\[\\]\\@]",ve="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",tt=e(mt,ve),wt=B?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",Xe=B?"[\\uE000-\\uF8FF]":"[]",_e=e(v,K,"[\\-\\.\\_\\~]",wt),rt=r(v+e(v,K,"[\\+\\-\\.]")+"*"),Ne=r(r(Oe+"|"+e(_e,ve,"[\\:]"))+"*"),ls=r(r("25[0-5]")+"|"+r("2[0-4]"+K)+"|"+r("1"+K+K)+"|"+r("[1-9]"+K)+"|"+K),Sr=r(r("25[0-5]")+"|"+r("2[0-4]"+K)+"|"+r("1"+K+K)+"|"+r("0?[1-9]"+K)+"|0?0?"+K),jr=r(Sr+"\\."+Sr+"\\."+Sr+"\\."+Sr),$e=r(te+"{1,4}"),Ar=r(r($e+"\\:"+$e)+"|"+jr),Wr=r(r($e+"\\:")+"{6}"+Ar),Pn=r("\\:\\:"+r($e+"\\:")+"{5}"+Ar),hs=r(r($e)+"?\\:\\:"+r($e+"\\:")+"{4}"+Ar),yi=r(r(r($e+"\\:")+"{0,1}"+$e)+"?\\:\\:"+r($e+"\\:")+"{3}"+Ar),yu=r(r(r($e+"\\:")+"{0,2}"+$e)+"?\\:\\:"+r($e+"\\:")+"{2}"+Ar),vf=r(r(r($e+"\\:")+"{0,3}"+$e)+"?\\:\\:"+$e+"\\:"+Ar),Sf=r(r(r($e+"\\:")+"{0,4}"+$e)+"?\\:\\:"+Ar),Ac=r(r(r($e+"\\:")+"{0,5}"+$e)+"?\\:\\:"+$e),Tc=r(r(r($e+"\\:")+"{0,6}"+$e)+"?\\:\\:"),gi=r([Wr,Pn,hs,yi,yu,vf,Sf,Ac,Tc].join("|")),_c=r(r(_e+"|"+Oe)+"+"),ty=r(gi+"\\%25"+_c),ps=r(gi+r("\\%25|\\%(?!"+te+"{2})")+_c),rB=r("[vV]"+te+"+\\."+e(_e,ve,"[\\:]")+"+"),nB=r("\\["+r(ps+"|"+gi+"|"+rB)+"\\]"),tx=r(r(Oe+"|"+e(_e,ve))+"*"),gu=r(nB+"|"+jr+"(?!"+tx+")|"+tx),mu=r(K+"*"),rx=r(r(Ne+"@")+"?"+gu+r("\\:"+mu)+"?"),wu=r(Oe+"|"+e(_e,ve,"[\\:\\@]")),iB=r(wu+"*"),nx=r(wu+"+"),oB=r(r(Oe+"|"+e(_e,ve,"[\\@]"))+"+"),mi=r(r("\\/"+iB)+"*"),Ic=r("\\/"+r(nx+mi)+"?"),ry=r(oB+mi),Af=r(nx+mi),Bc="(?!"+wu+")",NL=r(mi+"|"+Ic+"|"+ry+"|"+Af+"|"+Bc),Rc=r(r(wu+"|"+e("[\\/\\?]",Xe))+"*"),bu=r(r(wu+"|[\\/\\?]")+"*"),ix=r(r("\\/\\/"+rx+mi)+"|"+Ic+"|"+Af+"|"+Bc),sB=r(rt+"\\:"+ix+r("\\?"+Rc)+"?"+r("\\#"+bu)+"?"),cB=r(r("\\/\\/"+rx+mi)+"|"+Ic+"|"+ry+"|"+Bc),aB=r(cB+r("\\?"+Rc)+"?"+r("\\#"+bu)+"?"),CL=r(sB+"|"+aB),LL=r(rt+"\\:"+ix+r("\\?"+Rc)+"?"),PL="^("+rt+")\\:"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+gu+")"+r("\\:("+mu+")")+"?)")+"?("+mi+"|"+Ic+"|"+Af+"|"+Bc+")")+r("\\?("+Rc+")")+"?"+r("\\#("+bu+")")+"?$",ML="^(){0}"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+gu+")"+r("\\:("+mu+")")+"?)")+"?("+mi+"|"+Ic+"|"+ry+"|"+Bc+")")+r("\\?("+Rc+")")+"?"+r("\\#("+bu+")")+"?$",KL="^("+rt+")\\:"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+gu+")"+r("\\:("+mu+")")+"?)")+"?("+mi+"|"+Ic+"|"+Af+"|"+Bc+")")+r("\\?("+Rc+")")+"?$",$L="^"+r("\\#("+bu+")")+"?$",HL="^"+r("("+Ne+")@")+"?("+gu+")"+r("\\:("+mu+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",v,K,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",_e,ve),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",_e,ve),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",_e,ve),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",_e,ve),"g"),NOT_QUERY:new RegExp(e("[^\\%]",_e,ve,"[\\:\\@\\/\\?]",Xe),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",_e,ve,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",_e,ve),"g"),UNRESERVED:new RegExp(_e,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",_e,tt),"g"),PCT_ENCODED:new RegExp(Oe,"g"),IPV4ADDRESS:new RegExp("^("+jr+")$"),IPV6ADDRESS:new RegExp("^\\[?("+gi+")"+r(r("\\%25|\\%(?!"+te+"{2})")+"("+_c+")")+"?\\]?$")}}var a=c(!1),u=c(!0),d=function(){function B(v,k){var K=[],H=!0,te=!1,fe=void 0;try{for(var Se=v[Symbol.iterator](),Oe;!(H=(Oe=Se.next()).done)&&(K.push(Oe.value),!(k&&K.length===k));H=!0);}catch(mt){te=!0,fe=mt}finally{try{!H&&Se.return&&Se.return()}finally{if(te)throw fe}}return K}return function(v,k){if(Array.isArray(v))return v;if(Symbol.iterator in Object(v))return B(v,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(B){if(Array.isArray(B)){for(var v=0,k=Array(B.length);v<B.length;v++)k[v]=B[v];return k}else return Array.from(B)},h=2147483647,p=36,g=1,y=26,x=38,S=700,_=72,A=128,O="-",T=/^xn--/,M=/[^\0-\x7E]/,q=/[\x2E\u3002\uFF0E\uFF61]/g,j={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},$=p-g,Z=Math.floor,Q=String.fromCharCode;function G(B){throw new RangeError(j[B])}function I(B,v){for(var k=[],K=B.length;K--;)k[K]=v(B[K]);return k}function D(B,v){var k=B.split("@"),K="";k.length>1&&(K=k[0]+"@",B=k[1]),B=B.replace(q,".");var H=B.split("."),te=I(H,v).join(".");return K+te}function E(B){for(var v=[],k=0,K=B.length;k<K;){var H=B.charCodeAt(k++);if(H>=55296&&H<=56319&&k<K){var te=B.charCodeAt(k++);(te&64512)==56320?v.push(((H&1023)<<10)+(te&1023)+65536):(v.push(H),k--)}else v.push(H)}return v}var U=function(v){return String.fromCodePoint.apply(String,f(v))},L=function(v){return v-48<10?v-22:v-65<26?v-65:v-97<26?v-97:p},N=function(v,k){return v+22+75*(v<26)-((k!=0)<<5)},R=function(v,k,K){var H=0;for(v=K?Z(v/S):v>>1,v+=Z(v/k);v>$*y>>1;H+=p)v=Z(v/$);return Z(H+($+1)*v/(v+x))},C=function(v){var k=[],K=v.length,H=0,te=A,fe=_,Se=v.lastIndexOf(O);Se<0&&(Se=0);for(var Oe=0;Oe<Se;++Oe)v.charCodeAt(Oe)>=128&&G("not-basic"),k.push(v.charCodeAt(Oe));for(var mt=Se>0?Se+1:0;mt<K;){for(var ve=H,tt=1,wt=p;;wt+=p){mt>=K&&G("invalid-input");var Xe=L(v.charCodeAt(mt++));(Xe>=p||Xe>Z((h-H)/tt))&&G("overflow"),H+=Xe*tt;var _e=wt<=fe?g:wt>=fe+y?y:wt-fe;if(Xe<_e)break;var rt=p-_e;tt>Z(h/rt)&&G("overflow"),tt*=rt}var Ne=k.length+1;fe=R(H-ve,Ne,ve==0),Z(H/Ne)>h-te&&G("overflow"),te+=Z(H/Ne),H%=Ne,k.splice(H++,0,te)}return String.fromCodePoint.apply(String,k)},P=function(v){var k=[];v=E(v);var K=v.length,H=A,te=0,fe=_,Se=!0,Oe=!1,mt=void 0;try{for(var ve=v[Symbol.iterator](),tt;!(Se=(tt=ve.next()).done);Se=!0){var wt=tt.value;wt<128&&k.push(Q(wt))}}catch(ps){Oe=!0,mt=ps}finally{try{!Se&&ve.return&&ve.return()}finally{if(Oe)throw mt}}var Xe=k.length,_e=Xe;for(Xe&&k.push(O);_e<K;){var rt=h,Ne=!0,ls=!1,Sr=void 0;try{for(var jr=v[Symbol.iterator](),$e;!(Ne=($e=jr.next()).done);Ne=!0){var Ar=$e.value;Ar>=H&&Ar<rt&&(rt=Ar)}}catch(ps){ls=!0,Sr=ps}finally{try{!Ne&&jr.return&&jr.return()}finally{if(ls)throw Sr}}var Wr=_e+1;rt-H>Z((h-te)/Wr)&&G("overflow"),te+=(rt-H)*Wr,H=rt;var Pn=!0,hs=!1,yi=void 0;try{for(var yu=v[Symbol.iterator](),vf;!(Pn=(vf=yu.next()).done);Pn=!0){var Sf=vf.value;if(Sf<H&&++te>h&&G("overflow"),Sf==H){for(var Ac=te,Tc=p;;Tc+=p){var gi=Tc<=fe?g:Tc>=fe+y?y:Tc-fe;if(Ac<gi)break;var _c=Ac-gi,ty=p-gi;k.push(Q(N(gi+_c%ty,0))),Ac=Z(_c/ty)}k.push(Q(N(Ac,0))),fe=R(te,Wr,_e==Xe),te=0,++_e}}}catch(ps){hs=!0,yi=ps}finally{try{!Pn&&yu.return&&yu.return()}finally{if(hs)throw yi}}++te,++H}return k.join("")},V=function(v){return D(v,function(k){return T.test(k)?C(k.slice(4).toLowerCase()):k})},J=function(v){return D(v,function(k){return M.test(k)?"xn--"+P(k):k})},z={version:"2.1.0",ucs2:{decode:E,encode:U},decode:C,encode:P,toASCII:J,toUnicode:V},W={};function Y(B){var v=B.charCodeAt(0),k=void 0;return v<16?k="%0"+v.toString(16).toUpperCase():v<128?k="%"+v.toString(16).toUpperCase():v<2048?k="%"+(v>>6|192).toString(16).toUpperCase()+"%"+(v&63|128).toString(16).toUpperCase():k="%"+(v>>12|224).toString(16).toUpperCase()+"%"+(v>>6&63|128).toString(16).toUpperCase()+"%"+(v&63|128).toString(16).toUpperCase(),k}function X(B){for(var v="",k=0,K=B.length;k<K;){var H=parseInt(B.substr(k+1,2),16);if(H<128)v+=String.fromCharCode(H),k+=3;else if(H>=194&&H<224){if(K-k>=6){var te=parseInt(B.substr(k+4,2),16);v+=String.fromCharCode((H&31)<<6|te&63)}else v+=B.substr(k,6);k+=6}else if(H>=224){if(K-k>=9){var fe=parseInt(B.substr(k+4,2),16),Se=parseInt(B.substr(k+7,2),16);v+=String.fromCharCode((H&15)<<12|(fe&63)<<6|Se&63)}else v+=B.substr(k,9);k+=9}else v+=B.substr(k,3),k+=3}return v}function ue(B,v){function k(K){var H=X(K);return H.match(v.UNRESERVED)?H:K}return B.scheme&&(B.scheme=String(B.scheme).replace(v.PCT_ENCODED,k).toLowerCase().replace(v.NOT_SCHEME,"")),B.userinfo!==void 0&&(B.userinfo=String(B.userinfo).replace(v.PCT_ENCODED,k).replace(v.NOT_USERINFO,Y).replace(v.PCT_ENCODED,i)),B.host!==void 0&&(B.host=String(B.host).replace(v.PCT_ENCODED,k).toLowerCase().replace(v.NOT_HOST,Y).replace(v.PCT_ENCODED,i)),B.path!==void 0&&(B.path=String(B.path).replace(v.PCT_ENCODED,k).replace(B.scheme?v.NOT_PATH:v.NOT_PATH_NOSCHEME,Y).replace(v.PCT_ENCODED,i)),B.query!==void 0&&(B.query=String(B.query).replace(v.PCT_ENCODED,k).replace(v.NOT_QUERY,Y).replace(v.PCT_ENCODED,i)),B.fragment!==void 0&&(B.fragment=String(B.fragment).replace(v.PCT_ENCODED,k).replace(v.NOT_FRAGMENT,Y).replace(v.PCT_ENCODED,i)),B}function ee(B){return B.replace(/^0*(.*)/,"$1")||"0"}function ce(B,v){var k=B.match(v.IPV4ADDRESS)||[],K=d(k,2),H=K[1];return H?H.split(".").map(ee).join("."):B}function Ue(B,v){var k=B.match(v.IPV6ADDRESS)||[],K=d(k,3),H=K[1],te=K[2];if(H){for(var fe=H.toLowerCase().split("::").reverse(),Se=d(fe,2),Oe=Se[0],mt=Se[1],ve=mt?mt.split(":").map(ee):[],tt=Oe.split(":").map(ee),wt=v.IPV4ADDRESS.test(tt[tt.length-1]),Xe=wt?7:8,_e=tt.length-Xe,rt=Array(Xe),Ne=0;Ne<Xe;++Ne)rt[Ne]=ve[Ne]||tt[_e+Ne]||"";wt&&(rt[Xe-1]=ce(rt[Xe-1],v));var ls=rt.reduce(function(Wr,Pn,hs){if(!Pn||Pn==="0"){var yi=Wr[Wr.length-1];yi&&yi.index+yi.length===hs?yi.length++:Wr.push({index:hs,length:1})}return Wr},[]),Sr=ls.sort(function(Wr,Pn){return Pn.length-Wr.length})[0],jr=void 0;if(Sr&&Sr.length>1){var $e=rt.slice(0,Sr.index),Ar=rt.slice(Sr.index+Sr.length);jr=$e.join(":")+"::"+Ar.join(":")}else jr=rt.join(":");return te&&(jr+="%"+te),jr}else return B}var Ke=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function xt(B){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},k={},K=v.iri!==!1?u:a;v.reference==="suffix"&&(B=(v.scheme?v.scheme+":":"")+"//"+B);var H=B.match(Ke);if(H){Je?(k.scheme=H[1],k.userinfo=H[3],k.host=H[4],k.port=parseInt(H[5],10),k.path=H[6]||"",k.query=H[7],k.fragment=H[8],isNaN(k.port)&&(k.port=H[5])):(k.scheme=H[1]||void 0,k.userinfo=B.indexOf("@")!==-1?H[3]:void 0,k.host=B.indexOf("//")!==-1?H[4]:void 0,k.port=parseInt(H[5],10),k.path=H[6]||"",k.query=B.indexOf("?")!==-1?H[7]:void 0,k.fragment=B.indexOf("#")!==-1?H[8]:void 0,isNaN(k.port)&&(k.port=B.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?H[4]:void 0)),k.host&&(k.host=Ue(ce(k.host,K),K)),k.scheme===void 0&&k.userinfo===void 0&&k.host===void 0&&k.port===void 0&&!k.path&&k.query===void 0?k.reference="same-document":k.scheme===void 0?k.reference="relative":k.fragment===void 0?k.reference="absolute":k.reference="uri",v.reference&&v.reference!=="suffix"&&v.reference!==k.reference&&(k.error=k.error||"URI is not a "+v.reference+" reference.");var te=W[(v.scheme||k.scheme||"").toLowerCase()];if(!v.unicodeSupport&&(!te||!te.unicodeSupport)){if(k.host&&(v.domainHost||te&&te.domainHost))try{k.host=z.toASCII(k.host.replace(K.PCT_ENCODED,X).toLowerCase())}catch(fe){k.error=k.error||"Host's domain name can not be converted to ASCII via punycode: "+fe}ue(k,a)}else ue(k,K);te&&te.parse&&te.parse(k,v)}else k.error=k.error||"URI can not be parsed.";return k}function pi(B,v){var k=v.iri!==!1?u:a,K=[];return B.userinfo!==void 0&&(K.push(B.userinfo),K.push("@")),B.host!==void 0&&K.push(Ue(ce(String(B.host),k),k).replace(k.IPV6ADDRESS,function(H,te,fe){return"["+te+(fe?"%25"+fe:"")+"]"})),(typeof B.port=="number"||typeof B.port=="string")&&(K.push(":"),K.push(String(B.port))),K.length?K.join(""):void 0}var fo=/^\.\.?\//,fu=/^\/\.(\/|$)/,gf=/^\/\.\.(\/|$)/,Zp=/^\/?(?:.|\n)*?(?=\/|$)/;function lo(B){for(var v=[];B.length;)if(B.match(fo))B=B.replace(fo,"");else if(B.match(fu))B=B.replace(fu,"/");else if(B.match(gf))B=B.replace(gf,"/"),v.pop();else if(B==="."||B==="..")B="";else{var k=B.match(Zp);if(k){var K=k[0];B=B.slice(K.length),v.push(K)}else throw new Error("Unexpected dot segment condition")}return v.join("")}function qr(B){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},k=v.iri?u:a,K=[],H=W[(v.scheme||B.scheme||"").toLowerCase()];if(H&&H.serialize&&H.serialize(B,v),B.host&&!k.IPV6ADDRESS.test(B.host)){if(v.domainHost||H&&H.domainHost)try{B.host=v.iri?z.toUnicode(B.host):z.toASCII(B.host.replace(k.PCT_ENCODED,X).toLowerCase())}catch(Se){B.error=B.error||"Host's domain name can not be converted to "+(v.iri?"Unicode":"ASCII")+" via punycode: "+Se}}ue(B,k),v.reference!=="suffix"&&B.scheme&&(K.push(B.scheme),K.push(":"));var te=pi(B,v);if(te!==void 0&&(v.reference!=="suffix"&&K.push("//"),K.push(te),B.path&&B.path.charAt(0)!=="/"&&K.push("/")),B.path!==void 0){var fe=B.path;!v.absolutePath&&(!H||!H.absolutePath)&&(fe=lo(fe)),te===void 0&&(fe=fe.replace(/^\/\//,"/%2F")),K.push(fe)}return B.query!==void 0&&(K.push("?"),K.push(B.query)),B.fragment!==void 0&&(K.push("#"),K.push(B.fragment)),K.join("")}function lu(B,v){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},K=arguments[3],H={};return K||(B=xt(qr(B,k),k),v=xt(qr(v,k),k)),k=k||{},!k.tolerant&&v.scheme?(H.scheme=v.scheme,H.userinfo=v.userinfo,H.host=v.host,H.port=v.port,H.path=lo(v.path||""),H.query=v.query):(v.userinfo!==void 0||v.host!==void 0||v.port!==void 0?(H.userinfo=v.userinfo,H.host=v.host,H.port=v.port,H.path=lo(v.path||""),H.query=v.query):(v.path?(v.path.charAt(0)==="/"?H.path=lo(v.path):((B.userinfo!==void 0||B.host!==void 0||B.port!==void 0)&&!B.path?H.path="/"+v.path:B.path?H.path=B.path.slice(0,B.path.lastIndexOf("/")+1)+v.path:H.path=v.path,H.path=lo(H.path)),H.query=v.query):(H.path=B.path,v.query!==void 0?H.query=v.query:H.query=B.query),H.userinfo=B.userinfo,H.host=B.host,H.port=B.port),H.scheme=B.scheme),H.fragment=v.fragment,H}function mf(B,v,k){var K=s({scheme:"null"},k);return qr(lu(xt(B,K),xt(v,K),K,!0),K)}function hu(B,v){return typeof B=="string"?B=qr(xt(B,v),v):n(B)==="object"&&(B=xt(qr(B,v),v)),B}function wf(B,v,k){return typeof B=="string"?B=qr(xt(B,k),k):n(B)==="object"&&(B=qr(B,k)),typeof v=="string"?v=qr(xt(v,k),k):n(v)==="object"&&(v=qr(v,k)),B===v}function bf(B,v){return B&&B.toString().replace(!v||!v.iri?a.ESCAPE:u.ESCAPE,Y)}function Fr(B,v){return B&&B.toString().replace(!v||!v.iri?a.PCT_ENCODED:u.PCT_ENCODED,X)}var ho={scheme:"http",domainHost:!0,parse:function(v,k){return v.host||(v.error=v.error||"HTTP URIs must have a host."),v},serialize:function(v,k){var K=String(v.scheme).toLowerCase()==="https";return(v.port===(K?443:80)||v.port==="")&&(v.port=void 0),v.path||(v.path="/"),v}},pu={scheme:"https",domainHost:ho.domainHost,parse:ho.parse,serialize:ho.serialize};function xf(B){return typeof B.secure=="boolean"?B.secure:String(B.scheme).toLowerCase()==="wss"}var fs={scheme:"ws",domainHost:!0,parse:function(v,k){var K=v;return K.secure=xf(K),K.resourceName=(K.path||"/")+(K.query?"?"+K.query:""),K.path=void 0,K.query=void 0,K},serialize:function(v,k){if((v.port===(xf(v)?443:80)||v.port==="")&&(v.port=void 0),typeof v.secure=="boolean"&&(v.scheme=v.secure?"wss":"ws",v.secure=void 0),v.resourceName){var K=v.resourceName.split("?"),H=d(K,2),te=H[0],fe=H[1];v.path=te&&te!=="/"?te:void 0,v.query=fe,v.resourceName=void 0}return v.fragment=void 0,v}},Ef={scheme:"wss",domainHost:fs.domainHost,parse:fs.parse,serialize:fs.serialize},Qp={},jI=!0,Jb="[A-Za-z0-9\\-\\.\\_\\~"+(jI?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",Ln="[0-9A-Fa-f]",WI=r(r("%[EFef]"+Ln+"%"+Ln+Ln+"%"+Ln+Ln)+"|"+r("%[89A-Fa-f]"+Ln+"%"+Ln+Ln)+"|"+r("%"+Ln+Ln)),GI="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",zI="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",YI=e(zI,'[\\"\\\\]'),JI="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",XI=new RegExp(Jb,"g"),Sc=new RegExp(WI,"g"),ZI=new RegExp(e("[^]",GI,"[\\.]",'[\\"]',YI),"g"),Xb=new RegExp(e("[^]",Jb,JI),"g"),QI=Xb;function ey(B){var v=X(B);return v.match(XI)?v:B}var Zb={scheme:"mailto",parse:function(v,k){var K=v,H=K.to=K.path?K.path.split(","):[];if(K.path=void 0,K.query){for(var te=!1,fe={},Se=K.query.split("&"),Oe=0,mt=Se.length;Oe<mt;++Oe){var ve=Se[Oe].split("=");switch(ve[0]){case"to":for(var tt=ve[1].split(","),wt=0,Xe=tt.length;wt<Xe;++wt)H.push(tt[wt]);break;case"subject":K.subject=Fr(ve[1],k);break;case"body":K.body=Fr(ve[1],k);break;default:te=!0,fe[Fr(ve[0],k)]=Fr(ve[1],k);break}}te&&(K.headers=fe)}K.query=void 0;for(var _e=0,rt=H.length;_e<rt;++_e){var Ne=H[_e].split("@");if(Ne[0]=Fr(Ne[0]),k.unicodeSupport)Ne[1]=Fr(Ne[1],k).toLowerCase();else try{Ne[1]=z.toASCII(Fr(Ne[1],k).toLowerCase())}catch(ls){K.error=K.error||"Email address's domain name can not be converted to ASCII via punycode: "+ls}H[_e]=Ne.join("@")}return K},serialize:function(v,k){var K=v,H=o(v.to);if(H){for(var te=0,fe=H.length;te<fe;++te){var Se=String(H[te]),Oe=Se.lastIndexOf("@"),mt=Se.slice(0,Oe).replace(Sc,ey).replace(Sc,i).replace(ZI,Y),ve=Se.slice(Oe+1);try{ve=k.iri?z.toUnicode(ve):z.toASCII(Fr(ve,k).toLowerCase())}catch(_e){K.error=K.error||"Email address's domain name can not be converted to "+(k.iri?"Unicode":"ASCII")+" via punycode: "+_e}H[te]=mt+"@"+ve}K.path=H.join(",")}var tt=v.headers=v.headers||{};v.subject&&(tt.subject=v.subject),v.body&&(tt.body=v.body);var wt=[];for(var Xe in tt)tt[Xe]!==Qp[Xe]&&wt.push(Xe.replace(Sc,ey).replace(Sc,i).replace(Xb,Y)+"="+tt[Xe].replace(Sc,ey).replace(Sc,i).replace(QI,Y));return wt.length&&(K.query=wt.join("&")),K}},eB=/^([^\:]+)\:(.*)/,Qb={scheme:"urn",parse:function(v,k){var K=v.path&&v.path.match(eB),H=v;if(K){var te=k.scheme||H.scheme||"urn",fe=K[1].toLowerCase(),Se=K[2],Oe=te+":"+(k.nid||fe),mt=W[Oe];H.nid=fe,H.nss=Se,H.path=void 0,mt&&(H=mt.parse(H,k))}else H.error=H.error||"URN can not be parsed.";return H},serialize:function(v,k){var K=k.scheme||v.scheme||"urn",H=v.nid,te=K+":"+(k.nid||H),fe=W[te];fe&&(v=fe.serialize(v,k));var Se=v,Oe=v.nss;return Se.path=(H||k.nid)+":"+Oe,Se}},tB=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,ex={scheme:"urn:uuid",parse:function(v,k){var K=v;return K.uuid=K.nss,K.nss=void 0,!k.tolerant&&(!K.uuid||!K.uuid.match(tB))&&(K.error=K.error||"UUID is not valid."),K},serialize:function(v,k){var K=v;return K.nss=(v.uuid||"").toLowerCase(),K}};W[ho.scheme]=ho,W[pu.scheme]=pu,W[fs.scheme]=fs,W[Ef.scheme]=Ef,W[Zb.scheme]=Zb,W[Qb.scheme]=Qb,W[ex.scheme]=ex,t.SCHEMES=W,t.pctEncChar=Y,t.pctDecChars=X,t.parse=xt,t.removeDotSegments=lo,t.serialize=qr,t.resolveComponents=lu,t.resolve=mf,t.normalize=hu,t.equal=wf,t.escapeComponent=bf,t.unescapeComponent=Fr,Object.defineProperty(t,"__esModule",{value:!0})})});var H_=oe((CX,$_)=>{"use strict";l();$_.exports=function t(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?t(e.toJSON()):Array.isArray(e)?`[${e.reduce((i,o,s)=>`${i}${s===0?"":","}${t(o===void 0||typeof o=="symbol"?null:o)}`,"")}]`:`{${Object.keys(e).sort().reduce((n,i)=>{if(e[i]===void 0||typeof e[i]=="symbol")return n;let o=n.length===0?"":",";return`${n}${o}${t(i)}:${t(e[i])}`},"")}}`}});var eI=oe((MQ,Q_)=>{l();var Qa=1e3,eu=Qa*60,tu=eu*60,bc=tu*24,qC=bc*7,FC=bc*365.25;Q_.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return jC(t);if(r==="number"&&isFinite(t))return e.long?GC(t):WC(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function jC(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*FC;case"weeks":case"week":case"w":return r*qC;case"days":case"day":case"d":return r*bc;case"hours":case"hour":case"hrs":case"hr":case"h":return r*tu;case"minutes":case"minute":case"mins":case"min":case"m":return r*eu;case"seconds":case"second":case"secs":case"sec":case"s":return r*Qa;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function WC(t){var e=Math.abs(t);return e>=bc?Math.round(t/bc)+"d":e>=tu?Math.round(t/tu)+"h":e>=eu?Math.round(t/eu)+"m":e>=Qa?Math.round(t/Qa)+"s":t+"ms"}function GC(t){var e=Math.abs(t);return e>=bc?Pp(t,e,bc,"day"):e>=tu?Pp(t,e,tu,"hour"):e>=eu?Pp(t,e,eu,"minute"):e>=Qa?Pp(t,e,Qa,"second"):t+" ms"}function Pp(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});l();l();l();l();var ws=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xu(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function pn(t,...e){if(!bs(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Uf(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");xu(t.outputLen),xu(t.blockLen)}function Nc(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function _x(t,e){pn(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function qn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Of(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function yn(t,e){return t<<32-e|t>>>e}function Eu(t,e){return t<<e|t>>>32-e>>>0}var Ix=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",zB=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Pt(t){if(pn(t),Ix)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=zB[t[r]];return e}var vi={_0:48,_9:57,A:65,F:70,a:97,f:102};function Tx(t){if(t>=vi._0&&t<=vi._9)return t-vi._0;if(t>=vi.A&&t<=vi.F)return t-(vi.A-10);if(t>=vi.a&&t<=vi.f)return t-(vi.a-10)}function _r(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Ix)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=Tx(t.charCodeAt(o)),c=Tx(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function xs(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function vu(t){return typeof t=="string"&&(t=xs(t)),pn(t),t}function lt(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];pn(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var kc=class{};function Df(t){let e=n=>t().update(vu(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Ir(t=32){if(ws&&typeof ws.getRandomValues=="function")return ws.getRandomValues(new Uint8Array(t));if(ws&&typeof ws.randomBytes=="function")return Uint8Array.from(ws.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}l();l();l();l();l();function YB(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}function yy(t,e,r){return t&e^~t&r}function gy(t,e,r){return t&e^t&r^e&r}var Cc=class extends kc{constructor(e,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Of(this.buffer)}update(e){Nc(this),e=vu(e),pn(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Of(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Nc(this),_x(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,qn(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;YB(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Of(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=c,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Si=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var JB=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]),po=new Uint32Array(64),my=class extends Cc{constructor(e=32){super(64,e,8,!1),this.A=Si[0]|0,this.B=Si[1]|0,this.C=Si[2]|0,this.D=Si[3]|0,this.E=Si[4]|0,this.F=Si[5]|0,this.G=Si[6]|0,this.H=Si[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)po[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=po[f-15],p=po[f-2],g=yn(h,7)^yn(h,18)^h>>>3,y=yn(p,17)^yn(p,19)^p>>>10;po[f]=y+po[f-7]+g+po[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=yn(c,6)^yn(c,11)^yn(c,25),p=d+h+yy(c,a,u)+JB[f]+po[f]|0,y=(yn(n,2)^yn(n,13)^yn(n,22))+gy(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){qn(po)}destroy(){this.set(0,0,0,0,0,0,0,0),qn(this.buffer)}};var ke=Df(()=>new my);l();l();l();var kf=class extends kc{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Uf(e);let n=vu(r);if(this.iHash=e.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;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),qn(o)}update(e){return Nc(this),this.iHash.update(e),this}digestInto(e){Nc(this),pn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},wy=(t,e,r)=>new kf(t,e).update(r).digest();wy.create=(t,e)=>new kf(t,e);l();var Ey=BigInt(0),xy=BigInt(1);function Su(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function yo(t,e,r=""){let n=bs(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Au(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Bx(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Ey:BigInt("0x"+t)}function Ai(t){return Bx(Pt(t))}function vy(t){return pn(t),Bx(Pt(Uint8Array.from(t).reverse()))}function Lc(t,e){return _r(t.toString(16).padStart(e*2,"0"))}function Sy(t,e){return Lc(t,e).reverse()}function ot(t,e,r){let n;if(typeof e=="string")try{n=_r(e)}catch(o){throw new Error(t+" must be hex string or Uint8Array, cause: "+o)}else if(bs(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(t+" of length "+r+" expected, got "+i);return n}function go(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}var by=t=>typeof t=="bigint"&&Ey<=t;function Tu(t,e,r){return by(t)&&by(e)&&by(r)&&e<=t&&t<r}function Rx(t,e,r,n){if(!Tu(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Nf(t){let e;for(e=0;t>Ey;t>>=xy,e+=1);return e}var mo=t=>(xy<<BigInt(t))-xy;function Ux(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),i=p=>Uint8Array.of(p),o=n(t),s=n(t),c=0,a=()=>{o.fill(1),s.fill(0),c=0},u=(...p)=>r(s,o,...p),d=(p=n(0))=>{s=u(i(0),p),o=u(),p.length!==0&&(s=u(i(1),p),o=u())},f=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,g=[];for(;p<e;){o=u();let y=o.slice();g.push(y),p+=o.length}return lt(...g)};return(p,g)=>{a(),d(p);let y;for(;!(y=g(f()));)d();return a(),y}}function _u(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(i,o,s){let c=t[i];if(s&&c===void 0)return;let a=typeof c;if(a!==o||c===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${a}`)}Object.entries(e).forEach(([i,o])=>n(i,o,!1)),Object.entries(r).forEach(([i,o])=>n(i,o,!0))}function Ay(t){let e=new WeakMap;return(r,...n)=>{let i=e.get(r);if(i!==void 0)return i;let o=t(r,...n);return e.set(r,o),o}}l();l();var tr=BigInt(0),Ft=BigInt(1),Es=BigInt(2),kx=BigInt(3),Nx=BigInt(4),Cx=BigInt(5),XB=BigInt(7),Lx=BigInt(8),ZB=BigInt(9),Px=BigInt(16);function Br(t,e){let r=t%e;return r>=tr?r:e+r}function Rr(t,e,r){let n=t;for(;e-- >tr;)n*=n,n%=r;return n}function Ox(t,e){if(t===tr)throw new Error("invert: expected non-zero number");if(e<=tr)throw new Error("invert: expected positive modulus, got "+e);let r=Br(t,e),n=e,i=tr,o=Ft,s=Ft,c=tr;for(;r!==tr;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==Ft)throw new Error("invert: does not exist");return Br(i,e)}function Ty(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function Mx(t,e){let r=(t.ORDER+Ft)/Nx,n=t.pow(e,r);return Ty(t,n,e),n}function QB(t,e){let r=(t.ORDER-Cx)/Lx,n=t.mul(e,Es),i=t.pow(n,r),o=t.mul(e,i),s=t.mul(t.mul(o,Es),i),c=t.mul(o,t.sub(s,t.ONE));return Ty(t,c,e),c}function e8(t){let e=wo(t),r=Kx(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),s=(t+XB)/Px;return(c,a)=>{let u=c.pow(a,s),d=c.mul(u,n),f=c.mul(u,i),h=c.mul(u,o),p=c.eql(c.sqr(d),a),g=c.eql(c.sqr(f),a);u=c.cmov(u,d,p),d=c.cmov(h,f,g);let y=c.eql(c.sqr(d),a),x=c.cmov(u,d,y);return Ty(c,x,a),x}}function Kx(t){if(t<kx)throw new Error("sqrt is not defined for small field");let e=t-Ft,r=0;for(;e%Es===tr;)e/=Es,r++;let n=Es,i=wo(t);for(;Dx(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Mx;let o=i.pow(n,e),s=(e+Ft)/Es;return function(a,u){if(a.is0(u))return u;if(Dx(a,u)!==1)throw new Error("Cannot find square root");let d=r,f=a.mul(a.ONE,o),h=a.pow(u,e),p=a.pow(u,s);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,y=a.sqr(h);for(;!a.eql(y,a.ONE);)if(g++,y=a.sqr(y),g===d)throw new Error("Cannot find square root");let x=Ft<<BigInt(d-g-1),S=a.pow(f,x);d=g,f=a.sqr(S),h=a.mul(h,f),p=a.mul(p,S)}return p}}function t8(t){return t%Nx===kx?Mx:t%Lx===Cx?QB:t%Px===ZB?e8(t):Kx(t)}var r8=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _y(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=r8.reduce((n,i)=>(n[i]="function",n),e);return _u(t,r),t}function n8(t,e,r){if(r<tr)throw new Error("invalid exponent, negatives unsupported");if(r===tr)return t.ONE;if(r===Ft)return e;let n=t.ONE,i=e;for(;r>tr;)r&Ft&&(n=t.mul(n,i)),i=t.sqr(i),r>>=Ft;return n}function Cf(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),i=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),o=t.inv(i);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),o),n}function Dx(t,e){let r=(t.ORDER-Ft)/Es,n=t.pow(e,r),i=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Lf(t,e){e!==void 0&&xu(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function wo(t,e,r=!1,n={}){if(t<=tr)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,o,s=!1,c;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(i=h.BITS),h.sqrt&&(o=h.sqrt),typeof h.isLE=="boolean"&&(r=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),c=h.allowedLengths}else typeof e=="number"&&(i=e),n.sqrt&&(o=n.sqrt);let{nBitLength:a,nByteLength:u}=Lf(t,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,f=Object.freeze({ORDER:t,isLE:r,BITS:a,BYTES:u,MASK:mo(a),ZERO:tr,ONE:Ft,allowedLengths:c,create:h=>Br(h,t),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return tr<=h&&h<t},is0:h=>h===tr,isValidNot0:h=>!f.is0(h)&&f.isValid(h),isOdd:h=>(h&Ft)===Ft,neg:h=>Br(-h,t),eql:(h,p)=>h===p,sqr:h=>Br(h*h,t),add:(h,p)=>Br(h+p,t),sub:(h,p)=>Br(h-p,t),mul:(h,p)=>Br(h*p,t),pow:(h,p)=>n8(f,h,p),div:(h,p)=>Br(h*Ox(p,t),t),sqrN:h=>h*h,addN:(h,p)=>h+p,subN:(h,p)=>h-p,mulN:(h,p)=>h*p,inv:h=>Ox(h,t),sqrt:o||(h=>(d||(d=t8(t)),d(f,h))),toBytes:h=>r?Sy(h,u):Lc(h,u),fromBytes:(h,p=!0)=>{if(c){if(!c.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+h.length);let y=new Uint8Array(u);y.set(h,r?0:y.length-h.length),h=y}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let g=r?vy(h):Ai(h);if(s&&(g=Br(g,t)),!p&&!f.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:h=>Cf(f,h),cmov:(h,p,g)=>g?p:h});return Object.freeze(f)}function $x(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Iy(t){let e=$x(t);return e+Math.ceil(e/2)}function Pf(t,e,r=!1){let n=t.length,i=$x(e),o=Iy(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let s=r?vy(t):Ai(t),c=Br(s,e-Ft)+Ft;return r?Sy(c,i):Lc(c,i)}var Pc=BigInt(0),vs=BigInt(1);function Iu(t,e){let r=e.negate();return t?r:e}function Kf(t,e){let r=Cf(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Fx(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function By(t,e){Fx(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=mo(t),s=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function Hx(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r,c=Number(t&i),a=t>>s;c>n&&(c-=o,a+=vs);let u=e*n,d=u+Math.abs(c)-1,f=c===0,h=c<0,p=e%2!==0;return{nextN:a,offset:d,isZero:f,isNeg:h,isNegF:p,offsetF:u}}function i8(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function o8(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ry=new WeakMap,jx=new WeakMap;function Uy(t){return jx.get(t)||1}function Vx(t){if(t!==Pc)throw new Error("invalid wNAF")}var Mf=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>Pc;)r&vs&&(n=n.add(i)),i=i.double(),r>>=vs;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=By(r,this.bits),o=[],s=e,c=s;for(let a=0;a<n;a++){c=s,o.push(c);for(let u=1;u<i;u++)c=c.add(s),o.push(c);s=c.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=By(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:p}=Hx(n,c,s);n=a,d?o=o.add(Iu(h,r[p])):i=i.add(Iu(f,r[u]))}return Vx(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=By(e,this.bits);for(let s=0;s<o.windows&&n!==Pc;s++){let{nextN:c,offset:a,isZero:u,isNeg:d}=Hx(n,s,o);if(n=c,!u){let f=r[a];i=i.add(d?f.negate():f)}}return Vx(n),i}getPrecomputes(e,r,n){let i=Ry.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),Ry.set(r,i))),i}cached(e,r,n){let i=Uy(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=Uy(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){Fx(r,this.bits),jx.set(e,r),Ry.delete(e)}hasCache(e){return Uy(e)!==1}};function Wx(t,e,r,n){let i=e,o=t.ZERO,s=t.ZERO;for(;r>Pc||n>Pc;)r&vs&&(o=o.add(i)),n&vs&&(s=s.add(i)),i=i.double(),r>>=vs,n>>=vs;return{p1:o,p2:s}}function Gx(t,e,r,n){i8(r,t),o8(n,e);let i=r.length,o=n.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let s=t.ZERO,c=Nf(BigInt(i)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=mo(a),d=new Array(Number(u)+1).fill(s),f=Math.floor((e.BITS-1)/a)*a,h=s;for(let p=f;p>=0;p-=a){d.fill(s);for(let y=0;y<o;y++){let x=n[y],S=Number(x>>BigInt(p)&u);d[S]=d[S].add(r[y])}let g=s;for(let y=d.length-1,x=s;y>0;y--)x=x.add(d[y]),g=g.add(x);if(h=h.add(g),p!==0)for(let y=0;y<a;y++)h=h.double()}return h}function qx(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _y(e),e}else return wo(t,{isLE:r})}function zx(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>Pc))throw new Error(`CURVE.${a} must be positive bigint`)}let i=qx(e.p,r.Fp,n),o=qx(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}var Yx=(t,e)=>(t+(t>=0?e:-e)/Jx)/e;function s8(t,e,r){let[[n,i],[o,s]]=e,c=Yx(s*t,r),a=Yx(-i*t,r),u=t-c*n-a*o,d=-c*i-a*s,f=u<_i,h=d<_i;f&&(u=-u),h&&(d=-d);let p=mo(Math.ceil(Nf(r)/2))+Mc;if(u<_i||u>=p||d<_i||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}function Dy(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Oy(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Su(r.lowS,"lowS"),Su(r.prehash,"prehash"),r.format!==void 0&&Dy(r.format),r}var ky=class extends Error{constructor(e=""){super(e)}},Ti={Err:ky,_tlv:{encode:(t,e)=>{let{Err:r}=Ti;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=Au(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Au(i.length/2|128):"";return Au(t)+o+i+e},decode(t,e){let{Err:r}=Ti,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),s=0;if(!o)s=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)s=s<<8|d;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=Ti;if(t<_i)throw new e("integer: negative integers are not allowed");let r=Au(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ti;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ai(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ti,i=ot("signature",t),{v:o,l:s}=n.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:u,l:d}=n.decode(2,a);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ti,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}},_i=BigInt(0),Mc=BigInt(1),Jx=BigInt(2),$f=BigInt(3),c8=BigInt(4);function bo(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let i=ot("private key",e);try{n=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function a8(t,e={}){let r=zx("weierstrass",t,e),{Fp:n,Fn:i}=r,o=r.CURVE,{h:s,n:c}=o;_u(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=e;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Zx(n,i);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(G,I,D){let{x:E,y:U}=I.toAffine(),L=n.toBytes(E);if(Su(D,"isCompressed"),D){d();let N=!n.isOdd(U);return lt(Xx(N),L)}else return lt(Uint8Array.of(4),L,n.toBytes(U))}function h(G){yo(G,void 0,"Point");let{publicKey:I,publicKeyUncompressed:D}=u,E=G.length,U=G[0],L=G.subarray(1);if(E===I&&(U===2||U===3)){let N=n.fromBytes(L);if(!n.isValid(N))throw new Error("bad point: is not on curve, wrong x");let R=y(N),C;try{C=n.sqrt(R)}catch(J){let z=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let P=n.isOdd(C);return(U&1)===1!==P&&(C=n.neg(C)),{x:N,y:C}}else if(E===D&&U===4){let N=n.BYTES,R=n.fromBytes(L.subarray(0,N)),C=n.fromBytes(L.subarray(N,N*2));if(!x(R,C))throw new Error("bad point: is not on curve");return{x:R,y:C}}else throw new Error(`bad point: got length ${E}, expected compressed=${I} or uncompressed=${D}`)}let p=e.toBytes||f,g=e.fromBytes||h;function y(G){let I=n.sqr(G),D=n.mul(I,G);return n.add(n.add(D,n.mul(G,o.a)),o.b)}function x(G,I){let D=n.sqr(I),E=y(G);return n.eql(D,E)}if(!x(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(o.a,$f),c8),_=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(S,_)))throw new Error("bad curve params: a or b");function A(G,I,D=!1){if(!n.isValid(I)||D&&n.is0(I))throw new Error(`bad point coordinate ${G}`);return I}function O(G){if(!(G instanceof $))throw new Error("ProjectivePoint expected")}function T(G){if(!a||!a.basises)throw new Error("no endo");return s8(G,a.basises,i.ORDER)}let M=Ay((G,I)=>{let{X:D,Y:E,Z:U}=G;if(n.eql(U,n.ONE))return{x:D,y:E};let L=G.is0();I==null&&(I=L?n.ONE:n.inv(U));let N=n.mul(D,I),R=n.mul(E,I),C=n.mul(U,I);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),q=Ay(G=>{if(G.is0()){if(e.allowInfinityPoint&&!n.is0(G.Y))return;throw new Error("bad point: ZERO")}let{x:I,y:D}=G.toAffine();if(!n.isValid(I)||!n.isValid(D))throw new Error("bad point: x or y not field elements");if(!x(I,D))throw new Error("bad point: equation left != right");if(!G.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function j(G,I,D,E,U){return D=new $(n.mul(D.X,G),D.Y,D.Z),I=Iu(E,I),D=Iu(U,D),I.add(D)}class ${constructor(I,D,E){this.X=A("x",I),this.Y=A("y",D,!0),this.Z=A("z",E),Object.freeze(this)}static CURVE(){return o}static fromAffine(I){let{x:D,y:E}=I||{};if(!I||!n.isValid(D)||!n.isValid(E))throw new Error("invalid affine point");if(I instanceof $)throw new Error("projective point not allowed");return n.is0(D)&&n.is0(E)?$.ZERO:new $(D,E,n.ONE)}static fromBytes(I){let D=$.fromAffine(g(yo(I,void 0,"point")));return D.assertValidity(),D}static fromHex(I){return $.fromBytes(ot("pointHex",I))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(I=8,D=!0){return Q.createCache(this,I),D||this.multiply($f),this}assertValidity(){q(this)}hasEvenY(){let{y:I}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(I)}equals(I){O(I);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=I,C=n.eql(n.mul(D,R),n.mul(L,U)),P=n.eql(n.mul(E,R),n.mul(N,U));return C&&P}negate(){return new $(this.X,n.neg(this.Y),this.Z)}double(){let{a:I,b:D}=o,E=n.mul(D,$f),{X:U,Y:L,Z:N}=this,R=n.ZERO,C=n.ZERO,P=n.ZERO,V=n.mul(U,U),J=n.mul(L,L),z=n.mul(N,N),W=n.mul(U,L);return W=n.add(W,W),P=n.mul(U,N),P=n.add(P,P),R=n.mul(I,P),C=n.mul(E,z),C=n.add(R,C),R=n.sub(J,C),C=n.add(J,C),C=n.mul(R,C),R=n.mul(W,R),P=n.mul(E,P),z=n.mul(I,z),W=n.sub(V,z),W=n.mul(I,W),W=n.add(W,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,z),V=n.mul(V,W),C=n.add(C,V),z=n.mul(L,N),z=n.add(z,z),V=n.mul(z,W),R=n.sub(R,V),P=n.mul(z,J),P=n.add(P,P),P=n.add(P,P),new $(R,C,P)}add(I){O(I);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=I,C=n.ZERO,P=n.ZERO,V=n.ZERO,J=o.a,z=n.mul(o.b,$f),W=n.mul(D,L),Y=n.mul(E,N),X=n.mul(U,R),ue=n.add(D,E),ee=n.add(L,N);ue=n.mul(ue,ee),ee=n.add(W,Y),ue=n.sub(ue,ee),ee=n.add(D,U);let ce=n.add(L,R);return ee=n.mul(ee,ce),ce=n.add(W,X),ee=n.sub(ee,ce),ce=n.add(E,U),C=n.add(N,R),ce=n.mul(ce,C),C=n.add(Y,X),ce=n.sub(ce,C),V=n.mul(J,ee),C=n.mul(z,X),V=n.add(C,V),C=n.sub(Y,V),V=n.add(Y,V),P=n.mul(C,V),Y=n.add(W,W),Y=n.add(Y,W),X=n.mul(J,X),ee=n.mul(z,ee),Y=n.add(Y,X),X=n.sub(W,X),X=n.mul(J,X),ee=n.add(ee,X),W=n.mul(Y,ee),P=n.add(P,W),W=n.mul(ce,ee),C=n.mul(ue,C),C=n.sub(C,W),W=n.mul(ue,Y),V=n.mul(ce,V),V=n.add(V,W),new $(C,P,V)}subtract(I){return this.add(I.negate())}is0(){return this.equals($.ZERO)}multiply(I){let{endo:D}=e;if(!i.isValidNot0(I))throw new Error("invalid scalar: out of range");let E,U,L=N=>Q.cached(this,N,R=>Kf($,R));if(D){let{k1neg:N,k1:R,k2neg:C,k2:P}=T(I),{p:V,f:J}=L(R),{p:z,f:W}=L(P);U=J.add(W),E=j(D.beta,V,z,N,C)}else{let{p:N,f:R}=L(I);E=N,U=R}return Kf($,[E,U])[0]}multiplyUnsafe(I){let{endo:D}=e,E=this;if(!i.isValid(I))throw new Error("invalid scalar: out of range");if(I===_i||E.is0())return $.ZERO;if(I===Mc)return E;if(Q.hasCache(this))return this.multiply(I);if(D){let{k1neg:U,k1:L,k2neg:N,k2:R}=T(I),{p1:C,p2:P}=Wx($,E,L,R);return j(D.beta,C,P,U,N)}else return Q.unsafe(E,I)}multiplyAndAddUnsafe(I,D,E){let U=this.multiplyUnsafe(D).add(I.multiplyUnsafe(E));return U.is0()?void 0:U}toAffine(I){return M(this,I)}isTorsionFree(){let{isTorsionFree:I}=e;return s===Mc?!0:I?I($,this):Q.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:I}=e;return s===Mc?this:I?I($,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(I=!0){return Su(I,"isCompressed"),this.assertValidity(),p($,this,I)}toHex(I=!0){return Pt(this.toBytes(I))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(I=!0){return this.toBytes(I)}_setWindowSize(I){this.precompute(I)}static normalizeZ(I){return Kf($,I)}static msm(I,D){return Gx($,i,I,D)}static fromPrivateKey(I){return $.BASE.multiply(bo(i,I))}}$.BASE=new $(o.Gx,o.Gy,n.ONE),$.ZERO=new $(n.ZERO,n.ONE,n.ZERO),$.Fp=n,$.Fn=i;let Z=i.BITS,Q=new Mf($,e.endo?Math.ceil(Z/2):Z);return $.BASE.precompute(8),$}function Xx(t){return Uint8Array.of(t?2:3)}function Zx(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function u8(t,e={}){let{Fn:r}=t,n=e.randomBytes||Ir,i=Object.assign(Zx(t.Fp,r),{seed:Iy(r.ORDER)});function o(p){try{return!!bo(r,p)}catch{return!1}}function s(p,g){let{publicKey:y,publicKeyUncompressed:x}=i;try{let S=p.length;return g===!0&&S!==y||g===!1&&S!==x?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(i.seed)){return Pf(yo(p,i.seed,"seed"),r.ORDER)}function a(p,g=!0){return t.BASE.multiply(bo(r,p)).toBytes(g)}function u(p){let g=c(p);return{secretKey:g,publicKey:a(g)}}function d(p){if(typeof p=="bigint")return!1;if(p instanceof t)return!0;let{secretKey:g,publicKey:y,publicKeyUncompressed:x}=i;if(r.allowedLengths||g===y)return;let S=ot("key",p).length;return S===y||S===x}function f(p,g,y=!0){if(d(p)===!0)throw new Error("first arg must be private key");if(d(g)===!1)throw new Error("second arg must be public key");let x=bo(r,p);return t.fromHex(g).multiply(x).toBytes(y)}return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:u,Point:t,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:o,randomPrivateKey:c,normPrivateKeyToScalar:p=>bo(r,p),precompute(p=8,g=t.BASE){return g.precompute(p,!1)}},lengths:i})}function d8(t,e,r={}){Uf(e),_u(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Ir,i=r.hmac||((D,...E)=>wy(e,D,lt(...E))),{Fp:o,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p}=u8(t,r),g={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function x(D){let E=c>>Mc;return D>E}function S(D,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${D}: out of range 1..Point.Fn.ORDER`);return E}function _(D,E){Dy(E);let U=p.signature,L=E==="compact"?U:E==="recovered"?U+1:void 0;return yo(D,L,`${E} signature`)}class A{constructor(E,U,L){this.r=S("r",E),this.s=S("s",U),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(E,U=y){_(E,U);let L;if(U==="der"){let{r:P,s:V}=Ti.toSig(yo(E));return new A(P,V)}U==="recovered"&&(L=E[0],U="compact",E=E.subarray(1));let N=s.BYTES,R=E.subarray(0,N),C=E.subarray(N,N*2);return new A(s.fromBytes(R),s.fromBytes(C),L)}static fromHex(E,U){return this.fromBytes(_r(E),U)}addRecoveryBit(E){return new A(this.r,this.s,E)}recoverPublicKey(E){let U=o.ORDER,{r:L,s:N,recovery:R}=this;if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");if(c*Jx<U&&R>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=R===2||R===3?L+c:L;if(!o.isValid(P))throw new Error("recovery id 2 or 3 invalid");let V=o.toBytes(P),J=t.fromBytes(lt(Xx((R&1)===0),V)),z=s.inv(P),W=T(ot("msgHash",E)),Y=s.create(-W*z),X=s.create(N*z),ue=t.BASE.multiplyUnsafe(Y).add(J.multiplyUnsafe(X));if(ue.is0())throw new Error("point at infinify");return ue.assertValidity(),ue}hasHighS(){return x(this.s)}toBytes(E=y){if(Dy(E),E==="der")return _r(Ti.hexFromSig(this));let U=s.toBytes(this.r),L=s.toBytes(this.s);if(E==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return lt(Uint8Array.of(this.recovery),U,L)}return lt(U,L)}toHex(E){return Pt(this.toBytes(E))}assertValidity(){}static fromCompact(E){return A.fromBytes(ot("sig",E),"compact")}static fromDER(E){return A.fromBytes(ot("sig",E),"der")}normalizeS(){return this.hasHighS()?new A(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Pt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Pt(this.toBytes("compact"))}}let O=r.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let U=Ai(E),L=E.length*8-a;return L>0?U>>BigInt(L):U},T=r.bits2int_modN||function(E){return s.create(O(E))},M=mo(a);function q(D){return Rx("num < 2^"+a,D,_i,M),s.toBytes(D)}function j(D,E){return yo(D,void 0,"message"),E?yo(e(D),void 0,"prehashed message"):D}function $(D,E,U){if(["recovered","canonical"].some(Y=>Y in U))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:N,extraEntropy:R}=Oy(U,g);D=j(D,N);let C=T(D),P=bo(s,E),V=[q(P),q(C)];if(R!=null&&R!==!1){let Y=R===!0?n(p.secretKey):R;V.push(ot("extraEntropy",Y))}let J=lt(...V),z=C;function W(Y){let X=O(Y);if(!s.isValidNot0(X))return;let ue=s.inv(X),ee=t.BASE.multiply(X).toAffine(),ce=s.create(ee.x);if(ce===_i)return;let Ue=s.create(ue*s.create(z+ce*P));if(Ue===_i)return;let Ke=(ee.x===ce?0:2)|Number(ee.y&Mc),Je=Ue;return L&&x(Ue)&&(Je=s.neg(Ue),Ke^=1),new A(ce,Je,Ke)}return{seed:J,k2sig:W}}function Z(D,E,U={}){D=ot("message",D);let{seed:L,k2sig:N}=$(D,E,U);return Ux(e.outputLen,s.BYTES,i)(L,N)}function Q(D){let E,U=typeof D=="string"||bs(D),L=!U&&D!==null&&typeof D=="object"&&typeof D.r=="bigint"&&typeof D.s=="bigint";if(!U&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)E=new A(D.r,D.s);else if(U){try{E=A.fromBytes(ot("sig",D),"der")}catch(N){if(!(N instanceof Ti.Err))throw N}if(!E)try{E=A.fromBytes(ot("sig",D),"compact")}catch{return!1}}return E||!1}function G(D,E,U,L={}){let{lowS:N,prehash:R,format:C}=Oy(L,g);if(U=ot("publicKey",U),E=j(ot("message",E),R),"strict"in L)throw new Error("options.strict was renamed to lowS");let P=C===void 0?Q(D):A.fromBytes(ot("sig",D),C);if(P===!1)return!1;try{let V=t.fromBytes(U);if(N&&P.hasHighS())return!1;let{r:J,s:z}=P,W=T(E),Y=s.inv(z),X=s.create(W*Y),ue=s.create(J*Y),ee=t.BASE.multiplyUnsafe(X).add(V.multiplyUnsafe(ue));return ee.is0()?!1:s.create(ee.x)===J}catch{return!1}}function I(D,E,U={}){let{prehash:L}=Oy(U,g);return E=j(E,L),A.fromBytes(D,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p,Point:t,sign:Z,verify:G,recoverPublicKey:I,Signature:A,hash:e})}function f8(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,i=wo(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),o={Fp:r,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:o}}function l8(t){let{CURVE:e,curveOpts:r}=f8(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function h8(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,Lf(r.Fn.ORDER,r.Fn.BITS))})}function Qx(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:i}=l8(t),o=a8(e,r),s=d8(o,n,i);return h8(t,s)}function eE(t,e){let r=n=>Qx({...t,hash:n});return{...r(e),create:r}}var Kc={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},p8={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},y8=BigInt(0),tE=BigInt(1),Ny=BigInt(2);function g8(t){let e=Kc.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=Rr(d,r,e)*d%e,h=Rr(f,r,e)*d%e,p=Rr(h,Ny,e)*u%e,g=Rr(p,i,e)*p%e,y=Rr(g,o,e)*g%e,x=Rr(y,c,e)*y%e,S=Rr(x,a,e)*x%e,_=Rr(S,c,e)*y%e,A=Rr(_,r,e)*d%e,O=Rr(A,s,e)*g%e,T=Rr(O,n,e)*u%e,M=Rr(T,Ny,e);if(!Hf.eql(Hf.sqr(M),t))throw new Error("Cannot find square root");return M}var Hf=wo(Kc.p,{sqrt:g8}),xo=eE({...Kc,Fp:Hf,lowS:!0,endo:p8},ke),rE={};function Vf(t,...e){let r=rE[t];if(r===void 0){let n=ke(xs(t));r=lt(n,n),rE[t]=r}return ke(lt(r,...e))}var Ly=t=>t.toBytes(!0).slice(1),$c=xo.Point,Py=t=>t%Ny===y8;function Cy(t){let{Fn:e,BASE:r}=$c,n=bo(e,t),i=r.multiply(n);return{scalar:Py(i.y)?n:e.neg(n),bytes:Ly(i)}}function iE(t){let e=Hf;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);Py(i)||(i=e.neg(i));let o=$c.fromAffine({x:t,y:i});return o.assertValidity(),o}var Bu=Ai;function oE(...t){return $c.Fn.create(Bu(Vf("BIP0340/challenge",...t)))}function nE(t){return Cy(t).bytes}function m8(t,e,r=Ir(32)){let{Fn:n}=$c,i=ot("message",t),{bytes:o,scalar:s}=Cy(e),c=ot("auxRand",r,32),a=n.toBytes(s^Bu(Vf("BIP0340/aux",c))),u=Vf("BIP0340/nonce",a,o,i),{bytes:d,scalar:f}=Cy(u),h=oE(d,o,i),p=new Uint8Array(64);if(p.set(d,0),p.set(n.toBytes(n.create(f+h*s)),32),!sE(p,i,o))throw new Error("sign: Invalid signature produced");return p}function sE(t,e,r){let{Fn:n,BASE:i}=$c,o=ot("signature",t,64),s=ot("message",e),c=ot("publicKey",r,32);try{let a=iE(Bu(c)),u=Bu(o.subarray(0,32));if(!Tu(u,tE,Kc.p))return!1;let d=Bu(o.subarray(32,64));if(!Tu(d,tE,Kc.n))return!1;let f=oE(n.toBytes(u),Ly(a),s),h=i.multiplyUnsafe(d).add(a.multiplyUnsafe(n.neg(f))),{x:p,y:g}=h.toAffine();return!(h.is0()||!Py(g)||p!==u)}catch{return!1}}var Ur=(()=>{let r=(i=Ir(48))=>Pf(i,Kc.n);xo.utils.randomSecretKey;function n(i){let o=r(i);return{secretKey:o,publicKey:nE(o)}}return{keygen:n,getPublicKey:nE,sign:m8,verify:sE,Point:$c,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:Vf,lift_x:iE,pointToBytes:Ly,numberToBytesBE:Lc,bytesToNumberBE:Ai,mod:Br},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:32*2,seed:48}}})();l();var w8=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),aE=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),b8=aE.map(t=>(9*t+5)%16),uE=(()=>{let r=[[aE],[b8]];for(let n=0;n<4;n++)for(let i of r)i.push(i[n].map(o=>w8[o]));return r})(),dE=uE[0],fE=uE[1],lE=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>Uint8Array.from(t)),x8=dE.map((t,e)=>t.map(r=>lE[e][r])),E8=fE.map((t,e)=>t.map(r=>lE[e][r])),v8=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),S8=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function cE(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var qf=new Uint32Array(16),My=class extends Cc{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:i,h4:o}=this;return[e,r,n,i,o]}set(e,r,n,i,o){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(e,r){for(let p=0;p<16;p++,r+=4)qf[p]=e.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,c=this.h2|0,a=c,u=this.h3|0,d=u,f=this.h4|0,h=f;for(let p=0;p<5;p++){let g=4-p,y=v8[p],x=S8[p],S=dE[p],_=fE[p],A=x8[p],O=E8[p];for(let T=0;T<16;T++){let M=Eu(n+cE(p,o,c,u)+qf[S[T]]+y,A[T])+f|0;n=f,f=u,u=Eu(c,10)|0,c=o,o=M}for(let T=0;T<16;T++){let M=Eu(i+cE(g,s,a,d)+qf[_[T]]+x,O[T])+h|0;i=h,h=d,d=Eu(a,10)|0,a=s,s=M}}this.set(this.h1+c+d|0,this.h2+u+h|0,this.h3+f+i|0,this.h4+n+s|0,this.h0+o+a|0)}roundClean(){qn(qf)}destroy(){this.destroyed=!0,qn(this.buffer),this.set(0,0,0,0,0)}},hE=Df(()=>new My);l();l();function Hc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function A8(t,...e){if(!Hc(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function wE(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Hy(t){if(typeof t!="function")throw new Error("function expected");return!0}function Vc(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Uu(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function jf(t){if(!Array.isArray(t))throw new Error("array expected")}function bE(t,e){if(!wE(!0,e))throw new Error(`${t}: array of strings expected`)}function Vy(t,e){if(!wE(!1,e))throw new Error(`${t}: array of numbers expected`)}function Ou(...t){let e=o=>o,r=(o,s)=>c=>o(s(c)),n=t.map(o=>o.encode).reduceRight(r,e),i=t.map(o=>o.decode).reduce(r,e);return{encode:n,decode:i}}function Gf(t){let e=typeof t=="string"?t.split(""):t,r=e.length;bE("alphabet",e);let n=new Map(e.map((i,o)=>[i,o]));return{encode:i=>(jf(i),i.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);return e[o]})),decode:i=>(jf(i),i.map(o=>{Vc("alphabet.decode",o);let s=n.get(o);if(s===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);return s}))}}function zf(t=""){return Vc("join",t),{encode:e=>(bE("join.decode",e),e.join(t)),decode:e=>(Vc("join.decode",e),e.split(t))}}function T8(t){return Hy(t),{encode:e=>e,decode:e=>t(e)}}function pE(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(jf(t),!t.length)return[];let n=0,i=[],o=Array.from(t,c=>{if(Uu(c),c<0||c>=e)throw new Error(`invalid integer: ${c}`);return c}),s=o.length;for(;;){let c=0,a=!0;for(let u=n;u<s;u++){let d=o[u],f=e*c,h=f+d;if(!Number.isSafeInteger(h)||f/e!==c||h-d!==f)throw new Error("convertRadix: carry overflow");let p=h/r;c=h%r;let g=Math.floor(p);if(o[u]=g,!Number.isSafeInteger(g)||g*r+c!==h)throw new Error("convertRadix: carry overflow");if(a)g?a=!1:n=u;else continue}if(i.push(c),a)break}for(let c=0;c<t.length-1&&t[c]===0;c++)i.push(0);return i.reverse()}var xE=(t,e)=>e===0?t:xE(e,t%e),Wf=(t,e)=>t+(e-xE(t,e)),Ff=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Ky(t,e,r,n){if(jf(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Wf(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Wf(e,r)}`);let i=0,o=0,s=Ff[e],c=Ff[r]-1,a=[];for(let u of t){if(Uu(u),u>=s)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(i=i<<e|u,o+e>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);for(o+=e;o>=r;o-=r)a.push((i>>o-r&c)>>>0);let d=Ff[o];if(d===void 0)throw new Error("invalid carry");i&=d-1}if(i=i<<r-o&c,!n&&o>=e)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&o>0&&a.push(i>>>0),a}function _8(t){Uu(t);let e=2**8;return{encode:r=>{if(!Hc(r))throw new Error("radix.encode input should be Uint8Array");return pE(Array.from(r),e,t)},decode:r=>(Vy("radix.decode",r),Uint8Array.from(pE(r,t,e)))}}function qy(t,e=!1){if(Uu(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Wf(8,t)>32||Wf(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Hc(r))throw new Error("radix2.encode input should be Uint8Array");return Ky(Array.from(r),8,t,!e)},decode:r=>(Vy("radix2.decode",r),Uint8Array.from(Ky(r,t,8,e)))}}function yE(t){return Hy(t),function(...e){try{return t.apply(null,e)}catch{}}}function I8(t,e){return Uu(t),Hy(e),{encode(r){if(!Hc(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),i=new Uint8Array(r.length+t);return i.set(r),i.set(n,r.length),i},decode(r){if(!Hc(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),i=r.slice(-t),o=e(n).slice(0,t);for(let s=0;s<t;s++)if(o[s]!==i[s])throw new Error("Invalid checksum");return n}}}var qc=Ou(qy(6),Gf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),zf("")),B8=t=>Ou(_8(58),Gf(t),zf("")),Yf=B8("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var EE=t=>Ou(I8(4,e=>t(t(e))),Yf);var $y=Ou(Gf("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),zf("")),gE=[996825010,642813549,513874426,1027748829,705979059];function Ru(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<gE.length;n++)(e>>n&1)===1&&(r^=gE[n]);return r}function mE(t,e,r=1){let n=t.length,i=1;for(let o=0;o<n;o++){let s=t.charCodeAt(o);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);i=Ru(i)^s>>5}i=Ru(i);for(let o=0;o<n;o++)i=Ru(i)^t.charCodeAt(o)&31;for(let o of e)i=Ru(i)^o;for(let o=0;o<6;o++)i=Ru(i);return i^=r,$y.encode(Ky([i%Ff[30]],30,5,!1))}function vE(t){let e=t==="bech32"?1:734539939,r=qy(5),n=r.decode,i=r.encode,o=yE(n);function s(f,h,p=90){Vc("bech32.encode prefix",f),Hc(h)&&(h=Array.from(h)),Vy("bech32.encode",h);let g=f.length;if(g===0)throw new TypeError(`Invalid prefix length ${g}`);let y=g+7+h.length;if(p!==!1&&y>p)throw new TypeError(`Length ${y} exceeds limit ${p}`);let x=f.toLowerCase(),S=mE(x,h,e);return`${x}1${$y.encode(h)}${S}`}function c(f,h=90){Vc("bech32.decode input",f);let p=f.length;if(p<8||h!==!1&&p>h)throw new TypeError(`invalid string length: ${p} (${f}). Expected (8..${h})`);let g=f.toLowerCase();if(f!==g&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");let y=g.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');let x=g.slice(0,y),S=g.slice(y+1);if(S.length<6)throw new Error("Data must be at least 6 characters long");let _=$y.decode(S).slice(0,-6),A=mE(x,_,e);if(!S.endsWith(A))throw new Error(`Invalid checksum in ${f}: expected "${A}"`);return{prefix:x,words:_}}let a=yE(c);function u(f){let{prefix:h,words:p}=c(f,!1);return{prefix:h,words:p,bytes:n(p)}}function d(f,h){return s(f,i(h))}return{encode:s,decode:c,encodeFromBytes:d,decodeToBytes:u,decodeUnsafe:a,fromWords:n,fromWordsUnsafe:o,toWords:i}}var Jf=vE("bech32"),Ss=vE("bech32m"),SE={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},R8=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",U8={encode(t){return A8(t),t.toHex()},decode(t){return Vc("hex",t),Uint8Array.fromHex(t)}},xe=R8?U8:Ou(qy(4),Gf("0123456789abcdef"),zf(""),T8(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var Ve=new Uint8Array,Gy=new Uint8Array([0]);function Fc(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}function zr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function O8(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!zr(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var zy=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function jc(t){return Object.prototype.toString.call(t)==="[object Object]"}function Fn(t){return Number.isSafeInteger(t)}var Xf={equalBytes:Fc,isBytes:zr,isCoder:Or,checkBounds:TE,concatBytes:O8,createView:zy,isPlainObject:jc},AE=t=>{if(t!==null&&typeof t!="string"&&!Or(t)&&!zr(t)&&!Fn(t))throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${t} (${typeof t})`);return{encodeStream(e,r){if(t===null)return;if(Or(t))return t.encodeStream(e,r);let n;if(typeof t=="number"?n=t:typeof t=="string"&&(n=Ii.resolve(e.stack,t)),typeof n=="bigint"&&(n=Number(n)),n===void 0||n!==r)throw e.err(`Wrong length: ${n} len=${t} exp=${r} (${typeof r})`)},decodeStream(e){let r;if(Or(t)?r=Number(t.decodeStream(e)):typeof t=="number"?r=t:typeof t=="string"&&(r=Ii.resolve(e.stack,t)),typeof r=="bigint"&&(r=Number(r)),typeof r!="number")throw e.err(`Wrong length: ${r}`);return r}}},Dt={BITS:32,FULL_MASK:-1>>>0,len:t=>Math.ceil(t/32),create:t=>new Uint32Array(Dt.len(t)),clean:t=>t.fill(0),debug:t=>Array.from(t).map(e=>(e>>>0).toString(2).padStart(32,"0")),checkLen:(t,e)=>{if(Dt.len(e)!==t.length)throw new Error(`wrong length=${t.length}. Expected: ${Dt.len(e)}`)},chunkLen:(t,e,r)=>{if(e<0)throw new Error(`wrong pos=${e}`);if(e+r>t)throw new Error(`wrong range=${e}/${r} of ${t}`)},set:(t,e,r,n=!0)=>!n&&t[e]&r?!1:(t[e]|=r,!0),pos:(t,e)=>({chunk:Math.floor((t+e)/32),mask:1<<32-(t+e)%32-1}),indices:(t,e,r=!1)=>{Dt.checkLen(t,e);let{FULL_MASK:n,BITS:i}=Dt,o=i-e%i,s=o?n>>>o<<o:n,c=[];for(let a=0;a<t.length;a++){let u=t[a];if(r&&(u=~u),a===t.length-1&&(u&=s),u!==0)for(let d=0;d<i;d++){let f=1<<i-d-1;u&f&&c.push(a*i+d)}}return c},range:t=>{let e=[],r;for(let n of t)r===void 0||n!==r.pos+r.length?e.push(r={pos:n,length:1}):r.length+=1;return e},rangeDebug:(t,e,r=!1)=>`[${Dt.range(Dt.indices(t,e,r)).map(n=>`(${n.pos}/${n.length})`).join(", ")}]`,setRange:(t,e,r,n,i=!0)=>{Dt.chunkLen(e,r,n);let{FULL_MASK:o,BITS:s}=Dt,c=r%s?Math.floor(r/s):void 0,a=r+n,u=a%s?Math.floor(a/s):void 0;if(c!==void 0&&c===u)return Dt.set(t,c,o>>>s-n<<s-n-r,i);if(c!==void 0&&!Dt.set(t,c,o>>>r%s,i))return!1;let d=c!==void 0?c+1:r/s,f=u!==void 0?u:a/s;for(let h=d;h<f;h++)if(!Dt.set(t,h,o,i))return!1;return!(u!==void 0&&c!==u&&!Dt.set(t,u,o<<s-a%s,i))}},Ii={pushObj:(t,e,r)=>{let n={obj:e};t.push(n),r((i,o)=>{n.field=i,o(),n.field=void 0}),t.pop()},path:t=>{let e=[];for(let r of t)r.field!==void 0&&e.push(r.field);return e.join("/")},err:(t,e,r)=>{let n=new Error(`${t}(${Ii.path(e)}): ${typeof r=="string"?r:r.message}`);return r instanceof Error&&r.stack&&(n.stack=r.stack),n},resolve:(t,e)=>{let r=e.split("/"),n=t.map(s=>s.obj),i=0;for(;i<r.length&&r[i]==="..";i++)n.pop();let o=n.pop();for(;i<r.length;i++){if(!o||o[r[i]]===void 0)return;o=o[r[i]]}return o}},Fy=class t{constructor(e,r={},n=[],i=void 0,o=0){this.pos=0,this.bitBuf=0,this.bitPos=0,this.data=e,this.opts=r,this.stack=n,this.parent=i,this.parentOffset=o,this.view=zy(e)}_enablePointers(){if(this.parent)return this.parent._enablePointers();this.bs||(this.bs=Dt.create(this.data.length),Dt.setRange(this.bs,this.data.length,0,this.pos,this.opts.allowMultipleReads))}markBytesBS(e,r){return this.parent?this.parent.markBytesBS(this.parentOffset+e,r):!r||!this.bs?!0:Dt.setRange(this.bs,this.data.length,e,r,!1)}markBytes(e){let r=this.pos;this.pos+=e;let n=this.markBytesBS(r,e);if(!this.opts.allowMultipleReads&&!n)throw this.err(`multiple read pos=${this.pos} len=${e}`);return n}pushObj(e,r){return Ii.pushObj(this.stack,e,r)}readView(e,r){if(!Number.isFinite(e))throw this.err(`readView: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readView: Unexpected end of buffer");let n=r(this.view,this.pos);return this.markBytes(e),n}absBytes(e){if(e>this.data.length)throw new Error("Unexpected end of buffer");return this.data.subarray(e)}finish(){if(!this.opts.allowUnreadBytes){if(this.bitPos)throw this.err(`${this.bitPos} bits left after unpack: ${xe.encode(this.data.slice(this.pos))}`);if(this.bs&&!this.parent){let e=Dt.indices(this.bs,this.data.length,!0);if(e.length){let r=Dt.range(e).map(({pos:n,length:i})=>`(${n}/${i})[${xe.encode(this.data.subarray(n,n+i))}]`).join(", ");throw this.err(`unread byte ranges: ${r} (total=${this.data.length})`)}else return}if(!this.isEnd())throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${xe.encode(this.data.slice(this.pos))}`)}}err(e){return Ii.err("Reader",this.stack,e)}offsetReader(e){if(e>this.data.length)throw this.err("offsetReader: Unexpected end of buffer");return new t(this.absBytes(e),this.opts,this.stack,this,e)}bytes(e,r=!1){if(this.bitPos)throw this.err("readBytes: bitPos not empty");if(!Number.isFinite(e))throw this.err(`readBytes: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let n=this.data.subarray(this.pos,this.pos+e);return r||this.markBytes(e),n}byte(e=!1){if(this.bitPos)throw this.err("readByte: bitPos not empty");if(this.pos+1>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let r=this.data[this.pos];return e||this.markBytes(1),r}get leftBytes(){return this.data.length-this.pos}get totalBytes(){return this.data.length}isEnd(){return this.pos>=this.data.length&&!this.bitPos}bits(e){if(e>32)throw this.err("BitReader: cannot read more than 32 bits in single call");let r=0;for(;e;){this.bitPos||(this.bitBuf=this.byte(),this.bitPos=8);let n=Math.min(e,this.bitPos);this.bitPos-=n,r=r<<n|this.bitBuf>>this.bitPos&2**n-1,this.bitBuf&=2**this.bitPos-1,e-=n}return r>>>0}find(e,r=this.pos){if(!zr(e))throw this.err(`find: needle is not bytes! ${e}`);if(this.bitPos)throw this.err("findByte: bitPos not empty");if(!e.length)throw this.err("find: needle is empty");for(let n=r;(n=this.data.indexOf(e[0],n))!==-1;n++){if(n===-1||this.data.length-n<e.length)return;if(Fc(e,this.data.subarray(n,n+e.length)))return n}}},jy=class{constructor(e=[]){this.pos=0,this.buffers=[],this.ptrs=[],this.bitBuf=0,this.bitPos=0,this.viewBuf=new Uint8Array(8),this.finished=!1,this.stack=e,this.view=zy(this.viewBuf)}pushObj(e,r){return Ii.pushObj(this.stack,e,r)}writeView(e,r){if(this.finished)throw this.err("buffer: finished");if(!Fn(e)||e>8)throw new Error(`wrong writeView length=${e}`);r(this.view),this.bytes(this.viewBuf.slice(0,e)),this.viewBuf.fill(0)}err(e){if(this.finished)throw this.err("buffer: finished");return Ii.err("Reader",this.stack,e)}bytes(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeBytes: ends with non-empty bit buffer");this.buffers.push(e),this.pos+=e.length}byte(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeByte: ends with non-empty bit buffer");this.buffers.push(new Uint8Array([e])),this.pos++}finish(e=!0){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("buffer: ends with non-empty bit buffer");let r=this.buffers.concat(this.ptrs.map(o=>o.buffer)),n=r.map(o=>o.length).reduce((o,s)=>o+s,0),i=new Uint8Array(n);for(let o=0,s=0;o<r.length;o++){let c=r[o];i.set(c,s),s+=c.length}for(let o=this.pos,s=0;s<this.ptrs.length;s++){let c=this.ptrs[s];i.set(c.ptr.encode(o),c.pos),o+=c.buffer.length}if(e){this.buffers=[];for(let o of this.ptrs)o.buffer.fill(0);this.ptrs=[],this.finished=!0,this.bitBuf=0}return i}bits(e,r){if(r>32)throw this.err("writeBits: cannot write more than 32 bits in single call");if(e>=2**r)throw this.err(`writeBits: value (${e}) >= 2**bits (${r})`);for(;r;){let n=Math.min(r,8-this.bitPos);this.bitBuf=this.bitBuf<<n|e>>r-n,this.bitPos+=n,r-=n,e&=2**r-1,this.bitPos===8&&(this.bitPos=0,this.buffers.push(new Uint8Array([this.bitBuf])),this.pos++)}}},Wy=t=>Uint8Array.from(t).reverse();function TE(t,e,r){if(r){let n=2n**(e-1n);if(t<-n||t>=n)throw new Error(`value out of signed bounds. Expected ${-n} <= ${t} < ${n}`)}else if(0n>t||t>=2n**e)throw new Error(`value out of unsigned bounds. Expected 0 <= ${t} < ${2n**e}`)}function _E(t){return{encodeStream:t.encodeStream,decodeStream:t.decodeStream,size:t.size,encode:e=>{let r=new jy;return t.encodeStream(r,e),r.finish()},decode:(e,r={})=>{let n=new Fy(e,r),i=t.decodeStream(n);return n.finish(),i}}}function jt(t,e){if(!Or(t))throw new Error(`validate: invalid inner value ${t}`);if(typeof e!="function")throw new Error("validate: fn should be function");return _E({size:t.size,encodeStream:(r,n)=>{let i;try{i=e(n)}catch(o){throw r.err(o)}t.encodeStream(r,i)},decodeStream:r=>{let n=t.decodeStream(r);try{return e(n)}catch(i){throw r.err(i)}}})}var Wt=t=>{let e=_E(t);return t.validate?jt(e,t.validate):e},Zf=t=>jc(t)&&typeof t.decode=="function"&&typeof t.encode=="function";function Or(t){return jc(t)&&Zf(t)&&typeof t.encodeStream=="function"&&typeof t.decodeStream=="function"&&(t.size===void 0||Fn(t.size))}function D8(){return{encode:t=>{if(!Array.isArray(t))throw new Error("array expected");let e={};for(let r of t){if(!Array.isArray(r)||r.length!==2)throw new Error("array of two elements expected");let n=r[0],i=r[1];if(e[n]!==void 0)throw new Error(`key(${n}) appears twice in struct`);e[n]=i}return e},decode:t=>{if(!jc(t))throw new Error(`expected plain object, got ${t}`);return Object.entries(t)}}}var k8={encode:t=>{if(typeof t!="bigint")throw new Error(`expected bigint, got ${typeof t}`);if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error(`element bigger than MAX_SAFE_INTEGER=${t}`);return Number(t)},decode:t=>{if(!Fn(t))throw new Error("element is not a safe integer");return BigInt(t)}};function N8(t){if(!jc(t))throw new Error("plain object expected");return{encode:e=>{if(!Fn(e)||!(e in t))throw new Error(`wrong value ${e}`);return t[e]},decode:e=>{if(typeof e!="string")throw new Error(`wrong value ${typeof e}`);return t[e]}}}function C8(t,e=!1){if(!Fn(t))throw new Error(`decimal/precision: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`decimal/round: expected boolean, got ${typeof e}`);let r=10n**BigInt(t);return{encode:n=>{if(typeof n!="bigint")throw new Error(`expected bigint, got ${typeof n}`);let i=(n<0n?-n:n).toString(10),o=i.length-t;o<0&&(i=i.padStart(i.length-o,"0"),o=0);let s=i.length-1;for(;s>=o&&i[s]==="0";s--);let c=i.slice(0,o),a=i.slice(o,s+1);return c||(c="0"),n<0n&&(c="-"+c),a?`${c}.${a}`:c},decode:n=>{if(typeof n!="string")throw new Error(`expected string, got ${typeof n}`);if(n==="-0")throw new Error("negative zero is not allowed");let i=!1;if(n.startsWith("-")&&(i=!0,n=n.slice(1)),!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))throw new Error(`wrong string value=${n}`);let o=n.indexOf(".");o=o===-1?n.length:o;let s=n.slice(0,o),c=n.slice(o+1).replace(/0+$/,""),a=BigInt(s)*r;if(!e&&c.length>t)throw new Error(`fractional part cannot be represented with this precision (num=${n}, prec=${t})`);let u=Math.min(c.length,t),d=BigInt(c.slice(0,u))*10n**BigInt(t-u),f=a+d;return i?-f:f}}}function L8(t){if(!Array.isArray(t))throw new Error(`expected array, got ${typeof t}`);for(let e of t)if(!Zf(e))throw new Error(`wrong base coder ${e}`);return{encode:e=>{for(let r of t){let n=r.encode(e);if(n!==void 0)return n}throw new Error(`match/encode: cannot find match in ${e}`)},decode:e=>{for(let r of t){let n=r.decode(e);if(n!==void 0)return n}throw new Error(`match/decode: cannot find match in ${e}`)}}}var IE=t=>{if(!Zf(t))throw new Error("BaseCoder expected");return{encode:t.decode,decode:t.encode}},Bi={dict:D8,numberBigint:k8,tsEnum:N8,decimal:C8,match:L8,reverse:IE};var Yy=(t,e=!1,r=!1,n=!0)=>{if(!Fn(t))throw new Error(`bigint/size: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`bigint/le: expected boolean, got ${typeof e}`);if(typeof r!="boolean")throw new Error(`bigint/signed: expected boolean, got ${typeof r}`);if(typeof n!="boolean")throw new Error(`bigint/sized: expected boolean, got ${typeof n}`);let i=BigInt(t),o=2n**(8n*i-1n);return Wt({size:n?t:void 0,encodeStream:(s,c)=>{r&&c<0&&(c=c|o);let a=[];for(let d=0;d<t;d++)a.push(Number(c&255n)),c>>=8n;let u=new Uint8Array(a).reverse();if(!n){let d=0;for(d=0;d<u.length&&u[d]===0;d++);u=u.subarray(d)}s.bytes(e?u.reverse():u)},decodeStream:s=>{let c=s.bytes(n?t:Math.min(t,s.leftBytes)),a=e?c:Wy(c),u=0n;for(let d=0;d<a.length;d++)u|=BigInt(a[d])<<8n*BigInt(d);return r&&u&o&&(u=(u^o)-o),u},validate:s=>{if(typeof s!="bigint")throw new Error(`bigint: invalid value: ${s}`);return TE(s,8n*i,!!r),s}})};var BE=Yy(32,!1);var Wc=Yy(8,!0);var RE=Yy(8,!0,!0);var P8=(t,e)=>Wt({size:t,encodeStream:(r,n)=>r.writeView(t,i=>e.write(i,n)),decodeStream:r=>r.readView(t,e.read),validate:r=>{if(typeof r!="number")throw new Error(`viewCoder: expected number, got ${typeof r}`);return e.validate&&e.validate(r),r}}),Du=(t,e,r)=>{let n=t*8,i=2**(n-1),o=a=>{if(!Fn(a))throw new Error(`sintView: value is not safe integer: ${a}`);if(a<-i||a>=i)throw new Error(`sintView: value out of bounds. Expected ${-i} <= ${a} < ${i}`)},s=2**n,c=a=>{if(!Fn(a))throw new Error(`uintView: value is not safe integer: ${a}`);if(0>a||a>=s)throw new Error(`uintView: value out of bounds. Expected 0 <= ${a} < ${s}`)};return P8(t,{write:r.write,read:r.read,validate:e?o:c})},Ie=Du(4,!1,{read:(t,e)=>t.getUint32(e,!0),write:(t,e)=>t.setUint32(0,e,!0)}),UE=Du(4,!1,{read:(t,e)=>t.getUint32(e,!1),write:(t,e)=>t.setUint32(0,e,!1)}),Eo=Du(4,!0,{read:(t,e)=>t.getInt32(e,!0),write:(t,e)=>t.setInt32(0,e,!0)});var Jy=Du(2,!1,{read:(t,e)=>t.getUint16(e,!0),write:(t,e)=>t.setUint16(0,e,!0)});var mn=Du(1,!1,{read:(t,e)=>t.getUint8(e),write:(t,e)=>t.setUint8(0,e)});var Fe=(t,e=!1)=>{if(typeof e!="boolean")throw new Error(`bytes/le: expected boolean, got ${typeof e}`);let r=AE(t),n=zr(t);return Wt({size:typeof t=="number"?t:void 0,encodeStream:(i,o)=>{n||r.encodeStream(i,o.length),i.bytes(e?Wy(o):o),n&&i.bytes(t)},decodeStream:i=>{let o;if(n){let s=i.find(t);if(!s)throw i.err("bytes: cannot find terminator");o=i.bytes(s-i.pos),i.bytes(t.length)}else o=i.bytes(t===null?i.leftBytes:r.decodeStream(i));return e?Wy(o):o},validate:i=>{if(!zr(i))throw new Error(`bytes: invalid value ${i}`);return i}})};function OE(t,e){if(!Or(e))throw new Error(`prefix: invalid inner value ${e}`);return gn(Fe(t),IE(e))}var Qf=(t,e=!1)=>jt(gn(Fe(t,e),SE),r=>{if(typeof r!="string")throw new Error(`expected string, got ${typeof r}`);return r});var DE=(t,e={isLE:!1,with0x:!1})=>{let r=gn(Fe(t,e.isLE),xe),n=e.with0x;if(typeof n!="boolean")throw new Error(`hex/with0x: expected boolean, got ${typeof n}`);return n&&(r=gn(r,{encode:i=>`0x${i}`,decode:i=>{if(!i.startsWith("0x"))throw new Error("hex(with0x=true).encode input should start with 0x");return i.slice(2)}})),r};function gn(t,e){if(!Or(t))throw new Error(`apply: invalid inner value ${t}`);if(!Zf(e))throw new Error(`apply: invalid base value ${t}`);return Wt({size:t.size,encodeStream:(r,n)=>{let i;try{i=e.decode(n)}catch(o){throw r.err(""+o)}return t.encodeStream(r,i)},decodeStream:r=>{let n=t.decodeStream(r);try{return e.encode(n)}catch(i){throw r.err(""+i)}}})}var kE=(t,e=!1)=>{if(!zr(t))throw new Error(`flag/flagValue: expected Uint8Array, got ${typeof t}`);if(typeof e!="boolean")throw new Error(`flag/xor: expected boolean, got ${typeof e}`);return Wt({size:t.length,encodeStream:(r,n)=>{!!n!==e&&r.bytes(t)},decodeStream:r=>{let n=r.leftBytes>=t.length;return n&&(n=Fc(r.bytes(t.length,!0),t),n&&r.bytes(t.length)),n!==e},validate:r=>{if(r!==void 0&&typeof r!="boolean")throw new Error(`flag: expected boolean value or undefined, got ${typeof r}`);return r}})};function NE(t,e,r){if(!Or(e))throw new Error(`flagged: invalid inner value ${e}`);if(typeof t!="string"&&!Or(e))throw new Error(`flagged: wrong path=${t}`);return Wt({encodeStream:(n,i)=>{typeof t=="string"?Ii.resolve(n.stack,t)?e.encodeStream(n,i):r&&e.encodeStream(n,r):(t.encodeStream(n,!!i),i?e.encodeStream(n,i):r&&e.encodeStream(n,r))},decodeStream:n=>{let i=!1;if(typeof t=="string"?i=!!Ii.resolve(n.stack,t):i=t.decodeStream(n),i)return e.decodeStream(n);r&&e.decodeStream(n)}})}function el(t,e,r=!0){if(!Or(t))throw new Error(`magic: invalid inner value ${t}`);if(typeof r!="boolean")throw new Error(`magic: expected boolean, got ${typeof r}`);return Wt({size:t.size,encodeStream:(n,i)=>t.encodeStream(n,e),decodeStream:n=>{let i=t.decodeStream(n);if(r&&typeof i!="object"&&i!==e||zr(e)&&!Fc(e,i))throw n.err(`magic: invalid value: ${i} !== ${e}`)},validate:n=>{if(n!==void 0)throw new Error(`magic: wrong value=${typeof n}`);return n}})}function CE(t){let e=0;for(let r of t){if(r.size===void 0)return;if(!Fn(r.size))throw new Error(`sizeof: wrong element size=${e}`);e+=r.size}return e}function Et(t){if(!jc(t))throw new Error(`struct: expected plain object, got ${t}`);for(let e in t)if(!Or(t[e]))throw new Error(`struct: field ${e} is not CoderType`);return Wt({size:CE(Object.values(t)),encodeStream:(e,r)=>{e.pushObj(r,n=>{for(let i in t)n(i,()=>t[i].encodeStream(e,r[i]))})},decodeStream:e=>{let r={};return e.pushObj(r,n=>{for(let i in t)n(i,()=>r[i]=t[i].decodeStream(e))}),r},validate:e=>{if(typeof e!="object"||e===null)throw new Error(`struct: invalid value ${e}`);return e}})}function LE(t){if(!Array.isArray(t))throw new Error(`Packed.Tuple: got ${typeof t} instead of array`);for(let e=0;e<t.length;e++)if(!Or(t[e]))throw new Error(`tuple: field ${e} is not CoderType`);return Wt({size:CE(t),encodeStream:(e,r)=>{if(!Array.isArray(r))throw e.err(`tuple: invalid value ${r}`);e.pushObj(r,n=>{for(let i=0;i<t.length;i++)n(`${i}`,()=>t[i].encodeStream(e,r[i]))})},decodeStream:e=>{let r=[];return e.pushObj(r,n=>{for(let i=0;i<t.length;i++)n(`${i}`,()=>r.push(t[i].decodeStream(e)))}),r},validate:e=>{if(!Array.isArray(e))throw new Error(`tuple: invalid value ${e}`);if(e.length!==t.length)throw new Error(`tuple: wrong length=${e.length}, expected ${t.length}`);return e}})}function Gt(t,e){if(!Or(e))throw new Error(`array: invalid inner value ${e}`);let r=AE(typeof t=="string"?`../${t}`:t);return Wt({size:typeof t=="number"&&e.size?t*e.size:void 0,encodeStream:(n,i)=>{let o=n;o.pushObj(i,s=>{zr(t)||r.encodeStream(n,i.length);for(let c=0;c<i.length;c++)s(`${c}`,()=>{let a=i[c],u=n.pos;if(e.encodeStream(n,a),zr(t)){if(t.length>o.pos-u)return;let d=o.finish(!1).subarray(u,o.pos);if(Fc(d.subarray(0,t.length),t))throw o.err(`array: inner element encoding same as separator. elm=${a} data=${d}`)}})}),zr(t)&&n.bytes(t)},decodeStream:n=>{let i=[];return n.pushObj(i,o=>{if(t===null)for(let s=0;!n.isEnd()&&(o(`${s}`,()=>i.push(e.decodeStream(n))),!(e.size&&n.leftBytes<e.size));s++);else if(zr(t))for(let s=0;;s++){if(Fc(n.bytes(t.length,!0),t)){n.bytes(t.length);break}o(`${s}`,()=>i.push(e.decodeStream(n)))}else{let s;o("arrayLen",()=>s=r.decodeStream(n));for(let c=0;c<s;c++)o(`${c}`,()=>i.push(e.decodeStream(n)))}}),i},validate:n=>{if(!Array.isArray(n))throw new Error(`array: invalid value ${n}`);return n}})}var nl=xo.ProjectivePoint,rl=xo.CURVE.n,Ce=Xf.isBytes,jn=Xf.concatBytes,st=Xf.equalBytes;var Gc=t=>hE(ke(t)),Ri=(...t)=>ke(ke(jn(...t))),cM=Ur.utils.randomPrivateKey,il=Ur.getPublicKey,Xy=xo.getPublicKey,PE=t=>t.r<rl/2n;function ME(t,e,r=!1){let n=xo.sign(t,e);if(r&&!PE(n)){let i=new Uint8Array(32),o=0;for(;!PE(n);)if(i.set(Ie.encode(o++)),n=xo.sign(t,e,{extraEntropy:i}),o>4294967295)throw new Error("lowR counter overflow: report the error")}return n.toDERRawBytes()}var Zy=Ur.sign,ku=Ur.utils.taggedHash,vt;(function(t){t[t.ecdsa=0]="ecdsa",t[t.schnorr=1]="schnorr"})(vt||(vt={}));function vo(t,e){let r=t.length;if(e===vt.ecdsa){if(r===32)throw new Error("Expected non-Schnorr key");return nl.fromHex(t),t}else if(e===vt.schnorr){if(r!==32)throw new Error("Expected 32-byte Schnorr key");return Ur.utils.lift_x(Ur.utils.bytesToNumberBE(t)),t}else throw new Error("Unknown key type")}function KE(t,e){let r=Ur.utils,n=r.taggedHash("TapTweak",t,e),i=r.bytesToNumberBE(n);if(i>=rl)throw new Error("tweak higher than curve order");return i}function $E(t,e=Uint8Array.of()){let r=Ur.utils,n=r.bytesToNumberBE(t),i=nl.fromPrivateKey(n),o=i.hasEvenY()?n:r.mod(-n,rl),s=r.pointToBytes(i),c=KE(s,e);return r.numberToBytesBE(r.mod(o+c,rl),32)}function Nu(t,e){let r=Ur.utils,n=KE(t,e),o=r.lift_x(r.bytesToNumberBE(t)).add(nl.fromPrivateKey(n)),s=o.hasEvenY()?0:1;return[r.pointToBytes(o),s]}var ol=ke(nl.BASE.toRawBytes(!1)),Yr={bech32:"bc",pubKeyHash:0,scriptHash:5,wif:128},Qy={bech32:"tb",pubKeyHash:111,scriptHash:196,wif:239};function Cu(t,e){if(!Ce(t)||!Ce(e))throw new Error(`cmp: wrong type a=${typeof t} b=${typeof e}`);let r=Math.min(t.length,e.length);for(let n=0;n<r;n++)if(t[n]!=e[n])return Math.sign(t[n]-e[n]);return Math.sign(t.length-e.length)}l();l();l();var bt;(function(t){t[t.OP_0=0]="OP_0",t[t.PUSHDATA1=76]="PUSHDATA1",t[t.PUSHDATA2=77]="PUSHDATA2",t[t.PUSHDATA4=78]="PUSHDATA4",t[t["1NEGATE"]=79]="1NEGATE",t[t.RESERVED=80]="RESERVED",t[t.OP_1=81]="OP_1",t[t.OP_2=82]="OP_2",t[t.OP_3=83]="OP_3",t[t.OP_4=84]="OP_4",t[t.OP_5=85]="OP_5",t[t.OP_6=86]="OP_6",t[t.OP_7=87]="OP_7",t[t.OP_8=88]="OP_8",t[t.OP_9=89]="OP_9",t[t.OP_10=90]="OP_10",t[t.OP_11=91]="OP_11",t[t.OP_12=92]="OP_12",t[t.OP_13=93]="OP_13",t[t.OP_14=94]="OP_14",t[t.OP_15=95]="OP_15",t[t.OP_16=96]="OP_16",t[t.NOP=97]="NOP",t[t.VER=98]="VER",t[t.IF=99]="IF",t[t.NOTIF=100]="NOTIF",t[t.VERIF=101]="VERIF",t[t.VERNOTIF=102]="VERNOTIF",t[t.ELSE=103]="ELSE",t[t.ENDIF=104]="ENDIF",t[t.VERIFY=105]="VERIFY",t[t.RETURN=106]="RETURN",t[t.TOALTSTACK=107]="TOALTSTACK",t[t.FROMALTSTACK=108]="FROMALTSTACK",t[t["2DROP"]=109]="2DROP",t[t["2DUP"]=110]="2DUP",t[t["3DUP"]=111]="3DUP",t[t["2OVER"]=112]="2OVER",t[t["2ROT"]=113]="2ROT",t[t["2SWAP"]=114]="2SWAP",t[t.IFDUP=115]="IFDUP",t[t.DEPTH=116]="DEPTH",t[t.DROP=117]="DROP",t[t.DUP=118]="DUP",t[t.NIP=119]="NIP",t[t.OVER=120]="OVER",t[t.PICK=121]="PICK",t[t.ROLL=122]="ROLL",t[t.ROT=123]="ROT",t[t.SWAP=124]="SWAP",t[t.TUCK=125]="TUCK",t[t.CAT=126]="CAT",t[t.SUBSTR=127]="SUBSTR",t[t.LEFT=128]="LEFT",t[t.RIGHT=129]="RIGHT",t[t.SIZE=130]="SIZE",t[t.INVERT=131]="INVERT",t[t.AND=132]="AND",t[t.OR=133]="OR",t[t.XOR=134]="XOR",t[t.EQUAL=135]="EQUAL",t[t.EQUALVERIFY=136]="EQUALVERIFY",t[t.RESERVED1=137]="RESERVED1",t[t.RESERVED2=138]="RESERVED2",t[t["1ADD"]=139]="1ADD",t[t["1SUB"]=140]="1SUB",t[t["2MUL"]=141]="2MUL",t[t["2DIV"]=142]="2DIV",t[t.NEGATE=143]="NEGATE",t[t.ABS=144]="ABS",t[t.NOT=145]="NOT",t[t["0NOTEQUAL"]=146]="0NOTEQUAL",t[t.ADD=147]="ADD",t[t.SUB=148]="SUB",t[t.MUL=149]="MUL",t[t.DIV=150]="DIV",t[t.MOD=151]="MOD",t[t.LSHIFT=152]="LSHIFT",t[t.RSHIFT=153]="RSHIFT",t[t.BOOLAND=154]="BOOLAND",t[t.BOOLOR=155]="BOOLOR",t[t.NUMEQUAL=156]="NUMEQUAL",t[t.NUMEQUALVERIFY=157]="NUMEQUALVERIFY",t[t.NUMNOTEQUAL=158]="NUMNOTEQUAL",t[t.LESSTHAN=159]="LESSTHAN",t[t.GREATERTHAN=160]="GREATERTHAN",t[t.LESSTHANOREQUAL=161]="LESSTHANOREQUAL",t[t.GREATERTHANOREQUAL=162]="GREATERTHANOREQUAL",t[t.MIN=163]="MIN",t[t.MAX=164]="MAX",t[t.WITHIN=165]="WITHIN",t[t.RIPEMD160=166]="RIPEMD160",t[t.SHA1=167]="SHA1",t[t.SHA256=168]="SHA256",t[t.HASH160=169]="HASH160",t[t.HASH256=170]="HASH256",t[t.CODESEPARATOR=171]="CODESEPARATOR",t[t.CHECKSIG=172]="CHECKSIG",t[t.CHECKSIGVERIFY=173]="CHECKSIGVERIFY",t[t.CHECKMULTISIG=174]="CHECKMULTISIG",t[t.CHECKMULTISIGVERIFY=175]="CHECKMULTISIGVERIFY",t[t.NOP1=176]="NOP1",t[t.CHECKLOCKTIMEVERIFY=177]="CHECKLOCKTIMEVERIFY",t[t.CHECKSEQUENCEVERIFY=178]="CHECKSEQUENCEVERIFY",t[t.NOP4=179]="NOP4",t[t.NOP5=180]="NOP5",t[t.NOP6=181]="NOP6",t[t.NOP7=182]="NOP7",t[t.NOP8=183]="NOP8",t[t.NOP9=184]="NOP9",t[t.NOP10=185]="NOP10",t[t.CHECKSIGADD=186]="CHECKSIGADD",t[t.INVALID=255]="INVALID"})(bt||(bt={}));function e0(t=6,e=!1){return Wt({encodeStream:(r,n)=>{if(n===0n)return;let i=n<0,o=BigInt(n),s=[];for(let c=i?-o:o;c;c>>=8n)s.push(Number(c&0xffn));s[s.length-1]>=128?s.push(i?128:0):i&&(s[s.length-1]|=128),r.bytes(new Uint8Array(s))},decodeStream:r=>{let n=r.leftBytes;if(n>t)throw new Error(`ScriptNum: number (${n}) bigger than limit=${t}`);if(n===0)return 0n;if(e){let s=r.bytes(n,!0);if(!(s[s.length-1]&127)&&(n<=1||!(s[s.length-2]&128)))throw new Error("Non-minimally encoded ScriptNum")}let i=0,o=0n;for(let s=0;s<n;++s)i=r.byte(),o|=BigInt(i)<<8n*BigInt(s);return i>=128&&(o&=2n**BigInt(n*8)-1n>>1n,o=-o),o}})}function qE(t,e=4,r=!0){if(typeof t=="number")return t;if(Ce(t))try{let n=e0(e,r).decode(t);return n>Number.MAX_SAFE_INTEGER?void 0:Number(n)}catch{return}}var Ze=Wt({encodeStream:(t,e)=>{for(let r of e){if(typeof r=="string"){if(bt[r]===void 0)throw new Error(`Unknown opcode=${r}`);t.byte(bt[r]);continue}else if(typeof r=="number"){if(r===0){t.byte(0);continue}else if(1<=r&&r<=16){t.byte(bt.OP_1-1+r);continue}}if(typeof r=="number"&&(r=e0().encode(BigInt(r))),!Ce(r))throw new Error(`Wrong Script OP=${r} (${typeof r})`);let n=r.length;n<bt.PUSHDATA1?t.byte(n):n<=255?(t.byte(bt.PUSHDATA1),t.byte(n)):n<=65535?(t.byte(bt.PUSHDATA2),t.bytes(Jy.encode(n))):(t.byte(bt.PUSHDATA4),t.bytes(Ie.encode(n))),t.bytes(r)}},decodeStream:t=>{let e=[];for(;!t.isEnd();){let r=t.byte();if(bt.OP_0<r&&r<=bt.PUSHDATA4){let n;if(r<bt.PUSHDATA1)n=r;else if(r===bt.PUSHDATA1)n=mn.decodeStream(t);else if(r===bt.PUSHDATA2)n=Jy.decodeStream(t);else if(r===bt.PUSHDATA4)n=Ie.decodeStream(t);else throw new Error("Should be not possible");e.push(t.bytes(n))}else if(r===0)e.push(0);else if(bt.OP_1<=r&&r<=bt.OP_16)e.push(r-(bt.OP_1-1));else{let n=bt[r];if(n===void 0)throw new Error(`Unknown opcode=${r.toString(16)}`);e.push(n)}}return e}}),VE={253:[253,2,253n,65535n],254:[254,4,65536n,4294967295n],255:[255,8,4294967296n,18446744073709551615n]},zc=Wt({encodeStream:(t,e)=>{if(typeof e=="number"&&(e=BigInt(e)),0n<=e&&e<=252n)return t.byte(Number(e));for(let[r,n,i,o]of Object.values(VE))if(!(i>e||e>o)){t.byte(r);for(let s=0;s<n;s++)t.byte(Number(e>>8n*BigInt(s)&0xffn));return}throw t.err(`VarInt too big: ${e}`)},decodeStream:t=>{let e=t.byte();if(e<=252)return BigInt(e);let[r,n,i]=VE[e],o=0n;for(let s=0;s<n;s++)o|=BigInt(t.byte())<<8n*BigInt(s);if(o<i)throw t.err(`Wrong CompactSize(${8*n})`);return o}}),Dr=gn(zc,Bi.numberBigint),lr=Fe(zc),Yc=Gt(Dr,lr),sl=t=>Gt(zc,t),FE=Et({txid:Fe(32,!0),index:Ie,finalScriptSig:lr,sequence:Ie}),Ui=Et({amount:Wc,script:lr}),M8=Et({version:Eo,segwitFlag:kE(new Uint8Array([0,1])),inputs:sl(FE),outputs:sl(Ui),witnesses:NE("segwitFlag",Gt("inputs/length",Yc)),lockTime:Ie});function K8(t){if(t.segwitFlag&&t.witnesses&&!t.witnesses.length)throw new Error("Segwit flag with empty witnesses array");return t}var Oi=jt(M8,K8),As=Et({version:Eo,inputs:sl(FE),outputs:sl(Ui),lockTime:Ie});var r0=jt(Fe(null),t=>vo(t,vt.ecdsa)),cl=jt(Fe(32),t=>vo(t,vt.schnorr)),jE=jt(Fe(null),t=>{if(t.length!==64&&t.length!==65)throw new Error("Schnorr signature should be 64 or 65 bytes long");return t}),al=Et({fingerprint:UE,path:Gt(null,Ie)}),zE=Et({hashes:Gt(Dr,Fe(32)),der:al}),$8=Fe(78),H8=Et({pubKey:cl,leafHash:Fe(32)}),V8=Et({version:mn,internalKey:Fe(32),merklePath:Gt(null,Fe(32))}),Di=jt(V8,t=>{if(t.merklePath.length>128)throw new Error("TaprootControlBlock: merklePath should be of length 0..128 (inclusive)");return t}),q8=Gt(null,Et({depth:mn,version:mn,script:lr})),St=Fe(null),WE=Fe(20),Lu=Fe(32),ul={unsignedTx:[0,!1,As,[0],[0],!1],xpub:[1,$8,al,[],[0,2],!1],txVersion:[2,!1,Ie,[2],[2],!1],fallbackLocktime:[3,!1,Ie,[],[2],!1],inputCount:[4,!1,Dr,[2],[2],!1],outputCount:[5,!1,Dr,[2],[2],!1],txModifiable:[6,!1,mn,[],[2],!1],version:[251,!1,Ie,[],[0,2],!1],proprietary:[252,St,St,[],[0,2],!1]},Pu={nonWitnessUtxo:[0,!1,Oi,[],[0,2],!1],witnessUtxo:[1,!1,Ui,[],[0,2],!1],partialSig:[2,r0,St,[],[0,2],!1],sighashType:[3,!1,Ie,[],[0,2],!1],redeemScript:[4,!1,St,[],[0,2],!1],witnessScript:[5,!1,St,[],[0,2],!1],bip32Derivation:[6,r0,al,[],[0,2],!1],finalScriptSig:[7,!1,St,[],[0,2],!1],finalScriptWitness:[8,!1,Yc,[],[0,2],!1],porCommitment:[9,!1,St,[],[0,2],!1],ripemd160:[10,WE,St,[],[0,2],!1],sha256:[11,Lu,St,[],[0,2],!1],hash160:[12,WE,St,[],[0,2],!1],hash256:[13,Lu,St,[],[0,2],!1],txid:[14,!1,Lu,[2],[2],!0],index:[15,!1,Ie,[2],[2],!0],sequence:[16,!1,Ie,[],[2],!0],requiredTimeLocktime:[17,!1,Ie,[],[2],!1],requiredHeightLocktime:[18,!1,Ie,[],[2],!1],tapKeySig:[19,!1,jE,[],[0,2],!1],tapScriptSig:[20,H8,jE,[],[0,2],!1],tapLeafScript:[21,Di,St,[],[0,2],!1],tapBip32Derivation:[22,Lu,zE,[],[0,2],!1],tapInternalKey:[23,!1,cl,[],[0,2],!1],tapMerkleRoot:[24,!1,Lu,[],[0,2],!1],proprietary:[252,St,St,[],[0,2],!1]},YE=["txid","sequence","index","witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknown"],JE=["partialSig","finalScriptSig","finalScriptWitness","tapKeySig","tapScriptSig"],Mu={redeemScript:[0,!1,St,[],[0,2],!1],witnessScript:[1,!1,St,[],[0,2],!1],bip32Derivation:[2,r0,al,[],[0,2],!1],amount:[3,!1,RE,[2],[2],!0],script:[4,!1,St,[2],[2],!0],tapInternalKey:[5,!1,cl,[],[0,2],!1],tapTree:[6,!1,q8,[],[0,2],!1],tapBip32Derivation:[7,cl,zE,[],[0,2],!1],proprietary:[252,St,St,[],[0,2],!1]},XE=[],GE=Gt(Gy,Et({key:OE(Dr,Et({type:Dr,key:Fe(null)})),value:Fe(Dr)}));function n0(t){let[e,r,n,i,o,s]=t;return{type:e,kc:r,vc:n,reqInc:i,allowInc:o,silentIgnore:s}}var yM=Et({type:Dr,key:Fe(null)});function i0(t){let e={};for(let r in t){let[n,i,o]=t[r];e[n]=[r,i,o]}return Wt({encodeStream:(r,n)=>{let i=[];for(let o in t){let s=n[o];if(s===void 0)continue;let[c,a,u]=t[o];if(!a)i.push({key:{type:c,key:Ve},value:u.encode(s)});else{let d=s.map(([f,h])=>[a.encode(f),u.encode(h)]);d.sort((f,h)=>Cu(f[0],h[0]));for(let[f,h]of d)i.push({key:{key:f,type:c},value:h})}}if(n.unknown){n.unknown.sort((o,s)=>Cu(o[0].key,s[0].key));for(let[o,s]of n.unknown)i.push({key:o,value:s})}GE.encodeStream(r,i)},decodeStream:r=>{let n=GE.decodeStream(r),i={},o={};for(let s of n){let c="unknown",a=s.key.key,u=s.value;if(e[s.key.type]){let[d,f,h]=e[s.key.type];if(c=d,!f&&a.length)throw new Error(`PSBT: Non-empty key for ${c} (key=${xe.encode(a)} value=${xe.encode(u)}`);if(a=f?f.decode(a):void 0,u=h.decode(u),!f){if(i[c])throw new Error(`PSBT: Same keys: ${c} (key=${a} value=${u})`);i[c]=u,o[c]=!0;continue}}else a={type:s.key.type,key:s.key.key};if(o[c])throw new Error(`PSBT: Key type with empty key and no key=${c} val=${u}`);i[c]||(i[c]=[]),i[c].push([a,u])}return i}})}var dl=jt(i0(Pu),t=>{if(t.finalScriptWitness&&!t.finalScriptWitness.length)throw new Error("validateInput: empty finalScriptWitness");if(t.partialSig&&!t.partialSig.length)throw new Error("Empty partialSig");if(t.partialSig)for(let[e]of t.partialSig)vo(e,vt.ecdsa);if(t.bip32Derivation)for(let[e]of t.bip32Derivation)vo(e,vt.ecdsa);if(t.requiredTimeLocktime!==void 0&&t.requiredTimeLocktime<5e8)throw new Error(`validateInput: wrong timeLocktime=${t.requiredTimeLocktime}`);if(t.requiredHeightLocktime!==void 0&&(t.requiredHeightLocktime<=0||t.requiredHeightLocktime>=5e8))throw new Error(`validateInput: wrong heighLocktime=${t.requiredHeightLocktime}`);if(t.tapLeafScript)for(let[e,r]of t.tapLeafScript){if((e.version&254)!==r[r.length-1])throw new Error("validateInput: tapLeafScript version mimatch");if(r[r.length-1]&1)throw new Error("validateInput: tapLeafScript version has parity bit!")}return t}),fl=jt(i0(Mu),t=>{if(t.bip32Derivation)for(let[e]of t.bip32Derivation)vo(e,vt.ecdsa);return t}),ZE=jt(i0(ul),t=>{if((t.version||0)===0){if(!t.unsignedTx)throw new Error("PSBTv0: missing unsignedTx");for(let r of t.unsignedTx.inputs)if(r.finalScriptSig&&r.finalScriptSig.length)throw new Error("PSBTv0: input scriptSig found in unsignedTx")}return t}),F8=Et({magic:el(Qf(new Uint8Array([255])),"psbt"),global:ZE,inputs:Gt("global/unsignedTx/inputs/length",dl),outputs:Gt(null,fl)}),j8=Et({magic:el(Qf(new Uint8Array([255])),"psbt"),global:ZE,inputs:Gt("global/inputCount",dl),outputs:Gt("global/outputCount",fl)}),gM=Et({magic:el(Qf(new Uint8Array([255])),"psbt"),items:Gt(null,gn(Gt(Gy,LE([DE(Dr),Fe(zc)])),Bi.dict()))});function t0(t,e,r){for(let n in r){if(n==="unknown"||!e[n])continue;let{allowInc:i}=n0(e[n]);if(!i.includes(t))throw new Error(`PSBTv${t}: field ${n} is not allowed`)}for(let n in e){let{reqInc:i}=n0(e[n]);if(i.includes(t)&&r[n]===void 0)throw new Error(`PSBTv${t}: missing required field ${n}`)}}function o0(t,e,r){let n={};for(let i in r){let o=i;if(o!=="unknown"){if(!e[o])continue;let{allowInc:s,silentIgnore:c}=n0(e[o]);if(!s.includes(t)){if(c)continue;throw new Error(`Failed to serialize in PSBTv${t}: ${o} but versions allows inclusion=${s}`)}}n[o]=r[o]}return n}function QE(t){let e=t&&t.global&&t.global.version||0;t0(e,ul,t.global);for(let s of t.inputs)t0(e,Pu,s);for(let s of t.outputs)t0(e,Mu,s);let r=e?t.global.inputCount:t.global.unsignedTx.inputs.length;if(t.inputs.length<r)throw new Error("Not enough inputs");let n=t.inputs.slice(r);if(n.length>1||n.length&&Object.keys(n[0]).length)throw new Error(`Unexpected inputs left in tx=${n}`);let i=e?t.global.outputCount:t.global.unsignedTx.outputs.length;if(t.outputs.length<i)throw new Error("Not outputs inputs");let o=t.outputs.slice(i);if(o.length>1||o.length&&Object.keys(o[0]).length)throw new Error(`Unexpected outputs left in tx=${o}`);return t}function ll(t,e,r,n,i){let o={...r,...e};for(let s in t){let c=s,[a,u,d]=t[c],f=n&&!n.includes(s);if(e[s]===void 0&&s in e){if(f)throw new Error(`Cannot remove signed field=${s}`);delete o[s]}else if(u){let h=r&&r[s]?r[s]:[],p=e[c];if(p){if(!Array.isArray(p))throw new Error(`keyMap(${s}): KV pairs should be [k, v][]`);p=p.map(x=>{if(x.length!==2)throw new Error(`keyMap(${s}): KV pairs should be [k, v][]`);return[typeof x[0]=="string"?u.decode(xe.decode(x[0])):x[0],typeof x[1]=="string"?d.decode(xe.decode(x[1])):x[1]]});let g={},y=(x,S,_)=>{if(g[x]===void 0){g[x]=[S,_];return}let A=xe.encode(d.encode(g[x][1])),O=xe.encode(d.encode(_));if(A!==O)throw new Error(`keyMap(${c}): same key=${x} oldVal=${A} newVal=${O}`)};for(let[x,S]of h){let _=xe.encode(u.encode(x));y(_,x,S)}for(let[x,S]of p){let _=xe.encode(u.encode(x));if(S===void 0){if(f)throw new Error(`Cannot remove signed field=${c}/${x}`);delete g[_]}else y(_,x,S)}o[c]=Object.values(g)}}else if(typeof o[s]=="string")o[s]=d.decode(xe.decode(o[s]));else if(f&&s in e&&r&&r[s]!==void 0&&!st(d.encode(e[s]),d.encode(r[s])))throw new Error(`Cannot change signed field=${s}`)}for(let s in o)if(!t[s]){if(i&&s==="unknown")continue;delete o[s]}return o}var s0=jt(F8,QE),c0=jt(j8,QE);var G8={encode(t){if(!(t.length!==2||t[0]!==1||!Ce(t[1])||xe.encode(t[1])!=="4e73"))return{type:"p2a",script:Ze.encode(t)}},decode:t=>{if(t.type==="p2a")return[1,xe.decode("4e73")]}};function So(t,e){try{return vo(t,e),!0}catch{return!1}}var z8={encode(t){if(!(t.length!==2||!Ce(t[0])||!So(t[0],vt.ecdsa)||t[1]!=="CHECKSIG"))return{type:"pk",pubkey:t[0]}},decode:t=>t.type==="pk"?[t.pubkey,"CHECKSIG"]:void 0},Y8={encode(t){if(!(t.length!==5||t[0]!=="DUP"||t[1]!=="HASH160"||!Ce(t[2]))&&!(t[3]!=="EQUALVERIFY"||t[4]!=="CHECKSIG"))return{type:"pkh",hash:t[2]}},decode:t=>t.type==="pkh"?["DUP","HASH160",t.hash,"EQUALVERIFY","CHECKSIG"]:void 0},J8={encode(t){if(!(t.length!==3||t[0]!=="HASH160"||!Ce(t[1])||t[2]!=="EQUAL"))return{type:"sh",hash:t[1]}},decode:t=>t.type==="sh"?["HASH160",t.hash,"EQUAL"]:void 0},X8={encode(t){if(!(t.length!==2||t[0]!==0||!Ce(t[1]))&&t[1].length===32)return{type:"wsh",hash:t[1]}},decode:t=>t.type==="wsh"?[0,t.hash]:void 0},Z8={encode(t){if(!(t.length!==2||t[0]!==0||!Ce(t[1]))&&t[1].length===20)return{type:"wpkh",hash:t[1]}},decode:t=>t.type==="wpkh"?[0,t.hash]:void 0},Q8={encode(t){let e=t.length-1;if(t[e]!=="CHECKMULTISIG")return;let r=t[0],n=t[e-1];if(typeof r!="number"||typeof n!="number")return;let i=t.slice(1,-2);if(n===i.length){for(let o of i)if(!Ce(o))return;return{type:"ms",m:r,pubkeys:i}}},decode:t=>t.type==="ms"?[t.m,...t.pubkeys,t.pubkeys.length,"CHECKMULTISIG"]:void 0},eR={encode(t){if(!(t.length!==2||t[0]!==1||!Ce(t[1])))return{type:"tr",pubkey:t[1]}},decode:t=>t.type==="tr"?[1,t.pubkey]:void 0},tR={encode(t){let e=t.length-1;if(t[e]!=="CHECKSIG")return;let r=[];for(let n=0;n<e;n++){let i=t[n];if(n&1){if(i!=="CHECKSIGVERIFY"||n===e-1)return;continue}if(!Ce(i))return;r.push(i)}return{type:"tr_ns",pubkeys:r}},decode:t=>{if(t.type!=="tr_ns")return;let e=[];for(let r=0;r<t.pubkeys.length-1;r++)e.push(t.pubkeys[r],"CHECKSIGVERIFY");return e.push(t.pubkeys[t.pubkeys.length-1],"CHECKSIG"),e}},rR={encode(t){let e=t.length-1;if(t[e]!=="NUMEQUAL"||t[1]!=="CHECKSIG")return;let r=[],n=qE(t[e-1]);if(typeof n=="number"){for(let i=0;i<e-1;i++){let o=t[i];if(i&1){if(o!==(i===1?"CHECKSIG":"CHECKSIGADD"))throw new Error("OutScript.encode/tr_ms: wrong element");continue}if(!Ce(o))throw new Error("OutScript.encode/tr_ms: wrong key element");r.push(o)}return{type:"tr_ms",pubkeys:r,m:n}}},decode:t=>{if(t.type!=="tr_ms")return;let e=[t.pubkeys[0],"CHECKSIG"];for(let r=1;r<t.pubkeys.length;r++)e.push(t.pubkeys[r],"CHECKSIGADD");return e.push(t.m,"NUMEQUAL"),e}},nR={encode(t){return{type:"unknown",script:Ze.encode(t)}},decode:t=>t.type==="unknown"?Ze.decode(t.script):void 0},iR=[G8,z8,Y8,J8,X8,Z8,Q8,eR,tR,rR,nR],oR=gn(Ze,Bi.match(iR)),Qe=jt(oR,t=>{if(t.type==="pk"&&!So(t.pubkey,vt.ecdsa))throw new Error("OutScript/pk: wrong key");if((t.type==="pkh"||t.type==="sh"||t.type==="wpkh")&&(!Ce(t.hash)||t.hash.length!==20))throw new Error(`OutScript/${t.type}: wrong hash`);if(t.type==="wsh"&&(!Ce(t.hash)||t.hash.length!==32))throw new Error("OutScript/wsh: wrong hash");if(t.type==="tr"&&(!Ce(t.pubkey)||!So(t.pubkey,vt.schnorr)))throw new Error("OutScript/tr: wrong taproot public key");if((t.type==="ms"||t.type==="tr_ns"||t.type==="tr_ms")&&!Array.isArray(t.pubkeys))throw new Error("OutScript/multisig: wrong pubkeys array");if(t.type==="ms"){let e=t.pubkeys.length;for(let r of t.pubkeys)if(!So(r,vt.ecdsa))throw new Error("OutScript/multisig: wrong pubkey");if(t.m<=0||e>16||t.m>e)throw new Error("OutScript/multisig: invalid params")}if(t.type==="tr_ns"||t.type==="tr_ms"){for(let e of t.pubkeys)if(!So(e,vt.schnorr))throw new Error(`OutScript/${t.type}: wrong pubkey`)}if(t.type==="tr_ms"){let e=t.pubkeys.length;if(t.m<=0||e>999||t.m>e)throw new Error("OutScript/tr_ms: invalid params")}return t});function ev(t,e){if(!st(t.hash,ke(e)))throw new Error("checkScript: wsh wrong witnessScript hash");let r=Qe.decode(e);if(r.type==="tr"||r.type==="tr_ns"||r.type==="tr_ms")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2SH`);if(r.type==="wpkh"||r.type==="sh")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2WSH`)}function h0(t,e,r){if(t){let n=Qe.decode(t);if(n.type==="tr_ns"||n.type==="tr_ms"||n.type==="ms"||n.type=="pk")throw new Error(`checkScript: non-wrapped ${n.type}`);if(n.type==="sh"&&e){if(!st(n.hash,Gc(e)))throw new Error("checkScript: sh wrong redeemScript hash");let i=Qe.decode(e);if(i.type==="tr"||i.type==="tr_ns"||i.type==="tr_ms")throw new Error(`checkScript: P2${i.type} cannot be wrapped in P2SH`);if(i.type==="sh")throw new Error("checkScript: P2SH cannot be wrapped in P2SH")}n.type==="wsh"&&r&&ev(n,r)}if(e){let n=Qe.decode(e);n.type==="wsh"&&r&&ev(n,r)}}var ki=(t,e=Yr)=>{if(!So(t,vt.ecdsa))throw new Error("P2PKH: invalid publicKey");let r=Gc(t);return{type:"pkh",script:Qe.encode({type:"pkh",hash:r}),address:Jr(e).encode({type:"pkh",hash:r}),hash:r}};var Ts=(t,e=Yr)=>{if(!So(t,vt.ecdsa))throw new Error("P2WPKH: invalid publicKey");if(t.length===65)throw new Error("P2WPKH: uncompressed public key");let r=Gc(t);return{type:"wpkh",script:Qe.encode({type:"wpkh",hash:r}),address:Jr(e).encode({type:"wpkh",hash:r}),hash:r}};function sR(t,e,r=!1,n){let i=Qe.decode(t);if(i.type==="unknown"){if(n){let c=gn(Ze,Bi.match(n)).decode(t);if(c!==void 0){if(typeof c.type!="string"||!c.type.startsWith("tr_"))throw new Error(`P2TR: invalid custom type=${c.type}`);return}}if(r)return}if(!["tr_ns","tr_ms"].includes(i.type))throw new Error(`P2TR: invalid leaf script=${i.type}`);let o=i;if(!r&&o.pubkeys)for(let s of o.pubkeys){if(st(s,ol))throw new Error("Unspendable taproot key in leaf script");if(st(s,e))throw new Error("Using P2TR with leaf script with same key as internal key is not supported")}}function rv(t){let e=Array.from(t);for(;e.length>=2;){e.sort((s,c)=>(c.weight||1)-(s.weight||1));let n=e.pop(),i=e.pop(),o=(i?.weight||1)+(n?.weight||1);e.push({weight:o,childs:[i?.childs||i,n?.childs||n]})}let r=e[0];return r?.childs||r}function u0(t,e=[]){if(!t)throw new Error("taprootAddPath: empty tree");if(t.type==="leaf")return{...t,path:e};if(t.type!=="branch")throw new Error(`taprootAddPath: wrong type=${t}`);return{...t,path:e,left:u0(t.left,[t.right.hash,...e]),right:u0(t.right,[t.left.hash,...e])}}function d0(t){if(!t)throw new Error("taprootAddPath: empty tree");if(t.type==="leaf")return[t];if(t.type!=="branch")throw new Error(`taprootWalkTree: wrong type=${t}`);return[...d0(t.left),...d0(t.right)]}function f0(t,e,r=!1,n){if(!t)throw new Error("taprootHashTree: empty tree");if(Array.isArray(t)&&t.length===1&&(t=t[0]),!Array.isArray(t)){let{leafVersion:a,script:u}=t;if(t.tapLeafScript||t.tapMerkleRoot&&!st(t.tapMerkleRoot,Ve))throw new Error("P2TR: tapRoot leafScript cannot have tree");let d=typeof u=="string"?xe.decode(u):u;if(!Ce(d))throw new Error(`checkScript: wrong script type=${d}`);return sR(d,e,r,n),{type:"leaf",version:a,script:d,hash:Ku(d,a)}}if(t.length!==2&&(t=rv(t)),t.length!==2)throw new Error("hashTree: non binary tree!");let i=f0(t[0],e,r,n),o=f0(t[1],e,r,n),[s,c]=[i.hash,o.hash];return Cu(c,s)===-1&&([s,c]=[c,s]),{type:"branch",left:i,right:o,hash:ku("TapBranch",s,c)}}var l0=192,Ku=(t,e=l0)=>ku("TapLeaf",new Uint8Array([e]),lr.encode(t));function _s(t,e,r=Yr,n=!1,i){if(!t&&!e)throw new Error("p2tr: should have pubKey or scriptTree (or both)");let o=typeof t=="string"?xe.decode(t):t||ol;if(!So(o,vt.schnorr))throw new Error("p2tr: non-schnorr pubkey");if(e){let s=u0(f0(e,o,n,i)),c=s.hash,[a,u]=Nu(o,c),d=d0(s).map(f=>({...f,controlBlock:Di.encode({version:(f.version||l0)+u,internalKey:o,merklePath:f.path})}));return{type:"tr",script:Qe.encode({type:"tr",pubkey:a}),address:Jr(r).encode({type:"tr",pubkey:a}),tweakedPubkey:a,tapInternalKey:o,leaves:d,tapLeafScript:d.map(f=>[Di.decode(f.controlBlock),jn(f.script,new Uint8Array([f.version||l0]))]),tapMerkleRoot:c}}else{let s=Nu(o,Ve)[0];return{type:"tr",script:Qe.encode({type:"tr",pubkey:s}),address:Jr(r).encode({type:"tr",pubkey:s}),tweakedPubkey:s,tapInternalKey:o}}}var nv=EE(ke);function iv(t,e){if(e.length<2||e.length>40)throw new Error("Witness: invalid length");if(t>16)throw new Error("Witness: invalid version");if(t===0&&!(e.length===20||e.length===32))throw new Error("Witness: invalid length for version")}function a0(t,e,r=Yr){iv(t,e);let n=t===0?Jf:Ss;return n.encode(r.bech32,[t].concat(n.toWords(e)))}function tv(t,e){return nv.encode(jn(Uint8Array.from(e),t))}function Jr(t=Yr){return{encode(e){let{type:r}=e;if(r==="wpkh")return a0(0,e.hash,t);if(r==="wsh")return a0(0,e.hash,t);if(r==="tr")return a0(1,e.pubkey,t);if(r==="pkh")return tv(e.hash,[t.pubKeyHash]);if(r==="sh")return tv(e.hash,[t.scriptHash]);throw new Error(`Unknown address type=${r}`)},decode(e){if(e.length<14||e.length>74)throw new Error("Invalid address length");if(t.bech32&&e.toLowerCase().startsWith(`${t.bech32}1`)){let n;try{if(n=Jf.decode(e),n.words[0]!==0)throw new Error(`bech32: wrong version=${n.words[0]}`)}catch{if(n=Ss.decode(e),n.words[0]===0)throw new Error(`bech32m: wrong version=${n.words[0]}`)}if(n.prefix!==t.bech32)throw new Error(`wrong bech32 prefix=${n.prefix}`);let[i,...o]=n.words,s=Jf.fromWords(o);if(iv(i,s),i===0&&s.length===32)return{type:"wsh",hash:s};if(i===0&&s.length===20)return{type:"wpkh",hash:s};if(i===1&&s.length===32)return{type:"tr",pubkey:s};throw new Error("Unknown witness program")}let r=nv.decode(e);if(r.length!==21)throw new Error("Invalid base58 address");if(r[0]===t.pubKeyHash)return{type:"pkh",hash:r.slice(1)};if(r[0]===t.scriptHash)return{type:"sh",hash:r.slice(1)};throw new Error(`Invalid address prefix=${r[0]}`)}}}l();var hl=new Uint8Array(32),cR={amount:0xffffffffffffffffn,script:Ve},aR=t=>Math.ceil(t/4),uR=8,dR=2,Is=0,m0=4294967295,fR=Bi.decimal(uR),Hu=(t,e)=>t===void 0?e:t;function yl(t){if(Array.isArray(t))return t.map(e=>yl(e));if(Ce(t))return Uint8Array.from(t);if(["number","bigint","boolean","string","undefined"].includes(typeof t))return t;if(t===null)return t;if(typeof t=="object")return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,yl(r)]));throw new Error(`cloneDeep: unknown type=${t} (${typeof t})`)}var je;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.ANYONECANPAY=128]="ANYONECANPAY"})(je||(je={}));var Ao;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.DEFAULT_ANYONECANPAY=128]="DEFAULT_ANYONECANPAY",t[t.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",t[t.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",t[t.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY"})(Ao||(Ao={}));function lR(t,e,r,n=Ve){return st(r,e)&&(t=$E(t,n),e=il(t)),{privKey:t,pubKey:e}}function Bs(t){if(t.script===void 0||t.amount===void 0)throw new Error("Transaction/output: script and amount required");return{script:t.script,amount:t.amount}}function $u(t){if(t.txid===void 0||t.index===void 0)throw new Error("Transaction/input: txid and index required");return{txid:t.txid,index:t.index,sequence:Hu(t.sequence,m0),finalScriptSig:Hu(t.finalScriptSig,Ve)}}function p0(t){for(let e in t){let r=e;YE.includes(r)||delete t[r]}}var y0=Et({txid:Fe(32,!0),index:Ie});function hR(t){if(typeof t!="number"||typeof Ao[t]!="string")throw new Error(`Invalid SigHash=${t}`);return t}function ov(t){let e=t&31;return{isAny:!!(t&je.ANYONECANPAY),isNone:e===je.NONE,isSingle:e===je.SINGLE}}function pR(t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error(`Wrong object type for transaction options: ${t}`);let e={...t,version:Hu(t.version,dR),lockTime:Hu(t.lockTime,0),PSBTVersion:Hu(t.PSBTVersion,0)};if(typeof e.allowUnknowInput<"u"&&(t.allowUnknownInputs=e.allowUnknowInput),typeof e.allowUnknowOutput<"u"&&(t.allowUnknownOutputs=e.allowUnknowOutput),typeof e.lockTime!="number")throw new Error("Transaction lock time should be number");if(Ie.encode(e.lockTime),e.PSBTVersion!==0&&e.PSBTVersion!==2)throw new Error(`Unknown PSBT version ${e.PSBTVersion}`);for(let r of["allowUnknownVersion","allowUnknownOutputs","allowUnknownInputs","disableScriptCheck","bip174jsCompat","allowLegacyWitnessUtxo","lowR"]){let n=e[r];if(n!==void 0&&typeof n!="boolean")throw new Error(`Transation options wrong type: ${r}=${n} (${typeof n})`)}if(e.allowUnknownVersion?typeof e.version=="number":![-1,0,1,2,3].includes(e.version))throw new Error(`Unknown version: ${e.version}`);if(e.customScripts!==void 0){let r=e.customScripts;if(!Array.isArray(r))throw new Error(`wrong custom scripts type (expected array): customScripts=${r} (${typeof r})`);for(let n of r){if(typeof n.encode!="function"||typeof n.decode!="function")throw new Error(`wrong script=${n} (${typeof n})`);if(n.finalizeTaproot!==void 0&&typeof n.finalizeTaproot!="function")throw new Error(`wrong script=${n} (${typeof n})`)}}return Object.freeze(e)}function sv(t){if(t.nonWitnessUtxo&&t.index!==void 0){let e=t.nonWitnessUtxo.outputs.length-1;if(t.index>e)throw new Error(`validateInput: index(${t.index}) not in nonWitnessUtxo`);let r=t.nonWitnessUtxo.outputs[t.index];if(t.witnessUtxo&&(!st(t.witnessUtxo.script,r.script)||t.witnessUtxo.amount!==r.amount))throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo");if(t.txid){if(t.nonWitnessUtxo.outputs.length-1<t.index)throw new Error("nonWitnessUtxo: incorect output index");let i=Rs.fromRaw(Oi.encode(t.nonWitnessUtxo),{allowUnknownOutputs:!0,disableScriptCheck:!0,allowUnknownInputs:!0}),o=xe.encode(t.txid);if(i.isFinal&&i.id!==o)throw new Error(`nonWitnessUtxo: wrong txid, exp=${o} got=${i.id}`)}}return t}function pl(t){if(t.nonWitnessUtxo){if(t.index===void 0)throw new Error("Unknown input index");return t.nonWitnessUtxo.outputs[t.index]}else{if(t.witnessUtxo)return t.witnessUtxo;throw new Error("Cannot find previous output info")}}function cv(t,e,r,n=!1,i=!1){let{nonWitnessUtxo:o,txid:s}=t;typeof o=="string"&&(o=xe.decode(o)),Ce(o)&&(o=Oi.decode(o)),!("nonWitnessUtxo"in t)&&o===void 0&&(o=e?.nonWitnessUtxo),typeof s=="string"&&(s=xe.decode(s)),s===void 0&&(s=e?.txid);let c={...e,...t,nonWitnessUtxo:o,txid:s};!("nonWitnessUtxo"in t)&&c.nonWitnessUtxo===void 0&&delete c.nonWitnessUtxo,c.sequence===void 0&&(c.sequence=m0),c.tapMerkleRoot===null&&delete c.tapMerkleRoot,c=ll(Pu,c,e,r,i),dl.encode(c);let a;return c.nonWitnessUtxo&&c.index!==void 0?a=c.nonWitnessUtxo.outputs[c.index]:c.witnessUtxo&&(a=c.witnessUtxo),a&&!n&&h0(a&&a.script,c.redeemScript,c.witnessScript),c}function g0(t,e=!1){let r="legacy",n=je.ALL,i=pl(t),o=Qe.decode(i.script),s=o.type,c=o,a=[o];if(o.type==="tr")return n=je.DEFAULT,{txType:"taproot",type:"tr",last:o,lastScript:i.script,defaultSighash:n,sighash:t.sighashType||n};{if((o.type==="wpkh"||o.type==="wsh")&&(r="segwit"),o.type==="sh"){if(!t.redeemScript)throw new Error("inputType: sh without redeemScript");let h=Qe.decode(t.redeemScript);(h.type==="wpkh"||h.type==="wsh")&&(r="segwit"),a.push(h),c=h,s+=`-${h.type}`}if(c.type==="wsh"){if(!t.witnessScript)throw new Error("inputType: wsh without witnessScript");let h=Qe.decode(t.witnessScript);h.type==="wsh"&&(r="segwit"),a.push(h),c=h,s+=`-${h.type}`}let u=a[a.length-1];if(u.type==="sh"||u.type==="wsh")throw new Error("inputType: sh/wsh cannot be terminal type");let d=Qe.encode(u),f={type:s,txType:r,last:u,lastScript:d,defaultSighash:n,sighash:t.sighashType||n};if(r==="legacy"&&!e&&!t.nonWitnessUtxo)throw new Error("Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure");return f}}var Rs=class t{constructor(e={}){this.global={},this.inputs=[],this.outputs=[];let r=this.opts=pR(e);r.lockTime!==Is&&(this.global.fallbackLocktime=r.lockTime),this.global.txVersion=r.version}static fromRaw(e,r={}){let n=Oi.decode(e),i=new t({...r,version:n.version,lockTime:n.lockTime});for(let o of n.outputs)i.addOutput(o);if(i.outputs=n.outputs,i.inputs=n.inputs,n.witnesses)for(let o=0;o<n.witnesses.length;o++)i.inputs[o].finalScriptWitness=n.witnesses[o];return i}static fromPSBT(e,r={}){let n;try{n=s0.decode(e)}catch(f){try{n=c0.decode(e)}catch{throw f}}let i=n.global.version||0;if(i!==0&&i!==2)throw new Error(`Wrong PSBT version=${i}`);let o=n.global.unsignedTx,s=i===0?o?.version:n.global.txVersion,c=i===0?o?.lockTime:n.global.fallbackLocktime,a=new t({...r,version:s,lockTime:c,PSBTVersion:i}),u=i===0?o?.inputs.length:n.global.inputCount;a.inputs=n.inputs.slice(0,u).map((f,h)=>sv({finalScriptSig:Ve,...n.global.unsignedTx?.inputs[h],...f}));let d=i===0?o?.outputs.length:n.global.outputCount;return a.outputs=n.outputs.slice(0,d).map((f,h)=>({...f,...n.global.unsignedTx?.outputs[h]})),a.global={...n.global,txVersion:s},c!==Is&&(a.global.fallbackLocktime=c),a}toPSBT(e=this.opts.PSBTVersion){if(e!==0&&e!==2)throw new Error(`Wrong PSBT version=${e}`);let r=this.inputs.map(o=>sv(o0(e,Pu,o)));for(let o of r)o.partialSig&&!o.partialSig.length&&delete o.partialSig,o.finalScriptSig&&!o.finalScriptSig.length&&delete o.finalScriptSig,o.finalScriptWitness&&!o.finalScriptWitness.length&&delete o.finalScriptWitness;let n=this.outputs.map(o=>o0(e,Mu,o)),i={...this.global};return e===0?(i.unsignedTx=As.decode(As.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map($u).map(o=>({...o,finalScriptSig:Ve})),outputs:this.outputs.map(Bs)})),delete i.fallbackLocktime,delete i.txVersion):(i.version=e,i.txVersion=this.version,i.inputCount=this.inputs.length,i.outputCount=this.outputs.length,i.fallbackLocktime&&i.fallbackLocktime===Is&&delete i.fallbackLocktime),this.opts.bip174jsCompat&&(r.length||r.push({}),n.length||n.push({})),(e===0?s0:c0).encode({global:i,inputs:r,outputs:n})}get lockTime(){let e=Is,r=0,n=Is,i=0;for(let o of this.inputs)o.requiredHeightLocktime&&(e=Math.max(e,o.requiredHeightLocktime),r++),o.requiredTimeLocktime&&(n=Math.max(n,o.requiredTimeLocktime),i++);return r&&r>=i?e:n!==Is?n:this.global.fallbackLocktime||Is}get version(){if(this.global.txVersion===void 0)throw new Error("No global.txVersion");return this.global.txVersion}inputStatus(e){this.checkInputIdx(e);let r=this.inputs[e];return r.finalScriptSig&&r.finalScriptSig.length||r.finalScriptWitness&&r.finalScriptWitness.length?"finalized":r.tapKeySig||r.tapScriptSig&&r.tapScriptSig.length||r.partialSig&&r.partialSig.length?"signed":"unsigned"}inputSighash(e){this.checkInputIdx(e);let r=this.inputs[e].sighashType,n=r===void 0?je.DEFAULT:r,i=n===je.DEFAULT?je.ALL:n&3;return{sigInputs:n&je.ANYONECANPAY,sigOutputs:i}}signStatus(){let e=!0,r=!0,n=[],i=[];for(let o=0;o<this.inputs.length;o++){if(this.inputStatus(o)==="unsigned")continue;let{sigInputs:c,sigOutputs:a}=this.inputSighash(o);if(c===je.ANYONECANPAY?n.push(o):e=!1,a===je.ALL)r=!1;else if(a===je.SINGLE)i.push(o);else if(a!==je.NONE)throw new Error(`Wrong signature hash output type: ${a}`)}return{addInput:e,addOutput:r,inputs:n,outputs:i}}get isFinal(){for(let e=0;e<this.inputs.length;e++)if(this.inputStatus(e)!=="finalized")return!1;return!0}get hasWitnesses(){let e=!1;for(let r of this.inputs)r.finalScriptWitness&&r.finalScriptWitness.length&&(e=!0);return e}get weight(){if(!this.isFinal)throw new Error("Transaction is not finalized");let e=32,r=this.outputs.map(Bs);e+=4*Dr.encode(this.outputs.length).length;for(let n of r)e+=32+4*lr.encode(n.script).length;this.hasWitnesses&&(e+=2),e+=4*Dr.encode(this.inputs.length).length;for(let n of this.inputs)e+=160+4*lr.encode(n.finalScriptSig||Ve).length,this.hasWitnesses&&n.finalScriptWitness&&(e+=Yc.encode(n.finalScriptWitness).length);return e}get vsize(){return aR(this.weight)}toBytes(e=!1,r=!1){return Oi.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map($u).map(n=>({...n,finalScriptSig:e&&n.finalScriptSig||Ve})),outputs:this.outputs.map(Bs),witnesses:this.inputs.map(n=>n.finalScriptWitness||[]),segwitFlag:r&&this.hasWitnesses})}get unsignedTx(){return this.toBytes(!1,!1)}get hex(){return xe.encode(this.toBytes(!0,this.hasWitnesses))}get hash(){if(!this.isFinal)throw new Error("Transaction is not finalized");return xe.encode(Ri(this.toBytes(!0)))}get id(){if(!this.isFinal)throw new Error("Transaction is not finalized");return xe.encode(Ri(this.toBytes(!0)).reverse())}checkInputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.inputs.length)throw new Error(`Wrong input index=${e}`)}getInput(e){return this.checkInputIdx(e),yl(this.inputs[e])}get inputsLength(){return this.inputs.length}addInput(e,r=!1){if(!r&&!this.signStatus().addInput)throw new Error("Tx has signed inputs, cannot add new one");return this.inputs.push(cv(e,void 0,void 0,this.opts.disableScriptCheck)),this.inputs.length-1}updateInput(e,r,n=!1){this.checkInputIdx(e);let i;if(!n){let o=this.signStatus();(!o.addInput||o.inputs.includes(e))&&(i=JE)}this.inputs[e]=cv(r,this.inputs[e],i,this.opts.disableScriptCheck,this.opts.allowUnknown)}checkOutputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.outputs.length)throw new Error(`Wrong output index=${e}`)}getOutput(e){return this.checkOutputIdx(e),yl(this.outputs[e])}getOutputAddress(e,r=Yr){let n=this.getOutput(e);if(n.script)return Jr(r).encode(Qe.decode(n.script))}get outputsLength(){return this.outputs.length}normalizeOutput(e,r,n){let{amount:i,script:o}=e;if(i===void 0&&(i=r?.amount),typeof i!="bigint")throw new Error(`Wrong amount type, should be of type bigint in sats, but got ${i} of type ${typeof i}`);typeof o=="string"&&(o=xe.decode(o)),o===void 0&&(o=r?.script);let s={...r,...e,amount:i,script:o};if(s.amount===void 0&&delete s.amount,s=ll(Mu,s,r,n,this.opts.allowUnknown),fl.encode(s),s.script&&!this.opts.allowUnknownOutputs&&Qe.decode(s.script).type==="unknown")throw new Error("Transaction/output: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure");return this.opts.disableScriptCheck||h0(s.script,s.redeemScript,s.witnessScript),s}addOutput(e,r=!1){if(!r&&!this.signStatus().addOutput)throw new Error("Tx has signed outputs, cannot add new one");return this.outputs.push(this.normalizeOutput(e)),this.outputs.length-1}updateOutput(e,r,n=!1){this.checkOutputIdx(e);let i;if(!n){let o=this.signStatus();(!o.addOutput||o.outputs.includes(e))&&(i=XE)}this.outputs[e]=this.normalizeOutput(r,this.outputs[e],i)}addOutputAddress(e,r,n=Yr){return this.addOutput({script:Qe.encode(Jr(n).decode(e)),amount:r})}get fee(){let e=0n;for(let n of this.inputs){let i=pl(n);if(!i)throw new Error("Empty input amount");e+=i.amount}let r=this.outputs.map(Bs);for(let n of r)e-=n.amount;return e}preimageLegacy(e,r,n){let{isAny:i,isNone:o,isSingle:s}=ov(n);if(e<0||!Number.isSafeInteger(e))throw new Error(`Invalid input idx=${e}`);if(s&&e>=this.outputs.length||e>=this.inputs.length)return BE.encode(1n);r=Ze.encode(Ze.decode(r).filter(d=>d!=="CODESEPARATOR"));let c=this.inputs.map($u).map((d,f)=>({...d,finalScriptSig:f===e?r:Ve}));i?c=[c[e]]:(o||s)&&(c=c.map((d,f)=>({...d,sequence:f===e?d.sequence:0})));let a=this.outputs.map(Bs);o?a=[]:s&&(a=a.slice(0,e).fill(cR).concat([a[e]]));let u=Oi.encode({lockTime:this.lockTime,version:this.version,segwitFlag:!1,inputs:c,outputs:a});return Ri(u,Eo.encode(n))}preimageWitnessV0(e,r,n,i){let{isAny:o,isNone:s,isSingle:c}=ov(n),a=hl,u=hl,d=hl,f=this.inputs.map($u),h=this.outputs.map(Bs);o||(a=Ri(...f.map(y0.encode))),!o&&!c&&!s&&(u=Ri(...f.map(g=>Ie.encode(g.sequence)))),!c&&!s?d=Ri(...h.map(Ui.encode)):c&&e<h.length&&(d=Ri(Ui.encode(h[e])));let p=f[e];return Ri(Eo.encode(this.version),a,u,Fe(32,!0).encode(p.txid),Ie.encode(p.index),lr.encode(r),Wc.encode(i),Ie.encode(p.sequence),d,Ie.encode(this.lockTime),Ie.encode(n))}preimageWitnessV1(e,r,n,i,o=-1,s,c=192,a){if(!Array.isArray(i)||this.inputs.length!==i.length)throw new Error(`Invalid amounts array=${i}`);if(!Array.isArray(r)||this.inputs.length!==r.length)throw new Error(`Invalid prevOutScript array=${r}`);let u=[mn.encode(0),mn.encode(n),Eo.encode(this.version),Ie.encode(this.lockTime)],d=n===je.DEFAULT?je.ALL:n&3,f=n&je.ANYONECANPAY,h=this.inputs.map($u),p=this.outputs.map(Bs);f!==je.ANYONECANPAY&&u.push(...[h.map(y0.encode),i.map(Wc.encode),r.map(lr.encode),h.map(y=>Ie.encode(y.sequence))].map(y=>ke(jn(...y)))),d===je.ALL&&u.push(ke(jn(...p.map(Ui.encode))));let g=(a?1:0)|(s?2:0);if(u.push(new Uint8Array([g])),f===je.ANYONECANPAY){let y=h[e];u.push(y0.encode(y),Wc.encode(i[e]),lr.encode(r[e]),Ie.encode(y.sequence))}else u.push(Ie.encode(e));return g&1&&u.push(ke(lr.encode(a||Ve))),d===je.SINGLE&&u.push(e<p.length?ke(Ui.encode(p[e])):hl),s&&u.push(Ku(s,c),mn.encode(0),Eo.encode(o)),ku("TapSighash",...u)}signIdx(e,r,n,i){this.checkInputIdx(r);let o=this.inputs[r],s=g0(o,this.opts.allowLegacyWitnessUtxo);if(!Ce(e)){if(!o.bip32Derivation||!o.bip32Derivation.length)throw new Error("bip32Derivation: empty");let d=o.bip32Derivation.filter(h=>h[1].fingerprint==e.fingerprint).map(([h,{path:p}])=>{let g=e;for(let y of p)g=g.deriveChild(y);if(!st(g.publicKey,h))throw new Error("bip32Derivation: wrong pubKey");if(!g.privateKey)throw new Error("bip32Derivation: no privateKey");return g});if(!d.length)throw new Error(`bip32Derivation: no items with fingerprint=${e.fingerprint}`);let f=!1;for(let h of d)this.signIdx(h.privateKey,r)&&(f=!0);return f}n?n.forEach(hR):n=[s.defaultSighash];let c=s.sighash;if(!n.includes(c))throw new Error(`Input with not allowed sigHash=${c}. Allowed: ${n.join(", ")}`);let{sigOutputs:a}=this.inputSighash(r);if(a===je.SINGLE&&r>=this.outputs.length)throw new Error(`Input with sighash SINGLE, but there is no output with corresponding index=${r}`);let u=pl(o);if(s.txType==="taproot"){let d=this.inputs.map(pl),f=d.map(x=>x.script),h=d.map(x=>x.amount),p=!1,g=il(e),y=o.tapMerkleRoot||Ve;if(o.tapInternalKey){let{pubKey:x,privKey:S}=lR(e,g,o.tapInternalKey,y),[_,A]=Nu(o.tapInternalKey,y);if(st(_,x)){let O=this.preimageWitnessV1(r,f,c,h),T=jn(Zy(O,S,i),c!==je.DEFAULT?new Uint8Array([c]):Ve);this.updateInput(r,{tapKeySig:T},!0),p=!0}}if(o.tapLeafScript){o.tapScriptSig=o.tapScriptSig||[];for(let[x,S]of o.tapLeafScript){let _=S.subarray(0,-1),A=Ze.decode(_),O=S[S.length-1],T=Ku(_,O);if(A.findIndex($=>Ce($)&&st($,g))===-1)continue;let q=this.preimageWitnessV1(r,f,c,h,void 0,_,O),j=jn(Zy(q,e,i),c!==je.DEFAULT?new Uint8Array([c]):Ve);this.updateInput(r,{tapScriptSig:[[{pubKey:g,leafHash:T},j]]},!0),p=!0}}if(!p)throw new Error("No taproot scripts signed");return!0}else{let d=Xy(e),f=!1,h=Gc(d);for(let y of Ze.decode(s.lastScript))Ce(y)&&(st(y,d)||st(y,h))&&(f=!0);if(!f)throw new Error(`Input script doesn't have pubKey: ${s.lastScript}`);let p;if(s.txType==="legacy")p=this.preimageLegacy(r,s.lastScript,c);else if(s.txType==="segwit"){let y=s.lastScript;s.last.type==="wpkh"&&(y=Qe.encode({type:"pkh",hash:s.last.hash})),p=this.preimageWitnessV0(r,y,c,u.amount)}else throw new Error(`Transaction/sign: unknown tx type: ${s.txType}`);let g=ME(p,e,this.opts.lowR);this.updateInput(r,{partialSig:[[d,jn(g,new Uint8Array([c]))]]},!0)}return!0}sign(e,r,n){let i=0;for(let o=0;o<this.inputs.length;o++)try{this.signIdx(e,o,r,n)&&i++}catch{}if(!i)throw new Error("No inputs signed");return i}finalizeIdx(e){if(this.checkInputIdx(e),this.fee<0n)throw new Error("Outputs spends more than inputs amount");let r=this.inputs[e],n=g0(r,this.opts.allowLegacyWitnessUtxo);if(n.txType==="taproot"){if(r.tapKeySig)r.finalScriptWitness=[r.tapKeySig];else if(r.tapLeafScript&&r.tapScriptSig){let a=r.tapLeafScript.sort((u,d)=>Di.encode(u[0]).length-Di.encode(d[0]).length);for(let[u,d]of a){let f=d.slice(0,-1),h=d[d.length-1],p=Qe.decode(f),g=Ku(f,h),y=r.tapScriptSig.filter(S=>st(S[0].leafHash,g)),x=[];if(p.type==="tr_ms"){let S=p.m,_=p.pubkeys,A=0;for(let O of _){let T=y.findIndex(M=>st(M[0].pubKey,O));if(A===S||T===-1){x.push(Ve);continue}x.push(y[T][1]),A++}if(A!==S)continue}else if(p.type==="tr_ns"){for(let S of p.pubkeys){let _=y.findIndex(A=>st(A[0].pubKey,S));_!==-1&&x.push(y[_][1])}if(x.length!==p.pubkeys.length)continue}else if(p.type==="unknown"&&this.opts.allowUnknownInputs){let S=Ze.decode(f);if(x=y.map(([{pubKey:_},A])=>{let O=S.findIndex(T=>Ce(T)&&st(T,_));if(O===-1)throw new Error("finalize/taproot: cannot find position of pubkey in script");return{signature:A,pos:O}}).sort((_,A)=>_.pos-A.pos).map(_=>_.signature),!x.length)continue}else{let S=this.opts.customScripts;if(S)for(let _ of S){if(!_.finalizeTaproot)continue;let A=Ze.decode(f),O=_.encode(A);if(O===void 0)continue;let T=_.finalizeTaproot(f,O,y);if(T){r.finalScriptWitness=T.concat(Di.encode(u)),r.finalScriptSig=Ve,p0(r);return}}throw new Error("Finalize: Unknown tapLeafScript")}r.finalScriptWitness=x.reverse().concat([f,Di.encode(u)]);break}if(!r.finalScriptWitness)throw new Error("finalize/taproot: empty witness")}else throw new Error("finalize/taproot: unknown input");r.finalScriptSig=Ve,p0(r);return}if(!r.partialSig||!r.partialSig.length)throw new Error("Not enough partial sign");let i=Ve,o=[];if(n.last.type==="ms"){let a=n.last.m,u=n.last.pubkeys,d=[];for(let f of u){let h=r.partialSig.find(p=>st(f,p[0]));h&&d.push(h[1])}if(d=d.slice(0,a),d.length!==a)throw new Error(`Multisig: wrong signatures count, m=${a} n=${u.length} signatures=${d.length}`);i=Ze.encode([0,...d])}else if(n.last.type==="pk")i=Ze.encode([r.partialSig[0][1]]);else if(n.last.type==="pkh")i=Ze.encode([r.partialSig[0][1],r.partialSig[0][0]]);else if(n.last.type==="wpkh")i=Ve,o=[r.partialSig[0][1],r.partialSig[0][0]];else if(n.last.type==="unknown"&&!this.opts.allowUnknownInputs)throw new Error("Unknown inputs not allowed");let s,c;if(n.type.includes("wsh-")&&(i.length&&n.lastScript.length&&(o=Ze.decode(i).map(a=>{if(a===0)return Ve;if(Ce(a))return a;throw new Error(`Wrong witness op=${a}`)})),o=o.concat(n.lastScript)),n.txType==="segwit"&&(c=o),n.type.startsWith("sh-wsh-")?s=Ze.encode([Ze.encode([0,ke(n.lastScript)])]):n.type.startsWith("sh-")?s=Ze.encode([...Ze.decode(i),n.lastScript]):n.type.startsWith("wsh-")||n.txType!=="segwit"&&(s=i),!s&&!c)throw new Error("Unknown error finalizing input");s&&(r.finalScriptSig=s),c&&(r.finalScriptWitness=c),p0(r)}finalize(){for(let e=0;e<this.inputs.length;e++)this.finalizeIdx(e)}extract(){if(!this.isFinal)throw new Error("Transaction has unfinalized inputs");if(!this.outputs.length)throw new Error("Transaction has no outputs");if(this.fee<0n)throw new Error("Outputs spends more than inputs amount");return this.toBytes(!0,!0)}combine(e){for(let i of["PSBTVersion","version","lockTime"])if(this.opts[i]!==e.opts[i])throw new Error(`Transaction/combine: different ${i} this=${this.opts[i]} other=${e.opts[i]}`);for(let i of["inputs","outputs"])if(this[i].length!==e[i].length)throw new Error(`Transaction/combine: different ${i} length this=${this[i].length} other=${e[i].length}`);let r=this.global.unsignedTx?As.encode(this.global.unsignedTx):Ve,n=e.global.unsignedTx?As.encode(e.global.unsignedTx):Ve;if(!st(r,n))throw new Error("Transaction/combine: different unsigned tx");this.global=ll(ul,this.global,e.global,void 0,this.opts.allowUnknown);for(let i=0;i<this.inputs.length;i++)this.updateInput(i,e.inputs[i],!0);for(let i=0;i<this.outputs.length;i++)this.updateOutput(i,e.outputs[i],!0);return this}clone(){return t.fromPSBT(this.toPSBT(this.opts.PSBTVersion),this.opts)}};l();l();l();l();l();function av(t,e){var r="",n=e&&e.include,i=e&&e.exclude;i&&typeof i=="string"&&(i=[i]),n&&n.sort();var o=new WeakMap,s=e&&e.allowCircular,c=e&&e.filterUndefined,a=e&&e.undefinedInArrayToNull;return u(t,""),r;function u(d,f){if(d===null||typeof d!="object"||d.toJSON!=null)r+=JSON.stringify(d);else if(Array.isArray(d)){var h=o.get(d);if(h!==void 0&&f.startsWith(h)){if(!s)throw new Error("Circular reference detected");r+='"[Circular]"';return}o.set(d,f),r+="[";var p=!1;d.forEach(function(S,_){p&&(r+=","),p=!0,a&&S===void 0&&(S=null),u(S,f+"["+_+"]")}),r+="]"}else{var h=o.get(d);if(h!==void 0&&f.startsWith(h)){if(!s)throw new Error("Circular reference detected");r+='"[Circular]"';return}o.set(d,f),r+="{";var g=!1,y=function(_){i&&i.includes(_)||(g&&(r+=","),g=!0,r+=JSON.stringify(_),r+=":",u(d[_],f+"."+_))};if(f===""&&n)n.forEach(function(_){d.hasOwnProperty(_)&&y(_)});else{var x=Object.keys(d);c&&(x=x.filter(function(_){return d[_]!==void 0})),x.sort(),x.forEach(function(_){y(_)})}r+="}"}}}function uv(t,e){return av(t,{allowCircular:e,filterUndefined:!0,undefinedInArrayToNull:!0})}l();var w0;(function(t){t.INVALID_DID="INVALID_DID",t.METHOD_NOT_SUPPORTED="METHOD_NOT_SUPPORTED",t.INTERNAL_ERROR="INTERNAL_ERROR",t.INVALID_DID_DOCUMENT="INVALID_DID_DOCUMENT",t.INVALID_DID_UPDATE="INVALID_DID_UPDATE",t.INVALID_DID_DOCUMENT_LENGTH="INVALID_DID_DOCUMENT_LENGTH",t.INVALID_DID_URL="INVALID_DID_URL",t.INVALID_PREVIOUS_DID_PROOF="INVALID_PREVIOUS_DID_PROOF",t.INVALID_PUBLIC_KEY="INVALID_PUBLIC_KEY",t.INVALID_PUBLIC_KEY_MULTIBASE="INVALID_PUBLIC_KEY_MULTIBASE",t.INVALID_PUBLIC_KEY_LENGTH="INVALID_PUBLIC_KEY_LENGTH",t.INVALID_PUBLIC_KEY_TYPE="INVALID_PUBLIC_KEY_TYPE",t.INVALID_SIGNATURE="INVALID_SIGNATURE",t.NOT_FOUND="NOT_FOUND",t.REPRESENTATION_NOT_SUPPORTED="REPRESENTATION_NOT_SUPPORTED",t.UNSUPPORTED_PUBLIC_KEY_TYPE="UNSUPPORTED_PUBLIC_KEY_TYPE",t.PROOF_VERIFICATION_ERROR="PROOF_VERIFICATION_ERROR",t.PROOF_GENERATION_ERROR="PROOF_GENERATION_ERROR",t.PROOF_SERIALIZATION_ERROR="PROOF_SERIALIZATION_ERROR",t.PROOF_PARSING_ERROR="PROOF_PARSING_ERROR",t.VERIFICATION_METHOD_ERROR="VERIFICATION_METHOD_ERROR",t.LATE_PUBLISHING_ERROR="LATE_PUBLISHING_ERROR",t.INVALID_SIDECAR_DATA="INVALID_SIDECAR_DATA",t.MISSING_UPDATE_DATA="MISSING_UPDATE_DATA",t.INVALID_UPDATE="INVALID_UPDATE",t.INVALID_DOMAIN_ERROR="INVALID_DOMAIN_ERROR",t.MISSING_RESOLUTION_OPTIONS="MISSING_RESOLUTION_OPTIONS",t.INVALID_OPTIONS="INVALID_OPTIONS"})(w0||(w0={}));var{INVALID_DID:ht,METHOD_NOT_SUPPORTED:gl,INTERNAL_ERROR:dv,INVALID_DID_DOCUMENT:Le,INVALID_DID_UPDATE:Ae,INVALID_DID_URL:oK,INVALID_PREVIOUS_DID_PROOF:sK,INVALID_PUBLIC_KEY:cK,INVALID_PUBLIC_KEY_MULTIBASE:aK,INVALID_PUBLIC_KEY_LENGTH:uK,INVALID_PUBLIC_KEY_TYPE:dK,INVALID_SIGNATURE:fK,NOT_FOUND:lK,PROOF_VERIFICATION_ERROR:Ni,PROOF_GENERATION_ERROR:_o,PROOF_SERIALIZATION_ERROR:fv,PROOF_PARSING_ERROR:hK,VERIFICATION_METHOD_ERROR:ml,LATE_PUBLISHING_ERROR:wl,INVALID_SIDECAR_DATA:pK,MISSING_UPDATE_DATA:yK,MISSING_RESOLUTION_OPTIONS:gK,INVALID_OPTIONS:lv}=w0,zt=class t extends Error{name="DidMethodError";type="DidMethodError";data;constructor(e,r={}){super(e),this.type=r.type??this.type,this.name=r.name??this.name,this.data=r.data,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace?.(this,t)}},we=class extends zt{constructor(e,r="MethodError",n){super(e,{type:r,name:r,data:n})}};var ct=class extends zt{constructor(e,r="IdentifierError",n){super(e,{type:r,name:r,data:n})}},At=class extends zt{constructor(e,r="UpdateError",n){super(e,{type:r,name:r,data:n})}},De=class extends zt{constructor(e,r="ResolveError",n){super(e,{type:r,name:r,data:n})}};var qe=class extends zt{constructor(e,r="DidDocumentError",n){super(e,{type:r,name:r,data:n})}},To=class extends zt{constructor(e,r="CryptosuiteError",n){super(e,{type:r,name:r,data:n})}},wn=class extends zt{constructor(e,r="DataIntegrityProofError",n){super(e,{type:r,name:r,data:n})}},bn=class extends zt{constructor(e,r="KeyPairError",n){super(e,{type:r,name:r,data:n})}},Wn=class extends zt{constructor(e,r="SecretKeyError",n){super(e,{type:r,name:r,data:n})}},Us=class extends zt{constructor(e,r="PublicKeyError",n){super(e,{type:r,name:r,data:n})}},xn=class extends zt{constructor(e,r="MultikeyError",n){super(e,{type:r,name:r,data:n})}};var Jc=class extends zt{constructor(e,r="CanonicalizationError",n){super(e,{type:r,name:r,data:n})}};var yR=new Set(["jcs"]),gR=new Set(["hex","base58","base64urlnopad"]);function b0(t){let e=t.toLowerCase();if(!yR.has(e))throw new Jc(`Unsupported algorithm: ${t}`,"ALGORITHM_ERROR");return e}function x0(t){let e=t.toLowerCase();if(!gR.has(e))throw new Jc(`Unsupported encoding: ${t}`,"ENCODING_ERROR");return e}function rr(t,e="jcs"){switch(b0(e)){case"jcs":{let n=JSON.parse(JSON.stringify(t));return uv(n)}default:throw new Jc(`Unsupported algorithm: ${e}`,"ALGORITHM_ERROR")}}function Io(t){return ke(t)}function Xr(t,e="base64urlnopad"){switch(x0(e)){case"hex":return xe.encode(t);case"base58":return Yf.encode(t);case"base64urlnopad":return qc.encode(t)}}function Os(t,e="base64urlnopad"){switch(x0(e)){case"hex":return xe.decode(t);case"base58":return Yf.decode(t);case"base64urlnopad":return qc.decode(t)}}function Bo(t,e="jcs"){return Io(rr(t,b0(e)))}function Gn(t,e){let r=b0(e?.algorithm??"jcs"),n=x0(e?.encoding??"base64urlnopad");return Xr(Io(rr(t,r)),n)}l();l();var E0={};Tf(E0,{JsonPatchError:()=>at,_areEquals:()=>Fu,applyOperation:()=>Ds,applyPatch:()=>Tl,applyReducer:()=>ER,deepClone:()=>bR,getValueByPointer:()=>Sl,validate:()=>pv,validator:()=>Al});l();l();var mR=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var o in i)i.hasOwnProperty(o)&&(n[o]=i[o])},t(e,r)};return function(e,r){t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),wR=Object.prototype.hasOwnProperty;function xl(t,e){return wR.call(t,e)}function El(t){if(Array.isArray(t)){for(var e=new Array(t.length),r=0;r<e.length;r++)e[r]=""+r;return e}if(Object.keys)return Object.keys(t);var n=[];for(var i in t)xl(t,i)&&n.push(i);return n}function Mt(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function vl(t){for(var e=0,r=t.length,n;e<r;){if(n=t.charCodeAt(e),n>=48&&n<=57){e++;continue}return!1}return!0}function zn(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function Vu(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function bl(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)if(bl(t[e]))return!0}else if(typeof t=="object"){for(var n=El(t),i=n.length,o=0;o<i;o++)if(bl(t[n[o]]))return!0}}return!1}function hv(t,e){var r=[t];for(var n in e){var i=typeof e[n]=="object"?JSON.stringify(e[n],null,2):e[n];typeof i<"u"&&r.push(n+": "+i)}return r.join(`
|
|
3
|
-
`)}var qu=function(t){mR(e,t);function e(r,n,i,o,s){var c=this.constructor,a=t.call(this,hv(r,{name:n,index:i,operation:o,tree:s}))||this;return a.name=n,a.index=i,a.operation=o,a.tree=s,Object.setPrototypeOf(a,c.prototype),a.message=hv(r,{name:n,index:i,operation:o,tree:s}),a}return e}(Error);var at=qu,bR=Mt,Xc={add:function(t,e,r){return t[e]=this.value,{newDocument:r}},remove:function(t,e,r){var n=t[e];return delete t[e],{newDocument:r,removed:n}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:function(t,e,r){var n=Sl(r,this.path);n&&(n=Mt(n));var i=Ds(r,{op:"remove",path:this.from}).removed;return Ds(r,{op:"add",path:this.path,value:i}),{newDocument:r,removed:n}},copy:function(t,e,r){var n=Sl(r,this.from);return Ds(r,{op:"add",path:this.path,value:Mt(n)}),{newDocument:r}},test:function(t,e,r){return{newDocument:r,test:Fu(t[e],this.value)}},_get:function(t,e,r){return this.value=t[e],{newDocument:r}}},xR={add:function(t,e,r){return vl(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:r,index:e}},remove:function(t,e,r){var n=t.splice(e,1);return{newDocument:r,removed:n[0]}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:Xc.move,copy:Xc.copy,test:Xc.test,_get:Xc._get};function Sl(t,e){if(e=="")return t;var r={op:"_get",path:e};return Ds(t,r),r.value}function Ds(t,e,r,n,i,o){if(r===void 0&&(r=!1),n===void 0&&(n=!0),i===void 0&&(i=!0),o===void 0&&(o=0),r&&(typeof r=="function"?r(e,0,t,e.path):Al(e,0)),e.path===""){var s={newDocument:t};if(e.op==="add")return s.newDocument=e.value,s;if(e.op==="replace")return s.newDocument=e.value,s.removed=t,s;if(e.op==="move"||e.op==="copy")return s.newDocument=Sl(t,e.from),e.op==="move"&&(s.removed=t),s;if(e.op==="test"){if(s.test=Fu(t,e.value),s.test===!1)throw new at("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s.newDocument=t,s}else{if(e.op==="remove")return s.removed=t,s.newDocument=null,s;if(e.op==="_get")return e.value=t,s;if(r)throw new at("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",o,e,t);return s}}else{n||(t=Mt(t));var c=e.path||"",a=c.split("/"),u=t,d=1,f=a.length,h=void 0,p=void 0,g=void 0;for(typeof r=="function"?g=r:g=Al;;){if(p=a[d],p&&p.indexOf("~")!=-1&&(p=Vu(p)),i&&(p=="__proto__"||p=="prototype"&&d>0&&a[d-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(r&&h===void 0&&(u[p]===void 0?h=a.slice(0,d).join("/"):d==f-1&&(h=e.path),h!==void 0&&g(e,0,t,h)),d++,Array.isArray(u)){if(p==="-")p=u.length;else{if(r&&!vl(p))throw new at("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",o,e,t);vl(p)&&(p=~~p)}if(d>=f){if(r&&e.op==="add"&&p>u.length)throw new at("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",o,e,t);var s=xR[e.op].call(e,u,p,t);if(s.test===!1)throw new at("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}}else if(d>=f){var s=Xc[e.op].call(e,u,p,t);if(s.test===!1)throw new at("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}if(u=u[p],r&&d<f&&(!u||typeof u!="object"))throw new at("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",o,e,t)}}}function Tl(t,e,r,n,i){if(n===void 0&&(n=!0),i===void 0&&(i=!0),r&&!Array.isArray(e))throw new at("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");n||(t=Mt(t));for(var o=new Array(e.length),s=0,c=e.length;s<c;s++)o[s]=Ds(t,e[s],r,!0,i,s),t=o[s].newDocument;return o.newDocument=t,o}function ER(t,e,r){var n=Ds(t,e);if(n.test===!1)throw new at("Test operation failed","TEST_OPERATION_FAILED",r,e,t);return n.newDocument}function Al(t,e,r,n){if(typeof t!="object"||t===null||Array.isArray(t))throw new at("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,r);if(Xc[t.op]){if(typeof t.path!="string")throw new at("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,r);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new at('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,r);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new at("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new at("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&bl(t.value))throw new at("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,r);if(r){if(t.op=="add"){var i=t.path.split("/").length,o=n.split("/").length;if(i!==o+1&&i!==o)throw new at("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,r)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==n)throw new at("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,r)}else if(t.op==="move"||t.op==="copy"){var s={op:"_get",path:t.from,value:void 0},c=pv([s],r);if(c&&c.name==="OPERATION_PATH_UNRESOLVABLE")throw new at("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,r)}}}else throw new at("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,r)}function pv(t,e,r){try{if(!Array.isArray(t))throw new at("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)Tl(Mt(e),Mt(t),r||!0);else{r=r||Al;for(var n=0;n<t.length;n++)r(t[n],n,e,void 0)}}catch(i){if(i instanceof at)return i;throw i}}function Fu(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=Array.isArray(t),n=Array.isArray(e),i,o,s;if(r&&n){if(o=t.length,o!=e.length)return!1;for(i=o;i--!==0;)if(!Fu(t[i],e[i]))return!1;return!0}if(r!=n)return!1;var c=Object.keys(t);if(o=c.length,o!==Object.keys(e).length)return!1;for(i=o;i--!==0;)if(!e.hasOwnProperty(c[i]))return!1;for(i=o;i--!==0;)if(s=c[i],!Fu(t[s],e[s]))return!1;return!0}return t!==t&&e!==e}var T0={};Tf(T0,{compare:()=>RR,generate:()=>v0,observe:()=>BR,unobserve:()=>IR});l();var S0=new WeakMap,vR=function(){function t(e){this.observers=new Map,this.obj=e}return t}(),SR=function(){function t(e,r){this.callback=e,this.observer=r}return t}();function AR(t){return S0.get(t)}function TR(t,e){return t.observers.get(e)}function _R(t,e){t.observers.delete(e.callback)}function IR(t,e){e.unobserve()}function BR(t,e){var r=[],n,i=AR(t);if(!i)i=new vR(t),S0.set(t,i);else{var o=TR(i,e);n=o&&o.observer}if(n)return n;if(n={},i.value=Mt(t),e){n.callback=e,n.next=null;var s=function(){v0(n)},c=function(){clearTimeout(n.next),n.next=setTimeout(s)};typeof window<"u"&&(window.addEventListener("mouseup",c),window.addEventListener("keyup",c),window.addEventListener("mousedown",c),window.addEventListener("keydown",c),window.addEventListener("change",c))}return n.patches=r,n.object=t,n.unobserve=function(){v0(n),clearTimeout(n.next),_R(i,n),typeof window<"u"&&(window.removeEventListener("mouseup",c),window.removeEventListener("keyup",c),window.removeEventListener("mousedown",c),window.removeEventListener("keydown",c),window.removeEventListener("change",c))},i.observers.set(e,new SR(e,n)),n}function v0(t,e){e===void 0&&(e=!1);var r=S0.get(t.object);A0(r.value,t.object,t.patches,"",e),t.patches.length&&Tl(r.value,t.patches);var n=t.patches;return n.length>0&&(t.patches=[],t.callback&&t.callback(n)),n}function A0(t,e,r,n,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var o=El(e),s=El(t),c=!1,a=!1,u=s.length-1;u>=0;u--){var d=s[u],f=t[d];if(xl(e,d)&&!(e[d]===void 0&&f!==void 0&&Array.isArray(e)===!1)){var h=e[d];typeof f=="object"&&f!=null&&typeof h=="object"&&h!=null&&Array.isArray(f)===Array.isArray(h)?A0(f,h,r,n+"/"+zn(d),i):f!==h&&(c=!0,i&&r.push({op:"test",path:n+"/"+zn(d),value:Mt(f)}),r.push({op:"replace",path:n+"/"+zn(d),value:Mt(h)}))}else Array.isArray(t)===Array.isArray(e)?(i&&r.push({op:"test",path:n+"/"+zn(d),value:Mt(f)}),r.push({op:"remove",path:n+"/"+zn(d)}),a=!0):(i&&r.push({op:"test",path:n,value:t}),r.push({op:"replace",path:n,value:e}),c=!0)}if(!(!a&&o.length==s.length))for(var u=0;u<o.length;u++){var d=o[u];!xl(t,d)&&e[d]!==void 0&&r.push({op:"add",path:n+"/"+zn(d),value:Mt(e[d])})}}}function RR(t,e,r){r===void 0&&(r=!1);var n=[];return A0(t,e,n,"",r),n}var yv=Object.assign({},E0,T0,{JsonPatchError:qu,deepClone:Mt,escapePathComponent:zn,unescapePathComponent:Vu});var{applyPatch:UR,compare:OR,deepClone:DR}=yv,kR=new Set(["__proto__","constructor","prototype"]);function gv(t){return t.split("/").map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~")).find(e=>kR.has(e))}var Zc=class{static apply(e,r,n={}){let i=n.mutate??!1,o=n.clone??DR,s=i?e:o(e),c=this.validateOperations(r);if(c)throw new we("Invalid JSON Patch operations","JSON_PATCH_APPLY_ERROR",{error:c});try{let a=UR(s,r,!1,i);if(a.newDocument===void 0)throw new we("JSON Patch application failed","JSON_PATCH_APPLY_ERROR",{result:a});return a.newDocument}catch(a){throw new we("JSON Patch application failed","JSON_PATCH_APPLY_ERROR",{error:a})}}static diff(e,r,n=""){let i=OR(e??{},r??{});if(!n)return i;let o=n.endsWith("/")?n.slice(0,-1):n;return i.map(s=>({...s,path:this.joinPointer(o,s.path)}))}static joinPointer(e,r){if(!e)return r;let n=e.startsWith("/")?e:`/${e}`;return`${this.escapeSegmentPath(n)}${r}`}static escapeSegmentPath(e){return e.split("/").map((r,n)=>n===0?r:r.replace(/~/g,"~0").replace(/\//g,"~1")).join("/")}static validateOperations(e){if(!Array.isArray(e))return new we("Operations must be an array","JSON_PATCH_VALIDATION_ERROR");for(let r of e){if(!r||typeof r!="object")return new we("Operation must be an object","JSON_PATCH_VALIDATION_ERROR");if(typeof r.op!="string")return new we("Operation.op must be a string","JSON_PATCH_VALIDATION_ERROR");if(typeof r.path!="string")return new we("Operation.path must be a string","JSON_PATCH_VALIDATION_ERROR");let n=gv(r.path);if(n)return new we(`Operation.path traverses prototype machinery: ${n}`,"JSON_PATCH_VALIDATION_ERROR");if((r.op==="move"||r.op==="copy")&&typeof r.from!="string")return new we(`Operation.from must be a string for op=${r.op}`,"JSON_PATCH_VALIDATION_ERROR");if(typeof r.from=="string"){let i=gv(r.from);if(i)return new we(`Operation.from traverses prototype machinery: ${i}`,"JSON_PATCH_VALIDATION_ERROR")}}return null}};l();var Zr;(function(t){t.KEY="KEY",t.EXTERNAL="EXTERNAL"})(Zr||(Zr={}));var _l;(function(t){t.k="k",t.x="x"})(_l||(_l={}));var Qc;(function(t){t[t.bitcoin=0]="bitcoin",t[t.signet=1]="signet",t[t.regtest=2]="regtest",t[t.testnet3=3]="testnet3",t[t.testnet4=4]="testnet4",t[t.mutinynet=5]="mutinynet"})(Qc||(Qc={}));l();var Ro=class{static toISOStringNonFractional(e=new Date){let r=e.getTime();if(Number.isNaN(r))throw new we(`Invalid date: ${e}`,"INVALID_DATE");return e.toISOString().replace(/\.\d{3}Z$/,"Z")}static toUnixSeconds(e=new Date){let r=e.getTime();if(Number.isNaN(r))throw new we(`Invalid date: ${e}`,"INVALID_DATE");return Math.floor(e.getTime()/1e3)}static dateStringToTimestamp(e){let r=new Date(e);return Number.isNaN(r.getTime())?new Date(0):r}static blocktimeToTimestamp(e){return new Date(e*1e3)}static isValidXsdDateTime(e){if(!e)return!1;let r=/^-?(\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,n=e.match(r);if(!n)return!1;let[,i,o,s,c,a,u,,d]=n,f=parseInt(i,10),h=parseInt(o,10),p=parseInt(s,10),g=parseInt(c,10),y=parseInt(a,10),x=parseInt(u,10);if(f===0||h<1||h>12)return!1;let S=[31,28,31,30,31,30,31,31,30,31,30,31],_=f%4===0&&f%100!==0||f%400===0,A=h===2&&_?29:S[h-1];if(p<1||p>A)return!1;if(g===24){if(y!==0||x!==0)return!1}else if(g>23)return!1;if(y>59||x>59)return!1;if(d&&d!=="Z"){let O=d.match(/^[+-](\d{2}):(\d{2})$/);if(O){let T=parseInt(O[1],10),M=parseInt(O[2],10);if(T>14||T===14&&M!==0||M>59)return!1}}return!0}};l();function _0(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}var ks=class{static isObject(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}static isParsable(e){if(typeof e!="string")return!1;try{return JSON.parse(e),!0}catch{return!1}}static isUnprototyped(e){return e===null||typeof e!="object"?!1:Object.getPrototypeOf(e)===null}static normalize(e){return this.cloneInternal(e,{stripPrototypes:!0})}static copy(e){return{...e}}static clone(e){return typeof structuredClone=="function"?structuredClone(e):this.cloneInternal(e)}static cloneReplace(e,r,n){return this.cloneInternal(e,{transform:i=>typeof i=="string"?i.replace(r,n):i})}static deepEqual(e,r,n=new WeakMap,i=0){if(i>1024)throw new we("Maximum comparison depth exceeded","MAX_DEPTH_EXCEEDED");if(Object.is(e,r))return!0;if(typeof e!=typeof r||e===null||r===null||typeof e!="object")return!1;if(n.get(e)===r)return!0;if(n.set(e,r),ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){let c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);if(c.byteLength!==a.byteLength)return!1;for(let u=0;u<c.byteLength;u++)if(c[u]!==a[u])return!1;return!0}if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(let c of e){let a=!1;for(let u of r)if(this.deepEqual(c,u,n,i+1)){a=!0;break}if(!a)return!1}return!0}if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(let[c,a]of e){let u=!1;if(r.has(c))u=this.deepEqual(a,r.get(c),n,i+1);else for(let[d,f]of r)if(this.deepEqual(c,d,n,i+1)&&this.deepEqual(a,f,n,i+1)){u=!0;break}if(!u)return!1}return!0}if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return!1;for(let c=0;c<e.length;c++)if(!this.deepEqual(e[c],r[c],n,i+1))return!1;return!0}let o=Object.keys(e),s=Object.keys(r);if(o.length!==s.length)return!1;for(let c of o)if(!Object.prototype.hasOwnProperty.call(r,c)||!this.deepEqual(e[c],r[c],n,i+1))return!1;return!0}static deleteKeys(e,r){let n=new Set(r.map(o=>typeof o=="number"?o.toString():o)),i=o=>{if(Array.isArray(o))return o.map(s=>i(s));if(o&&typeof o=="object"){let s={};for(let c of Object.keys(o))n.has(c)||_0(s,c,i(o[c]));return s}return o};return i(e)}static sanitize(e){let r=n=>{if(Array.isArray(n))return n.filter(i=>i!==void 0).map(i=>r(i));if(n&&typeof n=="object"){let i={};for(let[o,s]of Object.entries(n)){let c=r(s);c!==void 0&&_0(i,o,c)}return i}return n};return r(e)}static cloneInternal(e,r={},n=new WeakMap,i=0){if(i>1024)throw new we("Maximum clone depth exceeded","MAX_DEPTH_EXCEEDED");let o=r.transform?r.transform(e):e;if(o!==e||typeof e!="object"||e===null)return o;if(n.has(e))throw new we("Cannot clone circular structure","CIRCULAR_STRUCTURE");if(Array.isArray(e)){let c=[];n.set(e,c);for(let a of e)c.push(this.cloneInternal(a,r,n,i+1));return c}if(ArrayBuffer.isView(e)){if(e instanceof DataView)return new DataView(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(typeof e.slice=="function")return e.slice()}if(e instanceof Date)return new Date(e.getTime());let s=r.stripPrototypes?{}:Object.create(Object.getPrototypeOf(e));n.set(e,s);for(let c of Object.keys(e))_0(s,c,this.cloneInternal(e[c],r,n,i+1));return s}};l();var nr=class extends we{constructor(e,r="BeaconError",n){super(e,r,n)}},mv=class extends we{constructor(e,r="SingletonBeaconError",n){super(e,r,n)}},wv=class extends we{constructor(e,r="AggregateBeaconError",n){super(e,r,n)}},bv=class extends we{constructor(e,r="CASBeaconError",n){super(e,r,n)}},ju=class extends we{constructor(e,r="SMTBeaconError",n){super(e,r,n)}};l();l();l();l();l();l();l();l();l();l();l();l();l();l();l();var qR={bech32:"bcrt",pubKeyHash:111,scriptHash:196,wif:239};function Uo(t){switch(t){case"bitcoin":return Yr;case"testnet3":case"testnet4":case"signet":case"mutinynet":return Qy;case"regtest":return qR;default:throw new Error(`Unknown network "${t}"`)}}l();var Wu=class{satsPerVbyte;constructor(e=5){if(e<0||!Number.isFinite(e))throw new Error(`Invalid satsPerVbyte: ${e}`);this.satsPerVbyte=e}async estimateFee(e){if(e<0||!Number.isFinite(e))throw new Error(`Invalid vsize: ${e}`);return BigInt(Math.ceil(e*this.satsPerVbyte))}};l();var B0="0000000000000000000000000000000000000000000000000000000000000000",R0="4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";l();var U0;(function(t){t[t.hex=0]="hex",t[t.json=1]="json",t[t.jsonext=2]="jsonext",t[t.jsonextprev=3]="jsonextprev"})(U0||(U0={}));var O0=new Wu(5);var WR=160,GR=155,zR=240,YR={p2pkh:zR,p2wpkh:GR,p2tr:WR},Ev={p2pkh:34,p2wpkh:31,p2tr:43},vv={p2pkh:546,p2wpkh:294,p2tr:330};function Sv(t,e){return YR[t]-Ev[t]+Ev[e]}function Av(t,e){let r=Jr(e).decode(t);if(r.type==="pkh")return"p2pkh";if(r.type==="wpkh")return"p2wpkh";if(r.type==="tr")return"p2tr";throw new nr(`Unsupported singleton beacon address type "${r.type}". Expected P2PKH, P2WPKH, or P2TR (taproot key-path).`,"UNSUPPORTED_BEACON_ADDRESS_TYPE",{address:t,kind:r.type})}function JR(t,e,r){return t==="p2pkh"?ki(e,r).address:t==="p2wpkh"?Ts(e,r).address:_s(e.slice(1,33),void 0,r).address}function Tv(t,e,r){if(!r||r===t)return t;try{Jr(e).decode(r)}catch{throw new nr(`Invalid change address "${r}" for network "${e}".`,"INVALID_CHANGE_ADDRESS",{changeAddress:r,network:e})}return r}function _v(t,e){try{return Av(t,e)}catch{return"p2tr"}}function Iv(t){return Ze.encode(["RETURN",t])}var D0=546;function XR(t){return t.status.confirmed===!0}function ZR(t,e){if(t.status.block_height!==e.status.block_height)return t.status.block_height-e.status.block_height;let r=t.txid.localeCompare(e.txid);return r!==0?r:t.vout-e.vout}function QR(t,e){if(!t.length)throw new nr("No UTXOs found, please fund address!","UNFUNDED_BEACON_ADDRESS",{address:e});let r=t.filter(XR),n=r.filter(i=>i.value>D0);if(!n.length){let i=r.length===0?`all ${t.length} UTXO(s) are unconfirmed`:`all ${r.length} confirmed UTXO(s) are at or below the ${D0}-sat dust limit`;throw new nr(`No spendable UTXO at beacon address: ${i}.`,"NO_SPENDABLE_BEACON_UTXO",{address:e,total:t.length,confirmed:r.length,dustLimit:D0})}return[...n].sort(ZR)[0]}async function Bv(t,e){let r=await e.rest.address.getUtxos(t),n=QR(r,t),i=await e.rest.transaction.getHex(n.txid);return{utxo:n,prevTxBytes:_r(i)}}async function $$(t){let e=t.feeEstimator??O0,{utxo:r,prevTxBytes:n}=await Bv(t.beaconAddress,t.bitcoin),i=Tv(t.beaconAddress,t.network,t.changeAddress),o=Qe.encode(Jr(t.network).decode(t.beaconAddress)),s=_v(i,t.network),c=await e.estimateFee(Sv("p2tr",s));if(BigInt(r.value)<=c)throw new nr(`UTXO value (${r.value}) insufficient to cover fee (${c}).`,"INSUFFICIENT_FUNDS",{address:t.beaconAddress,valueSats:r.value,feeSats:c});let a=new Rs({allowUnknownOutputs:!0});a.addInput({txid:r.txid,index:r.vout,nonWitnessUtxo:n,witnessUtxo:{amount:BigInt(r.value),script:o},tapInternalKey:t.internalPubkey});let u=BigInt(r.value)-c;return u>=BigInt(vv[s])&&a.addOutputAddress(i,u,t.network),a.addOutput({script:Iv(t.signalBytes),amount:0n}),{tx:a,prevOutScripts:[o],prevOutValues:[BigInt(r.value)],beaconAddress:t.beaconAddress,changeAddress:i,utxo:r,feeSats:c,scriptKind:"p2tr"}}async function e6(t,e,r,n,i,o){let s=n.publicKey;if(r==="p2pkh"){let u=Ao.ALL,d=t.preimageLegacy(e,i,u),f=n.sign(d,"ecdsa"),h=lt(f,new Uint8Array([u]));return t.updateInput(e,{partialSig:[[s,h]]},!0),t.finalize(),t.hex}if(r==="p2wpkh"){let u=Qe.decode(i);if(u.type!=="wpkh")throw new nr(`Expected P2WPKH prev-output script, got "${u.type}".`,"PREVOUT_SCRIPT_MISMATCH",{kind:r,observedScriptType:u.type});let d=Qe.encode({type:"pkh",hash:u.hash}),f=Ao.ALL,h=t.preimageWitnessV0(e,d,f,o),p=n.sign(h,"ecdsa"),g=lt(p,new Uint8Array([f]));return t.updateInput(e,{partialSig:[[s,g]]},!0),t.finalize(),t.hex}let c=t.preimageWitnessV1(e,[i],Ao.DEFAULT,[o]),a=n.sign(c,"bip341");return t.updateInput(e,{tapKeySig:a}),t.finalize(),t.hex}var Oo=class{service;did;constructor(e,r){this.service=e,this.did=r}async buildSignAndBroadcast(e,r,n,i){let o=i?.feeEstimator??O0,s=this.service.serviceEndpoint.replace("bitcoin:",""),{utxo:c,prevTxBytes:a}=await Bv(s,n),u=await this.buildSinglePartyTx({signalBytes:e,beaconAddress:s,utxo:c,prevTxBytes:a,signer:r,bitcoin:n,feeEstimator:o,changeAddress:i?.changeAddress}),d=await this.signSinglePartyTx(u,r);return this.broadcastRawTx(n,d)}async buildSinglePartyTx(e){let r=e.bitcoin.data,n=e.signer.publicKey,i=Av(e.beaconAddress,r),o=Tv(e.beaconAddress,r,e.changeAddress),s=JR(i,n,r);if(s!==e.beaconAddress)throw new nr(`Signer pubkey produces ${i.toUpperCase()} address "${s}", but beacon address is "${e.beaconAddress}".`,"SIGNER_KEY_MISMATCH",{kind:i,address:e.beaconAddress,derivedAddress:s});let c=_v(o,r),a=await e.feeEstimator.estimateFee(Sv(i,c)),u=BigInt(e.utxo.value);if(u<=a)throw new nr(`UTXO value (${e.utxo.value}) insufficient to cover fee (${a}).`,"INSUFFICIENT_FUNDS",{address:e.beaconAddress,valueSats:e.utxo.value,feeSats:a});let d=new Rs({allowUnknownOutputs:!0}),f;if(i==="p2pkh")f=ki(n,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes});else if(i==="p2wpkh")f=Ts(n,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes,witnessUtxo:{amount:u,script:f}});else{let p=n.slice(1,33);f=_s(p,void 0,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes,witnessUtxo:{amount:u,script:f},tapInternalKey:p})}let h=u-a;return h>=BigInt(vv[c])&&d.addOutputAddress(o,h,r),d.addOutput({script:Iv(e.signalBytes),amount:0n}),{tx:d,prevOutScripts:[f],prevOutValues:[u],beaconAddress:e.beaconAddress,changeAddress:o,utxo:e.utxo,feeSats:a,scriptKind:i}}async signSinglePartyTx(e,r){return e6(e.tx,0,e.scriptKind,r,e.prevOutScripts[0],e.prevOutValues[0])}async broadcastRawTx(e,r){return e.rest.transaction.send(r)}};l();var Il=class extends Oo{constructor(e,r){super({...e,type:"CASBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array,o=this.did;for(let s of e){let c=s.signalBytes,a=r.casMap.get(c);if(!a){i.push({kind:"NeedCASAnnouncement",announcementHash:c,beaconServiceId:this.service.id});continue}let u=a[o];if(!u)continue;let d=Xr(Os(u,"base64urlnopad"),"hex"),f=r.updateMap.get(d);if(!f){i.push({kind:"NeedSignedUpdate",updateHash:d,beaconServiceId:this.service.id});continue}n.push([f,s.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=this.did,s=Gn(e),c={[o]:s},a=Io(rr(c));i?.casPublish&&await i.casPublish(c);let u=await this.buildSignAndBroadcast(a,r,n,i);return{signedUpdate:e,txid:u,announcement:c}}};l();l();var Bl=class extends Oo{constructor(e,r){super({...e,type:"SingletonBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array;for(let o of e){let s=o.signalBytes,c=r.updateMap.get(s);if(!c){i.push({kind:"NeedSignedUpdate",updateHash:s,beaconServiceId:this.service.id});continue}n.push([c,o.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=Io(rr(e)),s=await this.buildSignAndBroadcast(o,r,n,i);return{signedUpdate:e,txid:s}}};l();l();l();var t6=new Uint8Array(32),k0=1n<<BigInt(256),Rv=(()=>{let t=new Array(257),e=k0>>1n;for(let r=0;r<256;r++)t[r]=e,e>>=1n;return t[256]=0n,t})();l();l();l();function Gu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Yn(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function Te(t,e,r=""){let n=Gu(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Rl(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Yn(t.outputLen),Yn(t.blockLen)}function ea(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ov(t,e){Te(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ns(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ul(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function En(t,e){return t<<32-e|t>>>e}var Dv=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",r6=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Cs(t){if(Te(t),Dv)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=r6[t[r]];return e}var Ci={_0:48,_9:57,A:65,F:70,a:97,f:102};function Uv(t){if(t>=Ci._0&&t<=Ci._9)return t-Ci._0;if(t>=Ci.A&&t<=Ci.F)return t-(Ci.A-10);if(t>=Ci.a&&t<=Ci.f)return t-(Ci.a-10)}function Ls(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Dv)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=Uv(t.charCodeAt(o)),c=Uv(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function hr(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Te(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}function kv(t,e={}){let r=(i,o)=>t(o).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function Ps(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Nv=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var C0=BigInt(0),N0=BigInt(1);function zu(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Cv(t){if(typeof t=="bigint"){if(!Ol(t))throw new Error("positive bigint expected, got "+t)}else Yn(t);return t}function Yu(t){let e=Cv(t).toString(16);return e.length&1?"0"+e:e}function Lv(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?C0:BigInt("0x"+t)}function Do(t){return Lv(Cs(t))}function L0(t){return Lv(Cs(n6(Te(t)).reverse()))}function Dl(t,e){Yn(e),t=Cv(t);let r=Ls(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function P0(t,e){return Dl(t,e).reverse()}function ta(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function n6(t){return Uint8Array.from(t)}function Pv(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Ol=t=>typeof t=="bigint"&&C0<=t;function i6(t,e,r){return Ol(t)&&Ol(e)&&Ol(r)&&e<=t&&t<r}function Mv(t,e,r,n){if(!i6(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function M0(t){let e;for(e=0;t>C0;t>>=N0,e+=1);return e}var Ju=t=>(N0<<BigInt(t))-N0;function Kv(t,e,r){if(Yn(t,"hashLen"),Yn(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),i=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(t),u=n(t),d=0,f=()=>{a.fill(1),u.fill(0),d=0},h=(...x)=>r(u,hr(a,...x)),p=(x=i)=>{u=h(o,x),a=h(),x.length!==0&&(u=h(s,x),a=h())},g=()=>{if(d++>=c)throw new Error("drbg: tried max amount of iterations");let x=0,S=[];for(;x<e;){a=h();let _=a.slice();S.push(_),x+=a.length}return hr(...S)};return(x,S)=>{f(),p(x);let _;for(;!(_=S(g()));)p();return f(),_}}function Xu(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,c){let a=t[o];if(c&&a===void 0)return;let u=typeof a;if(u!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${u}`)}let i=(o,s)=>Object.entries(o).forEach(([c,a])=>n(c,a,s));i(e,!1),i(r,!0)}function K0(t){let e=new WeakMap;return(r,...n)=>{let i=e.get(r);if(i!==void 0)return i;let o=t(r,...n);return e.set(r,o),o}}function $0(t){return t.length===32}function kl(t){if(!$0(t))throw new RangeError(`Invalid hash: expected ${32} bytes, got ${t.length}`)}function pt(...t){return ke(lt(...t))}function Zu(t){kl(t);let e=0n;for(let r of t)e=e<<8n|BigInt(r);return e}function H0(t){let e=new Uint8Array(32),r=t;for(let n=31;n>=0;n--)e[n]=Number(r&0xffn),r>>=8n;if(r!==0n)throw new RangeError("Value exceeds 256 bits");return e}function V0(t){kl(t);let e="";for(let r of t)e+=r.toString(16).padStart(2,"0");return e}function q0(t,e){return!$0(t)||!$0(e)?!1:ta(t,e)}function ra(t){return kl(t),qc.encode(t)}function Jn(t){let e=qc.decode(t);if(e.length!==32)throw new RangeError(`Invalid base64url hash: expected ${32} decoded bytes, got ${e.length}`);return e}l();l();var $v;(function(t){t[t.Pending=0]="Pending",t[t.Valid=1]="Valid",t[t.Invalid=2]="Invalid"})($v||($v={}));l();l();var ko=256;function na(t,e){return Number(t>>BigInt(e)&1n)}var Hv=(()=>{let t=new Array(ko+1),e=new Uint8Array(32);for(let r=0;r<=ko;r++)e=pt(e,e),t[r]=e;return t})();function Nl(t,e){if(t.length===0)return Hv[e];if(e===0)return t[0].leaf;let r=ko-e,n=[],i=[];for(let o of t)(na(o.index,r)===0?n:i).push(o);return pt(Nl(n,e-1),Nl(i,e-1))}function Vv(t){return Nl(t,ko)}function qv(t,e){let r=0n,n=[];for(let i=1;i<=ko;i++){let o=ko-i,s=[];for(let c of t){if(c.index===e)continue;let a=!0;for(let u=0;u<o;u++)if(na(c.index,u)!==na(e,u)){a=!1;break}a&&na(c.index,o)!==na(e,o)&&s.push(c)}s.length===0?r|=1n<<BigInt(o):n.push(Nl(s,i-1))}return{collapsed:r,hashes:n}}function Fv(t,e,r,n,i){let o=n,s=0;for(let c=0;c<ko;c++){let a=ko-1-c,u;if((t>>BigInt(a)&1n)===1n)u=Hv[c];else{if(s>=e.length)return!1;u=e[s++]}o=na(r,a)===1?pt(u,o):pt(o,u)}return s===e.length&&q0(o,i)}l();var o6=new TextEncoder;function Cl(t){return Zu(pt(o6.encode(t)))}function jv(t,e){return pt(pt(t),pt(e))}function Wv(t){return pt(pt(t))}l();function Gv(t,e,r){let n={id:ra(t),collapsed:ra(H0(e.collapsed)),hashes:e.hashes.map(i=>ra(i))};return r?.nonce&&(n.nonce=ra(r.nonce)),r?.updateId&&(n.updateId=ra(r.updateId)),n}function s6(t){let e={rootHash:Jn(t.id),collapsed:Zu(Jn(t.collapsed)),hashes:t.hashes.map(r=>Jn(r))};return t.nonce&&(e.nonce=Jn(t.nonce)),t.updateId&&(e.updateId=Jn(t.updateId)),e}function zv(t,e,r){let{rootHash:n,collapsed:i,hashes:o}=s6(t);return Fv(i,o,e,r,n)}l();var Ll=class{#e=new Map;#t=new Map;#n=null;#r=null;constructor(e=!0){}addEntries(e){for(let r of e){let n=Cl(r.did);if(this.#e.has(n))throw new RangeError(`Duplicate DID index for: ${r.did}`);this.#e.set(n,r),this.#t.set(r.did,n)}this.#n=null,this.#r=null}finalize(){let e=[];for(let[r,n]of this.#e){let i=n.signedUpdate!==void 0?jv(n.nonce,n.signedUpdate):Wv(n.nonce);e.push({index:r,leaf:i})}this.#n=e,this.#r=Vv(e)}get rootHash(){if(this.#r===null)throw new Error("Tree not finalized: call finalize() first");return this.#r}proof(e){let r=this.#t.get(e);if(r===void 0)throw new RangeError(`DID not in tree: ${e}`);if(this.#n===null||this.#r===null)throw new Error("Tree not finalized: call finalize() first");let n=this.#e.get(r),i=qv(this.#n,r),o=n.signedUpdate!==void 0?pt(n.signedUpdate):void 0;return Gv(this.#r,i,{nonce:n.nonce,updateId:o})}reset(){this.#n=null,this.#r=null}};var Pl=class extends Oo{constructor(e,r){super({...e,type:"SMTBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array,o=this.did;for(let s of e){let c=r.smtMap.get(s.signalBytes);if(!c){i.push({kind:"NeedSMTProof",smtRootHash:s.signalBytes,beaconServiceId:this.service.id});continue}if(!c.nonce)throw new ju("SMT proof missing required nonce field.","INVALID_SMT_PROOF",{smtProof:c,did:o});let a=Cl(o),u=Jn(c.nonce),d=c.updateId?pt(pt(u),Jn(c.updateId)):pt(pt(u));if(!zv(c,a,d))throw new ju("SMT proof verification failed.","INVALID_SMT_PROOF",{smtProof:c,did:o});if(!c.updateId)continue;let h=V0(Jn(c.updateId)),p=r.updateMap.get(h);if(!p){i.push({kind:"NeedSignedUpdate",updateHash:h,beaconServiceId:this.service.id});continue}n.push([p,s.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=this.did,s=new TextEncoder().encode(rr(e)),c=Ir(32),a=new Ll;a.addEntries([{did:o,nonce:c,signedUpdate:s}]),a.finalize();let u=a.proof(o),d=await this.buildSignAndBroadcast(a.rootHash,r,n,i);return{signedUpdate:e,txid:d,proof:u}}};var ia=class{static establish(e,r){switch(e.type){case"SingletonBeacon":return new Bl(e,r);case"CASBeacon":return new Il(e,r);case"SMTBeacon":return new Pl(e,r);default:throw new we("Invalid Beacon Type","INVALID_BEACON_ERROR",e)}}};l();l();l();l();l();l();var Pi;(function(t){t.authentication="authentication",t.assertionMethod="assertionMethod",t.keyAgreement="keyAgreement",t.capabilityInvocation="capabilityInvocation",t.capabilityDelegation="capabilityDelegation"})(Pi||(Pi={}));l();var yt={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};l();var me=class t{constructor({method:e,id:r,path:n,query:i,fragment:o,params:s}){this.uri=`did:${e}:${r}`,this.method=e,this.id=r,this.path=n,this.query=i,this.fragment=o,this.params=s}static parse(e){if(!e)return null;let r=t.DID_URI_PATTERN.exec(e);if(!r||!r.groups)return null;let{method:n,id:i,path:o,query:s,fragment:c}=r.groups,a={uri:`did:${n}:${i}`,method:n,id:i};if(o&&(a.path=o),s&&(a.query=s.slice(1)),c&&(a.fragment=c.slice(1)),s){let u={},d=s.slice(1).split("&");for(let f of d){let[h,p]=f.split("=");u[h]=p}a.params=u}return a}};me.METHOD_PATTERN="([a-z0-9]+)";me.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})";me.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${me.PCT_ENCODED_PATTERN})`;me.METHOD_ID_PATTERN=`((?:${me.ID_CHAR_PATTERN}*:)*(${me.ID_CHAR_PATTERN}+))`;me.PATH_PATTERN="(/[^#?]*)?";me.QUERY_PATTERN="([?][^#]*)?";me.FRAGMENT_PATTERN="(#.*)?";me.DID_URI_PATTERN=new RegExp(`^did:(?<method>${me.METHOD_PATTERN}):(?<id>${me.METHOD_ID_PATTERN})(?<path>${me.PATH_PATTERN})(?<query>${me.QUERY_PATTERN})(?<fragment>${me.FRAGMENT_PATTERN})$`);l();var re=class t extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,t)}},ie;(function(t){t.InvalidDid="invalidDid",t.MethodNotSupported="methodNotSupported",t.InternalError="internalError",t.InvalidDidDocument="invalidDidDocument",t.InvalidDidDocumentLength="invalidDidDocumentLength",t.InvalidDidUrl="invalidDidUrl",t.InvalidPreviousDidProof="invalidPreviousDidProof",t.InvalidPublicKey="invalidPublicKey",t.InvalidPublicKeyLength="invalidPublicKeyLength",t.InvalidPublicKeyType="invalidPublicKeyType",t.InvalidSignature="invalidSignature",t.NotFound="notFound",t.RepresentationNotSupported="representationNotSupported",t.UnsupportedPublicKeyType="unsupportedPublicKeyType"})(ie||(ie={}));l();l();l();l();l();var u6=Mn(Jv(),1);l();l();l();l();var LH=new Uint8Array(0);function Xv(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function oa(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}l();function f6(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function f(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 y=0,x=0,S=0,_=g.length;S!==_&&g[S]===0;)S++,y++;for(var A=(_-S)*d+1>>>0,O=new Uint8Array(A);S!==_;){for(var T=g[S],M=0,q=A-1;(T!==0||M<x)&&q!==-1;q--,M++)T+=256*O[q]>>>0,O[q]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");x=M,S++}for(var j=A-x;j!==A&&O[j]===0;)j++;for(var $=a.repeat(y);j<A;++j)$+=t.charAt(O[j]);return $}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var x=0,S=0;g[y]===a;)x++,y++;for(var _=(g.length-y)*u+1>>>0,A=new Uint8Array(_);g[y];){var O=r[g.charCodeAt(y)];if(O===255)return;for(var T=0,M=_-1;(O!==0||T<S)&&M!==-1;M--,T++)O+=c*A[M]>>>0,A[M]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");S=T,y++}if(g[y]!==" "){for(var q=_-S;q!==_&&A[q]===0;)q++;for(var j=new Uint8Array(x+(_-q)),$=x;q!==_;)j[$++]=A[q++];return j}}}function p(g){var y=h(g);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var l6=f6,h6=l6,Zv=h6;var G0=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},z0=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Qv(this,e)}},Y0=class{decoders;constructor(e){this.decoders=e}or(e){return Qv(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Qv(t,e){return new Y0({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var J0=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new G0(e,r,n),this.decoder=new z0(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function e1({name:t,prefix:e,encode:r,decode:n}){return new J0(t,e,r,n)}function X0({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=Zv(r,t);return e1({prefix:e,name:t,encode:n,decode:o=>oa(i(o))})}function p6(t,e,r,n){let i={};for(let d=0;d<e.length;++d)i[e[d]]=d;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),c=0,a=0,u=0;for(let d=0;d<o;++d){let f=i[t[d]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,c+=r,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=r||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function y6(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,c=0;for(let a=0;a<t.length;++a)for(c=c<<8|t[a],s+=8;s>r;)s-=r,o+=e[i&c>>s];if(s!==0&&(o+=e[i&c<<r-s]),n)for(;o.length*r&7;)o+="=";return o}function ir({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return e1({prefix:e,name:t,encode(i){return y6(i,n,r)},decode(i){return p6(i,n,r,t)}})}var Qu=ir({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jH=ir({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),WH=ir({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),GH=ir({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zH=ir({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),YH=ir({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),JH=ir({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),XH=ir({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Z0=ir({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});l();var pr=X0({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tV=X0({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});l();var oV=ir({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sV=ir({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xn=ir({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cV=ir({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});l();function t1(t){return t.byteOffset!==0||t.byteLength!==t.buffer.byteLength}function r1(t){return typeof t!="object"||t===null?!1:typeof t[Symbol.asyncIterator]=="function"}function sa(t){let r=Object.prototype.toString.call(t).match(/\s([a-zA-Z0-9]+)/),[n,i]=r;return i}var ed=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},n1=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(c,a){s=t[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(u){o({value:u,done:c})},s)}},Kl=new TextEncoder,Ms=new TextDecoder,ne=class t{constructor(e,r){this.data=e,this.format=r}static arrayBuffer(e){return new t(e,"ArrayBuffer")}static asyncIterable(e){if(!r1(e))throw new TypeError("Input must be of type AsyncIterable.");return new t(e,"AsyncIterable")}static base32Z(e){return new t(e,"Base32Z")}static base58Btc(e){return new t(e,"Base58Btc")}static base64Url(e){return new t(e,"Base64Url")}static bufferSource(e){return new t(e,"BufferSource")}static hex(e){if(typeof e!="string")throw new TypeError("Hex input must be a string.");if(e.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new t(e,"Hex")}static multibase(e){return new t(e,"Multibase")}static object(e){return new t(e,"Object")}static string(e){return new t(e,"String")}static uint8Array(e){return new t(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return pr.baseDecode(this.data).buffer;case"Base64Url":return Xn.baseDecode(this.data).buffer;case"BufferSource":{if(sa(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return t1(this.data)?this.data.buffer.slice(this.data.byteOffset,this.data.byteOffset+this.data.byteLength):this.data.buffer;throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":return this.toUint8Array().buffer;case"String":return this.toUint8Array().buffer;case"Uint8Array":return this.data.buffer;default:throw new TypeError(`Conversion from ${this.format} to ArrayBuffer is not supported.`)}}toArrayBufferAsync(){return ed(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":return yield(yield this.toBlobAsync()).arrayBuffer();default:throw new TypeError(`Asynchronous conversion from ${this.format} to ArrayBuffer is not supported.`)}})}toBase32Z(){switch(this.format){case"Uint8Array":return Z0.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return pr.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return pr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Xn.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return Xn.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),r=Kl.encode(e);return Xn.baseEncode(r)}case"String":{let e=Kl.encode(this.data);return Xn.baseEncode(e)}case"Uint8Array":return Xn.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return ed(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=n1(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let d=i;a.push(d)}}catch(d){r={error:d}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(r,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let r=this.toUint8Array();return t.uint8Array(r).toHex()}case"Base64Url":{let r=this.toUint8Array();return t.uint8Array(r).toHex()}case"Uint8Array":{let r="";for(let n=0;n<this.data.length;n++)r+=e[this.data[n]];return r}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let e=Xn.baseDecode(this.data),r=Ms.decode(e);return JSON.parse(r)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Ms.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return ed(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toStringAsync();return JSON.parse(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return Ms.decode(this.data);case"Base64Url":{let e=Xn.baseDecode(this.data);return Ms.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Ms.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return ed(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=n1(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let u=i;typeof u=="string"?a+=u:a+=Ms.decode(u,{stream:!0})}}catch(u){r={error:u}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return a+=Ms.decode(void 0,{stream:!1}),a}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return Z0.baseDecode(this.data);case"Base58Btc":return pr.baseDecode(this.data);case"Base64Url":return Xn.baseDecode(this.data);case"BufferSource":{let e=sa(this.data);if(e==="Uint8Array")return this.data;if(e==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let e=new Uint8Array(this.data.length/2);for(let r=0;r<this.data.length;r+=2){let n=parseInt(this.data.substring(r,r+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[r/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return Kl.encode(e)}case"String":return Kl.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return ed(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toArrayBufferAsync();return new Uint8Array(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};l();var td;(function(t){t.Debug="debug",t.Silent="silent"})(td||(td={}));var Q0=class{constructor(){this.logLevel=td.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==td.Silent&&console.info(e)}error(e){this.logLevel!==td.Silent&&console.error(e)}},g6=new Q0;typeof window<"u"&&(window.web5logger=g6);l();l();l();l();var Mi={};Tf(Mi,{decode:()=>ca,encodeTo:()=>Ks,encodingLength:()=>$s});l();l();var m6=s1,i1=128,w6=127,b6=~w6,x6=Math.pow(2,31);function s1(t,e,r){e=e||[],r=r||0;for(var n=r;t>=x6;)e[r++]=t&255|i1,t/=128;for(;t&b6;)e[r++]=t&255|i1,t>>>=7;return e[r]=t|0,s1.bytes=r-n+1,e}var E6=eg,v6=128,o1=127;function eg(t,n){var r=0,n=n||0,i=0,o=n,s,c=t.length;do{if(o>=c)throw eg.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&o1)<<i:(s&o1)*Math.pow(2,i),i+=7}while(s>=v6);return eg.bytes=o-n,r}var S6=Math.pow(2,7),A6=Math.pow(2,14),T6=Math.pow(2,21),_6=Math.pow(2,28),I6=Math.pow(2,35),B6=Math.pow(2,42),R6=Math.pow(2,49),U6=Math.pow(2,56),O6=Math.pow(2,63),D6=function(t){return t<S6?1:t<A6?2:t<T6?3:t<_6?4:t<I6?5:t<B6?6:t<R6?7:t<U6?8:t<O6?9:10},k6={encode:m6,decode:E6,encodingLength:D6},N6=k6,rd=N6;function ca(t,e=0){return[rd.decode(t,e),rd.decode.bytes]}function Ks(t,e,r=0){return rd.encode(t,e,r),e}function $s(t){return rd.encodingLength(t)}function tg(t,e){let r=e.byteLength,n=$s(t),i=n+$s(r),o=new Uint8Array(i+r);return Ks(t,o,0),Ks(r,o,n),o.set(e,i),new aa(t,r,e,o)}function c1(t){let e=oa(t),[r,n]=ca(e),[i,o]=ca(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new aa(r,i,s,e)}function a1(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Xv(t.bytes,r.bytes)}}var aa=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};l();function u1(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return L6(r,ng(t),e??pr.encoder);default:return P6(r,ng(t),e??Qu.encoder)}}var d1=new WeakMap;function ng(t){let e=d1.get(t);if(e==null){let r=new Map;return d1.set(t,r),r}return e}var ig=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==nd)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==M6)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=tg(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&a1(e.multihash,n.multihash)}toString(e){return u1(this,e)}toJSON(){return{"/":u1(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??f1(n,i,o.bytes))}else if(r[K6]===!0){let{version:n,multihash:i,code:o}=r,s=c1(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==nd)throw new Error(`Version 0 CID must use dag-pb (code: ${nd}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=f1(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,nd,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=oa(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new aa(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,h]=ca(e.subarray(r));return r+=h,f},i=n(),o=nd;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,c=n(),a=n(),u=r+a,d=u-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(e,r){let[n,i]=C6(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ng(o).set(n,e),o}};function C6(t,e){switch(t[0]){case"Q":{let r=e??pr;return[pr.prefix,r.decode(`${pr.prefix}${t}`)]}case pr.prefix:{let r=e??pr;return[pr.prefix,r.decode(t)]}case Qu.prefix:{let r=e??Qu;return[Qu.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function L6(t,e,r){let{prefix:n}=r;if(n!==pr.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function P6(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var nd=112,M6=18;function f1(t,e,r){let n=$s(t),i=n+$s(e),o=new Uint8Array(i+r.byteLength);return Ks(t,o,0),Ks(e,o,n),o.set(r,i),o}var K6=Symbol.for("@ipld/js-cid/CID");l();l();l();l();l();l();var Yt=class t{static addPrefix(e){var r;let{code:n,data:i,name:o}=e;if(!(o?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=t.codeToName.has(n)?n:t.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(r=e.name)!==null&&r!==void 0?r:e.code}`);let s=Mi.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),Mi.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:r}=e,[n,i]=Mi.decode(r);return n}static getCodeFromName(e){let{name:r}=e,n=t.nameToCode.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static getNameFromCode(e){let{code:r}=e,n=t.codeToName.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static registerCodec(e){t.codeToName.set(e.code,e.name),t.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:r}=e,[n,i]=Mi.decode(r),o=t.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:r.slice(i),name:o}}};Yt.codeToName=new Map;Yt.nameToCode=new Map;Yt.registerCodec({code:237,name:"ed25519-pub"});Yt.registerCodec({code:4864,name:"ed25519-priv"});Yt.registerCodec({code:236,name:"x25519-pub"});Yt.registerCodec({code:4866,name:"x25519-priv"});Yt.registerCodec({code:231,name:"secp256k1-pub"});Yt.registerCodec({code:4865,name:"secp256k1-priv"});l();function og(t){Object.keys(t).forEach(e=>{t[e]===void 0?delete t[e]:typeof t[e]=="object"&&og(t[e])})}l();var WU=Mn(Xg(),1),tc=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})};var hh=class{constructor(){this.store=new Map}clear(){return tc(this,void 0,void 0,function*(){this.store.clear()})}close(){return tc(this,void 0,void 0,function*(){})}delete(e){return tc(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return tc(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return tc(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return tc(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,r){return tc(this,void 0,void 0,function*(){this.store.set(e,r)})}};l();l();var u4=Mn(uw(),1);var d4=Mn(uw(),1);l();l();l();l();l();function f4(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function dw(t,...e){if(!f4(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function fw(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function wT(t,e){dw(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}l();l();var Na=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Wh=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),In=(t,e)=>t<<32-e|t>>>e;var kj=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function l4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function lw(t){return typeof t=="string"&&(t=l4(t)),dw(t),t}var jh=class{clone(){return this._cloneInto()}},Nj={}.toString;function bT(t){let e=n=>t().update(lw(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function xT(t=32){if(Na&&typeof Na.getRandomValues=="function")return Na.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function h4(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}var ET=(t,e,r)=>t&e^~t&r,vT=(t,e,r)=>t&e^t&r^e&r,Gh=class extends jh{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Wh(this.buffer)}update(e){fw(this);let{view:r,buffer:n,blockLen:i}=this;e=lw(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Wh(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){fw(this),wT(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;h4(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Wh(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var p4=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wo=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Go=new Uint32Array(64),hw=class extends Gh{constructor(){super(64,32,8,!1),this.A=Wo[0]|0,this.B=Wo[1]|0,this.C=Wo[2]|0,this.D=Wo[3]|0,this.E=Wo[4]|0,this.F=Wo[5]|0,this.G=Wo[6]|0,this.H=Wo[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)Go[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=Go[f-15],p=Go[f-2],g=In(h,7)^In(h,18)^h>>>3,y=In(p,17)^In(p,19)^p>>>10;Go[f]=y+Go[f-7]+g+Go[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=In(c,6)^In(c,11)^In(c,25),p=d+h+ET(c,a,u)+p4[f]+Go[f]|0,y=(In(n,2)^In(n,13)^In(n,22))+vT(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Go.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var zo=bT(()=>new hw);var y4=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Ca=class{static digest(e){return y4(this,arguments,void 0,function*({data:r}){return zo(r)})}};l();var ci=class{};var g4=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},zh=class extends ci{digest(e){return g4(this,arguments,void 0,function*({algorithm:r,data:n}){switch(r){case"SHA-256":return yield Ca.digest({data:n})}})}};l();l();l();l();l();l();function ST(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function m4(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function pw(t,...e){if(!m4(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function AT(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ST(t.outputLen),ST(t.blockLen)}function La(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function TT(t,e){pw(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}l();l();var Yh=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _T(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Jh=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Bn=(t,e)=>t<<32-e|t>>>e,w4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!w4)throw new Error("Non little-endian hardware is not supported");function yw(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Ld(t){if(typeof t=="string"&&(t=yw(t)),!_T(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Xh(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!_T(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var Pa=class{clone(){return this._cloneInto()}},oW={}.toString;function Zh(t){let e=n=>t().update(Ld(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Pd(t=32){if(Yh&&typeof Yh.getRandomValues=="function")return Yh.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function b4(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}var Ma=class extends Pa{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Jh(this.buffer)}update(e){La(this);let{view:r,buffer:n,blockLen:i}=this;e=Ld(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Jh(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){La(this),TT(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;b4(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Jh(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var x4=(t,e,r)=>t&e^~t&r,E4=(t,e,r)=>t&e^t&r^e&r,v4=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Yo=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Jo=new Uint32Array(64),gw=class extends Ma{constructor(){super(64,32,8,!1),this.A=Yo[0]|0,this.B=Yo[1]|0,this.C=Yo[2]|0,this.D=Yo[3]|0,this.E=Yo[4]|0,this.F=Yo[5]|0,this.G=Yo[6]|0,this.H=Yo[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)Jo[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=Jo[f-15],p=Jo[f-2],g=Bn(h,7)^Bn(h,18)^h>>>3,y=Bn(p,17)^Bn(p,19)^p>>>10;Jo[f]=y+Jo[f-7]+g+Jo[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=Bn(c,6)^Bn(c,11)^Bn(c,25),p=d+h+x4(c,a,u)+v4[f]+Jo[f]|0,y=(Bn(n,2)^Bn(n,13)^Bn(n,22))+E4(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Jo.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Qh=Zh(()=>new gw);l();var tp={};Tf(tp,{bitGet:()=>R4,bitLen:()=>B4,bitMask:()=>Md,bitSet:()=>U4,bytesToHex:()=>Xi,bytesToNumberBE:()=>Zi,bytesToNumberLE:()=>Un,concatBytes:()=>eo,createHmacDrbg:()=>bw,ensureBytes:()=>Ge,equalBytes:()=>_4,hexToBytes:()=>hc,hexToNumber:()=>ww,isBytes:()=>Rn,numberToBytesBE:()=>gr,numberToBytesLE:()=>Qi,numberToHexUnpadded:()=>UT,numberToVarBytesBE:()=>T4,utf8ToBytes:()=>I4,validateObject:()=>nn});l();var RT=BigInt(0),ep=BigInt(1),S4=BigInt(2);function Rn(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var A4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Xi(t){if(!Rn(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=A4[t[r]];return e}function UT(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function ww(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var Ji={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function IT(t){if(t>=Ji._0&&t<=Ji._9)return t-Ji._0;if(t>=Ji._A&&t<=Ji._F)return t-(Ji._A-10);if(t>=Ji._a&&t<=Ji._f)return t-(Ji._a-10)}function hc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=IT(t.charCodeAt(o)),c=IT(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function Zi(t){return ww(Xi(t))}function Un(t){if(!Rn(t))throw new Error("Uint8Array expected");return ww(Xi(Uint8Array.from(t).reverse()))}function gr(t,e){return hc(t.toString(16).padStart(e*2,"0"))}function Qi(t,e){return gr(t,e).reverse()}function T4(t){return hc(UT(t))}function Ge(t,e,r){let n;if(typeof e=="string")try{n=hc(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Rn(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function eo(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!Rn(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let o=t[i];r.set(o,n),n+=o.length}return r}function _4(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function I4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function B4(t){let e;for(e=0;t>RT;t>>=ep,e+=1);return e}function R4(t,e){return t>>BigInt(e)&ep}var U4=(t,e,r)=>t|(r?ep:RT)<<BigInt(e),Md=t=>(S4<<BigInt(t-1))-ep,mw=t=>new Uint8Array(t),BT=t=>Uint8Array.from(t);function bw(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=mw(t),i=mw(t),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...f)=>r(i,n,...f),a=(f=mw())=>{i=c(BT([0]),f),n=c(),f.length!==0&&(i=c(BT([1]),f),n=c())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=c();let p=n.slice();h.push(p),f+=n.length}return eo(...h)};return(f,h)=>{s(),a(f);let p;for(;!(p=h(u()));)a();return s(),p}}var O4={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Rn(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function nn(t,e,r={}){let n=(i,o,s)=>{let c=O4[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let a=t[i];if(!(s&&a===void 0)&&!c(a,t))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return t}var It=BigInt(0),et=BigInt(1),pc=BigInt(2),D4=BigInt(3),xw=BigInt(4),OT=BigInt(5),DT=BigInt(8),k4=BigInt(9),N4=BigInt(16);function Be(t,e){let r=t%e;return r>=It?r:e+r}function Ew(t,e,r){if(r<=It||e<It)throw new Error("Expected power/modulo > 0");if(r===et)return It;let n=et;for(;e>It;)e&et&&(n=n*t%r),t=t*t%r,e>>=et;return n}function ze(t,e,r){let n=t;for(;e-- >It;)n*=n,n%=r;return n}function rp(t,e){if(t===It||e<=It)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Be(t,e),n=e,i=It,o=et,s=et,c=It;for(;r!==It;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==et)throw new Error("invert: does not exist");return Be(i,e)}function C4(t){let e=(t-et)/pc,r,n,i;for(r=t-et,n=0;r%pc===It;r/=pc,n++);for(i=pc;i<t&&Ew(i,e,t)!==t-et;i++);if(n===1){let s=(t+et)/xw;return function(a,u){let d=a.pow(u,s);if(!a.eql(a.sqr(d),u))throw new Error("Cannot find square root");return d}}let o=(r+et)/pc;return function(c,a){if(c.pow(a,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,d=c.pow(c.mul(c.ONE,i),r),f=c.pow(a,o),h=c.pow(a,r);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let p=1;for(let y=c.sqr(h);p<u&&!c.eql(y,c.ONE);p++)y=c.sqr(y);let g=c.pow(d,et<<BigInt(u-p-1));d=c.sqr(g),f=c.mul(f,g),h=c.mul(h,d),u=p}return f}}function L4(t){if(t%xw===D4){let e=(t+et)/xw;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(t%DT===OT){let e=(t-OT)/DT;return function(n,i){let o=n.mul(i,pc),s=n.pow(o,e),c=n.mul(i,s),a=n.mul(n.mul(c,pc),s),u=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return t%N4,C4(t)}var kT=(t,e)=>(Be(t,e)&et)===et,P4=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vw(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=P4.reduce((n,i)=>(n[i]="function",n),e);return nn(t,r)}function M4(t,e,r){if(r<It)throw new Error("Expected power > 0");if(r===It)return t.ONE;if(r===et)return e;let n=t.ONE,i=e;for(;r>It;)r&et&&(n=t.mul(n,i)),i=t.sqr(i),r>>=et;return n}function K4(t,e){let r=new Array(e.length),n=e.reduce((o,s,c)=>t.is0(s)?o:(r[c]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,c)=>t.is0(s)?o:(r[c]=t.mul(o,r[c]),t.mul(o,s)),i),r}function Sw(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Ka(t,e,r=!1,n={}){if(t<=It)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=Sw(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=L4(t),c=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:Md(i),ZERO:It,ONE:et,create:a=>Be(a,t),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return It<=a&&a<t},is0:a=>a===It,isOdd:a=>(a&et)===et,neg:a=>Be(-a,t),eql:(a,u)=>a===u,sqr:a=>Be(a*a,t),add:(a,u)=>Be(a+u,t),sub:(a,u)=>Be(a-u,t),mul:(a,u)=>Be(a*u,t),pow:(a,u)=>M4(c,a,u),div:(a,u)=>Be(a*rp(u,t),t),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>rp(a,t),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>K4(c,a),cmov:(a,u,d)=>d?u:a,toBytes:a=>r?Qi(a,o):gr(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return r?Un(a):Zi(a)}});return Object.freeze(c)}function NT(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function CT(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Aw(t){let e=CT(t);return e+Math.ceil(e/2)}function LT(t,e,r=!1){let n=t.length,i=CT(e),o=Aw(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=r?Zi(t):Un(t),c=Be(s,e-et)+et;return r?Qi(c,i):gr(c,i)}l();l();var H4=BigInt(0),Tw=BigInt(1);function np(t,e){let r=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,o){let s=t.ZERO,c=i;for(;o>H4;)o&Tw&&(s=s.add(c)),c=c.double(),o>>=Tw;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),a=[],u=i,d=u;for(let f=0;f<s;f++){d=u,a.push(d);for(let h=1;h<c;h++)d=d.add(u),a.push(d);u=d.double()}return a},wNAF(i,o,s){let{windows:c,windowSize:a}=n(i),u=t.ZERO,d=t.BASE,f=BigInt(2**i-1),h=2**i,p=BigInt(i);for(let g=0;g<c;g++){let y=g*a,x=Number(s&f);s>>=p,x>a&&(x-=h,s+=Tw);let S=y,_=y+Math.abs(x)-1,A=g%2!==0,O=x<0;x===0?d=d.add(r(A,o[S])):u=u.add(r(O,o[_]))}return{p:u,f:d}},wNAFCached(i,o,s,c){let a=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&o.set(i,c(u))),this.wNAF(a,u,s)}}}function Kd(t){return vw(t.Fp),nn(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Sw(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function V4(t){let e=Kd(t);nn(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:q4,hexToBytes:F4}=tp,yc={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){let{Err:e}=yc;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");let r=t[1],n=t.subarray(2,r+2);if(!r||n.length!==r)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:q4(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=yc,r=typeof t=="string"?F4(t):t;if(!Rn(r))throw new Error("ui8a expected");let n=r.length;if(n<2||r[0]!=48)throw new e("Invalid signature tag");if(r[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=yc._parseInt(r.subarray(2)),{d:s,l:c}=yc._parseInt(o);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,r=u=>{let d=u.toString(16);return d.length&1?`0${d}`:d},n=e(r(t.s)),i=e(r(t.r)),o=n.length/2,s=i.length/2,c=r(o),a=r(s);return`30${r(s+o+4)}02${a}${i}02${c}${n}`}},to=BigInt(0),on=BigInt(1),_W=BigInt(2),PT=BigInt(3),IW=BigInt(4);function j4(t){let e=V4(t),{Fp:r}=e,n=e.toBytes||((g,y,x)=>{let S=y.toAffine();return eo(Uint8Array.from([4]),r.toBytes(S.x),r.toBytes(S.y))}),i=e.fromBytes||(g=>{let y=g.subarray(1),x=r.fromBytes(y.subarray(0,r.BYTES)),S=r.fromBytes(y.subarray(r.BYTES,2*r.BYTES));return{x,y:S}});function o(g){let{a:y,b:x}=e,S=r.sqr(g),_=r.mul(S,g);return r.add(r.add(_,r.mul(g,y)),x)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&to<g&&g<e.n}function c(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(g){let{allowedPrivateKeyLengths:y,nByteLength:x,wrapPrivateKey:S,n:_}=e;if(y&&typeof g!="bigint"){if(Rn(g)&&(g=Xi(g)),typeof g!="string"||!y.includes(g.length))throw new Error("Invalid key");g=g.padStart(x*2,"0")}let A;try{A=typeof g=="bigint"?g:Zi(Ge("private key",g,x))}catch{throw new Error(`private key must be ${x} bytes, hex or bigint, not ${typeof g}`)}return S&&(A=Be(A,_)),c(A),A}let u=new Map;function d(g){if(!(g instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(y,x,S){if(this.px=y,this.py=x,this.pz=S,y==null||!r.isValid(y))throw new Error("x required");if(x==null||!r.isValid(x))throw new Error("y required");if(S==null||!r.isValid(S))throw new Error("z required")}static fromAffine(y){let{x,y:S}=y||{};if(!y||!r.isValid(x)||!r.isValid(S))throw new Error("invalid affine point");if(y instanceof f)throw new Error("projective point not allowed");let _=A=>r.eql(A,r.ZERO);return _(x)&&_(S)?f.ZERO:new f(x,S,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){let x=r.invertBatch(y.map(S=>S.pz));return y.map((S,_)=>S.toAffine(x[_])).map(f.fromAffine)}static fromHex(y){let x=f.fromAffine(i(Ge("pointHex",y)));return x.assertValidity(),x}static fromPrivateKey(y){return f.BASE.multiply(a(y))}_setWindowSize(y){this._WINDOW_SIZE=y,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:y,y:x}=this.toAffine();if(!r.isValid(y)||!r.isValid(x))throw new Error("bad point: x or y not FE");let S=r.sqr(x),_=o(y);if(!r.eql(S,_))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(r.isOdd)return!r.isOdd(y);throw new Error("Field doesn't support isOdd")}equals(y){d(y);let{px:x,py:S,pz:_}=this,{px:A,py:O,pz:T}=y,M=r.eql(r.mul(x,T),r.mul(A,_)),q=r.eql(r.mul(S,T),r.mul(O,_));return M&&q}negate(){return new f(this.px,r.neg(this.py),this.pz)}double(){let{a:y,b:x}=e,S=r.mul(x,PT),{px:_,py:A,pz:O}=this,T=r.ZERO,M=r.ZERO,q=r.ZERO,j=r.mul(_,_),$=r.mul(A,A),Z=r.mul(O,O),Q=r.mul(_,A);return Q=r.add(Q,Q),q=r.mul(_,O),q=r.add(q,q),T=r.mul(y,q),M=r.mul(S,Z),M=r.add(T,M),T=r.sub($,M),M=r.add($,M),M=r.mul(T,M),T=r.mul(Q,T),q=r.mul(S,q),Z=r.mul(y,Z),Q=r.sub(j,Z),Q=r.mul(y,Q),Q=r.add(Q,q),q=r.add(j,j),j=r.add(q,j),j=r.add(j,Z),j=r.mul(j,Q),M=r.add(M,j),Z=r.mul(A,O),Z=r.add(Z,Z),j=r.mul(Z,Q),T=r.sub(T,j),q=r.mul(Z,$),q=r.add(q,q),q=r.add(q,q),new f(T,M,q)}add(y){d(y);let{px:x,py:S,pz:_}=this,{px:A,py:O,pz:T}=y,M=r.ZERO,q=r.ZERO,j=r.ZERO,$=e.a,Z=r.mul(e.b,PT),Q=r.mul(x,A),G=r.mul(S,O),I=r.mul(_,T),D=r.add(x,S),E=r.add(A,O);D=r.mul(D,E),E=r.add(Q,G),D=r.sub(D,E),E=r.add(x,_);let U=r.add(A,T);return E=r.mul(E,U),U=r.add(Q,I),E=r.sub(E,U),U=r.add(S,_),M=r.add(O,T),U=r.mul(U,M),M=r.add(G,I),U=r.sub(U,M),j=r.mul($,E),M=r.mul(Z,I),j=r.add(M,j),M=r.sub(G,j),j=r.add(G,j),q=r.mul(M,j),G=r.add(Q,Q),G=r.add(G,Q),I=r.mul($,I),E=r.mul(Z,E),G=r.add(G,I),I=r.sub(Q,I),I=r.mul($,I),E=r.add(E,I),Q=r.mul(G,E),q=r.add(q,Q),Q=r.mul(U,E),M=r.mul(D,M),M=r.sub(M,Q),Q=r.mul(D,G),j=r.mul(U,j),j=r.add(j,Q),new f(M,q,j)}subtract(y){return this.add(y.negate())}is0(){return this.equals(f.ZERO)}wNAF(y){return p.wNAFCached(this,u,y,x=>{let S=r.invertBatch(x.map(_=>_.pz));return x.map((_,A)=>_.toAffine(S[A])).map(f.fromAffine)})}multiplyUnsafe(y){let x=f.ZERO;if(y===to)return x;if(c(y),y===on)return this;let{endo:S}=e;if(!S)return p.unsafeLadder(this,y);let{k1neg:_,k1:A,k2neg:O,k2:T}=S.splitScalar(y),M=x,q=x,j=this;for(;A>to||T>to;)A&on&&(M=M.add(j)),T&on&&(q=q.add(j)),j=j.double(),A>>=on,T>>=on;return _&&(M=M.negate()),O&&(q=q.negate()),q=new f(r.mul(q.px,S.beta),q.py,q.pz),M.add(q)}multiply(y){c(y);let x=y,S,_,{endo:A}=e;if(A){let{k1neg:O,k1:T,k2neg:M,k2:q}=A.splitScalar(x),{p:j,f:$}=this.wNAF(T),{p:Z,f:Q}=this.wNAF(q);j=p.constTimeNegate(O,j),Z=p.constTimeNegate(M,Z),Z=new f(r.mul(Z.px,A.beta),Z.py,Z.pz),S=j.add(Z),_=$.add(Q)}else{let{p:O,f:T}=this.wNAF(x);S=O,_=T}return f.normalizeZ([S,_])[0]}multiplyAndAddUnsafe(y,x,S){let _=f.BASE,A=(T,M)=>M===to||M===on||!T.equals(_)?T.multiplyUnsafe(M):T.multiply(M),O=A(this,x).add(A(y,S));return O.is0()?void 0:O}toAffine(y){let{px:x,py:S,pz:_}=this,A=this.is0();y==null&&(y=A?r.ONE:r.inv(_));let O=r.mul(x,y),T=r.mul(S,y),M=r.mul(_,y);if(A)return{x:r.ZERO,y:r.ZERO};if(!r.eql(M,r.ONE))throw new Error("invZ was invalid");return{x:O,y:T}}isTorsionFree(){let{h:y,isTorsionFree:x}=e;if(y===on)return!0;if(x)return x(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:y,clearCofactor:x}=e;return y===on?this:x?x(f,this):this.multiplyUnsafe(e.h)}toRawBytes(y=!0){return this.assertValidity(),n(f,this,y)}toHex(y=!0){return Xi(this.toRawBytes(y))}}f.BASE=new f(e.Gx,e.Gy,r.ONE),f.ZERO=new f(r.ZERO,r.ONE,r.ZERO);let h=e.nBitLength,p=np(f,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function W4(t){let e=Kd(t);return nn(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function MT(t){let e=W4(t),{Fp:r,n}=e,i=r.BYTES+1,o=2*r.BYTES+1;function s(E){return to<E&&E<r.ORDER}function c(E){return Be(E,n)}function a(E){return rp(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:d,weierstrassEquation:f,isWithinCurveOrder:h}=j4({...e,toBytes(E,U,L){let N=U.toAffine(),R=r.toBytes(N.x),C=eo;return L?C(Uint8Array.from([U.hasEvenY()?2:3]),R):C(Uint8Array.from([4]),R,r.toBytes(N.y))},fromBytes(E){let U=E.length,L=E[0],N=E.subarray(1);if(U===i&&(L===2||L===3)){let R=Zi(N);if(!s(R))throw new Error("Point is not on curve");let C=f(R),P=r.sqrt(C),V=(P&on)===on;return(L&1)===1!==V&&(P=r.neg(P)),{x:R,y:P}}else if(U===o&&L===4){let R=r.fromBytes(N.subarray(0,r.BYTES)),C=r.fromBytes(N.subarray(r.BYTES,2*r.BYTES));return{x:R,y:C}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),p=E=>Xi(gr(E,e.nByteLength));function g(E){let U=n>>on;return E>U}function y(E){return g(E)?c(-E):E}let x=(E,U,L)=>Zi(E.slice(U,L));class S{constructor(U,L,N){this.r=U,this.s=L,this.recovery=N,this.assertValidity()}static fromCompact(U){let L=e.nByteLength;return U=Ge("compactSignature",U,L*2),new S(x(U,0,L),x(U,L,2*L))}static fromDER(U){let{r:L,s:N}=yc.toSig(Ge("DER",U));return new S(L,N)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(U){return new S(this.r,this.s,U)}recoverPublicKey(U){let{r:L,s:N,recovery:R}=this,C=q(Ge("msgHash",U));if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");let P=R===2||R===3?L+e.n:L;if(P>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let V=R&1?"03":"02",J=u.fromHex(V+p(P)),z=a(P),W=c(-C*z),Y=c(N*z),X=u.BASE.multiplyAndAddUnsafe(J,W,Y);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new S(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return hc(this.toDERHex())}toDERHex(){return yc.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hc(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let _={isValidPrivateKey(E){try{return d(E),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let E=Aw(e.n);return LT(e.randomBytes(E),e.n)},precompute(E=8,U=u.BASE){return U._setWindowSize(E),U.multiply(BigInt(3)),U}};function A(E,U=!0){return u.fromPrivateKey(E).toRawBytes(U)}function O(E){let U=Rn(E),L=typeof E=="string",N=(U||L)&&E.length;return U?N===i||N===o:L?N===2*i||N===2*o:E instanceof u}function T(E,U,L=!0){if(O(E))throw new Error("first arg must be private key");if(!O(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(d(E)).toRawBytes(L)}let M=e.bits2int||function(E){let U=Zi(E),L=E.length*8-e.nBitLength;return L>0?U>>BigInt(L):U},q=e.bits2int_modN||function(E){return c(M(E))},j=Md(e.nBitLength);function $(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(to<=E&&E<j))throw new Error(`bigint expected < 2^${e.nBitLength}`);return gr(E,e.nByteLength)}function Z(E,U,L=Q){if(["recovered","canonical"].some(ee=>ee in L))throw new Error("sign() legacy options not supported");let{hash:N,randomBytes:R}=e,{lowS:C,prehash:P,extraEntropy:V}=L;C==null&&(C=!0),E=Ge("msgHash",E),P&&(E=Ge("prehashed msgHash",N(E)));let J=q(E),z=d(U),W=[$(z),$(J)];if(V!=null){let ee=V===!0?R(r.BYTES):V;W.push(Ge("extraEntropy",ee))}let Y=eo(...W),X=J;function ue(ee){let ce=M(ee);if(!h(ce))return;let Ue=a(ce),Ke=u.BASE.multiply(ce).toAffine(),Je=c(Ke.x);if(Je===to)return;let xt=c(Ue*c(X+Je*z));if(xt===to)return;let pi=(Ke.x===Je?0:2)|Number(Ke.y&on),fo=xt;return C&&g(xt)&&(fo=y(xt),pi^=1),new S(Je,fo,pi)}return{seed:Y,k2sig:ue}}let Q={lowS:e.lowS,prehash:!1},G={lowS:e.lowS,prehash:!1};function I(E,U,L=Q){let{seed:N,k2sig:R}=Z(E,U,L),C=e;return bw(C.hash.outputLen,C.nByteLength,C.hmac)(N,R)}u.BASE._setWindowSize(8);function D(E,U,L,N=G){let R=E;if(U=Ge("msgHash",U),L=Ge("publicKey",L),"strict"in N)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:P}=N,V,J;try{if(typeof R=="string"||Rn(R))try{V=S.fromDER(R)}catch(Ke){if(!(Ke instanceof yc.Err))throw Ke;V=S.fromCompact(R)}else if(typeof R=="object"&&typeof R.r=="bigint"&&typeof R.s=="bigint"){let{r:Ke,s:Je}=R;V=new S(Ke,Je)}else throw new Error("PARSE");J=u.fromHex(L)}catch(Ke){if(Ke.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&V.hasHighS())return!1;P&&(U=e.hash(U));let{r:z,s:W}=V,Y=q(U),X=a(W),ue=c(Y*X),ee=c(z*X),ce=u.BASE.multiplyAndAddUnsafe(J,ue,ee)?.toAffine();return ce?c(ce.x)===z:!1}return{CURVE:e,getPublicKey:A,getSharedSecret:T,sign:I,verify:D,ProjectivePoint:u,Signature:S,utils:_}}l();l();var ip=class extends Pa{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,AT(e);let n=Ld(r);if(this.iHash=e.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;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return La(this),this.iHash.update(e),this}digestInto(e){La(this),pw(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},_w=(t,e,r)=>new ip(t,e).update(r).digest();_w.create=(t,e)=>new ip(t,e);function G4(t){return{hash:t,hmac:(e,...r)=>_w(t,e,Xh(...r)),randomBytes:Pd}}function op(t,e){let r=n=>MT({...t,...G4(n)});return Object.freeze({...r(e),create:r})}var HT=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),KT=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),z4=BigInt(1),Iw=BigInt(2),$T=(t,e)=>(t+e/Iw)/e;function Y4(t){let e=HT,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=ze(d,r,e)*d%e,h=ze(f,r,e)*d%e,p=ze(h,Iw,e)*u%e,g=ze(p,i,e)*p%e,y=ze(g,o,e)*g%e,x=ze(y,c,e)*y%e,S=ze(x,a,e)*x%e,_=ze(S,c,e)*y%e,A=ze(_,r,e)*d%e,O=ze(A,s,e)*g%e,T=ze(O,n,e)*u%e,M=ze(T,Iw,e);if(!Bw.eql(Bw.sqr(M),t))throw new Error("Cannot find square root");return M}var Bw=Ka(HT,void 0,void 0,{sqrt:Y4}),mr=op({a:BigInt(0),b:BigInt(7),Fp:Bw,n:KT,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=KT,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-z4*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),c=$T(o*t,e),a=$T(-n*t,e),u=Be(t-c*r-a*i,e),d=Be(-c*n-a*o,e),f=u>s,h=d>s;if(f&&(u=e-u),h&&(d=e-d),u>s||d>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}}},Qh),VW=BigInt(0);var qW=mr.ProjectivePoint;l();l();function VT(t){let e=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=e(n[s]);return o}return n},r=e(t);return JSON.stringify(r)}var J4=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Rw="urn:jwk:";function ge(t){return J4(this,arguments,void 0,function*({jwk:e}){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);og(n);let i=VT(n),o=ne.string(i).toUint8Array(),s=yield Ca.digest({data:o});return ne.uint8Array(s).toBase64Url()})}function ai(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="EC"||typeof t.d!="string"||typeof t.x!="string")}function $a(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t)||"d"in t||t.kty!=="EC"||typeof t.x!="string")}function ui(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="OKP"||typeof t.d!="string"||typeof t.x!="string")}function Ha(t){return!(!t||typeof t!="object"||"d"in t||!("kty"in t&&"crv"in t&&"x"in t)||t.kty!=="OKP"||typeof t.x!="string")}function qT(t){if(!t||typeof t!="object")return!1;switch(t.kty){case"EC":case"OKP":case"RSA":return"d"in t;case"oct":return"k"in t;default:return!1}}var $t=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},X4=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},kt=class t{static adjustSignatureToLowS(e){return $t(this,arguments,void 0,function*({signature:r}){let n=mr.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return $t(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static bytesToPublicKey(e){return $t(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static compressPublicKey(e){return $t(this,arguments,void 0,function*({publicKeyBytes:r}){return mr.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return $t(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=yield t.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"secp256k1",x:ne.uint8Array(i.x).toBase64Url(),y:ne.uint8Array(i.y).toBase64Url()};return o.kid=yield ge({jwk:o}),o})}static convertDerToCompactSignature(e){return $t(this,arguments,void 0,function*({derSignature:r}){return mr.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return $t(this,arguments,void 0,function*({publicKeyBytes:r}){return mr.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return $t(this,void 0,void 0,function*(){let e=mr.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield ge({jwk:r}),r})}static getPublicKey(e){return $t(this,arguments,void 0,function*({key:r}){var n;if(!(ai(r)&&r.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=r,o=X4(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield ge({jwk:o})),o})}static privateKeyToBytes(e){return $t(this,arguments,void 0,function*({privateKey:r}){if(!ai(r))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return $t(this,arguments,void 0,function*({publicKey:r}){if(!($a(r)&&r.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=ne.base64Url(r.x).toUint8Array(),o=ne.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return $t(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return mr.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return $t(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=zo(r);return mr.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return $t(this,arguments,void 0,function*({privateKeyBytes:r}){return mr.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return $t(this,arguments,void 0,function*({publicKeyBytes:r}){try{mr.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return $t(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=zo(i);return mr.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return $t(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=mr.getPublicKey(r));let n=mr.ProjectivePoint.fromHex(r),i=gr(n.x,32),o=gr(n.y,32);return{x:i,y:o}})}};l();l();var FT=Ka(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),Z4=FT.create(BigInt("-3")),Q4=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),eN=op({a:Z4,b:Q4,Fp:FT,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Qh),Lr=eN;var Ht=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},tN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Vt=class t{static adjustSignatureToLowS(e){return Ht(this,arguments,void 0,function*({signature:r}){let n=Lr.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return Ht(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static bytesToPublicKey(e){return Ht(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static compressPublicKey(e){return Ht(this,arguments,void 0,function*({publicKeyBytes:r}){return Lr.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return Ht(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=yield t.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"P-256",x:ne.uint8Array(i.x).toBase64Url(),y:ne.uint8Array(i.y).toBase64Url()};return o.kid=yield ge({jwk:o}),o})}static convertDerToCompactSignature(e){return Ht(this,arguments,void 0,function*({derSignature:r}){return Lr.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return Ht(this,arguments,void 0,function*({publicKeyBytes:r}){return Lr.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return Ht(this,void 0,void 0,function*(){let e=Lr.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield ge({jwk:r}),r})}static getPublicKey(e){return Ht(this,arguments,void 0,function*({key:r}){var n;if(!(ai(r)&&r.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=r,o=tN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield ge({jwk:o})),o})}static privateKeyToBytes(e){return Ht(this,arguments,void 0,function*({privateKey:r}){if(!ai(r))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Ht(this,arguments,void 0,function*({publicKey:r}){if(!($a(r)&&r.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=ne.base64Url(r.x).toUint8Array(),o=ne.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return Ht(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return Lr.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return Ht(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=zo(r);return Lr.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ht(this,arguments,void 0,function*({privateKeyBytes:r}){return Lr.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return Ht(this,arguments,void 0,function*({publicKeyBytes:r}){try{Lr.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Ht(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=zo(i);return Lr.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Ht(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=Lr.getPublicKey(r));let n=Lr.ProjectivePoint.fromHex(r),i=gr(n.x,32),o=gr(n.y,32);return{x:i,y:o}})}};var $d=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Hd=class extends ci{computePublicKey(e){return $d(this,arguments,void 0,function*({key:r}){if(!ai(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":{let n=yield kt.computePublicKey({key:r});return n.alg="ES256K",n}case"P-256":{let n=yield Vt.computePublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return $d(this,arguments,void 0,function*({algorithm:r}){switch(r){case"ES256K":case"secp256k1":{let n=yield kt.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield Vt.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return $d(this,arguments,void 0,function*({key:r}){if(!ai(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":{let n=yield kt.getPublicKey({key:r});return n.alg="ES256K",n}case"P-256":{let n=yield Vt.getPublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return $d(this,arguments,void 0,function*({key:r,data:n}){if(!ai(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":return yield kt.sign({key:r,data:n});case"P-256":return yield Vt.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return $d(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!$a(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(r.crv){case"secp256k1":return yield kt.verify({key:r,signature:n,data:i});case"P-256":return yield Vt.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};l();l();l();l();l();var sp=BigInt(4294967295),Uw=BigInt(32);function jT(t,e=!1){return e?{h:Number(t&sp),l:Number(t>>Uw&sp)}:{h:Number(t>>Uw&sp)|0,l:Number(t&sp)|0}}function rN(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=jT(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var nN=(t,e)=>BigInt(t>>>0)<<Uw|BigInt(e>>>0),iN=(t,e,r)=>t>>>r,oN=(t,e,r)=>t<<32-r|e>>>r,sN=(t,e,r)=>t>>>r|e<<32-r,cN=(t,e,r)=>t<<32-r|e>>>r,aN=(t,e,r)=>t<<64-r|e>>>r-32,uN=(t,e,r)=>t>>>r-32|e<<64-r,dN=(t,e)=>e,fN=(t,e)=>t,lN=(t,e,r)=>t<<r|e>>>32-r,hN=(t,e,r)=>e<<r|t>>>32-r,pN=(t,e,r)=>e<<r-32|t>>>64-r,yN=(t,e,r)=>t<<r-32|e>>>64-r;function gN(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var mN=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),wN=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,bN=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),xN=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,EN=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),vN=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var SN={fromBig:jT,split:rN,toBig:nN,shrSH:iN,shrSL:oN,rotrSH:sN,rotrSL:cN,rotrBH:aN,rotrBL:uN,rotr32H:dN,rotr32L:fN,rotlSH:lN,rotlSL:hN,rotlBH:pN,rotlBL:yN,add:gN,add3L:mN,add3H:wN,add4L:bN,add4H:xN,add5H:vN,add5L:EN},le=SN;var[AN,TN]=le.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(t=>BigInt(t))),Xo=new Uint32Array(80),Zo=new Uint32Array(80),Ow=class extends Ma{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:u,El:d,Fh:f,Fl:h,Gh:p,Gl:g,Hh:y,Hl:x}=this;return[e,r,n,i,o,s,c,a,u,d,f,h,p,g,y,x]}set(e,r,n,i,o,s,c,a,u,d,f,h,p,g,y,x){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=g|0,this.Hh=y|0,this.Hl=x|0}process(e,r){for(let A=0;A<16;A++,r+=4)Xo[A]=e.getUint32(r),Zo[A]=e.getUint32(r+=4);for(let A=16;A<80;A++){let O=Xo[A-15]|0,T=Zo[A-15]|0,M=le.rotrSH(O,T,1)^le.rotrSH(O,T,8)^le.shrSH(O,T,7),q=le.rotrSL(O,T,1)^le.rotrSL(O,T,8)^le.shrSL(O,T,7),j=Xo[A-2]|0,$=Zo[A-2]|0,Z=le.rotrSH(j,$,19)^le.rotrBH(j,$,61)^le.shrSH(j,$,6),Q=le.rotrSL(j,$,19)^le.rotrBL(j,$,61)^le.shrSL(j,$,6),G=le.add4L(q,Q,Zo[A-7],Zo[A-16]),I=le.add4H(G,M,Z,Xo[A-7],Xo[A-16]);Xo[A]=I|0,Zo[A]=G|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:u,Dl:d,Eh:f,El:h,Fh:p,Fl:g,Gh:y,Gl:x,Hh:S,Hl:_}=this;for(let A=0;A<80;A++){let O=le.rotrSH(f,h,14)^le.rotrSH(f,h,18)^le.rotrBH(f,h,41),T=le.rotrSL(f,h,14)^le.rotrSL(f,h,18)^le.rotrBL(f,h,41),M=f&p^~f&y,q=h&g^~h&x,j=le.add5L(_,T,q,TN[A],Zo[A]),$=le.add5H(j,S,O,M,AN[A],Xo[A]),Z=j|0,Q=le.rotrSH(n,i,28)^le.rotrBH(n,i,34)^le.rotrBH(n,i,39),G=le.rotrSL(n,i,28)^le.rotrBL(n,i,34)^le.rotrBL(n,i,39),I=n&o^n&c^o&c,D=i&s^i&a^s&a;S=y|0,_=x|0,y=p|0,x=g|0,p=f|0,g=h|0,{h:f,l:h}=le.add(u|0,d|0,$|0,Z|0),u=c|0,d=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let E=le.add3L(Z,G,D);n=le.add3H(E,$,Q,I),i=E|0}({h:n,l:i}=le.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=le.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=le.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=le.add(this.Dh|0,this.Dl|0,u|0,d|0),{h:f,l:h}=le.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:g}=le.add(this.Fh|0,this.Fl|0,p|0,g|0),{h:y,l:x}=le.add(this.Gh|0,this.Gl|0,y|0,x|0),{h:S,l:_}=le.add(this.Hh|0,this.Hl|0,S|0,_|0),this.set(n,i,o,s,c,a,u,d,f,h,p,g,y,x,S,_)}roundClean(){Xo.fill(0),Zo.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dw=Zh(()=>new Ow);l();var On=BigInt(0),Pr=BigInt(1),cp=BigInt(2),_N=BigInt(8),IN={zip215:!0};function BN(t){let e=Kd(t);return nn(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function ap(t){let e=BN(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=e,u=cp<<BigInt(c*8)-Pr,d=r.create,f=e.uvRatio||((N,R)=>{try{return{isValid:!0,value:r.sqrt(N*r.inv(R))}}catch{return{isValid:!1,value:On}}}),h=e.adjustScalarBytes||(N=>N),p=e.domain||((N,R,C)=>{if(R.length||C)throw new Error("Contexts/pre-hash are not supported");return N}),g=N=>typeof N=="bigint"&&On<N,y=(N,R)=>g(N)&&g(R)&&N<R,x=N=>N===On||y(N,u);function S(N,R){if(y(N,R))return N;throw new Error(`Expected valid scalar < ${R}, got ${typeof N} ${N}`)}function _(N){return N===On?N:S(N,n)}let A=new Map;function O(N){if(!(N instanceof T))throw new Error("ExtendedPoint expected")}class T{constructor(R,C,P,V){if(this.ex=R,this.ey=C,this.ez=P,this.et=V,!x(R))throw new Error("x required");if(!x(C))throw new Error("y required");if(!x(P))throw new Error("z required");if(!x(V))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(R){if(R instanceof T)throw new Error("extended point not allowed");let{x:C,y:P}=R||{};if(!x(C)||!x(P))throw new Error("invalid affine point");return new T(C,P,Pr,d(C*P))}static normalizeZ(R){let C=r.invertBatch(R.map(P=>P.ez));return R.map((P,V)=>P.toAffine(C[V])).map(T.fromAffine)}_setWindowSize(R){this._WINDOW_SIZE=R,A.delete(this)}assertValidity(){let{a:R,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:P,ey:V,ez:J,et:z}=this,W=d(P*P),Y=d(V*V),X=d(J*J),ue=d(X*X),ee=d(W*R),ce=d(X*d(ee+Y)),Ue=d(ue+d(C*d(W*Y)));if(ce!==Ue)throw new Error("bad point: equation left != right (1)");let Ke=d(P*V),Je=d(J*z);if(Ke!==Je)throw new Error("bad point: equation left != right (2)")}equals(R){O(R);let{ex:C,ey:P,ez:V}=this,{ex:J,ey:z,ez:W}=R,Y=d(C*W),X=d(J*V),ue=d(P*W),ee=d(z*V);return Y===X&&ue===ee}is0(){return this.equals(T.ZERO)}negate(){return new T(d(-this.ex),this.ey,this.ez,d(-this.et))}double(){let{a:R}=e,{ex:C,ey:P,ez:V}=this,J=d(C*C),z=d(P*P),W=d(cp*d(V*V)),Y=d(R*J),X=C+P,ue=d(d(X*X)-J-z),ee=Y+z,ce=ee-W,Ue=Y-z,Ke=d(ue*ce),Je=d(ee*Ue),xt=d(ue*Ue),pi=d(ce*ee);return new T(Ke,Je,pi,xt)}add(R){O(R);let{a:C,d:P}=e,{ex:V,ey:J,ez:z,et:W}=this,{ex:Y,ey:X,ez:ue,et:ee}=R;if(C===BigInt(-1)){let lu=d((J-V)*(X+Y)),mf=d((J+V)*(X-Y)),hu=d(mf-lu);if(hu===On)return this.double();let wf=d(z*cp*ee),bf=d(W*cp*ue),Fr=bf+wf,ho=mf+lu,pu=bf-wf,xf=d(Fr*hu),fs=d(ho*pu),Ef=d(Fr*pu),Qp=d(hu*ho);return new T(xf,fs,Qp,Ef)}let ce=d(V*Y),Ue=d(J*X),Ke=d(W*P*ee),Je=d(z*ue),xt=d((V+J)*(Y+X)-ce-Ue),pi=Je-Ke,fo=Je+Ke,fu=d(Ue-C*ce),gf=d(xt*pi),Zp=d(fo*fu),lo=d(xt*fu),qr=d(pi*fo);return new T(gf,Zp,qr,lo)}subtract(R){return this.add(R.negate())}wNAF(R){return j.wNAFCached(this,A,R,T.normalizeZ)}multiply(R){let{p:C,f:P}=this.wNAF(S(R,n));return T.normalizeZ([C,P])[0]}multiplyUnsafe(R){let C=_(R);return C===On?q:this.equals(q)||C===Pr?this:this.equals(M)?this.wNAF(C).p:j.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return j.unsafeLadder(this,n).is0()}toAffine(R){let{ex:C,ey:P,ez:V}=this,J=this.is0();R==null&&(R=J?_N:r.inv(V));let z=d(C*R),W=d(P*R),Y=d(V*R);if(J)return{x:On,y:Pr};if(Y!==Pr)throw new Error("invZ was invalid");return{x:z,y:W}}clearCofactor(){let{h:R}=e;return R===Pr?this:this.multiplyUnsafe(R)}static fromHex(R,C=!1){let{d:P,a:V}=e,J=r.BYTES;R=Ge("pointHex",R,J);let z=R.slice(),W=R[J-1];z[J-1]=W&-129;let Y=Un(z);Y===On||(C?S(Y,u):S(Y,r.ORDER));let X=d(Y*Y),ue=d(X-Pr),ee=d(P*X-V),{isValid:ce,value:Ue}=f(ue,ee);if(!ce)throw new Error("Point.fromHex: invalid y coordinate");let Ke=(Ue&Pr)===Pr,Je=(W&128)!==0;if(!C&&Ue===On&&Je)throw new Error("Point.fromHex: x=0 and x_0=1");return Je!==Ke&&(Ue=d(-Ue)),T.fromAffine({x:Ue,y:Y})}static fromPrivateKey(R){return Q(R).point}toRawBytes(){let{x:R,y:C}=this.toAffine(),P=Qi(C,r.BYTES);return P[P.length-1]|=R&Pr?128:0,P}toHex(){return Xi(this.toRawBytes())}}T.BASE=new T(e.Gx,e.Gy,Pr,d(e.Gx*e.Gy)),T.ZERO=new T(On,Pr,Pr,On);let{BASE:M,ZERO:q}=T,j=np(T,c*8);function $(N){return Be(N,n)}function Z(N){return $(Un(N))}function Q(N){let R=c;N=Ge("private key",N,R);let C=Ge("hashed private key",o(N),2*R),P=h(C.slice(0,R)),V=C.slice(R,2*R),J=Z(P),z=M.multiply(J),W=z.toRawBytes();return{head:P,prefix:V,scalar:J,point:z,pointBytes:W}}function G(N){return Q(N).pointBytes}function I(N=new Uint8Array,...R){let C=eo(...R);return Z(o(p(C,Ge("context",N),!!i)))}function D(N,R,C={}){N=Ge("message",N),i&&(N=i(N));let{prefix:P,scalar:V,pointBytes:J}=Q(R),z=I(C.context,P,N),W=M.multiply(z).toRawBytes(),Y=I(C.context,W,J,N),X=$(z+Y*V);_(X);let ue=eo(W,Qi(X,r.BYTES));return Ge("result",ue,c*2)}let E=IN;function U(N,R,C,P=E){let{context:V,zip215:J}=P,z=r.BYTES;N=Ge("signature",N,2*z),R=Ge("message",R),i&&(R=i(R));let W=Un(N.slice(z,2*z)),Y,X,ue;try{Y=T.fromHex(C,J),X=T.fromHex(N.slice(0,z),J),ue=M.multiplyUnsafe(W)}catch{return!1}if(!J&&Y.isSmallOrder())return!1;let ee=I(V,X.toRawBytes(),Y.toRawBytes(),R);return X.add(Y.multiplyUnsafe(ee)).subtract(ue).clearCofactor().equals(T.ZERO)}return M._setWindowSize(8),{CURVE:e,getPublicKey:G,sign:D,verify:U,ExtendedPoint:T,utils:{getExtendedPublicKey:Q,randomPrivateKey:()=>s(r.BYTES),precompute(N=8,R=T.BASE){return R._setWindowSize(N),R.multiply(BigInt(3)),R}}}}l();var Vd=BigInt(0),kw=BigInt(1);function RN(t){return nn(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function WT(t){let e=RN(t),{P:r}=e,n=A=>Be(A,r),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(A=>A),a=e.powPminus2||(A=>Ew(A,r-BigInt(2),r));function u(A,O,T){let M=n(A*(O-T));return O=n(O-M),T=n(T+M),[O,T]}function d(A){if(typeof A=="bigint"&&Vd<=A&&A<r)return A;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function h(A,O){let T=d(A),M=d(O),q=T,j=kw,$=Vd,Z=T,Q=kw,G=Vd,I;for(let E=BigInt(i-1);E>=Vd;E--){let U=M>>E&kw;G^=U,I=u(G,j,Z),j=I[0],Z=I[1],I=u(G,$,Q),$=I[0],Q=I[1],G=U;let L=j+$,N=n(L*L),R=j-$,C=n(R*R),P=N-C,V=Z+Q,J=Z-Q,z=n(J*L),W=n(V*R),Y=z+W,X=z-W;Z=n(Y*Y),Q=n(q*n(X*X)),j=n(N*C),$=n(P*(N+n(f*P)))}I=u(G,j,Z),j=I[0],Z=I[1],I=u(G,$,Q),$=I[0],Q=I[1];let D=a($);return n(j*D)}function p(A){return Qi(n(A),o)}function g(A){let O=Ge("u coordinate",A,o);return s===32&&(O[31]&=127),Un(O)}function y(A){let O=Ge("scalar",A),T=O.length;if(T!==o&&T!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${T}`);return Un(c(O))}function x(A,O){let T=g(O),M=y(A),q=h(T,M);if(q===Vd)throw new Error("Invalid private or public key received");return p(q)}let S=p(e.Gu);function _(A){return x(A,S)}return{scalarMult:x,scalarMultBase:_,getSharedSecret:(A,O)=>x(A,O),getPublicKey:A=>_(A),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:S}}var qd=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),GT=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),jG=BigInt(0),UN=BigInt(1),Nw=BigInt(2),ON=BigInt(5),zT=BigInt(10),DN=BigInt(20),kN=BigInt(40),YT=BigInt(80);function JT(t){let e=qd,n=t*t%e*t%e,i=ze(n,Nw,e)*n%e,o=ze(i,UN,e)*t%e,s=ze(o,ON,e)*o%e,c=ze(s,zT,e)*s%e,a=ze(c,DN,e)*c%e,u=ze(a,kN,e)*a%e,d=ze(u,YT,e)*u%e,f=ze(d,YT,e)*u%e,h=ze(f,zT,e)*s%e;return{pow_p_5_8:ze(h,Nw,e)*t%e,b2:n}}function XT(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function NN(t,e){let r=qd,n=Be(e*e*e,r),i=Be(n*n*e,r),o=JT(t*i).pow_p_5_8,s=Be(t*n*o,r),c=Be(e*s*s,r),a=s,u=Be(s*GT,r),d=c===t,f=c===Be(-t,r),h=c===Be(-t*GT,r);return d&&(s=a),(f||h)&&(s=u),kT(s,r)&&(s=Be(-s,r)),{isValid:d||f,value:s}}var sn=Ka(qd,void 0,!0),Fd={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:sn,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Dw,randomBytes:Pd,adjustScalarBytes:XT,uvRatio:NN},Qo=ap(Fd);function ZT(t,e,r){if(e.length>255)throw new Error("Context is too big");return Xh(yw("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var WG=ap({...Fd,domain:ZT}),GG=ap({...Fd,domain:ZT,prehash:Dw}),gc=WT({P:qd,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=qd,{pow_p_5_8:r,b2:n}=JT(t);return Be(ze(r,BigInt(3),e)*n,e)},adjustScalarBytes:XT,randomBytes:Pd});function QT(t){let{y:e}=Qo.ExtendedPoint.fromHex(t),r=BigInt(1);return sn.toBytes(sn.create((r+e)*sn.inv(r-e)))}function e_(t){let e=Fd.hash(t.subarray(0,32));return Fd.adjustScalarBytes(e).subarray(0,32)}var CN=(sn.ORDER+BigInt(3))/BigInt(8),zG=sn.pow(Nw,CN),YG=sn.sqrt(sn.neg(sn.ONE)),JG=(sn.ORDER-BigInt(5))/BigInt(8),XG=BigInt(486662);var ZG=NT(sn,sn.neg(BigInt(486664)));var QG=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ez=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),tz=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rz=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var nz=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var cn=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},LN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Bt=class t{static bytesToPrivateKey(e){return cn(this,arguments,void 0,function*({privateKeyBytes:r}){let n=Qo.getPublicKey(r),i={crv:"Ed25519",d:ne.uint8Array(r).toBase64Url(),kty:"OKP",x:ne.uint8Array(n).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static bytesToPublicKey(e){return cn(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"Ed25519",x:ne.uint8Array(r).toBase64Url()};return n.kid=yield ge({jwk:n}),n})}static computePublicKey(e){return cn(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=Qo.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:ne.uint8Array(i).toBase64Url()};return o.kid=yield ge({jwk:o}),o})}static convertPrivateKeyToX25519(e){return cn(this,arguments,void 0,function*({privateKey:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=e_(n),o=gc.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:ne.uint8Array(i).toBase64Url(),x:ne.uint8Array(o).toBase64Url()};return s.kid=yield ge({jwk:s}),s})}static convertPublicKeyToX25519(e){return cn(this,arguments,void 0,function*({publicKey:r}){let n=yield t.publicKeyToBytes({publicKey:r});if(!(yield t.validatePublicKey({publicKeyBytes:n})))throw new Error("Ed25519: Invalid public key.");let o=QT(n),s={kty:"OKP",crv:"X25519",x:ne.uint8Array(o).toBase64Url()};return s.kid=yield ge({jwk:s}),s})}static generateKey(){return cn(this,void 0,void 0,function*(){let e=Qo.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield ge({jwk:r}),r})}static getPublicKey(e){return cn(this,arguments,void 0,function*({key:r}){var n;if(!(ui(r)&&r.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=r,o=LN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield ge({jwk:o})),o})}static privateKeyToBytes(e){return cn(this,arguments,void 0,function*({privateKey:r}){if(!ui(r))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return cn(this,arguments,void 0,function*({publicKey:r}){if(!Ha(r))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return ne.base64Url(r.x).toUint8Array()})}static sign(e){return cn(this,arguments,void 0,function*({key:r,data:n}){let i=yield t.privateKeyToBytes({privateKey:r});return Qo.sign(n,i)})}static validatePublicKey(e){return cn(this,arguments,void 0,function*({publicKeyBytes:r}){try{Qo.ExtendedPoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return cn(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r});return Qo.verify(n,i,o)})}};var jd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},up=class extends ci{computePublicKey(e){return jd(this,arguments,void 0,function*({key:r}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Bt.computePublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return jd(this,arguments,void 0,function*({algorithm:r}){switch(r){case"Ed25519":{let n=yield Bt.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return jd(this,arguments,void 0,function*({key:r}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Bt.getPublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return jd(this,arguments,void 0,function*({key:r,data:n}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":return yield Bt.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return jd(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!Ha(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(r.crv){case"Ed25519":return yield Bt.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};var ro=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Cw={Ed25519:{implementation:up,names:["Ed25519"]},secp256k1:{implementation:Hd,names:["ES256K","secp256k1"]},secp256r1:{implementation:Hd,names:["ES256","secp256r1"]},"SHA-256":{implementation:zh,names:["SHA-256"]}},Qt=class{constructor(e){var r;this._algorithmInstances=new Map,this._keyStore=(r=e?.keyStore)!==null&&r!==void 0?r:new hh}digest(e){return ro(this,arguments,void 0,function*({algorithm:r,data:n}){return yield this.getAlgorithm({algorithm:r}).digest({algorithm:r,data:n})})}exportKey(e){return ro(this,arguments,void 0,function*({keyUri:r}){return yield this.getPrivateKey({keyUri:r})})}generateKey(e){return ro(this,arguments,void 0,function*({algorithm:r}){let i=yield this.getAlgorithm({algorithm:r}).generateKey({algorithm:r});if(i?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let o=`${Rw}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return ro(this,arguments,void 0,function*({key:r}){let n=yield ge({jwk:r});return`${Rw}${n}`})}getPublicKey(e){return ro(this,arguments,void 0,function*({keyUri:r}){let n=yield this.getPrivateKey({keyUri:r}),i=this.getAlgorithmName({key:n});return yield this.getAlgorithm({algorithm:i}).getPublicKey({key:n})})}importKey(e){return ro(this,arguments,void 0,function*({key:r}){var n;if(!qT(r))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let i=structuredClone(r);(n=i.kid)!==null&&n!==void 0||(i.kid=yield ge({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return ro(this,arguments,void 0,function*({keyUri:r,data:n}){let i=yield this.getPrivateKey({keyUri:r}),o=this.getAlgorithmName({key:i});return this.getAlgorithm({algorithm:o}).sign({data:n,key:i})})}verify(e){return ro(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=this.getAlgorithmName({key:r});return this.getAlgorithm({algorithm:o}).verify({key:r,signature:n,data:i})})}getAlgorithm({algorithm:e}){var r;let n=(r=Cw[e])===null||r===void 0?void 0:r.implementation;if(!n)throw new Error(`Algorithm not supported: ${e}`);return this._algorithmInstances.has(n)||this._algorithmInstances.set(n,new n),this._algorithmInstances.get(n)}getAlgorithmName({key:e}){let r=e.alg,n=e.crv;for(let i in Cw){let o=Cw[i];if(r&&o.names.includes(r))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${r}, crv=${n}`)}getPrivateKey(e){return ro(this,arguments,void 0,function*({keyUri:r}){let n=yield this._keyStore.get(r);if(!n)throw new Error(`Key not found: ${r}`);return n})}};l();var dp=class t{static getJoseSignatureAlgorithmFromPublicKey(e){let r={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(r).includes(e.alg))return e.alg;if(e.crv&&Object.keys(r).includes(e.crv))return r[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(r).join(", ")}. Supported 'crv' values: ${Object.keys(r).join(", ")}.`)}static randomBytes(e){return xT(e)}static randomUuid(){return Na.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let r=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let o=t.randomBytes(Math.ceil(e/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>r)}else{let i=Math.pow(10,10);do{let o=t.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>r)}return n.toString().padStart(e,"0")}};l();l();l();l();l();l();l();l();l();l();var es=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},PN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Va=class t{static bytesToPrivateKey(e){return es(this,arguments,void 0,function*({privateKeyBytes:r}){let n=gc.getPublicKey(r),i={kty:"OKP",crv:"X25519",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n).toBase64Url()};return i.kid=yield ge({jwk:i}),i})}static bytesToPublicKey(e){return es(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"X25519",x:ne.uint8Array(r).toBase64Url()};return n.kid=yield ge({jwk:n}),n})}static computePublicKey(e){return es(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=gc.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:ne.uint8Array(i).toBase64Url()};return o.kid=yield ge({jwk:o}),o})}static generateKey(){return es(this,void 0,void 0,function*(){let e=gc.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield ge({jwk:r}),r})}static getPublicKey(e){return es(this,arguments,void 0,function*({key:r}){var n;if(!(ui(r)&&r.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=r,o=PN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield ge({jwk:o})),o})}static privateKeyToBytes(e){return es(this,arguments,void 0,function*({privateKey:r}){if(!ui(r))throw new Error("X25519: The provided key is not a valid OKP private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return es(this,arguments,void 0,function*({publicKey:r}){if(!Ha(r))throw new Error("X25519: The provided key is not a valid OKP public key.");return ne.base64Url(r.x).toUint8Array()})}static sharedSecret(e){return es(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return gc.getSharedSecret(i,o)})}};l();l();l();function Mr(t){if(typeof t=="string"&&t.length!==0)return t.split("#").pop()}function Mw({didDocument:t}){var e,r;if(!t)throw new TypeError("Required parameter missing: 'didDocument'");let n=[];return n.push(...(r=(e=t.verificationMethod)===null||e===void 0?void 0:e.filter(Pw))!==null&&r!==void 0?r:[]),Object.keys(Pi).forEach(i=>{var o,s;n.push(...(s=(o=t[i])===null||o===void 0?void 0:o.filter(Pw))!==null&&s!==void 0?s:[])}),n}function t_({didDocument:t}){let r=Mw({didDocument:t}).map(n=>n.type);return[...new Set(r)]}function r_({didDocument:t,methodId:e}){let r=[];return Object.keys(Pi).forEach(n=>{if(Array.isArray(t[n])){let i=t[n],o=Mr(e);i.some(c=>{let a=Mr(c)===o,u=Pw(c)&&Mr(c.id)===o;return a||u})&&r.push(n)}}),r}function n_(t){return!t||typeof t!="object"||t===null?!1:"id"in t&&"type"in t&&"serviceEndpoint"in t}function Pw(t){return!(!t||typeof t!="object"||t===null||!("id"in t&&"type"in t&&"controller"in t)||typeof t.id!="string"||typeof t.type!="string"||typeof t.controller!="string")}function Kw({keyBytes:t,multicodecCode:e,multicodecName:r}){let n=Yt.addPrefix({code:e,data:t,name:r}),i=ne.uint8Array(n).toBase58Btc();return ne.base58Btc(i).toMultibase()}function $w({multibaseKeyId:t}){try{let e=ne.multibase(t).toBase58Btc(),r=ne.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=Yt.removePrefix({prefixedData:r});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new re(ie.InvalidDid,`Invalid multibase identifier: ${t}`)}}var Wd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},wr=class t{constructor({uri:e,document:r,metadata:n,keyManager:i}){this.uri=e,this.document=r,this.metadata=n,this.keyManager=i}export(){return Wd(this,void 0,void 0,function*(){if(!(Array.isArray(this.document.verificationMethod)&&this.document.verificationMethod.length>0))throw new Error(`DID document for '${this.uri}' is missing verification methods`);let e=JSON.parse(JSON.stringify({uri:this.uri,document:this.document,metadata:this.metadata}));if("exportKey"in this.keyManager&&typeof this.keyManager.exportKey=="function"){let r=[];for(let n of this.document.verificationMethod){if(!n.publicKeyJwk)throw new Error(`Verification method '${n.id}' does not contain a public key in JWK format`);let i=yield this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=yield this.keyManager.exportKey({keyUri:i});r.push(Object.assign({},o))}e.privateKeys=r}return e})}getSigner(e){return Wd(this,void 0,void 0,function*(){var r;let n=(r=this.document.verificationMethod)===null||r===void 0?void 0:r.find(a=>{var u,d;return Mr(a.id)===((u=Mr(e?.methodId))!==null&&u!==void 0?u:Mr((d=this.document.assertionMethod)===null||d===void 0?void 0:d[0]))});if(!(n&&n.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");let i=yield this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=yield this.keyManager.getPublicKey({keyUri:i}),s=this.keyManager;return{algorithm:dp.getJoseSignatureAlgorithmFromPublicKey(o),keyId:n.id,sign(a){return Wd(this,arguments,void 0,function*({data:u}){return yield s.sign({data:u,keyUri:i})})},verify(a){return Wd(this,arguments,void 0,function*({data:u,signature:d}){return yield s.verify({data:u,key:o,signature:d})})}}})}static import(e){return Wd(this,arguments,void 0,function*({portableDid:r,keyManager:n=new Qt}){var i;let o=Mw({didDocument:r.document});if(o.length===0)throw new re(ie.InvalidDidDocument,"At least one verification method is required but 0 were given");for(let c of(i=r.privateKeys)!==null&&i!==void 0?i:[]){let a=yield n.getKeyUri({key:c});(yield n.getPublicKey({keyUri:a}).then(()=>!0).catch(()=>!1))||(yield n.importKey({key:c}))}for(let c of o){if(!c.publicKeyJwk)throw new Error(`Verification method '${c.id}' does not contain a public key in JWK format`);let a=yield n.getKeyUri({key:c.publicKeyJwk});yield n.getPublicKey({keyUri:a})}return new t({uri:r.uri,document:r.document,metadata:r.metadata,keyManager:n})})}};l();l();l();l();l();var Hw="0123456789abcdef",o_=[],i_=[];for(let t=0;t<256;t++)o_[t]=Hw[t>>4&15]+Hw[t&15],t<16&&(t<10?i_[48+t]=t:i_[87+t]=t);var Vw=t=>{let e=t.length,r="",n=0;for(;n<e;)r+=o_[t[n++]];return r};var s_=(t,e=0)=>{let r=t.length||0;if(!e){let s=r;for(;s--;)e+=t[s].length}let n=new Uint8Array(e),i=e,o=r;for(;o--;)i-=t[o].length,n.set(t[o],i);return n};l();var c_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",KN=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Gd=0;Gd<c_.length;Gd++)KN[c_.charCodeAt(Gd)]=Gd;var Gd;var $N=new TextDecoder,qw=(t,e)=>e?new TextDecoder(e).decode(t):$N.decode(t),HN=new TextEncoder,an=t=>HN.encode(t);var a_=typeof window<"u"?window:self,u_=a_.crypto||a_.msCrypto||{},nJ=u_.subtle||u_.webkitSubtle;l();function qa(t){let e=t<0?1:0;return t=Math.abs(Number(t||1)),Math.floor(Math.log10(t))+1+e}function fp(t){return ArrayBuffer.isView(t)?"arraybufferview":Array.isArray(t)?"array":t instanceof Number?"number":t instanceof Boolean?"boolean":t instanceof Set?"set":t instanceof Map?"map":t instanceof String?"string":t instanceof ArrayBuffer?"arraybuffer":typeof t}function Re(t,e,r){let n=[],i=null;return Re._encode(n,t),i=s_(n),Re.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,r),e):i}Re.bytes=-1;Re._floatConversionDetected=!1;Re._encode=function(t,e){if(e!=null)switch(fp(e)){case"object":Re.dict(t,e);break;case"map":Re.dictMap(t,e);break;case"array":Re.list(t,e);break;case"set":Re.listSet(t,e);break;case"string":Re.string(t,e);break;case"number":Re.number(t,e);break;case"boolean":Re.number(t,e);break;case"arraybufferview":Re.buffer(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":Re.buffer(t,new Uint8Array(e));break}};var lp=new Uint8Array([101]),d_=new Uint8Array([100]),f_=new Uint8Array([108]);Re.buffer=function(t,e){t.push(an(e.length+":"),e)};Re.string=function(t,e){t.push(an(an(e).byteLength+":"+e))};Re.number=function(t,e){if(Number.isInteger(e))return t.push(an("i"+BigInt(e)+"e"));let r=2147483648,n=e/r<<0,i=e%r<<0,o=n*r+i;t.push(an("i"+o+"e")),o!==e&&!Re._floatConversionDetected&&(Re._floatConversionDetected=!0,console.warn('WARNING: Possible data corruption detected with value "'+e+'":','Bencoding only defines support for integers, value was converted to "'+o+'"'),console.trace())};Re.dict=function(t,e){t.push(d_);let r=0,n,i=Object.keys(e).sort(),o=i.length;for(;r<o;r++)n=i[r],e[n]!=null&&(Re.string(t,n),Re._encode(t,e[n]));t.push(lp)};Re.dictMap=function(t,e){t.push(d_);let r=Array.from(e.keys()).sort();for(let n of r)e.get(n)!=null&&(ArrayBuffer.isView(n)?Re._encode(t,n):Re.string(t,String(n)),Re._encode(t,e.get(n)));t.push(lp)};Re.list=function(t,e){let r=0,n=e.length;for(t.push(f_);r<n;r++)e[r]!=null&&Re._encode(t,e[r]);t.push(lp)};Re.listSet=function(t,e){t.push(f_);for(let r of e)r!=null&&Re._encode(t,r);t.push(lp)};var l_=Re;l();var VN=105,qN=58,FN=100,jN=108,Fw=101;function h_(t,e,r){let n=0,i=1;for(let o=e;o<r;o++){let s=t[o];if(s<58&&s>=48){n=n*10+(s-48);continue}if(!(o===e&&s===43)){if(o===e&&s===45){i=-1;continue}if(s===46)break;throw new Error("not a number: buffer["+o+"] = "+s)}}return n*i}function de(t,e,r,n){return t==null||t.length===0?null:(typeof e!="number"&&n==null&&(n=e,e=void 0),typeof r!="number"&&n==null&&(n=r,r=void 0),de.position=0,de.encoding=n||null,de.data=ArrayBuffer.isView(t)?new Uint8Array(t.slice(e,r)):an(t),de.bytes=de.data.length,de.next())}de.bytes=0;de.position=0;de.data=null;de.encoding=null;de.next=function(){switch(de.data[de.position]){case FN:return de.dictionary();case jN:return de.list();case VN:return de.integer();default:return de.buffer()}};de.find=function(t){let e=de.position,r=de.data.length,n=de.data;for(;e<r;){if(n[e]===t)return e;e++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(t)+'" [0x'+t.toString(16)+"]")};de.dictionary=function(){de.position++;let t={};for(;de.data[de.position]!==Fw;){let e=de.buffer(),r=qw(e);r.includes("\uFFFD")&&(r=Vw(e)),t[r]=de.next()}return de.position++,t};de.list=function(){de.position++;let t=[];for(;de.data[de.position]!==Fw;)t.push(de.next());return de.position++,t};de.integer=function(){let t=de.find(Fw),e=h_(de.data,de.position+1,t);return de.position+=t+1-de.position,e};de.buffer=function(){let t=de.find(qN),e=h_(de.data,de.position,t),r=++t+e;return de.position=r,de.encoding?qw(de.data.slice(t,r)):de.data.slice(t,r)};var p_=de;l();function WN(t){let e=2;for(let r of t)e+=hp(r);return e}function GN(t){let e=2;for(let[r,n]of t){let i=an(r).byteLength;e+=qa(i)+1+i,e+=hp(n)}return e}function zN(t){let e=2,r=Object.keys(t);for(let n=0;n<r.length;n++){let i=an(r[n]).byteLength;e+=qa(i)+1+i,e+=hp(t[r[n]])}return e}function YN(t){let e=an(t).byteLength;return qa(e)+1+e}function JN(t){let e=t.byteLength-t.byteOffset;return qa(e)+1+e}function hp(t){if(t==null)return 0;let r=fp(t);switch(r){case"arraybufferview":return JN(t);case"string":return YN(t);case"array":case"set":return WN(t);case"number":return 1+qa(Math.floor(t))+1;case"bigint":return 1+t.toString().length+1;case"object":return zN(t);case"map":return GN(t);default:throw new TypeError(`Unsupported value of type "${r}"`)}}var jw=hp;var XN=jw,Ww={encode:l_,decode:p_,byteLength:jw,encodingLength:XN};l();l();var ZN=/^(\d{1,3}\.){3,3}\d{1,3}$/;var QN=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var Dn={name:"v4",size:4,isFormat:t=>ZN.test(t),encode(t,e,r){r=~~r,e=e||new Uint8Array(r+4);let n=t.length,i=0;for(let o=0;o<n;){let s=t.charCodeAt(o++);s===46?(e[r++]=i,i=0):i=i*10+(s-48)}return e[r]=i,e},decode(t,e){return e=~~e,`${t[e++]}.${t[e++]}.${t[e++]}.${t[e]}`}},no={name:"v6",size:16,isFormat:t=>t.length>0&&QN.test(t),encode(t,e,r){r=~~r;let n=r+16,i=-1,o=0,s=0,c=!0,a=!1;e=e||new Uint8Array(r+16);for(let u=0;u<t.length;u++){let d=t.charCodeAt(u);d===58?(c?i!==-1?(r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2):r<n&&(i=r):(a===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=o>>8),r<n-1&&(e[r+1]=o&255),r+=2),o=0,s=0),c=!0,a=!1):d===46?(r<n&&(e[r]=s),r++,s=0,o=0,c=!1,a=!0):(c=!1,d>=97?d-=87:d>=65?d-=55:(d-=48,s=s*10+d),o=(o<<4)+d)}if(c===!1)a===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=o>>8),r<n-1&&(e[r+1]=o&255),r+=2);else if(i===0)r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2;else if(i!==-1){r+=2;for(let u=Math.min(r-1,n-1);u>=i+2;u--)e[u]=e[u-2];e[i]=0,e[i+1]=0,i=r}if(i!==r&&i!==-1)for(r>n-2&&(r=n-2);n>i;)e[--n]=r<n&&r>i?e[--r]:0;else for(;r<n;)e[r++]=0;return e},decode(t,e){e=~~e;let r="";for(let n=0;n<16;n+=2)n!==0&&(r+=":"),r+=(t[e+n]<<8|t[e+n+1]).toString(16);return r.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};function y_(t){if(Dn.isFormat(t))return Dn.size;if(no.isFormat(t))return no.size;throw Error(`Invalid ip address: ${t}`)}function g_(t){return y_(t)===Dn.size?1:2}function m_(t,e,r){r=~~r;let n=y_(t);return typeof e=="function"&&(e=e(r+n)),n===Dn.size?Dn.encode(t,e,r):no.encode(t,e,r)}function w_(t,e,r){if(e=~~e,r=r||t.length-e,r===Dn.size)return Dn.decode(t,e,r);if(r===no.size)return no.decode(t,e,r);throw Error(`Invalid buffer size needs to be ${Dn.size} for v4 or ${no.size} for v6.`)}l();function zd(t){switch(t){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+t}function Fa(t){switch(t.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return t.toUpperCase().startsWith("UNKNOWN_")?parseInt(t.slice(8)):0}l();function b_(t){switch(t){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+t}l();function x_(t){switch(t){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+t}l();function Gw(t){switch(t){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+t}function zw(t){switch(t.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}l();function E_(t){switch(t){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return t<0?null:`OPTION_${t}`}function Yw(t){if(typeof t=="number")return t;if(!t)return-1;switch(t.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=t.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}l();l();function Jw(t){let e=0,r=t.length;for(let n=0;n<r;n+=1){let i=t.charCodeAt(n);if(i<=127)e+=1;else if(i<=2047)e+=2;else if((i&63488)!==55296)e+=3;else{let o=n+1;o===r||i>=56320||(t.charCodeAt(o)&64512)!==56320?e+=3:(n=o,e+=4)}}return e}function ja(t,e,r){let n=t.length;r==null&&(r=0),e===void 0&&(e=new Uint8Array(Jw(t)+r));let i=r;for(let o=0;o<n;o+=1){let s=t.charCodeAt(o);if(s<=127)e[i++]=s;else if(s<=2047)e[i++]=192|(s&1984)>>6,e[i++]=128|s&63;else if((s&63488)!==55296)e[i++]=224|(s&61440)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63;else{let c=o+1;if(c===n||s>=56320)e[i++]=239,e[i++]=191,e[i++]=189;else{let a=t.charCodeAt(c);(a&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(o=c,s=65536|(s&1023)<<10|a&1023,e[i++]=240|(s&1835008)>>18,e[i++]=128|(s&258048)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63)}}}return ja.bytes=i-r,e}ja.bytes=0;function Wa(t,e,r){let n="";e==null&&(e=0),r==null&&(r=t.length);for(let i=e;i<r;){let o=t[i++],s;if(o<=128)s=o;else if(o>191&&o<224)s=(o&31)<<6|t[i++]&63;else if(o>239&&o<365){s=((o&7)<<18|(t[i++]&63)<<12|(t[i++]&63)<<6|t[i++]&63)-65536;let c=55296|s>>10&1023;n+=String.fromCharCode(c),s=56320|s&1023}else s=(o&15)<<12|(t[i++]&63)<<6|t[i++]&63;n+=String.fromCharCode(s)}return Wa.bytes=r-e,n}Wa.bytes=0;var ts=t=>t instanceof Uint8Array;function io(t){return typeof t=="string"?Jw(t):t.byteLength}function pp(t){return t instanceof Uint8Array?t:Array.isArray(t)?new Uint8Array(t):ja(t)}function yp(t,e,r){if(typeof e!="string")throw new Error("unknown input type");return ja(e,t,r),ja.bytes}var Yd={},v_=new Array(255);for(let t=0;t<=15;t+=1){let e=t.toString(16),r=e.toUpperCase();for(let n=0;n<=15;n+=1){let i=n.toString(16),o=i.toUpperCase(),s=t<<4|n,c=`${e}${i}`;v_[s]=c,Yd[c]=s,Yd[`${r}${i}`]=s,Yd[`${e}${o}`]=s,Yd[`${r}${o}`]=s}}function S_(t,e,r){let n="";for(let i=e;i<r;){let o=t[i++];n+=v_[o]}return n}function Xw(t){return t.length>>>1}function A_(t,e,r,n){let i=0;for(;r<n;){let o=e.substr(i,2),s=Yd[o];if(s===void 0)return;t[r++]=s,i+=2}return t}var cC=Math.pow(2,24),aC=Math.pow(2,16),uC=Math.pow(2,8),di=(t,e)=>t[e]*cC+t[e+1]*aC+t[e+2]*uC+t[e+3],he=(t,e)=>t[e]<<8|t[e+1],fi=(t,e,r)=>(e=+e,t[r+3]=e,e=e>>>8,t[r+2]=e,e=e>>>8,t[r+1]=e,e=e>>>8,t[r]=e,r+4),ae=(t,e,r)=>(t[r]=e>>8,t[r+1]=e&255,r+2);function br(t,e,r,n,i){return r<0&&(n-=r,r=0),n<0&&(n=0),i<0?new Uint8Array(0):r>=e.length||n>=i?0:dC(t,e,r,n,i)}function dC(t,e,r,n,i){i-n>e.length-r&&(i=n+e.length-r);let o=i-n,s=t.length-n;return o>s&&(o=s),(n!==0||i<t.length)&&(t=new Uint8Array(t.buffer,t.byteOffset+n,o)),e.set(t,r),o}var lC=0,T_=32768,Qw=32768,hC=~Qw,I_=32768,pC=~I_;function He({bytes:t=0,encode:e,decode:r,encodingLength:n}){return e.bytes=t,r.bytes=t,{encode:e,decode:r,encodingLength:n||(()=>t)}}var se=He({encode(t,e,r){e||(e=new Uint8Array(se.encodingLength(t))),r||(r=0);let n=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let o=i.split(".");for(let s=0;s<o.length;s++){let c=yp(e,o[s],r+1);e[r]=c,r+=c+1}}return e[r++]=0,se.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=[],n=e,i=0,o=0,s=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let c=t[e++];if(o+=s?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let a=he(t,e-1)-49152;if(a>=n)throw new Error("Cannot decode name (bad pointer)");e=a,n=a,o+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");r.push(Wa(t,e,e+c)),e+=c,o+=s?0:c}}return se.decode.bytes=o,r.length===0?".":r.join(".")},encodingLength(t){return t==="."||t===".."?1:io(t.replace(/^\.|\.$/gm,""))+2}}),Rt=He({encode(t,e,r){e||(e=new Uint8Array(Rt.encodingLength(t))),r||(r=0);let n=yp(e,t,r+1);return e[r]=n,Rt.encode.bytes=n+1,e},decode(t,e){e||(e=0);let r=t[e],n=Wa(t,e+1,e+1+r);return Rt.decode.bytes=r+1,n},encodingLength(t){return io(t)+1}}),Ga=He({bytes:12,encode(t,e,r){e||(e=new Uint8Array(Ga.encodingLength(t))),r||(r=0);let n=(t.flags||0)&32767,i=t.type==="response"?T_:lC;return ae(e,t.id||0,r),ae(e,n|i,r+2),ae(e,t.questions.length,r+4),ae(e,t.answers.length,r+6),ae(e,t.authorities.length,r+8),ae(e,t.additionals.length,r+10),e},decode(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=he(t,e+2);return{id:he(t,e),type:r&T_?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:x_(r>>11&15),flag_aa:(r>>10&1)===1,flag_tc:(r>>9&1)===1,flag_rd:(r>>8&1)===1,flag_ra:(r>>7&1)===1,flag_z:(r>>6&1)===1,flag_ad:(r>>5&1)===1,flag_cd:(r>>4&1)===1,rcode:b_(r&15),questions:new Array(he(t,e+4)),answers:new Array(he(t,e+6)),authorities:new Array(he(t,e+8)),additionals:new Array(he(t,e+10))}},encodingLength(){return 12}}),mp=He({encode(t,e,r){e||(e=new Uint8Array(mp.encodingLength(t))),r||(r=0);let n=t.length;return ae(e,n,r),br(t,e,r+2,0,n),mp.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=he(t,e),n=t.slice(e+2,e+2+r);return mp.decode.bytes=r+2,n},encodingLength(t){return t.length+2}}),wp=He({encode(t,e,r){return e||(e=new Uint8Array(wp.encodingLength(t))),r||(r=0),se.encode(t,e,r+2),ae(e,se.encode.bytes,r),wp.encode.bytes=se.encode.bytes+2,e},decode(t,e){e||(e=0);let r=he(t,e),n=se.decode(t,e+2);return wp.decode.bytes=r+2,n},encodingLength(t){return se.encodingLength(t)+2}}),bp=He({encode(t,e,r){e||(e=new Uint8Array(bp.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.mname,e,r),r+=se.encode.bytes,se.encode(t.rname,e,r),r+=se.encode.bytes,fi(e,t.serial||0,r),r+=4,fi(e,t.refresh||0,r),r+=4,fi(e,t.retry||0,r),r+=4,fi(e,t.expire||0,r),r+=4,fi(e,t.minimum||0,r),r+=4,ae(e,r-n-2,n),bp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=se.decode(t,e),e+=se.decode.bytes,n.rname=se.decode(t,e),e+=se.decode.bytes,n.serial=di(t,e),e+=4,n.refresh=di(t,e),e+=4,n.retry=di(t,e),e+=4,n.expire=di(t,e),e+=4,n.minimum=di(t,e),e+=4,bp.decode.bytes=e-r,n},encodingLength(t){return 22+se.encodingLength(t.mname)+se.encodingLength(t.rname)}}),xp=He({encode(t,e,r){Array.isArray(t)||(t=[t]);for(let i=0;i<t.length;i++)if(typeof t[i]=="string"&&(t[i]=pp(t[i])),!ts(t[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(xp.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(i){e[r++]=i.length,br(i,e,r,0,i.length),r+=i.length}),ae(e,r-n-2,n),xp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=he(t,e);e+=2;let i=[];for(;n>0;){let o=t[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(t.slice(e,e+o)),e+=o,n-=o}return xp.decode.bytes=e-r,i},encodingLength(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=io(r)+1:e+=r.length+1}),e}}),Ep=He({encode(t,e,r){e||(e=new Uint8Array(Ep.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=pp(t)),t||(t=new Uint8Array(0));let n=r;r+=2;let i=t.length;return br(t,e,r,0,i),r+=i,ae(e,r-n-2,n),Ep.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=he(t,e);e+=2;let i=t.slice(e,e+n);return e+=n,Ep.decode.bytes=e-r,i},encodingLength(t){return t?(ts(t)?t.length:io(t))+2:2}}),vp=He({encode(t,e,r){e||(e=new Uint8Array(vp.encodingLength(t))),r||(r=0);let n=r;return r+=2,Rt.encode(t.cpu,e,r),r+=Rt.encode.bytes,Rt.encode(t.os,e,r),r+=Rt.encode.bytes,ae(e,r-n-2,n),vp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=Rt.decode(t,e),e+=Rt.decode.bytes,n.os=Rt.decode(t,e),e+=Rt.decode.bytes,vp.decode.bytes=e-r,n},encodingLength(t){return Rt.encodingLength(t.cpu)+Rt.encodingLength(t.os)+2}}),Ja=He({encode(t,e,r){return e||(e=new Uint8Array(Ja.encodingLength(t))),r||(r=0),se.encode(t,e,r+2),ae(e,se.encode.bytes,r),Ja.encode.bytes=se.encode.bytes+2,e},decode(t,e){e||(e=0);let r=se.decode(t,e+2);return Ja.decode.bytes=se.decode.bytes+2,r},encodingLength(t){return se.encodingLength(t)+2}}),Sp=He({encode(t,e,r){e||(e=new Uint8Array(Sp.encodingLength(t))),r||(r=0),ae(e,t.priority||0,r+2),ae(e,t.weight||0,r+4),ae(e,t.port||0,r+6),se.encode(t.target,e,r+8);let n=se.encode.bytes+6;return ae(e,n,r),Sp.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=he(t,e),n={};return n.priority=he(t,e+2),n.weight=he(t,e+4),n.port=he(t,e+6),n.target=se.decode(t,e+8),Sp.decode.bytes=r+2,n},encodingLength(t){return 8+se.encodingLength(t.target)}}),rs=He({encode(t,e,r){let n=rs.encodingLength(t);return e||(e=new Uint8Array(rs.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=rs.ISSUER_CRITICAL),ae(e,n-2,r),r+=2,e[r]=t.flags||0,r+=1,Rt.encode(t.tag,e,r),r+=Rt.encode.bytes,yp(e,t.value,r),r+=io(t.value),rs.encode.bytes=n,e},decode(t,e){e||(e=0);let r=he(t,e);e+=2;let n=e,i={};return i.flags=t[e],e+=1,i.tag=Rt.decode(t,e),e+=Rt.decode.bytes,i.value=Wa(t,e,n+r),i.issuerCritical=!!(i.flags&rs.ISSUER_CRITICAL),rs.decode.bytes=r+2,i},encodingLength(t){return Rt.encodingLength(t.tag)+Rt.encodingLength(t.value)+2}});rs.ISSUER_CRITICAL=128;var Ap=He({encode(t,e,r){e||(e=new Uint8Array(Ap.encodingLength(t))),r||(r=0);let n=r;return r+=2,ae(e,t.preference||0,r),r+=2,se.encode(t.exchange,e,r),r+=se.encode.bytes,ae(e,r-n-2,n),Ap.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=he(t,e),e+=2,n.exchange=se.decode(t,e),e+=se.decode.bytes,Ap.decode.bytes=e-r,n},encodingLength(t){return 4+se.encodingLength(t.exchange)}}),B_=He({encode(t,e,r){return e||(e=new Uint8Array(B_.encodingLength(t))),r||(r=0),ae(e,4,r),r+=2,Dn.encode(t,e,r),e},decode(t,e){return e||(e=0),e+=2,Dn.decode(t,e)},bytes:6}),Tp=He({encode(t,e,r){return e||(e=new Uint8Array(Tp.encodingLength(t))),r||(r=0),ae(e,16,r),r+=2,no.encode(t,e,r),Tp.encode.bytes=18,e},decode(t,e){e||(e=0),e+=2;let r=no.decode(t,e);return Tp.decode.bytes=18,r},bytes:18}),__=t=>new Uint8Array(t),oo=He({encode(t,e,r){e||(e=new Uint8Array(oo.encodingLength(t))),r||(r=0);let n=r,i=Yw(t.code);if(ae(e,i,r),r+=2,t.data)ae(e,t.data.length,r),r+=2,br(t.data,e,r),r+=t.data.length;else switch(i){case 8:{let o=t.sourcePrefixLength||0,s=t.family||g_(t.ip,__),c=m_(t.ip,__),a=Math.ceil(o/8);ae(e,a+4,r),r+=2,ae(e,s,r),r+=2,e[r++]=o,e[r++]=t.scopePrefixLength||0,br(c,e,r,0,a),r+=a}break;case 11:t.timeout?(ae(e,2,r),r+=2,ae(e,t.timeout,r),r+=2):(ae(e,0,r),r+=2);break;case 12:{let o=t.length||0;ae(e,o,r),r+=2,e.fill(0,r,r+o),r+=o}break;case 14:{let o=t.tags.length*2;ae(e,o,r),r+=2;for(let s of t.tags)ae(e,s,r),r+=2}break;default:throw new Error(`Unknown roption code: ${t.code}`)}return oo.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={};r.code=he(t,e),r.type=E_(r.code),e+=2;let n=he(t,e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=he(t,e),e+=2,r.sourcePrefixLength=t[e++],r.scopePrefixLength=t[e++];{let i=new Uint8Array(r.family===1?4:16);br(t,i,0,e,e+n-4),r.ip=w_(i)}break;case 11:n>0&&(r.timeout=he(t,e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(he(t,e)),e+=2}return oo.decode.bytes=n+4,r},encodingLength(t){if(t.data)return t.data.length+4;switch(Yw(t.code)){case 8:{let r=t.sourcePrefixLength||0;return Math.ceil(r/8)+8}case 11:return typeof t.timeout=="number"?6:4;case 12:return t.length+4;case 14:return 4+t.tags.length*2}throw new Error(`Unknown roption code: ${t.code}`)}}),ns=He({encode(t,e,r){e||(e=new Uint8Array(ns.encodingLength(t))),r||(r=0);let n=r,i=Ya(t,oo);return ae(e,i,r),r=tf(t,oo,e,r+2),ns.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=[],i=he(t,e);e+=2;let o=0;for(;i>0;)n[o++]=oo.decode(t,e),e+=oo.decode.bytes,i-=oo.decode.bytes;return ns.decode.bytes=e-r,n},encodingLength(t){return 2+Ya(t||[],oo)}}),li=He({encode(t,e,r){e||(e=new Uint8Array(li.encodingLength(t))),r||(r=0);let n=r,i=t.key;if(!ts(i))throw new Error("Key must be a Buffer");return r+=2,ae(e,t.flags,r),r+=2,e[r]=li.PROTOCOL_DNSSEC,r+=1,e[r]=t.algorithm,r+=1,br(i,e,r,0,i.length),r+=i.length,li.encode.bytes=r-n,ae(e,li.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=he(t,e);if(e+=2,n.flags=he(t,e),e+=2,t[e]!==li.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t[e],e+=1,n.key=t.slice(e,r+i+2),e+=n.key.length,li.decode.bytes=e-r,n},encodingLength(t){return 6+io(t.key)}});li.PROTOCOL_DNSSEC=3;li.ZONE_KEY=128;li.SECURE_ENTRYPOINT=32768;var Jd=He({encode(t,e,r){e||(e=new Uint8Array(Jd.encodingLength(t))),r||(r=0);let n=r,i=t.signature;if(!ts(i))throw new Error("Signature must be a Buffer");return r+=2,ae(e,Fa(t.typeCovered),r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.labels,r+=1,fi(e,t.originalTTL,r),r+=4,fi(e,t.expiration,r),r+=4,fi(e,t.inception,r),r+=4,ae(e,t.keyTag,r),r+=2,se.encode(t.signersName,e,r),r+=se.encode.bytes,br(i,e,r,0,i.length),r+=i.length,Jd.encode.bytes=r-n,ae(e,Jd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=he(t,e);return e+=2,n.typeCovered=zd(he(t,e)),e+=2,n.algorithm=t[e],e+=1,n.labels=t[e],e+=1,n.originalTTL=di(t,e),e+=4,n.expiration=di(t,e),e+=4,n.inception=di(t,e),e+=4,n.keyTag=he(t,e),e+=2,n.signersName=se.decode(t,e),e+=se.decode.bytes,n.signature=t.slice(e,r+i+2),e+=n.signature.length,Jd.decode.bytes=e-r,n},encodingLength(t){return 20+se.encodingLength(t.signersName)+io(t.signature)}}),Xd=He({encode(t,e,r){e||(e=new Uint8Array(Xd.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.mbox||".",e,r),r+=se.encode.bytes,se.encode(t.txt||".",e,r),r+=se.encode.bytes,Xd.encode.bytes=r-n,ae(e,Xd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=se.decode(t,e)||".",e+=se.decode.bytes,n.txt=se.decode(t,e)||".",e+=se.decode.bytes,Xd.decode.bytes=e-r,n},encodingLength(t){return 2+se.encodingLength(t.mbox||".")+se.encodingLength(t.txt||".")}}),Kr=He({encode(t,e,r){e||(e=new Uint8Array(Kr.encodingLength(t))),r||(r=0);let n=r,i=[];for(let o=0;o<t.length;o++){let s=Fa(t[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(let o=0;o<i.length;o++)if(i[o]!==void 0){let s=pp(i[o]);e[r]=o,r+=1,e[r]=s.length,r+=1,br(s,e,r,0,s.length),r+=s.length}return Kr.encode.bytes=r-n,e},decode(t,e,r){e||(e=0);let n=e,i=[];for(;e-n<r;){let o=t[e];e+=1;let s=t[e];e+=1;for(let c=0;c<s;c++){let a=t[e+c];for(let u=0;u<8;u++)if(a&1<<7-u){let d=zd(o<<8|c<<3|u);i.push(d)}}e+=s}return Kr.decode.bytes=e-n,i},encodingLength(t){let e=[];for(let n=0;n<t.length;n++){let i=Fa(t[n]);e[i>>8]=Math.max(e[i>>8]||0,i&255)}let r=0;for(let n=0;n<e.length;n++)e[n]!==void 0&&(r+=2+Math.ceil((e[n]+1)/8));return r}}),Zd=He({encode(t,e,r){e||(e=new Uint8Array(Zd.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.nextDomain,e,r),r+=se.encode.bytes,Kr.encode(t.rrtypes,e,r),r+=Kr.encode.bytes,Zd.encode.bytes=r-n,ae(e,Zd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=he(t,e);return e+=2,n.nextDomain=se.decode(t,e),e+=se.decode.bytes,n.rrtypes=Kr.decode(t,e,i-(e-r)),e+=Kr.decode.bytes,Zd.decode.bytes=e-r,n},encodingLength(t){return 2+se.encodingLength(t.nextDomain)+Kr.encodingLength(t.rrtypes)}}),Qd=He({encode(t,e,r){e||(e=new Uint8Array(Qd.encodingLength(t))),r||(r=0);let n=r,i=t.salt;if(!ts(i))throw new Error("salt must be a Buffer");let o=t.nextDomain;if(!ts(o))throw new Error("nextDomain must be a Buffer");return r+=2,e[r]=t.algorithm,r+=1,e[r]=t.flags,r+=1,ae(e,t.iterations,r),r+=2,e[r]=i.length,r+=1,br(i,e,r,0,i.length),r+=i.length,e[r]=o.length,r+=1,br(o,e,r,0,o.length),r+=o.length,Kr.encode(t.rrtypes,e,r),r+=Kr.encode.bytes,Qd.encode.bytes=r-n,ae(e,Qd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=he(t,e);e+=2,n.algorithm=t[e],e+=1,n.flags=t[e],e+=1,n.iterations=he(t,e),e+=2;let o=t[e];e+=1,n.salt=t.slice(e,e+o),e+=o;let s=t[e];return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=Kr.decode(t,e,i-(e-r)),e+=Kr.decode.bytes,Qd.decode.bytes=e-r,n},encodingLength(t){return 8+t.salt.length+t.nextDomain.length+Kr.encodingLength(t.rrtypes)}}),ef=He({encode(t,e,r){e||(e=new Uint8Array(ef.encodingLength(t))),r||(r=0);let n=r,i=t.digest;if(!ts(i))throw new Error("Digest must be a Buffer");return r+=2,ae(e,t.keyTag,r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.digestType,r+=1,br(i,e,r,0,i.length),r+=i.length,ef.encode.bytes=r-n,ae(e,ef.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=he(t,e);return e+=2,n.keyTag=he(t,e),e+=2,n.algorithm=t[e],e+=1,n.digestType=t[e],e+=1,n.digest=t.slice(e,r+i+2),e+=n.digest.length,ef.decode.bytes=e-r,n},encodingLength(t){return 6+io(t.digest)}}),za=He({encode(t,e,r){e||(e=new Uint8Array(za.encodingLength(t))),r||(r=0);let n=r;r+=2,e[r]=t.algorithm,r+=1,e[r]=t.hash,r+=1;let i=Xw(t.fingerprint),o=eb(t.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${t.fingerprint}" for hashType=${t.hash}: ${i} != ${o}`);return A_(e,t.fingerprint,r,r+=i),za.encode.bytes=r-n,ae(e,za.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};e+=2,n.algorithm=t[e],e+=1,n.hash=t[e],e+=1;let i=eb(n.hash);return n.fingerprint=S_(t,e,e+i),e+=i,za.decode.bytes=e-r,n},encodingLength(t){return 4+Xw(t.fingerprint)}});function eb(t){if(t===1)return 20;if(t===2)return 32;throw new Error(`Invalid hashType=${t}, supported=1,2`)}za.getFingerprintLengthForHashType=eb;function Zw(t){switch(t.toUpperCase()){case"A":return B_;case"PTR":return Ja;case"CNAME":return Ja;case"DNAME":return Ja;case"TXT":return xp;case"NULL":return Ep;case"AAAA":return Tp;case"SRV":return Sp;case"HINFO":return vp;case"CAA":return rs;case"NS":return wp;case"SOA":return bp;case"MX":return Ap;case"OPT":return ns;case"DNSKEY":return li;case"RRSIG":return Jd;case"RP":return Xd;case"NSEC":return Zd;case"NSEC3":return Qd;case"SSHFP":return za;case"DS":return ef}return mp}var un=He({encode(t,e,r){e||(e=new Uint8Array(un.encodingLength(t))),r||(r=0);let n=r;if(se.encode(t.name,e,r),r+=se.encode.bytes,ae(e,Fa(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");ae(e,t.udpPayloadSize||4096,r+2),e[r+4]=t.extendedRcode||0,e[r+5]=t.ednsVersion||0,ae(e,t.flags||0,r+6),r+=8,ns.encode(t.options||[],e,r),r+=ns.encode.bytes}else{let i=zw(t.class===void 0?"IN":t.class);t.flush&&(i|=Qw),ae(e,i,r+2),fi(e,t.ttl||0,r+4),r+=8;let o=Zw(t.type);o.encode(t.data,e,r),r+=o.encode.bytes}return un.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={},n=e;if(r.name=se.decode(t,e),e+=se.decode.bytes,r.type=zd(he(t,e)),r.type==="OPT")r.udpPayloadSize=he(t,e+2),r.extendedRcode=t[e+4],r.ednsVersion=t[e+5],r.flags=he(t,e+6),r.flag_do=(r.flags>>15&1)===1,r.options=ns.decode(t,e+8),e+=8+ns.decode.bytes;else{let i=he(t,e+2);r.ttl=di(t,e+4),r.class=Gw(i&hC),r.flush=!!(i&Qw);let o=Zw(r.type);r.data=o.decode(t,e+8),e+=8+o.decode.bytes}return un.decode.bytes=e-n,r},encodingLength(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return se.encodingLength(t.name)+8+Zw(t.type).encodingLength(e)}}),Xa=He({encode(t,e,r){e||(e=new Uint8Array(Xa.encodingLength(t))),r||(r=0);let n=r;return se.encode(t.name,e,r),r+=se.encode.bytes,ae(e,Fa(t.type),r),r+=2,ae(e,zw(t.class===void 0?"IN":t.class),r),r+=2,Xa.encode.bytes=r-n,t},decode(t,e){e||(e=0);let r=e,n={};return n.name=se.decode(t,e),e+=se.decode.bytes,n.type=zd(he(t,e)),e+=2,n.class=Gw(he(t,e)),e+=2,!!(n.class&I_)&&(n.class&=pC),Xa.decode.bytes=e-r,n},encodingLength(t){return se.encodingLength(t.name)+4}});var R_=1024;var qt={encode:function(t,e,r){let n=!e;n&&(e=new Uint8Array(yC(t))),r||(r=0);let i=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Ga.encode(t,e,r),r+=Ga.encode.bytes,r=tf(t.questions,Xa,e,r),r=tf(t.answers,un,e,r),r=tf(t.authorities,un,e,r),r=tf(t.additionals,un,e,r),qt.encode.bytes=r-i,n&&rf.bytes!==e.length?e.slice(0,rf.bytes):e},decode:function(t,e){e||(e=0);let r=e,n=Ga.decode(t,e);return e+=Ga.decode.bytes,e=gp(n.questions,Xa,t,e),e=gp(n.answers,un,t,e),e=gp(n.authorities,un,t,e),e=gp(n.additionals,un,t,e),qt.decode.bytes=e-r,n},encodingLength:function(t){return Ga.encodingLength(t)+Ya(t.questions||[],Xa)+Ya(t.answers||[],un)+Ya(t.authorities||[],un)+Ya(t.additionals||[],un)}};qt.encode.bytes=0;qt.decode.bytes=0;function _p(t,e){if(t.questions)throw new Error("Only one .question object expected instead of a .questions array!");let r=Object.assign({type:e},t);return r.question&&(r.questions=[r.question],delete r.question),r}var Ip={encode:function(t,e,r){return e=qt.encode(_p(t,"query"),e,r),Ip.encode.bytes=qt.encode.bytes,e},decode:function(t,e){let r=qt.decode(t,e);return Ip.decode.bytes=qt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return qt.encodingLength(_p(t,"query"))}};Ip.encode.bytes=0;Ip.decode.bytes=0;var Bp={encode:function(t,e,r){return e=qt.encode(_p(t,"response"),e,r),Bp.encode.bytes=qt.encode.bytes,e},decode:function(t,e){let r=qt.decode(t,e);return Bp.decode.bytes=qt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return qt.encodingLength(_p(t,"response"))}};Bp.encode.bytes=0;Bp.decode.bytes=0;var rf=qt.encode,Rp=qt.decode,yC=qt.encodingLength;function U_(t){let e=rf(t),r=new Uint8Array(2+e.byteLength);return ae(r,e.byteLength),br(e,r,2,0,e.length),U_.bytes=r.byteLength,r}U_.bytes=0;function O_(t){let e=he(t,0);if(t.byteLength<e+2)return null;let r=Rp(t.slice(2));return O_.bytes=Rp.bytes,r}O_.bytes=0;function Ya(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function tf(t,e,r,n){for(let i=0;i<t.length;i++)e.encode(t[i],r,n),n+=e.encode.bytes;return n}function gp(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e.decode(r,n),n+=e.decode.bytes;return n}l();var D_=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},dn=class{static getSigningMethod(e){return D_(this,void 0,void 0,function*(){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")})}static resolve(e,r){return D_(this,void 0,void 0,function*(){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")})}};var Ct=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},k_=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},N_="https://diddht.tbddev.org",gC=0,is=7200,Up=";",sr=",",tb;(function(t){t[t.Discoverable=0]="Discoverable",t[t.Organization=1]="Organization",t[t.Government=2]="Government",t[t.Corporation=3]="Corporation",t[t.LocalBusiness=4]="LocalBusiness",t[t.SoftwarePackage=5]="SoftwarePackage",t[t.WebApp=6]="WebApp",t[t.FinancialInstitution=7]="FinancialInstitution"})(tb||(tb={}));var cr;(function(t){t[t.Ed25519=0]="Ed25519",t[t.secp256k1=1]="secp256k1",t[t.secp256r1=2]="secp256r1",t[t.X25519=3]="X25519"})(cr||(cr={}));var rb;(function(t){t.authentication="auth",t.assertionMethod="asm",t.capabilityDelegation="del",t.capabilityInvocation="inv",t.keyAgreement="agm"})(rb||(rb={}));var L_={Ed25519:cr.Ed25519,ES256K:cr.secp256k1,ES256:cr.secp256r1,"P-256":cr.secp256r1,secp256k1:cr.secp256k1,secp256r1:cr.secp256r1,X25519:cr.X25519},C_={[cr.Ed25519]:"EdDSA",[cr.secp256k1]:"ES256K",[cr.secp256r1]:"ES256",[cr.X25519]:"ECDH-ES+A256KW"},nf=class t extends dn{static create(){return Ct(this,arguments,void 0,function*({keyManager:e=new Qt,options:r={}}={}){var n,i,o,s,c,a,u,d,f,h,p;if(!((n=r.verificationMethods)===null||n===void 0)&&n.some(T=>!(T.algorithm in L_)))throw new Error("One or more verification method algorithms are not supported");let g=(i=r.verificationMethods)===null||i===void 0?void 0:i.filter(T=>"id"in T).map(T=>T.id);if(g&&g.length!==new Set(g).size)throw new Error("One or more verification method IDs are not unique");if(!((o=r.services)===null||o===void 0)&&o.some(T=>!T.id||!T.type||!T.serviceEndpoint))throw new Error("One or more services are missing required properties");let y=yield e.generateKey({algorithm:"Ed25519"}),x=yield e.getPublicKey({keyUri:y}),S=yield Nt.identityKeyToIdentifier({identityKey:x}),_=Object.assign(Object.assign({id:S},r.alsoKnownAs&&{alsoKnownAs:r.alsoKnownAs}),r.controllers&&{controller:r.controllers}),A=[...(s=r.verificationMethods)!==null&&s!==void 0?s:[]];A?.some(T=>{var M;return((M=T.id)===null||M===void 0?void 0:M.split("#").pop())==="0"})||A.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let T of A){let M=T.id&&T.id.split("#").pop()==="0"?y:yield e.generateKey({algorithm:T.algorithm}),q=yield e.getPublicKey({keyUri:M}),j=(a=(c=T.id)!==null&&c!==void 0?c:q.kid)!==null&&a!==void 0?a:yield ge({jwk:q});j=`${S}#${Mr(j)}`,(u=_.verificationMethod)!==null&&u!==void 0||(_.verificationMethod=[]),_.verificationMethod.push({id:j,type:"JsonWebKey",controller:(d=T.controller)!==null&&d!==void 0?d:S,publicKeyJwk:q});for(let $ of(f=T.purposes)!==null&&f!==void 0?f:[])_[$]||(_[$]=[]),_[$].push(j)}(h=r.services)===null||h===void 0||h.forEach(T=>{var M;(M=_.service)!==null&&M!==void 0||(_.service=[]),T.id=`${S}#${T.id.split("#").pop()}`,_.service.push(T)});let O=new wr({uri:S,document:_,metadata:Object.assign({published:!1},r.types&&{types:r.types}),keyManager:e});if(!((p=r.publish)!==null&&p!==void 0)||p){let T=yield t.publish({did:O,gatewayUri:r.gatewayUri});O.metadata=T.didDocumentMetadata}return O})}static import(e){return Ct(this,arguments,void 0,function*({portableDid:r,keyManager:n=new Qt}){var i;let o=me.parse(r.uri);if(o?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let s=yield wr.import({portableDid:r,keyManager:n});if(!(!((i=s.document.verificationMethod)===null||i===void 0)&&i.some(c=>{var a;return((a=c.id)===null||a===void 0?void 0:a.split("#").pop())==="0"})))throw new re(ie.InvalidDidDocument,"DID document must contain an Identity Key");return s})}static getSigningMethod(e){return Ct(this,arguments,void 0,function*({didDocument:r,methodId:n="#0"}){var i;let o=me.parse(r.id);if(o&&o.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${o.method}`);let s=(i=r.verificationMethod)===null||i===void 0?void 0:i.find(c=>{var a,u;return Mr(c.id)===((a=Mr(n))!==null&&a!==void 0?a:Mr((u=r.assertionMethod)===null||u===void 0?void 0:u[0]))});if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static publish(e){return Ct(this,arguments,void 0,function*({did:r,gatewayUri:n=N_}){return yield Op.put({did:r,gatewayUri:n})})}static resolve(e){return Ct(this,arguments,void 0,function*(r,n={}){var i;let o=(i=n?.gatewayUri)!==null&&i!==void 0?i:N_;try{yield Nt.identifierToIdentityKey({didUri:r});let{didDocument:s,didDocumentMetadata:c}=yield Op.get({didUri:r,gatewayUri:o});return Object.assign(Object.assign({},yt),{didDocument:s,didDocumentMetadata:c})}catch(s){if(!(s instanceof re))throw new Error(s);return Object.assign(Object.assign({},yt),{didResolutionMetadata:Object.assign({error:s.code},s.message&&{errorMessage:s.message})})}})}};nf.methodName="dht";var Op=class t{static get(e){return Ct(this,arguments,void 0,function*({didUri:r,gatewayUri:n}){let i=Nt.identifierToIdentityKeyBytes({didUri:r}),o=yield t.pkarrGet({gatewayUri:n,publicKeyBytes:i}),s=yield Nt.parseBep44GetMessage({bep44Message:o}),c=yield t.fromDnsPacket({didUri:r,dnsPacket:s});return c.didDocumentMetadata.versionId=o.seq.toString(),c})}static put(e){return Ct(this,arguments,void 0,function*({did:r,gatewayUri:n}){let i=yield t.toDnsPacket({didDocument:r.document,didMetadata:r.metadata,authoritativeGatewayUris:[n]}),o=yield Nt.createBep44PutMessage({dnsPacket:i,publicKeyBytes:Nt.identifierToIdentityKeyBytes({didUri:r.uri}),signer:yield r.getSigner({methodId:"0"})}),s=yield t.pkarrPut({gatewayUri:n,bep44Message:o});return{didDocument:r.document,didDocumentMetadata:Object.assign(Object.assign({},r.metadata),{published:s,versionId:o.seq.toString()}),didRegistrationMetadata:{}}})}static pkarrGet(e){return Ct(this,arguments,void 0,function*({gatewayUri:r,publicKeyBytes:n}){let i=ne.uint8Array(n).toBase32Z(),o=new URL(i,r).href,s;try{if(s=yield fetch(o,{method:"GET"}),!s.ok)throw new re(ie.NotFound,`Pkarr record not found for: ${i}`)}catch(u){throw u instanceof re?u:new re(ie.InternalError,`Failed to fetch Pkarr record: ${u.message}`)}let c=yield s.arrayBuffer();if(!c)throw new re(ie.NotFound,`Pkarr record not found for: ${i}`);if(c.byteLength<72)throw new re(ie.InvalidDidDocumentLength,`Pkarr response must be at least 72 bytes but got: ${c.byteLength}`);if(c.byteLength>1072)throw new re(ie.InvalidDidDocumentLength,`Pkarr response exceeds 1000 byte limit: ${c.byteLength}`);return{k:n,seq:Number(new DataView(c).getBigUint64(64)),sig:new Uint8Array(c,0,64),v:new Uint8Array(c,72)}})}static pkarrPut(e){return Ct(this,arguments,void 0,function*({gatewayUri:r,bep44Message:n}){let i=ne.uint8Array(n.k).toBase32Z(),o=new URL(i,r).href,s=new Uint8Array(n.v.length+72);s.set(n.sig,0),new DataView(s.buffer).setBigUint64(n.sig.length,BigInt(n.seq)),s.set(n.v,n.sig.length+8);let c;try{c=yield fetch(o,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:s})}catch(a){throw new re(ie.InternalError,`Failed to put Pkarr record for identifier ${i}: ${a.message}`)}return c.ok})}static fromDnsPacket(e){return Ct(this,arguments,void 0,function*({didUri:r,dnsPacket:n}){var i,o,s;let c={id:r},a={published:!0},u=new Map;for(let d of(i=n?.answers)!==null&&i!==void 0?i:[]){if(d.type!=="TXT")continue;let f=d.name.split(".")[0].substring(1);switch(!0){case f.startsWith("aka"):{let h=Nt.parseTxtDataToString(d.data);c.alsoKnownAs=h.split(sr);break}case f.startsWith("cnt"):{let h=Nt.parseTxtDataToString(d.data);c.controller=h.includes(sr)?h.split(sr):h;break}case f.startsWith("k"):{let{id:h,t:p,k:g,c:y,a:x}=Nt.parseTxtDataToObject(d.data),S=ne.base64Url(g).toUint8Array(),_=cr[Number(p)],A=yield Nt.keyConverter(_).bytesToPublicKey({publicKeyBytes:S});A.alg=x||C_[Number(p)];let O=f==="k0"?"0":h!==void 0?h:yield ge({jwk:A});(o=c.verificationMethod)!==null&&o!==void 0||(c.verificationMethod=[]);let T=`${r}#${O}`;c.verificationMethod.push({id:T,type:"JsonWebKey",controller:y??r,publicKeyJwk:A}),u.set(f,T);break}case f.startsWith("s"):{let h=Nt.parseTxtDataToObject(d.data),{id:p,t:g,se:y}=h,x=k_(h,["id","t","se"]),S=y.includes(sr)?y.split(sr):[y],_=Object.fromEntries(Object.entries(x).map(([A,O])=>[A,O.includes(sr)?O.split(sr):O]));(s=c.service)!==null&&s!==void 0||(c.service=[]),c.service.push(Object.assign(Object.assign({},_),{id:`${r}#${p}`,type:g,serviceEndpoint:S}));break}case f.startsWith("typ"):{let{id:h}=Nt.parseTxtDataToObject(d.data);a.types=h.split(sr).map(p=>Number(p));break}case f.startsWith("did"):{let h=_=>_.split(sr).map(A=>u.get(A)).filter(A=>typeof A=="string"),{auth:p,asm:g,del:y,inv:x,agm:S}=Nt.parseTxtDataToObject(d.data);p&&(c.authentication=h(p)),g&&(c.assertionMethod=h(g)),y&&(c.capabilityDelegation=h(y)),x&&(c.capabilityInvocation=h(x)),S&&(c.keyAgreement=h(S));break}}}return{didDocument:c,didDocumentMetadata:a,didResolutionMetadata:{}}})}static toDnsPacket(e){return Ct(this,arguments,void 0,function*({didDocument:r,didMetadata:n,authoritativeGatewayUris:i,previousDidProof:o}){var s,c,a,u,d;let f=[],h=[],p=new Map,g=[],y=[];if(o!==void 0){let{signature:_,previousDid:A}=o;yield Nt.validatePreviousDidProof({newDid:r.id,previousDidProof:o}),f.push({type:"TXT",name:"_prv._did.",ttl:is,data:`id=${A};s=${_}`})}if(r.alsoKnownAs&&f.push({type:"TXT",name:"_aka._did.",ttl:is,data:r.alsoKnownAs.join(sr)}),r.controller){let _=Array.isArray(r.controller)?r.controller.join(sr):r.controller;f.push({type:"TXT",name:"_cnt._did.",ttl:is,data:_})}for(let[_,A]of(c=(s=r.verificationMethod)===null||s===void 0?void 0:s.entries())!==null&&c!==void 0?c:[]){let O=`k${_}`;y.push(O);let T=A.id.split("#").pop();p.set(T,O);let M=A.publicKeyJwk;if(!(M?.crv&&M.crv in L_))throw new re(ie.InvalidPublicKeyType,`Verification method '${A.id}' contains an unsupported key type: ${(a=M?.crv)!==null&&a!==void 0?a:"undefined"}`);let q=cr[M.crv],j=yield Nt.keyConverter(M.crv).publicKeyToBytes({publicKey:M}),$=ne.uint8Array(j).toBase64Url(),Z=[`t=${q}`,`k=${$}`];T!=="0"&&(yield ge({jwk:M}))!==T&&Z.unshift(`id=${T}`),M.alg!==C_[q]&&Z.push(`a=${M.alg}`),A.controller!==r.id&&Z.push(`c=${A.controller}`),f.push({type:"TXT",name:`_${O}._did.`,ttl:is,data:Z.join(Up)})}(u=r.service)===null||u===void 0||u.forEach((_,A)=>{let O=`s${A}`;g.push(O);let{id:T,type:M,serviceEndpoint:q}=_,j=k_(_,["id","type","serviceEndpoint"]);T=Mr(T),q=Array.isArray(q)?q.join(","):q;let Z=Object.entries(Object.assign({id:T,t:M,se:q},j)).map(([G,I])=>`${G}=${I}`).join(Up),Q=Nt.chunkDataIfNeeded(Z);f.push({type:"TXT",name:`_${O}._did.`,ttl:is,data:Q})});let x=[`v=${gC}`];if(y.length&&x.push(`vm=${y.join(sr)}`),Object.keys(Pi).forEach(_=>{var A;let O=(A=r[_])===null||A===void 0?void 0:A.map(T=>p.get(T.split("#").pop()));if(O){let T=rb[_];x.push(`${T}=${O.join(sr)}`)}}),g.length&&x.push(`svc=${g.join(sr)}`),!((d=n.types)===null||d===void 0)&&d.length){let A=n.types.map(O=>typeof O=="string"?tb[O]:O);f.push({type:"TXT",name:"_typ._did.",ttl:is,data:`id=${A.join(sr)}`})}f.push({type:"TXT",name:"_did."+t.getUniqueDidSuffix(r.id)+".",ttl:is,data:x.join(Up)});for(let _ of i||[])h.push({type:"NS",name:"_did."+t.getUniqueDidSuffix(r.id)+".",ttl:is,data:_+"."});return{id:0,type:"response",flags:R_,answers:[...f,...h]}})}static getUniqueDidSuffix(e){return e.split(":")[2]}},Nt=class t{static createBep44PutMessage(e){return Ct(this,arguments,void 0,function*({dnsPacket:r,publicKeyBytes:n,signer:i}){let o=Math.ceil(Date.now()/1e3),s=rf(r),c=Ww.encode({seq:o,v:s}).subarray(1,-1);if(c.length>1e3)throw new re(ie.InvalidDidDocumentLength,`DNS packet exceeds the 1000 byte maximum size: ${c.length} bytes`);let a=yield i.sign({data:c});return{k:n,seq:o,sig:a,v:s}})}static identifierToIdentityKey(e){return Ct(this,arguments,void 0,function*({didUri:r}){let n=t.identifierToIdentityKeyBytes({didUri:r});return yield Bt.bytesToPublicKey({publicKeyBytes:n})})}static identifierToIdentityKeyBytes({didUri:e}){let r=me.parse(e);if(!r)throw new re(ie.InvalidDid,`Invalid DID URI: ${e}`);if(r.method!==nf.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${r.method}`);let n;try{n=ne.base32Z(r.id).toUint8Array()}catch{throw new re(ie.InvalidPublicKey,"Failed to decode method-specific identifier")}if(n.length!==32)throw new re(ie.InvalidPublicKeyLength,`Invalid public key length: ${n.length}`);return n}static identityKeyToIdentifier(e){return Ct(this,arguments,void 0,function*({identityKey:r}){let n=yield Bt.publicKeyToBytes({publicKey:r}),i=ne.uint8Array(n).toBase32Z();return`did:${nf.methodName}:${i}`})}static keyConverter(e){let n={Ed25519:Bt,"P-256":{publicKeyToBytes:i=>Ct(this,[i],void 0,function*({publicKey:o}){let s=yield Vt.publicKeyToBytes({publicKey:o});return yield Vt.compressPublicKey({publicKeyBytes:s})}),bytesToPublicKey:Vt.bytesToPublicKey,privateKeyToBytes:Vt.privateKeyToBytes,bytesToPrivateKey:Vt.bytesToPrivateKey},secp256k1:{publicKeyToBytes:i=>Ct(this,[i],void 0,function*({publicKey:o}){let s=yield kt.publicKeyToBytes({publicKey:o});return yield kt.compressPublicKey({publicKeyBytes:s})}),bytesToPublicKey:kt.bytesToPublicKey,privateKeyToBytes:kt.privateKeyToBytes,bytesToPrivateKey:kt.bytesToPrivateKey},X25519:Va}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static parseBep44GetMessage(e){return Ct(this,arguments,void 0,function*({bep44Message:r}){let n=yield Bt.bytesToPublicKey({publicKeyBytes:r.k}),i=Ww.encode({seq:r.seq,v:r.v}).subarray(1,-1);if(!(yield Bt.verify({key:n,signature:r.sig,data:i})))throw new re(ie.InvalidSignature,"Invalid signature for DHT BEP44 message");return Rp(r.v)})}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split(Up).reduce((r,n)=>{let[i,o]=n.split("=");return r[i]=o,r},{})}static parseTxtDataToString(e){if(typeof e=="string")return e;if(e instanceof Uint8Array)return ne.uint8Array(e).toString();if(Array.isArray(e))return e.map(r=>this.parseTxtDataToString(r)).join("");throw new re(ie.InternalError,"Pkarr returned DNS TXT record with invalid data type")}static validatePreviousDidProof(e){return Ct(this,arguments,void 0,function*({newDid:r,previousDidProof:n}){let i=yield t.identifierToIdentityKey({didUri:n.previousDid}),o=t.identifierToIdentityKeyBytes({didUri:r}),s=ne.base64Url(n.signature).toUint8Array();if(!(yield Bt.verify({key:i,data:o,signature:s})))throw new re(ie.InvalidPreviousDidProof,"The previous DID proof is invalid.")})}static chunkDataIfNeeded(e){if(e.length<=255)return e;let r=[];for(let n=0;n<e.length;n+=255)r.push(e.slice(n,n+255));return r}};l();l();l();l();l();var Ye={DeltaExceedsMaximumSize:"DeltaExceedsMaximumSize",DidDocumentPublicKeyIdDuplicated:"DidDocumentPublicKeyIdDuplicated",DidDocumentPublicKeyMissingOrIncorrectType:"DidDocumentPublicKeyMissingOrIncorrectType",DidDocumentServiceIdDuplicated:"DidDocumentServiceIdDuplicated",DidSuffixIncorrectLength:"DidSuffixIncorrectLength",EncodedStringIncorrectEncoding:"EncodedStringIncorrectEncoding",IdNotUsingBase64UrlCharacterSet:"IdNotUsingBase64UrlCharacterSet",IdTooLong:"IdTooLong",JwkEs256kMissingOrInvalidCrv:"JwkEs256kMissingOrInvalidCrv",JwkEs256kMissingOrInvalidKty:"JwkEs256kMissingOrInvalidKty",JwkEs256kHasIncorrectLengthOfX:"JwkEs256kHasIncorrectLengthOfX",JwkEs256kHasIncorrectLengthOfY:"JwkEs256kHasIncorrectLengthOfY",JwkEs256kHasIncorrectLengthOfD:"JwkEs256kHasIncorrectLengthOfD",MultihashStringNotAMultihash:"MultihashStringNotAMultihash",MultihashUnsupportedHashAlgorithm:"MultihashUnsupportedHashAlgorithm",PublicKeyJwkEs256kHasUnexpectedProperty:"PublicKeyJwkEs256kHasUnexpectedProperty",PublicKeyPurposeDuplicated:"PublicKeyPurposeDuplicated",ServiceEndpointCannotBeAnArray:"ServiceEndpointCannotBeAnArray",ServiceEndpointStringNotValidUri:"ServiceEndpointStringNotValidUri",ServiceTypeTooLong:"ServiceTypeTooLong"};l();var Me=class extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};l();l();l();l();var nX=new Uint8Array(0);var nb=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};l();var ib=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ob=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return P_(this,e)}},sb=class{constructor(e){this.decoders=e}or(e){return P_(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},P_=(t,e)=>new sb({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),cb=class{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new ib(e,r,n),this.decoder=new ob(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},mC=({name:t,prefix:e,encode:r,decode:n})=>new cb(t,e,r,n);var wC=(t,e,r,n)=>{let i={};for(let d=0;d<e.length;++d)i[e[d]]=d;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),c=0,a=0,u=0;for(let d=0;d<o;++d){let f=i[t[d]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,c+=r,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=r||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s},bC=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,c=0;for(let a=0;a<t.length;++a)for(c=c<<8|t[a],s+=8;s>r;)s-=r,o+=e[i&c>>s];if(s&&(o+=e[i&c<<r-s]),n)for(;o.length*r&7;)o+="=";return o},of=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>mC({prefix:e,name:t,encode(i){return bC(i,n,r)},decode(i){return wC(i,n,r,t)}});var pX=of({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yX=of({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sf=of({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),gX=of({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xr=class t{static encode(e){return sf.baseEncode(e)}static decodeAsBytes(e,r){if(!t.isBase64UrlString(e))throw new Me(Ye.EncodedStringIncorrectEncoding,`Given ${r} must be base64url string.`);return sf.baseDecode(e)}static decodeAsString(e,r){let n=t.decodeAsBytes(e,r);return t.bytesToString(n)}static isBase64UrlString(e){return/^[A-Za-z0-9_-]+$/.test(e)}static stringToBytes(e){return new TextEncoder().encode(e)}static bytesToString(e){return new TextDecoder().decode(e)}};l();var z_=Mn(K_(),1);l();l();var ab;(function(t){t.Public="public",t.Private="private"})(ab||(ab={}));var $r=ab;var Ut=class{static validateEs256kOperationKey(e,r){let n=new Set(["kty","crv","x","y"]);r===$r.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new Me(Ye.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new Me(Ye.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new Me(Ye.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new Me(Ye.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new Me(Ye.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(r===$r.Private&&(e.d===void 0||e.d.length!==43))throw new Me(Ye.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new Me(Ye.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!xr.isBase64UrlString(e))throw new Me(Ye.IdNotUsingBase64UrlCharacterSet,`Key ID '${e}' is not a Base64URL string.`)}static validatePublicKeyPurposes(e){if(e===void 0)return;let r=new Set;for(let n of e){if(r.has(n))throw new Me(Ye.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);r.add(n)}}};l();var cf=class{};cf.hashAlgorithmInMultihashCode=18;cf.maxCanonicalizedDeltaSizeInBytes=1e3;var ar=cf;l();var V_=Mn(H_(),1);var kn=class t{static canonicalizeAsBytes(e){let r=t.removeAllUndefinedProperties(e),n=V_.default(r);return xr.stringToBytes(n)}static removeAllUndefinedProperties(e){for(let r in e)typeof e[r]=="object"?t.removeAllUndefinedProperties(e[r]):e[r]===void 0&&delete e[r];return e}};l();l();l();l();var xC=j_,q_=128,EC=127,vC=~EC,SC=Math.pow(2,31);function j_(t,e,r){e=e||[],r=r||0;for(var n=r;t>=SC;)e[r++]=t&255|q_,t/=128;for(;t&vC;)e[r++]=t&255|q_,t>>>=7;return e[r]=t|0,j_.bytes=r-n+1,e}var AC=ub,TC=128,F_=127;function ub(t,n){var r=0,n=n||0,i=0,o=n,s,c=t.length;do{if(o>=c)throw ub.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&F_)<<i:(s&F_)*Math.pow(2,i),i+=7}while(s>=TC);return ub.bytes=o-n,r}var _C=Math.pow(2,7),IC=Math.pow(2,14),BC=Math.pow(2,21),RC=Math.pow(2,28),UC=Math.pow(2,35),OC=Math.pow(2,42),DC=Math.pow(2,49),kC=Math.pow(2,56),NC=Math.pow(2,63),CC=function(t){return t<_C?1:t<IC?2:t<BC?3:t<RC?4:t<UC?5:t<OC?6:t<DC?7:t<kC?8:t<NC?9:10},LC={encode:xC,decode:AC,encodingLength:CC},PC=LC,af=PC;var db=(t,e=0)=>[af.decode(t,e),af.decode.bytes],fb=(t,e,r=0)=>(af.encode(t,e,r),e),lb=t=>af.encodingLength(t);var hb=(t,e)=>{let r=e.byteLength,n=lb(t),i=n+lb(r),o=new Uint8Array(i+r);return fb(t,o,0),fb(r,o,n),o.set(e,i),new kp(t,r,e,o)},W_=t=>{let e=nb(t),[r,n]=db(e),[i,o]=db(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new kp(r,i,s,e)};var kp=class{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};l();l();var yb=({name:t,code:e,encode:r})=>new pb(t,e,r),pb=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?hb(this.code,r):r.then(n=>hb(this.code,n))}else throw Error("Unknown type, must be binary type")}};var G_=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Np=yb({name:"sha2-256",code:18,encode:G_("SHA-256")}),JX=yb({name:"sha2-512",code:19,encode:G_("SHA-512")});var uf=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Lt=class t{static hash(e,r){return uf(this,void 0,void 0,function*(){let n;switch(r){case 18:n=(yield Np.digest(e)).bytes;break;default:throw new Me(Ye.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,r){return uf(this,void 0,void 0,function*(){let n;switch(r){case 18:n=yield Np.encode(e);break;default:throw new Me(Ye.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,r){return uf(this,void 0,void 0,function*(){let n=kn.canonicalizeAsBytes(e);return yield t.hashThenEncode(n,r)})}static canonicalizeThenDoubleHashThenEncode(e,r){return uf(this,void 0,void 0,function*(){let n=kn.canonicalizeAsBytes(e),i=yield t.hashAsNonMultihashBytes(n,r);return yield t.hashThenEncode(i,r)})}static hashThenEncode(e,r){return uf(this,void 0,void 0,function*(){let n=yield t.hash(e,r);return xr.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,r){let n,i=xr.decodeAsBytes(e,r);try{n=W_(i)}catch{throw new Me(Ye.MultihashStringNotAMultihash,`Given ${r} string '${e}' is not a multihash after decoding.`)}let o=ar.hashAlgorithmInMultihashCode;if(o!==n.code)throw new Me(Ye.MultihashUnsupportedHashAlgorithm,`Given ${r} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};l();var gb;(function(t){t.Create="create",t.Update="update",t.Deactivate="deactivate",t.Recover="recover"})(gb||(gb={}));var df=gb;l();var mb;(function(t){t.Replace="replace",t.AddPublicKeys="add-public-keys",t.RemovePublicKeys="remove-public-keys",t.AddServices="add-services",t.RemoveServices="remove-services"})(mb||(mb={}));var mc=mb;var Cp=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},os=class t{static createCreateRequest(e){return Cp(this,void 0,void 0,function*(){let r=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;Ut.validateEs256kOperationKey(r,$r.Public),Ut.validateEs256kOperationKey(n,$r.Public),t.validateDidDocumentKeys(i),t.validateServices(o);let s=ar.hashAlgorithmInMultihashCode,c=[{action:mc.Replace,document:e.document}],a={updateCommitment:yield Lt.canonicalizeThenDoubleHashThenEncode(n,s),patches:c};t.validateDeltaSize(a);let d={deltaHash:yield Lt.canonicalizeThenHashThenEncode(a,s),recoveryCommitment:yield Lt.canonicalizeThenDoubleHashThenEncode(r,s)};return{type:df.Create,suffixData:d,delta:a}})}static createDeactivateRequest(e){return Cp(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.recoveryPublicKey,$r.Public);let r=ar.hashAlgorithmInMultihashCode,n=yield Lt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:df.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return Cp(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.recoveryPublicKey,$r.Public),Ut.validateEs256kOperationKey(e.nextRecoveryPublicKey,$r.Public),Ut.validateEs256kOperationKey(e.nextUpdatePublicKey,$r.Public),t.validateDidDocumentKeys(e.document.publicKeys),t.validateServices(e.document.services);let r=ar.hashAlgorithmInMultihashCode,n=yield Lt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i=[{action:mc.Replace,document:e.document}],o=yield Lt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,r),s={patches:i,updateCommitment:o},c=yield Lt.canonicalizeThenHashThenEncode(s,r),u={recoveryCommitment:yield Lt.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,r),recoveryKey:e.recoveryPublicKey,deltaHash:c},d=yield e.signer.sign({alg:"ES256K"},u);return{type:df.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:d}})}static createUpdateRequest(e){return Cp(this,void 0,void 0,function*(){if(t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.updatePublicKey,$r.Public),Ut.validateEs256kOperationKey(e.nextUpdatePublicKey,$r.Public),t.validateServices(e.servicesToAdd),t.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let g of e.idsOfServicesToRemove)Ut.validateId(g);if(e.idsOfPublicKeysToRemove!==void 0)for(let g of e.idsOfPublicKeysToRemove)Ut.validateId(g);let r=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let g={action:mc.AddServices,services:n};r.push(g)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let g={action:mc.RemoveServices,ids:i};r.push(g)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let g={action:mc.AddPublicKeys,publicKeys:o};r.push(g)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let g={action:mc.RemovePublicKeys,ids:s};r.push(g)}let c=ar.hashAlgorithmInMultihashCode,a=yield Lt.canonicalizeThenHashThenEncode(e.updatePublicKey,c),u=yield Lt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,c),d={patches:r,updateCommitment:u},f=yield Lt.canonicalizeThenHashThenEncode(d,c),h={updateKey:e.updatePublicKey,deltaHash:f},p=yield e.signer.sign({alg:"ES256K"},h);return{type:df.Update,didSuffix:e.didSuffix,revealValue:a,delta:d,signedData:p}})}static validateDidSuffix(e){Lt.validateEncodedHashComputedUsingSupportedHashAlgorithm(e,"didSuffix")}static validateDidDocumentKeys(e){if(e===void 0)return;let r=new Set;for(let n of e){if(Array.isArray(n.publicKeyJwk))throw new Me(Ye.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(Ut.validateId(n.id),r.has(n.id))throw new Me(Ye.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);r.add(n.id),Ut.validatePublicKeyPurposes(n.purposes)}}static validateServices(e){if(e!==void 0&&e.length!==0){let r=new Set;for(let n of e){if(t.validateService(n),r.has(n.id))throw new Me(Ye.DidDocumentServiceIdDuplicated,"Service id has to be unique");r.add(n.id)}}}static validateService(e){Ut.validateId(e.id);let r=30;if(e.type.length>r){let n=`Service endpoint type length ${e.type.length} exceeds max allowed length of ${r}.`;throw new Me(Ye.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new Me(Ye.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&z_.parse(e.serviceEndpoint).error!==void 0)throw new Me(Ye.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let r=kn.canonicalizeAsBytes(e);if(r.length>ar.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${r.length} bytes exceeded limit of ${ar.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new Me(Ye.DeltaExceedsMaximumSize,n)}}};var Y_=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Za=class t{static createLongFormDid(e){return Y_(this,void 0,void 0,function*(){let r=yield os.createCreateRequest(e),n=yield t.computeDidUniqueSuffix(r.suffixData),i;ar.network===void 0||ar.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${ar.network}:${n}`;let o={suffixData:r.suffixData,delta:r.delta},s=kn.canonicalizeAsBytes(o),c=xr.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return Y_(this,void 0,void 0,function*(){let r=kn.canonicalizeAsBytes(e),n=yield Lt.hash(r,ar.hashAlgorithmInMultihashCode);return xr.encode(n)})}};l();l();var J_;(function(t){t.Mainnet="mainnet",t.Testnet="test"})(J_||(J_={}));l();var X_;(function(t){t.Authentication="authentication",t.AssertionMethod="assertionMethod",t.CapabilityInvocation="capabilityInvocation",t.CapabilityDelegation="capabilityDelegation",t.KeyAgreement="keyAgreement"})(X_||(X_={}));l();var ss=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},hi;(function(t){t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519"})(hi||(hi={}));var $C={Ed25519:hi.Ed25519,ES256K:hi.secp256k1,ES256:hi.secp256r1,"P-256":hi.secp256r1,secp256k1:hi.secp256k1,secp256r1:hi.secp256r1},Z_="https://ion.tbd.engineering",wb=class t extends dn{static create(){return ss(this,arguments,void 0,function*({keyManager:e=new Qt,options:r={}}={}){var n,i,o,s,c,a,u;if(!((n=r.verificationMethods)===null||n===void 0)&&n.some(T=>!(T.algorithm in $C)))throw new Error("One or more verification method algorithms are not supported");let d=(i=r.verificationMethods)===null||i===void 0?void 0:i.filter(T=>"id"in T).map(T=>T.id);if(d&&d.length!==new Set(d).size)throw new Error("One or more verification method IDs are not unique");if(!((o=r.services)===null||o===void 0)&&o.some(T=>!T.id||!T.type||!T.serviceEndpoint))throw new Error("One or more services are missing required properties");let f={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},h=[];for(let T of(s=r.verificationMethods)!==null&&s!==void 0?s:[f]){let M=yield e.generateKey({algorithm:T.algorithm}),q=yield e.getPublicKey({keyUri:M});h.push({id:T.id,publicKeyJwk:q,purposes:(c=T.purposes)!==null&&c!==void 0?c:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let p=yield e.generateKey({algorithm:hi.secp256k1}),g=yield e.getPublicKey({keyUri:p}),y=yield e.generateKey({algorithm:hi.secp256k1}),x=yield e.getPublicKey({keyUri:y}),S=yield wc.computeLongFormDidUri({recoveryKey:g,updateKey:x,services:(a=r.services)!==null&&a!==void 0?a:[],verificationMethods:h}),{didDocument:_,didResolutionMetadata:A}=yield t.resolve(S,{gatewayUri:r.gatewayUri});if(_===null)throw new Error(`Unable to resolve DID during creation: ${A?.error}`);let O=new wr({uri:S,document:_,metadata:{published:!1,canonicalId:S.split(":",3).join(":"),recoveryKey:g,updateKey:x},keyManager:e});if(!((u=r.publish)!==null&&u!==void 0)||u){let T=yield t.publish({did:O,gatewayUri:r.gatewayUri});O.metadata=T.didDocumentMetadata}return O})}static getSigningMethod(e){return ss(this,arguments,void 0,function*({didDocument:r,methodId:n}){var i;let o=me.parse(r.id);if(o&&o.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${o.method}`);let s=(i=r.verificationMethod)===null||i===void 0?void 0:i.find(c=>{var a;return c.id===(n??((a=r.assertionMethod)===null||a===void 0?void 0:a[0]))});if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static import(e){return ss(this,arguments,void 0,function*({portableDid:r,keyManager:n=new Qt}){let i=me.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");return yield wr.import({portableDid:r,keyManager:n})})}static publish(e){return ss(this,arguments,void 0,function*({did:r,gatewayUri:n=Z_}){var i,o,s;let c=(o=(i=r.document.verificationMethod)===null||i===void 0?void 0:i.map(d=>({id:d.id,publicKeyJwk:d.publicKeyJwk,purposes:r_({didDocument:r.document,methodId:d.id})})))!==null&&o!==void 0?o:[],a=yield wc.createIonDocument({services:(s=r.document.service)!==null&&s!==void 0?s:[],verificationMethods:c}),u=yield wc.constructCreateRequest({ionDocument:a,recoveryKey:r.metadata.recoveryKey,updateKey:r.metadata.updateKey});try{let d=wc.appendPathToUrl({baseUrl:n,path:"/operations"}),f=yield fetch(d,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});return{didDocument:r.document,didDocumentMetadata:Object.assign(Object.assign({},r.metadata),{published:f.ok}),didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:ie.InternalError,errorMessage:`Failed to publish DID document for: ${r.uri}`}}}})}static resolve(e){return ss(this,arguments,void 0,function*(r,n={}){var i,o;let s=me.parse(r);if(!s)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"invalidDid"}});if(s.method!==t.methodName)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"methodNotSupported"}});let c=(i=n?.gatewayUri)!==null&&i!==void 0?i:Z_;try{let a=wc.appendPathToUrl({baseUrl:c,path:`/identifiers/${r}`}),u=yield fetch(a);if(!u.ok)throw new re(ie.NotFound,`Unable to find DID document for: ${r}`);let{didDocument:d,didDocumentMetadata:f}=yield u.json();return Object.assign(Object.assign(Object.assign({},yt),d&&{didDocument:d}),{didDocumentMetadata:Object.assign({published:(o=f?.method)===null||o===void 0?void 0:o.published},f)})}catch(a){if(!(a instanceof re))throw new Error(a);return Object.assign(Object.assign({},yt),{didResolutionMetadata:Object.assign({error:a.code},a.message&&{errorMessage:a.message})})}})}};wb.methodName="ion";var wc=class t{static appendPathToUrl({baseUrl:e,path:r}){let n=new URL(e);return n.pathname=n.pathname.endsWith("/")?n.pathname:n.pathname+"/",n.pathname+=r.startsWith("/")?r.substring(1):r,n.toString()}static computeLongFormDidUri(e){return ss(this,arguments,void 0,function*({recoveryKey:r,updateKey:n,services:i,verificationMethods:o}){let s=yield t.createIonDocument({services:i,verificationMethods:o}),c=t.normalizeJwk(r),a=t.normalizeJwk(n);return yield Za.createLongFormDid({document:s,recoveryKey:c,updateKey:a})})}static constructCreateRequest(e){return ss(this,arguments,void 0,function*({ionDocument:r,recoveryKey:n,updateKey:i}){return yield os.createCreateRequest({document:r,recoveryKey:t.normalizeJwk(n),updateKey:t.normalizeJwk(i)})})}static createIonDocument(e){return ss(this,arguments,void 0,function*({services:r,verificationMethods:n}){var i,o;let s=[];for(let u of n){let d=(o=(i=u.id)!==null&&i!==void 0?i:u.publicKeyJwk.kid)!==null&&o!==void 0?o:yield ge({jwk:u.publicKeyJwk});d=`${d.split("#").pop()}`;let f={id:d,publicKeyJwk:t.normalizeJwk(u.publicKeyJwk),purposes:u.purposes,type:"JsonWebKey2020"};s.push(f)}let c=r.map(u=>Object.assign(Object.assign({},u),{id:`${u.id.split("#").pop()}`}));return{publicKeys:s,services:c}})}static normalizeJwk(e){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);return n}};l();var Lp=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},bb=class t extends dn{static create(){return Lp(this,arguments,void 0,function*({keyManager:e=new Qt,options:r={}}={}){var n,i,o,s;if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let c=(s=(n=r.algorithm)!==null&&n!==void 0?n:(o=(i=r.verificationMethods)===null||i===void 0?void 0:i[0])===null||o===void 0?void 0:o.algorithm)!==null&&s!==void 0?s:"Ed25519",a=yield e.generateKey({algorithm:c}),u=yield e.getPublicKey({keyUri:a}),d=ne.object(u).toBase64Url(),f=`did:${t.methodName}:${d}`,p=(yield t.resolve(f)).didDocument;return new wr({uri:f,document:p,metadata:{},keyManager:e})})}static getSigningMethod(e){return Lp(this,arguments,void 0,function*({didDocument:r}){var n;let i=me.parse(r.id);if(i&&i.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${i.method}`);let[o]=(n=r.verificationMethod)!==null&&n!==void 0?n:[];if(!(o&&o.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return o})}static import(e){return Lp(this,arguments,void 0,function*({portableDid:r,keyManager:n=new Qt}){let i=me.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let o=yield wr.import({portableDid:r,keyManager:n});if(o.document.verificationMethod.length!==1)throw new re(ie.InvalidDidDocument,"DID document must contain exactly one verification method");return o})}static resolve(e,r){return Lp(this,void 0,void 0,function*(){let n=me.parse(e),i;try{i=ne.base64Url(n.id).toObject()}catch{}if(!n||!i)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"invalidDid"}});if(n.method!==t.methodName)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"methodNotSupported"}});let o={"@context":["https://www.w3.org/ns/did/v1"],id:n.uri},s=`${o.id}#0`;switch(o.verificationMethod=[{id:s,type:"JsonWebKey",controller:o.id,publicKeyJwk:i}],o.authentication=[s],o.assertionMethod=[s],o.capabilityInvocation=[s],o.capabilityDelegation=[s],o.keyAgreement=[s],i.use){case"sig":{delete o.keyAgreement;break}case"enc":{delete o.authentication,delete o.assertionMethod,delete o.capabilityInvocation,delete o.capabilityDelegation;break}}return Object.assign(Object.assign({},yt),{didDocument:o})})}};bb.methodName="jwk";l();var Nn=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},so;(function(t){t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519"})(so||(so={}));var xb={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1",X25519KeyAgreementKey2020:"https://w3id.org/security/suites/x25519-2020/v1"},HC={Ed25519:so.Ed25519,ES256K:so.secp256k1,ES256:so.secp256r1,"P-256":so.secp256r1,secp256k1:so.secp256k1,secp256r1:so.secp256r1,X25519:so.X25519},Eb=class t extends dn{static create(){return Nn(this,arguments,void 0,function*({keyManager:e=new Qt,options:r={}}={}){var n,i,o,s;if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let c=(s=(n=r.algorithm)!==null&&n!==void 0?n:(o=(i=r.verificationMethods)===null||i===void 0?void 0:i[0])===null||o===void 0?void 0:o.algorithm)!==null&&s!==void 0?s:"Ed25519",a=yield e.generateKey({algorithm:c}),u=yield e.getPublicKey({keyUri:a}),d=yield Er.publicKeyToMultibaseId({publicKey:u}),f=`did:${t.methodName}:${d}`,p=(yield t.resolve(f,r)).didDocument;return new wr({uri:f,document:p,metadata:{},keyManager:e})})}static getSigningMethod(e){return Nn(this,arguments,void 0,function*({didDocument:r}){var n;let i=me.parse(r.id);if(i&&i.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${i.method}`);let[o]=r.assertionMethod||[],s=(n=r.verificationMethod)===null||n===void 0?void 0:n.find(c=>c.id===o);if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static import(e){return Nn(this,arguments,void 0,function*({portableDid:r,keyManager:n=new Qt}){let i=me.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let o=yield wr.import({portableDid:r,keyManager:n});if(o.document.verificationMethod.length!==1)throw new re(ie.InvalidDidDocument,"DID document must contain exactly one verification method");return o})}static resolve(e,r){return Nn(this,void 0,void 0,function*(){try{let n=yield t.createDocument({didUri:e,options:r});return Object.assign(Object.assign({},yt),{didDocument:n})}catch(n){if(!(n instanceof re))throw new Error(n);return Object.assign(Object.assign({},yt),{didResolutionMetadata:Object.assign({error:n.code},n.message&&{errorMessage:n.message})})}})}static createDocument(e){return Nn(this,arguments,void 0,function*({didUri:r,options:n={}}){let{defaultContext:i="https://www.w3.org/ns/did/v1",enableEncryptionKeyDerivation:o=!1,enableExperimentalPublicKeyTypes:s=!1,publicKeyFormat:c="JsonWebKey2020"}=n,a={id:""},u=me.parse(r);if(!u)throw new re(ie.InvalidDid,`Invalid DID URI: ${r}`);let d=u.id;if(u.method!==t.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${u.method}`);if(!t.validateIdentifier(u))throw new re(ie.InvalidDid,`Invalid DID URI: ${r}`);let f=yield t.createSignatureMethod({didUri:r,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:s,publicKeyFormat:c}});if(a.id=u.uri,a.verificationMethod=[f],a.authentication=[f.id],a.assertionMethod=[f.id],a.capabilityInvocation=[f.id],a.capabilityDelegation=[f.id],o===!0){let g=c==="Ed25519VerificationKey2020"?"X25519KeyAgreementKey2020":"JsonWebKey2020",y=yield this.createEncryptionMethod({didUri:r,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:s,publicKeyFormat:g}});a.verificationMethod.push(y),a.keyAgreement=[y.id]}let h=[i];return t_({didDocument:a}).forEach(g=>{let y=xb[g];h.push(y)}),a["@context"]=h,a})}static createEncryptionMethod(e){return Nn(this,arguments,void 0,function*({didUri:r,multibaseValue:n,options:i}){let{enableExperimentalPublicKeyTypes:o,publicKeyFormat:s}=i,c={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u}=yield t.deriveEncryptionKey({multibaseValue:n}),d=a.byteLength,f=Er.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(d!==f)throw new re(ie.InvalidPublicKeyLength,`Expected ${d} bytes. Actual: ${f}`);let h=Kw({keyBytes:a,multicodecCode:u});c.id=`${r}#${h}`;try{new URL(c.id)}catch{throw new re(ie.InvalidDidUrl,"Verification Method ID is not a valid DID URL.")}if(!(s in xb))throw new re(ie.UnsupportedPublicKeyType,`Unsupported format: ${s}`);if(o===!1&&!["Multikey","JsonWebKey2020","X25519KeyAgreementKey2020"].includes(s))throw new re(ie.InvalidPublicKeyType,`Specified '${s}' without setting enableExperimentalPublicKeyTypes to true.`);if(c.type=s,c.controller=r,s==="X25519KeyAgreementKey2020"&&(c.publicKeyMultibase=h),s==="JsonWebKey2020"){let{crv:g}=yield Er.multicodecToJwk({code:u});c.publicKeyJwk=yield Er.keyConverter(g).bytesToPublicKey({publicKeyBytes:a})}return c})}static createSignatureMethod(e){return Nn(this,arguments,void 0,function*({didUri:r,multibaseValue:n,options:i}){let{enableExperimentalPublicKeyTypes:o,publicKeyFormat:s}=i,c={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u,multicodecName:d}=$w({multibaseKeyId:n}),f=a.byteLength,h=Er.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(f!==h)throw new re(ie.InvalidPublicKeyLength,`Expected ${f} bytes. Actual: ${h}`);let p=!1;switch(d){case"secp256k1-pub":p=yield kt.validatePublicKey({publicKeyBytes:a});break;case"ed25519-pub":p=yield Bt.validatePublicKey({publicKeyBytes:a});break;case"x25519-pub":p=!0;break}if(!p)throw new re(ie.InvalidPublicKey,"Invalid public key detected.");c.id=`${r}#${n}`;try{new URL(c.id)}catch{throw new re(ie.InvalidDidUrl,"Verification Method ID is not a valid DID URL.")}if(!(s in xb))throw new re(ie.UnsupportedPublicKeyType,`Unsupported format: ${s}`);if(o===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(s))throw new re(ie.InvalidPublicKeyType,`Specified '${s}' without setting enableExperimentalPublicKeyTypes to true.`);if(c.type=s,c.controller=r,s==="Ed25519VerificationKey2020"&&(c.publicKeyMultibase=n),s==="JsonWebKey2020"){let{crv:y}=yield Er.multicodecToJwk({code:u});c.publicKeyJwk=yield Er.keyConverter(y).bytesToPublicKey({publicKeyBytes:a})}return c})}static deriveEncryptionKey(e){return Nn(this,arguments,void 0,function*({multibaseValue:r}){let n={keyBytes:new Uint8Array,multicodecCode:0},{keyBytes:i,multicodecCode:o}=$w({multibaseKeyId:r});if(o===237){let s=yield Er.keyConverter("Ed25519").bytesToPublicKey({publicKeyBytes:i}),c=yield Bt.convertPublicKeyToX25519({publicKey:s});n={keyBytes:yield Er.keyConverter("Ed25519").publicKeyToBytes({publicKey:c}),multicodecCode:236}}return n})}static validateIdentifier(e){let{method:r,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&r==="key"&&Number("1")>0&&sa(n)==="String"&&n.startsWith("z")}};Eb.methodName="key";var Er=class t{static jwkToMulticodec(e){return Nn(this,arguments,void 0,function*({jwk:r}){let n=[];r.crv&&(n.push(r.crv),r.d?n.push("private"):n.push("public"));let i=n.join(":"),o=t.JWK_TO_MULTICODEC[i];if(o===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${i}'`);return{code:Yt.getCodeFromName({name:o}),name:o}})}static keyCompressor(e){let n={"P-256":Vt.compressPublicKey,secp256k1:kt.compressPublicKey}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Bt,"P-256":Vt,secp256k1:kt,X25519:Va}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static multicodecToJwk(e){return Nn(this,arguments,void 0,function*({code:r,name:n}){if(!(n?!r:r))throw new Error("Either 'name' or 'code' must be defined, but not both.");n=n===void 0?Yt.getNameFromCode({code:r}):n;let i=n,o=t.MULTICODEC_TO_JWK[i];if(o===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return Object.assign({},o)})}static publicKeyToMultibaseId(e){return Nn(this,arguments,void 0,function*({publicKey:r}){var n;if(!(r?.crv&&r.crv in HC))throw new re(ie.InvalidPublicKeyType,`Public key contains an unsupported key type: ${(n=r?.crv)!==null&&n!==void 0?n:"undefined"}`);let i=yield t.keyConverter(r.crv).publicKeyToBytes({publicKey:r});/^(secp256k1|P-256|P-384|P-521)$/.test(r.crv)&&(i=yield t.keyCompressor(r.crv)({publicKeyBytes:i}));let{name:o}=yield t.jwkToMulticodec({jwk:r});return Kw({keyBytes:i,multicodecName:o})})}};Er.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv","X25519:public":"x25519-pub","X25519:private":"x25519-priv"};Er.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,236:32,237:32};Er.MULTICODEC_TO_JWK={"ed25519-pub":{crv:"Ed25519",kty:"OKP",x:""},"ed25519-priv":{crv:"Ed25519",kty:"OKP",x:"",d:""},"secp256k1-pub":{crv:"secp256k1",kty:"EC",x:"",y:""},"secp256k1-priv":{crv:"secp256k1",kty:"EC",x:"",y:"",d:""},"x25519-pub":{crv:"X25519",kty:"OKP",x:""},"x25519-priv":{crv:"X25519",kty:"OKP",x:"",d:""}};l();var VC=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},vb=class t extends dn{static resolve(e,r){return VC(this,void 0,void 0,function*(){let n=me.parse(e);if(!n)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"invalidDid"}});if(n.method!==t.methodName)return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"methodNotSupported"}});let i=`https://${n.id.replace(/:/g,"/")}`;i=decodeURIComponent(i);let o=n.id.includes(":")?`${i}/did.json`:`${i}/.well-known/did.json`;try{let s=yield fetch(o);if(!s.ok)throw new Error("HTTP error status code returned");let c=yield s.json();return Object.assign(Object.assign({},yt),{didDocument:c})}catch{return Object.assign(Object.assign({},yt),{didResolutionMetadata:{error:"notFound"}})}})}};vb.methodName="web";l();var zC=Mn(eI(),1),YC=Mn(Xg(),1);l();l();var ut=class t{static absoluteDidUrl(e,r){if(typeof e=="string"&&e.length!==0)return e.startsWith("#")?`${r}${e}`:e}static relationshipMethodId(e,r){let n=typeof e=="object"&&e!==null&&!Array.isArray(e)?e.id:e;return t.absoluteDidUrl(n,r)}static isDidVerificationMethod(e){return!(!e||typeof e!="object"||e===null||!("id"in e&&"type"in e&&"controller"in e)||typeof e.id!="string"||typeof e.type!="string"||typeof e.controller!="string")}static isDidService(e){return!(!e||typeof e!="object"||e===null||!("id"in e&&"type"in e&&"serviceEndpoint"in e)||typeof e.id!="string"||typeof e.type!="string"||typeof e.serviceEndpoint!="string")}static getVerificationMethods(e){if(!e)throw new qe("Required parameter missing: 'didDocument'");let r=[];return r.push(...e.verificationMethod?.filter(t.isDidVerificationMethod)??[]),Object.keys(Pi).forEach(n=>{r.push(...e[n]?.filter(t.isDidVerificationMethod)??[])}),r}static deriveRootCapability(e){return{"@context":"https://w3id.org/zcap/v1",id:`urn:zcap:root:${encodeURIComponent(e)}`,controller:e,invocationTarget:e}}static dereferenceZcapId(e){let r={},[n,i,o,s]=e.split(":")??[];if([n,i,o,s].length!==4)throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);if(!n||n!=="urn")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);if(!i||i!=="zcap")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);if(!o||o!=="root")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);let a=decodeURIComponent(s);return r.id=e,r.controller=a,r.invocationTarget=a,r}};l();l();l();l();l();l();l();function tI(t,e,r){return t&e^~t&r}function rI(t,e,r){return t&e^t&r^e&r}var Mp=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Ul(this.buffer)}update(e){ea(this),Te(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Ul(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ea(this),Ov(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,Ns(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;n.setBigUint64(i-8,BigInt(this.length*8),o),this.process(n,0);let c=Ul(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=c,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},co=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var JC=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]),cs=new Uint32Array(64),Sb=class extends Mp{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)cs[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=cs[f-15],p=cs[f-2],g=En(h,7)^En(h,18)^h>>>3,y=En(p,17)^En(p,19)^p>>>10;cs[f]=y+cs[f-7]+g+cs[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=En(c,6)^En(c,11)^En(c,25),p=d+h+tI(c,a,u)+JC[f]+cs[f]|0,y=(En(n,2)^En(n,13)^En(n,22))+rI(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Ns(cs)}destroy(){this.set(0,0,0,0,0,0,0,0),Ns(this.buffer)}},Ab=class extends Sb{A=co[0]|0;B=co[1]|0;C=co[2]|0;D=co[3]|0;E=co[4]|0;F=co[5]|0;G=co[6]|0;H=co[7]|0;constructor(){super(32)}};var Kp=kv(()=>new Ab,Nv(1));l();l();var ur=BigInt(0),er=BigInt(1),xc=BigInt(2),oI=BigInt(3),sI=BigInt(4),cI=BigInt(5),XC=BigInt(7),aI=BigInt(8),ZC=BigInt(9),uI=BigInt(16);function Cn(t,e){let r=t%e;return r>=ur?r:e+r}function Hr(t,e,r){let n=t;for(;e-- >ur;)n*=n,n%=r;return n}function nI(t,e){if(t===ur)throw new Error("invert: expected non-zero number");if(e<=ur)throw new Error("invert: expected positive modulus, got "+e);let r=Cn(t,e),n=e,i=ur,o=er,s=er,c=ur;for(;r!==ur;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==er)throw new Error("invert: does not exist");return Cn(i,e)}function _b(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function dI(t,e){let r=(t.ORDER+er)/sI,n=t.pow(e,r);return _b(t,n,e),n}function QC(t,e){let r=(t.ORDER-cI)/aI,n=t.mul(e,xc),i=t.pow(n,r),o=t.mul(e,i),s=t.mul(t.mul(o,xc),i),c=t.mul(o,t.sub(s,t.ONE));return _b(t,c,e),c}function eL(t){let e=ru(t),r=fI(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),s=(t+XC)/uI;return(c,a)=>{let u=c.pow(a,s),d=c.mul(u,n),f=c.mul(u,i),h=c.mul(u,o),p=c.eql(c.sqr(d),a),g=c.eql(c.sqr(f),a);u=c.cmov(u,d,p),d=c.cmov(h,f,g);let y=c.eql(c.sqr(d),a),x=c.cmov(u,d,y);return _b(c,x,a),x}}function fI(t){if(t<oI)throw new Error("sqrt is not defined for small field");let e=t-er,r=0;for(;e%xc===ur;)e/=xc,r++;let n=xc,i=ru(t);for(;iI(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return dI;let o=i.pow(n,e),s=(e+er)/xc;return function(a,u){if(a.is0(u))return u;if(iI(a,u)!==1)throw new Error("Cannot find square root");let d=r,f=a.mul(a.ONE,o),h=a.pow(u,e),p=a.pow(u,s);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,y=a.sqr(h);for(;!a.eql(y,a.ONE);)if(g++,y=a.sqr(y),g===d)throw new Error("Cannot find square root");let x=er<<BigInt(d-g-1),S=a.pow(f,x);d=g,f=a.sqr(S),h=a.mul(h,f),p=a.mul(p,S)}return p}}function tL(t){return t%sI===oI?dI:t%aI===cI?QC:t%uI===ZC?eL(t):fI(t)}var rL=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ib(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=rL.reduce((n,i)=>(n[i]="function",n),e);return Xu(t,r),t}function nL(t,e,r){if(r<ur)throw new Error("invalid exponent, negatives unsupported");if(r===ur)return t.ONE;if(r===er)return e;let n=t.ONE,i=e;for(;r>ur;)r&er&&(n=t.mul(n,i)),i=t.sqr(i),r>>=er;return n}function $p(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),i=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),o=t.inv(i);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),o),n}function iI(t,e){let r=(t.ORDER-er)/xc,n=t.pow(e,r),i=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function iL(t,e){e!==void 0&&Yn(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Tb=class{ORDER;BITS;BYTES;isLE;ZERO=ur;ONE=er;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=ur)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:o}=iL(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Cn(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return ur<=e&&e<this.ORDER}is0(e){return e===ur}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&er)===er}neg(e){return Cn(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Cn(e*e,this.ORDER)}add(e,r){return Cn(e+r,this.ORDER)}sub(e,r){return Cn(e-r,this.ORDER)}mul(e,r){return Cn(e*r,this.ORDER)}pow(e,r){return nL(this,e,r)}div(e,r){return Cn(e*nI(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return nI(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=tL(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?P0(e,this.BYTES):Dl(e,this.BYTES)}fromBytes(e,r=!1){Te(e);let{_lengths:n,BYTES:i,isLE:o,ORDER:s,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(i);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let a=o?L0(e):Do(e);if(c&&(a=Cn(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return $p(this,e)}cmov(e,r,n){return n?r:e}};function ru(t,e={}){return new Tb(t,e)}function lI(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Bb(t){let e=lI(t);return e+Math.ceil(e/2)}function Hp(t,e,r=!1){Te(t);let n=t.length,i=lI(e),o=Bb(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let s=r?L0(t):Do(t),c=Cn(s,e-er)+er;return r?P0(c,i):Dl(c,i)}var nu=BigInt(0),Ec=BigInt(1);function ff(t,e){let r=e.negate();return t?r:e}function Db(t,e){let r=$p(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function gI(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Rb(t,e){gI(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=Ju(t),s=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function hI(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r,c=Number(t&i),a=t>>s;c>n&&(c-=o,a+=Ec);let u=e*n,d=u+Math.abs(c)-1,f=c===0,h=c<0,p=e%2!==0;return{nextN:a,offset:d,isZero:f,isNeg:h,isNegF:p,offsetF:u}}var Ub=new WeakMap,mI=new WeakMap;function Ob(t){return mI.get(t)||1}function pI(t){if(t!==nu)throw new Error("invalid wNAF")}var Vp=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>nu;)r&Ec&&(n=n.add(i)),i=i.double(),r>>=Ec;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=Rb(r,this.bits),o=[],s=e,c=s;for(let a=0;a<n;a++){c=s,o.push(c);for(let u=1;u<i;u++)c=c.add(s),o.push(c);s=c.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=Rb(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:p}=hI(n,c,s);n=a,d?o=o.add(ff(h,r[p])):i=i.add(ff(f,r[u]))}return pI(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=Rb(e,this.bits);for(let s=0;s<o.windows&&n!==nu;s++){let{nextN:c,offset:a,isZero:u,isNeg:d}=hI(n,s,o);if(n=c,!u){let f=r[a];i=i.add(d?f.negate():f)}}return pI(n),i}getPrecomputes(e,r,n){let i=Ub.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),Ub.set(r,i))),i}cached(e,r,n){let i=Ob(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=Ob(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){gI(r,this.bits),mI.set(e,r),Ub.delete(e)}hasCache(e){return Ob(e)!==1}};function wI(t,e,r,n){let i=e,o=t.ZERO,s=t.ZERO;for(;r>nu||n>nu;)r&Ec&&(o=o.add(i)),n&Ec&&(s=s.add(i)),i=i.double(),r>>=Ec,n>>=Ec;return{p1:o,p2:s}}function yI(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ib(e),e}else return ru(t,{isLE:r})}function bI(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>nu))throw new Error(`CURVE.${a} must be positive bigint`)}let i=yI(e.p,r.Fp,n),o=yI(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}function qp(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}l();l();var Fp=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if(Rl(e),Te(r,void 0,"key"),this.iHash=e.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;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Ns(i)}update(e){return ea(this),this.iHash.update(e),this}digestInto(e){ea(this),Te(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},kb=(t,e,r)=>new Fp(t,e).update(r).digest();kb.create=(t,e)=>new Fp(t,e);var xI=(t,e)=>(t+(t>=0?e:-e)/EI)/e;function oL(t,e,r){let[[n,i],[o,s]]=e,c=xI(s*t,r),a=xI(-i*t,r),u=t-c*n-a*o,d=-c*i-a*s,f=u<ao,h=d<ao;f&&(u=-u),h&&(d=-d);let p=Ju(Math.ceil(M0(r)/2))+iu;if(u<ao||u>=p||d<ao||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}function Cb(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Nb(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return zu(r.lowS,"lowS"),zu(r.prehash,"prehash"),r.format!==void 0&&Cb(r.format),r}var Lb=class extends Error{constructor(e=""){super(e)}},as={Err:Lb,_tlv:{encode:(t,e)=>{let{Err:r}=as;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=Yu(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Yu(i.length/2|128):"";return Yu(t)+o+i+e},decode(t,e){let{Err:r}=as,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),s=0;if(!o)s=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)s=s<<8|d;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=as;if(t<ao)throw new e("integer: negative integers are not allowed");let r=Yu(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=as;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Do(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=as,i=Te(t,void 0,"signature"),{v:o,l:s}=n.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:u,l:d}=n.decode(2,a);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=as,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}},ao=BigInt(0),iu=BigInt(1),EI=BigInt(2),jp=BigInt(3),sL=BigInt(4);function vI(t,e={}){let r=bI("weierstrass",t,e),{Fp:n,Fn:i}=r,o=r.CURVE,{h:s,n:c}=o;Xu(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=AI(n,i);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(G,I,D){let{x:E,y:U}=I.toAffine(),L=n.toBytes(E);if(zu(D,"isCompressed"),D){d();let N=!n.isOdd(U);return hr(SI(N),L)}else return hr(Uint8Array.of(4),L,n.toBytes(U))}function h(G){Te(G,void 0,"Point");let{publicKey:I,publicKeyUncompressed:D}=u,E=G.length,U=G[0],L=G.subarray(1);if(E===I&&(U===2||U===3)){let N=n.fromBytes(L);if(!n.isValid(N))throw new Error("bad point: is not on curve, wrong x");let R=y(N),C;try{C=n.sqrt(R)}catch(J){let z=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let P=n.isOdd(C);return(U&1)===1!==P&&(C=n.neg(C)),{x:N,y:C}}else if(E===D&&U===4){let N=n.BYTES,R=n.fromBytes(L.subarray(0,N)),C=n.fromBytes(L.subarray(N,N*2));if(!x(R,C))throw new Error("bad point: is not on curve");return{x:R,y:C}}else throw new Error(`bad point: got length ${E}, expected compressed=${I} or uncompressed=${D}`)}let p=e.toBytes||f,g=e.fromBytes||h;function y(G){let I=n.sqr(G),D=n.mul(I,G);return n.add(n.add(D,n.mul(G,o.a)),o.b)}function x(G,I){let D=n.sqr(I),E=y(G);return n.eql(D,E)}if(!x(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(o.a,jp),sL),_=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(S,_)))throw new Error("bad curve params: a or b");function A(G,I,D=!1){if(!n.isValid(I)||D&&n.is0(I))throw new Error(`bad point coordinate ${G}`);return I}function O(G){if(!(G instanceof $))throw new Error("Weierstrass Point expected")}function T(G){if(!a||!a.basises)throw new Error("no endo");return oL(G,a.basises,i.ORDER)}let M=K0((G,I)=>{let{X:D,Y:E,Z:U}=G;if(n.eql(U,n.ONE))return{x:D,y:E};let L=G.is0();I==null&&(I=L?n.ONE:n.inv(U));let N=n.mul(D,I),R=n.mul(E,I),C=n.mul(U,I);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),q=K0(G=>{if(G.is0()){if(e.allowInfinityPoint&&!n.is0(G.Y))return;throw new Error("bad point: ZERO")}let{x:I,y:D}=G.toAffine();if(!n.isValid(I)||!n.isValid(D))throw new Error("bad point: x or y not field elements");if(!x(I,D))throw new Error("bad point: equation left != right");if(!G.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function j(G,I,D,E,U){return D=new $(n.mul(D.X,G),D.Y,D.Z),I=ff(E,I),D=ff(U,D),I.add(D)}class ${static BASE=new $(o.Gx,o.Gy,n.ONE);static ZERO=new $(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(I,D,E){this.X=A("x",I),this.Y=A("y",D,!0),this.Z=A("z",E),Object.freeze(this)}static CURVE(){return o}static fromAffine(I){let{x:D,y:E}=I||{};if(!I||!n.isValid(D)||!n.isValid(E))throw new Error("invalid affine point");if(I instanceof $)throw new Error("projective point not allowed");return n.is0(D)&&n.is0(E)?$.ZERO:new $(D,E,n.ONE)}static fromBytes(I){let D=$.fromAffine(g(Te(I,void 0,"point")));return D.assertValidity(),D}static fromHex(I){return $.fromBytes(Ls(I))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(I=8,D=!0){return Q.createCache(this,I),D||this.multiply(jp),this}assertValidity(){q(this)}hasEvenY(){let{y:I}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(I)}equals(I){O(I);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=I,C=n.eql(n.mul(D,R),n.mul(L,U)),P=n.eql(n.mul(E,R),n.mul(N,U));return C&&P}negate(){return new $(this.X,n.neg(this.Y),this.Z)}double(){let{a:I,b:D}=o,E=n.mul(D,jp),{X:U,Y:L,Z:N}=this,R=n.ZERO,C=n.ZERO,P=n.ZERO,V=n.mul(U,U),J=n.mul(L,L),z=n.mul(N,N),W=n.mul(U,L);return W=n.add(W,W),P=n.mul(U,N),P=n.add(P,P),R=n.mul(I,P),C=n.mul(E,z),C=n.add(R,C),R=n.sub(J,C),C=n.add(J,C),C=n.mul(R,C),R=n.mul(W,R),P=n.mul(E,P),z=n.mul(I,z),W=n.sub(V,z),W=n.mul(I,W),W=n.add(W,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,z),V=n.mul(V,W),C=n.add(C,V),z=n.mul(L,N),z=n.add(z,z),V=n.mul(z,W),R=n.sub(R,V),P=n.mul(z,J),P=n.add(P,P),P=n.add(P,P),new $(R,C,P)}add(I){O(I);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=I,C=n.ZERO,P=n.ZERO,V=n.ZERO,J=o.a,z=n.mul(o.b,jp),W=n.mul(D,L),Y=n.mul(E,N),X=n.mul(U,R),ue=n.add(D,E),ee=n.add(L,N);ue=n.mul(ue,ee),ee=n.add(W,Y),ue=n.sub(ue,ee),ee=n.add(D,U);let ce=n.add(L,R);return ee=n.mul(ee,ce),ce=n.add(W,X),ee=n.sub(ee,ce),ce=n.add(E,U),C=n.add(N,R),ce=n.mul(ce,C),C=n.add(Y,X),ce=n.sub(ce,C),V=n.mul(J,ee),C=n.mul(z,X),V=n.add(C,V),C=n.sub(Y,V),V=n.add(Y,V),P=n.mul(C,V),Y=n.add(W,W),Y=n.add(Y,W),X=n.mul(J,X),ee=n.mul(z,ee),Y=n.add(Y,X),X=n.sub(W,X),X=n.mul(J,X),ee=n.add(ee,X),W=n.mul(Y,ee),P=n.add(P,W),W=n.mul(ce,ee),C=n.mul(ue,C),C=n.sub(C,W),W=n.mul(ue,Y),V=n.mul(ce,V),V=n.add(V,W),new $(C,P,V)}subtract(I){return this.add(I.negate())}is0(){return this.equals($.ZERO)}multiply(I){let{endo:D}=e;if(!i.isValidNot0(I))throw new Error("invalid scalar: out of range");let E,U,L=N=>Q.cached(this,N,R=>Db($,R));if(D){let{k1neg:N,k1:R,k2neg:C,k2:P}=T(I),{p:V,f:J}=L(R),{p:z,f:W}=L(P);U=J.add(W),E=j(D.beta,V,z,N,C)}else{let{p:N,f:R}=L(I);E=N,U=R}return Db($,[E,U])[0]}multiplyUnsafe(I){let{endo:D}=e,E=this;if(!i.isValid(I))throw new Error("invalid scalar: out of range");if(I===ao||E.is0())return $.ZERO;if(I===iu)return E;if(Q.hasCache(this))return this.multiply(I);if(D){let{k1neg:U,k1:L,k2neg:N,k2:R}=T(I),{p1:C,p2:P}=wI($,E,L,R);return j(D.beta,C,P,U,N)}else return Q.unsafe(E,I)}toAffine(I){return M(this,I)}isTorsionFree(){let{isTorsionFree:I}=e;return s===iu?!0:I?I($,this):Q.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:I}=e;return s===iu?this:I?I($,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(I=!0){return zu(I,"isCompressed"),this.assertValidity(),p($,this,I)}toHex(I=!0){return Cs(this.toBytes(I))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Z=i.BITS,Q=new Vp($,e.endo?Math.ceil(Z/2):Z);return $.BASE.precompute(8),$}function SI(t){return Uint8Array.of(t?2:3)}function AI(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function cL(t,e={}){let{Fn:r}=t,n=e.randomBytes||Ps,i=Object.assign(AI(t.Fp,r),{seed:Bb(r.ORDER)});function o(p){try{let g=r.fromBytes(p);return r.isValidNot0(g)}catch{return!1}}function s(p,g){let{publicKey:y,publicKeyUncompressed:x}=i;try{let S=p.length;return g===!0&&S!==y||g===!1&&S!==x?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(i.seed)){return Hp(Te(p,i.seed,"seed"),r.ORDER)}function a(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:y,publicKeyUncompressed:x}=i;if(!Gu(p)||"_lengths"in r&&r._lengths||g===y)return;let S=Te(p,void 0,"key").length;return S===y||S===x}function d(p,g,y=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let x=r.fromBytes(p);return t.fromBytes(g).multiply(x).toBytes(y)}let f={isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c},h=qp(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:d,keygen:h,Point:t,utils:f,lengths:i})}function TI(t,e,r={}){Rl(e),Xu(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Ps,i=r.hmac||((D,E)=>kb(e,D,E)),{Fp:o,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p}=cL(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*EI<o.ORDER;function x(D){let E=c>>iu;return D>E}function S(D,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${D}: out of range 1..Point.Fn.ORDER`);return E}function _(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function A(D,E){Cb(E);let U=p.signature,L=E==="compact"?U:E==="recovered"?U+1:void 0;return Te(D,L)}class O{r;s;recovery;constructor(E,U,L){if(this.r=S("r",E),this.s=S("s",U),L!=null){if(_(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(E,U=g.format){A(E,U);let L;if(U==="der"){let{r:P,s:V}=as.toSig(Te(E));return new O(P,V)}U==="recovered"&&(L=E[0],U="compact",E=E.subarray(1));let N=p.signature/2,R=E.subarray(0,N),C=E.subarray(N,N*2);return new O(s.fromBytes(R),s.fromBytes(C),L)}static fromHex(E,U){return this.fromBytes(Ls(E),U)}assertRecovery(){let{recovery:E}=this;if(E==null)throw new Error("invalid recovery id: must be present");return E}addRecoveryBit(E){return new O(this.r,this.s,E)}recoverPublicKey(E){let{r:U,s:L}=this,N=this.assertRecovery(),R=N===2||N===3?U+c:U;if(!o.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=o.toBytes(R),P=t.fromBytes(hr(SI((N&1)===0),C)),V=s.inv(R),J=M(Te(E,void 0,"msgHash")),z=s.create(-J*V),W=s.create(L*V),Y=t.BASE.multiplyUnsafe(z).add(P.multiplyUnsafe(W));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return x(this.s)}toBytes(E=g.format){if(Cb(E),E==="der")return Ls(as.hexFromSig(this));let{r:U,s:L}=this,N=s.toBytes(U),R=s.toBytes(L);return E==="recovered"?(_(),hr(Uint8Array.of(this.assertRecovery()),N,R)):hr(N,R)}toHex(E){return Cs(this.toBytes(E))}}let T=r.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let U=Do(E),L=E.length*8-a;return L>0?U>>BigInt(L):U},M=r.bits2int_modN||function(E){return s.create(T(E))},q=Ju(a);function j(D){return Mv("num < 2^"+a,D,ao,q),s.toBytes(D)}function $(D,E){return Te(D,void 0,"message"),E?Te(e(D),void 0,"prehashed message"):D}function Z(D,E,U){let{lowS:L,prehash:N,extraEntropy:R}=Nb(U,g);D=$(D,N);let C=M(D),P=s.fromBytes(E);if(!s.isValidNot0(P))throw new Error("invalid private key");let V=[j(P),j(C)];if(R!=null&&R!==!1){let Y=R===!0?n(p.secretKey):R;V.push(Te(Y,void 0,"extraEntropy"))}let J=hr(...V),z=C;function W(Y){let X=T(Y);if(!s.isValidNot0(X))return;let ue=s.inv(X),ee=t.BASE.multiply(X).toAffine(),ce=s.create(ee.x);if(ce===ao)return;let Ue=s.create(ue*s.create(z+ce*P));if(Ue===ao)return;let Ke=(ee.x===ce?0:2)|Number(ee.y&iu),Je=Ue;return L&&x(Ue)&&(Je=s.neg(Ue),Ke^=1),new O(ce,Je,y?void 0:Ke)}return{seed:J,k2sig:W}}function Q(D,E,U={}){let{seed:L,k2sig:N}=Z(D,E,U);return Kv(e.outputLen,s.BYTES,i)(L,N).toBytes(U.format)}function G(D,E,U,L={}){let{lowS:N,prehash:R,format:C}=Nb(L,g);if(U=Te(U,void 0,"publicKey"),E=$(E,R),!Gu(D)){let P=D instanceof O?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}A(D,C);try{let P=O.fromBytes(D,C),V=t.fromBytes(U);if(N&&P.hasHighS())return!1;let{r:J,s:z}=P,W=M(E),Y=s.inv(z),X=s.create(W*Y),ue=s.create(J*Y),ee=t.BASE.multiplyUnsafe(X).add(V.multiplyUnsafe(ue));return ee.is0()?!1:s.create(ee.x)===J}catch{return!1}}function I(D,E,U={}){let{prehash:L}=Nb(U,g);return E=$(E,L),O.fromBytes(D,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p,Point:t,sign:Q,verify:G,recoverPublicKey:I,Signature:O,hash:e})}var zp={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},aL={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},uL=BigInt(0),Pb=BigInt(2);function dL(t){let e=zp.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=Hr(d,r,e)*d%e,h=Hr(f,r,e)*d%e,p=Hr(h,Pb,e)*u%e,g=Hr(p,i,e)*p%e,y=Hr(g,o,e)*g%e,x=Hr(y,c,e)*y%e,S=Hr(x,a,e)*x%e,_=Hr(S,c,e)*y%e,A=Hr(_,r,e)*d%e,O=Hr(A,s,e)*g%e,T=Hr(O,n,e)*u%e,M=Hr(T,Pb,e);if(!Wp.eql(Wp.sqr(M),t))throw new Error("Cannot find square root");return M}var Wp=ru(zp.p,{sqrt:dL}),vc=vI(zp,{Fp:Wp,endo:aL}),fn=TI(vc,Kp),_I={};function Gp(t,...e){let r=_I[t];if(r===void 0){let n=Kp(Pv(t));r=hr(n,n),_I[t]=r}return Kp(hr(r,...e))}var Kb=t=>t.toBytes(!0).slice(1),$b=t=>t%Pb===uL;function Mb(t){let{Fn:e,BASE:r}=vc,n=e.fromBytes(t),i=r.multiply(n);return{scalar:$b(i.y)?n:e.neg(n),bytes:Kb(i)}}function BI(t){let e=Wp;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);$b(i)||(i=e.neg(i));let o=vc.fromAffine({x:t,y:i});return o.assertValidity(),o}var lf=Do;function RI(...t){return vc.Fn.create(lf(Gp("BIP0340/challenge",...t)))}function II(t){return Mb(t).bytes}function fL(t,e,r=Ps(32)){let{Fn:n}=vc,i=Te(t,void 0,"message"),{bytes:o,scalar:s}=Mb(e),c=Te(r,32,"auxRand"),a=n.toBytes(s^lf(Gp("BIP0340/aux",c))),u=Gp("BIP0340/nonce",a,o,i),{bytes:d,scalar:f}=Mb(u),h=RI(d,o,i),p=new Uint8Array(64);if(p.set(d,0),p.set(n.toBytes(n.create(f+h*s)),32),!UI(p,i,o))throw new Error("sign: Invalid signature produced");return p}function UI(t,e,r){let{Fp:n,Fn:i,BASE:o}=vc,s=Te(t,64,"signature"),c=Te(e,void 0,"message"),a=Te(r,32,"publicKey");try{let u=BI(lf(a)),d=lf(s.subarray(0,32));if(!n.isValidNot0(d))return!1;let f=lf(s.subarray(32,64));if(!i.isValidNot0(f))return!1;let h=RI(i.toBytes(d),Kb(u),c),p=o.multiplyUnsafe(f).add(u.multiplyUnsafe(i.neg(h))),{x:g,y}=p.toAffine();return!(p.is0()||!$b(y)||g!==d)}catch{return!1}}var Yp=(()=>{let r=(n=Ps(48))=>Hp(n,zp.n);return{keygen:qp(r,II),getPublicKey:II,sign:fL,verify:UI,Point:vc,utils:{randomSecretKey:r,taggedHash:Gp,lift_x:BI,pointToBytes:Kb},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:32*2,seed:48}}})();l();function lL(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function DI(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Hb(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function kI(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Vb(t){if(!Array.isArray(t))throw new Error("array expected")}function NI(t,e){if(!DI(!0,e))throw new Error(`${t}: array of strings expected`)}function hL(t,e){if(!DI(!1,e))throw new Error(`${t}: array of numbers expected`)}function pL(...t){let e=o=>o,r=(o,s)=>c=>o(s(c)),n=t.map(o=>o.encode).reduceRight(r,e),i=t.map(o=>o.decode).reduce(r,e);return{encode:n,decode:i}}function yL(t){let e=typeof t=="string"?t.split(""):t,r=e.length;NI("alphabet",e);let n=new Map(e.map((i,o)=>[i,o]));return{encode:i=>(Vb(i),i.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);return e[o]})),decode:i=>(Vb(i),i.map(o=>{Hb("alphabet.decode",o);let s=n.get(o);if(s===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);return s}))}}function gL(t=""){return Hb("join",t),{encode:e=>(NI("join.decode",e),e.join(t)),decode:e=>(Hb("join.decode",e),e.split(t))}}function OI(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Vb(t),!t.length)return[];let n=0,i=[],o=Array.from(t,c=>{if(kI(c),c<0||c>=e)throw new Error(`invalid integer: ${c}`);return c}),s=o.length;for(;;){let c=0,a=!0;for(let u=n;u<s;u++){let d=o[u],f=e*c,h=f+d;if(!Number.isSafeInteger(h)||f/e!==c||h-d!==f)throw new Error("convertRadix: carry overflow");let p=h/r;c=h%r;let g=Math.floor(p);if(o[u]=g,!Number.isSafeInteger(g)||g*r+c!==h)throw new Error("convertRadix: carry overflow");if(a)g?a=!1:n=u;else continue}if(i.push(c),a)break}for(let c=0;c<t.length-1&&t[c]===0;c++)i.push(0);return i.reverse()}function mL(t){kI(t);let e=2**8;return{encode:r=>{if(!lL(r))throw new Error("radix.encode input should be Uint8Array");return OI(Array.from(r),e,t)},decode:r=>(hL("radix.decode",r),Uint8Array.from(OI(r,t,e)))}}var wL=t=>pL(mL(58),yL(t),gL("")),ou=wL("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var CI=new Uint8Array([231,1]),dt=class t{#e;#t={prefix:CI,key:[],encoded:""};constructor(e){let r=e instanceof Uint8Array?e:_r(e);if(!r||r.length!==33)throw new Us("Invalid argument: byte length must be 33 (compressed)","CONSTRUCTOR_ERROR",{keyBytes:r});if(!fn.utils.isValidPublicKey(r))throw new Us("Invalid argument: not a valid secp256k1 compressed point","CONSTRUCTOR_ERROR",{keyBytes:r});this.#e=new Uint8Array(r),this.#t.encoded=this.encode(),this.#t.key=[...this.#t.prefix,...this.compressed]}get compressed(){return new Uint8Array(this.#e)}get uncompressed(){return fn.Point.fromBytes(this.compressed).toBytes(!1)}get xOnly(){return this.compressed.slice(1)}get parity(){let e=this.compressed[0];if(![2,3].includes(e))throw new Us("Invalid state: parity byte must be 2 or 3","PARITY_ERROR",{parity:e});return e}get isEven(){return this.parity===2}get x(){return this.compressed.slice(1,33)}get y(){return this.uncompressed.slice(33,65)}get multibase(){return{prefix:new Uint8Array(this.#t.prefix),key:[...this.#t.key],encoded:this.#t.encoded}}get hex(){return Pt(this.compressed)}get point(){return{x:this.x,y:this.y}}bip340(){return this.xOnly}decode(){return ou.decode(this.multibase.encoded.slice(1))}encode(){let e=Array.from(this.compressed),r=Array.from(CI);return r.push(...e),"z"+ou.encode(Uint8Array.from(r))}verify(e,r,n){if(n??={scheme:"schnorr"},n.scheme==="ecdsa")return fn.verify(e,r,this.compressed);if(n.scheme==="schnorr")return Yp.verify(e,r,this.x);throw new Us(`Invalid scheme: ${n.scheme}.`,"VERIFY_SIGNATURE_ERROR",n)}equals(e){return ta(this.compressed,e.compressed)}toJSON(){return{hex:this.hex,multibase:this.multibase,point:{x:Array.from(this.x),y:Array.from(this.y),parity:this.parity}}}static isValid(e){try{return new t(e),!0}catch{return!1}}static fromJSON(e){return new t(Uint8Array.from([e.point.parity,...e.point.x]))}};l();var LI=new Uint8Array([129,38]),bL=Pt(ke(LI)),Vr=class t{#e;#t;#n;constructor(e){let r=e instanceof Uint8Array,n=typeof e=="bigint";if(!r&&!n)throw new Wn("Invalid entropy: must be a valid byte array (32) or bigint","CONSTRUCTOR_ERROR");if(r&&e.length===32&&(this.#e=new Uint8Array(e),this.#t=t.toSecret(this.#e)),n&&e>=1n&&e<fn.Point.Fn.ORDER&&(this.#e=t.toBytes(e),this.#t=e),!this.#e||this.#e.length!==32)throw new Wn("Invalid bytes: must be a valid 32-byte secret key","CONSTRUCTOR_ERROR");if(!this.#t||this.#t<1n||this.#t>=fn.Point.Fn.ORDER)throw new Wn("Invalid seed: must be valid bigint","CONSTRUCTOR_ERROR");this.#n=this.encode()}destroy(){this.#e&&this.#e.fill(0),this.#t=void 0,this.#n=""}get bytes(){return new Uint8Array(this.#e)}get seed(){return BigInt(this.#t)}get hex(){return Pt(this.bytes)}get multibase(){return this.#n}encode(){let e=Array.from(this.bytes),r=Array.from(LI);return r.push(...e),"z"+ou.encode(Uint8Array.from(r))}equals(e){return ta(this.bytes,e.bytes)}computePublicKey(){return new dt(fn.getPublicKey(this.bytes))}toJSON(){return{type:"Secp256k1SecretKey"}}exportJSON(){return{bytes:Array.from(this.bytes),seed:this.seed.toString(),hex:this.hex}}toString(){return"[Secp256k1SecretKey]"}[Symbol.for("nodejs.util.inspect.custom")](){return"[Secp256k1SecretKey]"}isValid(){return fn.utils.isValidSecretKey(this.bytes)}hasValidPublicKey(){try{return this.computePublicKey(),!0}catch{return!1}}sign(e,r){if(r??={scheme:"schnorr"},r.scheme==="ecdsa")return fn.sign(e,this.bytes);if(r.scheme==="schnorr")return Yp.sign(e,this.bytes);throw new Wn(`Invalid scheme: ${r.scheme}.`,"SIGN_ERROR",r)}static decode(e){let r=ou.decode(e.slice(1));if(r.length!==34)throw new Wn("Invalid argument: must be 34 byte secretKeyMultibase","DECODE_MULTIBASE_ERROR");let n=r.slice(0,2);if(Pt(ke(n))!==bL)throw new Wn(`Invalid prefix: malformed multibase prefix ${n}`,"DECODE_MULTIBASE_ERROR");return r}static fromJSON(e){return new t(new Uint8Array(e.bytes))}static toSecret(e){return e.reduce((r,n)=>r<<8n|BigInt(n),0n)}static toBytes(e){let r=Uint8Array.from({length:32},(n,i)=>Number(e>>BigInt(8*(31-i))&BigInt(255)));if(!fn.utils.isValidSecretKey(r))throw new Wn("Invalid secret key: secret out of valid range","SET_PRIVATE_KEY_ERROR");return new Uint8Array(r)}static fromBigInt(e){return new t(t.toBytes(e))}static random(){let e;do e=Ir(32);while(!fn.utils.isValidSecretKey(e));return e}static generate(){let e=this.random();return new t(e)}static getPublicKey(e){return new t(e).computePublicKey()}};var uo=class t{#e;#t;constructor(e={}){if(!e.publicKey&&!e.secretKey)throw new bn("Argument missing: must at least provide a publicKey","CONSTRUCTOR_ERROR");if(e.secretKey instanceof Uint8Array?this.#e=new Vr(e.secretKey):e.secretKey instanceof Vr&&(this.#e=e.secretKey),e.publicKey instanceof dt?this.#t=e.publicKey:e.publicKey instanceof Uint8Array?this.#t=new dt(e.publicKey):this.#t=this.#e.computePublicKey(),this.#e&&e.publicKey){let r=this.#e.computePublicKey();if(!this.#t.equals(r))throw new bn("Public key does not match secret key","CONSTRUCTOR_ERROR")}}get secretKey(){if(!this.#e)throw new bn("Secret key not available","SECRET_KEY_ERROR");if(!this.#e.isValid())throw new bn("Secret key is not valid","SECRET_KEY_ERROR");return this.#e}set publicKey(e){if(this.#e){let r=this.#e.computePublicKey();if(!e.equals(r))throw new bn("Public key does not match secret key","PUBLIC_KEY_ERROR")}this.#t=e}get publicKey(){return this.#t}get hasSecretKey(){return!!this.#e}get raw(){return{public:this.publicKey.compressed,secret:this.#e?this.#e.bytes:void 0}}get hex(){return{public:this.publicKey.hex,secret:this.#e?this.#e.hex:void 0}}get multibase(){return{publicKeyMultibase:this.#t.multibase.encoded,secretKeyMultibase:this.#e?this.#e.multibase:""}}toJSON(){return{publicKey:this.publicKey.toJSON()}}exportJSON(){if(!this.#e)throw new bn("Cannot export: secret key required. Use publicKey.toJSON() for public-key-only pairs.","SERIALIZE_ERROR");return{secretKey:this.#e.exportJSON(),publicKey:this.publicKey.toJSON()}}[Symbol.for("nodejs.util.inspect.custom")](){return`[SchnorrKeyPair ${this.publicKey.hex}]`}static fromJSON(e){return new t({secretKey:Vr.fromJSON(e.secretKey),publicKey:dt.fromJSON(e.publicKey)})}static fromSecret(e){let r=typeof e=="string"?_r(e):e;if(r.length!==32)throw new bn("Invalid arg: must be 32 byte secret key","FROM_SECRET_KEY_ERROR");let n=new Vr(r),i=n.computePublicKey();return new t({secretKey:n,publicKey:i})}static fromBigInt(e){let r=Vr.fromBigInt(e),n=r.computePublicKey();return new t({secretKey:r,publicKey:n})}static toHex(e){return Pt(e)}static equals(e,r){return e.publicKey.equals(r.publicKey)}static generate(){let e=Vr.random(),r=new Vr(e),n=r.computePublicKey();return new t({secretKey:r,publicKey:n})}};l();l();l();l();var xL=["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"],su="Multikey",cu="zQ3s",dr="did:btcr2:_",Wte="",EL=/did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;function vL(t){if(!ut.isDidVerificationMethod(t))return!1;let{type:e,publicKeyMultibase:r}=t;return e===su&&typeof r=="string"&&r.startsWith(cu)}var qb=class{id;type;controller;publicKeyMultibase;secretKeyMultibase;constructor({id:e,type:r,controller:n,publicKeyMultibase:i,secretKeyMultibase:o}){if(r!==su)throw new qe(`Invalid verification method: type must be "${su}"`,Le,{id:e,type:r});if(typeof i!="string"||!i.startsWith(cu))throw new qe(`Invalid verification method: publicKeyMultibase must start with "${cu}"`,Le,{id:e,publicKeyMultibase:i});this.id=e,this.type=r,this.controller=n,this.publicKeyMultibase=i,this.secretKeyMultibase=o,o||delete this.secretKeyMultibase}},ln=class t{id;"@context"=["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"];verificationMethod;authentication;assertionMethod;capabilityInvocation;capabilityDelegation;service;deactivated;constructor(e){if(!e.id)throw new qe("DID Document must have an id",Le,e);let r=e.id.includes("k1")?Zr.KEY:Zr.EXTERNAL,n=e.id===dr,{id:i,verificationMethod:o,service:s}=e;if(!n){if(!t.isValidId(i))throw new qe(`Invalid id: ${i}`,Le,e);if(!t.isValidVerificationMethods(o))throw new qe("Invalid verificationMethod: "+o,Le,e);if(!t.isValidServices(s))throw new qe("Invalid service: "+s,Le,e)}if(this.id=e.id,this.verificationMethod=e.verificationMethod||[],this.service=e.service||[],this["@context"]=e["@context"]||["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"],r===Zr.KEY){let c=`${this.id}#initialKey`;this.authentication=e.authentication||[c],this.assertionMethod=e.assertionMethod||[c],this.capabilityInvocation=e.capabilityInvocation||[c],this.capabilityDelegation=e.capabilityDelegation||[c]}else this.authentication=e.authentication,this.assertionMethod=e.assertionMethod,this.capabilityInvocation=e.capabilityInvocation,this.capabilityDelegation=e.capabilityDelegation;t.sanitize(this),n?this.validateGenesis():t.validate(this)}toJSON(){return{id:this.id,"@context":this["@context"],verificationMethod:this.verificationMethod,authentication:this.authentication,assertionMethod:this.assertionMethod,capabilityInvocation:this.capabilityInvocation,capabilityDelegation:this.capabilityDelegation,service:this.service,deactivated:this.deactivated}}static fromKeyIdentifier(e,r,n){e=e.includes("#")?e:`${e}#initialKey`;let i={id:e,verificationMethod:[new qb({id:e,type:"Multikey",controller:e,publicKeyMultibase:r})],service:n};return new t(i)}static fromExternalIdentifier(e){return new t(e)}static sanitize(e){for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}static isValid(e){if(!this.isValidContext(e?.["@context"]))throw new qe('Invalid "@context"',Le,e);if(!this.isValidId(e?.id))throw new qe('Invalid "id"',Le,e);if(!this.isValidVerificationMethods(e?.verificationMethod))throw new qe('Invalid "verificationMethod"',Le,e);if(!this.isValidServices(e?.service))throw new qe('Invalid "service"',Le,e);if(!this.isValidVerificationRelationships(e))throw new qe("Invalid verification relationships",Le,e);return!0}static isValidContext(e){return!Array.isArray(e)||e.length===0?!1:xL.every(r=>e.includes(r))}static isValidId(e){if(typeof e!="string")return!1;try{return vr.decode(e),!0}catch{return!1}}static isValidVerificationMethods(e){return Array.isArray(e)&&e.every(vL)}static isValidServices(e){return Array.isArray(e)&&e.every(n_)}static isValidVerificationRelationships(e){let r=["authentication","assertionMethod","capabilityInvocation","capabilityDelegation"],n=Object.keys(e);return r.filter(o=>n.includes(o)).every(o=>{let s=e[o];return s&&Array.isArray(s)&&s.every(c=>typeof c=="string"||ut.isDidVerificationMethod(c))})}static validate(e){return e.id===dr?e.validateGenesis():t.isValid(e),e}validateGenesis(){if(this.id!==dr)throw new qe("Invalid GenesisDocument ID",Le,this);if(!this.verificationMethod.every(e=>e.id.includes(dr)&&e.controller===dr))throw new qe("Invalid GenesisDocument verificationMethod",Le,this);if(!this.service.every(e=>e.id.includes(dr)))throw new qe("Invalid GenesisDocument service",Le,this);if(!t.isValidVerificationRelationships(this))throw new qe("Invalid GenesisDocument assertionMethod",Le,this);return!0}toIntermediate(){if(this.id.includes("k1"))throw new qe("Cannot convert a key identifier to an intermediate document",Le,this);return new hf(this)}},hf=class t extends ln{constructor(e){super(e)}toDidDocument(e){let r=JSON.stringify(this).replaceAll(dr,e),n=JSON.parse(r);return new ln(n)}static fromDidDocument(e){let r=ks.cloneReplace(e,EL,dr);return new t(r)}static create(e,r,n){return new t({id:dr,...r,verificationMethod:e,service:n})}static fromPublicKey(e,r){let n=new dt(e),i=dr,o=ki(n.compressed,Uo(r)).address,s=[{id:`${i}#service-0`,serviceEndpoint:`bitcoin:${o}`,type:"SingletonBeacon"}],c={authentication:[`${i}#key-0`],assertionMethod:[`${i}#key-0`],capabilityInvocation:[`${i}#key-0`],capabilityDelegation:[`${i}#key-0`]},a=[{id:`${i}#key-0`,type:"Multikey",controller:i,publicKeyMultibase:n.multibase.encoded}];return t.create(a,c,s)}static fromJSON(e){return new t(e)}static toGenesisBytes(e){return Io(rr(e))}};var PI="did:btcr2:",vr=class t{static encode(e,r){let{idType:n,version:i=1,network:o="bitcoin"}=r;if(!(n in Zr))throw new ct('Expected "idType" to be "KEY" or "EXTERNAL"',ht,{idType:n});if(i!==1)throw new ct('Expected "version" to be 1',ht,{version:i});if(typeof o!="string")throw new ct('Expected "network" to be a known network name',ht,{network:o});let s=Qc[o];if(s===void 0)throw new ct('Invalid "network" name',ht,{network:o});if(n==="KEY")try{new dt(e)}catch{throw new ct('Expected "genesisBytes" to be a valid compressed secp256k1 public key',ht,{genesisBytes:e})}else if(e.length!==32)throw new ct('Expected "genesisBytes" to be a 32-byte hash for EXTERNAL identifiers',ht,{genesisBytes:e});let c=n==="KEY"?"k":"x",a=i-1<<4|s,u=new Uint8Array([a,...e]);return`${PI}${Ss.encodeFromBytes(c,u)}`}static decode(e){let r=e.split(":");if(r.length!==3)throw new ct(`Invalid did: ${e}`,ht,{identifier:e});let[n,i,o]=r;if(n!=="did")throw new ct(`Invalid did: ${e}`,ht,{identifier:e});if(i!=="btcr2")throw new ct(`Invalid did method: ${i}`,gl,{identifier:e});if(!o)throw new ct(`Invalid method-specific id: ${e}`,ht,{identifier:e});if(o!==o.toLowerCase())throw new ct(`Invalid method-specific id (must be lowercase): ${e}`,ht,{identifier:e});let s,c;try{({prefix:s,bytes:c}=Ss.decodeToBytes(o))}catch(g){let y=g instanceof Error?g.message:String(g);throw new ct(`Invalid method-specific id (Bech32m decoding failed: ${y}): ${e}`,ht,{identifier:e,reason:y})}if(!["x","k"].includes(s))throw new ct(`Invalid hrp: ${s}`,ht,{identifier:e});if(!c||c.length<1)throw new ct(`Failed to decode id: ${o}`,ht,{identifier:e});let a=s==="k"?"KEY":"EXTERNAL",u=c[0]>>>4;if(u!==0)throw new ct(`Invalid btcr2_version (expected 0): ${u}`,ht,{identifier:e});let d=1,f=c[0]&15,h=Qc[f];if(typeof h!="string"){let g=f>=12?"custom network not supported":"reserved";throw new ct(`Invalid network (${g}): ${f}`,ht,{identifier:e})}let p=c.slice(1);if(a==="KEY")try{new dt(p)}catch{throw new ct(`Invalid genesisBytes: ${p}`,ht,{identifier:e})}else if(p.length!==32)throw new ct(`Invalid genesisBytes: ${p}`,ht,{identifier:e});return{idType:a,hrp:s,version:d,network:h,genesisBytes:p}}static validate(e,r={}){let n=[],i=(x,S)=>{n.push(S===void 0?{name:x,ok:!0}:{name:x,ok:!0,detail:S})},o=(x,S,_={})=>(n.push({name:x,ok:!1,detail:S}),{did:e,valid:!1,..._,checks:n});if(typeof e!="string")return o("prefix","The identifier is not a string.");let s=e.split(":");if(s.length!==3||s[0]!=="did"||s[1]!=="btcr2")return o("prefix",`The identifier must be "${PI}" followed by the method-specific id.`);let c=s[2];if(c.length===0)return o("prefix","The method-specific id is empty.");if(i("prefix"),c!==c.toLowerCase())return o("lowercase","The method-specific id must be lowercase.");i("lowercase");let a,u;try{({prefix:a,bytes:u}=Ss.decodeToBytes(c))}catch(x){return o("bech32m",`Bech32m decoding failed: ${x instanceof Error?x.message:String(x)}`)}if(a!=="k"&&a!=="x")return o("bech32m",`The hrp must be "k" or "x", got "${a}".`);let d=a==="k"?Zr.KEY:Zr.EXTERNAL;if(u.length<1)return o("bech32m","The data bytes are empty.",{idType:d});i("bech32m",`hrp "${a}", ${u.length} data bytes`);let f=u[0]>>>4;if(f!==0)return o("version",`btcr2_version must be 0, got ${f}.`,{idType:d});i("version","btcr2_version 0 (version_number 1)");let h=u[0]&15,p=Qc[h];if(typeof p!="string"){let x=h>=12?`network_value ${h} is a custom network, not supported by this implementation.`:`network_value ${h} is reserved.`;return o("network",x,{idType:d})}i("network",`network_value ${h} (${p})`);let g=u.slice(1);if(d===Zr.KEY){try{new dt(g)}catch{return o("genesisBytes",`Expected a 33-byte SEC compressed secp256k1 public key, got ${g.length} bytes that are not a valid key.`,{idType:d,network:p})}i("genesisBytes","33-byte SEC compressed secp256k1 public key")}else{if(g.length!==32)return o("genesisBytes",`Expected a 32-byte SHA-256 hash, got ${g.length} bytes.`,{idType:d,network:p});i("genesisBytes","32-byte SHA-256 hash")}let y;try{y=t.encode(g,{idType:d,version:1,network:p})}catch(x){return o("roundTrip",`Re-encoding failed: ${x instanceof Error?x.message:String(x)}`,{idType:d,network:p})}if(y!==e)return o("roundTrip",`Re-encoding produced "${y}".`,{idType:d,network:p});if(i("roundTrip"),r.genesisBytes!==void 0){let x=r.genesisBytes;if(!(x instanceof Uint8Array))return o("genesisBytesMatch","The supplied genesis bytes are not a Uint8Array.",{idType:d,network:p});if(x.length!==g.length)return o("genesisBytesMatch",`Expected ${g.length} genesis bytes for a ${d} identifier, got ${x.length}.`,{idType:d,network:p});if(!go(x,g))return o("genesisBytesMatch",`The supplied genesis bytes ${xe.encode(x)} do not equal the genesis bytes of the identifier ${xe.encode(g)}.`,{idType:d,network:p});i("genesisBytesMatch","The supplied genesis bytes equal the genesis bytes of the identifier.")}if(r.genesisDocument!==void 0){let x=r.genesisDocument;if(d===Zr.KEY)return o("genesisDocument","A KEY identifier has no genesis document.",{idType:d,network:p});let S=x.id;if(S!==dr)return o("genesisDocument",`The genesis document id must be "${dr}", got ${JSON.stringify(S)}.`,{idType:d,network:p});try{hf.fromJSON(x)}catch(A){return o("genesisDocument",`Invalid genesis document: ${A instanceof Error?A.message:String(A)}`,{idType:d,network:p})}let _=Bo(x);if(!go(_,g))return o("genesisDocument",`The genesis document hash ${xe.encode(_)} does not equal the genesis bytes ${xe.encode(g)}.`,{idType:d,network:p});i("genesisDocument","The genesis document hashes to the genesis bytes.")}return{did:e,valid:!0,idType:d,network:p,checks:n}}static generate(){let e=uo.generate(),r=this.encode(e.publicKey.compressed,{idType:"KEY",version:1,network:"regtest"});return{keyPair:e.exportJSON(),did:r}}static getPublicKey(e){let{idType:r,genesisBytes:n}=t.decode(e);if(r!=="KEY")throw new ct(`Cannot extract public key from EXTERNAL DID: ${e}. EXTERNAL DIDs encode a document hash, not a public key.`,ht,{did:e,idType:r});return new dt(n)}static isValid(e){try{return this.decode(e),!0}catch{return!1}}};var hn=class{static parseBitcoinAddress(e){if(!e.startsWith("bitcoin:"))throw new we("Invalid Bitcoin URI format","BEACON_SERVICE_ERROR",{uri:e});return e.replace("bitcoin:","").split("?")[0]}static isBeaconService(e){return!(!ut.isDidService(e)||!["SingletonBeacon","CASBeacon","SMTBeacon"].includes(e.type)||[e.serviceEndpoint].flat().some(r=>typeof r=="string"&&!r.startsWith("bitcoin:")))}static getBeaconServices(e){return e.service.filter(this.isBeaconService)??[]}static createBeaconServices(e,r){try{return["p2pkh","p2wpkh","p2tr"].map(i=>this.createBeaconService(e,i,r))}catch(n){throw new nr("Failed to create beacon services: "+n.message,"BEACON_SERVICE_ERROR",{did:e,beaconType:r})}}static createBeaconService(e,r,n){try{let i=vr.decode(e),o=Uo(i.network),s=i.genesisBytes,c=`${e}#initial${r.toUpperCase()}`,u=`bitcoin:${r==="p2tr"?_s(s.slice(1,33),void 0,o).address:r==="p2wpkh"?Ts(s,o).address:ki(s,o).address}`;return{id:c,type:n,serviceEndpoint:u}}catch(i){throw new nr("Failed to create beacon service: "+i.message,"BEACON_SERVICE_ERROR",{did:e,beaconType:n})}}static generateBeaconServices({id:e,publicKey:r,network:n,beaconType:i}){try{let o=ki(r,n).address,s=Ts(r,n).address,c=_s(r.slice(1,33),void 0,n).address;if(!o||!s||!c)throw new zt("Failed to generate bitcoin addresses");return[{id:`${e}#initialP2PKH`,type:i,serviceEndpoint:`bitcoin:${o}`},{id:`${e}#initialP2WPKH`,type:i,serviceEndpoint:`bitcoin:${s}`},{id:`${e}#initialP2TR`,type:i,serviceEndpoint:`bitcoin:${c}`}]}catch(o){throw new nr("Failed to create beacon services: "+o.message,"BEACON_SERVICE_ERROR",{id:e,publicKey:r,network:n,beaconType:i})}}static parseBeaconServiceEndpoint(e){return{...e,serviceEndpoint:e.serviceEndpoint.replace("bitcoin:","")}}static getBeaconServiceIds(e){return this.getBeaconServices(e).map(r=>r.id)}};var SL=/^6a20([0-9a-f]{64})$/i;function MI(t){if(!t)return null;let e=SL.exec(t.trim());return e?e[1].toLowerCase():null}var KI=class t{static async spendsFromAddress(e,r,n){for(let i of e.vin??[]){if(i.is_coinbase)continue;let o=i.prevout;if(!o&&i.txid&&(o=(await n.rest.transaction.get(i.txid))?.vout?.[i.vout]),o?.scriptpubkey_address===r)return!0}return!1}static async indexer(e,r){let n=new Map,i=await r.rest.block.count();for(let o of e){n.set(o,[]);let s=hn.parseBitcoinAddress(o.serviceEndpoint),c=await r.rest.address.getTxs(s);if(!(!c||!c.length))for(let a of c){let u=a.status;if(u.confirmed!==!0)continue;let d=a.vout.slice(-1)[0];if(!d)continue;let f=MI(d.scriptpubkey);if(!f||!await t.spendsFromAddress(a,s,r))continue;let h=i-u.block_height+1;n.get(o)?.push({tx:a,signalBytes:f,blockMetadata:{confirmations:h,height:u.block_height,time:u.block_time}})}}return n}static async fullnode(e,r){let n=new Map;for(let u of e)n.set(u,[]);let i=r.rpc;if(!i)throw new De("RPC connection is not available","RPC_CONNECTION_ERROR",r);let o=await i.getBlockCount(),s=new Map(e.map(u=>[hn.parseBitcoinAddress(u.serviceEndpoint),u])),c=0,a=await r.rpc.getBlock({height:c});for(console.info("Searching for beacon signals, please wait ...");a.height<=o;){for(let u of a.tx){if(u.txid===R0)continue;let d=u.vout.slice(-1)[0];if(!d)continue;let f=MI(d.scriptPubKey?.hex);if(!f)continue;let h=new Set;for(let p of u.vin){if(p.coinbase||p.txinwitness&&p.txinwitness.length===1&&p.txinwitness[0]===B0||!p.txid||p.vout===void 0)continue;let g=await i.getRawTransaction(p.txid,2);if(!g.vout[p.vout])continue;let y=g.vout[p.vout].scriptPubKey;if(!y.address)continue;let x=s.get(y.address);!x||h.has(x)||(h.add(x),console.info(`Tx ${u.txid} contains beacon address ${y.address}`),n.get(x)?.push({tx:u,signalBytes:f,blockMetadata:{height:a.height,time:a.time,confirmations:a.confirmations}}))}}if(c+=1,c>o){console.info(`Chain tip reached ${c}, breaking ...`);break}a=await i.getBlock({height:c})}return n}};l();var au=Object.freeze(["https://w3id.org/json-ld-patch/v1","https://w3id.org/zcap/v1","https://w3id.org/security/data-integrity/v2","https://btcr2.dev/context/v1"]);function Fb(t,e=au){return Array.isArray(t)&&t.length===e.length&&t.every((r,n)=>r===e[n])}l();l();l();l();l();l();var mre=new Uint8Array(0);function $I(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}l();function AL(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function f(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 y=0,x=0,S=0,_=g.length;S!==_&&g[S]===0;)S++,y++;for(var A=(_-S)*d+1>>>0,O=new Uint8Array(A);S!==_;){for(var T=g[S],M=0,q=A-1;(T!==0||M<x)&&q!==-1;q--,M++)T+=256*O[q]>>>0,O[q]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");x=M,S++}for(var j=A-x;j!==A&&O[j]===0;)j++;for(var $=a.repeat(y);j<A;++j)$+=t.charAt(O[j]);return $}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var x=0,S=0;g[y]===a;)x++,y++;for(var _=(g.length-y)*u+1>>>0,A=new Uint8Array(_);g[y];){var O=r[g.charCodeAt(y)];if(O===255)return;for(var T=0,M=_-1;(O!==0||T<S)&&M!==-1;M--,T++)O+=c*A[M]>>>0,A[M]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");S=T,y++}if(g[y]!==" "){for(var q=_-S;q!==_&&A[q]===0;)q++;for(var j=new Uint8Array(x+(_-q)),$=x;q!==_;)j[$++]=A[q++];return j}}}function p(g){var y=h(g);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var TL=AL,_L=TL,HI=_L;var jb=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Wb=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return VI(this,e)}},Gb=class{decoders;constructor(e){this.decoders=e}or(e){return VI(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function VI(t,e){return new Gb({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var zb=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new jb(e,r,n),this.decoder=new Wb(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function IL({name:t,prefix:e,encode:r,decode:n}){return new zb(t,e,r,n)}function Yb({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=HI(r,t);return IL({prefix:e,name:t,encode:n,decode:o=>$I(i(o))})}var pf=Yb({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ire=Yb({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});l();function qI(t){return t===void 0?[]:Array.isArray(t)?t:[t]}var uu=class{cryptosuite;constructor(e){this.cryptosuite=e}addProof(e,r){let n=this.cryptosuite.createProof(e,r);if(!n.type||!n.verificationMethod||!n.proofPurpose)throw new wn("Invalid proof: missing proof.type, proof.verificationMethod and/or proof.proofPurpose",_o,{config:r,proof:n});if(r.domain&&n.domain!==r.domain)throw new wn("Domain mismatch: proof.domain !== config.domain",_o,{config:r,proof:n});if(r.challenge&&n.challenge!==r.challenge)throw new wn("Challenge mismatch options and challenge passed",_o,{config:r,proof:n});let i=e;return i.proof=n,i}verifyProof(e,r,n,i,o){let s=JSON.parse(e),c=s.proof;if(!c.type||!c.verificationMethod||!c.proofPurpose)throw new wn("Invalid proof: missing proof.type, proof.verificationMethod and/or proof.proofPurpose",Ni,s);if(r&&r!==c.proofPurpose)throw new wn("Proof purpose mismatch: proof.proofPurpose !== expectedPurpose",Ni,{proof:c,expectedPurpose:r});if(o&&o!==c.challenge)throw new wn("Challenge mismatch: proof.challenge !== expectedChallenge","INVALID_CHALLENGE_ERROR",{proof:c,expectedChallenge:o});if(i){let u=qI(i),d=qI(c.domain);if(u.length!==d.length)throw new wn("Domain mismatch: expectedDomain length does not match proof.domain length",Ni,{proof:c,expectedDomain:i});if(!u.every(f=>d.includes(f))||!d.every(f=>u.includes(f)))throw new wn("Domain mismatch: expectedDomain and proof.domain do not match",Ni,{proof:c,expectedDomain:i})}let a=this.cryptosuite.verifyProof(s);return a.mediaType=n,a}};var du=class{type="DataIntegrityProof";cryptosuite="bip340-jcs-2025";multikey;constructor(e){this.multikey=e}toDataIntegrityProof(){return new uu(this)}#e(){return{type:this.type,cryptosuite:this.cryptosuite,verificationMethod:this.multikey.fullId()}}createProof(e,r){r["@context"]=e["@context"]??r["@context"];let n=this.proofConfiguration(r),i=this.transformDocument(e,r),o=this.generateHash(n,i),s=this.proofSerialization(o,r),c=r;return c.proofValue=pf.encode(s),c.cryptosuite=this.cryptosuite,c.type=this.type,c}verifyProof(e){let{proof:r,...n}=e,{proofValue:i,...o}=r,s=this.transformDocument(n,o),c=this.proofConfiguration(o),a=this.generateHash(c,s),u=pf.decode(e.proof.proofValue),d=this.proofVerification(a,u,o);return{verified:d,verifiedDocument:d?e:void 0}}transformDocument(e,r){if(r.type!==this.type)throw new we("Type mismatch: config.type !== this.type",Ni,{config:r,suite:this.#e()});if(r.cryptosuite!==this.cryptosuite)throw new we("Cryptosuite mismatch: config.cryptosuite !== this.cryptosuite",Ni,{config:r,suite:this.#e()});return rr(e)}generateHash(e,r){let n=ke(xs(e)),i=ke(xs(r)),o=lt(n,i);return ke(o)}proofConfiguration(e){if(e.type!==this.type)throw new To("Type mismatch: config.type !== this.type",_o,{config:e,suite:this.#e()});if(e.cryptosuite!==this.cryptosuite)throw new To("Cryptosuite mismatch: config.cryptosuite !== this.cryptosuite",_o,{config:e,suite:this.#e()});if(e.created&&!Ro.isValidXsdDateTime(e.created))throw new To('Invalid config: "created" must be a valid XMLSchema DateTime string',_o,e);return rr(e)}proofSerialization(e,r){if(r.verificationMethod!==this.multikey.fullId())throw new To("Id mismatch: config.verificationMethod !== this.multikey.fullId()",fv,{config:r,suite:this.#e()});return this.multikey.sign(e)}proofVerification(e,r,n){if(n.verificationMethod!==this.multikey.fullId())throw new To("Id mismatch: config.verificationMethod !== this.multikey.fullId()",Ni,{config:n,suite:this.#e()});return this.multikey.verify(r,e)}};l();l();l();var us=class t{static type="Multikey";id;controller;#e;#t;constructor({id:e,controller:r,keyPair:n,externalSigner:i}){if(!n)throw new xn('Argument missing: "keyPair" required',"CONSTRUCTOR_ERROR");if(!n.publicKey)throw new xn('Argument missing: "keyPair" must contain a "publicKey"',"CONSTRUCTOR_ERROR");if(i){let o=i.publicKey,s=n.publicKey.compressed;if(o.length!==s.length||!o.every((c,a)=>c===s[a]))throw new xn("externalSigner.publicKey does not match keyPair.publicKey.compressed","CONSTRUCTOR_ERROR")}this.id=e,this.controller=r,this.#e=n,this.#t=i}get keyPair(){return this.#e}get publicKey(){return this.#e.publicKey}get secretKey(){try{return this.#e.secretKey}catch{throw new xn("Cannot get: no secretKey","PRIVATE_KEY_ERROR")}}toCryptosuite(){return new du(this)}sign(e){if(this.#t)return this.#t.sign(e,"bip340");if(!this.signer)throw new xn("Cannot sign: no secretKey","SIGN_ERROR");return Ur.sign(e,this.secretKey.bytes,Ir(32))}verify(e,r){return Ur.verify(e,r,this.publicKey.x)}fullId(){return this.id.startsWith("#")?`${this.controller}${this.id}`:this.id}toVerificationMethod(){return{id:this.id,type:t.type,controller:this.controller,publicKeyMultibase:this.publicKey.multibase.encoded}}get signer(){return!!this.#t||!!this.#e.secretKey}toJSON(){let e;try{e=this.signer}catch{e=!1}return{id:this.id,controller:this.controller,fullId:this.fullId(),signer:e,keyPair:this.keyPair.toJSON(),verificationMethod:this.toVerificationMethod()}}static create({id:e,controller:r,keyPair:n}){return new t({id:e,controller:r,keyPair:n})}static fromSecretKey(e,r,n){let i=new Vr(n),o=i.computePublicKey(),s=new uo({publicKey:o,secretKey:i});return new t({id:e,controller:r,keyPair:s})}static fromSigner(e,r,n){let i=new dt(n.publicKey),o=new uo({publicKey:i});return new t({id:e,controller:r,keyPair:o,externalSigner:n})}static fromPublicKey({id:e,controller:r,publicKeyBytes:n}){let i=new dt(n),o=new uo({publicKey:i});return new t({id:e,controller:r,keyPair:o})}static fromVerificationMethod({id:e,controller:r,publicKeyMultibase:n}){if(!n)throw new xn("Invalid publicKeyMultibase: cannot be undefined",ml,{publicKeyMultibase:n});let i=pf.decode(n);if(i.length!==35)throw new xn(`Invalid publicKeyMultibase length: ${i.length}`,ml,{publicKeyMultibase:n});if(i[0]!==231||i[1]!==1)throw new xn(`Invalid publicKeyMultibase prefix: expected secp256k1 multicodec [0xe7, 0x01], got [0x${i[0]?.toString(16)??"??"}, 0x${i[1]?.toString(16)??"??"}]`,ml,{publicKeyMultibase:n});let o=i.slice(2),s=new uo({publicKey:o});return new t({id:e,controller:r,keyPair:s})}};l();l();l();l();var Jp=class t{#e={phase:"Construct"};#t;#n;#r;#o;#i;constructor(e){this.#t=e.sourceDocument,this.#n=e.patches,this.#r=e.sourceVersionId,this.#o=e.verificationMethod,this.#i=e.beaconService}static construct(e,r,n){let i={"@context":[...au],patch:r,targetHash:"",targetVersionId:n+1,sourceHash:Gn(e)},o=Zc.apply(e,r);if(o.id!==e.id)throw new At(`Patches must not change the DID document id (source "${e.id}" to target "${o.id}").`,Ae,{sourceId:e.id,targetId:o.id});try{ln.isValid(o)}catch(s){throw new At("Error validating targetDocument: "+(s instanceof Error?s.message:String(s)),Ae,o)}return i.targetHash=Gn(o),i}static sign(e,r,n,i){if(!e.startsWith("did:btcr2:"))throw new At(`Expected a did:btcr2 identifier for the root capability; got "${e}".`,Ae,{did:e});let o=n.controller,s=n.id.indexOf("#");if(s<0)throw new At(`Verification method id must contain a fragment (e.g. "${n.id}#initialKey"); got "${n.id}".`,Ae,{verificationMethodId:n.id});let c=n.id.slice(s),a=us.fromSigner(c,o,i),u=s===0?`${e}${c}`:n.id,d=a.publicKey.multibase.encoded;if(n.publicKeyMultibase&&d!==n.publicKeyMultibase)throw new At(`Signing key does not match verification method "${n.id}": the signer's public key differs from the method's published publicKeyMultibase.`,Ae,{verificationMethodId:n.id,expected:n.publicKeyMultibase,actual:d});let f={"@context":[...au],cryptosuite:"bip340-jcs-2025",type:"DataIntegrityProof",verificationMethod:u,proofPurpose:"capabilityInvocation",capability:`urn:zcap:root:${encodeURIComponent(e)}`,capabilityAction:"Write"};return a.toCryptosuite().toDataIntegrityProof().addProof(r,f)}static async announce(e,r,n,i,o,s){return ia.establish(e,r).broadcastSignal(n,i,o,s)}#s(){return t.construct(this.#t,this.#n,this.#r)}advance(){for(;;)switch(this.#e.phase){case"Construct":{let e=this.#s();this.#e={phase:"Sign",unsignedUpdate:e};continue}case"Sign":return{status:"action-required",needs:[{kind:"NeedSigningKey",verificationMethodId:this.#o.id,unsignedUpdate:this.#e.unsignedUpdate}]};case"Fund":return{status:"action-required",needs:[{kind:"NeedFunding",beaconAddress:this.#i.serviceEndpoint.replace("bitcoin:",""),beaconService:this.#i}]};case"Broadcast":return{status:"action-required",needs:[{kind:"NeedBroadcast",beaconService:this.#i,signedUpdate:this.#e.signedUpdate,did:this.#t.id}]};case"Complete":return{status:"complete",result:{signedUpdate:this.#e.signedUpdate}}}}provide(e,r){switch(e.kind){case"NeedSigningKey":{if(this.#e.phase!=="Sign")throw new At(`Cannot provide NeedSigningKey: updater phase is ${this.#e.phase}, expected Sign.`,Ae,{phase:this.#e.phase});if(!r)throw new At("NeedSigningKey requires a Signer.",Ae);let n=this.#e.unsignedUpdate,i=t.sign(this.#t.id,n,this.#o,r);this.#e={phase:"Fund",unsignedUpdate:n,signedUpdate:i};break}case"NeedFunding":{if(this.#e.phase!=="Fund")throw new At(`Cannot provide NeedFunding: updater phase is ${this.#e.phase}, expected Fund.`,Ae,{phase:this.#e.phase});if(r!==void 0){let n=r;if(typeof n.utxoCount!="number"||!Number.isFinite(n.utxoCount)||n.utxoCount<1)throw new At(`NeedFunding proof must have utxoCount >= 1; got ${String(n.utxoCount)}.`,Ae,{utxoCount:n.utxoCount})}this.#e={phase:"Broadcast",unsignedUpdate:this.#e.unsignedUpdate,signedUpdate:this.#e.signedUpdate};break}case"NeedBroadcast":{if(this.#e.phase!=="Broadcast")throw new At(`Cannot provide NeedBroadcast: updater phase is ${this.#e.phase}, expected Broadcast.`,Ae,{phase:this.#e.phase});this.#e={phase:"Complete",signedUpdate:this.#e.signedUpdate};break}}}};var Xp=class{static methodName="btcr2";static create(e,r){let{idType:n,version:i=1,network:o="bitcoin"}=r||{};if(!n)throw new we("idType is required for creating a did:btcr2 identifier",Le,r);return vr.encode(e,{idType:n,version:i,network:o})}static resolve(e,r={}){let n=vr.decode(e),i=ds.sidecarData(r.sidecar),o=n.hrp===_l.k?ds.deterministic(n):null;return new ds(n,i,o,{versionId:r.versionId,versionTime:r.versionTime,genesisDocument:r.sidecar?.genesisDocument,maxDiscoveryRounds:r.maxDiscoveryRounds,minConf:r.minConf})}static update({sourceDocument:e,patches:r,sourceVersionId:n,verificationMethodId:i,beaconId:o}){let s=ut.relationshipMethodId(i,e.id);if(!(s!==void 0&&e.capabilityInvocation?.some(f=>ut.relationshipMethodId(f,e.id)===s)))throw new At("Invalid verificationMethodId: not authorized for capabilityInvocation",Le,e);let a=this.getSigningMethod(e,i);if(!a)throw new At("Invalid verificationMethod: not found in source document",Le,{sourceDocument:e,verificationMethodId:i});if(a.type!==su)throw new At(`Invalid verificationMethod: verificationMethod.type must be "${su}"`,Le,a);if(!a.publicKeyMultibase?.startsWith(cu))throw new At(`Invalid verificationMethodId: publicKeyMultibase prefix must start with "${cu}"`,Le,a);let u=ut.absoluteDidUrl(o,e.id),d=e.service.filter(f=>u!==void 0&&ut.absoluteDidUrl(f.id,e.id)===u).filter(f=>!!f).shift();if(!d)throw new At("No beacon service found for provided beaconId",Ae,{sourceDocument:e,beaconId:o});return new Jp({sourceDocument:e,patches:r,sourceVersionId:n,verificationMethod:a,beaconService:d})}static getSigningMethod(e,r){r??="#initialKey";let n=me.parse(e.id);if(n&&n.method!==this.methodName)throw new we(`Method not supported: ${n.method}`,gl,{identifier:e.id});let i=ut.absoluteDidUrl(r,e.id)??ut.relationshipMethodId(e.assertionMethod?.[0],e.id),o=i===void 0?void 0:e.verificationMethod?.find(s=>ut.absoluteDidUrl(s.id,e.id)===i);if(!(o&&o.publicKeyMultibase))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return o}};var BL=6;function yf(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function RL(t){return yf(t)&&Object.values(t).every(e=>typeof e=="string")}function UL(t){return yf(t)?Array.isArray(t.patch)&&typeof t.sourceHash=="string"&&typeof t.targetHash=="string"&&Number.isInteger(t.targetVersionId)&&t.targetVersionId>=2&&yf(t.proof):!1}function OL(t){return yf(t)?typeof t.id=="string"&&typeof t.collapsed=="string"&&Array.isArray(t.hashes):!1}function DL(t){if(t===void 0)return BL;if(typeof t=="number"&&Number.isInteger(t)&&t>=1)return t;let e=typeof t=="string"?JSON.stringify(t):String(t);throw new De(`Invalid resolution option minConf: expected a positive integer (minimum 1), got ${e}.`,lv,{minConf:t})}var ds=class t{#e;#t;#n;#r;#o;#i;#s=null;#f=new Map;#l=new Set;#d=new Set;#c=[];#a=null;#h=1;#g=[];#u;#p=0;#y;constructor(e,r,n,i){this.#e=e,this.#o=r,this.#i=n,this.#t=i?.versionId,this.#n=i?.versionTime;let o=i?.maxDiscoveryRounds;this.#u=typeof o=="number"&&o>0?o:1/0,this.#y=DL(i?.minConf),i?.genesisDocument&&(this.#s=i.genesisDocument),this.#r=n?"BeaconDiscovery":"GenesisDocument"}static deterministic(e){let r=e.genesisBytes,n=vr.encode(r,e),{multibase:i}=new dt(r),o=hn.generateBeaconServices({id:n,publicKey:r,network:Uo(e.network),beaconType:"SingletonBeacon"});return new ln({id:n,verificationMethod:[{id:`${n}#initialKey`,type:"Multikey",controller:n,publicKeyMultibase:i.encoded}],service:o})}static external(e,r){let n=Bo(r);if(!go(e.genesisBytes,n))throw new De("Initial document mismatch: genesisBytes !== genesisDocumentHash",ht,{genesisBytes:Xr(e.genesisBytes,"hex"),genesisDocumentHash:Xr(n,"hex")});let i=vr.encode(e.genesisBytes,e),o=JSON.parse(JSON.stringify(r).replaceAll(dr,i));return new ln(o)}static sidecarData(e={}){let r=new Map;if(e.updates?.length)for(let o of e.updates)r.set(Gn(o,{encoding:"hex"}),o);let n=new Map;if(e.casUpdates?.length)for(let o of e.casUpdates)n.set(Gn(o,{encoding:"hex"}),o);let i=new Map;if(e.smtProofs?.length)for(let o of e.smtProofs)i.set(Xr(Os(o.id,"base64urlnopad"),"hex"),o);return{updateMap:r,casMap:n,smtMap:i}}static updates(e,r,n,i,o={currentVersionId:1,updateHashHistory:[]}){let s=o.currentVersionId,c=o.updateHashHistory,a=r.sort(([d,f],[h,p])=>d.targetVersionId-h.targetVersionId||f.height-p.height),u={didDocument:e,metadata:{versionId:`${s}`,confirmations:0,deactivated:e.deactivated||!1}};for(let[d,f]of a){let h=Bo(u.didDocument),p=Ro.blocktimeToTimestamp(f.time);if(u.metadata.updated=Ro.toISOStringNonFractional(p),u.metadata.confirmations=f.confirmations,d.targetVersionId<=s){this.confirmDuplicate(d,c);continue}if(n&&p>Ro.dateStringToTimestamp(n))return u;if(d.targetVersionId===s+1){let y=Os(d.sourceHash,"base64urlnopad");if(!go(y,h))throw new De("Hash mismatch: update.sourceHash !== currentDocumentHash",Ae,{sourceHash:d.sourceHash,currentDocumentHash:Xr(h,"hex")});u.didDocument=this.applyUpdate(u.didDocument,d);let x=ks.deleteKeys(d,["proof"]);c.push(Bo(x))}else throw new De("Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1",wl,{targetVersionId:d.targetVersionId,currentVersionId:s+1});s++,u.metadata.versionId=`${s}`;let g=Number(i);if(!isNaN(g)&&g<=s)return u;if(u.didDocument.deactivated)return u.metadata.deactivated=u.didDocument.deactivated,u}return u}static confirmDuplicate(e,r){if(!Number.isInteger(e.targetVersionId)||e.targetVersionId<2)throw new De("Invalid duplicate: targetVersionId must be an integer >= 2",Ae,{targetVersionId:e.targetVersionId});let{proof:n,...i}=e,o=Bo(i),s=r[e.targetVersionId-2];if(s===void 0)throw new De("Invalid duplicate: no applied update in history for targetVersionId",wl,{targetVersionId:e.targetVersionId,historyLength:r.length});if(!go(s,o))throw new De("Invalid duplicate: unsigned update hash does not match historical hash",wl,{unsignedUpdateHash:Xr(o,"hex"),historicalHash:Xr(s,"hex")})}static applyUpdate(e,r){if(!Fb(r["@context"]))throw new De("Invalid update: @context is not the array the specification pins for a BTCR2 Update",Ae,{context:r["@context"],expected:[...au]});if(!Fb(r.proof?.["@context"],r["@context"]))throw new De("Invalid update: proof @context does not equal the update @context",Ae,{proofContext:r.proof?.["@context"],context:r["@context"]});let n=r.proof?.capability;if(!n)throw new De("No root capability found in update",Ae,r);let i=ut.dereferenceZcapId(n),{invocationTarget:o,controller:s}=i;if(![o,s].every(A=>A===e.id))throw new De("Invalid root capability",Ae,{rootCapability:i,currentDocument:e});let c=r.proof?.verificationMethod;if(!c)throw new De("No verificationMethod found in update",Ae,r);let a=ut.relationshipMethodId(c,e.id);if(!(a!==void 0&&e.capabilityInvocation?.some(A=>ut.relationshipMethodId(A,e.id)===a)))throw new De("Invalid update: verificationMethod is not authorized for capabilityInvocation",Ae,{verificationMethodId:c,capabilityInvocation:e.capabilityInvocation});let d=Xp.getSigningMethod(e,c),f=us.fromVerificationMethod(d),h=new du(f),p=rr(r),y=new uu(h).verifyProof(p,"capabilityInvocation");if(!y.verified)throw new De("Invalid update: proof not verified",Ae,y);let x=Zc.apply(e,r.patch);ln.validate(x);let S=Bo(x),_=Os(r.targetHash);if(!go(_,S))throw new De("Invalid update: update.targetHash !== currentDocumentHash",Ae,{updateTargetHash:_,currentDocumentHash:S});return x}resolve(){for(;;)switch(this.#r){case"GenesisDocument":{if(this.#s){this.#i=t.external(this.#e,this.#s),this.#s=null,this.#r="BeaconDiscovery";continue}return{status:"action-required",needs:[{kind:"NeedGenesisDocument",genesisHash:Xr(this.#e.genesisBytes,"hex")}]}}case"BeaconDiscovery":{let r=hn.getBeaconServices(this.#i).filter(n=>{let i=hn.parseBitcoinAddress(n.serviceEndpoint);return!this.#d.has(i)});if(r.length>0){for(let n of r){let i=hn.parseBitcoinAddress(n.serviceEndpoint);this.#d.add(i)}return{status:"action-required",needs:[{kind:"NeedBeaconSignals",beaconServices:r}]}}this.#r="BeaconProcess";continue}case"BeaconProcess":{let e=[];for(let[r,n]of this.#f){if(this.#l.has(r.id)||!n.length)continue;let i=this.#m(n);if(!i.length)continue;let s=ia.establish(r,this.#i.id).processSignals(i,this.#o);s.needs.length>0?e.push(...s.needs):(this.#c.push(...s.updates),this.#l.add(r.id))}if(e.length>0)return{status:"action-required",needs:e};this.#r="ApplyUpdates";continue}case"ApplyUpdates":{if(this.#c.length>0&&(this.#a=t.updates(this.#i,this.#c,this.#n,this.#t,{currentVersionId:this.#h,updateHashHistory:this.#g}),this.#h=Number(this.#a.metadata.versionId),this.#i=this.#a.didDocument,this.#c=[],hn.getBeaconServices(this.#i).some(n=>{let i=hn.parseBitcoinAddress(n.serviceEndpoint);return!this.#d.has(i)}))){if(++this.#p>this.#u)throw new De(`Exceeded the configured maximum of ${this.#u} beacon-discovery rounds. Raise or remove ResolutionOptions.maxDiscoveryRounds to resolve this DID.`,dv,{maxDiscoveryRounds:this.#u,discoveryRounds:this.#p});this.#r="BeaconDiscovery";continue}this.#r="Complete";continue}case"Complete":return{status:"resolved",result:this.#a??{didDocument:this.#i,metadata:{versionId:this.#t??"1",confirmations:0,deactivated:this.#i.deactivated||!1}}}}}#m(e){let r=[];for(let n of e){let i=n.blockMetadata,o=i?.confirmations;if(!(!Number.isInteger(o)||o<this.#y)){if(!Number.isFinite(i?.height)||!Number.isFinite(i?.time))throw new De(`Beacon signal ${n.signalBytes} has ${o} confirmations but no valid block height or block time.`,Ae,{signalBytes:n.signalBytes,confirmations:o,height:i?.height,time:i?.time});r.push(n)}}return r}provide(e,r){switch(e.kind){case"NeedGenesisDocument":{if(!yf(r))throw new De("Provided data for NeedGenesisDocument must be a document object.",Ae,{kind:e.kind});this.#s=r;break}case"NeedBeaconSignals":{if(!(r instanceof Map))throw new De("Provided data for NeedBeaconSignals must be a Map of beacon services to signals.",Ae,{kind:e.kind});for(let[n,i]of r)this.#f.set(n,i);break}case"NeedCASAnnouncement":{if(!RL(r))throw new De("Provided data for NeedCASAnnouncement is not a CAS announcement.",Ae,{kind:e.kind});let n=Gn(r,{encoding:"hex"});if(n!==e.announcementHash)throw new De(`CAS announcement hash mismatch: expected ${e.announcementHash}, got ${n}.`,Ae,{expected:e.announcementHash,actual:n});this.#o.casMap.set(n,r);break}case"NeedSignedUpdate":{if(!UL(r))throw new De("Provided data for NeedSignedUpdate is not a signed BTCR2 update.",Ae,{kind:e.kind});let n=Gn(r,{encoding:"hex"});if(n!==e.updateHash)throw new De(`Signed update hash mismatch: expected ${e.updateHash}, got ${n}.`,Ae,{expected:e.updateHash,actual:n});this.#o.updateMap.set(n,r);break}case"NeedSMTProof":{if(!OL(r))throw new De("Provided data for NeedSMTProof is not an SMT proof.",Ae,{kind:e.kind});let n=Xr(Os(r.id,"base64urlnopad"),"hex");if(n!==e.smtRootHash)throw new De(`SMT proof root hash mismatch: expected ${e.smtRootHash}, got ${n}`,Ae,{expected:e.smtRootHash,actual:n});this.#o.smtMap.set(e.smtRootHash,r);break}}}};function kL(t){let e=t.capabilityInvocation?.[0];if(e===void 0)throw new qe("Cannot derive aggregation communication key: capabilityInvocation is absent",Le,{id:t.id});let r=ut.absoluteDidUrl(e,t.id),n=typeof e=="string"?r===void 0?void 0:t.verificationMethod?.find(i=>ut.absoluteDidUrl(i.id,t.id)===r):e;if(!n)throw new qe(`Cannot derive aggregation communication key: capabilityInvocation[0] "${e}" does not resolve to a verification method`,Le,{id:t.id,invocation:e});return us.fromVerificationMethod(n).publicKey}function Hne(t,e){try{let r=vr.decode(t);if(r.idType==="KEY")return new dt(r.genesisBytes);if(e?.genesisDocument){let n=ds.external(r,e.genesisDocument);return kL(n)}}catch{}}l();l();l();var FI=class{document={};constructor(e){if(!e.id)throw new qe('Missing required "id" property',Le,e);this.document.id=e.id,this.document.verificationMethod=e.verificationMethod??[],e["@context"]&&(this.document["@context"]=e["@context"])}withAuthentication(e){return e&&(this.document.authentication=e),this}withAssertionMethod(e){return e&&(this.document.assertionMethod=e),this}withCapabilityInvocation(e){return e&&(this.document.capabilityInvocation=e),this}withCapabilityDelegation(e){return e&&(this.document.capabilityDelegation=e),this}withService(e){return e&&(this.document.service=e),this}build(){let e=new ln(this.document);for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}};export{wv as AggregateBeaconError,ut as Appendix,Wte as BECH32M_CHARS,xL as BTCR2_DID_DOCUMENT_CONTEXT,au as BTCR2_UPDATE_CONTEXT,nr as BeaconError,ia as BeaconFactory,KI as BeaconSignalDiscovery,hn as BeaconUtils,Il as CASBeacon,bv as CASBeaconError,Ev as CHANGE_OUTPUT_VBYTES,O0 as DEFAULT_FEE_ESTIMATOR,BL as DEFAULT_MIN_CONF,EL as DID_REGEX,vv as DUST_LIMIT_SATS,Xp as DidBtcr2,ln as DidDocument,FI as DidDocumentBuilder,qb as DidVerificationMethod,hf as GenesisDocument,dr as ID_PLACEHOLDER_VALUE,vr as Identifier,cu as MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX,su as MULTIKEY_VERIFICATION_METHOD_TYPE,zR as P2PKH_BEACON_TX_VSIZE,WR as P2TR_BEACON_TX_VSIZE,GR as P2WPKH_BEACON_TX_VSIZE,ds as Resolver,YR as SINGLETON_BEACON_TX_VSIZE,Pl as SMTBeacon,ju as SMTBeaconError,D0 as SPENDABLE_DUST_LIMIT_SATS,Oo as SinglePartyBeacon,Bl as SingletonBeacon,mv as SingletonBeaconError,Wu as StaticFeeEstimator,Jp as Updater,Sv as beaconTxVsize,$$ as buildAggregationBeaconTx,JR as deriveSingletonAddress,Av as detectSingletonScriptKind,MI as extractOpReturnSignalHash,kL as getAggregationCommunicationKey,Fb as isBtcr2UpdateContext,vL as isMultikeyVerificationMethod,Iv as opReturnScript,Hne as resolveBtcr2SenderPk,Tv as resolveChangeAddress,QR as selectSpendableUtxo};
|
|
1
|
+
var hB=Object.create;var oy=Object.defineProperty;var pB=Object.getOwnPropertyDescriptor;var yB=Object.getOwnPropertyNames;var gB=Object.getPrototypeOf,mB=Object.prototype.hasOwnProperty;var wB=(t,e)=>()=>(t&&(e=t(t=0)),e);var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),If=(t,e)=>{for(var r in e)oy(t,r,{get:e[r],enumerable:!0})},bB=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yB(e))!mB.call(t,i)&&i!==r&&oy(t,i,{get:()=>e[i],enumerable:!(n=pB(e,i))||n.enumerable});return t};var Kn=(t,e,r)=>(r=t!=null?hB(gB(t)):{},bB(e||!t||!t.__esModule?oy(r,"default",{value:t,enumerable:!0}):r,t));var dx=oe(Bf=>{"use strict";l();Bf.byteLength=EB;Bf.toByteArray=SB;Bf.fromByteArray=_B;var $n=[],zr=[],xB=typeof Uint8Array<"u"?Uint8Array:Array,sy="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(gs=0,ax=sy.length;gs<ax;++gs)$n[gs]=sy[gs],zr[sy.charCodeAt(gs)]=gs;var gs,ax;zr[45]=62;zr[95]=63;function ux(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function EB(t){var e=ux(t),r=e[0],n=e[1];return(r+n)*3/4-n}function vB(t,e,r){return(e+r)*3/4-r}function SB(t){var e,r=ux(t),n=r[0],i=r[1],o=new xB(vB(t,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)e=zr[t.charCodeAt(a)]<<18|zr[t.charCodeAt(a+1)]<<12|zr[t.charCodeAt(a+2)]<<6|zr[t.charCodeAt(a+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=zr[t.charCodeAt(a)]<<2|zr[t.charCodeAt(a+1)]>>4,o[s++]=e&255),i===1&&(e=zr[t.charCodeAt(a)]<<10|zr[t.charCodeAt(a+1)]<<4|zr[t.charCodeAt(a+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function AB(t){return $n[t>>18&63]+$n[t>>12&63]+$n[t>>6&63]+$n[t&63]}function TB(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(AB(n));return i.join("")}function _B(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,c=r-n;s<c;s+=o)i.push(TB(t,s,s+o>c?c:s+o));return n===1?(e=t[r-1],i.push($n[e>>2]+$n[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push($n[e>>10]+$n[e>>4&63]+$n[e<<2&63]+"=")),i.join("")}});var fx=oe(cy=>{l();cy.read=function(t,e,r,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,u=a>>1,d=-7,f=r?i-1:0,h=r?-1:1,p=t[e+f];for(f+=h,o=p&(1<<-d)-1,p>>=-d,d+=c;d>0;o=o*256+t[e+f],f+=h,d-=8);for(s=o&(1<<-d)-1,o>>=-d,d+=n;d>0;s=s*256+t[e+f],f+=h,d-=8);if(o===0)o=1-u;else{if(o===a)return s?NaN:(p?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(p?-1:1)*s*Math.pow(2,o-n)};cy.write=function(t,e,r,n,i,o){var s,c,a,u=o*8-i-1,d=(1<<u)-1,f=d>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,g=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=d):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+f>=1?e+=h/a:e+=h*Math.pow(2,1-f),e*a>=2&&(s++,a/=2),s+f>=d?(c=0,s=d):s+f>=1?(c=(e*a-1)*Math.pow(2,i),s=s+f):(c=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[r+p]=c&255,p+=g,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;t[r+p]=s&255,p+=g,s/=256,u-=8);t[r+p-g]|=y*128}});var _r=oe(Oc=>{"use strict";l();var ay=dx(),Uc=fx(),lx=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Oc.Buffer=F;Oc.SlowBuffer=DB;Oc.INSPECT_MAX_BYTES=50;var Rf=2147483647;Oc.kMaxLength=Rf;F.TYPED_ARRAY_SUPPORT=IB();!F.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 IB(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(F.prototype,"parent",{enumerable:!0,get:function(){if(F.isBuffer(this))return this.buffer}});Object.defineProperty(F.prototype,"offset",{enumerable:!0,get:function(){if(F.isBuffer(this))return this.byteOffset}});function bi(t){if(t>Rf)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,F.prototype),e}function F(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ly(t)}return yx(t,e,r)}F.poolSize=8192;function yx(t,e,r){if(typeof t=="string")return RB(t,e);if(ArrayBuffer.isView(t))return UB(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Hn(t,ArrayBuffer)||t&&Hn(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Hn(t,SharedArrayBuffer)||t&&Hn(t.buffer,SharedArrayBuffer)))return dy(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return F.from(n,e,r);var i=OB(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return F.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}F.from=function(t,e,r){return yx(t,e,r)};Object.setPrototypeOf(F.prototype,Uint8Array.prototype);Object.setPrototypeOf(F,Uint8Array);function gx(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function BB(t,e,r){return gx(t),t<=0?bi(t):e!==void 0?typeof r=="string"?bi(t).fill(e,r):bi(t).fill(e):bi(t)}F.alloc=function(t,e,r){return BB(t,e,r)};function ly(t){return gx(t),bi(t<0?0:hy(t)|0)}F.allocUnsafe=function(t){return ly(t)};F.allocUnsafeSlow=function(t){return ly(t)};function RB(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!F.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=mx(t,e)|0,n=bi(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function uy(t){for(var e=t.length<0?0:hy(t.length)|0,r=bi(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function UB(t){if(Hn(t,Uint8Array)){var e=new Uint8Array(t);return dy(e.buffer,e.byteOffset,e.byteLength)}return uy(t)}function dy(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,F.prototype),n}function OB(t){if(F.isBuffer(t)){var e=hy(t.length)|0,r=bi(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||py(t.length)?bi(0):uy(t);if(t.type==="Buffer"&&Array.isArray(t.data))return uy(t.data)}function hy(t){if(t>=Rf)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Rf.toString(16)+" bytes");return t|0}function DB(t){return+t!=t&&(t=0),F.alloc(+t)}F.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==F.prototype};F.compare=function(e,r){if(Hn(e,Uint8Array)&&(e=F.from(e,e.offset,e.byteLength)),Hn(r,Uint8Array)&&(r=F.from(r,r.offset,r.byteLength)),!F.isBuffer(e)||!F.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,i=r.length,o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};F.isEncoding=function(e){switch(String(e).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}};F.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return F.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var i=F.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){var s=e[n];if(Hn(s,Uint8Array))o+s.length>i.length?F.from(s).copy(i,o):Uint8Array.prototype.set.call(i,s,o);else if(F.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function mx(t,e){if(F.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Hn(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return fy(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Sx(t).length;default:if(i)return n?-1:fy(t).length;e=(""+e).toLowerCase(),i=!0}}F.byteLength=mx;function kB(t,e,r){var n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return qB(this,e,r);case"utf8":case"utf-8":return bx(this,e,r);case"ascii":return HB(this,e,r);case"latin1":case"binary":return VB(this,e,r);case"base64":return KB(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return FB(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}F.prototype._isBuffer=!0;function ms(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}F.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<e;r+=2)ms(this,r,r+1);return this};F.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<e;r+=4)ms(this,r,r+3),ms(this,r+1,r+2);return this};F.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<e;r+=8)ms(this,r,r+7),ms(this,r+1,r+6),ms(this,r+2,r+5),ms(this,r+3,r+4);return this};F.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?bx(this,0,e):kB.apply(this,arguments)};F.prototype.toLocaleString=F.prototype.toString;F.prototype.equals=function(e){if(!F.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:F.compare(this,e)===0};F.prototype.inspect=function(){var e="",r=Oc.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};lx&&(F.prototype[lx]=F.prototype.inspect);F.prototype.compare=function(e,r,n,i,o){if(Hn(e,Uint8Array)&&(e=F.from(e,e.offset,e.byteLength)),!F.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;for(var s=o-i,c=n-r,a=Math.min(s,c),u=this.slice(i,o),d=e.slice(r,n),f=0;f<a;++f)if(u[f]!==d[f]){s=u[f],c=d[f];break}return s<c?-1:c<s?1:0};function wx(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,py(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=F.from(e,n)),F.isBuffer(e))return e.length===0?-1:hx(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):hx(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function hx(t,e,r,n,i){var o=1,s=t.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,c/=2,r/=2}function a(p,g){return o===1?p[g]:p.readUInt16BE(g*o)}var u;if(i){var d=-1;for(u=r;u<s;u++)if(a(t,u)===a(e,d===-1?0:u-d)){if(d===-1&&(d=u),u-d+1===c)return d*o}else d!==-1&&(u-=u-d),d=-1}else for(r+c>s&&(r=s-c),u=r;u>=0;u--){for(var f=!0,h=0;h<c;h++)if(a(t,u+h)!==a(e,h)){f=!1;break}if(f)return u}return-1}F.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};F.prototype.indexOf=function(e,r,n){return wx(this,e,r,n,!0)};F.prototype.lastIndexOf=function(e,r,n){return wx(this,e,r,n,!1)};function NB(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var c=parseInt(e.substr(s*2,2),16);if(py(c))return s;t[r+s]=c}return s}function CB(t,e,r,n){return Uf(fy(e,t.length-r),t,r,n)}function LB(t,e,r,n){return Uf(GB(e),t,r,n)}function PB(t,e,r,n){return Uf(Sx(e),t,r,n)}function MB(t,e,r,n){return Uf(zB(e,t.length-r),t,r,n)}F.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return NB(this,e,r,n);case"utf8":case"utf-8":return CB(this,e,r,n);case"ascii":case"latin1":case"binary":return LB(this,e,r,n);case"base64":return PB(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return MB(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};F.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function KB(t,e,r){return e===0&&r===t.length?ay.fromByteArray(t):ay.fromByteArray(t.slice(e,r))}function bx(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o=t[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=r){var a,u,d,f;switch(c){case 1:o<128&&(s=o);break;case 2:a=t[i+1],(a&192)===128&&(f=(o&31)<<6|a&63,f>127&&(s=f));break;case 3:a=t[i+1],u=t[i+2],(a&192)===128&&(u&192)===128&&(f=(o&15)<<12|(a&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:a=t[i+1],u=t[i+2],d=t[i+3],(a&192)===128&&(u&192)===128&&(d&192)===128&&(f=(o&15)<<18|(a&63)<<12|(u&63)<<6|d&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return $B(n)}var px=4096;function $B(t){var e=t.length;if(e<=px)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=px));return r}function HB(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function VB(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function qB(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=YB[t[o]];return i}function FB(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}F.prototype.slice=function(e,r){var n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);var i=this.subarray(e,r);return Object.setPrototypeOf(i,F.prototype),i};function Ot(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}F.prototype.readUintLE=F.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e],o=1,s=0;++s<r&&(o*=256);)i+=this[e+s]*o;return i};F.prototype.readUintBE=F.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e+--r],o=1;r>0&&(o*=256);)i+=this[e+--r]*o;return i};F.prototype.readUint8=F.prototype.readUInt8=function(e,r){return e=e>>>0,r||Ot(e,1,this.length),this[e]};F.prototype.readUint16LE=F.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||Ot(e,2,this.length),this[e]|this[e+1]<<8};F.prototype.readUint16BE=F.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||Ot(e,2,this.length),this[e]<<8|this[e+1]};F.prototype.readUint32LE=F.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};F.prototype.readUint32BE=F.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};F.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=this[e],o=1,s=0;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};F.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ot(e,r,this.length);for(var i=r,o=1,s=this[e+--i];i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};F.prototype.readInt8=function(e,r){return e=e>>>0,r||Ot(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};F.prototype.readInt16LE=function(e,r){e=e>>>0,r||Ot(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};F.prototype.readInt16BE=function(e,r){e=e>>>0,r||Ot(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};F.prototype.readInt32LE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};F.prototype.readInt32BE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};F.prototype.readFloatLE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),Uc.read(this,e,!0,23,4)};F.prototype.readFloatBE=function(e,r){return e=e>>>0,r||Ot(e,4,this.length),Uc.read(this,e,!1,23,4)};F.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||Ot(e,8,this.length),Uc.read(this,e,!0,52,8)};F.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||Ot(e,8,this.length),Uc.read(this,e,!1,52,8)};function fr(t,e,r,n,i,o){if(!F.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}F.prototype.writeUintLE=F.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;fr(this,e,r,n,o,0)}var s=1,c=0;for(this[r]=e&255;++c<n&&(s*=256);)this[r+c]=e/s&255;return r+n};F.prototype.writeUintBE=F.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;fr(this,e,r,n,o,0)}var s=n-1,c=1;for(this[r+s]=e&255;--s>=0&&(c*=256);)this[r+s]=e/c&255;return r+n};F.prototype.writeUint8=F.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,1,255,0),this[r]=e&255,r+1};F.prototype.writeUint16LE=F.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};F.prototype.writeUint16BE=F.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};F.prototype.writeUint32LE=F.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};F.prototype.writeUint32BE=F.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};F.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);fr(this,e,r,n,o-1,-o)}var s=0,c=1,a=0;for(this[r]=e&255;++s<n&&(c*=256);)e<0&&a===0&&this[r+s-1]!==0&&(a=1),this[r+s]=(e/c>>0)-a&255;return r+n};F.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);fr(this,e,r,n,o-1,-o)}var s=n-1,c=1,a=0;for(this[r+s]=e&255;--s>=0&&(c*=256);)e<0&&a===0&&this[r+s+1]!==0&&(a=1),this[r+s]=(e/c>>0)-a&255;return r+n};F.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};F.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};F.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};F.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};F.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||fr(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function xx(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Ex(t,e,r,n,i){return e=+e,r=r>>>0,i||xx(t,e,r,4,34028234663852886e22,-34028234663852886e22),Uc.write(t,e,r,n,23,4),r+4}F.prototype.writeFloatLE=function(e,r,n){return Ex(this,e,r,!0,n)};F.prototype.writeFloatBE=function(e,r,n){return Ex(this,e,r,!1,n)};function vx(t,e,r,n,i){return e=+e,r=r>>>0,i||xx(t,e,r,8,17976931348623157e292,-17976931348623157e292),Uc.write(t,e,r,n,52,8),r+8}F.prototype.writeDoubleLE=function(e,r,n){return vx(this,e,r,!0,n)};F.prototype.writeDoubleBE=function(e,r,n){return vx(this,e,r,!1,n)};F.prototype.copy=function(e,r,n,i){if(!F.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);var o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};F.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!F.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){var o=e.charCodeAt(0);(i==="utf8"&&o<128||i==="latin1")&&(e=o)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if(typeof e=="number")for(s=r;s<n;++s)this[s]=e;else{var c=F.isBuffer(e)?e:F.from(e,i),a=c.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=c[s%a]}return this};var jB=/[^+/0-9A-Za-z-_]/g;function WB(t){if(t=t.split("=")[0],t=t.trim().replace(jB,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function fy(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function GB(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function zB(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Sx(t){return ay.toByteArray(WB(t))}function Uf(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Hn(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function py(t){return t!==t}var YB=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=r*16,i=0;i<16;++i)e[n+i]=t[r]+t[i];return e}()});var vi=oe((cP,Ix)=>{l();var lt=Ix.exports={},Vn,qn;function yy(){throw new Error("setTimeout has not been defined")}function gy(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Vn=setTimeout:Vn=yy}catch{Vn=yy}try{typeof clearTimeout=="function"?qn=clearTimeout:qn=gy}catch{qn=gy}})();function Ax(t){if(Vn===setTimeout)return setTimeout(t,0);if((Vn===yy||!Vn)&&setTimeout)return Vn=setTimeout,setTimeout(t,0);try{return Vn(t,0)}catch{try{return Vn.call(null,t,0)}catch{return Vn.call(this,t,0)}}}function JB(t){if(qn===clearTimeout)return clearTimeout(t);if((qn===gy||!qn)&&clearTimeout)return qn=clearTimeout,clearTimeout(t);try{return qn(t)}catch{try{return qn.call(null,t)}catch{return qn.call(this,t)}}}var xi=[],Dc=!1,ws,Of=-1;function XB(){!Dc||!ws||(Dc=!1,ws.length?xi=ws.concat(xi):Of=-1,xi.length&&Tx())}function Tx(){if(!Dc){var t=Ax(XB);Dc=!0;for(var e=xi.length;e;){for(ws=xi,xi=[];++Of<e;)ws&&ws[Of].run();Of=-1,e=xi.length}ws=null,Dc=!1,JB(t)}}lt.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];xi.push(new _x(t,e)),xi.length===1&&!Dc&&Ax(Tx)};function _x(t,e){this.fun=t,this.array=e}_x.prototype.run=function(){this.fun.apply(null,this.array)};lt.title="browser";lt.browser=!0;lt.env={};lt.argv=[];lt.version="";lt.versions={};function Ei(){}lt.on=Ei;lt.addListener=Ei;lt.once=Ei;lt.off=Ei;lt.removeListener=Ei;lt.removeAllListeners=Ei;lt.emit=Ei;lt.prependListener=Ei;lt.prependOnceListener=Ei;lt.listeners=function(t){return[]};lt.binding=function(t){throw new Error("process.binding is not supported")};lt.cwd=function(){return"/"};lt.chdir=function(t){throw new Error("process.chdir is not supported")};lt.umask=function(){return 0}});var b,w,uP,l=wB(()=>{b=Kn(_r()),w=Kn(vi()),uP=function(t){function e(){var n=this||self;return delete t.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();t.defineProperty(t.prototype,"__magic__",{configurable:!0,get:e});var r=__magic__;return r}(Object)});var Zv=oe((qH,Xv)=>{l();var p6=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Hl=()=>p6.now(),y6=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),G0=t=>t===1/0||y6(t),z0=class t{constructor({max:e=1/0,ttl:r,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:o=!1,dispose:s,noDisposeOnSet:c=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,r!==void 0&&!G0(r))throw new TypeError("ttl must be positive integer or Infinity if set");if(!G0(e))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=r,this.max=e,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!o,this.noDisposeOnSet=!!c,s!==void 0){if(typeof s!="function")throw new TypeError("dispose must be function if set");this.dispose=s}this.timer=void 0,this.timerExpiration=void 0}setTimer(e,r){if(this.timerExpiration<e)return;this.timer&&clearTimeout(this.timer);let n=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let i in this.expirations){this.setTimer(i,i-Hl());break}},r);n.unref&&n.unref(),this.timerExpiration=e,this.timer=n}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return w.default.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let e=this.dispose!==t.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[r,n]of e)this.dispose(n,r,"delete")}setTTL(e,r=this.ttl){let n=this.expirationMap.get(e);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==e)}if(r!==1/0){let i=Math.floor(Hl()+r);this.expirationMap.set(e,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,r)),this.expirations[i].push(e)}else this.expirationMap.set(e,1/0)}set(e,r,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!G0(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(e)){i||this.setTTL(e,n);let s=this.data.get(e);s!==r&&(this.data.set(e,r),o||this.dispose(s,e,"set"))}else this.setTTL(e,n),this.data.set(e,r);for(;this.size>this.max;)this.purgeToCapacity();return this}has(e){return this.data.has(e)}getRemainingTTL(e){let r=this.expirationMap.get(e);return r===1/0?r:r!==void 0?Math.max(0,Math.ceil(r-Hl())):0}get(e,{updateAgeOnGet:r=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(e);if(i&&this.getRemainingTTL(e)===0){this.delete(e);return}return r&&this.setTTL(e,n),o}dispose(e,r){}delete(e){let r=this.expirationMap.get(e);if(r!==void 0){let n=this.data.get(e);this.data.delete(e),this.expirationMap.delete(e);let i=this.expirations[r];return i&&(i.length<=1?delete this.expirations[r]:this.expirations[r]=i.filter(o=>o!==e)),this.dispose(n,e,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let e in this.expirations){let r=this.expirations[e];if(this.size-r.length>=this.max){delete this.expirations[e];let n=[];for(let i of r)n.push([i,this.data.get(i)]),this.data.delete(i),this.expirationMap.delete(i);for(let[i,o]of n)this.dispose(o,i,"evict")}else{let n=this.size-this.max,i=[];for(let o of r.splice(0,n))i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"evict");return}}}get size(){return this.data.size}purgeStale(){let e=Math.ceil(Hl());for(let r in this.expirations){if(r==="Infinity"||r>e)return;let n=[...this.expirations[r]||[]],i=[];delete this.expirations[r];for(let o of n)i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let e in this.expirations)for(let r of this.expirations[e])yield[r,this.data.get(r)]}*keys(){for(let e in this.expirations)for(let r of this.expirations[e])yield r}*values(){for(let e in this.expirations)for(let r of this.expirations[e])yield this.data.get(r)}[Symbol.iterator](){return this.entries()}};Xv.exports=z0});var y1=oe(p1=>{"use strict";l();p1.supports=function(...e){let r=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(r,{snapshots:r.snapshots||!1,permanence:r.permanence||!1,seek:r.seek||!1,clear:r.clear||!1,getMany:r.getMany||!1,keyIterator:r.keyIterator||!1,valueIterator:r.valueIterator||!1,iteratorNextv:r.iteratorNextv||!1,iteratorAll:r.iteratorAll||!1,status:r.status||!1,createIfMissing:r.createIfMissing||!1,errorIfExists:r.errorIfExists||!1,deferredOpen:r.deferredOpen||!1,promises:r.promises||!1,streams:r.streams||!1,encodings:Object.assign({},r.encodings),events:Object.assign({},r.events),additionalMethods:Object.assign({},r.additionalMethods)})}});var Sn=oe((hq,g1)=>{"use strict";l();g1.exports=class extends Error{constructor(e,r){super(e||""),typeof r=="object"&&r!==null&&(r.code&&(this.code=String(r.code)),r.expected&&(this.expected=!0),r.transient&&(this.transient=!0),r.cause&&(this.cause=r.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var ug=oe((yq,m1)=>{"use strict";l();var ag=null;m1.exports=function(){return ag===null&&(ag={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),ag}});var lg=oe(w1=>{"use strict";l();var dg=Sn(),z6=new Set(["buffer","view","utf8"]),fg=class{constructor(e){if(this.encode=e.encode||this.encode,this.decode=e.decode||this.decode,this.name=e.name||this.name,this.format=e.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!z6.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");e.createViewTranscoder&&(this.createViewTranscoder=e.createViewTranscoder),e.createBufferTranscoder&&(this.createBufferTranscoder=e.createBufferTranscoder),e.createUTF8Transcoder&&(this.createUTF8Transcoder=e.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new dg(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new dg(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new dg(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};w1.Encoding=fg});var gg=oe(ql=>{"use strict";l();var{Buffer:pg}=_r()||{},{Encoding:yg}=lg(),Y6=ug(),sd=class extends yg{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new cd({encode:this.encode,decode:e=>this.decode(pg.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},cd=class extends yg{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new sd({encode:e=>{let r=this.encode(e);return pg.from(r.buffer,r.byteOffset,r.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},hg=class extends yg{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new sd({encode:e=>pg.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:r}=Y6();return new cd({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(r.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};ql.BufferFormat=sd;ql.ViewFormat=cd;ql.UTF8Format=hg});var v1=oe(Hs=>{"use strict";l();var{Buffer:Xt}=_r()||{Buffer:{isBuffer:()=>!1}},{textEncoder:x1,textDecoder:b1}=ug()(),{BufferFormat:ad,ViewFormat:mg,UTF8Format:E1}=gg(),Fl=t=>t;Hs.utf8=new E1({encode:function(t){return Xt.isBuffer(t)?t.toString("utf8"):ArrayBuffer.isView(t)?b1.decode(t):String(t)},decode:Fl,name:"utf8",createViewTranscoder(){return new mg({encode:function(t){return ArrayBuffer.isView(t)?t:x1.encode(t)},decode:function(t){return b1.decode(t)},name:`${this.name}+view`})},createBufferTranscoder(){return new ad({encode:function(t){return Xt.isBuffer(t)?t:ArrayBuffer.isView(t)?Xt.from(t.buffer,t.byteOffset,t.byteLength):Xt.from(String(t),"utf8")},decode:function(t){return t.toString("utf8")},name:`${this.name}+buffer`})}});Hs.json=new E1({encode:JSON.stringify,decode:JSON.parse,name:"json"});Hs.buffer=new ad({encode:function(t){return Xt.isBuffer(t)?t:ArrayBuffer.isView(t)?Xt.from(t.buffer,t.byteOffset,t.byteLength):Xt.from(String(t),"utf8")},decode:Fl,name:"buffer",createViewTranscoder(){return new mg({encode:function(t){return ArrayBuffer.isView(t)?t:Xt.from(String(t),"utf8")},decode:function(t){return Xt.from(t.buffer,t.byteOffset,t.byteLength)},name:`${this.name}+view`})}});Hs.view=new mg({encode:function(t){return ArrayBuffer.isView(t)?t:x1.encode(t)},decode:Fl,name:"view",createBufferTranscoder(){return new ad({encode:function(t){return Xt.isBuffer(t)?t:ArrayBuffer.isView(t)?Xt.from(t.buffer,t.byteOffset,t.byteLength):Xt.from(String(t),"utf8")},decode:Fl,name:`${this.name}+buffer`})}});Hs.hex=new ad({encode:function(t){return Xt.isBuffer(t)?t:Xt.from(String(t),"hex")},decode:function(t){return t.toString("hex")},name:"hex"});Hs.base64=new ad({encode:function(t){return Xt.isBuffer(t)?t:Xt.from(String(t),"base64")},decode:function(t){return t.toString("base64")},name:"base64"})});var T1=oe(A1=>{"use strict";l();var S1=Sn(),Wl=v1(),{Encoding:J6}=lg(),{BufferFormat:X6,ViewFormat:Z6,UTF8Format:Q6}=gg(),ud=Symbol("formats"),jl=Symbol("encodings"),eU=new Set(["buffer","view","utf8"]),wg=class{constructor(e){if(Array.isArray(e)){if(!e.every(r=>eU.has(r)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[jl]=new Map,this[ud]=new Set(e);for(let r in Wl)try{this.encoding(r)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[jl].values()))}encoding(e){let r=this[jl].get(e);if(r===void 0){if(typeof e=="string"&&e!==""){if(r=iU[e],!r)throw new S1(`Encoding '${e}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof e!="object"||e===null)throw new TypeError("First argument 'encoding' must be a string or object");r=tU(e)}let{name:n,format:i}=r;if(!this[ud].has(i))if(this[ud].has("view"))r=r.createViewTranscoder();else if(this[ud].has("buffer"))r=r.createBufferTranscoder();else if(this[ud].has("utf8"))r=r.createUTF8Transcoder();else throw new S1(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,r.name,r.commonName])this[jl].set(o,r)}return r}};A1.Transcoder=wg;function tU(t){if(t instanceof J6)return t;let e="type"in t&&typeof t.type=="string"?t.type:void 0,r=t.name||e||`anonymous-${oU++}`;switch(rU(t)){case"view":return new Z6({...t,name:r});case"utf8":return new Q6({...t,name:r});case"buffer":return new X6({...t,name:r});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function rU(t){return"format"in t&&t.format!==void 0?t.format:"buffer"in t&&typeof t.buffer=="boolean"?t.buffer?"buffer":"utf8":"code"in t&&Number.isInteger(t.code)?"view":"buffer"}var nU={binary:Wl.buffer,"utf-8":Wl.utf8},iU={...Wl,...nU},oU=0});var fa=oe((Tq,bg)=>{"use strict";l();var da=typeof Reflect=="object"?Reflect:null,_1=da&&typeof da.apply=="function"?da.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Gl;da&&typeof da.ownKeys=="function"?Gl=da.ownKeys:Object.getOwnPropertySymbols?Gl=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Gl=function(e){return Object.getOwnPropertyNames(e)};function sU(t){console&&console.warn&&console.warn(t)}var B1=Number.isNaN||function(e){return e!==e};function Le(){Le.init.call(this)}bg.exports=Le;bg.exports.once=dU;Le.EventEmitter=Le;Le.prototype._events=void 0;Le.prototype._eventsCount=0;Le.prototype._maxListeners=void 0;var I1=10;function zl(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(Le,"defaultMaxListeners",{enumerable:!0,get:function(){return I1},set:function(t){if(typeof t!="number"||t<0||B1(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");I1=t}});Le.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};Le.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||B1(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function R1(t){return t._maxListeners===void 0?Le.defaultMaxListeners:t._maxListeners}Le.prototype.getMaxListeners=function(){return R1(this)};Le.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=e==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var a=o[e];if(a===void 0)return!1;if(typeof a=="function")_1(a,this,r);else for(var u=a.length,d=N1(a,u),n=0;n<u;++n)_1(d[n],this,r);return!0};function U1(t,e,r,n){var i,o,s;if(zl(r),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]),s===void 0)s=o[e]=r,++t._eventsCount;else if(typeof s=="function"?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=R1(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,sU(c)}return t}Le.prototype.addListener=function(e,r){return U1(this,e,r,!1)};Le.prototype.on=Le.prototype.addListener;Le.prototype.prependListener=function(e,r){return U1(this,e,r,!0)};function cU(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function O1(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=cU.bind(n);return i.listener=r,n.wrapFn=i,i}Le.prototype.once=function(e,r){return zl(r),this.on(e,O1(this,e,r)),this};Le.prototype.prependOnceListener=function(e,r){return zl(r),this.prependListener(e,O1(this,e,r)),this};Le.prototype.removeListener=function(e,r){var n,i,o,s,c;if(zl(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():aU(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};Le.prototype.off=Le.prototype.removeListener;Le.prototype.removeAllListeners=function(e){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(e,r[i]);return this};function D1(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?uU(i):N1(i,i.length)}Le.prototype.listeners=function(e){return D1(this,e,!0)};Le.prototype.rawListeners=function(e){return D1(this,e,!1)};Le.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):k1.call(t,e)};Le.prototype.listenerCount=k1;function k1(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}Le.prototype.eventNames=function(){return this._eventsCount>0?Gl(this._events):[]};function N1(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function aU(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function uU(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function dU(t,e){return new Promise(function(r,n){function i(s){t.removeListener(e,o),n(s)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),r([].slice.call(arguments))}C1(t,e,o,{once:!0}),e!=="error"&&fU(t,i,{once:!0})})}function fU(t,e,r){typeof t.on=="function"&&C1(t,"error",e,r)}function C1(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(o){n.once&&t.removeEventListener(e,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var P1=oe((Iq,L1)=>{l();L1.exports=typeof queueMicrotask=="function"?queueMicrotask:t=>Promise.resolve().then(t)});var dd=oe(xg=>{"use strict";l();var M1=P1();xg.fromCallback=function(t,e){if(t===void 0){var r=new Promise(function(n,i){t=function(o,s){o?i(o):n(s)}});t[e!==void 0?e:"promise"]=r}else if(typeof t!="function")throw new TypeError("Callback must be a function");return t};xg.fromPromise=function(t,e){if(e===void 0)return t;t.then(function(r){M1(()=>e(null,r))}).catch(function(r){M1(()=>e(r))})}});var Yl=oe(Eg=>{"use strict";l();Eg.getCallback=function(t,e){return typeof t=="function"?t:e};Eg.getOptions=function(t,e){return typeof t=="object"&&t!==null?t:e!==void 0?e:{}}});var Ho=oe(Ql=>{"use strict";l();var{fromCallback:vg}=dd(),Nr=Sn(),{getOptions:Sg,getCallback:K1}=Yl(),Vs=Symbol("promise"),la=Symbol("callback"),Qn=Symbol("working"),qs=Symbol("handleOne"),Hi=Symbol("handleMany"),Ag=Symbol("autoClose"),Ko=Symbol("finishWork"),ei=Symbol("returnMany"),Lo=Symbol("closing"),fd=Symbol("handleClose"),Jl=Symbol("closed"),ld=Symbol("closeCallbacks"),Mo=Symbol("keyEncoding"),Fs=Symbol("valueEncoding"),Tg=Symbol("abortOnClose"),Xl=Symbol("legacy"),_g=Symbol("keys"),Ig=Symbol("values"),Po=Symbol("limit"),en=Symbol("count"),Zl=Object.freeze({}),lU=()=>{},$1=!1,hd=class{constructor(e,r,n){if(typeof e!="object"||e===null){let i=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof r!="object"||r===null)throw new TypeError("The second argument must be an options object");this[Jl]=!1,this[ld]=[],this[Qn]=!1,this[Lo]=!1,this[Ag]=!1,this[la]=null,this[qs]=this[qs].bind(this),this[Hi]=this[Hi].bind(this),this[fd]=this[fd].bind(this),this[Mo]=r[Mo],this[Fs]=r[Fs],this[Xl]=n,this[Po]=Number.isInteger(r.limit)&&r.limit>=0?r.limit:1/0,this[en]=0,this[Tg]=!!r.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[en]}get limit(){return this[Po]}next(e){let r;if(e===void 0)r=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[Xl]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof e!="function")throw new TypeError("Callback must be a function");return this[Lo]?this.nextTick(e,new Nr("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Qn]?this.nextTick(e,new Nr("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Qn]=!0,this[la]=e,this[en]>=this[Po]?this.nextTick(this[qs],null):this._next(this[qs])),r}_next(e){this.nextTick(e)}nextv(e,r,n){return n=K1(r,n),n=vg(n,Vs),r=Sg(r,Zl),Number.isInteger(e)?(this[Lo]?this.nextTick(n,new Nr("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Qn]?this.nextTick(n,new Nr("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[Po]<1/0&&(e=Math.min(e,this[Po]-this[en])),this[Qn]=!0,this[la]=n,e<=0?this.nextTick(this[Hi],null,[]):this._nextv(e,r,this[Hi])),n[Vs]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[Vs])}_nextv(e,r,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[Xl]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[Xl]?[c,a]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,r){return r=K1(e,r),r=vg(r,Vs),e=Sg(e,Zl),this[Lo]?this.nextTick(r,new Nr("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Qn]?this.nextTick(r,new Nr("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Qn]=!0,this[la]=r,this[Ag]=!0,this[en]>=this[Po]?this.nextTick(this[Hi],null,[]):this._all(e,this[Hi])),r[Vs]}_all(e,r){let n=this[en],i=[],o=()=>{let c=this[Po]<1/0?Math.min(1e3,this[Po]-n):1e3;c<=0?this.nextTick(r,null,i):this._nextv(c,Zl,s)},s=(c,a)=>{c?r(c):a.length===0?r(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[Ko](){let e=this[la];return this[Tg]&&e===null?lU:(this[Qn]=!1,this[la]=null,this[Lo]&&this._close(this[fd]),e)}[ei](e,r,n){this[Ag]?this.close(e.bind(null,r,n)):e(r,n)}seek(e,r){if(r=Sg(r,Zl),!this[Lo]){if(this[Qn])throw new Nr("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(r.keyEncoding||this[Mo]),i=n.format;r.keyEncoding!==i&&(r={...r,keyEncoding:i});let o=this.db.prefixKey(n.encode(e),i);this._seek(o,r)}}}_seek(e,r){throw new Nr("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=vg(e,Vs),this[Jl]?this.nextTick(e):this[Lo]?this[ld].push(e):(this[Lo]=!0,this[ld].push(e),this[Qn]?this[Tg]&&this[Ko]()(new Nr("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[fd])),e[Vs]}_close(e){this.nextTick(e)}[fd](){this[Jl]=!0,this.db.detachResource(this);let e=this[ld];this[ld]=[];for(let r of e)r()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Jl]||await this.close()}}},ha=class extends hd{constructor(e,r){super(e,r,!0),this[_g]=r.keys!==!1,this[Ig]=r.values!==!1}[qs](e,r,n){let i=this[Ko]();if(e)return i(e);try{r=this[_g]&&r!==void 0?this[Mo].decode(r):void 0,n=this[Ig]&&n!==void 0?this[Fs].decode(n):void 0}catch(o){return i(new $o("entry",o))}r===void 0&&n===void 0||this[en]++,i(null,r,n)}[Hi](e,r){let n=this[Ko]();if(e)return this[ei](n,e);try{for(let i of r){let o=i[0],s=i[1];i[0]=this[_g]&&o!==void 0?this[Mo].decode(o):void 0,i[1]=this[Ig]&&s!==void 0?this[Fs].decode(s):void 0}}catch(i){return this[ei](n,new $o("entries",i))}this[en]+=r.length,this[ei](n,null,r)}end(e){return!$1&&typeof console<"u"&&($1=!0,console.warn(new Nr("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(e)}},Bg=class extends hd{constructor(e,r){super(e,r,!1)}[qs](e,r){let n=this[Ko]();if(e)return n(e);try{r=r!==void 0?this[Mo].decode(r):void 0}catch(i){return n(new $o("key",i))}r!==void 0&&this[en]++,n(null,r)}[Hi](e,r){let n=this[Ko]();if(e)return this[ei](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[Mo].decode(o):void 0}}catch(i){return this[ei](n,new $o("keys",i))}this[en]+=r.length,this[ei](n,null,r)}},Rg=class extends hd{constructor(e,r){super(e,r,!1)}[qs](e,r){let n=this[Ko]();if(e)return n(e);try{r=r!==void 0?this[Fs].decode(r):void 0}catch(i){return n(new $o("value",i))}r!==void 0&&this[en]++,n(null,r)}[Hi](e,r){let n=this[Ko]();if(e)return this[ei](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[Fs].decode(o):void 0}}catch(i){return this[ei](n,new $o("values",i))}this[en]+=r.length,this[ei](n,null,r)}},$o=class extends Nr{constructor(e,r){super(`Iterator could not decode ${e}`,{code:"LEVEL_DECODE_ERROR",cause:r})}};for(let t of["_ended property","_nexting property","_end method"])Object.defineProperty(ha.prototype,t.split(" ")[0],{get(){throw new Nr(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Nr(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})}});ha.keyEncoding=Mo;ha.valueEncoding=Fs;Ql.AbstractIterator=ha;Ql.AbstractKeyIterator=Bg;Ql.AbstractValueIterator=Rg});var H1=oe(Ug=>{"use strict";l();var{AbstractKeyIterator:hU,AbstractValueIterator:pU}=Ho(),js=Symbol("iterator"),pd=Symbol("callback"),pa=Symbol("handleOne"),Ws=Symbol("handleMany"),yd=class extends hU{constructor(e,r){super(e,r),this[js]=e.iterator({...r,keys:!0,values:!1}),this[pa]=this[pa].bind(this),this[Ws]=this[Ws].bind(this)}},eh=class extends pU{constructor(e,r){super(e,r),this[js]=e.iterator({...r,keys:!1,values:!0}),this[pa]=this[pa].bind(this),this[Ws]=this[Ws].bind(this)}};for(let t of[yd,eh]){let e=t===yd,r=e?n=>n[0]:n=>n[1];t.prototype._next=function(n){this[pd]=n,this[js].next(this[pa])},t.prototype[pa]=function(n,i,o){let s=this[pd];n?s(n):s(null,e?i:o)},t.prototype._nextv=function(n,i,o){this[pd]=o,this[js].nextv(n,i,this[Ws])},t.prototype._all=function(n,i){this[pd]=i,this[js].all(n,this[Ws])},t.prototype[Ws]=function(n,i){let o=this[pd];n?o(n):o(null,i.map(r))},t.prototype._seek=function(n,i){this[js].seek(n,i)},t.prototype._close=function(n){this[js].close(n)}}Ug.DefaultKeyIterator=yd;Ug.DefaultValueIterator=eh});var V1=oe(sh=>{"use strict";l();var{AbstractIterator:yU,AbstractKeyIterator:gU,AbstractValueIterator:mU}=Ho(),Og=Sn(),yr=Symbol("nut"),ih=Symbol("undefer"),oh=Symbol("factory"),th=class extends yU{constructor(e,r){super(e,r),this[yr]=null,this[oh]=()=>e.iterator(r),this.db.defer(()=>this[ih]())}},rh=class extends gU{constructor(e,r){super(e,r),this[yr]=null,this[oh]=()=>e.keys(r),this.db.defer(()=>this[ih]())}},nh=class extends mU{constructor(e,r){super(e,r),this[yr]=null,this[oh]=()=>e.values(r),this.db.defer(()=>this[ih]())}};for(let t of[th,rh,nh])t.prototype[ih]=function(){this.db.status==="open"&&(this[yr]=this[oh]())},t.prototype._next=function(e){this[yr]!==null?this[yr].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new Og("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._nextv=function(e,r,n){this[yr]!==null?this[yr].nextv(e,r,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,r,n)):this.nextTick(n,new Og("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._all=function(e,r){this[yr]!==null?this[yr].all(r):this.db.status==="opening"?this.db.defer(()=>this._all(e,r)):this.nextTick(r,new Og("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._seek=function(e,r){this[yr]!==null?this[yr]._seek(e,r):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,r))},t.prototype._close=function(e){this[yr]!==null?this[yr].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};sh.DeferredIterator=th;sh.DeferredKeyIterator=rh;sh.DeferredValueIterator=nh});var kg=oe(F1=>{"use strict";l();var{fromCallback:q1}=dd(),ch=Sn(),{getCallback:wU,getOptions:bU}=Yl(),ah=Symbol("promise"),tn=Symbol("status"),ya=Symbol("operations"),gd=Symbol("finishClose"),ga=Symbol("closeCallbacks"),Dg=class{constructor(e){if(typeof e!="object"||e===null){let r=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${r}`)}this[ya]=[],this[ga]=[],this[tn]="open",this[gd]=this[gd].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[ya].length}put(e,r,n){if(this[tn]!=="open")throw new ch("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(e)||this.db._checkValue(r);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),a=o.valueEncoding(n&&n.valueEncoding),u=c.format;n={...n,keyEncoding:u,valueEncoding:a.format},o!==this.db&&(n.sublevel=null);let d=o.prefixKey(c.encode(e),u),f=a.encode(r);return this._put(d,f,n),this[ya].push({...s,type:"put",key:e,value:r}),this}_put(e,r,n){}del(e,r){if(this[tn]!=="open")throw new ch("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(e);if(n)throw n;let i=r&&r.sublevel!=null?r.sublevel:this.db,o=r,s=i.keyEncoding(r&&r.keyEncoding),c=s.format;return r={...r,keyEncoding:c},i!==this.db&&(r.sublevel=null),this._del(i.prefixKey(s.encode(e),c),r),this[ya].push({...o,type:"del",key:e}),this}_del(e,r){}clear(){if(this[tn]!=="open")throw new ch("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[ya]=[],this}_clear(){}write(e,r){return r=wU(e,r),r=q1(r,ah),e=bU(e),this[tn]!=="open"?this.nextTick(r,new ch("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(r):(this[tn]="writing",this._write(e,n=>{this[tn]="closing",this[ga].push(()=>r(n)),n||this.db.emit("batch",this[ya]),this._close(this[gd])})),r[ah]}_write(e,r){}close(e){return e=q1(e,ah),this[tn]==="closing"?this[ga].push(e):this[tn]==="closed"?this.nextTick(e):(this[ga].push(e),this[tn]!=="writing"&&(this[tn]="closing",this._close(this[gd]))),e[ah]}_close(e){this.nextTick(e)}[gd](){this[tn]="closed",this.db.detachResource(this);let e=this[ga];this[ga]=[];for(let r of e)r()}};F1.AbstractChainedBatch=Dg});var W1=oe(j1=>{"use strict";l();var{AbstractChainedBatch:xU}=kg(),EU=Sn(),ma=Symbol("encoded"),Ng=class extends xU{constructor(e){super(e),this[ma]=[]}_put(e,r,n){this[ma].push({...n,type:"put",key:e,value:r})}_del(e,r){this[ma].push({...r,type:"del",key:e})}_clear(){this[ma]=[]}_write(e,r){this.db.status==="opening"?this.db.defer(()=>this._write(e,r)):this.db.status==="open"?this[ma].length===0?this.nextTick(r):this.db._batch(this[ma],e,r):this.nextTick(r,new EU("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};j1.DefaultChainedBatch=Ng});var Y1=oe((qq,z1)=>{"use strict";l();var G1=Sn(),vU=Object.prototype.hasOwnProperty,SU=new Set(["lt","lte","gt","gte"]);z1.exports=function(t,e){let r={};for(let n in t)if(vU.call(t,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new G1(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new G1("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});SU.has(n)?r[n]=e.encode(t[n]):r[n]=t[n]}return r.reverse=!!r.reverse,r.limit=Number.isInteger(r.limit)&&r.limit>=0?r.limit:-1,r}});var Cg=oe((jq,X1)=>{l();var J1;X1.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):t=>(J1||(J1=Promise.resolve())).then(t).catch(e=>setTimeout(()=>{throw e},0))});var e2=oe((Gq,Q1)=>{"use strict";l();var Z1=Cg();Q1.exports=function(t,...e){e.length===0?Z1(t):Z1(()=>t(...e))}});var t2=oe(uh=>{"use strict";l();var{AbstractIterator:AU,AbstractKeyIterator:TU,AbstractValueIterator:_U}=Ho(),wa=Symbol("unfix"),An=Symbol("iterator"),Gs=Symbol("handleOne"),Vo=Symbol("handleMany"),Vi=Symbol("callback"),md=class extends AU{constructor(e,r,n,i){super(e,r),this[An]=n,this[wa]=i,this[Gs]=this[Gs].bind(this),this[Vo]=this[Vo].bind(this),this[Vi]=null}[Gs](e,r,n){let i=this[Vi];if(e)return i(e);r!==void 0&&(r=this[wa](r)),i(e,r,n)}[Vo](e,r){let n=this[Vi];if(e)return n(e);for(let i of r){let o=i[0];o!==void 0&&(i[0]=this[wa](o))}n(e,r)}},wd=class extends TU{constructor(e,r,n,i){super(e,r),this[An]=n,this[wa]=i,this[Gs]=this[Gs].bind(this),this[Vo]=this[Vo].bind(this),this[Vi]=null}[Gs](e,r){let n=this[Vi];if(e)return n(e);r!==void 0&&(r=this[wa](r)),n(e,r)}[Vo](e,r){let n=this[Vi];if(e)return n(e);for(let i=0;i<r.length;i++){let o=r[i];o!==void 0&&(r[i]=this[wa](o))}n(e,r)}},bd=class extends _U{constructor(e,r,n){super(e,r),this[An]=n}};for(let t of[md,wd])t.prototype._next=function(e){this[Vi]=e,this[An].next(this[Gs])},t.prototype._nextv=function(e,r,n){this[Vi]=n,this[An].nextv(e,r,this[Vo])},t.prototype._all=function(e,r){this[Vi]=r,this[An].all(e,this[Vo])};for(let t of[bd])t.prototype._next=function(e){this[An].next(e)},t.prototype._nextv=function(e,r,n){this[An].nextv(e,r,n)},t.prototype._all=function(e,r){this[An].all(e,r)};for(let t of[md,wd,bd])t.prototype._seek=function(e,r){this[An].seek(e,r)},t.prototype._close=function(e){this[An].close(e)};uh.AbstractSublevelIterator=md;uh.AbstractSublevelKeyIterator=wd;uh.AbstractSublevelValueIterator=bd});var o2=oe((Xq,i2)=>{"use strict";l();var Lg=Sn(),{Buffer:Kg}=_r()||{},{AbstractSublevelIterator:IU,AbstractSublevelKeyIterator:BU,AbstractSublevelValueIterator:RU}=t2(),qi=Symbol("prefix"),r2=Symbol("upperBound"),xd=Symbol("prefixRange"),Cr=Symbol("parent"),Pg=Symbol("unfix"),n2=new TextEncoder,UU={separator:"!"};i2.exports=function({AbstractLevel:t}){class e extends t{static defaults(n){if(typeof n=="string")throw new Lg("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new Lg("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?UU:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=e.defaults(o);i=DU(i,s);let u=s.charCodeAt(0)+1,d=n[Cr]||n;if(!n2.encode(i).every(p=>p>u&&p<127))throw new Lg(`Prefix must use bytes > ${u} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(OU(d,c),a);let f=(n.prefix||"")+s+i+s,h=f.slice(0,-1)+String.fromCharCode(u);this[Cr]=d,this[qi]=new dh(f),this[r2]=new dh(h),this[Pg]=new $g,this.nextTick=d.nextTick}prefixKey(n,i){if(i==="utf8")return this[qi].utf8+n;if(n.byteLength===0)return this[qi][i];if(i==="view"){let o=this[qi].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[qi].buffer;return Kg.concat([o,n],o.byteLength+n.byteLength)}}[xd](n,i){n.gte!==void 0?n.gte=this.prefixKey(n.gte,i):n.gt!==void 0?n.gt=this.prefixKey(n.gt,i):n.gte=this[qi][i],n.lte!==void 0?n.lte=this.prefixKey(n.lte,i):n.lt!==void 0?n.lt=this.prefixKey(n.lt,i):n.lte=this[r2][i]}get prefix(){return this[qi].utf8}get db(){return this[Cr]}_open(n,i){this[Cr].open({passive:!0},i)}_put(n,i,o,s){this[Cr].put(n,i,o,s)}_get(n,i,o){this[Cr].get(n,i,o)}_getMany(n,i,o){this[Cr].getMany(n,i,o)}_del(n,i,o){this[Cr].del(n,i,o)}_batch(n,i,o){this[Cr].batch(n,i,o)}_clear(n,i){this[xd](n,n.keyEncoding),this[Cr].clear(n,i)}_iterator(n){this[xd](n,n.keyEncoding);let i=this[Cr].iterator(n),o=this[Pg].get(this[qi].utf8.length,n.keyEncoding);return new IU(this,n,i,o)}_keys(n){this[xd](n,n.keyEncoding);let i=this[Cr].keys(n),o=this[Pg].get(this[qi].utf8.length,n.keyEncoding);return new BU(this,n,i,o)}_values(n){this[xd](n,n.keyEncoding);let i=this[Cr].values(n);return new RU(this,n,i)}}return{AbstractSublevel:e}};var OU=function(t,e){return{...t.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:Mg(t,"utf8"),buffer:Mg(t,"buffer"),view:Mg(t,"view")}}},Mg=function(t,e){return t.supports.encodings[e]?t.keyEncoding(e).name===e:!1},dh=class{constructor(e){this.utf8=e,this.view=n2.encode(e),this.buffer=Kg?Kg.from(this.view.buffer,0,this.view.byteLength):{}}},$g=class{constructor(){this.cache=new Map}get(e,r){let n=this.cache.get(r);return n===void 0&&(r==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,e):n=(function(i,o){return o.slice(i)}).bind(null,e),this.cache.set(r,n)),n}},DU=function(t,e){let r=0,n=t.length;for(;r<n&&t[r]===e;)r++;for(;n>r&&t[n-1]===e;)n--;return t.slice(r,n)}});var jg=oe(Fg=>{"use strict";l();var{supports:kU}=y1(),{Transcoder:NU}=T1(),{EventEmitter:CU}=fa(),{fromCallback:qo}=dd(),Tn=Sn(),{AbstractIterator:zs}=Ho(),{DefaultKeyIterator:LU,DefaultValueIterator:PU}=H1(),{DeferredIterator:MU,DeferredKeyIterator:KU,DeferredValueIterator:$U}=V1(),{DefaultChainedBatch:s2}=W1(),{getCallback:Ys,getOptions:Fo}=Yl(),fh=Y1(),ge=Symbol("promise"),Fi=Symbol("landed"),Js=Symbol("resources"),Hg=Symbol("closeResources"),Ed=Symbol("operations"),vd=Symbol("undefer"),lh=Symbol("deferOpen"),c2=Symbol("options"),Ee=Symbol("status"),Xs=Symbol("defaultOptions"),ba=Symbol("transcoder"),hh=Symbol("keyEncoding"),Vg=Symbol("valueEncoding"),HU=()=>{},Sd=class extends CU{constructor(e,r){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");r=Fo(r);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=r;this[Js]=new Set,this[Ed]=[],this[lh]=!0,this[c2]=s,this[Ee]="opening",this.supports=kU(e,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:e.snapshots!==!1,permanence:e.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:e.encodings||{},events:Object.assign({},e.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[ba]=new NU(VU(this)),this[hh]=this[ba].encoding(n||"utf8"),this[Vg]=this[ba].encoding(i||"utf8");for(let c of this[ba].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Xs]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[hh].commonName,valueEncoding:this[Vg].commonName}),key:Object.freeze({keyEncoding:this[hh].commonName})},this.nextTick(()=>{this[lh]&&this.open({passive:!1},HU)})}get status(){return this[Ee]}keyEncoding(e){return this[ba].encoding(e??this[hh])}valueEncoding(e){return this[ba].encoding(e??this[Vg])}open(e,r){r=Ys(e,r),r=qo(r,ge),e={...this[c2],...Fo(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[Ee]==="closing"||this[Ee]==="opening"?this.once(Fi,i?()=>n(i):n):this[Ee]!=="open"?r(new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):r()};return e.passive?this[Ee]==="opening"?this.once(Fi,n):this.nextTick(n):this[Ee]==="closed"||this[lh]?(this[lh]=!1,this[Ee]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[Ee]="closed",this[Hg](()=>{this.emit(Fi),n(i)}),this[vd]();return}this[Ee]="open",this[vd](),this.emit(Fi),this[Ee]==="open"&&this.emit("open"),this[Ee]==="open"&&this.emit("ready"),n()})):this[Ee]==="open"?this.nextTick(n):this.once(Fi,()=>this.open(e,r)),r[ge]}_open(e,r){this.nextTick(r)}close(e){e=qo(e,ge);let r=n=>{this[Ee]==="opening"||this[Ee]==="closing"?this.once(Fi,n?r(n):r):this[Ee]!=="closed"?e(new Tn("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[Ee]==="open"){this[Ee]="closing",this.emit("closing");let n=i=>{this[Ee]="open",this[vd](),this.emit(Fi),r(i)};this[Hg](()=>{this._close(i=>{if(i)return n(i);this[Ee]="closed",this[vd](),this.emit(Fi),this[Ee]==="closed"&&this.emit("closed"),r()})})}else this[Ee]==="closed"?this.nextTick(r):this.once(Fi,()=>this.close(e));return e[ge]}[Hg](e){if(this[Js].size===0)return this.nextTick(e);let r=this[Js].size,n=!0,i=()=>{--r===0&&(n?this.nextTick(e):e())};for(let o of this[Js])o.close(i);n=!1,this[Js].clear()}_close(e){this.nextTick(e)}get(e,r,n){if(n=Ys(r,n),n=qo(n,ge),r=Fo(r,this[Xs].entry),this[Ee]==="opening")return this.defer(()=>this.get(e,r,n)),n[ge];if(xa(this,n))return n[ge];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ge];let o=this.keyEncoding(r.keyEncoding),s=this.valueEncoding(r.valueEncoding),c=o.format,a=s.format;return(r.keyEncoding!==c||r.valueEncoding!==a)&&(r=Object.assign({},r,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(e),c),r,(u,d)=>{if(u)return(u.code==="LEVEL_NOT_FOUND"||u.notFound||/NotFound/i.test(u))&&(u.code||(u.code="LEVEL_NOT_FOUND"),u.notFound||(u.notFound=!0),u.status||(u.status=404)),n(u);try{d=s.decode(d)}catch(f){return n(new Tn("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:f}))}n(null,d)}),n[ge]}_get(e,r,n){this.nextTick(n,new Error("NotFound"))}getMany(e,r,n){if(n=Ys(r,n),n=qo(n,ge),r=Fo(r,this[Xs].entry),this[Ee]==="opening")return this.defer(()=>this.getMany(e,r,n)),n[ge];if(xa(this,n))return n[ge];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[ge];if(e.length===0)return this.nextTick(n,null,[]),n[ge];let i=this.keyEncoding(r.keyEncoding),o=this.valueEncoding(r.valueEncoding),s=i.format,c=o.format;(r.keyEncoding!==s||r.valueEncoding!==c)&&(r=Object.assign({},r,{keyEncoding:s,valueEncoding:c}));let a=new Array(e.length);for(let u=0;u<e.length;u++){let d=e[u],f=this._checkKey(d);if(f)return this.nextTick(n,f),n[ge];a[u]=this.prefixKey(i.encode(d),s)}return this._getMany(a,r,(u,d)=>{if(u)return n(u);try{for(let f=0;f<d.length;f++)d[f]!==void 0&&(d[f]=o.decode(d[f]))}catch(f){return n(new Tn(`Could not decode one or more of ${d.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:f}))}n(null,d)}),n[ge]}_getMany(e,r,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,r,n,i){if(i=Ys(n,i),i=qo(i,ge),n=Fo(n,this[Xs].entry),this[Ee]==="opening")return this.defer(()=>this.put(e,r,n,i)),i[ge];if(xa(this,i))return i[ge];let o=this._checkKey(e)||this._checkValue(r);if(o)return this.nextTick(i,o),i[ge];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),a=s.format,u=c.format;(n.keyEncoding!==a||n.valueEncoding!==u)&&(n=Object.assign({},n,{keyEncoding:a,valueEncoding:u}));let d=this.prefixKey(s.encode(e),a),f=c.encode(r);return this._put(d,f,n,h=>{if(h)return i(h);this.emit("put",e,r),i()}),i[ge]}_put(e,r,n,i){this.nextTick(i)}del(e,r,n){if(n=Ys(r,n),n=qo(n,ge),r=Fo(r,this[Xs].key),this[Ee]==="opening")return this.defer(()=>this.del(e,r,n)),n[ge];if(xa(this,n))return n[ge];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ge];let o=this.keyEncoding(r.keyEncoding),s=o.format;return r.keyEncoding!==s&&(r=Object.assign({},r,{keyEncoding:s})),this._del(this.prefixKey(o.encode(e),s),r,c=>{if(c)return n(c);this.emit("del",e),n()}),n[ge]}_del(e,r,n){this.nextTick(n)}batch(e,r,n){if(!arguments.length){if(this[Ee]==="opening")return new s2(this);if(this[Ee]!=="open")throw new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=Ys(r,n),n=qo(n,ge),r=Fo(r,this[Xs].empty),this[Ee]==="opening")return this.defer(()=>this.batch(e,r,n)),n[ge];if(xa(this,n))return n[ge];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[ge];if(e.length===0)return this.nextTick(n),n[ge];let i=new Array(e.length),{keyEncoding:o,valueEncoding:s,...c}=r;for(let a=0;a<e.length;a++){if(typeof e[a]!="object"||e[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[ge];let u=Object.assign({},e[a]);if(u.type!=="put"&&u.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[ge];let d=this._checkKey(u.key);if(d)return this.nextTick(n,d),n[ge];let f=u.sublevel!=null?u.sublevel:this,h=f.keyEncoding(u.keyEncoding||o),p=h.format;if(u.key=f.prefixKey(h.encode(u.key),p),u.keyEncoding=p,u.type==="put"){let g=this._checkValue(u.value);if(g)return this.nextTick(n,g),n[ge];let y=f.valueEncoding(u.valueEncoding||s);u.value=y.encode(u.value),u.valueEncoding=y.format}f!==this&&(u.sublevel=null),i[a]=u}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",e),n()}),n[ge]}_batch(e,r,n){this.nextTick(n)}sublevel(e,r){return this._sublevel(e,qg.defaults(r))}_sublevel(e,r){return new qg(this,e,r)}prefixKey(e,r){return e}clear(e,r){if(r=Ys(e,r),r=qo(r,ge),e=Fo(e,this[Xs].empty),this[Ee]==="opening")return this.defer(()=>this.clear(e,r)),r[ge];if(xa(this,r))return r[ge];let n=e,i=this.keyEncoding(e.keyEncoding);return e=fh(e,i),e.keyEncoding=i.format,e.limit===0?this.nextTick(r):this._clear(e,o=>{if(o)return r(o);this.emit("clear",n),r()}),r[ge]}_clear(e,r){this.nextTick(r)}iterator(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=fh(e,r),e.keys=e.keys!==!1,e.values=e.values!==!1,e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[Ee]==="opening")return new MU(this,e);if(this[Ee]!=="open")throw new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new zs(this,e)}keys(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=fh(e,r),e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[Ee]==="opening")return new KU(this,e);if(this[Ee]!=="open")throw new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new LU(this,e)}values(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=fh(e,r),e[zs.keyEncoding]=r,e[zs.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[Ee]==="opening")return new $U(this,e);if(this[Ee]!=="open")throw new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new PU(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[Ed].push(e)}[vd](){if(this[Ed].length===0)return;let e=this[Ed];this[Ed]=[];for(let r of e)r()}attachResource(e){if(typeof e!="object"||e===null||typeof e.close!="function")throw new TypeError("The first argument must be a resource object");this[Js].add(e)}detachResource(e){this[Js].delete(e)}_chainedBatch(){return new s2(this)}_checkKey(e){if(e==null)return new Tn("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new Tn("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Sd.prototype.nextTick=e2();var{AbstractSublevel:qg}=o2()({AbstractLevel:Sd});Fg.AbstractLevel=Sd;Fg.AbstractSublevel=qg;var xa=function(t,e){return t[Ee]!=="open"?(t.nextTick(e,new Tn("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},VU=function(t){return Object.keys(t.supports.encodings).filter(e=>!!t.supports.encodings[e])}});var Wg=oe(Zs=>{"use strict";l();Zs.AbstractLevel=jg().AbstractLevel;Zs.AbstractSublevel=jg().AbstractSublevel;Zs.AbstractIterator=Ho().AbstractIterator;Zs.AbstractKeyIterator=Ho().AbstractKeyIterator;Zs.AbstractValueIterator=Ho().AbstractValueIterator;Zs.AbstractChainedBatch=kg().AbstractChainedBatch});var u2=oe((nF,a2)=>{l();a2.exports=FU;var qU=Cg();function FU(t,e,r){if(typeof e!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,a=!0,u;Array.isArray(t)?(n=[],o=i=t.length):(s=Object.keys(t),n={},o=i=s.length);function d(h){function p(){r&&r(h,n),r=null}a?qU(p):p()}function f(h,p,g){if(n[h]=g,p&&(c=!0),--o===0||p)d(p);else if(!c&&u<i){let y;s?(y=s[u],u+=1,t[y](function(x,S){f(y,x,S)})):(y=u,u+=1,t[y](function(x,S){f(y,x,S)}))}}u=e,o?s?s.some(function(h,p){return t[h](function(g,y){f(h,g,y)}),p===e-1}):t.some(function(h,p){return h(function(g,y){f(p,g,y)}),p===e-1}):d(null),a=!1}});var Gg=oe((oF,d2)=>{"use strict";l();d2.exports=function(e){let r=e.gte!==void 0?e.gte:e.gt!==void 0?e.gt:void 0,n=e.lte!==void 0?e.lte:e.lt!==void 0?e.lt:void 0,i=e.gte===void 0,o=e.lte===void 0;return r!==void 0&&n!==void 0?IDBKeyRange.bound(r,n,i,o):r!==void 0?IDBKeyRange.lowerBound(r,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var zg=oe((cF,f2)=>{"use strict";l();var jU=new TextEncoder;f2.exports=function(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):jU.encode(t)}});var g2=oe(y2=>{"use strict";l();var{AbstractIterator:WU}=Wg(),l2=Gg(),ph=zg(),ti=Symbol("cache"),ji=Symbol("finished"),Lr=Symbol("options"),Wi=Symbol("currentOptions"),Qs=Symbol("position"),Yg=Symbol("location"),Ea=Symbol("first"),h2={},Jg=class extends WU{constructor(e,r,n){super(e,n),this[ti]=[],this[ji]=this.limit===0,this[Lr]=n,this[Wi]={...n},this[Qs]=void 0,this[Yg]=r,this[Ea]=!0}_nextv(e,r,n){if(this[Ea]=!1,this[ji])return this.nextTick(n,null,[]);if(this[ti].length>0)return e=Math.min(e,this[ti].length),this.nextTick(n,null,this[ti].splice(0,e));this[Qs]!==void 0&&(this[Lr].reverse?(this[Wi].lt=this[Qs],this[Wi].lte=void 0):(this[Wi].gt=this[Qs],this[Wi].gte=void 0));let i;try{i=l2(this[Wi])}catch{return this[ji]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Yg]],"readonly"),s=o.objectStore(this[Yg]),c=[];if(this[Lr].reverse){let a=!this[Lr].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=u=>{let d=u.target.result;if(d){let{key:f,value:h}=d;this[Qs]=f,c.push([this[Lr].keys&&f!==void 0?ph(f):void 0,this[Lr].values&&h!==void 0?ph(h):void 0]),c.length<e?d.continue():p2(o)}else this[ji]=!0}}else{let a,u,d=()=>{if(a===void 0||u===void 0)return;let f=Math.max(a.length,u.length);f===0||e===1/0?this[ji]=!0:this[Qs]=a[f-1],c.length=f;for(let h=0;h<f;h++){let p=a[h],g=u[h];c[h]=[this[Lr].keys&&p!==void 0?ph(p):void 0,this[Lr].values&&g!==void 0?ph(g):void 0]}p2(o)};this[Lr].keys||e<1/0?s.getAllKeys(i,e<1/0?e:void 0).onsuccess=f=>{a=f.target.result,d()}:(a=[],this.nextTick(d)),this[Lr].values?s.getAll(i,e<1/0?e:void 0).onsuccess=f=>{u=f.target.result,d()}:(u=[],this.nextTick(d))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(e){if(this[ti].length>0){let[r,n]=this[ti].shift();this.nextTick(e,null,r,n)}else if(this[ji])this.nextTick(e);else{let r=Math.min(100,this.limit-this.count);this[Ea]&&(this[Ea]=!1,r=1),this._nextv(r,h2,(n,i)=>{if(n)return e(n);this[ti]=i,this._next(e)})}}_all(e,r){this[Ea]=!1;let n=this[ti].splice(0,this[ti].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(r,null,n);this._nextv(i,h2,(o,s)=>{if(o)return r(o);n.length>0&&(s=n.concat(s)),r(null,s)})}_seek(e,r){this[Ea]=!0,this[ti]=[],this[ji]=!1,this[Qs]=void 0,this[Wi]={...this[Lr]};let n;try{n=l2(this[Lr])}catch{this[ji]=!0;return}n!==null&&!n.includes(e)?this[ji]=!0:this[Lr].reverse?this[Wi].lte=e:this[Wi].gte=e}};y2.Iterator=Jg;function p2(t){typeof t.commit=="function"&&t.commit()}});var w2=oe((fF,m2)=>{"use strict";l();m2.exports=function(e,r,n,i,o){if(i.limit===0)return e.nextTick(o);let s=e.db.transaction([r],"readwrite"),c=s.objectStore(r),a=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let u=c.openKeyCursor?"openKeyCursor":"openCursor",d=i.reverse?"prev":"next";c[u](n,d).onsuccess=function(f){let h=f.target.result;h&&(c.delete(h.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&h.continue()})}}});var A2=oe(S2=>{"use strict";l();var{AbstractLevel:GU}=Wg(),b2=Sn(),zU=u2(),{fromCallback:YU}=dd(),{Iterator:JU}=g2(),x2=zg(),XU=w2(),ZU=Gg(),v2="level-js-",Ad=Symbol("idb"),Xg=Symbol("namePrefix"),Gi=Symbol("location"),Zg=Symbol("version"),ec=Symbol("store"),Td=Symbol("onComplete"),E2=Symbol("promise"),yh=class extends GU{constructor(e,r,n){if(typeof r=="function"||typeof n=="function")throw new b2("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=r||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof e!="string")throw new Error("constructor requires a location string argument");this[Gi]=e,this[Xg]=i??v2,this[Zg]=parseInt(o||1,10),this[Ad]=null}get location(){return this[Gi]}get namePrefix(){return this[Xg]}get version(){return this[Zg]}get db(){return this[Ad]}get type(){return"browser-level"}_open(e,r){let n=indexedDB.open(this[Xg]+this[Gi],this[Zg]);n.onerror=function(){r(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[Ad]=n.result,r()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Gi])||o.createObjectStore(this[Gi])}}[ec](e){return this[Ad].transaction([this[Gi]],e).objectStore(this[Gi])}[Td](e,r){let n=e.transaction;n.onabort=function(){r(n.error||new Error("aborted by user"))},n.oncomplete=function(){r(null,e.result)}}_get(e,r,n){let i=this[ec]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Td](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new b2("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,x2(c))})}_getMany(e,r,n){let i=this[ec]("readonly"),o=e.map(s=>c=>{let a;try{a=i.get(s)}catch(u){return c(u)}a.onsuccess=()=>{let u=a.result;c(null,u===void 0?u:x2(u))},a.onerror=u=>{u.stopPropagation(),c(a.error)}});zU(o,16,n)}_del(e,r,n){let i=this[ec]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Td](o,n)}_put(e,r,n,i){let o=this[ec]("readwrite"),s;try{s=o.put(r,e)}catch(c){return this.nextTick(i,c)}this[Td](s,i)}_iterator(e){return new JU(this,this[Gi],e)}_batch(e,r,n){let i=this[ec]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let u=e[s++],d=u.key,f;try{f=u.type==="del"?i.delete(d):i.put(u.value,d)}catch(h){c=h,o.abort();return}s<e.length?f.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(e,r){let n,i;try{n=ZU(e)}catch{return this.nextTick(r)}if(e.limit>=0)return XU(this,this[Gi],n,e,r);try{let o=this[ec]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(r,o)}this[Td](i,r)}_close(e){this[Ad].close(),this.nextTick(e)}};yh.destroy=function(t,e,r){typeof e=="function"&&(r=e,e=v2),r=YU(r,E2);let n=indexedDB.deleteDatabase(e+t);return n.onsuccess=function(){r()},n.onerror=function(i){r(i)},r[E2]};S2.BrowserLevel=yh});var Qg=oe(T2=>{l();T2.Level=A2().BrowserLevel});var it=oe((vF,_2)=>{"use strict";l();_2.exports={ArrayIsArray(t){return Array.isArray(t)},ArrayPrototypeIncludes(t,e){return t.includes(e)},ArrayPrototypeIndexOf(t,e){return t.indexOf(e)},ArrayPrototypeJoin(t,e){return t.join(e)},ArrayPrototypeMap(t,e){return t.map(e)},ArrayPrototypePop(t,e){return t.pop(e)},ArrayPrototypePush(t,e){return t.push(e)},ArrayPrototypeSlice(t,e,r){return t.slice(e,r)},Error,FunctionPrototypeCall(t,e,...r){return t.call(e,...r)},FunctionPrototypeSymbolHasInstance(t,e){return Function.prototype[Symbol.hasInstance].call(t,e)},MathFloor:Math.floor,Number,NumberIsInteger:Number.isInteger,NumberIsNaN:Number.isNaN,NumberMAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,NumberMIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,NumberParseInt:Number.parseInt,ObjectDefineProperties(t,e){return Object.defineProperties(t,e)},ObjectDefineProperty(t,e,r){return Object.defineProperty(t,e,r)},ObjectGetOwnPropertyDescriptor(t,e){return Object.getOwnPropertyDescriptor(t,e)},ObjectKeys(t){return Object.keys(t)},ObjectSetPrototypeOf(t,e){return Object.setPrototypeOf(t,e)},Promise,PromisePrototypeCatch(t,e){return t.catch(e)},PromisePrototypeThen(t,e,r){return t.then(e,r)},PromiseReject(t){return Promise.reject(t)},PromiseResolve(t){return Promise.resolve(t)},ReflectApply:Reflect.apply,RegExpPrototypeTest(t,e){return t.test(e)},SafeSet:Set,String,StringPrototypeSlice(t,e,r){return t.slice(e,r)},StringPrototypeToLowerCase(t){return t.toLowerCase()},StringPrototypeToUpperCase(t){return t.toUpperCase()},StringPrototypeTrim(t){return t.trim()},Symbol,SymbolFor:Symbol.for,SymbolAsyncIterator:Symbol.asyncIterator,SymbolHasInstance:Symbol.hasInstance,SymbolIterator:Symbol.iterator,SymbolDispose:Symbol.dispose||Symbol("Symbol.dispose"),SymbolAsyncDispose:Symbol.asyncDispose||Symbol("Symbol.asyncDispose"),TypedArrayPrototypeSet(t,e,r){return t.set(e,r)},Boolean,Uint8Array}});var va=oe((AF,mh)=>{"use strict";l();var{AbortController:I2,AbortSignal:eO}=typeof self<"u"?self:typeof window<"u"?window:void 0;mh.exports=I2;mh.exports.AbortSignal=eO;mh.exports.default=I2});var Zt=oe((_F,tm)=>{"use strict";l();var tO=_r(),{kResistStopPropagation:rO,SymbolDispose:nO}=it(),iO=globalThis.AbortSignal||va().AbortSignal,oO=globalThis.AbortController||va().AbortController,sO=Object.getPrototypeOf(async function(){}).constructor,B2=globalThis.Blob||tO.Blob,cO=typeof B2<"u"?function(e){return e instanceof B2}:function(e){return!1},R2=(t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new ERR_INVALID_ARG_TYPE(e,"AbortSignal",t)},aO=(t,e)=>{if(typeof t!="function")throw new ERR_INVALID_ARG_TYPE(e,"Function",t)},em=class extends Error{constructor(e){if(!Array.isArray(e))throw new TypeError(`Expected input to be an Array, got ${typeof e}`);let r="";for(let n=0;n<e.length;n++)r+=` ${e[n].stack}
|
|
2
|
+
`;super(r),this.name="AggregateError",this.errors=e}};tm.exports={AggregateError:em,kEmptyObject:Object.freeze({}),once(t){let e=!1;return function(...r){e||(e=!0,t.apply(this,r))}},createDeferredPromise:function(){let t,e;return{promise:new Promise((n,i)=>{t=n,e=i}),resolve:t,reject:e}},promisify(t){return new Promise((e,r)=>{t((n,...i)=>n?r(n):e(...i))})},debuglog(){return function(){}},format(t,...e){return t.replace(/%([sdifj])/g,function(...[r,n]){let i=e.shift();return n==="f"?i.toFixed(6):n==="j"?JSON.stringify(i):n==="s"&&typeof i=="object"?`${i.constructor!==Object?i.constructor.name:""} {}`.trim():i.toString()})},inspect(t){switch(typeof t){case"string":if(t.includes("'"))if(t.includes('"')){if(!t.includes("`")&&!t.includes("${"))return`\`${t}\``}else return`"${t}"`;return`'${t}'`;case"number":return isNaN(t)?"NaN":Object.is(t,-0)?String(t):t;case"bigint":return`${String(t)}n`;case"boolean":case"undefined":return String(t);case"object":return"{}"}},types:{isAsyncFunction(t){return t instanceof sO},isArrayBufferView(t){return ArrayBuffer.isView(t)}},isBlob:cO,deprecate(t,e){return t},addAbortListener:fa().addAbortListener||function(e,r){if(e===void 0)throw new ERR_INVALID_ARG_TYPE("signal","AbortSignal",e);R2(e,"signal"),aO(r,"listener");let n;return e.aborted?queueMicrotask(()=>r()):(e.addEventListener("abort",r,{__proto__:null,once:!0,[rO]:!0}),n=()=>{e.removeEventListener("abort",r)}),{__proto__:null,[nO](){var i;(i=n)===null||i===void 0||i()}}},AbortSignalAny:iO.any||function(e){if(e.length===1)return e[0];let r=new oO,n=()=>r.abort();return e.forEach(i=>{R2(i,"signals"),i.addEventListener("abort",n,{once:!0})}),r.signal.addEventListener("abort",()=>{e.forEach(i=>i.removeEventListener("abort",n))},{once:!0}),r.signal}};tm.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")});var or=oe((BF,D2)=>{"use strict";l();var{format:uO,inspect:wh,AggregateError:dO}=Zt(),fO=globalThis.AggregateError||dO,lO=Symbol("kIsNodeError"),hO=["string","function","number","object","Function","Object","boolean","bigint","symbol"],pO=/^([A-Z][a-z0-9]*)+$/,yO="__node_internal_",bh={};function rc(t,e){if(!t)throw new bh.ERR_INTERNAL_ASSERTION(e)}function U2(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function gO(t,e,r){if(typeof e=="function")return rc(e.length<=r.length,`Code: ${t}; The provided arguments length (${r.length}) does not match the required ones (${e.length}).`),e(...r);let n=(e.match(/%[dfijoOs]/g)||[]).length;return rc(n===r.length,`Code: ${t}; The provided arguments length (${r.length}) does not match the required ones (${n}).`),r.length===0?e:uO(e,...r)}function Ht(t,e,r){r||(r=Error);class n extends r{constructor(...o){super(gO(t,e,o))}toString(){return`${this.name} [${t}]: ${this.message}`}}Object.defineProperties(n.prototype,{name:{value:r.name,writable:!0,enumerable:!1,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},writable:!0,enumerable:!1,configurable:!0}}),n.prototype.code=t,n.prototype[lO]=!0,bh[t]=n}function O2(t){let e=yO+t.name;return Object.defineProperty(t,"name",{value:e}),t}function mO(t,e){if(t&&e&&t!==e){if(Array.isArray(e.errors))return e.errors.push(t),e;let r=new fO([e,t],e.message);return r.code=e.code,r}return t||e}var rm=class extends Error{constructor(e="The operation was aborted",r=void 0){if(r!==void 0&&typeof r!="object")throw new bh.ERR_INVALID_ARG_TYPE("options","Object",r);super(e,r),this.code="ABORT_ERR",this.name="AbortError"}};Ht("ERR_ASSERTION","%s",Error);Ht("ERR_INVALID_ARG_TYPE",(t,e,r)=>{rc(typeof t=="string","'name' must be a string"),Array.isArray(e)||(e=[e]);let n="The ";t.endsWith(" argument")?n+=`${t} `:n+=`"${t}" ${t.includes(".")?"property":"argument"} `,n+="must be ";let i=[],o=[],s=[];for(let a of e)rc(typeof a=="string","All expected entries have to be of type string"),hO.includes(a)?i.push(a.toLowerCase()):pO.test(a)?o.push(a):(rc(a!=="object",'The value "object" should be written as "Object"'),s.push(a));if(o.length>0){let a=i.indexOf("object");a!==-1&&(i.splice(i,a,1),o.push("Object"))}if(i.length>0){switch(i.length){case 1:n+=`of type ${i[0]}`;break;case 2:n+=`one of type ${i[0]} or ${i[1]}`;break;default:{let a=i.pop();n+=`one of type ${i.join(", ")}, or ${a}`}}(o.length>0||s.length>0)&&(n+=" or ")}if(o.length>0){switch(o.length){case 1:n+=`an instance of ${o[0]}`;break;case 2:n+=`an instance of ${o[0]} or ${o[1]}`;break;default:{let a=o.pop();n+=`an instance of ${o.join(", ")}, or ${a}`}}s.length>0&&(n+=" or ")}switch(s.length){case 0:break;case 1:s[0].toLowerCase()!==s[0]&&(n+="an "),n+=`${s[0]}`;break;case 2:n+=`one of ${s[0]} or ${s[1]}`;break;default:{let a=s.pop();n+=`one of ${s.join(", ")}, or ${a}`}}if(r==null)n+=`. Received ${r}`;else if(typeof r=="function"&&r.name)n+=`. Received function ${r.name}`;else if(typeof r=="object"){var c;if((c=r.constructor)!==null&&c!==void 0&&c.name)n+=`. Received an instance of ${r.constructor.name}`;else{let a=wh(r,{depth:-1});n+=`. Received ${a}`}}else{let a=wh(r,{colors:!1});a.length>25&&(a=`${a.slice(0,25)}...`),n+=`. Received type ${typeof r} (${a})`}return n},TypeError);Ht("ERR_INVALID_ARG_VALUE",(t,e,r="is invalid")=>{let n=wh(e);return n.length>128&&(n=n.slice(0,128)+"..."),`The ${t.includes(".")?"property":"argument"} '${t}' ${r}. Received ${n}`},TypeError);Ht("ERR_INVALID_RETURN_VALUE",(t,e,r)=>{var n;let i=r!=null&&(n=r.constructor)!==null&&n!==void 0&&n.name?`instance of ${r.constructor.name}`:`type ${typeof r}`;return`Expected ${t} to be returned from the "${e}" function but got ${i}.`},TypeError);Ht("ERR_MISSING_ARGS",(...t)=>{rc(t.length>0,"At least one arg needs to be specified");let e,r=t.length;switch(t=(Array.isArray(t)?t:[t]).map(n=>`"${n}"`).join(" or "),r){case 1:e+=`The ${t[0]} argument`;break;case 2:e+=`The ${t[0]} and ${t[1]} arguments`;break;default:{let n=t.pop();e+=`The ${t.join(", ")}, and ${n} arguments`}break}return`${e} must be specified`},TypeError);Ht("ERR_OUT_OF_RANGE",(t,e,r)=>{rc(e,'Missing "range" argument');let n;return Number.isInteger(r)&&Math.abs(r)>2**32?n=U2(String(r)):typeof r=="bigint"?(n=String(r),(r>2n**32n||r<-(2n**32n))&&(n=U2(n)),n+="n"):n=wh(r),`The value of "${t}" is out of range. It must be ${e}. Received ${n}`},RangeError);Ht("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error);Ht("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error);Ht("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error);Ht("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error);Ht("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error);Ht("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);Ht("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error);Ht("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error);Ht("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error);Ht("ERR_STREAM_WRITE_AFTER_END","write after end",Error);Ht("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError);D2.exports={AbortError:rm,aggregateTwoErrors:O2(mO),hideStackFrames:O2,codes:bh}});var Aa=oe((UF,V2)=>{"use strict";l();var{ArrayIsArray:im,ArrayPrototypeIncludes:L2,ArrayPrototypeJoin:P2,ArrayPrototypeMap:wO,NumberIsInteger:om,NumberIsNaN:bO,NumberMAX_SAFE_INTEGER:xO,NumberMIN_SAFE_INTEGER:EO,NumberParseInt:vO,ObjectPrototypeHasOwnProperty:SO,RegExpPrototypeExec:M2,String:AO,StringPrototypeToUpperCase:TO,StringPrototypeTrim:_O}=it(),{hideStackFrames:rn,codes:{ERR_SOCKET_BAD_PORT:IO,ERR_INVALID_ARG_TYPE:Qt,ERR_INVALID_ARG_VALUE:Sa,ERR_OUT_OF_RANGE:nc,ERR_UNKNOWN_SIGNAL:k2}}=or(),{normalizeEncoding:BO}=Zt(),{isAsyncFunction:RO,isArrayBufferView:UO}=Zt().types,N2={};function OO(t){return t===(t|0)}function DO(t){return t===t>>>0}var kO=/^[0-7]+$/,NO="must be a 32-bit unsigned integer or an octal string";function CO(t,e,r){if(typeof t>"u"&&(t=r),typeof t=="string"){if(M2(kO,t)===null)throw new Sa(e,t,NO);t=vO(t,8)}return K2(t,e),t}var LO=rn((t,e,r=EO,n=xO)=>{if(typeof t!="number")throw new Qt(e,"number",t);if(!om(t))throw new nc(e,"an integer",t);if(t<r||t>n)throw new nc(e,`>= ${r} && <= ${n}`,t)}),PO=rn((t,e,r=-2147483648,n=2147483647)=>{if(typeof t!="number")throw new Qt(e,"number",t);if(!om(t))throw new nc(e,"an integer",t);if(t<r||t>n)throw new nc(e,`>= ${r} && <= ${n}`,t)}),K2=rn((t,e,r=!1)=>{if(typeof t!="number")throw new Qt(e,"number",t);if(!om(t))throw new nc(e,"an integer",t);let n=r?1:0,i=4294967295;if(t<n||t>i)throw new nc(e,`>= ${n} && <= ${i}`,t)});function sm(t,e){if(typeof t!="string")throw new Qt(e,"string",t)}function MO(t,e,r=void 0,n){if(typeof t!="number")throw new Qt(e,"number",t);if(r!=null&&t<r||n!=null&&t>n||(r!=null||n!=null)&&bO(t))throw new nc(e,`${r!=null?`>= ${r}`:""}${r!=null&&n!=null?" && ":""}${n!=null?`<= ${n}`:""}`,t)}var KO=rn((t,e,r)=>{if(!L2(r,t)){let i="must be one of: "+P2(wO(r,o=>typeof o=="string"?`'${o}'`:AO(o)),", ");throw new Sa(e,t,i)}});function $2(t,e){if(typeof t!="boolean")throw new Qt(e,"boolean",t)}function nm(t,e,r){return t==null||!SO(t,e)?r:t[e]}var $O=rn((t,e,r=null)=>{let n=nm(r,"allowArray",!1),i=nm(r,"allowFunction",!1);if(!nm(r,"nullable",!1)&&t===null||!n&&im(t)||typeof t!="object"&&(!i||typeof t!="function"))throw new Qt(e,"Object",t)}),HO=rn((t,e)=>{if(t!=null&&typeof t!="object"&&typeof t!="function")throw new Qt(e,"a dictionary",t)}),xh=rn((t,e,r=0)=>{if(!im(t))throw new Qt(e,"Array",t);if(t.length<r){let n=`must be longer than ${r}`;throw new Sa(e,t,n)}});function VO(t,e){xh(t,e);for(let r=0;r<t.length;r++)sm(t[r],`${e}[${r}]`)}function qO(t,e){xh(t,e);for(let r=0;r<t.length;r++)$2(t[r],`${e}[${r}]`)}function FO(t,e){xh(t,e);for(let r=0;r<t.length;r++){let n=t[r],i=`${e}[${r}]`;if(n==null)throw new Qt(i,"AbortSignal",n);H2(n,i)}}function jO(t,e="signal"){if(sm(t,e),N2[t]===void 0)throw N2[TO(t)]!==void 0?new k2(t+" (signals must use all capital letters)"):new k2(t)}var WO=rn((t,e="buffer")=>{if(!UO(t))throw new Qt(e,["Buffer","TypedArray","DataView"],t)});function GO(t,e){let r=BO(e),n=t.length;if(r==="hex"&&n%2!==0)throw new Sa("encoding",e,`is invalid for data of length ${n}`)}function zO(t,e="Port",r=!0){if(typeof t!="number"&&typeof t!="string"||typeof t=="string"&&_O(t).length===0||+t!==+t>>>0||t>65535||t===0&&!r)throw new IO(e,t,r);return t|0}var H2=rn((t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new Qt(e,"AbortSignal",t)}),YO=rn((t,e)=>{if(typeof t!="function")throw new Qt(e,"Function",t)}),JO=rn((t,e)=>{if(typeof t!="function"||RO(t))throw new Qt(e,"Function",t)}),XO=rn((t,e)=>{if(t!==void 0)throw new Qt(e,"undefined",t)});function ZO(t,e,r){if(!L2(r,t))throw new Qt(e,`('${P2(r,"|")}')`,t)}var QO=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function C2(t,e){if(typeof t>"u"||!M2(QO,t))throw new Sa(e,t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}function e5(t){if(typeof t=="string")return C2(t,"hints"),t;if(im(t)){let e=t.length,r="";if(e===0)return r;for(let n=0;n<e;n++){let i=t[n];C2(i,"hints"),r+=i,n!==e-1&&(r+=", ")}return r}throw new Sa("hints",t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}V2.exports={isInt32:OO,isUint32:DO,parseFileMode:CO,validateArray:xh,validateStringArray:VO,validateBooleanArray:qO,validateAbortSignalArray:FO,validateBoolean:$2,validateBuffer:WO,validateDictionary:HO,validateEncoding:GO,validateFunction:YO,validateInt32:PO,validateInteger:LO,validateNumber:MO,validateObject:$O,validateOneOf:KO,validatePlainFunction:JO,validatePort:zO,validateSignalName:jO,validateString:sm,validateUint32:K2,validateUndefined:XO,validateUnion:ZO,validateAbortSignal:H2,validateLinkHeaderValue:e5}});var ni=oe((DF,nS)=>{"use strict";l();var{SymbolAsyncIterator:q2,SymbolIterator:F2,SymbolFor:ic}=it(),j2=ic("nodejs.stream.destroyed"),W2=ic("nodejs.stream.errored"),cm=ic("nodejs.stream.readable"),am=ic("nodejs.stream.writable"),G2=ic("nodejs.stream.disturbed"),t5=ic("nodejs.webstream.isClosedPromise"),r5=ic("nodejs.webstream.controllerErrorFunction");function Eh(t,e=!1){var r;return!!(t&&typeof t.pipe=="function"&&typeof t.on=="function"&&(!e||typeof t.pause=="function"&&typeof t.resume=="function")&&(!t._writableState||((r=t._readableState)===null||r===void 0?void 0:r.readable)!==!1)&&(!t._writableState||t._readableState))}function vh(t){var e;return!!(t&&typeof t.write=="function"&&typeof t.on=="function"&&(!t._readableState||((e=t._writableState)===null||e===void 0?void 0:e.writable)!==!1))}function n5(t){return!!(t&&typeof t.pipe=="function"&&t._readableState&&typeof t.on=="function"&&typeof t.write=="function")}function ri(t){return t&&(t._readableState||t._writableState||typeof t.write=="function"&&typeof t.on=="function"||typeof t.pipe=="function"&&typeof t.on=="function")}function z2(t){return!!(t&&!ri(t)&&typeof t.pipeThrough=="function"&&typeof t.getReader=="function"&&typeof t.cancel=="function")}function Y2(t){return!!(t&&!ri(t)&&typeof t.getWriter=="function"&&typeof t.abort=="function")}function J2(t){return!!(t&&!ri(t)&&typeof t.readable=="object"&&typeof t.writable=="object")}function i5(t){return z2(t)||Y2(t)||J2(t)}function o5(t,e){return t==null?!1:e===!0?typeof t[q2]=="function":e===!1?typeof t[F2]=="function":typeof t[q2]=="function"||typeof t[F2]=="function"}function Sh(t){if(!ri(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!!(t.destroyed||t[j2]||n!=null&&n.destroyed)}function X2(t){if(!vh(t))return null;if(t.writableEnded===!0)return!0;let e=t._writableState;return e!=null&&e.errored?!1:typeof e?.ended!="boolean"?null:e.ended}function s5(t,e){if(!vh(t))return null;if(t.writableFinished===!0)return!0;let r=t._writableState;return r!=null&&r.errored?!1:typeof r?.finished!="boolean"?null:!!(r.finished||e===!1&&r.ended===!0&&r.length===0)}function c5(t){if(!Eh(t))return null;if(t.readableEnded===!0)return!0;let e=t._readableState;return!e||e.errored?!1:typeof e?.ended!="boolean"?null:e.ended}function Z2(t,e){if(!Eh(t))return null;let r=t._readableState;return r!=null&&r.errored?!1:typeof r?.endEmitted!="boolean"?null:!!(r.endEmitted||e===!1&&r.ended===!0&&r.length===0)}function Q2(t){return t&&t[cm]!=null?t[cm]:typeof t?.readable!="boolean"?null:Sh(t)?!1:Eh(t)&&t.readable&&!Z2(t)}function eS(t){return t&&t[am]!=null?t[am]:typeof t?.writable!="boolean"?null:Sh(t)?!1:vh(t)&&t.writable&&!X2(t)}function a5(t,e){return ri(t)?Sh(t)?!0:!(e?.readable!==!1&&Q2(t)||e?.writable!==!1&&eS(t)):null}function u5(t){var e,r;return ri(t)?t.writableErrored?t.writableErrored:(e=(r=t._writableState)===null||r===void 0?void 0:r.errored)!==null&&e!==void 0?e:null:null}function d5(t){var e,r;return ri(t)?t.readableErrored?t.readableErrored:(e=(r=t._readableState)===null||r===void 0?void 0:r.errored)!==null&&e!==void 0?e:null:null}function f5(t){if(!ri(t))return null;if(typeof t.closed=="boolean")return t.closed;let e=t._writableState,r=t._readableState;return typeof e?.closed=="boolean"||typeof r?.closed=="boolean"?e?.closed||r?.closed:typeof t._closed=="boolean"&&tS(t)?t._closed:null}function tS(t){return typeof t._closed=="boolean"&&typeof t._defaultKeepAlive=="boolean"&&typeof t._removedConnection=="boolean"&&typeof t._removedContLen=="boolean"}function rS(t){return typeof t._sent100=="boolean"&&tS(t)}function l5(t){var e;return typeof t._consuming=="boolean"&&typeof t._dumped=="boolean"&&((e=t.req)===null||e===void 0?void 0:e.upgradeOrConnect)===void 0}function h5(t){if(!ri(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!n&&rS(t)||!!(n&&n.autoDestroy&&n.emitClose&&n.closed===!1)}function p5(t){var e;return!!(t&&((e=t[G2])!==null&&e!==void 0?e:t.readableDidRead||t.readableAborted))}function y5(t){var e,r,n,i,o,s,c,a,u,d;return!!(t&&((e=(r=(n=(i=(o=(s=t[W2])!==null&&s!==void 0?s:t.readableErrored)!==null&&o!==void 0?o:t.writableErrored)!==null&&i!==void 0?i:(c=t._readableState)===null||c===void 0?void 0:c.errorEmitted)!==null&&n!==void 0?n:(a=t._writableState)===null||a===void 0?void 0:a.errorEmitted)!==null&&r!==void 0?r:(u=t._readableState)===null||u===void 0?void 0:u.errored)!==null&&e!==void 0?e:!((d=t._writableState)===null||d===void 0)&&d.errored))}nS.exports={isDestroyed:Sh,kIsDestroyed:j2,isDisturbed:p5,kIsDisturbed:G2,isErrored:y5,kIsErrored:W2,isReadable:Q2,kIsReadable:cm,kIsClosedPromise:t5,kControllerErrorFunction:r5,kIsWritable:am,isClosed:f5,isDuplexNodeStream:n5,isFinished:a5,isIterable:o5,isReadableNodeStream:Eh,isReadableStream:z2,isReadableEnded:c5,isReadableFinished:Z2,isReadableErrored:d5,isNodeStream:ri,isWebStream:i5,isWritable:eS,isWritableNodeStream:vh,isWritableStream:Y2,isWritableEnded:X2,isWritableFinished:s5,isWritableErrored:u5,isServerRequest:l5,isServerResponse:rS,willEmitClose:h5,isTransformStream:J2}});var zi=oe((NF,hm)=>{l();var jo=vi(),{AbortError:lS,codes:g5}=or(),{ERR_INVALID_ARG_TYPE:m5,ERR_STREAM_PREMATURE_CLOSE:iS}=g5,{kEmptyObject:dm,once:fm}=Zt(),{validateAbortSignal:w5,validateFunction:b5,validateObject:x5,validateBoolean:E5}=Aa(),{Promise:v5,PromisePrototypeThen:S5,SymbolDispose:hS}=it(),{isClosed:A5,isReadable:oS,isReadableNodeStream:um,isReadableStream:T5,isReadableFinished:sS,isReadableErrored:cS,isWritable:aS,isWritableNodeStream:uS,isWritableStream:_5,isWritableFinished:dS,isWritableErrored:fS,isNodeStream:I5,willEmitClose:B5,kIsClosedPromise:R5}=ni(),Ta;function U5(t){return t.setHeader&&typeof t.abort=="function"}var lm=()=>{};function pS(t,e,r){var n,i;if(arguments.length===2?(r=e,e=dm):e==null?e=dm:x5(e,"options"),b5(r,"callback"),w5(e.signal,"options.signal"),r=fm(r),T5(t)||_5(t))return O5(t,e,r);if(!I5(t))throw new m5("stream",["ReadableStream","WritableStream","Stream"],t);let o=(n=e.readable)!==null&&n!==void 0?n:um(t),s=(i=e.writable)!==null&&i!==void 0?i:uS(t),c=t._writableState,a=t._readableState,u=()=>{t.writable||h()},d=B5(t)&&um(t)===o&&uS(t)===s,f=dS(t,!1),h=()=>{f=!0,t.destroyed&&(d=!1),!(d&&(!t.readable||o))&&(!o||p)&&r.call(t)},p=sS(t,!1),g=()=>{p=!0,t.destroyed&&(d=!1),!(d&&(!t.writable||s))&&(!s||f)&&r.call(t)},y=T=>{r.call(t,T)},x=A5(t),S=()=>{x=!0;let T=fS(t)||cS(t);if(T&&typeof T!="boolean")return r.call(t,T);if(o&&!p&&um(t,!0)&&!sS(t,!1))return r.call(t,new iS);if(s&&!f&&!dS(t,!1))return r.call(t,new iS);r.call(t)},I=()=>{x=!0;let T=fS(t)||cS(t);if(T&&typeof T!="boolean")return r.call(t,T);r.call(t)},A=()=>{t.req.on("finish",h)};U5(t)?(t.on("complete",h),d||t.on("abort",S),t.req?A():t.on("request",A)):s&&!c&&(t.on("end",u),t.on("close",u)),!d&&typeof t.aborted=="boolean"&&t.on("aborted",S),t.on("end",g),t.on("finish",h),e.error!==!1&&t.on("error",y),t.on("close",S),x?jo.nextTick(S):c!=null&&c.errorEmitted||a!=null&&a.errorEmitted?d||jo.nextTick(I):(!o&&(!d||oS(t))&&(f||aS(t)===!1)||!s&&(!d||aS(t))&&(p||oS(t)===!1)||a&&t.req&&t.aborted)&&jo.nextTick(I);let O=()=>{r=lm,t.removeListener("aborted",S),t.removeListener("complete",h),t.removeListener("abort",S),t.removeListener("request",A),t.req&&t.req.removeListener("finish",h),t.removeListener("end",u),t.removeListener("close",u),t.removeListener("finish",h),t.removeListener("end",g),t.removeListener("error",y),t.removeListener("close",S)};if(e.signal&&!x){let T=()=>{let M=r;O(),M.call(t,new lS(void 0,{cause:e.signal.reason}))};if(e.signal.aborted)jo.nextTick(T);else{Ta=Ta||Zt().addAbortListener;let M=Ta(e.signal,T),q=r;r=fm((...j)=>{M[hS](),q.apply(t,j)})}}return O}function O5(t,e,r){let n=!1,i=lm;if(e.signal)if(i=()=>{n=!0,r.call(t,new lS(void 0,{cause:e.signal.reason}))},e.signal.aborted)jo.nextTick(i);else{Ta=Ta||Zt().addAbortListener;let s=Ta(e.signal,i),c=r;r=fm((...a)=>{s[hS](),c.apply(t,a)})}let o=(...s)=>{n||jo.nextTick(()=>r.apply(t,s))};return S5(t[R5].promise,o,o),lm}function D5(t,e){var r;let n=!1;return e===null&&(e=dm),(r=e)!==null&&r!==void 0&&r.cleanup&&(E5(e.cleanup,"cleanup"),n=e.cleanup),new v5((i,o)=>{let s=pS(t,e,c=>{n&&s(),c?o(c):i()})})}hm.exports=pS;hm.exports.finished=D5});var oc=oe((LF,vS)=>{"use strict";l();var ii=vi(),{aggregateTwoErrors:k5,codes:{ERR_MULTIPLE_CALLBACK:N5},AbortError:C5}=or(),{Symbol:mS}=it(),{kIsDestroyed:L5,isDestroyed:P5,isFinished:M5,isServerRequest:K5}=ni(),wS=mS("kDestroy"),pm=mS("kConstruct");function bS(t,e,r){t&&(t.stack,e&&!e.errored&&(e.errored=t),r&&!r.errored&&(r.errored=t))}function $5(t,e){let r=this._readableState,n=this._writableState,i=n||r;return n!=null&&n.destroyed||r!=null&&r.destroyed?(typeof e=="function"&&e(),this):(bS(t,n,r),n&&(n.destroyed=!0),r&&(r.destroyed=!0),i.constructed?yS(this,t,e):this.once(wS,function(o){yS(this,k5(o,t),e)}),this)}function yS(t,e,r){let n=!1;function i(o){if(n)return;n=!0;let s=t._readableState,c=t._writableState;bS(o,c,s),c&&(c.closed=!0),s&&(s.closed=!0),typeof r=="function"&&r(o),o?ii.nextTick(H5,t,o):ii.nextTick(xS,t)}try{t._destroy(e||null,i)}catch(o){i(o)}}function H5(t,e){ym(t,e),xS(t)}function xS(t){let e=t._readableState,r=t._writableState;r&&(r.closeEmitted=!0),e&&(e.closeEmitted=!0),(r!=null&&r.emitClose||e!=null&&e.emitClose)&&t.emit("close")}function ym(t,e){let r=t._readableState,n=t._writableState;n!=null&&n.errorEmitted||r!=null&&r.errorEmitted||(n&&(n.errorEmitted=!0),r&&(r.errorEmitted=!0),t.emit("error",e))}function V5(){let t=this._readableState,e=this._writableState;t&&(t.constructed=!0,t.closed=!1,t.closeEmitted=!1,t.destroyed=!1,t.errored=null,t.errorEmitted=!1,t.reading=!1,t.ended=t.readable===!1,t.endEmitted=t.readable===!1),e&&(e.constructed=!0,e.destroyed=!1,e.closed=!1,e.closeEmitted=!1,e.errored=null,e.errorEmitted=!1,e.finalCalled=!1,e.prefinished=!1,e.ended=e.writable===!1,e.ending=e.writable===!1,e.finished=e.writable===!1)}function gm(t,e,r){let n=t._readableState,i=t._writableState;if(i!=null&&i.destroyed||n!=null&&n.destroyed)return this;n!=null&&n.autoDestroy||i!=null&&i.autoDestroy?t.destroy(e):e&&(e.stack,i&&!i.errored&&(i.errored=e),n&&!n.errored&&(n.errored=e),r?ii.nextTick(ym,t,e):ym(t,e))}function q5(t,e){if(typeof t._construct!="function")return;let r=t._readableState,n=t._writableState;r&&(r.constructed=!1),n&&(n.constructed=!1),t.once(pm,e),!(t.listenerCount(pm)>1)&&ii.nextTick(F5,t)}function F5(t){let e=!1;function r(n){if(e){gm(t,n??new N5);return}e=!0;let i=t._readableState,o=t._writableState,s=o||i;i&&(i.constructed=!0),o&&(o.constructed=!0),s.destroyed?t.emit(wS,n):n?gm(t,n,!0):ii.nextTick(j5,t)}try{t._construct(n=>{ii.nextTick(r,n)})}catch(n){ii.nextTick(r,n)}}function j5(t){t.emit(pm)}function gS(t){return t?.setHeader&&typeof t.abort=="function"}function ES(t){t.emit("close")}function W5(t,e){t.emit("error",e),ii.nextTick(ES,t)}function G5(t,e){!t||P5(t)||(!e&&!M5(t)&&(e=new C5),K5(t)?(t.socket=null,t.destroy(e)):gS(t)?t.abort():gS(t.req)?t.req.abort():typeof t.destroy=="function"?t.destroy(e):typeof t.close=="function"?t.close():e?ii.nextTick(W5,t,e):ii.nextTick(ES,t),t.destroyed||(t[L5]=!0))}vS.exports={construct:q5,destroyer:G5,destroy:$5,undestroy:V5,errorOrDestroy:gm}});var _h=oe((MF,AS)=>{"use strict";l();var{ArrayIsArray:z5,ObjectSetPrototypeOf:SS}=it(),{EventEmitter:Ah}=fa();function Th(t){Ah.call(this,t)}SS(Th.prototype,Ah.prototype);SS(Th,Ah);Th.prototype.pipe=function(t,e){let r=this;function n(d){t.writable&&t.write(d)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}t.on("drain",i),!t._isStdio&&(!e||e.end!==!1)&&(r.on("end",s),r.on("close",c));let o=!1;function s(){o||(o=!0,t.end())}function c(){o||(o=!0,typeof t.destroy=="function"&&t.destroy())}function a(d){u(),Ah.listenerCount(this,"error")===0&&this.emit("error",d)}mm(r,"error",a),mm(t,"error",a);function u(){r.removeListener("data",n),t.removeListener("drain",i),r.removeListener("end",s),r.removeListener("close",c),r.removeListener("error",a),t.removeListener("error",a),r.removeListener("end",u),r.removeListener("close",u),t.removeListener("close",u)}return r.on("end",u),r.on("close",u),t.on("close",u),t.emit("pipe",r),t};function mm(t,e,r){if(typeof t.prependListener=="function")return t.prependListener(e,r);!t._events||!t._events[e]?t.on(e,r):z5(t._events[e])?t._events[e].unshift(r):t._events[e]=[r,t._events[e]]}AS.exports={Stream:Th,prependListener:mm}});var _d=oe(($F,Ih)=>{"use strict";l();var{SymbolDispose:Y5}=it(),{AbortError:TS,codes:J5}=or(),{isNodeStream:_S,isWebStream:X5,kControllerErrorFunction:Z5}=ni(),Q5=zi(),{ERR_INVALID_ARG_TYPE:IS}=J5,wm,e3=(t,e)=>{if(typeof t!="object"||!("aborted"in t))throw new IS(e,"AbortSignal",t)};Ih.exports.addAbortSignal=function(e,r){if(e3(e,"signal"),!_S(r)&&!X5(r))throw new IS("stream",["ReadableStream","WritableStream","Stream"],r);return Ih.exports.addAbortSignalNoValidate(e,r)};Ih.exports.addAbortSignalNoValidate=function(t,e){if(typeof t!="object"||!("aborted"in t))return e;let r=_S(e)?()=>{e.destroy(new TS(void 0,{cause:t.reason}))}:()=>{e[Z5](new TS(void 0,{cause:t.reason}))};if(t.aborted)r();else{wm=wm||Zt().addAbortListener;let n=wm(t,r);Q5(e,n[Y5])}return e}});var US=oe((qF,RS)=>{"use strict";l();var{StringPrototypeSlice:BS,SymbolIterator:t3,TypedArrayPrototypeSet:Bh,Uint8Array:r3}=it(),{Buffer:bm}=_r(),{inspect:n3}=Zt();RS.exports=class{constructor(){this.head=null,this.tail=null,this.length=0}push(e){let r={data:e,next:null};this.length>0?this.tail.next=r:this.head=r,this.tail=r,++this.length}unshift(e){let r={data:e,next:this.head};this.length===0&&(this.tail=r),this.head=r,++this.length}shift(){if(this.length===0)return;let e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}clear(){this.head=this.tail=null,this.length=0}join(e){if(this.length===0)return"";let r=this.head,n=""+r.data;for(;(r=r.next)!==null;)n+=e+r.data;return n}concat(e){if(this.length===0)return bm.alloc(0);let r=bm.allocUnsafe(e>>>0),n=this.head,i=0;for(;n;)Bh(r,n.data,i),i+=n.data.length,n=n.next;return r}consume(e,r){let n=this.head.data;if(e<n.length){let i=n.slice(0,e);return this.head.data=n.slice(e),i}return e===n.length?this.shift():r?this._getString(e):this._getBuffer(e)}first(){return this.head.data}*[t3](){for(let e=this.head;e;e=e.next)yield e.data}_getString(e){let r="",n=this.head,i=0;do{let o=n.data;if(e>o.length)r+=o,e-=o.length;else{e===o.length?(r+=o,++i,n.next?this.head=n.next:this.head=this.tail=null):(r+=BS(o,0,e),this.head=n,n.data=BS(o,e));break}++i}while((n=n.next)!==null);return this.length-=i,r}_getBuffer(e){let r=bm.allocUnsafe(e),n=e,i=this.head,o=0;do{let s=i.data;if(e>s.length)Bh(r,s,n-e),e-=s.length;else{e===s.length?(Bh(r,s,n-e),++o,i.next?this.head=i.next:this.head=this.tail=null):(Bh(r,new r3(s.buffer,s.byteOffset,e),n-e),this.head=i,i.data=s.slice(e));break}++o}while((i=i.next)!==null);return this.length-=o,r}[Symbol.for("nodejs.util.inspect.custom")](e,r){return n3(this,{...r,depth:0,customInspect:!1})}}});var Id=oe((jF,NS)=>{"use strict";l();var{MathFloor:i3,NumberIsInteger:o3}=it(),{validateInteger:s3}=Aa(),{ERR_INVALID_ARG_VALUE:c3}=or().codes,OS=16*1024,DS=16;function a3(t,e,r){return t.highWaterMark!=null?t.highWaterMark:e?t[r]:null}function kS(t){return t?DS:OS}function u3(t,e){s3(e,"value",0),t?DS=e:OS=e}function d3(t,e,r,n){let i=a3(e,n,r);if(i!=null){if(!o3(i)||i<0){let o=n?`options.${r}`:"options.highWaterMark";throw new c3(o,i)}return i3(i)}return kS(t.objectMode)}NS.exports={getHighWaterMark:d3,getDefaultHighWaterMark:kS,setDefaultHighWaterMark:u3}});var PS=oe((xm,LS)=>{l();var Rh=_r(),oi=Rh.Buffer;function CS(t,e){for(var r in t)e[r]=t[r]}oi.from&&oi.alloc&&oi.allocUnsafe&&oi.allocUnsafeSlow?LS.exports=Rh:(CS(Rh,xm),xm.Buffer=sc);function sc(t,e,r){return oi(t,e,r)}sc.prototype=Object.create(oi.prototype);CS(oi,sc);sc.from=function(t,e,r){if(typeof t=="number")throw new TypeError("Argument must not be a number");return oi(t,e,r)};sc.alloc=function(t,e,r){if(typeof t!="number")throw new TypeError("Argument must be a number");var n=oi(t);return e!==void 0?typeof r=="string"?n.fill(e,r):n.fill(e):n.fill(0),n};sc.allocUnsafe=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return oi(t)};sc.allocUnsafeSlow=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return Rh.SlowBuffer(t)}});var $S=oe(KS=>{"use strict";l();var vm=PS().Buffer,MS=vm.isEncoding||function(t){switch(t=""+t,t&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function f3(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}function l3(t){var e=f3(t);if(typeof e!="string"&&(vm.isEncoding===MS||!MS(t)))throw new Error("Unknown encoding: "+t);return e||t}KS.StringDecoder=Bd;function Bd(t){this.encoding=l3(t);var e;switch(this.encoding){case"utf16le":this.text=w3,this.end=b3,e=4;break;case"utf8":this.fillLast=y3,e=4;break;case"base64":this.text=x3,this.end=E3,e=3;break;default:this.write=v3,this.end=S3;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=vm.allocUnsafe(e)}Bd.prototype.write=function(t){if(t.length===0)return"";var e,r;if(this.lastNeed){if(e=this.fillLast(t),e===void 0)return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<t.length?e?e+this.text(t,r):this.text(t,r):e||""};Bd.prototype.end=m3;Bd.prototype.text=g3;Bd.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length};function Em(t){return t<=127?0:t>>5===6?2:t>>4===14?3:t>>3===30?4:t>>6===2?-1:-2}function h3(t,e,r){var n=e.length-1;if(n<r)return 0;var i=Em(e[n]);return i>=0?(i>0&&(t.lastNeed=i-1),i):--n<r||i===-2?0:(i=Em(e[n]),i>=0?(i>0&&(t.lastNeed=i-2),i):--n<r||i===-2?0:(i=Em(e[n]),i>=0?(i>0&&(i===2?i=0:t.lastNeed=i-3),i):0))}function p3(t,e,r){if((e[0]&192)!==128)return t.lastNeed=0,"\uFFFD";if(t.lastNeed>1&&e.length>1){if((e[1]&192)!==128)return t.lastNeed=1,"\uFFFD";if(t.lastNeed>2&&e.length>2&&(e[2]&192)!==128)return t.lastNeed=2,"\uFFFD"}}function y3(t){var e=this.lastTotal-this.lastNeed,r=p3(this,t,e);if(r!==void 0)return r;if(this.lastNeed<=t.length)return t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,e,0,t.length),this.lastNeed-=t.length}function g3(t,e){var r=h3(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=r;var n=t.length-(r-this.lastNeed);return t.copy(this.lastChar,0,n),t.toString("utf8",e,n)}function m3(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"\uFFFD":e}function w3(t,e){if((t.length-e)%2===0){var r=t.toString("utf16le",e);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function b3(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,r)}return e}function x3(t,e){var r=(t.length-e)%3;return r===0?t.toString("base64",e):(this.lastNeed=3-r,this.lastTotal=3,r===1?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-r))}function E3(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function v3(t){return t.toString(this.encoding)}function S3(t){return t&&t.length?this.write(t):""}});var Sm=oe((JF,FS)=>{"use strict";l();var HS=vi(),{PromisePrototypeThen:A3,SymbolAsyncIterator:VS,SymbolIterator:qS}=it(),{Buffer:T3}=_r(),{ERR_INVALID_ARG_TYPE:_3,ERR_STREAM_NULL_VALUES:I3}=or().codes;function B3(t,e,r){let n;if(typeof e=="string"||e instanceof T3)return new t({objectMode:!0,...r,read(){this.push(e),this.push(null)}});let i;if(e&&e[VS])i=!0,n=e[VS]();else if(e&&e[qS])i=!1,n=e[qS]();else throw new _3("iterable",["Iterable"],e);let o=new t({objectMode:!0,highWaterMark:1,...r}),s=!1;o._read=function(){s||(s=!0,a())},o._destroy=function(u,d){A3(c(u),()=>HS.nextTick(d,u),f=>HS.nextTick(d,f||u))};async function c(u){let d=u!=null,f=typeof n.throw=="function";if(d&&f){let{value:h,done:p}=await n.throw(u);if(await h,p)return}if(typeof n.return=="function"){let{value:h}=await n.return();await h}}async function a(){for(;;){try{let{value:u,done:d}=i?await n.next():n.next();if(d)o.push(null);else{let f=u&&typeof u.then=="function"?await u:u;if(f===null)throw s=!1,new I3;if(o.push(f))continue;s=!1}}catch(u){o.destroy(u)}break}}return o}FS.exports=B3});var Ud=oe((ZF,aA)=>{l();var _n=vi(),{ArrayPrototypeIndexOf:R3,NumberIsInteger:U3,NumberIsNaN:O3,NumberParseInt:D3,ObjectDefineProperties:Om,ObjectKeys:k3,ObjectSetPrototypeOf:GS,Promise:zS,SafeSet:N3,SymbolAsyncDispose:C3,SymbolAsyncIterator:L3,Symbol:P3}=it();aA.exports=me;me.ReadableState=kh;var{EventEmitter:M3}=fa(),{Stream:Wo,prependListener:K3}=_h(),{Buffer:Am}=_r(),{addAbortSignal:$3}=_d(),YS=zi(),Se=Zt().debuglog("stream",t=>{Se=t}),H3=US(),Ba=oc(),{getHighWaterMark:V3,getDefaultHighWaterMark:q3}=Id(),{aggregateTwoErrors:jS,codes:{ERR_INVALID_ARG_TYPE:F3,ERR_METHOD_NOT_IMPLEMENTED:j3,ERR_OUT_OF_RANGE:W3,ERR_STREAM_PUSH_AFTER_EOF:G3,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:z3},AbortError:Y3}=or(),{validateObject:J3}=Aa(),cc=P3("kPaused"),{StringDecoder:JS}=$S(),X3=Sm();GS(me.prototype,Wo.prototype);GS(me,Wo);var Tm=()=>{},{errorOrDestroy:_a}=Ba,Ia=1,Z3=2,XS=4,Rd=8,ZS=16,Uh=32,Oh=64,QS=128,Q3=256,eD=512,tD=1024,Rm=2048,Um=4096,rD=8192,nD=16384,iD=32768,eA=65536,oD=1<<17,sD=1<<18;function Tt(t){return{enumerable:!1,get(){return(this.state&t)!==0},set(e){e?this.state|=t:this.state&=~t}}}Om(kh.prototype,{objectMode:Tt(Ia),ended:Tt(Z3),endEmitted:Tt(XS),reading:Tt(Rd),constructed:Tt(ZS),sync:Tt(Uh),needReadable:Tt(Oh),emittedReadable:Tt(QS),readableListening:Tt(Q3),resumeScheduled:Tt(eD),errorEmitted:Tt(tD),emitClose:Tt(Rm),autoDestroy:Tt(Um),destroyed:Tt(rD),closed:Tt(nD),closeEmitted:Tt(iD),multiAwaitDrain:Tt(eA),readingMore:Tt(oD),dataEmitted:Tt(sD)});function kh(t,e,r){typeof r!="boolean"&&(r=e instanceof si()),this.state=Rm|Um|ZS|Uh,t&&t.objectMode&&(this.state|=Ia),r&&t&&t.readableObjectMode&&(this.state|=Ia),this.highWaterMark=t?V3(this,t,"readableHighWaterMark",r):q3(!1),this.buffer=new H3,this.length=0,this.pipes=[],this.flowing=null,this[cc]=null,t&&t.emitClose===!1&&(this.state&=~Rm),t&&t.autoDestroy===!1&&(this.state&=~Um),this.errored=null,this.defaultEncoding=t&&t.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,t&&t.encoding&&(this.decoder=new JS(t.encoding),this.encoding=t.encoding)}function me(t){if(!(this instanceof me))return new me(t);let e=this instanceof si();this._readableState=new kh(t,this,e),t&&(typeof t.read=="function"&&(this._read=t.read),typeof t.destroy=="function"&&(this._destroy=t.destroy),typeof t.construct=="function"&&(this._construct=t.construct),t.signal&&!e&&$3(t.signal,this)),Wo.call(this,t),Ba.construct(this,()=>{this._readableState.needReadable&&Dh(this,this._readableState)})}me.prototype.destroy=Ba.destroy;me.prototype._undestroy=Ba.undestroy;me.prototype._destroy=function(t,e){e(t)};me.prototype[M3.captureRejectionSymbol]=function(t){this.destroy(t)};me.prototype[C3]=function(){let t;return this.destroyed||(t=this.readableEnded?null:new Y3,this.destroy(t)),new zS((e,r)=>YS(this,n=>n&&n!==t?r(n):e(null)))};me.prototype.push=function(t,e){return tA(this,t,e,!1)};me.prototype.unshift=function(t,e){return tA(this,t,e,!0)};function tA(t,e,r,n){Se("readableAddChunk",e);let i=t._readableState,o;if(i.state&Ia||(typeof e=="string"?(r=r||i.defaultEncoding,i.encoding!==r&&(n&&i.encoding?e=Am.from(e,r).toString(i.encoding):(e=Am.from(e,r),r=""))):e instanceof Am?r="":Wo._isUint8Array(e)?(e=Wo._uint8ArrayToBuffer(e),r=""):e!=null&&(o=new F3("chunk",["string","Buffer","Uint8Array"],e))),o)_a(t,o);else if(e===null)i.state&=~Rd,uD(t,i);else if(i.state&Ia||e&&e.length>0)if(n)if(i.state&XS)_a(t,new z3);else{if(i.destroyed||i.errored)return!1;_m(t,i,e,!0)}else if(i.ended)_a(t,new G3);else{if(i.destroyed||i.errored)return!1;i.state&=~Rd,i.decoder&&!r?(e=i.decoder.write(e),i.objectMode||e.length!==0?_m(t,i,e,!1):Dh(t,i)):_m(t,i,e,!1)}else n||(i.state&=~Rd,Dh(t,i));return!i.ended&&(i.length<i.highWaterMark||i.length===0)}function _m(t,e,r,n){e.flowing&&e.length===0&&!e.sync&&t.listenerCount("data")>0?(e.state&eA?e.awaitDrainWriters.clear():e.awaitDrainWriters=null,e.dataEmitted=!0,t.emit("data",r)):(e.length+=e.objectMode?1:r.length,n?e.buffer.unshift(r):e.buffer.push(r),e.state&Oh&&Nh(t)),Dh(t,e)}me.prototype.isPaused=function(){let t=this._readableState;return t[cc]===!0||t.flowing===!1};me.prototype.setEncoding=function(t){let e=new JS(t);this._readableState.decoder=e,this._readableState.encoding=this._readableState.decoder.encoding;let r=this._readableState.buffer,n="";for(let i of r)n+=e.write(i);return r.clear(),n!==""&&r.push(n),this._readableState.length=n.length,this};var cD=1073741824;function aD(t){if(t>cD)throw new W3("size","<= 1GiB",t);return t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++,t}function WS(t,e){return t<=0||e.length===0&&e.ended?0:e.state&Ia?1:O3(t)?e.flowing&&e.length?e.buffer.first().length:e.length:t<=e.length?t:e.ended?e.length:0}me.prototype.read=function(t){Se("read",t),t===void 0?t=NaN:U3(t)||(t=D3(t,10));let e=this._readableState,r=t;if(t>e.highWaterMark&&(e.highWaterMark=aD(t)),t!==0&&(e.state&=~QS),t===0&&e.needReadable&&((e.highWaterMark!==0?e.length>=e.highWaterMark:e.length>0)||e.ended))return Se("read: emitReadable",e.length,e.ended),e.length===0&&e.ended?Im(this):Nh(this),null;if(t=WS(t,e),t===0&&e.ended)return e.length===0&&Im(this),null;let n=(e.state&Oh)!==0;if(Se("need readable",n),(e.length===0||e.length-t<e.highWaterMark)&&(n=!0,Se("length less than watermark",n)),e.ended||e.reading||e.destroyed||e.errored||!e.constructed)n=!1,Se("reading, ended or constructing",n);else if(n){Se("do read"),e.state|=Rd|Uh,e.length===0&&(e.state|=Oh);try{this._read(e.highWaterMark)}catch(o){_a(this,o)}e.state&=~Uh,e.reading||(t=WS(r,e))}let i;return t>0?i=sA(t,e):i=null,i===null?(e.needReadable=e.length<=e.highWaterMark,t=0):(e.length-=t,e.multiAwaitDrain?e.awaitDrainWriters.clear():e.awaitDrainWriters=null),e.length===0&&(e.ended||(e.needReadable=!0),r!==t&&e.ended&&Im(this)),i!==null&&!e.errorEmitted&&!e.closeEmitted&&(e.dataEmitted=!0,this.emit("data",i)),i};function uD(t,e){if(Se("onEofChunk"),!e.ended){if(e.decoder){let r=e.decoder.end();r&&r.length&&(e.buffer.push(r),e.length+=e.objectMode?1:r.length)}e.ended=!0,e.sync?Nh(t):(e.needReadable=!1,e.emittedReadable=!0,rA(t))}}function Nh(t){let e=t._readableState;Se("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(Se("emitReadable",e.flowing),e.emittedReadable=!0,_n.nextTick(rA,t))}function rA(t){let e=t._readableState;Se("emitReadable_",e.destroyed,e.length,e.ended),!e.destroyed&&!e.errored&&(e.length||e.ended)&&(t.emit("readable"),e.emittedReadable=!1),e.needReadable=!e.flowing&&!e.ended&&e.length<=e.highWaterMark,iA(t)}function Dh(t,e){!e.readingMore&&e.constructed&&(e.readingMore=!0,_n.nextTick(dD,t,e))}function dD(t,e){for(;!e.reading&&!e.ended&&(e.length<e.highWaterMark||e.flowing&&e.length===0);){let r=e.length;if(Se("maybeReadMore read 0"),t.read(0),r===e.length)break}e.readingMore=!1}me.prototype._read=function(t){throw new j3("_read()")};me.prototype.pipe=function(t,e){let r=this,n=this._readableState;n.pipes.length===1&&(n.multiAwaitDrain||(n.multiAwaitDrain=!0,n.awaitDrainWriters=new N3(n.awaitDrainWriters?[n.awaitDrainWriters]:[]))),n.pipes.push(t),Se("pipe count=%d opts=%j",n.pipes.length,e);let o=(!e||e.end!==!1)&&t!==_n.stdout&&t!==_n.stderr?c:x;n.endEmitted?_n.nextTick(o):r.once("end",o),t.on("unpipe",s);function s(S,I){Se("onunpipe"),S===r&&I&&I.hasUnpiped===!1&&(I.hasUnpiped=!0,d())}function c(){Se("onend"),t.end()}let a,u=!1;function d(){Se("cleanup"),t.removeListener("close",g),t.removeListener("finish",y),a&&t.removeListener("drain",a),t.removeListener("error",p),t.removeListener("unpipe",s),r.removeListener("end",c),r.removeListener("end",x),r.removeListener("data",h),u=!0,a&&n.awaitDrainWriters&&(!t._writableState||t._writableState.needDrain)&&a()}function f(){u||(n.pipes.length===1&&n.pipes[0]===t?(Se("false write response, pause",0),n.awaitDrainWriters=t,n.multiAwaitDrain=!1):n.pipes.length>1&&n.pipes.includes(t)&&(Se("false write response, pause",n.awaitDrainWriters.size),n.awaitDrainWriters.add(t)),r.pause()),a||(a=fD(r,t),t.on("drain",a))}r.on("data",h);function h(S){Se("ondata");let I=t.write(S);Se("dest.write",I),I===!1&&f()}function p(S){if(Se("onerror",S),x(),t.removeListener("error",p),t.listenerCount("error")===0){let I=t._writableState||t._readableState;I&&!I.errorEmitted?_a(t,S):t.emit("error",S)}}K3(t,"error",p);function g(){t.removeListener("finish",y),x()}t.once("close",g);function y(){Se("onfinish"),t.removeListener("close",g),x()}t.once("finish",y);function x(){Se("unpipe"),r.unpipe(t)}return t.emit("pipe",r),t.writableNeedDrain===!0?f():n.flowing||(Se("pipe resume"),r.resume()),t};function fD(t,e){return function(){let n=t._readableState;n.awaitDrainWriters===e?(Se("pipeOnDrain",1),n.awaitDrainWriters=null):n.multiAwaitDrain&&(Se("pipeOnDrain",n.awaitDrainWriters.size),n.awaitDrainWriters.delete(e)),(!n.awaitDrainWriters||n.awaitDrainWriters.size===0)&&t.listenerCount("data")&&t.resume()}}me.prototype.unpipe=function(t){let e=this._readableState,r={hasUnpiped:!1};if(e.pipes.length===0)return this;if(!t){let i=e.pipes;e.pipes=[],this.pause();for(let o=0;o<i.length;o++)i[o].emit("unpipe",this,{hasUnpiped:!1});return this}let n=R3(e.pipes,t);return n===-1?this:(e.pipes.splice(n,1),e.pipes.length===0&&this.pause(),t.emit("unpipe",this,r),this)};me.prototype.on=function(t,e){let r=Wo.prototype.on.call(this,t,e),n=this._readableState;return t==="data"?(n.readableListening=this.listenerCount("readable")>0,n.flowing!==!1&&this.resume()):t==="readable"&&!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.flowing=!1,n.emittedReadable=!1,Se("on readable",n.length,n.reading),n.length?Nh(this):n.reading||_n.nextTick(lD,this)),r};me.prototype.addListener=me.prototype.on;me.prototype.removeListener=function(t,e){let r=Wo.prototype.removeListener.call(this,t,e);return t==="readable"&&_n.nextTick(nA,this),r};me.prototype.off=me.prototype.removeListener;me.prototype.removeAllListeners=function(t){let e=Wo.prototype.removeAllListeners.apply(this,arguments);return(t==="readable"||t===void 0)&&_n.nextTick(nA,this),e};function nA(t){let e=t._readableState;e.readableListening=t.listenerCount("readable")>0,e.resumeScheduled&&e[cc]===!1?e.flowing=!0:t.listenerCount("data")>0?t.resume():e.readableListening||(e.flowing=null)}function lD(t){Se("readable nexttick read 0"),t.read(0)}me.prototype.resume=function(){let t=this._readableState;return t.flowing||(Se("resume"),t.flowing=!t.readableListening,hD(this,t)),t[cc]=!1,this};function hD(t,e){e.resumeScheduled||(e.resumeScheduled=!0,_n.nextTick(pD,t,e))}function pD(t,e){Se("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),iA(t),e.flowing&&!e.reading&&t.read(0)}me.prototype.pause=function(){return Se("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(Se("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState[cc]=!0,this};function iA(t){let e=t._readableState;for(Se("flow",e.flowing);e.flowing&&t.read()!==null;);}me.prototype.wrap=function(t){let e=!1;t.on("data",n=>{!this.push(n)&&t.pause&&(e=!0,t.pause())}),t.on("end",()=>{this.push(null)}),t.on("error",n=>{_a(this,n)}),t.on("close",()=>{this.destroy()}),t.on("destroy",()=>{this.destroy()}),this._read=()=>{e&&t.resume&&(e=!1,t.resume())};let r=k3(t);for(let n=1;n<r.length;n++){let i=r[n];this[i]===void 0&&typeof t[i]=="function"&&(this[i]=t[i].bind(t))}return this};me.prototype[L3]=function(){return oA(this)};me.prototype.iterator=function(t){return t!==void 0&&J3(t,"options"),oA(this,t)};function oA(t,e){typeof t.read!="function"&&(t=me.wrap(t,{objectMode:!0}));let r=yD(t,e);return r.stream=t,r}async function*yD(t,e){let r=Tm;function n(s){this===t?(r(),r=Tm):r=s}t.on("readable",n);let i,o=YS(t,{writable:!1},s=>{i=s?jS(i,s):null,r(),r=Tm});try{for(;;){let s=t.destroyed?null:t.read();if(s!==null)yield s;else{if(i)throw i;if(i===null)return;await new zS(n)}}}catch(s){throw i=jS(i,s),i}finally{(i||e?.destroyOnReturn!==!1)&&(i===void 0||t._readableState.autoDestroy)?Ba.destroyer(t,null):(t.off("readable",n),o())}}Om(me.prototype,{readable:{__proto__:null,get(){let t=this._readableState;return!!t&&t.readable!==!1&&!t.destroyed&&!t.errorEmitted&&!t.endEmitted},set(t){this._readableState&&(this._readableState.readable=!!t)}},readableDidRead:{__proto__:null,enumerable:!1,get:function(){return this._readableState.dataEmitted}},readableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._readableState.readable!==!1&&(this._readableState.destroyed||this._readableState.errored)&&!this._readableState.endEmitted)}},readableHighWaterMark:{__proto__:null,enumerable:!1,get:function(){return this._readableState.highWaterMark}},readableBuffer:{__proto__:null,enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}},readableFlowing:{__proto__:null,enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}},readableLength:{__proto__:null,enumerable:!1,get(){return this._readableState.length}},readableObjectMode:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.objectMode:!1}},readableEncoding:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.encoding:null}},errored:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.errored:null}},closed:{__proto__:null,get(){return this._readableState?this._readableState.closed:!1}},destroyed:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.destroyed:!1},set(t){this._readableState&&(this._readableState.destroyed=t)}},readableEnded:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.endEmitted:!1}}});Om(kh.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return this[cc]!==!1},set(t){this[cc]=!!t}}});me._fromList=sA;function sA(t,e){if(e.length===0)return null;let r;return e.objectMode?r=e.buffer.shift():!t||t>=e.length?(e.decoder?r=e.buffer.join(""):e.buffer.length===1?r=e.buffer.first():r=e.buffer.concat(e.length),e.buffer.clear()):r=e.buffer.consume(t,e.decoder),r}function Im(t){let e=t._readableState;Se("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,_n.nextTick(gD,e,t))}function gD(t,e){if(Se("endReadableNT",t.endEmitted,t.length),!t.errored&&!t.closeEmitted&&!t.endEmitted&&t.length===0){if(t.endEmitted=!0,e.emit("end"),e.writable&&e.allowHalfOpen===!1)_n.nextTick(mD,e);else if(t.autoDestroy){let r=e._writableState;(!r||r.autoDestroy&&(r.finished||r.writable===!1))&&e.destroy()}}}function mD(t){t.writable&&!t.writableEnded&&!t.destroyed&&t.end()}me.from=function(t,e){return X3(me,t,e)};var Bm;function cA(){return Bm===void 0&&(Bm={}),Bm}me.fromWeb=function(t,e){return cA().newStreamReadableFromReadableStream(t,e)};me.toWeb=function(t,e){return cA().newReadableStreamFromStreamReadable(t,e)};me.wrap=function(t,e){var r,n;return new me({objectMode:(r=(n=t.readableObjectMode)!==null&&n!==void 0?n:t.objectMode)!==null&&r!==void 0?r:!0,...e,destroy(i,o){Ba.destroyer(t,i),o(i)}}).wrap(t)}});var Kh=oe((ej,xA)=>{l();var ac=vi(),{ArrayPrototypeSlice:fA,Error:wD,FunctionPrototypeSymbolHasInstance:lA,ObjectDefineProperty:hA,ObjectDefineProperties:bD,ObjectSetPrototypeOf:pA,StringPrototypeToLowerCase:xD,Symbol:ED,SymbolHasInstance:vD}=it();xA.exports=ot;ot.WritableState=kd;var{EventEmitter:SD}=fa(),Od=_h().Stream,{Buffer:Ch}=_r(),Mh=oc(),{addAbortSignal:AD}=_d(),{getHighWaterMark:TD,getDefaultHighWaterMark:_D}=Id(),{ERR_INVALID_ARG_TYPE:ID,ERR_METHOD_NOT_IMPLEMENTED:BD,ERR_MULTIPLE_CALLBACK:yA,ERR_STREAM_CANNOT_PIPE:RD,ERR_STREAM_DESTROYED:Dd,ERR_STREAM_ALREADY_FINISHED:UD,ERR_STREAM_NULL_VALUES:OD,ERR_STREAM_WRITE_AFTER_END:DD,ERR_UNKNOWN_ENCODING:gA}=or().codes,{errorOrDestroy:Ra}=Mh;pA(ot.prototype,Od.prototype);pA(ot,Od);function Nm(){}var Ua=ED("kOnFinished");function kd(t,e,r){typeof r!="boolean"&&(r=e instanceof si()),this.objectMode=!!(t&&t.objectMode),r&&(this.objectMode=this.objectMode||!!(t&&t.writableObjectMode)),this.highWaterMark=t?TD(this,t,"writableHighWaterMark",r):_D(!1),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;let n=!!(t&&t.decodeStrings===!1);this.decodeStrings=!n,this.defaultEncoding=t&&t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=ND.bind(void 0,e),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,Ph(this),this.pendingcb=0,this.constructed=!0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!t||t.emitClose!==!1,this.autoDestroy=!t||t.autoDestroy!==!1,this.errored=null,this.closed=!1,this.closeEmitted=!1,this[Ua]=[]}function Ph(t){t.buffered=[],t.bufferedIndex=0,t.allBuffers=!0,t.allNoop=!0}kd.prototype.getBuffer=function(){return fA(this.buffered,this.bufferedIndex)};hA(kd.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}});function ot(t){let e=this instanceof si();if(!e&&!lA(ot,this))return new ot(t);this._writableState=new kd(t,this,e),t&&(typeof t.write=="function"&&(this._write=t.write),typeof t.writev=="function"&&(this._writev=t.writev),typeof t.destroy=="function"&&(this._destroy=t.destroy),typeof t.final=="function"&&(this._final=t.final),typeof t.construct=="function"&&(this._construct=t.construct),t.signal&&AD(t.signal,this)),Od.call(this,t),Mh.construct(this,()=>{let r=this._writableState;r.writing||Lm(this,r),Pm(this,r)})}hA(ot,vD,{__proto__:null,value:function(t){return lA(this,t)?!0:this!==ot?!1:t&&t._writableState instanceof kd}});ot.prototype.pipe=function(){Ra(this,new RD)};function mA(t,e,r,n){let i=t._writableState;if(typeof r=="function")n=r,r=i.defaultEncoding;else{if(!r)r=i.defaultEncoding;else if(r!=="buffer"&&!Ch.isEncoding(r))throw new gA(r);typeof n!="function"&&(n=Nm)}if(e===null)throw new OD;if(!i.objectMode)if(typeof e=="string")i.decodeStrings!==!1&&(e=Ch.from(e,r),r="buffer");else if(e instanceof Ch)r="buffer";else if(Od._isUint8Array(e))e=Od._uint8ArrayToBuffer(e),r="buffer";else throw new ID("chunk",["string","Buffer","Uint8Array"],e);let o;return i.ending?o=new DD:i.destroyed&&(o=new Dd("write")),o?(ac.nextTick(n,o),Ra(t,o,!0),o):(i.pendingcb++,kD(t,i,e,r,n))}ot.prototype.write=function(t,e,r){return mA(this,t,e,r)===!0};ot.prototype.cork=function(){this._writableState.corked++};ot.prototype.uncork=function(){let t=this._writableState;t.corked&&(t.corked--,t.writing||Lm(this,t))};ot.prototype.setDefaultEncoding=function(e){if(typeof e=="string"&&(e=xD(e)),!Ch.isEncoding(e))throw new gA(e);return this._writableState.defaultEncoding=e,this};function kD(t,e,r,n,i){let o=e.objectMode?1:r.length;e.length+=o;let s=e.length<e.highWaterMark;return s||(e.needDrain=!0),e.writing||e.corked||e.errored||!e.constructed?(e.buffered.push({chunk:r,encoding:n,callback:i}),e.allBuffers&&n!=="buffer"&&(e.allBuffers=!1),e.allNoop&&i!==Nm&&(e.allNoop=!1)):(e.writelen=o,e.writecb=i,e.writing=!0,e.sync=!0,t._write(r,n,e.onwrite),e.sync=!1),s&&!e.errored&&!e.destroyed}function uA(t,e,r,n,i,o,s){e.writelen=n,e.writecb=s,e.writing=!0,e.sync=!0,e.destroyed?e.onwrite(new Dd("write")):r?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function dA(t,e,r,n){--e.pendingcb,n(r),Cm(e),Ra(t,r)}function ND(t,e){let r=t._writableState,n=r.sync,i=r.writecb;if(typeof i!="function"){Ra(t,new yA);return}r.writing=!1,r.writecb=null,r.length-=r.writelen,r.writelen=0,e?(e.stack,r.errored||(r.errored=e),t._readableState&&!t._readableState.errored&&(t._readableState.errored=e),n?ac.nextTick(dA,t,r,e,i):dA(t,r,e,i)):(r.buffered.length>r.bufferedIndex&&Lm(t,r),n?r.afterWriteTickInfo!==null&&r.afterWriteTickInfo.cb===i?r.afterWriteTickInfo.count++:(r.afterWriteTickInfo={count:1,cb:i,stream:t,state:r},ac.nextTick(CD,r.afterWriteTickInfo)):wA(t,r,1,i))}function CD({stream:t,state:e,count:r,cb:n}){return e.afterWriteTickInfo=null,wA(t,e,r,n)}function wA(t,e,r,n){for(!e.ending&&!t.destroyed&&e.length===0&&e.needDrain&&(e.needDrain=!1,t.emit("drain"));r-- >0;)e.pendingcb--,n();e.destroyed&&Cm(e),Pm(t,e)}function Cm(t){if(t.writing)return;for(let i=t.bufferedIndex;i<t.buffered.length;++i){var e;let{chunk:o,callback:s}=t.buffered[i],c=t.objectMode?1:o.length;t.length-=c,s((e=t.errored)!==null&&e!==void 0?e:new Dd("write"))}let r=t[Ua].splice(0);for(let i=0;i<r.length;i++){var n;r[i]((n=t.errored)!==null&&n!==void 0?n:new Dd("end"))}Ph(t)}function Lm(t,e){if(e.corked||e.bufferProcessing||e.destroyed||!e.constructed)return;let{buffered:r,bufferedIndex:n,objectMode:i}=e,o=r.length-n;if(!o)return;let s=n;if(e.bufferProcessing=!0,o>1&&t._writev){e.pendingcb-=o-1;let c=e.allNoop?Nm:u=>{for(let d=s;d<r.length;++d)r[d].callback(u)},a=e.allNoop&&s===0?r:fA(r,s);a.allBuffers=e.allBuffers,uA(t,e,!0,e.length,a,"",c),Ph(e)}else{do{let{chunk:c,encoding:a,callback:u}=r[s];r[s++]=null;let d=i?1:c.length;uA(t,e,!1,d,c,a,u)}while(s<r.length&&!e.writing);s===r.length?Ph(e):s>256?(r.splice(0,s),e.bufferedIndex=0):e.bufferedIndex=s}e.bufferProcessing=!1}ot.prototype._write=function(t,e,r){if(this._writev)this._writev([{chunk:t,encoding:e}],r);else throw new BD("_write()")};ot.prototype._writev=null;ot.prototype.end=function(t,e,r){let n=this._writableState;typeof t=="function"?(r=t,t=null,e=null):typeof e=="function"&&(r=e,e=null);let i;if(t!=null){let o=mA(this,t,e);o instanceof wD&&(i=o)}return n.corked&&(n.corked=1,this.uncork()),i||(!n.errored&&!n.ending?(n.ending=!0,Pm(this,n,!0),n.ended=!0):n.finished?i=new UD("end"):n.destroyed&&(i=new Dd("end"))),typeof r=="function"&&(i||n.finished?ac.nextTick(r,i):n[Ua].push(r)),this};function Lh(t){return t.ending&&!t.destroyed&&t.constructed&&t.length===0&&!t.errored&&t.buffered.length===0&&!t.finished&&!t.writing&&!t.errorEmitted&&!t.closeEmitted}function LD(t,e){let r=!1;function n(i){if(r){Ra(t,i??yA());return}if(r=!0,e.pendingcb--,i){let o=e[Ua].splice(0);for(let s=0;s<o.length;s++)o[s](i);Ra(t,i,e.sync)}else Lh(e)&&(e.prefinished=!0,t.emit("prefinish"),e.pendingcb++,ac.nextTick(km,t,e))}e.sync=!0,e.pendingcb++;try{t._final(n)}catch(i){n(i)}e.sync=!1}function PD(t,e){!e.prefinished&&!e.finalCalled&&(typeof t._final=="function"&&!e.destroyed?(e.finalCalled=!0,LD(t,e)):(e.prefinished=!0,t.emit("prefinish")))}function Pm(t,e,r){Lh(e)&&(PD(t,e),e.pendingcb===0&&(r?(e.pendingcb++,ac.nextTick((n,i)=>{Lh(i)?km(n,i):i.pendingcb--},t,e)):Lh(e)&&(e.pendingcb++,km(t,e))))}function km(t,e){e.pendingcb--,e.finished=!0;let r=e[Ua].splice(0);for(let n=0;n<r.length;n++)r[n]();if(t.emit("finish"),e.autoDestroy){let n=t._readableState;(!n||n.autoDestroy&&(n.endEmitted||n.readable===!1))&&t.destroy()}}bD(ot.prototype,{closed:{__proto__:null,get(){return this._writableState?this._writableState.closed:!1}},destroyed:{__proto__:null,get(){return this._writableState?this._writableState.destroyed:!1},set(t){this._writableState&&(this._writableState.destroyed=t)}},writable:{__proto__:null,get(){let t=this._writableState;return!!t&&t.writable!==!1&&!t.destroyed&&!t.errored&&!t.ending&&!t.ended},set(t){this._writableState&&(this._writableState.writable=!!t)}},writableFinished:{__proto__:null,get(){return this._writableState?this._writableState.finished:!1}},writableObjectMode:{__proto__:null,get(){return this._writableState?this._writableState.objectMode:!1}},writableBuffer:{__proto__:null,get(){return this._writableState&&this._writableState.getBuffer()}},writableEnded:{__proto__:null,get(){return this._writableState?this._writableState.ending:!1}},writableNeedDrain:{__proto__:null,get(){let t=this._writableState;return t?!t.destroyed&&!t.ending&&t.needDrain:!1}},writableHighWaterMark:{__proto__:null,get(){return this._writableState&&this._writableState.highWaterMark}},writableCorked:{__proto__:null,get(){return this._writableState?this._writableState.corked:0}},writableLength:{__proto__:null,get(){return this._writableState&&this._writableState.length}},errored:{__proto__:null,enumerable:!1,get(){return this._writableState?this._writableState.errored:null}},writableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._writableState.writable!==!1&&(this._writableState.destroyed||this._writableState.errored)&&!this._writableState.finished)}}});var MD=Mh.destroy;ot.prototype.destroy=function(t,e){let r=this._writableState;return!r.destroyed&&(r.bufferedIndex<r.buffered.length||r[Ua].length)&&ac.nextTick(Cm,r),MD.call(this,t,e),this};ot.prototype._undestroy=Mh.undestroy;ot.prototype._destroy=function(t,e){e(t)};ot.prototype[SD.captureRejectionSymbol]=function(t){this.destroy(t)};var Dm;function bA(){return Dm===void 0&&(Dm={}),Dm}ot.fromWeb=function(t,e){return bA().newStreamWritableFromWritableStream(t,e)};ot.toWeb=function(t){return bA().newWritableStreamFromStreamWritable(t)}});var CA=oe((rj,NA)=>{l();var Mm=vi(),KD=_r(),{isReadable:$D,isWritable:HD,isIterable:EA,isNodeStream:VD,isReadableNodeStream:vA,isWritableNodeStream:SA,isDuplexNodeStream:qD,isReadableStream:AA,isWritableStream:TA}=ni(),_A=zi(),{AbortError:DA,codes:{ERR_INVALID_ARG_TYPE:FD,ERR_INVALID_RETURN_VALUE:IA}}=or(),{destroyer:Da}=oc(),jD=si(),kA=Ud(),WD=Kh(),{createDeferredPromise:BA}=Zt(),RA=Sm(),UA=globalThis.Blob||KD.Blob,GD=typeof UA<"u"?function(e){return e instanceof UA}:function(e){return!1},zD=globalThis.AbortController||va().AbortController,{FunctionPrototypeCall:OA}=it(),Go=class extends jD{constructor(e){super(e),e?.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),e?.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)}};NA.exports=function t(e,r){if(qD(e))return e;if(vA(e))return Oa({readable:e});if(SA(e))return Oa({writable:e});if(VD(e))return Oa({writable:!1,readable:!1});if(AA(e))return Oa({readable:kA.fromWeb(e)});if(TA(e))return Oa({writable:WD.fromWeb(e)});if(typeof e=="function"){let{value:i,write:o,final:s,destroy:c}=YD(e);if(EA(i))return RA(Go,i,{objectMode:!0,write:o,final:s,destroy:c});let a=i?.then;if(typeof a=="function"){let u,d=OA(a,i,f=>{if(f!=null)throw new IA("nully","body",f)},f=>{Da(u,f)});return u=new Go({objectMode:!0,readable:!1,write:o,final(f){s(async()=>{try{await d,Mm.nextTick(f,null)}catch(h){Mm.nextTick(f,h)}})},destroy:c})}throw new IA("Iterable, AsyncIterable or AsyncFunction",r,i)}if(GD(e))return t(e.arrayBuffer());if(EA(e))return RA(Go,e,{objectMode:!0,writable:!1});if(AA(e?.readable)&&TA(e?.writable))return Go.fromWeb(e);if(typeof e?.writable=="object"||typeof e?.readable=="object"){let i=e!=null&&e.readable?vA(e?.readable)?e?.readable:t(e.readable):void 0,o=e!=null&&e.writable?SA(e?.writable)?e?.writable:t(e.writable):void 0;return Oa({readable:i,writable:o})}let n=e?.then;if(typeof n=="function"){let i;return OA(n,e,o=>{o!=null&&i.push(o),i.push(null)},o=>{Da(i,o)}),i=new Go({objectMode:!0,writable:!1,read(){}})}throw new FD(r,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],e)};function YD(t){let{promise:e,resolve:r}=BA(),n=new zD,i=n.signal;return{value:t(async function*(){for(;;){let s=e;e=null;let{chunk:c,done:a,cb:u}=await s;if(Mm.nextTick(u),a)return;if(i.aborted)throw new DA(void 0,{cause:i.reason});({promise:e,resolve:r}=BA()),yield c}}(),{signal:i}),write(s,c,a){let u=r;r=null,u({chunk:s,done:!1,cb:a})},final(s){let c=r;r=null,c({done:!0,cb:s})},destroy(s,c){n.abort(),c(s)}}}function Oa(t){let e=t.readable&&typeof t.readable.read!="function"?kA.wrap(t.readable):t.readable,r=t.writable,n=!!$D(e),i=!!HD(r),o,s,c,a,u;function d(f){let h=a;a=null,h?h(f):f&&u.destroy(f)}return u=new Go({readableObjectMode:!!(e!=null&&e.readableObjectMode),writableObjectMode:!!(r!=null&&r.writableObjectMode),readable:n,writable:i}),i&&(_A(r,f=>{i=!1,f&&Da(e,f),d(f)}),u._write=function(f,h,p){r.write(f,h)?p():o=p},u._final=function(f){r.end(),s=f},r.on("drain",function(){if(o){let f=o;o=null,f()}}),r.on("finish",function(){if(s){let f=s;s=null,f()}})),n&&(_A(e,f=>{n=!1,f&&Da(e,f),d(f)}),e.on("readable",function(){if(c){let f=c;c=null,f()}}),e.on("end",function(){u.push(null)}),u._read=function(){for(;;){let f=e.read();if(f===null){c=u._read;return}if(!u.push(f))return}}),u._destroy=function(f,h){!f&&a!==null&&(f=new DA),c=null,o=null,s=null,a===null?h(f):(a=h,Da(r,f),Da(e,f))},u}});var si=oe((ij,MA)=>{"use strict";l();var{ObjectDefineProperties:JD,ObjectGetOwnPropertyDescriptor:Yi,ObjectKeys:XD,ObjectSetPrototypeOf:LA}=it();MA.exports=In;var Hm=Ud(),nn=Kh();LA(In.prototype,Hm.prototype);LA(In,Hm);{let t=XD(nn.prototype);for(let e=0;e<t.length;e++){let r=t[e];In.prototype[r]||(In.prototype[r]=nn.prototype[r])}}function In(t){if(!(this instanceof In))return new In(t);Hm.call(this,t),nn.call(this,t),t?(this.allowHalfOpen=t.allowHalfOpen!==!1,t.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),t.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)):this.allowHalfOpen=!0}JD(In.prototype,{writable:{__proto__:null,...Yi(nn.prototype,"writable")},writableHighWaterMark:{__proto__:null,...Yi(nn.prototype,"writableHighWaterMark")},writableObjectMode:{__proto__:null,...Yi(nn.prototype,"writableObjectMode")},writableBuffer:{__proto__:null,...Yi(nn.prototype,"writableBuffer")},writableLength:{__proto__:null,...Yi(nn.prototype,"writableLength")},writableFinished:{__proto__:null,...Yi(nn.prototype,"writableFinished")},writableCorked:{__proto__:null,...Yi(nn.prototype,"writableCorked")},writableEnded:{__proto__:null,...Yi(nn.prototype,"writableEnded")},writableNeedDrain:{__proto__:null,...Yi(nn.prototype,"writableNeedDrain")},destroyed:{__proto__:null,get(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set(t){this._readableState&&this._writableState&&(this._readableState.destroyed=t,this._writableState.destroyed=t)}}});var Km;function PA(){return Km===void 0&&(Km={}),Km}In.fromWeb=function(t,e){return PA().newStreamDuplexFromReadableWritablePair(t,e)};In.toWeb=function(t){return PA().newReadableWritablePairFromDuplex(t)};var $m;In.from=function(t){return $m||($m=CA()),$m(t,"body")}});var Fm=oe((sj,$A)=>{"use strict";l();var{ObjectSetPrototypeOf:KA,Symbol:ZD}=it();$A.exports=Ji;var{ERR_METHOD_NOT_IMPLEMENTED:QD}=or().codes,qm=si(),{getHighWaterMark:ek}=Id();KA(Ji.prototype,qm.prototype);KA(Ji,qm);var Nd=ZD("kCallback");function Ji(t){if(!(this instanceof Ji))return new Ji(t);let e=t?ek(this,t,"readableHighWaterMark",!0):null;e===0&&(t={...t,highWaterMark:null,readableHighWaterMark:e,writableHighWaterMark:t.writableHighWaterMark||0}),qm.call(this,t),this._readableState.sync=!1,this[Nd]=null,t&&(typeof t.transform=="function"&&(this._transform=t.transform),typeof t.flush=="function"&&(this._flush=t.flush)),this.on("prefinish",tk)}function Vm(t){typeof this._flush=="function"&&!this.destroyed?this._flush((e,r)=>{if(e){t?t(e):this.destroy(e);return}r!=null&&this.push(r),this.push(null),t&&t()}):(this.push(null),t&&t())}function tk(){this._final!==Vm&&Vm.call(this)}Ji.prototype._final=Vm;Ji.prototype._transform=function(t,e,r){throw new QD("_transform()")};Ji.prototype._write=function(t,e,r){let n=this._readableState,i=this._writableState,o=n.length;this._transform(t,e,(s,c)=>{if(s){r(s);return}c!=null&&this.push(c),i.ended||o===n.length||n.length<n.highWaterMark?r():this[Nd]=r})};Ji.prototype._read=function(){if(this[Nd]){let t=this[Nd];this[Nd]=null,t()}}});var Wm=oe((aj,VA)=>{"use strict";l();var{ObjectSetPrototypeOf:HA}=it();VA.exports=ka;var jm=Fm();HA(ka.prototype,jm.prototype);HA(ka,jm);function ka(t){if(!(this instanceof ka))return new ka(t);jm.call(this,t)}ka.prototype._transform=function(t,e,r){r(null,t)}});var qh=oe((dj,GA)=>{l();var Cd=vi(),{ArrayIsArray:rk,Promise:nk,SymbolAsyncIterator:ik,SymbolDispose:ok}=it(),Vh=zi(),{once:sk}=Zt(),ck=oc(),qA=si(),{aggregateTwoErrors:ak,codes:{ERR_INVALID_ARG_TYPE:tw,ERR_INVALID_RETURN_VALUE:Gm,ERR_MISSING_ARGS:uk,ERR_STREAM_DESTROYED:dk,ERR_STREAM_PREMATURE_CLOSE:fk},AbortError:lk}=or(),{validateFunction:hk,validateAbortSignal:pk}=Aa(),{isIterable:uc,isReadable:zm,isReadableNodeStream:Hh,isNodeStream:FA,isTransformStream:Na,isWebStream:yk,isReadableStream:Ym,isReadableFinished:gk}=ni(),mk=globalThis.AbortController||va().AbortController,Jm,Xm,Zm;function jA(t,e,r){let n=!1;t.on("close",()=>{n=!0});let i=Vh(t,{readable:e,writable:r},o=>{n=!o});return{destroy:o=>{n||(n=!0,ck.destroyer(t,o||new dk("pipe")))},cleanup:i}}function wk(t){return hk(t[t.length-1],"streams[stream.length - 1]"),t.pop()}function Qm(t){if(uc(t))return t;if(Hh(t))return bk(t);throw new tw("val",["Readable","Iterable","AsyncIterable"],t)}async function*bk(t){Xm||(Xm=Ud()),yield*Xm.prototype[ik].call(t)}async function $h(t,e,r,{end:n}){let i,o=null,s=u=>{if(u&&(i=u),o){let d=o;o=null,d()}},c=()=>new nk((u,d)=>{i?d(i):o=()=>{i?d(i):u()}});e.on("drain",s);let a=Vh(e,{readable:!1},s);try{e.writableNeedDrain&&await c();for await(let u of t)e.write(u)||await c();n&&(e.end(),await c()),r()}catch(u){r(i!==u?ak(i,u):u)}finally{a(),e.off("drain",s)}}async function ew(t,e,r,{end:n}){Na(e)&&(e=e.writable);let i=e.getWriter();try{for await(let o of t)await i.ready,i.write(o).catch(()=>{});await i.ready,n&&await i.close(),r()}catch(o){try{await i.abort(o),r(o)}catch(s){r(s)}}}function xk(...t){return WA(t,sk(wk(t)))}function WA(t,e,r){if(t.length===1&&rk(t[0])&&(t=t[0]),t.length<2)throw new uk("streams");let n=new mk,i=n.signal,o=r?.signal,s=[];pk(o,"options.signal");function c(){g(new lk)}Zm=Zm||Zt().addAbortListener;let a;o&&(a=Zm(o,c));let u,d,f=[],h=0;function p(A){g(A,--h===0)}function g(A,O){var T;if(A&&(!u||u.code==="ERR_STREAM_PREMATURE_CLOSE")&&(u=A),!(!u&&!O)){for(;f.length;)f.shift()(u);(T=a)===null||T===void 0||T[ok](),n.abort(),O&&(u||s.forEach(M=>M()),Cd.nextTick(e,u,d))}}let y;for(let A=0;A<t.length;A++){let O=t[A],T=A<t.length-1,M=A>0,q=T||r?.end!==!1,j=A===t.length-1;if(FA(O)){let $=function(Z){Z&&Z.name!=="AbortError"&&Z.code!=="ERR_STREAM_PREMATURE_CLOSE"&&p(Z)};var I=$;if(q){let{destroy:Z,cleanup:Q}=jA(O,T,M);f.push(Z),zm(O)&&j&&s.push(Q)}O.on("error",$),zm(O)&&j&&s.push(()=>{O.removeListener("error",$)})}if(A===0)if(typeof O=="function"){if(y=O({signal:i}),!uc(y))throw new Gm("Iterable, AsyncIterable or Stream","source",y)}else uc(O)||Hh(O)||Na(O)?y=O:y=qA.from(O);else if(typeof O=="function"){if(Na(y)){var x;y=Qm((x=y)===null||x===void 0?void 0:x.readable)}else y=Qm(y);if(y=O(y,{signal:i}),T){if(!uc(y,!0))throw new Gm("AsyncIterable",`transform[${A-1}]`,y)}else{var S;Jm||(Jm=Wm());let $=new Jm({objectMode:!0}),Z=(S=y)===null||S===void 0?void 0:S.then;if(typeof Z=="function")h++,Z.call(y,_=>{d=_,_!=null&&$.write(_),q&&$.end(),Cd.nextTick(p)},_=>{$.destroy(_),Cd.nextTick(p,_)});else if(uc(y,!0))h++,$h(y,$,p,{end:q});else if(Ym(y)||Na(y)){let _=y.readable||y;h++,$h(_,$,p,{end:q})}else throw new Gm("AsyncIterable or Promise","destination",y);y=$;let{destroy:Q,cleanup:G}=jA(y,!1,!0);f.push(Q),j&&s.push(G)}}else if(FA(O)){if(Hh(y)){h+=2;let $=Ek(y,O,p,{end:q});zm(O)&&j&&s.push($)}else if(Na(y)||Ym(y)){let $=y.readable||y;h++,$h($,O,p,{end:q})}else if(uc(y))h++,$h(y,O,p,{end:q});else throw new tw("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=O}else if(yk(O)){if(Hh(y))h++,ew(Qm(y),O,p,{end:q});else if(Ym(y)||uc(y))h++,ew(y,O,p,{end:q});else if(Na(y))h++,ew(y.readable,O,p,{end:q});else throw new tw("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=O}else y=qA.from(O)}return(i!=null&&i.aborted||o!=null&&o.aborted)&&Cd.nextTick(c),y}function Ek(t,e,r,{end:n}){let i=!1;if(e.on("close",()=>{i||r(new fk)}),t.pipe(e,{end:!1}),n){let s=function(){i=!0,e.end()};var o=s;gk(t)?Cd.nextTick(s):t.once("end",s)}else r();return Vh(t,{readable:!0,writable:!1},s=>{let c=t._readableState;s&&s.code==="ERR_STREAM_PREMATURE_CLOSE"&&c&&c.ended&&!c.errored&&!c.errorEmitted?t.once("end",r).once("error",r):r(s)}),Vh(e,{readable:!1,writable:!0},r)}GA.exports={pipelineImpl:WA,pipeline:xk}});var nw=oe((lj,QA)=>{"use strict";l();var{pipeline:vk}=qh(),Fh=si(),{destroyer:Sk}=oc(),{isNodeStream:jh,isReadable:zA,isWritable:YA,isWebStream:rw,isTransformStream:dc,isWritableStream:JA,isReadableStream:XA}=ni(),{AbortError:Ak,codes:{ERR_INVALID_ARG_VALUE:ZA,ERR_MISSING_ARGS:Tk}}=or(),_k=zi();QA.exports=function(...e){if(e.length===0)throw new Tk("streams");if(e.length===1)return Fh.from(e[0]);let r=[...e];if(typeof e[0]=="function"&&(e[0]=Fh.from(e[0])),typeof e[e.length-1]=="function"){let p=e.length-1;e[p]=Fh.from(e[p])}for(let p=0;p<e.length;++p)if(!(!jh(e[p])&&!rw(e[p]))){if(p<e.length-1&&!(zA(e[p])||XA(e[p])||dc(e[p])))throw new ZA(`streams[${p}]`,r[p],"must be readable");if(p>0&&!(YA(e[p])||JA(e[p])||dc(e[p])))throw new ZA(`streams[${p}]`,r[p],"must be writable")}let n,i,o,s,c;function a(p){let g=s;s=null,g?g(p):p?c.destroy(p):!h&&!f&&c.destroy()}let u=e[0],d=vk(e,a),f=!!(YA(u)||JA(u)||dc(u)),h=!!(zA(d)||XA(d)||dc(d));if(c=new Fh({writableObjectMode:!!(u!=null&&u.writableObjectMode),readableObjectMode:!!(d!=null&&d.readableObjectMode),writable:f,readable:h}),f){if(jh(u))c._write=function(g,y,x){u.write(g,y)?x():n=x},c._final=function(g){u.end(),i=g},u.on("drain",function(){if(n){let g=n;n=null,g()}});else if(rw(u)){let y=(dc(u)?u.writable:u).getWriter();c._write=async function(x,S,I){try{await y.ready,y.write(x).catch(()=>{}),I()}catch(A){I(A)}},c._final=async function(x){try{await y.ready,y.close().catch(()=>{}),i=x}catch(S){x(S)}}}let p=dc(d)?d.readable:d;_k(p,()=>{if(i){let g=i;i=null,g()}})}if(h){if(jh(d))d.on("readable",function(){if(o){let p=o;o=null,p()}}),d.on("end",function(){c.push(null)}),c._read=function(){for(;;){let p=d.read();if(p===null){o=c._read;return}if(!c.push(p))return}};else if(rw(d)){let g=(dc(d)?d.readable:d).getReader();c._read=async function(){for(;;)try{let{value:y,done:x}=await g.read();if(!c.push(y))return;if(x){c.push(null);return}}catch{return}}}}return c._destroy=function(p,g){!p&&s!==null&&(p=new Ak),o=null,n=null,i=null,s===null?g(p):(s=g,jh(d)&&Sk(d,p))},c}});var uT=oe((pj,sw)=>{"use strict";l();var Ik=globalThis.AbortController||va().AbortController,{codes:{ERR_INVALID_ARG_VALUE:Bk,ERR_INVALID_ARG_TYPE:Ld,ERR_MISSING_ARGS:Rk,ERR_OUT_OF_RANGE:Uk},AbortError:ci}=or(),{validateAbortSignal:fc,validateInteger:eT,validateObject:lc}=Aa(),Ok=it().Symbol("kWeak"),Dk=it().Symbol("kResistStopPropagation"),{finished:kk}=zi(),Nk=nw(),{addAbortSignalNoValidate:Ck}=_d(),{isWritable:Lk,isNodeStream:Pk}=ni(),{deprecate:Mk}=Zt(),{ArrayPrototypePush:Kk,Boolean:$k,MathFloor:tT,Number:Hk,NumberIsNaN:Vk,Promise:rT,PromiseReject:nT,PromiseResolve:qk,PromisePrototypeThen:iT,Symbol:sT}=it(),Wh=sT("kEmpty"),oT=sT("kEof");function Fk(t,e){if(e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),Pk(t)&&!Lk(t))throw new Bk("stream",t,"must be writable");let r=Nk(this,t);return e!=null&&e.signal&&Ck(e.signal,r),r}function Gh(t,e){if(typeof t!="function")throw new Ld("fn",["Function","AsyncFunction"],t);e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal");let r=1;e?.concurrency!=null&&(r=tT(e.concurrency));let n=r-1;return e?.highWaterMark!=null&&(n=tT(e.highWaterMark)),eT(r,"options.concurrency",1),eT(n,"options.highWaterMark",0),n+=r,(async function*(){let o=Zt().AbortSignalAny([e?.signal].filter($k)),s=this,c=[],a={signal:o},u,d,f=!1,h=0;function p(){f=!0,g()}function g(){h-=1,y()}function y(){d&&!f&&h<r&&c.length<n&&(d(),d=null)}async function x(){try{for await(let S of s){if(f)return;if(o.aborted)throw new ci;try{if(S=t(S,a),S===Wh)continue;S=qk(S)}catch(I){S=nT(I)}h+=1,iT(S,g,p),c.push(S),u&&(u(),u=null),!f&&(c.length>=n||h>=r)&&await new rT(I=>{d=I})}c.push(oT)}catch(S){let I=nT(S);iT(I,g,p),c.push(I)}finally{f=!0,u&&(u(),u=null)}}x();try{for(;;){for(;c.length>0;){let S=await c[0];if(S===oT)return;if(o.aborted)throw new ci;S!==Wh&&(yield S),c.shift(),y()}await new rT(S=>{u=S})}}finally{f=!0,d&&(d(),d=null)}}).call(this)}function jk(t=void 0){return t!=null&&lc(t,"options"),t?.signal!=null&&fc(t.signal,"options.signal"),(async function*(){let r=0;for await(let i of this){var n;if(t!=null&&(n=t.signal)!==null&&n!==void 0&&n.aborted)throw new ci({cause:t.signal.reason});yield[r++,i]}}).call(this)}async function cT(t,e=void 0){for await(let r of ow.call(this,t,e))return!0;return!1}async function Wk(t,e=void 0){if(typeof t!="function")throw new Ld("fn",["Function","AsyncFunction"],t);return!await cT.call(this,async(...r)=>!await t(...r),e)}async function Gk(t,e){for await(let r of ow.call(this,t,e))return r}async function zk(t,e){if(typeof t!="function")throw new Ld("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i),Wh}for await(let n of Gh.call(this,r,e));}function ow(t,e){if(typeof t!="function")throw new Ld("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i)?n:Wh}return Gh.call(this,r,e)}var iw=class extends Rk{constructor(){super("reduce"),this.message="Reduce of an empty stream requires an initial value"}};async function Yk(t,e,r){var n;if(typeof t!="function")throw new Ld("reducer",["Function","AsyncFunction"],t);r!=null&&lc(r,"options"),r?.signal!=null&&fc(r.signal,"options.signal");let i=arguments.length>1;if(r!=null&&(n=r.signal)!==null&&n!==void 0&&n.aborted){let u=new ci(void 0,{cause:r.signal.reason});throw this.once("error",()=>{}),await kk(this.destroy(u)),u}let o=new Ik,s=o.signal;if(r!=null&&r.signal){let u={once:!0,[Ok]:this,[Dk]:!0};r.signal.addEventListener("abort",()=>o.abort(),u)}let c=!1;try{for await(let u of this){var a;if(c=!0,r!=null&&(a=r.signal)!==null&&a!==void 0&&a.aborted)throw new ci;i?e=await t(e,u,{signal:s}):(e=u,i=!0)}if(!c&&!i)throw new iw}finally{o.abort()}return e}async function Jk(t){t!=null&&lc(t,"options"),t?.signal!=null&&fc(t.signal,"options.signal");let e=[];for await(let n of this){var r;if(t!=null&&(r=t.signal)!==null&&r!==void 0&&r.aborted)throw new ci(void 0,{cause:t.signal.reason});Kk(e,n)}return e}function Xk(t,e){let r=Gh.call(this,t,e);return(async function*(){for await(let i of r)yield*i}).call(this)}function aT(t){if(t=Hk(t),Vk(t))return 0;if(t<0)throw new Uk("number",">= 0",t);return t}function Zk(t,e=void 0){return e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),t=aT(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new ci;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new ci;t--<=0&&(yield o)}}).call(this)}function Qk(t,e=void 0){return e!=null&&lc(e,"options"),e?.signal!=null&&fc(e.signal,"options.signal"),t=aT(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new ci;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new ci;if(t-- >0&&(yield o),t<=0)return}}).call(this)}sw.exports.streamReturningOperators={asIndexedPairs:Mk(jk,"readable.asIndexedPairs will be removed in a future version."),drop:Zk,filter:ow,flatMap:Xk,map:Gh,take:Qk,compose:Fk};sw.exports.promiseReturningOperators={every:Wk,forEach:zk,reduce:Yk,toArray:Jk,some:cT,find:Gk}});var cw=oe((gj,dT)=>{"use strict";l();var{ArrayPrototypePop:e4,Promise:t4}=it(),{isIterable:r4,isNodeStream:n4,isWebStream:i4}=ni(),{pipelineImpl:o4}=qh(),{finished:s4}=zi();aw();function c4(...t){return new t4((e,r)=>{let n,i,o=t[t.length-1];if(o&&typeof o=="object"&&!n4(o)&&!r4(o)&&!i4(o)){let s=e4(t);n=s.signal,i=s.end}o4(t,(s,c)=>{s?r(s):e(c)},{signal:n,end:i})})}dT.exports={finished:s4,pipeline:c4}});var aw=oe((wj,bT)=>{l();var{Buffer:a4}=_r(),{ObjectDefineProperty:Xi,ObjectKeys:hT,ReflectApply:pT}=it(),{promisify:{custom:yT}}=Zt(),{streamReturningOperators:fT,promiseReturningOperators:lT}=uT(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:gT}}=or(),u4=nw(),{setDefaultHighWaterMark:d4,getDefaultHighWaterMark:f4}=Id(),{pipeline:mT}=qh(),{destroyer:l4}=oc(),wT=zi(),uw=cw(),Pd=ni(),We=bT.exports=_h().Stream;We.isDestroyed=Pd.isDestroyed;We.isDisturbed=Pd.isDisturbed;We.isErrored=Pd.isErrored;We.isReadable=Pd.isReadable;We.isWritable=Pd.isWritable;We.Readable=Ud();for(let t of hT(fT)){let r=function(...n){if(new.target)throw gT();return We.Readable.from(pT(e,this,n))};dw=r;let e=fT[t];Xi(r,"name",{__proto__:null,value:e.name}),Xi(r,"length",{__proto__:null,value:e.length}),Xi(We.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var dw;for(let t of hT(lT)){let r=function(...i){if(new.target)throw gT();return pT(e,this,i)};dw=r;let e=lT[t];Xi(r,"name",{__proto__:null,value:e.name}),Xi(r,"length",{__proto__:null,value:e.length}),Xi(We.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var dw;We.Writable=Kh();We.Duplex=si();We.Transform=Fm();We.PassThrough=Wm();We.pipeline=mT;var{addAbortSignal:h4}=_d();We.addAbortSignal=h4;We.finished=wT;We.destroy=l4;We.compose=u4;We.setDefaultHighWaterMark=d4;We.getDefaultHighWaterMark=f4;Xi(We,"promises",{__proto__:null,configurable:!0,enumerable:!0,get(){return uw}});Xi(mT,yT,{__proto__:null,enumerable:!0,get(){return uw.pipeline}});Xi(wT,yT,{__proto__:null,enumerable:!0,get(){return uw.finished}});We.Stream=We;We._isUint8Array=function(e){return e instanceof Uint8Array};We._uint8ArrayToBuffer=function(e){return a4.from(e.buffer,e.byteOffset,e.byteLength)}});var fw=oe((xj,mt)=>{"use strict";l();var _t=aw(),p4=cw(),y4=_t.Readable.destroy;mt.exports=_t.Readable;mt.exports._uint8ArrayToBuffer=_t._uint8ArrayToBuffer;mt.exports._isUint8Array=_t._isUint8Array;mt.exports.isDisturbed=_t.isDisturbed;mt.exports.isErrored=_t.isErrored;mt.exports.isReadable=_t.isReadable;mt.exports.Readable=_t.Readable;mt.exports.Writable=_t.Writable;mt.exports.Duplex=_t.Duplex;mt.exports.Transform=_t.Transform;mt.exports.PassThrough=_t.PassThrough;mt.exports.addAbortSignal=_t.addAbortSignal;mt.exports.finished=_t.finished;mt.exports.destroy=_t.destroy;mt.exports.destroy=y4;mt.exports.pipeline=_t.pipeline;mt.exports.compose=_t.compose;Object.defineProperty(_t,"promises",{configurable:!0,enumerable:!0,get(){return p4}});mt.exports.Stream=_t.Stream;mt.exports.default=mt.exports});var H_=oe((Cp,$_)=>{l();(function(t,e){typeof Cp=="object"&&typeof $_<"u"?e(Cp):typeof define=="function"&&define.amd?define(["exports"],e):e(t.URI=t.URI||{})})(Cp,function(t){"use strict";function e(){for(var B=arguments.length,v=Array(B),k=0;k<B;k++)v[k]=arguments[k];if(v.length>1){v[0]=v[0].slice(0,-1);for(var K=v.length-1,H=1;H<K;++H)v[H]=v[H].slice(1,-1);return v[K]=v[K].slice(1),v.join("")}else return v[0]}function r(B){return"(?:"+B+")"}function n(B){return B===void 0?"undefined":B===null?"null":Object.prototype.toString.call(B).split(" ").pop().split("]").shift().toLowerCase()}function i(B){return B.toUpperCase()}function o(B){return B!=null?B instanceof Array?B:typeof B.length!="number"||B.split||B.setInterval||B.call?[B]:Array.prototype.slice.call(B):[]}function s(B,v){var k=B;if(v)for(var K in v)k[K]=v[K];return k}function c(B){var v="[A-Za-z]",k="[\\x0D]",K="[0-9]",H="[\\x22]",te=e(K,"[A-Fa-f]"),he="[\\x0A]",Te="[\\x20]",De=r(r("%[EFef]"+te+"%"+te+te+"%"+te+te)+"|"+r("%[89A-Fa-f]"+te+"%"+te+te)+"|"+r("%"+te+te)),wt="[\\:\\/\\?\\#\\[\\]\\@]",Ae="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",tt=e(wt,Ae),bt=B?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",Xe=B?"[\\uE000-\\uF8FF]":"[]",Ie=e(v,K,"[\\-\\.\\_\\~]",bt),rt=r(v+e(v,K,"[\\+\\-\\.]")+"*"),Ne=r(r(De+"|"+e(Ie,Ae,"[\\:]"))+"*"),hs=r(r("25[0-5]")+"|"+r("2[0-4]"+K)+"|"+r("1"+K+K)+"|"+r("[1-9]"+K)+"|"+K),Ar=r(r("25[0-5]")+"|"+r("2[0-4]"+K)+"|"+r("1"+K+K)+"|"+r("0?[1-9]"+K)+"|0?0?"+K),Wr=r(Ar+"\\."+Ar+"\\."+Ar+"\\."+Ar),Ke=r(te+"{1,4}"),Tr=r(r(Ke+"\\:"+Ke)+"|"+Wr),Gr=r(r(Ke+"\\:")+"{6}"+Tr),Mn=r("\\:\\:"+r(Ke+"\\:")+"{5}"+Tr),ps=r(r(Ke)+"?\\:\\:"+r(Ke+"\\:")+"{4}"+Tr),gi=r(r(r(Ke+"\\:")+"{0,1}"+Ke)+"?\\:\\:"+r(Ke+"\\:")+"{3}"+Tr),gu=r(r(r(Ke+"\\:")+"{0,2}"+Ke)+"?\\:\\:"+r(Ke+"\\:")+"{2}"+Tr),Af=r(r(r(Ke+"\\:")+"{0,3}"+Ke)+"?\\:\\:"+Ke+"\\:"+Tr),Tf=r(r(r(Ke+"\\:")+"{0,4}"+Ke)+"?\\:\\:"+Tr),Ac=r(r(r(Ke+"\\:")+"{0,5}"+Ke)+"?\\:\\:"+Ke),Tc=r(r(r(Ke+"\\:")+"{0,6}"+Ke)+"?\\:\\:"),mi=r([Gr,Mn,ps,gi,gu,Af,Tf,Ac,Tc].join("|")),_c=r(r(Ie+"|"+De)+"+"),ny=r(mi+"\\%25"+_c),ys=r(mi+r("\\%25|\\%(?!"+te+"{2})")+_c),sB=r("[vV]"+te+"+\\."+e(Ie,Ae,"[\\:]")+"+"),cB=r("\\["+r(ys+"|"+mi+"|"+sB)+"\\]"),ix=r(r(De+"|"+e(Ie,Ae))+"*"),mu=r(cB+"|"+Wr+"(?!"+ix+")|"+ix),wu=r(K+"*"),ox=r(r(Ne+"@")+"?"+mu+r("\\:"+wu)+"?"),bu=r(De+"|"+e(Ie,Ae,"[\\:\\@]")),aB=r(bu+"*"),sx=r(bu+"+"),uB=r(r(De+"|"+e(Ie,Ae,"[\\@]"))+"+"),wi=r(r("\\/"+aB)+"*"),Ic=r("\\/"+r(sx+wi)+"?"),iy=r(uB+wi),_f=r(sx+wi),Bc="(?!"+bu+")",WL=r(wi+"|"+Ic+"|"+iy+"|"+_f+"|"+Bc),Rc=r(r(bu+"|"+e("[\\/\\?]",Xe))+"*"),xu=r(r(bu+"|[\\/\\?]")+"*"),cx=r(r("\\/\\/"+ox+wi)+"|"+Ic+"|"+_f+"|"+Bc),dB=r(rt+"\\:"+cx+r("\\?"+Rc)+"?"+r("\\#"+xu)+"?"),fB=r(r("\\/\\/"+ox+wi)+"|"+Ic+"|"+iy+"|"+Bc),lB=r(fB+r("\\?"+Rc)+"?"+r("\\#"+xu)+"?"),GL=r(dB+"|"+lB),zL=r(rt+"\\:"+cx+r("\\?"+Rc)+"?"),YL="^("+rt+")\\:"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+mu+")"+r("\\:("+wu+")")+"?)")+"?("+wi+"|"+Ic+"|"+_f+"|"+Bc+")")+r("\\?("+Rc+")")+"?"+r("\\#("+xu+")")+"?$",JL="^(){0}"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+mu+")"+r("\\:("+wu+")")+"?)")+"?("+wi+"|"+Ic+"|"+iy+"|"+Bc+")")+r("\\?("+Rc+")")+"?"+r("\\#("+xu+")")+"?$",XL="^("+rt+")\\:"+r(r("\\/\\/("+r("("+Ne+")@")+"?("+mu+")"+r("\\:("+wu+")")+"?)")+"?("+wi+"|"+Ic+"|"+_f+"|"+Bc+")")+r("\\?("+Rc+")")+"?$",ZL="^"+r("\\#("+xu+")")+"?$",QL="^"+r("("+Ne+")@")+"?("+mu+")"+r("\\:("+wu+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",v,K,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",Ie,Ae),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",Ie,Ae),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",Ie,Ae),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",Ie,Ae),"g"),NOT_QUERY:new RegExp(e("[^\\%]",Ie,Ae,"[\\:\\@\\/\\?]",Xe),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",Ie,Ae,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",Ie,Ae),"g"),UNRESERVED:new RegExp(Ie,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",Ie,tt),"g"),PCT_ENCODED:new RegExp(De,"g"),IPV4ADDRESS:new RegExp("^("+Wr+")$"),IPV6ADDRESS:new RegExp("^\\[?("+mi+")"+r(r("\\%25|\\%(?!"+te+"{2})")+"("+_c+")")+"?\\]?$")}}var a=c(!1),u=c(!0),d=function(){function B(v,k){var K=[],H=!0,te=!1,he=void 0;try{for(var Te=v[Symbol.iterator](),De;!(H=(De=Te.next()).done)&&(K.push(De.value),!(k&&K.length===k));H=!0);}catch(wt){te=!0,he=wt}finally{try{!H&&Te.return&&Te.return()}finally{if(te)throw he}}return K}return function(v,k){if(Array.isArray(v))return v;if(Symbol.iterator in Object(v))return B(v,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(B){if(Array.isArray(B)){for(var v=0,k=Array(B.length);v<B.length;v++)k[v]=B[v];return k}else return Array.from(B)},h=2147483647,p=36,g=1,y=26,x=38,S=700,I=72,A=128,O="-",T=/^xn--/,M=/[^\0-\x7E]/,q=/[\x2E\u3002\uFF0E\uFF61]/g,j={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},$=p-g,Z=Math.floor,Q=String.fromCharCode;function G(B){throw new RangeError(j[B])}function _(B,v){for(var k=[],K=B.length;K--;)k[K]=v(B[K]);return k}function D(B,v){var k=B.split("@"),K="";k.length>1&&(K=k[0]+"@",B=k[1]),B=B.replace(q,".");var H=B.split("."),te=_(H,v).join(".");return K+te}function E(B){for(var v=[],k=0,K=B.length;k<K;){var H=B.charCodeAt(k++);if(H>=55296&&H<=56319&&k<K){var te=B.charCodeAt(k++);(te&64512)==56320?v.push(((H&1023)<<10)+(te&1023)+65536):(v.push(H),k--)}else v.push(H)}return v}var U=function(v){return String.fromCodePoint.apply(String,f(v))},L=function(v){return v-48<10?v-22:v-65<26?v-65:v-97<26?v-97:p},N=function(v,k){return v+22+75*(v<26)-((k!=0)<<5)},R=function(v,k,K){var H=0;for(v=K?Z(v/S):v>>1,v+=Z(v/k);v>$*y>>1;H+=p)v=Z(v/$);return Z(H+($+1)*v/(v+x))},C=function(v){var k=[],K=v.length,H=0,te=A,he=I,Te=v.lastIndexOf(O);Te<0&&(Te=0);for(var De=0;De<Te;++De)v.charCodeAt(De)>=128&&G("not-basic"),k.push(v.charCodeAt(De));for(var wt=Te>0?Te+1:0;wt<K;){for(var Ae=H,tt=1,bt=p;;bt+=p){wt>=K&&G("invalid-input");var Xe=L(v.charCodeAt(wt++));(Xe>=p||Xe>Z((h-H)/tt))&&G("overflow"),H+=Xe*tt;var Ie=bt<=he?g:bt>=he+y?y:bt-he;if(Xe<Ie)break;var rt=p-Ie;tt>Z(h/rt)&&G("overflow"),tt*=rt}var Ne=k.length+1;he=R(H-Ae,Ne,Ae==0),Z(H/Ne)>h-te&&G("overflow"),te+=Z(H/Ne),H%=Ne,k.splice(H++,0,te)}return String.fromCodePoint.apply(String,k)},P=function(v){var k=[];v=E(v);var K=v.length,H=A,te=0,he=I,Te=!0,De=!1,wt=void 0;try{for(var Ae=v[Symbol.iterator](),tt;!(Te=(tt=Ae.next()).done);Te=!0){var bt=tt.value;bt<128&&k.push(Q(bt))}}catch(ys){De=!0,wt=ys}finally{try{!Te&&Ae.return&&Ae.return()}finally{if(De)throw wt}}var Xe=k.length,Ie=Xe;for(Xe&&k.push(O);Ie<K;){var rt=h,Ne=!0,hs=!1,Ar=void 0;try{for(var Wr=v[Symbol.iterator](),Ke;!(Ne=(Ke=Wr.next()).done);Ne=!0){var Tr=Ke.value;Tr>=H&&Tr<rt&&(rt=Tr)}}catch(ys){hs=!0,Ar=ys}finally{try{!Ne&&Wr.return&&Wr.return()}finally{if(hs)throw Ar}}var Gr=Ie+1;rt-H>Z((h-te)/Gr)&&G("overflow"),te+=(rt-H)*Gr,H=rt;var Mn=!0,ps=!1,gi=void 0;try{for(var gu=v[Symbol.iterator](),Af;!(Mn=(Af=gu.next()).done);Mn=!0){var Tf=Af.value;if(Tf<H&&++te>h&&G("overflow"),Tf==H){for(var Ac=te,Tc=p;;Tc+=p){var mi=Tc<=he?g:Tc>=he+y?y:Tc-he;if(Ac<mi)break;var _c=Ac-mi,ny=p-mi;k.push(Q(N(mi+_c%ny,0))),Ac=Z(_c/ny)}k.push(Q(N(Ac,0))),he=R(te,Gr,Ie==Xe),te=0,++Ie}}}catch(ys){ps=!0,gi=ys}finally{try{!Mn&&gu.return&&gu.return()}finally{if(ps)throw gi}}++te,++H}return k.join("")},V=function(v){return D(v,function(k){return T.test(k)?C(k.slice(4).toLowerCase()):k})},J=function(v){return D(v,function(k){return M.test(k)?"xn--"+P(k):k})},z={version:"2.1.0",ucs2:{decode:E,encode:U},decode:C,encode:P,toASCII:J,toUnicode:V},W={};function Y(B){var v=B.charCodeAt(0),k=void 0;return v<16?k="%0"+v.toString(16).toUpperCase():v<128?k="%"+v.toString(16).toUpperCase():v<2048?k="%"+(v>>6|192).toString(16).toUpperCase()+"%"+(v&63|128).toString(16).toUpperCase():k="%"+(v>>12|224).toString(16).toUpperCase()+"%"+(v>>6&63|128).toString(16).toUpperCase()+"%"+(v&63|128).toString(16).toUpperCase(),k}function X(B){for(var v="",k=0,K=B.length;k<K;){var H=parseInt(B.substr(k+1,2),16);if(H<128)v+=String.fromCharCode(H),k+=3;else if(H>=194&&H<224){if(K-k>=6){var te=parseInt(B.substr(k+4,2),16);v+=String.fromCharCode((H&31)<<6|te&63)}else v+=B.substr(k,6);k+=6}else if(H>=224){if(K-k>=9){var he=parseInt(B.substr(k+4,2),16),Te=parseInt(B.substr(k+7,2),16);v+=String.fromCharCode((H&15)<<12|(he&63)<<6|Te&63)}else v+=B.substr(k,9);k+=9}else v+=B.substr(k,3),k+=3}return v}function ue(B,v){function k(K){var H=X(K);return H.match(v.UNRESERVED)?H:K}return B.scheme&&(B.scheme=String(B.scheme).replace(v.PCT_ENCODED,k).toLowerCase().replace(v.NOT_SCHEME,"")),B.userinfo!==void 0&&(B.userinfo=String(B.userinfo).replace(v.PCT_ENCODED,k).replace(v.NOT_USERINFO,Y).replace(v.PCT_ENCODED,i)),B.host!==void 0&&(B.host=String(B.host).replace(v.PCT_ENCODED,k).toLowerCase().replace(v.NOT_HOST,Y).replace(v.PCT_ENCODED,i)),B.path!==void 0&&(B.path=String(B.path).replace(v.PCT_ENCODED,k).replace(B.scheme?v.NOT_PATH:v.NOT_PATH_NOSCHEME,Y).replace(v.PCT_ENCODED,i)),B.query!==void 0&&(B.query=String(B.query).replace(v.PCT_ENCODED,k).replace(v.NOT_QUERY,Y).replace(v.PCT_ENCODED,i)),B.fragment!==void 0&&(B.fragment=String(B.fragment).replace(v.PCT_ENCODED,k).replace(v.NOT_FRAGMENT,Y).replace(v.PCT_ENCODED,i)),B}function ee(B){return B.replace(/^0*(.*)/,"$1")||"0"}function ce(B,v){var k=B.match(v.IPV4ADDRESS)||[],K=d(k,2),H=K[1];return H?H.split(".").map(ee).join("."):B}function Oe(B,v){var k=B.match(v.IPV6ADDRESS)||[],K=d(k,3),H=K[1],te=K[2];if(H){for(var he=H.toLowerCase().split("::").reverse(),Te=d(he,2),De=Te[0],wt=Te[1],Ae=wt?wt.split(":").map(ee):[],tt=De.split(":").map(ee),bt=v.IPV4ADDRESS.test(tt[tt.length-1]),Xe=bt?7:8,Ie=tt.length-Xe,rt=Array(Xe),Ne=0;Ne<Xe;++Ne)rt[Ne]=Ae[Ne]||tt[Ie+Ne]||"";bt&&(rt[Xe-1]=ce(rt[Xe-1],v));var hs=rt.reduce(function(Gr,Mn,ps){if(!Mn||Mn==="0"){var gi=Gr[Gr.length-1];gi&&gi.index+gi.length===ps?gi.length++:Gr.push({index:ps,length:1})}return Gr},[]),Ar=hs.sort(function(Gr,Mn){return Mn.length-Gr.length})[0],Wr=void 0;if(Ar&&Ar.length>1){var Ke=rt.slice(0,Ar.index),Tr=rt.slice(Ar.index+Ar.length);Wr=Ke.join(":")+"::"+Tr.join(":")}else Wr=rt.join(":");return te&&(Wr+="%"+te),Wr}else return B}var Me=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function Et(B){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},k={},K=v.iri!==!1?u:a;v.reference==="suffix"&&(B=(v.scheme?v.scheme+":":"")+"//"+B);var H=B.match(Me);if(H){Je?(k.scheme=H[1],k.userinfo=H[3],k.host=H[4],k.port=parseInt(H[5],10),k.path=H[6]||"",k.query=H[7],k.fragment=H[8],isNaN(k.port)&&(k.port=H[5])):(k.scheme=H[1]||void 0,k.userinfo=B.indexOf("@")!==-1?H[3]:void 0,k.host=B.indexOf("//")!==-1?H[4]:void 0,k.port=parseInt(H[5],10),k.path=H[6]||"",k.query=B.indexOf("?")!==-1?H[7]:void 0,k.fragment=B.indexOf("#")!==-1?H[8]:void 0,isNaN(k.port)&&(k.port=B.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?H[4]:void 0)),k.host&&(k.host=Oe(ce(k.host,K),K)),k.scheme===void 0&&k.userinfo===void 0&&k.host===void 0&&k.port===void 0&&!k.path&&k.query===void 0?k.reference="same-document":k.scheme===void 0?k.reference="relative":k.fragment===void 0?k.reference="absolute":k.reference="uri",v.reference&&v.reference!=="suffix"&&v.reference!==k.reference&&(k.error=k.error||"URI is not a "+v.reference+" reference.");var te=W[(v.scheme||k.scheme||"").toLowerCase()];if(!v.unicodeSupport&&(!te||!te.unicodeSupport)){if(k.host&&(v.domainHost||te&&te.domainHost))try{k.host=z.toASCII(k.host.replace(K.PCT_ENCODED,X).toLowerCase())}catch(he){k.error=k.error||"Host's domain name can not be converted to ASCII via punycode: "+he}ue(k,a)}else ue(k,K);te&&te.parse&&te.parse(k,v)}else k.error=k.error||"URI can not be parsed.";return k}function yi(B,v){var k=v.iri!==!1?u:a,K=[];return B.userinfo!==void 0&&(K.push(B.userinfo),K.push("@")),B.host!==void 0&&K.push(Oe(ce(String(B.host),k),k).replace(k.IPV6ADDRESS,function(H,te,he){return"["+te+(he?"%25"+he:"")+"]"})),(typeof B.port=="number"||typeof B.port=="string")&&(K.push(":"),K.push(String(B.port))),K.length?K.join(""):void 0}var po=/^\.\.?\//,lu=/^\/\.(\/|$)/,wf=/^\/\.\.(\/|$)/,ey=/^\/?(?:.|\n)*?(?=\/|$)/;function yo(B){for(var v=[];B.length;)if(B.match(po))B=B.replace(po,"");else if(B.match(lu))B=B.replace(lu,"/");else if(B.match(wf))B=B.replace(wf,"/"),v.pop();else if(B==="."||B==="..")B="";else{var k=B.match(ey);if(k){var K=k[0];B=B.slice(K.length),v.push(K)}else throw new Error("Unexpected dot segment condition")}return v.join("")}function Fr(B){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},k=v.iri?u:a,K=[],H=W[(v.scheme||B.scheme||"").toLowerCase()];if(H&&H.serialize&&H.serialize(B,v),B.host&&!k.IPV6ADDRESS.test(B.host)){if(v.domainHost||H&&H.domainHost)try{B.host=v.iri?z.toUnicode(B.host):z.toASCII(B.host.replace(k.PCT_ENCODED,X).toLowerCase())}catch(Te){B.error=B.error||"Host's domain name can not be converted to "+(v.iri?"Unicode":"ASCII")+" via punycode: "+Te}}ue(B,k),v.reference!=="suffix"&&B.scheme&&(K.push(B.scheme),K.push(":"));var te=yi(B,v);if(te!==void 0&&(v.reference!=="suffix"&&K.push("//"),K.push(te),B.path&&B.path.charAt(0)!=="/"&&K.push("/")),B.path!==void 0){var he=B.path;!v.absolutePath&&(!H||!H.absolutePath)&&(he=yo(he)),te===void 0&&(he=he.replace(/^\/\//,"/%2F")),K.push(he)}return B.query!==void 0&&(K.push("?"),K.push(B.query)),B.fragment!==void 0&&(K.push("#"),K.push(B.fragment)),K.join("")}function hu(B,v){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},K=arguments[3],H={};return K||(B=Et(Fr(B,k),k),v=Et(Fr(v,k),k)),k=k||{},!k.tolerant&&v.scheme?(H.scheme=v.scheme,H.userinfo=v.userinfo,H.host=v.host,H.port=v.port,H.path=yo(v.path||""),H.query=v.query):(v.userinfo!==void 0||v.host!==void 0||v.port!==void 0?(H.userinfo=v.userinfo,H.host=v.host,H.port=v.port,H.path=yo(v.path||""),H.query=v.query):(v.path?(v.path.charAt(0)==="/"?H.path=yo(v.path):((B.userinfo!==void 0||B.host!==void 0||B.port!==void 0)&&!B.path?H.path="/"+v.path:B.path?H.path=B.path.slice(0,B.path.lastIndexOf("/")+1)+v.path:H.path=v.path,H.path=yo(H.path)),H.query=v.query):(H.path=B.path,v.query!==void 0?H.query=v.query:H.query=B.query),H.userinfo=B.userinfo,H.host=B.host,H.port=B.port),H.scheme=B.scheme),H.fragment=v.fragment,H}function bf(B,v,k){var K=s({scheme:"null"},k);return Fr(hu(Et(B,K),Et(v,K),K,!0),K)}function pu(B,v){return typeof B=="string"?B=Fr(Et(B,v),v):n(B)==="object"&&(B=Et(Fr(B,v),v)),B}function xf(B,v,k){return typeof B=="string"?B=Fr(Et(B,k),k):n(B)==="object"&&(B=Fr(B,k)),typeof v=="string"?v=Fr(Et(v,k),k):n(v)==="object"&&(v=Fr(v,k)),B===v}function Ef(B,v){return B&&B.toString().replace(!v||!v.iri?a.ESCAPE:u.ESCAPE,Y)}function jr(B,v){return B&&B.toString().replace(!v||!v.iri?a.PCT_ENCODED:u.PCT_ENCODED,X)}var go={scheme:"http",domainHost:!0,parse:function(v,k){return v.host||(v.error=v.error||"HTTP URIs must have a host."),v},serialize:function(v,k){var K=String(v.scheme).toLowerCase()==="https";return(v.port===(K?443:80)||v.port==="")&&(v.port=void 0),v.path||(v.path="/"),v}},yu={scheme:"https",domainHost:go.domainHost,parse:go.parse,serialize:go.serialize};function vf(B){return typeof B.secure=="boolean"?B.secure:String(B.scheme).toLowerCase()==="wss"}var ls={scheme:"ws",domainHost:!0,parse:function(v,k){var K=v;return K.secure=vf(K),K.resourceName=(K.path||"/")+(K.query?"?"+K.query:""),K.path=void 0,K.query=void 0,K},serialize:function(v,k){if((v.port===(vf(v)?443:80)||v.port==="")&&(v.port=void 0),typeof v.secure=="boolean"&&(v.scheme=v.secure?"wss":"ws",v.secure=void 0),v.resourceName){var K=v.resourceName.split("?"),H=d(K,2),te=H[0],he=H[1];v.path=te&&te!=="/"?te:void 0,v.query=he,v.resourceName=void 0}return v.fragment=void 0,v}},Sf={scheme:"wss",domainHost:ls.domainHost,parse:ls.parse,serialize:ls.serialize},ty={},YI=!0,Qb="[A-Za-z0-9\\-\\.\\_\\~"+(YI?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",Pn="[0-9A-Fa-f]",JI=r(r("%[EFef]"+Pn+"%"+Pn+Pn+"%"+Pn+Pn)+"|"+r("%[89A-Fa-f]"+Pn+"%"+Pn+Pn)+"|"+r("%"+Pn+Pn)),XI="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",ZI="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",QI=e(ZI,'[\\"\\\\]'),eB="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",tB=new RegExp(Qb,"g"),Sc=new RegExp(JI,"g"),rB=new RegExp(e("[^]",XI,"[\\.]",'[\\"]',QI),"g"),ex=new RegExp(e("[^]",Qb,eB),"g"),nB=ex;function ry(B){var v=X(B);return v.match(tB)?v:B}var tx={scheme:"mailto",parse:function(v,k){var K=v,H=K.to=K.path?K.path.split(","):[];if(K.path=void 0,K.query){for(var te=!1,he={},Te=K.query.split("&"),De=0,wt=Te.length;De<wt;++De){var Ae=Te[De].split("=");switch(Ae[0]){case"to":for(var tt=Ae[1].split(","),bt=0,Xe=tt.length;bt<Xe;++bt)H.push(tt[bt]);break;case"subject":K.subject=jr(Ae[1],k);break;case"body":K.body=jr(Ae[1],k);break;default:te=!0,he[jr(Ae[0],k)]=jr(Ae[1],k);break}}te&&(K.headers=he)}K.query=void 0;for(var Ie=0,rt=H.length;Ie<rt;++Ie){var Ne=H[Ie].split("@");if(Ne[0]=jr(Ne[0]),k.unicodeSupport)Ne[1]=jr(Ne[1],k).toLowerCase();else try{Ne[1]=z.toASCII(jr(Ne[1],k).toLowerCase())}catch(hs){K.error=K.error||"Email address's domain name can not be converted to ASCII via punycode: "+hs}H[Ie]=Ne.join("@")}return K},serialize:function(v,k){var K=v,H=o(v.to);if(H){for(var te=0,he=H.length;te<he;++te){var Te=String(H[te]),De=Te.lastIndexOf("@"),wt=Te.slice(0,De).replace(Sc,ry).replace(Sc,i).replace(rB,Y),Ae=Te.slice(De+1);try{Ae=k.iri?z.toUnicode(Ae):z.toASCII(jr(Ae,k).toLowerCase())}catch(Ie){K.error=K.error||"Email address's domain name can not be converted to "+(k.iri?"Unicode":"ASCII")+" via punycode: "+Ie}H[te]=wt+"@"+Ae}K.path=H.join(",")}var tt=v.headers=v.headers||{};v.subject&&(tt.subject=v.subject),v.body&&(tt.body=v.body);var bt=[];for(var Xe in tt)tt[Xe]!==ty[Xe]&&bt.push(Xe.replace(Sc,ry).replace(Sc,i).replace(ex,Y)+"="+tt[Xe].replace(Sc,ry).replace(Sc,i).replace(nB,Y));return bt.length&&(K.query=bt.join("&")),K}},iB=/^([^\:]+)\:(.*)/,rx={scheme:"urn",parse:function(v,k){var K=v.path&&v.path.match(iB),H=v;if(K){var te=k.scheme||H.scheme||"urn",he=K[1].toLowerCase(),Te=K[2],De=te+":"+(k.nid||he),wt=W[De];H.nid=he,H.nss=Te,H.path=void 0,wt&&(H=wt.parse(H,k))}else H.error=H.error||"URN can not be parsed.";return H},serialize:function(v,k){var K=k.scheme||v.scheme||"urn",H=v.nid,te=K+":"+(k.nid||H),he=W[te];he&&(v=he.serialize(v,k));var Te=v,De=v.nss;return Te.path=(H||k.nid)+":"+De,Te}},oB=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,nx={scheme:"urn:uuid",parse:function(v,k){var K=v;return K.uuid=K.nss,K.nss=void 0,!k.tolerant&&(!K.uuid||!K.uuid.match(oB))&&(K.error=K.error||"UUID is not valid."),K},serialize:function(v,k){var K=v;return K.nss=(v.uuid||"").toLowerCase(),K}};W[go.scheme]=go,W[yu.scheme]=yu,W[ls.scheme]=ls,W[Sf.scheme]=Sf,W[tx.scheme]=tx,W[rx.scheme]=rx,W[nx.scheme]=nx,t.SCHEMES=W,t.pctEncChar=Y,t.pctDecChars=X,t.parse=Et,t.removeDotSegments=yo,t.serialize=Fr,t.resolveComponents=hu,t.resolve=bf,t.normalize=pu,t.equal=xf,t.escapeComponent=Ef,t.unescapeComponent=jr,Object.defineProperty(t,"__esModule",{value:!0})})});var q_=oe((WX,V_)=>{"use strict";l();V_.exports=function t(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?t(e.toJSON()):Array.isArray(e)?`[${e.reduce((i,o,s)=>`${i}${s===0?"":","}${t(o===void 0||typeof o=="symbol"?null:o)}`,"")}]`:`{${Object.keys(e).sort().reduce((n,i)=>{if(e[i]===void 0||typeof e[i]=="symbol")return n;let o=n.length===0?"":",";return`${n}${o}${t(i)}:${t(e[i])}`},"")}}`}});var rI=oe((YQ,tI)=>{l();var eu=1e3,tu=eu*60,ru=tu*60,bc=ru*24,JC=bc*7,XC=bc*365.25;tI.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return ZC(t);if(r==="number"&&isFinite(t))return e.long?eL(t):QC(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function ZC(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*XC;case"weeks":case"week":case"w":return r*JC;case"days":case"day":case"d":return r*bc;case"hours":case"hour":case"hrs":case"hr":case"h":return r*ru;case"minutes":case"minute":case"mins":case"min":case"m":return r*tu;case"seconds":case"second":case"secs":case"sec":case"s":return r*eu;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function QC(t){var e=Math.abs(t);return e>=bc?Math.round(t/bc)+"d":e>=ru?Math.round(t/ru)+"h":e>=tu?Math.round(t/tu)+"m":e>=eu?Math.round(t/eu)+"s":t+"ms"}function eL(t){var e=Math.abs(t);return e>=bc?$p(t,e,bc,"day"):e>=ru?$p(t,e,ru,"hour"):e>=tu?$p(t,e,tu,"minute"):e>=eu?$p(t,e,eu,"second"):t+" ms"}function $p(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});l();l();l();l();var bs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function xs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Eu(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function yn(t,...e){if(!xs(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Df(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Eu(t.outputLen),Eu(t.blockLen)}function Nc(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Rx(t,e){yn(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Fn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function kf(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function gn(t,e){return t<<32-e|t>>>e}function vu(t,e){return t<<e|t>>>32-e>>>0}var Ux=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ZB=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Mt(t){if(yn(t),Ux)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ZB[t[r]];return e}var Si={_0:48,_9:57,A:65,F:70,a:97,f:102};function Bx(t){if(t>=Si._0&&t<=Si._9)return t-Si._0;if(t>=Si.A&&t<=Si.F)return t-(Si.A-10);if(t>=Si.a&&t<=Si.f)return t-(Si.a-10)}function Ir(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Ux)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=Bx(t.charCodeAt(o)),c=Bx(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function Es(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Su(t){return typeof t=="string"&&(t=Es(t)),yn(t),t}function ht(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];yn(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var kc=class{};function Nf(t){let e=n=>t().update(Su(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Br(t=32){if(bs&&typeof bs.getRandomValues=="function")return bs.getRandomValues(new Uint8Array(t));if(bs&&typeof bs.randomBytes=="function")return Uint8Array.from(bs.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}l();l();l();l();l();function QB(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}function my(t,e,r){return t&e^~t&r}function wy(t,e,r){return t&e^t&r^e&r}var Cc=class extends kc{constructor(e,r,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=kf(this.buffer)}update(e){Nc(this),e=Su(e),yn(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=kf(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Nc(this),Rx(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,Fn(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;QB(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=kf(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=c,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Ai=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var e8=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]),mo=new Uint32Array(64),by=class extends Cc{constructor(e=32){super(64,e,8,!1),this.A=Ai[0]|0,this.B=Ai[1]|0,this.C=Ai[2]|0,this.D=Ai[3]|0,this.E=Ai[4]|0,this.F=Ai[5]|0,this.G=Ai[6]|0,this.H=Ai[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)mo[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=mo[f-15],p=mo[f-2],g=gn(h,7)^gn(h,18)^h>>>3,y=gn(p,17)^gn(p,19)^p>>>10;mo[f]=y+mo[f-7]+g+mo[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=gn(c,6)^gn(c,11)^gn(c,25),p=d+h+my(c,a,u)+e8[f]+mo[f]|0,y=(gn(n,2)^gn(n,13)^gn(n,22))+wy(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Fn(mo)}destroy(){this.set(0,0,0,0,0,0,0,0),Fn(this.buffer)}};var ke=Nf(()=>new by);l();l();l();var Cf=class extends kc{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Df(e);let n=Su(r);if(this.iHash=e.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;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Fn(o)}update(e){return Nc(this),this.iHash.update(e),this}digestInto(e){Nc(this),yn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xy=(t,e,r)=>new Cf(t,e).update(r).digest();xy.create=(t,e)=>new Cf(t,e);l();var Sy=BigInt(0),vy=BigInt(1);function Au(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function wo(t,e,r=""){let n=xs(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Tu(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Ox(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Sy:BigInt("0x"+t)}function Ti(t){return Ox(Mt(t))}function Ay(t){return yn(t),Ox(Mt(Uint8Array.from(t).reverse()))}function Lc(t,e){return Ir(t.toString(16).padStart(e*2,"0"))}function Ty(t,e){return Lc(t,e).reverse()}function ct(t,e,r){let n;if(typeof e=="string")try{n=Ir(e)}catch(o){throw new Error(t+" must be hex string or Uint8Array, cause: "+o)}else if(xs(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(t+" of length "+r+" expected, got "+i);return n}function bo(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}var Ey=t=>typeof t=="bigint"&&Sy<=t;function _u(t,e,r){return Ey(t)&&Ey(e)&&Ey(r)&&e<=t&&t<r}function Dx(t,e,r,n){if(!_u(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Lf(t){let e;for(e=0;t>Sy;t>>=vy,e+=1);return e}var xo=t=>(vy<<BigInt(t))-vy;function kx(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),i=p=>Uint8Array.of(p),o=n(t),s=n(t),c=0,a=()=>{o.fill(1),s.fill(0),c=0},u=(...p)=>r(s,o,...p),d=(p=n(0))=>{s=u(i(0),p),o=u(),p.length!==0&&(s=u(i(1),p),o=u())},f=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,g=[];for(;p<e;){o=u();let y=o.slice();g.push(y),p+=o.length}return ht(...g)};return(p,g)=>{a(),d(p);let y;for(;!(y=g(f()));)d();return a(),y}}function Iu(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(i,o,s){let c=t[i];if(s&&c===void 0)return;let a=typeof c;if(a!==o||c===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${a}`)}Object.entries(e).forEach(([i,o])=>n(i,o,!1)),Object.entries(r).forEach(([i,o])=>n(i,o,!0))}function _y(t){let e=new WeakMap;return(r,...n)=>{let i=e.get(r);if(i!==void 0)return i;let o=t(r,...n);return e.set(r,o),o}}l();l();var rr=BigInt(0),Wt=BigInt(1),vs=BigInt(2),Lx=BigInt(3),Px=BigInt(4),Mx=BigInt(5),t8=BigInt(7),Kx=BigInt(8),r8=BigInt(9),$x=BigInt(16);function Rr(t,e){let r=t%e;return r>=rr?r:e+r}function Ur(t,e,r){let n=t;for(;e-- >rr;)n*=n,n%=r;return n}function Nx(t,e){if(t===rr)throw new Error("invert: expected non-zero number");if(e<=rr)throw new Error("invert: expected positive modulus, got "+e);let r=Rr(t,e),n=e,i=rr,o=Wt,s=Wt,c=rr;for(;r!==rr;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==Wt)throw new Error("invert: does not exist");return Rr(i,e)}function Iy(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function Hx(t,e){let r=(t.ORDER+Wt)/Px,n=t.pow(e,r);return Iy(t,n,e),n}function n8(t,e){let r=(t.ORDER-Mx)/Kx,n=t.mul(e,vs),i=t.pow(n,r),o=t.mul(e,i),s=t.mul(t.mul(o,vs),i),c=t.mul(o,t.sub(s,t.ONE));return Iy(t,c,e),c}function i8(t){let e=Eo(t),r=Vx(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),s=(t+t8)/$x;return(c,a)=>{let u=c.pow(a,s),d=c.mul(u,n),f=c.mul(u,i),h=c.mul(u,o),p=c.eql(c.sqr(d),a),g=c.eql(c.sqr(f),a);u=c.cmov(u,d,p),d=c.cmov(h,f,g);let y=c.eql(c.sqr(d),a),x=c.cmov(u,d,y);return Iy(c,x,a),x}}function Vx(t){if(t<Lx)throw new Error("sqrt is not defined for small field");let e=t-Wt,r=0;for(;e%vs===rr;)e/=vs,r++;let n=vs,i=Eo(t);for(;Cx(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Hx;let o=i.pow(n,e),s=(e+Wt)/vs;return function(a,u){if(a.is0(u))return u;if(Cx(a,u)!==1)throw new Error("Cannot find square root");let d=r,f=a.mul(a.ONE,o),h=a.pow(u,e),p=a.pow(u,s);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,y=a.sqr(h);for(;!a.eql(y,a.ONE);)if(g++,y=a.sqr(y),g===d)throw new Error("Cannot find square root");let x=Wt<<BigInt(d-g-1),S=a.pow(f,x);d=g,f=a.sqr(S),h=a.mul(h,f),p=a.mul(p,S)}return p}}function o8(t){return t%Px===Lx?Hx:t%Kx===Mx?n8:t%$x===r8?i8(t):Vx(t)}var s8=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function By(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=s8.reduce((n,i)=>(n[i]="function",n),e);return Iu(t,r),t}function c8(t,e,r){if(r<rr)throw new Error("invalid exponent, negatives unsupported");if(r===rr)return t.ONE;if(r===Wt)return e;let n=t.ONE,i=e;for(;r>rr;)r&Wt&&(n=t.mul(n,i)),i=t.sqr(i),r>>=Wt;return n}function Pf(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),i=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),o=t.inv(i);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),o),n}function Cx(t,e){let r=(t.ORDER-Wt)/vs,n=t.pow(e,r),i=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Mf(t,e){e!==void 0&&Eu(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Eo(t,e,r=!1,n={}){if(t<=rr)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,o,s=!1,c;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(i=h.BITS),h.sqrt&&(o=h.sqrt),typeof h.isLE=="boolean"&&(r=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),c=h.allowedLengths}else typeof e=="number"&&(i=e),n.sqrt&&(o=n.sqrt);let{nBitLength:a,nByteLength:u}=Mf(t,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,f=Object.freeze({ORDER:t,isLE:r,BITS:a,BYTES:u,MASK:xo(a),ZERO:rr,ONE:Wt,allowedLengths:c,create:h=>Rr(h,t),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return rr<=h&&h<t},is0:h=>h===rr,isValidNot0:h=>!f.is0(h)&&f.isValid(h),isOdd:h=>(h&Wt)===Wt,neg:h=>Rr(-h,t),eql:(h,p)=>h===p,sqr:h=>Rr(h*h,t),add:(h,p)=>Rr(h+p,t),sub:(h,p)=>Rr(h-p,t),mul:(h,p)=>Rr(h*p,t),pow:(h,p)=>c8(f,h,p),div:(h,p)=>Rr(h*Nx(p,t),t),sqrN:h=>h*h,addN:(h,p)=>h+p,subN:(h,p)=>h-p,mulN:(h,p)=>h*p,inv:h=>Nx(h,t),sqrt:o||(h=>(d||(d=o8(t)),d(f,h))),toBytes:h=>r?Ty(h,u):Lc(h,u),fromBytes:(h,p=!0)=>{if(c){if(!c.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+h.length);let y=new Uint8Array(u);y.set(h,r?0:y.length-h.length),h=y}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let g=r?Ay(h):Ti(h);if(s&&(g=Rr(g,t)),!p&&!f.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:h=>Pf(f,h),cmov:(h,p,g)=>g?p:h});return Object.freeze(f)}function qx(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ry(t){let e=qx(t);return e+Math.ceil(e/2)}function Kf(t,e,r=!1){let n=t.length,i=qx(e),o=Ry(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let s=r?Ay(t):Ti(t),c=Rr(s,e-Wt)+Wt;return r?Ty(c,i):Lc(c,i)}var Pc=BigInt(0),Ss=BigInt(1);function Bu(t,e){let r=e.negate();return t?r:e}function Hf(t,e){let r=Pf(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Gx(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Uy(t,e){Gx(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=xo(t),s=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function Fx(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r,c=Number(t&i),a=t>>s;c>n&&(c-=o,a+=Ss);let u=e*n,d=u+Math.abs(c)-1,f=c===0,h=c<0,p=e%2!==0;return{nextN:a,offset:d,isZero:f,isNeg:h,isNegF:p,offsetF:u}}function a8(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function u8(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Oy=new WeakMap,zx=new WeakMap;function Dy(t){return zx.get(t)||1}function jx(t){if(t!==Pc)throw new Error("invalid wNAF")}var $f=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>Pc;)r&Ss&&(n=n.add(i)),i=i.double(),r>>=Ss;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=Uy(r,this.bits),o=[],s=e,c=s;for(let a=0;a<n;a++){c=s,o.push(c);for(let u=1;u<i;u++)c=c.add(s),o.push(c);s=c.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=Uy(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:p}=Fx(n,c,s);n=a,d?o=o.add(Bu(h,r[p])):i=i.add(Bu(f,r[u]))}return jx(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=Uy(e,this.bits);for(let s=0;s<o.windows&&n!==Pc;s++){let{nextN:c,offset:a,isZero:u,isNeg:d}=Fx(n,s,o);if(n=c,!u){let f=r[a];i=i.add(d?f.negate():f)}}return jx(n),i}getPrecomputes(e,r,n){let i=Oy.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),Oy.set(r,i))),i}cached(e,r,n){let i=Dy(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=Dy(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){Gx(r,this.bits),zx.set(e,r),Oy.delete(e)}hasCache(e){return Dy(e)!==1}};function Yx(t,e,r,n){let i=e,o=t.ZERO,s=t.ZERO;for(;r>Pc||n>Pc;)r&Ss&&(o=o.add(i)),n&Ss&&(s=s.add(i)),i=i.double(),r>>=Ss,n>>=Ss;return{p1:o,p2:s}}function Jx(t,e,r,n){a8(r,t),u8(n,e);let i=r.length,o=n.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let s=t.ZERO,c=Lf(BigInt(i)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=xo(a),d=new Array(Number(u)+1).fill(s),f=Math.floor((e.BITS-1)/a)*a,h=s;for(let p=f;p>=0;p-=a){d.fill(s);for(let y=0;y<o;y++){let x=n[y],S=Number(x>>BigInt(p)&u);d[S]=d[S].add(r[y])}let g=s;for(let y=d.length-1,x=s;y>0;y--)x=x.add(d[y]),g=g.add(x);if(h=h.add(g),p!==0)for(let y=0;y<a;y++)h=h.double()}return h}function Wx(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return By(e),e}else return Eo(t,{isLE:r})}function Xx(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>Pc))throw new Error(`CURVE.${a} must be positive bigint`)}let i=Wx(e.p,r.Fp,n),o=Wx(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}var Zx=(t,e)=>(t+(t>=0?e:-e)/Qx)/e;function d8(t,e,r){let[[n,i],[o,s]]=e,c=Zx(s*t,r),a=Zx(-i*t,r),u=t-c*n-a*o,d=-c*i-a*s,f=u<Ii,h=d<Ii;f&&(u=-u),h&&(d=-d);let p=xo(Math.ceil(Lf(r)/2))+Mc;if(u<Ii||u>=p||d<Ii||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}function Ny(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ky(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Au(r.lowS,"lowS"),Au(r.prehash,"prehash"),r.format!==void 0&&Ny(r.format),r}var Cy=class extends Error{constructor(e=""){super(e)}},_i={Err:Cy,_tlv:{encode:(t,e)=>{let{Err:r}=_i;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=Tu(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Tu(i.length/2|128):"";return Tu(t)+o+i+e},decode(t,e){let{Err:r}=_i,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),s=0;if(!o)s=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)s=s<<8|d;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=_i;if(t<Ii)throw new e("integer: negative integers are not allowed");let r=Tu(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=_i;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ti(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=_i,i=ct("signature",t),{v:o,l:s}=n.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:u,l:d}=n.decode(2,a);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=_i,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}},Ii=BigInt(0),Mc=BigInt(1),Qx=BigInt(2),Vf=BigInt(3),f8=BigInt(4);function vo(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let i=ct("private key",e);try{n=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function l8(t,e={}){let r=Xx("weierstrass",t,e),{Fp:n,Fn:i}=r,o=r.CURVE,{h:s,n:c}=o;Iu(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=e;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=tE(n,i);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(G,_,D){let{x:E,y:U}=_.toAffine(),L=n.toBytes(E);if(Au(D,"isCompressed"),D){d();let N=!n.isOdd(U);return ht(eE(N),L)}else return ht(Uint8Array.of(4),L,n.toBytes(U))}function h(G){wo(G,void 0,"Point");let{publicKey:_,publicKeyUncompressed:D}=u,E=G.length,U=G[0],L=G.subarray(1);if(E===_&&(U===2||U===3)){let N=n.fromBytes(L);if(!n.isValid(N))throw new Error("bad point: is not on curve, wrong x");let R=y(N),C;try{C=n.sqrt(R)}catch(J){let z=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let P=n.isOdd(C);return(U&1)===1!==P&&(C=n.neg(C)),{x:N,y:C}}else if(E===D&&U===4){let N=n.BYTES,R=n.fromBytes(L.subarray(0,N)),C=n.fromBytes(L.subarray(N,N*2));if(!x(R,C))throw new Error("bad point: is not on curve");return{x:R,y:C}}else throw new Error(`bad point: got length ${E}, expected compressed=${_} or uncompressed=${D}`)}let p=e.toBytes||f,g=e.fromBytes||h;function y(G){let _=n.sqr(G),D=n.mul(_,G);return n.add(n.add(D,n.mul(G,o.a)),o.b)}function x(G,_){let D=n.sqr(_),E=y(G);return n.eql(D,E)}if(!x(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(o.a,Vf),f8),I=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(S,I)))throw new Error("bad curve params: a or b");function A(G,_,D=!1){if(!n.isValid(_)||D&&n.is0(_))throw new Error(`bad point coordinate ${G}`);return _}function O(G){if(!(G instanceof $))throw new Error("ProjectivePoint expected")}function T(G){if(!a||!a.basises)throw new Error("no endo");return d8(G,a.basises,i.ORDER)}let M=_y((G,_)=>{let{X:D,Y:E,Z:U}=G;if(n.eql(U,n.ONE))return{x:D,y:E};let L=G.is0();_==null&&(_=L?n.ONE:n.inv(U));let N=n.mul(D,_),R=n.mul(E,_),C=n.mul(U,_);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),q=_y(G=>{if(G.is0()){if(e.allowInfinityPoint&&!n.is0(G.Y))return;throw new Error("bad point: ZERO")}let{x:_,y:D}=G.toAffine();if(!n.isValid(_)||!n.isValid(D))throw new Error("bad point: x or y not field elements");if(!x(_,D))throw new Error("bad point: equation left != right");if(!G.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function j(G,_,D,E,U){return D=new $(n.mul(D.X,G),D.Y,D.Z),_=Bu(E,_),D=Bu(U,D),_.add(D)}class ${constructor(_,D,E){this.X=A("x",_),this.Y=A("y",D,!0),this.Z=A("z",E),Object.freeze(this)}static CURVE(){return o}static fromAffine(_){let{x:D,y:E}=_||{};if(!_||!n.isValid(D)||!n.isValid(E))throw new Error("invalid affine point");if(_ instanceof $)throw new Error("projective point not allowed");return n.is0(D)&&n.is0(E)?$.ZERO:new $(D,E,n.ONE)}static fromBytes(_){let D=$.fromAffine(g(wo(_,void 0,"point")));return D.assertValidity(),D}static fromHex(_){return $.fromBytes(ct("pointHex",_))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,D=!0){return Q.createCache(this,_),D||this.multiply(Vf),this}assertValidity(){q(this)}hasEvenY(){let{y:_}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(_)}equals(_){O(_);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=_,C=n.eql(n.mul(D,R),n.mul(L,U)),P=n.eql(n.mul(E,R),n.mul(N,U));return C&&P}negate(){return new $(this.X,n.neg(this.Y),this.Z)}double(){let{a:_,b:D}=o,E=n.mul(D,Vf),{X:U,Y:L,Z:N}=this,R=n.ZERO,C=n.ZERO,P=n.ZERO,V=n.mul(U,U),J=n.mul(L,L),z=n.mul(N,N),W=n.mul(U,L);return W=n.add(W,W),P=n.mul(U,N),P=n.add(P,P),R=n.mul(_,P),C=n.mul(E,z),C=n.add(R,C),R=n.sub(J,C),C=n.add(J,C),C=n.mul(R,C),R=n.mul(W,R),P=n.mul(E,P),z=n.mul(_,z),W=n.sub(V,z),W=n.mul(_,W),W=n.add(W,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,z),V=n.mul(V,W),C=n.add(C,V),z=n.mul(L,N),z=n.add(z,z),V=n.mul(z,W),R=n.sub(R,V),P=n.mul(z,J),P=n.add(P,P),P=n.add(P,P),new $(R,C,P)}add(_){O(_);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=_,C=n.ZERO,P=n.ZERO,V=n.ZERO,J=o.a,z=n.mul(o.b,Vf),W=n.mul(D,L),Y=n.mul(E,N),X=n.mul(U,R),ue=n.add(D,E),ee=n.add(L,N);ue=n.mul(ue,ee),ee=n.add(W,Y),ue=n.sub(ue,ee),ee=n.add(D,U);let ce=n.add(L,R);return ee=n.mul(ee,ce),ce=n.add(W,X),ee=n.sub(ee,ce),ce=n.add(E,U),C=n.add(N,R),ce=n.mul(ce,C),C=n.add(Y,X),ce=n.sub(ce,C),V=n.mul(J,ee),C=n.mul(z,X),V=n.add(C,V),C=n.sub(Y,V),V=n.add(Y,V),P=n.mul(C,V),Y=n.add(W,W),Y=n.add(Y,W),X=n.mul(J,X),ee=n.mul(z,ee),Y=n.add(Y,X),X=n.sub(W,X),X=n.mul(J,X),ee=n.add(ee,X),W=n.mul(Y,ee),P=n.add(P,W),W=n.mul(ce,ee),C=n.mul(ue,C),C=n.sub(C,W),W=n.mul(ue,Y),V=n.mul(ce,V),V=n.add(V,W),new $(C,P,V)}subtract(_){return this.add(_.negate())}is0(){return this.equals($.ZERO)}multiply(_){let{endo:D}=e;if(!i.isValidNot0(_))throw new Error("invalid scalar: out of range");let E,U,L=N=>Q.cached(this,N,R=>Hf($,R));if(D){let{k1neg:N,k1:R,k2neg:C,k2:P}=T(_),{p:V,f:J}=L(R),{p:z,f:W}=L(P);U=J.add(W),E=j(D.beta,V,z,N,C)}else{let{p:N,f:R}=L(_);E=N,U=R}return Hf($,[E,U])[0]}multiplyUnsafe(_){let{endo:D}=e,E=this;if(!i.isValid(_))throw new Error("invalid scalar: out of range");if(_===Ii||E.is0())return $.ZERO;if(_===Mc)return E;if(Q.hasCache(this))return this.multiply(_);if(D){let{k1neg:U,k1:L,k2neg:N,k2:R}=T(_),{p1:C,p2:P}=Yx($,E,L,R);return j(D.beta,C,P,U,N)}else return Q.unsafe(E,_)}multiplyAndAddUnsafe(_,D,E){let U=this.multiplyUnsafe(D).add(_.multiplyUnsafe(E));return U.is0()?void 0:U}toAffine(_){return M(this,_)}isTorsionFree(){let{isTorsionFree:_}=e;return s===Mc?!0:_?_($,this):Q.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:_}=e;return s===Mc?this:_?_($,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(_=!0){return Au(_,"isCompressed"),this.assertValidity(),p($,this,_)}toHex(_=!0){return Mt(this.toBytes(_))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(_=!0){return this.toBytes(_)}_setWindowSize(_){this.precompute(_)}static normalizeZ(_){return Hf($,_)}static msm(_,D){return Jx($,i,_,D)}static fromPrivateKey(_){return $.BASE.multiply(vo(i,_))}}$.BASE=new $(o.Gx,o.Gy,n.ONE),$.ZERO=new $(n.ZERO,n.ONE,n.ZERO),$.Fp=n,$.Fn=i;let Z=i.BITS,Q=new $f($,e.endo?Math.ceil(Z/2):Z);return $.BASE.precompute(8),$}function eE(t){return Uint8Array.of(t?2:3)}function tE(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function h8(t,e={}){let{Fn:r}=t,n=e.randomBytes||Br,i=Object.assign(tE(t.Fp,r),{seed:Ry(r.ORDER)});function o(p){try{return!!vo(r,p)}catch{return!1}}function s(p,g){let{publicKey:y,publicKeyUncompressed:x}=i;try{let S=p.length;return g===!0&&S!==y||g===!1&&S!==x?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(i.seed)){return Kf(wo(p,i.seed,"seed"),r.ORDER)}function a(p,g=!0){return t.BASE.multiply(vo(r,p)).toBytes(g)}function u(p){let g=c(p);return{secretKey:g,publicKey:a(g)}}function d(p){if(typeof p=="bigint")return!1;if(p instanceof t)return!0;let{secretKey:g,publicKey:y,publicKeyUncompressed:x}=i;if(r.allowedLengths||g===y)return;let S=ct("key",p).length;return S===y||S===x}function f(p,g,y=!0){if(d(p)===!0)throw new Error("first arg must be private key");if(d(g)===!1)throw new Error("second arg must be public key");let x=vo(r,p);return t.fromHex(g).multiply(x).toBytes(y)}return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:u,Point:t,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:o,randomPrivateKey:c,normPrivateKeyToScalar:p=>vo(r,p),precompute(p=8,g=t.BASE){return g.precompute(p,!1)}},lengths:i})}function p8(t,e,r={}){Df(e),Iu(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Br,i=r.hmac||((D,...E)=>xy(e,D,ht(...E))),{Fp:o,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p}=h8(t,r),g={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function x(D){let E=c>>Mc;return D>E}function S(D,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${D}: out of range 1..Point.Fn.ORDER`);return E}function I(D,E){Ny(E);let U=p.signature,L=E==="compact"?U:E==="recovered"?U+1:void 0;return wo(D,L,`${E} signature`)}class A{constructor(E,U,L){this.r=S("r",E),this.s=S("s",U),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(E,U=y){I(E,U);let L;if(U==="der"){let{r:P,s:V}=_i.toSig(wo(E));return new A(P,V)}U==="recovered"&&(L=E[0],U="compact",E=E.subarray(1));let N=s.BYTES,R=E.subarray(0,N),C=E.subarray(N,N*2);return new A(s.fromBytes(R),s.fromBytes(C),L)}static fromHex(E,U){return this.fromBytes(Ir(E),U)}addRecoveryBit(E){return new A(this.r,this.s,E)}recoverPublicKey(E){let U=o.ORDER,{r:L,s:N,recovery:R}=this;if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");if(c*Qx<U&&R>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=R===2||R===3?L+c:L;if(!o.isValid(P))throw new Error("recovery id 2 or 3 invalid");let V=o.toBytes(P),J=t.fromBytes(ht(eE((R&1)===0),V)),z=s.inv(P),W=T(ct("msgHash",E)),Y=s.create(-W*z),X=s.create(N*z),ue=t.BASE.multiplyUnsafe(Y).add(J.multiplyUnsafe(X));if(ue.is0())throw new Error("point at infinify");return ue.assertValidity(),ue}hasHighS(){return x(this.s)}toBytes(E=y){if(Ny(E),E==="der")return Ir(_i.hexFromSig(this));let U=s.toBytes(this.r),L=s.toBytes(this.s);if(E==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),U,L)}return ht(U,L)}toHex(E){return Mt(this.toBytes(E))}assertValidity(){}static fromCompact(E){return A.fromBytes(ct("sig",E),"compact")}static fromDER(E){return A.fromBytes(ct("sig",E),"der")}normalizeS(){return this.hasHighS()?new A(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Mt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Mt(this.toBytes("compact"))}}let O=r.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let U=Ti(E),L=E.length*8-a;return L>0?U>>BigInt(L):U},T=r.bits2int_modN||function(E){return s.create(O(E))},M=xo(a);function q(D){return Dx("num < 2^"+a,D,Ii,M),s.toBytes(D)}function j(D,E){return wo(D,void 0,"message"),E?wo(e(D),void 0,"prehashed message"):D}function $(D,E,U){if(["recovered","canonical"].some(Y=>Y in U))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:N,extraEntropy:R}=ky(U,g);D=j(D,N);let C=T(D),P=vo(s,E),V=[q(P),q(C)];if(R!=null&&R!==!1){let Y=R===!0?n(p.secretKey):R;V.push(ct("extraEntropy",Y))}let J=ht(...V),z=C;function W(Y){let X=O(Y);if(!s.isValidNot0(X))return;let ue=s.inv(X),ee=t.BASE.multiply(X).toAffine(),ce=s.create(ee.x);if(ce===Ii)return;let Oe=s.create(ue*s.create(z+ce*P));if(Oe===Ii)return;let Me=(ee.x===ce?0:2)|Number(ee.y&Mc),Je=Oe;return L&&x(Oe)&&(Je=s.neg(Oe),Me^=1),new A(ce,Je,Me)}return{seed:J,k2sig:W}}function Z(D,E,U={}){D=ct("message",D);let{seed:L,k2sig:N}=$(D,E,U);return kx(e.outputLen,s.BYTES,i)(L,N)}function Q(D){let E,U=typeof D=="string"||xs(D),L=!U&&D!==null&&typeof D=="object"&&typeof D.r=="bigint"&&typeof D.s=="bigint";if(!U&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)E=new A(D.r,D.s);else if(U){try{E=A.fromBytes(ct("sig",D),"der")}catch(N){if(!(N instanceof _i.Err))throw N}if(!E)try{E=A.fromBytes(ct("sig",D),"compact")}catch{return!1}}return E||!1}function G(D,E,U,L={}){let{lowS:N,prehash:R,format:C}=ky(L,g);if(U=ct("publicKey",U),E=j(ct("message",E),R),"strict"in L)throw new Error("options.strict was renamed to lowS");let P=C===void 0?Q(D):A.fromBytes(ct("sig",D),C);if(P===!1)return!1;try{let V=t.fromBytes(U);if(N&&P.hasHighS())return!1;let{r:J,s:z}=P,W=T(E),Y=s.inv(z),X=s.create(W*Y),ue=s.create(J*Y),ee=t.BASE.multiplyUnsafe(X).add(V.multiplyUnsafe(ue));return ee.is0()?!1:s.create(ee.x)===J}catch{return!1}}function _(D,E,U={}){let{prehash:L}=ky(U,g);return E=j(E,L),A.fromBytes(D,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p,Point:t,sign:Z,verify:G,recoverPublicKey:_,Signature:A,hash:e})}function y8(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,i=Eo(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),o={Fp:r,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:o}}function g8(t){let{CURVE:e,curveOpts:r}=y8(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function m8(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,Mf(r.Fn.ORDER,r.Fn.BITS))})}function rE(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:i}=g8(t),o=l8(e,r),s=p8(o,n,i);return m8(t,s)}function nE(t,e){let r=n=>rE({...t,hash:n});return{...r(e),create:r}}var Kc={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},w8={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},b8=BigInt(0),iE=BigInt(1),Ly=BigInt(2);function x8(t){let e=Kc.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=Ur(d,r,e)*d%e,h=Ur(f,r,e)*d%e,p=Ur(h,Ly,e)*u%e,g=Ur(p,i,e)*p%e,y=Ur(g,o,e)*g%e,x=Ur(y,c,e)*y%e,S=Ur(x,a,e)*x%e,I=Ur(S,c,e)*y%e,A=Ur(I,r,e)*d%e,O=Ur(A,s,e)*g%e,T=Ur(O,n,e)*u%e,M=Ur(T,Ly,e);if(!qf.eql(qf.sqr(M),t))throw new Error("Cannot find square root");return M}var qf=Eo(Kc.p,{sqrt:x8}),So=nE({...Kc,Fp:qf,lowS:!0,endo:w8},ke),oE={};function Ff(t,...e){let r=oE[t];if(r===void 0){let n=ke(Es(t));r=ht(n,n),oE[t]=r}return ke(ht(r,...e))}var My=t=>t.toBytes(!0).slice(1),$c=So.Point,Ky=t=>t%Ly===b8;function Py(t){let{Fn:e,BASE:r}=$c,n=vo(e,t),i=r.multiply(n);return{scalar:Ky(i.y)?n:e.neg(n),bytes:My(i)}}function cE(t){let e=qf;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);Ky(i)||(i=e.neg(i));let o=$c.fromAffine({x:t,y:i});return o.assertValidity(),o}var Ru=Ti;function aE(...t){return $c.Fn.create(Ru(Ff("BIP0340/challenge",...t)))}function sE(t){return Py(t).bytes}function E8(t,e,r=Br(32)){let{Fn:n}=$c,i=ct("message",t),{bytes:o,scalar:s}=Py(e),c=ct("auxRand",r,32),a=n.toBytes(s^Ru(Ff("BIP0340/aux",c))),u=Ff("BIP0340/nonce",a,o,i),{bytes:d,scalar:f}=Py(u),h=aE(d,o,i),p=new Uint8Array(64);if(p.set(d,0),p.set(n.toBytes(n.create(f+h*s)),32),!uE(p,i,o))throw new Error("sign: Invalid signature produced");return p}function uE(t,e,r){let{Fn:n,BASE:i}=$c,o=ct("signature",t,64),s=ct("message",e),c=ct("publicKey",r,32);try{let a=cE(Ru(c)),u=Ru(o.subarray(0,32));if(!_u(u,iE,Kc.p))return!1;let d=Ru(o.subarray(32,64));if(!_u(d,iE,Kc.n))return!1;let f=aE(n.toBytes(u),My(a),s),h=i.multiplyUnsafe(d).add(a.multiplyUnsafe(n.neg(f))),{x:p,y:g}=h.toAffine();return!(h.is0()||!Ky(g)||p!==u)}catch{return!1}}var Or=(()=>{let r=(i=Br(48))=>Kf(i,Kc.n);So.utils.randomSecretKey;function n(i){let o=r(i);return{secretKey:o,publicKey:sE(o)}}return{keygen:n,getPublicKey:sE,sign:E8,verify:uE,Point:$c,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:Ff,lift_x:cE,pointToBytes:My,numberToBytesBE:Lc,bytesToNumberBE:Ti,mod:Rr},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:32*2,seed:48}}})();l();var v8=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),fE=Uint8Array.from(new Array(16).fill(0).map((t,e)=>e)),S8=fE.map(t=>(9*t+5)%16),lE=(()=>{let r=[[fE],[S8]];for(let n=0;n<4;n++)for(let i of r)i.push(i[n].map(o=>v8[o]));return r})(),hE=lE[0],pE=lE[1],yE=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>Uint8Array.from(t)),A8=hE.map((t,e)=>t.map(r=>yE[e][r])),T8=pE.map((t,e)=>t.map(r=>yE[e][r])),_8=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),I8=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function dE(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var jf=new Uint32Array(16),$y=class extends Cc{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:i,h4:o}=this;return[e,r,n,i,o]}set(e,r,n,i,o){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=o|0}process(e,r){for(let p=0;p<16;p++,r+=4)jf[p]=e.getUint32(r,!0);let n=this.h0|0,i=n,o=this.h1|0,s=o,c=this.h2|0,a=c,u=this.h3|0,d=u,f=this.h4|0,h=f;for(let p=0;p<5;p++){let g=4-p,y=_8[p],x=I8[p],S=hE[p],I=pE[p],A=A8[p],O=T8[p];for(let T=0;T<16;T++){let M=vu(n+dE(p,o,c,u)+jf[S[T]]+y,A[T])+f|0;n=f,f=u,u=vu(c,10)|0,c=o,o=M}for(let T=0;T<16;T++){let M=vu(i+dE(g,s,a,d)+jf[I[T]]+x,O[T])+h|0;i=h,h=d,d=vu(a,10)|0,a=s,s=M}}this.set(this.h1+c+d|0,this.h2+u+h|0,this.h3+f+i|0,this.h4+n+s|0,this.h0+o+a|0)}roundClean(){Fn(jf)}destroy(){this.destroyed=!0,Fn(this.buffer),this.set(0,0,0,0,0)}},gE=Nf(()=>new $y);l();l();function Hc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function B8(t,...e){if(!Hc(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function EE(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function qy(t){if(typeof t!="function")throw new Error("function expected");return!0}function Vc(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Ou(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Gf(t){if(!Array.isArray(t))throw new Error("array expected")}function vE(t,e){if(!EE(!0,e))throw new Error(`${t}: array of strings expected`)}function Fy(t,e){if(!EE(!1,e))throw new Error(`${t}: array of numbers expected`)}function Du(...t){let e=o=>o,r=(o,s)=>c=>o(s(c)),n=t.map(o=>o.encode).reduceRight(r,e),i=t.map(o=>o.decode).reduce(r,e);return{encode:n,decode:i}}function Yf(t){let e=typeof t=="string"?t.split(""):t,r=e.length;vE("alphabet",e);let n=new Map(e.map((i,o)=>[i,o]));return{encode:i=>(Gf(i),i.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);return e[o]})),decode:i=>(Gf(i),i.map(o=>{Vc("alphabet.decode",o);let s=n.get(o);if(s===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);return s}))}}function Jf(t=""){return Vc("join",t),{encode:e=>(vE("join.decode",e),e.join(t)),decode:e=>(Vc("join.decode",e),e.split(t))}}function R8(t){return qy(t),{encode:e=>e,decode:e=>t(e)}}function mE(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Gf(t),!t.length)return[];let n=0,i=[],o=Array.from(t,c=>{if(Ou(c),c<0||c>=e)throw new Error(`invalid integer: ${c}`);return c}),s=o.length;for(;;){let c=0,a=!0;for(let u=n;u<s;u++){let d=o[u],f=e*c,h=f+d;if(!Number.isSafeInteger(h)||f/e!==c||h-d!==f)throw new Error("convertRadix: carry overflow");let p=h/r;c=h%r;let g=Math.floor(p);if(o[u]=g,!Number.isSafeInteger(g)||g*r+c!==h)throw new Error("convertRadix: carry overflow");if(a)g?a=!1:n=u;else continue}if(i.push(c),a)break}for(let c=0;c<t.length-1&&t[c]===0;c++)i.push(0);return i.reverse()}var SE=(t,e)=>e===0?t:SE(e,t%e),zf=(t,e)=>t+(e-SE(t,e)),Wf=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Hy(t,e,r,n){if(Gf(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(zf(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${zf(e,r)}`);let i=0,o=0,s=Wf[e],c=Wf[r]-1,a=[];for(let u of t){if(Ou(u),u>=s)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(i=i<<e|u,o+e>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);for(o+=e;o>=r;o-=r)a.push((i>>o-r&c)>>>0);let d=Wf[o];if(d===void 0)throw new Error("invalid carry");i&=d-1}if(i=i<<r-o&c,!n&&o>=e)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&o>0&&a.push(i>>>0),a}function U8(t){Ou(t);let e=2**8;return{encode:r=>{if(!Hc(r))throw new Error("radix.encode input should be Uint8Array");return mE(Array.from(r),e,t)},decode:r=>(Fy("radix.decode",r),Uint8Array.from(mE(r,t,e)))}}function jy(t,e=!1){if(Ou(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(zf(8,t)>32||zf(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Hc(r))throw new Error("radix2.encode input should be Uint8Array");return Hy(Array.from(r),8,t,!e)},decode:r=>(Fy("radix2.decode",r),Uint8Array.from(Hy(r,t,8,e)))}}function wE(t){return qy(t),function(...e){try{return t.apply(null,e)}catch{}}}function O8(t,e){return Ou(t),qy(e),{encode(r){if(!Hc(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),i=new Uint8Array(r.length+t);return i.set(r),i.set(n,r.length),i},decode(r){if(!Hc(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),i=r.slice(-t),o=e(n).slice(0,t);for(let s=0;s<t;s++)if(o[s]!==i[s])throw new Error("Invalid checksum");return n}}}var qc=Du(jy(6),Yf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Jf("")),D8=t=>Du(U8(58),Yf(t),Jf("")),Xf=D8("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var AE=t=>Du(O8(4,e=>t(t(e))),Xf);var Vy=Du(Yf("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Jf("")),bE=[996825010,642813549,513874426,1027748829,705979059];function Uu(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<bE.length;n++)(e>>n&1)===1&&(r^=bE[n]);return r}function xE(t,e,r=1){let n=t.length,i=1;for(let o=0;o<n;o++){let s=t.charCodeAt(o);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);i=Uu(i)^s>>5}i=Uu(i);for(let o=0;o<n;o++)i=Uu(i)^t.charCodeAt(o)&31;for(let o of e)i=Uu(i)^o;for(let o=0;o<6;o++)i=Uu(i);return i^=r,Vy.encode(Hy([i%Wf[30]],30,5,!1))}function TE(t){let e=t==="bech32"?1:734539939,r=jy(5),n=r.decode,i=r.encode,o=wE(n);function s(f,h,p=90){Vc("bech32.encode prefix",f),Hc(h)&&(h=Array.from(h)),Fy("bech32.encode",h);let g=f.length;if(g===0)throw new TypeError(`Invalid prefix length ${g}`);let y=g+7+h.length;if(p!==!1&&y>p)throw new TypeError(`Length ${y} exceeds limit ${p}`);let x=f.toLowerCase(),S=xE(x,h,e);return`${x}1${Vy.encode(h)}${S}`}function c(f,h=90){Vc("bech32.decode input",f);let p=f.length;if(p<8||h!==!1&&p>h)throw new TypeError(`invalid string length: ${p} (${f}). Expected (8..${h})`);let g=f.toLowerCase();if(f!==g&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");let y=g.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');let x=g.slice(0,y),S=g.slice(y+1);if(S.length<6)throw new Error("Data must be at least 6 characters long");let I=Vy.decode(S).slice(0,-6),A=xE(x,I,e);if(!S.endsWith(A))throw new Error(`Invalid checksum in ${f}: expected "${A}"`);return{prefix:x,words:I}}let a=wE(c);function u(f){let{prefix:h,words:p}=c(f,!1);return{prefix:h,words:p,bytes:n(p)}}function d(f,h){return s(f,i(h))}return{encode:s,decode:c,encodeFromBytes:d,decodeToBytes:u,decodeUnsafe:a,fromWords:n,fromWordsUnsafe:o,toWords:i}}var Zf=TE("bech32"),As=TE("bech32m"),_E={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},k8=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",N8={encode(t){return B8(t),t.toHex()},decode(t){return Vc("hex",t),Uint8Array.fromHex(t)}},ve=k8?N8:Du(jy(4),Yf("0123456789abcdef"),Jf(""),R8(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var He=new Uint8Array,Yy=new Uint8Array([0]);function Fc(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}function Yr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function C8(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!Yr(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var Jy=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function jc(t){return Object.prototype.toString.call(t)==="[object Object]"}function jn(t){return Number.isSafeInteger(t)}var Qf={equalBytes:Fc,isBytes:Yr,isCoder:Dr,checkBounds:BE,concatBytes:C8,createView:Jy,isPlainObject:jc},IE=t=>{if(t!==null&&typeof t!="string"&&!Dr(t)&&!Yr(t)&&!jn(t))throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${t} (${typeof t})`);return{encodeStream(e,r){if(t===null)return;if(Dr(t))return t.encodeStream(e,r);let n;if(typeof t=="number"?n=t:typeof t=="string"&&(n=Bi.resolve(e.stack,t)),typeof n=="bigint"&&(n=Number(n)),n===void 0||n!==r)throw e.err(`Wrong length: ${n} len=${t} exp=${r} (${typeof r})`)},decodeStream(e){let r;if(Dr(t)?r=Number(t.decodeStream(e)):typeof t=="number"?r=t:typeof t=="string"&&(r=Bi.resolve(e.stack,t)),typeof r=="bigint"&&(r=Number(r)),typeof r!="number")throw e.err(`Wrong length: ${r}`);return r}}},Dt={BITS:32,FULL_MASK:-1>>>0,len:t=>Math.ceil(t/32),create:t=>new Uint32Array(Dt.len(t)),clean:t=>t.fill(0),debug:t=>Array.from(t).map(e=>(e>>>0).toString(2).padStart(32,"0")),checkLen:(t,e)=>{if(Dt.len(e)!==t.length)throw new Error(`wrong length=${t.length}. Expected: ${Dt.len(e)}`)},chunkLen:(t,e,r)=>{if(e<0)throw new Error(`wrong pos=${e}`);if(e+r>t)throw new Error(`wrong range=${e}/${r} of ${t}`)},set:(t,e,r,n=!0)=>!n&&t[e]&r?!1:(t[e]|=r,!0),pos:(t,e)=>({chunk:Math.floor((t+e)/32),mask:1<<32-(t+e)%32-1}),indices:(t,e,r=!1)=>{Dt.checkLen(t,e);let{FULL_MASK:n,BITS:i}=Dt,o=i-e%i,s=o?n>>>o<<o:n,c=[];for(let a=0;a<t.length;a++){let u=t[a];if(r&&(u=~u),a===t.length-1&&(u&=s),u!==0)for(let d=0;d<i;d++){let f=1<<i-d-1;u&f&&c.push(a*i+d)}}return c},range:t=>{let e=[],r;for(let n of t)r===void 0||n!==r.pos+r.length?e.push(r={pos:n,length:1}):r.length+=1;return e},rangeDebug:(t,e,r=!1)=>`[${Dt.range(Dt.indices(t,e,r)).map(n=>`(${n.pos}/${n.length})`).join(", ")}]`,setRange:(t,e,r,n,i=!0)=>{Dt.chunkLen(e,r,n);let{FULL_MASK:o,BITS:s}=Dt,c=r%s?Math.floor(r/s):void 0,a=r+n,u=a%s?Math.floor(a/s):void 0;if(c!==void 0&&c===u)return Dt.set(t,c,o>>>s-n<<s-n-r,i);if(c!==void 0&&!Dt.set(t,c,o>>>r%s,i))return!1;let d=c!==void 0?c+1:r/s,f=u!==void 0?u:a/s;for(let h=d;h<f;h++)if(!Dt.set(t,h,o,i))return!1;return!(u!==void 0&&c!==u&&!Dt.set(t,u,o<<s-a%s,i))}},Bi={pushObj:(t,e,r)=>{let n={obj:e};t.push(n),r((i,o)=>{n.field=i,o(),n.field=void 0}),t.pop()},path:t=>{let e=[];for(let r of t)r.field!==void 0&&e.push(r.field);return e.join("/")},err:(t,e,r)=>{let n=new Error(`${t}(${Bi.path(e)}): ${typeof r=="string"?r:r.message}`);return r instanceof Error&&r.stack&&(n.stack=r.stack),n},resolve:(t,e)=>{let r=e.split("/"),n=t.map(s=>s.obj),i=0;for(;i<r.length&&r[i]==="..";i++)n.pop();let o=n.pop();for(;i<r.length;i++){if(!o||o[r[i]]===void 0)return;o=o[r[i]]}return o}},Wy=class t{constructor(e,r={},n=[],i=void 0,o=0){this.pos=0,this.bitBuf=0,this.bitPos=0,this.data=e,this.opts=r,this.stack=n,this.parent=i,this.parentOffset=o,this.view=Jy(e)}_enablePointers(){if(this.parent)return this.parent._enablePointers();this.bs||(this.bs=Dt.create(this.data.length),Dt.setRange(this.bs,this.data.length,0,this.pos,this.opts.allowMultipleReads))}markBytesBS(e,r){return this.parent?this.parent.markBytesBS(this.parentOffset+e,r):!r||!this.bs?!0:Dt.setRange(this.bs,this.data.length,e,r,!1)}markBytes(e){let r=this.pos;this.pos+=e;let n=this.markBytesBS(r,e);if(!this.opts.allowMultipleReads&&!n)throw this.err(`multiple read pos=${this.pos} len=${e}`);return n}pushObj(e,r){return Bi.pushObj(this.stack,e,r)}readView(e,r){if(!Number.isFinite(e))throw this.err(`readView: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readView: Unexpected end of buffer");let n=r(this.view,this.pos);return this.markBytes(e),n}absBytes(e){if(e>this.data.length)throw new Error("Unexpected end of buffer");return this.data.subarray(e)}finish(){if(!this.opts.allowUnreadBytes){if(this.bitPos)throw this.err(`${this.bitPos} bits left after unpack: ${ve.encode(this.data.slice(this.pos))}`);if(this.bs&&!this.parent){let e=Dt.indices(this.bs,this.data.length,!0);if(e.length){let r=Dt.range(e).map(({pos:n,length:i})=>`(${n}/${i})[${ve.encode(this.data.subarray(n,n+i))}]`).join(", ");throw this.err(`unread byte ranges: ${r} (total=${this.data.length})`)}else return}if(!this.isEnd())throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${ve.encode(this.data.slice(this.pos))}`)}}err(e){return Bi.err("Reader",this.stack,e)}offsetReader(e){if(e>this.data.length)throw this.err("offsetReader: Unexpected end of buffer");return new t(this.absBytes(e),this.opts,this.stack,this,e)}bytes(e,r=!1){if(this.bitPos)throw this.err("readBytes: bitPos not empty");if(!Number.isFinite(e))throw this.err(`readBytes: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let n=this.data.subarray(this.pos,this.pos+e);return r||this.markBytes(e),n}byte(e=!1){if(this.bitPos)throw this.err("readByte: bitPos not empty");if(this.pos+1>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let r=this.data[this.pos];return e||this.markBytes(1),r}get leftBytes(){return this.data.length-this.pos}get totalBytes(){return this.data.length}isEnd(){return this.pos>=this.data.length&&!this.bitPos}bits(e){if(e>32)throw this.err("BitReader: cannot read more than 32 bits in single call");let r=0;for(;e;){this.bitPos||(this.bitBuf=this.byte(),this.bitPos=8);let n=Math.min(e,this.bitPos);this.bitPos-=n,r=r<<n|this.bitBuf>>this.bitPos&2**n-1,this.bitBuf&=2**this.bitPos-1,e-=n}return r>>>0}find(e,r=this.pos){if(!Yr(e))throw this.err(`find: needle is not bytes! ${e}`);if(this.bitPos)throw this.err("findByte: bitPos not empty");if(!e.length)throw this.err("find: needle is empty");for(let n=r;(n=this.data.indexOf(e[0],n))!==-1;n++){if(n===-1||this.data.length-n<e.length)return;if(Fc(e,this.data.subarray(n,n+e.length)))return n}}},Gy=class{constructor(e=[]){this.pos=0,this.buffers=[],this.ptrs=[],this.bitBuf=0,this.bitPos=0,this.viewBuf=new Uint8Array(8),this.finished=!1,this.stack=e,this.view=Jy(this.viewBuf)}pushObj(e,r){return Bi.pushObj(this.stack,e,r)}writeView(e,r){if(this.finished)throw this.err("buffer: finished");if(!jn(e)||e>8)throw new Error(`wrong writeView length=${e}`);r(this.view),this.bytes(this.viewBuf.slice(0,e)),this.viewBuf.fill(0)}err(e){if(this.finished)throw this.err("buffer: finished");return Bi.err("Reader",this.stack,e)}bytes(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeBytes: ends with non-empty bit buffer");this.buffers.push(e),this.pos+=e.length}byte(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeByte: ends with non-empty bit buffer");this.buffers.push(new Uint8Array([e])),this.pos++}finish(e=!0){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("buffer: ends with non-empty bit buffer");let r=this.buffers.concat(this.ptrs.map(o=>o.buffer)),n=r.map(o=>o.length).reduce((o,s)=>o+s,0),i=new Uint8Array(n);for(let o=0,s=0;o<r.length;o++){let c=r[o];i.set(c,s),s+=c.length}for(let o=this.pos,s=0;s<this.ptrs.length;s++){let c=this.ptrs[s];i.set(c.ptr.encode(o),c.pos),o+=c.buffer.length}if(e){this.buffers=[];for(let o of this.ptrs)o.buffer.fill(0);this.ptrs=[],this.finished=!0,this.bitBuf=0}return i}bits(e,r){if(r>32)throw this.err("writeBits: cannot write more than 32 bits in single call");if(e>=2**r)throw this.err(`writeBits: value (${e}) >= 2**bits (${r})`);for(;r;){let n=Math.min(r,8-this.bitPos);this.bitBuf=this.bitBuf<<n|e>>r-n,this.bitPos+=n,r-=n,e&=2**r-1,this.bitPos===8&&(this.bitPos=0,this.buffers.push(new Uint8Array([this.bitBuf])),this.pos++)}}},zy=t=>Uint8Array.from(t).reverse();function BE(t,e,r){if(r){let n=2n**(e-1n);if(t<-n||t>=n)throw new Error(`value out of signed bounds. Expected ${-n} <= ${t} < ${n}`)}else if(0n>t||t>=2n**e)throw new Error(`value out of unsigned bounds. Expected 0 <= ${t} < ${2n**e}`)}function RE(t){return{encodeStream:t.encodeStream,decodeStream:t.decodeStream,size:t.size,encode:e=>{let r=new Gy;return t.encodeStream(r,e),r.finish()},decode:(e,r={})=>{let n=new Wy(e,r),i=t.decodeStream(n);return n.finish(),i}}}function Gt(t,e){if(!Dr(t))throw new Error(`validate: invalid inner value ${t}`);if(typeof e!="function")throw new Error("validate: fn should be function");return RE({size:t.size,encodeStream:(r,n)=>{let i;try{i=e(n)}catch(o){throw r.err(o)}t.encodeStream(r,i)},decodeStream:r=>{let n=t.decodeStream(r);try{return e(n)}catch(i){throw r.err(i)}}})}var zt=t=>{let e=RE(t);return t.validate?Gt(e,t.validate):e},el=t=>jc(t)&&typeof t.decode=="function"&&typeof t.encode=="function";function Dr(t){return jc(t)&&el(t)&&typeof t.encodeStream=="function"&&typeof t.decodeStream=="function"&&(t.size===void 0||jn(t.size))}function L8(){return{encode:t=>{if(!Array.isArray(t))throw new Error("array expected");let e={};for(let r of t){if(!Array.isArray(r)||r.length!==2)throw new Error("array of two elements expected");let n=r[0],i=r[1];if(e[n]!==void 0)throw new Error(`key(${n}) appears twice in struct`);e[n]=i}return e},decode:t=>{if(!jc(t))throw new Error(`expected plain object, got ${t}`);return Object.entries(t)}}}var P8={encode:t=>{if(typeof t!="bigint")throw new Error(`expected bigint, got ${typeof t}`);if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error(`element bigger than MAX_SAFE_INTEGER=${t}`);return Number(t)},decode:t=>{if(!jn(t))throw new Error("element is not a safe integer");return BigInt(t)}};function M8(t){if(!jc(t))throw new Error("plain object expected");return{encode:e=>{if(!jn(e)||!(e in t))throw new Error(`wrong value ${e}`);return t[e]},decode:e=>{if(typeof e!="string")throw new Error(`wrong value ${typeof e}`);return t[e]}}}function K8(t,e=!1){if(!jn(t))throw new Error(`decimal/precision: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`decimal/round: expected boolean, got ${typeof e}`);let r=10n**BigInt(t);return{encode:n=>{if(typeof n!="bigint")throw new Error(`expected bigint, got ${typeof n}`);let i=(n<0n?-n:n).toString(10),o=i.length-t;o<0&&(i=i.padStart(i.length-o,"0"),o=0);let s=i.length-1;for(;s>=o&&i[s]==="0";s--);let c=i.slice(0,o),a=i.slice(o,s+1);return c||(c="0"),n<0n&&(c="-"+c),a?`${c}.${a}`:c},decode:n=>{if(typeof n!="string")throw new Error(`expected string, got ${typeof n}`);if(n==="-0")throw new Error("negative zero is not allowed");let i=!1;if(n.startsWith("-")&&(i=!0,n=n.slice(1)),!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))throw new Error(`wrong string value=${n}`);let o=n.indexOf(".");o=o===-1?n.length:o;let s=n.slice(0,o),c=n.slice(o+1).replace(/0+$/,""),a=BigInt(s)*r;if(!e&&c.length>t)throw new Error(`fractional part cannot be represented with this precision (num=${n}, prec=${t})`);let u=Math.min(c.length,t),d=BigInt(c.slice(0,u))*10n**BigInt(t-u),f=a+d;return i?-f:f}}}function $8(t){if(!Array.isArray(t))throw new Error(`expected array, got ${typeof t}`);for(let e of t)if(!el(e))throw new Error(`wrong base coder ${e}`);return{encode:e=>{for(let r of t){let n=r.encode(e);if(n!==void 0)return n}throw new Error(`match/encode: cannot find match in ${e}`)},decode:e=>{for(let r of t){let n=r.decode(e);if(n!==void 0)return n}throw new Error(`match/decode: cannot find match in ${e}`)}}}var UE=t=>{if(!el(t))throw new Error("BaseCoder expected");return{encode:t.decode,decode:t.encode}},Ri={dict:L8,numberBigint:P8,tsEnum:M8,decimal:K8,match:$8,reverse:UE};var Xy=(t,e=!1,r=!1,n=!0)=>{if(!jn(t))throw new Error(`bigint/size: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`bigint/le: expected boolean, got ${typeof e}`);if(typeof r!="boolean")throw new Error(`bigint/signed: expected boolean, got ${typeof r}`);if(typeof n!="boolean")throw new Error(`bigint/sized: expected boolean, got ${typeof n}`);let i=BigInt(t),o=2n**(8n*i-1n);return zt({size:n?t:void 0,encodeStream:(s,c)=>{r&&c<0&&(c=c|o);let a=[];for(let d=0;d<t;d++)a.push(Number(c&255n)),c>>=8n;let u=new Uint8Array(a).reverse();if(!n){let d=0;for(d=0;d<u.length&&u[d]===0;d++);u=u.subarray(d)}s.bytes(e?u.reverse():u)},decodeStream:s=>{let c=s.bytes(n?t:Math.min(t,s.leftBytes)),a=e?c:zy(c),u=0n;for(let d=0;d<a.length;d++)u|=BigInt(a[d])<<8n*BigInt(d);return r&&u&o&&(u=(u^o)-o),u},validate:s=>{if(typeof s!="bigint")throw new Error(`bigint: invalid value: ${s}`);return BE(s,8n*i,!!r),s}})};var OE=Xy(32,!1);var Wc=Xy(8,!0);var DE=Xy(8,!0,!0);var H8=(t,e)=>zt({size:t,encodeStream:(r,n)=>r.writeView(t,i=>e.write(i,n)),decodeStream:r=>r.readView(t,e.read),validate:r=>{if(typeof r!="number")throw new Error(`viewCoder: expected number, got ${typeof r}`);return e.validate&&e.validate(r),r}}),ku=(t,e,r)=>{let n=t*8,i=2**(n-1),o=a=>{if(!jn(a))throw new Error(`sintView: value is not safe integer: ${a}`);if(a<-i||a>=i)throw new Error(`sintView: value out of bounds. Expected ${-i} <= ${a} < ${i}`)},s=2**n,c=a=>{if(!jn(a))throw new Error(`uintView: value is not safe integer: ${a}`);if(0>a||a>=s)throw new Error(`uintView: value out of bounds. Expected 0 <= ${a} < ${s}`)};return H8(t,{write:r.write,read:r.read,validate:e?o:c})},Be=ku(4,!1,{read:(t,e)=>t.getUint32(e,!0),write:(t,e)=>t.setUint32(0,e,!0)}),kE=ku(4,!1,{read:(t,e)=>t.getUint32(e,!1),write:(t,e)=>t.setUint32(0,e,!1)}),Ao=ku(4,!0,{read:(t,e)=>t.getInt32(e,!0),write:(t,e)=>t.setInt32(0,e,!0)});var Zy=ku(2,!1,{read:(t,e)=>t.getUint16(e,!0),write:(t,e)=>t.setUint16(0,e,!0)});var wn=ku(1,!1,{read:(t,e)=>t.getUint8(e),write:(t,e)=>t.setUint8(0,e)});var Fe=(t,e=!1)=>{if(typeof e!="boolean")throw new Error(`bytes/le: expected boolean, got ${typeof e}`);let r=IE(t),n=Yr(t);return zt({size:typeof t=="number"?t:void 0,encodeStream:(i,o)=>{n||r.encodeStream(i,o.length),i.bytes(e?zy(o):o),n&&i.bytes(t)},decodeStream:i=>{let o;if(n){let s=i.find(t);if(!s)throw i.err("bytes: cannot find terminator");o=i.bytes(s-i.pos),i.bytes(t.length)}else o=i.bytes(t===null?i.leftBytes:r.decodeStream(i));return e?zy(o):o},validate:i=>{if(!Yr(i))throw new Error(`bytes: invalid value ${i}`);return i}})};function NE(t,e){if(!Dr(e))throw new Error(`prefix: invalid inner value ${e}`);return mn(Fe(t),UE(e))}var tl=(t,e=!1)=>Gt(mn(Fe(t,e),_E),r=>{if(typeof r!="string")throw new Error(`expected string, got ${typeof r}`);return r});var CE=(t,e={isLE:!1,with0x:!1})=>{let r=mn(Fe(t,e.isLE),ve),n=e.with0x;if(typeof n!="boolean")throw new Error(`hex/with0x: expected boolean, got ${typeof n}`);return n&&(r=mn(r,{encode:i=>`0x${i}`,decode:i=>{if(!i.startsWith("0x"))throw new Error("hex(with0x=true).encode input should start with 0x");return i.slice(2)}})),r};function mn(t,e){if(!Dr(t))throw new Error(`apply: invalid inner value ${t}`);if(!el(e))throw new Error(`apply: invalid base value ${t}`);return zt({size:t.size,encodeStream:(r,n)=>{let i;try{i=e.decode(n)}catch(o){throw r.err(""+o)}return t.encodeStream(r,i)},decodeStream:r=>{let n=t.decodeStream(r);try{return e.encode(n)}catch(i){throw r.err(""+i)}}})}var LE=(t,e=!1)=>{if(!Yr(t))throw new Error(`flag/flagValue: expected Uint8Array, got ${typeof t}`);if(typeof e!="boolean")throw new Error(`flag/xor: expected boolean, got ${typeof e}`);return zt({size:t.length,encodeStream:(r,n)=>{!!n!==e&&r.bytes(t)},decodeStream:r=>{let n=r.leftBytes>=t.length;return n&&(n=Fc(r.bytes(t.length,!0),t),n&&r.bytes(t.length)),n!==e},validate:r=>{if(r!==void 0&&typeof r!="boolean")throw new Error(`flag: expected boolean value or undefined, got ${typeof r}`);return r}})};function PE(t,e,r){if(!Dr(e))throw new Error(`flagged: invalid inner value ${e}`);if(typeof t!="string"&&!Dr(e))throw new Error(`flagged: wrong path=${t}`);return zt({encodeStream:(n,i)=>{typeof t=="string"?Bi.resolve(n.stack,t)?e.encodeStream(n,i):r&&e.encodeStream(n,r):(t.encodeStream(n,!!i),i?e.encodeStream(n,i):r&&e.encodeStream(n,r))},decodeStream:n=>{let i=!1;if(typeof t=="string"?i=!!Bi.resolve(n.stack,t):i=t.decodeStream(n),i)return e.decodeStream(n);r&&e.decodeStream(n)}})}function rl(t,e,r=!0){if(!Dr(t))throw new Error(`magic: invalid inner value ${t}`);if(typeof r!="boolean")throw new Error(`magic: expected boolean, got ${typeof r}`);return zt({size:t.size,encodeStream:(n,i)=>t.encodeStream(n,e),decodeStream:n=>{let i=t.decodeStream(n);if(r&&typeof i!="object"&&i!==e||Yr(e)&&!Fc(e,i))throw n.err(`magic: invalid value: ${i} !== ${e}`)},validate:n=>{if(n!==void 0)throw new Error(`magic: wrong value=${typeof n}`);return n}})}function ME(t){let e=0;for(let r of t){if(r.size===void 0)return;if(!jn(r.size))throw new Error(`sizeof: wrong element size=${e}`);e+=r.size}return e}function vt(t){if(!jc(t))throw new Error(`struct: expected plain object, got ${t}`);for(let e in t)if(!Dr(t[e]))throw new Error(`struct: field ${e} is not CoderType`);return zt({size:ME(Object.values(t)),encodeStream:(e,r)=>{e.pushObj(r,n=>{for(let i in t)n(i,()=>t[i].encodeStream(e,r[i]))})},decodeStream:e=>{let r={};return e.pushObj(r,n=>{for(let i in t)n(i,()=>r[i]=t[i].decodeStream(e))}),r},validate:e=>{if(typeof e!="object"||e===null)throw new Error(`struct: invalid value ${e}`);return e}})}function KE(t){if(!Array.isArray(t))throw new Error(`Packed.Tuple: got ${typeof t} instead of array`);for(let e=0;e<t.length;e++)if(!Dr(t[e]))throw new Error(`tuple: field ${e} is not CoderType`);return zt({size:ME(t),encodeStream:(e,r)=>{if(!Array.isArray(r))throw e.err(`tuple: invalid value ${r}`);e.pushObj(r,n=>{for(let i=0;i<t.length;i++)n(`${i}`,()=>t[i].encodeStream(e,r[i]))})},decodeStream:e=>{let r=[];return e.pushObj(r,n=>{for(let i=0;i<t.length;i++)n(`${i}`,()=>r.push(t[i].decodeStream(e)))}),r},validate:e=>{if(!Array.isArray(e))throw new Error(`tuple: invalid value ${e}`);if(e.length!==t.length)throw new Error(`tuple: wrong length=${e.length}, expected ${t.length}`);return e}})}function Yt(t,e){if(!Dr(e))throw new Error(`array: invalid inner value ${e}`);let r=IE(typeof t=="string"?`../${t}`:t);return zt({size:typeof t=="number"&&e.size?t*e.size:void 0,encodeStream:(n,i)=>{let o=n;o.pushObj(i,s=>{Yr(t)||r.encodeStream(n,i.length);for(let c=0;c<i.length;c++)s(`${c}`,()=>{let a=i[c],u=n.pos;if(e.encodeStream(n,a),Yr(t)){if(t.length>o.pos-u)return;let d=o.finish(!1).subarray(u,o.pos);if(Fc(d.subarray(0,t.length),t))throw o.err(`array: inner element encoding same as separator. elm=${a} data=${d}`)}})}),Yr(t)&&n.bytes(t)},decodeStream:n=>{let i=[];return n.pushObj(i,o=>{if(t===null)for(let s=0;!n.isEnd()&&(o(`${s}`,()=>i.push(e.decodeStream(n))),!(e.size&&n.leftBytes<e.size));s++);else if(Yr(t))for(let s=0;;s++){if(Fc(n.bytes(t.length,!0),t)){n.bytes(t.length);break}o(`${s}`,()=>i.push(e.decodeStream(n)))}else{let s;o("arrayLen",()=>s=r.decodeStream(n));for(let c=0;c<s;c++)o(`${c}`,()=>i.push(e.decodeStream(n)))}}),i},validate:n=>{if(!Array.isArray(n))throw new Error(`array: invalid value ${n}`);return n}})}var ol=So.ProjectivePoint,il=So.CURVE.n,Ce=Qf.isBytes,Wn=Qf.concatBytes,at=Qf.equalBytes;var Gc=t=>gE(ke(t)),Ui=(...t)=>ke(ke(Wn(...t))),bM=Or.utils.randomPrivateKey,sl=Or.getPublicKey,Qy=So.getPublicKey,$E=t=>t.r<il/2n;function HE(t,e,r=!1){let n=So.sign(t,e);if(r&&!$E(n)){let i=new Uint8Array(32),o=0;for(;!$E(n);)if(i.set(Be.encode(o++)),n=So.sign(t,e,{extraEntropy:i}),o>4294967295)throw new Error("lowR counter overflow: report the error")}return n.toDERRawBytes()}var e0=Or.sign,Nu=Or.utils.taggedHash,St;(function(t){t[t.ecdsa=0]="ecdsa",t[t.schnorr=1]="schnorr"})(St||(St={}));function To(t,e){let r=t.length;if(e===St.ecdsa){if(r===32)throw new Error("Expected non-Schnorr key");return ol.fromHex(t),t}else if(e===St.schnorr){if(r!==32)throw new Error("Expected 32-byte Schnorr key");return Or.utils.lift_x(Or.utils.bytesToNumberBE(t)),t}else throw new Error("Unknown key type")}function VE(t,e){let r=Or.utils,n=r.taggedHash("TapTweak",t,e),i=r.bytesToNumberBE(n);if(i>=il)throw new Error("tweak higher than curve order");return i}function qE(t,e=Uint8Array.of()){let r=Or.utils,n=r.bytesToNumberBE(t),i=ol.fromPrivateKey(n),o=i.hasEvenY()?n:r.mod(-n,il),s=r.pointToBytes(i),c=VE(s,e);return r.numberToBytesBE(r.mod(o+c,il),32)}function Cu(t,e){let r=Or.utils,n=VE(t,e),o=r.lift_x(r.bytesToNumberBE(t)).add(ol.fromPrivateKey(n)),s=o.hasEvenY()?0:1;return[r.pointToBytes(o),s]}var cl=ke(ol.BASE.toRawBytes(!1)),Jr={bech32:"bc",pubKeyHash:0,scriptHash:5,wif:128},t0={bech32:"tb",pubKeyHash:111,scriptHash:196,wif:239};function Lu(t,e){if(!Ce(t)||!Ce(e))throw new Error(`cmp: wrong type a=${typeof t} b=${typeof e}`);let r=Math.min(t.length,e.length);for(let n=0;n<r;n++)if(t[n]!=e[n])return Math.sign(t[n]-e[n]);return Math.sign(t.length-e.length)}l();l();l();var xt;(function(t){t[t.OP_0=0]="OP_0",t[t.PUSHDATA1=76]="PUSHDATA1",t[t.PUSHDATA2=77]="PUSHDATA2",t[t.PUSHDATA4=78]="PUSHDATA4",t[t["1NEGATE"]=79]="1NEGATE",t[t.RESERVED=80]="RESERVED",t[t.OP_1=81]="OP_1",t[t.OP_2=82]="OP_2",t[t.OP_3=83]="OP_3",t[t.OP_4=84]="OP_4",t[t.OP_5=85]="OP_5",t[t.OP_6=86]="OP_6",t[t.OP_7=87]="OP_7",t[t.OP_8=88]="OP_8",t[t.OP_9=89]="OP_9",t[t.OP_10=90]="OP_10",t[t.OP_11=91]="OP_11",t[t.OP_12=92]="OP_12",t[t.OP_13=93]="OP_13",t[t.OP_14=94]="OP_14",t[t.OP_15=95]="OP_15",t[t.OP_16=96]="OP_16",t[t.NOP=97]="NOP",t[t.VER=98]="VER",t[t.IF=99]="IF",t[t.NOTIF=100]="NOTIF",t[t.VERIF=101]="VERIF",t[t.VERNOTIF=102]="VERNOTIF",t[t.ELSE=103]="ELSE",t[t.ENDIF=104]="ENDIF",t[t.VERIFY=105]="VERIFY",t[t.RETURN=106]="RETURN",t[t.TOALTSTACK=107]="TOALTSTACK",t[t.FROMALTSTACK=108]="FROMALTSTACK",t[t["2DROP"]=109]="2DROP",t[t["2DUP"]=110]="2DUP",t[t["3DUP"]=111]="3DUP",t[t["2OVER"]=112]="2OVER",t[t["2ROT"]=113]="2ROT",t[t["2SWAP"]=114]="2SWAP",t[t.IFDUP=115]="IFDUP",t[t.DEPTH=116]="DEPTH",t[t.DROP=117]="DROP",t[t.DUP=118]="DUP",t[t.NIP=119]="NIP",t[t.OVER=120]="OVER",t[t.PICK=121]="PICK",t[t.ROLL=122]="ROLL",t[t.ROT=123]="ROT",t[t.SWAP=124]="SWAP",t[t.TUCK=125]="TUCK",t[t.CAT=126]="CAT",t[t.SUBSTR=127]="SUBSTR",t[t.LEFT=128]="LEFT",t[t.RIGHT=129]="RIGHT",t[t.SIZE=130]="SIZE",t[t.INVERT=131]="INVERT",t[t.AND=132]="AND",t[t.OR=133]="OR",t[t.XOR=134]="XOR",t[t.EQUAL=135]="EQUAL",t[t.EQUALVERIFY=136]="EQUALVERIFY",t[t.RESERVED1=137]="RESERVED1",t[t.RESERVED2=138]="RESERVED2",t[t["1ADD"]=139]="1ADD",t[t["1SUB"]=140]="1SUB",t[t["2MUL"]=141]="2MUL",t[t["2DIV"]=142]="2DIV",t[t.NEGATE=143]="NEGATE",t[t.ABS=144]="ABS",t[t.NOT=145]="NOT",t[t["0NOTEQUAL"]=146]="0NOTEQUAL",t[t.ADD=147]="ADD",t[t.SUB=148]="SUB",t[t.MUL=149]="MUL",t[t.DIV=150]="DIV",t[t.MOD=151]="MOD",t[t.LSHIFT=152]="LSHIFT",t[t.RSHIFT=153]="RSHIFT",t[t.BOOLAND=154]="BOOLAND",t[t.BOOLOR=155]="BOOLOR",t[t.NUMEQUAL=156]="NUMEQUAL",t[t.NUMEQUALVERIFY=157]="NUMEQUALVERIFY",t[t.NUMNOTEQUAL=158]="NUMNOTEQUAL",t[t.LESSTHAN=159]="LESSTHAN",t[t.GREATERTHAN=160]="GREATERTHAN",t[t.LESSTHANOREQUAL=161]="LESSTHANOREQUAL",t[t.GREATERTHANOREQUAL=162]="GREATERTHANOREQUAL",t[t.MIN=163]="MIN",t[t.MAX=164]="MAX",t[t.WITHIN=165]="WITHIN",t[t.RIPEMD160=166]="RIPEMD160",t[t.SHA1=167]="SHA1",t[t.SHA256=168]="SHA256",t[t.HASH160=169]="HASH160",t[t.HASH256=170]="HASH256",t[t.CODESEPARATOR=171]="CODESEPARATOR",t[t.CHECKSIG=172]="CHECKSIG",t[t.CHECKSIGVERIFY=173]="CHECKSIGVERIFY",t[t.CHECKMULTISIG=174]="CHECKMULTISIG",t[t.CHECKMULTISIGVERIFY=175]="CHECKMULTISIGVERIFY",t[t.NOP1=176]="NOP1",t[t.CHECKLOCKTIMEVERIFY=177]="CHECKLOCKTIMEVERIFY",t[t.CHECKSEQUENCEVERIFY=178]="CHECKSEQUENCEVERIFY",t[t.NOP4=179]="NOP4",t[t.NOP5=180]="NOP5",t[t.NOP6=181]="NOP6",t[t.NOP7=182]="NOP7",t[t.NOP8=183]="NOP8",t[t.NOP9=184]="NOP9",t[t.NOP10=185]="NOP10",t[t.CHECKSIGADD=186]="CHECKSIGADD",t[t.INVALID=255]="INVALID"})(xt||(xt={}));function r0(t=6,e=!1){return zt({encodeStream:(r,n)=>{if(n===0n)return;let i=n<0,o=BigInt(n),s=[];for(let c=i?-o:o;c;c>>=8n)s.push(Number(c&0xffn));s[s.length-1]>=128?s.push(i?128:0):i&&(s[s.length-1]|=128),r.bytes(new Uint8Array(s))},decodeStream:r=>{let n=r.leftBytes;if(n>t)throw new Error(`ScriptNum: number (${n}) bigger than limit=${t}`);if(n===0)return 0n;if(e){let s=r.bytes(n,!0);if(!(s[s.length-1]&127)&&(n<=1||!(s[s.length-2]&128)))throw new Error("Non-minimally encoded ScriptNum")}let i=0,o=0n;for(let s=0;s<n;++s)i=r.byte(),o|=BigInt(i)<<8n*BigInt(s);return i>=128&&(o&=2n**BigInt(n*8)-1n>>1n,o=-o),o}})}function WE(t,e=4,r=!0){if(typeof t=="number")return t;if(Ce(t))try{let n=r0(e,r).decode(t);return n>Number.MAX_SAFE_INTEGER?void 0:Number(n)}catch{return}}var Ze=zt({encodeStream:(t,e)=>{for(let r of e){if(typeof r=="string"){if(xt[r]===void 0)throw new Error(`Unknown opcode=${r}`);t.byte(xt[r]);continue}else if(typeof r=="number"){if(r===0){t.byte(0);continue}else if(1<=r&&r<=16){t.byte(xt.OP_1-1+r);continue}}if(typeof r=="number"&&(r=r0().encode(BigInt(r))),!Ce(r))throw new Error(`Wrong Script OP=${r} (${typeof r})`);let n=r.length;n<xt.PUSHDATA1?t.byte(n):n<=255?(t.byte(xt.PUSHDATA1),t.byte(n)):n<=65535?(t.byte(xt.PUSHDATA2),t.bytes(Zy.encode(n))):(t.byte(xt.PUSHDATA4),t.bytes(Be.encode(n))),t.bytes(r)}},decodeStream:t=>{let e=[];for(;!t.isEnd();){let r=t.byte();if(xt.OP_0<r&&r<=xt.PUSHDATA4){let n;if(r<xt.PUSHDATA1)n=r;else if(r===xt.PUSHDATA1)n=wn.decodeStream(t);else if(r===xt.PUSHDATA2)n=Zy.decodeStream(t);else if(r===xt.PUSHDATA4)n=Be.decodeStream(t);else throw new Error("Should be not possible");e.push(t.bytes(n))}else if(r===0)e.push(0);else if(xt.OP_1<=r&&r<=xt.OP_16)e.push(r-(xt.OP_1-1));else{let n=xt[r];if(n===void 0)throw new Error(`Unknown opcode=${r.toString(16)}`);e.push(n)}}return e}}),jE={253:[253,2,253n,65535n],254:[254,4,65536n,4294967295n],255:[255,8,4294967296n,18446744073709551615n]},zc=zt({encodeStream:(t,e)=>{if(typeof e=="number"&&(e=BigInt(e)),0n<=e&&e<=252n)return t.byte(Number(e));for(let[r,n,i,o]of Object.values(jE))if(!(i>e||e>o)){t.byte(r);for(let s=0;s<n;s++)t.byte(Number(e>>8n*BigInt(s)&0xffn));return}throw t.err(`VarInt too big: ${e}`)},decodeStream:t=>{let e=t.byte();if(e<=252)return BigInt(e);let[r,n,i]=jE[e],o=0n;for(let s=0;s<n;s++)o|=BigInt(t.byte())<<8n*BigInt(s);if(o<i)throw t.err(`Wrong CompactSize(${8*n})`);return o}}),kr=mn(zc,Ri.numberBigint),lr=Fe(zc),Yc=Yt(kr,lr),al=t=>Yt(zc,t),GE=vt({txid:Fe(32,!0),index:Be,finalScriptSig:lr,sequence:Be}),Oi=vt({amount:Wc,script:lr}),V8=vt({version:Ao,segwitFlag:LE(new Uint8Array([0,1])),inputs:al(GE),outputs:al(Oi),witnesses:PE("segwitFlag",Yt("inputs/length",Yc)),lockTime:Be});function q8(t){if(t.segwitFlag&&t.witnesses&&!t.witnesses.length)throw new Error("Segwit flag with empty witnesses array");return t}var Di=Gt(V8,q8),Ts=vt({version:Ao,inputs:al(GE),outputs:al(Oi),lockTime:Be});var i0=Gt(Fe(null),t=>To(t,St.ecdsa)),ul=Gt(Fe(32),t=>To(t,St.schnorr)),zE=Gt(Fe(null),t=>{if(t.length!==64&&t.length!==65)throw new Error("Schnorr signature should be 64 or 65 bytes long");return t}),dl=vt({fingerprint:kE,path:Yt(null,Be)}),XE=vt({hashes:Yt(kr,Fe(32)),der:dl}),F8=Fe(78),j8=vt({pubKey:ul,leafHash:Fe(32)}),W8=vt({version:wn,internalKey:Fe(32),merklePath:Yt(null,Fe(32))}),ki=Gt(W8,t=>{if(t.merklePath.length>128)throw new Error("TaprootControlBlock: merklePath should be of length 0..128 (inclusive)");return t}),G8=Yt(null,vt({depth:wn,version:wn,script:lr})),At=Fe(null),YE=Fe(20),Pu=Fe(32),fl={unsignedTx:[0,!1,Ts,[0],[0],!1],xpub:[1,F8,dl,[],[0,2],!1],txVersion:[2,!1,Be,[2],[2],!1],fallbackLocktime:[3,!1,Be,[],[2],!1],inputCount:[4,!1,kr,[2],[2],!1],outputCount:[5,!1,kr,[2],[2],!1],txModifiable:[6,!1,wn,[],[2],!1],version:[251,!1,Be,[],[0,2],!1],proprietary:[252,At,At,[],[0,2],!1]},Mu={nonWitnessUtxo:[0,!1,Di,[],[0,2],!1],witnessUtxo:[1,!1,Oi,[],[0,2],!1],partialSig:[2,i0,At,[],[0,2],!1],sighashType:[3,!1,Be,[],[0,2],!1],redeemScript:[4,!1,At,[],[0,2],!1],witnessScript:[5,!1,At,[],[0,2],!1],bip32Derivation:[6,i0,dl,[],[0,2],!1],finalScriptSig:[7,!1,At,[],[0,2],!1],finalScriptWitness:[8,!1,Yc,[],[0,2],!1],porCommitment:[9,!1,At,[],[0,2],!1],ripemd160:[10,YE,At,[],[0,2],!1],sha256:[11,Pu,At,[],[0,2],!1],hash160:[12,YE,At,[],[0,2],!1],hash256:[13,Pu,At,[],[0,2],!1],txid:[14,!1,Pu,[2],[2],!0],index:[15,!1,Be,[2],[2],!0],sequence:[16,!1,Be,[],[2],!0],requiredTimeLocktime:[17,!1,Be,[],[2],!1],requiredHeightLocktime:[18,!1,Be,[],[2],!1],tapKeySig:[19,!1,zE,[],[0,2],!1],tapScriptSig:[20,j8,zE,[],[0,2],!1],tapLeafScript:[21,ki,At,[],[0,2],!1],tapBip32Derivation:[22,Pu,XE,[],[0,2],!1],tapInternalKey:[23,!1,ul,[],[0,2],!1],tapMerkleRoot:[24,!1,Pu,[],[0,2],!1],proprietary:[252,At,At,[],[0,2],!1]},ZE=["txid","sequence","index","witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknown"],QE=["partialSig","finalScriptSig","finalScriptWitness","tapKeySig","tapScriptSig"],Ku={redeemScript:[0,!1,At,[],[0,2],!1],witnessScript:[1,!1,At,[],[0,2],!1],bip32Derivation:[2,i0,dl,[],[0,2],!1],amount:[3,!1,DE,[2],[2],!0],script:[4,!1,At,[2],[2],!0],tapInternalKey:[5,!1,ul,[],[0,2],!1],tapTree:[6,!1,G8,[],[0,2],!1],tapBip32Derivation:[7,ul,XE,[],[0,2],!1],proprietary:[252,At,At,[],[0,2],!1]},ev=[],JE=Yt(Yy,vt({key:NE(kr,vt({type:kr,key:Fe(null)})),value:Fe(kr)}));function o0(t){let[e,r,n,i,o,s]=t;return{type:e,kc:r,vc:n,reqInc:i,allowInc:o,silentIgnore:s}}var IM=vt({type:kr,key:Fe(null)});function s0(t){let e={};for(let r in t){let[n,i,o]=t[r];e[n]=[r,i,o]}return zt({encodeStream:(r,n)=>{let i=[];for(let o in t){let s=n[o];if(s===void 0)continue;let[c,a,u]=t[o];if(!a)i.push({key:{type:c,key:He},value:u.encode(s)});else{let d=s.map(([f,h])=>[a.encode(f),u.encode(h)]);d.sort((f,h)=>Lu(f[0],h[0]));for(let[f,h]of d)i.push({key:{key:f,type:c},value:h})}}if(n.unknown){n.unknown.sort((o,s)=>Lu(o[0].key,s[0].key));for(let[o,s]of n.unknown)i.push({key:o,value:s})}JE.encodeStream(r,i)},decodeStream:r=>{let n=JE.decodeStream(r),i={},o={};for(let s of n){let c="unknown",a=s.key.key,u=s.value;if(e[s.key.type]){let[d,f,h]=e[s.key.type];if(c=d,!f&&a.length)throw new Error(`PSBT: Non-empty key for ${c} (key=${ve.encode(a)} value=${ve.encode(u)}`);if(a=f?f.decode(a):void 0,u=h.decode(u),!f){if(i[c])throw new Error(`PSBT: Same keys: ${c} (key=${a} value=${u})`);i[c]=u,o[c]=!0;continue}}else a={type:s.key.type,key:s.key.key};if(o[c])throw new Error(`PSBT: Key type with empty key and no key=${c} val=${u}`);i[c]||(i[c]=[]),i[c].push([a,u])}return i}})}var ll=Gt(s0(Mu),t=>{if(t.finalScriptWitness&&!t.finalScriptWitness.length)throw new Error("validateInput: empty finalScriptWitness");if(t.partialSig&&!t.partialSig.length)throw new Error("Empty partialSig");if(t.partialSig)for(let[e]of t.partialSig)To(e,St.ecdsa);if(t.bip32Derivation)for(let[e]of t.bip32Derivation)To(e,St.ecdsa);if(t.requiredTimeLocktime!==void 0&&t.requiredTimeLocktime<5e8)throw new Error(`validateInput: wrong timeLocktime=${t.requiredTimeLocktime}`);if(t.requiredHeightLocktime!==void 0&&(t.requiredHeightLocktime<=0||t.requiredHeightLocktime>=5e8))throw new Error(`validateInput: wrong heighLocktime=${t.requiredHeightLocktime}`);if(t.tapLeafScript)for(let[e,r]of t.tapLeafScript){if((e.version&254)!==r[r.length-1])throw new Error("validateInput: tapLeafScript version mimatch");if(r[r.length-1]&1)throw new Error("validateInput: tapLeafScript version has parity bit!")}return t}),hl=Gt(s0(Ku),t=>{if(t.bip32Derivation)for(let[e]of t.bip32Derivation)To(e,St.ecdsa);return t}),tv=Gt(s0(fl),t=>{if((t.version||0)===0){if(!t.unsignedTx)throw new Error("PSBTv0: missing unsignedTx");for(let r of t.unsignedTx.inputs)if(r.finalScriptSig&&r.finalScriptSig.length)throw new Error("PSBTv0: input scriptSig found in unsignedTx")}return t}),z8=vt({magic:rl(tl(new Uint8Array([255])),"psbt"),global:tv,inputs:Yt("global/unsignedTx/inputs/length",ll),outputs:Yt(null,hl)}),Y8=vt({magic:rl(tl(new Uint8Array([255])),"psbt"),global:tv,inputs:Yt("global/inputCount",ll),outputs:Yt("global/outputCount",hl)}),BM=vt({magic:rl(tl(new Uint8Array([255])),"psbt"),items:Yt(null,mn(Yt(Yy,KE([CE(kr),Fe(zc)])),Ri.dict()))});function n0(t,e,r){for(let n in r){if(n==="unknown"||!e[n])continue;let{allowInc:i}=o0(e[n]);if(!i.includes(t))throw new Error(`PSBTv${t}: field ${n} is not allowed`)}for(let n in e){let{reqInc:i}=o0(e[n]);if(i.includes(t)&&r[n]===void 0)throw new Error(`PSBTv${t}: missing required field ${n}`)}}function c0(t,e,r){let n={};for(let i in r){let o=i;if(o!=="unknown"){if(!e[o])continue;let{allowInc:s,silentIgnore:c}=o0(e[o]);if(!s.includes(t)){if(c)continue;throw new Error(`Failed to serialize in PSBTv${t}: ${o} but versions allows inclusion=${s}`)}}n[o]=r[o]}return n}function rv(t){let e=t&&t.global&&t.global.version||0;n0(e,fl,t.global);for(let s of t.inputs)n0(e,Mu,s);for(let s of t.outputs)n0(e,Ku,s);let r=e?t.global.inputCount:t.global.unsignedTx.inputs.length;if(t.inputs.length<r)throw new Error("Not enough inputs");let n=t.inputs.slice(r);if(n.length>1||n.length&&Object.keys(n[0]).length)throw new Error(`Unexpected inputs left in tx=${n}`);let i=e?t.global.outputCount:t.global.unsignedTx.outputs.length;if(t.outputs.length<i)throw new Error("Not outputs inputs");let o=t.outputs.slice(i);if(o.length>1||o.length&&Object.keys(o[0]).length)throw new Error(`Unexpected outputs left in tx=${o}`);return t}function pl(t,e,r,n,i){let o={...r,...e};for(let s in t){let c=s,[a,u,d]=t[c],f=n&&!n.includes(s);if(e[s]===void 0&&s in e){if(f)throw new Error(`Cannot remove signed field=${s}`);delete o[s]}else if(u){let h=r&&r[s]?r[s]:[],p=e[c];if(p){if(!Array.isArray(p))throw new Error(`keyMap(${s}): KV pairs should be [k, v][]`);p=p.map(x=>{if(x.length!==2)throw new Error(`keyMap(${s}): KV pairs should be [k, v][]`);return[typeof x[0]=="string"?u.decode(ve.decode(x[0])):x[0],typeof x[1]=="string"?d.decode(ve.decode(x[1])):x[1]]});let g={},y=(x,S,I)=>{if(g[x]===void 0){g[x]=[S,I];return}let A=ve.encode(d.encode(g[x][1])),O=ve.encode(d.encode(I));if(A!==O)throw new Error(`keyMap(${c}): same key=${x} oldVal=${A} newVal=${O}`)};for(let[x,S]of h){let I=ve.encode(u.encode(x));y(I,x,S)}for(let[x,S]of p){let I=ve.encode(u.encode(x));if(S===void 0){if(f)throw new Error(`Cannot remove signed field=${c}/${x}`);delete g[I]}else y(I,x,S)}o[c]=Object.values(g)}}else if(typeof o[s]=="string")o[s]=d.decode(ve.decode(o[s]));else if(f&&s in e&&r&&r[s]!==void 0&&!at(d.encode(e[s]),d.encode(r[s])))throw new Error(`Cannot change signed field=${s}`)}for(let s in o)if(!t[s]){if(i&&s==="unknown")continue;delete o[s]}return o}var a0=Gt(z8,rv),u0=Gt(Y8,rv);var X8={encode(t){if(!(t.length!==2||t[0]!==1||!Ce(t[1])||ve.encode(t[1])!=="4e73"))return{type:"p2a",script:Ze.encode(t)}},decode:t=>{if(t.type==="p2a")return[1,ve.decode("4e73")]}};function _o(t,e){try{return To(t,e),!0}catch{return!1}}var Z8={encode(t){if(!(t.length!==2||!Ce(t[0])||!_o(t[0],St.ecdsa)||t[1]!=="CHECKSIG"))return{type:"pk",pubkey:t[0]}},decode:t=>t.type==="pk"?[t.pubkey,"CHECKSIG"]:void 0},Q8={encode(t){if(!(t.length!==5||t[0]!=="DUP"||t[1]!=="HASH160"||!Ce(t[2]))&&!(t[3]!=="EQUALVERIFY"||t[4]!=="CHECKSIG"))return{type:"pkh",hash:t[2]}},decode:t=>t.type==="pkh"?["DUP","HASH160",t.hash,"EQUALVERIFY","CHECKSIG"]:void 0},eR={encode(t){if(!(t.length!==3||t[0]!=="HASH160"||!Ce(t[1])||t[2]!=="EQUAL"))return{type:"sh",hash:t[1]}},decode:t=>t.type==="sh"?["HASH160",t.hash,"EQUAL"]:void 0},tR={encode(t){if(!(t.length!==2||t[0]!==0||!Ce(t[1]))&&t[1].length===32)return{type:"wsh",hash:t[1]}},decode:t=>t.type==="wsh"?[0,t.hash]:void 0},rR={encode(t){if(!(t.length!==2||t[0]!==0||!Ce(t[1]))&&t[1].length===20)return{type:"wpkh",hash:t[1]}},decode:t=>t.type==="wpkh"?[0,t.hash]:void 0},nR={encode(t){let e=t.length-1;if(t[e]!=="CHECKMULTISIG")return;let r=t[0],n=t[e-1];if(typeof r!="number"||typeof n!="number")return;let i=t.slice(1,-2);if(n===i.length){for(let o of i)if(!Ce(o))return;return{type:"ms",m:r,pubkeys:i}}},decode:t=>t.type==="ms"?[t.m,...t.pubkeys,t.pubkeys.length,"CHECKMULTISIG"]:void 0},iR={encode(t){if(!(t.length!==2||t[0]!==1||!Ce(t[1])))return{type:"tr",pubkey:t[1]}},decode:t=>t.type==="tr"?[1,t.pubkey]:void 0},oR={encode(t){let e=t.length-1;if(t[e]!=="CHECKSIG")return;let r=[];for(let n=0;n<e;n++){let i=t[n];if(n&1){if(i!=="CHECKSIGVERIFY"||n===e-1)return;continue}if(!Ce(i))return;r.push(i)}return{type:"tr_ns",pubkeys:r}},decode:t=>{if(t.type!=="tr_ns")return;let e=[];for(let r=0;r<t.pubkeys.length-1;r++)e.push(t.pubkeys[r],"CHECKSIGVERIFY");return e.push(t.pubkeys[t.pubkeys.length-1],"CHECKSIG"),e}},sR={encode(t){let e=t.length-1;if(t[e]!=="NUMEQUAL"||t[1]!=="CHECKSIG")return;let r=[],n=WE(t[e-1]);if(typeof n=="number"){for(let i=0;i<e-1;i++){let o=t[i];if(i&1){if(o!==(i===1?"CHECKSIG":"CHECKSIGADD"))throw new Error("OutScript.encode/tr_ms: wrong element");continue}if(!Ce(o))throw new Error("OutScript.encode/tr_ms: wrong key element");r.push(o)}return{type:"tr_ms",pubkeys:r,m:n}}},decode:t=>{if(t.type!=="tr_ms")return;let e=[t.pubkeys[0],"CHECKSIG"];for(let r=1;r<t.pubkeys.length;r++)e.push(t.pubkeys[r],"CHECKSIGADD");return e.push(t.m,"NUMEQUAL"),e}},cR={encode(t){return{type:"unknown",script:Ze.encode(t)}},decode:t=>t.type==="unknown"?Ze.decode(t.script):void 0},aR=[X8,Z8,Q8,eR,tR,rR,nR,iR,oR,sR,cR],uR=mn(Ze,Ri.match(aR)),Qe=Gt(uR,t=>{if(t.type==="pk"&&!_o(t.pubkey,St.ecdsa))throw new Error("OutScript/pk: wrong key");if((t.type==="pkh"||t.type==="sh"||t.type==="wpkh")&&(!Ce(t.hash)||t.hash.length!==20))throw new Error(`OutScript/${t.type}: wrong hash`);if(t.type==="wsh"&&(!Ce(t.hash)||t.hash.length!==32))throw new Error("OutScript/wsh: wrong hash");if(t.type==="tr"&&(!Ce(t.pubkey)||!_o(t.pubkey,St.schnorr)))throw new Error("OutScript/tr: wrong taproot public key");if((t.type==="ms"||t.type==="tr_ns"||t.type==="tr_ms")&&!Array.isArray(t.pubkeys))throw new Error("OutScript/multisig: wrong pubkeys array");if(t.type==="ms"){let e=t.pubkeys.length;for(let r of t.pubkeys)if(!_o(r,St.ecdsa))throw new Error("OutScript/multisig: wrong pubkey");if(t.m<=0||e>16||t.m>e)throw new Error("OutScript/multisig: invalid params")}if(t.type==="tr_ns"||t.type==="tr_ms"){for(let e of t.pubkeys)if(!_o(e,St.schnorr))throw new Error(`OutScript/${t.type}: wrong pubkey`)}if(t.type==="tr_ms"){let e=t.pubkeys.length;if(t.m<=0||e>999||t.m>e)throw new Error("OutScript/tr_ms: invalid params")}return t});function nv(t,e){if(!at(t.hash,ke(e)))throw new Error("checkScript: wsh wrong witnessScript hash");let r=Qe.decode(e);if(r.type==="tr"||r.type==="tr_ns"||r.type==="tr_ms")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2SH`);if(r.type==="wpkh"||r.type==="sh")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2WSH`)}function y0(t,e,r){if(t){let n=Qe.decode(t);if(n.type==="tr_ns"||n.type==="tr_ms"||n.type==="ms"||n.type=="pk")throw new Error(`checkScript: non-wrapped ${n.type}`);if(n.type==="sh"&&e){if(!at(n.hash,Gc(e)))throw new Error("checkScript: sh wrong redeemScript hash");let i=Qe.decode(e);if(i.type==="tr"||i.type==="tr_ns"||i.type==="tr_ms")throw new Error(`checkScript: P2${i.type} cannot be wrapped in P2SH`);if(i.type==="sh")throw new Error("checkScript: P2SH cannot be wrapped in P2SH")}n.type==="wsh"&&r&&nv(n,r)}if(e){let n=Qe.decode(e);n.type==="wsh"&&r&&nv(n,r)}}var Ni=(t,e=Jr)=>{if(!_o(t,St.ecdsa))throw new Error("P2PKH: invalid publicKey");let r=Gc(t);return{type:"pkh",script:Qe.encode({type:"pkh",hash:r}),address:Xr(e).encode({type:"pkh",hash:r}),hash:r}};var _s=(t,e=Jr)=>{if(!_o(t,St.ecdsa))throw new Error("P2WPKH: invalid publicKey");if(t.length===65)throw new Error("P2WPKH: uncompressed public key");let r=Gc(t);return{type:"wpkh",script:Qe.encode({type:"wpkh",hash:r}),address:Xr(e).encode({type:"wpkh",hash:r}),hash:r}};function dR(t,e,r=!1,n){let i=Qe.decode(t);if(i.type==="unknown"){if(n){let c=mn(Ze,Ri.match(n)).decode(t);if(c!==void 0){if(typeof c.type!="string"||!c.type.startsWith("tr_"))throw new Error(`P2TR: invalid custom type=${c.type}`);return}}if(r)return}if(!["tr_ns","tr_ms"].includes(i.type))throw new Error(`P2TR: invalid leaf script=${i.type}`);let o=i;if(!r&&o.pubkeys)for(let s of o.pubkeys){if(at(s,cl))throw new Error("Unspendable taproot key in leaf script");if(at(s,e))throw new Error("Using P2TR with leaf script with same key as internal key is not supported")}}function ov(t){let e=Array.from(t);for(;e.length>=2;){e.sort((s,c)=>(c.weight||1)-(s.weight||1));let n=e.pop(),i=e.pop(),o=(i?.weight||1)+(n?.weight||1);e.push({weight:o,childs:[i?.childs||i,n?.childs||n]})}let r=e[0];return r?.childs||r}function f0(t,e=[]){if(!t)throw new Error("taprootAddPath: empty tree");if(t.type==="leaf")return{...t,path:e};if(t.type!=="branch")throw new Error(`taprootAddPath: wrong type=${t}`);return{...t,path:e,left:f0(t.left,[t.right.hash,...e]),right:f0(t.right,[t.left.hash,...e])}}function l0(t){if(!t)throw new Error("taprootAddPath: empty tree");if(t.type==="leaf")return[t];if(t.type!=="branch")throw new Error(`taprootWalkTree: wrong type=${t}`);return[...l0(t.left),...l0(t.right)]}function h0(t,e,r=!1,n){if(!t)throw new Error("taprootHashTree: empty tree");if(Array.isArray(t)&&t.length===1&&(t=t[0]),!Array.isArray(t)){let{leafVersion:a,script:u}=t;if(t.tapLeafScript||t.tapMerkleRoot&&!at(t.tapMerkleRoot,He))throw new Error("P2TR: tapRoot leafScript cannot have tree");let d=typeof u=="string"?ve.decode(u):u;if(!Ce(d))throw new Error(`checkScript: wrong script type=${d}`);return dR(d,e,r,n),{type:"leaf",version:a,script:d,hash:$u(d,a)}}if(t.length!==2&&(t=ov(t)),t.length!==2)throw new Error("hashTree: non binary tree!");let i=h0(t[0],e,r,n),o=h0(t[1],e,r,n),[s,c]=[i.hash,o.hash];return Lu(c,s)===-1&&([s,c]=[c,s]),{type:"branch",left:i,right:o,hash:Nu("TapBranch",s,c)}}var p0=192,$u=(t,e=p0)=>Nu("TapLeaf",new Uint8Array([e]),lr.encode(t));function Is(t,e,r=Jr,n=!1,i){if(!t&&!e)throw new Error("p2tr: should have pubKey or scriptTree (or both)");let o=typeof t=="string"?ve.decode(t):t||cl;if(!_o(o,St.schnorr))throw new Error("p2tr: non-schnorr pubkey");if(e){let s=f0(h0(e,o,n,i)),c=s.hash,[a,u]=Cu(o,c),d=l0(s).map(f=>({...f,controlBlock:ki.encode({version:(f.version||p0)+u,internalKey:o,merklePath:f.path})}));return{type:"tr",script:Qe.encode({type:"tr",pubkey:a}),address:Xr(r).encode({type:"tr",pubkey:a}),tweakedPubkey:a,tapInternalKey:o,leaves:d,tapLeafScript:d.map(f=>[ki.decode(f.controlBlock),Wn(f.script,new Uint8Array([f.version||p0]))]),tapMerkleRoot:c}}else{let s=Cu(o,He)[0];return{type:"tr",script:Qe.encode({type:"tr",pubkey:s}),address:Xr(r).encode({type:"tr",pubkey:s}),tweakedPubkey:s,tapInternalKey:o}}}var sv=AE(ke);function cv(t,e){if(e.length<2||e.length>40)throw new Error("Witness: invalid length");if(t>16)throw new Error("Witness: invalid version");if(t===0&&!(e.length===20||e.length===32))throw new Error("Witness: invalid length for version")}function d0(t,e,r=Jr){cv(t,e);let n=t===0?Zf:As;return n.encode(r.bech32,[t].concat(n.toWords(e)))}function iv(t,e){return sv.encode(Wn(Uint8Array.from(e),t))}function Xr(t=Jr){return{encode(e){let{type:r}=e;if(r==="wpkh")return d0(0,e.hash,t);if(r==="wsh")return d0(0,e.hash,t);if(r==="tr")return d0(1,e.pubkey,t);if(r==="pkh")return iv(e.hash,[t.pubKeyHash]);if(r==="sh")return iv(e.hash,[t.scriptHash]);throw new Error(`Unknown address type=${r}`)},decode(e){if(e.length<14||e.length>74)throw new Error("Invalid address length");if(t.bech32&&e.toLowerCase().startsWith(`${t.bech32}1`)){let n;try{if(n=Zf.decode(e),n.words[0]!==0)throw new Error(`bech32: wrong version=${n.words[0]}`)}catch{if(n=As.decode(e),n.words[0]===0)throw new Error(`bech32m: wrong version=${n.words[0]}`)}if(n.prefix!==t.bech32)throw new Error(`wrong bech32 prefix=${n.prefix}`);let[i,...o]=n.words,s=Zf.fromWords(o);if(cv(i,s),i===0&&s.length===32)return{type:"wsh",hash:s};if(i===0&&s.length===20)return{type:"wpkh",hash:s};if(i===1&&s.length===32)return{type:"tr",pubkey:s};throw new Error("Unknown witness program")}let r=sv.decode(e);if(r.length!==21)throw new Error("Invalid base58 address");if(r[0]===t.pubKeyHash)return{type:"pkh",hash:r.slice(1)};if(r[0]===t.scriptHash)return{type:"sh",hash:r.slice(1)};throw new Error(`Invalid address prefix=${r[0]}`)}}}l();var yl=new Uint8Array(32),fR={amount:0xffffffffffffffffn,script:He},lR=t=>Math.ceil(t/4),hR=8,pR=2,Bs=0,b0=4294967295,yR=Ri.decimal(hR),Vu=(t,e)=>t===void 0?e:t;function ml(t){if(Array.isArray(t))return t.map(e=>ml(e));if(Ce(t))return Uint8Array.from(t);if(["number","bigint","boolean","string","undefined"].includes(typeof t))return t;if(t===null)return t;if(typeof t=="object")return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,ml(r)]));throw new Error(`cloneDeep: unknown type=${t} (${typeof t})`)}var je;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.ANYONECANPAY=128]="ANYONECANPAY"})(je||(je={}));var Io;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.DEFAULT_ANYONECANPAY=128]="DEFAULT_ANYONECANPAY",t[t.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",t[t.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",t[t.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY"})(Io||(Io={}));function gR(t,e,r,n=He){return at(r,e)&&(t=qE(t,n),e=sl(t)),{privKey:t,pubKey:e}}function Rs(t){if(t.script===void 0||t.amount===void 0)throw new Error("Transaction/output: script and amount required");return{script:t.script,amount:t.amount}}function Hu(t){if(t.txid===void 0||t.index===void 0)throw new Error("Transaction/input: txid and index required");return{txid:t.txid,index:t.index,sequence:Vu(t.sequence,b0),finalScriptSig:Vu(t.finalScriptSig,He)}}function g0(t){for(let e in t){let r=e;ZE.includes(r)||delete t[r]}}var m0=vt({txid:Fe(32,!0),index:Be});function mR(t){if(typeof t!="number"||typeof Io[t]!="string")throw new Error(`Invalid SigHash=${t}`);return t}function av(t){let e=t&31;return{isAny:!!(t&je.ANYONECANPAY),isNone:e===je.NONE,isSingle:e===je.SINGLE}}function wR(t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error(`Wrong object type for transaction options: ${t}`);let e={...t,version:Vu(t.version,pR),lockTime:Vu(t.lockTime,0),PSBTVersion:Vu(t.PSBTVersion,0)};if(typeof e.allowUnknowInput<"u"&&(t.allowUnknownInputs=e.allowUnknowInput),typeof e.allowUnknowOutput<"u"&&(t.allowUnknownOutputs=e.allowUnknowOutput),typeof e.lockTime!="number")throw new Error("Transaction lock time should be number");if(Be.encode(e.lockTime),e.PSBTVersion!==0&&e.PSBTVersion!==2)throw new Error(`Unknown PSBT version ${e.PSBTVersion}`);for(let r of["allowUnknownVersion","allowUnknownOutputs","allowUnknownInputs","disableScriptCheck","bip174jsCompat","allowLegacyWitnessUtxo","lowR"]){let n=e[r];if(n!==void 0&&typeof n!="boolean")throw new Error(`Transation options wrong type: ${r}=${n} (${typeof n})`)}if(e.allowUnknownVersion?typeof e.version=="number":![-1,0,1,2,3].includes(e.version))throw new Error(`Unknown version: ${e.version}`);if(e.customScripts!==void 0){let r=e.customScripts;if(!Array.isArray(r))throw new Error(`wrong custom scripts type (expected array): customScripts=${r} (${typeof r})`);for(let n of r){if(typeof n.encode!="function"||typeof n.decode!="function")throw new Error(`wrong script=${n} (${typeof n})`);if(n.finalizeTaproot!==void 0&&typeof n.finalizeTaproot!="function")throw new Error(`wrong script=${n} (${typeof n})`)}}return Object.freeze(e)}function uv(t){if(t.nonWitnessUtxo&&t.index!==void 0){let e=t.nonWitnessUtxo.outputs.length-1;if(t.index>e)throw new Error(`validateInput: index(${t.index}) not in nonWitnessUtxo`);let r=t.nonWitnessUtxo.outputs[t.index];if(t.witnessUtxo&&(!at(t.witnessUtxo.script,r.script)||t.witnessUtxo.amount!==r.amount))throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo");if(t.txid){if(t.nonWitnessUtxo.outputs.length-1<t.index)throw new Error("nonWitnessUtxo: incorect output index");let i=Us.fromRaw(Di.encode(t.nonWitnessUtxo),{allowUnknownOutputs:!0,disableScriptCheck:!0,allowUnknownInputs:!0}),o=ve.encode(t.txid);if(i.isFinal&&i.id!==o)throw new Error(`nonWitnessUtxo: wrong txid, exp=${o} got=${i.id}`)}}return t}function gl(t){if(t.nonWitnessUtxo){if(t.index===void 0)throw new Error("Unknown input index");return t.nonWitnessUtxo.outputs[t.index]}else{if(t.witnessUtxo)return t.witnessUtxo;throw new Error("Cannot find previous output info")}}function dv(t,e,r,n=!1,i=!1){let{nonWitnessUtxo:o,txid:s}=t;typeof o=="string"&&(o=ve.decode(o)),Ce(o)&&(o=Di.decode(o)),!("nonWitnessUtxo"in t)&&o===void 0&&(o=e?.nonWitnessUtxo),typeof s=="string"&&(s=ve.decode(s)),s===void 0&&(s=e?.txid);let c={...e,...t,nonWitnessUtxo:o,txid:s};!("nonWitnessUtxo"in t)&&c.nonWitnessUtxo===void 0&&delete c.nonWitnessUtxo,c.sequence===void 0&&(c.sequence=b0),c.tapMerkleRoot===null&&delete c.tapMerkleRoot,c=pl(Mu,c,e,r,i),ll.encode(c);let a;return c.nonWitnessUtxo&&c.index!==void 0?a=c.nonWitnessUtxo.outputs[c.index]:c.witnessUtxo&&(a=c.witnessUtxo),a&&!n&&y0(a&&a.script,c.redeemScript,c.witnessScript),c}function w0(t,e=!1){let r="legacy",n=je.ALL,i=gl(t),o=Qe.decode(i.script),s=o.type,c=o,a=[o];if(o.type==="tr")return n=je.DEFAULT,{txType:"taproot",type:"tr",last:o,lastScript:i.script,defaultSighash:n,sighash:t.sighashType||n};{if((o.type==="wpkh"||o.type==="wsh")&&(r="segwit"),o.type==="sh"){if(!t.redeemScript)throw new Error("inputType: sh without redeemScript");let h=Qe.decode(t.redeemScript);(h.type==="wpkh"||h.type==="wsh")&&(r="segwit"),a.push(h),c=h,s+=`-${h.type}`}if(c.type==="wsh"){if(!t.witnessScript)throw new Error("inputType: wsh without witnessScript");let h=Qe.decode(t.witnessScript);h.type==="wsh"&&(r="segwit"),a.push(h),c=h,s+=`-${h.type}`}let u=a[a.length-1];if(u.type==="sh"||u.type==="wsh")throw new Error("inputType: sh/wsh cannot be terminal type");let d=Qe.encode(u),f={type:s,txType:r,last:u,lastScript:d,defaultSighash:n,sighash:t.sighashType||n};if(r==="legacy"&&!e&&!t.nonWitnessUtxo)throw new Error("Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure");return f}}var Us=class t{constructor(e={}){this.global={},this.inputs=[],this.outputs=[];let r=this.opts=wR(e);r.lockTime!==Bs&&(this.global.fallbackLocktime=r.lockTime),this.global.txVersion=r.version}static fromRaw(e,r={}){let n=Di.decode(e),i=new t({...r,version:n.version,lockTime:n.lockTime});for(let o of n.outputs)i.addOutput(o);if(i.outputs=n.outputs,i.inputs=n.inputs,n.witnesses)for(let o=0;o<n.witnesses.length;o++)i.inputs[o].finalScriptWitness=n.witnesses[o];return i}static fromPSBT(e,r={}){let n;try{n=a0.decode(e)}catch(f){try{n=u0.decode(e)}catch{throw f}}let i=n.global.version||0;if(i!==0&&i!==2)throw new Error(`Wrong PSBT version=${i}`);let o=n.global.unsignedTx,s=i===0?o?.version:n.global.txVersion,c=i===0?o?.lockTime:n.global.fallbackLocktime,a=new t({...r,version:s,lockTime:c,PSBTVersion:i}),u=i===0?o?.inputs.length:n.global.inputCount;a.inputs=n.inputs.slice(0,u).map((f,h)=>uv({finalScriptSig:He,...n.global.unsignedTx?.inputs[h],...f}));let d=i===0?o?.outputs.length:n.global.outputCount;return a.outputs=n.outputs.slice(0,d).map((f,h)=>({...f,...n.global.unsignedTx?.outputs[h]})),a.global={...n.global,txVersion:s},c!==Bs&&(a.global.fallbackLocktime=c),a}toPSBT(e=this.opts.PSBTVersion){if(e!==0&&e!==2)throw new Error(`Wrong PSBT version=${e}`);let r=this.inputs.map(o=>uv(c0(e,Mu,o)));for(let o of r)o.partialSig&&!o.partialSig.length&&delete o.partialSig,o.finalScriptSig&&!o.finalScriptSig.length&&delete o.finalScriptSig,o.finalScriptWitness&&!o.finalScriptWitness.length&&delete o.finalScriptWitness;let n=this.outputs.map(o=>c0(e,Ku,o)),i={...this.global};return e===0?(i.unsignedTx=Ts.decode(Ts.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(Hu).map(o=>({...o,finalScriptSig:He})),outputs:this.outputs.map(Rs)})),delete i.fallbackLocktime,delete i.txVersion):(i.version=e,i.txVersion=this.version,i.inputCount=this.inputs.length,i.outputCount=this.outputs.length,i.fallbackLocktime&&i.fallbackLocktime===Bs&&delete i.fallbackLocktime),this.opts.bip174jsCompat&&(r.length||r.push({}),n.length||n.push({})),(e===0?a0:u0).encode({global:i,inputs:r,outputs:n})}get lockTime(){let e=Bs,r=0,n=Bs,i=0;for(let o of this.inputs)o.requiredHeightLocktime&&(e=Math.max(e,o.requiredHeightLocktime),r++),o.requiredTimeLocktime&&(n=Math.max(n,o.requiredTimeLocktime),i++);return r&&r>=i?e:n!==Bs?n:this.global.fallbackLocktime||Bs}get version(){if(this.global.txVersion===void 0)throw new Error("No global.txVersion");return this.global.txVersion}inputStatus(e){this.checkInputIdx(e);let r=this.inputs[e];return r.finalScriptSig&&r.finalScriptSig.length||r.finalScriptWitness&&r.finalScriptWitness.length?"finalized":r.tapKeySig||r.tapScriptSig&&r.tapScriptSig.length||r.partialSig&&r.partialSig.length?"signed":"unsigned"}inputSighash(e){this.checkInputIdx(e);let r=this.inputs[e].sighashType,n=r===void 0?je.DEFAULT:r,i=n===je.DEFAULT?je.ALL:n&3;return{sigInputs:n&je.ANYONECANPAY,sigOutputs:i}}signStatus(){let e=!0,r=!0,n=[],i=[];for(let o=0;o<this.inputs.length;o++){if(this.inputStatus(o)==="unsigned")continue;let{sigInputs:c,sigOutputs:a}=this.inputSighash(o);if(c===je.ANYONECANPAY?n.push(o):e=!1,a===je.ALL)r=!1;else if(a===je.SINGLE)i.push(o);else if(a!==je.NONE)throw new Error(`Wrong signature hash output type: ${a}`)}return{addInput:e,addOutput:r,inputs:n,outputs:i}}get isFinal(){for(let e=0;e<this.inputs.length;e++)if(this.inputStatus(e)!=="finalized")return!1;return!0}get hasWitnesses(){let e=!1;for(let r of this.inputs)r.finalScriptWitness&&r.finalScriptWitness.length&&(e=!0);return e}get weight(){if(!this.isFinal)throw new Error("Transaction is not finalized");let e=32,r=this.outputs.map(Rs);e+=4*kr.encode(this.outputs.length).length;for(let n of r)e+=32+4*lr.encode(n.script).length;this.hasWitnesses&&(e+=2),e+=4*kr.encode(this.inputs.length).length;for(let n of this.inputs)e+=160+4*lr.encode(n.finalScriptSig||He).length,this.hasWitnesses&&n.finalScriptWitness&&(e+=Yc.encode(n.finalScriptWitness).length);return e}get vsize(){return lR(this.weight)}toBytes(e=!1,r=!1){return Di.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(Hu).map(n=>({...n,finalScriptSig:e&&n.finalScriptSig||He})),outputs:this.outputs.map(Rs),witnesses:this.inputs.map(n=>n.finalScriptWitness||[]),segwitFlag:r&&this.hasWitnesses})}get unsignedTx(){return this.toBytes(!1,!1)}get hex(){return ve.encode(this.toBytes(!0,this.hasWitnesses))}get hash(){if(!this.isFinal)throw new Error("Transaction is not finalized");return ve.encode(Ui(this.toBytes(!0)))}get id(){if(!this.isFinal)throw new Error("Transaction is not finalized");return ve.encode(Ui(this.toBytes(!0)).reverse())}checkInputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.inputs.length)throw new Error(`Wrong input index=${e}`)}getInput(e){return this.checkInputIdx(e),ml(this.inputs[e])}get inputsLength(){return this.inputs.length}addInput(e,r=!1){if(!r&&!this.signStatus().addInput)throw new Error("Tx has signed inputs, cannot add new one");return this.inputs.push(dv(e,void 0,void 0,this.opts.disableScriptCheck)),this.inputs.length-1}updateInput(e,r,n=!1){this.checkInputIdx(e);let i;if(!n){let o=this.signStatus();(!o.addInput||o.inputs.includes(e))&&(i=QE)}this.inputs[e]=dv(r,this.inputs[e],i,this.opts.disableScriptCheck,this.opts.allowUnknown)}checkOutputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.outputs.length)throw new Error(`Wrong output index=${e}`)}getOutput(e){return this.checkOutputIdx(e),ml(this.outputs[e])}getOutputAddress(e,r=Jr){let n=this.getOutput(e);if(n.script)return Xr(r).encode(Qe.decode(n.script))}get outputsLength(){return this.outputs.length}normalizeOutput(e,r,n){let{amount:i,script:o}=e;if(i===void 0&&(i=r?.amount),typeof i!="bigint")throw new Error(`Wrong amount type, should be of type bigint in sats, but got ${i} of type ${typeof i}`);typeof o=="string"&&(o=ve.decode(o)),o===void 0&&(o=r?.script);let s={...r,...e,amount:i,script:o};if(s.amount===void 0&&delete s.amount,s=pl(Ku,s,r,n,this.opts.allowUnknown),hl.encode(s),s.script&&!this.opts.allowUnknownOutputs&&Qe.decode(s.script).type==="unknown")throw new Error("Transaction/output: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure");return this.opts.disableScriptCheck||y0(s.script,s.redeemScript,s.witnessScript),s}addOutput(e,r=!1){if(!r&&!this.signStatus().addOutput)throw new Error("Tx has signed outputs, cannot add new one");return this.outputs.push(this.normalizeOutput(e)),this.outputs.length-1}updateOutput(e,r,n=!1){this.checkOutputIdx(e);let i;if(!n){let o=this.signStatus();(!o.addOutput||o.outputs.includes(e))&&(i=ev)}this.outputs[e]=this.normalizeOutput(r,this.outputs[e],i)}addOutputAddress(e,r,n=Jr){return this.addOutput({script:Qe.encode(Xr(n).decode(e)),amount:r})}get fee(){let e=0n;for(let n of this.inputs){let i=gl(n);if(!i)throw new Error("Empty input amount");e+=i.amount}let r=this.outputs.map(Rs);for(let n of r)e-=n.amount;return e}preimageLegacy(e,r,n){let{isAny:i,isNone:o,isSingle:s}=av(n);if(e<0||!Number.isSafeInteger(e))throw new Error(`Invalid input idx=${e}`);if(s&&e>=this.outputs.length||e>=this.inputs.length)return OE.encode(1n);r=Ze.encode(Ze.decode(r).filter(d=>d!=="CODESEPARATOR"));let c=this.inputs.map(Hu).map((d,f)=>({...d,finalScriptSig:f===e?r:He}));i?c=[c[e]]:(o||s)&&(c=c.map((d,f)=>({...d,sequence:f===e?d.sequence:0})));let a=this.outputs.map(Rs);o?a=[]:s&&(a=a.slice(0,e).fill(fR).concat([a[e]]));let u=Di.encode({lockTime:this.lockTime,version:this.version,segwitFlag:!1,inputs:c,outputs:a});return Ui(u,Ao.encode(n))}preimageWitnessV0(e,r,n,i){let{isAny:o,isNone:s,isSingle:c}=av(n),a=yl,u=yl,d=yl,f=this.inputs.map(Hu),h=this.outputs.map(Rs);o||(a=Ui(...f.map(m0.encode))),!o&&!c&&!s&&(u=Ui(...f.map(g=>Be.encode(g.sequence)))),!c&&!s?d=Ui(...h.map(Oi.encode)):c&&e<h.length&&(d=Ui(Oi.encode(h[e])));let p=f[e];return Ui(Ao.encode(this.version),a,u,Fe(32,!0).encode(p.txid),Be.encode(p.index),lr.encode(r),Wc.encode(i),Be.encode(p.sequence),d,Be.encode(this.lockTime),Be.encode(n))}preimageWitnessV1(e,r,n,i,o=-1,s,c=192,a){if(!Array.isArray(i)||this.inputs.length!==i.length)throw new Error(`Invalid amounts array=${i}`);if(!Array.isArray(r)||this.inputs.length!==r.length)throw new Error(`Invalid prevOutScript array=${r}`);let u=[wn.encode(0),wn.encode(n),Ao.encode(this.version),Be.encode(this.lockTime)],d=n===je.DEFAULT?je.ALL:n&3,f=n&je.ANYONECANPAY,h=this.inputs.map(Hu),p=this.outputs.map(Rs);f!==je.ANYONECANPAY&&u.push(...[h.map(m0.encode),i.map(Wc.encode),r.map(lr.encode),h.map(y=>Be.encode(y.sequence))].map(y=>ke(Wn(...y)))),d===je.ALL&&u.push(ke(Wn(...p.map(Oi.encode))));let g=(a?1:0)|(s?2:0);if(u.push(new Uint8Array([g])),f===je.ANYONECANPAY){let y=h[e];u.push(m0.encode(y),Wc.encode(i[e]),lr.encode(r[e]),Be.encode(y.sequence))}else u.push(Be.encode(e));return g&1&&u.push(ke(lr.encode(a||He))),d===je.SINGLE&&u.push(e<p.length?ke(Oi.encode(p[e])):yl),s&&u.push($u(s,c),wn.encode(0),Ao.encode(o)),Nu("TapSighash",...u)}signIdx(e,r,n,i){this.checkInputIdx(r);let o=this.inputs[r],s=w0(o,this.opts.allowLegacyWitnessUtxo);if(!Ce(e)){if(!o.bip32Derivation||!o.bip32Derivation.length)throw new Error("bip32Derivation: empty");let d=o.bip32Derivation.filter(h=>h[1].fingerprint==e.fingerprint).map(([h,{path:p}])=>{let g=e;for(let y of p)g=g.deriveChild(y);if(!at(g.publicKey,h))throw new Error("bip32Derivation: wrong pubKey");if(!g.privateKey)throw new Error("bip32Derivation: no privateKey");return g});if(!d.length)throw new Error(`bip32Derivation: no items with fingerprint=${e.fingerprint}`);let f=!1;for(let h of d)this.signIdx(h.privateKey,r)&&(f=!0);return f}n?n.forEach(mR):n=[s.defaultSighash];let c=s.sighash;if(!n.includes(c))throw new Error(`Input with not allowed sigHash=${c}. Allowed: ${n.join(", ")}`);let{sigOutputs:a}=this.inputSighash(r);if(a===je.SINGLE&&r>=this.outputs.length)throw new Error(`Input with sighash SINGLE, but there is no output with corresponding index=${r}`);let u=gl(o);if(s.txType==="taproot"){let d=this.inputs.map(gl),f=d.map(x=>x.script),h=d.map(x=>x.amount),p=!1,g=sl(e),y=o.tapMerkleRoot||He;if(o.tapInternalKey){let{pubKey:x,privKey:S}=gR(e,g,o.tapInternalKey,y),[I,A]=Cu(o.tapInternalKey,y);if(at(I,x)){let O=this.preimageWitnessV1(r,f,c,h),T=Wn(e0(O,S,i),c!==je.DEFAULT?new Uint8Array([c]):He);this.updateInput(r,{tapKeySig:T},!0),p=!0}}if(o.tapLeafScript){o.tapScriptSig=o.tapScriptSig||[];for(let[x,S]of o.tapLeafScript){let I=S.subarray(0,-1),A=Ze.decode(I),O=S[S.length-1],T=$u(I,O);if(A.findIndex($=>Ce($)&&at($,g))===-1)continue;let q=this.preimageWitnessV1(r,f,c,h,void 0,I,O),j=Wn(e0(q,e,i),c!==je.DEFAULT?new Uint8Array([c]):He);this.updateInput(r,{tapScriptSig:[[{pubKey:g,leafHash:T},j]]},!0),p=!0}}if(!p)throw new Error("No taproot scripts signed");return!0}else{let d=Qy(e),f=!1,h=Gc(d);for(let y of Ze.decode(s.lastScript))Ce(y)&&(at(y,d)||at(y,h))&&(f=!0);if(!f)throw new Error(`Input script doesn't have pubKey: ${s.lastScript}`);let p;if(s.txType==="legacy")p=this.preimageLegacy(r,s.lastScript,c);else if(s.txType==="segwit"){let y=s.lastScript;s.last.type==="wpkh"&&(y=Qe.encode({type:"pkh",hash:s.last.hash})),p=this.preimageWitnessV0(r,y,c,u.amount)}else throw new Error(`Transaction/sign: unknown tx type: ${s.txType}`);let g=HE(p,e,this.opts.lowR);this.updateInput(r,{partialSig:[[d,Wn(g,new Uint8Array([c]))]]},!0)}return!0}sign(e,r,n){let i=0;for(let o=0;o<this.inputs.length;o++)try{this.signIdx(e,o,r,n)&&i++}catch{}if(!i)throw new Error("No inputs signed");return i}finalizeIdx(e){if(this.checkInputIdx(e),this.fee<0n)throw new Error("Outputs spends more than inputs amount");let r=this.inputs[e],n=w0(r,this.opts.allowLegacyWitnessUtxo);if(n.txType==="taproot"){if(r.tapKeySig)r.finalScriptWitness=[r.tapKeySig];else if(r.tapLeafScript&&r.tapScriptSig){let a=r.tapLeafScript.sort((u,d)=>ki.encode(u[0]).length-ki.encode(d[0]).length);for(let[u,d]of a){let f=d.slice(0,-1),h=d[d.length-1],p=Qe.decode(f),g=$u(f,h),y=r.tapScriptSig.filter(S=>at(S[0].leafHash,g)),x=[];if(p.type==="tr_ms"){let S=p.m,I=p.pubkeys,A=0;for(let O of I){let T=y.findIndex(M=>at(M[0].pubKey,O));if(A===S||T===-1){x.push(He);continue}x.push(y[T][1]),A++}if(A!==S)continue}else if(p.type==="tr_ns"){for(let S of p.pubkeys){let I=y.findIndex(A=>at(A[0].pubKey,S));I!==-1&&x.push(y[I][1])}if(x.length!==p.pubkeys.length)continue}else if(p.type==="unknown"&&this.opts.allowUnknownInputs){let S=Ze.decode(f);if(x=y.map(([{pubKey:I},A])=>{let O=S.findIndex(T=>Ce(T)&&at(T,I));if(O===-1)throw new Error("finalize/taproot: cannot find position of pubkey in script");return{signature:A,pos:O}}).sort((I,A)=>I.pos-A.pos).map(I=>I.signature),!x.length)continue}else{let S=this.opts.customScripts;if(S)for(let I of S){if(!I.finalizeTaproot)continue;let A=Ze.decode(f),O=I.encode(A);if(O===void 0)continue;let T=I.finalizeTaproot(f,O,y);if(T){r.finalScriptWitness=T.concat(ki.encode(u)),r.finalScriptSig=He,g0(r);return}}throw new Error("Finalize: Unknown tapLeafScript")}r.finalScriptWitness=x.reverse().concat([f,ki.encode(u)]);break}if(!r.finalScriptWitness)throw new Error("finalize/taproot: empty witness")}else throw new Error("finalize/taproot: unknown input");r.finalScriptSig=He,g0(r);return}if(!r.partialSig||!r.partialSig.length)throw new Error("Not enough partial sign");let i=He,o=[];if(n.last.type==="ms"){let a=n.last.m,u=n.last.pubkeys,d=[];for(let f of u){let h=r.partialSig.find(p=>at(f,p[0]));h&&d.push(h[1])}if(d=d.slice(0,a),d.length!==a)throw new Error(`Multisig: wrong signatures count, m=${a} n=${u.length} signatures=${d.length}`);i=Ze.encode([0,...d])}else if(n.last.type==="pk")i=Ze.encode([r.partialSig[0][1]]);else if(n.last.type==="pkh")i=Ze.encode([r.partialSig[0][1],r.partialSig[0][0]]);else if(n.last.type==="wpkh")i=He,o=[r.partialSig[0][1],r.partialSig[0][0]];else if(n.last.type==="unknown"&&!this.opts.allowUnknownInputs)throw new Error("Unknown inputs not allowed");let s,c;if(n.type.includes("wsh-")&&(i.length&&n.lastScript.length&&(o=Ze.decode(i).map(a=>{if(a===0)return He;if(Ce(a))return a;throw new Error(`Wrong witness op=${a}`)})),o=o.concat(n.lastScript)),n.txType==="segwit"&&(c=o),n.type.startsWith("sh-wsh-")?s=Ze.encode([Ze.encode([0,ke(n.lastScript)])]):n.type.startsWith("sh-")?s=Ze.encode([...Ze.decode(i),n.lastScript]):n.type.startsWith("wsh-")||n.txType!=="segwit"&&(s=i),!s&&!c)throw new Error("Unknown error finalizing input");s&&(r.finalScriptSig=s),c&&(r.finalScriptWitness=c),g0(r)}finalize(){for(let e=0;e<this.inputs.length;e++)this.finalizeIdx(e)}extract(){if(!this.isFinal)throw new Error("Transaction has unfinalized inputs");if(!this.outputs.length)throw new Error("Transaction has no outputs");if(this.fee<0n)throw new Error("Outputs spends more than inputs amount");return this.toBytes(!0,!0)}combine(e){for(let i of["PSBTVersion","version","lockTime"])if(this.opts[i]!==e.opts[i])throw new Error(`Transaction/combine: different ${i} this=${this.opts[i]} other=${e.opts[i]}`);for(let i of["inputs","outputs"])if(this[i].length!==e[i].length)throw new Error(`Transaction/combine: different ${i} length this=${this[i].length} other=${e[i].length}`);let r=this.global.unsignedTx?Ts.encode(this.global.unsignedTx):He,n=e.global.unsignedTx?Ts.encode(e.global.unsignedTx):He;if(!at(r,n))throw new Error("Transaction/combine: different unsigned tx");this.global=pl(fl,this.global,e.global,void 0,this.opts.allowUnknown);for(let i=0;i<this.inputs.length;i++)this.updateInput(i,e.inputs[i],!0);for(let i=0;i<this.outputs.length;i++)this.updateOutput(i,e.outputs[i],!0);return this}clone(){return t.fromPSBT(this.toPSBT(this.opts.PSBTVersion),this.opts)}};l();l();l();l();l();function fv(t,e){var r="",n=e&&e.include,i=e&&e.exclude;i&&typeof i=="string"&&(i=[i]),n&&n.sort();var o=new WeakMap,s=e&&e.allowCircular,c=e&&e.filterUndefined,a=e&&e.undefinedInArrayToNull;return u(t,""),r;function u(d,f){if(d===null||typeof d!="object"||d.toJSON!=null)r+=JSON.stringify(d);else if(Array.isArray(d)){var h=o.get(d);if(h!==void 0&&f.startsWith(h)){if(!s)throw new Error("Circular reference detected");r+='"[Circular]"';return}o.set(d,f),r+="[";var p=!1;d.forEach(function(S,I){p&&(r+=","),p=!0,a&&S===void 0&&(S=null),u(S,f+"["+I+"]")}),r+="]"}else{var h=o.get(d);if(h!==void 0&&f.startsWith(h)){if(!s)throw new Error("Circular reference detected");r+='"[Circular]"';return}o.set(d,f),r+="{";var g=!1,y=function(I){i&&i.includes(I)||(g&&(r+=","),g=!0,r+=JSON.stringify(I),r+=":",u(d[I],f+"."+I))};if(f===""&&n)n.forEach(function(I){d.hasOwnProperty(I)&&y(I)});else{var x=Object.keys(d);c&&(x=x.filter(function(I){return d[I]!==void 0})),x.sort(),x.forEach(function(I){y(I)})}r+="}"}}}function lv(t,e){return fv(t,{allowCircular:e,filterUndefined:!0,undefinedInArrayToNull:!0})}l();var x0;(function(t){t.INVALID_DID="INVALID_DID",t.METHOD_NOT_SUPPORTED="METHOD_NOT_SUPPORTED",t.INTERNAL_ERROR="INTERNAL_ERROR",t.INVALID_DID_DOCUMENT="INVALID_DID_DOCUMENT",t.INVALID_DID_UPDATE="INVALID_DID_UPDATE",t.INVALID_DID_DOCUMENT_LENGTH="INVALID_DID_DOCUMENT_LENGTH",t.INVALID_DID_URL="INVALID_DID_URL",t.INVALID_PREVIOUS_DID_PROOF="INVALID_PREVIOUS_DID_PROOF",t.INVALID_PUBLIC_KEY="INVALID_PUBLIC_KEY",t.INVALID_PUBLIC_KEY_MULTIBASE="INVALID_PUBLIC_KEY_MULTIBASE",t.INVALID_PUBLIC_KEY_LENGTH="INVALID_PUBLIC_KEY_LENGTH",t.INVALID_PUBLIC_KEY_TYPE="INVALID_PUBLIC_KEY_TYPE",t.INVALID_SIGNATURE="INVALID_SIGNATURE",t.NOT_FOUND="NOT_FOUND",t.REPRESENTATION_NOT_SUPPORTED="REPRESENTATION_NOT_SUPPORTED",t.UNSUPPORTED_PUBLIC_KEY_TYPE="UNSUPPORTED_PUBLIC_KEY_TYPE",t.PROOF_VERIFICATION_ERROR="PROOF_VERIFICATION_ERROR",t.PROOF_GENERATION_ERROR="PROOF_GENERATION_ERROR",t.PROOF_SERIALIZATION_ERROR="PROOF_SERIALIZATION_ERROR",t.PROOF_PARSING_ERROR="PROOF_PARSING_ERROR",t.VERIFICATION_METHOD_ERROR="VERIFICATION_METHOD_ERROR",t.LATE_PUBLISHING_ERROR="LATE_PUBLISHING_ERROR",t.INVALID_SIDECAR_DATA="INVALID_SIDECAR_DATA",t.MISSING_UPDATE_DATA="MISSING_UPDATE_DATA",t.INVALID_UPDATE="INVALID_UPDATE",t.INVALID_DOMAIN_ERROR="INVALID_DOMAIN_ERROR",t.MISSING_RESOLUTION_OPTIONS="MISSING_RESOLUTION_OPTIONS",t.INVALID_OPTIONS="INVALID_OPTIONS"})(x0||(x0={}));var{INVALID_DID:pt,METHOD_NOT_SUPPORTED:wl,INTERNAL_ERROR:bl,INVALID_DID_DOCUMENT:qe,INVALID_DID_UPDATE:fe,INVALID_DID_URL:mK,INVALID_PREVIOUS_DID_PROOF:wK,INVALID_PUBLIC_KEY:bK,INVALID_PUBLIC_KEY_MULTIBASE:xK,INVALID_PUBLIC_KEY_LENGTH:EK,INVALID_PUBLIC_KEY_TYPE:vK,INVALID_SIGNATURE:SK,NOT_FOUND:hv,PROOF_VERIFICATION_ERROR:Ci,PROOF_GENERATION_ERROR:Ro,PROOF_SERIALIZATION_ERROR:pv,PROOF_PARSING_ERROR:AK,VERIFICATION_METHOD_ERROR:xl,LATE_PUBLISHING_ERROR:El,INVALID_SIDECAR_DATA:TK,MISSING_UPDATE_DATA:_K,MISSING_RESOLUTION_OPTIONS:IK,INVALID_OPTIONS:qu}=x0,kt=class t extends Error{name="DidMethodError";type="DidMethodError";data;constructor(e,r={}){super(e),this.type=r.type??this.type,this.name=r.name??this.name,this.data=r.data,Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace?.(this,t)}},be=class extends kt{constructor(e,r="MethodError",n){super(e,{type:r,name:r,data:n})}};var ut=class extends kt{constructor(e,r="IdentifierError",n){super(e,{type:r,name:r,data:n})}},nt=class extends kt{constructor(e,r="UpdateError",n){super(e,{type:r,name:r,data:n})}},le=class extends kt{constructor(e,r="ResolveError",n){super(e,{type:r,name:r,data:n})}};var Ve=class extends kt{constructor(e,r="DidDocumentError",n){super(e,{type:r,name:r,data:n})}},Bo=class extends kt{constructor(e,r="CryptosuiteError",n){super(e,{type:r,name:r,data:n})}},bn=class extends kt{constructor(e,r="DataIntegrityProofError",n){super(e,{type:r,name:r,data:n})}},xn=class extends kt{constructor(e,r="KeyPairError",n){super(e,{type:r,name:r,data:n})}},Gn=class extends kt{constructor(e,r="SecretKeyError",n){super(e,{type:r,name:r,data:n})}},Os=class extends kt{constructor(e,r="PublicKeyError",n){super(e,{type:r,name:r,data:n})}},En=class extends kt{constructor(e,r="MultikeyError",n){super(e,{type:r,name:r,data:n})}};var Jc=class extends kt{constructor(e,r="CanonicalizationError",n){super(e,{type:r,name:r,data:n})}};var bR=new Set(["jcs"]),xR=new Set(["hex","base58","base64urlnopad"]);function E0(t){let e=t.toLowerCase();if(!bR.has(e))throw new Jc(`Unsupported algorithm: ${t}`,"ALGORITHM_ERROR");return e}function v0(t){let e=t.toLowerCase();if(!xR.has(e))throw new Jc(`Unsupported encoding: ${t}`,"ENCODING_ERROR");return e}function Kt(t,e="jcs"){switch(E0(e)){case"jcs":{let n=JSON.parse(JSON.stringify(t));return lv(n)}default:throw new Jc(`Unsupported algorithm: ${e}`,"ALGORITHM_ERROR")}}function Uo(t){return ke(t)}function Zr(t,e="base64urlnopad"){switch(v0(e)){case"hex":return ve.encode(t);case"base58":return Xf.encode(t);case"base64urlnopad":return qc.encode(t)}}function Xc(t,e="base64urlnopad"){switch(v0(e)){case"hex":return ve.decode(t);case"base58":return Xf.decode(t);case"base64urlnopad":return qc.decode(t)}}function Oo(t,e="jcs"){return Uo(Kt(t,E0(e)))}function zn(t,e){let r=E0(e?.algorithm??"jcs"),n=v0(e?.encoding??"base64urlnopad");return Zr(Uo(Kt(t,r)),n)}l();l();var S0={};If(S0,{JsonPatchError:()=>dt,_areEquals:()=>Wu,applyOperation:()=>Ds,applyPatch:()=>Bl,applyReducer:()=>TR,deepClone:()=>SR,getValueByPointer:()=>_l,validate:()=>gv,validator:()=>Il});l();l();var ER=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var o in i)i.hasOwnProperty(o)&&(n[o]=i[o])},t(e,r)};return function(e,r){t(e,r);function n(){this.constructor=e}e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),vR=Object.prototype.hasOwnProperty;function Sl(t,e){return vR.call(t,e)}function Al(t){if(Array.isArray(t)){for(var e=new Array(t.length),r=0;r<e.length;r++)e[r]=""+r;return e}if(Object.keys)return Object.keys(t);var n=[];for(var i in t)Sl(t,i)&&n.push(i);return n}function $t(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function Tl(t){for(var e=0,r=t.length,n;e<r;){if(n=t.charCodeAt(e),n>=48&&n<=57){e++;continue}return!1}return!0}function Yn(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function Fu(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function vl(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)if(vl(t[e]))return!0}else if(typeof t=="object"){for(var n=Al(t),i=n.length,o=0;o<i;o++)if(vl(t[n[o]]))return!0}}return!1}function yv(t,e){var r=[t];for(var n in e){var i=typeof e[n]=="object"?JSON.stringify(e[n],null,2):e[n];typeof i<"u"&&r.push(n+": "+i)}return r.join(`
|
|
3
|
+
`)}var ju=function(t){ER(e,t);function e(r,n,i,o,s){var c=this.constructor,a=t.call(this,yv(r,{name:n,index:i,operation:o,tree:s}))||this;return a.name=n,a.index=i,a.operation=o,a.tree=s,Object.setPrototypeOf(a,c.prototype),a.message=yv(r,{name:n,index:i,operation:o,tree:s}),a}return e}(Error);var dt=ju,SR=$t,Zc={add:function(t,e,r){return t[e]=this.value,{newDocument:r}},remove:function(t,e,r){var n=t[e];return delete t[e],{newDocument:r,removed:n}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:function(t,e,r){var n=_l(r,this.path);n&&(n=$t(n));var i=Ds(r,{op:"remove",path:this.from}).removed;return Ds(r,{op:"add",path:this.path,value:i}),{newDocument:r,removed:n}},copy:function(t,e,r){var n=_l(r,this.from);return Ds(r,{op:"add",path:this.path,value:$t(n)}),{newDocument:r}},test:function(t,e,r){return{newDocument:r,test:Wu(t[e],this.value)}},_get:function(t,e,r){return this.value=t[e],{newDocument:r}}},AR={add:function(t,e,r){return Tl(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:r,index:e}},remove:function(t,e,r){var n=t.splice(e,1);return{newDocument:r,removed:n[0]}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:Zc.move,copy:Zc.copy,test:Zc.test,_get:Zc._get};function _l(t,e){if(e=="")return t;var r={op:"_get",path:e};return Ds(t,r),r.value}function Ds(t,e,r,n,i,o){if(r===void 0&&(r=!1),n===void 0&&(n=!0),i===void 0&&(i=!0),o===void 0&&(o=0),r&&(typeof r=="function"?r(e,0,t,e.path):Il(e,0)),e.path===""){var s={newDocument:t};if(e.op==="add")return s.newDocument=e.value,s;if(e.op==="replace")return s.newDocument=e.value,s.removed=t,s;if(e.op==="move"||e.op==="copy")return s.newDocument=_l(t,e.from),e.op==="move"&&(s.removed=t),s;if(e.op==="test"){if(s.test=Wu(t,e.value),s.test===!1)throw new dt("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s.newDocument=t,s}else{if(e.op==="remove")return s.removed=t,s.newDocument=null,s;if(e.op==="_get")return e.value=t,s;if(r)throw new dt("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",o,e,t);return s}}else{n||(t=$t(t));var c=e.path||"",a=c.split("/"),u=t,d=1,f=a.length,h=void 0,p=void 0,g=void 0;for(typeof r=="function"?g=r:g=Il;;){if(p=a[d],p&&p.indexOf("~")!=-1&&(p=Fu(p)),i&&(p=="__proto__"||p=="prototype"&&d>0&&a[d-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(r&&h===void 0&&(u[p]===void 0?h=a.slice(0,d).join("/"):d==f-1&&(h=e.path),h!==void 0&&g(e,0,t,h)),d++,Array.isArray(u)){if(p==="-")p=u.length;else{if(r&&!Tl(p))throw new dt("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",o,e,t);Tl(p)&&(p=~~p)}if(d>=f){if(r&&e.op==="add"&&p>u.length)throw new dt("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",o,e,t);var s=AR[e.op].call(e,u,p,t);if(s.test===!1)throw new dt("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}}else if(d>=f){var s=Zc[e.op].call(e,u,p,t);if(s.test===!1)throw new dt("Test operation failed","TEST_OPERATION_FAILED",o,e,t);return s}if(u=u[p],r&&d<f&&(!u||typeof u!="object"))throw new dt("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",o,e,t)}}}function Bl(t,e,r,n,i){if(n===void 0&&(n=!0),i===void 0&&(i=!0),r&&!Array.isArray(e))throw new dt("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");n||(t=$t(t));for(var o=new Array(e.length),s=0,c=e.length;s<c;s++)o[s]=Ds(t,e[s],r,!0,i,s),t=o[s].newDocument;return o.newDocument=t,o}function TR(t,e,r){var n=Ds(t,e);if(n.test===!1)throw new dt("Test operation failed","TEST_OPERATION_FAILED",r,e,t);return n.newDocument}function Il(t,e,r,n){if(typeof t!="object"||t===null||Array.isArray(t))throw new dt("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,r);if(Zc[t.op]){if(typeof t.path!="string")throw new dt("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,r);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new dt('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,r);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new dt("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new dt("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&vl(t.value))throw new dt("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,r);if(r){if(t.op=="add"){var i=t.path.split("/").length,o=n.split("/").length;if(i!==o+1&&i!==o)throw new dt("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,r)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==n)throw new dt("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,r)}else if(t.op==="move"||t.op==="copy"){var s={op:"_get",path:t.from,value:void 0},c=gv([s],r);if(c&&c.name==="OPERATION_PATH_UNRESOLVABLE")throw new dt("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,r)}}}else throw new dt("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,r)}function gv(t,e,r){try{if(!Array.isArray(t))throw new dt("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)Bl($t(e),$t(t),r||!0);else{r=r||Il;for(var n=0;n<t.length;n++)r(t[n],n,e,void 0)}}catch(i){if(i instanceof dt)return i;throw i}}function Wu(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=Array.isArray(t),n=Array.isArray(e),i,o,s;if(r&&n){if(o=t.length,o!=e.length)return!1;for(i=o;i--!==0;)if(!Wu(t[i],e[i]))return!1;return!0}if(r!=n)return!1;var c=Object.keys(t);if(o=c.length,o!==Object.keys(e).length)return!1;for(i=o;i--!==0;)if(!e.hasOwnProperty(c[i]))return!1;for(i=o;i--!==0;)if(s=c[i],!Wu(t[s],e[s]))return!1;return!0}return t!==t&&e!==e}var I0={};If(I0,{compare:()=>kR,generate:()=>A0,observe:()=>DR,unobserve:()=>OR});l();var T0=new WeakMap,_R=function(){function t(e){this.observers=new Map,this.obj=e}return t}(),IR=function(){function t(e,r){this.callback=e,this.observer=r}return t}();function BR(t){return T0.get(t)}function RR(t,e){return t.observers.get(e)}function UR(t,e){t.observers.delete(e.callback)}function OR(t,e){e.unobserve()}function DR(t,e){var r=[],n,i=BR(t);if(!i)i=new _R(t),T0.set(t,i);else{var o=RR(i,e);n=o&&o.observer}if(n)return n;if(n={},i.value=$t(t),e){n.callback=e,n.next=null;var s=function(){A0(n)},c=function(){clearTimeout(n.next),n.next=setTimeout(s)};typeof window<"u"&&(window.addEventListener("mouseup",c),window.addEventListener("keyup",c),window.addEventListener("mousedown",c),window.addEventListener("keydown",c),window.addEventListener("change",c))}return n.patches=r,n.object=t,n.unobserve=function(){A0(n),clearTimeout(n.next),UR(i,n),typeof window<"u"&&(window.removeEventListener("mouseup",c),window.removeEventListener("keyup",c),window.removeEventListener("mousedown",c),window.removeEventListener("keydown",c),window.removeEventListener("change",c))},i.observers.set(e,new IR(e,n)),n}function A0(t,e){e===void 0&&(e=!1);var r=T0.get(t.object);_0(r.value,t.object,t.patches,"",e),t.patches.length&&Bl(r.value,t.patches);var n=t.patches;return n.length>0&&(t.patches=[],t.callback&&t.callback(n)),n}function _0(t,e,r,n,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var o=Al(e),s=Al(t),c=!1,a=!1,u=s.length-1;u>=0;u--){var d=s[u],f=t[d];if(Sl(e,d)&&!(e[d]===void 0&&f!==void 0&&Array.isArray(e)===!1)){var h=e[d];typeof f=="object"&&f!=null&&typeof h=="object"&&h!=null&&Array.isArray(f)===Array.isArray(h)?_0(f,h,r,n+"/"+Yn(d),i):f!==h&&(c=!0,i&&r.push({op:"test",path:n+"/"+Yn(d),value:$t(f)}),r.push({op:"replace",path:n+"/"+Yn(d),value:$t(h)}))}else Array.isArray(t)===Array.isArray(e)?(i&&r.push({op:"test",path:n+"/"+Yn(d),value:$t(f)}),r.push({op:"remove",path:n+"/"+Yn(d)}),a=!0):(i&&r.push({op:"test",path:n,value:t}),r.push({op:"replace",path:n,value:e}),c=!0)}if(!(!a&&o.length==s.length))for(var u=0;u<o.length;u++){var d=o[u];!Sl(t,d)&&e[d]!==void 0&&r.push({op:"add",path:n+"/"+Yn(d),value:$t(e[d])})}}}function kR(t,e,r){r===void 0&&(r=!1);var n=[];return _0(t,e,n,"",r),n}var mv=Object.assign({},S0,I0,{JsonPatchError:ju,deepClone:$t,escapePathComponent:Yn,unescapePathComponent:Fu});var{applyPatch:NR,compare:CR,deepClone:LR}=mv,PR=new Set(["__proto__","constructor","prototype"]);function wv(t){return t.split("/").map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~")).find(e=>PR.has(e))}var MR=new Set(["add","remove","replace","move","copy","test"]),KR=new Set(["add","replace","test"]);function $R(t){if(!(t instanceof Error))return"";let{index:e,operation:r}=t;return`${typeof e=="number"&&r&&typeof r=="object"?` at operation ${e} (${String(r.op)} ${String(r.path)})`:""}: ${t.message}`}var Qc=class{static apply(e,r,n={}){let i=n.mutate??!1,o=n.strict??!1,s=n.clone??LR,c=i?e:s(e),a=this.validateOperations(r,o);if(a)throw new be(`Invalid JSON Patch operations: ${a.message}`,"JSON_PATCH_APPLY_ERROR",{error:a});let u;try{u=NR(c,r,o,i)}catch(d){throw new be(`JSON Patch application failed${$R(d)}`,"JSON_PATCH_APPLY_ERROR",{error:d})}if(u.newDocument===void 0)throw new be("JSON Patch application failed: no document","JSON_PATCH_APPLY_ERROR",{result:u});return u.newDocument}static diff(e,r,n=""){let i=CR(e??{},r??{});if(!n)return i;let o=n.endsWith("/")?n.slice(0,-1):n;return i.map(s=>({...s,path:this.joinPointer(o,s.path)}))}static joinPointer(e,r){if(!e)return r;let n=e.startsWith("/")?e:`/${e}`;return`${this.escapeSegmentPath(n)}${r}`}static escapeSegmentPath(e){return e.split("/").map((r,n)=>n===0?r:r.replace(/~/g,"~0").replace(/\//g,"~1")).join("/")}static validateOperations(e,r=!1){if(!Array.isArray(e))return new be("Operations must be an array","JSON_PATCH_VALIDATION_ERROR");for(let n of e){if(!n||typeof n!="object")return new be("Operation must be an object","JSON_PATCH_VALIDATION_ERROR");if(typeof n.op!="string")return new be("Operation.op must be a string","JSON_PATCH_VALIDATION_ERROR");if(typeof n.path!="string")return new be("Operation.path must be a string","JSON_PATCH_VALIDATION_ERROR");if(r&&!MR.has(n.op))return new be(`Operation.op is not an RFC 6902 operation: ${n.op}`,"JSON_PATCH_VALIDATION_ERROR");if(r&&KR.has(n.op)&&n.value===void 0)return new be(`Operation.value is required for op=${n.op}`,"JSON_PATCH_VALIDATION_ERROR");let i=wv(n.path);if(i)return new be(`Operation.path traverses prototype machinery: ${i}`,"JSON_PATCH_VALIDATION_ERROR");if((n.op==="move"||n.op==="copy")&&typeof n.from!="string")return new be(`Operation.from must be a string for op=${n.op}`,"JSON_PATCH_VALIDATION_ERROR");if(typeof n.from=="string"){let o=wv(n.from);if(o)return new be(`Operation.from traverses prototype machinery: ${o}`,"JSON_PATCH_VALIDATION_ERROR")}}return null}};l();var Qr;(function(t){t.KEY="KEY",t.EXTERNAL="EXTERNAL"})(Qr||(Qr={}));var Rl;(function(t){t.k="k",t.x="x"})(Rl||(Rl={}));var ea;(function(t){t[t.bitcoin=0]="bitcoin",t[t.signet=1]="signet",t[t.regtest=2]="regtest",t[t.testnet3=3]="testnet3",t[t.testnet4=4]="testnet4",t[t.mutinynet=5]="mutinynet"})(ea||(ea={}));l();var Li=class{static toISOStringNonFractional(e=new Date){let r=e.getTime();if(Number.isNaN(r))throw new be(`Invalid date: ${e}`,"INVALID_DATE");return e.toISOString().replace(/\.\d{3}Z$/,"Z")}static toUnixSeconds(e=new Date){let r=e.getTime();if(Number.isNaN(r))throw new be(`Invalid date: ${e}`,"INVALID_DATE");return Math.floor(e.getTime()/1e3)}static dateStringToTimestamp(e){let r=new Date(e);return Number.isNaN(r.getTime())?new Date(0):r}static blocktimeToTimestamp(e){return new Date(e*1e3)}static isValidXsdDateTime(e){if(!e)return!1;let r=/^-?(\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,n=e.match(r);if(!n)return!1;let[,i,o,s,c,a,u,,d]=n,f=parseInt(i,10),h=parseInt(o,10),p=parseInt(s,10),g=parseInt(c,10),y=parseInt(a,10),x=parseInt(u,10);if(f===0||h<1||h>12)return!1;let S=[31,28,31,30,31,30,31,31,30,31,30,31],I=f%4===0&&f%100!==0||f%400===0,A=h===2&&I?29:S[h-1];if(p<1||p>A)return!1;if(g===24){if(y!==0||x!==0)return!1}else if(g>23)return!1;if(y>59||x>59)return!1;if(d&&d!=="Z"){let O=d.match(/^[+-](\d{2}):(\d{2})$/);if(O){let T=parseInt(O[1],10),M=parseInt(O[2],10);if(T>14||T===14&&M!==0||M>59)return!1}}return!0}};l();function B0(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}var ks=class{static isObject(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}static isParsable(e){if(typeof e!="string")return!1;try{return JSON.parse(e),!0}catch{return!1}}static isUnprototyped(e){return e===null||typeof e!="object"?!1:Object.getPrototypeOf(e)===null}static normalize(e){return this.cloneInternal(e,{stripPrototypes:!0})}static copy(e){return{...e}}static clone(e){return typeof structuredClone=="function"?structuredClone(e):this.cloneInternal(e)}static cloneReplace(e,r,n){return this.cloneInternal(e,{transform:i=>typeof i=="string"?i.replace(r,n):i})}static deepEqual(e,r,n=new WeakMap,i=0){if(i>1024)throw new be("Maximum comparison depth exceeded","MAX_DEPTH_EXCEEDED");if(Object.is(e,r))return!0;if(typeof e!=typeof r||e===null||r===null||typeof e!="object")return!1;if(n.get(e)===r)return!0;if(n.set(e,r),ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){let c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);if(c.byteLength!==a.byteLength)return!1;for(let u=0;u<c.byteLength;u++)if(c[u]!==a[u])return!1;return!0}if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(let c of e){let a=!1;for(let u of r)if(this.deepEqual(c,u,n,i+1)){a=!0;break}if(!a)return!1}return!0}if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(let[c,a]of e){let u=!1;if(r.has(c))u=this.deepEqual(a,r.get(c),n,i+1);else for(let[d,f]of r)if(this.deepEqual(c,d,n,i+1)&&this.deepEqual(a,f,n,i+1)){u=!0;break}if(!u)return!1}return!0}if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return!1;for(let c=0;c<e.length;c++)if(!this.deepEqual(e[c],r[c],n,i+1))return!1;return!0}let o=Object.keys(e),s=Object.keys(r);if(o.length!==s.length)return!1;for(let c of o)if(!Object.prototype.hasOwnProperty.call(r,c)||!this.deepEqual(e[c],r[c],n,i+1))return!1;return!0}static deleteKeys(e,r){let n=new Set(r.map(o=>typeof o=="number"?o.toString():o)),i=o=>{if(Array.isArray(o))return o.map(s=>i(s));if(o&&typeof o=="object"){let s={};for(let c of Object.keys(o))n.has(c)||B0(s,c,i(o[c]));return s}return o};return i(e)}static sanitize(e){let r=n=>{if(Array.isArray(n))return n.filter(i=>i!==void 0).map(i=>r(i));if(n&&typeof n=="object"){let i={};for(let[o,s]of Object.entries(n)){let c=r(s);c!==void 0&&B0(i,o,c)}return i}return n};return r(e)}static cloneInternal(e,r={},n=new WeakMap,i=0){if(i>1024)throw new be("Maximum clone depth exceeded","MAX_DEPTH_EXCEEDED");let o=r.transform?r.transform(e):e;if(o!==e||typeof e!="object"||e===null)return o;if(n.has(e))throw new be("Cannot clone circular structure","CIRCULAR_STRUCTURE");if(Array.isArray(e)){let c=[];n.set(e,c);for(let a of e)c.push(this.cloneInternal(a,r,n,i+1));return c}if(ArrayBuffer.isView(e)){if(e instanceof DataView)return new DataView(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(typeof e.slice=="function")return e.slice()}if(e instanceof Date)return new Date(e.getTime());let s=r.stripPrototypes?{}:Object.create(Object.getPrototypeOf(e));n.set(e,s);for(let c of Object.keys(e))B0(s,c,this.cloneInternal(e[c],r,n,i+1));return s}};l();var nr=class extends be{constructor(e,r="BeaconError",n){super(e,r,n)}},bv=class extends be{constructor(e,r="SingletonBeaconError",n){super(e,r,n)}},xv=class extends be{constructor(e,r="AggregateBeaconError",n){super(e,r,n)}},Ev=class extends be{constructor(e,r="CASBeaconError",n){super(e,r,n)}},Gu=class extends be{constructor(e,r="SMTBeaconError",n){super(e,r,n)}};l();l();l();l();l();l();l();l();l();l();l();l();l();l();l();var JR={bech32:"bcrt",pubKeyHash:111,scriptHash:196,wif:239};function Do(t){switch(t){case"bitcoin":return Jr;case"testnet3":case"testnet4":case"signet":case"mutinynet":return t0;case"regtest":return JR;default:throw new Error(`Unknown network "${t}"`)}}l();var zu=class{satsPerVbyte;constructor(e=5){if(e<0||!Number.isFinite(e))throw new Error(`Invalid satsPerVbyte: ${e}`);this.satsPerVbyte=e}async estimateFee(e){if(e<0||!Number.isFinite(e))throw new Error(`Invalid vsize: ${e}`);return BigInt(Math.ceil(e*this.satsPerVbyte))}};l();var U0="0000000000000000000000000000000000000000000000000000000000000000",O0="4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";l();var D0;(function(t){t[t.hex=0]="hex",t[t.json=1]="json",t[t.jsonext=2]="jsonext",t[t.jsonextprev=3]="jsonextprev"})(D0||(D0={}));var k0=new zu(5);var QR=160,e6=155,t6=240,r6={p2pkh:t6,p2wpkh:e6,p2tr:QR},Sv={p2pkh:34,p2wpkh:31,p2tr:43},Av={p2pkh:546,p2wpkh:294,p2tr:330};function Tv(t,e){return r6[t]-Sv[t]+Sv[e]}function _v(t,e){let r=Xr(e).decode(t);if(r.type==="pkh")return"p2pkh";if(r.type==="wpkh")return"p2wpkh";if(r.type==="tr")return"p2tr";throw new nr(`Unsupported singleton beacon address type "${r.type}". Expected P2PKH, P2WPKH, or P2TR (taproot key-path).`,"UNSUPPORTED_BEACON_ADDRESS_TYPE",{address:t,kind:r.type})}function n6(t,e,r){return t==="p2pkh"?Ni(e,r).address:t==="p2wpkh"?_s(e,r).address:Is(e.slice(1,33),void 0,r).address}function Iv(t,e,r){if(!r||r===t)return t;try{Xr(e).decode(r)}catch{throw new nr(`Invalid change address "${r}" for network "${e}".`,"INVALID_CHANGE_ADDRESS",{changeAddress:r,network:e})}return r}function Bv(t,e){try{return _v(t,e)}catch{return"p2tr"}}function Rv(t){return Ze.encode(["RETURN",t])}var N0=546;function i6(t){return t.status.confirmed===!0}function o6(t,e){if(t.status.block_height!==e.status.block_height)return t.status.block_height-e.status.block_height;let r=t.txid.localeCompare(e.txid);return r!==0?r:t.vout-e.vout}function s6(t,e){if(!t.length)throw new nr("No UTXOs found, please fund address!","UNFUNDED_BEACON_ADDRESS",{address:e});let r=t.filter(i6),n=r.filter(i=>i.value>N0);if(!n.length){let i=r.length===0?`all ${t.length} UTXO(s) are unconfirmed`:`all ${r.length} confirmed UTXO(s) are at or below the ${N0}-sat dust limit`;throw new nr(`No spendable UTXO at beacon address: ${i}.`,"NO_SPENDABLE_BEACON_UTXO",{address:e,total:t.length,confirmed:r.length,dustLimit:N0})}return[...n].sort(o6)[0]}async function Uv(t,e){let r=await e.rest.address.getUtxos(t),n=s6(r,t),i=await e.rest.transaction.getHex(n.txid);return{utxo:n,prevTxBytes:Ir(i)}}async function X9(t){let e=t.feeEstimator??k0,{utxo:r,prevTxBytes:n}=await Uv(t.beaconAddress,t.bitcoin),i=Iv(t.beaconAddress,t.network,t.changeAddress),o=Qe.encode(Xr(t.network).decode(t.beaconAddress)),s=Bv(i,t.network),c=await e.estimateFee(Tv("p2tr",s));if(BigInt(r.value)<=c)throw new nr(`UTXO value (${r.value}) insufficient to cover fee (${c}).`,"INSUFFICIENT_FUNDS",{address:t.beaconAddress,valueSats:r.value,feeSats:c});let a=new Us({allowUnknownOutputs:!0});a.addInput({txid:r.txid,index:r.vout,nonWitnessUtxo:n,witnessUtxo:{amount:BigInt(r.value),script:o},tapInternalKey:t.internalPubkey});let u=BigInt(r.value)-c;return u>=BigInt(Av[s])&&a.addOutputAddress(i,u,t.network),a.addOutput({script:Rv(t.signalBytes),amount:0n}),{tx:a,prevOutScripts:[o],prevOutValues:[BigInt(r.value)],beaconAddress:t.beaconAddress,changeAddress:i,utxo:r,feeSats:c,scriptKind:"p2tr"}}async function c6(t,e,r,n,i,o){let s=n.publicKey;if(r==="p2pkh"){let u=Io.ALL,d=t.preimageLegacy(e,i,u),f=n.sign(d,"ecdsa"),h=ht(f,new Uint8Array([u]));return t.updateInput(e,{partialSig:[[s,h]]},!0),t.finalize(),t.hex}if(r==="p2wpkh"){let u=Qe.decode(i);if(u.type!=="wpkh")throw new nr(`Expected P2WPKH prev-output script, got "${u.type}".`,"PREVOUT_SCRIPT_MISMATCH",{kind:r,observedScriptType:u.type});let d=Qe.encode({type:"pkh",hash:u.hash}),f=Io.ALL,h=t.preimageWitnessV0(e,d,f,o),p=n.sign(h,"ecdsa"),g=ht(p,new Uint8Array([f]));return t.updateInput(e,{partialSig:[[s,g]]},!0),t.finalize(),t.hex}let c=t.preimageWitnessV1(e,[i],Io.DEFAULT,[o]),a=n.sign(c,"bip341");return t.updateInput(e,{tapKeySig:a}),t.finalize(),t.hex}var ko=class{service;did;constructor(e,r){this.service=e,this.did=r}async buildSignAndBroadcast(e,r,n,i){let o=i?.feeEstimator??k0,s=this.service.serviceEndpoint.replace("bitcoin:",""),{utxo:c,prevTxBytes:a}=await Uv(s,n),u=await this.buildSinglePartyTx({signalBytes:e,beaconAddress:s,utxo:c,prevTxBytes:a,signer:r,bitcoin:n,feeEstimator:o,changeAddress:i?.changeAddress}),d=await this.signSinglePartyTx(u,r);return this.broadcastRawTx(n,d)}async buildSinglePartyTx(e){let r=e.bitcoin.data,n=e.signer.publicKey,i=_v(e.beaconAddress,r),o=Iv(e.beaconAddress,r,e.changeAddress),s=n6(i,n,r);if(s!==e.beaconAddress)throw new nr(`Signer pubkey produces ${i.toUpperCase()} address "${s}", but beacon address is "${e.beaconAddress}".`,"SIGNER_KEY_MISMATCH",{kind:i,address:e.beaconAddress,derivedAddress:s});let c=Bv(o,r),a=await e.feeEstimator.estimateFee(Tv(i,c)),u=BigInt(e.utxo.value);if(u<=a)throw new nr(`UTXO value (${e.utxo.value}) insufficient to cover fee (${a}).`,"INSUFFICIENT_FUNDS",{address:e.beaconAddress,valueSats:e.utxo.value,feeSats:a});let d=new Us({allowUnknownOutputs:!0}),f;if(i==="p2pkh")f=Ni(n,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes});else if(i==="p2wpkh")f=_s(n,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes,witnessUtxo:{amount:u,script:f}});else{let p=n.slice(1,33);f=Is(p,void 0,r).script,d.addInput({txid:e.utxo.txid,index:e.utxo.vout,nonWitnessUtxo:e.prevTxBytes,witnessUtxo:{amount:u,script:f},tapInternalKey:p})}let h=u-a;return h>=BigInt(Av[c])&&d.addOutputAddress(o,h,r),d.addOutput({script:Rv(e.signalBytes),amount:0n}),{tx:d,prevOutScripts:[f],prevOutValues:[u],beaconAddress:e.beaconAddress,changeAddress:o,utxo:e.utxo,feeSats:a,scriptKind:i}}async signSinglePartyTx(e,r){return c6(e.tx,0,e.scriptKind,r,e.prevOutScripts[0],e.prevOutValues[0])}async broadcastRawTx(e,r){return e.rest.transaction.send(r)}};l();var Ul=class extends ko{constructor(e,r){super({...e,type:"CASBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array,o=this.did;for(let s of e){let c=s.signalBytes,a=r.casMap.get(c);if(!a){i.push({kind:"NeedCASAnnouncement",announcementHash:c,beaconServiceId:this.service.id});continue}let u=a[o];if(!u)continue;let d=Zr(Xc(u,"base64urlnopad"),"hex"),f=r.updateMap.get(d);if(!f){i.push({kind:"NeedSignedUpdate",updateHash:d,beaconServiceId:this.service.id});continue}n.push([f,s.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=this.did,s=zn(e),c={[o]:s},a=Uo(Kt(c));i?.casPublish&&await i.casPublish(c);let u=await this.buildSignAndBroadcast(a,r,n,i);return{signedUpdate:e,txid:u,announcement:c}}};l();l();var Ol=class extends ko{constructor(e,r){super({...e,type:"SingletonBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array;for(let o of e){let s=o.signalBytes,c=r.updateMap.get(s);if(!c){i.push({kind:"NeedSignedUpdate",updateHash:s,beaconServiceId:this.service.id});continue}n.push([c,o.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=Uo(Kt(e)),s=await this.buildSignAndBroadcast(o,r,n,i);return{signedUpdate:e,txid:s}}};l();l();l();var a6=new Uint8Array(32),C0=1n<<BigInt(256),Ov=(()=>{let t=new Array(257),e=C0>>1n;for(let r=0;r<256;r++)t[r]=e,e>>=1n;return t[256]=0n,t})();l();l();l();function Yu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Jn(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function _e(t,e,r=""){let n=Yu(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Dl(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Jn(t.outputLen),Jn(t.blockLen)}function ta(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function kv(t,e){_e(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ns(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function kl(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function vn(t,e){return t<<32-e|t>>>e}var Nv=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",u6=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Cs(t){if(_e(t),Nv)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=u6[t[r]];return e}var Pi={_0:48,_9:57,A:65,F:70,a:97,f:102};function Dv(t){if(t>=Pi._0&&t<=Pi._9)return t-Pi._0;if(t>=Pi.A&&t<=Pi.F)return t-(Pi.A-10);if(t>=Pi.a&&t<=Pi.f)return t-(Pi.a-10)}function Ls(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Nv)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=Dv(t.charCodeAt(o)),c=Dv(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function hr(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];_e(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}function Cv(t,e={}){let r=(i,o)=>t(o).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function Ps(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Lv=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var P0=BigInt(0),L0=BigInt(1);function Ju(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Pv(t){if(typeof t=="bigint"){if(!Nl(t))throw new Error("positive bigint expected, got "+t)}else Jn(t);return t}function Xu(t){let e=Pv(t).toString(16);return e.length&1?"0"+e:e}function Mv(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?P0:BigInt("0x"+t)}function No(t){return Mv(Cs(t))}function M0(t){return Mv(Cs(d6(_e(t)).reverse()))}function Cl(t,e){Jn(e),t=Pv(t);let r=Ls(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function K0(t,e){return Cl(t,e).reverse()}function ra(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function d6(t){return Uint8Array.from(t)}function Kv(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Nl=t=>typeof t=="bigint"&&P0<=t;function f6(t,e,r){return Nl(t)&&Nl(e)&&Nl(r)&&e<=t&&t<r}function $v(t,e,r,n){if(!f6(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function $0(t){let e;for(e=0;t>P0;t>>=L0,e+=1);return e}var Zu=t=>(L0<<BigInt(t))-L0;function Hv(t,e,r){if(Jn(t,"hashLen"),Jn(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),i=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(t),u=n(t),d=0,f=()=>{a.fill(1),u.fill(0),d=0},h=(...x)=>r(u,hr(a,...x)),p=(x=i)=>{u=h(o,x),a=h(),x.length!==0&&(u=h(s,x),a=h())},g=()=>{if(d++>=c)throw new Error("drbg: tried max amount of iterations");let x=0,S=[];for(;x<e;){a=h();let I=a.slice();S.push(I),x+=a.length}return hr(...S)};return(x,S)=>{f(),p(x);let I;for(;!(I=S(g()));)p();return f(),I}}function Qu(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,c){let a=t[o];if(c&&a===void 0)return;let u=typeof a;if(u!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${u}`)}let i=(o,s)=>Object.entries(o).forEach(([c,a])=>n(c,a,s));i(e,!1),i(r,!0)}function H0(t){let e=new WeakMap;return(r,...n)=>{let i=e.get(r);if(i!==void 0)return i;let o=t(r,...n);return e.set(r,o),o}}function V0(t){return t.length===32}function Ll(t){if(!V0(t))throw new RangeError(`Invalid hash: expected ${32} bytes, got ${t.length}`)}function yt(...t){return ke(ht(...t))}function ed(t){Ll(t);let e=0n;for(let r of t)e=e<<8n|BigInt(r);return e}function q0(t){let e=new Uint8Array(32),r=t;for(let n=31;n>=0;n--)e[n]=Number(r&0xffn),r>>=8n;if(r!==0n)throw new RangeError("Value exceeds 256 bits");return e}function F0(t){Ll(t);let e="";for(let r of t)e+=r.toString(16).padStart(2,"0");return e}function j0(t,e){return!V0(t)||!V0(e)?!1:ra(t,e)}function na(t){return Ll(t),qc.encode(t)}function Xn(t){let e=qc.decode(t);if(e.length!==32)throw new RangeError(`Invalid base64url hash: expected ${32} decoded bytes, got ${e.length}`);return e}l();l();var Vv;(function(t){t[t.Pending=0]="Pending",t[t.Valid=1]="Valid",t[t.Invalid=2]="Invalid"})(Vv||(Vv={}));l();l();var Co=256;function ia(t,e){return Number(t>>BigInt(e)&1n)}var qv=(()=>{let t=new Array(Co+1),e=new Uint8Array(32);for(let r=0;r<=Co;r++)e=yt(e,e),t[r]=e;return t})();function Pl(t,e){if(t.length===0)return qv[e];if(e===0)return t[0].leaf;let r=Co-e,n=[],i=[];for(let o of t)(ia(o.index,r)===0?n:i).push(o);return yt(Pl(n,e-1),Pl(i,e-1))}function Fv(t){return Pl(t,Co)}function jv(t,e){let r=0n,n=[];for(let i=1;i<=Co;i++){let o=Co-i,s=[];for(let c of t){if(c.index===e)continue;let a=!0;for(let u=0;u<o;u++)if(ia(c.index,u)!==ia(e,u)){a=!1;break}a&&ia(c.index,o)!==ia(e,o)&&s.push(c)}s.length===0?r|=1n<<BigInt(o):n.push(Pl(s,i-1))}return{collapsed:r,hashes:n}}function Wv(t,e,r,n,i){let o=n,s=0;for(let c=0;c<Co;c++){let a=Co-1-c,u;if((t>>BigInt(a)&1n)===1n)u=qv[c];else{if(s>=e.length)return!1;u=e[s++]}o=ia(r,a)===1?yt(u,o):yt(o,u)}return s===e.length&&j0(o,i)}l();var l6=new TextEncoder;function Ml(t){return ed(yt(l6.encode(t)))}function Gv(t,e){return yt(yt(t),yt(e))}function zv(t){return yt(yt(t))}l();function Yv(t,e,r){let n={id:na(t),collapsed:na(q0(e.collapsed)),hashes:e.hashes.map(i=>na(i))};return r?.nonce&&(n.nonce=na(r.nonce)),r?.updateId&&(n.updateId=na(r.updateId)),n}function h6(t){let e={rootHash:Xn(t.id),collapsed:ed(Xn(t.collapsed)),hashes:t.hashes.map(r=>Xn(r))};return t.nonce&&(e.nonce=Xn(t.nonce)),t.updateId&&(e.updateId=Xn(t.updateId)),e}function Jv(t,e,r){let{rootHash:n,collapsed:i,hashes:o}=h6(t);return Wv(i,o,e,r,n)}l();var Kl=class{#e=new Map;#t=new Map;#n=null;#r=null;constructor(e=!0){}addEntries(e){for(let r of e){let n=Ml(r.did);if(this.#e.has(n))throw new RangeError(`Duplicate DID index for: ${r.did}`);this.#e.set(n,r),this.#t.set(r.did,n)}this.#n=null,this.#r=null}finalize(){let e=[];for(let[r,n]of this.#e){let i=n.signedUpdate!==void 0?Gv(n.nonce,n.signedUpdate):zv(n.nonce);e.push({index:r,leaf:i})}this.#n=e,this.#r=Fv(e)}get rootHash(){if(this.#r===null)throw new Error("Tree not finalized: call finalize() first");return this.#r}proof(e){let r=this.#t.get(e);if(r===void 0)throw new RangeError(`DID not in tree: ${e}`);if(this.#n===null||this.#r===null)throw new Error("Tree not finalized: call finalize() first");let n=this.#e.get(r),i=jv(this.#n,r),o=n.signedUpdate!==void 0?yt(n.signedUpdate):void 0;return Yv(this.#r,i,{nonce:n.nonce,updateId:o})}reset(){this.#n=null,this.#r=null}};var $l=class extends ko{constructor(e,r){super({...e,type:"SMTBeacon"},r)}processSignals(e,r){let n=new Array,i=new Array,o=this.did;for(let s of e){let c=r.smtMap.get(s.signalBytes);if(!c){i.push({kind:"NeedSMTProof",smtRootHash:s.signalBytes,beaconServiceId:this.service.id});continue}if(!c.nonce)throw new Gu("SMT proof missing required nonce field.","INVALID_SMT_PROOF",{smtProof:c,did:o});let a=Ml(o),u=Xn(c.nonce),d=c.updateId?yt(yt(u),Xn(c.updateId)):yt(yt(u));if(!Jv(c,a,d))throw new Gu("SMT proof verification failed.","INVALID_SMT_PROOF",{smtProof:c,did:o});if(!c.updateId)continue;let h=F0(Xn(c.updateId)),p=r.updateMap.get(h);if(!p){i.push({kind:"NeedSignedUpdate",updateHash:h,beaconServiceId:this.service.id});continue}n.push([p,s.blockMetadata])}return{updates:n,needs:i}}async broadcastSignal(e,r,n,i){let o=this.did,s=new TextEncoder().encode(Kt(e)),c=Br(32),a=new Kl;a.addEntries([{did:o,nonce:c,signedUpdate:s}]),a.finalize();let u=a.proof(o),d=await this.buildSignAndBroadcast(a.rootHash,r,n,i);return{signedUpdate:e,txid:d,proof:u}}};var oa=class{static establish(e,r){switch(e.type){case"SingletonBeacon":return new Ol(e,r);case"CASBeacon":return new Ul(e,r);case"SMTBeacon":return new $l(e,r);default:throw new be("Invalid Beacon Type","INVALID_BEACON_ERROR",e)}}};l();l();l();l();l();l();var Ki;(function(t){t.authentication="authentication",t.assertionMethod="assertionMethod",t.keyAgreement="keyAgreement",t.capabilityInvocation="capabilityInvocation",t.capabilityDelegation="capabilityDelegation"})(Ki||(Ki={}));l();var gt={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};l();var xe=class t{constructor({method:e,id:r,path:n,query:i,fragment:o,params:s}){this.uri=`did:${e}:${r}`,this.method=e,this.id=r,this.path=n,this.query=i,this.fragment=o,this.params=s}static parse(e){if(!e)return null;let r=t.DID_URI_PATTERN.exec(e);if(!r||!r.groups)return null;let{method:n,id:i,path:o,query:s,fragment:c}=r.groups,a={uri:`did:${n}:${i}`,method:n,id:i};if(o&&(a.path=o),s&&(a.query=s.slice(1)),c&&(a.fragment=c.slice(1)),s){let u={},d=s.slice(1).split("&");for(let f of d){let[h,p]=f.split("=");u[h]=p}a.params=u}return a}};xe.METHOD_PATTERN="([a-z0-9]+)";xe.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})";xe.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${xe.PCT_ENCODED_PATTERN})`;xe.METHOD_ID_PATTERN=`((?:${xe.ID_CHAR_PATTERN}*:)*(${xe.ID_CHAR_PATTERN}+))`;xe.PATH_PATTERN="(/[^#?]*)?";xe.QUERY_PATTERN="([?][^#]*)?";xe.FRAGMENT_PATTERN="(#.*)?";xe.DID_URI_PATTERN=new RegExp(`^did:(?<method>${xe.METHOD_PATTERN}):(?<id>${xe.METHOD_ID_PATTERN})(?<path>${xe.PATH_PATTERN})(?<query>${xe.QUERY_PATTERN})(?<fragment>${xe.FRAGMENT_PATTERN})$`);l();var re=class t extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,t)}},ie;(function(t){t.InvalidDid="invalidDid",t.MethodNotSupported="methodNotSupported",t.InternalError="internalError",t.InvalidDidDocument="invalidDidDocument",t.InvalidDidDocumentLength="invalidDidDocumentLength",t.InvalidDidUrl="invalidDidUrl",t.InvalidPreviousDidProof="invalidPreviousDidProof",t.InvalidPublicKey="invalidPublicKey",t.InvalidPublicKeyLength="invalidPublicKeyLength",t.InvalidPublicKeyType="invalidPublicKeyType",t.InvalidSignature="invalidSignature",t.NotFound="notFound",t.RepresentationNotSupported="representationNotSupported",t.UnsupportedPublicKeyType="unsupportedPublicKeyType"})(ie||(ie={}));l();l();l();l();l();var g6=Kn(Zv(),1);l();l();l();l();var GH=new Uint8Array(0);function Qv(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function sa(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}l();function w6(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function f(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 y=0,x=0,S=0,I=g.length;S!==I&&g[S]===0;)S++,y++;for(var A=(I-S)*d+1>>>0,O=new Uint8Array(A);S!==I;){for(var T=g[S],M=0,q=A-1;(T!==0||M<x)&&q!==-1;q--,M++)T+=256*O[q]>>>0,O[q]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");x=M,S++}for(var j=A-x;j!==A&&O[j]===0;)j++;for(var $=a.repeat(y);j<A;++j)$+=t.charAt(O[j]);return $}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var x=0,S=0;g[y]===a;)x++,y++;for(var I=(g.length-y)*u+1>>>0,A=new Uint8Array(I);g[y];){var O=r[g.charCodeAt(y)];if(O===255)return;for(var T=0,M=I-1;(O!==0||T<S)&&M!==-1;M--,T++)O+=c*A[M]>>>0,A[M]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");S=T,y++}if(g[y]!==" "){for(var q=I-S;q!==I&&A[q]===0;)q++;for(var j=new Uint8Array(x+(I-q)),$=x;q!==I;)j[$++]=A[q++];return j}}}function p(g){var y=h(g);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var b6=w6,x6=b6,e1=x6;var Y0=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},J0=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return t1(this,e)}},X0=class{decoders;constructor(e){this.decoders=e}or(e){return t1(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function t1(t,e){return new X0({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Z0=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Y0(e,r,n),this.decoder=new J0(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function r1({name:t,prefix:e,encode:r,decode:n}){return new Z0(t,e,r,n)}function Q0({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=e1(r,t);return r1({prefix:e,name:t,encode:n,decode:o=>sa(i(o))})}function E6(t,e,r,n){let i={};for(let d=0;d<e.length;++d)i[e[d]]=d;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),c=0,a=0,u=0;for(let d=0;d<o;++d){let f=i[t[d]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,c+=r,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=r||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function v6(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,c=0;for(let a=0;a<t.length;++a)for(c=c<<8|t[a],s+=8;s>r;)s-=r,o+=e[i&c>>s];if(s!==0&&(o+=e[i&c<<r-s]),n)for(;o.length*r&7;)o+="=";return o}function ir({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return r1({prefix:e,name:t,encode(i){return v6(i,n,r)},decode(i){return E6(i,n,r,t)}})}var td=ir({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rV=ir({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),nV=ir({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),iV=ir({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),oV=ir({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sV=ir({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cV=ir({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),aV=ir({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),eg=ir({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});l();var pr=Q0({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lV=Q0({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});l();var gV=ir({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mV=ir({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zn=ir({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wV=ir({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});l();function n1(t){return t.byteOffset!==0||t.byteLength!==t.buffer.byteLength}function i1(t){return typeof t!="object"||t===null?!1:typeof t[Symbol.asyncIterator]=="function"}function ca(t){let r=Object.prototype.toString.call(t).match(/\s([a-zA-Z0-9]+)/),[n,i]=r;return i}var rd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},o1=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(c,a){s=t[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(u){o({value:u,done:c})},s)}},Vl=new TextEncoder,Ms=new TextDecoder,ne=class t{constructor(e,r){this.data=e,this.format=r}static arrayBuffer(e){return new t(e,"ArrayBuffer")}static asyncIterable(e){if(!i1(e))throw new TypeError("Input must be of type AsyncIterable.");return new t(e,"AsyncIterable")}static base32Z(e){return new t(e,"Base32Z")}static base58Btc(e){return new t(e,"Base58Btc")}static base64Url(e){return new t(e,"Base64Url")}static bufferSource(e){return new t(e,"BufferSource")}static hex(e){if(typeof e!="string")throw new TypeError("Hex input must be a string.");if(e.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new t(e,"Hex")}static multibase(e){return new t(e,"Multibase")}static object(e){return new t(e,"Object")}static string(e){return new t(e,"String")}static uint8Array(e){return new t(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return pr.baseDecode(this.data).buffer;case"Base64Url":return Zn.baseDecode(this.data).buffer;case"BufferSource":{if(ca(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return n1(this.data)?this.data.buffer.slice(this.data.byteOffset,this.data.byteOffset+this.data.byteLength):this.data.buffer;throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":return this.toUint8Array().buffer;case"String":return this.toUint8Array().buffer;case"Uint8Array":return this.data.buffer;default:throw new TypeError(`Conversion from ${this.format} to ArrayBuffer is not supported.`)}}toArrayBufferAsync(){return rd(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":return yield(yield this.toBlobAsync()).arrayBuffer();default:throw new TypeError(`Asynchronous conversion from ${this.format} to ArrayBuffer is not supported.`)}})}toBase32Z(){switch(this.format){case"Uint8Array":return eg.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return pr.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return pr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Zn.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return Zn.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),r=Vl.encode(e);return Zn.baseEncode(r)}case"String":{let e=Vl.encode(this.data);return Zn.baseEncode(e)}case"Uint8Array":return Zn.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return rd(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=o1(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let d=i;a.push(d)}}catch(d){r={error:d}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(r,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let r=this.toUint8Array();return t.uint8Array(r).toHex()}case"Base64Url":{let r=this.toUint8Array();return t.uint8Array(r).toHex()}case"Uint8Array":{let r="";for(let n=0;n<this.data.length;n++)r+=e[this.data[n]];return r}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let e=Zn.baseDecode(this.data),r=Ms.decode(e);return JSON.parse(r)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Ms.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return rd(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toStringAsync();return JSON.parse(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return Ms.decode(this.data);case"Base64Url":{let e=Zn.baseDecode(this.data);return Ms.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Ms.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return rd(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=o1(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let u=i;typeof u=="string"?a+=u:a+=Ms.decode(u,{stream:!0})}}catch(u){r={error:u}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return a+=Ms.decode(void 0,{stream:!1}),a}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return eg.baseDecode(this.data);case"Base58Btc":return pr.baseDecode(this.data);case"Base64Url":return Zn.baseDecode(this.data);case"BufferSource":{let e=ca(this.data);if(e==="Uint8Array")return this.data;if(e==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let e=new Uint8Array(this.data.length/2);for(let r=0;r<this.data.length;r+=2){let n=parseInt(this.data.substring(r,r+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[r/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return Vl.encode(e)}case"String":return Vl.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return rd(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toArrayBufferAsync();return new Uint8Array(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};l();var nd;(function(t){t.Debug="debug",t.Silent="silent"})(nd||(nd={}));var tg=class{constructor(){this.logLevel=nd.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==nd.Silent&&console.info(e)}error(e){this.logLevel!==nd.Silent&&console.error(e)}},S6=new tg;typeof window<"u"&&(window.web5logger=S6);l();l();l();l();var $i={};If($i,{decode:()=>aa,encodeTo:()=>Ks,encodingLength:()=>$s});l();l();var A6=a1,s1=128,T6=127,_6=~T6,I6=Math.pow(2,31);function a1(t,e,r){e=e||[],r=r||0;for(var n=r;t>=I6;)e[r++]=t&255|s1,t/=128;for(;t&_6;)e[r++]=t&255|s1,t>>>=7;return e[r]=t|0,a1.bytes=r-n+1,e}var B6=rg,R6=128,c1=127;function rg(t,n){var r=0,n=n||0,i=0,o=n,s,c=t.length;do{if(o>=c)throw rg.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&c1)<<i:(s&c1)*Math.pow(2,i),i+=7}while(s>=R6);return rg.bytes=o-n,r}var U6=Math.pow(2,7),O6=Math.pow(2,14),D6=Math.pow(2,21),k6=Math.pow(2,28),N6=Math.pow(2,35),C6=Math.pow(2,42),L6=Math.pow(2,49),P6=Math.pow(2,56),M6=Math.pow(2,63),K6=function(t){return t<U6?1:t<O6?2:t<D6?3:t<k6?4:t<N6?5:t<C6?6:t<L6?7:t<P6?8:t<M6?9:10},$6={encode:A6,decode:B6,encodingLength:K6},H6=$6,id=H6;function aa(t,e=0){return[id.decode(t,e),id.decode.bytes]}function Ks(t,e,r=0){return id.encode(t,e,r),e}function $s(t){return id.encodingLength(t)}function ng(t,e){let r=e.byteLength,n=$s(t),i=n+$s(r),o=new Uint8Array(i+r);return Ks(t,o,0),Ks(r,o,n),o.set(e,i),new ua(t,r,e,o)}function u1(t){let e=sa(t),[r,n]=aa(e),[i,o]=aa(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new ua(r,i,s,e)}function d1(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Qv(t.bytes,r.bytes)}}var ua=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};l();function f1(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return q6(r,og(t),e??pr.encoder);default:return F6(r,og(t),e??td.encoder)}}var l1=new WeakMap;function og(t){let e=l1.get(t);if(e==null){let r=new Map;return l1.set(t,r),r}return e}var sg=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==od)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==j6)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=ng(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&d1(e.multihash,n.multihash)}toString(e){return f1(this,e)}toJSON(){return{"/":f1(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??h1(n,i,o.bytes))}else if(r[W6]===!0){let{version:n,multihash:i,code:o}=r,s=u1(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==od)throw new Error(`Version 0 CID must use dag-pb (code: ${od}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=h1(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,od,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=sa(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new ua(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,h]=aa(e.subarray(r));return r+=h,f},i=n(),o=od;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,c=n(),a=n(),u=r+a,d=u-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(e,r){let[n,i]=V6(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return og(o).set(n,e),o}};function V6(t,e){switch(t[0]){case"Q":{let r=e??pr;return[pr.prefix,r.decode(`${pr.prefix}${t}`)]}case pr.prefix:{let r=e??pr;return[pr.prefix,r.decode(t)]}case td.prefix:{let r=e??td;return[td.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function q6(t,e,r){let{prefix:n}=r;if(n!==pr.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function F6(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var od=112,j6=18;function h1(t,e,r){let n=$s(t),i=n+$s(e),o=new Uint8Array(i+r.byteLength);return Ks(t,o,0),Ks(e,o,n),o.set(r,i),o}var W6=Symbol.for("@ipld/js-cid/CID");l();l();l();l();l();l();var Jt=class t{static addPrefix(e){var r;let{code:n,data:i,name:o}=e;if(!(o?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=t.codeToName.has(n)?n:t.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(r=e.name)!==null&&r!==void 0?r:e.code}`);let s=$i.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),$i.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:r}=e,[n,i]=$i.decode(r);return n}static getCodeFromName(e){let{name:r}=e,n=t.nameToCode.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static getNameFromCode(e){let{code:r}=e,n=t.codeToName.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static registerCodec(e){t.codeToName.set(e.code,e.name),t.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:r}=e,[n,i]=$i.decode(r),o=t.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:r.slice(i),name:o}}};Jt.codeToName=new Map;Jt.nameToCode=new Map;Jt.registerCodec({code:237,name:"ed25519-pub"});Jt.registerCodec({code:4864,name:"ed25519-priv"});Jt.registerCodec({code:236,name:"x25519-pub"});Jt.registerCodec({code:4866,name:"x25519-priv"});Jt.registerCodec({code:231,name:"secp256k1-pub"});Jt.registerCodec({code:4865,name:"secp256k1-priv"});l();function cg(t){Object.keys(t).forEach(e=>{t[e]===void 0?delete t[e]:typeof t[e]=="object"&&cg(t[e])})}l();var QU=Kn(Qg(),1),tc=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})};var gh=class{constructor(){this.store=new Map}clear(){return tc(this,void 0,void 0,function*(){this.store.clear()})}close(){return tc(this,void 0,void 0,function*(){})}delete(e){return tc(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return tc(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return tc(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return tc(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,r){return tc(this,void 0,void 0,function*(){this.store.set(e,r)})}};l();l();var g4=Kn(fw(),1);var m4=Kn(fw(),1);l();l();l();l();l();function w4(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function lw(t,...e){if(!w4(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function hw(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function xT(t,e){lw(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}l();l();var Ca=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Yh=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Bn=(t,e)=>t<<32-e|t>>>e;var Fj=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function b4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function pw(t){return typeof t=="string"&&(t=b4(t)),lw(t),t}var zh=class{clone(){return this._cloneInto()}},jj={}.toString;function ET(t){let e=n=>t().update(pw(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function vT(t=32){if(Ca&&typeof Ca.getRandomValues=="function")return Ca.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function x4(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}var ST=(t,e,r)=>t&e^~t&r,AT=(t,e,r)=>t&e^t&r^e&r,Jh=class extends zh{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Yh(this.buffer)}update(e){hw(this);let{view:r,buffer:n,blockLen:i}=this;e=pw(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Yh(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){hw(this),xT(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;x4(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Yh(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var E4=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),zo=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yo=new Uint32Array(64),yw=class extends Jh{constructor(){super(64,32,8,!1),this.A=zo[0]|0,this.B=zo[1]|0,this.C=zo[2]|0,this.D=zo[3]|0,this.E=zo[4]|0,this.F=zo[5]|0,this.G=zo[6]|0,this.H=zo[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)Yo[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=Yo[f-15],p=Yo[f-2],g=Bn(h,7)^Bn(h,18)^h>>>3,y=Bn(p,17)^Bn(p,19)^p>>>10;Yo[f]=y+Yo[f-7]+g+Yo[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=Bn(c,6)^Bn(c,11)^Bn(c,25),p=d+h+ST(c,a,u)+E4[f]+Yo[f]|0,y=(Bn(n,2)^Bn(n,13)^Bn(n,22))+AT(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Yo.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Jo=ET(()=>new yw);var v4=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},La=class{static digest(e){return v4(this,arguments,void 0,function*({data:r}){return Jo(r)})}};l();var ai=class{};var S4=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Xh=class extends ai{digest(e){return S4(this,arguments,void 0,function*({algorithm:r,data:n}){switch(r){case"SHA-256":return yield La.digest({data:n})}})}};l();l();l();l();l();l();function TT(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function A4(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function gw(t,...e){if(!A4(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function _T(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");TT(t.outputLen),TT(t.blockLen)}function Pa(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function IT(t,e){gw(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}l();l();var Zh=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function BT(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Qh=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Rn=(t,e)=>t<<32-e|t>>>e,T4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!T4)throw new Error("Non little-endian hardware is not supported");function mw(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Md(t){if(typeof t=="string"&&(t=mw(t)),!BT(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function ep(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!BT(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var Ma=class{clone(){return this._cloneInto()}},gW={}.toString;function tp(t){let e=n=>t().update(Md(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Kd(t=32){if(Zh&&typeof Zh.getRandomValues=="function")return Zh.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function _4(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),c=Number(r&o),a=n?4:0,u=n?0:4;t.setUint32(e+a,s,n),t.setUint32(e+u,c,n)}var Ka=class extends Ma{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Qh(this.buffer)}update(e){Pa(this);let{view:r,buffer:n,blockLen:i}=this;e=Md(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Qh(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pa(this),IT(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;_4(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Qh(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var I4=(t,e,r)=>t&e^~t&r,B4=(t,e,r)=>t&e^t&r^e&r,R4=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Xo=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Zo=new Uint32Array(64),ww=class extends Ka{constructor(){super(64,32,8,!1),this.A=Xo[0]|0,this.B=Xo[1]|0,this.C=Xo[2]|0,this.D=Xo[3]|0,this.E=Xo[4]|0,this.F=Xo[5]|0,this.G=Xo[6]|0,this.H=Xo[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)Zo[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=Zo[f-15],p=Zo[f-2],g=Rn(h,7)^Rn(h,18)^h>>>3,y=Rn(p,17)^Rn(p,19)^p>>>10;Zo[f]=y+Zo[f-7]+g+Zo[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=Rn(c,6)^Rn(c,11)^Rn(c,25),p=d+h+I4(c,a,u)+R4[f]+Zo[f]|0,y=(Rn(n,2)^Rn(n,13)^Rn(n,22))+B4(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Zo.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var rp=tp(()=>new ww);l();var ip={};If(ip,{bitGet:()=>L4,bitLen:()=>C4,bitMask:()=>$d,bitSet:()=>P4,bytesToHex:()=>Qi,bytesToNumberBE:()=>eo,bytesToNumberLE:()=>On,concatBytes:()=>ro,createHmacDrbg:()=>Ew,ensureBytes:()=>Ge,equalBytes:()=>k4,hexToBytes:()=>hc,hexToNumber:()=>xw,isBytes:()=>Un,numberToBytesBE:()=>gr,numberToBytesLE:()=>to,numberToHexUnpadded:()=>DT,numberToVarBytesBE:()=>D4,utf8ToBytes:()=>N4,validateObject:()=>on});l();var OT=BigInt(0),np=BigInt(1),U4=BigInt(2);function Un(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var O4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Qi(t){if(!Un(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=O4[t[r]];return e}function DT(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function xw(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var Zi={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function RT(t){if(t>=Zi._0&&t<=Zi._9)return t-Zi._0;if(t>=Zi._A&&t<=Zi._F)return t-(Zi._A-10);if(t>=Zi._a&&t<=Zi._f)return t-(Zi._a-10)}function hc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=RT(t.charCodeAt(o)),c=RT(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function eo(t){return xw(Qi(t))}function On(t){if(!Un(t))throw new Error("Uint8Array expected");return xw(Qi(Uint8Array.from(t).reverse()))}function gr(t,e){return hc(t.toString(16).padStart(e*2,"0"))}function to(t,e){return gr(t,e).reverse()}function D4(t){return hc(DT(t))}function Ge(t,e,r){let n;if(typeof e=="string")try{n=hc(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Un(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function ro(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!Un(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let o=t[i];r.set(o,n),n+=o.length}return r}function k4(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function N4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function C4(t){let e;for(e=0;t>OT;t>>=np,e+=1);return e}function L4(t,e){return t>>BigInt(e)&np}var P4=(t,e,r)=>t|(r?np:OT)<<BigInt(e),$d=t=>(U4<<BigInt(t-1))-np,bw=t=>new Uint8Array(t),UT=t=>Uint8Array.from(t);function Ew(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=bw(t),i=bw(t),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...f)=>r(i,n,...f),a=(f=bw())=>{i=c(UT([0]),f),n=c(),f.length!==0&&(i=c(UT([1]),f),n=c())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=c();let p=n.slice();h.push(p),f+=n.length}return ro(...h)};return(f,h)=>{s(),a(f);let p;for(;!(p=h(u()));)a();return s(),p}}var M4={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Un(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function on(t,e,r={}){let n=(i,o,s)=>{let c=M4[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let a=t[i];if(!(s&&a===void 0)&&!c(a,t))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return t}var It=BigInt(0),et=BigInt(1),pc=BigInt(2),K4=BigInt(3),vw=BigInt(4),kT=BigInt(5),NT=BigInt(8),$4=BigInt(9),H4=BigInt(16);function Re(t,e){let r=t%e;return r>=It?r:e+r}function Sw(t,e,r){if(r<=It||e<It)throw new Error("Expected power/modulo > 0");if(r===et)return It;let n=et;for(;e>It;)e&et&&(n=n*t%r),t=t*t%r,e>>=et;return n}function ze(t,e,r){let n=t;for(;e-- >It;)n*=n,n%=r;return n}function op(t,e){if(t===It||e<=It)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Re(t,e),n=e,i=It,o=et,s=et,c=It;for(;r!==It;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==et)throw new Error("invert: does not exist");return Re(i,e)}function V4(t){let e=(t-et)/pc,r,n,i;for(r=t-et,n=0;r%pc===It;r/=pc,n++);for(i=pc;i<t&&Sw(i,e,t)!==t-et;i++);if(n===1){let s=(t+et)/vw;return function(a,u){let d=a.pow(u,s);if(!a.eql(a.sqr(d),u))throw new Error("Cannot find square root");return d}}let o=(r+et)/pc;return function(c,a){if(c.pow(a,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,d=c.pow(c.mul(c.ONE,i),r),f=c.pow(a,o),h=c.pow(a,r);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let p=1;for(let y=c.sqr(h);p<u&&!c.eql(y,c.ONE);p++)y=c.sqr(y);let g=c.pow(d,et<<BigInt(u-p-1));d=c.sqr(g),f=c.mul(f,g),h=c.mul(h,d),u=p}return f}}function q4(t){if(t%vw===K4){let e=(t+et)/vw;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(t%NT===kT){let e=(t-kT)/NT;return function(n,i){let o=n.mul(i,pc),s=n.pow(o,e),c=n.mul(i,s),a=n.mul(n.mul(c,pc),s),u=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return t%H4,V4(t)}var CT=(t,e)=>(Re(t,e)&et)===et,F4=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Aw(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=F4.reduce((n,i)=>(n[i]="function",n),e);return on(t,r)}function j4(t,e,r){if(r<It)throw new Error("Expected power > 0");if(r===It)return t.ONE;if(r===et)return e;let n=t.ONE,i=e;for(;r>It;)r&et&&(n=t.mul(n,i)),i=t.sqr(i),r>>=et;return n}function W4(t,e){let r=new Array(e.length),n=e.reduce((o,s,c)=>t.is0(s)?o:(r[c]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,c)=>t.is0(s)?o:(r[c]=t.mul(o,r[c]),t.mul(o,s)),i),r}function Tw(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function $a(t,e,r=!1,n={}){if(t<=It)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=Tw(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=q4(t),c=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:$d(i),ZERO:It,ONE:et,create:a=>Re(a,t),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return It<=a&&a<t},is0:a=>a===It,isOdd:a=>(a&et)===et,neg:a=>Re(-a,t),eql:(a,u)=>a===u,sqr:a=>Re(a*a,t),add:(a,u)=>Re(a+u,t),sub:(a,u)=>Re(a-u,t),mul:(a,u)=>Re(a*u,t),pow:(a,u)=>j4(c,a,u),div:(a,u)=>Re(a*op(u,t),t),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>op(a,t),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>W4(c,a),cmov:(a,u,d)=>d?u:a,toBytes:a=>r?to(a,o):gr(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return r?On(a):eo(a)}});return Object.freeze(c)}function LT(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function PT(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function _w(t){let e=PT(t);return e+Math.ceil(e/2)}function MT(t,e,r=!1){let n=t.length,i=PT(e),o=_w(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=r?eo(t):On(t),c=Re(s,e-et)+et;return r?to(c,i):gr(c,i)}l();l();var z4=BigInt(0),Iw=BigInt(1);function sp(t,e){let r=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,o){let s=t.ZERO,c=i;for(;o>z4;)o&Iw&&(s=s.add(c)),c=c.double(),o>>=Iw;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),a=[],u=i,d=u;for(let f=0;f<s;f++){d=u,a.push(d);for(let h=1;h<c;h++)d=d.add(u),a.push(d);u=d.double()}return a},wNAF(i,o,s){let{windows:c,windowSize:a}=n(i),u=t.ZERO,d=t.BASE,f=BigInt(2**i-1),h=2**i,p=BigInt(i);for(let g=0;g<c;g++){let y=g*a,x=Number(s&f);s>>=p,x>a&&(x-=h,s+=Iw);let S=y,I=y+Math.abs(x)-1,A=g%2!==0,O=x<0;x===0?d=d.add(r(A,o[S])):u=u.add(r(O,o[I]))}return{p:u,f:d}},wNAFCached(i,o,s,c){let a=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&o.set(i,c(u))),this.wNAF(a,u,s)}}}function Hd(t){return Aw(t.Fp),on(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Tw(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Y4(t){let e=Hd(t);on(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:J4,hexToBytes:X4}=ip,yc={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){let{Err:e}=yc;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");let r=t[1],n=t.subarray(2,r+2);if(!r||n.length!==r)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:J4(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=yc,r=typeof t=="string"?X4(t):t;if(!Un(r))throw new Error("ui8a expected");let n=r.length;if(n<2||r[0]!=48)throw new e("Invalid signature tag");if(r[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=yc._parseInt(r.subarray(2)),{d:s,l:c}=yc._parseInt(o);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,r=u=>{let d=u.toString(16);return d.length&1?`0${d}`:d},n=e(r(t.s)),i=e(r(t.r)),o=n.length/2,s=i.length/2,c=r(o),a=r(s);return`30${r(s+o+4)}02${a}${i}02${c}${n}`}},no=BigInt(0),sn=BigInt(1),PW=BigInt(2),KT=BigInt(3),MW=BigInt(4);function Z4(t){let e=Y4(t),{Fp:r}=e,n=e.toBytes||((g,y,x)=>{let S=y.toAffine();return ro(Uint8Array.from([4]),r.toBytes(S.x),r.toBytes(S.y))}),i=e.fromBytes||(g=>{let y=g.subarray(1),x=r.fromBytes(y.subarray(0,r.BYTES)),S=r.fromBytes(y.subarray(r.BYTES,2*r.BYTES));return{x,y:S}});function o(g){let{a:y,b:x}=e,S=r.sqr(g),I=r.mul(S,g);return r.add(r.add(I,r.mul(g,y)),x)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(g){return typeof g=="bigint"&&no<g&&g<e.n}function c(g){if(!s(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(g){let{allowedPrivateKeyLengths:y,nByteLength:x,wrapPrivateKey:S,n:I}=e;if(y&&typeof g!="bigint"){if(Un(g)&&(g=Qi(g)),typeof g!="string"||!y.includes(g.length))throw new Error("Invalid key");g=g.padStart(x*2,"0")}let A;try{A=typeof g=="bigint"?g:eo(Ge("private key",g,x))}catch{throw new Error(`private key must be ${x} bytes, hex or bigint, not ${typeof g}`)}return S&&(A=Re(A,I)),c(A),A}let u=new Map;function d(g){if(!(g instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(y,x,S){if(this.px=y,this.py=x,this.pz=S,y==null||!r.isValid(y))throw new Error("x required");if(x==null||!r.isValid(x))throw new Error("y required");if(S==null||!r.isValid(S))throw new Error("z required")}static fromAffine(y){let{x,y:S}=y||{};if(!y||!r.isValid(x)||!r.isValid(S))throw new Error("invalid affine point");if(y instanceof f)throw new Error("projective point not allowed");let I=A=>r.eql(A,r.ZERO);return I(x)&&I(S)?f.ZERO:new f(x,S,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){let x=r.invertBatch(y.map(S=>S.pz));return y.map((S,I)=>S.toAffine(x[I])).map(f.fromAffine)}static fromHex(y){let x=f.fromAffine(i(Ge("pointHex",y)));return x.assertValidity(),x}static fromPrivateKey(y){return f.BASE.multiply(a(y))}_setWindowSize(y){this._WINDOW_SIZE=y,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:y,y:x}=this.toAffine();if(!r.isValid(y)||!r.isValid(x))throw new Error("bad point: x or y not FE");let S=r.sqr(x),I=o(y);if(!r.eql(S,I))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(r.isOdd)return!r.isOdd(y);throw new Error("Field doesn't support isOdd")}equals(y){d(y);let{px:x,py:S,pz:I}=this,{px:A,py:O,pz:T}=y,M=r.eql(r.mul(x,T),r.mul(A,I)),q=r.eql(r.mul(S,T),r.mul(O,I));return M&&q}negate(){return new f(this.px,r.neg(this.py),this.pz)}double(){let{a:y,b:x}=e,S=r.mul(x,KT),{px:I,py:A,pz:O}=this,T=r.ZERO,M=r.ZERO,q=r.ZERO,j=r.mul(I,I),$=r.mul(A,A),Z=r.mul(O,O),Q=r.mul(I,A);return Q=r.add(Q,Q),q=r.mul(I,O),q=r.add(q,q),T=r.mul(y,q),M=r.mul(S,Z),M=r.add(T,M),T=r.sub($,M),M=r.add($,M),M=r.mul(T,M),T=r.mul(Q,T),q=r.mul(S,q),Z=r.mul(y,Z),Q=r.sub(j,Z),Q=r.mul(y,Q),Q=r.add(Q,q),q=r.add(j,j),j=r.add(q,j),j=r.add(j,Z),j=r.mul(j,Q),M=r.add(M,j),Z=r.mul(A,O),Z=r.add(Z,Z),j=r.mul(Z,Q),T=r.sub(T,j),q=r.mul(Z,$),q=r.add(q,q),q=r.add(q,q),new f(T,M,q)}add(y){d(y);let{px:x,py:S,pz:I}=this,{px:A,py:O,pz:T}=y,M=r.ZERO,q=r.ZERO,j=r.ZERO,$=e.a,Z=r.mul(e.b,KT),Q=r.mul(x,A),G=r.mul(S,O),_=r.mul(I,T),D=r.add(x,S),E=r.add(A,O);D=r.mul(D,E),E=r.add(Q,G),D=r.sub(D,E),E=r.add(x,I);let U=r.add(A,T);return E=r.mul(E,U),U=r.add(Q,_),E=r.sub(E,U),U=r.add(S,I),M=r.add(O,T),U=r.mul(U,M),M=r.add(G,_),U=r.sub(U,M),j=r.mul($,E),M=r.mul(Z,_),j=r.add(M,j),M=r.sub(G,j),j=r.add(G,j),q=r.mul(M,j),G=r.add(Q,Q),G=r.add(G,Q),_=r.mul($,_),E=r.mul(Z,E),G=r.add(G,_),_=r.sub(Q,_),_=r.mul($,_),E=r.add(E,_),Q=r.mul(G,E),q=r.add(q,Q),Q=r.mul(U,E),M=r.mul(D,M),M=r.sub(M,Q),Q=r.mul(D,G),j=r.mul(U,j),j=r.add(j,Q),new f(M,q,j)}subtract(y){return this.add(y.negate())}is0(){return this.equals(f.ZERO)}wNAF(y){return p.wNAFCached(this,u,y,x=>{let S=r.invertBatch(x.map(I=>I.pz));return x.map((I,A)=>I.toAffine(S[A])).map(f.fromAffine)})}multiplyUnsafe(y){let x=f.ZERO;if(y===no)return x;if(c(y),y===sn)return this;let{endo:S}=e;if(!S)return p.unsafeLadder(this,y);let{k1neg:I,k1:A,k2neg:O,k2:T}=S.splitScalar(y),M=x,q=x,j=this;for(;A>no||T>no;)A&sn&&(M=M.add(j)),T&sn&&(q=q.add(j)),j=j.double(),A>>=sn,T>>=sn;return I&&(M=M.negate()),O&&(q=q.negate()),q=new f(r.mul(q.px,S.beta),q.py,q.pz),M.add(q)}multiply(y){c(y);let x=y,S,I,{endo:A}=e;if(A){let{k1neg:O,k1:T,k2neg:M,k2:q}=A.splitScalar(x),{p:j,f:$}=this.wNAF(T),{p:Z,f:Q}=this.wNAF(q);j=p.constTimeNegate(O,j),Z=p.constTimeNegate(M,Z),Z=new f(r.mul(Z.px,A.beta),Z.py,Z.pz),S=j.add(Z),I=$.add(Q)}else{let{p:O,f:T}=this.wNAF(x);S=O,I=T}return f.normalizeZ([S,I])[0]}multiplyAndAddUnsafe(y,x,S){let I=f.BASE,A=(T,M)=>M===no||M===sn||!T.equals(I)?T.multiplyUnsafe(M):T.multiply(M),O=A(this,x).add(A(y,S));return O.is0()?void 0:O}toAffine(y){let{px:x,py:S,pz:I}=this,A=this.is0();y==null&&(y=A?r.ONE:r.inv(I));let O=r.mul(x,y),T=r.mul(S,y),M=r.mul(I,y);if(A)return{x:r.ZERO,y:r.ZERO};if(!r.eql(M,r.ONE))throw new Error("invZ was invalid");return{x:O,y:T}}isTorsionFree(){let{h:y,isTorsionFree:x}=e;if(y===sn)return!0;if(x)return x(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:y,clearCofactor:x}=e;return y===sn?this:x?x(f,this):this.multiplyUnsafe(e.h)}toRawBytes(y=!0){return this.assertValidity(),n(f,this,y)}toHex(y=!0){return Qi(this.toRawBytes(y))}}f.BASE=new f(e.Gx,e.Gy,r.ONE),f.ZERO=new f(r.ZERO,r.ONE,r.ZERO);let h=e.nBitLength,p=sp(f,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function Q4(t){let e=Hd(t);return on(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function $T(t){let e=Q4(t),{Fp:r,n}=e,i=r.BYTES+1,o=2*r.BYTES+1;function s(E){return no<E&&E<r.ORDER}function c(E){return Re(E,n)}function a(E){return op(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:d,weierstrassEquation:f,isWithinCurveOrder:h}=Z4({...e,toBytes(E,U,L){let N=U.toAffine(),R=r.toBytes(N.x),C=ro;return L?C(Uint8Array.from([U.hasEvenY()?2:3]),R):C(Uint8Array.from([4]),R,r.toBytes(N.y))},fromBytes(E){let U=E.length,L=E[0],N=E.subarray(1);if(U===i&&(L===2||L===3)){let R=eo(N);if(!s(R))throw new Error("Point is not on curve");let C=f(R),P=r.sqrt(C),V=(P&sn)===sn;return(L&1)===1!==V&&(P=r.neg(P)),{x:R,y:P}}else if(U===o&&L===4){let R=r.fromBytes(N.subarray(0,r.BYTES)),C=r.fromBytes(N.subarray(r.BYTES,2*r.BYTES));return{x:R,y:C}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),p=E=>Qi(gr(E,e.nByteLength));function g(E){let U=n>>sn;return E>U}function y(E){return g(E)?c(-E):E}let x=(E,U,L)=>eo(E.slice(U,L));class S{constructor(U,L,N){this.r=U,this.s=L,this.recovery=N,this.assertValidity()}static fromCompact(U){let L=e.nByteLength;return U=Ge("compactSignature",U,L*2),new S(x(U,0,L),x(U,L,2*L))}static fromDER(U){let{r:L,s:N}=yc.toSig(Ge("DER",U));return new S(L,N)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(U){return new S(this.r,this.s,U)}recoverPublicKey(U){let{r:L,s:N,recovery:R}=this,C=q(Ge("msgHash",U));if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");let P=R===2||R===3?L+e.n:L;if(P>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let V=R&1?"03":"02",J=u.fromHex(V+p(P)),z=a(P),W=c(-C*z),Y=c(N*z),X=u.BASE.multiplyAndAddUnsafe(J,W,Y);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new S(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return hc(this.toDERHex())}toDERHex(){return yc.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hc(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let I={isValidPrivateKey(E){try{return d(E),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let E=_w(e.n);return MT(e.randomBytes(E),e.n)},precompute(E=8,U=u.BASE){return U._setWindowSize(E),U.multiply(BigInt(3)),U}};function A(E,U=!0){return u.fromPrivateKey(E).toRawBytes(U)}function O(E){let U=Un(E),L=typeof E=="string",N=(U||L)&&E.length;return U?N===i||N===o:L?N===2*i||N===2*o:E instanceof u}function T(E,U,L=!0){if(O(E))throw new Error("first arg must be private key");if(!O(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(d(E)).toRawBytes(L)}let M=e.bits2int||function(E){let U=eo(E),L=E.length*8-e.nBitLength;return L>0?U>>BigInt(L):U},q=e.bits2int_modN||function(E){return c(M(E))},j=$d(e.nBitLength);function $(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(no<=E&&E<j))throw new Error(`bigint expected < 2^${e.nBitLength}`);return gr(E,e.nByteLength)}function Z(E,U,L=Q){if(["recovered","canonical"].some(ee=>ee in L))throw new Error("sign() legacy options not supported");let{hash:N,randomBytes:R}=e,{lowS:C,prehash:P,extraEntropy:V}=L;C==null&&(C=!0),E=Ge("msgHash",E),P&&(E=Ge("prehashed msgHash",N(E)));let J=q(E),z=d(U),W=[$(z),$(J)];if(V!=null){let ee=V===!0?R(r.BYTES):V;W.push(Ge("extraEntropy",ee))}let Y=ro(...W),X=J;function ue(ee){let ce=M(ee);if(!h(ce))return;let Oe=a(ce),Me=u.BASE.multiply(ce).toAffine(),Je=c(Me.x);if(Je===no)return;let Et=c(Oe*c(X+Je*z));if(Et===no)return;let yi=(Me.x===Je?0:2)|Number(Me.y&sn),po=Et;return C&&g(Et)&&(po=y(Et),yi^=1),new S(Je,po,yi)}return{seed:Y,k2sig:ue}}let Q={lowS:e.lowS,prehash:!1},G={lowS:e.lowS,prehash:!1};function _(E,U,L=Q){let{seed:N,k2sig:R}=Z(E,U,L),C=e;return Ew(C.hash.outputLen,C.nByteLength,C.hmac)(N,R)}u.BASE._setWindowSize(8);function D(E,U,L,N=G){let R=E;if(U=Ge("msgHash",U),L=Ge("publicKey",L),"strict"in N)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:P}=N,V,J;try{if(typeof R=="string"||Un(R))try{V=S.fromDER(R)}catch(Me){if(!(Me instanceof yc.Err))throw Me;V=S.fromCompact(R)}else if(typeof R=="object"&&typeof R.r=="bigint"&&typeof R.s=="bigint"){let{r:Me,s:Je}=R;V=new S(Me,Je)}else throw new Error("PARSE");J=u.fromHex(L)}catch(Me){if(Me.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&V.hasHighS())return!1;P&&(U=e.hash(U));let{r:z,s:W}=V,Y=q(U),X=a(W),ue=c(Y*X),ee=c(z*X),ce=u.BASE.multiplyAndAddUnsafe(J,ue,ee)?.toAffine();return ce?c(ce.x)===z:!1}return{CURVE:e,getPublicKey:A,getSharedSecret:T,sign:_,verify:D,ProjectivePoint:u,Signature:S,utils:I}}l();l();var cp=class extends Ma{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,_T(e);let n=Md(r);if(this.iHash=e.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;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return Pa(this),this.iHash.update(e),this}digestInto(e){Pa(this),gw(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bw=(t,e,r)=>new cp(t,e).update(r).digest();Bw.create=(t,e)=>new cp(t,e);function eN(t){return{hash:t,hmac:(e,...r)=>Bw(t,e,ep(...r)),randomBytes:Kd}}function ap(t,e){let r=n=>$T({...t,...eN(n)});return Object.freeze({...r(e),create:r})}var qT=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),HT=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),tN=BigInt(1),Rw=BigInt(2),VT=(t,e)=>(t+e/Rw)/e;function rN(t){let e=qT,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=ze(d,r,e)*d%e,h=ze(f,r,e)*d%e,p=ze(h,Rw,e)*u%e,g=ze(p,i,e)*p%e,y=ze(g,o,e)*g%e,x=ze(y,c,e)*y%e,S=ze(x,a,e)*x%e,I=ze(S,c,e)*y%e,A=ze(I,r,e)*d%e,O=ze(A,s,e)*g%e,T=ze(O,n,e)*u%e,M=ze(T,Rw,e);if(!Uw.eql(Uw.sqr(M),t))throw new Error("Cannot find square root");return M}var Uw=$a(qT,void 0,void 0,{sqrt:rN}),mr=ap({a:BigInt(0),b:BigInt(7),Fp:Uw,n:HT,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=HT,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-tN*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),c=VT(o*t,e),a=VT(-n*t,e),u=Re(t-c*r-a*i,e),d=Re(-c*n-a*o,e),f=u>s,h=d>s;if(f&&(u=e-u),h&&(d=e-d),u>s||d>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}}},rp),QW=BigInt(0);var eG=mr.ProjectivePoint;l();l();function FT(t){let e=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=e(n[s]);return o}return n},r=e(t);return JSON.stringify(r)}var nN=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Ow="urn:jwk:";function we(t){return nN(this,arguments,void 0,function*({jwk:e}){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);cg(n);let i=FT(n),o=ne.string(i).toUint8Array(),s=yield La.digest({data:o});return ne.uint8Array(s).toBase64Url()})}function ui(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="EC"||typeof t.d!="string"||typeof t.x!="string")}function Ha(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t)||"d"in t||t.kty!=="EC"||typeof t.x!="string")}function di(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="OKP"||typeof t.d!="string"||typeof t.x!="string")}function Va(t){return!(!t||typeof t!="object"||"d"in t||!("kty"in t&&"crv"in t&&"x"in t)||t.kty!=="OKP"||typeof t.x!="string")}function jT(t){if(!t||typeof t!="object")return!1;switch(t.kty){case"EC":case"OKP":case"RSA":return"d"in t;case"oct":return"k"in t;default:return!1}}var Vt=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},iN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Nt=class t{static adjustSignatureToLowS(e){return Vt(this,arguments,void 0,function*({signature:r}){let n=mr.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return Vt(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static bytesToPublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static compressPublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:r}){return mr.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return Vt(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=yield t.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"secp256k1",x:ne.uint8Array(i.x).toBase64Url(),y:ne.uint8Array(i.y).toBase64Url()};return o.kid=yield we({jwk:o}),o})}static convertDerToCompactSignature(e){return Vt(this,arguments,void 0,function*({derSignature:r}){return mr.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:r}){return mr.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return Vt(this,void 0,void 0,function*(){let e=mr.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield we({jwk:r}),r})}static getPublicKey(e){return Vt(this,arguments,void 0,function*({key:r}){var n;if(!(ui(r)&&r.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=r,o=iN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield we({jwk:o})),o})}static privateKeyToBytes(e){return Vt(this,arguments,void 0,function*({privateKey:r}){if(!ui(r))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Vt(this,arguments,void 0,function*({publicKey:r}){if(!(Ha(r)&&r.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=ne.base64Url(r.x).toUint8Array(),o=ne.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return Vt(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return mr.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return Vt(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=Jo(r);return mr.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Vt(this,arguments,void 0,function*({privateKeyBytes:r}){return mr.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:r}){try{mr.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Vt(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=Jo(i);return mr.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Vt(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=mr.getPublicKey(r));let n=mr.ProjectivePoint.fromHex(r),i=gr(n.x,32),o=gr(n.y,32);return{x:i,y:o}})}};l();l();var WT=$a(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),oN=WT.create(BigInt("-3")),sN=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),cN=ap({a:oN,b:sN,Fp:WT,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},rp),Pr=cN;var qt=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},aN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Ft=class t{static adjustSignatureToLowS(e){return qt(this,arguments,void 0,function*({signature:r}){let n=Pr.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return qt(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static bytesToPublicKey(e){return qt(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",x:ne.uint8Array(n.x).toBase64Url(),y:ne.uint8Array(n.y).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static compressPublicKey(e){return qt(this,arguments,void 0,function*({publicKeyBytes:r}){return Pr.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return qt(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=yield t.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"P-256",x:ne.uint8Array(i.x).toBase64Url(),y:ne.uint8Array(i.y).toBase64Url()};return o.kid=yield we({jwk:o}),o})}static convertDerToCompactSignature(e){return qt(this,arguments,void 0,function*({derSignature:r}){return Pr.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return qt(this,arguments,void 0,function*({publicKeyBytes:r}){return Pr.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return qt(this,void 0,void 0,function*(){let e=Pr.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield we({jwk:r}),r})}static getPublicKey(e){return qt(this,arguments,void 0,function*({key:r}){var n;if(!(ui(r)&&r.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=r,o=aN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield we({jwk:o})),o})}static privateKeyToBytes(e){return qt(this,arguments,void 0,function*({privateKey:r}){if(!ui(r))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return qt(this,arguments,void 0,function*({publicKey:r}){if(!(Ha(r)&&r.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=ne.base64Url(r.x).toUint8Array(),o=ne.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return qt(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return Pr.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return qt(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=Jo(r);return Pr.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return qt(this,arguments,void 0,function*({privateKeyBytes:r}){return Pr.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return qt(this,arguments,void 0,function*({publicKeyBytes:r}){try{Pr.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return qt(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=Jo(i);return Pr.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return qt(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=Pr.getPublicKey(r));let n=Pr.ProjectivePoint.fromHex(r),i=gr(n.x,32),o=gr(n.y,32);return{x:i,y:o}})}};var Vd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},qd=class extends ai{computePublicKey(e){return Vd(this,arguments,void 0,function*({key:r}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":{let n=yield Nt.computePublicKey({key:r});return n.alg="ES256K",n}case"P-256":{let n=yield Ft.computePublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return Vd(this,arguments,void 0,function*({algorithm:r}){switch(r){case"ES256K":case"secp256k1":{let n=yield Nt.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield Ft.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return Vd(this,arguments,void 0,function*({key:r}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":{let n=yield Nt.getPublicKey({key:r});return n.alg="ES256K",n}case"P-256":{let n=yield Ft.getPublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return Vd(this,arguments,void 0,function*({key:r,data:n}){if(!ui(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(r.crv){case"secp256k1":return yield Nt.sign({key:r,data:n});case"P-256":return yield Ft.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return Vd(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!Ha(r))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(r.crv){case"secp256k1":return yield Nt.verify({key:r,signature:n,data:i});case"P-256":return yield Ft.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};l();l();l();l();l();var up=BigInt(4294967295),Dw=BigInt(32);function GT(t,e=!1){return e?{h:Number(t&up),l:Number(t>>Dw&up)}:{h:Number(t>>Dw&up)|0,l:Number(t&up)|0}}function uN(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=GT(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var dN=(t,e)=>BigInt(t>>>0)<<Dw|BigInt(e>>>0),fN=(t,e,r)=>t>>>r,lN=(t,e,r)=>t<<32-r|e>>>r,hN=(t,e,r)=>t>>>r|e<<32-r,pN=(t,e,r)=>t<<32-r|e>>>r,yN=(t,e,r)=>t<<64-r|e>>>r-32,gN=(t,e,r)=>t>>>r-32|e<<64-r,mN=(t,e)=>e,wN=(t,e)=>t,bN=(t,e,r)=>t<<r|e>>>32-r,xN=(t,e,r)=>e<<r|t>>>32-r,EN=(t,e,r)=>e<<r-32|t>>>64-r,vN=(t,e,r)=>t<<r-32|e>>>64-r;function SN(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var AN=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),TN=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,_N=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),IN=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,BN=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),RN=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var UN={fromBig:GT,split:uN,toBig:dN,shrSH:fN,shrSL:lN,rotrSH:hN,rotrSL:pN,rotrBH:yN,rotrBL:gN,rotr32H:mN,rotr32L:wN,rotlSH:bN,rotlSL:xN,rotlBH:EN,rotlBL:vN,add:SN,add3L:AN,add3H:TN,add4L:_N,add4H:IN,add5H:RN,add5L:BN},pe=UN;var[ON,DN]=pe.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(t=>BigInt(t))),Qo=new Uint32Array(80),es=new Uint32Array(80),kw=class extends Ka{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:u,El:d,Fh:f,Fl:h,Gh:p,Gl:g,Hh:y,Hl:x}=this;return[e,r,n,i,o,s,c,a,u,d,f,h,p,g,y,x]}set(e,r,n,i,o,s,c,a,u,d,f,h,p,g,y,x){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=g|0,this.Hh=y|0,this.Hl=x|0}process(e,r){for(let A=0;A<16;A++,r+=4)Qo[A]=e.getUint32(r),es[A]=e.getUint32(r+=4);for(let A=16;A<80;A++){let O=Qo[A-15]|0,T=es[A-15]|0,M=pe.rotrSH(O,T,1)^pe.rotrSH(O,T,8)^pe.shrSH(O,T,7),q=pe.rotrSL(O,T,1)^pe.rotrSL(O,T,8)^pe.shrSL(O,T,7),j=Qo[A-2]|0,$=es[A-2]|0,Z=pe.rotrSH(j,$,19)^pe.rotrBH(j,$,61)^pe.shrSH(j,$,6),Q=pe.rotrSL(j,$,19)^pe.rotrBL(j,$,61)^pe.shrSL(j,$,6),G=pe.add4L(q,Q,es[A-7],es[A-16]),_=pe.add4H(G,M,Z,Qo[A-7],Qo[A-16]);Qo[A]=_|0,es[A]=G|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:u,Dl:d,Eh:f,El:h,Fh:p,Fl:g,Gh:y,Gl:x,Hh:S,Hl:I}=this;for(let A=0;A<80;A++){let O=pe.rotrSH(f,h,14)^pe.rotrSH(f,h,18)^pe.rotrBH(f,h,41),T=pe.rotrSL(f,h,14)^pe.rotrSL(f,h,18)^pe.rotrBL(f,h,41),M=f&p^~f&y,q=h&g^~h&x,j=pe.add5L(I,T,q,DN[A],es[A]),$=pe.add5H(j,S,O,M,ON[A],Qo[A]),Z=j|0,Q=pe.rotrSH(n,i,28)^pe.rotrBH(n,i,34)^pe.rotrBH(n,i,39),G=pe.rotrSL(n,i,28)^pe.rotrBL(n,i,34)^pe.rotrBL(n,i,39),_=n&o^n&c^o&c,D=i&s^i&a^s&a;S=y|0,I=x|0,y=p|0,x=g|0,p=f|0,g=h|0,{h:f,l:h}=pe.add(u|0,d|0,$|0,Z|0),u=c|0,d=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let E=pe.add3L(Z,G,D);n=pe.add3H(E,$,Q,_),i=E|0}({h:n,l:i}=pe.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=pe.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=pe.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=pe.add(this.Dh|0,this.Dl|0,u|0,d|0),{h:f,l:h}=pe.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:g}=pe.add(this.Fh|0,this.Fl|0,p|0,g|0),{h:y,l:x}=pe.add(this.Gh|0,this.Gl|0,y|0,x|0),{h:S,l:I}=pe.add(this.Hh|0,this.Hl|0,S|0,I|0),this.set(n,i,o,s,c,a,u,d,f,h,p,g,y,x,S,I)}roundClean(){Qo.fill(0),es.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Nw=tp(()=>new kw);l();var Dn=BigInt(0),Mr=BigInt(1),dp=BigInt(2),kN=BigInt(8),NN={zip215:!0};function CN(t){let e=Hd(t);return on(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function fp(t){let e=CN(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=e,u=dp<<BigInt(c*8)-Mr,d=r.create,f=e.uvRatio||((N,R)=>{try{return{isValid:!0,value:r.sqrt(N*r.inv(R))}}catch{return{isValid:!1,value:Dn}}}),h=e.adjustScalarBytes||(N=>N),p=e.domain||((N,R,C)=>{if(R.length||C)throw new Error("Contexts/pre-hash are not supported");return N}),g=N=>typeof N=="bigint"&&Dn<N,y=(N,R)=>g(N)&&g(R)&&N<R,x=N=>N===Dn||y(N,u);function S(N,R){if(y(N,R))return N;throw new Error(`Expected valid scalar < ${R}, got ${typeof N} ${N}`)}function I(N){return N===Dn?N:S(N,n)}let A=new Map;function O(N){if(!(N instanceof T))throw new Error("ExtendedPoint expected")}class T{constructor(R,C,P,V){if(this.ex=R,this.ey=C,this.ez=P,this.et=V,!x(R))throw new Error("x required");if(!x(C))throw new Error("y required");if(!x(P))throw new Error("z required");if(!x(V))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(R){if(R instanceof T)throw new Error("extended point not allowed");let{x:C,y:P}=R||{};if(!x(C)||!x(P))throw new Error("invalid affine point");return new T(C,P,Mr,d(C*P))}static normalizeZ(R){let C=r.invertBatch(R.map(P=>P.ez));return R.map((P,V)=>P.toAffine(C[V])).map(T.fromAffine)}_setWindowSize(R){this._WINDOW_SIZE=R,A.delete(this)}assertValidity(){let{a:R,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:P,ey:V,ez:J,et:z}=this,W=d(P*P),Y=d(V*V),X=d(J*J),ue=d(X*X),ee=d(W*R),ce=d(X*d(ee+Y)),Oe=d(ue+d(C*d(W*Y)));if(ce!==Oe)throw new Error("bad point: equation left != right (1)");let Me=d(P*V),Je=d(J*z);if(Me!==Je)throw new Error("bad point: equation left != right (2)")}equals(R){O(R);let{ex:C,ey:P,ez:V}=this,{ex:J,ey:z,ez:W}=R,Y=d(C*W),X=d(J*V),ue=d(P*W),ee=d(z*V);return Y===X&&ue===ee}is0(){return this.equals(T.ZERO)}negate(){return new T(d(-this.ex),this.ey,this.ez,d(-this.et))}double(){let{a:R}=e,{ex:C,ey:P,ez:V}=this,J=d(C*C),z=d(P*P),W=d(dp*d(V*V)),Y=d(R*J),X=C+P,ue=d(d(X*X)-J-z),ee=Y+z,ce=ee-W,Oe=Y-z,Me=d(ue*ce),Je=d(ee*Oe),Et=d(ue*Oe),yi=d(ce*ee);return new T(Me,Je,yi,Et)}add(R){O(R);let{a:C,d:P}=e,{ex:V,ey:J,ez:z,et:W}=this,{ex:Y,ey:X,ez:ue,et:ee}=R;if(C===BigInt(-1)){let hu=d((J-V)*(X+Y)),bf=d((J+V)*(X-Y)),pu=d(bf-hu);if(pu===Dn)return this.double();let xf=d(z*dp*ee),Ef=d(W*dp*ue),jr=Ef+xf,go=bf+hu,yu=Ef-xf,vf=d(jr*pu),ls=d(go*yu),Sf=d(jr*yu),ty=d(pu*go);return new T(vf,ls,ty,Sf)}let ce=d(V*Y),Oe=d(J*X),Me=d(W*P*ee),Je=d(z*ue),Et=d((V+J)*(Y+X)-ce-Oe),yi=Je-Me,po=Je+Me,lu=d(Oe-C*ce),wf=d(Et*yi),ey=d(po*lu),yo=d(Et*lu),Fr=d(yi*po);return new T(wf,ey,Fr,yo)}subtract(R){return this.add(R.negate())}wNAF(R){return j.wNAFCached(this,A,R,T.normalizeZ)}multiply(R){let{p:C,f:P}=this.wNAF(S(R,n));return T.normalizeZ([C,P])[0]}multiplyUnsafe(R){let C=I(R);return C===Dn?q:this.equals(q)||C===Mr?this:this.equals(M)?this.wNAF(C).p:j.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return j.unsafeLadder(this,n).is0()}toAffine(R){let{ex:C,ey:P,ez:V}=this,J=this.is0();R==null&&(R=J?kN:r.inv(V));let z=d(C*R),W=d(P*R),Y=d(V*R);if(J)return{x:Dn,y:Mr};if(Y!==Mr)throw new Error("invZ was invalid");return{x:z,y:W}}clearCofactor(){let{h:R}=e;return R===Mr?this:this.multiplyUnsafe(R)}static fromHex(R,C=!1){let{d:P,a:V}=e,J=r.BYTES;R=Ge("pointHex",R,J);let z=R.slice(),W=R[J-1];z[J-1]=W&-129;let Y=On(z);Y===Dn||(C?S(Y,u):S(Y,r.ORDER));let X=d(Y*Y),ue=d(X-Mr),ee=d(P*X-V),{isValid:ce,value:Oe}=f(ue,ee);if(!ce)throw new Error("Point.fromHex: invalid y coordinate");let Me=(Oe&Mr)===Mr,Je=(W&128)!==0;if(!C&&Oe===Dn&&Je)throw new Error("Point.fromHex: x=0 and x_0=1");return Je!==Me&&(Oe=d(-Oe)),T.fromAffine({x:Oe,y:Y})}static fromPrivateKey(R){return Q(R).point}toRawBytes(){let{x:R,y:C}=this.toAffine(),P=to(C,r.BYTES);return P[P.length-1]|=R&Mr?128:0,P}toHex(){return Qi(this.toRawBytes())}}T.BASE=new T(e.Gx,e.Gy,Mr,d(e.Gx*e.Gy)),T.ZERO=new T(Dn,Mr,Mr,Dn);let{BASE:M,ZERO:q}=T,j=sp(T,c*8);function $(N){return Re(N,n)}function Z(N){return $(On(N))}function Q(N){let R=c;N=Ge("private key",N,R);let C=Ge("hashed private key",o(N),2*R),P=h(C.slice(0,R)),V=C.slice(R,2*R),J=Z(P),z=M.multiply(J),W=z.toRawBytes();return{head:P,prefix:V,scalar:J,point:z,pointBytes:W}}function G(N){return Q(N).pointBytes}function _(N=new Uint8Array,...R){let C=ro(...R);return Z(o(p(C,Ge("context",N),!!i)))}function D(N,R,C={}){N=Ge("message",N),i&&(N=i(N));let{prefix:P,scalar:V,pointBytes:J}=Q(R),z=_(C.context,P,N),W=M.multiply(z).toRawBytes(),Y=_(C.context,W,J,N),X=$(z+Y*V);I(X);let ue=ro(W,to(X,r.BYTES));return Ge("result",ue,c*2)}let E=NN;function U(N,R,C,P=E){let{context:V,zip215:J}=P,z=r.BYTES;N=Ge("signature",N,2*z),R=Ge("message",R),i&&(R=i(R));let W=On(N.slice(z,2*z)),Y,X,ue;try{Y=T.fromHex(C,J),X=T.fromHex(N.slice(0,z),J),ue=M.multiplyUnsafe(W)}catch{return!1}if(!J&&Y.isSmallOrder())return!1;let ee=_(V,X.toRawBytes(),Y.toRawBytes(),R);return X.add(Y.multiplyUnsafe(ee)).subtract(ue).clearCofactor().equals(T.ZERO)}return M._setWindowSize(8),{CURVE:e,getPublicKey:G,sign:D,verify:U,ExtendedPoint:T,utils:{getExtendedPublicKey:Q,randomPrivateKey:()=>s(r.BYTES),precompute(N=8,R=T.BASE){return R._setWindowSize(N),R.multiply(BigInt(3)),R}}}}l();var Fd=BigInt(0),Cw=BigInt(1);function LN(t){return on(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function zT(t){let e=LN(t),{P:r}=e,n=A=>Re(A,r),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(A=>A),a=e.powPminus2||(A=>Sw(A,r-BigInt(2),r));function u(A,O,T){let M=n(A*(O-T));return O=n(O-M),T=n(T+M),[O,T]}function d(A){if(typeof A=="bigint"&&Fd<=A&&A<r)return A;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let f=(e.a-BigInt(2))/BigInt(4);function h(A,O){let T=d(A),M=d(O),q=T,j=Cw,$=Fd,Z=T,Q=Cw,G=Fd,_;for(let E=BigInt(i-1);E>=Fd;E--){let U=M>>E&Cw;G^=U,_=u(G,j,Z),j=_[0],Z=_[1],_=u(G,$,Q),$=_[0],Q=_[1],G=U;let L=j+$,N=n(L*L),R=j-$,C=n(R*R),P=N-C,V=Z+Q,J=Z-Q,z=n(J*L),W=n(V*R),Y=z+W,X=z-W;Z=n(Y*Y),Q=n(q*n(X*X)),j=n(N*C),$=n(P*(N+n(f*P)))}_=u(G,j,Z),j=_[0],Z=_[1],_=u(G,$,Q),$=_[0],Q=_[1];let D=a($);return n(j*D)}function p(A){return to(n(A),o)}function g(A){let O=Ge("u coordinate",A,o);return s===32&&(O[31]&=127),On(O)}function y(A){let O=Ge("scalar",A),T=O.length;if(T!==o&&T!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${T}`);return On(c(O))}function x(A,O){let T=g(O),M=y(A),q=h(T,M);if(q===Fd)throw new Error("Invalid private or public key received");return p(q)}let S=p(e.Gu);function I(A){return x(A,S)}return{scalarMult:x,scalarMultBase:I,getSharedSecret:(A,O)=>x(A,O),getPublicKey:A=>I(A),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:S}}var jd=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),YT=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),rz=BigInt(0),PN=BigInt(1),Lw=BigInt(2),MN=BigInt(5),JT=BigInt(10),KN=BigInt(20),$N=BigInt(40),XT=BigInt(80);function ZT(t){let e=jd,n=t*t%e*t%e,i=ze(n,Lw,e)*n%e,o=ze(i,PN,e)*t%e,s=ze(o,MN,e)*o%e,c=ze(s,JT,e)*s%e,a=ze(c,KN,e)*c%e,u=ze(a,$N,e)*a%e,d=ze(u,XT,e)*u%e,f=ze(d,XT,e)*u%e,h=ze(f,JT,e)*s%e;return{pow_p_5_8:ze(h,Lw,e)*t%e,b2:n}}function QT(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function HN(t,e){let r=jd,n=Re(e*e*e,r),i=Re(n*n*e,r),o=ZT(t*i).pow_p_5_8,s=Re(t*n*o,r),c=Re(e*s*s,r),a=s,u=Re(s*YT,r),d=c===t,f=c===Re(-t,r),h=c===Re(-t*YT,r);return d&&(s=a),(f||h)&&(s=u),CT(s,r)&&(s=Re(-s,r)),{isValid:d||f,value:s}}var cn=$a(jd,void 0,!0),Wd={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:cn,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Nw,randomBytes:Kd,adjustScalarBytes:QT,uvRatio:HN},ts=fp(Wd);function e_(t,e,r){if(e.length>255)throw new Error("Context is too big");return ep(mw("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var nz=fp({...Wd,domain:e_}),iz=fp({...Wd,domain:e_,prehash:Nw}),gc=zT({P:jd,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=jd,{pow_p_5_8:r,b2:n}=ZT(t);return Re(ze(r,BigInt(3),e)*n,e)},adjustScalarBytes:QT,randomBytes:Kd});function t_(t){let{y:e}=ts.ExtendedPoint.fromHex(t),r=BigInt(1);return cn.toBytes(cn.create((r+e)*cn.inv(r-e)))}function r_(t){let e=Wd.hash(t.subarray(0,32));return Wd.adjustScalarBytes(e).subarray(0,32)}var VN=(cn.ORDER+BigInt(3))/BigInt(8),oz=cn.pow(Lw,VN),sz=cn.sqrt(cn.neg(cn.ONE)),cz=(cn.ORDER-BigInt(5))/BigInt(8),az=BigInt(486662);var uz=LT(cn,cn.neg(BigInt(486664)));var dz=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),fz=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),lz=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),hz=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var pz=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var an=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},qN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Bt=class t{static bytesToPrivateKey(e){return an(this,arguments,void 0,function*({privateKeyBytes:r}){let n=ts.getPublicKey(r),i={crv:"Ed25519",d:ne.uint8Array(r).toBase64Url(),kty:"OKP",x:ne.uint8Array(n).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static bytesToPublicKey(e){return an(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"Ed25519",x:ne.uint8Array(r).toBase64Url()};return n.kid=yield we({jwk:n}),n})}static computePublicKey(e){return an(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=ts.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:ne.uint8Array(i).toBase64Url()};return o.kid=yield we({jwk:o}),o})}static convertPrivateKeyToX25519(e){return an(this,arguments,void 0,function*({privateKey:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=r_(n),o=gc.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:ne.uint8Array(i).toBase64Url(),x:ne.uint8Array(o).toBase64Url()};return s.kid=yield we({jwk:s}),s})}static convertPublicKeyToX25519(e){return an(this,arguments,void 0,function*({publicKey:r}){let n=yield t.publicKeyToBytes({publicKey:r});if(!(yield t.validatePublicKey({publicKeyBytes:n})))throw new Error("Ed25519: Invalid public key.");let o=t_(n),s={kty:"OKP",crv:"X25519",x:ne.uint8Array(o).toBase64Url()};return s.kid=yield we({jwk:s}),s})}static generateKey(){return an(this,void 0,void 0,function*(){let e=ts.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield we({jwk:r}),r})}static getPublicKey(e){return an(this,arguments,void 0,function*({key:r}){var n;if(!(di(r)&&r.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=r,o=qN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield we({jwk:o})),o})}static privateKeyToBytes(e){return an(this,arguments,void 0,function*({privateKey:r}){if(!di(r))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return an(this,arguments,void 0,function*({publicKey:r}){if(!Va(r))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return ne.base64Url(r.x).toUint8Array()})}static sign(e){return an(this,arguments,void 0,function*({key:r,data:n}){let i=yield t.privateKeyToBytes({privateKey:r});return ts.sign(n,i)})}static validatePublicKey(e){return an(this,arguments,void 0,function*({publicKeyBytes:r}){try{ts.ExtendedPoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return an(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r});return ts.verify(n,i,o)})}};var Gd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},lp=class extends ai{computePublicKey(e){return Gd(this,arguments,void 0,function*({key:r}){if(!di(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Bt.computePublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return Gd(this,arguments,void 0,function*({algorithm:r}){switch(r){case"Ed25519":{let n=yield Bt.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return Gd(this,arguments,void 0,function*({key:r}){if(!di(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Bt.getPublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return Gd(this,arguments,void 0,function*({key:r,data:n}){if(!di(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":return yield Bt.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return Gd(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!Va(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(r.crv){case"Ed25519":return yield Bt.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};var io=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Pw={Ed25519:{implementation:lp,names:["Ed25519"]},secp256k1:{implementation:qd,names:["ES256K","secp256k1"]},secp256r1:{implementation:qd,names:["ES256","secp256r1"]},"SHA-256":{implementation:Xh,names:["SHA-256"]}},er=class{constructor(e){var r;this._algorithmInstances=new Map,this._keyStore=(r=e?.keyStore)!==null&&r!==void 0?r:new gh}digest(e){return io(this,arguments,void 0,function*({algorithm:r,data:n}){return yield this.getAlgorithm({algorithm:r}).digest({algorithm:r,data:n})})}exportKey(e){return io(this,arguments,void 0,function*({keyUri:r}){return yield this.getPrivateKey({keyUri:r})})}generateKey(e){return io(this,arguments,void 0,function*({algorithm:r}){let i=yield this.getAlgorithm({algorithm:r}).generateKey({algorithm:r});if(i?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let o=`${Ow}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return io(this,arguments,void 0,function*({key:r}){let n=yield we({jwk:r});return`${Ow}${n}`})}getPublicKey(e){return io(this,arguments,void 0,function*({keyUri:r}){let n=yield this.getPrivateKey({keyUri:r}),i=this.getAlgorithmName({key:n});return yield this.getAlgorithm({algorithm:i}).getPublicKey({key:n})})}importKey(e){return io(this,arguments,void 0,function*({key:r}){var n;if(!jT(r))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let i=structuredClone(r);(n=i.kid)!==null&&n!==void 0||(i.kid=yield we({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return io(this,arguments,void 0,function*({keyUri:r,data:n}){let i=yield this.getPrivateKey({keyUri:r}),o=this.getAlgorithmName({key:i});return this.getAlgorithm({algorithm:o}).sign({data:n,key:i})})}verify(e){return io(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=this.getAlgorithmName({key:r});return this.getAlgorithm({algorithm:o}).verify({key:r,signature:n,data:i})})}getAlgorithm({algorithm:e}){var r;let n=(r=Pw[e])===null||r===void 0?void 0:r.implementation;if(!n)throw new Error(`Algorithm not supported: ${e}`);return this._algorithmInstances.has(n)||this._algorithmInstances.set(n,new n),this._algorithmInstances.get(n)}getAlgorithmName({key:e}){let r=e.alg,n=e.crv;for(let i in Pw){let o=Pw[i];if(r&&o.names.includes(r))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${r}, crv=${n}`)}getPrivateKey(e){return io(this,arguments,void 0,function*({keyUri:r}){let n=yield this._keyStore.get(r);if(!n)throw new Error(`Key not found: ${r}`);return n})}};l();var hp=class t{static getJoseSignatureAlgorithmFromPublicKey(e){let r={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(r).includes(e.alg))return e.alg;if(e.crv&&Object.keys(r).includes(e.crv))return r[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(r).join(", ")}. Supported 'crv' values: ${Object.keys(r).join(", ")}.`)}static randomBytes(e){return vT(e)}static randomUuid(){return Ca.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let r=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let o=t.randomBytes(Math.ceil(e/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>r)}else{let i=Math.pow(10,10);do{let o=t.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>r)}return n.toString().padStart(e,"0")}};l();l();l();l();l();l();l();l();l();l();var rs=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},FN=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},qa=class t{static bytesToPrivateKey(e){return rs(this,arguments,void 0,function*({privateKeyBytes:r}){let n=gc.getPublicKey(r),i={kty:"OKP",crv:"X25519",d:ne.uint8Array(r).toBase64Url(),x:ne.uint8Array(n).toBase64Url()};return i.kid=yield we({jwk:i}),i})}static bytesToPublicKey(e){return rs(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"X25519",x:ne.uint8Array(r).toBase64Url()};return n.kid=yield we({jwk:n}),n})}static computePublicKey(e){return rs(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=gc.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:ne.uint8Array(i).toBase64Url()};return o.kid=yield we({jwk:o}),o})}static generateKey(){return rs(this,void 0,void 0,function*(){let e=gc.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield we({jwk:r}),r})}static getPublicKey(e){return rs(this,arguments,void 0,function*({key:r}){var n;if(!(di(r)&&r.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=r,o=FN(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield we({jwk:o})),o})}static privateKeyToBytes(e){return rs(this,arguments,void 0,function*({privateKey:r}){if(!di(r))throw new Error("X25519: The provided key is not a valid OKP private key.");return ne.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return rs(this,arguments,void 0,function*({publicKey:r}){if(!Va(r))throw new Error("X25519: The provided key is not a valid OKP public key.");return ne.base64Url(r.x).toUint8Array()})}static sharedSecret(e){return rs(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield t.privateKeyToBytes({privateKey:r}),o=yield t.publicKeyToBytes({publicKey:n});return gc.getSharedSecret(i,o)})}};l();l();l();function Kr(t){if(typeof t=="string"&&t.length!==0)return t.split("#").pop()}function $w({didDocument:t}){var e,r;if(!t)throw new TypeError("Required parameter missing: 'didDocument'");let n=[];return n.push(...(r=(e=t.verificationMethod)===null||e===void 0?void 0:e.filter(Kw))!==null&&r!==void 0?r:[]),Object.keys(Ki).forEach(i=>{var o,s;n.push(...(s=(o=t[i])===null||o===void 0?void 0:o.filter(Kw))!==null&&s!==void 0?s:[])}),n}function n_({didDocument:t}){let r=$w({didDocument:t}).map(n=>n.type);return[...new Set(r)]}function i_({didDocument:t,methodId:e}){let r=[];return Object.keys(Ki).forEach(n=>{if(Array.isArray(t[n])){let i=t[n],o=Kr(e);i.some(c=>{let a=Kr(c)===o,u=Kw(c)&&Kr(c.id)===o;return a||u})&&r.push(n)}}),r}function o_(t){return!t||typeof t!="object"||t===null?!1:"id"in t&&"type"in t&&"serviceEndpoint"in t}function Kw(t){return!(!t||typeof t!="object"||t===null||!("id"in t&&"type"in t&&"controller"in t)||typeof t.id!="string"||typeof t.type!="string"||typeof t.controller!="string")}function Hw({keyBytes:t,multicodecCode:e,multicodecName:r}){let n=Jt.addPrefix({code:e,data:t,name:r}),i=ne.uint8Array(n).toBase58Btc();return ne.base58Btc(i).toMultibase()}function Vw({multibaseKeyId:t}){try{let e=ne.multibase(t).toBase58Btc(),r=ne.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=Jt.removePrefix({prefixedData:r});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new re(ie.InvalidDid,`Invalid multibase identifier: ${t}`)}}var zd=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},wr=class t{constructor({uri:e,document:r,metadata:n,keyManager:i}){this.uri=e,this.document=r,this.metadata=n,this.keyManager=i}export(){return zd(this,void 0,void 0,function*(){if(!(Array.isArray(this.document.verificationMethod)&&this.document.verificationMethod.length>0))throw new Error(`DID document for '${this.uri}' is missing verification methods`);let e=JSON.parse(JSON.stringify({uri:this.uri,document:this.document,metadata:this.metadata}));if("exportKey"in this.keyManager&&typeof this.keyManager.exportKey=="function"){let r=[];for(let n of this.document.verificationMethod){if(!n.publicKeyJwk)throw new Error(`Verification method '${n.id}' does not contain a public key in JWK format`);let i=yield this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=yield this.keyManager.exportKey({keyUri:i});r.push(Object.assign({},o))}e.privateKeys=r}return e})}getSigner(e){return zd(this,void 0,void 0,function*(){var r;let n=(r=this.document.verificationMethod)===null||r===void 0?void 0:r.find(a=>{var u,d;return Kr(a.id)===((u=Kr(e?.methodId))!==null&&u!==void 0?u:Kr((d=this.document.assertionMethod)===null||d===void 0?void 0:d[0]))});if(!(n&&n.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");let i=yield this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=yield this.keyManager.getPublicKey({keyUri:i}),s=this.keyManager;return{algorithm:hp.getJoseSignatureAlgorithmFromPublicKey(o),keyId:n.id,sign(a){return zd(this,arguments,void 0,function*({data:u}){return yield s.sign({data:u,keyUri:i})})},verify(a){return zd(this,arguments,void 0,function*({data:u,signature:d}){return yield s.verify({data:u,key:o,signature:d})})}}})}static import(e){return zd(this,arguments,void 0,function*({portableDid:r,keyManager:n=new er}){var i;let o=$w({didDocument:r.document});if(o.length===0)throw new re(ie.InvalidDidDocument,"At least one verification method is required but 0 were given");for(let c of(i=r.privateKeys)!==null&&i!==void 0?i:[]){let a=yield n.getKeyUri({key:c});(yield n.getPublicKey({keyUri:a}).then(()=>!0).catch(()=>!1))||(yield n.importKey({key:c}))}for(let c of o){if(!c.publicKeyJwk)throw new Error(`Verification method '${c.id}' does not contain a public key in JWK format`);let a=yield n.getKeyUri({key:c.publicKeyJwk});yield n.getPublicKey({keyUri:a})}return new t({uri:r.uri,document:r.document,metadata:r.metadata,keyManager:n})})}};l();l();l();l();l();var qw="0123456789abcdef",c_=[],s_=[];for(let t=0;t<256;t++)c_[t]=qw[t>>4&15]+qw[t&15],t<16&&(t<10?s_[48+t]=t:s_[87+t]=t);var Fw=t=>{let e=t.length,r="",n=0;for(;n<e;)r+=c_[t[n++]];return r};var a_=(t,e=0)=>{let r=t.length||0;if(!e){let s=r;for(;s--;)e+=t[s].length}let n=new Uint8Array(e),i=e,o=r;for(;o--;)i-=t[o].length,n.set(t[o],i);return n};l();var u_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",WN=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Yd=0;Yd<u_.length;Yd++)WN[u_.charCodeAt(Yd)]=Yd;var Yd;var GN=new TextDecoder,jw=(t,e)=>e?new TextDecoder(e).decode(t):GN.decode(t),zN=new TextEncoder,un=t=>zN.encode(t);var d_=typeof window<"u"?window:self,f_=d_.crypto||d_.msCrypto||{},pJ=f_.subtle||f_.webkitSubtle;l();function Fa(t){let e=t<0?1:0;return t=Math.abs(Number(t||1)),Math.floor(Math.log10(t))+1+e}function pp(t){return ArrayBuffer.isView(t)?"arraybufferview":Array.isArray(t)?"array":t instanceof Number?"number":t instanceof Boolean?"boolean":t instanceof Set?"set":t instanceof Map?"map":t instanceof String?"string":t instanceof ArrayBuffer?"arraybuffer":typeof t}function Ue(t,e,r){let n=[],i=null;return Ue._encode(n,t),i=a_(n),Ue.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,r),e):i}Ue.bytes=-1;Ue._floatConversionDetected=!1;Ue._encode=function(t,e){if(e!=null)switch(pp(e)){case"object":Ue.dict(t,e);break;case"map":Ue.dictMap(t,e);break;case"array":Ue.list(t,e);break;case"set":Ue.listSet(t,e);break;case"string":Ue.string(t,e);break;case"number":Ue.number(t,e);break;case"boolean":Ue.number(t,e);break;case"arraybufferview":Ue.buffer(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":Ue.buffer(t,new Uint8Array(e));break}};var yp=new Uint8Array([101]),l_=new Uint8Array([100]),h_=new Uint8Array([108]);Ue.buffer=function(t,e){t.push(un(e.length+":"),e)};Ue.string=function(t,e){t.push(un(un(e).byteLength+":"+e))};Ue.number=function(t,e){if(Number.isInteger(e))return t.push(un("i"+BigInt(e)+"e"));let r=2147483648,n=e/r<<0,i=e%r<<0,o=n*r+i;t.push(un("i"+o+"e")),o!==e&&!Ue._floatConversionDetected&&(Ue._floatConversionDetected=!0,console.warn('WARNING: Possible data corruption detected with value "'+e+'":','Bencoding only defines support for integers, value was converted to "'+o+'"'),console.trace())};Ue.dict=function(t,e){t.push(l_);let r=0,n,i=Object.keys(e).sort(),o=i.length;for(;r<o;r++)n=i[r],e[n]!=null&&(Ue.string(t,n),Ue._encode(t,e[n]));t.push(yp)};Ue.dictMap=function(t,e){t.push(l_);let r=Array.from(e.keys()).sort();for(let n of r)e.get(n)!=null&&(ArrayBuffer.isView(n)?Ue._encode(t,n):Ue.string(t,String(n)),Ue._encode(t,e.get(n)));t.push(yp)};Ue.list=function(t,e){let r=0,n=e.length;for(t.push(h_);r<n;r++)e[r]!=null&&Ue._encode(t,e[r]);t.push(yp)};Ue.listSet=function(t,e){t.push(h_);for(let r of e)r!=null&&Ue._encode(t,r);t.push(yp)};var p_=Ue;l();var YN=105,JN=58,XN=100,ZN=108,Ww=101;function y_(t,e,r){let n=0,i=1;for(let o=e;o<r;o++){let s=t[o];if(s<58&&s>=48){n=n*10+(s-48);continue}if(!(o===e&&s===43)){if(o===e&&s===45){i=-1;continue}if(s===46)break;throw new Error("not a number: buffer["+o+"] = "+s)}}return n*i}function de(t,e,r,n){return t==null||t.length===0?null:(typeof e!="number"&&n==null&&(n=e,e=void 0),typeof r!="number"&&n==null&&(n=r,r=void 0),de.position=0,de.encoding=n||null,de.data=ArrayBuffer.isView(t)?new Uint8Array(t.slice(e,r)):un(t),de.bytes=de.data.length,de.next())}de.bytes=0;de.position=0;de.data=null;de.encoding=null;de.next=function(){switch(de.data[de.position]){case XN:return de.dictionary();case ZN:return de.list();case YN:return de.integer();default:return de.buffer()}};de.find=function(t){let e=de.position,r=de.data.length,n=de.data;for(;e<r;){if(n[e]===t)return e;e++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(t)+'" [0x'+t.toString(16)+"]")};de.dictionary=function(){de.position++;let t={};for(;de.data[de.position]!==Ww;){let e=de.buffer(),r=jw(e);r.includes("\uFFFD")&&(r=Fw(e)),t[r]=de.next()}return de.position++,t};de.list=function(){de.position++;let t=[];for(;de.data[de.position]!==Ww;)t.push(de.next());return de.position++,t};de.integer=function(){let t=de.find(Ww),e=y_(de.data,de.position+1,t);return de.position+=t+1-de.position,e};de.buffer=function(){let t=de.find(JN),e=y_(de.data,de.position,t),r=++t+e;return de.position=r,de.encoding?jw(de.data.slice(t,r)):de.data.slice(t,r)};var g_=de;l();function QN(t){let e=2;for(let r of t)e+=gp(r);return e}function eC(t){let e=2;for(let[r,n]of t){let i=un(r).byteLength;e+=Fa(i)+1+i,e+=gp(n)}return e}function tC(t){let e=2,r=Object.keys(t);for(let n=0;n<r.length;n++){let i=un(r[n]).byteLength;e+=Fa(i)+1+i,e+=gp(t[r[n]])}return e}function rC(t){let e=un(t).byteLength;return Fa(e)+1+e}function nC(t){let e=t.byteLength-t.byteOffset;return Fa(e)+1+e}function gp(t){if(t==null)return 0;let r=pp(t);switch(r){case"arraybufferview":return nC(t);case"string":return rC(t);case"array":case"set":return QN(t);case"number":return 1+Fa(Math.floor(t))+1;case"bigint":return 1+t.toString().length+1;case"object":return tC(t);case"map":return eC(t);default:throw new TypeError(`Unsupported value of type "${r}"`)}}var Gw=gp;var iC=Gw,zw={encode:p_,decode:g_,byteLength:Gw,encodingLength:iC};l();l();var oC=/^(\d{1,3}\.){3,3}\d{1,3}$/;var sC=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var kn={name:"v4",size:4,isFormat:t=>oC.test(t),encode(t,e,r){r=~~r,e=e||new Uint8Array(r+4);let n=t.length,i=0;for(let o=0;o<n;){let s=t.charCodeAt(o++);s===46?(e[r++]=i,i=0):i=i*10+(s-48)}return e[r]=i,e},decode(t,e){return e=~~e,`${t[e++]}.${t[e++]}.${t[e++]}.${t[e]}`}},oo={name:"v6",size:16,isFormat:t=>t.length>0&&sC.test(t),encode(t,e,r){r=~~r;let n=r+16,i=-1,o=0,s=0,c=!0,a=!1;e=e||new Uint8Array(r+16);for(let u=0;u<t.length;u++){let d=t.charCodeAt(u);d===58?(c?i!==-1?(r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2):r<n&&(i=r):(a===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=o>>8),r<n-1&&(e[r+1]=o&255),r+=2),o=0,s=0),c=!0,a=!1):d===46?(r<n&&(e[r]=s),r++,s=0,o=0,c=!1,a=!0):(c=!1,d>=97?d-=87:d>=65?d-=55:(d-=48,s=s*10+d),o=(o<<4)+d)}if(c===!1)a===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=o>>8),r<n-1&&(e[r+1]=o&255),r+=2);else if(i===0)r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2;else if(i!==-1){r+=2;for(let u=Math.min(r-1,n-1);u>=i+2;u--)e[u]=e[u-2];e[i]=0,e[i+1]=0,i=r}if(i!==r&&i!==-1)for(r>n-2&&(r=n-2);n>i;)e[--n]=r<n&&r>i?e[--r]:0;else for(;r<n;)e[r++]=0;return e},decode(t,e){e=~~e;let r="";for(let n=0;n<16;n+=2)n!==0&&(r+=":"),r+=(t[e+n]<<8|t[e+n+1]).toString(16);return r.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};function m_(t){if(kn.isFormat(t))return kn.size;if(oo.isFormat(t))return oo.size;throw Error(`Invalid ip address: ${t}`)}function w_(t){return m_(t)===kn.size?1:2}function b_(t,e,r){r=~~r;let n=m_(t);return typeof e=="function"&&(e=e(r+n)),n===kn.size?kn.encode(t,e,r):oo.encode(t,e,r)}function x_(t,e,r){if(e=~~e,r=r||t.length-e,r===kn.size)return kn.decode(t,e,r);if(r===oo.size)return oo.decode(t,e,r);throw Error(`Invalid buffer size needs to be ${kn.size} for v4 or ${oo.size} for v6.`)}l();function Jd(t){switch(t){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+t}function ja(t){switch(t.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return t.toUpperCase().startsWith("UNKNOWN_")?parseInt(t.slice(8)):0}l();function E_(t){switch(t){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+t}l();function v_(t){switch(t){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+t}l();function Yw(t){switch(t){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+t}function Jw(t){switch(t.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}l();function S_(t){switch(t){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return t<0?null:`OPTION_${t}`}function Xw(t){if(typeof t=="number")return t;if(!t)return-1;switch(t.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=t.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}l();l();function Zw(t){let e=0,r=t.length;for(let n=0;n<r;n+=1){let i=t.charCodeAt(n);if(i<=127)e+=1;else if(i<=2047)e+=2;else if((i&63488)!==55296)e+=3;else{let o=n+1;o===r||i>=56320||(t.charCodeAt(o)&64512)!==56320?e+=3:(n=o,e+=4)}}return e}function Wa(t,e,r){let n=t.length;r==null&&(r=0),e===void 0&&(e=new Uint8Array(Zw(t)+r));let i=r;for(let o=0;o<n;o+=1){let s=t.charCodeAt(o);if(s<=127)e[i++]=s;else if(s<=2047)e[i++]=192|(s&1984)>>6,e[i++]=128|s&63;else if((s&63488)!==55296)e[i++]=224|(s&61440)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63;else{let c=o+1;if(c===n||s>=56320)e[i++]=239,e[i++]=191,e[i++]=189;else{let a=t.charCodeAt(c);(a&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(o=c,s=65536|(s&1023)<<10|a&1023,e[i++]=240|(s&1835008)>>18,e[i++]=128|(s&258048)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63)}}}return Wa.bytes=i-r,e}Wa.bytes=0;function Ga(t,e,r){let n="";e==null&&(e=0),r==null&&(r=t.length);for(let i=e;i<r;){let o=t[i++],s;if(o<=128)s=o;else if(o>191&&o<224)s=(o&31)<<6|t[i++]&63;else if(o>239&&o<365){s=((o&7)<<18|(t[i++]&63)<<12|(t[i++]&63)<<6|t[i++]&63)-65536;let c=55296|s>>10&1023;n+=String.fromCharCode(c),s=56320|s&1023}else s=(o&15)<<12|(t[i++]&63)<<6|t[i++]&63;n+=String.fromCharCode(s)}return Ga.bytes=r-e,n}Ga.bytes=0;var ns=t=>t instanceof Uint8Array;function so(t){return typeof t=="string"?Zw(t):t.byteLength}function mp(t){return t instanceof Uint8Array?t:Array.isArray(t)?new Uint8Array(t):Wa(t)}function wp(t,e,r){if(typeof e!="string")throw new Error("unknown input type");return Wa(e,t,r),Wa.bytes}var Xd={},A_=new Array(255);for(let t=0;t<=15;t+=1){let e=t.toString(16),r=e.toUpperCase();for(let n=0;n<=15;n+=1){let i=n.toString(16),o=i.toUpperCase(),s=t<<4|n,c=`${e}${i}`;A_[s]=c,Xd[c]=s,Xd[`${r}${i}`]=s,Xd[`${e}${o}`]=s,Xd[`${r}${o}`]=s}}function T_(t,e,r){let n="";for(let i=e;i<r;){let o=t[i++];n+=A_[o]}return n}function Qw(t){return t.length>>>1}function __(t,e,r,n){let i=0;for(;r<n;){let o=e.substr(i,2),s=Xd[o];if(s===void 0)return;t[r++]=s,i+=2}return t}var pC=Math.pow(2,24),yC=Math.pow(2,16),gC=Math.pow(2,8),fi=(t,e)=>t[e]*pC+t[e+1]*yC+t[e+2]*gC+t[e+3],ye=(t,e)=>t[e]<<8|t[e+1],li=(t,e,r)=>(e=+e,t[r+3]=e,e=e>>>8,t[r+2]=e,e=e>>>8,t[r+1]=e,e=e>>>8,t[r]=e,r+4),ae=(t,e,r)=>(t[r]=e>>8,t[r+1]=e&255,r+2);function br(t,e,r,n,i){return r<0&&(n-=r,r=0),n<0&&(n=0),i<0?new Uint8Array(0):r>=e.length||n>=i?0:mC(t,e,r,n,i)}function mC(t,e,r,n,i){i-n>e.length-r&&(i=n+e.length-r);let o=i-n,s=t.length-n;return o>s&&(o=s),(n!==0||i<t.length)&&(t=new Uint8Array(t.buffer,t.byteOffset+n,o)),e.set(t,r),o}var bC=0,I_=32768,tb=32768,xC=~tb,R_=32768,EC=~R_;function $e({bytes:t=0,encode:e,decode:r,encodingLength:n}){return e.bytes=t,r.bytes=t,{encode:e,decode:r,encodingLength:n||(()=>t)}}var se=$e({encode(t,e,r){e||(e=new Uint8Array(se.encodingLength(t))),r||(r=0);let n=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let o=i.split(".");for(let s=0;s<o.length;s++){let c=wp(e,o[s],r+1);e[r]=c,r+=c+1}}return e[r++]=0,se.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=[],n=e,i=0,o=0,s=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let c=t[e++];if(o+=s?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let a=ye(t,e-1)-49152;if(a>=n)throw new Error("Cannot decode name (bad pointer)");e=a,n=a,o+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");r.push(Ga(t,e,e+c)),e+=c,o+=s?0:c}}return se.decode.bytes=o,r.length===0?".":r.join(".")},encodingLength(t){return t==="."||t===".."?1:so(t.replace(/^\.|\.$/gm,""))+2}}),Rt=$e({encode(t,e,r){e||(e=new Uint8Array(Rt.encodingLength(t))),r||(r=0);let n=wp(e,t,r+1);return e[r]=n,Rt.encode.bytes=n+1,e},decode(t,e){e||(e=0);let r=t[e],n=Ga(t,e+1,e+1+r);return Rt.decode.bytes=r+1,n},encodingLength(t){return so(t)+1}}),za=$e({bytes:12,encode(t,e,r){e||(e=new Uint8Array(za.encodingLength(t))),r||(r=0);let n=(t.flags||0)&32767,i=t.type==="response"?I_:bC;return ae(e,t.id||0,r),ae(e,n|i,r+2),ae(e,t.questions.length,r+4),ae(e,t.answers.length,r+6),ae(e,t.authorities.length,r+8),ae(e,t.additionals.length,r+10),e},decode(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=ye(t,e+2);return{id:ye(t,e),type:r&I_?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:v_(r>>11&15),flag_aa:(r>>10&1)===1,flag_tc:(r>>9&1)===1,flag_rd:(r>>8&1)===1,flag_ra:(r>>7&1)===1,flag_z:(r>>6&1)===1,flag_ad:(r>>5&1)===1,flag_cd:(r>>4&1)===1,rcode:E_(r&15),questions:new Array(ye(t,e+4)),answers:new Array(ye(t,e+6)),authorities:new Array(ye(t,e+8)),additionals:new Array(ye(t,e+10))}},encodingLength(){return 12}}),xp=$e({encode(t,e,r){e||(e=new Uint8Array(xp.encodingLength(t))),r||(r=0);let n=t.length;return ae(e,n,r),br(t,e,r+2,0,n),xp.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=ye(t,e),n=t.slice(e+2,e+2+r);return xp.decode.bytes=r+2,n},encodingLength(t){return t.length+2}}),Ep=$e({encode(t,e,r){return e||(e=new Uint8Array(Ep.encodingLength(t))),r||(r=0),se.encode(t,e,r+2),ae(e,se.encode.bytes,r),Ep.encode.bytes=se.encode.bytes+2,e},decode(t,e){e||(e=0);let r=ye(t,e),n=se.decode(t,e+2);return Ep.decode.bytes=r+2,n},encodingLength(t){return se.encodingLength(t)+2}}),vp=$e({encode(t,e,r){e||(e=new Uint8Array(vp.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.mname,e,r),r+=se.encode.bytes,se.encode(t.rname,e,r),r+=se.encode.bytes,li(e,t.serial||0,r),r+=4,li(e,t.refresh||0,r),r+=4,li(e,t.retry||0,r),r+=4,li(e,t.expire||0,r),r+=4,li(e,t.minimum||0,r),r+=4,ae(e,r-n-2,n),vp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=se.decode(t,e),e+=se.decode.bytes,n.rname=se.decode(t,e),e+=se.decode.bytes,n.serial=fi(t,e),e+=4,n.refresh=fi(t,e),e+=4,n.retry=fi(t,e),e+=4,n.expire=fi(t,e),e+=4,n.minimum=fi(t,e),e+=4,vp.decode.bytes=e-r,n},encodingLength(t){return 22+se.encodingLength(t.mname)+se.encodingLength(t.rname)}}),Sp=$e({encode(t,e,r){Array.isArray(t)||(t=[t]);for(let i=0;i<t.length;i++)if(typeof t[i]=="string"&&(t[i]=mp(t[i])),!ns(t[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Sp.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(i){e[r++]=i.length,br(i,e,r,0,i.length),r+=i.length}),ae(e,r-n-2,n),Sp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=ye(t,e);e+=2;let i=[];for(;n>0;){let o=t[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(t.slice(e,e+o)),e+=o,n-=o}return Sp.decode.bytes=e-r,i},encodingLength(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=so(r)+1:e+=r.length+1}),e}}),Ap=$e({encode(t,e,r){e||(e=new Uint8Array(Ap.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=mp(t)),t||(t=new Uint8Array(0));let n=r;r+=2;let i=t.length;return br(t,e,r,0,i),r+=i,ae(e,r-n-2,n),Ap.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=ye(t,e);e+=2;let i=t.slice(e,e+n);return e+=n,Ap.decode.bytes=e-r,i},encodingLength(t){return t?(ns(t)?t.length:so(t))+2:2}}),Tp=$e({encode(t,e,r){e||(e=new Uint8Array(Tp.encodingLength(t))),r||(r=0);let n=r;return r+=2,Rt.encode(t.cpu,e,r),r+=Rt.encode.bytes,Rt.encode(t.os,e,r),r+=Rt.encode.bytes,ae(e,r-n-2,n),Tp.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=Rt.decode(t,e),e+=Rt.decode.bytes,n.os=Rt.decode(t,e),e+=Rt.decode.bytes,Tp.decode.bytes=e-r,n},encodingLength(t){return Rt.encodingLength(t.cpu)+Rt.encodingLength(t.os)+2}}),Xa=$e({encode(t,e,r){return e||(e=new Uint8Array(Xa.encodingLength(t))),r||(r=0),se.encode(t,e,r+2),ae(e,se.encode.bytes,r),Xa.encode.bytes=se.encode.bytes+2,e},decode(t,e){e||(e=0);let r=se.decode(t,e+2);return Xa.decode.bytes=se.decode.bytes+2,r},encodingLength(t){return se.encodingLength(t)+2}}),_p=$e({encode(t,e,r){e||(e=new Uint8Array(_p.encodingLength(t))),r||(r=0),ae(e,t.priority||0,r+2),ae(e,t.weight||0,r+4),ae(e,t.port||0,r+6),se.encode(t.target,e,r+8);let n=se.encode.bytes+6;return ae(e,n,r),_p.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=ye(t,e),n={};return n.priority=ye(t,e+2),n.weight=ye(t,e+4),n.port=ye(t,e+6),n.target=se.decode(t,e+8),_p.decode.bytes=r+2,n},encodingLength(t){return 8+se.encodingLength(t.target)}}),is=$e({encode(t,e,r){let n=is.encodingLength(t);return e||(e=new Uint8Array(is.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=is.ISSUER_CRITICAL),ae(e,n-2,r),r+=2,e[r]=t.flags||0,r+=1,Rt.encode(t.tag,e,r),r+=Rt.encode.bytes,wp(e,t.value,r),r+=so(t.value),is.encode.bytes=n,e},decode(t,e){e||(e=0);let r=ye(t,e);e+=2;let n=e,i={};return i.flags=t[e],e+=1,i.tag=Rt.decode(t,e),e+=Rt.decode.bytes,i.value=Ga(t,e,n+r),i.issuerCritical=!!(i.flags&is.ISSUER_CRITICAL),is.decode.bytes=r+2,i},encodingLength(t){return Rt.encodingLength(t.tag)+Rt.encodingLength(t.value)+2}});is.ISSUER_CRITICAL=128;var Ip=$e({encode(t,e,r){e||(e=new Uint8Array(Ip.encodingLength(t))),r||(r=0);let n=r;return r+=2,ae(e,t.preference||0,r),r+=2,se.encode(t.exchange,e,r),r+=se.encode.bytes,ae(e,r-n-2,n),Ip.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=ye(t,e),e+=2,n.exchange=se.decode(t,e),e+=se.decode.bytes,Ip.decode.bytes=e-r,n},encodingLength(t){return 4+se.encodingLength(t.exchange)}}),U_=$e({encode(t,e,r){return e||(e=new Uint8Array(U_.encodingLength(t))),r||(r=0),ae(e,4,r),r+=2,kn.encode(t,e,r),e},decode(t,e){return e||(e=0),e+=2,kn.decode(t,e)},bytes:6}),Bp=$e({encode(t,e,r){return e||(e=new Uint8Array(Bp.encodingLength(t))),r||(r=0),ae(e,16,r),r+=2,oo.encode(t,e,r),Bp.encode.bytes=18,e},decode(t,e){e||(e=0),e+=2;let r=oo.decode(t,e);return Bp.decode.bytes=18,r},bytes:18}),B_=t=>new Uint8Array(t),co=$e({encode(t,e,r){e||(e=new Uint8Array(co.encodingLength(t))),r||(r=0);let n=r,i=Xw(t.code);if(ae(e,i,r),r+=2,t.data)ae(e,t.data.length,r),r+=2,br(t.data,e,r),r+=t.data.length;else switch(i){case 8:{let o=t.sourcePrefixLength||0,s=t.family||w_(t.ip,B_),c=b_(t.ip,B_),a=Math.ceil(o/8);ae(e,a+4,r),r+=2,ae(e,s,r),r+=2,e[r++]=o,e[r++]=t.scopePrefixLength||0,br(c,e,r,0,a),r+=a}break;case 11:t.timeout?(ae(e,2,r),r+=2,ae(e,t.timeout,r),r+=2):(ae(e,0,r),r+=2);break;case 12:{let o=t.length||0;ae(e,o,r),r+=2,e.fill(0,r,r+o),r+=o}break;case 14:{let o=t.tags.length*2;ae(e,o,r),r+=2;for(let s of t.tags)ae(e,s,r),r+=2}break;default:throw new Error(`Unknown roption code: ${t.code}`)}return co.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={};r.code=ye(t,e),r.type=S_(r.code),e+=2;let n=ye(t,e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=ye(t,e),e+=2,r.sourcePrefixLength=t[e++],r.scopePrefixLength=t[e++];{let i=new Uint8Array(r.family===1?4:16);br(t,i,0,e,e+n-4),r.ip=x_(i)}break;case 11:n>0&&(r.timeout=ye(t,e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(ye(t,e)),e+=2}return co.decode.bytes=n+4,r},encodingLength(t){if(t.data)return t.data.length+4;switch(Xw(t.code)){case 8:{let r=t.sourcePrefixLength||0;return Math.ceil(r/8)+8}case 11:return typeof t.timeout=="number"?6:4;case 12:return t.length+4;case 14:return 4+t.tags.length*2}throw new Error(`Unknown roption code: ${t.code}`)}}),os=$e({encode(t,e,r){e||(e=new Uint8Array(os.encodingLength(t))),r||(r=0);let n=r,i=Ja(t,co);return ae(e,i,r),r=nf(t,co,e,r+2),os.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=[],i=ye(t,e);e+=2;let o=0;for(;i>0;)n[o++]=co.decode(t,e),e+=co.decode.bytes,i-=co.decode.bytes;return os.decode.bytes=e-r,n},encodingLength(t){return 2+Ja(t||[],co)}}),hi=$e({encode(t,e,r){e||(e=new Uint8Array(hi.encodingLength(t))),r||(r=0);let n=r,i=t.key;if(!ns(i))throw new Error("Key must be a Buffer");return r+=2,ae(e,t.flags,r),r+=2,e[r]=hi.PROTOCOL_DNSSEC,r+=1,e[r]=t.algorithm,r+=1,br(i,e,r,0,i.length),r+=i.length,hi.encode.bytes=r-n,ae(e,hi.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ye(t,e);if(e+=2,n.flags=ye(t,e),e+=2,t[e]!==hi.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t[e],e+=1,n.key=t.slice(e,r+i+2),e+=n.key.length,hi.decode.bytes=e-r,n},encodingLength(t){return 6+so(t.key)}});hi.PROTOCOL_DNSSEC=3;hi.ZONE_KEY=128;hi.SECURE_ENTRYPOINT=32768;var Zd=$e({encode(t,e,r){e||(e=new Uint8Array(Zd.encodingLength(t))),r||(r=0);let n=r,i=t.signature;if(!ns(i))throw new Error("Signature must be a Buffer");return r+=2,ae(e,ja(t.typeCovered),r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.labels,r+=1,li(e,t.originalTTL,r),r+=4,li(e,t.expiration,r),r+=4,li(e,t.inception,r),r+=4,ae(e,t.keyTag,r),r+=2,se.encode(t.signersName,e,r),r+=se.encode.bytes,br(i,e,r,0,i.length),r+=i.length,Zd.encode.bytes=r-n,ae(e,Zd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ye(t,e);return e+=2,n.typeCovered=Jd(ye(t,e)),e+=2,n.algorithm=t[e],e+=1,n.labels=t[e],e+=1,n.originalTTL=fi(t,e),e+=4,n.expiration=fi(t,e),e+=4,n.inception=fi(t,e),e+=4,n.keyTag=ye(t,e),e+=2,n.signersName=se.decode(t,e),e+=se.decode.bytes,n.signature=t.slice(e,r+i+2),e+=n.signature.length,Zd.decode.bytes=e-r,n},encodingLength(t){return 20+se.encodingLength(t.signersName)+so(t.signature)}}),Qd=$e({encode(t,e,r){e||(e=new Uint8Array(Qd.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.mbox||".",e,r),r+=se.encode.bytes,se.encode(t.txt||".",e,r),r+=se.encode.bytes,Qd.encode.bytes=r-n,ae(e,Qd.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=se.decode(t,e)||".",e+=se.decode.bytes,n.txt=se.decode(t,e)||".",e+=se.decode.bytes,Qd.decode.bytes=e-r,n},encodingLength(t){return 2+se.encodingLength(t.mbox||".")+se.encodingLength(t.txt||".")}}),$r=$e({encode(t,e,r){e||(e=new Uint8Array($r.encodingLength(t))),r||(r=0);let n=r,i=[];for(let o=0;o<t.length;o++){let s=ja(t[o]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(let o=0;o<i.length;o++)if(i[o]!==void 0){let s=mp(i[o]);e[r]=o,r+=1,e[r]=s.length,r+=1,br(s,e,r,0,s.length),r+=s.length}return $r.encode.bytes=r-n,e},decode(t,e,r){e||(e=0);let n=e,i=[];for(;e-n<r;){let o=t[e];e+=1;let s=t[e];e+=1;for(let c=0;c<s;c++){let a=t[e+c];for(let u=0;u<8;u++)if(a&1<<7-u){let d=Jd(o<<8|c<<3|u);i.push(d)}}e+=s}return $r.decode.bytes=e-n,i},encodingLength(t){let e=[];for(let n=0;n<t.length;n++){let i=ja(t[n]);e[i>>8]=Math.max(e[i>>8]||0,i&255)}let r=0;for(let n=0;n<e.length;n++)e[n]!==void 0&&(r+=2+Math.ceil((e[n]+1)/8));return r}}),ef=$e({encode(t,e,r){e||(e=new Uint8Array(ef.encodingLength(t))),r||(r=0);let n=r;return r+=2,se.encode(t.nextDomain,e,r),r+=se.encode.bytes,$r.encode(t.rrtypes,e,r),r+=$r.encode.bytes,ef.encode.bytes=r-n,ae(e,ef.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ye(t,e);return e+=2,n.nextDomain=se.decode(t,e),e+=se.decode.bytes,n.rrtypes=$r.decode(t,e,i-(e-r)),e+=$r.decode.bytes,ef.decode.bytes=e-r,n},encodingLength(t){return 2+se.encodingLength(t.nextDomain)+$r.encodingLength(t.rrtypes)}}),tf=$e({encode(t,e,r){e||(e=new Uint8Array(tf.encodingLength(t))),r||(r=0);let n=r,i=t.salt;if(!ns(i))throw new Error("salt must be a Buffer");let o=t.nextDomain;if(!ns(o))throw new Error("nextDomain must be a Buffer");return r+=2,e[r]=t.algorithm,r+=1,e[r]=t.flags,r+=1,ae(e,t.iterations,r),r+=2,e[r]=i.length,r+=1,br(i,e,r,0,i.length),r+=i.length,e[r]=o.length,r+=1,br(o,e,r,0,o.length),r+=o.length,$r.encode(t.rrtypes,e,r),r+=$r.encode.bytes,tf.encode.bytes=r-n,ae(e,tf.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ye(t,e);e+=2,n.algorithm=t[e],e+=1,n.flags=t[e],e+=1,n.iterations=ye(t,e),e+=2;let o=t[e];e+=1,n.salt=t.slice(e,e+o),e+=o;let s=t[e];return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=$r.decode(t,e,i-(e-r)),e+=$r.decode.bytes,tf.decode.bytes=e-r,n},encodingLength(t){return 8+t.salt.length+t.nextDomain.length+$r.encodingLength(t.rrtypes)}}),rf=$e({encode(t,e,r){e||(e=new Uint8Array(rf.encodingLength(t))),r||(r=0);let n=r,i=t.digest;if(!ns(i))throw new Error("Digest must be a Buffer");return r+=2,ae(e,t.keyTag,r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.digestType,r+=1,br(i,e,r,0,i.length),r+=i.length,rf.encode.bytes=r-n,ae(e,rf.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ye(t,e);return e+=2,n.keyTag=ye(t,e),e+=2,n.algorithm=t[e],e+=1,n.digestType=t[e],e+=1,n.digest=t.slice(e,r+i+2),e+=n.digest.length,rf.decode.bytes=e-r,n},encodingLength(t){return 6+so(t.digest)}}),Ya=$e({encode(t,e,r){e||(e=new Uint8Array(Ya.encodingLength(t))),r||(r=0);let n=r;r+=2,e[r]=t.algorithm,r+=1,e[r]=t.hash,r+=1;let i=Qw(t.fingerprint),o=rb(t.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${t.fingerprint}" for hashType=${t.hash}: ${i} != ${o}`);return __(e,t.fingerprint,r,r+=i),Ya.encode.bytes=r-n,ae(e,Ya.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};e+=2,n.algorithm=t[e],e+=1,n.hash=t[e],e+=1;let i=rb(n.hash);return n.fingerprint=T_(t,e,e+i),e+=i,Ya.decode.bytes=e-r,n},encodingLength(t){return 4+Qw(t.fingerprint)}});function rb(t){if(t===1)return 20;if(t===2)return 32;throw new Error(`Invalid hashType=${t}, supported=1,2`)}Ya.getFingerprintLengthForHashType=rb;function eb(t){switch(t.toUpperCase()){case"A":return U_;case"PTR":return Xa;case"CNAME":return Xa;case"DNAME":return Xa;case"TXT":return Sp;case"NULL":return Ap;case"AAAA":return Bp;case"SRV":return _p;case"HINFO":return Tp;case"CAA":return is;case"NS":return Ep;case"SOA":return vp;case"MX":return Ip;case"OPT":return os;case"DNSKEY":return hi;case"RRSIG":return Zd;case"RP":return Qd;case"NSEC":return ef;case"NSEC3":return tf;case"SSHFP":return Ya;case"DS":return rf}return xp}var dn=$e({encode(t,e,r){e||(e=new Uint8Array(dn.encodingLength(t))),r||(r=0);let n=r;if(se.encode(t.name,e,r),r+=se.encode.bytes,ae(e,ja(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");ae(e,t.udpPayloadSize||4096,r+2),e[r+4]=t.extendedRcode||0,e[r+5]=t.ednsVersion||0,ae(e,t.flags||0,r+6),r+=8,os.encode(t.options||[],e,r),r+=os.encode.bytes}else{let i=Jw(t.class===void 0?"IN":t.class);t.flush&&(i|=tb),ae(e,i,r+2),li(e,t.ttl||0,r+4),r+=8;let o=eb(t.type);o.encode(t.data,e,r),r+=o.encode.bytes}return dn.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={},n=e;if(r.name=se.decode(t,e),e+=se.decode.bytes,r.type=Jd(ye(t,e)),r.type==="OPT")r.udpPayloadSize=ye(t,e+2),r.extendedRcode=t[e+4],r.ednsVersion=t[e+5],r.flags=ye(t,e+6),r.flag_do=(r.flags>>15&1)===1,r.options=os.decode(t,e+8),e+=8+os.decode.bytes;else{let i=ye(t,e+2);r.ttl=fi(t,e+4),r.class=Yw(i&xC),r.flush=!!(i&tb);let o=eb(r.type);r.data=o.decode(t,e+8),e+=8+o.decode.bytes}return dn.decode.bytes=e-n,r},encodingLength(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return se.encodingLength(t.name)+8+eb(t.type).encodingLength(e)}}),Za=$e({encode(t,e,r){e||(e=new Uint8Array(Za.encodingLength(t))),r||(r=0);let n=r;return se.encode(t.name,e,r),r+=se.encode.bytes,ae(e,ja(t.type),r),r+=2,ae(e,Jw(t.class===void 0?"IN":t.class),r),r+=2,Za.encode.bytes=r-n,t},decode(t,e){e||(e=0);let r=e,n={};return n.name=se.decode(t,e),e+=se.decode.bytes,n.type=Jd(ye(t,e)),e+=2,n.class=Yw(ye(t,e)),e+=2,!!(n.class&R_)&&(n.class&=EC),Za.decode.bytes=e-r,n},encodingLength(t){return se.encodingLength(t.name)+4}});var O_=1024;var jt={encode:function(t,e,r){let n=!e;n&&(e=new Uint8Array(vC(t))),r||(r=0);let i=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),za.encode(t,e,r),r+=za.encode.bytes,r=nf(t.questions,Za,e,r),r=nf(t.answers,dn,e,r),r=nf(t.authorities,dn,e,r),r=nf(t.additionals,dn,e,r),jt.encode.bytes=r-i,n&&of.bytes!==e.length?e.slice(0,of.bytes):e},decode:function(t,e){e||(e=0);let r=e,n=za.decode(t,e);return e+=za.decode.bytes,e=bp(n.questions,Za,t,e),e=bp(n.answers,dn,t,e),e=bp(n.authorities,dn,t,e),e=bp(n.additionals,dn,t,e),jt.decode.bytes=e-r,n},encodingLength:function(t){return za.encodingLength(t)+Ja(t.questions||[],Za)+Ja(t.answers||[],dn)+Ja(t.authorities||[],dn)+Ja(t.additionals||[],dn)}};jt.encode.bytes=0;jt.decode.bytes=0;function Rp(t,e){if(t.questions)throw new Error("Only one .question object expected instead of a .questions array!");let r=Object.assign({type:e},t);return r.question&&(r.questions=[r.question],delete r.question),r}var Up={encode:function(t,e,r){return e=jt.encode(Rp(t,"query"),e,r),Up.encode.bytes=jt.encode.bytes,e},decode:function(t,e){let r=jt.decode(t,e);return Up.decode.bytes=jt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return jt.encodingLength(Rp(t,"query"))}};Up.encode.bytes=0;Up.decode.bytes=0;var Op={encode:function(t,e,r){return e=jt.encode(Rp(t,"response"),e,r),Op.encode.bytes=jt.encode.bytes,e},decode:function(t,e){let r=jt.decode(t,e);return Op.decode.bytes=jt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return jt.encodingLength(Rp(t,"response"))}};Op.encode.bytes=0;Op.decode.bytes=0;var of=jt.encode,Dp=jt.decode,vC=jt.encodingLength;function D_(t){let e=of(t),r=new Uint8Array(2+e.byteLength);return ae(r,e.byteLength),br(e,r,2,0,e.length),D_.bytes=r.byteLength,r}D_.bytes=0;function k_(t){let e=ye(t,0);if(t.byteLength<e+2)return null;let r=Dp(t.slice(2));return k_.bytes=Dp.bytes,r}k_.bytes=0;function Ja(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function nf(t,e,r,n){for(let i=0;i<t.length;i++)e.encode(t[i],r,n),n+=e.encode.bytes;return n}function bp(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e.decode(r,n),n+=e.decode.bytes;return n}l();var N_=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},fn=class{static getSigningMethod(e){return N_(this,void 0,void 0,function*(){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")})}static resolve(e,r){return N_(this,void 0,void 0,function*(){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")})}};var Lt=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},C_=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},L_="https://diddht.tbddev.org",SC=0,ss=7200,kp=";",sr=",",nb;(function(t){t[t.Discoverable=0]="Discoverable",t[t.Organization=1]="Organization",t[t.Government=2]="Government",t[t.Corporation=3]="Corporation",t[t.LocalBusiness=4]="LocalBusiness",t[t.SoftwarePackage=5]="SoftwarePackage",t[t.WebApp=6]="WebApp",t[t.FinancialInstitution=7]="FinancialInstitution"})(nb||(nb={}));var cr;(function(t){t[t.Ed25519=0]="Ed25519",t[t.secp256k1=1]="secp256k1",t[t.secp256r1=2]="secp256r1",t[t.X25519=3]="X25519"})(cr||(cr={}));var ib;(function(t){t.authentication="auth",t.assertionMethod="asm",t.capabilityDelegation="del",t.capabilityInvocation="inv",t.keyAgreement="agm"})(ib||(ib={}));var M_={Ed25519:cr.Ed25519,ES256K:cr.secp256k1,ES256:cr.secp256r1,"P-256":cr.secp256r1,secp256k1:cr.secp256k1,secp256r1:cr.secp256r1,X25519:cr.X25519},P_={[cr.Ed25519]:"EdDSA",[cr.secp256k1]:"ES256K",[cr.secp256r1]:"ES256",[cr.X25519]:"ECDH-ES+A256KW"},sf=class t extends fn{static create(){return Lt(this,arguments,void 0,function*({keyManager:e=new er,options:r={}}={}){var n,i,o,s,c,a,u,d,f,h,p;if(!((n=r.verificationMethods)===null||n===void 0)&&n.some(T=>!(T.algorithm in M_)))throw new Error("One or more verification method algorithms are not supported");let g=(i=r.verificationMethods)===null||i===void 0?void 0:i.filter(T=>"id"in T).map(T=>T.id);if(g&&g.length!==new Set(g).size)throw new Error("One or more verification method IDs are not unique");if(!((o=r.services)===null||o===void 0)&&o.some(T=>!T.id||!T.type||!T.serviceEndpoint))throw new Error("One or more services are missing required properties");let y=yield e.generateKey({algorithm:"Ed25519"}),x=yield e.getPublicKey({keyUri:y}),S=yield Ct.identityKeyToIdentifier({identityKey:x}),I=Object.assign(Object.assign({id:S},r.alsoKnownAs&&{alsoKnownAs:r.alsoKnownAs}),r.controllers&&{controller:r.controllers}),A=[...(s=r.verificationMethods)!==null&&s!==void 0?s:[]];A?.some(T=>{var M;return((M=T.id)===null||M===void 0?void 0:M.split("#").pop())==="0"})||A.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let T of A){let M=T.id&&T.id.split("#").pop()==="0"?y:yield e.generateKey({algorithm:T.algorithm}),q=yield e.getPublicKey({keyUri:M}),j=(a=(c=T.id)!==null&&c!==void 0?c:q.kid)!==null&&a!==void 0?a:yield we({jwk:q});j=`${S}#${Kr(j)}`,(u=I.verificationMethod)!==null&&u!==void 0||(I.verificationMethod=[]),I.verificationMethod.push({id:j,type:"JsonWebKey",controller:(d=T.controller)!==null&&d!==void 0?d:S,publicKeyJwk:q});for(let $ of(f=T.purposes)!==null&&f!==void 0?f:[])I[$]||(I[$]=[]),I[$].push(j)}(h=r.services)===null||h===void 0||h.forEach(T=>{var M;(M=I.service)!==null&&M!==void 0||(I.service=[]),T.id=`${S}#${T.id.split("#").pop()}`,I.service.push(T)});let O=new wr({uri:S,document:I,metadata:Object.assign({published:!1},r.types&&{types:r.types}),keyManager:e});if(!((p=r.publish)!==null&&p!==void 0)||p){let T=yield t.publish({did:O,gatewayUri:r.gatewayUri});O.metadata=T.didDocumentMetadata}return O})}static import(e){return Lt(this,arguments,void 0,function*({portableDid:r,keyManager:n=new er}){var i;let o=xe.parse(r.uri);if(o?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let s=yield wr.import({portableDid:r,keyManager:n});if(!(!((i=s.document.verificationMethod)===null||i===void 0)&&i.some(c=>{var a;return((a=c.id)===null||a===void 0?void 0:a.split("#").pop())==="0"})))throw new re(ie.InvalidDidDocument,"DID document must contain an Identity Key");return s})}static getSigningMethod(e){return Lt(this,arguments,void 0,function*({didDocument:r,methodId:n="#0"}){var i;let o=xe.parse(r.id);if(o&&o.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${o.method}`);let s=(i=r.verificationMethod)===null||i===void 0?void 0:i.find(c=>{var a,u;return Kr(c.id)===((a=Kr(n))!==null&&a!==void 0?a:Kr((u=r.assertionMethod)===null||u===void 0?void 0:u[0]))});if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static publish(e){return Lt(this,arguments,void 0,function*({did:r,gatewayUri:n=L_}){return yield Np.put({did:r,gatewayUri:n})})}static resolve(e){return Lt(this,arguments,void 0,function*(r,n={}){var i;let o=(i=n?.gatewayUri)!==null&&i!==void 0?i:L_;try{yield Ct.identifierToIdentityKey({didUri:r});let{didDocument:s,didDocumentMetadata:c}=yield Np.get({didUri:r,gatewayUri:o});return Object.assign(Object.assign({},gt),{didDocument:s,didDocumentMetadata:c})}catch(s){if(!(s instanceof re))throw new Error(s);return Object.assign(Object.assign({},gt),{didResolutionMetadata:Object.assign({error:s.code},s.message&&{errorMessage:s.message})})}})}};sf.methodName="dht";var Np=class t{static get(e){return Lt(this,arguments,void 0,function*({didUri:r,gatewayUri:n}){let i=Ct.identifierToIdentityKeyBytes({didUri:r}),o=yield t.pkarrGet({gatewayUri:n,publicKeyBytes:i}),s=yield Ct.parseBep44GetMessage({bep44Message:o}),c=yield t.fromDnsPacket({didUri:r,dnsPacket:s});return c.didDocumentMetadata.versionId=o.seq.toString(),c})}static put(e){return Lt(this,arguments,void 0,function*({did:r,gatewayUri:n}){let i=yield t.toDnsPacket({didDocument:r.document,didMetadata:r.metadata,authoritativeGatewayUris:[n]}),o=yield Ct.createBep44PutMessage({dnsPacket:i,publicKeyBytes:Ct.identifierToIdentityKeyBytes({didUri:r.uri}),signer:yield r.getSigner({methodId:"0"})}),s=yield t.pkarrPut({gatewayUri:n,bep44Message:o});return{didDocument:r.document,didDocumentMetadata:Object.assign(Object.assign({},r.metadata),{published:s,versionId:o.seq.toString()}),didRegistrationMetadata:{}}})}static pkarrGet(e){return Lt(this,arguments,void 0,function*({gatewayUri:r,publicKeyBytes:n}){let i=ne.uint8Array(n).toBase32Z(),o=new URL(i,r).href,s;try{if(s=yield fetch(o,{method:"GET"}),!s.ok)throw new re(ie.NotFound,`Pkarr record not found for: ${i}`)}catch(u){throw u instanceof re?u:new re(ie.InternalError,`Failed to fetch Pkarr record: ${u.message}`)}let c=yield s.arrayBuffer();if(!c)throw new re(ie.NotFound,`Pkarr record not found for: ${i}`);if(c.byteLength<72)throw new re(ie.InvalidDidDocumentLength,`Pkarr response must be at least 72 bytes but got: ${c.byteLength}`);if(c.byteLength>1072)throw new re(ie.InvalidDidDocumentLength,`Pkarr response exceeds 1000 byte limit: ${c.byteLength}`);return{k:n,seq:Number(new DataView(c).getBigUint64(64)),sig:new Uint8Array(c,0,64),v:new Uint8Array(c,72)}})}static pkarrPut(e){return Lt(this,arguments,void 0,function*({gatewayUri:r,bep44Message:n}){let i=ne.uint8Array(n.k).toBase32Z(),o=new URL(i,r).href,s=new Uint8Array(n.v.length+72);s.set(n.sig,0),new DataView(s.buffer).setBigUint64(n.sig.length,BigInt(n.seq)),s.set(n.v,n.sig.length+8);let c;try{c=yield fetch(o,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:s})}catch(a){throw new re(ie.InternalError,`Failed to put Pkarr record for identifier ${i}: ${a.message}`)}return c.ok})}static fromDnsPacket(e){return Lt(this,arguments,void 0,function*({didUri:r,dnsPacket:n}){var i,o,s;let c={id:r},a={published:!0},u=new Map;for(let d of(i=n?.answers)!==null&&i!==void 0?i:[]){if(d.type!=="TXT")continue;let f=d.name.split(".")[0].substring(1);switch(!0){case f.startsWith("aka"):{let h=Ct.parseTxtDataToString(d.data);c.alsoKnownAs=h.split(sr);break}case f.startsWith("cnt"):{let h=Ct.parseTxtDataToString(d.data);c.controller=h.includes(sr)?h.split(sr):h;break}case f.startsWith("k"):{let{id:h,t:p,k:g,c:y,a:x}=Ct.parseTxtDataToObject(d.data),S=ne.base64Url(g).toUint8Array(),I=cr[Number(p)],A=yield Ct.keyConverter(I).bytesToPublicKey({publicKeyBytes:S});A.alg=x||P_[Number(p)];let O=f==="k0"?"0":h!==void 0?h:yield we({jwk:A});(o=c.verificationMethod)!==null&&o!==void 0||(c.verificationMethod=[]);let T=`${r}#${O}`;c.verificationMethod.push({id:T,type:"JsonWebKey",controller:y??r,publicKeyJwk:A}),u.set(f,T);break}case f.startsWith("s"):{let h=Ct.parseTxtDataToObject(d.data),{id:p,t:g,se:y}=h,x=C_(h,["id","t","se"]),S=y.includes(sr)?y.split(sr):[y],I=Object.fromEntries(Object.entries(x).map(([A,O])=>[A,O.includes(sr)?O.split(sr):O]));(s=c.service)!==null&&s!==void 0||(c.service=[]),c.service.push(Object.assign(Object.assign({},I),{id:`${r}#${p}`,type:g,serviceEndpoint:S}));break}case f.startsWith("typ"):{let{id:h}=Ct.parseTxtDataToObject(d.data);a.types=h.split(sr).map(p=>Number(p));break}case f.startsWith("did"):{let h=I=>I.split(sr).map(A=>u.get(A)).filter(A=>typeof A=="string"),{auth:p,asm:g,del:y,inv:x,agm:S}=Ct.parseTxtDataToObject(d.data);p&&(c.authentication=h(p)),g&&(c.assertionMethod=h(g)),y&&(c.capabilityDelegation=h(y)),x&&(c.capabilityInvocation=h(x)),S&&(c.keyAgreement=h(S));break}}}return{didDocument:c,didDocumentMetadata:a,didResolutionMetadata:{}}})}static toDnsPacket(e){return Lt(this,arguments,void 0,function*({didDocument:r,didMetadata:n,authoritativeGatewayUris:i,previousDidProof:o}){var s,c,a,u,d;let f=[],h=[],p=new Map,g=[],y=[];if(o!==void 0){let{signature:I,previousDid:A}=o;yield Ct.validatePreviousDidProof({newDid:r.id,previousDidProof:o}),f.push({type:"TXT",name:"_prv._did.",ttl:ss,data:`id=${A};s=${I}`})}if(r.alsoKnownAs&&f.push({type:"TXT",name:"_aka._did.",ttl:ss,data:r.alsoKnownAs.join(sr)}),r.controller){let I=Array.isArray(r.controller)?r.controller.join(sr):r.controller;f.push({type:"TXT",name:"_cnt._did.",ttl:ss,data:I})}for(let[I,A]of(c=(s=r.verificationMethod)===null||s===void 0?void 0:s.entries())!==null&&c!==void 0?c:[]){let O=`k${I}`;y.push(O);let T=A.id.split("#").pop();p.set(T,O);let M=A.publicKeyJwk;if(!(M?.crv&&M.crv in M_))throw new re(ie.InvalidPublicKeyType,`Verification method '${A.id}' contains an unsupported key type: ${(a=M?.crv)!==null&&a!==void 0?a:"undefined"}`);let q=cr[M.crv],j=yield Ct.keyConverter(M.crv).publicKeyToBytes({publicKey:M}),$=ne.uint8Array(j).toBase64Url(),Z=[`t=${q}`,`k=${$}`];T!=="0"&&(yield we({jwk:M}))!==T&&Z.unshift(`id=${T}`),M.alg!==P_[q]&&Z.push(`a=${M.alg}`),A.controller!==r.id&&Z.push(`c=${A.controller}`),f.push({type:"TXT",name:`_${O}._did.`,ttl:ss,data:Z.join(kp)})}(u=r.service)===null||u===void 0||u.forEach((I,A)=>{let O=`s${A}`;g.push(O);let{id:T,type:M,serviceEndpoint:q}=I,j=C_(I,["id","type","serviceEndpoint"]);T=Kr(T),q=Array.isArray(q)?q.join(","):q;let Z=Object.entries(Object.assign({id:T,t:M,se:q},j)).map(([G,_])=>`${G}=${_}`).join(kp),Q=Ct.chunkDataIfNeeded(Z);f.push({type:"TXT",name:`_${O}._did.`,ttl:ss,data:Q})});let x=[`v=${SC}`];if(y.length&&x.push(`vm=${y.join(sr)}`),Object.keys(Ki).forEach(I=>{var A;let O=(A=r[I])===null||A===void 0?void 0:A.map(T=>p.get(T.split("#").pop()));if(O){let T=ib[I];x.push(`${T}=${O.join(sr)}`)}}),g.length&&x.push(`svc=${g.join(sr)}`),!((d=n.types)===null||d===void 0)&&d.length){let A=n.types.map(O=>typeof O=="string"?nb[O]:O);f.push({type:"TXT",name:"_typ._did.",ttl:ss,data:`id=${A.join(sr)}`})}f.push({type:"TXT",name:"_did."+t.getUniqueDidSuffix(r.id)+".",ttl:ss,data:x.join(kp)});for(let I of i||[])h.push({type:"NS",name:"_did."+t.getUniqueDidSuffix(r.id)+".",ttl:ss,data:I+"."});return{id:0,type:"response",flags:O_,answers:[...f,...h]}})}static getUniqueDidSuffix(e){return e.split(":")[2]}},Ct=class t{static createBep44PutMessage(e){return Lt(this,arguments,void 0,function*({dnsPacket:r,publicKeyBytes:n,signer:i}){let o=Math.ceil(Date.now()/1e3),s=of(r),c=zw.encode({seq:o,v:s}).subarray(1,-1);if(c.length>1e3)throw new re(ie.InvalidDidDocumentLength,`DNS packet exceeds the 1000 byte maximum size: ${c.length} bytes`);let a=yield i.sign({data:c});return{k:n,seq:o,sig:a,v:s}})}static identifierToIdentityKey(e){return Lt(this,arguments,void 0,function*({didUri:r}){let n=t.identifierToIdentityKeyBytes({didUri:r});return yield Bt.bytesToPublicKey({publicKeyBytes:n})})}static identifierToIdentityKeyBytes({didUri:e}){let r=xe.parse(e);if(!r)throw new re(ie.InvalidDid,`Invalid DID URI: ${e}`);if(r.method!==sf.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${r.method}`);let n;try{n=ne.base32Z(r.id).toUint8Array()}catch{throw new re(ie.InvalidPublicKey,"Failed to decode method-specific identifier")}if(n.length!==32)throw new re(ie.InvalidPublicKeyLength,`Invalid public key length: ${n.length}`);return n}static identityKeyToIdentifier(e){return Lt(this,arguments,void 0,function*({identityKey:r}){let n=yield Bt.publicKeyToBytes({publicKey:r}),i=ne.uint8Array(n).toBase32Z();return`did:${sf.methodName}:${i}`})}static keyConverter(e){let n={Ed25519:Bt,"P-256":{publicKeyToBytes:i=>Lt(this,[i],void 0,function*({publicKey:o}){let s=yield Ft.publicKeyToBytes({publicKey:o});return yield Ft.compressPublicKey({publicKeyBytes:s})}),bytesToPublicKey:Ft.bytesToPublicKey,privateKeyToBytes:Ft.privateKeyToBytes,bytesToPrivateKey:Ft.bytesToPrivateKey},secp256k1:{publicKeyToBytes:i=>Lt(this,[i],void 0,function*({publicKey:o}){let s=yield Nt.publicKeyToBytes({publicKey:o});return yield Nt.compressPublicKey({publicKeyBytes:s})}),bytesToPublicKey:Nt.bytesToPublicKey,privateKeyToBytes:Nt.privateKeyToBytes,bytesToPrivateKey:Nt.bytesToPrivateKey},X25519:qa}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static parseBep44GetMessage(e){return Lt(this,arguments,void 0,function*({bep44Message:r}){let n=yield Bt.bytesToPublicKey({publicKeyBytes:r.k}),i=zw.encode({seq:r.seq,v:r.v}).subarray(1,-1);if(!(yield Bt.verify({key:n,signature:r.sig,data:i})))throw new re(ie.InvalidSignature,"Invalid signature for DHT BEP44 message");return Dp(r.v)})}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split(kp).reduce((r,n)=>{let[i,o]=n.split("=");return r[i]=o,r},{})}static parseTxtDataToString(e){if(typeof e=="string")return e;if(e instanceof Uint8Array)return ne.uint8Array(e).toString();if(Array.isArray(e))return e.map(r=>this.parseTxtDataToString(r)).join("");throw new re(ie.InternalError,"Pkarr returned DNS TXT record with invalid data type")}static validatePreviousDidProof(e){return Lt(this,arguments,void 0,function*({newDid:r,previousDidProof:n}){let i=yield t.identifierToIdentityKey({didUri:n.previousDid}),o=t.identifierToIdentityKeyBytes({didUri:r}),s=ne.base64Url(n.signature).toUint8Array();if(!(yield Bt.verify({key:i,data:o,signature:s})))throw new re(ie.InvalidPreviousDidProof,"The previous DID proof is invalid.")})}static chunkDataIfNeeded(e){if(e.length<=255)return e;let r=[];for(let n=0;n<e.length;n+=255)r.push(e.slice(n,n+255));return r}};l();l();l();l();l();var Ye={DeltaExceedsMaximumSize:"DeltaExceedsMaximumSize",DidDocumentPublicKeyIdDuplicated:"DidDocumentPublicKeyIdDuplicated",DidDocumentPublicKeyMissingOrIncorrectType:"DidDocumentPublicKeyMissingOrIncorrectType",DidDocumentServiceIdDuplicated:"DidDocumentServiceIdDuplicated",DidSuffixIncorrectLength:"DidSuffixIncorrectLength",EncodedStringIncorrectEncoding:"EncodedStringIncorrectEncoding",IdNotUsingBase64UrlCharacterSet:"IdNotUsingBase64UrlCharacterSet",IdTooLong:"IdTooLong",JwkEs256kMissingOrInvalidCrv:"JwkEs256kMissingOrInvalidCrv",JwkEs256kMissingOrInvalidKty:"JwkEs256kMissingOrInvalidKty",JwkEs256kHasIncorrectLengthOfX:"JwkEs256kHasIncorrectLengthOfX",JwkEs256kHasIncorrectLengthOfY:"JwkEs256kHasIncorrectLengthOfY",JwkEs256kHasIncorrectLengthOfD:"JwkEs256kHasIncorrectLengthOfD",MultihashStringNotAMultihash:"MultihashStringNotAMultihash",MultihashUnsupportedHashAlgorithm:"MultihashUnsupportedHashAlgorithm",PublicKeyJwkEs256kHasUnexpectedProperty:"PublicKeyJwkEs256kHasUnexpectedProperty",PublicKeyPurposeDuplicated:"PublicKeyPurposeDuplicated",ServiceEndpointCannotBeAnArray:"ServiceEndpointCannotBeAnArray",ServiceEndpointStringNotValidUri:"ServiceEndpointStringNotValidUri",ServiceTypeTooLong:"ServiceTypeTooLong"};l();var Pe=class extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};l();l();l();l();var pX=new Uint8Array(0);var ob=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};l();var sb=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},cb=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return K_(this,e)}},ab=class{constructor(e){this.decoders=e}or(e){return K_(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},K_=(t,e)=>new ab({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),ub=class{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new sb(e,r,n),this.decoder=new cb(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},AC=({name:t,prefix:e,encode:r,decode:n})=>new ub(t,e,r,n);var TC=(t,e,r,n)=>{let i={};for(let d=0;d<e.length;++d)i[e[d]]=d;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),c=0,a=0,u=0;for(let d=0;d<o;++d){let f=i[t[d]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,c+=r,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=r||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s},_C=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,c=0;for(let a=0;a<t.length;++a)for(c=c<<8|t[a],s+=8;s>r;)s-=r,o+=e[i&c>>s];if(s&&(o+=e[i&c<<r-s]),n)for(;o.length*r&7;)o+="=";return o},cf=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>AC({prefix:e,name:t,encode(i){return _C(i,n,r)},decode(i){return TC(i,n,r,t)}});var TX=cf({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_X=cf({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),af=cf({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),IX=cf({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xr=class t{static encode(e){return af.baseEncode(e)}static decodeAsBytes(e,r){if(!t.isBase64UrlString(e))throw new Pe(Ye.EncodedStringIncorrectEncoding,`Given ${r} must be base64url string.`);return af.baseDecode(e)}static decodeAsString(e,r){let n=t.decodeAsBytes(e,r);return t.bytesToString(n)}static isBase64UrlString(e){return/^[A-Za-z0-9_-]+$/.test(e)}static stringToBytes(e){return new TextEncoder().encode(e)}static bytesToString(e){return new TextDecoder().decode(e)}};l();var J_=Kn(H_(),1);l();l();var db;(function(t){t.Public="public",t.Private="private"})(db||(db={}));var Hr=db;var Ut=class{static validateEs256kOperationKey(e,r){let n=new Set(["kty","crv","x","y"]);r===Hr.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new Pe(Ye.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new Pe(Ye.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new Pe(Ye.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new Pe(Ye.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new Pe(Ye.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(r===Hr.Private&&(e.d===void 0||e.d.length!==43))throw new Pe(Ye.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new Pe(Ye.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!xr.isBase64UrlString(e))throw new Pe(Ye.IdNotUsingBase64UrlCharacterSet,`Key ID '${e}' is not a Base64URL string.`)}static validatePublicKeyPurposes(e){if(e===void 0)return;let r=new Set;for(let n of e){if(r.has(n))throw new Pe(Ye.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);r.add(n)}}};l();var uf=class{};uf.hashAlgorithmInMultihashCode=18;uf.maxCanonicalizedDeltaSizeInBytes=1e3;var ar=uf;l();var F_=Kn(q_(),1);var Nn=class t{static canonicalizeAsBytes(e){let r=t.removeAllUndefinedProperties(e),n=F_.default(r);return xr.stringToBytes(n)}static removeAllUndefinedProperties(e){for(let r in e)typeof e[r]=="object"?t.removeAllUndefinedProperties(e[r]):e[r]===void 0&&delete e[r];return e}};l();l();l();l();var IC=G_,j_=128,BC=127,RC=~BC,UC=Math.pow(2,31);function G_(t,e,r){e=e||[],r=r||0;for(var n=r;t>=UC;)e[r++]=t&255|j_,t/=128;for(;t&RC;)e[r++]=t&255|j_,t>>>=7;return e[r]=t|0,G_.bytes=r-n+1,e}var OC=fb,DC=128,W_=127;function fb(t,n){var r=0,n=n||0,i=0,o=n,s,c=t.length;do{if(o>=c)throw fb.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&W_)<<i:(s&W_)*Math.pow(2,i),i+=7}while(s>=DC);return fb.bytes=o-n,r}var kC=Math.pow(2,7),NC=Math.pow(2,14),CC=Math.pow(2,21),LC=Math.pow(2,28),PC=Math.pow(2,35),MC=Math.pow(2,42),KC=Math.pow(2,49),$C=Math.pow(2,56),HC=Math.pow(2,63),VC=function(t){return t<kC?1:t<NC?2:t<CC?3:t<LC?4:t<PC?5:t<MC?6:t<KC?7:t<$C?8:t<HC?9:10},qC={encode:IC,decode:OC,encodingLength:VC},FC=qC,df=FC;var lb=(t,e=0)=>[df.decode(t,e),df.decode.bytes],hb=(t,e,r=0)=>(df.encode(t,e,r),e),pb=t=>df.encodingLength(t);var yb=(t,e)=>{let r=e.byteLength,n=pb(t),i=n+pb(r),o=new Uint8Array(i+r);return hb(t,o,0),hb(r,o,n),o.set(e,i),new Lp(t,r,e,o)},z_=t=>{let e=ob(t),[r,n]=lb(e),[i,o]=lb(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Lp(r,i,s,e)};var Lp=class{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};l();l();var mb=({name:t,code:e,encode:r})=>new gb(t,e,r),gb=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?yb(this.code,r):r.then(n=>yb(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Y_=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Pp=mb({name:"sha2-256",code:18,encode:Y_("SHA-256")}),cZ=mb({name:"sha2-512",code:19,encode:Y_("SHA-512")});var ff=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Pt=class t{static hash(e,r){return ff(this,void 0,void 0,function*(){let n;switch(r){case 18:n=(yield Pp.digest(e)).bytes;break;default:throw new Pe(Ye.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,r){return ff(this,void 0,void 0,function*(){let n;switch(r){case 18:n=yield Pp.encode(e);break;default:throw new Pe(Ye.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,r){return ff(this,void 0,void 0,function*(){let n=Nn.canonicalizeAsBytes(e);return yield t.hashThenEncode(n,r)})}static canonicalizeThenDoubleHashThenEncode(e,r){return ff(this,void 0,void 0,function*(){let n=Nn.canonicalizeAsBytes(e),i=yield t.hashAsNonMultihashBytes(n,r);return yield t.hashThenEncode(i,r)})}static hashThenEncode(e,r){return ff(this,void 0,void 0,function*(){let n=yield t.hash(e,r);return xr.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,r){let n,i=xr.decodeAsBytes(e,r);try{n=z_(i)}catch{throw new Pe(Ye.MultihashStringNotAMultihash,`Given ${r} string '${e}' is not a multihash after decoding.`)}let o=ar.hashAlgorithmInMultihashCode;if(o!==n.code)throw new Pe(Ye.MultihashUnsupportedHashAlgorithm,`Given ${r} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};l();var wb;(function(t){t.Create="create",t.Update="update",t.Deactivate="deactivate",t.Recover="recover"})(wb||(wb={}));var lf=wb;l();var bb;(function(t){t.Replace="replace",t.AddPublicKeys="add-public-keys",t.RemovePublicKeys="remove-public-keys",t.AddServices="add-services",t.RemoveServices="remove-services"})(bb||(bb={}));var mc=bb;var Mp=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},cs=class t{static createCreateRequest(e){return Mp(this,void 0,void 0,function*(){let r=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;Ut.validateEs256kOperationKey(r,Hr.Public),Ut.validateEs256kOperationKey(n,Hr.Public),t.validateDidDocumentKeys(i),t.validateServices(o);let s=ar.hashAlgorithmInMultihashCode,c=[{action:mc.Replace,document:e.document}],a={updateCommitment:yield Pt.canonicalizeThenDoubleHashThenEncode(n,s),patches:c};t.validateDeltaSize(a);let d={deltaHash:yield Pt.canonicalizeThenHashThenEncode(a,s),recoveryCommitment:yield Pt.canonicalizeThenDoubleHashThenEncode(r,s)};return{type:lf.Create,suffixData:d,delta:a}})}static createDeactivateRequest(e){return Mp(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.recoveryPublicKey,Hr.Public);let r=ar.hashAlgorithmInMultihashCode,n=yield Pt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:lf.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return Mp(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.recoveryPublicKey,Hr.Public),Ut.validateEs256kOperationKey(e.nextRecoveryPublicKey,Hr.Public),Ut.validateEs256kOperationKey(e.nextUpdatePublicKey,Hr.Public),t.validateDidDocumentKeys(e.document.publicKeys),t.validateServices(e.document.services);let r=ar.hashAlgorithmInMultihashCode,n=yield Pt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i=[{action:mc.Replace,document:e.document}],o=yield Pt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,r),s={patches:i,updateCommitment:o},c=yield Pt.canonicalizeThenHashThenEncode(s,r),u={recoveryCommitment:yield Pt.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,r),recoveryKey:e.recoveryPublicKey,deltaHash:c},d=yield e.signer.sign({alg:"ES256K"},u);return{type:lf.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:d}})}static createUpdateRequest(e){return Mp(this,void 0,void 0,function*(){if(t.validateDidSuffix(e.didSuffix),Ut.validateEs256kOperationKey(e.updatePublicKey,Hr.Public),Ut.validateEs256kOperationKey(e.nextUpdatePublicKey,Hr.Public),t.validateServices(e.servicesToAdd),t.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let g of e.idsOfServicesToRemove)Ut.validateId(g);if(e.idsOfPublicKeysToRemove!==void 0)for(let g of e.idsOfPublicKeysToRemove)Ut.validateId(g);let r=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let g={action:mc.AddServices,services:n};r.push(g)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let g={action:mc.RemoveServices,ids:i};r.push(g)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let g={action:mc.AddPublicKeys,publicKeys:o};r.push(g)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let g={action:mc.RemovePublicKeys,ids:s};r.push(g)}let c=ar.hashAlgorithmInMultihashCode,a=yield Pt.canonicalizeThenHashThenEncode(e.updatePublicKey,c),u=yield Pt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,c),d={patches:r,updateCommitment:u},f=yield Pt.canonicalizeThenHashThenEncode(d,c),h={updateKey:e.updatePublicKey,deltaHash:f},p=yield e.signer.sign({alg:"ES256K"},h);return{type:lf.Update,didSuffix:e.didSuffix,revealValue:a,delta:d,signedData:p}})}static validateDidSuffix(e){Pt.validateEncodedHashComputedUsingSupportedHashAlgorithm(e,"didSuffix")}static validateDidDocumentKeys(e){if(e===void 0)return;let r=new Set;for(let n of e){if(Array.isArray(n.publicKeyJwk))throw new Pe(Ye.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(Ut.validateId(n.id),r.has(n.id))throw new Pe(Ye.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);r.add(n.id),Ut.validatePublicKeyPurposes(n.purposes)}}static validateServices(e){if(e!==void 0&&e.length!==0){let r=new Set;for(let n of e){if(t.validateService(n),r.has(n.id))throw new Pe(Ye.DidDocumentServiceIdDuplicated,"Service id has to be unique");r.add(n.id)}}}static validateService(e){Ut.validateId(e.id);let r=30;if(e.type.length>r){let n=`Service endpoint type length ${e.type.length} exceeds max allowed length of ${r}.`;throw new Pe(Ye.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new Pe(Ye.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&J_.parse(e.serviceEndpoint).error!==void 0)throw new Pe(Ye.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let r=Nn.canonicalizeAsBytes(e);if(r.length>ar.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${r.length} bytes exceeded limit of ${ar.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new Pe(Ye.DeltaExceedsMaximumSize,n)}}};var X_=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Qa=class t{static createLongFormDid(e){return X_(this,void 0,void 0,function*(){let r=yield cs.createCreateRequest(e),n=yield t.computeDidUniqueSuffix(r.suffixData),i;ar.network===void 0||ar.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${ar.network}:${n}`;let o={suffixData:r.suffixData,delta:r.delta},s=Nn.canonicalizeAsBytes(o),c=xr.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return X_(this,void 0,void 0,function*(){let r=Nn.canonicalizeAsBytes(e),n=yield Pt.hash(r,ar.hashAlgorithmInMultihashCode);return xr.encode(n)})}};l();l();var Z_;(function(t){t.Mainnet="mainnet",t.Testnet="test"})(Z_||(Z_={}));l();var Q_;(function(t){t.Authentication="authentication",t.AssertionMethod="assertionMethod",t.CapabilityInvocation="capabilityInvocation",t.CapabilityDelegation="capabilityDelegation",t.KeyAgreement="keyAgreement"})(Q_||(Q_={}));l();var as=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},pi;(function(t){t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519"})(pi||(pi={}));var GC={Ed25519:pi.Ed25519,ES256K:pi.secp256k1,ES256:pi.secp256r1,"P-256":pi.secp256r1,secp256k1:pi.secp256k1,secp256r1:pi.secp256r1},eI="https://ion.tbd.engineering",xb=class t extends fn{static create(){return as(this,arguments,void 0,function*({keyManager:e=new er,options:r={}}={}){var n,i,o,s,c,a,u;if(!((n=r.verificationMethods)===null||n===void 0)&&n.some(T=>!(T.algorithm in GC)))throw new Error("One or more verification method algorithms are not supported");let d=(i=r.verificationMethods)===null||i===void 0?void 0:i.filter(T=>"id"in T).map(T=>T.id);if(d&&d.length!==new Set(d).size)throw new Error("One or more verification method IDs are not unique");if(!((o=r.services)===null||o===void 0)&&o.some(T=>!T.id||!T.type||!T.serviceEndpoint))throw new Error("One or more services are missing required properties");let f={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},h=[];for(let T of(s=r.verificationMethods)!==null&&s!==void 0?s:[f]){let M=yield e.generateKey({algorithm:T.algorithm}),q=yield e.getPublicKey({keyUri:M});h.push({id:T.id,publicKeyJwk:q,purposes:(c=T.purposes)!==null&&c!==void 0?c:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let p=yield e.generateKey({algorithm:pi.secp256k1}),g=yield e.getPublicKey({keyUri:p}),y=yield e.generateKey({algorithm:pi.secp256k1}),x=yield e.getPublicKey({keyUri:y}),S=yield wc.computeLongFormDidUri({recoveryKey:g,updateKey:x,services:(a=r.services)!==null&&a!==void 0?a:[],verificationMethods:h}),{didDocument:I,didResolutionMetadata:A}=yield t.resolve(S,{gatewayUri:r.gatewayUri});if(I===null)throw new Error(`Unable to resolve DID during creation: ${A?.error}`);let O=new wr({uri:S,document:I,metadata:{published:!1,canonicalId:S.split(":",3).join(":"),recoveryKey:g,updateKey:x},keyManager:e});if(!((u=r.publish)!==null&&u!==void 0)||u){let T=yield t.publish({did:O,gatewayUri:r.gatewayUri});O.metadata=T.didDocumentMetadata}return O})}static getSigningMethod(e){return as(this,arguments,void 0,function*({didDocument:r,methodId:n}){var i;let o=xe.parse(r.id);if(o&&o.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${o.method}`);let s=(i=r.verificationMethod)===null||i===void 0?void 0:i.find(c=>{var a;return c.id===(n??((a=r.assertionMethod)===null||a===void 0?void 0:a[0]))});if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static import(e){return as(this,arguments,void 0,function*({portableDid:r,keyManager:n=new er}){let i=xe.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");return yield wr.import({portableDid:r,keyManager:n})})}static publish(e){return as(this,arguments,void 0,function*({did:r,gatewayUri:n=eI}){var i,o,s;let c=(o=(i=r.document.verificationMethod)===null||i===void 0?void 0:i.map(d=>({id:d.id,publicKeyJwk:d.publicKeyJwk,purposes:i_({didDocument:r.document,methodId:d.id})})))!==null&&o!==void 0?o:[],a=yield wc.createIonDocument({services:(s=r.document.service)!==null&&s!==void 0?s:[],verificationMethods:c}),u=yield wc.constructCreateRequest({ionDocument:a,recoveryKey:r.metadata.recoveryKey,updateKey:r.metadata.updateKey});try{let d=wc.appendPathToUrl({baseUrl:n,path:"/operations"}),f=yield fetch(d,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});return{didDocument:r.document,didDocumentMetadata:Object.assign(Object.assign({},r.metadata),{published:f.ok}),didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:ie.InternalError,errorMessage:`Failed to publish DID document for: ${r.uri}`}}}})}static resolve(e){return as(this,arguments,void 0,function*(r,n={}){var i,o;let s=xe.parse(r);if(!s)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"invalidDid"}});if(s.method!==t.methodName)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"methodNotSupported"}});let c=(i=n?.gatewayUri)!==null&&i!==void 0?i:eI;try{let a=wc.appendPathToUrl({baseUrl:c,path:`/identifiers/${r}`}),u=yield fetch(a);if(!u.ok)throw new re(ie.NotFound,`Unable to find DID document for: ${r}`);let{didDocument:d,didDocumentMetadata:f}=yield u.json();return Object.assign(Object.assign(Object.assign({},gt),d&&{didDocument:d}),{didDocumentMetadata:Object.assign({published:(o=f?.method)===null||o===void 0?void 0:o.published},f)})}catch(a){if(!(a instanceof re))throw new Error(a);return Object.assign(Object.assign({},gt),{didResolutionMetadata:Object.assign({error:a.code},a.message&&{errorMessage:a.message})})}})}};xb.methodName="ion";var wc=class t{static appendPathToUrl({baseUrl:e,path:r}){let n=new URL(e);return n.pathname=n.pathname.endsWith("/")?n.pathname:n.pathname+"/",n.pathname+=r.startsWith("/")?r.substring(1):r,n.toString()}static computeLongFormDidUri(e){return as(this,arguments,void 0,function*({recoveryKey:r,updateKey:n,services:i,verificationMethods:o}){let s=yield t.createIonDocument({services:i,verificationMethods:o}),c=t.normalizeJwk(r),a=t.normalizeJwk(n);return yield Qa.createLongFormDid({document:s,recoveryKey:c,updateKey:a})})}static constructCreateRequest(e){return as(this,arguments,void 0,function*({ionDocument:r,recoveryKey:n,updateKey:i}){return yield cs.createCreateRequest({document:r,recoveryKey:t.normalizeJwk(n),updateKey:t.normalizeJwk(i)})})}static createIonDocument(e){return as(this,arguments,void 0,function*({services:r,verificationMethods:n}){var i,o;let s=[];for(let u of n){let d=(o=(i=u.id)!==null&&i!==void 0?i:u.publicKeyJwk.kid)!==null&&o!==void 0?o:yield we({jwk:u.publicKeyJwk});d=`${d.split("#").pop()}`;let f={id:d,publicKeyJwk:t.normalizeJwk(u.publicKeyJwk),purposes:u.purposes,type:"JsonWebKey2020"};s.push(f)}let c=r.map(u=>Object.assign(Object.assign({},u),{id:`${u.id.split("#").pop()}`}));return{publicKeys:s,services:c}})}static normalizeJwk(e){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);return n}};l();var Kp=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Eb=class t extends fn{static create(){return Kp(this,arguments,void 0,function*({keyManager:e=new er,options:r={}}={}){var n,i,o,s;if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let c=(s=(n=r.algorithm)!==null&&n!==void 0?n:(o=(i=r.verificationMethods)===null||i===void 0?void 0:i[0])===null||o===void 0?void 0:o.algorithm)!==null&&s!==void 0?s:"Ed25519",a=yield e.generateKey({algorithm:c}),u=yield e.getPublicKey({keyUri:a}),d=ne.object(u).toBase64Url(),f=`did:${t.methodName}:${d}`,p=(yield t.resolve(f)).didDocument;return new wr({uri:f,document:p,metadata:{},keyManager:e})})}static getSigningMethod(e){return Kp(this,arguments,void 0,function*({didDocument:r}){var n;let i=xe.parse(r.id);if(i&&i.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${i.method}`);let[o]=(n=r.verificationMethod)!==null&&n!==void 0?n:[];if(!(o&&o.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return o})}static import(e){return Kp(this,arguments,void 0,function*({portableDid:r,keyManager:n=new er}){let i=xe.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let o=yield wr.import({portableDid:r,keyManager:n});if(o.document.verificationMethod.length!==1)throw new re(ie.InvalidDidDocument,"DID document must contain exactly one verification method");return o})}static resolve(e,r){return Kp(this,void 0,void 0,function*(){let n=xe.parse(e),i;try{i=ne.base64Url(n.id).toObject()}catch{}if(!n||!i)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"invalidDid"}});if(n.method!==t.methodName)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"methodNotSupported"}});let o={"@context":["https://www.w3.org/ns/did/v1"],id:n.uri},s=`${o.id}#0`;switch(o.verificationMethod=[{id:s,type:"JsonWebKey",controller:o.id,publicKeyJwk:i}],o.authentication=[s],o.assertionMethod=[s],o.capabilityInvocation=[s],o.capabilityDelegation=[s],o.keyAgreement=[s],i.use){case"sig":{delete o.keyAgreement;break}case"enc":{delete o.authentication,delete o.assertionMethod,delete o.capabilityInvocation,delete o.capabilityDelegation;break}}return Object.assign(Object.assign({},gt),{didDocument:o})})}};Eb.methodName="jwk";l();var Cn=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},ao;(function(t){t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519"})(ao||(ao={}));var vb={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1",X25519KeyAgreementKey2020:"https://w3id.org/security/suites/x25519-2020/v1"},zC={Ed25519:ao.Ed25519,ES256K:ao.secp256k1,ES256:ao.secp256r1,"P-256":ao.secp256r1,secp256k1:ao.secp256k1,secp256r1:ao.secp256r1,X25519:ao.X25519},Sb=class t extends fn{static create(){return Cn(this,arguments,void 0,function*({keyManager:e=new er,options:r={}}={}){var n,i,o,s;if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let c=(s=(n=r.algorithm)!==null&&n!==void 0?n:(o=(i=r.verificationMethods)===null||i===void 0?void 0:i[0])===null||o===void 0?void 0:o.algorithm)!==null&&s!==void 0?s:"Ed25519",a=yield e.generateKey({algorithm:c}),u=yield e.getPublicKey({keyUri:a}),d=yield Er.publicKeyToMultibaseId({publicKey:u}),f=`did:${t.methodName}:${d}`,p=(yield t.resolve(f,r)).didDocument;return new wr({uri:f,document:p,metadata:{},keyManager:e})})}static getSigningMethod(e){return Cn(this,arguments,void 0,function*({didDocument:r}){var n;let i=xe.parse(r.id);if(i&&i.method!==this.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${i.method}`);let[o]=r.assertionMethod||[],s=(n=r.verificationMethod)===null||n===void 0?void 0:n.find(c=>c.id===o);if(!(s&&s.publicKeyJwk))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return s})}static import(e){return Cn(this,arguments,void 0,function*({portableDid:r,keyManager:n=new er}){let i=xe.parse(r.uri);if(i?.method!==t.methodName)throw new re(ie.MethodNotSupported,"Method not supported");let o=yield wr.import({portableDid:r,keyManager:n});if(o.document.verificationMethod.length!==1)throw new re(ie.InvalidDidDocument,"DID document must contain exactly one verification method");return o})}static resolve(e,r){return Cn(this,void 0,void 0,function*(){try{let n=yield t.createDocument({didUri:e,options:r});return Object.assign(Object.assign({},gt),{didDocument:n})}catch(n){if(!(n instanceof re))throw new Error(n);return Object.assign(Object.assign({},gt),{didResolutionMetadata:Object.assign({error:n.code},n.message&&{errorMessage:n.message})})}})}static createDocument(e){return Cn(this,arguments,void 0,function*({didUri:r,options:n={}}){let{defaultContext:i="https://www.w3.org/ns/did/v1",enableEncryptionKeyDerivation:o=!1,enableExperimentalPublicKeyTypes:s=!1,publicKeyFormat:c="JsonWebKey2020"}=n,a={id:""},u=xe.parse(r);if(!u)throw new re(ie.InvalidDid,`Invalid DID URI: ${r}`);let d=u.id;if(u.method!==t.methodName)throw new re(ie.MethodNotSupported,`Method not supported: ${u.method}`);if(!t.validateIdentifier(u))throw new re(ie.InvalidDid,`Invalid DID URI: ${r}`);let f=yield t.createSignatureMethod({didUri:r,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:s,publicKeyFormat:c}});if(a.id=u.uri,a.verificationMethod=[f],a.authentication=[f.id],a.assertionMethod=[f.id],a.capabilityInvocation=[f.id],a.capabilityDelegation=[f.id],o===!0){let g=c==="Ed25519VerificationKey2020"?"X25519KeyAgreementKey2020":"JsonWebKey2020",y=yield this.createEncryptionMethod({didUri:r,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:s,publicKeyFormat:g}});a.verificationMethod.push(y),a.keyAgreement=[y.id]}let h=[i];return n_({didDocument:a}).forEach(g=>{let y=vb[g];h.push(y)}),a["@context"]=h,a})}static createEncryptionMethod(e){return Cn(this,arguments,void 0,function*({didUri:r,multibaseValue:n,options:i}){let{enableExperimentalPublicKeyTypes:o,publicKeyFormat:s}=i,c={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u}=yield t.deriveEncryptionKey({multibaseValue:n}),d=a.byteLength,f=Er.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(d!==f)throw new re(ie.InvalidPublicKeyLength,`Expected ${d} bytes. Actual: ${f}`);let h=Hw({keyBytes:a,multicodecCode:u});c.id=`${r}#${h}`;try{new URL(c.id)}catch{throw new re(ie.InvalidDidUrl,"Verification Method ID is not a valid DID URL.")}if(!(s in vb))throw new re(ie.UnsupportedPublicKeyType,`Unsupported format: ${s}`);if(o===!1&&!["Multikey","JsonWebKey2020","X25519KeyAgreementKey2020"].includes(s))throw new re(ie.InvalidPublicKeyType,`Specified '${s}' without setting enableExperimentalPublicKeyTypes to true.`);if(c.type=s,c.controller=r,s==="X25519KeyAgreementKey2020"&&(c.publicKeyMultibase=h),s==="JsonWebKey2020"){let{crv:g}=yield Er.multicodecToJwk({code:u});c.publicKeyJwk=yield Er.keyConverter(g).bytesToPublicKey({publicKeyBytes:a})}return c})}static createSignatureMethod(e){return Cn(this,arguments,void 0,function*({didUri:r,multibaseValue:n,options:i}){let{enableExperimentalPublicKeyTypes:o,publicKeyFormat:s}=i,c={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u,multicodecName:d}=Vw({multibaseKeyId:n}),f=a.byteLength,h=Er.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(f!==h)throw new re(ie.InvalidPublicKeyLength,`Expected ${f} bytes. Actual: ${h}`);let p=!1;switch(d){case"secp256k1-pub":p=yield Nt.validatePublicKey({publicKeyBytes:a});break;case"ed25519-pub":p=yield Bt.validatePublicKey({publicKeyBytes:a});break;case"x25519-pub":p=!0;break}if(!p)throw new re(ie.InvalidPublicKey,"Invalid public key detected.");c.id=`${r}#${n}`;try{new URL(c.id)}catch{throw new re(ie.InvalidDidUrl,"Verification Method ID is not a valid DID URL.")}if(!(s in vb))throw new re(ie.UnsupportedPublicKeyType,`Unsupported format: ${s}`);if(o===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(s))throw new re(ie.InvalidPublicKeyType,`Specified '${s}' without setting enableExperimentalPublicKeyTypes to true.`);if(c.type=s,c.controller=r,s==="Ed25519VerificationKey2020"&&(c.publicKeyMultibase=n),s==="JsonWebKey2020"){let{crv:y}=yield Er.multicodecToJwk({code:u});c.publicKeyJwk=yield Er.keyConverter(y).bytesToPublicKey({publicKeyBytes:a})}return c})}static deriveEncryptionKey(e){return Cn(this,arguments,void 0,function*({multibaseValue:r}){let n={keyBytes:new Uint8Array,multicodecCode:0},{keyBytes:i,multicodecCode:o}=Vw({multibaseKeyId:r});if(o===237){let s=yield Er.keyConverter("Ed25519").bytesToPublicKey({publicKeyBytes:i}),c=yield Bt.convertPublicKeyToX25519({publicKey:s});n={keyBytes:yield Er.keyConverter("Ed25519").publicKeyToBytes({publicKey:c}),multicodecCode:236}}return n})}static validateIdentifier(e){let{method:r,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&r==="key"&&Number("1")>0&&ca(n)==="String"&&n.startsWith("z")}};Sb.methodName="key";var Er=class t{static jwkToMulticodec(e){return Cn(this,arguments,void 0,function*({jwk:r}){let n=[];r.crv&&(n.push(r.crv),r.d?n.push("private"):n.push("public"));let i=n.join(":"),o=t.JWK_TO_MULTICODEC[i];if(o===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${i}'`);return{code:Jt.getCodeFromName({name:o}),name:o}})}static keyCompressor(e){let n={"P-256":Ft.compressPublicKey,secp256k1:Nt.compressPublicKey}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Bt,"P-256":Ft,secp256k1:Nt,X25519:qa}[e];if(!n)throw new re(ie.InvalidPublicKeyType,`Unsupported curve: ${e}`);return n}static multicodecToJwk(e){return Cn(this,arguments,void 0,function*({code:r,name:n}){if(!(n?!r:r))throw new Error("Either 'name' or 'code' must be defined, but not both.");n=n===void 0?Jt.getNameFromCode({code:r}):n;let i=n,o=t.MULTICODEC_TO_JWK[i];if(o===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return Object.assign({},o)})}static publicKeyToMultibaseId(e){return Cn(this,arguments,void 0,function*({publicKey:r}){var n;if(!(r?.crv&&r.crv in zC))throw new re(ie.InvalidPublicKeyType,`Public key contains an unsupported key type: ${(n=r?.crv)!==null&&n!==void 0?n:"undefined"}`);let i=yield t.keyConverter(r.crv).publicKeyToBytes({publicKey:r});/^(secp256k1|P-256|P-384|P-521)$/.test(r.crv)&&(i=yield t.keyCompressor(r.crv)({publicKeyBytes:i}));let{name:o}=yield t.jwkToMulticodec({jwk:r});return Hw({keyBytes:i,multicodecName:o})})}};Er.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv","X25519:public":"x25519-pub","X25519:private":"x25519-priv"};Er.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,236:32,237:32};Er.MULTICODEC_TO_JWK={"ed25519-pub":{crv:"Ed25519",kty:"OKP",x:""},"ed25519-priv":{crv:"Ed25519",kty:"OKP",x:"",d:""},"secp256k1-pub":{crv:"secp256k1",kty:"EC",x:"",y:""},"secp256k1-priv":{crv:"secp256k1",kty:"EC",x:"",y:"",d:""},"x25519-pub":{crv:"X25519",kty:"OKP",x:""},"x25519-priv":{crv:"X25519",kty:"OKP",x:"",d:""}};l();var YC=function(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function c(d){try{u(n.next(d))}catch(f){s(f)}}function a(d){try{u(n.throw(d))}catch(f){s(f)}}function u(d){d.done?o(d.value):i(d.value).then(c,a)}u((n=n.apply(t,e||[])).next())})},Ab=class t extends fn{static resolve(e,r){return YC(this,void 0,void 0,function*(){let n=xe.parse(e);if(!n)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"invalidDid"}});if(n.method!==t.methodName)return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"methodNotSupported"}});let i=`https://${n.id.replace(/:/g,"/")}`;i=decodeURIComponent(i);let o=n.id.includes(":")?`${i}/did.json`:`${i}/.well-known/did.json`;try{let s=yield fetch(o);if(!s.ok)throw new Error("HTTP error status code returned");let c=yield s.json();return Object.assign(Object.assign({},gt),{didDocument:c})}catch{return Object.assign(Object.assign({},gt),{didResolutionMetadata:{error:"notFound"}})}})}};Ab.methodName="web";l();var tL=Kn(rI(),1),rL=Kn(Qg(),1);l();l();var st=class t{static absoluteDidUrl(e,r){if(typeof e=="string"&&e.length!==0)return e.startsWith("#")?`${r}${e}`:e}static relationshipMethodId(e,r){let n=typeof e=="object"&&e!==null&&!Array.isArray(e)?e.id:e;return t.absoluteDidUrl(n,r)}static capabilityInvocationEntry(e,r){let n=t.relationshipMethodId(r,e.id);if(n!==void 0)return e.capabilityInvocation?.find(i=>t.relationshipMethodId(i,e.id)===n)}static verificationMethodOfEntry(e,r){if(t.isDidVerificationMethod(r))return r;let n=t.absoluteDidUrl(r,e.id);if(n!==void 0)return e.verificationMethod?.find(i=>t.absoluteDidUrl(i?.id,e.id)===n)}static isDidVerificationMethod(e){return!(!e||typeof e!="object"||e===null||!("id"in e&&"type"in e&&"controller"in e)||typeof e.id!="string"||typeof e.type!="string"||typeof e.controller!="string")}static isDidService(e){return!(!e||typeof e!="object"||e===null||!("id"in e&&"type"in e&&"serviceEndpoint"in e)||typeof e.id!="string"||typeof e.type!="string"||typeof e.serviceEndpoint!="string")}static getVerificationMethods(e){if(!e)throw new Ve("Required parameter missing: 'didDocument'");let r=[];return r.push(...e.verificationMethod?.filter(t.isDidVerificationMethod)??[]),Object.keys(Ki).forEach(n=>{r.push(...e[n]?.filter(t.isDidVerificationMethod)??[])}),r}static deriveRootCapability(e){return{"@context":"https://w3id.org/zcap/v1",id:`urn:zcap:root:${encodeURIComponent(e)}`,controller:e,invocationTarget:e}}static dereferenceZcapId(e){let r={},n=e.split(":");if(n.length!==4)throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);let[i,o,s,c]=n;if(!i||i!=="urn")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);if(!o||o!=="zcap")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);if(!s||s!=="root")throw new re(ie.InvalidDid,`Invalid capabilityId: ${e}`);let u=decodeURIComponent(c);return r.id=e,r.controller=u,r.invocationTarget=u,r}};l();l();l();l();l();l();l();function nI(t,e,r){return t&e^~t&r}function iI(t,e,r){return t&e^t&r^e&r}var Hp=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=kl(this.buffer)}update(e){ta(this),_e(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=kl(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ta(this),kv(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,Ns(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;n.setBigUint64(i-8,BigInt(this.length*8),o),this.process(n,0);let c=kl(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)c.setUint32(4*f,d[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=c,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},uo=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nL=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]),us=new Uint32Array(64),Tb=class extends Hp{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let f=0;f<16;f++,r+=4)us[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let h=us[f-15],p=us[f-2],g=vn(h,7)^vn(h,18)^h>>>3,y=vn(p,17)^vn(p,19)^p>>>10;us[f]=y+us[f-7]+g+us[f-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:d}=this;for(let f=0;f<64;f++){let h=vn(c,6)^vn(c,11)^vn(c,25),p=d+h+nI(c,a,u)+nL[f]+us[f]|0,y=(vn(n,2)^vn(n,13)^vn(n,22))+iI(n,i,o)|0;d=u,u=a,a=c,c=s+p|0,s=o,o=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,i,o,s,c,a,u,d)}roundClean(){Ns(us)}destroy(){this.set(0,0,0,0,0,0,0,0),Ns(this.buffer)}},_b=class extends Tb{A=uo[0]|0;B=uo[1]|0;C=uo[2]|0;D=uo[3]|0;E=uo[4]|0;F=uo[5]|0;G=uo[6]|0;H=uo[7]|0;constructor(){super(32)}};var Vp=Cv(()=>new _b,Lv(1));l();l();var ur=BigInt(0),tr=BigInt(1),xc=BigInt(2),cI=BigInt(3),aI=BigInt(4),uI=BigInt(5),iL=BigInt(7),dI=BigInt(8),oL=BigInt(9),fI=BigInt(16);function Ln(t,e){let r=t%e;return r>=ur?r:e+r}function Vr(t,e,r){let n=t;for(;e-- >ur;)n*=n,n%=r;return n}function oI(t,e){if(t===ur)throw new Error("invert: expected non-zero number");if(e<=ur)throw new Error("invert: expected positive modulus, got "+e);let r=Ln(t,e),n=e,i=ur,o=tr,s=tr,c=ur;for(;r!==ur;){let u=n/r,d=n%r,f=i-s*u,h=o-c*u;n=r,r=d,i=s,o=c,s=f,c=h}if(n!==tr)throw new Error("invert: does not exist");return Ln(i,e)}function Bb(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function lI(t,e){let r=(t.ORDER+tr)/aI,n=t.pow(e,r);return Bb(t,n,e),n}function sL(t,e){let r=(t.ORDER-uI)/dI,n=t.mul(e,xc),i=t.pow(n,r),o=t.mul(e,i),s=t.mul(t.mul(o,xc),i),c=t.mul(o,t.sub(s,t.ONE));return Bb(t,c,e),c}function cL(t){let e=nu(t),r=hI(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),s=(t+iL)/fI;return(c,a)=>{let u=c.pow(a,s),d=c.mul(u,n),f=c.mul(u,i),h=c.mul(u,o),p=c.eql(c.sqr(d),a),g=c.eql(c.sqr(f),a);u=c.cmov(u,d,p),d=c.cmov(h,f,g);let y=c.eql(c.sqr(d),a),x=c.cmov(u,d,y);return Bb(c,x,a),x}}function hI(t){if(t<cI)throw new Error("sqrt is not defined for small field");let e=t-tr,r=0;for(;e%xc===ur;)e/=xc,r++;let n=xc,i=nu(t);for(;sI(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return lI;let o=i.pow(n,e),s=(e+tr)/xc;return function(a,u){if(a.is0(u))return u;if(sI(a,u)!==1)throw new Error("Cannot find square root");let d=r,f=a.mul(a.ONE,o),h=a.pow(u,e),p=a.pow(u,s);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let g=1,y=a.sqr(h);for(;!a.eql(y,a.ONE);)if(g++,y=a.sqr(y),g===d)throw new Error("Cannot find square root");let x=tr<<BigInt(d-g-1),S=a.pow(f,x);d=g,f=a.sqr(S),h=a.mul(h,f),p=a.mul(p,S)}return p}}function aL(t){return t%aI===cI?lI:t%dI===uI?sL:t%fI===oL?cL(t):hI(t)}var uL=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Rb(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=uL.reduce((n,i)=>(n[i]="function",n),e);return Qu(t,r),t}function dL(t,e,r){if(r<ur)throw new Error("invalid exponent, negatives unsupported");if(r===ur)return t.ONE;if(r===tr)return e;let n=t.ONE,i=e;for(;r>ur;)r&tr&&(n=t.mul(n,i)),i=t.sqr(i),r>>=tr;return n}function qp(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),i=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),o=t.inv(i);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),o),n}function sI(t,e){let r=(t.ORDER-tr)/xc,n=t.pow(e,r),i=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function fL(t,e){e!==void 0&&Jn(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Ib=class{ORDER;BITS;BYTES;isLE;ZERO=ur;ONE=tr;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=ur)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:o}=fL(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Ln(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return ur<=e&&e<this.ORDER}is0(e){return e===ur}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&tr)===tr}neg(e){return Ln(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Ln(e*e,this.ORDER)}add(e,r){return Ln(e+r,this.ORDER)}sub(e,r){return Ln(e-r,this.ORDER)}mul(e,r){return Ln(e*r,this.ORDER)}pow(e,r){return dL(this,e,r)}div(e,r){return Ln(e*oI(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return oI(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=aL(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?K0(e,this.BYTES):Cl(e,this.BYTES)}fromBytes(e,r=!1){_e(e);let{_lengths:n,BYTES:i,isLE:o,ORDER:s,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(i);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let a=o?M0(e):No(e);if(c&&(a=Ln(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return qp(this,e)}cmov(e,r,n){return n?r:e}};function nu(t,e={}){return new Ib(t,e)}function pI(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ub(t){let e=pI(t);return e+Math.ceil(e/2)}function Fp(t,e,r=!1){_e(t);let n=t.length,i=pI(e),o=Ub(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let s=r?M0(t):No(t),c=Ln(s,e-tr)+tr;return r?K0(c,i):Cl(c,i)}var iu=BigInt(0),Ec=BigInt(1);function hf(t,e){let r=e.negate();return t?r:e}function Nb(t,e){let r=qp(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function wI(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Ob(t,e){wI(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=Zu(t),s=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function yI(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r,c=Number(t&i),a=t>>s;c>n&&(c-=o,a+=Ec);let u=e*n,d=u+Math.abs(c)-1,f=c===0,h=c<0,p=e%2!==0;return{nextN:a,offset:d,isZero:f,isNeg:h,isNegF:p,offsetF:u}}var Db=new WeakMap,bI=new WeakMap;function kb(t){return bI.get(t)||1}function gI(t){if(t!==iu)throw new Error("invalid wNAF")}var jp=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>iu;)r&Ec&&(n=n.add(i)),i=i.double(),r>>=Ec;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=Ob(r,this.bits),o=[],s=e,c=s;for(let a=0;a<n;a++){c=s,o.push(c);for(let u=1;u<i;u++)c=c.add(s),o.push(c);s=c.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=Ob(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:p}=yI(n,c,s);n=a,d?o=o.add(hf(h,r[p])):i=i.add(hf(f,r[u]))}return gI(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=Ob(e,this.bits);for(let s=0;s<o.windows&&n!==iu;s++){let{nextN:c,offset:a,isZero:u,isNeg:d}=yI(n,s,o);if(n=c,!u){let f=r[a];i=i.add(d?f.negate():f)}}return gI(n),i}getPrecomputes(e,r,n){let i=Db.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),Db.set(r,i))),i}cached(e,r,n){let i=kb(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=kb(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){wI(r,this.bits),bI.set(e,r),Db.delete(e)}hasCache(e){return kb(e)!==1}};function xI(t,e,r,n){let i=e,o=t.ZERO,s=t.ZERO;for(;r>iu||n>iu;)r&Ec&&(o=o.add(i)),n&Ec&&(s=s.add(i)),i=i.double(),r>>=Ec,n>>=Ec;return{p1:o,p2:s}}function mI(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Rb(e),e}else return nu(t,{isLE:r})}function EI(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>iu))throw new Error(`CURVE.${a} must be positive bigint`)}let i=mI(e.p,r.Fp,n),o=mI(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}function Wp(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}l();l();var Gp=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if(Dl(e),_e(r,void 0,"key"),this.iHash=e.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;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Ns(i)}update(e){return ta(this),this.iHash.update(e),this}digestInto(e){ta(this),_e(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Cb=(t,e,r)=>new Gp(t,e).update(r).digest();Cb.create=(t,e)=>new Gp(t,e);var vI=(t,e)=>(t+(t>=0?e:-e)/SI)/e;function lL(t,e,r){let[[n,i],[o,s]]=e,c=vI(s*t,r),a=vI(-i*t,r),u=t-c*n-a*o,d=-c*i-a*s,f=u<fo,h=d<fo;f&&(u=-u),h&&(d=-d);let p=Zu(Math.ceil($0(r)/2))+ou;if(u<fo||u>=p||d<fo||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:h,k2:d}}function Pb(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Lb(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ju(r.lowS,"lowS"),Ju(r.prehash,"prehash"),r.format!==void 0&&Pb(r.format),r}var Mb=class extends Error{constructor(e=""){super(e)}},ds={Err:Mb,_tlv:{encode:(t,e)=>{let{Err:r}=ds;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,i=Xu(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?Xu(i.length/2|128):"";return Xu(t)+o+i+e},decode(t,e){let{Err:r}=ds,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let i=e[n++],o=!!(i&128),s=0;if(!o)s=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)s=s<<8|d;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=ds;if(t<fo)throw new e("integer: negative integers are not allowed");let r=Xu(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ds;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return No(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ds,i=_e(t,void 0,"signature"),{v:o,l:s}=n.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:u,l:d}=n.decode(2,a);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ds,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}},fo=BigInt(0),ou=BigInt(1),SI=BigInt(2),zp=BigInt(3),hL=BigInt(4);function AI(t,e={}){let r=EI("weierstrass",t,e),{Fp:n,Fn:i}=r,o=r.CURVE,{h:s,n:c}=o;Qu(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=_I(n,i);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(G,_,D){let{x:E,y:U}=_.toAffine(),L=n.toBytes(E);if(Ju(D,"isCompressed"),D){d();let N=!n.isOdd(U);return hr(TI(N),L)}else return hr(Uint8Array.of(4),L,n.toBytes(U))}function h(G){_e(G,void 0,"Point");let{publicKey:_,publicKeyUncompressed:D}=u,E=G.length,U=G[0],L=G.subarray(1);if(E===_&&(U===2||U===3)){let N=n.fromBytes(L);if(!n.isValid(N))throw new Error("bad point: is not on curve, wrong x");let R=y(N),C;try{C=n.sqrt(R)}catch(J){let z=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let P=n.isOdd(C);return(U&1)===1!==P&&(C=n.neg(C)),{x:N,y:C}}else if(E===D&&U===4){let N=n.BYTES,R=n.fromBytes(L.subarray(0,N)),C=n.fromBytes(L.subarray(N,N*2));if(!x(R,C))throw new Error("bad point: is not on curve");return{x:R,y:C}}else throw new Error(`bad point: got length ${E}, expected compressed=${_} or uncompressed=${D}`)}let p=e.toBytes||f,g=e.fromBytes||h;function y(G){let _=n.sqr(G),D=n.mul(_,G);return n.add(n.add(D,n.mul(G,o.a)),o.b)}function x(G,_){let D=n.sqr(_),E=y(G);return n.eql(D,E)}if(!x(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(o.a,zp),hL),I=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(S,I)))throw new Error("bad curve params: a or b");function A(G,_,D=!1){if(!n.isValid(_)||D&&n.is0(_))throw new Error(`bad point coordinate ${G}`);return _}function O(G){if(!(G instanceof $))throw new Error("Weierstrass Point expected")}function T(G){if(!a||!a.basises)throw new Error("no endo");return lL(G,a.basises,i.ORDER)}let M=H0((G,_)=>{let{X:D,Y:E,Z:U}=G;if(n.eql(U,n.ONE))return{x:D,y:E};let L=G.is0();_==null&&(_=L?n.ONE:n.inv(U));let N=n.mul(D,_),R=n.mul(E,_),C=n.mul(U,_);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:N,y:R}}),q=H0(G=>{if(G.is0()){if(e.allowInfinityPoint&&!n.is0(G.Y))return;throw new Error("bad point: ZERO")}let{x:_,y:D}=G.toAffine();if(!n.isValid(_)||!n.isValid(D))throw new Error("bad point: x or y not field elements");if(!x(_,D))throw new Error("bad point: equation left != right");if(!G.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function j(G,_,D,E,U){return D=new $(n.mul(D.X,G),D.Y,D.Z),_=hf(E,_),D=hf(U,D),_.add(D)}class ${static BASE=new $(o.Gx,o.Gy,n.ONE);static ZERO=new $(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(_,D,E){this.X=A("x",_),this.Y=A("y",D,!0),this.Z=A("z",E),Object.freeze(this)}static CURVE(){return o}static fromAffine(_){let{x:D,y:E}=_||{};if(!_||!n.isValid(D)||!n.isValid(E))throw new Error("invalid affine point");if(_ instanceof $)throw new Error("projective point not allowed");return n.is0(D)&&n.is0(E)?$.ZERO:new $(D,E,n.ONE)}static fromBytes(_){let D=$.fromAffine(g(_e(_,void 0,"point")));return D.assertValidity(),D}static fromHex(_){return $.fromBytes(Ls(_))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,D=!0){return Q.createCache(this,_),D||this.multiply(zp),this}assertValidity(){q(this)}hasEvenY(){let{y:_}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(_)}equals(_){O(_);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=_,C=n.eql(n.mul(D,R),n.mul(L,U)),P=n.eql(n.mul(E,R),n.mul(N,U));return C&&P}negate(){return new $(this.X,n.neg(this.Y),this.Z)}double(){let{a:_,b:D}=o,E=n.mul(D,zp),{X:U,Y:L,Z:N}=this,R=n.ZERO,C=n.ZERO,P=n.ZERO,V=n.mul(U,U),J=n.mul(L,L),z=n.mul(N,N),W=n.mul(U,L);return W=n.add(W,W),P=n.mul(U,N),P=n.add(P,P),R=n.mul(_,P),C=n.mul(E,z),C=n.add(R,C),R=n.sub(J,C),C=n.add(J,C),C=n.mul(R,C),R=n.mul(W,R),P=n.mul(E,P),z=n.mul(_,z),W=n.sub(V,z),W=n.mul(_,W),W=n.add(W,P),P=n.add(V,V),V=n.add(P,V),V=n.add(V,z),V=n.mul(V,W),C=n.add(C,V),z=n.mul(L,N),z=n.add(z,z),V=n.mul(z,W),R=n.sub(R,V),P=n.mul(z,J),P=n.add(P,P),P=n.add(P,P),new $(R,C,P)}add(_){O(_);let{X:D,Y:E,Z:U}=this,{X:L,Y:N,Z:R}=_,C=n.ZERO,P=n.ZERO,V=n.ZERO,J=o.a,z=n.mul(o.b,zp),W=n.mul(D,L),Y=n.mul(E,N),X=n.mul(U,R),ue=n.add(D,E),ee=n.add(L,N);ue=n.mul(ue,ee),ee=n.add(W,Y),ue=n.sub(ue,ee),ee=n.add(D,U);let ce=n.add(L,R);return ee=n.mul(ee,ce),ce=n.add(W,X),ee=n.sub(ee,ce),ce=n.add(E,U),C=n.add(N,R),ce=n.mul(ce,C),C=n.add(Y,X),ce=n.sub(ce,C),V=n.mul(J,ee),C=n.mul(z,X),V=n.add(C,V),C=n.sub(Y,V),V=n.add(Y,V),P=n.mul(C,V),Y=n.add(W,W),Y=n.add(Y,W),X=n.mul(J,X),ee=n.mul(z,ee),Y=n.add(Y,X),X=n.sub(W,X),X=n.mul(J,X),ee=n.add(ee,X),W=n.mul(Y,ee),P=n.add(P,W),W=n.mul(ce,ee),C=n.mul(ue,C),C=n.sub(C,W),W=n.mul(ue,Y),V=n.mul(ce,V),V=n.add(V,W),new $(C,P,V)}subtract(_){return this.add(_.negate())}is0(){return this.equals($.ZERO)}multiply(_){let{endo:D}=e;if(!i.isValidNot0(_))throw new Error("invalid scalar: out of range");let E,U,L=N=>Q.cached(this,N,R=>Nb($,R));if(D){let{k1neg:N,k1:R,k2neg:C,k2:P}=T(_),{p:V,f:J}=L(R),{p:z,f:W}=L(P);U=J.add(W),E=j(D.beta,V,z,N,C)}else{let{p:N,f:R}=L(_);E=N,U=R}return Nb($,[E,U])[0]}multiplyUnsafe(_){let{endo:D}=e,E=this;if(!i.isValid(_))throw new Error("invalid scalar: out of range");if(_===fo||E.is0())return $.ZERO;if(_===ou)return E;if(Q.hasCache(this))return this.multiply(_);if(D){let{k1neg:U,k1:L,k2neg:N,k2:R}=T(_),{p1:C,p2:P}=xI($,E,L,R);return j(D.beta,C,P,U,N)}else return Q.unsafe(E,_)}toAffine(_){return M(this,_)}isTorsionFree(){let{isTorsionFree:_}=e;return s===ou?!0:_?_($,this):Q.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:_}=e;return s===ou?this:_?_($,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(_=!0){return Ju(_,"isCompressed"),this.assertValidity(),p($,this,_)}toHex(_=!0){return Cs(this.toBytes(_))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let Z=i.BITS,Q=new jp($,e.endo?Math.ceil(Z/2):Z);return $.BASE.precompute(8),$}function TI(t){return Uint8Array.of(t?2:3)}function _I(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function pL(t,e={}){let{Fn:r}=t,n=e.randomBytes||Ps,i=Object.assign(_I(t.Fp,r),{seed:Ub(r.ORDER)});function o(p){try{let g=r.fromBytes(p);return r.isValidNot0(g)}catch{return!1}}function s(p,g){let{publicKey:y,publicKeyUncompressed:x}=i;try{let S=p.length;return g===!0&&S!==y||g===!1&&S!==x?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(i.seed)){return Fp(_e(p,i.seed,"seed"),r.ORDER)}function a(p,g=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(g)}function u(p){let{secretKey:g,publicKey:y,publicKeyUncompressed:x}=i;if(!Yu(p)||"_lengths"in r&&r._lengths||g===y)return;let S=_e(p,void 0,"key").length;return S===y||S===x}function d(p,g,y=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let x=r.fromBytes(p);return t.fromBytes(g).multiply(x).toBytes(y)}let f={isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c},h=Wp(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:d,keygen:h,Point:t,utils:f,lengths:i})}function II(t,e,r={}){Dl(e),Qu(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Ps,i=r.hmac||((D,E)=>Cb(e,D,E)),{Fp:o,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p}=pL(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*SI<o.ORDER;function x(D){let E=c>>ou;return D>E}function S(D,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${D}: out of range 1..Point.Fn.ORDER`);return E}function I(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function A(D,E){Pb(E);let U=p.signature,L=E==="compact"?U:E==="recovered"?U+1:void 0;return _e(D,L)}class O{r;s;recovery;constructor(E,U,L){if(this.r=S("r",E),this.s=S("s",U),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(E,U=g.format){A(E,U);let L;if(U==="der"){let{r:P,s:V}=ds.toSig(_e(E));return new O(P,V)}U==="recovered"&&(L=E[0],U="compact",E=E.subarray(1));let N=p.signature/2,R=E.subarray(0,N),C=E.subarray(N,N*2);return new O(s.fromBytes(R),s.fromBytes(C),L)}static fromHex(E,U){return this.fromBytes(Ls(E),U)}assertRecovery(){let{recovery:E}=this;if(E==null)throw new Error("invalid recovery id: must be present");return E}addRecoveryBit(E){return new O(this.r,this.s,E)}recoverPublicKey(E){let{r:U,s:L}=this,N=this.assertRecovery(),R=N===2||N===3?U+c:U;if(!o.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=o.toBytes(R),P=t.fromBytes(hr(TI((N&1)===0),C)),V=s.inv(R),J=M(_e(E,void 0,"msgHash")),z=s.create(-J*V),W=s.create(L*V),Y=t.BASE.multiplyUnsafe(z).add(P.multiplyUnsafe(W));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return x(this.s)}toBytes(E=g.format){if(Pb(E),E==="der")return Ls(ds.hexFromSig(this));let{r:U,s:L}=this,N=s.toBytes(U),R=s.toBytes(L);return E==="recovered"?(I(),hr(Uint8Array.of(this.assertRecovery()),N,R)):hr(N,R)}toHex(E){return Cs(this.toBytes(E))}}let T=r.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let U=No(E),L=E.length*8-a;return L>0?U>>BigInt(L):U},M=r.bits2int_modN||function(E){return s.create(T(E))},q=Zu(a);function j(D){return $v("num < 2^"+a,D,fo,q),s.toBytes(D)}function $(D,E){return _e(D,void 0,"message"),E?_e(e(D),void 0,"prehashed message"):D}function Z(D,E,U){let{lowS:L,prehash:N,extraEntropy:R}=Lb(U,g);D=$(D,N);let C=M(D),P=s.fromBytes(E);if(!s.isValidNot0(P))throw new Error("invalid private key");let V=[j(P),j(C)];if(R!=null&&R!==!1){let Y=R===!0?n(p.secretKey):R;V.push(_e(Y,void 0,"extraEntropy"))}let J=hr(...V),z=C;function W(Y){let X=T(Y);if(!s.isValidNot0(X))return;let ue=s.inv(X),ee=t.BASE.multiply(X).toAffine(),ce=s.create(ee.x);if(ce===fo)return;let Oe=s.create(ue*s.create(z+ce*P));if(Oe===fo)return;let Me=(ee.x===ce?0:2)|Number(ee.y&ou),Je=Oe;return L&&x(Oe)&&(Je=s.neg(Oe),Me^=1),new O(ce,Je,y?void 0:Me)}return{seed:J,k2sig:W}}function Q(D,E,U={}){let{seed:L,k2sig:N}=Z(D,E,U);return Hv(e.outputLen,s.BYTES,i)(L,N).toBytes(U.format)}function G(D,E,U,L={}){let{lowS:N,prehash:R,format:C}=Lb(L,g);if(U=_e(U,void 0,"publicKey"),E=$(E,R),!Yu(D)){let P=D instanceof O?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}A(D,C);try{let P=O.fromBytes(D,C),V=t.fromBytes(U);if(N&&P.hasHighS())return!1;let{r:J,s:z}=P,W=M(E),Y=s.inv(z),X=s.create(W*Y),ue=s.create(J*Y),ee=t.BASE.multiplyUnsafe(X).add(V.multiplyUnsafe(ue));return ee.is0()?!1:s.create(ee.x)===J}catch{return!1}}function _(D,E,U={}){let{prehash:L}=Lb(U,g);return E=$(E,L),O.fromBytes(D,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:h,lengths:p,Point:t,sign:Q,verify:G,recoverPublicKey:_,Signature:O,hash:e})}var Xp={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yL={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},gL=BigInt(0),Kb=BigInt(2);function mL(t){let e=Xp.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=Vr(d,r,e)*d%e,h=Vr(f,r,e)*d%e,p=Vr(h,Kb,e)*u%e,g=Vr(p,i,e)*p%e,y=Vr(g,o,e)*g%e,x=Vr(y,c,e)*y%e,S=Vr(x,a,e)*x%e,I=Vr(S,c,e)*y%e,A=Vr(I,r,e)*d%e,O=Vr(A,s,e)*g%e,T=Vr(O,n,e)*u%e,M=Vr(T,Kb,e);if(!Yp.eql(Yp.sqr(M),t))throw new Error("Cannot find square root");return M}var Yp=nu(Xp.p,{sqrt:mL}),vc=AI(Xp,{Fp:Yp,endo:yL}),ln=II(vc,Vp),BI={};function Jp(t,...e){let r=BI[t];if(r===void 0){let n=Vp(Kv(t));r=hr(n,n),BI[t]=r}return Vp(hr(r,...e))}var Hb=t=>t.toBytes(!0).slice(1),Vb=t=>t%Kb===gL;function $b(t){let{Fn:e,BASE:r}=vc,n=e.fromBytes(t),i=r.multiply(n);return{scalar:Vb(i.y)?n:e.neg(n),bytes:Hb(i)}}function UI(t){let e=Yp;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);Vb(i)||(i=e.neg(i));let o=vc.fromAffine({x:t,y:i});return o.assertValidity(),o}var pf=No;function OI(...t){return vc.Fn.create(pf(Jp("BIP0340/challenge",...t)))}function RI(t){return $b(t).bytes}function wL(t,e,r=Ps(32)){let{Fn:n}=vc,i=_e(t,void 0,"message"),{bytes:o,scalar:s}=$b(e),c=_e(r,32,"auxRand"),a=n.toBytes(s^pf(Jp("BIP0340/aux",c))),u=Jp("BIP0340/nonce",a,o,i),{bytes:d,scalar:f}=$b(u),h=OI(d,o,i),p=new Uint8Array(64);if(p.set(d,0),p.set(n.toBytes(n.create(f+h*s)),32),!DI(p,i,o))throw new Error("sign: Invalid signature produced");return p}function DI(t,e,r){let{Fp:n,Fn:i,BASE:o}=vc,s=_e(t,64,"signature"),c=_e(e,void 0,"message"),a=_e(r,32,"publicKey");try{let u=UI(pf(a)),d=pf(s.subarray(0,32));if(!n.isValidNot0(d))return!1;let f=pf(s.subarray(32,64));if(!i.isValidNot0(f))return!1;let h=OI(i.toBytes(d),Hb(u),c),p=o.multiplyUnsafe(f).add(u.multiplyUnsafe(i.neg(h))),{x:g,y}=p.toAffine();return!(p.is0()||!Vb(y)||g!==d)}catch{return!1}}var Zp=(()=>{let r=(n=Ps(48))=>Fp(n,Xp.n);return{keygen:Wp(r,RI),getPublicKey:RI,sign:wL,verify:DI,Point:vc,utils:{randomSecretKey:r,taggedHash:Jp,lift_x:UI,pointToBytes:Hb},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:32*2,seed:48}}})();l();function bL(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function NI(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function qb(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function CI(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Fb(t){if(!Array.isArray(t))throw new Error("array expected")}function LI(t,e){if(!NI(!0,e))throw new Error(`${t}: array of strings expected`)}function xL(t,e){if(!NI(!1,e))throw new Error(`${t}: array of numbers expected`)}function EL(...t){let e=o=>o,r=(o,s)=>c=>o(s(c)),n=t.map(o=>o.encode).reduceRight(r,e),i=t.map(o=>o.decode).reduce(r,e);return{encode:n,decode:i}}function vL(t){let e=typeof t=="string"?t.split(""):t,r=e.length;LI("alphabet",e);let n=new Map(e.map((i,o)=>[i,o]));return{encode:i=>(Fb(i),i.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);return e[o]})),decode:i=>(Fb(i),i.map(o=>{qb("alphabet.decode",o);let s=n.get(o);if(s===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);return s}))}}function SL(t=""){return qb("join",t),{encode:e=>(LI("join.decode",e),e.join(t)),decode:e=>(qb("join.decode",e),e.split(t))}}function kI(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Fb(t),!t.length)return[];let n=0,i=[],o=Array.from(t,c=>{if(CI(c),c<0||c>=e)throw new Error(`invalid integer: ${c}`);return c}),s=o.length;for(;;){let c=0,a=!0;for(let u=n;u<s;u++){let d=o[u],f=e*c,h=f+d;if(!Number.isSafeInteger(h)||f/e!==c||h-d!==f)throw new Error("convertRadix: carry overflow");let p=h/r;c=h%r;let g=Math.floor(p);if(o[u]=g,!Number.isSafeInteger(g)||g*r+c!==h)throw new Error("convertRadix: carry overflow");if(a)g?a=!1:n=u;else continue}if(i.push(c),a)break}for(let c=0;c<t.length-1&&t[c]===0;c++)i.push(0);return i.reverse()}function AL(t){CI(t);let e=2**8;return{encode:r=>{if(!bL(r))throw new Error("radix.encode input should be Uint8Array");return kI(Array.from(r),e,t)},decode:r=>(xL("radix.decode",r),Uint8Array.from(kI(r,t,e)))}}var TL=t=>EL(AL(58),vL(t),SL("")),su=TL("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var PI=new Uint8Array([231,1]),ft=class t{#e;#t={prefix:PI,key:[],encoded:""};constructor(e){let r=e instanceof Uint8Array?e:Ir(e);if(!r||r.length!==33)throw new Os("Invalid argument: byte length must be 33 (compressed)","CONSTRUCTOR_ERROR",{keyBytes:r});if(!ln.utils.isValidPublicKey(r))throw new Os("Invalid argument: not a valid secp256k1 compressed point","CONSTRUCTOR_ERROR",{keyBytes:r});this.#e=new Uint8Array(r),this.#t.encoded=this.encode(),this.#t.key=[...this.#t.prefix,...this.compressed]}get compressed(){return new Uint8Array(this.#e)}get uncompressed(){return ln.Point.fromBytes(this.compressed).toBytes(!1)}get xOnly(){return this.compressed.slice(1)}get parity(){let e=this.compressed[0];if(![2,3].includes(e))throw new Os("Invalid state: parity byte must be 2 or 3","PARITY_ERROR",{parity:e});return e}get isEven(){return this.parity===2}get x(){return this.compressed.slice(1,33)}get y(){return this.uncompressed.slice(33,65)}get multibase(){return{prefix:new Uint8Array(this.#t.prefix),key:[...this.#t.key],encoded:this.#t.encoded}}get hex(){return Mt(this.compressed)}get point(){return{x:this.x,y:this.y}}bip340(){return this.xOnly}decode(){return su.decode(this.multibase.encoded.slice(1))}encode(){let e=Array.from(this.compressed),r=Array.from(PI);return r.push(...e),"z"+su.encode(Uint8Array.from(r))}verify(e,r,n){if(n??={scheme:"schnorr"},n.scheme==="ecdsa")return ln.verify(e,r,this.compressed);if(n.scheme==="schnorr")return Zp.verify(e,r,this.x);throw new Os(`Invalid scheme: ${n.scheme}.`,"VERIFY_SIGNATURE_ERROR",n)}equals(e){return ra(this.compressed,e.compressed)}toJSON(){return{hex:this.hex,multibase:this.multibase,point:{x:Array.from(this.x),y:Array.from(this.y),parity:this.parity}}}static isValid(e){try{return new t(e),!0}catch{return!1}}static fromJSON(e){return new t(Uint8Array.from([e.point.parity,...e.point.x]))}};l();var MI=new Uint8Array([129,38]),_L=Mt(ke(MI)),qr=class t{#e;#t;#n;constructor(e){let r=e instanceof Uint8Array,n=typeof e=="bigint";if(!r&&!n)throw new Gn("Invalid entropy: must be a valid byte array (32) or bigint","CONSTRUCTOR_ERROR");if(r&&e.length===32&&(this.#e=new Uint8Array(e),this.#t=t.toSecret(this.#e)),n&&e>=1n&&e<ln.Point.Fn.ORDER&&(this.#e=t.toBytes(e),this.#t=e),!this.#e||this.#e.length!==32)throw new Gn("Invalid bytes: must be a valid 32-byte secret key","CONSTRUCTOR_ERROR");if(!this.#t||this.#t<1n||this.#t>=ln.Point.Fn.ORDER)throw new Gn("Invalid seed: must be valid bigint","CONSTRUCTOR_ERROR");this.#n=this.encode()}destroy(){this.#e&&this.#e.fill(0),this.#t=void 0,this.#n=""}get bytes(){return new Uint8Array(this.#e)}get seed(){return BigInt(this.#t)}get hex(){return Mt(this.bytes)}get multibase(){return this.#n}encode(){let e=Array.from(this.bytes),r=Array.from(MI);return r.push(...e),"z"+su.encode(Uint8Array.from(r))}equals(e){return ra(this.bytes,e.bytes)}computePublicKey(){return new ft(ln.getPublicKey(this.bytes))}toJSON(){return{type:"Secp256k1SecretKey"}}exportJSON(){return{bytes:Array.from(this.bytes),seed:this.seed.toString(),hex:this.hex}}toString(){return"[Secp256k1SecretKey]"}[Symbol.for("nodejs.util.inspect.custom")](){return"[Secp256k1SecretKey]"}isValid(){return ln.utils.isValidSecretKey(this.bytes)}hasValidPublicKey(){try{return this.computePublicKey(),!0}catch{return!1}}sign(e,r){if(r??={scheme:"schnorr"},r.scheme==="ecdsa")return ln.sign(e,this.bytes);if(r.scheme==="schnorr")return Zp.sign(e,this.bytes);throw new Gn(`Invalid scheme: ${r.scheme}.`,"SIGN_ERROR",r)}static decode(e){let r=su.decode(e.slice(1));if(r.length!==34)throw new Gn("Invalid argument: must be 34 byte secretKeyMultibase","DECODE_MULTIBASE_ERROR");let n=r.slice(0,2);if(Mt(ke(n))!==_L)throw new Gn(`Invalid prefix: malformed multibase prefix ${n}`,"DECODE_MULTIBASE_ERROR");return r}static fromJSON(e){return new t(new Uint8Array(e.bytes))}static toSecret(e){return e.reduce((r,n)=>r<<8n|BigInt(n),0n)}static toBytes(e){let r=Uint8Array.from({length:32},(n,i)=>Number(e>>BigInt(8*(31-i))&BigInt(255)));if(!ln.utils.isValidSecretKey(r))throw new Gn("Invalid secret key: secret out of valid range","SET_PRIVATE_KEY_ERROR");return new Uint8Array(r)}static fromBigInt(e){return new t(t.toBytes(e))}static random(){let e;do e=Br(32);while(!ln.utils.isValidSecretKey(e));return e}static generate(){let e=this.random();return new t(e)}static getPublicKey(e){return new t(e).computePublicKey()}};var lo=class t{#e;#t;constructor(e={}){if(!e.publicKey&&!e.secretKey)throw new xn("Argument missing: must at least provide a publicKey","CONSTRUCTOR_ERROR");if(e.secretKey instanceof Uint8Array?this.#e=new qr(e.secretKey):e.secretKey instanceof qr&&(this.#e=e.secretKey),e.publicKey instanceof ft?this.#t=e.publicKey:e.publicKey instanceof Uint8Array?this.#t=new ft(e.publicKey):this.#t=this.#e.computePublicKey(),this.#e&&e.publicKey){let r=this.#e.computePublicKey();if(!this.#t.equals(r))throw new xn("Public key does not match secret key","CONSTRUCTOR_ERROR")}}get secretKey(){if(!this.#e)throw new xn("Secret key not available","SECRET_KEY_ERROR");if(!this.#e.isValid())throw new xn("Secret key is not valid","SECRET_KEY_ERROR");return this.#e}set publicKey(e){if(this.#e){let r=this.#e.computePublicKey();if(!e.equals(r))throw new xn("Public key does not match secret key","PUBLIC_KEY_ERROR")}this.#t=e}get publicKey(){return this.#t}get hasSecretKey(){return!!this.#e}get raw(){return{public:this.publicKey.compressed,secret:this.#e?this.#e.bytes:void 0}}get hex(){return{public:this.publicKey.hex,secret:this.#e?this.#e.hex:void 0}}get multibase(){return{publicKeyMultibase:this.#t.multibase.encoded,secretKeyMultibase:this.#e?this.#e.multibase:""}}toJSON(){return{publicKey:this.publicKey.toJSON()}}exportJSON(){if(!this.#e)throw new xn("Cannot export: secret key required. Use publicKey.toJSON() for public-key-only pairs.","SERIALIZE_ERROR");return{secretKey:this.#e.exportJSON(),publicKey:this.publicKey.toJSON()}}[Symbol.for("nodejs.util.inspect.custom")](){return`[SchnorrKeyPair ${this.publicKey.hex}]`}static fromJSON(e){return new t({secretKey:qr.fromJSON(e.secretKey),publicKey:ft.fromJSON(e.publicKey)})}static fromSecret(e){let r=typeof e=="string"?Ir(e):e;if(r.length!==32)throw new xn("Invalid arg: must be 32 byte secret key","FROM_SECRET_KEY_ERROR");let n=new qr(r),i=n.computePublicKey();return new t({secretKey:n,publicKey:i})}static fromBigInt(e){let r=qr.fromBigInt(e),n=r.computePublicKey();return new t({secretKey:r,publicKey:n})}static toHex(e){return Mt(e)}static equals(e,r){return e.publicKey.equals(r.publicKey)}static generate(){let e=qr.random(),r=new qr(e),n=r.computePublicKey();return new t({secretKey:r,publicKey:n})}};l();l();l();l();var IL=["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"],cu="Multikey",au="zQ3s",dr="did:btcr2:_",nre="",BL=/did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;function RL(t){if(!st.isDidVerificationMethod(t))return!1;let{type:e,publicKeyMultibase:r}=t;return e===cu&&typeof r=="string"&&r.startsWith(au)}var jb=class{id;type;controller;publicKeyMultibase;secretKeyMultibase;constructor({id:e,type:r,controller:n,publicKeyMultibase:i,secretKeyMultibase:o}){if(r!==cu)throw new Ve(`Invalid verification method: type must be "${cu}"`,qe,{id:e,type:r});if(typeof i!="string"||!i.startsWith(au))throw new Ve(`Invalid verification method: publicKeyMultibase must start with "${au}"`,qe,{id:e,publicKeyMultibase:i});this.id=e,this.type=r,this.controller=n,this.publicKeyMultibase=i,this.secretKeyMultibase=o,o||delete this.secretKeyMultibase}},hn=class t{id;"@context"=["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"];verificationMethod;authentication;assertionMethod;capabilityInvocation;capabilityDelegation;service;deactivated;constructor(e){if(!e.id)throw new Ve("DID Document must have an id",qe,e);let r=e.id.includes("k1")?Qr.KEY:Qr.EXTERNAL,n=e.id===dr,{id:i,verificationMethod:o,service:s}=e;if(!n){if(!t.isValidId(i))throw new Ve(`Invalid id: ${i}`,qe,e);if(!t.isValidVerificationMethods(o))throw new Ve("Invalid verificationMethod: "+o,qe,e);if(!t.isValidServices(s))throw new Ve("Invalid service: "+s,qe,e)}if(this.id=e.id,this.verificationMethod=e.verificationMethod||[],this.service=e.service||[],this["@context"]=e["@context"]||["https://www.w3.org/ns/did/v1.1","https://btcr2.dev/context/v1"],r===Qr.KEY){let c=`${this.id}#initialKey`;this.authentication=e.authentication||[c],this.assertionMethod=e.assertionMethod||[c],this.capabilityInvocation=e.capabilityInvocation||[c],this.capabilityDelegation=e.capabilityDelegation||[c]}else this.authentication=e.authentication,this.assertionMethod=e.assertionMethod,this.capabilityInvocation=e.capabilityInvocation,this.capabilityDelegation=e.capabilityDelegation;t.sanitize(this),n?this.validateGenesis():t.validate(this)}toJSON(){return{id:this.id,"@context":this["@context"],verificationMethod:this.verificationMethod,authentication:this.authentication,assertionMethod:this.assertionMethod,capabilityInvocation:this.capabilityInvocation,capabilityDelegation:this.capabilityDelegation,service:this.service,deactivated:this.deactivated}}static fromKeyIdentifier(e,r,n){e=e.includes("#")?e:`${e}#initialKey`;let i={id:e,verificationMethod:[new jb({id:e,type:"Multikey",controller:e,publicKeyMultibase:r})],service:n};return new t(i)}static fromExternalIdentifier(e){return new t(e)}static sanitize(e){for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}static isValid(e){if(!this.isValidContext(e?.["@context"]))throw new Ve('Invalid "@context"',qe,e);if(!this.isValidId(e?.id))throw new Ve('Invalid "id"',qe,e);if(!this.isValidVerificationMethods(e?.verificationMethod))throw new Ve('Invalid "verificationMethod"',qe,e);if(!this.isValidServices(e?.service))throw new Ve('Invalid "service"',qe,e);if(!this.isValidVerificationRelationships(e))throw new Ve("Invalid verification relationships",qe,e);return!0}static isValidContext(e){return!Array.isArray(e)||e.length===0?!1:IL.every(r=>e.includes(r))}static isValidId(e){if(typeof e!="string")return!1;try{return vr.decode(e),!0}catch{return!1}}static isValidVerificationMethods(e){return Array.isArray(e)&&e.every(RL)}static isValidServices(e){return Array.isArray(e)&&e.every(o_)}static isValidVerificationRelationships(e){let r=["authentication","assertionMethod","capabilityInvocation","capabilityDelegation"],n=Object.keys(e);return r.filter(o=>n.includes(o)).every(o=>{let s=e[o];return s&&Array.isArray(s)&&s.every(c=>typeof c=="string"||st.isDidVerificationMethod(c))})}static validate(e){return e.id===dr?e.validateGenesis():t.isValid(e),e}validateGenesis(){if(this.id!==dr)throw new Ve("Invalid GenesisDocument ID",qe,this);if(!this.verificationMethod.every(e=>e.id.includes(dr)&&e.controller===dr))throw new Ve("Invalid GenesisDocument verificationMethod",qe,this);if(!this.service.every(e=>e.id.includes(dr)))throw new Ve("Invalid GenesisDocument service",qe,this);if(!t.isValidVerificationRelationships(this))throw new Ve("Invalid GenesisDocument assertionMethod",qe,this);return!0}toIntermediate(){if(this.id.includes("k1"))throw new Ve("Cannot convert a key identifier to an intermediate document",qe,this);return new yf(this)}},yf=class t extends hn{constructor(e){super(e)}toDidDocument(e){let r=JSON.stringify(this).replaceAll(dr,e),n=JSON.parse(r);return new hn(n)}static fromDidDocument(e){let r=ks.cloneReplace(e,BL,dr);return new t(r)}static create(e,r,n){return new t({id:dr,...r,verificationMethod:e,service:n})}static fromPublicKey(e,r){let n=new ft(e),i=dr,o=Ni(n.compressed,Do(r)).address,s=[{id:`${i}#service-0`,serviceEndpoint:`bitcoin:${o}`,type:"SingletonBeacon"}],c={authentication:[`${i}#key-0`],assertionMethod:[`${i}#key-0`],capabilityInvocation:[`${i}#key-0`],capabilityDelegation:[`${i}#key-0`]},a=[{id:`${i}#key-0`,type:"Multikey",controller:i,publicKeyMultibase:n.multibase.encoded}];return t.create(a,c,s)}static fromJSON(e){return new t(e)}static toGenesisBytes(e){return Uo(Kt(e))}};var KI="did:btcr2:",vr=class t{static encode(e,r){let{idType:n,version:i=1,network:o="bitcoin"}=r;if(!(n in Qr))throw new ut('Expected "idType" to be "KEY" or "EXTERNAL"',pt,{idType:n});if(i!==1)throw new ut('Expected "version" to be 1',pt,{version:i});if(typeof o!="string")throw new ut('Expected "network" to be a known network name',pt,{network:o});let s=ea[o];if(s===void 0)throw new ut('Invalid "network" name',pt,{network:o});if(n==="KEY")try{new ft(e)}catch{throw new ut('Expected "genesisBytes" to be a valid compressed secp256k1 public key',pt,{genesisBytes:e})}else if(e.length!==32)throw new ut('Expected "genesisBytes" to be a 32-byte hash for EXTERNAL identifiers',pt,{genesisBytes:e});let c=n==="KEY"?"k":"x",a=i-1<<4|s,u=new Uint8Array([a,...e]);return`${KI}${As.encodeFromBytes(c,u)}`}static decode(e){let r=e.split(":");if(r.length!==3)throw new ut(`Invalid did: ${e}`,pt,{identifier:e});let[n,i,o]=r;if(n!=="did")throw new ut(`Invalid did: ${e}`,pt,{identifier:e});if(i!=="btcr2")throw new ut(`Invalid did method: ${i}`,wl,{identifier:e});if(!o)throw new ut(`Invalid method-specific id: ${e}`,pt,{identifier:e});if(o!==o.toLowerCase())throw new ut(`Invalid method-specific id (must be lowercase): ${e}`,pt,{identifier:e});let s,c;try{({prefix:s,bytes:c}=As.decodeToBytes(o))}catch(g){let y=g instanceof Error?g.message:String(g);throw new ut(`Invalid method-specific id (Bech32m decoding failed: ${y}): ${e}`,pt,{identifier:e,reason:y})}if(!["x","k"].includes(s))throw new ut(`Invalid hrp: ${s}`,pt,{identifier:e});if(!c||c.length<1)throw new ut(`Failed to decode id: ${o}`,pt,{identifier:e});let a=s==="k"?"KEY":"EXTERNAL",u=c[0]>>>4;if(u!==0)throw new ut(`Invalid btcr2_version (expected 0): ${u}`,pt,{identifier:e});let d=1,f=c[0]&15,h=ea[f];if(typeof h!="string"){let g=f>=12?"custom network not supported":"reserved";throw new ut(`Invalid network (${g}): ${f}`,pt,{identifier:e})}let p=c.slice(1);if(a==="KEY")try{new ft(p)}catch{throw new ut(`Invalid genesisBytes: ${p}`,pt,{identifier:e})}else if(p.length!==32)throw new ut(`Invalid genesisBytes: ${p}`,pt,{identifier:e});return{idType:a,hrp:s,version:d,network:h,genesisBytes:p}}static validate(e,r={}){let n=[],i=(x,S)=>{n.push(S===void 0?{name:x,ok:!0}:{name:x,ok:!0,detail:S})},o=(x,S,I={})=>(n.push({name:x,ok:!1,detail:S}),{did:e,valid:!1,...I,checks:n});if(typeof e!="string")return o("prefix","The identifier is not a string.");let s=e.split(":");if(s.length!==3||s[0]!=="did"||s[1]!=="btcr2")return o("prefix",`The identifier must be "${KI}" followed by the method-specific id.`);let c=s[2];if(c.length===0)return o("prefix","The method-specific id is empty.");if(i("prefix"),c!==c.toLowerCase())return o("lowercase","The method-specific id must be lowercase.");i("lowercase");let a,u;try{({prefix:a,bytes:u}=As.decodeToBytes(c))}catch(x){return o("bech32m",`Bech32m decoding failed: ${x instanceof Error?x.message:String(x)}`)}if(a!=="k"&&a!=="x")return o("bech32m",`The hrp must be "k" or "x", got "${a}".`);let d=a==="k"?Qr.KEY:Qr.EXTERNAL;if(u.length<1)return o("bech32m","The data bytes are empty.",{idType:d});i("bech32m",`hrp "${a}", ${u.length} data bytes`);let f=u[0]>>>4;if(f!==0)return o("version",`btcr2_version must be 0, got ${f}.`,{idType:d});i("version","btcr2_version 0 (version_number 1)");let h=u[0]&15,p=ea[h];if(typeof p!="string"){let x=h>=12?`network_value ${h} is a custom network, not supported by this implementation.`:`network_value ${h} is reserved.`;return o("network",x,{idType:d})}i("network",`network_value ${h} (${p})`);let g=u.slice(1);if(d===Qr.KEY){try{new ft(g)}catch{return o("genesisBytes",`Expected a 33-byte SEC compressed secp256k1 public key, got ${g.length} bytes that are not a valid key.`,{idType:d,network:p})}i("genesisBytes","33-byte SEC compressed secp256k1 public key")}else{if(g.length!==32)return o("genesisBytes",`Expected a 32-byte SHA-256 hash, got ${g.length} bytes.`,{idType:d,network:p});i("genesisBytes","32-byte SHA-256 hash")}let y;try{y=t.encode(g,{idType:d,version:1,network:p})}catch(x){return o("roundTrip",`Re-encoding failed: ${x instanceof Error?x.message:String(x)}`,{idType:d,network:p})}if(y!==e)return o("roundTrip",`Re-encoding produced "${y}".`,{idType:d,network:p});if(i("roundTrip"),r.genesisBytes!==void 0){let x=r.genesisBytes;if(!(x instanceof Uint8Array))return o("genesisBytesMatch","The supplied genesis bytes are not a Uint8Array.",{idType:d,network:p});if(x.length!==g.length)return o("genesisBytesMatch",`Expected ${g.length} genesis bytes for a ${d} identifier, got ${x.length}.`,{idType:d,network:p});if(!bo(x,g))return o("genesisBytesMatch",`The supplied genesis bytes ${ve.encode(x)} do not equal the genesis bytes of the identifier ${ve.encode(g)}.`,{idType:d,network:p});i("genesisBytesMatch","The supplied genesis bytes equal the genesis bytes of the identifier.")}if(r.genesisDocument!==void 0){let x=r.genesisDocument;if(d===Qr.KEY)return o("genesisDocument","A KEY identifier has no genesis document.",{idType:d,network:p});let S=x.id;if(S!==dr)return o("genesisDocument",`The genesis document id must be "${dr}", got ${JSON.stringify(S)}.`,{idType:d,network:p});try{yf.fromJSON(x)}catch(A){return o("genesisDocument",`Invalid genesis document: ${A instanceof Error?A.message:String(A)}`,{idType:d,network:p})}let I=Oo(x);if(!bo(I,g))return o("genesisDocument",`The genesis document hash ${ve.encode(I)} does not equal the genesis bytes ${ve.encode(g)}.`,{idType:d,network:p});i("genesisDocument","The genesis document hashes to the genesis bytes.")}return{did:e,valid:!0,idType:d,network:p,checks:n}}static generate(){let e=lo.generate(),r=this.encode(e.publicKey.compressed,{idType:"KEY",version:1,network:"regtest"});return{keyPair:e.exportJSON(),did:r}}static getPublicKey(e){let{idType:r,genesisBytes:n}=t.decode(e);if(r!=="KEY")throw new ut(`Cannot extract public key from EXTERNAL DID: ${e}. EXTERNAL DIDs encode a document hash, not a public key.`,pt,{did:e,idType:r});return new ft(n)}static isValid(e){try{return this.decode(e),!0}catch{return!1}}};var pn=class{static parseBitcoinAddress(e){if(!e.startsWith("bitcoin:"))throw new be("Invalid Bitcoin URI format","BEACON_SERVICE_ERROR",{uri:e});return e.replace("bitcoin:","").split("?")[0]}static isBeaconService(e){return!(!st.isDidService(e)||!["SingletonBeacon","CASBeacon","SMTBeacon"].includes(e.type)||[e.serviceEndpoint].flat().some(r=>typeof r=="string"&&!r.startsWith("bitcoin:")))}static getBeaconServices(e){return e.service.filter(this.isBeaconService)??[]}static createBeaconServices(e,r){try{return["p2pkh","p2wpkh","p2tr"].map(i=>this.createBeaconService(e,i,r))}catch(n){throw new nr("Failed to create beacon services: "+n.message,"BEACON_SERVICE_ERROR",{did:e,beaconType:r})}}static createBeaconService(e,r,n){try{let i=vr.decode(e),o=Do(i.network),s=i.genesisBytes,c=`${e}#initial${r.toUpperCase()}`,u=`bitcoin:${r==="p2tr"?Is(s.slice(1,33),void 0,o).address:r==="p2wpkh"?_s(s,o).address:Ni(s,o).address}`;return{id:c,type:n,serviceEndpoint:u}}catch(i){throw new nr("Failed to create beacon service: "+i.message,"BEACON_SERVICE_ERROR",{did:e,beaconType:n})}}static generateBeaconServices({id:e,publicKey:r,network:n,beaconType:i}){try{let o=Ni(r,n).address,s=_s(r,n).address,c=Is(r.slice(1,33),void 0,n).address;if(!o||!s||!c)throw new kt("Failed to generate bitcoin addresses");return[{id:`${e}#initialP2PKH`,type:i,serviceEndpoint:`bitcoin:${o}`},{id:`${e}#initialP2WPKH`,type:i,serviceEndpoint:`bitcoin:${s}`},{id:`${e}#initialP2TR`,type:i,serviceEndpoint:`bitcoin:${c}`}]}catch(o){throw new nr("Failed to create beacon services: "+o.message,"BEACON_SERVICE_ERROR",{id:e,publicKey:r,network:n,beaconType:i})}}static parseBeaconServiceEndpoint(e){return{...e,serviceEndpoint:e.serviceEndpoint.replace("bitcoin:","")}}static getBeaconServiceIds(e){return this.getBeaconServices(e).map(r=>r.id)}};var UL=/^6a20([0-9a-f]{64})$/i;function $I(t){if(!t)return null;let e=UL.exec(t.trim());return e?e[1].toLowerCase():null}var HI=class t{static async spendsFromAddress(e,r,n){for(let i of e.vin??[]){if(i.is_coinbase)continue;let o=i.prevout;if(!o&&i.txid&&(o=(await n.rest.transaction.get(i.txid))?.vout?.[i.vout]),o?.scriptpubkey_address===r)return!0}return!1}static async indexer(e,r){let n=new Map,i=await r.rest.block.count(),o=new Map;for(let s of e){n.set(s,[]);let c=pn.parseBitcoinAddress(s.serviceEndpoint),a=await r.rest.address.getTxs(c);if(!(!a||!a.length))for(let u of a){let d=u.status;if(d.confirmed!==!0)continue;let f=u.vout.slice(-1)[0];if(!f)continue;let h=$I(f.scriptpubkey);if(!h||!await t.spendsFromAddress(u,c,r))continue;let p=i-d.block_height+1,g=await t.mediantime(d.block_hash,r,o);n.get(s)?.push({tx:u,signalBytes:h,blockMetadata:{confirmations:p,height:d.block_height,time:d.block_time,mediantime:g}})}}return n}static async mediantime(e,r,n){let i=n.get(e);if(i!==void 0)return i;let o=await r.rest.block.get({blockhash:e}),s=o?.mediantime;if(typeof s!="number"||!Number.isFinite(s))throw new le(`Block ${e} has no mediantime in the block record of the Bitcoin REST backend.`,bl,{blockhash:e,block:o});return n.set(e,s),s}static async fullnode(e,r){let n=new Map;for(let u of e)n.set(u,[]);let i=r.rpc;if(!i)throw new le("RPC connection is not available","RPC_CONNECTION_ERROR",r);let o=await i.getBlockCount(),s=new Map(e.map(u=>[pn.parseBitcoinAddress(u.serviceEndpoint),u])),c=0,a=await r.rpc.getBlock({height:c});for(console.info("Searching for beacon signals, please wait ...");a.height<=o;){for(let u of a.tx){if(u.txid===O0)continue;let d=u.vout.slice(-1)[0];if(!d)continue;let f=$I(d.scriptPubKey?.hex);if(!f)continue;let h=new Set;for(let p of u.vin){if(p.coinbase||p.txinwitness&&p.txinwitness.length===1&&p.txinwitness[0]===U0||!p.txid||p.vout===void 0)continue;let g=await i.getRawTransaction(p.txid,2);if(!g.vout[p.vout])continue;let y=g.vout[p.vout].scriptPubKey;if(!y.address)continue;let x=s.get(y.address);!x||h.has(x)||(h.add(x),console.info(`Tx ${u.txid} contains beacon address ${y.address}`),n.get(x)?.push({tx:u,signalBytes:f,blockMetadata:{height:a.height,time:a.time,mediantime:a.mediantime,confirmations:a.confirmations}}))}}if(c+=1,c>o){console.info(`Chain tip reached ${c}, breaking ...`);break}a=await i.getBlock({height:c})}return n}};l();var uu=Object.freeze(["https://w3id.org/json-ld-patch/v1","https://w3id.org/zcap/v1","https://w3id.org/security/data-integrity/v2","https://btcr2.dev/context/v1"]);function Wb(t,e=uu){return Array.isArray(t)&&t.length===e.length&&t.every((r,n)=>r===e[n])}var VI=Object.freeze({op:"add",path:"/deactivated",value:!0});l();l();l();l();l();l();var Bre=new Uint8Array(0);function qI(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}l();function OL(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function f(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 y=0,x=0,S=0,I=g.length;S!==I&&g[S]===0;)S++,y++;for(var A=(I-S)*d+1>>>0,O=new Uint8Array(A);S!==I;){for(var T=g[S],M=0,q=A-1;(T!==0||M<x)&&q!==-1;q--,M++)T+=256*O[q]>>>0,O[q]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");x=M,S++}for(var j=A-x;j!==A&&O[j]===0;)j++;for(var $=a.repeat(y);j<A;++j)$+=t.charAt(O[j]);return $}function h(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var x=0,S=0;g[y]===a;)x++,y++;for(var I=(g.length-y)*u+1>>>0,A=new Uint8Array(I);g[y];){var O=r[g.charCodeAt(y)];if(O===255)return;for(var T=0,M=I-1;(O!==0||T<S)&&M!==-1;M--,T++)O+=c*A[M]>>>0,A[M]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");S=T,y++}if(g[y]!==" "){for(var q=I-S;q!==I&&A[q]===0;)q++;for(var j=new Uint8Array(x+(I-q)),$=x;q!==I;)j[$++]=A[q++];return j}}}function p(g){var y=h(g);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var DL=OL,kL=DL,FI=kL;var Gb=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},zb=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return jI(this,e)}},Yb=class{decoders;constructor(e){this.decoders=e}or(e){return jI(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jI(t,e){return new Yb({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Jb=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Gb(e,r,n),this.decoder=new zb(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function NL({name:t,prefix:e,encode:r,decode:n}){return new Jb(t,e,r,n)}function Xb({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=FI(r,t);return NL({prefix:e,name:t,encode:n,decode:o=>qI(i(o))})}var gf=Xb({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mre=Xb({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});l();function WI(t){return t===void 0?[]:Array.isArray(t)?t:[t]}var du=class{cryptosuite;constructor(e){this.cryptosuite=e}addProof(e,r){let n=this.cryptosuite.createProof(e,r);if(!n.type||!n.verificationMethod||!n.proofPurpose)throw new bn("Invalid proof: missing proof.type, proof.verificationMethod and/or proof.proofPurpose",Ro,{config:r,proof:n});if(r.domain&&n.domain!==r.domain)throw new bn("Domain mismatch: proof.domain !== config.domain",Ro,{config:r,proof:n});if(r.challenge&&n.challenge!==r.challenge)throw new bn("Challenge mismatch options and challenge passed",Ro,{config:r,proof:n});let i=e;return i.proof=n,i}verifyProof(e,r,n,i,o){let s=JSON.parse(e),c=s.proof;if(!c.type||!c.verificationMethod||!c.proofPurpose)throw new bn("Invalid proof: missing proof.type, proof.verificationMethod and/or proof.proofPurpose",Ci,s);if(r&&r!==c.proofPurpose)throw new bn("Proof purpose mismatch: proof.proofPurpose !== expectedPurpose",Ci,{proof:c,expectedPurpose:r});if(o&&o!==c.challenge)throw new bn("Challenge mismatch: proof.challenge !== expectedChallenge","INVALID_CHALLENGE_ERROR",{proof:c,expectedChallenge:o});if(i){let u=WI(i),d=WI(c.domain);if(u.length!==d.length)throw new bn("Domain mismatch: expectedDomain length does not match proof.domain length",Ci,{proof:c,expectedDomain:i});if(!u.every(f=>d.includes(f))||!d.every(f=>u.includes(f)))throw new bn("Domain mismatch: expectedDomain and proof.domain do not match",Ci,{proof:c,expectedDomain:i})}let a=this.cryptosuite.verifyProof(s);return a.mediaType=n,a}};var fu=class{type="DataIntegrityProof";cryptosuite="bip340-jcs-2025";multikey;constructor(e){this.multikey=e}toDataIntegrityProof(){return new du(this)}#e(){return{type:this.type,cryptosuite:this.cryptosuite,verificationMethod:this.multikey.fullId()}}createProof(e,r){r["@context"]=e["@context"]??r["@context"];let n=this.proofConfiguration(r),i=this.transformDocument(e,r),o=this.generateHash(n,i),s=this.proofSerialization(o,r),c=r;return c.proofValue=gf.encode(s),c.cryptosuite=this.cryptosuite,c.type=this.type,c}verifyProof(e){let{proof:r,...n}=e,{proofValue:i,...o}=r,s=this.transformDocument(n,o),c=this.proofConfiguration(o),a=this.generateHash(c,s),u=gf.decode(e.proof.proofValue),d=this.proofVerification(a,u,o);return{verified:d,verifiedDocument:d?e:void 0}}transformDocument(e,r){if(r.type!==this.type)throw new be("Type mismatch: config.type !== this.type",Ci,{config:r,suite:this.#e()});if(r.cryptosuite!==this.cryptosuite)throw new be("Cryptosuite mismatch: config.cryptosuite !== this.cryptosuite",Ci,{config:r,suite:this.#e()});return Kt(e)}generateHash(e,r){let n=ke(Es(e)),i=ke(Es(r)),o=ht(n,i);return ke(o)}proofConfiguration(e){if(e.type!==this.type)throw new Bo("Type mismatch: config.type !== this.type",Ro,{config:e,suite:this.#e()});if(e.cryptosuite!==this.cryptosuite)throw new Bo("Cryptosuite mismatch: config.cryptosuite !== this.cryptosuite",Ro,{config:e,suite:this.#e()});if(e.created&&!Li.isValidXsdDateTime(e.created))throw new Bo('Invalid config: "created" must be a valid XMLSchema DateTime string',Ro,e);return Kt(e)}proofSerialization(e,r){if(r.verificationMethod!==this.multikey.fullId())throw new Bo("Id mismatch: config.verificationMethod !== this.multikey.fullId()",pv,{config:r,suite:this.#e()});return this.multikey.sign(e)}proofVerification(e,r,n){if(n.verificationMethod!==this.multikey.fullId())throw new Bo("Id mismatch: config.verificationMethod !== this.multikey.fullId()",Ci,{config:n,suite:this.#e()});return this.multikey.verify(r,e)}};l();l();l();var ho=class t{static type="Multikey";id;controller;#e;#t;constructor({id:e,controller:r,keyPair:n,externalSigner:i}){if(!n)throw new En('Argument missing: "keyPair" required',"CONSTRUCTOR_ERROR");if(!n.publicKey)throw new En('Argument missing: "keyPair" must contain a "publicKey"',"CONSTRUCTOR_ERROR");if(i){let o=i.publicKey,s=n.publicKey.compressed;if(o.length!==s.length||!o.every((c,a)=>c===s[a]))throw new En("externalSigner.publicKey does not match keyPair.publicKey.compressed","CONSTRUCTOR_ERROR")}this.id=e,this.controller=r,this.#e=n,this.#t=i}get keyPair(){return this.#e}get publicKey(){return this.#e.publicKey}get secretKey(){try{return this.#e.secretKey}catch{throw new En("Cannot get: no secretKey","PRIVATE_KEY_ERROR")}}toCryptosuite(){return new fu(this)}sign(e){if(this.#t)return this.#t.sign(e,"bip340");if(!this.signer)throw new En("Cannot sign: no secretKey","SIGN_ERROR");return Or.sign(e,this.secretKey.bytes,Br(32))}verify(e,r){return Or.verify(e,r,this.publicKey.x)}fullId(){return this.id.startsWith("#")?`${this.controller}${this.id}`:this.id}toVerificationMethod(){return{id:this.id,type:t.type,controller:this.controller,publicKeyMultibase:this.publicKey.multibase.encoded}}get signer(){return!!this.#t||!!this.#e.secretKey}toJSON(){let e;try{e=this.signer}catch{e=!1}return{id:this.id,controller:this.controller,fullId:this.fullId(),signer:e,keyPair:this.keyPair.toJSON(),verificationMethod:this.toVerificationMethod()}}static create({id:e,controller:r,keyPair:n}){return new t({id:e,controller:r,keyPair:n})}static fromSecretKey(e,r,n){let i=new qr(n),o=i.computePublicKey(),s=new lo({publicKey:o,secretKey:i});return new t({id:e,controller:r,keyPair:s})}static fromSigner(e,r,n){let i=new ft(n.publicKey),o=new lo({publicKey:i});return new t({id:e,controller:r,keyPair:o,externalSigner:n})}static fromPublicKey({id:e,controller:r,publicKeyBytes:n}){let i=new ft(n),o=new lo({publicKey:i});return new t({id:e,controller:r,keyPair:o})}static fromVerificationMethod({id:e,controller:r,publicKeyMultibase:n}){if(!n)throw new En("Invalid publicKeyMultibase: cannot be undefined",xl,{publicKeyMultibase:n});let i=gf.decode(n);if(i.length!==35)throw new En(`Invalid publicKeyMultibase length: ${i.length}`,xl,{publicKeyMultibase:n});if(i[0]!==231||i[1]!==1)throw new En(`Invalid publicKeyMultibase prefix: expected secp256k1 multicodec [0xe7, 0x01], got [0x${i[0]?.toString(16)??"??"}, 0x${i[1]?.toString(16)??"??"}]`,xl,{publicKeyMultibase:n});let o=i.slice(2),s=new lo({publicKey:o});return new t({id:e,controller:r,keyPair:s})}};l();l();l();function Sr(t){return t instanceof kt?{type:t.type,message:t.message}:t instanceof Error?{type:t.name,message:t.message}:{type:"unknown",message:String(t)}}var CL=6;function mf(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function LL(t){return mf(t)&&Object.values(t).every(e=>typeof e=="string")}function PL(t){return mf(t)?Array.isArray(t.patch)&&typeof t.sourceHash=="string"&&typeof t.targetHash=="string"&&Number.isInteger(t.targetVersionId)&&t.targetVersionId>=2&&mf(t.proof):!1}function ML(t){return mf(t)?typeof t.id=="string"&&typeof t.collapsed=="string"&&Array.isArray(t.hashes):!1}function KL(t){if(t===void 0)return CL;if(typeof t=="number"&&Number.isInteger(t)&&t>=1)return t;throw new le(`Invalid resolution option minConf: expected a positive integer (minimum 1), got ${Zb(t)}.`,qu,{minConf:t})}function Zb(t){return typeof t=="string"?JSON.stringify(t):String(t)}var $L=/^-?[0-9]+$/;function HL(t){if(t!==void 0){if(typeof t=="string"&&$L.test(t)&&Number.isSafeInteger(Number(t)))return Number(t);throw new le(`Invalid resolution option versionId: expected an ASCII string of an integer, got ${Zb(t)}.`,qu,{versionId:t})}}var VL=/^-?\d{4,}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/,qL=/(Z|[+-]\d{2}:\d{2})$/;function FL(t){if(t!==void 0){if(typeof t=="string"&&VL.test(t)&&Li.isValidXsdDateTime(t)){let e=Date.parse(t);if(Number.isFinite(e))return e}throw new le(`Invalid resolution option versionTime: expected an XML Datetime in UTC without a fraction (for example "2026-07-01T00:00:00Z"), got ${Zb(t)}.`,qu,{versionTime:t})}}var fs=class t{#e;#t;#n;#r;#o;#i;#c=null;#l=new Map;#h=new Set;#d=new Set;#a=[];#p=null;#s=1;#y=[];#g=0;#f;#u;#m=0;#w;constructor(e,r,n,i){if(this.#e=e,this.#o=r,this.#i=n,i?.versionId!==void 0&&i?.versionTime!==void 0)throw new le("Invalid resolution options: versionId and versionTime are mutually exclusive. Pass one of them.",qu,{versionId:i.versionId,versionTime:i.versionTime});this.#t=HL(i?.versionId),this.#n=FL(i?.versionTime);let o=i?.maxDiscoveryRounds;this.#u=typeof o=="number"&&o>0?o:1/0,this.#w=KL(i?.minConf),i?.genesisDocument&&(this.#c=i.genesisDocument),this.#r=n?"BeaconDiscovery":"GenesisDocument"}static deterministic(e){let r=e.genesisBytes,n=vr.encode(r,e),{multibase:i}=new ft(r),o=pn.generateBeaconServices({id:n,publicKey:r,network:Do(e.network),beaconType:"SingletonBeacon"});return new hn({id:n,verificationMethod:[{id:`${n}#initialKey`,type:"Multikey",controller:n,publicKeyMultibase:i.encoded}],service:o})}static external(e,r){let n=Oo(r);if(!bo(e.genesisBytes,n))throw new le("Initial document mismatch: genesisBytes !== genesisDocumentHash",pt,{genesisBytes:Zr(e.genesisBytes,"hex"),genesisDocumentHash:Zr(n,"hex")});let i=vr.encode(e.genesisBytes,e),o=JSON.parse(JSON.stringify(r).replaceAll(dr,i));return new hn(o)}static sidecarData(e={}){let r=new Map;if(e.updates?.length)for(let o of e.updates)r.set(zn(o,{encoding:"hex"}),o);let n=new Map;if(e.casUpdates?.length)for(let o of e.casUpdates)n.set(zn(o,{encoding:"hex"}),o);let i=new Map;if(e.smtProofs?.length)for(let o of e.smtProofs)i.set(Zr(Xc(o.id,"base64urlnopad"),"hex"),o);return{updateMap:r,casMap:n,smtMap:i}}static confirmDuplicate(e,r){if(!Number.isInteger(e.targetVersionId)||e.targetVersionId<2)throw new le("Invalid duplicate: targetVersionId must be an integer >= 2",fe,{targetVersionId:e.targetVersionId});let{proof:n,...i}=e,o=Oo(i),s=r[e.targetVersionId-2];if(s===void 0)throw new le("Invalid duplicate: no applied update in history for targetVersionId",El,{targetVersionId:e.targetVersionId,historyLength:r.length});if(!bo(s,o))throw new le("Invalid duplicate: unsigned update hash does not match historical hash",El,{unsignedUpdateHash:Zr(o,"hex"),historicalHash:Zr(s,"hex")})}static decodeUpdateHash(e,r){if(typeof e=="string")try{return Xc(e,"base64urlnopad")}catch(n){throw new le(`Invalid update: ${r} does not decode as base64url: ${Sr(n).message}`,fe,{[r]:e,cause:Sr(n)})}throw new le(`Invalid update: ${r} is not a string`,fe,{[r]:e})}static proofInstant(e,r){let n=e[r];if(n!==void 0){if(typeof n=="string"&&qL.test(n)&&Li.isValidXsdDateTime(n)){let i=Date.parse(n);if(Number.isFinite(i))return i}throw new le(`Invalid update: proof.${r} is not an XML Datetime with a timezone`,fe,{[r]:n})}}static checkProofWindow(e,r){let n=t.proofInstant(e,"created"),i=t.proofInstant(e,"expires");if(n!==void 0&&n>r.time*1e3)throw new le("Invalid update: proof.created is after the header time of the block that contains the Beacon Signal",fe,{created:e.created,blockTime:r.time});if(i!==void 0&&i<r.mediantime*1e3)throw new le("Invalid update: proof.expires is before the mediantime of the block that contains the Beacon Signal",fe,{expires:e.expires,mediantime:r.mediantime});if(n!==void 0&&i!==void 0&&i<n)throw new le("Invalid update: proof.expires is before proof.created",fe,{created:e.created,expires:e.expires})}static applyUpdate(e,r,n){let i=Oo(e),o=t.decodeUpdateHash(r.sourceHash,"sourceHash");if(!bo(o,i))throw new le("Hash mismatch: update.sourceHash !== currentDocumentHash",fe,{sourceHash:r.sourceHash,currentDocumentHash:Zr(i,"hex")});if(!Wb(r["@context"]))throw new le("Invalid update: @context is not the array the specification pins for a BTCR2 Update",fe,{context:r["@context"],expected:[...uu]});if(!Wb(r.proof?.["@context"],r["@context"]))throw new le("Invalid update: proof @context does not equal the update @context",fe,{proofContext:r.proof?.["@context"],context:r["@context"]});let s=r.proof,c=[["type","DataIntegrityProof"],["cryptosuite","bip340-jcs-2025"],["proofPurpose","capabilityInvocation"],["capabilityAction","Write"],["capability",`urn:zcap:root:${encodeURIComponent(e.id)}`]];for(let[y,x]of c){let S=s[y];if(S!==x)throw new le(`Invalid update: proof.${y} must equal "${x}"`,fe,{field:y,expected:x,actual:S})}let a=s.verificationMethod,u=st.capabilityInvocationEntry(e,a);if(u===void 0)throw new le("Invalid update: verificationMethod is not authorized for capabilityInvocation",fe,{verificationMethodId:a,capabilityInvocation:e.capabilityInvocation});let d=st.verificationMethodOfEntry(e,u);if(d===void 0)throw new le("Invalid update: verificationMethod is not found in the verificationMethod of the current document",fe,{verificationMethodId:a});t.checkProofWindow(s,n);let f;try{let y=ho.fromVerificationMethod({...d,id:st.absoluteDidUrl(d.id,e.id)??d.id});f=new du(new fu(y)).verifyProof(Kt(r),"capabilityInvocation").verified}catch(y){throw new le(`Invalid update: proof verification failed: ${Sr(y).message}`,fe,{verificationMethodId:a,cause:Sr(y)})}if(!f)throw new le("Invalid update: proof not verified",fe,{verificationMethodId:a});let h;try{h=Qc.apply(e,r.patch,{strict:!0})}catch(y){throw new le(`Invalid update: ${Sr(y).message}`,fe,{cause:Sr(y)})}if(h?.id!==e.id)throw new le(`Invalid update: the patch changes the document id (from "${e.id}" to "${String(h?.id)}")`,fe,{sourceId:e.id,targetId:h?.id});try{hn.validate(h)}catch(y){throw new le(`Invalid update: the patched document does not conform to DID Core: ${Sr(y).message}`,fe,{cause:Sr(y)})}let p=Oo(h),g=t.decodeUpdateHash(r.targetHash,"targetHash");if(!bo(g,p))throw new le("Invalid update: update.targetHash !== updatedDocumentHash",fe,{updateTargetHash:g,updatedDocumentHash:p});return h}resolve(){for(;;)switch(this.#r){case"GenesisDocument":{if(this.#c){this.#i=t.external(this.#e,this.#c),this.#c=null,this.#r="BeaconDiscovery";continue}return{status:"action-required",needs:[{kind:"NeedGenesisDocument",genesisHash:Zr(this.#e.genesisBytes,"hex")}]}}case"BeaconDiscovery":{let r=pn.getBeaconServices(this.#i).filter(n=>{let i=pn.parseBitcoinAddress(n.serviceEndpoint);return!this.#d.has(i)});if(r.length>0){for(let n of r){let i=pn.parseBitcoinAddress(n.serviceEndpoint);this.#d.add(i)}return{status:"action-required",needs:[{kind:"NeedBeaconSignals",beaconServices:r}]}}this.#r="BeaconProcess";continue}case"BeaconProcess":{let e=[];for(let[r,n]of this.#l){if(this.#h.has(r.id)||!n.length)continue;let i=this.#x(n);if(!i.length)continue;let s=oa.establish(r,this.#i.id).processSignals(i,this.#o);s.needs.length>0?e.push(...s.needs):(this.#a.push(...s.updates),this.#h.add(r.id))}if(e.length>0)return{status:"action-required",needs:e};this.#r="ProcessUpdate";continue}case"ProcessUpdate":{let e=this.#i;if(this.#t!==void 0&&this.#s===this.#t){this.#r="Complete";continue}if(this.#a.length===0||e.deactivated){if(this.#t!==void 0)throw new le(`Version ${this.#t} of the DID does not exist: the history `+(e.deactivated?`ends with the deactivation at version ${this.#s}.`:`ends at version ${this.#s}.`),hv,{versionId:this.#t,currentVersionId:this.#s});this.#r="Complete";continue}this.#a.sort(([o,s],[c,a])=>o.targetVersionId-c.targetVersionId||s.height-a.height);let[r,n]=this.#a.shift();if(r.targetVersionId<=this.#s){t.confirmDuplicate(r,this.#y);continue}if(this.#n!==void 0&&n.mediantime*1e3>this.#n){this.#r="Complete";continue}if(r.targetVersionId!==this.#s+1)throw new le("Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1",El,{targetVersionId:r.targetVersionId,currentVersionId:this.#s+1});this.#i=t.applyUpdate(e,r,n);let i=ks.deleteKeys(r,["proof"]);if(this.#y.push(Oo(i)),this.#s++,this.#g=n.confirmations,this.#f=Li.toISOStringNonFractional(Li.blocktimeToTimestamp(n.time)),this.#b()){if(++this.#m>this.#u)throw new le(`Exceeded the configured maximum of ${this.#u} beacon-discovery rounds. Raise or remove ResolutionOptions.maxDiscoveryRounds to resolve this DID.`,bl,{maxDiscoveryRounds:this.#u,discoveryRounds:this.#m});this.#r="BeaconDiscovery"}continue}case"Complete":return this.#p??={didDocument:this.#i,metadata:{versionId:`${this.#s}`,confirmations:this.#g,...this.#f!==void 0?{updated:this.#f}:{},deactivated:this.#i.deactivated||!1}},{status:"resolved",result:this.#p}}}#b(){return pn.getBeaconServices(this.#i).some(e=>!this.#d.has(pn.parseBitcoinAddress(e.serviceEndpoint)))}#x(e){let r=[];for(let n of e){let i=n.blockMetadata,o=i?.confirmations;if(!(!Number.isInteger(o)||o<this.#w)){if(!Number.isFinite(i?.height)||!Number.isFinite(i?.time)||!Number.isFinite(i?.mediantime))throw new le(`Beacon signal ${n.signalBytes} has ${o} confirmations but no valid block height, block time, or block mediantime.`,fe,{signalBytes:n.signalBytes,confirmations:o,height:i?.height,time:i?.time,mediantime:i?.mediantime});r.push(n)}}return r}provide(e,r){switch(e.kind){case"NeedGenesisDocument":{if(!mf(r))throw new le("Provided data for NeedGenesisDocument must be a document object.",fe,{kind:e.kind});this.#c=r;break}case"NeedBeaconSignals":{if(!(r instanceof Map))throw new le("Provided data for NeedBeaconSignals must be a Map of beacon services to signals.",fe,{kind:e.kind});for(let[n,i]of r)this.#l.set(n,i);break}case"NeedCASAnnouncement":{if(!LL(r))throw new le("Provided data for NeedCASAnnouncement is not a CAS announcement.",fe,{kind:e.kind});let n=zn(r,{encoding:"hex"});if(n!==e.announcementHash)throw new le(`CAS announcement hash mismatch: expected ${e.announcementHash}, got ${n}.`,fe,{expected:e.announcementHash,actual:n});this.#o.casMap.set(n,r);break}case"NeedSignedUpdate":{if(!PL(r))throw new le("Provided data for NeedSignedUpdate is not a signed BTCR2 update.",fe,{kind:e.kind});let n=zn(r,{encoding:"hex"});if(n!==e.updateHash)throw new le(`Signed update hash mismatch: expected ${e.updateHash}, got ${n}.`,fe,{expected:e.updateHash,actual:n});this.#o.updateMap.set(n,r);break}case"NeedSMTProof":{if(!ML(r))throw new le("Provided data for NeedSMTProof is not an SMT proof.",fe,{kind:e.kind});let n=Zr(Xc(r.id,"base64urlnopad"),"hex");if(n!==e.smtRootHash)throw new le(`SMT proof root hash mismatch: expected ${e.smtRootHash}, got ${n}`,fe,{expected:e.smtRootHash,actual:n});this.#o.smtMap.set(e.smtRootHash,r);break}}}};function jL(t){let e=t.capabilityInvocation?.[0];if(e===void 0)throw new Ve("Cannot derive aggregation communication key: capabilityInvocation is absent",qe,{id:t.id});let r=st.absoluteDidUrl(e,t.id),n=typeof e=="string"?r===void 0?void 0:t.verificationMethod?.find(i=>st.absoluteDidUrl(i.id,t.id)===r):e;if(!n)throw new Ve(`Cannot derive aggregation communication key: capabilityInvocation[0] "${e}" does not resolve to a verification method`,qe,{id:t.id,invocation:e});return ho.fromVerificationMethod(n).publicKey}function Kne(t,e){try{let r=vr.decode(t);if(r.idType==="KEY")return new ft(r.genesisBytes);if(e?.genesisDocument){let n=fs.external(r,e.genesisDocument);return jL(n)}}catch{}}l();l();l();var Qp=class t{#e={phase:"Construct"};#t;#n;#r;#o;#i;constructor(e){this.#t=e.sourceDocument,this.#n=e.patches,this.#r=e.sourceVersionId,this.#o=e.verificationMethod,this.#i=e.beaconService}static construct(e,r,n){let i={"@context":[...uu],patch:r,targetHash:"",targetVersionId:n+1,sourceHash:zn(e)},o;try{o=Qc.apply(e,r,{strict:!0})}catch(s){throw new nt(`Invalid patch: ${Sr(s).message}`,fe,{cause:Sr(s)})}if(o.id!==e.id)throw new nt(`Patches must not change the DID document id (source "${e.id}" to target "${o.id}").`,fe,{sourceId:e.id,targetId:o.id});try{hn.isValid(o)}catch(s){throw new nt("Error validating targetDocument: "+(s instanceof Error?s.message:String(s)),fe,o)}return i.targetHash=zn(o),i}static sign(e,r,n,i){if(!e.startsWith("did:btcr2:"))throw new nt(`Expected a did:btcr2 identifier for the root capability; got "${e}".`,fe,{did:e});let o=n.controller,s=n.id.indexOf("#");if(s<0)throw new nt(`Verification method id must contain a fragment (e.g. "${n.id}#initialKey"); got "${n.id}".`,fe,{verificationMethodId:n.id});let c=n.id.slice(s),a=ho.fromSigner(c,o,i),u=s===0?`${e}${c}`:n.id,d=a.publicKey.multibase.encoded;if(n.publicKeyMultibase&&d!==n.publicKeyMultibase)throw new nt(`Signing key does not match verification method "${n.id}": the signer's public key differs from the method's published publicKeyMultibase.`,fe,{verificationMethodId:n.id,expected:n.publicKeyMultibase,actual:d});let f={"@context":[...uu],cryptosuite:"bip340-jcs-2025",type:"DataIntegrityProof",verificationMethod:u,proofPurpose:"capabilityInvocation",capability:`urn:zcap:root:${encodeURIComponent(e)}`,capabilityAction:"Write"},p=a.toCryptosuite().toDataIntegrityProof().addProof(r,f),g;try{g=ho.fromVerificationMethod({...n,id:u}).toCryptosuite().toDataIntegrityProof().verifyProof(Kt(p),"capabilityInvocation").verified}catch(y){throw new nt(`Invalid update: the proof does not verify with the public key of "${n.id}": `+Sr(y).message,fe,{verificationMethodId:n.id,cause:Sr(y)})}if(!g)throw new nt(`Invalid update: the proof does not verify with the public key of "${n.id}".`,fe,{verificationMethodId:n.id});return p}static async announce(e,r,n,i,o,s){return oa.establish(e,r).broadcastSignal(n,i,o,s)}#c(){return t.construct(this.#t,this.#n,this.#r)}advance(){for(;;)switch(this.#e.phase){case"Construct":{let e=this.#c();this.#e={phase:"Sign",unsignedUpdate:e};continue}case"Sign":return{status:"action-required",needs:[{kind:"NeedSigningKey",verificationMethodId:this.#o.id,unsignedUpdate:this.#e.unsignedUpdate}]};case"Fund":return{status:"action-required",needs:[{kind:"NeedFunding",beaconAddress:this.#i.serviceEndpoint.replace("bitcoin:",""),beaconService:this.#i}]};case"Broadcast":return{status:"action-required",needs:[{kind:"NeedBroadcast",beaconService:this.#i,signedUpdate:this.#e.signedUpdate,did:this.#t.id}]};case"Complete":return{status:"complete",result:{signedUpdate:this.#e.signedUpdate}}}}provide(e,r){switch(e.kind){case"NeedSigningKey":{if(this.#e.phase!=="Sign")throw new nt(`Cannot provide NeedSigningKey: updater phase is ${this.#e.phase}, expected Sign.`,fe,{phase:this.#e.phase});if(!r)throw new nt("NeedSigningKey requires a Signer.",fe);let n=this.#e.unsignedUpdate,i=t.sign(this.#t.id,n,this.#o,r);this.#e={phase:"Fund",unsignedUpdate:n,signedUpdate:i};break}case"NeedFunding":{if(this.#e.phase!=="Fund")throw new nt(`Cannot provide NeedFunding: updater phase is ${this.#e.phase}, expected Fund.`,fe,{phase:this.#e.phase});if(r!==void 0){let n=r;if(typeof n.utxoCount!="number"||!Number.isFinite(n.utxoCount)||n.utxoCount<1)throw new nt(`NeedFunding proof must have utxoCount >= 1; got ${String(n.utxoCount)}.`,fe,{utxoCount:n.utxoCount})}this.#e={phase:"Broadcast",unsignedUpdate:this.#e.unsignedUpdate,signedUpdate:this.#e.signedUpdate};break}case"NeedBroadcast":{if(this.#e.phase!=="Broadcast")throw new nt(`Cannot provide NeedBroadcast: updater phase is ${this.#e.phase}, expected Broadcast.`,fe,{phase:this.#e.phase});this.#e={phase:"Complete",signedUpdate:this.#e.signedUpdate};break}}}};l();var GI=class{document={};constructor(e){if(!e.id)throw new Ve('Missing required "id" property',qe,e);this.document.id=e.id,this.document.verificationMethod=e.verificationMethod??[],e["@context"]&&(this.document["@context"]=e["@context"])}withAuthentication(e){return e&&(this.document.authentication=e),this}withAssertionMethod(e){return e&&(this.document.assertionMethod=e),this}withCapabilityInvocation(e){return e&&(this.document.capabilityInvocation=e),this}withCapabilityDelegation(e){return e&&(this.document.capabilityDelegation=e),this}withService(e){return e&&(this.document.service=e),this}build(){let e=new hn(this.document);for(let r of Object.keys(e))e[r]===void 0&&delete e[r];return e}};l();var zI=class{static methodName="btcr2";static create(e,r){let{idType:n,version:i=1,network:o="bitcoin"}=r||{};if(!n)throw new be("idType is required for creating a did:btcr2 identifier",qe,r);return vr.encode(e,{idType:n,version:i,network:o})}static resolve(e,r={}){let n=vr.decode(e),i=fs.sidecarData(r.sidecar),o=n.hrp===Rl.k?fs.deterministic(n):null;return new fs(n,i,o,{versionId:r.versionId,versionTime:r.versionTime,genesisDocument:r.sidecar?.genesisDocument,maxDiscoveryRounds:r.maxDiscoveryRounds,minConf:r.minConf})}static update({sourceDocument:e,patches:r,sourceVersionId:n,verificationMethodId:i,beaconId:o}){if(!Number.isInteger(n)||n<1)throw new nt(`Invalid sourceVersionId: expected an integer of at least 1, got ${String(n)}.`,fe,{sourceVersionId:n});let s=st.capabilityInvocationEntry(e,i);if(s===void 0)throw new nt("Invalid verificationMethodId: not authorized for capabilityInvocation",fe,{verificationMethodId:i,capabilityInvocation:e.capabilityInvocation});let c=st.verificationMethodOfEntry(e,s);if(!c)throw new nt("Invalid verificationMethodId: not found in source document",fe,{verificationMethodId:i});if(c.type!==cu)throw new nt(`Invalid verificationMethod: verificationMethod.type must be "${cu}"`,qe,c);if(!c.publicKeyMultibase?.startsWith(au))throw new nt(`Invalid verificationMethodId: publicKeyMultibase prefix must start with "${au}"`,qe,c);let a=st.absoluteDidUrl(o,e.id),u=e.service.filter(d=>a!==void 0&&st.absoluteDidUrl(d.id,e.id)===a).filter(d=>!!d).shift();if(!u)throw new nt("No beacon service found for provided beaconId",fe,{sourceDocument:e,beaconId:o});return new Qp({sourceDocument:e,patches:r,sourceVersionId:n,verificationMethod:c,beaconService:u})}static deactivate({sourceDocument:e,sourceVersionId:r,verificationMethodId:n,beaconId:i}){return this.update({sourceDocument:e,patches:[{...VI}],sourceVersionId:r,verificationMethodId:n,beaconId:i})}static getSigningMethod(e,r){r??="#initialKey";let n=xe.parse(e.id);if(n&&n.method!==this.methodName)throw new be(`Method not supported: ${n.method}`,wl,{identifier:e.id});let i=st.absoluteDidUrl(r,e.id)??st.relationshipMethodId(e.assertionMethod?.[0],e.id),o=i===void 0?void 0:st.getVerificationMethods(e).find(s=>st.absoluteDidUrl(s.id,e.id)===i);if(!(o&&o.publicKeyMultibase))throw new re(ie.InternalError,"A verification method intended for signing could not be determined from the DID Document");return o}};export{xv as AggregateBeaconError,st as Appendix,nre as BECH32M_CHARS,IL as BTCR2_DID_DOCUMENT_CONTEXT,uu as BTCR2_UPDATE_CONTEXT,nr as BeaconError,oa as BeaconFactory,HI as BeaconSignalDiscovery,pn as BeaconUtils,Ul as CASBeacon,Ev as CASBeaconError,Sv as CHANGE_OUTPUT_VBYTES,VI as DEACTIVATION_PATCH,k0 as DEFAULT_FEE_ESTIMATOR,CL as DEFAULT_MIN_CONF,BL as DID_REGEX,Av as DUST_LIMIT_SATS,zI as DidBtcr2,hn as DidDocument,GI as DidDocumentBuilder,jb as DidVerificationMethod,yf as GenesisDocument,dr as ID_PLACEHOLDER_VALUE,vr as Identifier,au as MULTIKEY_PUBLIC_KEY_MULTIBASE_PREFIX,cu as MULTIKEY_VERIFICATION_METHOD_TYPE,t6 as P2PKH_BEACON_TX_VSIZE,QR as P2TR_BEACON_TX_VSIZE,e6 as P2WPKH_BEACON_TX_VSIZE,fs as Resolver,r6 as SINGLETON_BEACON_TX_VSIZE,$l as SMTBeacon,Gu as SMTBeaconError,N0 as SPENDABLE_DUST_LIMIT_SATS,ko as SinglePartyBeacon,Ol as SingletonBeacon,bv as SingletonBeaconError,zu as StaticFeeEstimator,Qp as Updater,Tv as beaconTxVsize,X9 as buildAggregationBeaconTx,n6 as deriveSingletonAddress,_v as detectSingletonScriptKind,$I as extractOpReturnSignalHash,jL as getAggregationCommunicationKey,Wb as isBtcr2UpdateContext,RL as isMultikeyVerificationMethod,Rv as opReturnScript,Kne as resolveBtcr2SenderPk,Iv as resolveChangeAddress,s6 as selectSpendableUtxo};
|
|
4
4
|
/*! Bundled license information:
|
|
5
5
|
|
|
6
6
|
ieee754/index.js:
|