@enbox/dids 0.0.2 → 0.0.3

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.
Files changed (68) hide show
  1. package/README.md +41 -1
  2. package/dist/browser.js +6 -10
  3. package/dist/browser.js.map +4 -4
  4. package/dist/browser.mjs +6 -10
  5. package/dist/browser.mjs.map +4 -4
  6. package/dist/esm/bearer-did.js +5 -5
  7. package/dist/esm/bearer-did.js.map +1 -1
  8. package/dist/esm/did.js +13 -6
  9. package/dist/esm/did.js.map +1 -1
  10. package/dist/esm/methods/did-dht.js +34 -25
  11. package/dist/esm/methods/did-dht.js.map +1 -1
  12. package/dist/esm/methods/did-ion.js +9 -7
  13. package/dist/esm/methods/did-ion.js.map +1 -1
  14. package/dist/esm/methods/did-jwk.js +3 -3
  15. package/dist/esm/methods/did-jwk.js.map +1 -1
  16. package/dist/esm/methods/did-key.js +12 -240
  17. package/dist/esm/methods/did-key.js.map +1 -1
  18. package/dist/esm/methods/did-web.js +3 -2
  19. package/dist/esm/methods/did-web.js.map +1 -1
  20. package/dist/esm/resolver/resolver-cache-level.js +1 -1
  21. package/dist/esm/resolver/resolver-cache-level.js.map +1 -1
  22. package/dist/esm/resolver/resolver-cache-noop.js +10 -10
  23. package/dist/esm/resolver/resolver-cache-noop.js.map +1 -1
  24. package/dist/esm/resolver/universal-resolver.js +3 -3
  25. package/dist/esm/resolver/universal-resolver.js.map +1 -1
  26. package/dist/esm/utils.js +37 -21
  27. package/dist/esm/utils.js.map +1 -1
  28. package/dist/types/bearer-did.d.ts +3 -2
  29. package/dist/types/bearer-did.d.ts.map +1 -1
  30. package/dist/types/did.d.ts.map +1 -1
  31. package/dist/types/methods/did-dht.d.ts +4 -4
  32. package/dist/types/methods/did-dht.d.ts.map +1 -1
  33. package/dist/types/methods/did-ion.d.ts +3 -2
  34. package/dist/types/methods/did-ion.d.ts.map +1 -1
  35. package/dist/types/methods/did-jwk.d.ts +2 -2
  36. package/dist/types/methods/did-jwk.d.ts.map +1 -1
  37. package/dist/types/methods/did-key.d.ts +3 -52
  38. package/dist/types/methods/did-key.d.ts.map +1 -1
  39. package/dist/types/methods/did-method.d.ts +3 -3
  40. package/dist/types/methods/did-method.d.ts.map +1 -1
  41. package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -1
  42. package/dist/types/resolver/universal-resolver.d.ts +2 -2
  43. package/dist/types/resolver/universal-resolver.d.ts.map +1 -1
  44. package/dist/types/types/did-core.d.ts +1 -1
  45. package/dist/types/types/did-core.d.ts.map +1 -1
  46. package/dist/types/utils.d.ts +8 -5
  47. package/dist/types/utils.d.ts.map +1 -1
  48. package/dist/utils.js +1 -5
  49. package/dist/utils.js.map +4 -4
  50. package/package.json +30 -40
  51. package/src/bearer-did.ts +12 -11
  52. package/src/did.ts +8 -6
  53. package/src/methods/did-dht.ts +35 -35
  54. package/src/methods/did-ion.ts +12 -11
  55. package/src/methods/did-jwk.ts +6 -6
  56. package/src/methods/did-key.ts +24 -305
  57. package/src/methods/did-method.ts +3 -3
  58. package/src/methods/did-web.ts +2 -2
  59. package/src/resolver/resolver-cache-level.ts +4 -4
  60. package/src/resolver/resolver-cache-noop.ts +10 -10
  61. package/src/resolver/universal-resolver.ts +5 -5
  62. package/src/types/did-core.ts +3 -3
  63. package/src/utils.ts +28 -26
  64. package/dist/cjs/index.js +0 -6303
  65. package/dist/cjs/index.js.map +0 -7
  66. package/dist/cjs/package.json +0 -1
  67. package/dist/cjs/utils.js +0 -245
  68. package/dist/cjs/utils.js.map +0 -7
package/dist/browser.js CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";var Web5Dids=(()=>{var Hx=Object.create;var Na=Object.defineProperty;var jx=Object.getOwnPropertyDescriptor;var Wx=Object.getOwnPropertyNames;var zx=Object.getPrototypeOf,Gx=Object.prototype.hasOwnProperty;var $=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),$a=(t,e)=>{for(var r in e)Na(t,r,{get:e[r],enumerable:!0})},vp=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Wx(e))!Gx.call(t,i)&&i!==r&&Na(t,i,{get:()=>e[i],enumerable:!(n=jx(e,i))||n.enumerable});return t};var f=(t,e,r)=>(r=t!=null?Hx(zx(t)):{},vp(e||!t||!t.__esModule?Na(r,"default",{value:t,enumerable:!0}):r,t)),Jx=t=>vp(Na({},"__esModule",{value:!0}),t);var Ap=$(qa=>{"use strict";var VB=f(h());qa.byteLength=Xx;qa.toByteArray=Qx;qa.fromByteArray=rE;var xr=[],zt=[],Yx=typeof Uint8Array<"u"?Uint8Array:Array,ud="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ni=0,Sp=ud.length;ni<Sp;++ni)xr[ni]=ud[ni],zt[ud.charCodeAt(ni)]=ni;var ni,Sp;zt[45]=62;zt[95]=63;function _p(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 Xx(t){var e=_p(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Zx(t,e,r){return(e+r)*3/4-r}function Qx(t){var e,r=_p(t),n=r[0],i=r[1],o=new Yx(Zx(t,n,i)),s=0,a=i>0?n-4:n,u;for(u=0;u<a;u+=4)e=zt[t.charCodeAt(u)]<<18|zt[t.charCodeAt(u+1)]<<12|zt[t.charCodeAt(u+2)]<<6|zt[t.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=zt[t.charCodeAt(u)]<<2|zt[t.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=zt[t.charCodeAt(u)]<<10|zt[t.charCodeAt(u+1)]<<4|zt[t.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function eE(t){return xr[t>>18&63]+xr[t>>12&63]+xr[t>>6&63]+xr[t&63]}function tE(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(eE(n));return i.join("")}function rE(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(tE(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(xr[e>>2]+xr[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(xr[e>>10]+xr[e>>4&63]+xr[e<<2&63]+"=")),i.join("")}});var Tp=$(dd=>{var jB=f(h());dd.read=function(t,e,r,n,i){var o,s,a=i*8-n-1,u=(1<<a)-1,d=u>>1,c=-7,l=r?i-1:0,g=r?-1:1,w=t[e+l];for(l+=g,o=w&(1<<-c)-1,w>>=-c,c+=a;c>0;o=o*256+t[e+l],l+=g,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=s*256+t[e+l],l+=g,c-=8);if(o===0)o=1-d;else{if(o===u)return s?NaN:(w?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-d}return(w?-1:1)*s*Math.pow(2,o-n)};dd.write=function(t,e,r,n,i,o){var s,a,u,d=o*8-i-1,c=(1<<d)-1,l=c>>1,g=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=n?0:o-1,m=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),s+l>=1?e+=g/u:e+=g*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=c?(a=0,s=c):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s=s+l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+w]=a&255,w+=m,a/=256,i-=8);for(s=s<<i|a,d+=i;d>0;t[r+w]=s&255,w+=m,s/=256,d-=8);t[r+w-m]|=y*128}});var _t=$(no=>{"use strict";var GB=f(h());var ld=Ap(),to=Tp(),Ip=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;no.Buffer=T;no.SlowBuffer=cE;no.INSPECT_MAX_BYTES=50;var Fa=2147483647;no.kMaxLength=Fa;T.TYPED_ARRAY_SUPPORT=nE();!T.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 nE(){try{let 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(T.prototype,"parent",{enumerable:!0,get:function(){if(T.isBuffer(this))return this.buffer}});Object.defineProperty(T.prototype,"offset",{enumerable:!0,get:function(){if(T.isBuffer(this))return this.byteOffset}});function Wr(t){if(t>Fa)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,T.prototype),e}function T(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 yd(t)}return Op(t,e,r)}T.poolSize=8192;function Op(t,e,r){if(typeof t=="string")return oE(t,e);if(ArrayBuffer.isView(t))return sE(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(Er(t,ArrayBuffer)||t&&Er(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Er(t,SharedArrayBuffer)||t&&Er(t.buffer,SharedArrayBuffer)))return hd(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return T.from(n,e,r);let i=aE(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return T.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)}T.from=function(t,e,r){return Op(t,e,r)};Object.setPrototypeOf(T.prototype,Uint8Array.prototype);Object.setPrototypeOf(T,Uint8Array);function kp(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 iE(t,e,r){return kp(t),t<=0?Wr(t):e!==void 0?typeof r=="string"?Wr(t).fill(e,r):Wr(t).fill(e):Wr(t)}T.alloc=function(t,e,r){return iE(t,e,r)};function yd(t){return kp(t),Wr(t<0?0:md(t)|0)}T.allocUnsafe=function(t){return yd(t)};T.allocUnsafeSlow=function(t){return yd(t)};function oE(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!T.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Cp(t,e)|0,n=Wr(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function fd(t){let e=t.length<0?0:md(t.length)|0,r=Wr(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function sE(t){if(Er(t,Uint8Array)){let e=new Uint8Array(t);return hd(e.buffer,e.byteOffset,e.byteLength)}return fd(t)}function hd(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');let 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,T.prototype),n}function aE(t){if(T.isBuffer(t)){let e=md(t.length)|0,r=Wr(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||wd(t.length)?Wr(0):fd(t);if(t.type==="Buffer"&&Array.isArray(t.data))return fd(t.data)}function md(t){if(t>=Fa)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Fa.toString(16)+" bytes");return t|0}function cE(t){return+t!=t&&(t=0),T.alloc(+t)}T.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==T.prototype};T.compare=function(e,r){if(Er(e,Uint8Array)&&(e=T.from(e,e.offset,e.byteLength)),Er(r,Uint8Array)&&(r=T.from(r,r.offset,r.byteLength)),!T.isBuffer(e)||!T.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let 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};T.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}};T.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return T.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=T.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Er(s,Uint8Array))o+s.length>i.length?(T.isBuffer(s)||(s=T.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(T.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Cp(t,e){if(T.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Er(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);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return pd(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Fp(t).length;default:if(i)return n?-1:pd(t).length;e=(""+e).toLowerCase(),i=!0}}T.byteLength=Cp;function uE(t,e,r){let 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 bE(this,e,r);case"utf8":case"utf-8":return Pp(this,e,r);case"ascii":return gE(this,e,r);case"latin1":case"binary":return wE(this,e,r);case"base64":return yE(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return xE(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}T.prototype._isBuffer=!0;function ii(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}T.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)ii(this,r,r+1);return this};T.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)ii(this,r,r+3),ii(this,r+1,r+2);return this};T.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)ii(this,r,r+7),ii(this,r+1,r+6),ii(this,r+2,r+5),ii(this,r+3,r+4);return this};T.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Pp(this,0,e):uE.apply(this,arguments)};T.prototype.toLocaleString=T.prototype.toString;T.prototype.equals=function(e){if(!T.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:T.compare(this,e)===0};T.prototype.inspect=function(){let e="",r=no.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Ip&&(T.prototype[Ip]=T.prototype.inspect);T.prototype.compare=function(e,r,n,i,o){if(Er(e,Uint8Array)&&(e=T.from(e,e.offset,e.byteLength)),!T.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;let s=o-i,a=n-r,u=Math.min(s,a),d=this.slice(i,o),c=e.slice(r,n);for(let l=0;l<u;++l)if(d[l]!==c[l]){s=d[l],a=c[l];break}return s<a?-1:a<s?1:0};function Up(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,wd(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=T.from(e,n)),T.isBuffer(e))return e.length===0?-1:Dp(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):Dp(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Dp(t,e,r,n,i){let o=1,s=t.length,a=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,a/=2,r/=2}function u(c,l){return o===1?c[l]:c.readUInt16BE(l*o)}let d;if(i){let c=-1;for(d=r;d<s;d++)if(u(t,d)===u(e,c===-1?0:d-c)){if(c===-1&&(c=d),d-c+1===a)return c*o}else c!==-1&&(d-=d-c),c=-1}else for(r+a>s&&(r=s-a),d=r;d>=0;d--){let c=!0;for(let l=0;l<a;l++)if(u(t,d+l)!==u(e,l)){c=!1;break}if(c)return d}return-1}T.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};T.prototype.indexOf=function(e,r,n){return Up(this,e,r,n,!0)};T.prototype.lastIndexOf=function(e,r,n){return Up(this,e,r,n,!1)};function dE(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(wd(a))return s;t[r+s]=a}return s}function lE(t,e,r,n){return Va(pd(e,t.length-r),t,r,n)}function fE(t,e,r,n){return Va(_E(e),t,r,n)}function hE(t,e,r,n){return Va(Fp(e),t,r,n)}function pE(t,e,r,n){return Va(AE(e,t.length-r),t,r,n)}T.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");let 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");let s=!1;for(;;)switch(i){case"hex":return dE(this,e,r,n);case"utf8":case"utf-8":return lE(this,e,r,n);case"ascii":case"latin1":case"binary":return fE(this,e,r,n);case"base64":return hE(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pE(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};T.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function yE(t,e,r){return e===0&&r===t.length?ld.fromByteArray(t):ld.fromByteArray(t.slice(e,r))}function Pp(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let u,d,c,l;switch(a){case 1:o<128&&(s=o);break;case 2:u=t[i+1],(u&192)===128&&(l=(o&31)<<6|u&63,l>127&&(s=l));break;case 3:u=t[i+1],d=t[i+2],(u&192)===128&&(d&192)===128&&(l=(o&15)<<12|(u&63)<<6|d&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=t[i+1],d=t[i+2],c=t[i+3],(u&192)===128&&(d&192)===128&&(c&192)===128&&(l=(o&15)<<18|(u&63)<<12|(d&63)<<6|c&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return mE(n)}var Bp=4096;function mE(t){let e=t.length;if(e<=Bp)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Bp));return r}function gE(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function wE(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function bE(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=TE[t[o]];return i}function xE(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}T.prototype.slice=function(e,r){let 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);let i=this.subarray(e,r);return Object.setPrototypeOf(i,T.prototype),i};function rt(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")}T.prototype.readUintLE=T.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||rt(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};T.prototype.readUintBE=T.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||rt(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};T.prototype.readUint8=T.prototype.readUInt8=function(e,r){return e=e>>>0,r||rt(e,1,this.length),this[e]};T.prototype.readUint16LE=T.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||rt(e,2,this.length),this[e]|this[e+1]<<8};T.prototype.readUint16BE=T.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||rt(e,2,this.length),this[e]<<8|this[e+1]};T.prototype.readUint32LE=T.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};T.prototype.readUint32BE=T.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};T.prototype.readBigUInt64LE=Sn(function(e){e=e>>>0,ro(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ps(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});T.prototype.readBigUInt64BE=Sn(function(e){e=e>>>0,ro(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ps(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});T.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||rt(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};T.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||rt(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};T.prototype.readInt8=function(e,r){return e=e>>>0,r||rt(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};T.prototype.readInt16LE=function(e,r){e=e>>>0,r||rt(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};T.prototype.readInt16BE=function(e,r){e=e>>>0,r||rt(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};T.prototype.readInt32LE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};T.prototype.readInt32BE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};T.prototype.readBigInt64LE=Sn(function(e){e=e>>>0,ro(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ps(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});T.prototype.readBigInt64BE=Sn(function(e){e=e>>>0,ro(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ps(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});T.prototype.readFloatLE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),to.read(this,e,!0,23,4)};T.prototype.readFloatBE=function(e,r){return e=e>>>0,r||rt(e,4,this.length),to.read(this,e,!1,23,4)};T.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||rt(e,8,this.length),to.read(this,e,!0,52,8)};T.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||rt(e,8,this.length),to.read(this,e,!1,52,8)};function St(t,e,r,n,i,o){if(!T.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")}T.prototype.writeUintLE=T.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;St(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};T.prototype.writeUintBE=T.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;St(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};T.prototype.writeUint8=T.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,1,255,0),this[r]=e&255,r+1};T.prototype.writeUint16LE=T.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};T.prototype.writeUint16BE=T.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};T.prototype.writeUint32LE=T.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||St(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};T.prototype.writeUint32BE=T.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||St(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};function Kp(t,e,r,n,i){qp(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Lp(t,e,r,n,i){qp(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}T.prototype.writeBigUInt64LE=Sn(function(e,r=0){return Kp(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});T.prototype.writeBigUInt64BE=Sn(function(e,r=0){return Lp(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});T.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let u=Math.pow(2,8*n-1);St(this,e,r,n,u-1,-u)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};T.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let u=Math.pow(2,8*n-1);St(this,e,r,n,u-1,-u)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};T.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};T.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};T.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||St(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};T.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||St(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};T.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||St(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};T.prototype.writeBigInt64LE=Sn(function(e,r=0){return Kp(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});T.prototype.writeBigInt64BE=Sn(function(e,r=0){return Lp(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Mp(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 Np(t,e,r,n,i){return e=+e,r=r>>>0,i||Mp(t,e,r,4,34028234663852886e22,-34028234663852886e22),to.write(t,e,r,n,23,4),r+4}T.prototype.writeFloatLE=function(e,r,n){return Np(this,e,r,!0,n)};T.prototype.writeFloatBE=function(e,r,n){return Np(this,e,r,!1,n)};function $p(t,e,r,n,i){return e=+e,r=r>>>0,i||Mp(t,e,r,8,17976931348623157e292,-17976931348623157e292),to.write(t,e,r,n,52,8),r+8}T.prototype.writeDoubleLE=function(e,r,n){return $p(this,e,r,!0,n)};T.prototype.writeDoubleBE=function(e,r,n){return $p(this,e,r,!1,n)};T.prototype.copy=function(e,r,n,i){if(!T.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);let 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};T.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"&&!T.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}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);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=T.isBuffer(e)?e:T.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var eo={};function gd(t,e,r){eo[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}gd("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);gd("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);gd("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Rp(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Rp(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Rp(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 EE(t,e,r){ro(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&ps(e,t.length-(r+1))}function qp(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new eo.ERR_OUT_OF_RANGE("value",a,t)}EE(n,i,o)}function ro(t,e){if(typeof t!="number")throw new eo.ERR_INVALID_ARG_TYPE(e,"number",t)}function ps(t,e,r){throw Math.floor(t)!==t?(ro(t,r),new eo.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new eo.ERR_BUFFER_OUT_OF_BOUNDS:new eo.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var vE=/[^+/0-9A-Za-z-_]/g;function SE(t){if(t=t.split("=")[0],t=t.trim().replace(vE,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function pd(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let 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 _E(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function AE(t,e){let r,n,i,o=[];for(let 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 Fp(t){return ld.toByteArray(SE(t))}function Va(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Er(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function wd(t){return t!==t}var TE=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function Sn(t){return typeof BigInt>"u"?IE:t}function IE(){throw new Error("BigInt not supported")}});var h=$(()=>{"use strict";var Vp=_t().Buffer,{Buffer:DE}=_t();Vp.prototype.writeBigUInt64BE=DE.prototype.writeBigUInt64BE;globalThis.Buffer=Vp});var jp=$((o6,Hp)=>{var s6=f(h()),BE=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Ha=()=>BE.now(),RE=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),bd=t=>t===1/0||RE(t),xd=class t{constructor({max:e=1/0,ttl:r,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:o=!1,dispose:s,noDisposeOnSet:a=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,r!==void 0&&!bd(r))throw new TypeError("ttl must be positive integer or Infinity if set");if(!bd(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=!!a,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-Ha());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 process.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(Ha()+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(!bd(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-Ha())):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(Ha());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()}};Hp.exports=xd});var cy=$(ay=>{"use strict";var IR=f(h());ay.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 or=$((BR,uy)=>{"use strict";var RR=f(h());uy.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 Pd=$((OR,dy)=>{"use strict";var kR=f(h()),Ud=null;dy.exports=function(){return Ud===null&&(Ud={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ud}});var Md=$(ly=>{"use strict";var UR=f(h()),Kd=or(),u1=new Set(["buffer","view","utf8"]),Ld=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"||!u1.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 Kd(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Kd(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Kd(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ly.Encoding=Ld});var Fd=$(Wa=>{"use strict";var KR=f(h()),{Buffer:$d}=_t()||{},{Encoding:qd}=Md(),d1=Pd(),xs=class extends qd{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new Es({encode:this.encode,decode:e=>this.decode($d.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},Es=class extends qd{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new xs({encode:e=>{let r=this.encode(e);return $d.from(r.buffer,r.byteOffset,r.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Nd=class extends qd{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new xs({encode:e=>$d.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:r}=d1();return new Es({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(r.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};Wa.BufferFormat=xs;Wa.ViewFormat=Es;Wa.UTF8Format=Nd});var yy=$(ui=>{"use strict";var MR=f(h()),{Buffer:pt}=_t()||{Buffer:{isBuffer:()=>!1}},{textEncoder:hy,textDecoder:fy}=Pd()(),{BufferFormat:vs,ViewFormat:Vd,UTF8Format:py}=Fd(),za=t=>t;ui.utf8=new py({encode:function(t){return pt.isBuffer(t)?t.toString("utf8"):ArrayBuffer.isView(t)?fy.decode(t):String(t)},decode:za,name:"utf8",createViewTranscoder(){return new Vd({encode:function(t){return ArrayBuffer.isView(t)?t:hy.encode(t)},decode:function(t){return fy.decode(t)},name:`${this.name}+view`})},createBufferTranscoder(){return new vs({encode:function(t){return pt.isBuffer(t)?t:ArrayBuffer.isView(t)?pt.from(t.buffer,t.byteOffset,t.byteLength):pt.from(String(t),"utf8")},decode:function(t){return t.toString("utf8")},name:`${this.name}+buffer`})}});ui.json=new py({encode:JSON.stringify,decode:JSON.parse,name:"json"});ui.buffer=new vs({encode:function(t){return pt.isBuffer(t)?t:ArrayBuffer.isView(t)?pt.from(t.buffer,t.byteOffset,t.byteLength):pt.from(String(t),"utf8")},decode:za,name:"buffer",createViewTranscoder(){return new Vd({encode:function(t){return ArrayBuffer.isView(t)?t:pt.from(String(t),"utf8")},decode:function(t){return pt.from(t.buffer,t.byteOffset,t.byteLength)},name:`${this.name}+view`})}});ui.view=new Vd({encode:function(t){return ArrayBuffer.isView(t)?t:hy.encode(t)},decode:za,name:"view",createBufferTranscoder(){return new vs({encode:function(t){return pt.isBuffer(t)?t:ArrayBuffer.isView(t)?pt.from(t.buffer,t.byteOffset,t.byteLength):pt.from(String(t),"utf8")},decode:za,name:`${this.name}+buffer`})}});ui.hex=new vs({encode:function(t){return pt.isBuffer(t)?t:pt.from(String(t),"hex")},decode:function(t){return t.toString("hex")},name:"hex"});ui.base64=new vs({encode:function(t){return pt.isBuffer(t)?t:pt.from(String(t),"base64")},decode:function(t){return t.toString("base64")},name:"base64"})});var wy=$(gy=>{"use strict";var $R=f(h()),my=or(),Ja=yy(),{Encoding:l1}=Md(),{BufferFormat:f1,ViewFormat:h1,UTF8Format:p1}=Fd(),Ss=Symbol("formats"),Ga=Symbol("encodings"),y1=new Set(["buffer","view","utf8"]),Hd=class{constructor(e){if(Array.isArray(e)){if(!e.every(r=>y1.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[Ga]=new Map,this[Ss]=new Set(e);for(let r in Ja)try{this.encoding(r)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Ga].values()))}encoding(e){let r=this[Ga].get(e);if(r===void 0){if(typeof e=="string"&&e!==""){if(r=b1[e],!r)throw new my(`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=m1(e)}let{name:n,format:i}=r;if(!this[Ss].has(i))if(this[Ss].has("view"))r=r.createViewTranscoder();else if(this[Ss].has("buffer"))r=r.createBufferTranscoder();else if(this[Ss].has("utf8"))r=r.createUTF8Transcoder();else throw new my(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,r.name,r.commonName])this[Ga].set(o,r)}return r}};gy.Transcoder=Hd;function m1(t){if(t instanceof l1)return t;let e="type"in t&&typeof t.type=="string"?t.type:void 0,r=t.name||e||`anonymous-${x1++}`;switch(g1(t)){case"view":return new h1({...t,name:r});case"utf8":return new p1({...t,name:r});case"buffer":return new f1({...t,name:r});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function g1(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 w1={binary:Ja.buffer,"utf-8":Ja.utf8},b1={...Ja,...w1},x1=0});var uo=$((qR,jd)=>{"use strict";var FR=f(h()),co=typeof Reflect=="object"?Reflect:null,by=co&&typeof co.apply=="function"?co.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Ya;co&&typeof co.ownKeys=="function"?Ya=co.ownKeys:Object.getOwnPropertySymbols?Ya=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ya=function(e){return Object.getOwnPropertyNames(e)};function E1(t){console&&console.warn&&console.warn(t)}var Ey=Number.isNaN||function(e){return e!==e};function Ee(){Ee.init.call(this)}jd.exports=Ee;jd.exports.once=A1;Ee.EventEmitter=Ee;Ee.prototype._events=void 0;Ee.prototype._eventsCount=0;Ee.prototype._maxListeners=void 0;var xy=10;function Xa(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(Ee,"defaultMaxListeners",{enumerable:!0,get:function(){return xy},set:function(t){if(typeof t!="number"||t<0||Ey(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");xy=t}});Ee.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};Ee.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ey(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 vy(t){return t._maxListeners===void 0?Ee.defaultMaxListeners:t._maxListeners}Ee.prototype.getMaxListeners=function(){return vy(this)};Ee.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 a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var u=o[e];if(u===void 0)return!1;if(typeof u=="function")by(u,this,r);else for(var d=u.length,c=Iy(u,d),n=0;n<d;++n)by(c[n],this,r);return!0};function Sy(t,e,r,n){var i,o,s;if(Xa(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=vy(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,E1(a)}return t}Ee.prototype.addListener=function(e,r){return Sy(this,e,r,!1)};Ee.prototype.on=Ee.prototype.addListener;Ee.prototype.prependListener=function(e,r){return Sy(this,e,r,!0)};function v1(){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 _y(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=v1.bind(n);return i.listener=r,n.wrapFn=i,i}Ee.prototype.once=function(e,r){return Xa(r),this.on(e,_y(this,e,r)),this};Ee.prototype.prependOnceListener=function(e,r){return Xa(r),this.prependListener(e,_y(this,e,r)),this};Ee.prototype.removeListener=function(e,r){var n,i,o,s,a;if(Xa(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){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():S1(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};Ee.prototype.off=Ee.prototype.removeListener;Ee.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 Ay(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?_1(i):Iy(i,i.length)}Ee.prototype.listeners=function(e){return Ay(this,e,!0)};Ee.prototype.rawListeners=function(e){return Ay(this,e,!1)};Ee.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Ty.call(t,e)};Ee.prototype.listenerCount=Ty;function Ty(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}Ee.prototype.eventNames=function(){return this._eventsCount>0?Ya(this._events):[]};function Iy(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function S1(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function _1(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function A1(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))}Dy(t,e,o,{once:!0}),e!=="error"&&T1(t,i,{once:!0})})}function T1(t,e,r){typeof t.on=="function"&&Dy(t,"error",e,r)}function Dy(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 Ry=$((VR,By)=>{var HR=f(h());By.exports=typeof queueMicrotask=="function"?queueMicrotask:t=>Promise.resolve().then(t)});var _s=$(Wd=>{"use strict";var WR=f(h()),Oy=Ry();Wd.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};Wd.fromPromise=function(t,e){if(e===void 0)return t;t.then(function(r){Oy(()=>e(null,r))}).catch(function(r){Oy(()=>e(r))})}});var Za=$(zd=>{"use strict";var GR=f(h());zd.getCallback=function(t,e){return typeof t=="function"?t:e};zd.getOptions=function(t,e){return typeof t=="object"&&t!==null?t:e!==void 0?e:{}}});var Bn=$(rc=>{"use strict";var YR=f(h()),{fromCallback:Gd}=_s(),Pt=or(),{getOptions:Jd,getCallback:ky}=Za(),di=Symbol("promise"),lo=Symbol("callback"),Sr=Symbol("working"),li=Symbol("handleOne"),Jr=Symbol("handleMany"),Yd=Symbol("autoClose"),In=Symbol("finishWork"),_r=Symbol("returnMany"),_n=Symbol("closing"),As=Symbol("handleClose"),Qa=Symbol("closed"),Ts=Symbol("closeCallbacks"),Tn=Symbol("keyEncoding"),fi=Symbol("valueEncoding"),Xd=Symbol("abortOnClose"),ec=Symbol("legacy"),Zd=Symbol("keys"),Qd=Symbol("values"),An=Symbol("limit"),Gt=Symbol("count"),tc=Object.freeze({}),I1=()=>{},Cy=!1,Is=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[Qa]=!1,this[Ts]=[],this[Sr]=!1,this[_n]=!1,this[Yd]=!1,this[lo]=null,this[li]=this[li].bind(this),this[Jr]=this[Jr].bind(this),this[As]=this[As].bind(this),this[Tn]=r[Tn],this[fi]=r[fi],this[ec]=n,this[An]=Number.isInteger(r.limit)&&r.limit>=0?r.limit:1/0,this[Gt]=0,this[Xd]=!!r.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Gt]}get limit(){return this[An]}next(e){let r;if(e===void 0)r=new Promise((n,i)=>{e=(o,s,a)=>{o?i(o):this[ec]?s===void 0&&a===void 0?n():n([s,a]):n(s)}});else if(typeof e!="function")throw new TypeError("Callback must be a function");return this[_n]?this.nextTick(e,new Pt("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Sr]?this.nextTick(e,new Pt("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Sr]=!0,this[lo]=e,this[Gt]>=this[An]?this.nextTick(this[li],null):this._next(this[li])),r}_next(e){this.nextTick(e)}nextv(e,r,n){return n=ky(r,n),n=Gd(n,di),r=Jd(r,tc),Number.isInteger(e)?(this[_n]?this.nextTick(n,new Pt("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Sr]?this.nextTick(n,new Pt("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[An]<1/0&&(e=Math.min(e,this[An]-this[Gt])),this[Sr]=!0,this[lo]=n,e<=0?this.nextTick(this[Jr],null,[]):this._nextv(e,r,this[Jr])),n[di]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[di])}_nextv(e,r,n){let i=[],o=(s,a,u)=>{if(s)return n(s);if(this[ec]?a===void 0&&u===void 0:a===void 0)return n(null,i);i.push(this[ec]?[a,u]:a),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,r){return r=ky(e,r),r=Gd(r,di),e=Jd(e,tc),this[_n]?this.nextTick(r,new Pt("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Sr]?this.nextTick(r,new Pt("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Sr]=!0,this[lo]=r,this[Yd]=!0,this[Gt]>=this[An]?this.nextTick(this[Jr],null,[]):this._all(e,this[Jr])),r[di]}_all(e,r){let n=this[Gt],i=[],o=()=>{let a=this[An]<1/0?Math.min(1e3,this[An]-n):1e3;a<=0?this.nextTick(r,null,i):this._nextv(a,tc,s)},s=(a,u)=>{a?r(a):u.length===0?r(null,i):(i.push.apply(i,u),n+=u.length,o())};o()}[In](){let e=this[lo];return this[Xd]&&e===null?I1:(this[Sr]=!1,this[lo]=null,this[_n]&&this._close(this[As]),e)}[_r](e,r,n){this[Yd]?this.close(e.bind(null,r,n)):e(r,n)}seek(e,r){if(r=Jd(r,tc),!this[_n]){if(this[Sr])throw new Pt("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(r.keyEncoding||this[Tn]),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 Pt("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=Gd(e,di),this[Qa]?this.nextTick(e):this[_n]?this[Ts].push(e):(this[_n]=!0,this[Ts].push(e),this[Sr]?this[Xd]&&this[In]()(new Pt("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[As])),e[di]}_close(e){this.nextTick(e)}[As](){this[Qa]=!0,this.db.detachResource(this);let e=this[Ts];this[Ts]=[];for(let r of e)r()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Qa]||await this.close()}}},fo=class extends Is{constructor(e,r){super(e,r,!0),this[Zd]=r.keys!==!1,this[Qd]=r.values!==!1}[li](e,r,n){let i=this[In]();if(e)return i(e);try{r=this[Zd]&&r!==void 0?this[Tn].decode(r):void 0,n=this[Qd]&&n!==void 0?this[fi].decode(n):void 0}catch(o){return i(new Dn("entry",o))}r===void 0&&n===void 0||this[Gt]++,i(null,r,n)}[Jr](e,r){let n=this[In]();if(e)return this[_r](n,e);try{for(let i of r){let o=i[0],s=i[1];i[0]=this[Zd]&&o!==void 0?this[Tn].decode(o):void 0,i[1]=this[Qd]&&s!==void 0?this[fi].decode(s):void 0}}catch(i){return this[_r](n,new Dn("entries",i))}this[Gt]+=r.length,this[_r](n,null,r)}end(e){return!Cy&&typeof console<"u"&&(Cy=!0,console.warn(new Pt("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)}},el=class extends Is{constructor(e,r){super(e,r,!1)}[li](e,r){let n=this[In]();if(e)return n(e);try{r=r!==void 0?this[Tn].decode(r):void 0}catch(i){return n(new Dn("key",i))}r!==void 0&&this[Gt]++,n(null,r)}[Jr](e,r){let n=this[In]();if(e)return this[_r](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[Tn].decode(o):void 0}}catch(i){return this[_r](n,new Dn("keys",i))}this[Gt]+=r.length,this[_r](n,null,r)}},tl=class extends Is{constructor(e,r){super(e,r,!1)}[li](e,r){let n=this[In]();if(e)return n(e);try{r=r!==void 0?this[fi].decode(r):void 0}catch(i){return n(new Dn("value",i))}r!==void 0&&this[Gt]++,n(null,r)}[Jr](e,r){let n=this[In]();if(e)return this[_r](n,e);try{for(let i=0;i<r.length;i++){let o=r[i];r[i]=o!==void 0?this[fi].decode(o):void 0}}catch(i){return this[_r](n,new Dn("values",i))}this[Gt]+=r.length,this[_r](n,null,r)}},Dn=class extends Pt{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(fo.prototype,t.split(" ")[0],{get(){throw new Pt(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Pt(`The ${t} has been removed`,{code:"LEVEL_LEGACY"})}});fo.keyEncoding=Tn;fo.valueEncoding=fi;rc.AbstractIterator=fo;rc.AbstractKeyIterator=el;rc.AbstractValueIterator=tl});var Uy=$(rl=>{"use strict";var ZR=f(h()),{AbstractKeyIterator:D1,AbstractValueIterator:B1}=Bn(),hi=Symbol("iterator"),Ds=Symbol("callback"),ho=Symbol("handleOne"),pi=Symbol("handleMany"),Bs=class extends D1{constructor(e,r){super(e,r),this[hi]=e.iterator({...r,keys:!0,values:!1}),this[ho]=this[ho].bind(this),this[pi]=this[pi].bind(this)}},nc=class extends B1{constructor(e,r){super(e,r),this[hi]=e.iterator({...r,keys:!1,values:!0}),this[ho]=this[ho].bind(this),this[pi]=this[pi].bind(this)}};for(let t of[Bs,nc]){let e=t===Bs,r=e?n=>n[0]:n=>n[1];t.prototype._next=function(n){this[Ds]=n,this[hi].next(this[ho])},t.prototype[ho]=function(n,i,o){let s=this[Ds];n?s(n):s(null,e?i:o)},t.prototype._nextv=function(n,i,o){this[Ds]=o,this[hi].nextv(n,i,this[pi])},t.prototype._all=function(n,i){this[Ds]=i,this[hi].all(n,this[pi])},t.prototype[pi]=function(n,i){let o=this[Ds];n?o(n):o(null,i.map(r))},t.prototype._seek=function(n,i){this[hi].seek(n,i)},t.prototype._close=function(n){this[hi].close(n)}}rl.DefaultKeyIterator=Bs;rl.DefaultValueIterator=nc});var Py=$(uc=>{"use strict";var e8=f(h()),{AbstractIterator:R1,AbstractKeyIterator:O1,AbstractValueIterator:k1}=Bn(),nl=or(),Tt=Symbol("nut"),ac=Symbol("undefer"),cc=Symbol("factory"),ic=class extends R1{constructor(e,r){super(e,r),this[Tt]=null,this[cc]=()=>e.iterator(r),this.db.defer(()=>this[ac]())}},oc=class extends O1{constructor(e,r){super(e,r),this[Tt]=null,this[cc]=()=>e.keys(r),this.db.defer(()=>this[ac]())}},sc=class extends k1{constructor(e,r){super(e,r),this[Tt]=null,this[cc]=()=>e.values(r),this.db.defer(()=>this[ac]())}};for(let t of[ic,oc,sc])t.prototype[ac]=function(){this.db.status==="open"&&(this[Tt]=this[cc]())},t.prototype._next=function(e){this[Tt]!==null?this[Tt].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new nl("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._nextv=function(e,r,n){this[Tt]!==null?this[Tt].nextv(e,r,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,r,n)):this.nextTick(n,new nl("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._all=function(e,r){this[Tt]!==null?this[Tt].all(r):this.db.status==="opening"?this.db.defer(()=>this._all(e,r)):this.nextTick(r,new nl("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},t.prototype._seek=function(e,r){this[Tt]!==null?this[Tt]._seek(e,r):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,r))},t.prototype._close=function(e){this[Tt]!==null?this[Tt].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};uc.DeferredIterator=ic;uc.DeferredKeyIterator=oc;uc.DeferredValueIterator=sc});var ol=$(Ly=>{"use strict";var r8=f(h()),{fromCallback:Ky}=_s(),dc=or(),{getCallback:C1,getOptions:U1}=Za(),lc=Symbol("promise"),Jt=Symbol("status"),po=Symbol("operations"),Rs=Symbol("finishClose"),yo=Symbol("closeCallbacks"),il=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[po]=[],this[yo]=[],this[Jt]="open",this[Rs]=this[Rs].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[po].length}put(e,r,n){if(this[Jt]!=="open")throw new dc("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,a=o.keyEncoding(n&&n.keyEncoding),u=o.valueEncoding(n&&n.valueEncoding),d=a.format;n={...n,keyEncoding:d,valueEncoding:u.format},o!==this.db&&(n.sublevel=null);let c=o.prefixKey(a.encode(e),d),l=u.encode(r);return this._put(c,l,n),this[po].push({...s,type:"put",key:e,value:r}),this}_put(e,r,n){}del(e,r){if(this[Jt]!=="open")throw new dc("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),a=s.format;return r={...r,keyEncoding:a},i!==this.db&&(r.sublevel=null),this._del(i.prefixKey(s.encode(e),a),r),this[po].push({...o,type:"del",key:e}),this}_del(e,r){}clear(){if(this[Jt]!=="open")throw new dc("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[po]=[],this}_clear(){}write(e,r){return r=C1(e,r),r=Ky(r,lc),e=U1(e),this[Jt]!=="open"?this.nextTick(r,new dc("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(r):(this[Jt]="writing",this._write(e,n=>{this[Jt]="closing",this[yo].push(()=>r(n)),n||this.db.emit("batch",this[po]),this._close(this[Rs])})),r[lc]}_write(e,r){}close(e){return e=Ky(e,lc),this[Jt]==="closing"?this[yo].push(e):this[Jt]==="closed"?this.nextTick(e):(this[yo].push(e),this[Jt]!=="writing"&&(this[Jt]="closing",this._close(this[Rs]))),e[lc]}_close(e){this.nextTick(e)}[Rs](){this[Jt]="closed",this.db.detachResource(this);let e=this[yo];this[yo]=[];for(let r of e)r()}};Ly.AbstractChainedBatch=il});var Ny=$(My=>{"use strict";var i8=f(h()),{AbstractChainedBatch:P1}=ol(),K1=or(),mo=Symbol("encoded"),sl=class extends P1{constructor(e){super(e),this[mo]=[]}_put(e,r,n){this[mo].push({...n,type:"put",key:e,value:r})}_del(e,r){this[mo].push({...r,type:"del",key:e})}_clear(){this[mo]=[]}_write(e,r){this.db.status==="opening"?this.db.defer(()=>this._write(e,r)):this.db.status==="open"?this[mo].length===0?this.nextTick(r):this.db._batch(this[mo],e,r):this.nextTick(r,new K1("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};My.DefaultChainedBatch=sl});var Fy=$((o8,qy)=>{"use strict";var s8=f(h()),$y=or(),L1=Object.prototype.hasOwnProperty,M1=new Set(["lt","lte","gt","gte"]);qy.exports=function(t,e){let r={};for(let n in t)if(L1.call(t,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new $y(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new $y("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});M1.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 al=$((a8,Hy)=>{var c8=f(h());var Vy;Hy.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):t=>(Vy||(Vy=Promise.resolve())).then(t).catch(e=>setTimeout(()=>{throw e},0))});var zy=$((u8,Wy)=>{"use strict";var d8=f(h()),jy=al();Wy.exports=function(t,...e){e.length===0?jy(t):jy(()=>t(...e))}});var Gy=$(fc=>{"use strict";var f8=f(h()),{AbstractIterator:N1,AbstractKeyIterator:$1,AbstractValueIterator:q1}=Bn(),go=Symbol("unfix"),sr=Symbol("iterator"),yi=Symbol("handleOne"),Rn=Symbol("handleMany"),Yr=Symbol("callback"),Os=class extends N1{constructor(e,r,n,i){super(e,r),this[sr]=n,this[go]=i,this[yi]=this[yi].bind(this),this[Rn]=this[Rn].bind(this),this[Yr]=null}[yi](e,r,n){let i=this[Yr];if(e)return i(e);r!==void 0&&(r=this[go](r)),i(e,r,n)}[Rn](e,r){let n=this[Yr];if(e)return n(e);for(let i of r){let o=i[0];o!==void 0&&(i[0]=this[go](o))}n(e,r)}},ks=class extends $1{constructor(e,r,n,i){super(e,r),this[sr]=n,this[go]=i,this[yi]=this[yi].bind(this),this[Rn]=this[Rn].bind(this),this[Yr]=null}[yi](e,r){let n=this[Yr];if(e)return n(e);r!==void 0&&(r=this[go](r)),n(e,r)}[Rn](e,r){let n=this[Yr];if(e)return n(e);for(let i=0;i<r.length;i++){let o=r[i];o!==void 0&&(r[i]=this[go](o))}n(e,r)}},Cs=class extends q1{constructor(e,r,n){super(e,r),this[sr]=n}};for(let t of[Os,ks])t.prototype._next=function(e){this[Yr]=e,this[sr].next(this[yi])},t.prototype._nextv=function(e,r,n){this[Yr]=n,this[sr].nextv(e,r,this[Rn])},t.prototype._all=function(e,r){this[Yr]=r,this[sr].all(e,this[Rn])};for(let t of[Cs])t.prototype._next=function(e){this[sr].next(e)},t.prototype._nextv=function(e,r,n){this[sr].nextv(e,r,n)},t.prototype._all=function(e,r){this[sr].all(e,r)};for(let t of[Os,ks,Cs])t.prototype._seek=function(e,r){this[sr].seek(e,r)},t.prototype._close=function(e){this[sr].close(e)};fc.AbstractSublevelIterator=Os;fc.AbstractSublevelKeyIterator=ks;fc.AbstractSublevelValueIterator=Cs});var Zy=$((h8,Xy)=>{"use strict";var p8=f(h()),cl=or(),{Buffer:ll}=_t()||{},{AbstractSublevelIterator:F1,AbstractSublevelKeyIterator:V1,AbstractSublevelValueIterator:H1}=Gy(),Xr=Symbol("prefix"),Jy=Symbol("upperBound"),Us=Symbol("prefixRange"),Kt=Symbol("parent"),ul=Symbol("unfix"),Yy=new TextEncoder,j1={separator:"!"};Xy.exports=function({AbstractLevel:t}){class e extends t{static defaults(n){if(typeof n=="string")throw new cl("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new cl("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?j1:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:a,...u}=e.defaults(o);i=z1(i,s);let d=s.charCodeAt(0)+1,c=n[Kt]||n;if(!Yy.encode(i).every(w=>w>d&&w<127))throw new cl(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(W1(c,a),u);let l=(n.prefix||"")+s+i+s,g=l.slice(0,-1)+String.fromCharCode(d);this[Kt]=c,this[Xr]=new hc(l),this[Jy]=new hc(g),this[ul]=new fl,this.nextTick=c.nextTick}prefixKey(n,i){if(i==="utf8")return this[Xr].utf8+n;if(n.byteLength===0)return this[Xr][i];if(i==="view"){let o=this[Xr].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Xr].buffer;return ll.concat([o,n],o.byteLength+n.byteLength)}}[Us](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[Xr][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[Jy][i]}get prefix(){return this[Xr].utf8}get db(){return this[Kt]}_open(n,i){this[Kt].open({passive:!0},i)}_put(n,i,o,s){this[Kt].put(n,i,o,s)}_get(n,i,o){this[Kt].get(n,i,o)}_getMany(n,i,o){this[Kt].getMany(n,i,o)}_del(n,i,o){this[Kt].del(n,i,o)}_batch(n,i,o){this[Kt].batch(n,i,o)}_clear(n,i){this[Us](n,n.keyEncoding),this[Kt].clear(n,i)}_iterator(n){this[Us](n,n.keyEncoding);let i=this[Kt].iterator(n),o=this[ul].get(this[Xr].utf8.length,n.keyEncoding);return new F1(this,n,i,o)}_keys(n){this[Us](n,n.keyEncoding);let i=this[Kt].keys(n),o=this[ul].get(this[Xr].utf8.length,n.keyEncoding);return new V1(this,n,i,o)}_values(n){this[Us](n,n.keyEncoding);let i=this[Kt].values(n);return new H1(this,n,i)}}return{AbstractSublevel:e}};var W1=function(t,e){return{...t.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:dl(t,"utf8"),buffer:dl(t,"buffer"),view:dl(t,"view")}}},dl=function(t,e){return t.supports.encodings[e]?t.keyEncoding(e).name===e:!1},hc=class{constructor(e){this.utf8=e,this.view=Yy.encode(e),this.buffer=ll?ll.from(this.view.buffer,0,this.view.byteLength):{}}},fl=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}},z1=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 gl=$(ml=>{"use strict";var m8=f(h()),{supports:G1}=cy(),{Transcoder:J1}=wy(),{EventEmitter:Y1}=uo(),{fromCallback:On}=_s(),ar=or(),{AbstractIterator:mi}=Bn(),{DefaultKeyIterator:X1,DefaultValueIterator:Z1}=Uy(),{DeferredIterator:Q1,DeferredKeyIterator:ev,DeferredValueIterator:tv}=Py(),{DefaultChainedBatch:Qy}=Ny(),{getCallback:gi,getOptions:kn}=Za(),pc=Fy(),ue=Symbol("promise"),Zr=Symbol("landed"),wi=Symbol("resources"),hl=Symbol("closeResources"),Ps=Symbol("operations"),Ks=Symbol("undefer"),yc=Symbol("deferOpen"),e0=Symbol("options"),fe=Symbol("status"),bi=Symbol("defaultOptions"),wo=Symbol("transcoder"),mc=Symbol("keyEncoding"),pl=Symbol("valueEncoding"),rv=()=>{},Ls=class extends Y1{constructor(e,r){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");r=kn(r);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=r;this[wi]=new Set,this[Ps]=[],this[yc]=!0,this[e0]=s,this[fe]="opening",this.supports=G1(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[wo]=new J1(nv(this)),this[mc]=this[wo].encoding(n||"utf8"),this[pl]=this[wo].encoding(i||"utf8");for(let a of this[wo].encodings())this.supports.encodings[a.commonName]||(this.supports.encodings[a.commonName]=!0);this[bi]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[mc].commonName,valueEncoding:this[pl].commonName}),key:Object.freeze({keyEncoding:this[mc].commonName})},this.nextTick(()=>{this[yc]&&this.open({passive:!1},rv)})}get status(){return this[fe]}keyEncoding(e){return this[wo].encoding(e??this[mc])}valueEncoding(e){return this[wo].encoding(e??this[pl])}open(e,r){r=gi(e,r),r=On(r,ue),e={...this[e0],...kn(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[fe]==="closing"||this[fe]==="opening"?this.once(Zr,i?()=>n(i):n):this[fe]!=="open"?r(new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):r()};return e.passive?this[fe]==="opening"?this.once(Zr,n):this.nextTick(n):this[fe]==="closed"||this[yc]?(this[yc]=!1,this[fe]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[fe]="closed",this[hl](()=>{this.emit(Zr),n(i)}),this[Ks]();return}this[fe]="open",this[Ks](),this.emit(Zr),this[fe]==="open"&&this.emit("open"),this[fe]==="open"&&this.emit("ready"),n()})):this[fe]==="open"?this.nextTick(n):this.once(Zr,()=>this.open(e,r)),r[ue]}_open(e,r){this.nextTick(r)}close(e){e=On(e,ue);let r=n=>{this[fe]==="opening"||this[fe]==="closing"?this.once(Zr,n?r(n):r):this[fe]!=="closed"?e(new ar("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[fe]==="open"){this[fe]="closing",this.emit("closing");let n=i=>{this[fe]="open",this[Ks](),this.emit(Zr),r(i)};this[hl](()=>{this._close(i=>{if(i)return n(i);this[fe]="closed",this[Ks](),this.emit(Zr),this[fe]==="closed"&&this.emit("closed"),r()})})}else this[fe]==="closed"?this.nextTick(r):this.once(Zr,()=>this.close(e));return e[ue]}[hl](e){if(this[wi].size===0)return this.nextTick(e);let r=this[wi].size,n=!0,i=()=>{--r===0&&(n?this.nextTick(e):e())};for(let o of this[wi])o.close(i);n=!1,this[wi].clear()}_close(e){this.nextTick(e)}get(e,r,n){if(n=gi(r,n),n=On(n,ue),r=kn(r,this[bi].entry),this[fe]==="opening")return this.defer(()=>this.get(e,r,n)),n[ue];if(bo(this,n))return n[ue];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ue];let o=this.keyEncoding(r.keyEncoding),s=this.valueEncoding(r.valueEncoding),a=o.format,u=s.format;return(r.keyEncoding!==a||r.valueEncoding!==u)&&(r=Object.assign({},r,{keyEncoding:a,valueEncoding:u})),this._get(this.prefixKey(o.encode(e),a),r,(d,c)=>{if(d)return(d.code==="LEVEL_NOT_FOUND"||d.notFound||/NotFound/i.test(d))&&(d.code||(d.code="LEVEL_NOT_FOUND"),d.notFound||(d.notFound=!0),d.status||(d.status=404)),n(d);try{c=s.decode(c)}catch(l){return n(new ar("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,c)}),n[ue]}_get(e,r,n){this.nextTick(n,new Error("NotFound"))}getMany(e,r,n){if(n=gi(r,n),n=On(n,ue),r=kn(r,this[bi].entry),this[fe]==="opening")return this.defer(()=>this.getMany(e,r,n)),n[ue];if(bo(this,n))return n[ue];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[ue];if(e.length===0)return this.nextTick(n,null,[]),n[ue];let i=this.keyEncoding(r.keyEncoding),o=this.valueEncoding(r.valueEncoding),s=i.format,a=o.format;(r.keyEncoding!==s||r.valueEncoding!==a)&&(r=Object.assign({},r,{keyEncoding:s,valueEncoding:a}));let u=new Array(e.length);for(let d=0;d<e.length;d++){let c=e[d],l=this._checkKey(c);if(l)return this.nextTick(n,l),n[ue];u[d]=this.prefixKey(i.encode(c),s)}return this._getMany(u,r,(d,c)=>{if(d)return n(d);try{for(let l=0;l<c.length;l++)c[l]!==void 0&&(c[l]=o.decode(c[l]))}catch(l){return n(new ar(`Could not decode one or more of ${c.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,c)}),n[ue]}_getMany(e,r,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,r,n,i){if(i=gi(n,i),i=On(i,ue),n=kn(n,this[bi].entry),this[fe]==="opening")return this.defer(()=>this.put(e,r,n,i)),i[ue];if(bo(this,i))return i[ue];let o=this._checkKey(e)||this._checkValue(r);if(o)return this.nextTick(i,o),i[ue];let s=this.keyEncoding(n.keyEncoding),a=this.valueEncoding(n.valueEncoding),u=s.format,d=a.format;(n.keyEncoding!==u||n.valueEncoding!==d)&&(n=Object.assign({},n,{keyEncoding:u,valueEncoding:d}));let c=this.prefixKey(s.encode(e),u),l=a.encode(r);return this._put(c,l,n,g=>{if(g)return i(g);this.emit("put",e,r),i()}),i[ue]}_put(e,r,n,i){this.nextTick(i)}del(e,r,n){if(n=gi(r,n),n=On(n,ue),r=kn(r,this[bi].key),this[fe]==="opening")return this.defer(()=>this.del(e,r,n)),n[ue];if(bo(this,n))return n[ue];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ue];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,a=>{if(a)return n(a);this.emit("del",e),n()}),n[ue]}_del(e,r,n){this.nextTick(n)}batch(e,r,n){if(!arguments.length){if(this[fe]==="opening")return new Qy(this);if(this[fe]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=gi(r,n),n=On(n,ue),r=kn(r,this[bi].empty),this[fe]==="opening")return this.defer(()=>this.batch(e,r,n)),n[ue];if(bo(this,n))return n[ue];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[ue];if(e.length===0)return this.nextTick(n),n[ue];let i=new Array(e.length),{keyEncoding:o,valueEncoding:s,...a}=r;for(let u=0;u<e.length;u++){if(typeof e[u]!="object"||e[u]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[ue];let d=Object.assign({},e[u]);if(d.type!=="put"&&d.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[ue];let c=this._checkKey(d.key);if(c)return this.nextTick(n,c),n[ue];let l=d.sublevel!=null?d.sublevel:this,g=l.keyEncoding(d.keyEncoding||o),w=g.format;if(d.key=l.prefixKey(g.encode(d.key),w),d.keyEncoding=w,d.type==="put"){let m=this._checkValue(d.value);if(m)return this.nextTick(n,m),n[ue];let y=l.valueEncoding(d.valueEncoding||s);d.value=y.encode(d.value),d.valueEncoding=y.format}l!==this&&(d.sublevel=null),i[u]=d}return this._batch(i,a,u=>{if(u)return n(u);this.emit("batch",e),n()}),n[ue]}_batch(e,r,n){this.nextTick(n)}sublevel(e,r){return this._sublevel(e,yl.defaults(r))}_sublevel(e,r){return new yl(this,e,r)}prefixKey(e,r){return e}clear(e,r){if(r=gi(e,r),r=On(r,ue),e=kn(e,this[bi].empty),this[fe]==="opening")return this.defer(()=>this.clear(e,r)),r[ue];if(bo(this,r))return r[ue];let n=e,i=this.keyEncoding(e.keyEncoding);return e=pc(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[ue]}_clear(e,r){this.nextTick(r)}iterator(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=pc(e,r),e.keys=e.keys!==!1,e.values=e.values!==!1,e[mi.keyEncoding]=r,e[mi.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[fe]==="opening")return new Q1(this,e);if(this[fe]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new mi(this,e)}keys(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=pc(e,r),e[mi.keyEncoding]=r,e[mi.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[fe]==="opening")return new ev(this,e);if(this[fe]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new X1(this,e)}values(e){let r=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=pc(e,r),e[mi.keyEncoding]=r,e[mi.valueEncoding]=n,e.keyEncoding=r.format,e.valueEncoding=n.format,this[fe]==="opening")return new tv(this,e);if(this[fe]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new Z1(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[Ps].push(e)}[Ks](){if(this[Ps].length===0)return;let e=this[Ps];this[Ps]=[];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[wi].add(e)}detachResource(e){this[wi].delete(e)}_chainedBatch(){return new Qy(this)}_checkKey(e){if(e==null)return new ar("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new ar("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Ls.prototype.nextTick=zy();var{AbstractSublevel:yl}=Zy()({AbstractLevel:Ls});ml.AbstractLevel=Ls;ml.AbstractSublevel=yl;var bo=function(t,e){return t[fe]!=="open"?(t.nextTick(e,new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},nv=function(t){return Object.keys(t.supports.encodings).filter(e=>!!t.supports.encodings[e])}});var wl=$(xi=>{"use strict";var w8=f(h());xi.AbstractLevel=gl().AbstractLevel;xi.AbstractSublevel=gl().AbstractSublevel;xi.AbstractIterator=Bn().AbstractIterator;xi.AbstractKeyIterator=Bn().AbstractKeyIterator;xi.AbstractValueIterator=Bn().AbstractValueIterator;xi.AbstractChainedBatch=ol().AbstractChainedBatch});var r0=$((b8,t0)=>{var x8=f(h());t0.exports=ov;var iv=al();function ov(t,e,r){if(typeof e!="number")throw new Error("second argument must be a Number");let n,i,o,s,a,u=!0,d;Array.isArray(t)?(n=[],o=i=t.length):(s=Object.keys(t),n={},o=i=s.length);function c(g){function w(){r&&r(g,n),r=null}u?iv(w):w()}function l(g,w,m){if(n[g]=m,w&&(a=!0),--o===0||w)c(w);else if(!a&&d<i){let y;s?(y=s[d],d+=1,t[y](function(E,v){l(y,E,v)})):(y=d,d+=1,t[y](function(E,v){l(y,E,v)}))}}d=e,o?s?s.some(function(g,w){return t[g](function(m,y){l(g,m,y)}),w===e-1}):t.some(function(g,w){return g(function(m,y){l(w,m,y)}),w===e-1}):c(null),u=!1}});var bl=$((E8,n0)=>{"use strict";var v8=f(h());n0.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 xl=$((S8,i0)=>{"use strict";var _8=f(h()),sv=new TextEncoder;i0.exports=function(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):sv.encode(t)}});var u0=$(c0=>{"use strict";var T8=f(h()),{AbstractIterator:av}=wl(),o0=bl(),gc=xl(),Ar=Symbol("cache"),Qr=Symbol("finished"),Lt=Symbol("options"),en=Symbol("currentOptions"),Ei=Symbol("position"),El=Symbol("location"),xo=Symbol("first"),s0={},vl=class extends av{constructor(e,r,n){super(e,n),this[Ar]=[],this[Qr]=this.limit===0,this[Lt]=n,this[en]={...n},this[Ei]=void 0,this[El]=r,this[xo]=!0}_nextv(e,r,n){if(this[xo]=!1,this[Qr])return this.nextTick(n,null,[]);if(this[Ar].length>0)return e=Math.min(e,this[Ar].length),this.nextTick(n,null,this[Ar].splice(0,e));this[Ei]!==void 0&&(this[Lt].reverse?(this[en].lt=this[Ei],this[en].lte=void 0):(this[en].gt=this[Ei],this[en].gte=void 0));let i;try{i=o0(this[en])}catch{return this[Qr]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[El]],"readonly"),s=o.objectStore(this[El]),a=[];if(this[Lt].reverse){let u=!this[Lt].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[u](i,"prev").onsuccess=d=>{let c=d.target.result;if(c){let{key:l,value:g}=c;this[Ei]=l,a.push([this[Lt].keys&&l!==void 0?gc(l):void 0,this[Lt].values&&g!==void 0?gc(g):void 0]),a.length<e?c.continue():a0(o)}else this[Qr]=!0}}else{let u,d,c=()=>{if(u===void 0||d===void 0)return;let l=Math.max(u.length,d.length);l===0||e===1/0?this[Qr]=!0:this[Ei]=u[l-1],a.length=l;for(let g=0;g<l;g++){let w=u[g],m=d[g];a[g]=[this[Lt].keys&&w!==void 0?gc(w):void 0,this[Lt].values&&m!==void 0?gc(m):void 0]}a0(o)};this[Lt].keys||e<1/0?s.getAllKeys(i,e<1/0?e:void 0).onsuccess=l=>{u=l.target.result,c()}:(u=[],this.nextTick(c)),this[Lt].values?s.getAll(i,e<1/0?e:void 0).onsuccess=l=>{d=l.target.result,c()}:(d=[],this.nextTick(c))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,a),n=null}}_next(e){if(this[Ar].length>0){let[r,n]=this[Ar].shift();this.nextTick(e,null,r,n)}else if(this[Qr])this.nextTick(e);else{let r=Math.min(100,this.limit-this.count);this[xo]&&(this[xo]=!1,r=1),this._nextv(r,s0,(n,i)=>{if(n)return e(n);this[Ar]=i,this._next(e)})}}_all(e,r){this[xo]=!1;let n=this[Ar].splice(0,this[Ar].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(r,null,n);this._nextv(i,s0,(o,s)=>{if(o)return r(o);n.length>0&&(s=n.concat(s)),r(null,s)})}_seek(e,r){this[xo]=!0,this[Ar]=[],this[Qr]=!1,this[Ei]=void 0,this[en]={...this[Lt]};let n;try{n=o0(this[Lt])}catch{this[Qr]=!0;return}n!==null&&!n.includes(e)?this[Qr]=!0:this[Lt].reverse?this[en].lte=e:this[en].gte=e}};c0.Iterator=vl;function a0(t){typeof t.commit=="function"&&t.commit()}});var l0=$((I8,d0)=>{"use strict";var D8=f(h());d0.exports=function(e,r,n,i,o){if(i.limit===0)return e.nextTick(o);let s=e.db.transaction([r],"readwrite"),a=s.objectStore(r),u=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let d=a.openKeyCursor?"openKeyCursor":"openCursor",c=i.reverse?"prev":"next";a[d](n,c).onsuccess=function(l){let g=l.target.result;g&&(a.delete(g.key).onsuccess=function(){(i.limit<=0||++u<i.limit)&&g.continue()})}}});var g0=$(m0=>{"use strict";var R8=f(h()),{AbstractLevel:cv}=wl(),f0=or(),uv=r0(),{fromCallback:dv}=_s(),{Iterator:lv}=u0(),h0=xl(),fv=l0(),hv=bl(),y0="level-js-",Ms=Symbol("idb"),Sl=Symbol("namePrefix"),tn=Symbol("location"),_l=Symbol("version"),vi=Symbol("store"),Ns=Symbol("onComplete"),p0=Symbol("promise"),wc=class extends cv{constructor(e,r,n){if(typeof r=="function"||typeof n=="function")throw new f0("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[tn]=e,this[Sl]=i??y0,this[_l]=parseInt(o||1,10),this[Ms]=null}get location(){return this[tn]}get namePrefix(){return this[Sl]}get version(){return this[_l]}get db(){return this[Ms]}get type(){return"browser-level"}_open(e,r){let n=indexedDB.open(this[Sl]+this[tn],this[_l]);n.onerror=function(){r(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[Ms]=n.result,r()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[tn])||o.createObjectStore(this[tn])}}[vi](e){return this[Ms].transaction([this[tn]],e).objectStore(this[tn])}[Ns](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[vi]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Ns](o,function(s,a){if(s)return n(s);if(a===void 0)return n(new f0("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,h0(a))})}_getMany(e,r,n){let i=this[vi]("readonly"),o=e.map(s=>a=>{let u;try{u=i.get(s)}catch(d){return a(d)}u.onsuccess=()=>{let d=u.result;a(null,d===void 0?d:h0(d))},u.onerror=d=>{d.stopPropagation(),a(u.error)}});uv(o,16,n)}_del(e,r,n){let i=this[vi]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Ns](o,n)}_put(e,r,n,i){let o=this[vi]("readwrite"),s;try{s=o.put(r,e)}catch(a){return this.nextTick(i,a)}this[Ns](s,i)}_iterator(e){return new lv(this,this[tn],e)}_batch(e,r,n){let i=this[vi]("readwrite"),o=i.transaction,s=0,a;o.onabort=function(){n(a||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function u(){let d=e[s++],c=d.key,l;try{l=d.type==="del"?i.delete(c):i.put(d.value,c)}catch(g){a=g,o.abort();return}s<e.length?l.onsuccess=u:typeof o.commit=="function"&&o.commit()}u()}_clear(e,r){let n,i;try{n=hv(e)}catch{return this.nextTick(r)}if(e.limit>=0)return fv(this,this[tn],n,e,r);try{let o=this[vi]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(r,o)}this[Ns](i,r)}_close(e){this[Ms].close(),this.nextTick(e)}};wc.destroy=function(t,e,r){typeof e=="function"&&(r=e,e=y0),r=dv(r,p0);let n=indexedDB.deleteDatabase(e+t);return n.onsuccess=function(){r()},n.onerror=function(i){r(i)},r[p0]};m0.BrowserLevel=wc});var Al=$(w0=>{var k8=f(h());w0.Level=g0().BrowserLevel});var Le=$((M8,b0)=>{"use strict";var N8=f(h());b0.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 Eo=$(($8,xc)=>{"use strict";var q8=f(h()),{AbortController:x0,AbortSignal:yv}=typeof self<"u"?self:typeof window<"u"?window:void 0;xc.exports=x0;xc.exports.AbortSignal=yv;xc.exports.default=x0});var yt=$((F8,Il)=>{"use strict";var V8=f(h()),mv=_t(),{kResistStopPropagation:gv,SymbolDispose:wv}=Le(),bv=globalThis.AbortSignal||Eo().AbortSignal,xv=globalThis.AbortController||Eo().AbortController,Ev=Object.getPrototypeOf(async function(){}).constructor,E0=globalThis.Blob||mv.Blob,vv=typeof E0<"u"?function(e){return e instanceof E0}:function(e){return!1},v0=(t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new ERR_INVALID_ARG_TYPE(e,"AbortSignal",t)},Sv=(t,e)=>{if(typeof t!="function")throw new ERR_INVALID_ARG_TYPE(e,"Function",t)},Tl=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}};Il.exports={AggregateError:Tl,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 Ev},isArrayBufferView(t){return ArrayBuffer.isView(t)}},isBlob:vv,deprecate(t,e){return t},addAbortListener:uo().addAbortListener||function(e,r){if(e===void 0)throw new ERR_INVALID_ARG_TYPE("signal","AbortSignal",e);v0(e,"signal"),Sv(r,"listener");let n;return e.aborted?queueMicrotask(()=>r()):(e.addEventListener("abort",r,{__proto__:null,once:!0,[gv]:!0}),n=()=>{e.removeEventListener("abort",r)}),{__proto__:null,[wv](){var i;(i=n)===null||i===void 0||i()}}},AbortSignalAny:bv.any||function(e){if(e.length===1)return e[0];let r=new xv,n=()=>r.abort();return e.forEach(i=>{v0(i,"signals"),i.addEventListener("abort",n,{once:!0})}),r.signal.addEventListener("abort",()=>{e.forEach(i=>i.removeEventListener("abort",n))},{once:!0}),r.signal}};Il.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")});var bt=$((H8,A0)=>{"use strict";var j8=f(h()),{format:_v,inspect:Ec,AggregateError:Av}=yt(),Tv=globalThis.AggregateError||Av,Iv=Symbol("kIsNodeError"),Dv=["string","function","number","object","Function","Object","boolean","bigint","symbol"],Bv=/^([A-Z][a-z0-9]*)+$/,Rv="__node_internal_",vc={};function _i(t,e){if(!t)throw new vc.ERR_INTERNAL_ASSERTION(e)}function S0(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 Ov(t,e,r){if(typeof e=="function")return _i(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 _i(n===r.length,`Code: ${t}; The provided arguments length (${r.length}) does not match the required ones (${n}).`),r.length===0?e:_v(e,...r)}function at(t,e,r){r||(r=Error);class n extends r{constructor(...o){super(Ov(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[Iv]=!0,vc[t]=n}function _0(t){let e=Rv+t.name;return Object.defineProperty(t,"name",{value:e}),t}function kv(t,e){if(t&&e&&t!==e){if(Array.isArray(e.errors))return e.errors.push(t),e;let r=new Tv([e,t],e.message);return r.code=e.code,r}return t||e}var Dl=class extends Error{constructor(e="The operation was aborted",r=void 0){if(r!==void 0&&typeof r!="object")throw new vc.ERR_INVALID_ARG_TYPE("options","Object",r);super(e,r),this.code="ABORT_ERR",this.name="AbortError"}};at("ERR_ASSERTION","%s",Error);at("ERR_INVALID_ARG_TYPE",(t,e,r)=>{_i(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 u of e)_i(typeof u=="string","All expected entries have to be of type string"),Dv.includes(u)?i.push(u.toLowerCase()):Bv.test(u)?o.push(u):(_i(u!=="object",'The value "object" should be written as "Object"'),s.push(u));if(o.length>0){let u=i.indexOf("object");u!==-1&&(i.splice(i,u,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 u=i.pop();n+=`one of type ${i.join(", ")}, or ${u}`}}(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 u=o.pop();n+=`an instance of ${o.join(", ")}, or ${u}`}}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 u=s.pop();n+=`one of ${s.join(", ")}, or ${u}`}}if(r==null)n+=`. Received ${r}`;else if(typeof r=="function"&&r.name)n+=`. Received function ${r.name}`;else if(typeof r=="object"){var a;if((a=r.constructor)!==null&&a!==void 0&&a.name)n+=`. Received an instance of ${r.constructor.name}`;else{let u=Ec(r,{depth:-1});n+=`. Received ${u}`}}else{let u=Ec(r,{colors:!1});u.length>25&&(u=`${u.slice(0,25)}...`),n+=`. Received type ${typeof r} (${u})`}return n},TypeError);at("ERR_INVALID_ARG_VALUE",(t,e,r="is invalid")=>{let n=Ec(e);return n.length>128&&(n=n.slice(0,128)+"..."),`The ${t.includes(".")?"property":"argument"} '${t}' ${r}. Received ${n}`},TypeError);at("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);at("ERR_MISSING_ARGS",(...t)=>{_i(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);at("ERR_OUT_OF_RANGE",(t,e,r)=>{_i(e,'Missing "range" argument');let n;return Number.isInteger(r)&&Math.abs(r)>2**32?n=S0(String(r)):typeof r=="bigint"?(n=String(r),(r>2n**32n||r<-(2n**32n))&&(n=S0(n)),n+="n"):n=Ec(r),`The value of "${t}" is out of range. It must be ${e}. Received ${n}`},RangeError);at("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error);at("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error);at("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error);at("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error);at("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error);at("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);at("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error);at("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error);at("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error);at("ERR_STREAM_WRITE_AFTER_END","write after end",Error);at("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError);A0.exports={AbortError:Dl,aggregateTwoErrors:_0(kv),hideStackFrames:_0,codes:vc}});var So=$((W8,P0)=>{"use strict";var z8=f(h()),{ArrayIsArray:Rl,ArrayPrototypeIncludes:B0,ArrayPrototypeJoin:R0,ArrayPrototypeMap:Cv,NumberIsInteger:Ol,NumberIsNaN:Uv,NumberMAX_SAFE_INTEGER:Pv,NumberMIN_SAFE_INTEGER:Kv,NumberParseInt:Lv,ObjectPrototypeHasOwnProperty:Mv,RegExpPrototypeExec:O0,String:Nv,StringPrototypeToUpperCase:$v,StringPrototypeTrim:qv}=Le(),{hideStackFrames:Yt,codes:{ERR_SOCKET_BAD_PORT:Fv,ERR_INVALID_ARG_TYPE:mt,ERR_INVALID_ARG_VALUE:vo,ERR_OUT_OF_RANGE:Ai,ERR_UNKNOWN_SIGNAL:T0}}=bt(),{normalizeEncoding:Vv}=yt(),{isAsyncFunction:Hv,isArrayBufferView:jv}=yt().types,I0={};function Wv(t){return t===(t|0)}function zv(t){return t===t>>>0}var Gv=/^[0-7]+$/,Jv="must be a 32-bit unsigned integer or an octal string";function Yv(t,e,r){if(typeof t>"u"&&(t=r),typeof t=="string"){if(O0(Gv,t)===null)throw new vo(e,t,Jv);t=Lv(t,8)}return k0(t,e),t}var Xv=Yt((t,e,r=Kv,n=Pv)=>{if(typeof t!="number")throw new mt(e,"number",t);if(!Ol(t))throw new Ai(e,"an integer",t);if(t<r||t>n)throw new Ai(e,`>= ${r} && <= ${n}`,t)}),Zv=Yt((t,e,r=-2147483648,n=2147483647)=>{if(typeof t!="number")throw new mt(e,"number",t);if(!Ol(t))throw new Ai(e,"an integer",t);if(t<r||t>n)throw new Ai(e,`>= ${r} && <= ${n}`,t)}),k0=Yt((t,e,r=!1)=>{if(typeof t!="number")throw new mt(e,"number",t);if(!Ol(t))throw new Ai(e,"an integer",t);let n=r?1:0,i=4294967295;if(t<n||t>i)throw new Ai(e,`>= ${n} && <= ${i}`,t)});function kl(t,e){if(typeof t!="string")throw new mt(e,"string",t)}function Qv(t,e,r=void 0,n){if(typeof t!="number")throw new mt(e,"number",t);if(r!=null&&t<r||n!=null&&t>n||(r!=null||n!=null)&&Uv(t))throw new Ai(e,`${r!=null?`>= ${r}`:""}${r!=null&&n!=null?" && ":""}${n!=null?`<= ${n}`:""}`,t)}var e2=Yt((t,e,r)=>{if(!B0(r,t)){let i="must be one of: "+R0(Cv(r,o=>typeof o=="string"?`'${o}'`:Nv(o)),", ");throw new vo(e,t,i)}});function C0(t,e){if(typeof t!="boolean")throw new mt(e,"boolean",t)}function Bl(t,e,r){return t==null||!Mv(t,e)?r:t[e]}var t2=Yt((t,e,r=null)=>{let n=Bl(r,"allowArray",!1),i=Bl(r,"allowFunction",!1);if(!Bl(r,"nullable",!1)&&t===null||!n&&Rl(t)||typeof t!="object"&&(!i||typeof t!="function"))throw new mt(e,"Object",t)}),r2=Yt((t,e)=>{if(t!=null&&typeof t!="object"&&typeof t!="function")throw new mt(e,"a dictionary",t)}),Sc=Yt((t,e,r=0)=>{if(!Rl(t))throw new mt(e,"Array",t);if(t.length<r){let n=`must be longer than ${r}`;throw new vo(e,t,n)}});function n2(t,e){Sc(t,e);for(let r=0;r<t.length;r++)kl(t[r],`${e}[${r}]`)}function i2(t,e){Sc(t,e);for(let r=0;r<t.length;r++)C0(t[r],`${e}[${r}]`)}function o2(t,e){Sc(t,e);for(let r=0;r<t.length;r++){let n=t[r],i=`${e}[${r}]`;if(n==null)throw new mt(i,"AbortSignal",n);U0(n,i)}}function s2(t,e="signal"){if(kl(t,e),I0[t]===void 0)throw I0[$v(t)]!==void 0?new T0(t+" (signals must use all capital letters)"):new T0(t)}var a2=Yt((t,e="buffer")=>{if(!jv(t))throw new mt(e,["Buffer","TypedArray","DataView"],t)});function c2(t,e){let r=Vv(e),n=t.length;if(r==="hex"&&n%2!==0)throw new vo("encoding",e,`is invalid for data of length ${n}`)}function u2(t,e="Port",r=!0){if(typeof t!="number"&&typeof t!="string"||typeof t=="string"&&qv(t).length===0||+t!==+t>>>0||t>65535||t===0&&!r)throw new Fv(e,t,r);return t|0}var U0=Yt((t,e)=>{if(t!==void 0&&(t===null||typeof t!="object"||!("aborted"in t)))throw new mt(e,"AbortSignal",t)}),d2=Yt((t,e)=>{if(typeof t!="function")throw new mt(e,"Function",t)}),l2=Yt((t,e)=>{if(typeof t!="function"||Hv(t))throw new mt(e,"Function",t)}),f2=Yt((t,e)=>{if(t!==void 0)throw new mt(e,"undefined",t)});function h2(t,e,r){if(!B0(r,t))throw new mt(e,`('${R0(r,"|")}')`,t)}var p2=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function D0(t,e){if(typeof t>"u"||!O0(p2,t))throw new vo(e,t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}function y2(t){if(typeof t=="string")return D0(t,"hints"),t;if(Rl(t)){let e=t.length,r="";if(e===0)return r;for(let n=0;n<e;n++){let i=t[n];D0(i,"hints"),r+=i,n!==e-1&&(r+=", ")}return r}throw new vo("hints",t,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}P0.exports={isInt32:Wv,isUint32:zv,parseFileMode:Yv,validateArray:Sc,validateStringArray:n2,validateBooleanArray:i2,validateAbortSignalArray:o2,validateBoolean:C0,validateBuffer:a2,validateDictionary:r2,validateEncoding:c2,validateFunction:d2,validateInt32:Zv,validateInteger:Xv,validateNumber:Qv,validateObject:t2,validateOneOf:e2,validatePlainFunction:l2,validatePort:u2,validateSignalName:s2,validateString:kl,validateUint32:k0,validateUndefined:f2,validateUnion:h2,validateAbortSignal:U0,validateLinkHeaderValue:y2}});var Cn=$((G8,N0)=>{var J8=f(h()),qe=N0.exports={},Tr,Ir;function Cl(){throw new Error("setTimeout has not been defined")}function Ul(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?Tr=setTimeout:Tr=Cl}catch{Tr=Cl}try{typeof clearTimeout=="function"?Ir=clearTimeout:Ir=Ul}catch{Ir=Ul}})();function K0(t){if(Tr===setTimeout)return setTimeout(t,0);if((Tr===Cl||!Tr)&&setTimeout)return Tr=setTimeout,setTimeout(t,0);try{return Tr(t,0)}catch{try{return Tr.call(null,t,0)}catch{return Tr.call(this,t,0)}}}function m2(t){if(Ir===clearTimeout)return clearTimeout(t);if((Ir===Ul||!Ir)&&clearTimeout)return Ir=clearTimeout,clearTimeout(t);try{return Ir(t)}catch{try{return Ir.call(null,t)}catch{return Ir.call(this,t)}}}var rn=[],_o=!1,Ti,_c=-1;function g2(){!_o||!Ti||(_o=!1,Ti.length?rn=Ti.concat(rn):_c=-1,rn.length&&L0())}function L0(){if(!_o){var t=K0(g2);_o=!0;for(var e=rn.length;e;){for(Ti=rn,rn=[];++_c<e;)Ti&&Ti[_c].run();_c=-1,e=rn.length}Ti=null,_o=!1,m2(t)}}qe.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];rn.push(new M0(t,e)),rn.length===1&&!_o&&K0(L0)};function M0(t,e){this.fun=t,this.array=e}M0.prototype.run=function(){this.fun.apply(null,this.array)};qe.title="browser";qe.browser=!0;qe.env={};qe.argv=[];qe.version="";qe.versions={};function nn(){}qe.on=nn;qe.addListener=nn;qe.once=nn;qe.off=nn;qe.removeListener=nn;qe.removeAllListeners=nn;qe.emit=nn;qe.prependListener=nn;qe.prependOnceListener=nn;qe.listeners=function(t){return[]};qe.binding=function(t){throw new Error("process.binding is not supported")};qe.cwd=function(){return"/"};qe.chdir=function(t){throw new Error("process.chdir is not supported")};qe.umask=function(){return 0}});var Br=$((Y8,em)=>{"use strict";var X8=f(h()),{SymbolAsyncIterator:$0,SymbolIterator:q0,SymbolFor:Ii}=Le(),F0=Ii("nodejs.stream.destroyed"),V0=Ii("nodejs.stream.errored"),Pl=Ii("nodejs.stream.readable"),Kl=Ii("nodejs.stream.writable"),H0=Ii("nodejs.stream.disturbed"),w2=Ii("nodejs.webstream.isClosedPromise"),b2=Ii("nodejs.webstream.controllerErrorFunction");function Ac(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 Tc(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 x2(t){return!!(t&&typeof t.pipe=="function"&&t._readableState&&typeof t.on=="function"&&typeof t.write=="function")}function Dr(t){return t&&(t._readableState||t._writableState||typeof t.write=="function"&&typeof t.on=="function"||typeof t.pipe=="function"&&typeof t.on=="function")}function j0(t){return!!(t&&!Dr(t)&&typeof t.pipeThrough=="function"&&typeof t.getReader=="function"&&typeof t.cancel=="function")}function W0(t){return!!(t&&!Dr(t)&&typeof t.getWriter=="function"&&typeof t.abort=="function")}function z0(t){return!!(t&&!Dr(t)&&typeof t.readable=="object"&&typeof t.writable=="object")}function E2(t){return j0(t)||W0(t)||z0(t)}function v2(t,e){return t==null?!1:e===!0?typeof t[$0]=="function":e===!1?typeof t[q0]=="function":typeof t[$0]=="function"||typeof t[q0]=="function"}function Ic(t){if(!Dr(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!!(t.destroyed||t[F0]||n!=null&&n.destroyed)}function G0(t){if(!Tc(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 S2(t,e){if(!Tc(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 _2(t){if(!Ac(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 J0(t,e){if(!Ac(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 Y0(t){return t&&t[Pl]!=null?t[Pl]:typeof t?.readable!="boolean"?null:Ic(t)?!1:Ac(t)&&t.readable&&!J0(t)}function X0(t){return t&&t[Kl]!=null?t[Kl]:typeof t?.writable!="boolean"?null:Ic(t)?!1:Tc(t)&&t.writable&&!G0(t)}function A2(t,e){return Dr(t)?Ic(t)?!0:!(e?.readable!==!1&&Y0(t)||e?.writable!==!1&&X0(t)):null}function T2(t){var e,r;return Dr(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 I2(t){var e,r;return Dr(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 D2(t){if(!Dr(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"&&Z0(t)?t._closed:null}function Z0(t){return typeof t._closed=="boolean"&&typeof t._defaultKeepAlive=="boolean"&&typeof t._removedConnection=="boolean"&&typeof t._removedContLen=="boolean"}function Q0(t){return typeof t._sent100=="boolean"&&Z0(t)}function B2(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 R2(t){if(!Dr(t))return null;let e=t._writableState,r=t._readableState,n=e||r;return!n&&Q0(t)||!!(n&&n.autoDestroy&&n.emitClose&&n.closed===!1)}function O2(t){var e;return!!(t&&((e=t[H0])!==null&&e!==void 0?e:t.readableDidRead||t.readableAborted))}function k2(t){var e,r,n,i,o,s,a,u,d,c;return!!(t&&((e=(r=(n=(i=(o=(s=t[V0])!==null&&s!==void 0?s:t.readableErrored)!==null&&o!==void 0?o:t.writableErrored)!==null&&i!==void 0?i:(a=t._readableState)===null||a===void 0?void 0:a.errorEmitted)!==null&&n!==void 0?n:(u=t._writableState)===null||u===void 0?void 0:u.errorEmitted)!==null&&r!==void 0?r:(d=t._readableState)===null||d===void 0?void 0:d.errored)!==null&&e!==void 0?e:!((c=t._writableState)===null||c===void 0)&&c.errored))}em.exports={isDestroyed:Ic,kIsDestroyed:F0,isDisturbed:O2,kIsDisturbed:H0,isErrored:k2,kIsErrored:V0,isReadable:Y0,kIsReadable:Pl,kIsClosedPromise:w2,kControllerErrorFunction:b2,kIsWritable:Kl,isClosed:D2,isDuplexNodeStream:x2,isFinished:A2,isIterable:v2,isReadableNodeStream:Ac,isReadableStream:j0,isReadableEnded:_2,isReadableFinished:J0,isReadableErrored:I2,isNodeStream:Dr,isWebStream:E2,isWritable:X0,isWritableNodeStream:Tc,isWritableStream:W0,isWritableEnded:G0,isWritableFinished:S2,isWritableErrored:T2,isServerRequest:B2,isServerResponse:Q0,willEmitClose:R2,isTransformStream:z0}});var on=$((Z8,ql)=>{var Q8=f(h()),Un=Cn(),{AbortError:um,codes:C2}=bt(),{ERR_INVALID_ARG_TYPE:U2,ERR_STREAM_PREMATURE_CLOSE:tm}=C2,{kEmptyObject:Ml,once:Nl}=yt(),{validateAbortSignal:P2,validateFunction:K2,validateObject:L2,validateBoolean:M2}=So(),{Promise:N2,PromisePrototypeThen:$2,SymbolDispose:dm}=Le(),{isClosed:q2,isReadable:rm,isReadableNodeStream:Ll,isReadableStream:F2,isReadableFinished:nm,isReadableErrored:im,isWritable:om,isWritableNodeStream:sm,isWritableStream:V2,isWritableFinished:am,isWritableErrored:cm,isNodeStream:H2,willEmitClose:j2,kIsClosedPromise:W2}=Br(),Ao;function z2(t){return t.setHeader&&typeof t.abort=="function"}var $l=()=>{};function lm(t,e,r){var n,i;if(arguments.length===2?(r=e,e=Ml):e==null?e=Ml:L2(e,"options"),K2(r,"callback"),P2(e.signal,"options.signal"),r=Nl(r),F2(t)||V2(t))return G2(t,e,r);if(!H2(t))throw new U2("stream",["ReadableStream","WritableStream","Stream"],t);let o=(n=e.readable)!==null&&n!==void 0?n:Ll(t),s=(i=e.writable)!==null&&i!==void 0?i:sm(t),a=t._writableState,u=t._readableState,d=()=>{t.writable||g()},c=j2(t)&&Ll(t)===o&&sm(t)===s,l=am(t,!1),g=()=>{l=!0,t.destroyed&&(c=!1),!(c&&(!t.readable||o))&&(!o||w)&&r.call(t)},w=nm(t,!1),m=()=>{w=!0,t.destroyed&&(c=!1),!(c&&(!t.writable||s))&&(!s||l)&&r.call(t)},y=I=>{r.call(t,I)},E=q2(t),v=()=>{E=!0;let I=cm(t)||im(t);if(I&&typeof I!="boolean")return r.call(t,I);if(o&&!w&&Ll(t,!0)&&!nm(t,!1))return r.call(t,new tm);if(s&&!l&&!am(t,!1))return r.call(t,new tm);r.call(t)},D=()=>{E=!0;let I=cm(t)||im(t);if(I&&typeof I!="boolean")return r.call(t,I);r.call(t)},S=()=>{t.req.on("finish",g)};z2(t)?(t.on("complete",g),c||t.on("abort",v),t.req?S():t.on("request",S)):s&&!a&&(t.on("end",d),t.on("close",d)),!c&&typeof t.aborted=="boolean"&&t.on("aborted",v),t.on("end",m),t.on("finish",g),e.error!==!1&&t.on("error",y),t.on("close",v),E?Un.nextTick(v):a!=null&&a.errorEmitted||u!=null&&u.errorEmitted?c||Un.nextTick(D):(!o&&(!c||rm(t))&&(l||om(t)===!1)||!s&&(!c||om(t))&&(w||rm(t)===!1)||u&&t.req&&t.aborted)&&Un.nextTick(D);let B=()=>{r=$l,t.removeListener("aborted",v),t.removeListener("complete",g),t.removeListener("abort",v),t.removeListener("request",S),t.req&&t.req.removeListener("finish",g),t.removeListener("end",d),t.removeListener("close",d),t.removeListener("finish",g),t.removeListener("end",m),t.removeListener("error",y),t.removeListener("close",v)};if(e.signal&&!E){let I=()=>{let O=r;B(),O.call(t,new um(void 0,{cause:e.signal.reason}))};if(e.signal.aborted)Un.nextTick(I);else{Ao=Ao||yt().addAbortListener;let O=Ao(e.signal,I),C=r;r=Nl((...P)=>{O[dm](),C.apply(t,P)})}}return B}function G2(t,e,r){let n=!1,i=$l;if(e.signal)if(i=()=>{n=!0,r.call(t,new um(void 0,{cause:e.signal.reason}))},e.signal.aborted)Un.nextTick(i);else{Ao=Ao||yt().addAbortListener;let s=Ao(e.signal,i),a=r;r=Nl((...u)=>{s[dm](),a.apply(t,u)})}let o=(...s)=>{n||Un.nextTick(()=>r.apply(t,s))};return $2(t[W2].promise,o,o),$l}function J2(t,e){var r;let n=!1;return e===null&&(e=Ml),(r=e)!==null&&r!==void 0&&r.cleanup&&(M2(e.cleanup,"cleanup"),n=e.cleanup),new N2((i,o)=>{let s=lm(t,e,a=>{n&&s(),a?o(a):i()})})}ql.exports=lm;ql.exports.finished=J2});var Di=$((e5,bm)=>{"use strict";var t5=f(h()),Rr=Cn(),{aggregateTwoErrors:Y2,codes:{ERR_MULTIPLE_CALLBACK:X2},AbortError:Z2}=bt(),{Symbol:pm}=Le(),{kIsDestroyed:Q2,isDestroyed:eS,isFinished:tS,isServerRequest:rS}=Br(),ym=pm("kDestroy"),Fl=pm("kConstruct");function mm(t,e,r){t&&(t.stack,e&&!e.errored&&(e.errored=t),r&&!r.errored&&(r.errored=t))}function nS(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):(mm(t,n,r),n&&(n.destroyed=!0),r&&(r.destroyed=!0),i.constructed?fm(this,t,e):this.once(ym,function(o){fm(this,Y2(o,t),e)}),this)}function fm(t,e,r){let n=!1;function i(o){if(n)return;n=!0;let s=t._readableState,a=t._writableState;mm(o,a,s),a&&(a.closed=!0),s&&(s.closed=!0),typeof r=="function"&&r(o),o?Rr.nextTick(iS,t,o):Rr.nextTick(gm,t)}try{t._destroy(e||null,i)}catch(o){i(o)}}function iS(t,e){Vl(t,e),gm(t)}function gm(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 Vl(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 oS(){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 Hl(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?Rr.nextTick(Vl,t,e):Vl(t,e))}function sS(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(Fl,e),!(t.listenerCount(Fl)>1)&&Rr.nextTick(aS,t)}function aS(t){let e=!1;function r(n){if(e){Hl(t,n??new X2);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(ym,n):n?Hl(t,n,!0):Rr.nextTick(cS,t)}try{t._construct(n=>{Rr.nextTick(r,n)})}catch(n){Rr.nextTick(r,n)}}function cS(t){t.emit(Fl)}function hm(t){return t?.setHeader&&typeof t.abort=="function"}function wm(t){t.emit("close")}function uS(t,e){t.emit("error",e),Rr.nextTick(wm,t)}function dS(t,e){!t||eS(t)||(!e&&!tS(t)&&(e=new Z2),rS(t)?(t.socket=null,t.destroy(e)):hm(t)?t.abort():hm(t.req)?t.req.abort():typeof t.destroy=="function"?t.destroy(e):typeof t.close=="function"?t.close():e?Rr.nextTick(uS,t,e):Rr.nextTick(wm,t),t.destroyed||(t[Q2]=!0))}bm.exports={construct:sS,destroyer:dS,destroy:nS,undestroy:oS,errorOrDestroy:Hl}});var Rc=$((r5,Em)=>{"use strict";var n5=f(h()),{ArrayIsArray:lS,ObjectSetPrototypeOf:xm}=Le(),{EventEmitter:Dc}=uo();function Bc(t){Dc.call(this,t)}xm(Bc.prototype,Dc.prototype);xm(Bc,Dc);Bc.prototype.pipe=function(t,e){let r=this;function n(c){t.writable&&t.write(c)===!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",a));let o=!1;function s(){o||(o=!0,t.end())}function a(){o||(o=!0,typeof t.destroy=="function"&&t.destroy())}function u(c){d(),Dc.listenerCount(this,"error")===0&&this.emit("error",c)}jl(r,"error",u),jl(t,"error",u);function d(){r.removeListener("data",n),t.removeListener("drain",i),r.removeListener("end",s),r.removeListener("close",a),r.removeListener("error",u),t.removeListener("error",u),r.removeListener("end",d),r.removeListener("close",d),t.removeListener("close",d)}return r.on("end",d),r.on("close",d),t.on("close",d),t.emit("pipe",r),t};function jl(t,e,r){if(typeof t.prependListener=="function")return t.prependListener(e,r);!t._events||!t._events[e]?t.on(e,r):lS(t._events[e])?t._events[e].unshift(r):t._events[e]=[r,t._events[e]]}Em.exports={Stream:Bc,prependListener:jl}});var $s=$((i5,Oc)=>{"use strict";var o5=f(h()),{SymbolDispose:fS}=Le(),{AbortError:vm,codes:hS}=bt(),{isNodeStream:Sm,isWebStream:pS,kControllerErrorFunction:yS}=Br(),mS=on(),{ERR_INVALID_ARG_TYPE:_m}=hS,Wl,gS=(t,e)=>{if(typeof t!="object"||!("aborted"in t))throw new _m(e,"AbortSignal",t)};Oc.exports.addAbortSignal=function(e,r){if(gS(e,"signal"),!Sm(r)&&!pS(r))throw new _m("stream",["ReadableStream","WritableStream","Stream"],r);return Oc.exports.addAbortSignalNoValidate(e,r)};Oc.exports.addAbortSignalNoValidate=function(t,e){if(typeof t!="object"||!("aborted"in t))return e;let r=Sm(e)?()=>{e.destroy(new vm(void 0,{cause:t.reason}))}:()=>{e[yS](new vm(void 0,{cause:t.reason}))};if(t.aborted)r();else{Wl=Wl||yt().addAbortListener;let n=Wl(t,r);mS(e,n[fS])}return e}});var Im=$((a5,Tm)=>{"use strict";var c5=f(h()),{StringPrototypeSlice:Am,SymbolIterator:wS,TypedArrayPrototypeSet:kc,Uint8Array:bS}=Le(),{Buffer:zl}=_t(),{inspect:xS}=yt();Tm.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 zl.alloc(0);let r=zl.allocUnsafe(e>>>0),n=this.head,i=0;for(;n;)kc(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}*[wS](){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+=Am(o,0,e),this.head=n,n.data=Am(o,e));break}++i}while((n=n.next)!==null);return this.length-=i,r}_getBuffer(e){let r=zl.allocUnsafe(e),n=e,i=this.head,o=0;do{let s=i.data;if(e>s.length)kc(r,s,n-e),e-=s.length;else{e===s.length?(kc(r,s,n-e),++o,i.next?this.head=i.next:this.head=this.tail=null):(kc(r,new bS(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 xS(this,{...r,depth:0,customInspect:!1})}}});var qs=$((u5,Om)=>{"use strict";var d5=f(h()),{MathFloor:ES,NumberIsInteger:vS}=Le(),{validateInteger:SS}=So(),{ERR_INVALID_ARG_VALUE:_S}=bt().codes,Dm=16*1024,Bm=16;function AS(t,e,r){return t.highWaterMark!=null?t.highWaterMark:e?t[r]:null}function Rm(t){return t?Bm:Dm}function TS(t,e){SS(e,"value",0),t?Bm=e:Dm=e}function IS(t,e,r,n){let i=AS(e,n,r);if(i!=null){if(!vS(i)||i<0){let o=n?`options.${r}`:"options.highWaterMark";throw new _S(o,i)}return ES(i)}return Rm(t.objectMode)}Om.exports={getHighWaterMark:IS,getDefaultHighWaterMark:Rm,setDefaultHighWaterMark:TS}});var Um=$((Gl,Cm)=>{var l5=f(h());var Cc=_t(),Or=Cc.Buffer;function km(t,e){for(var r in t)e[r]=t[r]}Or.from&&Or.alloc&&Or.allocUnsafe&&Or.allocUnsafeSlow?Cm.exports=Cc:(km(Cc,Gl),Gl.Buffer=Bi);function Bi(t,e,r){return Or(t,e,r)}Bi.prototype=Object.create(Or.prototype);km(Or,Bi);Bi.from=function(t,e,r){if(typeof t=="number")throw new TypeError("Argument must not be a number");return Or(t,e,r)};Bi.alloc=function(t,e,r){if(typeof t!="number")throw new TypeError("Argument must be a number");var n=Or(t);return e!==void 0?typeof r=="string"?n.fill(e,r):n.fill(e):n.fill(0),n};Bi.allocUnsafe=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return Or(t)};Bi.allocUnsafeSlow=function(t){if(typeof t!="number")throw new TypeError("Argument must be a number");return Cc.SlowBuffer(t)}});var Lm=$(Km=>{"use strict";var h5=f(h()),Yl=Um().Buffer,Pm=Yl.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 DS(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 BS(t){var e=DS(t);if(typeof e!="string"&&(Yl.isEncoding===Pm||!Pm(t)))throw new Error("Unknown encoding: "+t);return e||t}Km.StringDecoder=Fs;function Fs(t){this.encoding=BS(t);var e;switch(this.encoding){case"utf16le":this.text=PS,this.end=KS,e=4;break;case"utf8":this.fillLast=kS,e=4;break;case"base64":this.text=LS,this.end=MS,e=3;break;default:this.write=NS,this.end=$S;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=Yl.allocUnsafe(e)}Fs.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||""};Fs.prototype.end=US;Fs.prototype.text=CS;Fs.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 Jl(t){return t<=127?0:t>>5===6?2:t>>4===14?3:t>>3===30?4:t>>6===2?-1:-2}function RS(t,e,r){var n=e.length-1;if(n<r)return 0;var i=Jl(e[n]);return i>=0?(i>0&&(t.lastNeed=i-1),i):--n<r||i===-2?0:(i=Jl(e[n]),i>=0?(i>0&&(t.lastNeed=i-2),i):--n<r||i===-2?0:(i=Jl(e[n]),i>=0?(i>0&&(i===2?i=0:t.lastNeed=i-3),i):0))}function OS(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 kS(t){var e=this.lastTotal-this.lastNeed,r=OS(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 CS(t,e){var r=RS(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 US(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"\uFFFD":e}function PS(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 KS(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 LS(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 MS(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function NS(t){return t.toString(this.encoding)}function $S(t){return t&&t.length?this.write(t):""}});var Xl=$((p5,qm)=>{"use strict";var y5=f(h()),Mm=Cn(),{PromisePrototypeThen:qS,SymbolAsyncIterator:Nm,SymbolIterator:$m}=Le(),{Buffer:FS}=_t(),{ERR_INVALID_ARG_TYPE:VS,ERR_STREAM_NULL_VALUES:HS}=bt().codes;function jS(t,e,r){let n;if(typeof e=="string"||e instanceof FS)return new t({objectMode:!0,...r,read(){this.push(e),this.push(null)}});let i;if(e&&e[Nm])i=!0,n=e[Nm]();else if(e&&e[$m])i=!1,n=e[$m]();else throw new VS("iterable",["Iterable"],e);let o=new t({objectMode:!0,highWaterMark:1,...r}),s=!1;o._read=function(){s||(s=!0,u())},o._destroy=function(d,c){qS(a(d),()=>Mm.nextTick(c,d),l=>Mm.nextTick(c,l||d))};async function a(d){let c=d!=null,l=typeof n.throw=="function";if(c&&l){let{value:g,done:w}=await n.throw(d);if(await g,w)return}if(typeof n.return=="function"){let{value:g}=await n.return();await g}}async function u(){for(;;){try{let{value:d,done:c}=i?await n.next():n.next();if(c)o.push(null);else{let l=d&&typeof d.then=="function"?await d:d;if(l===null)throw s=!1,new HS;if(o.push(l))continue;s=!1}}catch(d){o.destroy(d)}break}}return o}qm.exports=jS});var Hs=$((m5,og)=>{var g5=f(h()),cr=Cn(),{ArrayPrototypeIndexOf:WS,NumberIsInteger:zS,NumberIsNaN:GS,NumberParseInt:JS,ObjectDefineProperties:sf,ObjectKeys:YS,ObjectSetPrototypeOf:Hm,Promise:jm,SafeSet:XS,SymbolAsyncDispose:ZS,SymbolAsyncIterator:QS,Symbol:e_}=Le();og.exports=de;de.ReadableState=Lc;var{EventEmitter:t_}=uo(),{Stream:Pn,prependListener:r_}=Rc(),{Buffer:Zl}=_t(),{addAbortSignal:n_}=$s(),Wm=on(),he=yt().debuglog("stream",t=>{he=t}),i_=Im(),Do=Di(),{getHighWaterMark:o_,getDefaultHighWaterMark:s_}=qs(),{aggregateTwoErrors:Fm,codes:{ERR_INVALID_ARG_TYPE:a_,ERR_METHOD_NOT_IMPLEMENTED:c_,ERR_OUT_OF_RANGE:u_,ERR_STREAM_PUSH_AFTER_EOF:d_,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:l_},AbortError:f_}=bt(),{validateObject:h_}=So(),Ri=e_("kPaused"),{StringDecoder:zm}=Lm(),p_=Xl();Hm(de.prototype,Pn.prototype);Hm(de,Pn);var Ql=()=>{},{errorOrDestroy:To}=Do,Io=1,y_=2,Gm=4,Vs=8,Jm=16,Uc=32,Pc=64,Ym=128,m_=256,g_=512,w_=1024,nf=2048,of=4096,b_=8192,x_=16384,E_=32768,Xm=65536,v_=1<<17,S_=1<<18;function Ge(t){return{enumerable:!1,get(){return(this.state&t)!==0},set(e){e?this.state|=t:this.state&=~t}}}sf(Lc.prototype,{objectMode:Ge(Io),ended:Ge(y_),endEmitted:Ge(Gm),reading:Ge(Vs),constructed:Ge(Jm),sync:Ge(Uc),needReadable:Ge(Pc),emittedReadable:Ge(Ym),readableListening:Ge(m_),resumeScheduled:Ge(g_),errorEmitted:Ge(w_),emitClose:Ge(nf),autoDestroy:Ge(of),destroyed:Ge(b_),closed:Ge(x_),closeEmitted:Ge(E_),multiAwaitDrain:Ge(Xm),readingMore:Ge(v_),dataEmitted:Ge(S_)});function Lc(t,e,r){typeof r!="boolean"&&(r=e instanceof kr()),this.state=nf|of|Jm|Uc,t&&t.objectMode&&(this.state|=Io),r&&t&&t.readableObjectMode&&(this.state|=Io),this.highWaterMark=t?o_(this,t,"readableHighWaterMark",r):s_(!1),this.buffer=new i_,this.length=0,this.pipes=[],this.flowing=null,this[Ri]=null,t&&t.emitClose===!1&&(this.state&=~nf),t&&t.autoDestroy===!1&&(this.state&=~of),this.errored=null,this.defaultEncoding=t&&t.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,t&&t.encoding&&(this.decoder=new zm(t.encoding),this.encoding=t.encoding)}function de(t){if(!(this instanceof de))return new de(t);let e=this instanceof kr();this._readableState=new Lc(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&&n_(t.signal,this)),Pn.call(this,t),Do.construct(this,()=>{this._readableState.needReadable&&Kc(this,this._readableState)})}de.prototype.destroy=Do.destroy;de.prototype._undestroy=Do.undestroy;de.prototype._destroy=function(t,e){e(t)};de.prototype[t_.captureRejectionSymbol]=function(t){this.destroy(t)};de.prototype[ZS]=function(){let t;return this.destroyed||(t=this.readableEnded?null:new f_,this.destroy(t)),new jm((e,r)=>Wm(this,n=>n&&n!==t?r(n):e(null)))};de.prototype.push=function(t,e){return Zm(this,t,e,!1)};de.prototype.unshift=function(t,e){return Zm(this,t,e,!0)};function Zm(t,e,r,n){he("readableAddChunk",e);let i=t._readableState,o;if(i.state&Io||(typeof e=="string"?(r=r||i.defaultEncoding,i.encoding!==r&&(n&&i.encoding?e=Zl.from(e,r).toString(i.encoding):(e=Zl.from(e,r),r=""))):e instanceof Zl?r="":Pn._isUint8Array(e)?(e=Pn._uint8ArrayToBuffer(e),r=""):e!=null&&(o=new a_("chunk",["string","Buffer","Uint8Array"],e))),o)To(t,o);else if(e===null)i.state&=~Vs,T_(t,i);else if(i.state&Io||e&&e.length>0)if(n)if(i.state&Gm)To(t,new l_);else{if(i.destroyed||i.errored)return!1;ef(t,i,e,!0)}else if(i.ended)To(t,new d_);else{if(i.destroyed||i.errored)return!1;i.state&=~Vs,i.decoder&&!r?(e=i.decoder.write(e),i.objectMode||e.length!==0?ef(t,i,e,!1):Kc(t,i)):ef(t,i,e,!1)}else n||(i.state&=~Vs,Kc(t,i));return!i.ended&&(i.length<i.highWaterMark||i.length===0)}function ef(t,e,r,n){e.flowing&&e.length===0&&!e.sync&&t.listenerCount("data")>0?(e.state&Xm?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&Pc&&Mc(t)),Kc(t,e)}de.prototype.isPaused=function(){let t=this._readableState;return t[Ri]===!0||t.flowing===!1};de.prototype.setEncoding=function(t){let e=new zm(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 __=1073741824;function A_(t){if(t>__)throw new u_("size","<= 1GiB",t);return t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++,t}function Vm(t,e){return t<=0||e.length===0&&e.ended?0:e.state&Io?1:GS(t)?e.flowing&&e.length?e.buffer.first().length:e.length:t<=e.length?t:e.ended?e.length:0}de.prototype.read=function(t){he("read",t),t===void 0?t=NaN:zS(t)||(t=JS(t,10));let e=this._readableState,r=t;if(t>e.highWaterMark&&(e.highWaterMark=A_(t)),t!==0&&(e.state&=~Ym),t===0&&e.needReadable&&((e.highWaterMark!==0?e.length>=e.highWaterMark:e.length>0)||e.ended))return he("read: emitReadable",e.length,e.ended),e.length===0&&e.ended?tf(this):Mc(this),null;if(t=Vm(t,e),t===0&&e.ended)return e.length===0&&tf(this),null;let n=(e.state&Pc)!==0;if(he("need readable",n),(e.length===0||e.length-t<e.highWaterMark)&&(n=!0,he("length less than watermark",n)),e.ended||e.reading||e.destroyed||e.errored||!e.constructed)n=!1,he("reading, ended or constructing",n);else if(n){he("do read"),e.state|=Vs|Uc,e.length===0&&(e.state|=Pc);try{this._read(e.highWaterMark)}catch(o){To(this,o)}e.state&=~Uc,e.reading||(t=Vm(r,e))}let i;return t>0?i=ng(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&&tf(this)),i!==null&&!e.errorEmitted&&!e.closeEmitted&&(e.dataEmitted=!0,this.emit("data",i)),i};function T_(t,e){if(he("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?Mc(t):(e.needReadable=!1,e.emittedReadable=!0,Qm(t))}}function Mc(t){let e=t._readableState;he("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(he("emitReadable",e.flowing),e.emittedReadable=!0,cr.nextTick(Qm,t))}function Qm(t){let e=t._readableState;he("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,tg(t)}function Kc(t,e){!e.readingMore&&e.constructed&&(e.readingMore=!0,cr.nextTick(I_,t,e))}function I_(t,e){for(;!e.reading&&!e.ended&&(e.length<e.highWaterMark||e.flowing&&e.length===0);){let r=e.length;if(he("maybeReadMore read 0"),t.read(0),r===e.length)break}e.readingMore=!1}de.prototype._read=function(t){throw new c_("_read()")};de.prototype.pipe=function(t,e){let r=this,n=this._readableState;n.pipes.length===1&&(n.multiAwaitDrain||(n.multiAwaitDrain=!0,n.awaitDrainWriters=new XS(n.awaitDrainWriters?[n.awaitDrainWriters]:[]))),n.pipes.push(t),he("pipe count=%d opts=%j",n.pipes.length,e);let o=(!e||e.end!==!1)&&t!==cr.stdout&&t!==cr.stderr?a:E;n.endEmitted?cr.nextTick(o):r.once("end",o),t.on("unpipe",s);function s(v,D){he("onunpipe"),v===r&&D&&D.hasUnpiped===!1&&(D.hasUnpiped=!0,c())}function a(){he("onend"),t.end()}let u,d=!1;function c(){he("cleanup"),t.removeListener("close",m),t.removeListener("finish",y),u&&t.removeListener("drain",u),t.removeListener("error",w),t.removeListener("unpipe",s),r.removeListener("end",a),r.removeListener("end",E),r.removeListener("data",g),d=!0,u&&n.awaitDrainWriters&&(!t._writableState||t._writableState.needDrain)&&u()}function l(){d||(n.pipes.length===1&&n.pipes[0]===t?(he("false write response, pause",0),n.awaitDrainWriters=t,n.multiAwaitDrain=!1):n.pipes.length>1&&n.pipes.includes(t)&&(he("false write response, pause",n.awaitDrainWriters.size),n.awaitDrainWriters.add(t)),r.pause()),u||(u=D_(r,t),t.on("drain",u))}r.on("data",g);function g(v){he("ondata");let D=t.write(v);he("dest.write",D),D===!1&&l()}function w(v){if(he("onerror",v),E(),t.removeListener("error",w),t.listenerCount("error")===0){let D=t._writableState||t._readableState;D&&!D.errorEmitted?To(t,v):t.emit("error",v)}}r_(t,"error",w);function m(){t.removeListener("finish",y),E()}t.once("close",m);function y(){he("onfinish"),t.removeListener("close",m),E()}t.once("finish",y);function E(){he("unpipe"),r.unpipe(t)}return t.emit("pipe",r),t.writableNeedDrain===!0?l():n.flowing||(he("pipe resume"),r.resume()),t};function D_(t,e){return function(){let n=t._readableState;n.awaitDrainWriters===e?(he("pipeOnDrain",1),n.awaitDrainWriters=null):n.multiAwaitDrain&&(he("pipeOnDrain",n.awaitDrainWriters.size),n.awaitDrainWriters.delete(e)),(!n.awaitDrainWriters||n.awaitDrainWriters.size===0)&&t.listenerCount("data")&&t.resume()}}de.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=WS(e.pipes,t);return n===-1?this:(e.pipes.splice(n,1),e.pipes.length===0&&this.pause(),t.emit("unpipe",this,r),this)};de.prototype.on=function(t,e){let r=Pn.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,he("on readable",n.length,n.reading),n.length?Mc(this):n.reading||cr.nextTick(B_,this)),r};de.prototype.addListener=de.prototype.on;de.prototype.removeListener=function(t,e){let r=Pn.prototype.removeListener.call(this,t,e);return t==="readable"&&cr.nextTick(eg,this),r};de.prototype.off=de.prototype.removeListener;de.prototype.removeAllListeners=function(t){let e=Pn.prototype.removeAllListeners.apply(this,arguments);return(t==="readable"||t===void 0)&&cr.nextTick(eg,this),e};function eg(t){let e=t._readableState;e.readableListening=t.listenerCount("readable")>0,e.resumeScheduled&&e[Ri]===!1?e.flowing=!0:t.listenerCount("data")>0?t.resume():e.readableListening||(e.flowing=null)}function B_(t){he("readable nexttick read 0"),t.read(0)}de.prototype.resume=function(){let t=this._readableState;return t.flowing||(he("resume"),t.flowing=!t.readableListening,R_(this,t)),t[Ri]=!1,this};function R_(t,e){e.resumeScheduled||(e.resumeScheduled=!0,cr.nextTick(O_,t,e))}function O_(t,e){he("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),tg(t),e.flowing&&!e.reading&&t.read(0)}de.prototype.pause=function(){return he("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(he("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState[Ri]=!0,this};function tg(t){let e=t._readableState;for(he("flow",e.flowing);e.flowing&&t.read()!==null;);}de.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=>{To(this,n)}),t.on("close",()=>{this.destroy()}),t.on("destroy",()=>{this.destroy()}),this._read=()=>{e&&t.resume&&(e=!1,t.resume())};let r=YS(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};de.prototype[QS]=function(){return rg(this)};de.prototype.iterator=function(t){return t!==void 0&&h_(t,"options"),rg(this,t)};function rg(t,e){typeof t.read!="function"&&(t=de.wrap(t,{objectMode:!0}));let r=k_(t,e);return r.stream=t,r}async function*k_(t,e){let r=Ql;function n(s){this===t?(r(),r=Ql):r=s}t.on("readable",n);let i,o=Wm(t,{writable:!1},s=>{i=s?Fm(i,s):null,r(),r=Ql});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 jm(n)}}}catch(s){throw i=Fm(i,s),i}finally{(i||e?.destroyOnReturn!==!1)&&(i===void 0||t._readableState.autoDestroy)?Do.destroyer(t,null):(t.off("readable",n),o())}}sf(de.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}}});sf(Lc.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return this[Ri]!==!1},set(t){this[Ri]=!!t}}});de._fromList=ng;function ng(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 tf(t){let e=t._readableState;he("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,cr.nextTick(C_,e,t))}function C_(t,e){if(he("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)cr.nextTick(U_,e);else if(t.autoDestroy){let r=e._writableState;(!r||r.autoDestroy&&(r.finished||r.writable===!1))&&e.destroy()}}}function U_(t){t.writable&&!t.writableEnded&&!t.destroyed&&t.end()}de.from=function(t,e){return p_(de,t,e)};var rf;function ig(){return rf===void 0&&(rf={}),rf}de.fromWeb=function(t,e){return ig().newStreamReadableFromReadableStream(t,e)};de.toWeb=function(t,e){return ig().newReadableStreamFromStreamReadable(t,e)};de.wrap=function(t,e){var r,n;return new de({objectMode:(r=(n=t.readableObjectMode)!==null&&n!==void 0?n:t.objectMode)!==null&&r!==void 0?r:!0,...e,destroy(i,o){Do.destroyer(t,i),o(i)}}).wrap(t)}});var Vc=$((w5,gg)=>{var b5=f(h()),Oi=Cn(),{ArrayPrototypeSlice:cg,Error:P_,FunctionPrototypeSymbolHasInstance:ug,ObjectDefineProperty:dg,ObjectDefineProperties:K_,ObjectSetPrototypeOf:lg,StringPrototypeToLowerCase:L_,Symbol:M_,SymbolHasInstance:N_}=Le();gg.exports=Me;Me.WritableState=zs;var{EventEmitter:$_}=uo(),js=Rc().Stream,{Buffer:Nc}=_t(),Fc=Di(),{addAbortSignal:q_}=$s(),{getHighWaterMark:F_,getDefaultHighWaterMark:V_}=qs(),{ERR_INVALID_ARG_TYPE:H_,ERR_METHOD_NOT_IMPLEMENTED:j_,ERR_MULTIPLE_CALLBACK:fg,ERR_STREAM_CANNOT_PIPE:W_,ERR_STREAM_DESTROYED:Ws,ERR_STREAM_ALREADY_FINISHED:z_,ERR_STREAM_NULL_VALUES:G_,ERR_STREAM_WRITE_AFTER_END:J_,ERR_UNKNOWN_ENCODING:hg}=bt().codes,{errorOrDestroy:Bo}=Fc;lg(Me.prototype,js.prototype);lg(Me,js);function uf(){}var Ro=M_("kOnFinished");function zs(t,e,r){typeof r!="boolean"&&(r=e instanceof kr()),this.objectMode=!!(t&&t.objectMode),r&&(this.objectMode=this.objectMode||!!(t&&t.writableObjectMode)),this.highWaterMark=t?F_(this,t,"writableHighWaterMark",r):V_(!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=X_.bind(void 0,e),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,qc(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[Ro]=[]}function qc(t){t.buffered=[],t.bufferedIndex=0,t.allBuffers=!0,t.allNoop=!0}zs.prototype.getBuffer=function(){return cg(this.buffered,this.bufferedIndex)};dg(zs.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}});function Me(t){let e=this instanceof kr();if(!e&&!ug(Me,this))return new Me(t);this._writableState=new zs(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&&q_(t.signal,this)),js.call(this,t),Fc.construct(this,()=>{let r=this._writableState;r.writing||lf(this,r),ff(this,r)})}dg(Me,N_,{__proto__:null,value:function(t){return ug(this,t)?!0:this!==Me?!1:t&&t._writableState instanceof zs}});Me.prototype.pipe=function(){Bo(this,new W_)};function pg(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"&&!Nc.isEncoding(r))throw new hg(r);typeof n!="function"&&(n=uf)}if(e===null)throw new G_;if(!i.objectMode)if(typeof e=="string")i.decodeStrings!==!1&&(e=Nc.from(e,r),r="buffer");else if(e instanceof Nc)r="buffer";else if(js._isUint8Array(e))e=js._uint8ArrayToBuffer(e),r="buffer";else throw new H_("chunk",["string","Buffer","Uint8Array"],e);let o;return i.ending?o=new J_:i.destroyed&&(o=new Ws("write")),o?(Oi.nextTick(n,o),Bo(t,o,!0),o):(i.pendingcb++,Y_(t,i,e,r,n))}Me.prototype.write=function(t,e,r){return pg(this,t,e,r)===!0};Me.prototype.cork=function(){this._writableState.corked++};Me.prototype.uncork=function(){let t=this._writableState;t.corked&&(t.corked--,t.writing||lf(this,t))};Me.prototype.setDefaultEncoding=function(e){if(typeof e=="string"&&(e=L_(e)),!Nc.isEncoding(e))throw new hg(e);return this._writableState.defaultEncoding=e,this};function Y_(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!==uf&&(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 sg(t,e,r,n,i,o,s){e.writelen=n,e.writecb=s,e.writing=!0,e.sync=!0,e.destroyed?e.onwrite(new Ws("write")):r?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function ag(t,e,r,n){--e.pendingcb,n(r),df(e),Bo(t,r)}function X_(t,e){let r=t._writableState,n=r.sync,i=r.writecb;if(typeof i!="function"){Bo(t,new fg);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?Oi.nextTick(ag,t,r,e,i):ag(t,r,e,i)):(r.buffered.length>r.bufferedIndex&&lf(t,r),n?r.afterWriteTickInfo!==null&&r.afterWriteTickInfo.cb===i?r.afterWriteTickInfo.count++:(r.afterWriteTickInfo={count:1,cb:i,stream:t,state:r},Oi.nextTick(Z_,r.afterWriteTickInfo)):yg(t,r,1,i))}function Z_({stream:t,state:e,count:r,cb:n}){return e.afterWriteTickInfo=null,yg(t,e,r,n)}function yg(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&&df(e),ff(t,e)}function df(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],a=t.objectMode?1:o.length;t.length-=a,s((e=t.errored)!==null&&e!==void 0?e:new Ws("write"))}let r=t[Ro].splice(0);for(let i=0;i<r.length;i++){var n;r[i]((n=t.errored)!==null&&n!==void 0?n:new Ws("end"))}qc(t)}function lf(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 a=e.allNoop?uf:d=>{for(let c=s;c<r.length;++c)r[c].callback(d)},u=e.allNoop&&s===0?r:cg(r,s);u.allBuffers=e.allBuffers,sg(t,e,!0,e.length,u,"",a),qc(e)}else{do{let{chunk:a,encoding:u,callback:d}=r[s];r[s++]=null;let c=i?1:a.length;sg(t,e,!1,c,a,u,d)}while(s<r.length&&!e.writing);s===r.length?qc(e):s>256?(r.splice(0,s),e.bufferedIndex=0):e.bufferedIndex=s}e.bufferProcessing=!1}Me.prototype._write=function(t,e,r){if(this._writev)this._writev([{chunk:t,encoding:e}],r);else throw new j_("_write()")};Me.prototype._writev=null;Me.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=pg(this,t,e);o instanceof P_&&(i=o)}return n.corked&&(n.corked=1,this.uncork()),i||(!n.errored&&!n.ending?(n.ending=!0,ff(this,n,!0),n.ended=!0):n.finished?i=new z_("end"):n.destroyed&&(i=new Ws("end"))),typeof r=="function"&&(i||n.finished?Oi.nextTick(r,i):n[Ro].push(r)),this};function $c(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 Q_(t,e){let r=!1;function n(i){if(r){Bo(t,i??fg());return}if(r=!0,e.pendingcb--,i){let o=e[Ro].splice(0);for(let s=0;s<o.length;s++)o[s](i);Bo(t,i,e.sync)}else $c(e)&&(e.prefinished=!0,t.emit("prefinish"),e.pendingcb++,Oi.nextTick(cf,t,e))}e.sync=!0,e.pendingcb++;try{t._final(n)}catch(i){n(i)}e.sync=!1}function eA(t,e){!e.prefinished&&!e.finalCalled&&(typeof t._final=="function"&&!e.destroyed?(e.finalCalled=!0,Q_(t,e)):(e.prefinished=!0,t.emit("prefinish")))}function ff(t,e,r){$c(e)&&(eA(t,e),e.pendingcb===0&&(r?(e.pendingcb++,Oi.nextTick((n,i)=>{$c(i)?cf(n,i):i.pendingcb--},t,e)):$c(e)&&(e.pendingcb++,cf(t,e))))}function cf(t,e){e.pendingcb--,e.finished=!0;let r=e[Ro].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()}}K_(Me.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 tA=Fc.destroy;Me.prototype.destroy=function(t,e){let r=this._writableState;return!r.destroyed&&(r.bufferedIndex<r.buffered.length||r[Ro].length)&&Oi.nextTick(df,r),tA.call(this,t,e),this};Me.prototype._undestroy=Fc.undestroy;Me.prototype._destroy=function(t,e){e(t)};Me.prototype[$_.captureRejectionSymbol]=function(t){this.destroy(t)};var af;function mg(){return af===void 0&&(af={}),af}Me.fromWeb=function(t,e){return mg().newStreamWritableFromWritableStream(t,e)};Me.toWeb=function(t){return mg().newWritableStreamFromStreamWritable(t)}});var kg=$((x5,Og)=>{var E5=f(h()),hf=Cn(),rA=_t(),{isReadable:nA,isWritable:iA,isIterable:wg,isNodeStream:oA,isReadableNodeStream:bg,isWritableNodeStream:xg,isDuplexNodeStream:sA,isReadableStream:Eg,isWritableStream:vg}=Br(),Sg=on(),{AbortError:Bg,codes:{ERR_INVALID_ARG_TYPE:aA,ERR_INVALID_RETURN_VALUE:_g}}=bt(),{destroyer:ko}=Di(),cA=kr(),Rg=Hs(),uA=Vc(),{createDeferredPromise:Ag}=yt(),Tg=Xl(),Ig=globalThis.Blob||rA.Blob,dA=typeof Ig<"u"?function(e){return e instanceof Ig}:function(e){return!1},lA=globalThis.AbortController||Eo().AbortController,{FunctionPrototypeCall:Dg}=Le(),Kn=class extends cA{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)}};Og.exports=function t(e,r){if(sA(e))return e;if(bg(e))return Oo({readable:e});if(xg(e))return Oo({writable:e});if(oA(e))return Oo({writable:!1,readable:!1});if(Eg(e))return Oo({readable:Rg.fromWeb(e)});if(vg(e))return Oo({writable:uA.fromWeb(e)});if(typeof e=="function"){let{value:i,write:o,final:s,destroy:a}=fA(e);if(wg(i))return Tg(Kn,i,{objectMode:!0,write:o,final:s,destroy:a});let u=i?.then;if(typeof u=="function"){let d,c=Dg(u,i,l=>{if(l!=null)throw new _g("nully","body",l)},l=>{ko(d,l)});return d=new Kn({objectMode:!0,readable:!1,write:o,final(l){s(async()=>{try{await c,hf.nextTick(l,null)}catch(g){hf.nextTick(l,g)}})},destroy:a})}throw new _g("Iterable, AsyncIterable or AsyncFunction",r,i)}if(dA(e))return t(e.arrayBuffer());if(wg(e))return Tg(Kn,e,{objectMode:!0,writable:!1});if(Eg(e?.readable)&&vg(e?.writable))return Kn.fromWeb(e);if(typeof e?.writable=="object"||typeof e?.readable=="object"){let i=e!=null&&e.readable?bg(e?.readable)?e?.readable:t(e.readable):void 0,o=e!=null&&e.writable?xg(e?.writable)?e?.writable:t(e.writable):void 0;return Oo({readable:i,writable:o})}let n=e?.then;if(typeof n=="function"){let i;return Dg(n,e,o=>{o!=null&&i.push(o),i.push(null)},o=>{ko(i,o)}),i=new Kn({objectMode:!0,writable:!1,read(){}})}throw new aA(r,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],e)};function fA(t){let{promise:e,resolve:r}=Ag(),n=new lA,i=n.signal;return{value:t(async function*(){for(;;){let s=e;e=null;let{chunk:a,done:u,cb:d}=await s;if(hf.nextTick(d),u)return;if(i.aborted)throw new Bg(void 0,{cause:i.reason});({promise:e,resolve:r}=Ag()),yield a}}(),{signal:i}),write(s,a,u){let d=r;r=null,d({chunk:s,done:!1,cb:u})},final(s){let a=r;r=null,a({done:!0,cb:s})},destroy(s,a){n.abort(),a(s)}}}function Oo(t){let e=t.readable&&typeof t.readable.read!="function"?Rg.wrap(t.readable):t.readable,r=t.writable,n=!!nA(e),i=!!iA(r),o,s,a,u,d;function c(l){let g=u;u=null,g?g(l):l&&d.destroy(l)}return d=new Kn({readableObjectMode:!!(e!=null&&e.readableObjectMode),writableObjectMode:!!(r!=null&&r.writableObjectMode),readable:n,writable:i}),i&&(Sg(r,l=>{i=!1,l&&ko(e,l),c(l)}),d._write=function(l,g,w){r.write(l,g)?w():o=w},d._final=function(l){r.end(),s=l},r.on("drain",function(){if(o){let l=o;o=null,l()}}),r.on("finish",function(){if(s){let l=s;s=null,l()}})),n&&(Sg(e,l=>{n=!1,l&&ko(e,l),c(l)}),e.on("readable",function(){if(a){let l=a;a=null,l()}}),e.on("end",function(){d.push(null)}),d._read=function(){for(;;){let l=e.read();if(l===null){a=d._read;return}if(!d.push(l))return}}),d._destroy=function(l,g){!l&&u!==null&&(l=new Bg),a=null,o=null,s=null,u===null?g(l):(u=g,ko(r,l),ko(e,l))},d}});var kr=$((v5,Pg)=>{"use strict";var S5=f(h()),{ObjectDefineProperties:hA,ObjectGetOwnPropertyDescriptor:sn,ObjectKeys:pA,ObjectSetPrototypeOf:Cg}=Le();Pg.exports=ur;var mf=Hs(),Xt=Vc();Cg(ur.prototype,mf.prototype);Cg(ur,mf);{let t=pA(Xt.prototype);for(let e=0;e<t.length;e++){let r=t[e];ur.prototype[r]||(ur.prototype[r]=Xt.prototype[r])}}function ur(t){if(!(this instanceof ur))return new ur(t);mf.call(this,t),Xt.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}hA(ur.prototype,{writable:{__proto__:null,...sn(Xt.prototype,"writable")},writableHighWaterMark:{__proto__:null,...sn(Xt.prototype,"writableHighWaterMark")},writableObjectMode:{__proto__:null,...sn(Xt.prototype,"writableObjectMode")},writableBuffer:{__proto__:null,...sn(Xt.prototype,"writableBuffer")},writableLength:{__proto__:null,...sn(Xt.prototype,"writableLength")},writableFinished:{__proto__:null,...sn(Xt.prototype,"writableFinished")},writableCorked:{__proto__:null,...sn(Xt.prototype,"writableCorked")},writableEnded:{__proto__:null,...sn(Xt.prototype,"writableEnded")},writableNeedDrain:{__proto__:null,...sn(Xt.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 pf;function Ug(){return pf===void 0&&(pf={}),pf}ur.fromWeb=function(t,e){return Ug().newStreamDuplexFromReadableWritablePair(t,e)};ur.toWeb=function(t){return Ug().newReadableWritablePairFromDuplex(t)};var yf;ur.from=function(t){return yf||(yf=kg()),yf(t,"body")}});var bf=$((_5,Lg)=>{"use strict";var A5=f(h()),{ObjectSetPrototypeOf:Kg,Symbol:yA}=Le();Lg.exports=an;var{ERR_METHOD_NOT_IMPLEMENTED:mA}=bt().codes,wf=kr(),{getHighWaterMark:gA}=qs();Kg(an.prototype,wf.prototype);Kg(an,wf);var Gs=yA("kCallback");function an(t){if(!(this instanceof an))return new an(t);let e=t?gA(this,t,"readableHighWaterMark",!0):null;e===0&&(t={...t,highWaterMark:null,readableHighWaterMark:e,writableHighWaterMark:t.writableHighWaterMark||0}),wf.call(this,t),this._readableState.sync=!1,this[Gs]=null,t&&(typeof t.transform=="function"&&(this._transform=t.transform),typeof t.flush=="function"&&(this._flush=t.flush)),this.on("prefinish",wA)}function gf(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 wA(){this._final!==gf&&gf.call(this)}an.prototype._final=gf;an.prototype._transform=function(t,e,r){throw new mA("_transform()")};an.prototype._write=function(t,e,r){let n=this._readableState,i=this._writableState,o=n.length;this._transform(t,e,(s,a)=>{if(s){r(s);return}a!=null&&this.push(a),i.ended||o===n.length||n.length<n.highWaterMark?r():this[Gs]=r})};an.prototype._read=function(){if(this[Gs]){let t=this[Gs];this[Gs]=null,t()}}});var Ef=$((T5,Ng)=>{"use strict";var I5=f(h()),{ObjectSetPrototypeOf:Mg}=Le();Ng.exports=Co;var xf=bf();Mg(Co.prototype,xf.prototype);Mg(Co,xf);function Co(t){if(!(this instanceof Co))return new Co(t);xf.call(this,t)}Co.prototype._transform=function(t,e,r){r(null,t)}});var zc=$((D5,Hg)=>{var B5=f(h()),Js=Cn(),{ArrayIsArray:bA,Promise:xA,SymbolAsyncIterator:EA,SymbolDispose:vA}=Le(),Wc=on(),{once:SA}=yt(),_A=Di(),$g=kr(),{aggregateTwoErrors:AA,codes:{ERR_INVALID_ARG_TYPE:Rf,ERR_INVALID_RETURN_VALUE:vf,ERR_MISSING_ARGS:TA,ERR_STREAM_DESTROYED:IA,ERR_STREAM_PREMATURE_CLOSE:DA},AbortError:BA}=bt(),{validateFunction:RA,validateAbortSignal:OA}=So(),{isIterable:ki,isReadable:Sf,isReadableNodeStream:jc,isNodeStream:qg,isTransformStream:Uo,isWebStream:kA,isReadableStream:_f,isReadableFinished:CA}=Br(),UA=globalThis.AbortController||Eo().AbortController,Af,Tf,If;function Fg(t,e,r){let n=!1;t.on("close",()=>{n=!0});let i=Wc(t,{readable:e,writable:r},o=>{n=!o});return{destroy:o=>{n||(n=!0,_A.destroyer(t,o||new IA("pipe")))},cleanup:i}}function PA(t){return RA(t[t.length-1],"streams[stream.length - 1]"),t.pop()}function Df(t){if(ki(t))return t;if(jc(t))return KA(t);throw new Rf("val",["Readable","Iterable","AsyncIterable"],t)}async function*KA(t){Tf||(Tf=Hs()),yield*Tf.prototype[EA].call(t)}async function Hc(t,e,r,{end:n}){let i,o=null,s=d=>{if(d&&(i=d),o){let c=o;o=null,c()}},a=()=>new xA((d,c)=>{i?c(i):o=()=>{i?c(i):d()}});e.on("drain",s);let u=Wc(e,{readable:!1},s);try{e.writableNeedDrain&&await a();for await(let d of t)e.write(d)||await a();n&&(e.end(),await a()),r()}catch(d){r(i!==d?AA(i,d):d)}finally{u(),e.off("drain",s)}}async function Bf(t,e,r,{end:n}){Uo(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 LA(...t){return Vg(t,SA(PA(t)))}function Vg(t,e,r){if(t.length===1&&bA(t[0])&&(t=t[0]),t.length<2)throw new TA("streams");let n=new UA,i=n.signal,o=r?.signal,s=[];OA(o,"options.signal");function a(){m(new BA)}If=If||yt().addAbortListener;let u;o&&(u=If(o,a));let d,c,l=[],g=0;function w(S){m(S,--g===0)}function m(S,B){var I;if(S&&(!d||d.code==="ERR_STREAM_PREMATURE_CLOSE")&&(d=S),!(!d&&!B)){for(;l.length;)l.shift()(d);(I=u)===null||I===void 0||I[vA](),n.abort(),B&&(d||s.forEach(O=>O()),Js.nextTick(e,d,c))}}let y;for(let S=0;S<t.length;S++){let B=t[S],I=S<t.length-1,O=S>0,C=I||r?.end!==!1,P=S===t.length-1;if(qg(B)){let j=function(V){V&&V.name!=="AbortError"&&V.code!=="ERR_STREAM_PREMATURE_CLOSE"&&w(V)};var D=j;if(C){let{destroy:V,cleanup:z}=Fg(B,I,O);l.push(V),Sf(B)&&P&&s.push(z)}B.on("error",j),Sf(B)&&P&&s.push(()=>{B.removeListener("error",j)})}if(S===0)if(typeof B=="function"){if(y=B({signal:i}),!ki(y))throw new vf("Iterable, AsyncIterable or Stream","source",y)}else ki(B)||jc(B)||Uo(B)?y=B:y=$g.from(B);else if(typeof B=="function"){if(Uo(y)){var E;y=Df((E=y)===null||E===void 0?void 0:E.readable)}else y=Df(y);if(y=B(y,{signal:i}),I){if(!ki(y,!0))throw new vf("AsyncIterable",`transform[${S-1}]`,y)}else{var v;Af||(Af=Ef());let j=new Af({objectMode:!0}),V=(v=y)===null||v===void 0?void 0:v.then;if(typeof V=="function")g++,V.call(y,Q=>{c=Q,Q!=null&&j.write(Q),C&&j.end(),Js.nextTick(w)},Q=>{j.destroy(Q),Js.nextTick(w,Q)});else if(ki(y,!0))g++,Hc(y,j,w,{end:C});else if(_f(y)||Uo(y)){let Q=y.readable||y;g++,Hc(Q,j,w,{end:C})}else throw new vf("AsyncIterable or Promise","destination",y);y=j;let{destroy:z,cleanup:le}=Fg(y,!1,!0);l.push(z),P&&s.push(le)}}else if(qg(B)){if(jc(y)){g+=2;let j=MA(y,B,w,{end:C});Sf(B)&&P&&s.push(j)}else if(Uo(y)||_f(y)){let j=y.readable||y;g++,Hc(j,B,w,{end:C})}else if(ki(y))g++,Hc(y,B,w,{end:C});else throw new Rf("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=B}else if(kA(B)){if(jc(y))g++,Bf(Df(y),B,w,{end:C});else if(_f(y)||ki(y))g++,Bf(y,B,w,{end:C});else if(Uo(y))g++,Bf(y.readable,B,w,{end:C});else throw new Rf("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],y);y=B}else y=$g.from(B)}return(i!=null&&i.aborted||o!=null&&o.aborted)&&Js.nextTick(a),y}function MA(t,e,r,{end:n}){let i=!1;if(e.on("close",()=>{i||r(new DA)}),t.pipe(e,{end:!1}),n){let s=function(){i=!0,e.end()};var o=s;CA(t)?Js.nextTick(s):t.once("end",s)}else r();return Wc(t,{readable:!0,writable:!1},s=>{let a=t._readableState;s&&s.code==="ERR_STREAM_PREMATURE_CLOSE"&&a&&a.ended&&!a.errored&&!a.errorEmitted?t.once("end",r).once("error",r):r(s)}),Wc(e,{readable:!1,writable:!0},r)}Hg.exports={pipelineImpl:Vg,pipeline:LA}});var kf=$((R5,Yg)=>{"use strict";var O5=f(h()),{pipeline:NA}=zc(),Gc=kr(),{destroyer:$A}=Di(),{isNodeStream:Jc,isReadable:jg,isWritable:Wg,isWebStream:Of,isTransformStream:Ci,isWritableStream:zg,isReadableStream:Gg}=Br(),{AbortError:qA,codes:{ERR_INVALID_ARG_VALUE:Jg,ERR_MISSING_ARGS:FA}}=bt(),VA=on();Yg.exports=function(...e){if(e.length===0)throw new FA("streams");if(e.length===1)return Gc.from(e[0]);let r=[...e];if(typeof e[0]=="function"&&(e[0]=Gc.from(e[0])),typeof e[e.length-1]=="function"){let w=e.length-1;e[w]=Gc.from(e[w])}for(let w=0;w<e.length;++w)if(!(!Jc(e[w])&&!Of(e[w]))){if(w<e.length-1&&!(jg(e[w])||Gg(e[w])||Ci(e[w])))throw new Jg(`streams[${w}]`,r[w],"must be readable");if(w>0&&!(Wg(e[w])||zg(e[w])||Ci(e[w])))throw new Jg(`streams[${w}]`,r[w],"must be writable")}let n,i,o,s,a;function u(w){let m=s;s=null,m?m(w):w?a.destroy(w):!g&&!l&&a.destroy()}let d=e[0],c=NA(e,u),l=!!(Wg(d)||zg(d)||Ci(d)),g=!!(jg(c)||Gg(c)||Ci(c));if(a=new Gc({writableObjectMode:!!(d!=null&&d.writableObjectMode),readableObjectMode:!!(c!=null&&c.readableObjectMode),writable:l,readable:g}),l){if(Jc(d))a._write=function(m,y,E){d.write(m,y)?E():n=E},a._final=function(m){d.end(),i=m},d.on("drain",function(){if(n){let m=n;n=null,m()}});else if(Of(d)){let y=(Ci(d)?d.writable:d).getWriter();a._write=async function(E,v,D){try{await y.ready,y.write(E).catch(()=>{}),D()}catch(S){D(S)}},a._final=async function(E){try{await y.ready,y.close().catch(()=>{}),i=E}catch(v){E(v)}}}let w=Ci(c)?c.readable:c;VA(w,()=>{if(i){let m=i;i=null,m()}})}if(g){if(Jc(c))c.on("readable",function(){if(o){let w=o;o=null,w()}}),c.on("end",function(){a.push(null)}),a._read=function(){for(;;){let w=c.read();if(w===null){o=a._read;return}if(!a.push(w))return}};else if(Of(c)){let m=(Ci(c)?c.readable:c).getReader();a._read=async function(){for(;;)try{let{value:y,done:E}=await m.read();if(!a.push(y))return;if(E){a.push(null);return}}catch{return}}}}return a._destroy=function(w,m){!w&&s!==null&&(w=new qA),o=null,n=null,i=null,s===null?m(w):(s=m,Jc(c)&&$A(c,w))},a}});var sw=$((k5,Pf)=>{"use strict";var C5=f(h()),HA=globalThis.AbortController||Eo().AbortController,{codes:{ERR_INVALID_ARG_VALUE:jA,ERR_INVALID_ARG_TYPE:Ys,ERR_MISSING_ARGS:WA,ERR_OUT_OF_RANGE:zA},AbortError:Cr}=bt(),{validateAbortSignal:Ui,validateInteger:Xg,validateObject:Pi}=So(),GA=Le().Symbol("kWeak"),JA=Le().Symbol("kResistStopPropagation"),{finished:YA}=on(),XA=kf(),{addAbortSignalNoValidate:ZA}=$s(),{isWritable:QA,isNodeStream:eT}=Br(),{deprecate:tT}=yt(),{ArrayPrototypePush:rT,Boolean:nT,MathFloor:Zg,Number:iT,NumberIsNaN:oT,Promise:Qg,PromiseReject:ew,PromiseResolve:sT,PromisePrototypeThen:tw,Symbol:nw}=Le(),Yc=nw("kEmpty"),rw=nw("kEof");function aT(t,e){if(e!=null&&Pi(e,"options"),e?.signal!=null&&Ui(e.signal,"options.signal"),eT(t)&&!QA(t))throw new jA("stream",t,"must be writable");let r=XA(this,t);return e!=null&&e.signal&&ZA(e.signal,r),r}function Xc(t,e){if(typeof t!="function")throw new Ys("fn",["Function","AsyncFunction"],t);e!=null&&Pi(e,"options"),e?.signal!=null&&Ui(e.signal,"options.signal");let r=1;e?.concurrency!=null&&(r=Zg(e.concurrency));let n=r-1;return e?.highWaterMark!=null&&(n=Zg(e.highWaterMark)),Xg(r,"options.concurrency",1),Xg(n,"options.highWaterMark",0),n+=r,(async function*(){let o=yt().AbortSignalAny([e?.signal].filter(nT)),s=this,a=[],u={signal:o},d,c,l=!1,g=0;function w(){l=!0,m()}function m(){g-=1,y()}function y(){c&&!l&&g<r&&a.length<n&&(c(),c=null)}async function E(){try{for await(let v of s){if(l)return;if(o.aborted)throw new Cr;try{if(v=t(v,u),v===Yc)continue;v=sT(v)}catch(D){v=ew(D)}g+=1,tw(v,m,w),a.push(v),d&&(d(),d=null),!l&&(a.length>=n||g>=r)&&await new Qg(D=>{c=D})}a.push(rw)}catch(v){let D=ew(v);tw(D,m,w),a.push(D)}finally{l=!0,d&&(d(),d=null)}}E();try{for(;;){for(;a.length>0;){let v=await a[0];if(v===rw)return;if(o.aborted)throw new Cr;v!==Yc&&(yield v),a.shift(),y()}await new Qg(v=>{d=v})}}finally{l=!0,c&&(c(),c=null)}}).call(this)}function cT(t=void 0){return t!=null&&Pi(t,"options"),t?.signal!=null&&Ui(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 Cr({cause:t.signal.reason});yield[r++,i]}}).call(this)}async function iw(t,e=void 0){for await(let r of Uf.call(this,t,e))return!0;return!1}async function uT(t,e=void 0){if(typeof t!="function")throw new Ys("fn",["Function","AsyncFunction"],t);return!await iw.call(this,async(...r)=>!await t(...r),e)}async function dT(t,e){for await(let r of Uf.call(this,t,e))return r}async function lT(t,e){if(typeof t!="function")throw new Ys("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i),Yc}for await(let n of Xc.call(this,r,e));}function Uf(t,e){if(typeof t!="function")throw new Ys("fn",["Function","AsyncFunction"],t);async function r(n,i){return await t(n,i)?n:Yc}return Xc.call(this,r,e)}var Cf=class extends WA{constructor(){super("reduce"),this.message="Reduce of an empty stream requires an initial value"}};async function fT(t,e,r){var n;if(typeof t!="function")throw new Ys("reducer",["Function","AsyncFunction"],t);r!=null&&Pi(r,"options"),r?.signal!=null&&Ui(r.signal,"options.signal");let i=arguments.length>1;if(r!=null&&(n=r.signal)!==null&&n!==void 0&&n.aborted){let d=new Cr(void 0,{cause:r.signal.reason});throw this.once("error",()=>{}),await YA(this.destroy(d)),d}let o=new HA,s=o.signal;if(r!=null&&r.signal){let d={once:!0,[GA]:this,[JA]:!0};r.signal.addEventListener("abort",()=>o.abort(),d)}let a=!1;try{for await(let d of this){var u;if(a=!0,r!=null&&(u=r.signal)!==null&&u!==void 0&&u.aborted)throw new Cr;i?e=await t(e,d,{signal:s}):(e=d,i=!0)}if(!a&&!i)throw new Cf}finally{o.abort()}return e}async function hT(t){t!=null&&Pi(t,"options"),t?.signal!=null&&Ui(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 Cr(void 0,{cause:t.signal.reason});rT(e,n)}return e}function pT(t,e){let r=Xc.call(this,t,e);return(async function*(){for await(let i of r)yield*i}).call(this)}function ow(t){if(t=iT(t),oT(t))return 0;if(t<0)throw new zA("number",">= 0",t);return t}function yT(t,e=void 0){return e!=null&&Pi(e,"options"),e?.signal!=null&&Ui(e.signal,"options.signal"),t=ow(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new Cr;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new Cr;t--<=0&&(yield o)}}).call(this)}function mT(t,e=void 0){return e!=null&&Pi(e,"options"),e?.signal!=null&&Ui(e.signal,"options.signal"),t=ow(t),(async function*(){var n;if(e!=null&&(n=e.signal)!==null&&n!==void 0&&n.aborted)throw new Cr;for await(let o of this){var i;if(e!=null&&(i=e.signal)!==null&&i!==void 0&&i.aborted)throw new Cr;if(t-- >0&&(yield o),t<=0)return}}).call(this)}Pf.exports.streamReturningOperators={asIndexedPairs:tT(cT,"readable.asIndexedPairs will be removed in a future version."),drop:yT,filter:Uf,flatMap:pT,map:Xc,take:mT,compose:aT};Pf.exports.promiseReturningOperators={every:uT,forEach:lT,reduce:fT,toArray:hT,some:iw,find:dT}});var Kf=$((U5,aw)=>{"use strict";var P5=f(h()),{ArrayPrototypePop:gT,Promise:wT}=Le(),{isIterable:bT,isNodeStream:xT,isWebStream:ET}=Br(),{pipelineImpl:vT}=zc(),{finished:ST}=on();Lf();function _T(...t){return new wT((e,r)=>{let n,i,o=t[t.length-1];if(o&&typeof o=="object"&&!xT(o)&&!bT(o)&&!ET(o)){let s=gT(t);n=s.signal,i=s.end}vT(t,(s,a)=>{s?r(s):e(a)},{signal:n,end:i})})}aw.exports={finished:ST,pipeline:_T}});var Lf=$((K5,mw)=>{var L5=f(h()),{Buffer:AT}=_t(),{ObjectDefineProperty:cn,ObjectKeys:dw,ReflectApply:lw}=Le(),{promisify:{custom:fw}}=yt(),{streamReturningOperators:cw,promiseReturningOperators:uw}=sw(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:hw}}=bt(),TT=kf(),{setDefaultHighWaterMark:IT,getDefaultHighWaterMark:DT}=qs(),{pipeline:pw}=zc(),{destroyer:BT}=Di(),yw=on(),Mf=Kf(),Xs=Br(),Te=mw.exports=Rc().Stream;Te.isDestroyed=Xs.isDestroyed;Te.isDisturbed=Xs.isDisturbed;Te.isErrored=Xs.isErrored;Te.isReadable=Xs.isReadable;Te.isWritable=Xs.isWritable;Te.Readable=Hs();for(let t of dw(cw)){let r=function(...n){if(new.target)throw hw();return Te.Readable.from(lw(e,this,n))};Nf=r;let e=cw[t];cn(r,"name",{__proto__:null,value:e.name}),cn(r,"length",{__proto__:null,value:e.length}),cn(Te.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var Nf;for(let t of dw(uw)){let r=function(...i){if(new.target)throw hw();return lw(e,this,i)};Nf=r;let e=uw[t];cn(r,"name",{__proto__:null,value:e.name}),cn(r,"length",{__proto__:null,value:e.length}),cn(Te.Readable.prototype,t,{__proto__:null,value:r,enumerable:!1,configurable:!0,writable:!0})}var Nf;Te.Writable=Vc();Te.Duplex=kr();Te.Transform=bf();Te.PassThrough=Ef();Te.pipeline=pw;var{addAbortSignal:RT}=$s();Te.addAbortSignal=RT;Te.finished=yw;Te.destroy=BT;Te.compose=TT;Te.setDefaultHighWaterMark=IT;Te.getDefaultHighWaterMark=DT;cn(Te,"promises",{__proto__:null,configurable:!0,enumerable:!0,get(){return Mf}});cn(pw,fw,{__proto__:null,enumerable:!0,get(){return Mf.pipeline}});cn(yw,fw,{__proto__:null,enumerable:!0,get(){return Mf.finished}});Te.Stream=Te;Te._isUint8Array=function(e){return e instanceof Uint8Array};Te._uint8ArrayToBuffer=function(e){return AT.from(e.buffer,e.byteOffset,e.byteLength)}});var $f=$((M5,Fe)=>{"use strict";var N5=f(h()),Je=Lf(),OT=Kf(),kT=Je.Readable.destroy;Fe.exports=Je.Readable;Fe.exports._uint8ArrayToBuffer=Je._uint8ArrayToBuffer;Fe.exports._isUint8Array=Je._isUint8Array;Fe.exports.isDisturbed=Je.isDisturbed;Fe.exports.isErrored=Je.isErrored;Fe.exports.isReadable=Je.isReadable;Fe.exports.Readable=Je.Readable;Fe.exports.Writable=Je.Writable;Fe.exports.Duplex=Je.Duplex;Fe.exports.Transform=Je.Transform;Fe.exports.PassThrough=Je.PassThrough;Fe.exports.addAbortSignal=Je.addAbortSignal;Fe.exports.finished=Je.finished;Fe.exports.destroy=Je.destroy;Fe.exports.destroy=kT;Fe.exports.pipeline=Je.pipeline;Fe.exports.compose=Je.compose;Object.defineProperty(Je,"promises",{configurable:!0,enumerable:!0,get(){return OT}});Fe.exports.Stream=Je.Stream;Fe.exports.default=Fe.exports});var Ub=$((Fu,Cb)=>{var rK=f(h());(function(t,e){typeof Fu=="object"&&typeof Cb<"u"?e(Fu):typeof define=="function"&&define.amd?define(["exports"],e):e(t.URI=t.URI||{})})(Fu,function(t){"use strict";function e(){for(var b=arguments.length,p=Array(b),x=0;x<b;x++)p[x]=arguments[x];if(p.length>1){p[0]=p[0].slice(0,-1);for(var _=p.length-1,A=1;A<_;++A)p[A]=p[A].slice(1,-1);return p[_]=p[_].slice(1),p.join("")}else return p[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,p){var x=b;if(p)for(var _ in p)x[_]=p[_];return x}function a(b){var p="[A-Za-z]",x="[\\x0D]",_="[0-9]",A="[\\x22]",L=e(_,"[A-Fa-f]"),se="[\\x0A]",ye="[\\x20]",be=r(r("%[EFef]"+L+"%"+L+L+"%"+L+L)+"|"+r("%[89A-Fa-f]"+L+"%"+L+L)+"|"+r("%"+L+L)),He="[\\:\\/\\?\\#\\[\\]\\@]",pe="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",Pe=e(He,pe),je=b?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",Oe=b?"[\\uE000-\\uF8FF]":"[]",me=e(p,_,"[\\-\\.\\_\\~]",je),Ke=r(p+e(p,_,"[\\+\\-\\.]")+"*"),xe=r(r(be+"|"+e(me,pe,"[\\:]"))+"*"),ei=r(r("25[0-5]")+"|"+r("2[0-4]"+_)+"|"+r("1"+_+_)+"|"+r("[1-9]"+_)+"|"+_),Ct=r(r("25[0-5]")+"|"+r("2[0-4]"+_)+"|"+r("1"+_+_)+"|"+r("0?[1-9]"+_)+"|0?0?"+_),jt=r(Ct+"\\."+Ct+"\\."+Ct+"\\."+Ct),Se=r(L+"{1,4}"),Ut=r(r(Se+"\\:"+Se)+"|"+jt),Wt=r(r(Se+"\\:")+"{6}"+Ut),br=r("\\:\\:"+r(Se+"\\:")+"{5}"+Ut),ti=r(r(Se)+"?\\:\\:"+r(Se+"\\:")+"{4}"+Ut),Vr=r(r(r(Se+"\\:")+"{0,1}"+Se)+"?\\:\\:"+r(Se+"\\:")+"{3}"+Ut),us=r(r(r(Se+"\\:")+"{0,2}"+Se)+"?\\:\\:"+r(Se+"\\:")+"{2}"+Ut),Ka=r(r(r(Se+"\\:")+"{0,3}"+Se)+"?\\:\\:"+Se+"\\:"+Ut),La=r(r(r(Se+"\\:")+"{0,4}"+Se)+"?\\:\\:"+Ut),Gi=r(r(r(Se+"\\:")+"{0,5}"+Se)+"?\\:\\:"+Se),Ji=r(r(r(Se+"\\:")+"{0,6}"+Se)+"?\\:\\:"),Hr=r([Wt,br,ti,Vr,us,Ka,La,Gi,Ji].join("|")),Yi=r(r(me+"|"+be)+"+"),ad=r(Hr+"\\%25"+Yi),ri=r(Hr+r("\\%25|\\%(?!"+L+"{2})")+Yi),Lx=r("[vV]"+L+"+\\."+e(me,pe,"[\\:]")+"+"),Mx=r("\\["+r(ri+"|"+Hr+"|"+Lx)+"\\]"),wp=r(r(be+"|"+e(me,pe))+"*"),ds=r(Mx+"|"+jt+"(?!"+wp+")|"+wp),ls=r(_+"*"),bp=r(r(xe+"@")+"?"+ds+r("\\:"+ls)+"?"),fs=r(be+"|"+e(me,pe,"[\\:\\@]")),Nx=r(fs+"*"),xp=r(fs+"+"),$x=r(r(be+"|"+e(me,pe,"[\\@]"))+"+"),jr=r(r("\\/"+Nx)+"*"),Xi=r("\\/"+r(xp+jr)+"?"),cd=r($x+jr),Ma=r(xp+jr),Zi="(?!"+fs+")",CB=r(jr+"|"+Xi+"|"+cd+"|"+Ma+"|"+Zi),Qi=r(r(fs+"|"+e("[\\/\\?]",Oe))+"*"),hs=r(r(fs+"|[\\/\\?]")+"*"),Ep=r(r("\\/\\/"+bp+jr)+"|"+Xi+"|"+Ma+"|"+Zi),qx=r(Ke+"\\:"+Ep+r("\\?"+Qi)+"?"+r("\\#"+hs)+"?"),Fx=r(r("\\/\\/"+bp+jr)+"|"+Xi+"|"+cd+"|"+Zi),Vx=r(Fx+r("\\?"+Qi)+"?"+r("\\#"+hs)+"?"),UB=r(qx+"|"+Vx),PB=r(Ke+"\\:"+Ep+r("\\?"+Qi)+"?"),KB="^("+Ke+")\\:"+r(r("\\/\\/("+r("("+xe+")@")+"?("+ds+")"+r("\\:("+ls+")")+"?)")+"?("+jr+"|"+Xi+"|"+Ma+"|"+Zi+")")+r("\\?("+Qi+")")+"?"+r("\\#("+hs+")")+"?$",LB="^(){0}"+r(r("\\/\\/("+r("("+xe+")@")+"?("+ds+")"+r("\\:("+ls+")")+"?)")+"?("+jr+"|"+Xi+"|"+cd+"|"+Zi+")")+r("\\?("+Qi+")")+"?"+r("\\#("+hs+")")+"?$",MB="^("+Ke+")\\:"+r(r("\\/\\/("+r("("+xe+")@")+"?("+ds+")"+r("\\:("+ls+")")+"?)")+"?("+jr+"|"+Xi+"|"+Ma+"|"+Zi+")")+r("\\?("+Qi+")")+"?$",NB="^"+r("\\#("+hs+")")+"?$",$B="^"+r("("+xe+")@")+"?("+ds+")"+r("\\:("+ls+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",p,_,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",me,pe),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",me,pe),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",me,pe),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",me,pe),"g"),NOT_QUERY:new RegExp(e("[^\\%]",me,pe,"[\\:\\@\\/\\?]",Oe),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",me,pe,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",me,pe),"g"),UNRESERVED:new RegExp(me,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",me,Pe),"g"),PCT_ENCODED:new RegExp(be,"g"),IPV4ADDRESS:new RegExp("^("+jt+")$"),IPV6ADDRESS:new RegExp("^\\[?("+Hr+")"+r(r("\\%25|\\%(?!"+L+"{2})")+"("+Yi+")")+"?\\]?$")}}var u=a(!1),d=a(!0),c=function(){function b(p,x){var _=[],A=!0,L=!1,se=void 0;try{for(var ye=p[Symbol.iterator](),be;!(A=(be=ye.next()).done)&&(_.push(be.value),!(x&&_.length===x));A=!0);}catch(He){L=!0,se=He}finally{try{!A&&ye.return&&ye.return()}finally{if(L)throw se}}return _}return function(p,x){if(Array.isArray(p))return p;if(Symbol.iterator in Object(p))return b(p,x);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=function(b){if(Array.isArray(b)){for(var p=0,x=Array(b.length);p<b.length;p++)x[p]=b[p];return x}else return Array.from(b)},g=2147483647,w=36,m=1,y=26,E=38,v=700,D=72,S=128,B="-",I=/^xn--/,O=/[^\0-\x7E]/,C=/[\x2E\u3002\uFF0E\uFF61]/g,P={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},j=w-m,V=Math.floor,z=String.fromCharCode;function le(b){throw new RangeError(P[b])}function Q(b,p){for(var x=[],_=b.length;_--;)x[_]=p(b[_]);return x}function st(b,p){var x=b.split("@"),_="";x.length>1&&(_=x[0]+"@",b=x[1]),b=b.replace(C,".");var A=b.split("."),L=Q(A,p).join(".");return _+L}function k(b){for(var p=[],x=0,_=b.length;x<_;){var A=b.charCodeAt(x++);if(A>=55296&&A<=56319&&x<_){var L=b.charCodeAt(x++);(L&64512)==56320?p.push(((A&1023)<<10)+(L&1023)+65536):(p.push(A),x--)}else p.push(A)}return p}var N=function(p){return String.fromCodePoint.apply(String,l(p))},re=function(p){return p-48<10?p-22:p-65<26?p-65:p-97<26?p-97:w},U=function(p,x){return p+22+75*(p<26)-((x!=0)<<5)},R=function(p,x,_){var A=0;for(p=_?V(p/v):p>>1,p+=V(p/x);p>j*y>>1;A+=w)p=V(p/j);return V(A+(j+1)*p/(p+E))},K=function(p){var x=[],_=p.length,A=0,L=S,se=D,ye=p.lastIndexOf(B);ye<0&&(ye=0);for(var be=0;be<ye;++be)p.charCodeAt(be)>=128&&le("not-basic"),x.push(p.charCodeAt(be));for(var He=ye>0?ye+1:0;He<_;){for(var pe=A,Pe=1,je=w;;je+=w){He>=_&&le("invalid-input");var Oe=re(p.charCodeAt(He++));(Oe>=w||Oe>V((g-A)/Pe))&&le("overflow"),A+=Oe*Pe;var me=je<=se?m:je>=se+y?y:je-se;if(Oe<me)break;var Ke=w-me;Pe>V(g/Ke)&&le("overflow"),Pe*=Ke}var xe=x.length+1;se=R(A-pe,xe,pe==0),V(A/xe)>g-L&&le("overflow"),L+=V(A/xe),A%=xe,x.splice(A++,0,L)}return String.fromCodePoint.apply(String,x)},H=function(p){var x=[];p=k(p);var _=p.length,A=S,L=0,se=D,ye=!0,be=!1,He=void 0;try{for(var pe=p[Symbol.iterator](),Pe;!(ye=(Pe=pe.next()).done);ye=!0){var je=Pe.value;je<128&&x.push(z(je))}}catch(ri){be=!0,He=ri}finally{try{!ye&&pe.return&&pe.return()}finally{if(be)throw He}}var Oe=x.length,me=Oe;for(Oe&&x.push(B);me<_;){var Ke=g,xe=!0,ei=!1,Ct=void 0;try{for(var jt=p[Symbol.iterator](),Se;!(xe=(Se=jt.next()).done);xe=!0){var Ut=Se.value;Ut>=A&&Ut<Ke&&(Ke=Ut)}}catch(ri){ei=!0,Ct=ri}finally{try{!xe&&jt.return&&jt.return()}finally{if(ei)throw Ct}}var Wt=me+1;Ke-A>V((g-L)/Wt)&&le("overflow"),L+=(Ke-A)*Wt,A=Ke;var br=!0,ti=!1,Vr=void 0;try{for(var us=p[Symbol.iterator](),Ka;!(br=(Ka=us.next()).done);br=!0){var La=Ka.value;if(La<A&&++L>g&&le("overflow"),La==A){for(var Gi=L,Ji=w;;Ji+=w){var Hr=Ji<=se?m:Ji>=se+y?y:Ji-se;if(Gi<Hr)break;var Yi=Gi-Hr,ad=w-Hr;x.push(z(U(Hr+Yi%ad,0))),Gi=V(Yi/ad)}x.push(z(U(Gi,0))),se=R(L,Wt,me==Oe),L=0,++me}}}catch(ri){ti=!0,Vr=ri}finally{try{!br&&us.return&&us.return()}finally{if(ti)throw Vr}}++L,++A}return x.join("")},X=function(p){return st(p,function(x){return I.test(x)?K(x.slice(4).toLowerCase()):x})},ne=function(p){return st(p,function(x){return O.test(x)?"xn--"+H(x):x})},ee={version:"2.1.0",ucs2:{decode:k,encode:N},decode:K,encode:H,toASCII:ne,toUnicode:X},te={};function Z(b){var p=b.charCodeAt(0),x=void 0;return p<16?x="%0"+p.toString(16).toUpperCase():p<128?x="%"+p.toString(16).toUpperCase():p<2048?x="%"+(p>>6|192).toString(16).toUpperCase()+"%"+(p&63|128).toString(16).toUpperCase():x="%"+(p>>12|224).toString(16).toUpperCase()+"%"+(p>>6&63|128).toString(16).toUpperCase()+"%"+(p&63|128).toString(16).toUpperCase(),x}function ie(b){for(var p="",x=0,_=b.length;x<_;){var A=parseInt(b.substr(x+1,2),16);if(A<128)p+=String.fromCharCode(A),x+=3;else if(A>=194&&A<224){if(_-x>=6){var L=parseInt(b.substr(x+4,2),16);p+=String.fromCharCode((A&31)<<6|L&63)}else p+=b.substr(x,6);x+=6}else if(A>=224){if(_-x>=9){var se=parseInt(b.substr(x+4,2),16),ye=parseInt(b.substr(x+7,2),16);p+=String.fromCharCode((A&15)<<12|(se&63)<<6|ye&63)}else p+=b.substr(x,9);x+=9}else p+=b.substr(x,3),x+=3}return p}function Re(b,p){function x(_){var A=ie(_);return A.match(p.UNRESERVED)?A:_}return b.scheme&&(b.scheme=String(b.scheme).replace(p.PCT_ENCODED,x).toLowerCase().replace(p.NOT_SCHEME,"")),b.userinfo!==void 0&&(b.userinfo=String(b.userinfo).replace(p.PCT_ENCODED,x).replace(p.NOT_USERINFO,Z).replace(p.PCT_ENCODED,i)),b.host!==void 0&&(b.host=String(b.host).replace(p.PCT_ENCODED,x).toLowerCase().replace(p.NOT_HOST,Z).replace(p.PCT_ENCODED,i)),b.path!==void 0&&(b.path=String(b.path).replace(p.PCT_ENCODED,x).replace(b.scheme?p.NOT_PATH:p.NOT_PATH_NOSCHEME,Z).replace(p.PCT_ENCODED,i)),b.query!==void 0&&(b.query=String(b.query).replace(p.PCT_ENCODED,x).replace(p.NOT_QUERY,Z).replace(p.PCT_ENCODED,i)),b.fragment!==void 0&&(b.fragment=String(b.fragment).replace(p.PCT_ENCODED,x).replace(p.NOT_FRAGMENT,Z).replace(p.PCT_ENCODED,i)),b}function Ae(b){return b.replace(/^0*(.*)/,"$1")||"0"}function Ne(b,p){var x=b.match(p.IPV4ADDRESS)||[],_=c(x,2),A=_[1];return A?A.split(".").map(Ae).join("."):b}function Ve(b,p){var x=b.match(p.IPV6ADDRESS)||[],_=c(x,3),A=_[1],L=_[2];if(A){for(var se=A.toLowerCase().split("::").reverse(),ye=c(se,2),be=ye[0],He=ye[1],pe=He?He.split(":").map(Ae):[],Pe=be.split(":").map(Ae),je=p.IPV4ADDRESS.test(Pe[Pe.length-1]),Oe=je?7:8,me=Pe.length-Oe,Ke=Array(Oe),xe=0;xe<Oe;++xe)Ke[xe]=pe[xe]||Pe[me+xe]||"";je&&(Ke[Oe-1]=Ne(Ke[Oe-1],p));var ei=Ke.reduce(function(Wt,br,ti){if(!br||br==="0"){var Vr=Wt[Wt.length-1];Vr&&Vr.index+Vr.length===ti?Vr.length++:Wt.push({index:ti,length:1})}return Wt},[]),Ct=ei.sort(function(Wt,br){return br.length-Wt.length})[0],jt=void 0;if(Ct&&Ct.length>1){var Se=Ke.slice(0,Ct.index),Ut=Ke.slice(Ct.index+Ct.length);jt=Se.join(":")+"::"+Ut.join(":")}else jt=Ke.join(":");return L&&(jt+="%"+L),jt}else return b}var $e=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,tt="".match(/(){0}/)[1]===void 0;function We(b){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},x={},_=p.iri!==!1?d:u;p.reference==="suffix"&&(b=(p.scheme?p.scheme+":":"")+"//"+b);var A=b.match($e);if(A){tt?(x.scheme=A[1],x.userinfo=A[3],x.host=A[4],x.port=parseInt(A[5],10),x.path=A[6]||"",x.query=A[7],x.fragment=A[8],isNaN(x.port)&&(x.port=A[5])):(x.scheme=A[1]||void 0,x.userinfo=b.indexOf("@")!==-1?A[3]:void 0,x.host=b.indexOf("//")!==-1?A[4]:void 0,x.port=parseInt(A[5],10),x.path=A[6]||"",x.query=b.indexOf("?")!==-1?A[7]:void 0,x.fragment=b.indexOf("#")!==-1?A[8]:void 0,isNaN(x.port)&&(x.port=b.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?A[4]:void 0)),x.host&&(x.host=Ve(Ne(x.host,_),_)),x.scheme===void 0&&x.userinfo===void 0&&x.host===void 0&&x.port===void 0&&!x.path&&x.query===void 0?x.reference="same-document":x.scheme===void 0?x.reference="relative":x.fragment===void 0?x.reference="absolute":x.reference="uri",p.reference&&p.reference!=="suffix"&&p.reference!==x.reference&&(x.error=x.error||"URI is not a "+p.reference+" reference.");var L=te[(p.scheme||x.scheme||"").toLowerCase()];if(!p.unicodeSupport&&(!L||!L.unicodeSupport)){if(x.host&&(p.domainHost||L&&L.domainHost))try{x.host=ee.toASCII(x.host.replace(_.PCT_ENCODED,ie).toLowerCase())}catch(se){x.error=x.error||"Host's domain name can not be converted to ASCII via punycode: "+se}Re(x,u)}else Re(x,_);L&&L.parse&&L.parse(x,p)}else x.error=x.error||"URI can not be parsed.";return x}function Fr(b,p){var x=p.iri!==!1?d:u,_=[];return b.userinfo!==void 0&&(_.push(b.userinfo),_.push("@")),b.host!==void 0&&_.push(Ve(Ne(String(b.host),x),x).replace(x.IPV6ADDRESS,function(A,L,se){return"["+L+(se?"%25"+se:"")+"]"})),(typeof b.port=="number"||typeof b.port=="string")&&(_.push(":"),_.push(String(b.port))),_.length?_.join(""):void 0}var xn=/^\.\.?\//,os=/^\/\.(\/|$)/,Ra=/^\/\.\.(\/|$)/,id=/^\/?(?:.|\n)*?(?=\/|$)/;function En(b){for(var p=[];b.length;)if(b.match(xn))b=b.replace(xn,"");else if(b.match(os))b=b.replace(os,"/");else if(b.match(Ra))b=b.replace(Ra,"/"),p.pop();else if(b==="."||b==="..")b="";else{var x=b.match(id);if(x){var _=x[0];b=b.slice(_.length),p.push(_)}else throw new Error("Unexpected dot segment condition")}return p.join("")}function Vt(b){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},x=p.iri?d:u,_=[],A=te[(p.scheme||b.scheme||"").toLowerCase()];if(A&&A.serialize&&A.serialize(b,p),b.host&&!x.IPV6ADDRESS.test(b.host)){if(p.domainHost||A&&A.domainHost)try{b.host=p.iri?ee.toUnicode(b.host):ee.toASCII(b.host.replace(x.PCT_ENCODED,ie).toLowerCase())}catch(ye){b.error=b.error||"Host's domain name can not be converted to "+(p.iri?"Unicode":"ASCII")+" via punycode: "+ye}}Re(b,x),p.reference!=="suffix"&&b.scheme&&(_.push(b.scheme),_.push(":"));var L=Fr(b,p);if(L!==void 0&&(p.reference!=="suffix"&&_.push("//"),_.push(L),b.path&&b.path.charAt(0)!=="/"&&_.push("/")),b.path!==void 0){var se=b.path;!p.absolutePath&&(!A||!A.absolutePath)&&(se=En(se)),L===void 0&&(se=se.replace(/^\/\//,"/%2F")),_.push(se)}return b.query!==void 0&&(_.push("?"),_.push(b.query)),b.fragment!==void 0&&(_.push("#"),_.push(b.fragment)),_.join("")}function ss(b,p){var x=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=arguments[3],A={};return _||(b=We(Vt(b,x),x),p=We(Vt(p,x),x)),x=x||{},!x.tolerant&&p.scheme?(A.scheme=p.scheme,A.userinfo=p.userinfo,A.host=p.host,A.port=p.port,A.path=En(p.path||""),A.query=p.query):(p.userinfo!==void 0||p.host!==void 0||p.port!==void 0?(A.userinfo=p.userinfo,A.host=p.host,A.port=p.port,A.path=En(p.path||""),A.query=p.query):(p.path?(p.path.charAt(0)==="/"?A.path=En(p.path):((b.userinfo!==void 0||b.host!==void 0||b.port!==void 0)&&!b.path?A.path="/"+p.path:b.path?A.path=b.path.slice(0,b.path.lastIndexOf("/")+1)+p.path:A.path=p.path,A.path=En(A.path)),A.query=p.query):(A.path=b.path,p.query!==void 0?A.query=p.query:A.query=b.query),A.userinfo=b.userinfo,A.host=b.host,A.port=b.port),A.scheme=b.scheme),A.fragment=p.fragment,A}function Oa(b,p,x){var _=s({scheme:"null"},x);return Vt(ss(We(b,_),We(p,_),_,!0),_)}function as(b,p){return typeof b=="string"?b=Vt(We(b,p),p):n(b)==="object"&&(b=We(Vt(b,p),p)),b}function ka(b,p,x){return typeof b=="string"?b=Vt(We(b,x),x):n(b)==="object"&&(b=Vt(b,x)),typeof p=="string"?p=Vt(We(p,x),x):n(p)==="object"&&(p=Vt(p,x)),b===p}function Ca(b,p){return b&&b.toString().replace(!p||!p.iri?u.ESCAPE:d.ESCAPE,Z)}function Ht(b,p){return b&&b.toString().replace(!p||!p.iri?u.PCT_ENCODED:d.PCT_ENCODED,ie)}var vn={scheme:"http",domainHost:!0,parse:function(p,x){return p.host||(p.error=p.error||"HTTP URIs must have a host."),p},serialize:function(p,x){var _=String(p.scheme).toLowerCase()==="https";return(p.port===(_?443:80)||p.port==="")&&(p.port=void 0),p.path||(p.path="/"),p}},cs={scheme:"https",domainHost:vn.domainHost,parse:vn.parse,serialize:vn.serialize};function Ua(b){return typeof b.secure=="boolean"?b.secure:String(b.scheme).toLowerCase()==="wss"}var Qn={scheme:"ws",domainHost:!0,parse:function(p,x){var _=p;return _.secure=Ua(_),_.resourceName=(_.path||"/")+(_.query?"?"+_.query:""),_.path=void 0,_.query=void 0,_},serialize:function(p,x){if((p.port===(Ua(p)?443:80)||p.port==="")&&(p.port=void 0),typeof p.secure=="boolean"&&(p.scheme=p.secure?"wss":"ws",p.secure=void 0),p.resourceName){var _=p.resourceName.split("?"),A=c(_,2),L=A[0],se=A[1];p.path=L&&L!=="/"?L:void 0,p.query=se,p.resourceName=void 0}return p.fragment=void 0,p}},Pa={scheme:"wss",domainHost:Qn.domainHost,parse:Qn.parse,serialize:Qn.serialize},od={},Tx=!0,hp="[A-Za-z0-9\\-\\.\\_\\~"+(Tx?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",wr="[0-9A-Fa-f]",Ix=r(r("%[EFef]"+wr+"%"+wr+wr+"%"+wr+wr)+"|"+r("%[89A-Fa-f]"+wr+"%"+wr+wr)+"|"+r("%"+wr+wr)),Dx="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",Bx="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",Rx=e(Bx,'[\\"\\\\]'),Ox="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",kx=new RegExp(hp,"g"),zi=new RegExp(Ix,"g"),Cx=new RegExp(e("[^]",Dx,"[\\.]",'[\\"]',Rx),"g"),pp=new RegExp(e("[^]",hp,Ox),"g"),Ux=pp;function sd(b){var p=ie(b);return p.match(kx)?p:b}var yp={scheme:"mailto",parse:function(p,x){var _=p,A=_.to=_.path?_.path.split(","):[];if(_.path=void 0,_.query){for(var L=!1,se={},ye=_.query.split("&"),be=0,He=ye.length;be<He;++be){var pe=ye[be].split("=");switch(pe[0]){case"to":for(var Pe=pe[1].split(","),je=0,Oe=Pe.length;je<Oe;++je)A.push(Pe[je]);break;case"subject":_.subject=Ht(pe[1],x);break;case"body":_.body=Ht(pe[1],x);break;default:L=!0,se[Ht(pe[0],x)]=Ht(pe[1],x);break}}L&&(_.headers=se)}_.query=void 0;for(var me=0,Ke=A.length;me<Ke;++me){var xe=A[me].split("@");if(xe[0]=Ht(xe[0]),x.unicodeSupport)xe[1]=Ht(xe[1],x).toLowerCase();else try{xe[1]=ee.toASCII(Ht(xe[1],x).toLowerCase())}catch(ei){_.error=_.error||"Email address's domain name can not be converted to ASCII via punycode: "+ei}A[me]=xe.join("@")}return _},serialize:function(p,x){var _=p,A=o(p.to);if(A){for(var L=0,se=A.length;L<se;++L){var ye=String(A[L]),be=ye.lastIndexOf("@"),He=ye.slice(0,be).replace(zi,sd).replace(zi,i).replace(Cx,Z),pe=ye.slice(be+1);try{pe=x.iri?ee.toUnicode(pe):ee.toASCII(Ht(pe,x).toLowerCase())}catch(me){_.error=_.error||"Email address's domain name can not be converted to "+(x.iri?"Unicode":"ASCII")+" via punycode: "+me}A[L]=He+"@"+pe}_.path=A.join(",")}var Pe=p.headers=p.headers||{};p.subject&&(Pe.subject=p.subject),p.body&&(Pe.body=p.body);var je=[];for(var Oe in Pe)Pe[Oe]!==od[Oe]&&je.push(Oe.replace(zi,sd).replace(zi,i).replace(pp,Z)+"="+Pe[Oe].replace(zi,sd).replace(zi,i).replace(Ux,Z));return je.length&&(_.query=je.join("&")),_}},Px=/^([^\:]+)\:(.*)/,mp={scheme:"urn",parse:function(p,x){var _=p.path&&p.path.match(Px),A=p;if(_){var L=x.scheme||A.scheme||"urn",se=_[1].toLowerCase(),ye=_[2],be=L+":"+(x.nid||se),He=te[be];A.nid=se,A.nss=ye,A.path=void 0,He&&(A=He.parse(A,x))}else A.error=A.error||"URN can not be parsed.";return A},serialize:function(p,x){var _=x.scheme||p.scheme||"urn",A=p.nid,L=_+":"+(x.nid||A),se=te[L];se&&(p=se.serialize(p,x));var ye=p,be=p.nss;return ye.path=(A||x.nid)+":"+be,ye}},Kx=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,gp={scheme:"urn:uuid",parse:function(p,x){var _=p;return _.uuid=_.nss,_.nss=void 0,!x.tolerant&&(!_.uuid||!_.uuid.match(Kx))&&(_.error=_.error||"UUID is not valid."),_},serialize:function(p,x){var _=p;return _.nss=(p.uuid||"").toLowerCase(),_}};te[vn.scheme]=vn,te[cs.scheme]=cs,te[Qn.scheme]=Qn,te[Pa.scheme]=Pa,te[yp.scheme]=yp,te[mp.scheme]=mp,te[gp.scheme]=gp,t.SCHEMES=te,t.pctEncChar=Z,t.pctDecChars=ie,t.parse=We,t.removeDotSegments=En,t.serialize=Vt,t.resolveComponents=ss,t.resolve=Oa,t.normalize=as,t.equal=ka,t.escapeComponent=Ca,t.unescapeComponent=Ht,Object.defineProperty(t,"__esModule",{value:!0})})});var Kb=$((hK,Pb)=>{"use strict";var pK=f(h());Pb.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 Sx=$((S4,vx)=>{var _4=f(h()),rs=1e3,ns=rs*60,is=ns*60,Wi=is*24,IB=Wi*7,DB=Wi*365.25;vx.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return BB(t);if(r==="number"&&isFinite(t))return e.long?OB(t):RB(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function BB(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*DB;case"weeks":case"week":case"w":return r*IB;case"days":case"day":case"d":return r*Wi;case"hours":case"hour":case"hrs":case"hr":case"h":return r*is;case"minutes":case"minute":case"mins":case"min":case"m":return r*ns;case"seconds":case"second":case"secs":case"sec":case"s":return r*rs;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function RB(t){var e=Math.abs(t);return e>=Wi?Math.round(t/Wi)+"d":e>=is?Math.round(t/is)+"h":e>=ns?Math.round(t/ns)+"m":e>=rs?Math.round(t/rs)+"s":t+"ms"}function OB(t){var e=Math.abs(t);return e>=Wi?nd(t,e,Wi,"day"):e>=is?nd(t,e,is,"hour"):e>=ns?nd(t,e,ns,"minute"):e>=rs?nd(t,e,rs,"second"):t+" ms"}function nd(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});var kB={};$a(kB,{BearerDid:()=>xt,Did:()=>Ce,DidDht:()=>xa,DidDhtDocument:()=>Ea,DidDhtRegisteredDidType:()=>Oh,DidDhtRegisteredKeyType:()=>qu,DidDhtUtils:()=>Qe,DidDhtVerificationRelationship:()=>kh,DidError:()=>q,DidErrorCode:()=>zr,DidIon:()=>sp,DidIonRegisteredKeyType:()=>xx,DidIonUtils:()=>Zn,DidJwk:()=>ap,DidKey:()=>cp,DidKeyRegisteredKeyType:()=>Ex,DidKeyUtils:()=>ir,DidKeyVerificationMethodType:()=>td,DidMethod:()=>qt,DidResolverCacheLevel:()=>dp,DidResolverCacheNoop:()=>lp,DidVerificationRelationship:()=>oi,DidWeb:()=>up,EMPTY_DID_RESOLUTION_RESULT:()=>ke,UniversalResolver:()=>fp,utils:()=>mh});var P4=f(h(),1);var ZB=f(h(),1),oi=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(oi||{});var e6=f(h(),1),ke={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};var r6=f(h(),1),ze=class ze{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=ze.DID_URI_PATTERN.exec(e);if(!r||!r.groups)return null;let{method:n,id:i,path:o,query:s,fragment:a}=r.groups,u={uri:`did:${n}:${i}`,method:n,id:i};if(o&&(u.path=o),s&&(u.query=s.slice(1)),a&&(u.fragment=a.slice(1)),s){let d={},c=s.slice(1).split("&");for(let l of c){let[g,w]=l.split("=");d[g]=w}u.params=d}return u}};ze.METHOD_PATTERN="([a-z0-9]+)",ze.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})",ze.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${ze.PCT_ENCODED_PATTERN})`,ze.METHOD_ID_PATTERN=`((?:${ze.ID_CHAR_PATTERN}*:)*(${ze.ID_CHAR_PATTERN}+))`,ze.PATH_PATTERN="(/[^#?]*)?",ze.QUERY_PATTERN="([?][^#]*)?",ze.FRAGMENT_PATTERN="(#.*)?",ze.DID_URI_PATTERN=new RegExp(`^did:(?<method>${ze.METHOD_PATTERN}):(?<id>${ze.METHOD_ID_PATTERN})(?<path>${ze.PATH_PATTERN})(?<query>${ze.QUERY_PATTERN})(?<fragment>${ze.FRAGMENT_PATTERN})$`);var Ce=ze;var i6=f(h(),1),q=class t extends Error{constructor(r,n){super(`${r}: ${n}`);this.code=r;this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,t)}},zr=(m=>(m.InvalidDid="invalidDid",m.MethodNotSupported="methodNotSupported",m.InternalError="internalError",m.InvalidDidDocument="invalidDidDocument",m.InvalidDidDocumentLength="invalidDidDocumentLength",m.InvalidDidUrl="invalidDidUrl",m.InvalidPreviousDidProof="invalidPreviousDidProof",m.InvalidPublicKey="invalidPublicKey",m.InvalidPublicKeyLength="invalidPublicKeyLength",m.InvalidPublicKeyType="invalidPublicKeyType",m.InvalidSignature="invalidSignature",m.NotFound="notFound",m.RepresentationNotSupported="representationNotSupported",m.UnsupportedPublicKeyType="unsupportedPublicKeyType",m))(zr||{});var AP=f(h(),1);var FU=f(h(),1);var XC=f(h(),1);var W5=f(h(),1);var c6=f(h(),1),OE=f(jp(),1);var H6=f(h(),1);var T6=f(h(),1);var m6=f(h(),1);var d6=f(h(),1),u6=new Uint8Array(0);function Wp(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 io(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")}var f6=f(h(),1);function CE(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 a=t.length,u=t.charAt(0),d=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,E=0,v=0,D=m.length;v!==D&&m[v]===0;)v++,y++;for(var S=(D-v)*c+1>>>0,B=new Uint8Array(S);v!==D;){for(var I=m[v],O=0,C=S-1;(I!==0||O<E)&&C!==-1;C--,O++)I+=256*B[C]>>>0,B[C]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");E=O,v++}for(var P=S-E;P!==S&&B[P]===0;)P++;for(var j=u.repeat(y);P<S;++P)j+=t.charAt(B[P]);return j}function g(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var E=0,v=0;m[y]===u;)E++,y++;for(var D=(m.length-y)*d+1>>>0,S=new Uint8Array(D);m[y];){var B=r[m.charCodeAt(y)];if(B===255)return;for(var I=0,O=D-1;(B!==0||I<v)&&O!==-1;O--,I++)B+=a*S[O]>>>0,S[O]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");v=I,y++}if(m[y]!==" "){for(var C=D-v;C!==D&&S[C]===0;)C++;for(var P=new Uint8Array(E+(D-C)),j=E;C!==D;)P[j++]=S[C++];return P}}}function w(m){var y=g(m);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:g,decode:w}}var UE=CE,PE=UE,zp=PE;var Ed=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")}},vd=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 Gp(this,e)}},Sd=class{decoders;constructor(e){this.decoders=e}or(e){return Gp(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 Gp(t,e){return new Sd({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var _d=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 Ed(e,r,n),this.decoder=new vd(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Jp({name:t,prefix:e,encode:r,decode:n}){return new _d(t,e,r,n)}function Ad({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=zp(r,t);return Jp({prefix:e,name:t,encode:n,decode:o=>io(i(o))})}function KE(t,e,r,n){let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,u=0,d=0;for(let c=0;c<o;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<r|l,a+=r,a>=8&&(a-=8,s[d++]=255&u>>a)}if(a>=r||255&u<<8-a)throw new SyntaxError("Unexpected end of data");return s}function LE(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o}function wt({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return Jp({prefix:e,name:t,encode(i){return LE(i,n,r)},decode(i){return KE(i,n,r,t)}})}var ys=wt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),w6=wt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),b6=wt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),x6=wt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),E6=wt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),v6=wt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),S6=wt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_6=wt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Td=wt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var R6=f(h(),1);var At=Ad({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),D6=Ad({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var K6=f(h(),1);var k6=wt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),C6=wt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vr=wt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),U6=wt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var M6=f(h(),1);function Yp(t){return t.byteOffset!==0||t.byteLength!==t.buffer.byteLength}function Xp(t){return typeof t!="object"||t===null?!1:typeof t[Symbol.asyncIterator]=="function"}function oo(t){let r=Object.prototype.toString.call(t).match(/\s([a-zA-Z0-9]+)/),[n,i]=r;return i}var ms=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},Zp=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(a,u){s=t[o](s),i(a,u,s.done,s.value)})}}function i(o,s,a,u){Promise.resolve(u).then(function(d){o({value:d,done:a})},s)}},ja=new TextEncoder,si=new TextDecoder,M=class t{constructor(e,r){this.data=e,this.format=r}static arrayBuffer(e){return new t(e,"ArrayBuffer")}static asyncIterable(e){if(!Xp(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 At.baseDecode(this.data).buffer;case"Base64Url":return vr.baseDecode(this.data).buffer;case"BufferSource":{if(oo(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Yp(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 ms(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 Td.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 At.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return At.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 vr.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return vr.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),r=ja.encode(e);return vr.baseEncode(r)}case"String":{let e=ja.encode(this.data);return vr.baseEncode(e)}case"Uint8Array":return vr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return ms(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let u=[];try{for(var o=!0,s=Zp(this.data),a;a=yield s.next(),e=a.done,!e;o=!0){i=a.value,o=!1;let c=i;u.push(c)}}catch(c){r={error:c}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return new Blob(u)}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=vr.baseDecode(this.data),r=si.decode(e);return JSON.parse(r)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=si.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return ms(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 si.decode(this.data);case"Base64Url":{let e=vr.baseDecode(this.data);return si.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return si.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return ms(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let u="";try{for(var o=!0,s=Zp(this.data),a;a=yield s.next(),e=a.done,!e;o=!0){i=a.value,o=!1;let d=i;typeof d=="string"?u+=d:u+=si.decode(d,{stream:!0})}}catch(d){r={error:d}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return u+=si.decode(void 0,{stream:!1}),u}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 Td.baseDecode(this.data);case"Base58Btc":return At.baseDecode(this.data);case"Base64Url":return vr.baseDecode(this.data);case"BufferSource":{let e=oo(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 ja.encode(e)}case"String":return ja.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return ms(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.`)}})}};var W6=f(h(),1),gs;(function(t){t.Debug="debug",t.Silent="silent"})(gs||(gs={}));var Id=class{constructor(){this.logLevel=gs.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==gs.Silent&&console.info(e)}error(e){this.logLevel!==gs.Silent&&console.error(e)}},ME=new Id;typeof window<"u"&&(window.web5logger=ME);var SR=f(h(),1);var bR=f(h(),1);var iR=f(h(),1);var Z6=f(h(),1);var Gr={};$a(Gr,{decode:()=>so,encodeTo:()=>ai,encodingLength:()=>ci});var Y6=f(h(),1);var G6=f(h(),1),NE=ty,Qp=128,$E=127,qE=~$E,FE=Math.pow(2,31);function ty(t,e,r){e=e||[],r=r||0;for(var n=r;t>=FE;)e[r++]=t&255|Qp,t/=128;for(;t&qE;)e[r++]=t&255|Qp,t>>>=7;return e[r]=t|0,ty.bytes=r-n+1,e}var VE=Dd,HE=128,ey=127;function Dd(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Dd.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&ey)<<i:(s&ey)*Math.pow(2,i),i+=7}while(s>=HE);return Dd.bytes=o-n,r}var jE=Math.pow(2,7),WE=Math.pow(2,14),zE=Math.pow(2,21),GE=Math.pow(2,28),JE=Math.pow(2,35),YE=Math.pow(2,42),XE=Math.pow(2,49),ZE=Math.pow(2,56),QE=Math.pow(2,63),e1=function(t){return t<jE?1:t<WE?2:t<zE?3:t<GE?4:t<JE?5:t<YE?6:t<XE?7:t<ZE?8:t<QE?9:10},t1={encode:NE,decode:VE,encodingLength:e1},r1=t1,ws=r1;function so(t,e=0){return[ws.decode(t,e),ws.decode.bytes]}function ai(t,e,r=0){return ws.encode(t,e,r),e}function ci(t){return ws.encodingLength(t)}function Bd(t,e){let r=e.byteLength,n=ci(t),i=n+ci(r),o=new Uint8Array(i+r);return ai(t,o,0),ai(r,o,n),o.set(e,i),new ao(t,r,e,o)}function ry(t){let e=io(t),[r,n]=so(e),[i,o]=so(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new ao(r,i,s,e)}function ny(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Wp(t.bytes,r.bytes)}}var ao=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var Q6=f(h(),1);function iy(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return i1(r,Od(t),e??At.encoder);default:return o1(r,Od(t),e??ys.encoder)}}var oy=new WeakMap;function Od(t){let e=oy.get(t);if(e==null){let r=new Map;return oy.set(t,r),r}return e}var kd=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!==bs)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==s1)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=Bd(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&&ny(e.multihash,n.multihash)}toString(e){return iy(this,e)}toJSON(){return{"/":iy(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??sy(n,i,o.bytes))}else if(r[a1]===!0){let{version:n,multihash:i,code:o}=r,s=ry(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!==bs)throw new Error(`Version 0 CID must use dag-pb (code: ${bs}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=sy(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,bs,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=io(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 ao(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[l,g]=so(e.subarray(r));return r+=g,l},i=n(),o=bs;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),u=n(),d=r+u,c=d-s;return{version:i,codec:o,multihashCode:a,digestSize:u,multihashSize:c,size:d}}static parse(e,r){let[n,i]=n1(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 Od(o).set(n,e),o}};function n1(t,e){switch(t[0]){case"Q":{let r=e??At;return[At.prefix,r.decode(`${At.prefix}${t}`)]}case At.prefix:{let r=e??At;return[At.prefix,r.decode(t)]}case ys.prefix:{let r=e??ys;return[ys.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 i1(t,e,r){let{prefix:n}=r;if(n!==At.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 o1(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 bs=112,s1=18;function sy(t,e,r){let n=ci(t),i=n+ci(e),o=new Uint8Array(i+r.byteLength);return ai(t,o,0),ai(e,o,n),o.set(r,i),o}var a1=Symbol.for("@ipld/js-cid/CID");var sR=f(h(),1);var lR=f(h(),1);var aR=f(h(),1);var cR=f(h(),1);var uR=f(h(),1);var dR=f(h(),1);var ht=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=Gr.encodingLength(n),a=new Uint8Array(s+i.byteLength);return a.set(i,s),Gr.encodeTo(n,a),a}static getCodeFromData(e){let{prefixedData:r}=e,[n,i]=Gr.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]=Gr.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}}};ht.codeToName=new Map;ht.nameToCode=new Map;ht.registerCodec({code:237,name:"ed25519-pub"});ht.registerCodec({code:4864,name:"ed25519-priv"});ht.registerCodec({code:236,name:"x25519-pub"});ht.registerCodec({code:4866,name:"x25519-priv"});ht.registerCodec({code:231,name:"secp256k1-pub"});ht.registerCodec({code:4865,name:"secp256k1-priv"});var AR=f(h(),1);function Cd(t){Object.keys(t).forEach(e=>{t[e]===void 0?delete t[e]:typeof t[e]=="object"&&Cd(t[e])})}var U8=f(h(),1),pv=f(Al(),1),Si=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})};var bc=class{constructor(){this.store=new Map}clear(){return Si(this,void 0,void 0,function*(){this.store.clear()})}close(){return Si(this,void 0,void 0,function*(){})}delete(e){return Si(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return Si(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return Si(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return Si(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,r){return Si(this,void 0,void 0,function*(){this.store.set(e,r)})}};var L8=f(h(),1);var H5=f(h(),1),CT=f($f(),1);var UT=f($f(),1);var DO=f(h(),1);var vO=f(h(),1);var bO=f(h(),1);var yO=f(h(),1);var nO=f(h(),1);function PT(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function qf(t,...e){if(!PT(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 Ff(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 gw(t,e){qf(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var lO=f(h(),1);var oO=f(h(),1),Po=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Qc=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),dr=(t,e)=>t<<32-e|t>>>e;var cO=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function KT(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Vf(t){return typeof t=="string"&&(t=KT(t)),qf(t),t}var Zc=class{clone(){return this._cloneInto()}},uO={}.toString;function ww(t){let e=n=>t().update(Vf(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function bw(t=32){if(Po&&typeof Po.getRandomValues=="function")return Po.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function LT(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),a=Number(r&o),u=n?4:0,d=n?0:4;t.setUint32(e+u,s,n),t.setUint32(e+d,a,n)}var xw=(t,e,r)=>t&e^~t&r,Ew=(t,e,r)=>t&e^t&r^e&r,eu=class extends Zc{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=Qc(this.buffer)}update(e){Ff(this);let{view:r,buffer:n,blockLen:i}=this;e=Vf(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let u=Qc(e);for(;i<=o-s;s+=i)this.process(u,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ff(this),gw(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 l=s;l<i;l++)r[l]=0;LT(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=Qc(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,c=this.get();if(d>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,c[l],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:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var MT=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]),Ln=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Mn=new Uint32Array(64),Hf=class extends eu{constructor(){super(64,32,8,!1),this.A=Ln[0]|0,this.B=Ln[1]|0,this.C=Ln[2]|0,this.D=Ln[3]|0,this.E=Ln[4]|0,this.F=Ln[5]|0,this.G=Ln[6]|0,this.H=Ln[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:a,H:u}=this;return[e,r,n,i,o,s,a,u]}set(e,r,n,i,o,s,a,u){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=a|0,this.H=u|0}process(e,r){for(let l=0;l<16;l++,r+=4)Mn[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let g=Mn[l-15],w=Mn[l-2],m=dr(g,7)^dr(g,18)^g>>>3,y=dr(w,17)^dr(w,19)^w>>>10;Mn[l]=y+Mn[l-7]+m+Mn[l-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:u,G:d,H:c}=this;for(let l=0;l<64;l++){let g=dr(a,6)^dr(a,11)^dr(a,25),w=c+g+xw(a,u,d)+MT[l]+Mn[l]|0,y=(dr(n,2)^dr(n,13)^dr(n,22))+Ew(n,i,o)|0;c=d,d=u,u=a,a=s+w|0,s=o,o=i,i=n,n=w+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,d=d+this.G|0,c=c+this.H|0,this.set(n,i,o,s,a,u,d,c)}roundClean(){Mn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Nn=ww(()=>new Hf);var NT=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},Ko=class{static digest(e){return NT(this,arguments,void 0,function*({data:r}){return Nn(r)})}};var _O=f(h(),1),Ur=class{};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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},tu=class extends Ur{digest(e){return $T(this,arguments,void 0,function*({algorithm:r,data:n}){switch(r){case"SHA-256":return yield Ko.digest({data:n})}})}};var Zk=f(h(),1);var Uk=f(h(),1);var xk=f(h(),1);var HO=f(h(),1);var $O=f(h(),1);var RO=f(h(),1);function vw(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function qT(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function jf(t,...e){if(!qT(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 Sw(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vw(t.outputLen),vw(t.blockLen)}function Lo(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 _w(t,e){jf(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var KO=f(h(),1);var kO=f(h(),1),ru=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Aw(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var nu=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),lr=(t,e)=>t<<32-e|t>>>e,FT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!FT)throw new Error("Non little-endian hardware is not supported");function Wf(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Zs(t){if(typeof t=="string"&&(t=Wf(t)),!Aw(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function iu(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!Aw(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 Mo=class{clone(){return this._cloneInto()}},UO={}.toString;function ou(t){let e=n=>t().update(Zs(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Qs(t=32){if(ru&&typeof ru.getRandomValues=="function")return ru.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function VT(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),a=Number(r&o),u=n?4:0,d=n?0:4;t.setUint32(e+u,s,n),t.setUint32(e+d,a,n)}var No=class extends Mo{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=nu(this.buffer)}update(e){Lo(this);let{view:r,buffer:n,blockLen:i}=this;e=Zs(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let u=nu(e);for(;i<=o-s;s+=i)this.process(u,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Lo(this),_w(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 l=s;l<i;l++)r[l]=0;VT(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=nu(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,c=this.get();if(d>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,c[l],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:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var HT=(t,e,r)=>t&e^~t&r,jT=(t,e,r)=>t&e^t&r^e&r,WT=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]),$n=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),qn=new Uint32Array(64),zf=class extends No{constructor(){super(64,32,8,!1),this.A=$n[0]|0,this.B=$n[1]|0,this.C=$n[2]|0,this.D=$n[3]|0,this.E=$n[4]|0,this.F=$n[5]|0,this.G=$n[6]|0,this.H=$n[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:a,H:u}=this;return[e,r,n,i,o,s,a,u]}set(e,r,n,i,o,s,a,u){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=a|0,this.H=u|0}process(e,r){for(let l=0;l<16;l++,r+=4)qn[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let g=qn[l-15],w=qn[l-2],m=lr(g,7)^lr(g,18)^g>>>3,y=lr(w,17)^lr(w,19)^w>>>10;qn[l]=y+qn[l-7]+m+qn[l-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:u,G:d,H:c}=this;for(let l=0;l<64;l++){let g=lr(a,6)^lr(a,11)^lr(a,25),w=c+g+HT(a,u,d)+WT[l]+qn[l]|0,y=(lr(n,2)^lr(n,13)^lr(n,22))+jT(n,i,o)|0;c=d,d=u,u=a,a=s+w|0,s=o,o=i,i=n,n=w+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,d=d+this.G|0,c=c+this.H|0,this.set(n,i,o,s,a,u,d,c)}roundClean(){qn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var su=ou(()=>new zf);var zO=f(h(),1);var cu={};$a(cu,{bitGet:()=>QT,bitLen:()=>ZT,bitMask:()=>ea,bitSet:()=>eI,bytesToHex:()=>dn,bytesToNumberBE:()=>ln,bytesToNumberLE:()=>hr,concatBytes:()=>hn,createHmacDrbg:()=>Yf,ensureBytes:()=>Ie,equalBytes:()=>YT,hexToBytes:()=>Ki,hexToNumber:()=>Jf,isBytes:()=>fr,numberToBytesBE:()=>It,numberToBytesLE:()=>fn,numberToHexUnpadded:()=>Bw,numberToVarBytesBE:()=>JT,utf8ToBytes:()=>XT,validateObject:()=>Zt});var jO=f(h(),1);var Dw=BigInt(0),au=BigInt(1),zT=BigInt(2);function fr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var GT=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function dn(t){if(!fr(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=GT[t[r]];return e}function Bw(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function Jf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var un={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Tw(t){if(t>=un._0&&t<=un._9)return t-un._0;if(t>=un._A&&t<=un._F)return t-(un._A-10);if(t>=un._a&&t<=un._f)return t-(un._a-10)}function Ki(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=Tw(t.charCodeAt(o)),a=Tw(t.charCodeAt(o+1));if(s===void 0||a===void 0){let u=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+o)}n[i]=s*16+a}return n}function ln(t){return Jf(dn(t))}function hr(t){if(!fr(t))throw new Error("Uint8Array expected");return Jf(dn(Uint8Array.from(t).reverse()))}function It(t,e){return Ki(t.toString(16).padStart(e*2,"0"))}function fn(t,e){return It(t,e).reverse()}function JT(t){return Ki(Bw(t))}function Ie(t,e,r){let n;if(typeof e=="string")try{n=Ki(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(fr(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 hn(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!fr(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 YT(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 XT(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function ZT(t){let e;for(e=0;t>Dw;t>>=au,e+=1);return e}function QT(t,e){return t>>BigInt(e)&au}var eI=(t,e,r)=>t|(r?au:Dw)<<BigInt(e),ea=t=>(zT<<BigInt(t-1))-au,Gf=t=>new Uint8Array(t),Iw=t=>Uint8Array.from(t);function Yf(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=Gf(t),i=Gf(t),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...l)=>r(i,n,...l),u=(l=Gf())=>{i=a(Iw([0]),l),n=a(),l.length!==0&&(i=a(Iw([1]),l),n=a())},d=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,g=[];for(;l<e;){n=a();let w=n.slice();g.push(w),l+=n.length}return hn(...g)};return(l,g)=>{s(),u(l);let w;for(;!(w=g(d()));)u();return s(),w}}var tI={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"||fr(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 Zt(t,e,r={}){let n=(i,o,s)=>{let a=tI[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let u=t[i];if(!(s&&u===void 0)&&!a(u,t))throw new Error(`Invalid param ${String(i)}=${u} (${typeof u}), 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 Ye=BigInt(0),Ue=BigInt(1),Li=BigInt(2),rI=BigInt(3),Xf=BigInt(4),Rw=BigInt(5),Ow=BigInt(8),nI=BigInt(9),iI=BigInt(16);function ge(t,e){let r=t%e;return r>=Ye?r:e+r}function Zf(t,e,r){if(r<=Ye||e<Ye)throw new Error("Expected power/modulo > 0");if(r===Ue)return Ye;let n=Ue;for(;e>Ye;)e&Ue&&(n=n*t%r),t=t*t%r,e>>=Ue;return n}function De(t,e,r){let n=t;for(;e-- >Ye;)n*=n,n%=r;return n}function uu(t,e){if(t===Ye||e<=Ye)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=ge(t,e),n=e,i=Ye,o=Ue,s=Ue,a=Ye;for(;r!==Ye;){let d=n/r,c=n%r,l=i-s*d,g=o-a*d;n=r,r=c,i=s,o=a,s=l,a=g}if(n!==Ue)throw new Error("invert: does not exist");return ge(i,e)}function oI(t){let e=(t-Ue)/Li,r,n,i;for(r=t-Ue,n=0;r%Li===Ye;r/=Li,n++);for(i=Li;i<t&&Zf(i,e,t)!==t-Ue;i++);if(n===1){let s=(t+Ue)/Xf;return function(u,d){let c=u.pow(d,s);if(!u.eql(u.sqr(c),d))throw new Error("Cannot find square root");return c}}let o=(r+Ue)/Li;return function(a,u){if(a.pow(u,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let d=n,c=a.pow(a.mul(a.ONE,i),r),l=a.pow(u,o),g=a.pow(u,r);for(;!a.eql(g,a.ONE);){if(a.eql(g,a.ZERO))return a.ZERO;let w=1;for(let y=a.sqr(g);w<d&&!a.eql(y,a.ONE);w++)y=a.sqr(y);let m=a.pow(c,Ue<<BigInt(d-w-1));c=a.sqr(m),l=a.mul(l,m),g=a.mul(g,c),d=w}return l}}function sI(t){if(t%Xf===rI){let e=(t+Ue)/Xf;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%Ow===Rw){let e=(t-Rw)/Ow;return function(n,i){let o=n.mul(i,Li),s=n.pow(o,e),a=n.mul(i,s),u=n.mul(n.mul(a,Li),s),d=n.mul(a,n.sub(u,n.ONE));if(!n.eql(n.sqr(d),i))throw new Error("Cannot find square root");return d}}return t%iI,oI(t)}var kw=(t,e)=>(ge(t,e)&Ue)===Ue,aI=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Qf(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=aI.reduce((n,i)=>(n[i]="function",n),e);return Zt(t,r)}function cI(t,e,r){if(r<Ye)throw new Error("Expected power > 0");if(r===Ye)return t.ONE;if(r===Ue)return e;let n=t.ONE,i=e;for(;r>Ye;)r&Ue&&(n=t.mul(n,i)),i=t.sqr(i),r>>=Ue;return n}function uI(t,e){let r=new Array(e.length),n=e.reduce((o,s,a)=>t.is0(s)?o:(r[a]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,a)=>t.is0(s)?o:(r[a]=t.mul(o,r[a]),t.mul(o,s)),i),r}function eh(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function $o(t,e,r=!1,n={}){if(t<=Ye)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=eh(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=sI(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:ea(i),ZERO:Ye,ONE:Ue,create:u=>ge(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof u}`);return Ye<=u&&u<t},is0:u=>u===Ye,isOdd:u=>(u&Ue)===Ue,neg:u=>ge(-u,t),eql:(u,d)=>u===d,sqr:u=>ge(u*u,t),add:(u,d)=>ge(u+d,t),sub:(u,d)=>ge(u-d,t),mul:(u,d)=>ge(u*d,t),pow:(u,d)=>cI(a,u,d),div:(u,d)=>ge(u*uu(d,t),t),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>uu(u,t),sqrt:n.sqrt||(u=>s(a,u)),invertBatch:u=>uI(a,u),cmov:(u,d,c)=>c?d:u,toBytes:u=>r?fn(u,o):It(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return r?hr(u):ln(u)}});return Object.freeze(a)}function Cw(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 Uw(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 th(t){let e=Uw(t);return e+Math.ceil(e/2)}function Pw(t,e,r=!1){let n=t.length,i=Uw(e),o=th(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=r?ln(t):hr(t),a=ge(s,e-Ue)+Ue;return r?fn(a,i):It(a,i)}var ik=f(h(),1);var XO=f(h(),1);var lI=BigInt(0),rh=BigInt(1);function du(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,a=i;for(;o>lI;)o&rh&&(s=s.add(a)),a=a.double(),o>>=rh;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),u=[],d=i,c=d;for(let l=0;l<s;l++){c=d,u.push(c);for(let g=1;g<a;g++)c=c.add(d),u.push(c);d=c.double()}return u},wNAF(i,o,s){let{windows:a,windowSize:u}=n(i),d=t.ZERO,c=t.BASE,l=BigInt(2**i-1),g=2**i,w=BigInt(i);for(let m=0;m<a;m++){let y=m*u,E=Number(s&l);s>>=w,E>u&&(E-=g,s+=rh);let v=y,D=y+Math.abs(E)-1,S=m%2!==0,B=E<0;E===0?c=c.add(r(S,o[v])):d=d.add(r(B,o[D]))}return{p:d,f:c}},wNAFCached(i,o,s,a){let u=i._WINDOW_SIZE||1,d=o.get(i);return d||(d=this.precomputeWindow(i,u),u!==1&&o.set(i,a(d))),this.wNAF(u,d,s)}}}function ta(t){return Qf(t.Fp),Zt(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...eh(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function fI(t){let e=ta(t);Zt(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:hI,hexToBytes:pI}=cu,Mi={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){let{Err:e}=Mi;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:hI(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=Mi,r=typeof t=="string"?pI(t):t;if(!fr(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}=Mi._parseInt(r.subarray(2)),{d:s,l:a}=Mi._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=d=>Number.parseInt(d[0],16)&8?"00"+d:d,r=d=>{let c=d.toString(16);return c.length&1?`0${c}`:c},n=e(r(t.s)),i=e(r(t.r)),o=n.length/2,s=i.length/2,a=r(o),u=r(s);return`30${r(s+o+4)}02${u}${i}02${a}${n}`}},pn=BigInt(0),Qt=BigInt(1),tk=BigInt(2),Kw=BigInt(3),rk=BigInt(4);function yI(t){let e=fI(t),{Fp:r}=e,n=e.toBytes||((m,y,E)=>{let v=y.toAffine();return hn(Uint8Array.from([4]),r.toBytes(v.x),r.toBytes(v.y))}),i=e.fromBytes||(m=>{let y=m.subarray(1),E=r.fromBytes(y.subarray(0,r.BYTES)),v=r.fromBytes(y.subarray(r.BYTES,2*r.BYTES));return{x:E,y:v}});function o(m){let{a:y,b:E}=e,v=r.sqr(m),D=r.mul(v,m);return r.add(r.add(D,r.mul(m,y)),E)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(m){return typeof m=="bigint"&&pn<m&&m<e.n}function a(m){if(!s(m))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function u(m){let{allowedPrivateKeyLengths:y,nByteLength:E,wrapPrivateKey:v,n:D}=e;if(y&&typeof m!="bigint"){if(fr(m)&&(m=dn(m)),typeof m!="string"||!y.includes(m.length))throw new Error("Invalid key");m=m.padStart(E*2,"0")}let S;try{S=typeof m=="bigint"?m:ln(Ie("private key",m,E))}catch{throw new Error(`private key must be ${E} bytes, hex or bigint, not ${typeof m}`)}return v&&(S=ge(S,D)),a(S),S}let d=new Map;function c(m){if(!(m instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(y,E,v){if(this.px=y,this.py=E,this.pz=v,y==null||!r.isValid(y))throw new Error("x required");if(E==null||!r.isValid(E))throw new Error("y required");if(v==null||!r.isValid(v))throw new Error("z required")}static fromAffine(y){let{x:E,y:v}=y||{};if(!y||!r.isValid(E)||!r.isValid(v))throw new Error("invalid affine point");if(y instanceof l)throw new Error("projective point not allowed");let D=S=>r.eql(S,r.ZERO);return D(E)&&D(v)?l.ZERO:new l(E,v,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){let E=r.invertBatch(y.map(v=>v.pz));return y.map((v,D)=>v.toAffine(E[D])).map(l.fromAffine)}static fromHex(y){let E=l.fromAffine(i(Ie("pointHex",y)));return E.assertValidity(),E}static fromPrivateKey(y){return l.BASE.multiply(u(y))}_setWindowSize(y){this._WINDOW_SIZE=y,d.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:y,y:E}=this.toAffine();if(!r.isValid(y)||!r.isValid(E))throw new Error("bad point: x or y not FE");let v=r.sqr(E),D=o(y);if(!r.eql(v,D))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){c(y);let{px:E,py:v,pz:D}=this,{px:S,py:B,pz:I}=y,O=r.eql(r.mul(E,I),r.mul(S,D)),C=r.eql(r.mul(v,I),r.mul(B,D));return O&&C}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:y,b:E}=e,v=r.mul(E,Kw),{px:D,py:S,pz:B}=this,I=r.ZERO,O=r.ZERO,C=r.ZERO,P=r.mul(D,D),j=r.mul(S,S),V=r.mul(B,B),z=r.mul(D,S);return z=r.add(z,z),C=r.mul(D,B),C=r.add(C,C),I=r.mul(y,C),O=r.mul(v,V),O=r.add(I,O),I=r.sub(j,O),O=r.add(j,O),O=r.mul(I,O),I=r.mul(z,I),C=r.mul(v,C),V=r.mul(y,V),z=r.sub(P,V),z=r.mul(y,z),z=r.add(z,C),C=r.add(P,P),P=r.add(C,P),P=r.add(P,V),P=r.mul(P,z),O=r.add(O,P),V=r.mul(S,B),V=r.add(V,V),P=r.mul(V,z),I=r.sub(I,P),C=r.mul(V,j),C=r.add(C,C),C=r.add(C,C),new l(I,O,C)}add(y){c(y);let{px:E,py:v,pz:D}=this,{px:S,py:B,pz:I}=y,O=r.ZERO,C=r.ZERO,P=r.ZERO,j=e.a,V=r.mul(e.b,Kw),z=r.mul(E,S),le=r.mul(v,B),Q=r.mul(D,I),st=r.add(E,v),k=r.add(S,B);st=r.mul(st,k),k=r.add(z,le),st=r.sub(st,k),k=r.add(E,D);let N=r.add(S,I);return k=r.mul(k,N),N=r.add(z,Q),k=r.sub(k,N),N=r.add(v,D),O=r.add(B,I),N=r.mul(N,O),O=r.add(le,Q),N=r.sub(N,O),P=r.mul(j,k),O=r.mul(V,Q),P=r.add(O,P),O=r.sub(le,P),P=r.add(le,P),C=r.mul(O,P),le=r.add(z,z),le=r.add(le,z),Q=r.mul(j,Q),k=r.mul(V,k),le=r.add(le,Q),Q=r.sub(z,Q),Q=r.mul(j,Q),k=r.add(k,Q),z=r.mul(le,k),C=r.add(C,z),z=r.mul(N,k),O=r.mul(st,O),O=r.sub(O,z),z=r.mul(st,le),P=r.mul(N,P),P=r.add(P,z),new l(O,C,P)}subtract(y){return this.add(y.negate())}is0(){return this.equals(l.ZERO)}wNAF(y){return w.wNAFCached(this,d,y,E=>{let v=r.invertBatch(E.map(D=>D.pz));return E.map((D,S)=>D.toAffine(v[S])).map(l.fromAffine)})}multiplyUnsafe(y){let E=l.ZERO;if(y===pn)return E;if(a(y),y===Qt)return this;let{endo:v}=e;if(!v)return w.unsafeLadder(this,y);let{k1neg:D,k1:S,k2neg:B,k2:I}=v.splitScalar(y),O=E,C=E,P=this;for(;S>pn||I>pn;)S&Qt&&(O=O.add(P)),I&Qt&&(C=C.add(P)),P=P.double(),S>>=Qt,I>>=Qt;return D&&(O=O.negate()),B&&(C=C.negate()),C=new l(r.mul(C.px,v.beta),C.py,C.pz),O.add(C)}multiply(y){a(y);let E=y,v,D,{endo:S}=e;if(S){let{k1neg:B,k1:I,k2neg:O,k2:C}=S.splitScalar(E),{p:P,f:j}=this.wNAF(I),{p:V,f:z}=this.wNAF(C);P=w.constTimeNegate(B,P),V=w.constTimeNegate(O,V),V=new l(r.mul(V.px,S.beta),V.py,V.pz),v=P.add(V),D=j.add(z)}else{let{p:B,f:I}=this.wNAF(E);v=B,D=I}return l.normalizeZ([v,D])[0]}multiplyAndAddUnsafe(y,E,v){let D=l.BASE,S=(I,O)=>O===pn||O===Qt||!I.equals(D)?I.multiplyUnsafe(O):I.multiply(O),B=S(this,E).add(S(y,v));return B.is0()?void 0:B}toAffine(y){let{px:E,py:v,pz:D}=this,S=this.is0();y==null&&(y=S?r.ONE:r.inv(D));let B=r.mul(E,y),I=r.mul(v,y),O=r.mul(D,y);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(O,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}isTorsionFree(){let{h:y,isTorsionFree:E}=e;if(y===Qt)return!0;if(E)return E(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:y,clearCofactor:E}=e;return y===Qt?this:E?E(l,this):this.multiplyUnsafe(e.h)}toRawBytes(y=!0){return this.assertValidity(),n(l,this,y)}toHex(y=!0){return dn(this.toRawBytes(y))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let g=e.nBitLength,w=du(l,e.endo?Math.ceil(g/2):g);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:o,isWithinCurveOrder:s}}function mI(t){let e=ta(t);return Zt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Lw(t){let e=mI(t),{Fp:r,n}=e,i=r.BYTES+1,o=2*r.BYTES+1;function s(k){return pn<k&&k<r.ORDER}function a(k){return ge(k,n)}function u(k){return uu(k,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:l,isWithinCurveOrder:g}=yI({...e,toBytes(k,N,re){let U=N.toAffine(),R=r.toBytes(U.x),K=hn;return re?K(Uint8Array.from([N.hasEvenY()?2:3]),R):K(Uint8Array.from([4]),R,r.toBytes(U.y))},fromBytes(k){let N=k.length,re=k[0],U=k.subarray(1);if(N===i&&(re===2||re===3)){let R=ln(U);if(!s(R))throw new Error("Point is not on curve");let K=l(R),H=r.sqrt(K),X=(H&Qt)===Qt;return(re&1)===1!==X&&(H=r.neg(H)),{x:R,y:H}}else if(N===o&&re===4){let R=r.fromBytes(U.subarray(0,r.BYTES)),K=r.fromBytes(U.subarray(r.BYTES,2*r.BYTES));return{x:R,y:K}}else throw new Error(`Point of length ${N} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),w=k=>dn(It(k,e.nByteLength));function m(k){let N=n>>Qt;return k>N}function y(k){return m(k)?a(-k):k}let E=(k,N,re)=>ln(k.slice(N,re));class v{constructor(N,re,U){this.r=N,this.s=re,this.recovery=U,this.assertValidity()}static fromCompact(N){let re=e.nByteLength;return N=Ie("compactSignature",N,re*2),new v(E(N,0,re),E(N,re,2*re))}static fromDER(N){let{r:re,s:U}=Mi.toSig(Ie("DER",N));return new v(re,U)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(N){return new v(this.r,this.s,N)}recoverPublicKey(N){let{r:re,s:U,recovery:R}=this,K=C(Ie("msgHash",N));if(R==null||![0,1,2,3].includes(R))throw new Error("recovery id invalid");let H=R===2||R===3?re+e.n:re;if(H>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let X=R&1?"03":"02",ne=d.fromHex(X+w(H)),ee=u(H),te=a(-K*ee),Z=a(U*ee),ie=d.BASE.multiplyAndAddUnsafe(ne,te,Z);if(!ie)throw new Error("point at infinify");return ie.assertValidity(),ie}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new v(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ki(this.toDERHex())}toDERHex(){return Mi.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ki(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}let D={isValidPrivateKey(k){try{return c(k),!0}catch{return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{let k=th(e.n);return Pw(e.randomBytes(k),e.n)},precompute(k=8,N=d.BASE){return N._setWindowSize(k),N.multiply(BigInt(3)),N}};function S(k,N=!0){return d.fromPrivateKey(k).toRawBytes(N)}function B(k){let N=fr(k),re=typeof k=="string",U=(N||re)&&k.length;return N?U===i||U===o:re?U===2*i||U===2*o:k instanceof d}function I(k,N,re=!0){if(B(k))throw new Error("first arg must be private key");if(!B(N))throw new Error("second arg must be public key");return d.fromHex(N).multiply(c(k)).toRawBytes(re)}let O=e.bits2int||function(k){let N=ln(k),re=k.length*8-e.nBitLength;return re>0?N>>BigInt(re):N},C=e.bits2int_modN||function(k){return a(O(k))},P=ea(e.nBitLength);function j(k){if(typeof k!="bigint")throw new Error("bigint expected");if(!(pn<=k&&k<P))throw new Error(`bigint expected < 2^${e.nBitLength}`);return It(k,e.nByteLength)}function V(k,N,re=z){if(["recovered","canonical"].some(Ae=>Ae in re))throw new Error("sign() legacy options not supported");let{hash:U,randomBytes:R}=e,{lowS:K,prehash:H,extraEntropy:X}=re;K==null&&(K=!0),k=Ie("msgHash",k),H&&(k=Ie("prehashed msgHash",U(k)));let ne=C(k),ee=c(N),te=[j(ee),j(ne)];if(X!=null){let Ae=X===!0?R(r.BYTES):X;te.push(Ie("extraEntropy",Ae))}let Z=hn(...te),ie=ne;function Re(Ae){let Ne=O(Ae);if(!g(Ne))return;let Ve=u(Ne),$e=d.BASE.multiply(Ne).toAffine(),tt=a($e.x);if(tt===pn)return;let We=a(Ve*a(ie+tt*ee));if(We===pn)return;let Fr=($e.x===tt?0:2)|Number($e.y&Qt),xn=We;return K&&m(We)&&(xn=y(We),Fr^=1),new v(tt,xn,Fr)}return{seed:Z,k2sig:Re}}let z={lowS:e.lowS,prehash:!1},le={lowS:e.lowS,prehash:!1};function Q(k,N,re=z){let{seed:U,k2sig:R}=V(k,N,re),K=e;return Yf(K.hash.outputLen,K.nByteLength,K.hmac)(U,R)}d.BASE._setWindowSize(8);function st(k,N,re,U=le){let R=k;if(N=Ie("msgHash",N),re=Ie("publicKey",re),"strict"in U)throw new Error("options.strict was renamed to lowS");let{lowS:K,prehash:H}=U,X,ne;try{if(typeof R=="string"||fr(R))try{X=v.fromDER(R)}catch($e){if(!($e instanceof Mi.Err))throw $e;X=v.fromCompact(R)}else if(typeof R=="object"&&typeof R.r=="bigint"&&typeof R.s=="bigint"){let{r:$e,s:tt}=R;X=new v($e,tt)}else throw new Error("PARSE");ne=d.fromHex(re)}catch($e){if($e.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(K&&X.hasHighS())return!1;H&&(N=e.hash(N));let{r:ee,s:te}=X,Z=C(N),ie=u(te),Re=a(Z*ie),Ae=a(ee*ie),Ne=d.BASE.multiplyAndAddUnsafe(ne,Re,Ae)?.toAffine();return Ne?a(Ne.x)===ee:!1}return{CURVE:e,getPublicKey:S,getSharedSecret:I,sign:Q,verify:st,ProjectivePoint:d,Signature:v,utils:D}}var hk=f(h(),1);var ck=f(h(),1);var lu=class extends Mo{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Sw(e);let n=Zs(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 Lo(this),this.iHash.update(e),this}digestInto(e){Lo(this),jf(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:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},nh=(t,e,r)=>new lu(t,e).update(r).digest();nh.create=(t,e)=>new lu(t,e);function gI(t){return{hash:t,hmac:(e,...r)=>nh(t,e,iu(...r)),randomBytes:Qs}}function fu(t,e){let r=n=>Lw({...t,...gI(n)});return Object.freeze({...r(e),create:r})}var $w=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Mw=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wI=BigInt(1),ih=BigInt(2),Nw=(t,e)=>(t+e/ih)/e;function bI(t){let e=$w,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),d=t*t*t%e,c=d*d*t%e,l=De(c,r,e)*c%e,g=De(l,r,e)*c%e,w=De(g,ih,e)*d%e,m=De(w,i,e)*w%e,y=De(m,o,e)*m%e,E=De(y,a,e)*y%e,v=De(E,u,e)*E%e,D=De(v,a,e)*y%e,S=De(D,r,e)*c%e,B=De(S,s,e)*m%e,I=De(B,n,e)*d%e,O=De(I,ih,e);if(!oh.eql(oh.sqr(O),t))throw new Error("Cannot find square root");return O}var oh=$o($w,void 0,void 0,{sqrt:bI}),Dt=fu({a:BigInt(0),b:BigInt(7),Fp:oh,n:Mw,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=Mw,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wI*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=Nw(o*t,e),u=Nw(-n*t,e),d=ge(t-a*r-u*i,e),c=ge(-a*n-u*o,e),l=d>s,g=c>s;if(l&&(d=e-d),g&&(c=e-c),d>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:d,k2neg:g,k2:c}}}},su),gk=BigInt(0);var wk=Dt.ProjectivePoint;var Ik=f(h(),1);var vk=f(h(),1);function qw(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 xI=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},sh="urn:jwk:";function oe(t){return xI(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}`);Cd(n);let i=qw(n),o=M.string(i).toUint8Array(),s=yield Ko.digest({data:o});return M.uint8Array(s).toBase64Url()})}function Pr(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 qo(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 Kr(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 Fo(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 Fw(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 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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},EI=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 ct(this,arguments,void 0,function*({signature:r}){let n=Dt.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return ct(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",d:M.uint8Array(r).toBase64Url(),x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static bytesToPublicKey(e){return ct(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static compressPublicKey(e){return ct(this,arguments,void 0,function*({publicKeyBytes:r}){return Dt.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return ct(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:M.uint8Array(i.x).toBase64Url(),y:M.uint8Array(i.y).toBase64Url()};return o.kid=yield oe({jwk:o}),o})}static convertDerToCompactSignature(e){return ct(this,arguments,void 0,function*({derSignature:r}){return Dt.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return ct(this,arguments,void 0,function*({publicKeyBytes:r}){return Dt.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return ct(this,void 0,void 0,function*(){let e=Dt.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield oe({jwk:r}),r})}static getPublicKey(e){return ct(this,arguments,void 0,function*({key:r}){var n;if(!(Pr(r)&&r.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=r,o=EI(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield oe({jwk:o})),o})}static privateKeyToBytes(e){return ct(this,arguments,void 0,function*({privateKey:r}){if(!Pr(r))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return M.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return ct(this,arguments,void 0,function*({publicKey:r}){if(!(qo(r)&&r.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=M.base64Url(r.x).toUint8Array(),o=M.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return ct(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 Dt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return ct(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=Nn(r);return Dt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return ct(this,arguments,void 0,function*({privateKeyBytes:r}){return Dt.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return ct(this,arguments,void 0,function*({publicKeyBytes:r}){try{Dt.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return ct(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=Nn(i);return Dt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return ct(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=Dt.getPublicKey(r));let n=Dt.ProjectivePoint.fromHex(r),i=It(n.x,32),o=It(n.y,32);return{x:i,y:o}})}};var Wk=f(h(),1);var Nk=f(h(),1);var Vw=$o(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),vI=Vw.create(BigInt("-3")),SI=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),_I=fu({a:vI,b:SI,Fp:Vw,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},su),Mt=_I;var ut=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},AI=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},dt=class t{static adjustSignatureToLowS(e){return ut(this,arguments,void 0,function*({signature:r}){let n=Mt.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return ut(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",d:M.uint8Array(r).toBase64Url(),x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static bytesToPublicKey(e){return ut(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield t.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static compressPublicKey(e){return ut(this,arguments,void 0,function*({publicKeyBytes:r}){return Mt.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return ut(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:M.uint8Array(i.x).toBase64Url(),y:M.uint8Array(i.y).toBase64Url()};return o.kid=yield oe({jwk:o}),o})}static convertDerToCompactSignature(e){return ut(this,arguments,void 0,function*({derSignature:r}){return Mt.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return ut(this,arguments,void 0,function*({publicKeyBytes:r}){return Mt.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return ut(this,void 0,void 0,function*(){let e=Mt.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield oe({jwk:r}),r})}static getPublicKey(e){return ut(this,arguments,void 0,function*({key:r}){var n;if(!(Pr(r)&&r.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=r,o=AI(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield oe({jwk:o})),o})}static privateKeyToBytes(e){return ut(this,arguments,void 0,function*({privateKey:r}){if(!Pr(r))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return M.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return ut(this,arguments,void 0,function*({publicKey:r}){if(!(qo(r)&&r.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=M.base64Url(r.x).toUint8Array(),o=M.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return ut(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 Mt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return ut(this,arguments,void 0,function*({data:r,key:n}){let i=yield t.privateKeyToBytes({privateKey:n}),o=Nn(r);return Mt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return ut(this,arguments,void 0,function*({privateKeyBytes:r}){return Mt.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return ut(this,arguments,void 0,function*({publicKeyBytes:r}){try{Mt.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return ut(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r}),s=Nn(i);return Mt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return ut(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=Mt.getPublicKey(r));let n=Mt.ProjectivePoint.fromHex(r),i=It(n.x,32),o=It(n.y,32);return{x:i,y:o}})}};var ra=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},na=class extends Ur{computePublicKey(e){return ra(this,arguments,void 0,function*({key:r}){if(!Pr(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 dt.computePublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return ra(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 dt.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return ra(this,arguments,void 0,function*({key:r}){if(!Pr(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 dt.getPublicKey({key:r});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return ra(this,arguments,void 0,function*({key:r,data:n}){if(!Pr(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 dt.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return ra(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!qo(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 dt.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};var HC=f(h(),1);var NC=f(h(),1);var UC=f(h(),1);var oC=f(h(),1);var eC=f(h(),1),hu=BigInt(4294967295),ah=BigInt(32);function Hw(t,e=!1){return e?{h:Number(t&hu),l:Number(t>>ah&hu)}:{h:Number(t>>ah&hu)|0,l:Number(t&hu)|0}}function TI(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}=Hw(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var II=(t,e)=>BigInt(t>>>0)<<ah|BigInt(e>>>0),DI=(t,e,r)=>t>>>r,BI=(t,e,r)=>t<<32-r|e>>>r,RI=(t,e,r)=>t>>>r|e<<32-r,OI=(t,e,r)=>t<<32-r|e>>>r,kI=(t,e,r)=>t<<64-r|e>>>r-32,CI=(t,e,r)=>t>>>r-32|e<<64-r,UI=(t,e)=>e,PI=(t,e)=>t,KI=(t,e,r)=>t<<r|e>>>32-r,LI=(t,e,r)=>e<<r|t>>>32-r,MI=(t,e,r)=>e<<r-32|t>>>64-r,NI=(t,e,r)=>t<<r-32|e>>>64-r;function $I(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var qI=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),FI=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,VI=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),HI=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,jI=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),WI=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var zI={fromBig:Hw,split:TI,toBig:II,shrSH:DI,shrSL:BI,rotrSH:RI,rotrSL:OI,rotrBH:kI,rotrBL:CI,rotr32H:UI,rotr32L:PI,rotlSH:KI,rotlSL:LI,rotlBH:MI,rotlBL:NI,add:$I,add3L:qI,add3H:FI,add4L:VI,add4H:HI,add5H:WI,add5L:jI},ae=zI;var[GI,JI]=ae.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))),Fn=new Uint32Array(80),Vn=new Uint32Array(80),ch=class extends No{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:a,Dl:u,Eh:d,El:c,Fh:l,Fl:g,Gh:w,Gl:m,Hh:y,Hl:E}=this;return[e,r,n,i,o,s,a,u,d,c,l,g,w,m,y,E]}set(e,r,n,i,o,s,a,u,d,c,l,g,w,m,y,E){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=a|0,this.Dl=u|0,this.Eh=d|0,this.El=c|0,this.Fh=l|0,this.Fl=g|0,this.Gh=w|0,this.Gl=m|0,this.Hh=y|0,this.Hl=E|0}process(e,r){for(let S=0;S<16;S++,r+=4)Fn[S]=e.getUint32(r),Vn[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let B=Fn[S-15]|0,I=Vn[S-15]|0,O=ae.rotrSH(B,I,1)^ae.rotrSH(B,I,8)^ae.shrSH(B,I,7),C=ae.rotrSL(B,I,1)^ae.rotrSL(B,I,8)^ae.shrSL(B,I,7),P=Fn[S-2]|0,j=Vn[S-2]|0,V=ae.rotrSH(P,j,19)^ae.rotrBH(P,j,61)^ae.shrSH(P,j,6),z=ae.rotrSL(P,j,19)^ae.rotrBL(P,j,61)^ae.shrSL(P,j,6),le=ae.add4L(C,z,Vn[S-7],Vn[S-16]),Q=ae.add4H(le,O,V,Fn[S-7],Fn[S-16]);Fn[S]=Q|0,Vn[S]=le|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:u,Dh:d,Dl:c,Eh:l,El:g,Fh:w,Fl:m,Gh:y,Gl:E,Hh:v,Hl:D}=this;for(let S=0;S<80;S++){let B=ae.rotrSH(l,g,14)^ae.rotrSH(l,g,18)^ae.rotrBH(l,g,41),I=ae.rotrSL(l,g,14)^ae.rotrSL(l,g,18)^ae.rotrBL(l,g,41),O=l&w^~l&y,C=g&m^~g&E,P=ae.add5L(D,I,C,JI[S],Vn[S]),j=ae.add5H(P,v,B,O,GI[S],Fn[S]),V=P|0,z=ae.rotrSH(n,i,28)^ae.rotrBH(n,i,34)^ae.rotrBH(n,i,39),le=ae.rotrSL(n,i,28)^ae.rotrBL(n,i,34)^ae.rotrBL(n,i,39),Q=n&o^n&a^o&a,st=i&s^i&u^s&u;v=y|0,D=E|0,y=w|0,E=m|0,w=l|0,m=g|0,{h:l,l:g}=ae.add(d|0,c|0,j|0,V|0),d=a|0,c=u|0,a=o|0,u=s|0,o=n|0,s=i|0;let k=ae.add3L(V,le,st);n=ae.add3H(k,j,z,Q),i=k|0}({h:n,l:i}=ae.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=ae.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:u}=ae.add(this.Ch|0,this.Cl|0,a|0,u|0),{h:d,l:c}=ae.add(this.Dh|0,this.Dl|0,d|0,c|0),{h:l,l:g}=ae.add(this.Eh|0,this.El|0,l|0,g|0),{h:w,l:m}=ae.add(this.Fh|0,this.Fl|0,w|0,m|0),{h:y,l:E}=ae.add(this.Gh|0,this.Gl|0,y|0,E|0),{h:v,l:D}=ae.add(this.Hh|0,this.Hl|0,v|0,D|0),this.set(n,i,o,s,a,u,d,c,l,g,w,m,y,E,v,D)}roundClean(){Fn.fill(0),Vn.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 uh=ou(()=>new ch);var dC=f(h(),1);var pr=BigInt(0),Nt=BigInt(1),pu=BigInt(2),YI=BigInt(8),XI={zip215:!0};function ZI(t){let e=ta(t);return Zt(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function yu(t){let e=ZI(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:u}=e,d=pu<<BigInt(a*8)-Nt,c=r.create,l=e.uvRatio||((U,R)=>{try{return{isValid:!0,value:r.sqrt(U*r.inv(R))}}catch{return{isValid:!1,value:pr}}}),g=e.adjustScalarBytes||(U=>U),w=e.domain||((U,R,K)=>{if(R.length||K)throw new Error("Contexts/pre-hash are not supported");return U}),m=U=>typeof U=="bigint"&&pr<U,y=(U,R)=>m(U)&&m(R)&&U<R,E=U=>U===pr||y(U,d);function v(U,R){if(y(U,R))return U;throw new Error(`Expected valid scalar < ${R}, got ${typeof U} ${U}`)}function D(U){return U===pr?U:v(U,n)}let S=new Map;function B(U){if(!(U instanceof I))throw new Error("ExtendedPoint expected")}class I{constructor(R,K,H,X){if(this.ex=R,this.ey=K,this.ez=H,this.et=X,!E(R))throw new Error("x required");if(!E(K))throw new Error("y required");if(!E(H))throw new Error("z required");if(!E(X))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(R){if(R instanceof I)throw new Error("extended point not allowed");let{x:K,y:H}=R||{};if(!E(K)||!E(H))throw new Error("invalid affine point");return new I(K,H,Nt,c(K*H))}static normalizeZ(R){let K=r.invertBatch(R.map(H=>H.ez));return R.map((H,X)=>H.toAffine(K[X])).map(I.fromAffine)}_setWindowSize(R){this._WINDOW_SIZE=R,S.delete(this)}assertValidity(){let{a:R,d:K}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:H,ey:X,ez:ne,et:ee}=this,te=c(H*H),Z=c(X*X),ie=c(ne*ne),Re=c(ie*ie),Ae=c(te*R),Ne=c(ie*c(Ae+Z)),Ve=c(Re+c(K*c(te*Z)));if(Ne!==Ve)throw new Error("bad point: equation left != right (1)");let $e=c(H*X),tt=c(ne*ee);if($e!==tt)throw new Error("bad point: equation left != right (2)")}equals(R){B(R);let{ex:K,ey:H,ez:X}=this,{ex:ne,ey:ee,ez:te}=R,Z=c(K*te),ie=c(ne*X),Re=c(H*te),Ae=c(ee*X);return Z===ie&&Re===Ae}is0(){return this.equals(I.ZERO)}negate(){return new I(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:R}=e,{ex:K,ey:H,ez:X}=this,ne=c(K*K),ee=c(H*H),te=c(pu*c(X*X)),Z=c(R*ne),ie=K+H,Re=c(c(ie*ie)-ne-ee),Ae=Z+ee,Ne=Ae-te,Ve=Z-ee,$e=c(Re*Ne),tt=c(Ae*Ve),We=c(Re*Ve),Fr=c(Ne*Ae);return new I($e,tt,Fr,We)}add(R){B(R);let{a:K,d:H}=e,{ex:X,ey:ne,ez:ee,et:te}=this,{ex:Z,ey:ie,ez:Re,et:Ae}=R;if(K===BigInt(-1)){let ss=c((ne-X)*(ie+Z)),Oa=c((ne+X)*(ie-Z)),as=c(Oa-ss);if(as===pr)return this.double();let ka=c(ee*pu*Ae),Ca=c(te*pu*Re),Ht=Ca+ka,vn=Oa+ss,cs=Ca-ka,Ua=c(Ht*as),Qn=c(vn*cs),Pa=c(Ht*cs),od=c(as*vn);return new I(Ua,Qn,od,Pa)}let Ne=c(X*Z),Ve=c(ne*ie),$e=c(te*H*Ae),tt=c(ee*Re),We=c((X+ne)*(Z+ie)-Ne-Ve),Fr=tt-$e,xn=tt+$e,os=c(Ve-K*Ne),Ra=c(We*Fr),id=c(xn*os),En=c(We*os),Vt=c(Fr*xn);return new I(Ra,id,Vt,En)}subtract(R){return this.add(R.negate())}wNAF(R){return P.wNAFCached(this,S,R,I.normalizeZ)}multiply(R){let{p:K,f:H}=this.wNAF(v(R,n));return I.normalizeZ([K,H])[0]}multiplyUnsafe(R){let K=D(R);return K===pr?C:this.equals(C)||K===Nt?this:this.equals(O)?this.wNAF(K).p:P.unsafeLadder(this,K)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(R){let{ex:K,ey:H,ez:X}=this,ne=this.is0();R==null&&(R=ne?YI:r.inv(X));let ee=c(K*R),te=c(H*R),Z=c(X*R);if(ne)return{x:pr,y:Nt};if(Z!==Nt)throw new Error("invZ was invalid");return{x:ee,y:te}}clearCofactor(){let{h:R}=e;return R===Nt?this:this.multiplyUnsafe(R)}static fromHex(R,K=!1){let{d:H,a:X}=e,ne=r.BYTES;R=Ie("pointHex",R,ne);let ee=R.slice(),te=R[ne-1];ee[ne-1]=te&-129;let Z=hr(ee);Z===pr||(K?v(Z,d):v(Z,r.ORDER));let ie=c(Z*Z),Re=c(ie-Nt),Ae=c(H*ie-X),{isValid:Ne,value:Ve}=l(Re,Ae);if(!Ne)throw new Error("Point.fromHex: invalid y coordinate");let $e=(Ve&Nt)===Nt,tt=(te&128)!==0;if(!K&&Ve===pr&&tt)throw new Error("Point.fromHex: x=0 and x_0=1");return tt!==$e&&(Ve=c(-Ve)),I.fromAffine({x:Ve,y:Z})}static fromPrivateKey(R){return z(R).point}toRawBytes(){let{x:R,y:K}=this.toAffine(),H=fn(K,r.BYTES);return H[H.length-1]|=R&Nt?128:0,H}toHex(){return dn(this.toRawBytes())}}I.BASE=new I(e.Gx,e.Gy,Nt,c(e.Gx*e.Gy)),I.ZERO=new I(pr,Nt,Nt,pr);let{BASE:O,ZERO:C}=I,P=du(I,a*8);function j(U){return ge(U,n)}function V(U){return j(hr(U))}function z(U){let R=a;U=Ie("private key",U,R);let K=Ie("hashed private key",o(U),2*R),H=g(K.slice(0,R)),X=K.slice(R,2*R),ne=V(H),ee=O.multiply(ne),te=ee.toRawBytes();return{head:H,prefix:X,scalar:ne,point:ee,pointBytes:te}}function le(U){return z(U).pointBytes}function Q(U=new Uint8Array,...R){let K=hn(...R);return V(o(w(K,Ie("context",U),!!i)))}function st(U,R,K={}){U=Ie("message",U),i&&(U=i(U));let{prefix:H,scalar:X,pointBytes:ne}=z(R),ee=Q(K.context,H,U),te=O.multiply(ee).toRawBytes(),Z=Q(K.context,te,ne,U),ie=j(ee+Z*X);D(ie);let Re=hn(te,fn(ie,r.BYTES));return Ie("result",Re,a*2)}let k=XI;function N(U,R,K,H=k){let{context:X,zip215:ne}=H,ee=r.BYTES;U=Ie("signature",U,2*ee),R=Ie("message",R),i&&(R=i(R));let te=hr(U.slice(ee,2*ee)),Z,ie,Re;try{Z=I.fromHex(K,ne),ie=I.fromHex(U.slice(0,ee),ne),Re=O.multiplyUnsafe(te)}catch{return!1}if(!ne&&Z.isSmallOrder())return!1;let Ae=Q(X,ie.toRawBytes(),Z.toRawBytes(),R);return ie.add(Z.multiplyUnsafe(Ae)).subtract(Re).clearCofactor().equals(I.ZERO)}return O._setWindowSize(8),{CURVE:e,getPublicKey:le,sign:st,verify:N,ExtendedPoint:I,utils:{getExtendedPublicKey:z,randomPrivateKey:()=>s(r.BYTES),precompute(U=8,R=I.BASE){return R._setWindowSize(U),R.multiply(BigInt(3)),R}}}}var pC=f(h(),1);var ia=BigInt(0),dh=BigInt(1);function QI(t){return Zt(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function jw(t){let e=QI(t),{P:r}=e,n=S=>ge(S,r),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,a=e.adjustScalarBytes||(S=>S),u=e.powPminus2||(S=>Zf(S,r-BigInt(2),r));function d(S,B,I){let O=n(S*(B-I));return B=n(B-O),I=n(I+O),[B,I]}function c(S){if(typeof S=="bigint"&&ia<=S&&S<r)return S;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function g(S,B){let I=c(S),O=c(B),C=I,P=dh,j=ia,V=I,z=dh,le=ia,Q;for(let k=BigInt(i-1);k>=ia;k--){let N=O>>k&dh;le^=N,Q=d(le,P,V),P=Q[0],V=Q[1],Q=d(le,j,z),j=Q[0],z=Q[1],le=N;let re=P+j,U=n(re*re),R=P-j,K=n(R*R),H=U-K,X=V+z,ne=V-z,ee=n(ne*re),te=n(X*R),Z=ee+te,ie=ee-te;V=n(Z*Z),z=n(C*n(ie*ie)),P=n(U*K),j=n(H*(U+n(l*H)))}Q=d(le,P,V),P=Q[0],V=Q[1],Q=d(le,j,z),j=Q[0],z=Q[1];let st=u(j);return n(P*st)}function w(S){return fn(n(S),o)}function m(S){let B=Ie("u coordinate",S,o);return s===32&&(B[31]&=127),hr(B)}function y(S){let B=Ie("scalar",S),I=B.length;if(I!==o&&I!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${I}`);return hr(a(B))}function E(S,B){let I=m(B),O=y(S),C=g(I,O);if(C===ia)throw new Error("Invalid private or public key received");return w(C)}let v=w(e.Gu);function D(S){return E(S,v)}return{scalarMult:E,scalarMultBase:D,getSharedSecret:(S,B)=>E(S,B),getPublicKey:S=>D(S),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:v}}var oa=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ww=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),xC=BigInt(0),eD=BigInt(1),lh=BigInt(2),tD=BigInt(5),zw=BigInt(10),rD=BigInt(20),nD=BigInt(40),Gw=BigInt(80);function Jw(t){let e=oa,n=t*t%e*t%e,i=De(n,lh,e)*n%e,o=De(i,eD,e)*t%e,s=De(o,tD,e)*o%e,a=De(s,zw,e)*s%e,u=De(a,rD,e)*a%e,d=De(u,nD,e)*u%e,c=De(d,Gw,e)*d%e,l=De(c,Gw,e)*d%e,g=De(l,zw,e)*s%e;return{pow_p_5_8:De(g,lh,e)*t%e,b2:n}}function Yw(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function iD(t,e){let r=oa,n=ge(e*e*e,r),i=ge(n*n*e,r),o=Jw(t*i).pow_p_5_8,s=ge(t*n*o,r),a=ge(e*s*s,r),u=s,d=ge(s*Ww,r),c=a===t,l=a===ge(-t,r),g=a===ge(-t*Ww,r);return c&&(s=u),(l||g)&&(s=d),kw(s,r)&&(s=ge(-s,r)),{isValid:c||l,value:s}}var er=$o(oa,void 0,!0),sa={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:er,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:uh,randomBytes:Qs,adjustScalarBytes:Yw,uvRatio:iD},Hn=yu(sa);function Xw(t,e,r){if(e.length>255)throw new Error("Context is too big");return iu(Wf("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var EC=yu({...sa,domain:Xw}),vC=yu({...sa,domain:Xw,prehash:uh}),Ni=jw({P:oa,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=oa,{pow_p_5_8:r,b2:n}=Jw(t);return ge(De(r,BigInt(3),e)*n,e)},adjustScalarBytes:Yw,randomBytes:Qs});function Zw(t){let{y:e}=Hn.ExtendedPoint.fromHex(t),r=BigInt(1);return er.toBytes(er.create((r+e)*er.inv(r-e)))}function Qw(t){let e=sa.hash(t.subarray(0,32));return sa.adjustScalarBytes(e).subarray(0,32)}var oD=(er.ORDER+BigInt(3))/BigInt(8),SC=er.pow(lh,oD),_C=er.sqrt(er.neg(er.ONE)),AC=(er.ORDER-BigInt(5))/BigInt(8),TC=BigInt(486662);var IC=Cw(er,er.neg(BigInt(486664)));var DC=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),BC=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),RC=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),OC=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var kC=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var tr=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},sD=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},Xe=class t{static bytesToPrivateKey(e){return tr(this,arguments,void 0,function*({privateKeyBytes:r}){let n=Hn.getPublicKey(r),i={crv:"Ed25519",d:M.uint8Array(r).toBase64Url(),kty:"OKP",x:M.uint8Array(n).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static bytesToPublicKey(e){return tr(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"Ed25519",x:M.uint8Array(r).toBase64Url()};return n.kid=yield oe({jwk:n}),n})}static computePublicKey(e){return tr(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=Hn.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:M.uint8Array(i).toBase64Url()};return o.kid=yield oe({jwk:o}),o})}static convertPrivateKeyToX25519(e){return tr(this,arguments,void 0,function*({privateKey:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=Qw(n),o=Ni.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:M.uint8Array(i).toBase64Url(),x:M.uint8Array(o).toBase64Url()};return s.kid=yield oe({jwk:s}),s})}static convertPublicKeyToX25519(e){return tr(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=Zw(n),s={kty:"OKP",crv:"X25519",x:M.uint8Array(o).toBase64Url()};return s.kid=yield oe({jwk:s}),s})}static generateKey(){return tr(this,void 0,void 0,function*(){let e=Hn.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield oe({jwk:r}),r})}static getPublicKey(e){return tr(this,arguments,void 0,function*({key:r}){var n;if(!(Kr(r)&&r.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=r,o=sD(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield oe({jwk:o})),o})}static privateKeyToBytes(e){return tr(this,arguments,void 0,function*({privateKey:r}){if(!Kr(r))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return M.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return tr(this,arguments,void 0,function*({publicKey:r}){if(!Fo(r))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return M.base64Url(r.x).toUint8Array()})}static sign(e){return tr(this,arguments,void 0,function*({key:r,data:n}){let i=yield t.privateKeyToBytes({privateKey:r});return Hn.sign(n,i)})}static validatePublicKey(e){return tr(this,arguments,void 0,function*({publicKeyBytes:r}){try{Hn.ExtendedPoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return tr(this,arguments,void 0,function*({key:r,signature:n,data:i}){let o=yield t.publicKeyToBytes({publicKey:r});return Hn.verify(n,i,o)})}};var aa=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},mu=class extends Ur{computePublicKey(e){return aa(this,arguments,void 0,function*({key:r}){if(!Kr(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Xe.computePublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}generateKey(e){return aa(this,arguments,void 0,function*({algorithm:r}){switch(r){case"Ed25519":{let n=yield Xe.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return aa(this,arguments,void 0,function*({key:r}){if(!Kr(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":{let n=yield Xe.getPublicKey({key:r});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${r.crv}`)}})}sign(e){return aa(this,arguments,void 0,function*({key:r,data:n}){if(!Kr(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(r.crv){case"Ed25519":return yield Xe.sign({key:r,data:n});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}verify(e){return aa(this,arguments,void 0,function*({key:r,signature:n,data:i}){if(!Fo(r))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(r.crv){case"Ed25519":return yield Xe.verify({key:r,signature:n,data:i});default:throw new Error(`Unsupported curve: ${r.crv}`)}})}};var yn=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},fh={Ed25519:{implementation:mu,names:["Ed25519"]},secp256k1:{implementation:na,names:["ES256K","secp256k1"]},secp256r1:{implementation:na,names:["ES256","secp256r1"]},"SHA-256":{implementation:tu,names:["SHA-256"]}},gt=class{constructor(e){var r;this._algorithmInstances=new Map,this._keyStore=(r=e?.keyStore)!==null&&r!==void 0?r:new bc}digest(e){return yn(this,arguments,void 0,function*({algorithm:r,data:n}){return yield this.getAlgorithm({algorithm:r}).digest({algorithm:r,data:n})})}exportKey(e){return yn(this,arguments,void 0,function*({keyUri:r}){return yield this.getPrivateKey({keyUri:r})})}generateKey(e){return yn(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=`${sh}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return yn(this,arguments,void 0,function*({key:r}){let n=yield oe({jwk:r});return`${sh}${n}`})}getPublicKey(e){return yn(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 yn(this,arguments,void 0,function*({key:r}){var n;if(!Fw(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 oe({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return yn(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 yn(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=fh[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 fh){let o=fh[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 yn(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})}};var tU=f(h(),1);var gu=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 bw(e)}static randomUuid(){return Po.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")}};var dU=f(h(),1);var oU=f(h(),1);var bU=f(h(),1);var pU=f(h(),1);var xU=f(h(),1);var EU=f(h(),1);var vU=f(h(),1);var AU=f(h(),1);var IU=f(h(),1);var kU=f(h(),1);var jn=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},aD=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},Vo=class t{static bytesToPrivateKey(e){return jn(this,arguments,void 0,function*({privateKeyBytes:r}){let n=Ni.getPublicKey(r),i={kty:"OKP",crv:"X25519",d:M.uint8Array(r).toBase64Url(),x:M.uint8Array(n).toBase64Url()};return i.kid=yield oe({jwk:i}),i})}static bytesToPublicKey(e){return jn(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"X25519",x:M.uint8Array(r).toBase64Url()};return n.kid=yield oe({jwk:n}),n})}static computePublicKey(e){return jn(this,arguments,void 0,function*({key:r}){let n=yield t.privateKeyToBytes({privateKey:r}),i=Ni.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:M.uint8Array(i).toBase64Url()};return o.kid=yield oe({jwk:o}),o})}static generateKey(){return jn(this,void 0,void 0,function*(){let e=Ni.utils.randomPrivateKey(),r=yield t.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield oe({jwk:r}),r})}static getPublicKey(e){return jn(this,arguments,void 0,function*({key:r}){var n;if(!(Kr(r)&&r.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=r,o=aD(r,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield oe({jwk:o})),o})}static privateKeyToBytes(e){return jn(this,arguments,void 0,function*({privateKey:r}){if(!Kr(r))throw new Error("X25519: The provided key is not a valid OKP private key.");return M.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return jn(this,arguments,void 0,function*({publicKey:r}){if(!Fo(r))throw new Error("X25519: The provided key is not a valid OKP public key.");return M.base64Url(r.x).toUint8Array()})}static sharedSecret(e){return jn(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 Ni.getSharedSecret(i,o)})}};var KU=f(h(),1);var $U=f(h(),1);var mh={};$a(mh,{extractDidFragment:()=>Bt,getServices:()=>cD,getVerificationMethodByKey:()=>uD,getVerificationMethodTypes:()=>ph,getVerificationMethods:()=>ca,getVerificationRelationshipsById:()=>yh,isDidService:()=>eb,isDidVerificationMethod:()=>wu,isDwnDidService:()=>dD,keyBytesToMultibaseId:()=>bu,multibaseIdToKeyBytes:()=>xu});var xP=f(h(),1);function Bt(t){if(typeof t=="string"&&t.length!==0)return t.split("#").pop()}function cD({didDocument:t,id:e,type:r}){return t?.service?.filter(n=>!(e&&n.id!==e||r&&n.type!==r))??[]}async function uD({didDocument:t,publicKeyJwk:e,publicKeyMultibase:r}){let n=ca({didDocument:t});for(let i of n)if(e&&i.publicKeyJwk){if(await oe({jwk:e})===await oe({jwk:i.publicKeyJwk}))return i}else if(r&&i.publicKeyMultibase&&r===i.publicKeyMultibase)return i;return null}function ca({didDocument:t}){if(!t)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...t.verificationMethod?.filter(wu)??[]),Object.keys(oi).forEach(r=>{e.push(...t[r]?.filter(wu)??[])}),e}function ph({didDocument:t}){let r=ca({didDocument:t}).map(n=>n.type);return[...new Set(r)]}function yh({didDocument:t,methodId:e}){let r=[];return Object.keys(oi).forEach(n=>{if(Array.isArray(t[n])){let i=t[n],o=Bt(e);i.some(a=>{let u=Bt(a)===o,d=wu(a)&&Bt(a.id)===o;return u||d})&&r.push(n)}}),r}function eb(t){return!t||typeof t!="object"||t===null?!1:"id"in t&&"type"in t&&"serviceEndpoint"in t}function dD(t){if(!eb(t)||t.type!=="DecentralizedWebNode"||!("enc"in t&&"sig"in t))return!1;let e=r=>typeof r=="string"||Array.isArray(r)&&r.every(n=>typeof n=="string");return e(t.enc)&&e(t.sig)}function wu(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 bu({keyBytes:t,multicodecCode:e,multicodecName:r}){let n=ht.addPrefix({code:e,data:t,name:r}),i=M.uint8Array(n).toBase58Btc();return M.base58Btc(i).toMultibase()}function xu({multibaseKeyId:t}){try{let e=M.multibase(t).toBase58Btc(),r=M.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=ht.removePrefix({prefixedData:r});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new q("invalidDid",`Invalid multibase identifier: ${t}`)}}var xt=class t{constructor({uri:e,document:r,metadata:n,keyManager:i}){this.uri=e,this.document=r,this.metadata=n,this.keyManager=i}async export(){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=await this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=await this.keyManager.exportKey({keyUri:i});r.push({...o})}e.privateKeys=r}return e}async getSigner(e){let r=this.document.verificationMethod?.find(a=>Bt(a.id)===(Bt(e?.methodId)??Bt(this.document.assertionMethod?.[0])));if(!(r&&r.publicKeyJwk))throw new q("internalError","A verification method intended for signing could not be determined from the DID Document");let n=await this.keyManager.getKeyUri({key:r.publicKeyJwk}),i=await this.keyManager.getPublicKey({keyUri:n}),o=this.keyManager;return{algorithm:gu.getJoseSignatureAlgorithmFromPublicKey(i),keyId:r.id,async sign({data:a}){return await o.sign({data:a,keyUri:n})},async verify({data:a,signature:u}){return await o.verify({data:a,key:i,signature:u})}}}static async import({portableDid:e,keyManager:r=new gt}){let n=ca({didDocument:e.document});if(n.length===0)throw new q("invalidDidDocument","At least one verification method is required but 0 were given");for(let o of e.privateKeys??[]){let s=await r.getKeyUri({key:o});await r.getPublicKey({keyUri:s}).then(()=>!0).catch(()=>!1)||await r.importKey({key:o})}for(let o of n){if(!o.publicKeyJwk)throw new Error(`Verification method '${o.id}' does not contain a public key in JWK format`);let s=await r.getKeyUri({key:o.publicKeyJwk});await r.getPublicKey({keyUri:s})}return new t({uri:e.uri,document:e.document,metadata:e.metadata,keyManager:r})}};var D3=f(h(),1);var r3=f(h(),1);var HP=f(h(),1);var LP=f(h(),1);var IP=f(h(),1);var gh="0123456789abcdef",rb=[],tb=[];for(let t=0;t<256;t++)rb[t]=gh[t>>4&15]+gh[t&15],t<16&&(t<10?tb[48+t]=t:tb[87+t]=t);var wh=t=>{let e=t.length,r="",n=0;for(;n<e;)r+=rb[t[n++]];return r};var nb=(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};var BP=f(h()),ib="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",lD=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(ua=0;ua<ib.length;ua++)lD[ib.charCodeAt(ua)]=ua;var ua;var fD=new TextDecoder,bh=(t,e)=>e?new TextDecoder(e).decode(t):fD.decode(t),hD=new TextEncoder,rr=t=>hD.encode(t);var ob=typeof window<"u"?window:self,sb=ob.crypto||ob.msCrypto||{},PP=sb.subtle||sb.webkitSubtle;var $P=f(h(),1);function Ho(t){let e=t<0?1:0;return t=Math.abs(Number(t||1)),Math.floor(Math.log10(t))+1+e}function Eu(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 we(t,e,r){let n=[],i=null;return we._encode(n,t),i=nb(n),we.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,r),e):i}we.bytes=-1;we._floatConversionDetected=!1;we._encode=function(t,e){if(e!=null)switch(Eu(e)){case"object":we.dict(t,e);break;case"map":we.dictMap(t,e);break;case"array":we.list(t,e);break;case"set":we.listSet(t,e);break;case"string":we.string(t,e);break;case"number":we.number(t,e);break;case"boolean":we.number(t,e);break;case"arraybufferview":we.buffer(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":we.buffer(t,new Uint8Array(e));break}};var vu=new Uint8Array([101]),ab=new Uint8Array([100]),cb=new Uint8Array([108]);we.buffer=function(t,e){t.push(rr(e.length+":"),e)};we.string=function(t,e){t.push(rr(rr(e).byteLength+":"+e))};we.number=function(t,e){if(Number.isInteger(e))return t.push(rr("i"+BigInt(e)+"e"));let r=2147483648,n=e/r<<0,i=e%r<<0,o=n*r+i;t.push(rr("i"+o+"e")),o!==e&&!we._floatConversionDetected&&(we._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())};we.dict=function(t,e){t.push(ab);let r=0,n,i=Object.keys(e).sort(),o=i.length;for(;r<o;r++)n=i[r],e[n]!=null&&(we.string(t,n),we._encode(t,e[n]));t.push(vu)};we.dictMap=function(t,e){t.push(ab);let r=Array.from(e.keys()).sort();for(let n of r)e.get(n)!=null&&(ArrayBuffer.isView(n)?we._encode(t,n):we.string(t,String(n)),we._encode(t,e.get(n)));t.push(vu)};we.list=function(t,e){let r=0,n=e.length;for(t.push(cb);r<n;r++)e[r]!=null&&we._encode(t,e[r]);t.push(vu)};we.listSet=function(t,e){t.push(cb);for(let r of e)r!=null&&we._encode(t,r);t.push(vu)};var ub=we;var zP=f(h(),1);var pD=105,yD=58,mD=100,gD=108,xh=101;function db(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 Y(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),Y.position=0,Y.encoding=n||null,Y.data=ArrayBuffer.isView(t)?new Uint8Array(t.slice(e,r)):rr(t),Y.bytes=Y.data.length,Y.next())}Y.bytes=0;Y.position=0;Y.data=null;Y.encoding=null;Y.next=function(){switch(Y.data[Y.position]){case mD:return Y.dictionary();case gD:return Y.list();case pD:return Y.integer();default:return Y.buffer()}};Y.find=function(t){let e=Y.position,r=Y.data.length,n=Y.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)+"]")};Y.dictionary=function(){Y.position++;let t={};for(;Y.data[Y.position]!==xh;){let e=Y.buffer(),r=bh(e);r.includes("\uFFFD")&&(r=wh(e)),t[r]=Y.next()}return Y.position++,t};Y.list=function(){Y.position++;let t=[];for(;Y.data[Y.position]!==xh;)t.push(Y.next());return Y.position++,t};Y.integer=function(){let t=Y.find(xh),e=db(Y.data,Y.position+1,t);return Y.position+=t+1-Y.position,e};Y.buffer=function(){let t=Y.find(yD),e=db(Y.data,Y.position,t),r=++t+e;return Y.position=r,Y.encoding?bh(Y.data.slice(t,r)):Y.data.slice(t,r)};var lb=Y;var XP=f(h(),1);function wD(t){let e=2;for(let r of t)e+=Su(r);return e}function bD(t){let e=2;for(let[r,n]of t){let i=rr(r).byteLength;e+=Ho(i)+1+i,e+=Su(n)}return e}function xD(t){let e=2,r=Object.keys(t);for(let n=0;n<r.length;n++){let i=rr(r[n]).byteLength;e+=Ho(i)+1+i,e+=Su(t[r[n]])}return e}function ED(t){let e=rr(t).byteLength;return Ho(e)+1+e}function vD(t){let e=t.byteLength-t.byteOffset;return Ho(e)+1+e}function Su(t){if(t==null)return 0;let r=Eu(t);switch(r){case"arraybufferview":return vD(t);case"string":return ED(t);case"array":case"set":return wD(t);case"number":return 1+Ho(Math.floor(t))+1;case"bigint":return 1+t.toString().length+1;case"object":return xD(t);case"map":return bD(t);default:throw new TypeError(`Unsupported value of type "${r}"`)}}var Eh=Su;var SD=Eh,vh={encode:ub,decode:lb,byteLength:Eh,encodingLength:SD};var h3=f(h(),1);var n3=f(h(),1),_D=/^(\d{1,3}\.){3,3}\d{1,3}$/;var AD=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var yr={name:"v4",size:4,isFormat:t=>_D.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]}`}},mn={name:"v6",size:16,isFormat:t=>t.length>0&&AD.test(t),encode(t,e,r){r=~~r;let n=r+16,i=-1,o=0,s=0,a=!0,u=!1;e=e||new Uint8Array(r+16);for(let d=0;d<t.length;d++){let c=t.charCodeAt(d);c===58?(a?i!==-1?(r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2):r<n&&(i=r):(u===!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),a=!0,u=!1):c===46?(r<n&&(e[r]=s),r++,s=0,o=0,a=!1,u=!0):(a=!1,c>=97?c-=87:c>=65?c-=55:(c-=48,s=s*10+c),o=(o<<4)+c)}if(a===!1)u===!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 d=Math.min(r-1,n-1);d>=i+2;d--)e[d]=e[d-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 fb(t){if(yr.isFormat(t))return yr.size;if(mn.isFormat(t))return mn.size;throw Error(`Invalid ip address: ${t}`)}function hb(t){return fb(t)===yr.size?1:2}function pb(t,e,r){r=~~r;let n=fb(t);return typeof e=="function"&&(e=e(r+n)),n===yr.size?yr.encode(t,e,r):mn.encode(t,e,r)}function yb(t,e,r){if(e=~~e,r=r||t.length-e,r===yr.size)return yr.decode(t,e,r);if(r===mn.size)return mn.decode(t,e,r);throw Error(`Invalid buffer size needs to be ${yr.size} for v4 or ${mn.size} for v6.`)}var i3=f(h(),1);function da(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 jo(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}var o3=f(h(),1);function mb(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}var s3=f(h(),1);function gb(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}var a3=f(h(),1);function Sh(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 _h(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}var c3=f(h(),1);function wb(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 Ah(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}var d3=f(h(),1);var u3=f(h(),1);function Th(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 Wo(t,e,r){let n=t.length;r==null&&(r=0),e===void 0&&(e=new Uint8Array(Th(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 a=o+1;if(a===n||s>=56320)e[i++]=239,e[i++]=191,e[i++]=189;else{let u=t.charCodeAt(a);(u&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(o=a,s=65536|(s&1023)<<10|u&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 Wo.bytes=i-r,e}Wo.bytes=0;function zo(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 a=55296|s>>10&1023;n+=String.fromCharCode(a),s=56320|s&1023}else s=(o&15)<<12|(t[i++]&63)<<6|t[i++]&63;n+=String.fromCharCode(s)}return zo.bytes=r-e,n}zo.bytes=0;var Wn=t=>t instanceof Uint8Array;function gn(t){return typeof t=="string"?Th(t):t.byteLength}function _u(t){return t instanceof Uint8Array?t:Array.isArray(t)?new Uint8Array(t):Wo(t)}function Au(t,e,r){if(typeof e!="string")throw new Error("unknown input type");return Wo(e,t,r),Wo.bytes}var la={},bb=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,a=`${e}${i}`;bb[s]=a,la[a]=s,la[`${r}${i}`]=s,la[`${e}${o}`]=s,la[`${r}${o}`]=s}}function xb(t,e,r){let n="";for(let i=e;i<r;){let o=t[i++];n+=bb[o]}return n}function Ih(t){return t.length>>>1}function Eb(t,e,r,n){let i=0;for(;r<n;){let o=e.substr(i,2),s=la[o];if(s===void 0)return;t[r++]=s,i+=2}return t}var CD=Math.pow(2,24),UD=Math.pow(2,16),PD=Math.pow(2,8),Lr=(t,e)=>t[e]*CD+t[e+1]*UD+t[e+2]*PD+t[e+3],ce=(t,e)=>t[e]<<8|t[e+1],Mr=(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),G=(t,e,r)=>(t[r]=e>>8,t[r+1]=e&255,r+2);function Rt(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:KD(t,e,r,n,i)}function KD(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 MD=0,vb=32768,Bh=32768,ND=~Bh,_b=32768,$D=~_b;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 F=_e({encode(t,e,r){e||(e=new Uint8Array(F.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 a=Au(e,o[s],r+1);e[r]=a,r+=a+1}}return e[r++]=0,F.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 a=t[e++];if(o+=s?0:1,a===0)break;if(a&192)if((a&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let u=ce(t,e-1)-49152;if(u>=n)throw new Error("Cannot decode name (bad pointer)");e=u,n=u,o+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+a>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=a+1,i>254)throw new Error("Cannot decode name (name too long)");r.push(zo(t,e,e+a)),e+=a,o+=s?0:a}}return F.decode.bytes=o,r.length===0?".":r.join(".")},encodingLength(t){return t==="."||t===".."?1:gn(t.replace(/^\.|\.$/gm,""))+2}}),Ze=_e({encode(t,e,r){e||(e=new Uint8Array(Ze.encodingLength(t))),r||(r=0);let n=Au(e,t,r+1);return e[r]=n,Ze.encode.bytes=n+1,e},decode(t,e){e||(e=0);let r=t[e],n=zo(t,e+1,e+1+r);return Ze.decode.bytes=r+1,n},encodingLength(t){return gn(t)+1}}),Go=_e({bytes:12,encode(t,e,r){e||(e=new Uint8Array(Go.encodingLength(t))),r||(r=0);let n=(t.flags||0)&32767,i=t.type==="response"?vb:MD;return G(e,t.id||0,r),G(e,n|i,r+2),G(e,t.questions.length,r+4),G(e,t.answers.length,r+6),G(e,t.authorities.length,r+8),G(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=ce(t,e+2);return{id:ce(t,e),type:r&vb?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:gb(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:mb(r&15),questions:new Array(ce(t,e+4)),answers:new Array(ce(t,e+6)),authorities:new Array(ce(t,e+8)),additionals:new Array(ce(t,e+10))}},encodingLength(){return 12}}),Iu=_e({encode(t,e,r){e||(e=new Uint8Array(Iu.encodingLength(t))),r||(r=0);let n=t.length;return G(e,n,r),Rt(t,e,r+2,0,n),Iu.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=ce(t,e),n=t.slice(e+2,e+2+r);return Iu.decode.bytes=r+2,n},encodingLength(t){return t.length+2}}),Du=_e({encode(t,e,r){return e||(e=new Uint8Array(Du.encodingLength(t))),r||(r=0),F.encode(t,e,r+2),G(e,F.encode.bytes,r),Du.encode.bytes=F.encode.bytes+2,e},decode(t,e){e||(e=0);let r=ce(t,e),n=F.decode(t,e+2);return Du.decode.bytes=r+2,n},encodingLength(t){return F.encodingLength(t)+2}}),Bu=_e({encode(t,e,r){e||(e=new Uint8Array(Bu.encodingLength(t))),r||(r=0);let n=r;return r+=2,F.encode(t.mname,e,r),r+=F.encode.bytes,F.encode(t.rname,e,r),r+=F.encode.bytes,Mr(e,t.serial||0,r),r+=4,Mr(e,t.refresh||0,r),r+=4,Mr(e,t.retry||0,r),r+=4,Mr(e,t.expire||0,r),r+=4,Mr(e,t.minimum||0,r),r+=4,G(e,r-n-2,n),Bu.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=F.decode(t,e),e+=F.decode.bytes,n.rname=F.decode(t,e),e+=F.decode.bytes,n.serial=Lr(t,e),e+=4,n.refresh=Lr(t,e),e+=4,n.retry=Lr(t,e),e+=4,n.expire=Lr(t,e),e+=4,n.minimum=Lr(t,e),e+=4,Bu.decode.bytes=e-r,n},encodingLength(t){return 22+F.encodingLength(t.mname)+F.encodingLength(t.rname)}}),Ru=_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]=_u(t[i])),!Wn(t[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Ru.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(i){e[r++]=i.length,Rt(i,e,r,0,i.length),r+=i.length}),G(e,r-n-2,n),Ru.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=ce(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 Ru.decode.bytes=e-r,i},encodingLength(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=gn(r)+1:e+=r.length+1}),e}}),Ou=_e({encode(t,e,r){e||(e=new Uint8Array(Ou.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=_u(t)),t||(t=new Uint8Array(0));let n=r;r+=2;let i=t.length;return Rt(t,e,r,0,i),r+=i,G(e,r-n-2,n),Ou.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=ce(t,e);e+=2;let i=t.slice(e,e+n);return e+=n,Ou.decode.bytes=e-r,i},encodingLength(t){return t?(Wn(t)?t.length:gn(t))+2:2}}),ku=_e({encode(t,e,r){e||(e=new Uint8Array(ku.encodingLength(t))),r||(r=0);let n=r;return r+=2,Ze.encode(t.cpu,e,r),r+=Ze.encode.bytes,Ze.encode(t.os,e,r),r+=Ze.encode.bytes,G(e,r-n-2,n),ku.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=Ze.decode(t,e),e+=Ze.decode.bytes,n.os=Ze.decode(t,e),e+=Ze.decode.bytes,ku.decode.bytes=e-r,n},encodingLength(t){return Ze.encodingLength(t.cpu)+Ze.encodingLength(t.os)+2}}),Xo=_e({encode(t,e,r){return e||(e=new Uint8Array(Xo.encodingLength(t))),r||(r=0),F.encode(t,e,r+2),G(e,F.encode.bytes,r),Xo.encode.bytes=F.encode.bytes+2,e},decode(t,e){e||(e=0);let r=F.decode(t,e+2);return Xo.decode.bytes=F.decode.bytes+2,r},encodingLength(t){return F.encodingLength(t)+2}}),Cu=_e({encode(t,e,r){e||(e=new Uint8Array(Cu.encodingLength(t))),r||(r=0),G(e,t.priority||0,r+2),G(e,t.weight||0,r+4),G(e,t.port||0,r+6),F.encode(t.target,e,r+8);let n=F.encode.bytes+6;return G(e,n,r),Cu.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=ce(t,e),n={};return n.priority=ce(t,e+2),n.weight=ce(t,e+4),n.port=ce(t,e+6),n.target=F.decode(t,e+8),Cu.decode.bytes=r+2,n},encodingLength(t){return 8+F.encodingLength(t.target)}}),zn=_e({encode(t,e,r){let n=zn.encodingLength(t);return e||(e=new Uint8Array(zn.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=zn.ISSUER_CRITICAL),G(e,n-2,r),r+=2,e[r]=t.flags||0,r+=1,Ze.encode(t.tag,e,r),r+=Ze.encode.bytes,Au(e,t.value,r),r+=gn(t.value),zn.encode.bytes=n,e},decode(t,e){e||(e=0);let r=ce(t,e);e+=2;let n=e,i={};return i.flags=t[e],e+=1,i.tag=Ze.decode(t,e),e+=Ze.decode.bytes,i.value=zo(t,e,n+r),i.issuerCritical=!!(i.flags&zn.ISSUER_CRITICAL),zn.decode.bytes=r+2,i},encodingLength(t){return Ze.encodingLength(t.tag)+Ze.encodingLength(t.value)+2}});zn.ISSUER_CRITICAL=128;var Uu=_e({encode(t,e,r){e||(e=new Uint8Array(Uu.encodingLength(t))),r||(r=0);let n=r;return r+=2,G(e,t.preference||0,r),r+=2,F.encode(t.exchange,e,r),r+=F.encode.bytes,G(e,r-n-2,n),Uu.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=ce(t,e),e+=2,n.exchange=F.decode(t,e),e+=F.decode.bytes,Uu.decode.bytes=e-r,n},encodingLength(t){return 4+F.encodingLength(t.exchange)}}),Ab=_e({encode(t,e,r){return e||(e=new Uint8Array(Ab.encodingLength(t))),r||(r=0),G(e,4,r),r+=2,yr.encode(t,e,r),e},decode(t,e){return e||(e=0),e+=2,yr.decode(t,e)},bytes:6}),Pu=_e({encode(t,e,r){return e||(e=new Uint8Array(Pu.encodingLength(t))),r||(r=0),G(e,16,r),r+=2,mn.encode(t,e,r),Pu.encode.bytes=18,e},decode(t,e){e||(e=0),e+=2;let r=mn.decode(t,e);return Pu.decode.bytes=18,r},bytes:18}),Sb=t=>new Uint8Array(t),wn=_e({encode(t,e,r){e||(e=new Uint8Array(wn.encodingLength(t))),r||(r=0);let n=r,i=Ah(t.code);if(G(e,i,r),r+=2,t.data)G(e,t.data.length,r),r+=2,Rt(t.data,e,r),r+=t.data.length;else switch(i){case 8:{let o=t.sourcePrefixLength||0,s=t.family||hb(t.ip,Sb),a=pb(t.ip,Sb),u=Math.ceil(o/8);G(e,u+4,r),r+=2,G(e,s,r),r+=2,e[r++]=o,e[r++]=t.scopePrefixLength||0,Rt(a,e,r,0,u),r+=u}break;case 11:t.timeout?(G(e,2,r),r+=2,G(e,t.timeout,r),r+=2):(G(e,0,r),r+=2);break;case 12:{let o=t.length||0;G(e,o,r),r+=2,e.fill(0,r,r+o),r+=o}break;case 14:{let o=t.tags.length*2;G(e,o,r),r+=2;for(let s of t.tags)G(e,s,r),r+=2}break;default:throw new Error(`Unknown roption code: ${t.code}`)}return wn.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={};r.code=ce(t,e),r.type=wb(r.code),e+=2;let n=ce(t,e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=ce(t,e),e+=2,r.sourcePrefixLength=t[e++],r.scopePrefixLength=t[e++];{let i=new Uint8Array(r.family===1?4:16);Rt(t,i,0,e,e+n-4),r.ip=yb(i)}break;case 11:n>0&&(r.timeout=ce(t,e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(ce(t,e)),e+=2}return wn.decode.bytes=n+4,r},encodingLength(t){if(t.data)return t.data.length+4;switch(Ah(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}`)}}),Gn=_e({encode(t,e,r){e||(e=new Uint8Array(Gn.encodingLength(t))),r||(r=0);let n=r,i=Yo(t,wn);return G(e,i,r),r=ga(t,wn,e,r+2),Gn.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=[],i=ce(t,e);e+=2;let o=0;for(;i>0;)n[o++]=wn.decode(t,e),e+=wn.decode.bytes,i-=wn.decode.bytes;return Gn.decode.bytes=e-r,n},encodingLength(t){return 2+Yo(t||[],wn)}}),Nr=_e({encode(t,e,r){e||(e=new Uint8Array(Nr.encodingLength(t))),r||(r=0);let n=r,i=t.key;if(!Wn(i))throw new Error("Key must be a Buffer");return r+=2,G(e,t.flags,r),r+=2,e[r]=Nr.PROTOCOL_DNSSEC,r+=1,e[r]=t.algorithm,r+=1,Rt(i,e,r,0,i.length),r+=i.length,Nr.encode.bytes=r-n,G(e,Nr.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ce(t,e);if(e+=2,n.flags=ce(t,e),e+=2,t[e]!==Nr.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,Nr.decode.bytes=e-r,n},encodingLength(t){return 6+gn(t.key)}});Nr.PROTOCOL_DNSSEC=3;Nr.ZONE_KEY=128;Nr.SECURE_ENTRYPOINT=32768;var fa=_e({encode(t,e,r){e||(e=new Uint8Array(fa.encodingLength(t))),r||(r=0);let n=r,i=t.signature;if(!Wn(i))throw new Error("Signature must be a Buffer");return r+=2,G(e,jo(t.typeCovered),r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.labels,r+=1,Mr(e,t.originalTTL,r),r+=4,Mr(e,t.expiration,r),r+=4,Mr(e,t.inception,r),r+=4,G(e,t.keyTag,r),r+=2,F.encode(t.signersName,e,r),r+=F.encode.bytes,Rt(i,e,r,0,i.length),r+=i.length,fa.encode.bytes=r-n,G(e,fa.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ce(t,e);return e+=2,n.typeCovered=da(ce(t,e)),e+=2,n.algorithm=t[e],e+=1,n.labels=t[e],e+=1,n.originalTTL=Lr(t,e),e+=4,n.expiration=Lr(t,e),e+=4,n.inception=Lr(t,e),e+=4,n.keyTag=ce(t,e),e+=2,n.signersName=F.decode(t,e),e+=F.decode.bytes,n.signature=t.slice(e,r+i+2),e+=n.signature.length,fa.decode.bytes=e-r,n},encodingLength(t){return 20+F.encodingLength(t.signersName)+gn(t.signature)}}),ha=_e({encode(t,e,r){e||(e=new Uint8Array(ha.encodingLength(t))),r||(r=0);let n=r;return r+=2,F.encode(t.mbox||".",e,r),r+=F.encode.bytes,F.encode(t.txt||".",e,r),r+=F.encode.bytes,ha.encode.bytes=r-n,G(e,ha.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=F.decode(t,e)||".",e+=F.decode.bytes,n.txt=F.decode(t,e)||".",e+=F.decode.bytes,ha.decode.bytes=e-r,n},encodingLength(t){return 2+F.encodingLength(t.mbox||".")+F.encodingLength(t.txt||".")}}),$t=_e({encode(t,e,r){e||(e=new Uint8Array($t.encodingLength(t))),r||(r=0);let n=r,i=[];for(let o=0;o<t.length;o++){let s=jo(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=_u(i[o]);e[r]=o,r+=1,e[r]=s.length,r+=1,Rt(s,e,r,0,s.length),r+=s.length}return $t.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 a=0;a<s;a++){let u=t[e+a];for(let d=0;d<8;d++)if(u&1<<7-d){let c=da(o<<8|a<<3|d);i.push(c)}}e+=s}return $t.decode.bytes=e-n,i},encodingLength(t){let e=[];for(let n=0;n<t.length;n++){let i=jo(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}}),pa=_e({encode(t,e,r){e||(e=new Uint8Array(pa.encodingLength(t))),r||(r=0);let n=r;return r+=2,F.encode(t.nextDomain,e,r),r+=F.encode.bytes,$t.encode(t.rrtypes,e,r),r+=$t.encode.bytes,pa.encode.bytes=r-n,G(e,pa.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ce(t,e);return e+=2,n.nextDomain=F.decode(t,e),e+=F.decode.bytes,n.rrtypes=$t.decode(t,e,i-(e-r)),e+=$t.decode.bytes,pa.decode.bytes=e-r,n},encodingLength(t){return 2+F.encodingLength(t.nextDomain)+$t.encodingLength(t.rrtypes)}}),ya=_e({encode(t,e,r){e||(e=new Uint8Array(ya.encodingLength(t))),r||(r=0);let n=r,i=t.salt;if(!Wn(i))throw new Error("salt must be a Buffer");let o=t.nextDomain;if(!Wn(o))throw new Error("nextDomain must be a Buffer");return r+=2,e[r]=t.algorithm,r+=1,e[r]=t.flags,r+=1,G(e,t.iterations,r),r+=2,e[r]=i.length,r+=1,Rt(i,e,r,0,i.length),r+=i.length,e[r]=o.length,r+=1,Rt(o,e,r,0,o.length),r+=o.length,$t.encode(t.rrtypes,e,r),r+=$t.encode.bytes,ya.encode.bytes=r-n,G(e,ya.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ce(t,e);e+=2,n.algorithm=t[e],e+=1,n.flags=t[e],e+=1,n.iterations=ce(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=$t.decode(t,e,i-(e-r)),e+=$t.decode.bytes,ya.decode.bytes=e-r,n},encodingLength(t){return 8+t.salt.length+t.nextDomain.length+$t.encodingLength(t.rrtypes)}}),ma=_e({encode(t,e,r){e||(e=new Uint8Array(ma.encodingLength(t))),r||(r=0);let n=r,i=t.digest;if(!Wn(i))throw new Error("Digest must be a Buffer");return r+=2,G(e,t.keyTag,r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.digestType,r+=1,Rt(i,e,r,0,i.length),r+=i.length,ma.encode.bytes=r-n,G(e,ma.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=ce(t,e);return e+=2,n.keyTag=ce(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,ma.decode.bytes=e-r,n},encodingLength(t){return 6+gn(t.digest)}}),Jo=_e({encode(t,e,r){e||(e=new Uint8Array(Jo.encodingLength(t))),r||(r=0);let n=r;r+=2,e[r]=t.algorithm,r+=1,e[r]=t.hash,r+=1;let i=Ih(t.fingerprint),o=Rh(t.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${t.fingerprint}" for hashType=${t.hash}: ${i} != ${o}`);return Eb(e,t.fingerprint,r,r+=i),Jo.encode.bytes=r-n,G(e,Jo.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=Rh(n.hash);return n.fingerprint=xb(t,e,e+i),e+=i,Jo.decode.bytes=e-r,n},encodingLength(t){return 4+Ih(t.fingerprint)}});function Rh(t){if(t===1)return 20;if(t===2)return 32;throw new Error(`Invalid hashType=${t}, supported=1,2`)}Jo.getFingerprintLengthForHashType=Rh;function Dh(t){switch(t.toUpperCase()){case"A":return Ab;case"PTR":return Xo;case"CNAME":return Xo;case"DNAME":return Xo;case"TXT":return Ru;case"NULL":return Ou;case"AAAA":return Pu;case"SRV":return Cu;case"HINFO":return ku;case"CAA":return zn;case"NS":return Du;case"SOA":return Bu;case"MX":return Uu;case"OPT":return Gn;case"DNSKEY":return Nr;case"RRSIG":return fa;case"RP":return ha;case"NSEC":return pa;case"NSEC3":return ya;case"SSHFP":return Jo;case"DS":return ma}return Iu}var nr=_e({encode(t,e,r){e||(e=new Uint8Array(nr.encodingLength(t))),r||(r=0);let n=r;if(F.encode(t.name,e,r),r+=F.encode.bytes,G(e,jo(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");G(e,t.udpPayloadSize||4096,r+2),e[r+4]=t.extendedRcode||0,e[r+5]=t.ednsVersion||0,G(e,t.flags||0,r+6),r+=8,Gn.encode(t.options||[],e,r),r+=Gn.encode.bytes}else{let i=_h(t.class===void 0?"IN":t.class);t.flush&&(i|=Bh),G(e,i,r+2),Mr(e,t.ttl||0,r+4),r+=8;let o=Dh(t.type);o.encode(t.data,e,r),r+=o.encode.bytes}return nr.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={},n=e;if(r.name=F.decode(t,e),e+=F.decode.bytes,r.type=da(ce(t,e)),r.type==="OPT")r.udpPayloadSize=ce(t,e+2),r.extendedRcode=t[e+4],r.ednsVersion=t[e+5],r.flags=ce(t,e+6),r.flag_do=(r.flags>>15&1)===1,r.options=Gn.decode(t,e+8),e+=8+Gn.decode.bytes;else{let i=ce(t,e+2);r.ttl=Lr(t,e+4),r.class=Sh(i&ND),r.flush=!!(i&Bh);let o=Dh(r.type);r.data=o.decode(t,e+8),e+=8+o.decode.bytes}return nr.decode.bytes=e-n,r},encodingLength(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return F.encodingLength(t.name)+8+Dh(t.type).encodingLength(e)}}),Zo=_e({encode(t,e,r){e||(e=new Uint8Array(Zo.encodingLength(t))),r||(r=0);let n=r;return F.encode(t.name,e,r),r+=F.encode.bytes,G(e,jo(t.type),r),r+=2,G(e,_h(t.class===void 0?"IN":t.class),r),r+=2,Zo.encode.bytes=r-n,t},decode(t,e){e||(e=0);let r=e,n={};return n.name=F.decode(t,e),e+=F.decode.bytes,n.type=da(ce(t,e)),e+=2,n.class=Sh(ce(t,e)),e+=2,!!(n.class&_b)&&(n.class&=$D),Zo.decode.bytes=e-r,n},encodingLength(t){return F.encodingLength(t.name)+4}});var Tb=1024;var lt={encode:function(t,e,r){let n=!e;n&&(e=new Uint8Array(qD(t))),r||(r=0);let i=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Go.encode(t,e,r),r+=Go.encode.bytes,r=ga(t.questions,Zo,e,r),r=ga(t.answers,nr,e,r),r=ga(t.authorities,nr,e,r),r=ga(t.additionals,nr,e,r),lt.encode.bytes=r-i,n&&wa.bytes!==e.length?e.slice(0,wa.bytes):e},decode:function(t,e){e||(e=0);let r=e,n=Go.decode(t,e);return e+=Go.decode.bytes,e=Tu(n.questions,Zo,t,e),e=Tu(n.answers,nr,t,e),e=Tu(n.authorities,nr,t,e),e=Tu(n.additionals,nr,t,e),lt.decode.bytes=e-r,n},encodingLength:function(t){return Go.encodingLength(t)+Yo(t.questions||[],Zo)+Yo(t.answers||[],nr)+Yo(t.authorities||[],nr)+Yo(t.additionals||[],nr)}};lt.encode.bytes=0;lt.decode.bytes=0;function Ku(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 Lu={encode:function(t,e,r){return e=lt.encode(Ku(t,"query"),e,r),Lu.encode.bytes=lt.encode.bytes,e},decode:function(t,e){let r=lt.decode(t,e);return Lu.decode.bytes=lt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return lt.encodingLength(Ku(t,"query"))}};Lu.encode.bytes=0;Lu.decode.bytes=0;var Mu={encode:function(t,e,r){return e=lt.encode(Ku(t,"response"),e,r),Mu.encode.bytes=lt.encode.bytes,e},decode:function(t,e){let r=lt.decode(t,e);return Mu.decode.bytes=lt.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return lt.encodingLength(Ku(t,"response"))}};Mu.encode.bytes=0;Mu.decode.bytes=0;var wa=lt.encode,Nu=lt.decode,qD=lt.encodingLength;function Ib(t){let e=wa(t),r=new Uint8Array(2+e.byteLength);return G(r,e.byteLength),Rt(e,r,2,0,e.length),Ib.bytes=r.byteLength,r}Ib.bytes=0;function Db(t){let e=ce(t,0);if(t.byteLength<e+2)return null;let r=Nu(t.slice(2));return Db.bytes=Nu.bytes,r}Db.bytes=0;function Yo(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function ga(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 Tu(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e.decode(r,n),n+=e.decode.bytes;return n}var y3=f(h(),1),qt=class{static async getSigningMethod(e){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")}static async resolve(e,r){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")}};var Bb="https://did-dht-production.up.railway.app",FD=0,Jn=7200,$u=";",Et=",",Oh=(u=>(u[u.Discoverable=0]="Discoverable",u[u.Organization=1]="Organization",u[u.Government=2]="Government",u[u.Corporation=3]="Corporation",u[u.LocalBusiness=4]="LocalBusiness",u[u.SoftwarePackage=5]="SoftwarePackage",u[u.WebApp=6]="WebApp",u[u.FinancialInstitution=7]="FinancialInstitution",u))(Oh||{}),qu=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(qu||{}),kh=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(kh||{}),Ob={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},Rb={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"},ba=class ba extends qt{static async create({keyManager:e=new gt,options:r={}}={}){if(r.verificationMethods?.some(c=>!(c.algorithm in Ob)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(c=>"id"in c).map(c=>c.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(c=>!c.id||!c.type||!c.serviceEndpoint))throw new Error("One or more services are missing required properties");let i=await e.generateKey({algorithm:"Ed25519"}),o=await e.getPublicKey({keyUri:i}),s=await Qe.identityKeyToIdentifier({identityKey:o}),a={id:s,...r.alsoKnownAs&&{alsoKnownAs:r.alsoKnownAs},...r.controllers&&{controller:r.controllers}},u=[...r.verificationMethods??[]];u?.some(c=>c.id?.split("#").pop()==="0")||u.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let c of u){let l=c.id&&c.id.split("#").pop()==="0"?i:await e.generateKey({algorithm:c.algorithm}),g=await e.getPublicKey({keyUri:l}),w=c.id??g.kid??await oe({jwk:g});w=`${s}#${Bt(w)}`,a.verificationMethod??=[],a.verificationMethod.push({id:w,type:"JsonWebKey",controller:c.controller??s,publicKeyJwk:g});for(let m of c.purposes??[])a[m]||(a[m]=[]),a[m].push(w)}r.services?.forEach(c=>{a.service??=[],c.id=`${s}#${c.id.split("#").pop()}`,a.service.push(c)});let d=new xt({uri:s,document:a,metadata:{published:!1,...r.types&&{types:r.types}},keyManager:e});if(r.publish??!0){let c=await ba.publish({did:d,gatewayUri:r.gatewayUri});d.metadata=c.didDocumentMetadata}return d}static async import({portableDid:e,keyManager:r=new gt}){if(Ce.parse(e.uri)?.method!==ba.methodName)throw new q("methodNotSupported","Method not supported");let i=await xt.import({portableDid:e,keyManager:r});if(!i.document.verificationMethod?.some(o=>o.id?.split("#").pop()==="0"))throw new q("invalidDidDocument","DID document must contain an Identity Key");return i}static async getSigningMethod({didDocument:e,methodId:r="#0"}){let n=Ce.parse(e.id);if(n&&n.method!==this.methodName)throw new q("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>Bt(o.id)===(Bt(r)??Bt(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new q("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:r=Bb}){return await Ea.put({did:e,gatewayUri:r})}static async resolve(e,r={}){let n=r?.gatewayUri??Bb;try{await Qe.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await Ea.get({didUri:e,gatewayUri:n});return{...ke,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof q))throw new Error(i);return{...ke,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};ba.methodName="dht";var xa=ba,Ea=class t{static async get({didUri:e,gatewayUri:r}){let n=Qe.identifierToIdentityKeyBytes({didUri:e}),i=await t.pkarrGet({gatewayUri:r,publicKeyBytes:n}),o=await Qe.parseBep44GetMessage({bep44Message:i}),s=await t.fromDnsPacket({didUri:e,dnsPacket:o});return s.didDocumentMetadata.versionId=i.seq.toString(),s}static async put({did:e,gatewayUri:r}){let n=await t.toDnsPacket({didDocument:e.document,didMetadata:e.metadata,authoritativeGatewayUris:[r]}),i=await Qe.createBep44PutMessage({dnsPacket:n,publicKeyBytes:Qe.identifierToIdentityKeyBytes({didUri:e.uri}),signer:await e.getSigner({methodId:"0"})}),o=await t.pkarrPut({gatewayUri:r,bep44Message:i});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:o,versionId:i.seq.toString()},didRegistrationMetadata:{}}}static async pkarrGet({gatewayUri:e,publicKeyBytes:r}){let n=M.uint8Array(r).toBase32Z(),i=new URL(n,e).href,o;try{if(o=await fetch(i,{method:"GET"}),!o.ok)throw new q("notFound",`Pkarr record not found for: ${n}`)}catch(u){throw u instanceof q?u:new q("internalError",`Failed to fetch Pkarr record: ${u.message}`)}let s=await o.arrayBuffer();if(!s)throw new q("notFound",`Pkarr record not found for: ${n}`);if(s.byteLength<72)throw new q("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${s.byteLength}`);if(s.byteLength>1072)throw new q("invalidDidDocumentLength",`Pkarr response exceeds 1000 byte limit: ${s.byteLength}`);return{k:r,seq:Number(new DataView(s).getBigUint64(64)),sig:new Uint8Array(s,0,64),v:new Uint8Array(s,72)}}static async pkarrPut({gatewayUri:e,bep44Message:r}){let n=M.uint8Array(r.k).toBase32Z(),i=new URL(n,e).href,o=new Uint8Array(r.v.length+72);o.set(r.sig,0),new DataView(o.buffer).setBigUint64(r.sig.length,BigInt(r.seq)),o.set(r.v,r.sig.length+8);let s;try{s=await fetch(i,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:o})}catch(a){throw new q("internalError",`Failed to put Pkarr record for identifier ${n}: ${a.message}`)}return s.ok}static async fromDnsPacket({didUri:e,dnsPacket:r}){let n={id:e},i={published:!0},o=new Map;for(let s of r?.answers??[]){if(s.type!=="TXT")continue;let a=s.name.split(".")[0].substring(1);switch(!0){case a.startsWith("aka"):{let u=Qe.parseTxtDataToString(s.data);n.alsoKnownAs=u.split(Et);break}case a.startsWith("cnt"):{let u=Qe.parseTxtDataToString(s.data);n.controller=u.includes(Et)?u.split(Et):u;break}case a.startsWith("k"):{let{id:u,t:d,k:c,c:l,a:g}=Qe.parseTxtDataToObject(s.data),w=M.base64Url(c).toUint8Array(),m=qu[Number(d)],y=await Qe.keyConverter(m).bytesToPublicKey({publicKeyBytes:w});y.alg=g||Rb[Number(d)];let E=a==="k0"?"0":u!==void 0?u:await oe({jwk:y});n.verificationMethod??=[];let v=`${e}#${E}`;n.verificationMethod.push({id:v,type:"JsonWebKey",controller:l??e,publicKeyJwk:y}),o.set(a,v);break}case a.startsWith("s"):{let{id:u,t:d,se:c,...l}=Qe.parseTxtDataToObject(s.data),g=c.includes(Et)?c.split(Et):[c],w=Object.fromEntries(Object.entries(l).map(([m,y])=>[m,y.includes(Et)?y.split(Et):y]));n.service??=[],n.service.push({...w,id:`${e}#${u}`,type:d,serviceEndpoint:g});break}case a.startsWith("typ"):{let{id:u}=Qe.parseTxtDataToObject(s.data);i.types=u.split(Et).map(d=>Number(d));break}case a.startsWith("did"):{let u=m=>m.split(Et).map(y=>o.get(y)).filter(y=>typeof y=="string"),{auth:d,asm:c,del:l,inv:g,agm:w}=Qe.parseTxtDataToObject(s.data);d&&(n.authentication=u(d)),c&&(n.assertionMethod=u(c)),l&&(n.capabilityDelegation=u(l)),g&&(n.capabilityInvocation=u(g)),w&&(n.keyAgreement=u(w));break}}}return{didDocument:n,didDocumentMetadata:i,didResolutionMetadata:{}}}static async toDnsPacket({didDocument:e,didMetadata:r,authoritativeGatewayUris:n,previousDidProof:i}){let o=[],s=[],a=new Map,u=[],d=[];if(i!==void 0){let{signature:g,previousDid:w}=i;await Qe.validatePreviousDidProof({newDid:e.id,previousDidProof:i}),o.push({type:"TXT",name:"_prv._did.",ttl:Jn,data:`id=${w};s=${g}`})}if(e.alsoKnownAs&&o.push({type:"TXT",name:"_aka._did.",ttl:Jn,data:e.alsoKnownAs.join(Et)}),e.controller){let g=Array.isArray(e.controller)?e.controller.join(Et):e.controller;o.push({type:"TXT",name:"_cnt._did.",ttl:Jn,data:g})}for(let[g,w]of e.verificationMethod?.entries()??[]){let m=`k${g}`;d.push(m);let y=w.id.split("#").pop();a.set(y,m);let E=w.publicKeyJwk;if(!(E?.crv&&E.crv in Ob))throw new q("invalidPublicKeyType",`Verification method '${w.id}' contains an unsupported key type: ${E?.crv??"undefined"}`);let v=qu[E.crv],D=await Qe.keyConverter(E.crv).publicKeyToBytes({publicKey:E}),S=M.uint8Array(D).toBase64Url(),B=[`t=${v}`,`k=${S}`];y!=="0"&&await oe({jwk:E})!==y&&B.unshift(`id=${y}`),E.alg!==Rb[v]&&B.push(`a=${E.alg}`),w.controller!==e.id&&B.push(`c=${w.controller}`),o.push({type:"TXT",name:`_${m}._did.`,ttl:Jn,data:B.join($u)})}e.service?.forEach((g,w)=>{let m=`s${w}`;u.push(m);let{id:y,type:E,serviceEndpoint:v,...D}=g;y=Bt(y),v=Array.isArray(v)?v.join(","):v;let B=Object.entries({id:y,t:E,se:v,...D}).map(([O,C])=>`${O}=${C}`).join($u),I=Qe.chunkDataIfNeeded(B);o.push({type:"TXT",name:`_${m}._did.`,ttl:Jn,data:I})});let c=[`v=${FD}`];if(d.length&&c.push(`vm=${d.join(Et)}`),Object.keys(oi).forEach(g=>{let w=e[g]?.map(m=>a.get(m.split("#").pop()));if(w){let m=kh[g];c.push(`${m}=${w.join(Et)}`)}}),u.length&&c.push(`svc=${u.join(Et)}`),r.types?.length){let w=r.types.map(m=>typeof m=="string"?Oh[m]:m);o.push({type:"TXT",name:"_typ._did.",ttl:Jn,data:`id=${w.join(Et)}`})}o.push({type:"TXT",name:"_did."+t.getUniqueDidSuffix(e.id)+".",ttl:Jn,data:c.join($u)});for(let g of n||[])s.push({type:"NS",name:"_did."+t.getUniqueDidSuffix(e.id)+".",ttl:Jn,data:g+"."});return{id:0,type:"response",flags:Tb,answers:[...o,...s]}}static getUniqueDidSuffix(e){return e.split(":")[2]}},Qe=class t{static async createBep44PutMessage({dnsPacket:e,publicKeyBytes:r,signer:n}){let i=Math.ceil(Date.now()/1e3),o=wa(e),s=vh.encode({seq:i,v:o}).subarray(1,-1);if(s.length>1e3)throw new q("invalidDidDocumentLength",`DNS packet exceeds the 1000 byte maximum size: ${s.length} bytes`);let a=await n.sign({data:s});return{k:r,seq:i,sig:a,v:o}}static async identifierToIdentityKey({didUri:e}){let r=t.identifierToIdentityKeyBytes({didUri:e});return await Xe.bytesToPublicKey({publicKeyBytes:r})}static identifierToIdentityKeyBytes({didUri:e}){let r=Ce.parse(e);if(!r)throw new q("invalidDid",`Invalid DID URI: ${e}`);if(r.method!==xa.methodName)throw new q("methodNotSupported",`Method not supported: ${r.method}`);let n;try{n=M.base32Z(r.id).toUint8Array()}catch{throw new q("invalidPublicKey","Failed to decode method-specific identifier")}if(n.length!==32)throw new q("invalidPublicKeyLength",`Invalid public key length: ${n.length}`);return n}static async identityKeyToIdentifier({identityKey:e}){let r=await Xe.publicKeyToBytes({publicKey:e}),n=M.uint8Array(r).toBase32Z();return`did:${xa.methodName}:${n}`}static keyConverter(e){let n={Ed25519:Xe,"P-256":{publicKeyToBytes:async({publicKey:i})=>{let o=await dt.publicKeyToBytes({publicKey:i});return await dt.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:dt.bytesToPublicKey,privateKeyToBytes:dt.privateKeyToBytes,bytesToPrivateKey:dt.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:i})=>{let o=await nt.publicKeyToBytes({publicKey:i});return await nt.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:nt.bytesToPublicKey,privateKeyToBytes:nt.privateKeyToBytes,bytesToPrivateKey:nt.bytesToPrivateKey},X25519:Vo}[e];if(!n)throw new q("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async parseBep44GetMessage({bep44Message:e}){let r=await Xe.bytesToPublicKey({publicKeyBytes:e.k}),n=vh.encode({seq:e.seq,v:e.v}).subarray(1,-1);if(!await Xe.verify({key:r,signature:e.sig,data:n}))throw new q("invalidSignature","Invalid signature for DHT BEP44 message");return Nu(e.v)}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split($u).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 M.uint8Array(e).toString();if(Array.isArray(e))return e.map(r=>this.parseTxtDataToString(r)).join("");throw new q("internalError","Pkarr returned DNS TXT record with invalid data type")}static async validatePreviousDidProof({newDid:e,previousDidProof:r}){let n=await t.identifierToIdentityKey({didUri:r.previousDid}),i=t.identifierToIdentityKeyBytes({didUri:e}),o=M.base64Url(r.signature).toUint8Array();if(!await Xe.verify({key:n,data:i,signature:o}))throw new q("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}};var ZL=f(h(),1);var FL=f(h(),1);var aL=f(h(),1);var tK=f(h(),1);var R3=f(h(),1),Be={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"};var k3=f(h(),1),ve=class extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};var Y3=f(h(),1);var H3=f(h(),1);var U3=f(h(),1);var L3=f(h(),1),P3=new Uint8Array(0);var Ch=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")};var M3=f(h(),1);var Uh=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")}},Ph=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 kb(this,e)}},Kh=class{constructor(e){this.decoders=e}or(e){return kb(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`)}},kb=(t,e)=>new Kh({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Lh=class{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Uh(e,r,n),this.decoder=new Ph(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},VD=({name:t,prefix:e,encode:r,decode:n})=>new Lh(t,e,r,n);var HD=(t,e,r,n)=>{let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,u=0,d=0;for(let c=0;c<o;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<r|l,a+=r,a>=8&&(a-=8,s[d++]=255&u>>a)}if(a>=r||255&u<<8-a)throw new SyntaxError("Unexpected end of data");return s},jD=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o},va=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>VD({prefix:e,name:t,encode(i){return jD(i,n,r)},decode(i){return HD(i,n,r,t)}});var W3=va({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),z3=va({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sa=va({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),G3=va({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ot=class t{static encode(e){return Sa.baseEncode(e)}static decodeAsBytes(e,r){if(!t.isBase64UrlString(e))throw new ve(Be.EncodedStringIncorrectEncoding,`Given ${r} must be base64url string.`);return Sa.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)}};var eL=f(h(),1),Vb=f(Ub(),1);var dK=f(h(),1);var iK=f(h(),1),Mh;(function(t){t.Public="public",t.Private="private"})(Mh||(Mh={}));var Ft=Mh;var et=class{static validateEs256kOperationKey(e,r){let n=new Set(["kty","crv","x","y"]);r===Ft.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new ve(Be.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new ve(Be.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new ve(Be.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new ve(Be.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new ve(Be.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(r===Ft.Private&&(e.d===void 0||e.d.length!==43))throw new ve(Be.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new ve(Be.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!Ot.isBase64UrlString(e))throw new ve(Be.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 ve(Be.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);r.add(n)}}};var fK=f(h(),1),_a=class{};_a.hashAlgorithmInMultihashCode=18;_a.maxCanonicalizedDeltaSizeInBytes=1e3;var vt=_a;var gK=f(h(),1),Lb=f(Kb(),1);var mr=class t{static canonicalizeAsBytes(e){let r=t.removeAllUndefinedProperties(e),n=Lb.default(r);return Ot.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}};var NK=f(h(),1);var _K=f(h(),1);var EK=f(h(),1);var bK=f(h(),1),WD=$b,Mb=128,zD=127,GD=~zD,JD=Math.pow(2,31);function $b(t,e,r){e=e||[],r=r||0;for(var n=r;t>=JD;)e[r++]=t&255|Mb,t/=128;for(;t&GD;)e[r++]=t&255|Mb,t>>>=7;return e[r]=t|0,$b.bytes=r-n+1,e}var YD=Nh,XD=128,Nb=127;function Nh(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Nh.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Nb)<<i:(s&Nb)*Math.pow(2,i),i+=7}while(s>=XD);return Nh.bytes=o-n,r}var ZD=Math.pow(2,7),QD=Math.pow(2,14),eB=Math.pow(2,21),tB=Math.pow(2,28),rB=Math.pow(2,35),nB=Math.pow(2,42),iB=Math.pow(2,49),oB=Math.pow(2,56),sB=Math.pow(2,63),aB=function(t){return t<ZD?1:t<QD?2:t<eB?3:t<tB?4:t<rB?5:t<nB?6:t<iB?7:t<oB?8:t<sB?9:10},cB={encode:WD,decode:YD,encodingLength:aB},uB=cB,Aa=uB;var $h=(t,e=0)=>[Aa.decode(t,e),Aa.decode.bytes],qh=(t,e,r=0)=>(Aa.encode(t,e,r),e),Fh=t=>Aa.encodingLength(t);var Vh=(t,e)=>{let r=e.byteLength,n=Fh(t),i=n+Fh(r),o=new Uint8Array(i+r);return qh(t,o,0),qh(r,o,n),o.set(e,i),new Vu(t,r,e,o)},qb=t=>{let e=Ch(t),[r,n]=$h(e),[i,o]=$h(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Vu(r,i,s,e)};var Vu=class{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var RK=f(h(),1);var TK=f(h(),1);var jh=({name:t,code:e,encode:r})=>new Hh(t,e,r),Hh=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?Vh(this.code,r):r.then(n=>Vh(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Fb=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Hu=jh({name:"sha2-256",code:18,encode:Fb("SHA-256")}),DK=jh({name:"sha2-512",code:19,encode:Fb("SHA-512")});var Ta=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},it=class t{static hash(e,r){return Ta(this,void 0,void 0,function*(){let n;switch(r){case 18:n=(yield Hu.digest(e)).bytes;break;default:throw new ve(Be.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,r){return Ta(this,void 0,void 0,function*(){let n;switch(r){case 18:n=yield Hu.encode(e);break;default:throw new ve(Be.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,r){return Ta(this,void 0,void 0,function*(){let n=mr.canonicalizeAsBytes(e);return yield t.hashThenEncode(n,r)})}static canonicalizeThenDoubleHashThenEncode(e,r){return Ta(this,void 0,void 0,function*(){let n=mr.canonicalizeAsBytes(e),i=yield t.hashAsNonMultihashBytes(n,r);return yield t.hashThenEncode(i,r)})}static hashThenEncode(e,r){return Ta(this,void 0,void 0,function*(){let n=yield t.hash(e,r);return Ot.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,r){let n,i=Ot.decodeAsBytes(e,r);try{n=qb(i)}catch{throw new ve(Be.MultihashStringNotAMultihash,`Given ${r} string '${e}' is not a multihash after decoding.`)}let o=vt.hashAlgorithmInMultihashCode;if(o!==n.code)throw new ve(Be.MultihashUnsupportedHashAlgorithm,`Given ${r} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};var qK=f(h(),1),Wh;(function(t){t.Create="create",t.Update="update",t.Deactivate="deactivate",t.Recover="recover"})(Wh||(Wh={}));var Ia=Wh;var VK=f(h(),1),zh;(function(t){t.Replace="replace",t.AddPublicKeys="add-public-keys",t.RemovePublicKeys="remove-public-keys",t.AddServices="add-services",t.RemoveServices="remove-services"})(zh||(zh={}));var $i=zh;var ju=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},Yn=class t{static createCreateRequest(e){return ju(this,void 0,void 0,function*(){let r=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;et.validateEs256kOperationKey(r,Ft.Public),et.validateEs256kOperationKey(n,Ft.Public),t.validateDidDocumentKeys(i),t.validateServices(o);let s=vt.hashAlgorithmInMultihashCode,a=[{action:$i.Replace,document:e.document}],u={updateCommitment:yield it.canonicalizeThenDoubleHashThenEncode(n,s),patches:a};t.validateDeltaSize(u);let c={deltaHash:yield it.canonicalizeThenHashThenEncode(u,s),recoveryCommitment:yield it.canonicalizeThenDoubleHashThenEncode(r,s)};return{type:Ia.Create,suffixData:c,delta:u}})}static createDeactivateRequest(e){return ju(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),et.validateEs256kOperationKey(e.recoveryPublicKey,Ft.Public);let r=vt.hashAlgorithmInMultihashCode,n=yield it.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:Ia.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return ju(this,void 0,void 0,function*(){t.validateDidSuffix(e.didSuffix),et.validateEs256kOperationKey(e.recoveryPublicKey,Ft.Public),et.validateEs256kOperationKey(e.nextRecoveryPublicKey,Ft.Public),et.validateEs256kOperationKey(e.nextUpdatePublicKey,Ft.Public),t.validateDidDocumentKeys(e.document.publicKeys),t.validateServices(e.document.services);let r=vt.hashAlgorithmInMultihashCode,n=yield it.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i=[{action:$i.Replace,document:e.document}],o=yield it.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,r),s={patches:i,updateCommitment:o},a=yield it.canonicalizeThenHashThenEncode(s,r),d={recoveryCommitment:yield it.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,r),recoveryKey:e.recoveryPublicKey,deltaHash:a},c=yield e.signer.sign({alg:"ES256K"},d);return{type:Ia.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:c}})}static createUpdateRequest(e){return ju(this,void 0,void 0,function*(){if(t.validateDidSuffix(e.didSuffix),et.validateEs256kOperationKey(e.updatePublicKey,Ft.Public),et.validateEs256kOperationKey(e.nextUpdatePublicKey,Ft.Public),t.validateServices(e.servicesToAdd),t.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let m of e.idsOfServicesToRemove)et.validateId(m);if(e.idsOfPublicKeysToRemove!==void 0)for(let m of e.idsOfPublicKeysToRemove)et.validateId(m);let r=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let m={action:$i.AddServices,services:n};r.push(m)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let m={action:$i.RemoveServices,ids:i};r.push(m)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let m={action:$i.AddPublicKeys,publicKeys:o};r.push(m)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let m={action:$i.RemovePublicKeys,ids:s};r.push(m)}let a=vt.hashAlgorithmInMultihashCode,u=yield it.canonicalizeThenHashThenEncode(e.updatePublicKey,a),d=yield it.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,a),c={patches:r,updateCommitment:d},l=yield it.canonicalizeThenHashThenEncode(c,a),g={updateKey:e.updatePublicKey,deltaHash:l},w=yield e.signer.sign({alg:"ES256K"},g);return{type:Ia.Update,didSuffix:e.didSuffix,revealValue:u,delta:c,signedData:w}})}static validateDidSuffix(e){it.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 ve(Be.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(et.validateId(n.id),r.has(n.id))throw new ve(Be.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);r.add(n.id),et.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 ve(Be.DidDocumentServiceIdDuplicated,"Service id has to be unique");r.add(n.id)}}}static validateService(e){et.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 ve(Be.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new ve(Be.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&Vb.parse(e.serviceEndpoint).error!==void 0)throw new ve(Be.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let r=mr.canonicalizeAsBytes(e);if(r.length>vt.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${r.length} bytes exceeded limit of ${vt.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new ve(Be.DeltaExceedsMaximumSize,n)}}};var Hb=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 a(c){try{d(n.next(c))}catch(l){s(l)}}function u(c){try{d(n.throw(c))}catch(l){s(l)}}function d(c){c.done?o(c.value):i(c.value).then(a,u)}d((n=n.apply(t,e||[])).next())})},Qo=class t{static createLongFormDid(e){return Hb(this,void 0,void 0,function*(){let r=yield Yn.createCreateRequest(e),n=yield t.computeDidUniqueSuffix(r.suffixData),i;vt.network===void 0||vt.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${vt.network}:${n}`;let o={suffixData:r.suffixData,delta:r.delta},s=mr.canonicalizeAsBytes(o),a=Ot.encode(s);return`${i}:${a}`})}static computeDidUniqueSuffix(e){return Hb(this,void 0,void 0,function*(){let r=mr.canonicalizeAsBytes(e),n=yield it.hash(r,vt.hashAlgorithmInMultihashCode);return Ot.encode(n)})}};var gL=f(h(),1);var cL=f(h(),1);var ft=2n**255n-19n,zu=2n**252n+27742317777372353535851937790883648493n,Jh=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Yh=0x6666666666666666666666666666666666666666666666666666666666666658n,Wu={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:ft,n:zu,h:8,Gx:Jh,Gy:Yh},kt=(t="")=>{throw new Error(t)},Yb=t=>typeof t=="string",Xh=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?kt("Uint8Array expected"):t,es=t=>new Uint8Array(t),fB=(t,e)=>Xh(Yb(t)?Qh(t):es(t),e),J=(t,e=ft)=>{let r=t%e;return r>=0n?r:e+r},jb=t=>t instanceof Xn?t:kt("Point expected"),Wb,Xn=class t{constructor(e,r,n,i){this.ex=e,this.ey=r,this.ez=n,this.et=i}static fromAffine(e){return new t(e.x,e.y,1n,J(e.x*e.y))}static fromHex(e,r=!0){let{d:n}=Wu;e=fB(e,32);let i=e.slice();i[31]=e[31]&-129;let o=pB(i);o===0n||(r&&!(0n<o&&o<ft)&&kt("bad y coord 1"),!r&&!(0n<o&&o<2n**256n)&&kt("bad y coord 2"));let s=J(o*o),a=J(s-1n),u=J(n*s+1n),{isValid:d,value:c}=mB(a,u);d||kt("bad y coordinate 3");let l=(c&1n)===1n;return(e[31]&128)!==0!==l&&(c=J(-c)),new t(c,o,1n,J(c*o))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:r,ey:n,ez:i}=this,{ex:o,ey:s,ez:a}=jb(e),u=J(r*a),d=J(o*i),c=J(n*a),l=J(s*i);return u===d&&c===l}is0(){return this.equals(Gu)}negate(){return new t(J(-this.ex),this.ey,this.ez,J(-this.et))}double(){let{ex:e,ey:r,ez:n}=this,{a:i}=Wu,o=J(e*e),s=J(r*r),a=J(2n*J(n*n)),u=J(i*o),d=e+r,c=J(J(d*d)-o-s),l=u+s,g=l-a,w=u-s,m=J(c*g),y=J(l*w),E=J(c*w),v=J(g*l);return new t(m,y,v,E)}add(e){let{ex:r,ey:n,ez:i,et:o}=this,{ex:s,ey:a,ez:u,et:d}=jb(e),{a:c,d:l}=Wu,g=J(r*s),w=J(n*a),m=J(o*l*d),y=J(i*u),E=J((r+n)*(s+a)-g-w),v=J(y-m),D=J(y+m),S=J(w-c*g),B=J(E*v),I=J(D*S),O=J(E*S),C=J(v*D);return new t(B,I,C,O)}mul(e,r=!0){if(e===0n)return r===!0?kt("cannot multiply by 0"):Gu;if(typeof e=="bigint"&&0n<e&&e<zu||kt("invalid scalar, must be < L"),!r&&this.is0()||e===1n)return this;if(this.equals(Ju))return wB(e).p;let n=Gu,i=Ju;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):r&&(i=i.add(o));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(Wu.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(zu/2n,!1).double();return zu%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:r,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=Zb(n);return J(n*i)!==1n&&kt("invalid inverse"),{x:J(e*i),y:J(r*i)}}toRawBytes(){let{x:e,y:r}=this.toAffine(),n=hB(r);return n[31]|=e&1n?128:0,n}toHex(){return Zh(this.toRawBytes())}};Xn.BASE=new Xn(Jh,Yh,1n,J(Jh*Yh));Xn.ZERO=new Xn(0n,1n,1n,0n);var{BASE:Ju,ZERO:Gu}=Xn,Xb=(t,e)=>t.toString(16).padStart(e,"0"),Zh=t=>Array.from(t).map(e=>Xb(e,2)).join(""),Qh=t=>{let e=t.length;(!Yb(t)||e%2)&&kt("hex invalid 1");let r=es(e/2);for(let n=0;n<r.length;n++){let i=n*2,o=t.slice(i,i+2),s=Number.parseInt(o,16);(Number.isNaN(s)||s<0)&&kt("hex invalid 2"),r[n]=s}return r},hB=t=>Qh(Xb(t,32*2)).reverse(),pB=t=>BigInt("0x"+Zh(es(Xh(t)).reverse())),zb=(...t)=>{let e=es(t.reduce((n,i)=>n+Xh(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},Zb=(t,e=ft)=>{(t===0n||e<=0n)&&kt("no inverse n="+t+" mod="+e);let r=J(t,e),n=e,i=0n,o=1n,s=1n,a=0n;for(;r!==0n;){let u=n/r,d=n%r,c=i-s*u,l=o-a*u;n=r,r=d,i=s,o=a,s=c,a=l}return n===1n?J(i,e):kt("no inverse")},$r=(t,e)=>{let r=t;for(;e-- >0n;)r*=r,r%=ft;return r},yB=t=>{let r=t*t%ft*t%ft,n=$r(r,2n)*r%ft,i=$r(n,1n)*t%ft,o=$r(i,5n)*i%ft,s=$r(o,10n)*o%ft,a=$r(s,20n)*s%ft,u=$r(a,40n)*a%ft,d=$r(u,80n)*u%ft,c=$r(d,80n)*u%ft,l=$r(c,10n)*o%ft;return{pow_p_5_8:$r(l,2n)*t%ft,b2:r}},Gb=19681161376707505956807079304988542015446066515923890162744021073123829784752n,mB=(t,e)=>{let r=J(e*e*e),n=J(r*r*e),i=yB(t*n).pow_p_5_8,o=J(t*r*i),s=J(e*o*o),a=o,u=J(o*Gb),d=s===t,c=s===J(-t),l=s===J(-t*Gb);return d&&(o=a),(c||l)&&(o=u),(J(o)&1n)===1n&&(o=J(-o)),{isValid:d||c,value:o}};var Gh;var Jb=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Qb={bytesToHex:Zh,hexToBytes:Qh,concatBytes:zb,mod:J,invert:Zb,randomBytes:t=>{let e=Jb();return e||kt("crypto.getRandomValues must be defined"),e.getRandomValues(es(t))},sha512Async:async(...t)=>{let e=Jb();e||kt("crypto.subtle or etc.sha512Async must be defined");let r=zb(...t);return es(await e.subtle.digest("SHA-512",r.buffer))},sha512Sync:void 0};Object.defineProperties(Qb,{sha512Sync:{configurable:!1,get(){return Gh},set(t){Gh||(Gh=t)}}});var qi=8,gB=()=>{let t=[],e=256/qi+1,r=Ju,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let o=1;o<2**(qi-1);o++)n=n.add(r),t.push(n);r=n.double()}return t},wB=t=>{let e=Wb||(Wb=gB()),r=(c,l)=>{let g=l.negate();return c?g:l},n=Gu,i=Ju,o=1+256/qi,s=2**(qi-1),a=BigInt(2**qi-1),u=2**qi,d=BigInt(qi);for(let c=0;c<o;c++){let l=c*s,g=Number(t&a);t>>=d,g>s&&(g-=u,t+=1n);let w=l,m=l+Math.abs(g)-1,y=c%2!==0,E=g<0;g===0?i=i.add(r(y,e[w])):n=n.add(r(E,e[m]))}return{p:n,f:i}};var uL=f(h(),1);var tp=2n**256n,Vi=tp-0x1000003d1n,rp=tp-0x14551231950b75fc4402da1732fc9bebfn,ax=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,cx=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,ux={p:Vi,n:rp,a:0n,b:7n,Gx:ax,Gy:cx},ts=32,ex=t=>W(W(t*t)*t+ux.b),ot=(t="")=>{throw new Error(t)},Zu=t=>typeof t=="bigint",dx=t=>typeof t=="string",ep=t=>Zu(t)&&0n<t&&t<Vi,lx=t=>Zu(t)&&0n<t&&t<rp,fx=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?ot("Uint8Array expected"):t,Ba=t=>new Uint8Array(t),np=(t,e)=>fx(dx(t)?Qu(t):Ba(t),e),W=(t,e=Vi)=>{let r=t%e;return r>=0n?r:e+r},tx=t=>t instanceof bn?t:ot("Point expected"),rx,bn=class t{constructor(e,r,n){this.px=e,this.py=r,this.pz=n}static fromAffine(e){return new t(e.x,e.y,1n)}static fromHex(e){e=np(e);let r,n=e[0],i=e.subarray(1),o=nx(i,0,ts),s=e.length;if(s===33&&[2,3].includes(n)){ep(o)||ot("Point hex invalid: x not FE");let a=xB(ex(o)),u=(a&1n)===1n;(n&1)===1!==u&&(a=W(-a)),r=new t(o,a,1n)}return s===65&&n===4&&(r=new t(o,nx(i,ts,2*ts),1n)),r?r.ok():ot("Point is not on curve")}static fromPrivateKey(e){return Da.mul(EB(e))}get x(){return this.aff().x}get y(){return this.aff().y}equals(e){let{px:r,py:n,pz:i}=this,{px:o,py:s,pz:a}=tx(e),u=W(r*a),d=W(o*i),c=W(n*a),l=W(s*i);return u===d&&c===l}negate(){return new t(this.px,W(-this.py),this.pz)}double(){return this.add(this)}add(e){let{px:r,py:n,pz:i}=this,{px:o,py:s,pz:a}=tx(e),{a:u,b:d}=ux,c=0n,l=0n,g=0n,w=W(d*3n),m=W(r*o),y=W(n*s),E=W(i*a),v=W(r+n),D=W(o+s);v=W(v*D),D=W(m+y),v=W(v-D),D=W(r+i);let S=W(o+a);return D=W(D*S),S=W(m+E),D=W(D-S),S=W(n+i),c=W(s+a),S=W(S*c),c=W(y+E),S=W(S-c),g=W(u*D),c=W(w*E),g=W(c+g),c=W(y-g),g=W(y+g),l=W(c*g),y=W(m+m),y=W(y+m),E=W(u*E),D=W(w*D),y=W(y+E),E=W(m-E),E=W(u*E),D=W(D+E),m=W(y*D),l=W(l+m),m=W(S*D),c=W(v*c),c=W(c-m),m=W(v*y),g=W(S*g),g=W(g+m),new t(c,l,g)}mul(e,r=!0){if(!r&&e===0n)return Yu;if(lx(e)||ot("invalid scalar"),this.equals(Da))return _B(e).p;let n=Yu,i=Da;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):r&&(i=i.add(o));return n}mulAddQUns(e,r,n){return this.mul(r,!1).add(e.mul(n,!1)).ok()}toAffine(){let{px:e,py:r,pz:n}=this;if(this.equals(Yu))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let i=px(n);return W(n*i)!==1n&&ot("invalid inverse"),{x:W(e*i),y:W(r*i)}}assertValidity(){let{x:e,y:r}=this.aff();return(!ep(e)||!ep(r))&&ot("Point invalid: x or y"),W(r*r)===ex(e)?this:ot("Point invalid: not on curve")}multiply(e){return this.mul(e)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(e=!0){let{x:r,y:n}=this.aff();return(e?(n&1n)===0n?"02":"03":"04")+ix(r)+(e?"":ix(n))}toRawBytes(e=!0){return Qu(this.toHex(e))}};bn.BASE=new bn(ax,cx,1n);bn.ZERO=new bn(0n,1n,0n);var{BASE:Da,ZERO:Yu}=bn,hx=(t,e)=>t.toString(16).padStart(e,"0"),ip=t=>Array.from(t).map(e=>hx(e,2)).join(""),Qu=t=>{let e=t.length;(!dx(t)||e%2)&&ot("hex invalid 1");let r=Ba(e/2);for(let n=0;n<r.length;n++){let i=n*2,o=t.slice(i,i+2),s=Number.parseInt(o,16);(Number.isNaN(s)||s<0)&&ot("hex invalid 2"),r[n]=s}return r},ed=t=>BigInt("0x"+(ip(t)||"0")),nx=(t,e,r)=>ed(t.slice(e,r)),op=t=>Zu(t)&&t>=0n&&t<tp?Qu(hx(t,2*ts)):ot("bigint expected"),ix=t=>ip(op(t)),ox=(...t)=>{let e=Ba(t.reduce((n,i)=>n+fx(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},px=(t,e=Vi)=>{(t===0n||e<=0n)&&ot("no inverse n="+t+" mod="+e);let r=W(t,e),n=e,i=0n,o=1n,s=1n,a=0n;for(;r!==0n;){let u=n/r,d=n%r,c=i-s*u,l=o-a*u;n=r,r=d,i=s,o=a,s=c,a=l}return n===1n?W(i,e):ot("no inverse")},xB=t=>{let e=1n;for(let r=t,n=(Vi+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*r%Vi),r=r*r%Vi;return W(e*e)===t?e:ot("sqrt invalid")},EB=t=>(Zu(t)||(t=ed(np(t,ts))),lx(t)?t:ot("private key out of range"));var sx=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Xu;function vB(t){t=np(t);let e=ts+8;(t.length<e||t.length>1024)&&ot("expected proper params");let r=W(ed(t),rp-1n)+1n;return op(r)}var yx={hexToBytes:Qu,bytesToHex:ip,concatBytes:ox,bytesToNumberBE:ed,numberToBytesBE:op,mod:W,invert:px,hmacSha256Async:async(t,...e)=>{let r=sx();if(!r)return ot("etc.hmacSha256Async not set");let n=r.subtle,i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Ba(await n.sign("HMAC",i,ox(...e)))},hmacSha256Sync:Xu,hashToPrivateKey:vB,randomBytes:t=>{let e=sx();return e||ot("crypto.getRandomValues must be defined"),e.getRandomValues(Ba(t))}};Object.defineProperties(yx,{hmacSha256Sync:{configurable:!1,get(){return Xu},set(t){Xu||(Xu=t)}}});var Fi=8,SB=()=>{let t=[],e=256/Fi+1,r=Da,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let o=1;o<2**(Fi-1);o++)n=n.add(r),t.push(n);r=n.double()}return t},_B=t=>{let e=rx||(rx=SB()),r=(c,l)=>{let g=l.negate();return c?g:l},n=Yu,i=Da,o=1+256/Fi,s=2**(Fi-1),a=BigInt(2**Fi-1),u=2**Fi,d=BigInt(Fi);for(let c=0;c<o;c++){let l=c*s,g=Number(t&a);t>>=d,g>s&&(g-=u,t+=1n);let w=l,m=l+Math.abs(g)-1,y=c%2!==0,E=g<0;g===0?i=i.add(r(y,e[w])):n=n.add(r(E,e[m]))}return{p:n,f:i}};var bL=f(h(),1),gx;(function(t){t.Mainnet="mainnet",t.Testnet="test"})(gx||(gx={}));var EL=f(h(),1),wx;(function(t){t.Authentication="authentication",t.AssertionMethod="assertionMethod",t.CapabilityInvocation="capabilityInvocation",t.CapabilityDelegation="capabilityDelegation",t.KeyAgreement="keyAgreement"})(wx||(wx={}));var BL=f(h(),1);var xx=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(xx||{}),AB={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},bx="https://ion.tbd.engineering",Hi=class Hi extends qt{static async create({keyManager:e=new gt,options:r={}}={}){if(r.verificationMethods?.some(m=>!(m.algorithm in AB)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(m=>"id"in m).map(m=>m.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(m=>!m.id||!m.type||!m.serviceEndpoint))throw new Error("One or more services are missing required properties");let i={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},o=[];for(let m of r.verificationMethods??[i]){let y=await e.generateKey({algorithm:m.algorithm}),E=await e.getPublicKey({keyUri:y});o.push({id:m.id,publicKeyJwk:E,purposes:m.purposes??["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let s=await e.generateKey({algorithm:"secp256k1"}),a=await e.getPublicKey({keyUri:s}),u=await e.generateKey({algorithm:"secp256k1"}),d=await e.getPublicKey({keyUri:u}),c=await Zn.computeLongFormDidUri({recoveryKey:a,updateKey:d,services:r.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:g}=await Hi.resolve(c,{gatewayUri:r.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${g?.error}`);let w=new xt({uri:c,document:l,metadata:{published:!1,canonicalId:c.split(":",3).join(":"),recoveryKey:a,updateKey:d},keyManager:e});if(r.publish??!0){let m=await Hi.publish({did:w,gatewayUri:r.gatewayUri});w.metadata=m.didDocumentMetadata}return w}static async getSigningMethod({didDocument:e,methodId:r}){let n=Ce.parse(e.id);if(n&&n.method!==this.methodName)throw new q("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>o.id===(r??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new q("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new gt}){if(Ce.parse(e.uri)?.method!==Hi.methodName)throw new q("methodNotSupported","Method not supported");return await xt.import({portableDid:e,keyManager:r})}static async publish({did:e,gatewayUri:r=bx}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:yh({didDocument:e.document,methodId:s.id})}))??[],i=await Zn.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await Zn.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=Zn.appendPathToUrl({baseUrl:r,path:"/operations"}),a=await fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:a.ok},didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:"internalError",errorMessage:`Failed to publish DID document for: ${e.uri}`}}}}static async resolve(e,r={}){let n=Ce.parse(e);if(!n)return{...ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Hi.methodName)return{...ke,didResolutionMetadata:{error:"methodNotSupported"}};let i=r?.gatewayUri??bx;try{let o=Zn.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(o);if(!s.ok)throw new q("notFound",`Unable to find DID document for: ${e}`);let{didDocument:a,didDocumentMetadata:u}=await s.json();return{...ke,...a&&{didDocument:a},didDocumentMetadata:{published:u?.method?.published,...u}}}catch(o){if(!(o instanceof q))throw new Error(o);return{...ke,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};Hi.methodName="ion";var sp=Hi,Zn=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 async computeLongFormDidUri({recoveryKey:e,updateKey:r,services:n,verificationMethods:i}){let o=await t.createIonDocument({services:n,verificationMethods:i}),s=t.normalizeJwk(e),a=t.normalizeJwk(r);return await Qo.createLongFormDid({document:o,recoveryKey:s,updateKey:a})}static async constructCreateRequest({ionDocument:e,recoveryKey:r,updateKey:n}){return await Yn.createCreateRequest({document:e,recoveryKey:t.normalizeJwk(r),updateKey:t.normalizeJwk(n)})}static async createIonDocument({services:e,verificationMethods:r}){let n=[];for(let s of r){let a=s.id??s.publicKeyJwk.kid??await oe({jwk:s.publicKeyJwk});a=`${a.split("#").pop()}`;let u={id:a,publicKeyJwk:t.normalizeJwk(s.publicKeyJwk),purposes:s.purposes,type:"JsonWebKey2020"};n.push(u)}let i=e.map(s=>({...s,id:`${s.id.split("#").pop()}`}));return{publicKeys:n,services:i}}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}};var a4=f(h(),1);var ji=class ji extends qt{static async create({keyManager:e=new gt,options:r={}}={}){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 n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),o=await e.getPublicKey({keyUri:i}),s=M.object(o).toBase64Url(),a=`did:${ji.methodName}:${s}`,d=(await ji.resolve(a)).didDocument;return new xt({uri:a,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Ce.parse(e.id);if(r&&r.method!==this.methodName)throw new q("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new q("internalError","A verification method intended for signing could not be determined from the DID Document");return n}static async import({portableDid:e,keyManager:r=new gt}){if(Ce.parse(e.uri)?.method!==ji.methodName)throw new q("methodNotSupported","Method not supported");let i=await xt.import({portableDid:e,keyManager:r});if(i.document.verificationMethod.length!==1)throw new q("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,r){let n=Ce.parse(e),i;try{i=M.base64Url(n.id).toObject()}catch{}if(!n||!i)return{...ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ji.methodName)return{...ke,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{...ke,didDocument:o}}};ji.methodName="jwk";var ap=ji;var g4=f(h(),1);var Ex=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(Ex||{}),td={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"},TB={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1",X25519:"X25519"},gr=class gr extends qt{static async create({keyManager:e=new gt,options:r={}}={}){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 n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),o=await e.getPublicKey({keyUri:i}),s=await ir.publicKeyToMultibaseId({publicKey:o}),a=`did:${gr.methodName}:${s}`,d=(await gr.resolve(a,r)).didDocument;return new xt({uri:a,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Ce.parse(e.id);if(r&&r.method!==this.methodName)throw new q("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(o=>o.id===n);if(!(i&&i.publicKeyJwk))throw new q("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new gt}){if(Ce.parse(e.uri)?.method!==gr.methodName)throw new q("methodNotSupported","Method not supported");let i=await xt.import({portableDid:e,keyManager:r});if(i.document.verificationMethod.length!==1)throw new q("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,r){try{let n=await gr.createDocument({didUri:e,options:r});return{...ke,didDocument:n}}catch(n){if(!(n instanceof q))throw new Error(n);return{...ke,didResolutionMetadata:{error:n.code,...n.message&&{errorMessage:n.message}}}}}static async createDocument({didUri:e,options:r={}}){let{defaultContext:n="https://www.w3.org/ns/did/v1",enableEncryptionKeyDerivation:i=!1,enableExperimentalPublicKeyTypes:o=!1,publicKeyFormat:s="JsonWebKey2020"}=r,a={id:""},u=Ce.parse(e);if(!u)throw new q("invalidDid",`Invalid DID URI: ${e}`);let d=u.id;if(u.method!==gr.methodName)throw new q("methodNotSupported",`Method not supported: ${u.method}`);if(!gr.validateIdentifier(u))throw new q("invalidDid",`Invalid DID URI: ${e}`);let c=await gr.createSignatureMethod({didUri:e,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:o,publicKeyFormat:s}});if(a.id=u.uri,a.verificationMethod=[c],a.authentication=[c.id],a.assertionMethod=[c.id],a.capabilityInvocation=[c.id],a.capabilityDelegation=[c.id],i===!0){let w=s==="Ed25519VerificationKey2020"?"X25519KeyAgreementKey2020":"JsonWebKey2020",m=await this.createEncryptionMethod({didUri:e,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:o,publicKeyFormat:w}});a.verificationMethod.push(m),a.keyAgreement=[m.id]}let l=[n];return ph({didDocument:a}).forEach(w=>{let m=td[w];l.push(m)}),a["@context"]=l,a}static async createEncryptionMethod({didUri:e,multibaseValue:r,options:n}){let{enableExperimentalPublicKeyTypes:i,publicKeyFormat:o}=n,s={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u}=await gr.deriveEncryptionKey({multibaseValue:r}),d=a.byteLength,c=ir.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(d!==c)throw new q("invalidPublicKeyLength",`Expected ${d} bytes. Actual: ${c}`);let l=bu({keyBytes:a,multicodecCode:u});s.id=`${e}#${l}`;try{new URL(s.id)}catch{throw new q("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in td))throw new q("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","X25519KeyAgreementKey2020"].includes(o))throw new q("invalidPublicKeyType",`Specified '${o}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=o,s.controller=e,o==="X25519KeyAgreementKey2020"&&(s.publicKeyMultibase=l),o==="JsonWebKey2020"){let{crv:w}=await ir.multicodecToJwk({code:u});s.publicKeyJwk=await ir.keyConverter(w).bytesToPublicKey({publicKeyBytes:a})}return s}static async createSignatureMethod({didUri:e,multibaseValue:r,options:n}){let{enableExperimentalPublicKeyTypes:i,publicKeyFormat:o}=n,s={id:"",type:"",controller:""},{keyBytes:a,multicodecCode:u,multicodecName:d}=xu({multibaseKeyId:r}),c=a.byteLength,l=ir.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(c!==l)throw new q("invalidPublicKeyLength",`Expected ${c} bytes. Actual: ${l}`);let g=!1;switch(d){case"secp256k1-pub":g=await nt.validatePublicKey({publicKeyBytes:a});break;case"ed25519-pub":g=await Xe.validatePublicKey({publicKeyBytes:a});break;case"x25519-pub":g=!0;break}if(!g)throw new q("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${r}`;try{new URL(s.id)}catch{throw new q("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in td))throw new q("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(o))throw new q("invalidPublicKeyType",`Specified '${o}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=o,s.controller=e,o==="Ed25519VerificationKey2020"&&(s.publicKeyMultibase=r),o==="JsonWebKey2020"){let{crv:m}=await ir.multicodecToJwk({code:u});s.publicKeyJwk=await ir.keyConverter(m).bytesToPublicKey({publicKeyBytes:a})}return s}static async deriveEncryptionKey({multibaseValue:e}){let r={keyBytes:new Uint8Array,multicodecCode:0},{keyBytes:n,multicodecCode:i}=xu({multibaseKeyId:e});if(i===237){let o=await ir.keyConverter("Ed25519").bytesToPublicKey({publicKeyBytes:n}),s=await Xe.convertPublicKeyToX25519({publicKey:o});r={keyBytes:await ir.keyConverter("Ed25519").publicKeyToBytes({publicKey:s}),multicodecCode:236}}return r}static validateIdentifier(e){let{method:r,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&r==="key"&&Number("1")>0&&oo(n)==="String"&&n.startsWith("z")}};gr.methodName="key";var cp=gr,qr=class qr{static async jwkToMulticodec({jwk:e}){let r=[];e.crv&&(r.push(e.crv),e.d?r.push("private"):r.push("public"));let n=r.join(":"),i=qr.JWK_TO_MULTICODEC[n];if(i===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${n}'`);return{code:ht.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let n={"P-256":dt.compressPublicKey,secp256k1:nt.compressPublicKey}[e];if(!n)throw new q("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Xe,"P-256":dt,secp256k1:nt,X25519:Vo}[e];if(!n)throw new q("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async multicodecToJwk({code:e,name:r}){if(!(r?!e:e))throw new Error("Either 'name' or 'code' must be defined, but not both.");r=r===void 0?ht.getNameFromCode({code:e}):r;let n=r,i=qr.MULTICODEC_TO_JWK[n];if(i===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return{...i}}static async publicKeyToMultibaseId({publicKey:e}){if(!(e?.crv&&e.crv in TB))throw new q("invalidPublicKeyType",`Public key contains an unsupported key type: ${e?.crv??"undefined"}`);let r=await qr.keyConverter(e.crv).publicKeyToBytes({publicKey:e});/^(secp256k1|P-256|P-384|P-521)$/.test(e.crv)&&(r=await qr.keyCompressor(e.crv)({publicKeyBytes:r}));let{name:n}=await qr.jwkToMulticodec({jwk:e});return bu({keyBytes:r,multicodecName:n})}};qr.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"},qr.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,236:32,237:32},qr.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:""}};var ir=qr;var v4=f(h(),1);var rd=class rd extends qt{static async resolve(e,r){let n=Ce.parse(e);if(!n)return{...ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==rd.methodName)return{...ke,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=await fetch(o);if(!s.ok)throw new Error("HTTP error status code returned");let a=await s.json();return{...ke,didDocument:a}}catch{return{...ke,didResolutionMetadata:{error:"notFound"}}}}};rd.methodName="web";var up=rd;var T4=f(h(),1),_x=f(Sx(),1),Ax=f(Al(),1),dp=class{constructor({db:e,location:r="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new Ax.Level(r),this.ttl=(0,_x.default)(n)}async get(e){try{let r=await this.cache.get(e),n=JSON.parse(r);if(Date.now()>=n.ttlMillis){this.cache.nextTick(()=>this.cache.del(e));return}else return n.value}catch(r){if(r.notFound)return;throw r}}set(e,r){let n={ttlMillis:Date.now()+this.ttl,value:r},i=JSON.stringify(n);return this.cache.put(e,i)}delete(e){return this.cache.del(e)}clear(){return this.cache.clear()}close(){return this.cache.close()}};var D4=f(h(),1),lp={get:function(t){return null},set:function(t,e){return null},delete:function(t){return null},clear:function(){return null},close:function(){return null}};var U4=f(h(),1);var fp=class{constructor({cache:e,didResolvers:r}){this.didResolvers=new Map;this.cache=e||lp;for(let n of r)this.didResolvers.set(n.methodName,n)}async resolve(e,r){let n=Ce.parse(e);if(!n)return{...ke,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${e}`}};let i=this.didResolvers.get(n.method);if(!i)return{...ke,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${n.method}`}};let o=await this.cache.get(n.uri);if(o)return o;{let s=await i.resolve(n.uri,r);return s.didResolutionMetadata.error||await this.cache.set(n.uri,s),s}}async dereference(e,r){let n=Ce.parse(e);if(!n)return{dereferencingMetadata:{error:"invalidDidUrl"},contentStream:null,contentMetadata:{}};let{didDocument:i,didResolutionMetadata:o,didDocumentMetadata:s}=await this.resolve(n.uri);if(!i)return{dereferencingMetadata:{error:o.error},contentStream:null,contentMetadata:{}};if(!n.fragment||n.query)return{dereferencingMetadata:{contentType:"application/did+json"},contentStream:i,contentMetadata:s};let{service:a=[],verificationMethod:u=[]}=i,d=new Set([e,n.fragment,`#${n.fragment}`]),c;for(let l of u)if(d.has(l.id)){c=l;break}for(let l of a)if(d.has(l.id)){c=l;break}return c?{dereferencingMetadata:{contentType:"application/did+json"},contentStream:c,contentMetadata:o}:{dereferencingMetadata:{error:"notFound"},contentStream:null,contentMetadata:{}}}};return Jx(kB);})();
1
+ "use strict";var Web5Dids=(()=>{var Py=Object.create;var ws=Object.defineProperty;var Ly=Object.getOwnPropertyDescriptor;var My=Object.getOwnPropertyNames;var Ny=Object.getPrototypeOf,$y=Object.prototype.hasOwnProperty;var ae=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),xs=(r,e)=>{for(var t in e)ws(r,t,{get:e[t],enumerable:!0})},dl=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of My(e))!$y.call(r,i)&&i!==t&&ws(r,i,{get:()=>e[i],enumerable:!(n=Ly(e,i))||n.enumerable});return r};var h=(r,e,t)=>(t=r!=null?Py(Ny(r)):{},dl(e||!r||!r.__esModule?ws(t,"default",{value:r,enumerable:!0}):t,r)),Vy=r=>dl(ws({},"__esModule",{value:!0}),r);var fl=ae(bs=>{"use strict";var yb=h(f());bs.byteLength=Hy;bs.toByteArray=jy;bs.fromByteArray=Gy;var er=[],kt=[],Fy=typeof Uint8Array<"u"?Uint8Array:Array,ua="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(bn=0,ll=ua.length;bn<ll;++bn)er[bn]=ua[bn],kt[ua.charCodeAt(bn)]=bn;var bn,ll;kt[45]=62;kt[95]=63;function hl(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function Hy(r){var e=hl(r),t=e[0],n=e[1];return(t+n)*3/4-n}function qy(r,e,t){return(e+t)*3/4-t}function jy(r){var e,t=hl(r),n=t[0],i=t[1],o=new Fy(qy(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=kt[r.charCodeAt(u)]<<18|kt[r.charCodeAt(u+1)]<<12|kt[r.charCodeAt(u+2)]<<6|kt[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=kt[r.charCodeAt(u)]<<2|kt[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=kt[r.charCodeAt(u)]<<10|kt[r.charCodeAt(u+1)]<<4|kt[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function zy(r){return er[r>>18&63]+er[r>>12&63]+er[r>>6&63]+er[r&63]}function Jy(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(zy(n));return i.join("")}function Gy(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(Jy(r,s,s+o>c?c:s+o));return n===1?(e=r[t-1],i.push(er[e>>2]+er[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(er[e>>10]+er[e>>4&63]+er[e<<2&63]+"=")),i.join("")}});var pl=ae(da=>{var gb=h(f());da.read=function(r,e,t,n,i){var o,s,c=i*8-n-1,u=(1<<c)-1,d=u>>1,a=-7,l=t?i-1:0,g=t?-1:1,b=r[e+l];for(l+=g,o=b&(1<<-a)-1,b>>=-a,a+=c;a>0;o=o*256+r[e+l],l+=g,a-=8);for(s=o&(1<<-a)-1,o>>=-a,a+=n;a>0;s=s*256+r[e+l],l+=g,a-=8);if(o===0)o=1-d;else{if(o===u)return s?NaN:(b?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-d}return(b?-1:1)*s*Math.pow(2,o-n)};da.write=function(r,e,t,n,i,o){var s,c,u,d=o*8-i-1,a=(1<<d)-1,l=a>>1,g=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,b=n?0:o-1,m=n?1:-1,x=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=a):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),s+l>=1?e+=g/u:e+=g*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=a?(c=0,s=a):s+l>=1?(c=(e*u-1)*Math.pow(2,i),s=s+l):(c=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;r[t+b]=c&255,b+=m,c/=256,i-=8);for(s=s<<i|c,d+=i;d>0;r[t+b]=s&255,b+=m,s/=256,d-=8);r[t+b-m]|=x*128}});var di=ae(ui=>{"use strict";var bb=h(f());var la=fl(),ci=pl(),yl=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ui.Buffer=B;ui.SlowBuffer=e0;ui.INSPECT_MAX_BYTES=50;var vs=2147483647;ui.kMaxLength=vs;B.TYPED_ARRAY_SUPPORT=Wy();!B.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 Wy(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(B.prototype,"parent",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.buffer}});Object.defineProperty(B.prototype,"offset",{enumerable:!0,get:function(){if(B.isBuffer(this))return this.byteOffset}});function xr(r){if(r>vs)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,B.prototype),e}function B(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ya(r)}return xl(r,e,t)}B.poolSize=8192;function xl(r,e,t){if(typeof r=="string")return Xy(r,e);if(ArrayBuffer.isView(r))return Zy(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(tr(r,ArrayBuffer)||r&&tr(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(tr(r,SharedArrayBuffer)||r&&tr(r.buffer,SharedArrayBuffer)))return fa(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return B.from(n,e,t);let i=Qy(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return B.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}B.from=function(r,e,t){return xl(r,e,t)};Object.setPrototypeOf(B.prototype,Uint8Array.prototype);Object.setPrototypeOf(B,Uint8Array);function bl(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function Yy(r,e,t){return bl(r),r<=0?xr(r):e!==void 0?typeof t=="string"?xr(r).fill(e,t):xr(r).fill(e):xr(r)}B.alloc=function(r,e,t){return Yy(r,e,t)};function ya(r){return bl(r),xr(r<0?0:ma(r)|0)}B.allocUnsafe=function(r){return ya(r)};B.allocUnsafeSlow=function(r){return ya(r)};function Xy(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!B.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=vl(r,e)|0,n=xr(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function ha(r){let e=r.length<0?0:ma(r.length)|0,t=xr(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Zy(r){if(tr(r,Uint8Array)){let e=new Uint8Array(r);return fa(e.buffer,e.byteOffset,e.byteLength)}return ha(r)}function fa(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,B.prototype),n}function Qy(r){if(B.isBuffer(r)){let e=ma(r.length)|0,t=xr(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||wa(r.length)?xr(0):ha(r);if(r.type==="Buffer"&&Array.isArray(r.data))return ha(r.data)}function ma(r){if(r>=vs)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+vs.toString(16)+" bytes");return r|0}function e0(r){return+r!=r&&(r=0),B.alloc(+r)}B.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==B.prototype};B.compare=function(e,t){if(tr(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),tr(t,Uint8Array)&&(t=B.from(t,t.offset,t.byteLength)),!B.isBuffer(e)||!B.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};B.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}};B.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return B.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=B.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(tr(s,Uint8Array))o+s.length>i.length?(B.isBuffer(s)||(s=B.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(B.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function vl(r,e){if(B.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||tr(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return pa(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Ol(r).length;default:if(i)return n?-1:pa(r).length;e=(""+e).toLowerCase(),i=!0}}B.byteLength=vl;function t0(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return l0(this,e,t);case"utf8":case"utf-8":return Al(this,e,t);case"ascii":return u0(this,e,t);case"latin1":case"binary":return d0(this,e,t);case"base64":return c0(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return h0(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}B.prototype._isBuffer=!0;function vn(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}B.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)vn(this,t,t+1);return this};B.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)vn(this,t,t+3),vn(this,t+1,t+2);return this};B.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)vn(this,t,t+7),vn(this,t+1,t+6),vn(this,t+2,t+5),vn(this,t+3,t+4);return this};B.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Al(this,0,e):t0.apply(this,arguments)};B.prototype.toLocaleString=B.prototype.toString;B.prototype.equals=function(e){if(!B.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:B.compare(this,e)===0};B.prototype.inspect=function(){let e="",t=ui.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};yl&&(B.prototype[yl]=B.prototype.inspect);B.prototype.compare=function(e,t,n,i,o){if(tr(e,Uint8Array)&&(e=B.from(e,e.offset,e.byteLength)),!B.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,c=n-t,u=Math.min(s,c),d=this.slice(i,o),a=e.slice(t,n);for(let l=0;l<u;++l)if(d[l]!==a[l]){s=d[l],c=a[l];break}return s<c?-1:c<s?1:0};function El(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,wa(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=B.from(e,n)),B.isBuffer(e))return e.length===0?-1:ml(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):ml(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function ml(r,e,t,n,i){let o=1,s=r.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,c/=2,t/=2}function u(a,l){return o===1?a[l]:a.readUInt16BE(l*o)}let d;if(i){let a=-1;for(d=t;d<s;d++)if(u(r,d)===u(e,a===-1?0:d-a)){if(a===-1&&(a=d),d-a+1===c)return a*o}else a!==-1&&(d-=d-a),a=-1}else for(t+c>s&&(t=s-c),d=t;d>=0;d--){let a=!0;for(let l=0;l<c;l++)if(u(r,d+l)!==u(e,l)){a=!1;break}if(a)return d}return-1}B.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};B.prototype.indexOf=function(e,t,n){return El(this,e,t,n,!0)};B.prototype.lastIndexOf=function(e,t,n){return El(this,e,t,n,!1)};function r0(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(e.substr(s*2,2),16);if(wa(c))return s;r[t+s]=c}return s}function n0(r,e,t,n){return Es(pa(e,r.length-t),r,t,n)}function i0(r,e,t,n){return Es(m0(e),r,t,n)}function o0(r,e,t,n){return Es(Ol(e),r,t,n)}function s0(r,e,t,n){return Es(g0(e,r.length-t),r,t,n)}B.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>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");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return r0(this,e,t,n);case"utf8":case"utf-8":return n0(this,e,t,n);case"ascii":case"latin1":case"binary":return i0(this,e,t,n);case"base64":return o0(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s0(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};B.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function c0(r,e,t){return e===0&&t===r.length?la.fromByteArray(r):la.fromByteArray(r.slice(e,t))}function Al(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=t){let u,d,a,l;switch(c){case 1:o<128&&(s=o);break;case 2:u=r[i+1],(u&192)===128&&(l=(o&31)<<6|u&63,l>127&&(s=l));break;case 3:u=r[i+1],d=r[i+2],(u&192)===128&&(d&192)===128&&(l=(o&15)<<12|(u&63)<<6|d&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=r[i+1],d=r[i+2],a=r[i+3],(u&192)===128&&(d&192)===128&&(a&192)===128&&(l=(o&15)<<18|(u&63)<<12|(d&63)<<6|a&63,l>65535&&l<1114112&&(s=l))}}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 a0(n)}var gl=4096;function a0(r){let e=r.length;if(e<=gl)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=gl));return t}function u0(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function d0(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function l0(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=w0[r[o]];return i}function h0(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}B.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,B.prototype),i};function ze(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}B.prototype.readUintLE=B.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||ze(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};B.prototype.readUintBE=B.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||ze(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};B.prototype.readUint8=B.prototype.readUInt8=function(e,t){return e=e>>>0,t||ze(e,1,this.length),this[e]};B.prototype.readUint16LE=B.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||ze(e,2,this.length),this[e]|this[e+1]<<8};B.prototype.readUint16BE=B.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||ze(e,2,this.length),this[e]<<8|this[e+1]};B.prototype.readUint32LE=B.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};B.prototype.readUint32BE=B.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};B.prototype.readBigUInt64LE=Hr(function(e){e=e>>>0,ai(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&io(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});B.prototype.readBigUInt64BE=Hr(function(e){e=e>>>0,ai(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&io(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});B.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||ze(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};B.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||ze(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};B.prototype.readInt8=function(e,t){return e=e>>>0,t||ze(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};B.prototype.readInt16LE=function(e,t){e=e>>>0,t||ze(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};B.prototype.readInt16BE=function(e,t){e=e>>>0,t||ze(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};B.prototype.readInt32LE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};B.prototype.readInt32BE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};B.prototype.readBigInt64LE=Hr(function(e){e=e>>>0,ai(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&io(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});B.prototype.readBigInt64BE=Hr(function(e){e=e>>>0,ai(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&io(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});B.prototype.readFloatLE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),ci.read(this,e,!0,23,4)};B.prototype.readFloatBE=function(e,t){return e=e>>>0,t||ze(e,4,this.length),ci.read(this,e,!1,23,4)};B.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||ze(e,8,this.length),ci.read(this,e,!0,52,8)};B.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||ze(e,8,this.length),ci.read(this,e,!1,52,8)};function dt(r,e,t,n,i,o){if(!B.isBuffer(r))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(t+n>r.length)throw new RangeError("Index out of range")}B.prototype.writeUintLE=B.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;dt(this,e,t,n,c,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};B.prototype.writeUintBE=B.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;dt(this,e,t,n,c,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};B.prototype.writeUint8=B.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,1,255,0),this[t]=e&255,t+1};B.prototype.writeUint16LE=B.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};B.prototype.writeUint16BE=B.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};B.prototype.writeUint32LE=B.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};B.prototype.writeUint32BE=B.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Tl(r,e,t,n,i){Ul(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function Bl(r,e,t,n,i){Ul(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}B.prototype.writeBigUInt64LE=Hr(function(e,t=0){return Tl(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeBigUInt64BE=Hr(function(e,t=0){return Bl(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);dt(this,e,t,n,u-1,-u)}let o=0,s=1,c=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&c===0&&this[t+o-1]!==0&&(c=1),this[t+o]=(e/s>>0)-c&255;return t+n};B.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);dt(this,e,t,n,u-1,-u)}let o=n-1,s=1,c=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&c===0&&this[t+o+1]!==0&&(c=1),this[t+o]=(e/s>>0)-c&255;return t+n};B.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};B.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};B.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};B.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};B.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||dt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};B.prototype.writeBigInt64LE=Hr(function(e,t=0){return Tl(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});B.prototype.writeBigInt64BE=Hr(function(e,t=0){return Bl(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Sl(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Il(r,e,t,n,i){return e=+e,t=t>>>0,i||Sl(r,e,t,4,34028234663852886e22,-34028234663852886e22),ci.write(r,e,t,n,23,4),t+4}B.prototype.writeFloatLE=function(e,t,n){return Il(this,e,t,!0,n)};B.prototype.writeFloatBE=function(e,t,n){return Il(this,e,t,!1,n)};function Dl(r,e,t,n,i){return e=+e,t=t>>>0,i||Sl(r,e,t,8,17976931348623157e292,-17976931348623157e292),ci.write(r,e,t,n,52,8),t+8}B.prototype.writeDoubleLE=function(e,t,n){return Dl(this,e,t,!0,n)};B.prototype.writeDoubleBE=function(e,t,n){return Dl(this,e,t,!1,n)};B.prototype.copy=function(e,t,n,i){if(!B.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<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-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};B.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=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"&&!B.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=B.isBuffer(e)?e:B.from(e,i),c=s.length;if(c===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%c]}return this};var si={};function ga(r,e,t){si[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}ga("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);ga("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);ga("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=wl(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=wl(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function wl(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function f0(r,e,t){ai(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&io(e,r.length-(t+1))}function Ul(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",c;throw o>3?e===0||e===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:c=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:c=`>= ${e}${s} and <= ${t}${s}`,new si.ERR_OUT_OF_RANGE("value",c,r)}f0(n,i,o)}function ai(r,e){if(typeof r!="number")throw new si.ERR_INVALID_ARG_TYPE(e,"number",r)}function io(r,e,t){throw Math.floor(r)!==r?(ai(r,t),new si.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new si.ERR_BUFFER_OUT_OF_BOUNDS:new si.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var p0=/[^+/0-9A-Za-z-_]/g;function y0(r){if(r=r.split("=")[0],r=r.trim().replace(p0,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function pa(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>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=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function m0(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function g0(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function Ol(r){return la.toByteArray(y0(r))}function Es(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function tr(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function wa(r){return r!==r}var w0=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function Hr(r){return typeof BigInt>"u"?x0:r}function x0(){throw new Error("BigInt not supported")}});var f=ae(()=>{"use strict";var Kl=di().Buffer,{Buffer:b0}=di();Kl.prototype.writeBigUInt64BE=b0.prototype.writeBigUInt64BE;globalThis.Buffer=Kl});var kl=ae((kb,_l)=>{var Cb=h(f()),v0=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,As=()=>v0.now(),E0=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),ba=r=>r===1/0||E0(r),va=class r{constructor({max:e=1/0,ttl:t,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,t!==void 0&&!ba(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!ba(e))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=t,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,t){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-As());break}},t);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 process.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!==r.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[t,n]of e)this.dispose(n,t,"delete")}setTTL(e,t=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(t!==1/0){let i=Math.floor(As()+t);this.expirationMap.set(e,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,t)),this.expirations[i].push(e)}else this.expirationMap.set(e,1/0)}set(e,t,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!ba(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!==t&&(this.data.set(e,t),o||this.dispose(s,e,"set"))}else this.setTTL(e,n),this.data.set(e,t);for(;this.size>this.max;)this.purgeToCapacity();return this}has(e){return this.data.has(e)}getRemainingTTL(e){let t=this.expirationMap.get(e);return t===1/0?t:t!==void 0?Math.max(0,Math.ceil(t-As())):0}get(e,{updateAgeOnGet:t=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 t&&this.setTTL(e,n),o}dispose(e,t){}delete(e){let t=this.expirationMap.get(e);if(t!==void 0){let n=this.data.get(e);this.data.delete(e),this.expirationMap.delete(e);let i=this.expirations[t];return i&&(i.length<=1?delete this.expirations[t]:this.expirations[t]=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 t=this.expirations[e];if(this.size-t.length>=this.max){delete this.expirations[e];let n=[];for(let i of t)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 t.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(As());for(let t in this.expirations){if(t==="Infinity"||t>e)return;let n=[...this.expirations[t]||[]],i=[];delete this.expirations[t];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 t of this.expirations[e])yield[t,this.data.get(t)]}*keys(){for(let e in this.expirations)for(let t of this.expirations[e])yield t}*values(){for(let e in this.expirations)for(let t of this.expirations[e])yield this.data.get(t)}[Symbol.iterator](){return this.entries()}};_l.exports=va});var Yl=ae(Wl=>{"use strict";var t1=h(f());Wl.supports=function(...e){let t=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(t,{snapshots:t.snapshots||!1,permanence:t.permanence||!1,seek:t.seek||!1,clear:t.clear||!1,getMany:t.getMany||!1,keyIterator:t.keyIterator||!1,valueIterator:t.valueIterator||!1,iteratorNextv:t.iteratorNextv||!1,iteratorAll:t.iteratorAll||!1,status:t.status||!1,createIfMissing:t.createIfMissing||!1,errorIfExists:t.errorIfExists||!1,deferredOpen:t.deferredOpen||!1,promises:t.promises||!1,streams:t.streams||!1,encodings:Object.assign({},t.encodings),events:Object.assign({},t.events),additionalMethods:Object.assign({},t.additionalMethods)})}});var Ft=ae((n1,Xl)=>{"use strict";var i1=h(f());Xl.exports=class extends Error{constructor(e,t){super(e||""),typeof t=="object"&&t!==null&&(t.code&&(this.code=String(t.code)),t.expected&&(this.expected=!0),t.transient&&(this.transient=!0),t.cause&&(this.cause=t.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var Pa=ae((o1,Zl)=>{"use strict";var s1=h(f()),Ra=null;Zl.exports=function(){return Ra===null&&(Ra={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ra}});var Na=ae(Ql=>{"use strict";var a1=h(f()),La=Ft(),tm=new Set(["buffer","view","utf8"]),Ma=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"||!tm.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 La(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new La(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new La(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};Ql.Encoding=Ma});var Ha=ae(Bs=>{"use strict";var d1=h(f()),{Buffer:Va}=di()||{},{Encoding:Fa}=Na(),rm=Pa(),lo=class extends Fa{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new ho({encode:this.encode,decode:e=>this.decode(Va.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},ho=class extends Fa{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new lo({encode:e=>{let t=this.encode(e);return Va.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},$a=class extends Fa{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new lo({encode:e=>Va.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=rm();return new ho({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};Bs.BufferFormat=lo;Bs.ViewFormat=ho;Bs.UTF8Format=$a});var nh=ae(Sn=>{"use strict";var h1=h(f()),{Buffer:it}=di()||{Buffer:{isBuffer:()=>!1}},{textEncoder:th,textDecoder:eh}=Pa()(),{BufferFormat:fo,ViewFormat:qa,UTF8Format:rh}=Ha(),Ss=r=>r;Sn.utf8=new rh({encode:function(r){return it.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?eh.decode(r):String(r)},decode:Ss,name:"utf8",createViewTranscoder(){return new qa({encode:function(r){return ArrayBuffer.isView(r)?r:th.encode(r)},decode:function(r){return eh.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new fo({encode:function(r){return it.isBuffer(r)?r:ArrayBuffer.isView(r)?it.from(r.buffer,r.byteOffset,r.byteLength):it.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Sn.json=new rh({encode:JSON.stringify,decode:JSON.parse,name:"json"});Sn.buffer=new fo({encode:function(r){return it.isBuffer(r)?r:ArrayBuffer.isView(r)?it.from(r.buffer,r.byteOffset,r.byteLength):it.from(String(r),"utf8")},decode:Ss,name:"buffer",createViewTranscoder(){return new qa({encode:function(r){return ArrayBuffer.isView(r)?r:it.from(String(r),"utf8")},decode:function(r){return it.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Sn.view=new qa({encode:function(r){return ArrayBuffer.isView(r)?r:th.encode(r)},decode:Ss,name:"view",createBufferTranscoder(){return new fo({encode:function(r){return it.isBuffer(r)?r:ArrayBuffer.isView(r)?it.from(r.buffer,r.byteOffset,r.byteLength):it.from(String(r),"utf8")},decode:Ss,name:`${this.name}+buffer`})}});Sn.hex=new fo({encode:function(r){return it.isBuffer(r)?r:it.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Sn.base64=new fo({encode:function(r){return it.isBuffer(r)?r:it.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var sh=ae(oh=>{"use strict";var p1=h(f()),ih=Ft(),Ds=nh(),{Encoding:nm}=Na(),{BufferFormat:im,ViewFormat:om,UTF8Format:sm}=Ha(),po=Symbol("formats"),Is=Symbol("encodings"),cm=new Set(["buffer","view","utf8"]),ja=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>cm.has(t)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[Is]=new Map,this[po]=new Set(e);for(let t in Ds)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Is].values()))}encoding(e){let t=this[Is].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=lm[e],!t)throw new ih(`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");t=am(e)}let{name:n,format:i}=t;if(!this[po].has(i))if(this[po].has("view"))t=t.createViewTranscoder();else if(this[po].has("buffer"))t=t.createBufferTranscoder();else if(this[po].has("utf8"))t=t.createUTF8Transcoder();else throw new ih(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[Is].set(o,t)}return t}};oh.Transcoder=ja;function am(r){if(r instanceof nm)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${hm++}`;switch(um(r)){case"view":return new om({...r,name:t});case"utf8":return new sm({...r,name:t});case"buffer":return new im({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function um(r){return"format"in r&&r.format!==void 0?r.format:"buffer"in r&&typeof r.buffer=="boolean"?r.buffer?"buffer":"utf8":"code"in r&&Number.isInteger(r.code)?"view":"buffer"}var dm={binary:Ds.buffer,"utf-8":Ds.utf8},lm={...Ds,...dm},hm=0});var gh=ae((y1,za)=>{"use strict";var m1=h(f()),yi=typeof Reflect=="object"?Reflect:null,ch=yi&&typeof yi.apply=="function"?yi.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},Us;yi&&typeof yi.ownKeys=="function"?Us=yi.ownKeys:Object.getOwnPropertySymbols?Us=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Us=function(e){return Object.getOwnPropertyNames(e)};function fm(r){console&&console.warn&&console.warn(r)}var uh=Number.isNaN||function(e){return e!==e};function xe(){xe.init.call(this)}za.exports=xe;za.exports.once=gm;xe.EventEmitter=xe;xe.prototype._events=void 0;xe.prototype._eventsCount=0;xe.prototype._maxListeners=void 0;var ah=10;function Os(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(xe,"defaultMaxListeners",{enumerable:!0,get:function(){return ah},set:function(r){if(typeof r!="number"||r<0||uh(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");ah=r}});xe.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};xe.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||uh(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 dh(r){return r._maxListeners===void 0?xe.defaultMaxListeners:r._maxListeners}xe.prototype.getMaxListeners=function(){return dh(this)};xe.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.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(t.length>0&&(s=t[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=o[e];if(u===void 0)return!1;if(typeof u=="function")ch(u,this,t);else for(var d=u.length,a=yh(u,d),n=0;n<d;++n)ch(a[n],this,t);return!0};function lh(r,e,t,n){var i,o,s;if(Os(t),o=r._events,o===void 0?(o=r._events=Object.create(null),r._eventsCount=0):(o.newListener!==void 0&&(r.emit("newListener",e,t.listener?t.listener:t),o=r._events),s=o[e]),s===void 0)s=o[e]=t,++r._eventsCount;else if(typeof s=="function"?s=o[e]=n?[t,s]:[s,t]:n?s.unshift(t):s.push(t),i=dh(r),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=r,c.type=e,c.count=s.length,fm(c)}return r}xe.prototype.addListener=function(e,t){return lh(this,e,t,!1)};xe.prototype.on=xe.prototype.addListener;xe.prototype.prependListener=function(e,t){return lh(this,e,t,!0)};function pm(){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 hh(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},i=pm.bind(n);return i.listener=t,n.wrapFn=i,i}xe.prototype.once=function(e,t){return Os(t),this.on(e,hh(this,e,t)),this};xe.prototype.prependOnceListener=function(e,t){return Os(t),this.prependListener(e,hh(this,e,t)),this};xe.prototype.removeListener=function(e,t){var n,i,o,s,c;if(Os(t),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():ym(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||t)}return this};xe.prototype.off=xe.prototype.removeListener;xe.prototype.removeAllListeners=function(e){var t,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(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this};function fh(r,e,t){var n=r._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?t?[i.listener||i]:[i]:t?mm(i):yh(i,i.length)}xe.prototype.listeners=function(e){return fh(this,e,!0)};xe.prototype.rawListeners=function(e){return fh(this,e,!1)};xe.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):ph.call(r,e)};xe.prototype.listenerCount=ph;function ph(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}xe.prototype.eventNames=function(){return this._eventsCount>0?Us(this._events):[]};function yh(r,e){for(var t=new Array(e),n=0;n<e;++n)t[n]=r[n];return t}function ym(r,e){for(;e+1<r.length;e++)r[e]=r[e+1];r.pop()}function mm(r){for(var e=new Array(r.length),t=0;t<e.length;++t)e[t]=r[t].listener||r[t];return e}function gm(r,e){return new Promise(function(t,n){function i(s){r.removeListener(e,o),n(s)}function o(){typeof r.removeListener=="function"&&r.removeListener("error",i),t([].slice.call(arguments))}mh(r,e,o,{once:!0}),e!=="error"&&wm(r,i,{once:!0})})}function wm(r,e,t){typeof r.on=="function"&&mh(r,"error",e,t)}function mh(r,e,t,n){if(typeof r.on=="function")n.once?r.once(e,t):r.on(e,t);else if(typeof r.addEventListener=="function")r.addEventListener(e,function i(o){n.once&&r.removeEventListener(e,i),t(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r)}});var xh=ae((g1,wh)=>{var w1=h(f());wh.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var yo=ae(Ja=>{"use strict";var b1=h(f()),bh=xh();Ja.fromCallback=function(r,e){if(r===void 0){var t=new Promise(function(n,i){r=function(o,s){o?i(o):n(s)}});r[e!==void 0?e:"promise"]=t}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r};Ja.fromPromise=function(r,e){if(e===void 0)return r;r.then(function(t){bh(()=>e(null,t))}).catch(function(t){bh(()=>e(t))})}});var Ks=ae(Ga=>{"use strict";var E1=h(f());Ga.getCallback=function(r,e){return typeof r=="function"?r:e};Ga.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var Wr=ae(Rs=>{"use strict";var T1=h(f()),{fromCallback:Wa}=yo(),vt=Ft(),{getOptions:Ya,getCallback:vh}=Ks(),In=Symbol("promise"),mi=Symbol("callback"),nr=Symbol("working"),Dn=Symbol("handleOne"),Er=Symbol("handleMany"),Xa=Symbol("autoClose"),Jr=Symbol("finishWork"),ir=Symbol("returnMany"),qr=Symbol("closing"),mo=Symbol("handleClose"),_s=Symbol("closed"),go=Symbol("closeCallbacks"),zr=Symbol("keyEncoding"),Un=Symbol("valueEncoding"),Za=Symbol("abortOnClose"),ks=Symbol("legacy"),Qa=Symbol("keys"),eu=Symbol("values"),jr=Symbol("limit"),Ct=Symbol("count"),Cs=Object.freeze({}),xm=()=>{},Eh=!1,wo=class{constructor(e,t,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 t!="object"||t===null)throw new TypeError("The second argument must be an options object");this[_s]=!1,this[go]=[],this[nr]=!1,this[qr]=!1,this[Xa]=!1,this[mi]=null,this[Dn]=this[Dn].bind(this),this[Er]=this[Er].bind(this),this[mo]=this[mo].bind(this),this[zr]=t[zr],this[Un]=t[Un],this[ks]=n,this[jr]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[Ct]=0,this[Za]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Ct]}get limit(){return this[jr]}next(e){let t;if(e===void 0)t=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[ks]?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[qr]?this.nextTick(e,new vt("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[nr]?this.nextTick(e,new vt("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[nr]=!0,this[mi]=e,this[Ct]>=this[jr]?this.nextTick(this[Dn],null):this._next(this[Dn])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=vh(t,n),n=Wa(n,In),t=Ya(t,Cs),Number.isInteger(e)?(this[qr]?this.nextTick(n,new vt("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[nr]?this.nextTick(n,new vt("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[jr]<1/0&&(e=Math.min(e,this[jr]-this[Ct])),this[nr]=!0,this[mi]=n,e<=0?this.nextTick(this[Er],null,[]):this._nextv(e,t,this[Er])),n[In]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[In])}_nextv(e,t,n){let i=[],o=(s,c,u)=>{if(s)return n(s);if(this[ks]?c===void 0&&u===void 0:c===void 0)return n(null,i);i.push(this[ks]?[c,u]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=vh(e,t),t=Wa(t,In),e=Ya(e,Cs),this[qr]?this.nextTick(t,new vt("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[nr]?this.nextTick(t,new vt("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[nr]=!0,this[mi]=t,this[Xa]=!0,this[Ct]>=this[jr]?this.nextTick(this[Er],null,[]):this._all(e,this[Er])),t[In]}_all(e,t){let n=this[Ct],i=[],o=()=>{let c=this[jr]<1/0?Math.min(1e3,this[jr]-n):1e3;c<=0?this.nextTick(t,null,i):this._nextv(c,Cs,s)},s=(c,u)=>{c?t(c):u.length===0?t(null,i):(i.push.apply(i,u),n+=u.length,o())};o()}[Jr](){let e=this[mi];return this[Za]&&e===null?xm:(this[nr]=!1,this[mi]=null,this[qr]&&this._close(this[mo]),e)}[ir](e,t,n){this[Xa]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=Ya(t,Cs),!this[qr]){if(this[nr])throw new vt("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[zr]),i=n.format;t.keyEncoding!==i&&(t={...t,keyEncoding:i});let o=this.db.prefixKey(n.encode(e),i);this._seek(o,t)}}}_seek(e,t){throw new vt("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=Wa(e,In),this[_s]?this.nextTick(e):this[qr]?this[go].push(e):(this[qr]=!0,this[go].push(e),this[nr]?this[Za]&&this[Jr]()(new vt("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[mo])),e[In]}_close(e){this.nextTick(e)}[mo](){this[_s]=!0,this.db.detachResource(this);let e=this[go];this[go]=[];for(let t of e)t()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[_s]||await this.close()}}},gi=class extends wo{constructor(e,t){super(e,t,!0),this[Qa]=t.keys!==!1,this[eu]=t.values!==!1}[Dn](e,t,n){let i=this[Jr]();if(e)return i(e);try{t=this[Qa]&&t!==void 0?this[zr].decode(t):void 0,n=this[eu]&&n!==void 0?this[Un].decode(n):void 0}catch(o){return i(new Gr("entry",o))}t===void 0&&n===void 0||this[Ct]++,i(null,t,n)}[Er](e,t){let n=this[Jr]();if(e)return this[ir](n,e);try{for(let i of t){let o=i[0],s=i[1];i[0]=this[Qa]&&o!==void 0?this[zr].decode(o):void 0,i[1]=this[eu]&&s!==void 0?this[Un].decode(s):void 0}}catch(i){return this[ir](n,new Gr("entries",i))}this[Ct]+=t.length,this[ir](n,null,t)}end(e){return!Eh&&typeof console<"u"&&(Eh=!0,console.warn(new vt("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)}},tu=class extends wo{constructor(e,t){super(e,t,!1)}[Dn](e,t){let n=this[Jr]();if(e)return n(e);try{t=t!==void 0?this[zr].decode(t):void 0}catch(i){return n(new Gr("key",i))}t!==void 0&&this[Ct]++,n(null,t)}[Er](e,t){let n=this[Jr]();if(e)return this[ir](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[zr].decode(o):void 0}}catch(i){return this[ir](n,new Gr("keys",i))}this[Ct]+=t.length,this[ir](n,null,t)}},ru=class extends wo{constructor(e,t){super(e,t,!1)}[Dn](e,t){let n=this[Jr]();if(e)return n(e);try{t=t!==void 0?this[Un].decode(t):void 0}catch(i){return n(new Gr("value",i))}t!==void 0&&this[Ct]++,n(null,t)}[Er](e,t){let n=this[Jr]();if(e)return this[ir](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[Un].decode(o):void 0}}catch(i){return this[ir](n,new Gr("values",i))}this[Ct]+=t.length,this[ir](n,null,t)}},Gr=class extends vt{constructor(e,t){super(`Iterator could not decode ${e}`,{code:"LEVEL_DECODE_ERROR",cause:t})}};for(let r of["_ended property","_nexting property","_end method"])Object.defineProperty(gi.prototype,r.split(" ")[0],{get(){throw new vt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new vt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});gi.keyEncoding=zr;gi.valueEncoding=Un;Rs.AbstractIterator=gi;Rs.AbstractKeyIterator=tu;Rs.AbstractValueIterator=ru});var Ah=ae(nu=>{"use strict";var S1=h(f()),{AbstractKeyIterator:bm,AbstractValueIterator:vm}=Wr(),On=Symbol("iterator"),xo=Symbol("callback"),wi=Symbol("handleOne"),Kn=Symbol("handleMany"),bo=class extends bm{constructor(e,t){super(e,t),this[On]=e.iterator({...t,keys:!0,values:!1}),this[wi]=this[wi].bind(this),this[Kn]=this[Kn].bind(this)}},Ps=class extends vm{constructor(e,t){super(e,t),this[On]=e.iterator({...t,keys:!1,values:!0}),this[wi]=this[wi].bind(this),this[Kn]=this[Kn].bind(this)}};for(let r of[bo,Ps]){let e=r===bo,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[xo]=n,this[On].next(this[wi])},r.prototype[wi]=function(n,i,o){let s=this[xo];n?s(n):s(null,e?i:o)},r.prototype._nextv=function(n,i,o){this[xo]=o,this[On].nextv(n,i,this[Kn])},r.prototype._all=function(n,i){this[xo]=i,this[On].all(n,this[Kn])},r.prototype[Kn]=function(n,i){let o=this[xo];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[On].seek(n,i)},r.prototype._close=function(n){this[On].close(n)}}nu.DefaultKeyIterator=bo;nu.DefaultValueIterator=Ps});var Th=ae(Fs=>{"use strict";var D1=h(f()),{AbstractIterator:Em,AbstractKeyIterator:Am,AbstractValueIterator:Tm}=Wr(),iu=Ft(),ht=Symbol("nut"),$s=Symbol("undefer"),Vs=Symbol("factory"),Ls=class extends Em{constructor(e,t){super(e,t),this[ht]=null,this[Vs]=()=>e.iterator(t),this.db.defer(()=>this[$s]())}},Ms=class extends Am{constructor(e,t){super(e,t),this[ht]=null,this[Vs]=()=>e.keys(t),this.db.defer(()=>this[$s]())}},Ns=class extends Tm{constructor(e,t){super(e,t),this[ht]=null,this[Vs]=()=>e.values(t),this.db.defer(()=>this[$s]())}};for(let r of[Ls,Ms,Ns])r.prototype[$s]=function(){this.db.status==="open"&&(this[ht]=this[Vs]())},r.prototype._next=function(e){this[ht]!==null?this[ht].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new iu("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(e,t,n){this[ht]!==null?this[ht].nextv(e,t,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,t,n)):this.nextTick(n,new iu("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(e,t){this[ht]!==null?this[ht].all(t):this.db.status==="opening"?this.db.defer(()=>this._all(e,t)):this.nextTick(t,new iu("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(e,t){this[ht]!==null?this[ht]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t))},r.prototype._close=function(e){this[ht]!==null?this[ht].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};Fs.DeferredIterator=Ls;Fs.DeferredKeyIterator=Ms;Fs.DeferredValueIterator=Ns});var su=ae(Sh=>{"use strict";var O1=h(f()),{fromCallback:Bh}=yo(),Hs=Ft(),{getCallback:Bm,getOptions:Sm}=Ks(),qs=Symbol("promise"),Rt=Symbol("status"),xi=Symbol("operations"),vo=Symbol("finishClose"),bi=Symbol("closeCallbacks"),ou=class{constructor(e){if(typeof e!="object"||e===null){let t=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${t}`)}this[xi]=[],this[bi]=[],this[Rt]="open",this[vo]=this[vo].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[xi].length}put(e,t,n){if(this[Rt]!=="open")throw new Hs("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(t);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),u=o.valueEncoding(n&&n.valueEncoding),d=c.format;n={...n,keyEncoding:d,valueEncoding:u.format},o!==this.db&&(n.sublevel=null);let a=o.prefixKey(c.encode(e),d),l=u.encode(t);return this._put(a,l,n),this[xi].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[Rt]!=="open")throw new Hs("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=t&&t.sublevel!=null?t.sublevel:this.db,o=t,s=i.keyEncoding(t&&t.keyEncoding),c=s.format;return t={...t,keyEncoding:c},i!==this.db&&(t.sublevel=null),this._del(i.prefixKey(s.encode(e),c),t),this[xi].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[Rt]!=="open")throw new Hs("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[xi]=[],this}_clear(){}write(e,t){return t=Bm(e,t),t=Bh(t,qs),e=Sm(e),this[Rt]!=="open"?this.nextTick(t,new Hs("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[Rt]="writing",this._write(e,n=>{this[Rt]="closing",this[bi].push(()=>t(n)),n||this.db.emit("batch",this[xi]),this._close(this[vo])})),t[qs]}_write(e,t){}close(e){return e=Bh(e,qs),this[Rt]==="closing"?this[bi].push(e):this[Rt]==="closed"?this.nextTick(e):(this[bi].push(e),this[Rt]!=="writing"&&(this[Rt]="closing",this._close(this[vo]))),e[qs]}_close(e){this.nextTick(e)}[vo](){this[Rt]="closed",this.db.detachResource(this);let e=this[bi];this[bi]=[];for(let t of e)t()}};Sh.AbstractChainedBatch=ou});var Dh=ae(Ih=>{"use strict";var _1=h(f()),{AbstractChainedBatch:Im}=su(),Dm=Ft(),vi=Symbol("encoded"),cu=class extends Im{constructor(e){super(e),this[vi]=[]}_put(e,t,n){this[vi].push({...n,type:"put",key:e,value:t})}_del(e,t){this[vi].push({...t,type:"del",key:e})}_clear(){this[vi]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[vi].length===0?this.nextTick(t):this.db._batch(this[vi],e,t):this.nextTick(t,new Dm("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};Ih.DefaultChainedBatch=cu});var Kh=ae((k1,Oh)=>{"use strict";var C1=h(f()),Uh=Ft(),Um=Object.prototype.hasOwnProperty,Om=new Set(["lt","lte","gt","gte"]);Oh.exports=function(r,e){let t={};for(let n in r)if(Um.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new Uh(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new Uh("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});Om.has(n)?t[n]=e.encode(r[n]):t[n]=r[n]}return t.reverse=!!t.reverse,t.limit=Number.isInteger(t.limit)&&t.limit>=0?t.limit:-1,t}});var au=ae((R1,kh)=>{var P1=h(f());var _h;kh.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(_h||(_h=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var Ph=ae((L1,Rh)=>{"use strict";var M1=h(f()),Ch=au();Rh.exports=function(r,...e){e.length===0?Ch(r):Ch(()=>r(...e))}});var Lh=ae(js=>{"use strict";var $1=h(f()),{AbstractIterator:Km,AbstractKeyIterator:_m,AbstractValueIterator:km}=Wr(),Ei=Symbol("unfix"),Ht=Symbol("iterator"),_n=Symbol("handleOne"),Yr=Symbol("handleMany"),Ar=Symbol("callback"),Eo=class extends Km{constructor(e,t,n,i){super(e,t),this[Ht]=n,this[Ei]=i,this[_n]=this[_n].bind(this),this[Yr]=this[Yr].bind(this),this[Ar]=null}[_n](e,t,n){let i=this[Ar];if(e)return i(e);t!==void 0&&(t=this[Ei](t)),i(e,t,n)}[Yr](e,t){let n=this[Ar];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[Ei](o))}n(e,t)}},Ao=class extends _m{constructor(e,t,n,i){super(e,t),this[Ht]=n,this[Ei]=i,this[_n]=this[_n].bind(this),this[Yr]=this[Yr].bind(this),this[Ar]=null}[_n](e,t){let n=this[Ar];if(e)return n(e);t!==void 0&&(t=this[Ei](t)),n(e,t)}[Yr](e,t){let n=this[Ar];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[Ei](o))}n(e,t)}},To=class extends km{constructor(e,t,n){super(e,t),this[Ht]=n}};for(let r of[Eo,Ao])r.prototype._next=function(e){this[Ar]=e,this[Ht].next(this[_n])},r.prototype._nextv=function(e,t,n){this[Ar]=n,this[Ht].nextv(e,t,this[Yr])},r.prototype._all=function(e,t){this[Ar]=t,this[Ht].all(e,this[Yr])};for(let r of[To])r.prototype._next=function(e){this[Ht].next(e)},r.prototype._nextv=function(e,t,n){this[Ht].nextv(e,t,n)},r.prototype._all=function(e,t){this[Ht].all(e,t)};for(let r of[Eo,Ao,To])r.prototype._seek=function(e,t){this[Ht].seek(e,t)},r.prototype._close=function(e){this[Ht].close(e)};js.AbstractSublevelIterator=Eo;js.AbstractSublevelKeyIterator=Ao;js.AbstractSublevelValueIterator=To});var Vh=ae((V1,$h)=>{"use strict";var F1=h(f()),uu=Ft(),{Buffer:hu}=di()||{},{AbstractSublevelIterator:Cm,AbstractSublevelKeyIterator:Rm,AbstractSublevelValueIterator:Pm}=Lh(),Tr=Symbol("prefix"),Mh=Symbol("upperBound"),Bo=Symbol("prefixRange"),Et=Symbol("parent"),du=Symbol("unfix"),Nh=new TextEncoder,Lm={separator:"!"};$h.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new uu("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new uu("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?Lm:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...u}=e.defaults(o);i=Nm(i,s);let d=s.charCodeAt(0)+1,a=n[Et]||n;if(!Nh.encode(i).every(b=>b>d&&b<127))throw new uu(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Mm(a,c),u);let l=(n.prefix||"")+s+i+s,g=l.slice(0,-1)+String.fromCharCode(d);this[Et]=a,this[Tr]=new zs(l),this[Mh]=new zs(g),this[du]=new fu,this.nextTick=a.nextTick}prefixKey(n,i){if(i==="utf8")return this[Tr].utf8+n;if(n.byteLength===0)return this[Tr][i];if(i==="view"){let o=this[Tr].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Tr].buffer;return hu.concat([o,n],o.byteLength+n.byteLength)}}[Bo](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[Tr][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[Mh][i]}get prefix(){return this[Tr].utf8}get db(){return this[Et]}_open(n,i){this[Et].open({passive:!0},i)}_put(n,i,o,s){this[Et].put(n,i,o,s)}_get(n,i,o){this[Et].get(n,i,o)}_getMany(n,i,o){this[Et].getMany(n,i,o)}_del(n,i,o){this[Et].del(n,i,o)}_batch(n,i,o){this[Et].batch(n,i,o)}_clear(n,i){this[Bo](n,n.keyEncoding),this[Et].clear(n,i)}_iterator(n){this[Bo](n,n.keyEncoding);let i=this[Et].iterator(n),o=this[du].get(this[Tr].utf8.length,n.keyEncoding);return new Cm(this,n,i,o)}_keys(n){this[Bo](n,n.keyEncoding);let i=this[Et].keys(n),o=this[du].get(this[Tr].utf8.length,n.keyEncoding);return new Rm(this,n,i,o)}_values(n){this[Bo](n,n.keyEncoding);let i=this[Et].values(n);return new Pm(this,n,i)}}return{AbstractSublevel:e}};var Mm=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:lu(r,"utf8"),buffer:lu(r,"buffer"),view:lu(r,"view")}}},lu=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},zs=class{constructor(e){this.utf8=e,this.view=Nh.encode(e),this.buffer=hu?hu.from(this.view.buffer,0,this.view.byteLength):{}}},fu=class{constructor(){this.cache=new Map}get(e,t){let n=this.cache.get(t);return n===void 0&&(t==="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(t,n)),n}},Nm=function(r,e){let t=0,n=r.length;for(;t<n&&r[t]===e;)t++;for(;n>t&&r[n-1]===e;)n--;return r.slice(t,n)}});var wu=ae(gu=>{"use strict";var q1=h(f()),{supports:$m}=Yl(),{Transcoder:Vm}=sh(),{EventEmitter:Fm}=gh(),{fromCallback:Xr}=yo(),qt=Ft(),{AbstractIterator:kn}=Wr(),{DefaultKeyIterator:Hm,DefaultValueIterator:qm}=Ah(),{DeferredIterator:jm,DeferredKeyIterator:zm,DeferredValueIterator:Jm}=Th(),{DefaultChainedBatch:Fh}=Dh(),{getCallback:Cn,getOptions:Zr}=Ks(),Js=Kh(),ce=Symbol("promise"),Br=Symbol("landed"),Rn=Symbol("resources"),pu=Symbol("closeResources"),So=Symbol("operations"),Io=Symbol("undefer"),Gs=Symbol("deferOpen"),Hh=Symbol("options"),ue=Symbol("status"),Pn=Symbol("defaultOptions"),Ai=Symbol("transcoder"),Ws=Symbol("keyEncoding"),yu=Symbol("valueEncoding"),Gm=()=>{},Do=class extends Fm{constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=Zr(t);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=t;this[Rn]=new Set,this[So]=[],this[Gs]=!0,this[Hh]=s,this[ue]="opening",this.supports=$m(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[Ai]=new Vm(Wm(this)),this[Ws]=this[Ai].encoding(n||"utf8"),this[yu]=this[Ai].encoding(i||"utf8");for(let c of this[Ai].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Pn]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[Ws].commonName,valueEncoding:this[yu].commonName}),key:Object.freeze({keyEncoding:this[Ws].commonName})},this.nextTick(()=>{this[Gs]&&this.open({passive:!1},Gm)})}get status(){return this[ue]}keyEncoding(e){return this[Ai].encoding(e??this[Ws])}valueEncoding(e){return this[Ai].encoding(e??this[yu])}open(e,t){t=Cn(e,t),t=Xr(t,ce),e={...this[Hh],...Zr(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[ue]==="closing"||this[ue]==="opening"?this.once(Br,i?()=>n(i):n):this[ue]!=="open"?t(new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):t()};return e.passive?this[ue]==="opening"?this.once(Br,n):this.nextTick(n):this[ue]==="closed"||this[Gs]?(this[Gs]=!1,this[ue]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[ue]="closed",this[pu](()=>{this.emit(Br),n(i)}),this[Io]();return}this[ue]="open",this[Io](),this.emit(Br),this[ue]==="open"&&this.emit("open"),this[ue]==="open"&&this.emit("ready"),n()})):this[ue]==="open"?this.nextTick(n):this.once(Br,()=>this.open(e,t)),t[ce]}_open(e,t){this.nextTick(t)}close(e){e=Xr(e,ce);let t=n=>{this[ue]==="opening"||this[ue]==="closing"?this.once(Br,n?t(n):t):this[ue]!=="closed"?e(new qt("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[ue]==="open"){this[ue]="closing",this.emit("closing");let n=i=>{this[ue]="open",this[Io](),this.emit(Br),t(i)};this[pu](()=>{this._close(i=>{if(i)return n(i);this[ue]="closed",this[Io](),this.emit(Br),this[ue]==="closed"&&this.emit("closed"),t()})})}else this[ue]==="closed"?this.nextTick(t):this.once(Br,()=>this.close(e));return e[ce]}[pu](e){if(this[Rn].size===0)return this.nextTick(e);let t=this[Rn].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[Rn])o.close(i);n=!1,this[Rn].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=Cn(t,n),n=Xr(n,ce),t=Zr(t,this[Pn].entry),this[ue]==="opening")return this.defer(()=>this.get(e,t,n)),n[ce];if(Ti(this,n))return n[ce];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ce];let o=this.keyEncoding(t.keyEncoding),s=this.valueEncoding(t.valueEncoding),c=o.format,u=s.format;return(t.keyEncoding!==c||t.valueEncoding!==u)&&(t=Object.assign({},t,{keyEncoding:c,valueEncoding:u})),this._get(this.prefixKey(o.encode(e),c),t,(d,a)=>{if(d)return(d.code==="LEVEL_NOT_FOUND"||d.notFound||/NotFound/i.test(d))&&(d.code||(d.code="LEVEL_NOT_FOUND"),d.notFound||(d.notFound=!0),d.status||(d.status=404)),n(d);try{a=s.decode(a)}catch(l){return n(new qt("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[ce]}_get(e,t,n){this.nextTick(n,new Error("NotFound"))}getMany(e,t,n){if(n=Cn(t,n),n=Xr(n,ce),t=Zr(t,this[Pn].entry),this[ue]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[ce];if(Ti(this,n))return n[ce];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[ce];if(e.length===0)return this.nextTick(n,null,[]),n[ce];let i=this.keyEncoding(t.keyEncoding),o=this.valueEncoding(t.valueEncoding),s=i.format,c=o.format;(t.keyEncoding!==s||t.valueEncoding!==c)&&(t=Object.assign({},t,{keyEncoding:s,valueEncoding:c}));let u=new Array(e.length);for(let d=0;d<e.length;d++){let a=e[d],l=this._checkKey(a);if(l)return this.nextTick(n,l),n[ce];u[d]=this.prefixKey(i.encode(a),s)}return this._getMany(u,t,(d,a)=>{if(d)return n(d);try{for(let l=0;l<a.length;l++)a[l]!==void 0&&(a[l]=o.decode(a[l]))}catch(l){return n(new qt(`Could not decode one or more of ${a.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[ce]}_getMany(e,t,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,t,n,i){if(i=Cn(n,i),i=Xr(i,ce),n=Zr(n,this[Pn].entry),this[ue]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[ce];if(Ti(this,i))return i[ce];let o=this._checkKey(e)||this._checkValue(t);if(o)return this.nextTick(i,o),i[ce];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),u=s.format,d=c.format;(n.keyEncoding!==u||n.valueEncoding!==d)&&(n=Object.assign({},n,{keyEncoding:u,valueEncoding:d}));let a=this.prefixKey(s.encode(e),u),l=c.encode(t);return this._put(a,l,n,g=>{if(g)return i(g);this.emit("put",e,t),i()}),i[ce]}_put(e,t,n,i){this.nextTick(i)}del(e,t,n){if(n=Cn(t,n),n=Xr(n,ce),t=Zr(t,this[Pn].key),this[ue]==="opening")return this.defer(()=>this.del(e,t,n)),n[ce];if(Ti(this,n))return n[ce];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ce];let o=this.keyEncoding(t.keyEncoding),s=o.format;return t.keyEncoding!==s&&(t=Object.assign({},t,{keyEncoding:s})),this._del(this.prefixKey(o.encode(e),s),t,c=>{if(c)return n(c);this.emit("del",e),n()}),n[ce]}_del(e,t,n){this.nextTick(n)}batch(e,t,n){if(!arguments.length){if(this[ue]==="opening")return new Fh(this);if(this[ue]!=="open")throw new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=Cn(t,n),n=Xr(n,ce),t=Zr(t,this[Pn].empty),this[ue]==="opening")return this.defer(()=>this.batch(e,t,n)),n[ce];if(Ti(this,n))return n[ce];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[ce];if(e.length===0)return this.nextTick(n),n[ce];let i=new Array(e.length),{keyEncoding:o,valueEncoding:s,...c}=t;for(let u=0;u<e.length;u++){if(typeof e[u]!="object"||e[u]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[ce];let d=Object.assign({},e[u]);if(d.type!=="put"&&d.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[ce];let a=this._checkKey(d.key);if(a)return this.nextTick(n,a),n[ce];let l=d.sublevel!=null?d.sublevel:this,g=l.keyEncoding(d.keyEncoding||o),b=g.format;if(d.key=l.prefixKey(g.encode(d.key),b),d.keyEncoding=b,d.type==="put"){let m=this._checkValue(d.value);if(m)return this.nextTick(n,m),n[ce];let x=l.valueEncoding(d.valueEncoding||s);d.value=x.encode(d.value),d.valueEncoding=x.format}l!==this&&(d.sublevel=null),i[u]=d}return this._batch(i,c,u=>{if(u)return n(u);this.emit("batch",e),n()}),n[ce]}_batch(e,t,n){this.nextTick(n)}sublevel(e,t){return this._sublevel(e,mu.defaults(t))}_sublevel(e,t){return new mu(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=Cn(e,t),t=Xr(t,ce),e=Zr(e,this[Pn].empty),this[ue]==="opening")return this.defer(()=>this.clear(e,t)),t[ce];if(Ti(this,t))return t[ce];let n=e,i=this.keyEncoding(e.keyEncoding);return e=Js(e,i),e.keyEncoding=i.format,e.limit===0?this.nextTick(t):this._clear(e,o=>{if(o)return t(o);this.emit("clear",n),t()}),t[ce]}_clear(e,t){this.nextTick(t)}iterator(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Js(e,t),e.keys=e.keys!==!1,e.values=e.values!==!1,e[kn.keyEncoding]=t,e[kn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ue]==="opening")return new jm(this,e);if(this[ue]!=="open")throw new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new kn(this,e)}keys(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Js(e,t),e[kn.keyEncoding]=t,e[kn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ue]==="opening")return new zm(this,e);if(this[ue]!=="open")throw new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new Hm(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Js(e,t),e[kn.keyEncoding]=t,e[kn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ue]==="opening")return new Jm(this,e);if(this[ue]!=="open")throw new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new qm(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[So].push(e)}[Io](){if(this[So].length===0)return;let e=this[So];this[So]=[];for(let t of e)t()}attachResource(e){if(typeof e!="object"||e===null||typeof e.close!="function")throw new TypeError("The first argument must be a resource object");this[Rn].add(e)}detachResource(e){this[Rn].delete(e)}_chainedBatch(){return new Fh(this)}_checkKey(e){if(e==null)return new qt("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new qt("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Do.prototype.nextTick=Ph();var{AbstractSublevel:mu}=Vh()({AbstractLevel:Do});gu.AbstractLevel=Do;gu.AbstractSublevel=mu;var Ti=function(r,e){return r[ue]!=="open"?(r.nextTick(e,new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},Wm=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var xu=ae(Ln=>{"use strict";var z1=h(f());Ln.AbstractLevel=wu().AbstractLevel;Ln.AbstractSublevel=wu().AbstractSublevel;Ln.AbstractIterator=Wr().AbstractIterator;Ln.AbstractKeyIterator=Wr().AbstractKeyIterator;Ln.AbstractValueIterator=Wr().AbstractValueIterator;Ln.AbstractChainedBatch=su().AbstractChainedBatch});var jh=ae((J1,qh)=>{var G1=h(f());qh.exports=Xm;var Ym=au();function Xm(r,e,t){if(typeof e!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,u=!0,d;Array.isArray(r)?(n=[],o=i=r.length):(s=Object.keys(r),n={},o=i=s.length);function a(g){function b(){t&&t(g,n),t=null}u?Ym(b):b()}function l(g,b,m){if(n[g]=m,b&&(c=!0),--o===0||b)a(b);else if(!c&&d<i){let x;s?(x=s[d],d+=1,r[x](function(E,S){l(x,E,S)})):(x=d,d+=1,r[x](function(E,S){l(x,E,S)}))}}d=e,o?s?s.some(function(g,b){return r[g](function(m,x){l(g,m,x)}),b===e-1}):r.some(function(g,b){return g(function(m,x){l(b,m,x)}),b===e-1}):a(null),u=!1}});var bu=ae((W1,zh)=>{"use strict";var Y1=h(f());zh.exports=function(e){let t=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 t!==void 0&&n!==void 0?IDBKeyRange.bound(t,n,i,o):t!==void 0?IDBKeyRange.lowerBound(t,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var vu=ae((X1,Jh)=>{"use strict";var Z1=h(f()),Zm=new TextEncoder;Jh.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):Zm.encode(r)}});var Zh=ae(Xh=>{"use strict";var eE=h(f()),{AbstractIterator:Qm}=xu(),Gh=bu(),Ys=vu(),or=Symbol("cache"),Sr=Symbol("finished"),At=Symbol("options"),Ir=Symbol("currentOptions"),Mn=Symbol("position"),Eu=Symbol("location"),Bi=Symbol("first"),Wh={},Au=class extends Qm{constructor(e,t,n){super(e,n),this[or]=[],this[Sr]=this.limit===0,this[At]=n,this[Ir]={...n},this[Mn]=void 0,this[Eu]=t,this[Bi]=!0}_nextv(e,t,n){if(this[Bi]=!1,this[Sr])return this.nextTick(n,null,[]);if(this[or].length>0)return e=Math.min(e,this[or].length),this.nextTick(n,null,this[or].splice(0,e));this[Mn]!==void 0&&(this[At].reverse?(this[Ir].lt=this[Mn],this[Ir].lte=void 0):(this[Ir].gt=this[Mn],this[Ir].gte=void 0));let i;try{i=Gh(this[Ir])}catch{return this[Sr]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Eu]],"readonly"),s=o.objectStore(this[Eu]),c=[];if(this[At].reverse){let u=!this[At].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[u](i,"prev").onsuccess=d=>{let a=d.target.result;if(a){let{key:l,value:g}=a;this[Mn]=l,c.push([this[At].keys&&l!==void 0?Ys(l):void 0,this[At].values&&g!==void 0?Ys(g):void 0]),c.length<e?a.continue():Yh(o)}else this[Sr]=!0}}else{let u,d,a=()=>{if(u===void 0||d===void 0)return;let l=Math.max(u.length,d.length);l===0||e===1/0?this[Sr]=!0:this[Mn]=u[l-1],c.length=l;for(let g=0;g<l;g++){let b=u[g],m=d[g];c[g]=[this[At].keys&&b!==void 0?Ys(b):void 0,this[At].values&&m!==void 0?Ys(m):void 0]}Yh(o)};this[At].keys||e<1/0?s.getAllKeys(i,e<1/0?e:void 0).onsuccess=l=>{u=l.target.result,a()}:(u=[],this.nextTick(a)),this[At].values?s.getAll(i,e<1/0?e:void 0).onsuccess=l=>{d=l.target.result,a()}:(d=[],this.nextTick(a))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(e){if(this[or].length>0){let[t,n]=this[or].shift();this.nextTick(e,null,t,n)}else if(this[Sr])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[Bi]&&(this[Bi]=!1,t=1),this._nextv(t,Wh,(n,i)=>{if(n)return e(n);this[or]=i,this._next(e)})}}_all(e,t){this[Bi]=!1;let n=this[or].splice(0,this[or].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(t,null,n);this._nextv(i,Wh,(o,s)=>{if(o)return t(o);n.length>0&&(s=n.concat(s)),t(null,s)})}_seek(e,t){this[Bi]=!0,this[or]=[],this[Sr]=!1,this[Mn]=void 0,this[Ir]={...this[At]};let n;try{n=Gh(this[At])}catch{this[Sr]=!0;return}n!==null&&!n.includes(e)?this[Sr]=!0:this[At].reverse?this[Ir].lte=e:this[Ir].gte=e}};Xh.Iterator=Au;function Yh(r){typeof r.commit=="function"&&r.commit()}});var ef=ae((tE,Qh)=>{"use strict";var rE=h(f());Qh.exports=function(e,t,n,i,o){if(i.limit===0)return e.nextTick(o);let s=e.db.transaction([t],"readwrite"),c=s.objectStore(t),u=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let d=c.openKeyCursor?"openKeyCursor":"openCursor",a=i.reverse?"prev":"next";c[d](n,a).onsuccess=function(l){let g=l.target.result;g&&(c.delete(g.key).onsuccess=function(){(i.limit<=0||++u<i.limit)&&g.continue()})}}});var cf=ae(sf=>{"use strict";var iE=h(f()),{AbstractLevel:eg}=xu(),tf=Ft(),tg=jh(),{fromCallback:rg}=yo(),{Iterator:ng}=Zh(),rf=vu(),ig=ef(),og=bu(),of="level-js-",Uo=Symbol("idb"),Tu=Symbol("namePrefix"),Dr=Symbol("location"),Bu=Symbol("version"),Nn=Symbol("store"),Oo=Symbol("onComplete"),nf=Symbol("promise"),Xs=class extends eg{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new tf("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=t||{};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[Dr]=e,this[Tu]=i??of,this[Bu]=parseInt(o||1,10),this[Uo]=null}get location(){return this[Dr]}get namePrefix(){return this[Tu]}get version(){return this[Bu]}get db(){return this[Uo]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Tu]+this[Dr],this[Bu]);n.onerror=function(){t(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[Uo]=n.result,t()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Dr])||o.createObjectStore(this[Dr])}}[Nn](e){return this[Uo].transaction([this[Dr]],e).objectStore(this[Dr])}[Oo](e,t){let n=e.transaction;n.onabort=function(){t(n.error||new Error("aborted by user"))},n.oncomplete=function(){t(null,e.result)}}_get(e,t,n){let i=this[Nn]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Oo](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new tf("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,rf(c))})}_getMany(e,t,n){let i=this[Nn]("readonly"),o=e.map(s=>c=>{let u;try{u=i.get(s)}catch(d){return c(d)}u.onsuccess=()=>{let d=u.result;c(null,d===void 0?d:rf(d))},u.onerror=d=>{d.stopPropagation(),c(u.error)}});tg(o,16,n)}_del(e,t,n){let i=this[Nn]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Oo](o,n)}_put(e,t,n,i){let o=this[Nn]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[Oo](s,i)}_iterator(e){return new ng(this,this[Dr],e)}_batch(e,t,n){let i=this[Nn]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function u(){let d=e[s++],a=d.key,l;try{l=d.type==="del"?i.delete(a):i.put(d.value,a)}catch(g){c=g,o.abort();return}s<e.length?l.onsuccess=u:typeof o.commit=="function"&&o.commit()}u()}_clear(e,t){let n,i;try{n=og(e)}catch{return this.nextTick(t)}if(e.limit>=0)return ig(this,this[Dr],n,e,t);try{let o=this[Nn]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(t,o)}this[Oo](i,t)}_close(e){this[Uo].close(),this.nextTick(e)}};Xs.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=of),t=rg(t,nf);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[nf]};sf.BrowserLevel=Xs});var Su=ae(af=>{var sE=h(f());af.Level=cf().BrowserLevel});var Sp=ae((Hc,Bp)=>{var KS=h(f());(function(r,e){typeof Hc=="object"&&typeof Bp<"u"?e(Hc):typeof define=="function"&&define.amd?define(["exports"],e):e(r.URI=r.URI||{})})(Hc,function(r){"use strict";function e(){for(var y=arguments.length,p=Array(y),w=0;w<y;w++)p[w]=arguments[w];if(p.length>1){p[0]=p[0].slice(0,-1);for(var v=p.length-1,A=1;A<v;++A)p[A]=p[A].slice(1,-1);return p[v]=p[v].slice(1),p.join("")}else return p[0]}function t(y){return"(?:"+y+")"}function n(y){return y===void 0?"undefined":y===null?"null":Object.prototype.toString.call(y).split(" ").pop().split("]").shift().toLowerCase()}function i(y){return y.toUpperCase()}function o(y){return y!=null?y instanceof Array?y:typeof y.length!="number"||y.split||y.setInterval||y.call?[y]:Array.prototype.slice.call(y):[]}function s(y,p){var w=y;if(p)for(var v in p)w[v]=p[v];return w}function c(y){var p="[A-Za-z]",w="[\\x0D]",v="[0-9]",A="[\\x22]",L=e(v,"[A-Fa-f]"),ie="[\\x0A]",fe="[\\x20]",ge=t(t("%[EFef]"+L+"%"+L+L+"%"+L+L)+"|"+t("%[89A-Fa-f]"+L+"%"+L+L)+"|"+t("%"+L+L)),Le="[\\:\\/\\?\\#\\[\\]\\@]",he="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",_e=e(Le,he),Me=y?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",De=y?"[\\uE000-\\uF8FF]":"[]",pe=e(p,v,"[\\-\\.\\_\\~]",Me),ke=t(p+e(p,v,"[\\+\\-\\.]")+"*"),we=t(t(ge+"|"+e(pe,he,"[\\:]"))+"*"),gn=t(t("25[0-5]")+"|"+t("2[0-4]"+v)+"|"+t("1"+v+v)+"|"+t("[1-9]"+v)+"|"+v),xt=t(t("25[0-5]")+"|"+t("2[0-4]"+v)+"|"+t("1"+v+v)+"|"+t("0?[1-9]"+v)+"|0?0?"+v),Kt=t(xt+"\\."+xt+"\\."+xt+"\\."+xt),ve=t(L+"{1,4}"),bt=t(t(ve+"\\:"+ve)+"|"+Kt),_t=t(t(ve+"\\:")+"{6}"+bt),Qt=t("\\:\\:"+t(ve+"\\:")+"{5}"+bt),wn=t(t(ve)+"?\\:\\:"+t(ve+"\\:")+"{4}"+bt),mr=t(t(t(ve+"\\:")+"{0,1}"+ve)+"?\\:\\:"+t(ve+"\\:")+"{3}"+bt),Qi=t(t(t(ve+"\\:")+"{0,2}"+ve)+"?\\:\\:"+t(ve+"\\:")+"{2}"+bt),ys=t(t(t(ve+"\\:")+"{0,3}"+ve)+"?\\:\\:"+ve+"\\:"+bt),ms=t(t(t(ve+"\\:")+"{0,4}"+ve)+"?\\:\\:"+bt),ei=t(t(t(ve+"\\:")+"{0,5}"+ve)+"?\\:\\:"+ve),ti=t(t(t(ve+"\\:")+"{0,6}"+ve)+"?\\:\\:"),gr=t([_t,Qt,wn,mr,Qi,ys,ms,ei,ti].join("|")),ri=t(t(pe+"|"+ge)+"+"),ca=t(gr+"\\%25"+ri),xn=t(gr+t("\\%25|\\%(?!"+L+"{2})")+ri),Uy=t("[vV]"+L+"+\\."+e(pe,he,"[\\:]")+"+"),Oy=t("\\["+t(xn+"|"+gr+"|"+Uy)+"\\]"),sl=t(t(ge+"|"+e(pe,he))+"*"),eo=t(Oy+"|"+Kt+"(?!"+sl+")|"+sl),to=t(v+"*"),cl=t(t(we+"@")+"?"+eo+t("\\:"+to)+"?"),ro=t(ge+"|"+e(pe,he,"[\\:\\@]")),Ky=t(ro+"*"),al=t(ro+"+"),_y=t(t(ge+"|"+e(pe,he,"[\\@]"))+"+"),wr=t(t("\\/"+Ky)+"*"),ni=t("\\/"+t(al+wr)+"?"),aa=t(_y+wr),gs=t(al+wr),ii="(?!"+ro+")",ob=t(wr+"|"+ni+"|"+aa+"|"+gs+"|"+ii),oi=t(t(ro+"|"+e("[\\/\\?]",De))+"*"),no=t(t(ro+"|[\\/\\?]")+"*"),ul=t(t("\\/\\/"+cl+wr)+"|"+ni+"|"+gs+"|"+ii),ky=t(ke+"\\:"+ul+t("\\?"+oi)+"?"+t("\\#"+no)+"?"),Cy=t(t("\\/\\/"+cl+wr)+"|"+ni+"|"+aa+"|"+ii),Ry=t(Cy+t("\\?"+oi)+"?"+t("\\#"+no)+"?"),sb=t(ky+"|"+Ry),cb=t(ke+"\\:"+ul+t("\\?"+oi)+"?"),ab="^("+ke+")\\:"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ni+"|"+gs+"|"+ii+")")+t("\\?("+oi+")")+"?"+t("\\#("+no+")")+"?$",ub="^(){0}"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ni+"|"+aa+"|"+ii+")")+t("\\?("+oi+")")+"?"+t("\\#("+no+")")+"?$",db="^("+ke+")\\:"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ni+"|"+gs+"|"+ii+")")+t("\\?("+oi+")")+"?$",lb="^"+t("\\#("+no+")")+"?$",hb="^"+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",p,v,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",pe,he),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",pe,he),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",pe,he),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",pe,he),"g"),NOT_QUERY:new RegExp(e("[^\\%]",pe,he,"[\\:\\@\\/\\?]",De),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",pe,he,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",pe,he),"g"),UNRESERVED:new RegExp(pe,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",pe,_e),"g"),PCT_ENCODED:new RegExp(ge,"g"),IPV4ADDRESS:new RegExp("^("+Kt+")$"),IPV6ADDRESS:new RegExp("^\\[?("+gr+")"+t(t("\\%25|\\%(?!"+L+"{2})")+"("+ri+")")+"?\\]?$")}}var u=c(!1),d=c(!0),a=function(){function y(p,w){var v=[],A=!0,L=!1,ie=void 0;try{for(var fe=p[Symbol.iterator](),ge;!(A=(ge=fe.next()).done)&&(v.push(ge.value),!(w&&v.length===w));A=!0);}catch(Le){L=!0,ie=Le}finally{try{!A&&fe.return&&fe.return()}finally{if(L)throw ie}}return v}return function(p,w){if(Array.isArray(p))return p;if(Symbol.iterator in Object(p))return y(p,w);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=function(y){if(Array.isArray(y)){for(var p=0,w=Array(y.length);p<y.length;p++)w[p]=y[p];return w}else return Array.from(y)},g=2147483647,b=36,m=1,x=26,E=38,S=700,U=72,T=128,_="-",D=/^xn--/,k=/[^\0-\x7E]/,C=/[\x2E\u3002\uFF0E\uFF61]/g,R={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},ee=b-m,j=Math.floor,J=String.fromCharCode;function le(y){throw new RangeError(R[y])}function de(y,p){for(var w=[],v=y.length;v--;)w[v]=p(y[v]);return w}function Xe(y,p){var w=y.split("@"),v="";w.length>1&&(v=w[0]+"@",y=w[1]),y=y.replace(C,".");var A=y.split("."),L=de(A,p).join(".");return v+L}function O(y){for(var p=[],w=0,v=y.length;w<v;){var A=y.charCodeAt(w++);if(A>=55296&&A<=56319&&w<v){var L=y.charCodeAt(w++);(L&64512)==56320?p.push(((A&1023)<<10)+(L&1023)+65536):(p.push(A),w--)}else p.push(A)}return p}var N=function(p){return String.fromCodePoint.apply(String,l(p))},Q=function(p){return p-48<10?p-22:p-65<26?p-65:p-97<26?p-97:b},K=function(p,w){return p+22+75*(p<26)-((w!=0)<<5)},I=function(p,w,v){var A=0;for(p=v?j(p/S):p>>1,p+=j(p/w);p>ee*x>>1;A+=b)p=j(p/ee);return j(A+(ee+1)*p/(p+E))},P=function(p){var w=[],v=p.length,A=0,L=T,ie=U,fe=p.lastIndexOf(_);fe<0&&(fe=0);for(var ge=0;ge<fe;++ge)p.charCodeAt(ge)>=128&&le("not-basic"),w.push(p.charCodeAt(ge));for(var Le=fe>0?fe+1:0;Le<v;){for(var he=A,_e=1,Me=b;;Me+=b){Le>=v&&le("invalid-input");var De=Q(p.charCodeAt(Le++));(De>=b||De>j((g-A)/_e))&&le("overflow"),A+=De*_e;var pe=Me<=ie?m:Me>=ie+x?x:Me-ie;if(De<pe)break;var ke=b-pe;_e>j(g/ke)&&le("overflow"),_e*=ke}var we=w.length+1;ie=I(A-he,we,he==0),j(A/we)>g-L&&le("overflow"),L+=j(A/we),A%=we,w.splice(A++,0,L)}return String.fromCodePoint.apply(String,w)},V=function(p){var w=[];p=O(p);var v=p.length,A=T,L=0,ie=U,fe=!0,ge=!1,Le=void 0;try{for(var he=p[Symbol.iterator](),_e;!(fe=(_e=he.next()).done);fe=!0){var Me=_e.value;Me<128&&w.push(J(Me))}}catch(xn){ge=!0,Le=xn}finally{try{!fe&&he.return&&he.return()}finally{if(ge)throw Le}}var De=w.length,pe=De;for(De&&w.push(_);pe<v;){var ke=g,we=!0,gn=!1,xt=void 0;try{for(var Kt=p[Symbol.iterator](),ve;!(we=(ve=Kt.next()).done);we=!0){var bt=ve.value;bt>=A&&bt<ke&&(ke=bt)}}catch(xn){gn=!0,xt=xn}finally{try{!we&&Kt.return&&Kt.return()}finally{if(gn)throw xt}}var _t=pe+1;ke-A>j((g-L)/_t)&&le("overflow"),L+=(ke-A)*_t,A=ke;var Qt=!0,wn=!1,mr=void 0;try{for(var Qi=p[Symbol.iterator](),ys;!(Qt=(ys=Qi.next()).done);Qt=!0){var ms=ys.value;if(ms<A&&++L>g&&le("overflow"),ms==A){for(var ei=L,ti=b;;ti+=b){var gr=ti<=ie?m:ti>=ie+x?x:ti-ie;if(ei<gr)break;var ri=ei-gr,ca=b-gr;w.push(J(K(gr+ri%ca,0))),ei=j(ri/ca)}w.push(J(K(ei,0))),ie=I(L,_t,pe==De),L=0,++pe}}}catch(xn){wn=!0,mr=xn}finally{try{!Qt&&Qi.return&&Qi.return()}finally{if(wn)throw mr}}++L,++A}return w.join("")},W=function(p){return Xe(p,function(w){return D.test(w)?P(w.slice(4).toLowerCase()):w})},re=function(p){return Xe(p,function(w){return k.test(w)?"xn--"+V(w):w})},X={version:"2.1.0",ucs2:{decode:O,encode:N},decode:P,encode:V,toASCII:re,toUnicode:W},Z={};function Y(y){var p=y.charCodeAt(0),w=void 0;return p<16?w="%0"+p.toString(16).toUpperCase():p<128?w="%"+p.toString(16).toUpperCase():p<2048?w="%"+(p>>6|192).toString(16).toUpperCase()+"%"+(p&63|128).toString(16).toUpperCase():w="%"+(p>>12|224).toString(16).toUpperCase()+"%"+(p>>6&63|128).toString(16).toUpperCase()+"%"+(p&63|128).toString(16).toUpperCase(),w}function ne(y){for(var p="",w=0,v=y.length;w<v;){var A=parseInt(y.substr(w+1,2),16);if(A<128)p+=String.fromCharCode(A),w+=3;else if(A>=194&&A<224){if(v-w>=6){var L=parseInt(y.substr(w+4,2),16);p+=String.fromCharCode((A&31)<<6|L&63)}else p+=y.substr(w,6);w+=6}else if(A>=224){if(v-w>=9){var ie=parseInt(y.substr(w+4,2),16),fe=parseInt(y.substr(w+7,2),16);p+=String.fromCharCode((A&15)<<12|(ie&63)<<6|fe&63)}else p+=y.substr(w,9);w+=9}else p+=y.substr(w,3),w+=3}return p}function Ie(y,p){function w(v){var A=ne(v);return A.match(p.UNRESERVED)?A:v}return y.scheme&&(y.scheme=String(y.scheme).replace(p.PCT_ENCODED,w).toLowerCase().replace(p.NOT_SCHEME,"")),y.userinfo!==void 0&&(y.userinfo=String(y.userinfo).replace(p.PCT_ENCODED,w).replace(p.NOT_USERINFO,Y).replace(p.PCT_ENCODED,i)),y.host!==void 0&&(y.host=String(y.host).replace(p.PCT_ENCODED,w).toLowerCase().replace(p.NOT_HOST,Y).replace(p.PCT_ENCODED,i)),y.path!==void 0&&(y.path=String(y.path).replace(p.PCT_ENCODED,w).replace(y.scheme?p.NOT_PATH:p.NOT_PATH_NOSCHEME,Y).replace(p.PCT_ENCODED,i)),y.query!==void 0&&(y.query=String(y.query).replace(p.PCT_ENCODED,w).replace(p.NOT_QUERY,Y).replace(p.PCT_ENCODED,i)),y.fragment!==void 0&&(y.fragment=String(y.fragment).replace(p.PCT_ENCODED,w).replace(p.NOT_FRAGMENT,Y).replace(p.PCT_ENCODED,i)),y}function Ae(y){return y.replace(/^0*(.*)/,"$1")||"0"}function Ce(y,p){var w=y.match(p.IPV4ADDRESS)||[],v=a(w,2),A=v[1];return A?A.split(".").map(Ae).join("."):y}function Pe(y,p){var w=y.match(p.IPV6ADDRESS)||[],v=a(w,3),A=v[1],L=v[2];if(A){for(var ie=A.toLowerCase().split("::").reverse(),fe=a(ie,2),ge=fe[0],Le=fe[1],he=Le?Le.split(":").map(Ae):[],_e=ge.split(":").map(Ae),Me=p.IPV4ADDRESS.test(_e[_e.length-1]),De=Me?7:8,pe=_e.length-De,ke=Array(De),we=0;we<De;++we)ke[we]=he[we]||_e[pe+we]||"";Me&&(ke[De-1]=Ce(ke[De-1],p));var gn=ke.reduce(function(_t,Qt,wn){if(!Qt||Qt==="0"){var mr=_t[_t.length-1];mr&&mr.index+mr.length===wn?mr.length++:_t.push({index:wn,length:1})}return _t},[]),xt=gn.sort(function(_t,Qt){return Qt.length-_t.length})[0],Kt=void 0;if(xt&&xt.length>1){var ve=ke.slice(0,xt.index),bt=ke.slice(xt.index+xt.length);Kt=ve.join(":")+"::"+bt.join(":")}else Kt=ke.join(":");return L&&(Kt+="%"+L),Kt}else return y}var Re=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,je="".match(/(){0}/)[1]===void 0;function Ne(y){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},w={},v=p.iri!==!1?d:u;p.reference==="suffix"&&(y=(p.scheme?p.scheme+":":"")+"//"+y);var A=y.match(Re);if(A){je?(w.scheme=A[1],w.userinfo=A[3],w.host=A[4],w.port=parseInt(A[5],10),w.path=A[6]||"",w.query=A[7],w.fragment=A[8],isNaN(w.port)&&(w.port=A[5])):(w.scheme=A[1]||void 0,w.userinfo=y.indexOf("@")!==-1?A[3]:void 0,w.host=y.indexOf("//")!==-1?A[4]:void 0,w.port=parseInt(A[5],10),w.path=A[6]||"",w.query=y.indexOf("?")!==-1?A[7]:void 0,w.fragment=y.indexOf("#")!==-1?A[8]:void 0,isNaN(w.port)&&(w.port=y.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?A[4]:void 0)),w.host&&(w.host=Pe(Ce(w.host,v),v)),w.scheme===void 0&&w.userinfo===void 0&&w.host===void 0&&w.port===void 0&&!w.path&&w.query===void 0?w.reference="same-document":w.scheme===void 0?w.reference="relative":w.fragment===void 0?w.reference="absolute":w.reference="uri",p.reference&&p.reference!=="suffix"&&p.reference!==w.reference&&(w.error=w.error||"URI is not a "+p.reference+" reference.");var L=Z[(p.scheme||w.scheme||"").toLowerCase()];if(!p.unicodeSupport&&(!L||!L.unicodeSupport)){if(w.host&&(p.domainHost||L&&L.domainHost))try{w.host=X.toASCII(w.host.replace(v.PCT_ENCODED,ne).toLowerCase())}catch(ie){w.error=w.error||"Host's domain name can not be converted to ASCII via punycode: "+ie}Ie(w,u)}else Ie(w,v);L&&L.parse&&L.parse(w,p)}else w.error=w.error||"URI can not be parsed.";return w}function yr(y,p){var w=p.iri!==!1?d:u,v=[];return y.userinfo!==void 0&&(v.push(y.userinfo),v.push("@")),y.host!==void 0&&v.push(Pe(Ce(String(y.host),w),w).replace(w.IPV6ADDRESS,function(A,L,ie){return"["+L+(ie?"%25"+ie:"")+"]"})),(typeof y.port=="number"||typeof y.port=="string")&&(v.push(":"),v.push(String(y.port))),v.length?v.join(""):void 0}var $r=/^\.\.?\//,Wi=/^\/\.(\/|$)/,us=/^\/\.\.(\/|$)/,ia=/^\/?(?:.|\n)*?(?=\/|$)/;function Vr(y){for(var p=[];y.length;)if(y.match($r))y=y.replace($r,"");else if(y.match(Wi))y=y.replace(Wi,"/");else if(y.match(us))y=y.replace(us,"/"),p.pop();else if(y==="."||y==="..")y="";else{var w=y.match(ia);if(w){var v=w[0];y=y.slice(v.length),p.push(v)}else throw new Error("Unexpected dot segment condition")}return p.join("")}function Ut(y){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},w=p.iri?d:u,v=[],A=Z[(p.scheme||y.scheme||"").toLowerCase()];if(A&&A.serialize&&A.serialize(y,p),y.host&&!w.IPV6ADDRESS.test(y.host)){if(p.domainHost||A&&A.domainHost)try{y.host=p.iri?X.toUnicode(y.host):X.toASCII(y.host.replace(w.PCT_ENCODED,ne).toLowerCase())}catch(fe){y.error=y.error||"Host's domain name can not be converted to "+(p.iri?"Unicode":"ASCII")+" via punycode: "+fe}}Ie(y,w),p.reference!=="suffix"&&y.scheme&&(v.push(y.scheme),v.push(":"));var L=yr(y,p);if(L!==void 0&&(p.reference!=="suffix"&&v.push("//"),v.push(L),y.path&&y.path.charAt(0)!=="/"&&v.push("/")),y.path!==void 0){var ie=y.path;!p.absolutePath&&(!A||!A.absolutePath)&&(ie=Vr(ie)),L===void 0&&(ie=ie.replace(/^\/\//,"/%2F")),v.push(ie)}return y.query!==void 0&&(v.push("?"),v.push(y.query)),y.fragment!==void 0&&(v.push("#"),v.push(y.fragment)),v.join("")}function Yi(y,p){var w=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},v=arguments[3],A={};return v||(y=Ne(Ut(y,w),w),p=Ne(Ut(p,w),w)),w=w||{},!w.tolerant&&p.scheme?(A.scheme=p.scheme,A.userinfo=p.userinfo,A.host=p.host,A.port=p.port,A.path=Vr(p.path||""),A.query=p.query):(p.userinfo!==void 0||p.host!==void 0||p.port!==void 0?(A.userinfo=p.userinfo,A.host=p.host,A.port=p.port,A.path=Vr(p.path||""),A.query=p.query):(p.path?(p.path.charAt(0)==="/"?A.path=Vr(p.path):((y.userinfo!==void 0||y.host!==void 0||y.port!==void 0)&&!y.path?A.path="/"+p.path:y.path?A.path=y.path.slice(0,y.path.lastIndexOf("/")+1)+p.path:A.path=p.path,A.path=Vr(A.path)),A.query=p.query):(A.path=y.path,p.query!==void 0?A.query=p.query:A.query=y.query),A.userinfo=y.userinfo,A.host=y.host,A.port=y.port),A.scheme=y.scheme),A.fragment=p.fragment,A}function ds(y,p,w){var v=s({scheme:"null"},w);return Ut(Yi(Ne(y,v),Ne(p,v),v,!0),v)}function Xi(y,p){return typeof y=="string"?y=Ut(Ne(y,p),p):n(y)==="object"&&(y=Ne(Ut(y,p),p)),y}function ls(y,p,w){return typeof y=="string"?y=Ut(Ne(y,w),w):n(y)==="object"&&(y=Ut(y,w)),typeof p=="string"?p=Ut(Ne(p,w),w):n(p)==="object"&&(p=Ut(p,w)),y===p}function hs(y,p){return y&&y.toString().replace(!p||!p.iri?u.ESCAPE:d.ESCAPE,Y)}function Ot(y,p){return y&&y.toString().replace(!p||!p.iri?u.PCT_ENCODED:d.PCT_ENCODED,ne)}var Fr={scheme:"http",domainHost:!0,parse:function(p,w){return p.host||(p.error=p.error||"HTTP URIs must have a host."),p},serialize:function(p,w){var v=String(p.scheme).toLowerCase()==="https";return(p.port===(v?443:80)||p.port==="")&&(p.port=void 0),p.path||(p.path="/"),p}},Zi={scheme:"https",domainHost:Fr.domainHost,parse:Fr.parse,serialize:Fr.serialize};function fs(y){return typeof y.secure=="boolean"?y.secure:String(y.scheme).toLowerCase()==="wss"}var mn={scheme:"ws",domainHost:!0,parse:function(p,w){var v=p;return v.secure=fs(v),v.resourceName=(v.path||"/")+(v.query?"?"+v.query:""),v.path=void 0,v.query=void 0,v},serialize:function(p,w){if((p.port===(fs(p)?443:80)||p.port==="")&&(p.port=void 0),typeof p.secure=="boolean"&&(p.scheme=p.secure?"wss":"ws",p.secure=void 0),p.resourceName){var v=p.resourceName.split("?"),A=a(v,2),L=A[0],ie=A[1];p.path=L&&L!=="/"?L:void 0,p.query=ie,p.resourceName=void 0}return p.fragment=void 0,p}},ps={scheme:"wss",domainHost:mn.domainHost,parse:mn.parse,serialize:mn.serialize},oa={},wy=!0,tl="[A-Za-z0-9\\-\\.\\_\\~"+(wy?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",Zt="[0-9A-Fa-f]",xy=t(t("%[EFef]"+Zt+"%"+Zt+Zt+"%"+Zt+Zt)+"|"+t("%[89A-Fa-f]"+Zt+"%"+Zt+Zt)+"|"+t("%"+Zt+Zt)),by="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",vy="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",Ey=e(vy,'[\\"\\\\]'),Ay="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ty=new RegExp(tl,"g"),Qn=new RegExp(xy,"g"),By=new RegExp(e("[^]",by,"[\\.]",'[\\"]',Ey),"g"),rl=new RegExp(e("[^]",tl,Ay),"g"),Sy=rl;function sa(y){var p=ne(y);return p.match(Ty)?p:y}var nl={scheme:"mailto",parse:function(p,w){var v=p,A=v.to=v.path?v.path.split(","):[];if(v.path=void 0,v.query){for(var L=!1,ie={},fe=v.query.split("&"),ge=0,Le=fe.length;ge<Le;++ge){var he=fe[ge].split("=");switch(he[0]){case"to":for(var _e=he[1].split(","),Me=0,De=_e.length;Me<De;++Me)A.push(_e[Me]);break;case"subject":v.subject=Ot(he[1],w);break;case"body":v.body=Ot(he[1],w);break;default:L=!0,ie[Ot(he[0],w)]=Ot(he[1],w);break}}L&&(v.headers=ie)}v.query=void 0;for(var pe=0,ke=A.length;pe<ke;++pe){var we=A[pe].split("@");if(we[0]=Ot(we[0]),w.unicodeSupport)we[1]=Ot(we[1],w).toLowerCase();else try{we[1]=X.toASCII(Ot(we[1],w).toLowerCase())}catch(gn){v.error=v.error||"Email address's domain name can not be converted to ASCII via punycode: "+gn}A[pe]=we.join("@")}return v},serialize:function(p,w){var v=p,A=o(p.to);if(A){for(var L=0,ie=A.length;L<ie;++L){var fe=String(A[L]),ge=fe.lastIndexOf("@"),Le=fe.slice(0,ge).replace(Qn,sa).replace(Qn,i).replace(By,Y),he=fe.slice(ge+1);try{he=w.iri?X.toUnicode(he):X.toASCII(Ot(he,w).toLowerCase())}catch(pe){v.error=v.error||"Email address's domain name can not be converted to "+(w.iri?"Unicode":"ASCII")+" via punycode: "+pe}A[L]=Le+"@"+he}v.path=A.join(",")}var _e=p.headers=p.headers||{};p.subject&&(_e.subject=p.subject),p.body&&(_e.body=p.body);var Me=[];for(var De in _e)_e[De]!==oa[De]&&Me.push(De.replace(Qn,sa).replace(Qn,i).replace(rl,Y)+"="+_e[De].replace(Qn,sa).replace(Qn,i).replace(Sy,Y));return Me.length&&(v.query=Me.join("&")),v}},Iy=/^([^\:]+)\:(.*)/,il={scheme:"urn",parse:function(p,w){var v=p.path&&p.path.match(Iy),A=p;if(v){var L=w.scheme||A.scheme||"urn",ie=v[1].toLowerCase(),fe=v[2],ge=L+":"+(w.nid||ie),Le=Z[ge];A.nid=ie,A.nss=fe,A.path=void 0,Le&&(A=Le.parse(A,w))}else A.error=A.error||"URN can not be parsed.";return A},serialize:function(p,w){var v=w.scheme||p.scheme||"urn",A=p.nid,L=v+":"+(w.nid||A),ie=Z[L];ie&&(p=ie.serialize(p,w));var fe=p,ge=p.nss;return fe.path=(A||w.nid)+":"+ge,fe}},Dy=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,ol={scheme:"urn:uuid",parse:function(p,w){var v=p;return v.uuid=v.nss,v.nss=void 0,!w.tolerant&&(!v.uuid||!v.uuid.match(Dy))&&(v.error=v.error||"UUID is not valid."),v},serialize:function(p,w){var v=p;return v.nss=(p.uuid||"").toLowerCase(),v}};Z[Fr.scheme]=Fr,Z[Zi.scheme]=Zi,Z[mn.scheme]=mn,Z[ps.scheme]=ps,Z[nl.scheme]=nl,Z[il.scheme]=il,Z[ol.scheme]=ol,r.SCHEMES=Z,r.pctEncChar=Y,r.pctDecChars=ne,r.parse=Ne,r.removeDotSegments=Vr,r.serialize=Ut,r.resolveComponents=Yi,r.resolve=ds,r.normalize=Xi,r.equal=ls,r.escapeComponent=hs,r.unescapeComponent=Ot,Object.defineProperty(r,"__esModule",{value:!0})})});var Dp=ae((FS,Ip)=>{"use strict";var HS=h(f());Ip.exports=function r(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?r(e.toJSON()):Array.isArray(e)?`[${e.reduce((i,o,s)=>`${i}${s===0?"":","}${r(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}${r(i)}:${r(e[i])}`},"")}}`}});var yy=ae((ZI,py)=>{var QI=h(f()),zi=1e3,Ji=zi*60,Gi=Ji*60,Zn=Gi*24,Qx=Zn*7,eb=Zn*365.25;py.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return tb(r);if(t==="number"&&isFinite(r))return e.long?nb(r):rb(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function tb(r){if(r=String(r),!(r.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(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*eb;case"weeks":case"week":case"w":return t*Qx;case"days":case"day":case"d":return t*Zn;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Gi;case"minutes":case"minute":case"mins":case"min":case"m":return t*Ji;case"seconds":case"second":case"secs":case"sec":case"s":return t*zi;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function rb(r){var e=Math.abs(r);return e>=Zn?Math.round(r/Zn)+"d":e>=Gi?Math.round(r/Gi)+"h":e>=Ji?Math.round(r/Ji)+"m":e>=zi?Math.round(r/zi)+"s":r+"ms"}function nb(r){var e=Math.abs(r);return e>=Zn?na(r,e,Zn,"day"):e>=Gi?na(r,e,Gi,"hour"):e>=Ji?na(r,e,Ji,"minute"):e>=zi?na(r,e,zi,"second"):r+" ms"}function na(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var ib={};xs(ib,{BearerDid:()=>ct,Did:()=>Oe,DidDht:()=>Qo,DidDhtDocument:()=>es,DidDhtRegisteredDidType:()=>wd,DidDhtRegisteredKeyType:()=>Fc,DidDhtUtils:()=>He,DidDhtVerificationRelationship:()=>xd,DidError:()=>F,DidErrorCode:()=>br,DidIon:()=>Jd,DidIonRegisteredKeyType:()=>hy,DidIonUtils:()=>yn,DidJwk:()=>Gd,DidKey:()=>Yd,DidKeyRegisteredKeyType:()=>fy,DidKeyUtils:()=>Xn,DidKeyVerificationMethodType:()=>Wd,DidMethod:()=>It,DidResolverCacheLevel:()=>Zd,DidResolverCacheNoop:()=>Qd,DidVerificationRelationship:()=>En,DidWeb:()=>Xd,EMPTY_DID_RESOLUTION_RESULT:()=>Ue,UniversalResolver:()=>el,utils:()=>nd});var d5=h(f(),1);var Tb=h(f(),1),En=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(En||{});var Sb=h(f(),1),Ue={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};var Db=h(f(),1),$e=class $e{constructor({method:e,id:t,path:n,query:i,fragment:o,params:s}){this.uri=`did:${e}:${t}`,this.method=e,this.id=t,this.path=n,this.query=i,this.fragment=o,this.params=s}static parse(e){if(!e)return null;let t=$e.DID_URI_PATTERN.exec(e);if(!t||!t.groups)return null;let{method:n,id:i,path:o,query:s,fragment:c}=t.groups,u={uri:`did:${n}:${i}`,method:n,id:i};if(o&&(u.path=o),s&&(u.query=s.slice(1)),c&&(u.fragment=c.slice(1)),s){let d={},a=s.slice(1).split("&");for(let l of a){let[g,b]=l.split("=");d[g]=b}u.params=d}return u}};$e.METHOD_PATTERN="([a-z0-9]+)",$e.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})",$e.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${$e.PCT_ENCODED_PATTERN})`,$e.METHOD_ID_PATTERN=`((?:${$e.ID_CHAR_PATTERN}*:)*(${$e.ID_CHAR_PATTERN}+))`,$e.PATH_PATTERN="(/[^#?]*)?",$e.QUERY_PATTERN="([?][^#]*)?",$e.FRAGMENT_PATTERN="(#.*)?",$e.DID_URI_PATTERN=new RegExp("^did:(?<method>"+$e.METHOD_PATTERN+"):(?<id>"+$e.METHOD_ID_PATTERN+")(?<path>"+$e.PATH_PATTERN+")(?<query>"+$e.QUERY_PATTERN+")(?<fragment>"+$e.FRAGMENT_PATTERN+")$");var Oe=$e;var Ob=h(f(),1),F=class r extends Error{constructor(t,n){super(`${t}: ${n}`);this.code=t;this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},br=(m=>(m.InvalidDid="invalidDid",m.MethodNotSupported="methodNotSupported",m.InternalError="internalError",m.InvalidDidDocument="invalidDidDocument",m.InvalidDidDocumentLength="invalidDidDocumentLength",m.InvalidDidUrl="invalidDidUrl",m.InvalidPreviousDidProof="invalidPreviousDidProof",m.InvalidPublicKey="invalidPublicKey",m.InvalidPublicKeyLength="invalidPublicKeyLength",m.InvalidPublicKeyType="invalidPublicKeyType",m.InvalidSignature="invalidSignature",m.NotFound="notFound",m.RepresentationNotSupported="representationNotSupported",m.UnsupportedPublicKeyType="unsupportedPublicKeyType",m))(br||{});var eB=h(f(),1);var g6=h(f(),1);var _b=h(f(),1);var xa;(function(r){r.AlgorithmNotSupported="algorithmNotSupported",r.EncodingError="encodingError",r.InvalidJwe="invalidJwe",r.InvalidJwk="invalidJwk",r.OperationNotSupported="operationNotSupported"})(xa||(xa={}));var gT=h(f(),1);var fE=h(f(),1);var Pb=h(f(),1),A0=h(kl(),1);var wv=h(f(),1);var ev=h(f(),1);var qb=h(f(),1);var Mb=h(f(),1),Lb=new Uint8Array(0);function Cl(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function li(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}var $b=h(f(),1);function B0(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var c=r.length,u=r.charAt(0),d=Math.log(c)/Math.log(256),a=Math.log(256)/Math.log(c);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,E=0,S=0,U=m.length;S!==U&&m[S]===0;)S++,x++;for(var T=(U-S)*a+1>>>0,_=new Uint8Array(T);S!==U;){for(var D=m[S],k=0,C=T-1;(D!==0||k<E)&&C!==-1;C--,k++)D+=256*_[C]>>>0,_[C]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");E=k,S++}for(var R=T-E;R!==T&&_[R]===0;)R++;for(var ee=u.repeat(x);R<T;++R)ee+=r.charAt(_[R]);return ee}function g(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var E=0,S=0;m[x]===u;)E++,x++;for(var U=(m.length-x)*d+1>>>0,T=new Uint8Array(U);m[x];){var _=t[m.charCodeAt(x)];if(_===255)return;for(var D=0,k=U-1;(_!==0||D<S)&&k!==-1;k--,D++)_+=c*T[k]>>>0,T[k]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=D,x++}if(m[x]!==" "){for(var C=U-S;C!==U&&T[C]===0;)C++;for(var R=new Uint8Array(E+(U-C)),ee=E;C!==U;)R[ee++]=T[C++];return R}}}function b(m){var x=g(m);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:g,decode:b}}var S0=B0,I0=S0,Rl=I0;var Ea=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Aa=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.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 Pl(this,e)}},Ta=class{decoders;constructor(e){this.decoders=e}or(e){return Pl(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 Pl(r,e){return new Ta({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ba=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ea(e,t,n),this.decoder=new Aa(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ll({name:r,prefix:e,encode:t,decode:n}){return new Ba(r,e,t,n)}function Sa({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Rl(t,r);return Ll({prefix:e,name:r,encode:n,decode:o=>li(i(o))})}function D0(r,e,t,n){let i={};for(let a=0;a<e.length;++a)i[e[a]]=a;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),c=0,u=0,d=0;for(let a=0;a<o;++a){let l=i[r[a]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|l,c+=t,c>=8&&(c-=8,s[d++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s}function U0(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,o+=e[i&c>>s];if(s!==0&&(o+=e[i&c<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function st({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ll({prefix:e,name:r,encode(i){return U0(i,n,t)},decode(i){return D0(i,n,t,r)}})}var oo=st({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zb=st({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jb=st({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gb=st({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wb=st({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yb=st({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xb=st({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zb=st({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ia=st({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var iv=h(f(),1);var lt=Sa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rv=Sa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dv=h(f(),1);var sv=st({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cv=st({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rr=st({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),av=st({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hv=h(f(),1);function Ml(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function Nl(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function hi(r){let t=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=t;return i}var so=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},$l=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=r[o]&&function(s){return new Promise(function(c,u){s=r[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(d){o({value:d,done:c})},s)}},Ts=new TextEncoder,An=new TextDecoder,M=class r{constructor(e,t){this.data=e,this.format=t}static arrayBuffer(e){return new r(e,"ArrayBuffer")}static asyncIterable(e){if(!Nl(e))throw new TypeError("Input must be of type AsyncIterable.");return new r(e,"AsyncIterable")}static base32Z(e){return new r(e,"Base32Z")}static base58Btc(e){return new r(e,"Base58Btc")}static base64Url(e){return new r(e,"Base64Url")}static bufferSource(e){return new r(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 r(e,"Hex")}static multibase(e){return new r(e,"Multibase")}static object(e){return new r(e,"Object")}static string(e){return new r(e,"String")}static uint8Array(e){return new r(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return lt.baseDecode(this.data).buffer;case"Base64Url":return rr.baseDecode(this.data).buffer;case"BufferSource":{if(hi(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Ml(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 so(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 Ia.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 lt.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return lt.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 rr.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return rr.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),t=Ts.encode(e);return rr.baseEncode(t)}case"String":{let e=Ts.encode(this.data);return rr.baseEncode(e)}case"Uint8Array":return rr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return so(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u=[];try{for(var o=!0,s=$l(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let a=i;u.push(a)}}catch(a){t={error:a}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(t)throw t.error}}return new Blob(u)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(t,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let t=this.toUint8Array();return r.uint8Array(t).toHex()}case"Base64Url":{let t=this.toUint8Array();return r.uint8Array(t).toHex()}case"Uint8Array":{let t="";for(let n=0;n<this.data.length;n++)t+=e[this.data[n]];return t}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=rr.baseDecode(this.data),t=An.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=An.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return so(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 An.decode(this.data);case"Base64Url":{let e=rr.baseDecode(this.data);return An.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return An.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return so(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u="";try{for(var o=!0,s=$l(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let d=i;typeof d=="string"?u+=d:u+=An.decode(d,{stream:!0})}}catch(d){t={error:d}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(t)throw t.error}}return u+=An.decode(void 0,{stream:!1}),u}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 Ia.baseDecode(this.data);case"Base58Btc":return lt.baseDecode(this.data);case"Base64Url":return rr.baseDecode(this.data);case"BufferSource":{let e=hi(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 t=0;t<this.data.length;t+=2){let n=parseInt(this.data.substring(t,t+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[t/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return Ts.encode(e)}case"String":return Ts.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return so(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.`)}})}};var bv=h(f(),1),co;(function(r){r.Debug="debug",r.Silent="silent"})(co||(co={}));var Da=class{constructor(){this.logLevel=co.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==co.Silent&&console.info(e)}error(e){this.logLevel!==co.Silent&&console.error(e)}},O0=new Da;typeof window<"u"&&(window.web5logger=O0);var Xv=h(f(),1);var Jv=h(f(),1);var _v=h(f(),1);var Sv=h(f(),1);var vr={};xs(vr,{decode:()=>fi,encodeTo:()=>Tn,encodingLength:()=>Bn});var Tv=h(f(),1);var Ev=h(f(),1),K0=Hl,Vl=128,_0=127,k0=~_0,C0=Math.pow(2,31);function Hl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=C0;)e[t++]=r&255|Vl,r/=128;for(;r&k0;)e[t++]=r&255|Vl,r>>>=7;return e[t]=r|0,Hl.bytes=t-n+1,e}var R0=Ua,P0=128,Fl=127;function Ua(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Ua.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Fl)<<i:(s&Fl)*Math.pow(2,i),i+=7}while(s>=P0);return Ua.bytes=o-n,t}var L0=Math.pow(2,7),M0=Math.pow(2,14),N0=Math.pow(2,21),$0=Math.pow(2,28),V0=Math.pow(2,35),F0=Math.pow(2,42),H0=Math.pow(2,49),q0=Math.pow(2,56),j0=Math.pow(2,63),z0=function(r){return r<L0?1:r<M0?2:r<N0?3:r<$0?4:r<V0?5:r<F0?6:r<H0?7:r<q0?8:r<j0?9:10},J0={encode:K0,decode:R0,encodingLength:z0},G0=J0,ao=G0;function fi(r,e=0){return[ao.decode(r,e),ao.decode.bytes]}function Tn(r,e,t=0){return ao.encode(r,e,t),e}function Bn(r){return ao.encodingLength(r)}function Oa(r,e){let t=e.byteLength,n=Bn(r),i=n+Bn(t),o=new Uint8Array(i+t);return Tn(r,o,0),Tn(t,o,n),o.set(e,i),new pi(r,t,e,o)}function ql(r){let e=li(r),[t,n]=fi(e),[i,o]=fi(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new pi(t,i,s,e)}function jl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Cl(r.bytes,t.bytes)}}var pi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Iv=h(f(),1);function zl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Y0(t,_a(r),e??lt.encoder);default:return X0(t,_a(r),e??oo.encoder)}}var Jl=new WeakMap;function _a(r){let e=Jl.get(r);if(e==null){let t=new Map;return Jl.set(r,t),t}return e}var ka=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,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:t}=this;if(e!==uo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Z0)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=Oa(e,t);return r.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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&jl(e.multihash,n.multihash)}toString(e){return zl(this,e)}toJSON(){return{"/":zl(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??Gl(n,i,o.bytes))}else if(t[Q0]===!0){let{version:n,multihash:i,code:o}=t,s=ql(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="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(t!==uo)throw new Error(`Version 0 CID must use dag-pb (code: ${uo}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=Gl(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,uo,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=li(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new pi(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,g]=fi(e.subarray(t));return t+=g,l},i=n(),o=uo;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,c=n(),u=n(),d=t+u,a=d-s;return{version:i,codec:o,multihashCode:c,digestSize:u,multihashSize:a,size:d}}static parse(e,t){let[n,i]=W0(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return _a(o).set(n,e),o}};function W0(r,e){switch(r[0]){case"Q":{let t=e??lt;return[lt.prefix,t.decode(`${lt.prefix}${r}`)]}case lt.prefix:{let t=e??lt;return[lt.prefix,t.decode(r)]}case oo.prefix:{let t=e??oo;return[oo.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Y0(r,e,t){let{prefix:n}=t;if(n!==lt.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function X0(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var uo=112,Z0=18;function Gl(r,e,t){let n=Bn(r),i=n+Bn(e),o=new Uint8Array(i+t.byteLength);return Tn(r,o,0),Tn(e,o,n),o.set(t,i),o}var Q0=Symbol.for("@ipld/js-cid/CID");var Cv=h(f(),1);var Nv=h(f(),1);var Rv=h(f(),1);var Pv=h(f(),1);var Lv=h(f(),1);var Mv=h(f(),1);var nt=class r{static addPrefix(e){var t;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=r.codeToName.has(n)?n:r.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(t=e.name)!==null&&t!==void 0?t:e.code}`);let s=vr.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),vr.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=vr.decode(t);return n}static getCodeFromName(e){let{name:t}=e,n=r.nameToCode.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static getNameFromCode(e){let{code:t}=e,n=r.codeToName.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static registerCodec(e){r.codeToName.set(e.code,e.name),r.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:t}=e,[n,i]=vr.decode(t),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:t.slice(i),name:o}}};nt.codeToName=new Map;nt.nameToCode=new Map;nt.registerCodec({code:237,name:"ed25519-pub"});nt.registerCodec({code:4864,name:"ed25519-priv"});nt.registerCodec({code:236,name:"x25519-pub"});nt.registerCodec({code:4866,name:"x25519-priv"});nt.registerCodec({code:231,name:"secp256k1-pub"});nt.registerCodec({code:4865,name:"secp256k1-priv"});var Qv=h(f(),1);function Ca(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&Ca(r[e])})}var aE=h(f(),1),sg=h(Su(),1),$n=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})};var Zs=class{constructor(){this.store=new Map}clear(){return $n(this,void 0,void 0,function*(){this.store.clear()})}close(){return $n(this,void 0,void 0,function*(){})}delete(e){return $n(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return $n(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return $n(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return $n(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return $n(this,void 0,void 0,function*(){this.store.set(e,t)})}};var lE=h(f(),1);var pA=h(f(),1);var AE=h(f(),1),sr=class{};var Y2=h(f(),1);var ec={};xs(ec,{bitGet:()=>fg,bitLen:()=>hg,bitMask:()=>Ko,bitSet:()=>pg,bytesToHex:()=>Or,bytesToNumberBE:()=>Kr,bytesToNumberLE:()=>zt,concatBytes:()=>kr,createHmacDrbg:()=>Uu,ensureBytes:()=>Te,equalBytes:()=>dg,hexToBytes:()=>Vn,hexToNumber:()=>Du,isBytes:()=>jt,numberToBytesBE:()=>ft,numberToBytesLE:()=>_r,numberToHexUnpadded:()=>hf,numberToVarBytesBE:()=>ug,utf8ToBytes:()=>lg,validateObject:()=>Pt});var TE=h(f(),1);var lf=BigInt(0),Qs=BigInt(1),cg=BigInt(2);function jt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ag=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Or(r){if(!jt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=ag[r[t]];return e}function hf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Du(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Ur={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function uf(r){if(r>=Ur._0&&r<=Ur._9)return r-Ur._0;if(r>=Ur._A&&r<=Ur._F)return r-(Ur._A-10);if(r>=Ur._a&&r<=Ur._f)return r-(Ur._a-10)}function Vn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=uf(r.charCodeAt(o)),c=uf(r.charCodeAt(o+1));if(s===void 0||c===void 0){let u=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+o)}n[i]=s*16+c}return n}function Kr(r){return Du(Or(r))}function zt(r){if(!jt(r))throw new Error("Uint8Array expected");return Du(Or(Uint8Array.from(r).reverse()))}function ft(r,e){return Vn(r.toString(16).padStart(e*2,"0"))}function _r(r,e){return ft(r,e).reverse()}function ug(r){return Vn(hf(r))}function Te(r,e,t){let n;if(typeof e=="string")try{n=Vn(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(jt(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function kr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!jt(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function dg(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function lg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function hg(r){let e;for(e=0;r>lf;r>>=Qs,e+=1);return e}function fg(r,e){return r>>BigInt(e)&Qs}var pg=(r,e,t)=>r|(t?Qs:lf)<<BigInt(e),Ko=r=>(cg<<BigInt(r-1))-Qs,Iu=r=>new Uint8Array(r),df=r=>Uint8Array.from(r);function Uu(r,e,t){if(typeof r!="number"||r<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 t!="function")throw new Error("hmacFn must be a function");let n=Iu(r),i=Iu(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),u=(l=Iu())=>{i=c(df([0]),l),n=c(),l.length!==0&&(i=c(df([1]),l),n=c())},d=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,g=[];for(;l<e;){n=c();let b=n.slice();g.push(b),l+=n.length}return kr(...g)};return(l,g)=>{s(),u(l);let b;for(;!(b=g(d()));)u();return s(),b}}var yg={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||jt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Pt(r,e,t={}){let n=(i,o,s)=>{let c=yg[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let u=r[i];if(!(s&&u===void 0)&&!c(u,r))throw new Error(`Invalid param ${String(i)}=${u} (${typeof u}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var y2=h(f(),1);var $E=h(f(),1);var PE=h(f(),1);var SE=h(f(),1);function ff(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function mg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ou(r,...e){if(!mg(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function pf(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ff(r.outputLen),ff(r.blockLen)}function Si(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function yf(r,e){Ou(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var _E=h(f(),1);var DE=h(f(),1),tc=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function mf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var rc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Jt=(r,e)=>r<<32-e|r>>>e,gg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!gg)throw new Error("Non little-endian hardware is not supported");function Ku(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function _o(r){if(typeof r=="string"&&(r=Ku(r)),!mf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function nc(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!mf(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var Ii=class{clone(){return this._cloneInto()}},OE={}.toString;function ic(r){let e=n=>r().update(_o(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ko(r=32){if(tc&&typeof tc.getRandomValues=="function")return tc.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function wg(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),c=Number(t&o),u=n?4:0,d=n?0:4;r.setUint32(e+u,s,n),r.setUint32(e+d,c,n)}var Di=class extends Ii{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,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=rc(this.buffer)}update(e){Si(this);let{view:t,buffer:n,blockLen:i}=this;e=_o(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let u=rc(e);for(;i<=o-s;s+=i)this.process(u,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Si(this),yf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;wg(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=rc(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,a=this.get();if(d>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)c.setUint32(4*l,a[l],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,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%t&&e.buffer.set(n),e}};var xg=(r,e,t)=>r&e^~r&t,bg=(r,e,t)=>r&e^r&t^e&t,vg=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]),Qr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),en=new Uint32Array(64),_u=class extends Di{constructor(){super(64,32,8,!1),this.A=Qr[0]|0,this.B=Qr[1]|0,this.C=Qr[2]|0,this.D=Qr[3]|0,this.E=Qr[4]|0,this.F=Qr[5]|0,this.G=Qr[6]|0,this.H=Qr[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:c,H:u}=this;return[e,t,n,i,o,s,c,u]}set(e,t,n,i,o,s,c,u){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=u|0}process(e,t){for(let l=0;l<16;l++,t+=4)en[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let g=en[l-15],b=en[l-2],m=Jt(g,7)^Jt(g,18)^g>>>3,x=Jt(b,17)^Jt(b,19)^b>>>10;en[l]=x+en[l-7]+m+en[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:u,G:d,H:a}=this;for(let l=0;l<64;l++){let g=Jt(c,6)^Jt(c,11)^Jt(c,25),b=a+g+xg(c,u,d)+vg[l]+en[l]|0,x=(Jt(n,2)^Jt(n,13)^Jt(n,22))+bg(n,i,o)|0;a=d,d=u,u=c,c=s+b|0,s=o,o=i,i=n,n=b+x|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,u=u+this.F|0,d=d+this.G|0,a=a+this.H|0,this.set(n,i,o,s,c,u,d,a)}roundClean(){en.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var oc=ic(()=>new _u);var FE=h(f(),1);var Ve=BigInt(0),Ke=BigInt(1),Fn=BigInt(2),Eg=BigInt(3),ku=BigInt(4),gf=BigInt(5),wf=BigInt(8),Ag=BigInt(9),Tg=BigInt(16);function ye(r,e){let t=r%e;return t>=Ve?t:e+t}function Cu(r,e,t){if(t<=Ve||e<Ve)throw new Error("Expected power/modulo > 0");if(t===Ke)return Ve;let n=Ke;for(;e>Ve;)e&Ke&&(n=n*r%t),r=r*r%t,e>>=Ke;return n}function Be(r,e,t){let n=r;for(;e-- >Ve;)n*=n,n%=t;return n}function sc(r,e){if(r===Ve||e<=Ve)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=ye(r,e),n=e,i=Ve,o=Ke,s=Ke,c=Ve;for(;t!==Ve;){let d=n/t,a=n%t,l=i-s*d,g=o-c*d;n=t,t=a,i=s,o=c,s=l,c=g}if(n!==Ke)throw new Error("invert: does not exist");return ye(i,e)}function Bg(r){let e=(r-Ke)/Fn,t,n,i;for(t=r-Ke,n=0;t%Fn===Ve;t/=Fn,n++);for(i=Fn;i<r&&Cu(i,e,r)!==r-Ke;i++);if(n===1){let s=(r+Ke)/ku;return function(u,d){let a=u.pow(d,s);if(!u.eql(u.sqr(a),d))throw new Error("Cannot find square root");return a}}let o=(t+Ke)/Fn;return function(c,u){if(c.pow(u,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let d=n,a=c.pow(c.mul(c.ONE,i),t),l=c.pow(u,o),g=c.pow(u,t);for(;!c.eql(g,c.ONE);){if(c.eql(g,c.ZERO))return c.ZERO;let b=1;for(let x=c.sqr(g);b<d&&!c.eql(x,c.ONE);b++)x=c.sqr(x);let m=c.pow(a,Ke<<BigInt(d-b-1));a=c.sqr(m),l=c.mul(l,m),g=c.mul(g,a),d=b}return l}}function Sg(r){if(r%ku===Eg){let e=(r+Ke)/ku;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(r%wf===gf){let e=(r-gf)/wf;return function(n,i){let o=n.mul(i,Fn),s=n.pow(o,e),c=n.mul(i,s),u=n.mul(n.mul(c,Fn),s),d=n.mul(c,n.sub(u,n.ONE));if(!n.eql(n.sqr(d),i))throw new Error("Cannot find square root");return d}}return r%Tg,Bg(r)}var xf=(r,e)=>(ye(r,e)&Ke)===Ke,Ig=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ru(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Ig.reduce((n,i)=>(n[i]="function",n),e);return Pt(r,t)}function Dg(r,e,t){if(t<Ve)throw new Error("Expected power > 0");if(t===Ve)return r.ONE;if(t===Ke)return e;let n=r.ONE,i=e;for(;t>Ve;)t&Ke&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ke;return n}function Ug(r,e){let t=new Array(e.length),n=e.reduce((o,s,c)=>r.is0(s)?o:(t[c]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,c)=>r.is0(s)?o:(t[c]=r.mul(o,t[c]),r.mul(o,s)),i),t}function Pu(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ui(r,e,t=!1,n={}){if(r<=Ve)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Pu(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Sg(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Ko(i),ZERO:Ve,ONE:Ke,create:u=>ye(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof u}`);return Ve<=u&&u<r},is0:u=>u===Ve,isOdd:u=>(u&Ke)===Ke,neg:u=>ye(-u,r),eql:(u,d)=>u===d,sqr:u=>ye(u*u,r),add:(u,d)=>ye(u+d,r),sub:(u,d)=>ye(u-d,r),mul:(u,d)=>ye(u*d,r),pow:(u,d)=>Dg(c,u,d),div:(u,d)=>ye(u*sc(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>sc(u,r),sqrt:n.sqrt||(u=>s(c,u)),invertBatch:u=>Ug(c,u),cmov:(u,d,a)=>a?d:u,toBytes:u=>t?_r(u,o):ft(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return t?zt(u):Kr(u)}});return Object.freeze(c)}function bf(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function vf(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Lu(r){let e=vf(r);return e+Math.ceil(e/2)}function Ef(r,e,t=!1){let n=r.length,i=vf(e),o=Lu(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Kr(r):zt(r),c=ye(s,e-Ke)+Ke;return t?_r(c,i):ft(c,i)}var QE=h(f(),1);var zE=h(f(),1);var Kg=BigInt(0),Mu=BigInt(1);function cc(r,e){let t=(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:t,unsafeLadder(i,o){let s=r.ZERO,c=i;for(;o>Kg;)o&Mu&&(s=s.add(c)),c=c.double(),o>>=Mu;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),u=[],d=i,a=d;for(let l=0;l<s;l++){a=d,u.push(a);for(let g=1;g<c;g++)a=a.add(d),u.push(a);d=a.double()}return u},wNAF(i,o,s){let{windows:c,windowSize:u}=n(i),d=r.ZERO,a=r.BASE,l=BigInt(2**i-1),g=2**i,b=BigInt(i);for(let m=0;m<c;m++){let x=m*u,E=Number(s&l);s>>=b,E>u&&(E-=g,s+=Mu);let S=x,U=x+Math.abs(E)-1,T=m%2!==0,_=E<0;E===0?a=a.add(t(T,o[S])):d=d.add(t(_,o[U]))}return{p:d,f:a}},wNAFCached(i,o,s,c){let u=i._WINDOW_SIZE||1,d=o.get(i);return d||(d=this.precomputeWindow(i,u),u!==1&&o.set(i,c(d))),this.wNAF(u,d,s)}}}function Co(r){return Ru(r.Fp),Pt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pu(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function _g(r){let e=Co(r);Pt(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:kg,hexToBytes:Cg}=ec,Hn={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Hn;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)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:kg(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Hn,t=typeof r=="string"?Cg(r):r;if(!jt(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=Hn._parseInt(t.subarray(2)),{d:s,l:c}=Hn._parseInt(o);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=d=>Number.parseInt(d[0],16)&8?"00"+d:d,t=d=>{let a=d.toString(16);return a.length&1?`0${a}`:a},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,c=t(o),u=t(s);return`30${t(s+o+4)}02${u}${i}02${c}${n}`}},Cr=BigInt(0),Lt=BigInt(1),YE=BigInt(2),Af=BigInt(3),XE=BigInt(4);function Rg(r){let e=_g(r),{Fp:t}=e,n=e.toBytes||((m,x,E)=>{let S=x.toAffine();return kr(Uint8Array.from([4]),t.toBytes(S.x),t.toBytes(S.y))}),i=e.fromBytes||(m=>{let x=m.subarray(1),E=t.fromBytes(x.subarray(0,t.BYTES)),S=t.fromBytes(x.subarray(t.BYTES,2*t.BYTES));return{x:E,y:S}});function o(m){let{a:x,b:E}=e,S=t.sqr(m),U=t.mul(S,m);return t.add(t.add(U,t.mul(m,x)),E)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(m){return typeof m=="bigint"&&Cr<m&&m<e.n}function c(m){if(!s(m))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function u(m){let{allowedPrivateKeyLengths:x,nByteLength:E,wrapPrivateKey:S,n:U}=e;if(x&&typeof m!="bigint"){if(jt(m)&&(m=Or(m)),typeof m!="string"||!x.includes(m.length))throw new Error("Invalid key");m=m.padStart(E*2,"0")}let T;try{T=typeof m=="bigint"?m:Kr(Te("private key",m,E))}catch{throw new Error(`private key must be ${E} bytes, hex or bigint, not ${typeof m}`)}return S&&(T=ye(T,U)),c(T),T}let d=new Map;function a(m){if(!(m instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(x,E,S){if(this.px=x,this.py=E,this.pz=S,x==null||!t.isValid(x))throw new Error("x required");if(E==null||!t.isValid(E))throw new Error("y required");if(S==null||!t.isValid(S))throw new Error("z required")}static fromAffine(x){let{x:E,y:S}=x||{};if(!x||!t.isValid(E)||!t.isValid(S))throw new Error("invalid affine point");if(x instanceof l)throw new Error("projective point not allowed");let U=T=>t.eql(T,t.ZERO);return U(E)&&U(S)?l.ZERO:new l(E,S,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){let E=t.invertBatch(x.map(S=>S.pz));return x.map((S,U)=>S.toAffine(E[U])).map(l.fromAffine)}static fromHex(x){let E=l.fromAffine(i(Te("pointHex",x)));return E.assertValidity(),E}static fromPrivateKey(x){return l.BASE.multiply(u(x))}_setWindowSize(x){this._WINDOW_SIZE=x,d.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x,y:E}=this.toAffine();if(!t.isValid(x)||!t.isValid(E))throw new Error("bad point: x or y not FE");let S=t.sqr(E),U=o(x);if(!t.eql(S,U))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:x}=this.toAffine();if(t.isOdd)return!t.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){a(x);let{px:E,py:S,pz:U}=this,{px:T,py:_,pz:D}=x,k=t.eql(t.mul(E,D),t.mul(T,U)),C=t.eql(t.mul(S,D),t.mul(_,U));return k&&C}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:x,b:E}=e,S=t.mul(E,Af),{px:U,py:T,pz:_}=this,D=t.ZERO,k=t.ZERO,C=t.ZERO,R=t.mul(U,U),ee=t.mul(T,T),j=t.mul(_,_),J=t.mul(U,T);return J=t.add(J,J),C=t.mul(U,_),C=t.add(C,C),D=t.mul(x,C),k=t.mul(S,j),k=t.add(D,k),D=t.sub(ee,k),k=t.add(ee,k),k=t.mul(D,k),D=t.mul(J,D),C=t.mul(S,C),j=t.mul(x,j),J=t.sub(R,j),J=t.mul(x,J),J=t.add(J,C),C=t.add(R,R),R=t.add(C,R),R=t.add(R,j),R=t.mul(R,J),k=t.add(k,R),j=t.mul(T,_),j=t.add(j,j),R=t.mul(j,J),D=t.sub(D,R),C=t.mul(j,ee),C=t.add(C,C),C=t.add(C,C),new l(D,k,C)}add(x){a(x);let{px:E,py:S,pz:U}=this,{px:T,py:_,pz:D}=x,k=t.ZERO,C=t.ZERO,R=t.ZERO,ee=e.a,j=t.mul(e.b,Af),J=t.mul(E,T),le=t.mul(S,_),de=t.mul(U,D),Xe=t.add(E,S),O=t.add(T,_);Xe=t.mul(Xe,O),O=t.add(J,le),Xe=t.sub(Xe,O),O=t.add(E,U);let N=t.add(T,D);return O=t.mul(O,N),N=t.add(J,de),O=t.sub(O,N),N=t.add(S,U),k=t.add(_,D),N=t.mul(N,k),k=t.add(le,de),N=t.sub(N,k),R=t.mul(ee,O),k=t.mul(j,de),R=t.add(k,R),k=t.sub(le,R),R=t.add(le,R),C=t.mul(k,R),le=t.add(J,J),le=t.add(le,J),de=t.mul(ee,de),O=t.mul(j,O),le=t.add(le,de),de=t.sub(J,de),de=t.mul(ee,de),O=t.add(O,de),J=t.mul(le,O),C=t.add(C,J),J=t.mul(N,O),k=t.mul(Xe,k),k=t.sub(k,J),J=t.mul(Xe,le),R=t.mul(N,R),R=t.add(R,J),new l(k,C,R)}subtract(x){return this.add(x.negate())}is0(){return this.equals(l.ZERO)}wNAF(x){return b.wNAFCached(this,d,x,E=>{let S=t.invertBatch(E.map(U=>U.pz));return E.map((U,T)=>U.toAffine(S[T])).map(l.fromAffine)})}multiplyUnsafe(x){let E=l.ZERO;if(x===Cr)return E;if(c(x),x===Lt)return this;let{endo:S}=e;if(!S)return b.unsafeLadder(this,x);let{k1neg:U,k1:T,k2neg:_,k2:D}=S.splitScalar(x),k=E,C=E,R=this;for(;T>Cr||D>Cr;)T&Lt&&(k=k.add(R)),D&Lt&&(C=C.add(R)),R=R.double(),T>>=Lt,D>>=Lt;return U&&(k=k.negate()),_&&(C=C.negate()),C=new l(t.mul(C.px,S.beta),C.py,C.pz),k.add(C)}multiply(x){c(x);let E=x,S,U,{endo:T}=e;if(T){let{k1neg:_,k1:D,k2neg:k,k2:C}=T.splitScalar(E),{p:R,f:ee}=this.wNAF(D),{p:j,f:J}=this.wNAF(C);R=b.constTimeNegate(_,R),j=b.constTimeNegate(k,j),j=new l(t.mul(j.px,T.beta),j.py,j.pz),S=R.add(j),U=ee.add(J)}else{let{p:_,f:D}=this.wNAF(E);S=_,U=D}return l.normalizeZ([S,U])[0]}multiplyAndAddUnsafe(x,E,S){let U=l.BASE,T=(D,k)=>k===Cr||k===Lt||!D.equals(U)?D.multiplyUnsafe(k):D.multiply(k),_=T(this,E).add(T(x,S));return _.is0()?void 0:_}toAffine(x){let{px:E,py:S,pz:U}=this,T=this.is0();x==null&&(x=T?t.ONE:t.inv(U));let _=t.mul(E,x),D=t.mul(S,x),k=t.mul(U,x);if(T)return{x:t.ZERO,y:t.ZERO};if(!t.eql(k,t.ONE))throw new Error("invZ was invalid");return{x:_,y:D}}isTorsionFree(){let{h:x,isTorsionFree:E}=e;if(x===Lt)return!0;if(E)return E(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:x,clearCofactor:E}=e;return x===Lt?this:E?E(l,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return this.assertValidity(),n(l,this,x)}toHex(x=!0){return Or(this.toRawBytes(x))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let g=e.nBitLength,b=cc(l,e.endo?Math.ceil(g/2):g);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:o,isWithinCurveOrder:s}}function Pg(r){let e=Co(r);return Pt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Tf(r){let e=Pg(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(O){return Cr<O&&O<t.ORDER}function c(O){return ye(O,n)}function u(O){return sc(O,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:g}=Rg({...e,toBytes(O,N,Q){let K=N.toAffine(),I=t.toBytes(K.x),P=kr;return Q?P(Uint8Array.from([N.hasEvenY()?2:3]),I):P(Uint8Array.from([4]),I,t.toBytes(K.y))},fromBytes(O){let N=O.length,Q=O[0],K=O.subarray(1);if(N===i&&(Q===2||Q===3)){let I=Kr(K);if(!s(I))throw new Error("Point is not on curve");let P=l(I),V=t.sqrt(P),W=(V&Lt)===Lt;return(Q&1)===1!==W&&(V=t.neg(V)),{x:I,y:V}}else if(N===o&&Q===4){let I=t.fromBytes(K.subarray(0,t.BYTES)),P=t.fromBytes(K.subarray(t.BYTES,2*t.BYTES));return{x:I,y:P}}else throw new Error(`Point of length ${N} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),b=O=>Or(ft(O,e.nByteLength));function m(O){let N=n>>Lt;return O>N}function x(O){return m(O)?c(-O):O}let E=(O,N,Q)=>Kr(O.slice(N,Q));class S{constructor(N,Q,K){this.r=N,this.s=Q,this.recovery=K,this.assertValidity()}static fromCompact(N){let Q=e.nByteLength;return N=Te("compactSignature",N,Q*2),new S(E(N,0,Q),E(N,Q,2*Q))}static fromDER(N){let{r:Q,s:K}=Hn.toSig(Te("DER",N));return new S(Q,K)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(N){return new S(this.r,this.s,N)}recoverPublicKey(N){let{r:Q,s:K,recovery:I}=this,P=C(Te("msgHash",N));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");let V=I===2||I===3?Q+e.n:Q;if(V>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let W=I&1?"03":"02",re=d.fromHex(W+b(V)),X=u(V),Z=c(-P*X),Y=c(K*X),ne=d.BASE.multiplyAndAddUnsafe(re,Z,Y);if(!ne)throw new Error("point at infinify");return ne.assertValidity(),ne}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new S(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Vn(this.toDERHex())}toDERHex(){return Hn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Vn(this.toCompactHex())}toCompactHex(){return b(this.r)+b(this.s)}}let U={isValidPrivateKey(O){try{return a(O),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let O=Lu(e.n);return Ef(e.randomBytes(O),e.n)},precompute(O=8,N=d.BASE){return N._setWindowSize(O),N.multiply(BigInt(3)),N}};function T(O,N=!0){return d.fromPrivateKey(O).toRawBytes(N)}function _(O){let N=jt(O),Q=typeof O=="string",K=(N||Q)&&O.length;return N?K===i||K===o:Q?K===2*i||K===2*o:O instanceof d}function D(O,N,Q=!0){if(_(O))throw new Error("first arg must be private key");if(!_(N))throw new Error("second arg must be public key");return d.fromHex(N).multiply(a(O)).toRawBytes(Q)}let k=e.bits2int||function(O){let N=Kr(O),Q=O.length*8-e.nBitLength;return Q>0?N>>BigInt(Q):N},C=e.bits2int_modN||function(O){return c(k(O))},R=Ko(e.nBitLength);function ee(O){if(typeof O!="bigint")throw new Error("bigint expected");if(!(Cr<=O&&O<R))throw new Error(`bigint expected < 2^${e.nBitLength}`);return ft(O,e.nByteLength)}function j(O,N,Q=J){if(["recovered","canonical"].some(Ae=>Ae in Q))throw new Error("sign() legacy options not supported");let{hash:K,randomBytes:I}=e,{lowS:P,prehash:V,extraEntropy:W}=Q;P==null&&(P=!0),O=Te("msgHash",O),V&&(O=Te("prehashed msgHash",K(O)));let re=C(O),X=a(N),Z=[ee(X),ee(re)];if(W!=null){let Ae=W===!0?I(t.BYTES):W;Z.push(Te("extraEntropy",Ae))}let Y=kr(...Z),ne=re;function Ie(Ae){let Ce=k(Ae);if(!g(Ce))return;let Pe=u(Ce),Re=d.BASE.multiply(Ce).toAffine(),je=c(Re.x);if(je===Cr)return;let Ne=c(Pe*c(ne+je*X));if(Ne===Cr)return;let yr=(Re.x===je?0:2)|Number(Re.y&Lt),$r=Ne;return P&&m(Ne)&&($r=x(Ne),yr^=1),new S(je,$r,yr)}return{seed:Y,k2sig:Ie}}let J={lowS:e.lowS,prehash:!1},le={lowS:e.lowS,prehash:!1};function de(O,N,Q=J){let{seed:K,k2sig:I}=j(O,N,Q),P=e;return Uu(P.hash.outputLen,P.nByteLength,P.hmac)(K,I)}d.BASE._setWindowSize(8);function Xe(O,N,Q,K=le){let I=O;if(N=Te("msgHash",N),Q=Te("publicKey",Q),"strict"in K)throw new Error("options.strict was renamed to lowS");let{lowS:P,prehash:V}=K,W,re;try{if(typeof I=="string"||jt(I))try{W=S.fromDER(I)}catch(Re){if(!(Re instanceof Hn.Err))throw Re;W=S.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){let{r:Re,s:je}=I;W=new S(Re,je)}else throw new Error("PARSE");re=d.fromHex(Q)}catch(Re){if(Re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&W.hasHighS())return!1;V&&(N=e.hash(N));let{r:X,s:Z}=W,Y=C(N),ne=u(Z),Ie=c(Y*ne),Ae=c(X*ne),Ce=d.BASE.multiplyAndAddUnsafe(re,Ie,Ae)?.toAffine();return Ce?c(Ce.x)===X:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:D,sign:de,verify:Xe,ProjectivePoint:d,Signature:S,utils:U}}var a2=h(f(),1);var n2=h(f(),1);var ac=class extends Ii{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,pf(e);let n=_o(t);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 Si(this),this.iHash.update(e),this}digestInto(e){Si(this),Ou(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:t,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=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Nu=(r,e,t)=>new ac(r,e).update(t).digest();Nu.create=(r,e)=>new ac(r,e);function Lg(r){return{hash:r,hmac:(e,...t)=>Nu(r,e,nc(...t)),randomBytes:ko}}function uc(r,e){let t=n=>Tf({...r,...Lg(n)});return Object.freeze({...t(e),create:t})}var If=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Bf=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Mg=BigInt(1),$u=BigInt(2),Sf=(r,e)=>(r+e/$u)/e;function Ng(r){let e=If,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),u=BigInt(88),d=r*r*r%e,a=d*d*r%e,l=Be(a,t,e)*a%e,g=Be(l,t,e)*a%e,b=Be(g,$u,e)*d%e,m=Be(b,i,e)*b%e,x=Be(m,o,e)*m%e,E=Be(x,c,e)*x%e,S=Be(E,u,e)*E%e,U=Be(S,c,e)*x%e,T=Be(U,t,e)*a%e,_=Be(T,s,e)*m%e,D=Be(_,n,e)*d%e,k=Be(D,$u,e);if(!Vu.eql(Vu.sqr(k),r))throw new Error("Cannot find square root");return k}var Vu=Ui(If,void 0,void 0,{sqrt:Ng}),pt=uc({a:BigInt(0),b:BigInt(7),Fp:Vu,n:Bf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Bf,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Mg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=Sf(o*r,e),u=Sf(-n*r,e),d=ye(r-c*t-u*i,e),a=ye(-c*n-u*o,e),l=d>s,g=a>s;if(l&&(d=e-d),g&&(a=e-a),d>s||a>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:d,k2neg:g,k2:a}}}},oc),h2=BigInt(0);var f2=pt.ProjectivePoint;var k2=h(f(),1);var U2=h(f(),1);var g2=h(f(),1);function $g(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Fu(r,...e){if(!$g(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Hu(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Df(r,e){Fu(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var B2=h(f(),1);var x2=h(f(),1),Oi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var lc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Gt=(r,e)=>r<<32-e|r>>>e;var E2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Vg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function qu(r){return typeof r=="string"&&(r=Vg(r)),Fu(r),r}var dc=class{clone(){return this._cloneInto()}},A2={}.toString;function Uf(r){let e=n=>r().update(qu(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Of(r=32){if(Oi&&typeof Oi.getRandomValues=="function")return Oi.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Fg(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),c=Number(t&o),u=n?4:0,d=n?0:4;r.setUint32(e+u,s,n),r.setUint32(e+d,c,n)}var Kf=(r,e,t)=>r&e^~r&t,_f=(r,e,t)=>r&e^r&t^e&t,hc=class extends dc{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,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=lc(this.buffer)}update(e){Hu(this);let{view:t,buffer:n,blockLen:i}=this;e=qu(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let u=lc(e);for(;i<=o-s;s+=i)this.process(u,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Hu(this),Df(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;Fg(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=lc(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,a=this.get();if(d>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)c.setUint32(4*l,a[l],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,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%t&&e.buffer.set(n),e}};var Hg=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]),tn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rn=new Uint32Array(64),ju=class extends hc{constructor(){super(64,32,8,!1),this.A=tn[0]|0,this.B=tn[1]|0,this.C=tn[2]|0,this.D=tn[3]|0,this.E=tn[4]|0,this.F=tn[5]|0,this.G=tn[6]|0,this.H=tn[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:c,H:u}=this;return[e,t,n,i,o,s,c,u]}set(e,t,n,i,o,s,c,u){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=u|0}process(e,t){for(let l=0;l<16;l++,t+=4)rn[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let g=rn[l-15],b=rn[l-2],m=Gt(g,7)^Gt(g,18)^g>>>3,x=Gt(b,17)^Gt(b,19)^b>>>10;rn[l]=x+rn[l-7]+m+rn[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:u,G:d,H:a}=this;for(let l=0;l<64;l++){let g=Gt(c,6)^Gt(c,11)^Gt(c,25),b=a+g+Kf(c,u,d)+Hg[l]+rn[l]|0,x=(Gt(n,2)^Gt(n,13)^Gt(n,22))+_f(n,i,o)|0;a=d,d=u,u=c,c=s+b|0,s=o,o=i,i=n,n=b+x|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,u=u+this.F|0,d=d+this.G|0,a=a+this.H|0,this.set(n,i,o,s,c,u,d,a)}roundClean(){rn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var nn=Uf(()=>new ju);var H2=h(f(),1);var R2=h(f(),1);function kf(r){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},t=e(r);return JSON.stringify(t)}var M2=h(f(),1);var qg=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Ki=class{static digest(e){return qg(this,arguments,void 0,function*({data:t}){return nn(t)})}};var jg=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},zu="urn:jwk:";function te(r){return jg(this,arguments,void 0,function*({jwk:e}){let t=e.kty,n;if(t==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(t==="oct")n={k:e.k,kty:e.kty};else if(t==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(t==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${t}`);Ca(n);let i=kf(n),o=M.string(i).toUint8Array(),s=yield Ki.digest({data:o});return M.uint8Array(s).toBase64Url()})}function cr(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r&&"d"in r)||r.kty!=="EC"||typeof r.d!="string"||typeof r.x!="string")}function _i(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r)||"d"in r||r.kty!=="EC"||typeof r.x!="string")}function ar(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r&&"d"in r)||r.kty!=="OKP"||typeof r.d!="string"||typeof r.x!="string")}function ki(r){return!(!r||typeof r!="object"||"d"in r||!("kty"in r&&"crv"in r&&"x"in r)||r.kty!=="OKP"||typeof r.x!="string")}function Cf(r){if(!r||typeof r!="object")return!1;switch(r.kty){case"EC":case"OKP":case"RSA":return"d"in r;case"oct":return"k"in r;default:return!1}}var Ze=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},zg=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(t[n[i]]=r[n[i]]);return t},Je=class r{static adjustSignatureToLowS(e){return Ze(this,arguments,void 0,function*({signature:t}){let n=pt.Signature.fromCompact(t);return n.hasHighS()?n.normalizeS().toCompactRawBytes():t})}static bytesToPrivateKey(e){return Ze(this,arguments,void 0,function*({privateKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",d:M.uint8Array(t).toBase64Url(),x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static compressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return pt.ProjectivePoint.fromHex(t).toRawBytes(!0)})}static computePublicKey(e){return Ze(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=yield r.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"secp256k1",x:M.uint8Array(i.x).toBase64Url(),y:M.uint8Array(i.y).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertDerToCompactSignature(e){return Ze(this,arguments,void 0,function*({derSignature:t}){return pt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return pt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Ze(this,void 0,void 0,function*(){let e=pt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return Ze(this,arguments,void 0,function*({key:t}){var n;if(!(cr(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=t,o=zg(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return Ze(this,arguments,void 0,function*({privateKey:t}){if(!cr(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return M.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Ze(this,arguments,void 0,function*({publicKey:t}){if(!(_i(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=M.base64Url(t.x).toUint8Array(),o=M.base64Url(t.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return Ze(this,arguments,void 0,function*({privateKeyA:t,publicKeyB:n}){if("x"in t&&"x"in n&&t.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 r.privateKeyToBytes({privateKey:t}),o=yield r.publicKeyToBytes({publicKey:n});return pt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return Ze(this,arguments,void 0,function*({data:t,key:n}){let i=yield r.privateKeyToBytes({privateKey:n}),o=nn(t);return pt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ze(this,arguments,void 0,function*({privateKeyBytes:t}){return pt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){try{pt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Ze(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t}),s=nn(i);return pt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Ze(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=pt.getPublicKey(t));let n=pt.ProjectivePoint.fromHex(t),i=ft(n.x,32),o=ft(n.y,32);return{x:i,y:o}})}};var aA=h(f(),1);var tA=h(f(),1);var Rf=Ui(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),Jg=Rf.create(BigInt("-3")),Gg=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Wg=uc({a:Jg,b:Gg,Fp:Rf,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},oc),Tt=Wg;var Qe=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Yg=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(t[n[i]]=r[n[i]]);return t},et=class r{static adjustSignatureToLowS(e){return Qe(this,arguments,void 0,function*({signature:t}){let n=Tt.Signature.fromCompact(t);return n.hasHighS()?n.normalizeS().toCompactRawBytes():t})}static bytesToPrivateKey(e){return Qe(this,arguments,void 0,function*({privateKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"P-256",d:M.uint8Array(t).toBase64Url(),x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"P-256",x:M.uint8Array(n.x).toBase64Url(),y:M.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static compressPublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){return Tt.ProjectivePoint.fromHex(t).toRawBytes(!0)})}static computePublicKey(e){return Qe(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=yield r.getCurvePoint({keyBytes:n}),o={kty:"EC",crv:"P-256",x:M.uint8Array(i.x).toBase64Url(),y:M.uint8Array(i.y).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertDerToCompactSignature(e){return Qe(this,arguments,void 0,function*({derSignature:t}){return Tt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){return Tt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Qe(this,void 0,void 0,function*(){let e=Tt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return Qe(this,arguments,void 0,function*({key:t}){var n;if(!(cr(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=t,o=Yg(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return Qe(this,arguments,void 0,function*({privateKey:t}){if(!cr(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return M.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Qe(this,arguments,void 0,function*({publicKey:t}){if(!(_i(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=M.base64Url(t.x).toUint8Array(),o=M.base64Url(t.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return Qe(this,arguments,void 0,function*({privateKeyA:t,publicKeyB:n}){if("x"in t&&"x"in n&&t.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 r.privateKeyToBytes({privateKey:t}),o=yield r.publicKeyToBytes({publicKey:n});return Tt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return Qe(this,arguments,void 0,function*({data:t,key:n}){let i=yield r.privateKeyToBytes({privateKey:n}),o=nn(t);return Tt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Qe(this,arguments,void 0,function*({privateKeyBytes:t}){return Tt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){try{Tt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Qe(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t}),s=nn(i);return Tt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Qe(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=Tt.getPublicKey(t));let n=Tt.ProjectivePoint.fromHex(t),i=ft(n.x,32),o=ft(n.y,32);return{x:i,y:o}})}};var Ro=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Po=class extends sr{computePublicKey(e){return Ro(this,arguments,void 0,function*({key:t}){if(!cr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Je.computePublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield et.computePublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return Ro(this,arguments,void 0,function*({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let n=yield Je.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield et.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return Ro(this,arguments,void 0,function*({key:t}){if(!cr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Je.getPublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield et.getPublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return Ro(this,arguments,void 0,function*({key:t,data:n}){if(!cr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return yield Je.sign({key:t,data:n});case"P-256":return yield et.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return Ro(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!_i(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return yield Je.verify({key:t,signature:n,data:i});case"P-256":return yield et.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}};var sT=h(f(),1);var tT=h(f(),1);var YA=h(f(),1);var vA=h(f(),1);var mA=h(f(),1),fc=BigInt(4294967295),Ju=BigInt(32);function Pf(r,e=!1){return e?{h:Number(r&fc),l:Number(r>>Ju&fc)}:{h:Number(r>>Ju&fc)|0,l:Number(r&fc)|0}}function Xg(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=Pf(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var Zg=(r,e)=>BigInt(r>>>0)<<Ju|BigInt(e>>>0),Qg=(r,e,t)=>r>>>t,ew=(r,e,t)=>r<<32-t|e>>>t,tw=(r,e,t)=>r>>>t|e<<32-t,rw=(r,e,t)=>r<<32-t|e>>>t,nw=(r,e,t)=>r<<64-t|e>>>t-32,iw=(r,e,t)=>r>>>t-32|e<<64-t,ow=(r,e)=>e,sw=(r,e)=>r,cw=(r,e,t)=>r<<t|e>>>32-t,aw=(r,e,t)=>e<<t|r>>>32-t,uw=(r,e,t)=>e<<t-32|r>>>64-t,dw=(r,e,t)=>r<<t-32|e>>>64-t;function lw(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var hw=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),fw=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,pw=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),yw=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,mw=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),gw=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var ww={fromBig:Pf,split:Xg,toBig:Zg,shrSH:Qg,shrSL:ew,rotrSH:tw,rotrSL:rw,rotrBH:nw,rotrBL:iw,rotr32H:ow,rotr32L:sw,rotlSH:cw,rotlSL:aw,rotlBH:uw,rotlBL:dw,add:lw,add3L:hw,add3H:fw,add4L:pw,add4H:yw,add5H:gw,add5L:mw},oe=ww;var[xw,bw]=oe.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(r=>BigInt(r))),on=new Uint32Array(80),sn=new Uint32Array(80),Gu=class extends Di{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:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:u,Eh:d,El:a,Fh:l,Fl:g,Gh:b,Gl:m,Hh:x,Hl:E}=this;return[e,t,n,i,o,s,c,u,d,a,l,g,b,m,x,E]}set(e,t,n,i,o,s,c,u,d,a,l,g,b,m,x,E){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=u|0,this.Eh=d|0,this.El=a|0,this.Fh=l|0,this.Fl=g|0,this.Gh=b|0,this.Gl=m|0,this.Hh=x|0,this.Hl=E|0}process(e,t){for(let T=0;T<16;T++,t+=4)on[T]=e.getUint32(t),sn[T]=e.getUint32(t+=4);for(let T=16;T<80;T++){let _=on[T-15]|0,D=sn[T-15]|0,k=oe.rotrSH(_,D,1)^oe.rotrSH(_,D,8)^oe.shrSH(_,D,7),C=oe.rotrSL(_,D,1)^oe.rotrSL(_,D,8)^oe.shrSL(_,D,7),R=on[T-2]|0,ee=sn[T-2]|0,j=oe.rotrSH(R,ee,19)^oe.rotrBH(R,ee,61)^oe.shrSH(R,ee,6),J=oe.rotrSL(R,ee,19)^oe.rotrBL(R,ee,61)^oe.shrSL(R,ee,6),le=oe.add4L(C,J,sn[T-7],sn[T-16]),de=oe.add4H(le,k,j,on[T-7],on[T-16]);on[T]=de|0,sn[T]=le|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:u,Dh:d,Dl:a,Eh:l,El:g,Fh:b,Fl:m,Gh:x,Gl:E,Hh:S,Hl:U}=this;for(let T=0;T<80;T++){let _=oe.rotrSH(l,g,14)^oe.rotrSH(l,g,18)^oe.rotrBH(l,g,41),D=oe.rotrSL(l,g,14)^oe.rotrSL(l,g,18)^oe.rotrBL(l,g,41),k=l&b^~l&x,C=g&m^~g&E,R=oe.add5L(U,D,C,bw[T],sn[T]),ee=oe.add5H(R,S,_,k,xw[T],on[T]),j=R|0,J=oe.rotrSH(n,i,28)^oe.rotrBH(n,i,34)^oe.rotrBH(n,i,39),le=oe.rotrSL(n,i,28)^oe.rotrBL(n,i,34)^oe.rotrBL(n,i,39),de=n&o^n&c^o&c,Xe=i&s^i&u^s&u;S=x|0,U=E|0,x=b|0,E=m|0,b=l|0,m=g|0,{h:l,l:g}=oe.add(d|0,a|0,ee|0,j|0),d=c|0,a=u|0,c=o|0,u=s|0,o=n|0,s=i|0;let O=oe.add3L(j,le,Xe);n=oe.add3H(O,ee,J,de),i=O|0}({h:n,l:i}=oe.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=oe.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:u}=oe.add(this.Ch|0,this.Cl|0,c|0,u|0),{h:d,l:a}=oe.add(this.Dh|0,this.Dl|0,d|0,a|0),{h:l,l:g}=oe.add(this.Eh|0,this.El|0,l|0,g|0),{h:b,l:m}=oe.add(this.Fh|0,this.Fl|0,b|0,m|0),{h:x,l:E}=oe.add(this.Gh|0,this.Gl|0,x|0,E|0),{h:S,l:U}=oe.add(this.Hh|0,this.Hl|0,S|0,U|0),this.set(n,i,o,s,c,u,d,a,l,g,b,m,x,E,S,U)}roundClean(){on.fill(0),sn.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 Wu=ic(()=>new Gu);var SA=h(f(),1);var Wt=BigInt(0),Bt=BigInt(1),pc=BigInt(2),vw=BigInt(8),Ew={zip215:!0};function Aw(r){let e=Co(r);return Pt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function yc(r){let e=Aw(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:u}=e,d=pc<<BigInt(c*8)-Bt,a=t.create,l=e.uvRatio||((K,I)=>{try{return{isValid:!0,value:t.sqrt(K*t.inv(I))}}catch{return{isValid:!1,value:Wt}}}),g=e.adjustScalarBytes||(K=>K),b=e.domain||((K,I,P)=>{if(I.length||P)throw new Error("Contexts/pre-hash are not supported");return K}),m=K=>typeof K=="bigint"&&Wt<K,x=(K,I)=>m(K)&&m(I)&&K<I,E=K=>K===Wt||x(K,d);function S(K,I){if(x(K,I))return K;throw new Error(`Expected valid scalar < ${I}, got ${typeof K} ${K}`)}function U(K){return K===Wt?K:S(K,n)}let T=new Map;function _(K){if(!(K instanceof D))throw new Error("ExtendedPoint expected")}class D{constructor(I,P,V,W){if(this.ex=I,this.ey=P,this.ez=V,this.et=W,!E(I))throw new Error("x required");if(!E(P))throw new Error("y required");if(!E(V))throw new Error("z required");if(!E(W))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(I){if(I instanceof D)throw new Error("extended point not allowed");let{x:P,y:V}=I||{};if(!E(P)||!E(V))throw new Error("invalid affine point");return new D(P,V,Bt,a(P*V))}static normalizeZ(I){let P=t.invertBatch(I.map(V=>V.ez));return I.map((V,W)=>V.toAffine(P[W])).map(D.fromAffine)}_setWindowSize(I){this._WINDOW_SIZE=I,T.delete(this)}assertValidity(){let{a:I,d:P}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:V,ey:W,ez:re,et:X}=this,Z=a(V*V),Y=a(W*W),ne=a(re*re),Ie=a(ne*ne),Ae=a(Z*I),Ce=a(ne*a(Ae+Y)),Pe=a(Ie+a(P*a(Z*Y)));if(Ce!==Pe)throw new Error("bad point: equation left != right (1)");let Re=a(V*W),je=a(re*X);if(Re!==je)throw new Error("bad point: equation left != right (2)")}equals(I){_(I);let{ex:P,ey:V,ez:W}=this,{ex:re,ey:X,ez:Z}=I,Y=a(P*Z),ne=a(re*W),Ie=a(V*Z),Ae=a(X*W);return Y===ne&&Ie===Ae}is0(){return this.equals(D.ZERO)}negate(){return new D(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:I}=e,{ex:P,ey:V,ez:W}=this,re=a(P*P),X=a(V*V),Z=a(pc*a(W*W)),Y=a(I*re),ne=P+V,Ie=a(a(ne*ne)-re-X),Ae=Y+X,Ce=Ae-Z,Pe=Y-X,Re=a(Ie*Ce),je=a(Ae*Pe),Ne=a(Ie*Pe),yr=a(Ce*Ae);return new D(Re,je,yr,Ne)}add(I){_(I);let{a:P,d:V}=e,{ex:W,ey:re,ez:X,et:Z}=this,{ex:Y,ey:ne,ez:Ie,et:Ae}=I;if(P===BigInt(-1)){let Yi=a((re-W)*(ne+Y)),ds=a((re+W)*(ne-Y)),Xi=a(ds-Yi);if(Xi===Wt)return this.double();let ls=a(X*pc*Ae),hs=a(Z*pc*Ie),Ot=hs+ls,Fr=ds+Yi,Zi=hs-ls,fs=a(Ot*Xi),mn=a(Fr*Zi),ps=a(Ot*Zi),oa=a(Xi*Fr);return new D(fs,mn,oa,ps)}let Ce=a(W*Y),Pe=a(re*ne),Re=a(Z*V*Ae),je=a(X*Ie),Ne=a((W+re)*(Y+ne)-Ce-Pe),yr=je-Re,$r=je+Re,Wi=a(Pe-P*Ce),us=a(Ne*yr),ia=a($r*Wi),Vr=a(Ne*Wi),Ut=a(yr*$r);return new D(us,ia,Ut,Vr)}subtract(I){return this.add(I.negate())}wNAF(I){return R.wNAFCached(this,T,I,D.normalizeZ)}multiply(I){let{p:P,f:V}=this.wNAF(S(I,n));return D.normalizeZ([P,V])[0]}multiplyUnsafe(I){let P=U(I);return P===Wt?C:this.equals(C)||P===Bt?this:this.equals(k)?this.wNAF(P).p:R.unsafeLadder(this,P)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(I){let{ex:P,ey:V,ez:W}=this,re=this.is0();I==null&&(I=re?vw:t.inv(W));let X=a(P*I),Z=a(V*I),Y=a(W*I);if(re)return{x:Wt,y:Bt};if(Y!==Bt)throw new Error("invZ was invalid");return{x:X,y:Z}}clearCofactor(){let{h:I}=e;return I===Bt?this:this.multiplyUnsafe(I)}static fromHex(I,P=!1){let{d:V,a:W}=e,re=t.BYTES;I=Te("pointHex",I,re);let X=I.slice(),Z=I[re-1];X[re-1]=Z&-129;let Y=zt(X);Y===Wt||(P?S(Y,d):S(Y,t.ORDER));let ne=a(Y*Y),Ie=a(ne-Bt),Ae=a(V*ne-W),{isValid:Ce,value:Pe}=l(Ie,Ae);if(!Ce)throw new Error("Point.fromHex: invalid y coordinate");let Re=(Pe&Bt)===Bt,je=(Z&128)!==0;if(!P&&Pe===Wt&&je)throw new Error("Point.fromHex: x=0 and x_0=1");return je!==Re&&(Pe=a(-Pe)),D.fromAffine({x:Pe,y:Y})}static fromPrivateKey(I){return J(I).point}toRawBytes(){let{x:I,y:P}=this.toAffine(),V=_r(P,t.BYTES);return V[V.length-1]|=I&Bt?128:0,V}toHex(){return Or(this.toRawBytes())}}D.BASE=new D(e.Gx,e.Gy,Bt,a(e.Gx*e.Gy)),D.ZERO=new D(Wt,Bt,Bt,Wt);let{BASE:k,ZERO:C}=D,R=cc(D,c*8);function ee(K){return ye(K,n)}function j(K){return ee(zt(K))}function J(K){let I=c;K=Te("private key",K,I);let P=Te("hashed private key",o(K),2*I),V=g(P.slice(0,I)),W=P.slice(I,2*I),re=j(V),X=k.multiply(re),Z=X.toRawBytes();return{head:V,prefix:W,scalar:re,point:X,pointBytes:Z}}function le(K){return J(K).pointBytes}function de(K=new Uint8Array,...I){let P=kr(...I);return j(o(b(P,Te("context",K),!!i)))}function Xe(K,I,P={}){K=Te("message",K),i&&(K=i(K));let{prefix:V,scalar:W,pointBytes:re}=J(I),X=de(P.context,V,K),Z=k.multiply(X).toRawBytes(),Y=de(P.context,Z,re,K),ne=ee(X+Y*W);U(ne);let Ie=kr(Z,_r(ne,t.BYTES));return Te("result",Ie,c*2)}let O=Ew;function N(K,I,P,V=O){let{context:W,zip215:re}=V,X=t.BYTES;K=Te("signature",K,2*X),I=Te("message",I),i&&(I=i(I));let Z=zt(K.slice(X,2*X)),Y,ne,Ie;try{Y=D.fromHex(P,re),ne=D.fromHex(K.slice(0,X),re),Ie=k.multiplyUnsafe(Z)}catch{return!1}if(!re&&Y.isSmallOrder())return!1;let Ae=de(W,ne.toRawBytes(),Y.toRawBytes(),I);return ne.add(Y.multiplyUnsafe(Ae)).subtract(Ie).clearCofactor().equals(D.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:le,sign:Xe,verify:N,ExtendedPoint:D,utils:{getExtendedPublicKey:J,randomPrivateKey:()=>s(t.BYTES),precompute(K=8,I=D.BASE){return I._setWindowSize(K),I.multiply(BigInt(3)),I}}}}var OA=h(f(),1);var Lo=BigInt(0),Yu=BigInt(1);function Tw(r){return Pt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Lf(r){let e=Tw(r),{P:t}=e,n=T=>ye(T,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(T=>T),u=e.powPminus2||(T=>Cu(T,t-BigInt(2),t));function d(T,_,D){let k=n(T*(_-D));return _=n(_-k),D=n(D+k),[_,D]}function a(T){if(typeof T=="bigint"&&Lo<=T&&T<t)return T;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function g(T,_){let D=a(T),k=a(_),C=D,R=Yu,ee=Lo,j=D,J=Yu,le=Lo,de;for(let O=BigInt(i-1);O>=Lo;O--){let N=k>>O&Yu;le^=N,de=d(le,R,j),R=de[0],j=de[1],de=d(le,ee,J),ee=de[0],J=de[1],le=N;let Q=R+ee,K=n(Q*Q),I=R-ee,P=n(I*I),V=K-P,W=j+J,re=j-J,X=n(re*Q),Z=n(W*I),Y=X+Z,ne=X-Z;j=n(Y*Y),J=n(C*n(ne*ne)),R=n(K*P),ee=n(V*(K+n(l*V)))}de=d(le,R,j),R=de[0],j=de[1],de=d(le,ee,J),ee=de[0],J=de[1];let Xe=u(ee);return n(R*Xe)}function b(T){return _r(n(T),o)}function m(T){let _=Te("u coordinate",T,o);return s===32&&(_[31]&=127),zt(_)}function x(T){let _=Te("scalar",T),D=_.length;if(D!==o&&D!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${D}`);return zt(c(_))}function E(T,_){let D=m(_),k=x(T),C=g(D,k);if(C===Lo)throw new Error("Invalid private or public key received");return b(C)}let S=b(e.Gu);function U(T){return E(T,S)}return{scalarMult:E,scalarMultBase:U,getSharedSecret:(T,_)=>E(T,_),getPublicKey:T=>U(T),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:S}}var Mo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Mf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),PA=BigInt(0),Bw=BigInt(1),Xu=BigInt(2),Sw=BigInt(5),Nf=BigInt(10),Iw=BigInt(20),Dw=BigInt(40),$f=BigInt(80);function Vf(r){let e=Mo,n=r*r%e*r%e,i=Be(n,Xu,e)*n%e,o=Be(i,Bw,e)*r%e,s=Be(o,Sw,e)*o%e,c=Be(s,Nf,e)*s%e,u=Be(c,Iw,e)*c%e,d=Be(u,Dw,e)*u%e,a=Be(d,$f,e)*d%e,l=Be(a,$f,e)*d%e,g=Be(l,Nf,e)*s%e;return{pow_p_5_8:Be(g,Xu,e)*r%e,b2:n}}function Ff(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Uw(r,e){let t=Mo,n=ye(e*e*e,t),i=ye(n*n*e,t),o=Vf(r*i).pow_p_5_8,s=ye(r*n*o,t),c=ye(e*s*s,t),u=s,d=ye(s*Mf,t),a=c===r,l=c===ye(-r,t),g=c===ye(-r*Mf,t);return a&&(s=u),(l||g)&&(s=d),xf(s,t)&&(s=ye(-s,t)),{isValid:a||l,value:s}}var Mt=Ui(Mo,void 0,!0),No={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Mt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Wu,randomBytes:ko,adjustScalarBytes:Ff,uvRatio:Uw},cn=yc(No);function Hf(r,e,t){if(e.length>255)throw new Error("Context is too big");return nc(Ku("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var LA=yc({...No,domain:Hf}),MA=yc({...No,domain:Hf,prehash:Wu}),qn=Lf({P:Mo,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Mo,{pow_p_5_8:t,b2:n}=Vf(r);return ye(Be(t,BigInt(3),e)*n,e)},adjustScalarBytes:Ff,randomBytes:ko});function qf(r){let{y:e}=cn.ExtendedPoint.fromHex(r),t=BigInt(1);return Mt.toBytes(Mt.create((t+e)*Mt.inv(t-e)))}function jf(r){let e=No.hash(r.subarray(0,32));return No.adjustScalarBytes(e).subarray(0,32)}var Ow=(Mt.ORDER+BigInt(3))/BigInt(8),NA=Mt.pow(Xu,Ow),$A=Mt.sqrt(Mt.neg(Mt.ONE)),VA=(Mt.ORDER-BigInt(5))/BigInt(8),FA=BigInt(486662);var HA=bf(Mt,Mt.neg(BigInt(486664)));var qA=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jA=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),zA=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),JA=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var GA=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Nt=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Kw=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(t[n[i]]=r[n[i]]);return t},Ge=class r{static bytesToPrivateKey(e){return Nt(this,arguments,void 0,function*({privateKeyBytes:t}){let n=cn.getPublicKey(t),i={crv:"Ed25519",d:M.uint8Array(t).toBase64Url(),kty:"OKP",x:M.uint8Array(n).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return Nt(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"Ed25519",x:M.uint8Array(t).toBase64Url()};return n.kid=yield te({jwk:n}),n})}static computePublicKey(e){return Nt(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=cn.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:M.uint8Array(i).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertPrivateKeyToX25519(e){return Nt(this,arguments,void 0,function*({privateKey:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=jf(n),o=qn.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:M.uint8Array(i).toBase64Url(),x:M.uint8Array(o).toBase64Url()};return s.kid=yield te({jwk:s}),s})}static convertPublicKeyToX25519(e){return Nt(this,arguments,void 0,function*({publicKey:t}){let n=yield r.publicKeyToBytes({publicKey:t});if(!(yield r.validatePublicKey({publicKeyBytes:n})))throw new Error("Ed25519: Invalid public key.");let o=qf(n),s={kty:"OKP",crv:"X25519",x:M.uint8Array(o).toBase64Url()};return s.kid=yield te({jwk:s}),s})}static generateKey(){return Nt(this,void 0,void 0,function*(){let e=cn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return Nt(this,arguments,void 0,function*({key:t}){var n;if(!(ar(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=t,o=Kw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return Nt(this,arguments,void 0,function*({privateKey:t}){if(!ar(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return M.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Nt(this,arguments,void 0,function*({publicKey:t}){if(!ki(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return M.base64Url(t.x).toUint8Array()})}static sign(e){return Nt(this,arguments,void 0,function*({key:t,data:n}){let i=yield r.privateKeyToBytes({privateKey:t});return cn.sign(n,i)})}static validatePublicKey(e){return Nt(this,arguments,void 0,function*({publicKeyBytes:t}){try{cn.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Nt(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t});return cn.verify(n,i,o)})}};var $o=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},mc=class extends sr{computePublicKey(e){return $o(this,arguments,void 0,function*({key:t}){if(!ar(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield Ge.computePublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return $o(this,arguments,void 0,function*({algorithm:t}){switch(t){case"Ed25519":{let n=yield Ge.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return $o(this,arguments,void 0,function*({key:t}){if(!ar(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield Ge.getPublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return $o(this,arguments,void 0,function*({key:t,data:n}){if(!ar(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return yield Ge.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return $o(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!ki(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return yield Ge.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}};var dT=h(f(),1);var _w=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},gc=class extends sr{digest(e){return _w(this,arguments,void 0,function*({algorithm:t,data:n}){switch(t){case"SHA-256":return yield Ki.digest({data:n})}})}};var Rr=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Zu={Ed25519:{implementation:mc,names:["Ed25519"]},secp256k1:{implementation:Po,names:["ES256K","secp256k1"]},secp256r1:{implementation:Po,names:["ES256","secp256r1"]},"SHA-256":{implementation:gc,names:["SHA-256"]}},ot=class{constructor(e){var t;this._algorithmInstances=new Map,this._keyStore=(t=e?.keyStore)!==null&&t!==void 0?t:new Zs}digest(e){return Rr(this,arguments,void 0,function*({algorithm:t,data:n}){return yield this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:n})})}exportKey(e){return Rr(this,arguments,void 0,function*({keyUri:t}){return yield this.getPrivateKey({keyUri:t})})}generateKey(e){return Rr(this,arguments,void 0,function*({algorithm:t}){let i=yield this.getAlgorithm({algorithm:t}).generateKey({algorithm:t});if(i?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let o=`${zu}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return Rr(this,arguments,void 0,function*({key:t}){let n=yield te({jwk:t});return`${zu}${n}`})}getPublicKey(e){return Rr(this,arguments,void 0,function*({keyUri:t}){let n=yield this.getPrivateKey({keyUri:t}),i=this.getAlgorithmName({key:n});return yield this.getAlgorithm({algorithm:i}).getPublicKey({key:n})})}importKey(e){return Rr(this,arguments,void 0,function*({key:t}){var n;if(!Cf(t))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let i=structuredClone(t);(n=i.kid)!==null&&n!==void 0||(i.kid=yield te({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return Rr(this,arguments,void 0,function*({keyUri:t,data:n}){let i=yield this.getPrivateKey({keyUri:t}),o=this.getAlgorithmName({key:i});return this.getAlgorithm({algorithm:o}).sign({data:n,key:i})})}verify(e){return Rr(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=this.getAlgorithmName({key:t});return this.getAlgorithm({algorithm:o}).verify({key:t,signature:n,data:i})})}getAlgorithm({algorithm:e}){var t;let n=(t=Zu[e])===null||t===void 0?void 0:t.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 t=e.alg,n=e.crv;for(let i in Zu){let o=Zu[i];if(t&&o.names.includes(t))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${t}, crv=${n}`)}getPrivateKey(e){return Rr(this,arguments,void 0,function*({keyUri:t}){let n=yield this._keyStore.get(t);if(!n)throw new Error(`Key not found: ${t}`);return n})}};var vT=h(f(),1);var wc=class r{static getJoseSignatureAlgorithmFromPublicKey(e){let t={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(t).includes(e.alg))return e.alg;if(e.crv&&Object.keys(t).includes(e.crv))return t[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(t).join(", ")}. Supported 'crv' values: ${Object.keys(t).join(", ")}.`)}static randomBytes(e){return Of(e)}static randomUuid(){return Oi.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 t=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let o=r.randomBytes(Math.ceil(e/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>t)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>t)}return n.toString().padStart(e,"0")}};var OT=h(f(),1);var BT=h(f(),1);var NT=h(f(),1);var CT=h(f(),1);var $T=h(f(),1);var VT=h(f(),1);var FT=h(f(),1);var GT=h(f(),1);var XT=h(f(),1);var e6=h(f(),1);var r6=h(f(),1);var c6=h(f(),1);var an=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},kw=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(t[n[i]]=r[n[i]]);return t},bc=class r{static bytesToPrivateKey(e){return an(this,arguments,void 0,function*({privateKeyBytes:t}){let n=qn.getPublicKey(t),i={kty:"OKP",crv:"X25519",d:M.uint8Array(t).toBase64Url(),x:M.uint8Array(n).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return an(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"X25519",x:M.uint8Array(t).toBase64Url()};return n.kid=yield te({jwk:n}),n})}static computePublicKey(e){return an(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=qn.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:M.uint8Array(i).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static generateKey(){return an(this,void 0,void 0,function*(){let e=qn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return an(this,arguments,void 0,function*({key:t}){var n;if(!(ar(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=t,o=kw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return an(this,arguments,void 0,function*({privateKey:t}){if(!ar(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return M.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return an(this,arguments,void 0,function*({publicKey:t}){if(!ki(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return M.base64Url(t.x).toUint8Array()})}static sharedSecret(e){return an(this,arguments,void 0,function*({privateKeyA:t,publicKeyB:n}){if("x"in t&&"x"in n&&t.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 r.privateKeyToBytes({privateKey:t}),o=yield r.publicKeyToBytes({publicKey:n});return qn.getSharedSecret(i,o)})}};var l6=h(f(),1);var y6=h(f(),1);var nd={};xs(nd,{extractDidFragment:()=>yt,getServices:()=>Cw,getVerificationMethodByKey:()=>Rw,getVerificationMethodTypes:()=>Qu,getVerificationMethods:()=>Vo,getVerificationRelationshipsById:()=>ed,isDidService:()=>zf,isDidVerificationMethod:()=>vc,isDwnDidService:()=>Pw,keyBytesToMultibaseId:()=>td,multibaseIdToKeyBytes:()=>rd});var W6=h(f(),1);function yt(r){if(typeof r=="string"&&r.length!==0)return r.split("#").pop()}function Cw({didDocument:r,id:e,type:t}){return r?.service?.filter(n=>!(e&&n.id!==e||t&&n.type!==t))??[]}async function Rw({didDocument:r,publicKeyJwk:e,publicKeyMultibase:t}){let n=Vo({didDocument:r});for(let i of n)if(e&&i.publicKeyJwk){if(await te({jwk:e})===await te({jwk:i.publicKeyJwk}))return i}else if(t&&i.publicKeyMultibase&&t===i.publicKeyMultibase)return i;return null}function Vo({didDocument:r}){if(!r)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...r.verificationMethod?.filter(vc)??[]),Object.keys(En).forEach(t=>{e.push(...r[t]?.filter(vc)??[])}),e}function Qu({didDocument:r}){let t=Vo({didDocument:r}).map(n=>n.type);return[...new Set(t)]}function ed({didDocument:r,methodId:e}){let t=[];return Object.keys(En).forEach(n=>{if(Array.isArray(r[n])){let i=r[n],o=yt(e);i.some(c=>{let u=yt(c)===o,d=vc(c)&&yt(c.id)===o;return u||d})&&t.push(n)}}),t}function zf(r){return!r||typeof r!="object"||r===null?!1:"id"in r&&"type"in r&&"serviceEndpoint"in r}function Pw(r){if(!zf(r)||r.type!=="DecentralizedWebNode"||!("enc"in r&&"sig"in r))return!1;let e=t=>typeof t=="string"||Array.isArray(t)&&t.every(n=>typeof n=="string");return e(r.enc)&&e(r.sig)}function vc(r){return!(!r||typeof r!="object"||r===null||!("id"in r&&"type"in r&&"controller"in r)||typeof r.id!="string"||typeof r.type!="string"||typeof r.controller!="string")}function td({keyBytes:r,multicodecCode:e,multicodecName:t}){let n=nt.addPrefix({code:e,data:r,name:t}),i=M.uint8Array(n).toBase58Btc();return M.base58Btc(i).toMultibase()}function rd({multibaseKeyId:r}){try{let e=M.multibase(r).toBase58Btc(),t=M.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=nt.removePrefix({prefixedData:t});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new F("invalidDid",`Invalid multibase identifier: ${r}`)}}var ct=class r{constructor({uri:e,document:t,metadata:n,keyManager:i}){this.uri=e,this.document=t,this.metadata=n,this.keyManager=i}async export(){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 t=[];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=await this.keyManager.getKeyUri({key:n.publicKeyJwk}),o=await this.keyManager.exportKey({keyUri:i});t.push({...o})}e.privateKeys=t}return e}async getSigner(e){let t=this.document.verificationMethod?.find(c=>yt(c.id)===(yt(e?.methodId)??yt(this.document.assertionMethod?.[0])));if(!(t&&t.publicKeyJwk))throw new F("internalError","A verification method intended for signing could not be determined from the DID Document");let n=await this.keyManager.getKeyUri({key:t.publicKeyJwk}),i=await this.keyManager.getPublicKey({keyUri:n}),o=this.keyManager;return{algorithm:wc.getJoseSignatureAlgorithmFromPublicKey(i),keyId:t.id,async sign({data:c}){return await o.sign({data:c,keyUri:n})},async verify({data:c,signature:u}){return await o.verify({data:c,key:i,signature:u})}}}static async import({portableDid:e,keyManager:t=new ot}){let n=Vo({didDocument:e.document});if(n.length===0)throw new F("invalidDidDocument","At least one verification method is required but 0 were given");for(let o of e.privateKeys??[]){let s=await t.getKeyUri({key:o});await t.getPublicKey({keyUri:s}).then(()=>!0).catch(()=>!1)||await t.importKey({key:o})}for(let o of n){if(!o.publicKeyJwk)throw new Error(`Verification method '${o.id}' does not contain a public key in JWK format`);let s=await t.getKeyUri({key:o.publicKeyJwk});await t.getPublicKey({keyUri:s})}return new r({uri:e.uri,document:e.document,metadata:e.metadata,keyManager:t})}};var nS=h(f(),1);var KB=h(f(),1);var xB=h(f(),1);var hB=h(f(),1);var rB=h(f(),1);var id="0123456789abcdef",Gf=[],Jf=[];for(let r=0;r<256;r++)Gf[r]=id[r>>4&15]+id[r&15],r<16&&(r<10?Jf[48+r]=r:Jf[87+r]=r);var od=r=>{let e=r.length,t="",n=0;for(;n<e;)t+=Gf[r[n++]];return t};var Wf=(r,e=0)=>{let t=r.length||0;if(!e){let s=t;for(;s--;)e+=r[s].length}let n=new Uint8Array(e),i=e,o=t;for(;o--;)i-=r[o].length,n.set(r[o],i);return n};var iB=h(f()),Yf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Lw=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Fo=0;Fo<Yf.length;Fo++)Lw[Yf.charCodeAt(Fo)]=Fo;var Fo;var Mw=new TextDecoder,sd=(r,e)=>e?new TextDecoder(e).decode(r):Mw.decode(r),Nw=new TextEncoder,$t=r=>Nw.encode(r);var Xf=typeof window<"u"?window:self,Zf=Xf.crypto||Xf.msCrypto||{},dB=Zf.subtle||Zf.webkitSubtle;var yB=h(f(),1);function Ci(r){let e=r<0?1:0;return r=Math.abs(Number(r||1)),Math.floor(Math.log10(r))+1+e}function Ec(r){return ArrayBuffer.isView(r)?"arraybufferview":Array.isArray(r)?"array":r instanceof Number?"number":r instanceof Boolean?"boolean":r instanceof Set?"set":r instanceof Map?"map":r instanceof String?"string":r instanceof ArrayBuffer?"arraybuffer":typeof r}function me(r,e,t){let n=[],i=null;return me._encode(n,r),i=Wf(n),me.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,t),e):i}me.bytes=-1;me._floatConversionDetected=!1;me._encode=function(r,e){if(e!=null)switch(Ec(e)){case"object":me.dict(r,e);break;case"map":me.dictMap(r,e);break;case"array":me.list(r,e);break;case"set":me.listSet(r,e);break;case"string":me.string(r,e);break;case"number":me.number(r,e);break;case"boolean":me.number(r,e);break;case"arraybufferview":me.buffer(r,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":me.buffer(r,new Uint8Array(e));break}};var Ac=new Uint8Array([101]),Qf=new Uint8Array([100]),ep=new Uint8Array([108]);me.buffer=function(r,e){r.push($t(e.length+":"),e)};me.string=function(r,e){r.push($t($t(e).byteLength+":"+e))};me.number=function(r,e){if(Number.isInteger(e))return r.push($t("i"+BigInt(e)+"e"));let t=2147483648,n=e/t<<0,i=e%t<<0,o=n*t+i;r.push($t("i"+o+"e")),o!==e&&!me._floatConversionDetected&&(me._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())};me.dict=function(r,e){r.push(Qf);let t=0,n,i=Object.keys(e).sort(),o=i.length;for(;t<o;t++)n=i[t],e[n]!=null&&(me.string(r,n),me._encode(r,e[n]));r.push(Ac)};me.dictMap=function(r,e){r.push(Qf);let t=Array.from(e.keys()).sort();for(let n of t)e.get(n)!=null&&(ArrayBuffer.isView(n)?me._encode(r,n):me.string(r,String(n)),me._encode(r,e.get(n)));r.push(Ac)};me.list=function(r,e){let t=0,n=e.length;for(r.push(ep);t<n;t++)e[t]!=null&&me._encode(r,e[t]);r.push(Ac)};me.listSet=function(r,e){r.push(ep);for(let t of e)t!=null&&me._encode(r,t);r.push(Ac)};var tp=me;var EB=h(f(),1);var $w=105,Vw=58,Fw=100,Hw=108,cd=101;function rp(r,e,t){let n=0,i=1;for(let o=e;o<t;o++){let s=r[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 G(r,e,t,n){return r==null||r.length===0?null:(typeof e!="number"&&n==null&&(n=e,e=void 0),typeof t!="number"&&n==null&&(n=t,t=void 0),G.position=0,G.encoding=n||null,G.data=ArrayBuffer.isView(r)?new Uint8Array(r.slice(e,t)):$t(r),G.bytes=G.data.length,G.next())}G.bytes=0;G.position=0;G.data=null;G.encoding=null;G.next=function(){switch(G.data[G.position]){case Fw:return G.dictionary();case Hw:return G.list();case $w:return G.integer();default:return G.buffer()}};G.find=function(r){let e=G.position,t=G.data.length,n=G.data;for(;e<t;){if(n[e]===r)return e;e++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(r)+'" [0x'+r.toString(16)+"]")};G.dictionary=function(){G.position++;let r={};for(;G.data[G.position]!==cd;){let e=G.buffer(),t=sd(e);t.includes("\uFFFD")&&(t=od(e)),r[t]=G.next()}return G.position++,r};G.list=function(){G.position++;let r=[];for(;G.data[G.position]!==cd;)r.push(G.next());return G.position++,r};G.integer=function(){let r=G.find(cd),e=rp(G.data,G.position+1,r);return G.position+=r+1-G.position,e};G.buffer=function(){let r=G.find(Vw),e=rp(G.data,G.position,r),t=++r+e;return G.position=t,G.encoding?sd(G.data.slice(r,t)):G.data.slice(r,t)};var np=G;var SB=h(f(),1);function qw(r){let e=2;for(let t of r)e+=Tc(t);return e}function jw(r){let e=2;for(let[t,n]of r){let i=$t(t).byteLength;e+=Ci(i)+1+i,e+=Tc(n)}return e}function zw(r){let e=2,t=Object.keys(r);for(let n=0;n<t.length;n++){let i=$t(t[n]).byteLength;e+=Ci(i)+1+i,e+=Tc(r[t[n]])}return e}function Jw(r){let e=$t(r).byteLength;return Ci(e)+1+e}function Gw(r){let e=r.byteLength-r.byteOffset;return Ci(e)+1+e}function Tc(r){if(r==null)return 0;let t=Ec(r);switch(t){case"arraybufferview":return Gw(r);case"string":return Jw(r);case"array":case"set":return qw(r);case"number":return 1+Ci(Math.floor(r))+1;case"bigint":return 1+r.toString().length+1;case"object":return zw(r);case"map":return jw(r);default:throw new TypeError(`Unsupported value of type "${t}"`)}}var ad=Tc;var Ww=ad,ud={encode:tp,decode:np,byteLength:ad,encodingLength:Ww};var FB=h(f(),1);var _B=h(f(),1),Yw=/^(\d{1,3}\.){3,3}\d{1,3}$/;var Xw=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var Yt={name:"v4",size:4,isFormat:r=>Yw.test(r),encode(r,e,t){t=~~t,e=e||new Uint8Array(t+4);let n=r.length,i=0;for(let o=0;o<n;){let s=r.charCodeAt(o++);s===46?(e[t++]=i,i=0):i=i*10+(s-48)}return e[t]=i,e},decode(r,e){return e=~~e,`${r[e++]}.${r[e++]}.${r[e++]}.${r[e]}`}},Pr={name:"v6",size:16,isFormat:r=>r.length>0&&Xw.test(r),encode(r,e,t){t=~~t;let n=t+16,i=-1,o=0,s=0,c=!0,u=!1;e=e||new Uint8Array(t+16);for(let d=0;d<r.length;d++){let a=r.charCodeAt(d);a===58?(c?i!==-1?(t<n&&(e[t]=0),t<n-1&&(e[t+1]=0),t+=2):t<n&&(i=t):(u===!0?(t<n&&(e[t]=s),t++):(t<n&&(e[t]=o>>8),t<n-1&&(e[t+1]=o&255),t+=2),o=0,s=0),c=!0,u=!1):a===46?(t<n&&(e[t]=s),t++,s=0,o=0,c=!1,u=!0):(c=!1,a>=97?a-=87:a>=65?a-=55:(a-=48,s=s*10+a),o=(o<<4)+a)}if(c===!1)u===!0?(t<n&&(e[t]=s),t++):(t<n&&(e[t]=o>>8),t<n-1&&(e[t+1]=o&255),t+=2);else if(i===0)t<n&&(e[t]=0),t<n-1&&(e[t+1]=0),t+=2;else if(i!==-1){t+=2;for(let d=Math.min(t-1,n-1);d>=i+2;d--)e[d]=e[d-2];e[i]=0,e[i+1]=0,i=t}if(i!==t&&i!==-1)for(t>n-2&&(t=n-2);n>i;)e[--n]=t<n&&t>i?e[--t]:0;else for(;t<n;)e[t++]=0;return e},decode(r,e){e=~~e;let t="";for(let n=0;n<16;n+=2)n!==0&&(t+=":"),t+=(r[e+n]<<8|r[e+n+1]).toString(16);return t.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};function ip(r){if(Yt.isFormat(r))return Yt.size;if(Pr.isFormat(r))return Pr.size;throw Error(`Invalid ip address: ${r}`)}function op(r){return ip(r)===Yt.size?1:2}function sp(r,e,t){t=~~t;let n=ip(r);return typeof e=="function"&&(e=e(t+n)),n===Yt.size?Yt.encode(r,e,t):Pr.encode(r,e,t)}function cp(r,e,t){if(e=~~e,t=t||r.length-e,t===Yt.size)return Yt.decode(r,e,t);if(t===Pr.size)return Pr.decode(r,e,t);throw Error(`Invalid buffer size needs to be ${Yt.size} for v4 or ${Pr.size} for v6.`)}var kB=h(f(),1);function Ho(r){switch(r){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_"+r}function Ri(r){switch(r.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 r.toUpperCase().startsWith("UNKNOWN_")?parseInt(r.slice(8)):0}var CB=h(f(),1);function ap(r){switch(r){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_"+r}var RB=h(f(),1);function up(r){switch(r){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_"+r}var PB=h(f(),1);function dd(r){switch(r){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+r}function ld(r){switch(r.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}var LB=h(f(),1);function dp(r){switch(r){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 r<0?null:`OPTION_${r}`}function hd(r){if(typeof r=="number")return r;if(!r)return-1;switch(r.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=r.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}var NB=h(f(),1);var MB=h(f(),1);function fd(r){let e=0,t=r.length;for(let n=0;n<t;n+=1){let i=r.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===t||i>=56320||(r.charCodeAt(o)&64512)!==56320?e+=3:(n=o,e+=4)}}return e}function Pi(r,e,t){let n=r.length;t==null&&(t=0),e===void 0&&(e=new Uint8Array(fd(r)+t));let i=t;for(let o=0;o<n;o+=1){let s=r.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 u=r.charCodeAt(c);(u&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(o=c,s=65536|(s&1023)<<10|u&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 Pi.bytes=i-t,e}Pi.bytes=0;function Li(r,e,t){let n="";e==null&&(e=0),t==null&&(t=r.length);for(let i=e;i<t;){let o=r[i++],s;if(o<=128)s=o;else if(o>191&&o<224)s=(o&31)<<6|r[i++]&63;else if(o>239&&o<365){s=((o&7)<<18|(r[i++]&63)<<12|(r[i++]&63)<<6|r[i++]&63)-65536;let c=55296|s>>10&1023;n+=String.fromCharCode(c),s=56320|s&1023}else s=(o&15)<<12|(r[i++]&63)<<6|r[i++]&63;n+=String.fromCharCode(s)}return Li.bytes=t-e,n}Li.bytes=0;var un=r=>r instanceof Uint8Array;function Lr(r){return typeof r=="string"?fd(r):r.byteLength}function Bc(r){return r instanceof Uint8Array?r:Array.isArray(r)?new Uint8Array(r):Pi(r)}function Sc(r,e,t){if(typeof e!="string")throw new Error("unknown input type");return Pi(e,r,t),Pi.bytes}var qo={},lp=new Array(255);for(let r=0;r<=15;r+=1){let e=r.toString(16),t=e.toUpperCase();for(let n=0;n<=15;n+=1){let i=n.toString(16),o=i.toUpperCase(),s=r<<4|n,c=`${e}${i}`;lp[s]=c,qo[c]=s,qo[`${t}${i}`]=s,qo[`${e}${o}`]=s,qo[`${t}${o}`]=s}}function hp(r,e,t){let n="";for(let i=e;i<t;){let o=r[i++];n+=lp[o]}return n}function pd(r){return r.length>>>1}function fp(r,e,t,n){let i=0;for(;t<n;){let o=e.substr(i,2),s=qo[o];if(s===void 0)return;r[t++]=s,i+=2}return r}var ox=Math.pow(2,24),sx=Math.pow(2,16),cx=Math.pow(2,8),ur=(r,e)=>r[e]*ox+r[e+1]*sx+r[e+2]*cx+r[e+3],se=(r,e)=>r[e]<<8|r[e+1],dr=(r,e,t)=>(e=+e,r[t+3]=e,e=e>>>8,r[t+2]=e,e=e>>>8,r[t+1]=e,e=e>>>8,r[t]=e,t+4),q=(r,e,t)=>(r[t]=e>>8,r[t+1]=e&255,t+2);function mt(r,e,t,n,i){return t<0&&(n-=t,t=0),n<0&&(n=0),i<0?new Uint8Array(0):t>=e.length||n>=i?0:ax(r,e,t,n,i)}function ax(r,e,t,n,i){i-n>e.length-t&&(i=n+e.length-t);let o=i-n,s=r.length-n;return o>s&&(o=s),(n!==0||i<r.length)&&(r=new Uint8Array(r.buffer,r.byteOffset+n,o)),e.set(r,t),o}var dx=0,pp=32768,md=32768,lx=~md,mp=32768,hx=~mp;function Ee({bytes:r=0,encode:e,decode:t,encodingLength:n}){return e.bytes=r,t.bytes=r,{encode:e,decode:t,encodingLength:n||(()=>r)}}var $=Ee({encode(r,e,t){e||(e=new Uint8Array($.encodingLength(r))),t||(t=0);let n=t,i=r.replace(/^\.|\.$/gm,"");if(i.length){let o=i.split(".");for(let s=0;s<o.length;s++){let c=Sc(e,o[s],t+1);e[t]=c,t+=c+1}}return e[t++]=0,$.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=[],n=e,i=0,o=0,s=!1;for(;;){if(e>=r.length)throw new Error("Cannot decode name (buffer overflow)");let c=r[e++];if(o+=s?0:1,c===0)break;if(c&192)if((c&192)===192){if(e+1>r.length)throw new Error("Cannot decode name (buffer overflow)");let u=se(r,e-1)-49152;if(u>=n)throw new Error("Cannot decode name (bad pointer)");e=u,n=u,o+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+c>r.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");t.push(Li(r,e,e+c)),e+=c,o+=s?0:c}}return $.decode.bytes=o,t.length===0?".":t.join(".")},encodingLength(r){return r==="."||r===".."?1:Lr(r.replace(/^\.|\.$/gm,""))+2}}),Fe=Ee({encode(r,e,t){e||(e=new Uint8Array(Fe.encodingLength(r))),t||(t=0);let n=Sc(e,r,t+1);return e[t]=n,Fe.encode.bytes=n+1,e},decode(r,e){e||(e=0);let t=r[e],n=Li(r,e+1,e+1+t);return Fe.decode.bytes=t+1,n},encodingLength(r){return Lr(r)+1}}),Mi=Ee({bytes:12,encode(r,e,t){e||(e=new Uint8Array(Mi.encodingLength(r))),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?pp:dx;return q(e,r.id||0,t),q(e,n|i,t+2),q(e,r.questions.length,t+4),q(e,r.answers.length,t+6),q(e,r.authorities.length,t+8),q(e,r.additionals.length,t+10),e},decode(r,e){if(e||(e=0),r.length<12)throw new Error("Header must be 12 bytes");let t=se(r,e+2);return{id:se(r,e),type:t&pp?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:up(t>>11&15),flag_aa:(t>>10&1)===1,flag_tc:(t>>9&1)===1,flag_rd:(t>>8&1)===1,flag_ra:(t>>7&1)===1,flag_z:(t>>6&1)===1,flag_ad:(t>>5&1)===1,flag_cd:(t>>4&1)===1,rcode:ap(t&15),questions:new Array(se(r,e+4)),answers:new Array(se(r,e+6)),authorities:new Array(se(r,e+8)),additionals:new Array(se(r,e+10))}},encodingLength(){return 12}}),Dc=Ee({encode(r,e,t){e||(e=new Uint8Array(Dc.encodingLength(r))),t||(t=0);let n=r.length;return q(e,n,t),mt(r,e,t+2,0,n),Dc.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=se(r,e),n=r.slice(e+2,e+2+t);return Dc.decode.bytes=t+2,n},encodingLength(r){return r.length+2}}),Uc=Ee({encode(r,e,t){return e||(e=new Uint8Array(Uc.encodingLength(r))),t||(t=0),$.encode(r,e,t+2),q(e,$.encode.bytes,t),Uc.encode.bytes=$.encode.bytes+2,e},decode(r,e){e||(e=0);let t=se(r,e),n=$.decode(r,e+2);return Uc.decode.bytes=t+2,n},encodingLength(r){return $.encodingLength(r)+2}}),Oc=Ee({encode(r,e,t){e||(e=new Uint8Array(Oc.encodingLength(r))),t||(t=0);let n=t;return t+=2,$.encode(r.mname,e,t),t+=$.encode.bytes,$.encode(r.rname,e,t),t+=$.encode.bytes,dr(e,r.serial||0,t),t+=4,dr(e,r.refresh||0,t),t+=4,dr(e,r.retry||0,t),t+=4,dr(e,r.expire||0,t),t+=4,dr(e,r.minimum||0,t),t+=4,q(e,t-n-2,n),Oc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=$.decode(r,e),e+=$.decode.bytes,n.rname=$.decode(r,e),e+=$.decode.bytes,n.serial=ur(r,e),e+=4,n.refresh=ur(r,e),e+=4,n.retry=ur(r,e),e+=4,n.expire=ur(r,e),e+=4,n.minimum=ur(r,e),e+=4,Oc.decode.bytes=e-t,n},encodingLength(r){return 22+$.encodingLength(r.mname)+$.encodingLength(r.rname)}}),Kc=Ee({encode(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=Bc(r[i])),!un(r[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Kc.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,mt(i,e,t,0,i.length),t+=i.length}),q(e,t-n-2,n),Kc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=se(r,e);e+=2;let i=[];for(;n>0;){let o=r[e++];if(--n,n<o)throw new Error("Buffer overflow");i.push(r.slice(e,e+o)),e+=o,n-=o}return Kc.decode.bytes=e-t,i},encodingLength(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=Lr(t)+1:e+=t.length+1}),e}}),_c=Ee({encode(r,e,t){e||(e=new Uint8Array(_c.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=Bc(r)),r||(r=new Uint8Array(0));let n=t;t+=2;let i=r.length;return mt(r,e,t,0,i),t+=i,q(e,t-n-2,n),_c.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=se(r,e);e+=2;let i=r.slice(e,e+n);return e+=n,_c.decode.bytes=e-t,i},encodingLength(r){return r?(un(r)?r.length:Lr(r))+2:2}}),kc=Ee({encode(r,e,t){e||(e=new Uint8Array(kc.encodingLength(r))),t||(t=0);let n=t;return t+=2,Fe.encode(r.cpu,e,t),t+=Fe.encode.bytes,Fe.encode(r.os,e,t),t+=Fe.encode.bytes,q(e,t-n-2,n),kc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=Fe.decode(r,e),e+=Fe.decode.bytes,n.os=Fe.decode(r,e),e+=Fe.decode.bytes,kc.decode.bytes=e-t,n},encodingLength(r){return Fe.encodingLength(r.cpu)+Fe.encodingLength(r.os)+2}}),Vi=Ee({encode(r,e,t){return e||(e=new Uint8Array(Vi.encodingLength(r))),t||(t=0),$.encode(r,e,t+2),q(e,$.encode.bytes,t),Vi.encode.bytes=$.encode.bytes+2,e},decode(r,e){e||(e=0);let t=$.decode(r,e+2);return Vi.decode.bytes=$.decode.bytes+2,t},encodingLength(r){return $.encodingLength(r)+2}}),Cc=Ee({encode(r,e,t){e||(e=new Uint8Array(Cc.encodingLength(r))),t||(t=0),q(e,r.priority||0,t+2),q(e,r.weight||0,t+4),q(e,r.port||0,t+6),$.encode(r.target,e,t+8);let n=$.encode.bytes+6;return q(e,n,t),Cc.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=se(r,e),n={};return n.priority=se(r,e+2),n.weight=se(r,e+4),n.port=se(r,e+6),n.target=$.decode(r,e+8),Cc.decode.bytes=t+2,n},encodingLength(r){return 8+$.encodingLength(r.target)}}),dn=Ee({encode(r,e,t){let n=dn.encodingLength(r);return e||(e=new Uint8Array(dn.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=dn.ISSUER_CRITICAL),q(e,n-2,t),t+=2,e[t]=r.flags||0,t+=1,Fe.encode(r.tag,e,t),t+=Fe.encode.bytes,Sc(e,r.value,t),t+=Lr(r.value),dn.encode.bytes=n,e},decode(r,e){e||(e=0);let t=se(r,e);e+=2;let n=e,i={};return i.flags=r[e],e+=1,i.tag=Fe.decode(r,e),e+=Fe.decode.bytes,i.value=Li(r,e,n+t),i.issuerCritical=!!(i.flags&dn.ISSUER_CRITICAL),dn.decode.bytes=t+2,i},encodingLength(r){return Fe.encodingLength(r.tag)+Fe.encodingLength(r.value)+2}});dn.ISSUER_CRITICAL=128;var Rc=Ee({encode(r,e,t){e||(e=new Uint8Array(Rc.encodingLength(r))),t||(t=0);let n=t;return t+=2,q(e,r.preference||0,t),t+=2,$.encode(r.exchange,e,t),t+=$.encode.bytes,q(e,t-n-2,n),Rc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=se(r,e),e+=2,n.exchange=$.decode(r,e),e+=$.decode.bytes,Rc.decode.bytes=e-t,n},encodingLength(r){return 4+$.encodingLength(r.exchange)}}),gp=Ee({encode(r,e,t){return e||(e=new Uint8Array(gp.encodingLength(r))),t||(t=0),q(e,4,t),t+=2,Yt.encode(r,e,t),e},decode(r,e){return e||(e=0),e+=2,Yt.decode(r,e)},bytes:6}),Pc=Ee({encode(r,e,t){return e||(e=new Uint8Array(Pc.encodingLength(r))),t||(t=0),q(e,16,t),t+=2,Pr.encode(r,e,t),Pc.encode.bytes=18,e},decode(r,e){e||(e=0),e+=2;let t=Pr.decode(r,e);return Pc.decode.bytes=18,t},bytes:18}),yp=r=>new Uint8Array(r),Mr=Ee({encode(r,e,t){e||(e=new Uint8Array(Mr.encodingLength(r))),t||(t=0);let n=t,i=hd(r.code);if(q(e,i,t),t+=2,r.data)q(e,r.data.length,t),t+=2,mt(r.data,e,t),t+=r.data.length;else switch(i){case 8:{let o=r.sourcePrefixLength||0,s=r.family||op(r.ip,yp),c=sp(r.ip,yp),u=Math.ceil(o/8);q(e,u+4,t),t+=2,q(e,s,t),t+=2,e[t++]=o,e[t++]=r.scopePrefixLength||0,mt(c,e,t,0,u),t+=u}break;case 11:r.timeout?(q(e,2,t),t+=2,q(e,r.timeout,t),t+=2):(q(e,0,t),t+=2);break;case 12:{let o=r.length||0;q(e,o,t),t+=2,e.fill(0,t,t+o),t+=o}break;case 14:{let o=r.tags.length*2;q(e,o,t),t+=2;for(let s of r.tags)q(e,s,t),t+=2}break;default:throw new Error(`Unknown roption code: ${r.code}`)}return Mr.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={};t.code=se(r,e),t.type=dp(t.code),e+=2;let n=se(r,e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=se(r,e),e+=2,t.sourcePrefixLength=r[e++],t.scopePrefixLength=r[e++];{let i=new Uint8Array(t.family===1?4:16);mt(r,i,0,e,e+n-4),t.ip=cp(i)}break;case 11:n>0&&(t.timeout=se(r,e),e+=2);break;case 14:t.tags=[];for(let i=0;i<n;i+=2)t.tags.push(se(r,e)),e+=2}return Mr.decode.bytes=n+4,t},encodingLength(r){if(r.data)return r.data.length+4;switch(hd(r.code)){case 8:{let t=r.sourcePrefixLength||0;return Math.ceil(t/8)+8}case 11:return typeof r.timeout=="number"?6:4;case 12:return r.length+4;case 14:return 4+r.tags.length*2}throw new Error(`Unknown roption code: ${r.code}`)}}),ln=Ee({encode(r,e,t){e||(e=new Uint8Array(ln.encodingLength(r))),t||(t=0);let n=t,i=$i(r,Mr);return q(e,i,t),t=Yo(r,Mr,e,t+2),ln.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=[],i=se(r,e);e+=2;let o=0;for(;i>0;)n[o++]=Mr.decode(r,e),e+=Mr.decode.bytes,i-=Mr.decode.bytes;return ln.decode.bytes=e-t,n},encodingLength(r){return 2+$i(r||[],Mr)}}),lr=Ee({encode(r,e,t){e||(e=new Uint8Array(lr.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!un(i))throw new Error("Key must be a Buffer");return t+=2,q(e,r.flags,t),t+=2,e[t]=lr.PROTOCOL_DNSSEC,t+=1,e[t]=r.algorithm,t+=1,mt(i,e,t,0,i.length),t+=i.length,lr.encode.bytes=t-n,q(e,lr.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=se(r,e);if(e+=2,n.flags=se(r,e),e+=2,r[e]!==lr.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=r[e],e+=1,n.key=r.slice(e,t+i+2),e+=n.key.length,lr.decode.bytes=e-t,n},encodingLength(r){return 6+Lr(r.key)}});lr.PROTOCOL_DNSSEC=3;lr.ZONE_KEY=128;lr.SECURE_ENTRYPOINT=32768;var jo=Ee({encode(r,e,t){e||(e=new Uint8Array(jo.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!un(i))throw new Error("Signature must be a Buffer");return t+=2,q(e,Ri(r.typeCovered),t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.labels,t+=1,dr(e,r.originalTTL,t),t+=4,dr(e,r.expiration,t),t+=4,dr(e,r.inception,t),t+=4,q(e,r.keyTag,t),t+=2,$.encode(r.signersName,e,t),t+=$.encode.bytes,mt(i,e,t,0,i.length),t+=i.length,jo.encode.bytes=t-n,q(e,jo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=se(r,e);return e+=2,n.typeCovered=Ho(se(r,e)),e+=2,n.algorithm=r[e],e+=1,n.labels=r[e],e+=1,n.originalTTL=ur(r,e),e+=4,n.expiration=ur(r,e),e+=4,n.inception=ur(r,e),e+=4,n.keyTag=se(r,e),e+=2,n.signersName=$.decode(r,e),e+=$.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,jo.decode.bytes=e-t,n},encodingLength(r){return 20+$.encodingLength(r.signersName)+Lr(r.signature)}}),zo=Ee({encode(r,e,t){e||(e=new Uint8Array(zo.encodingLength(r))),t||(t=0);let n=t;return t+=2,$.encode(r.mbox||".",e,t),t+=$.encode.bytes,$.encode(r.txt||".",e,t),t+=$.encode.bytes,zo.encode.bytes=t-n,q(e,zo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=$.decode(r,e)||".",e+=$.decode.bytes,n.txt=$.decode(r,e)||".",e+=$.decode.bytes,zo.decode.bytes=e-t,n},encodingLength(r){return 2+$.encodingLength(r.mbox||".")+$.encodingLength(r.txt||".")}}),St=Ee({encode(r,e,t){e||(e=new Uint8Array(St.encodingLength(r))),t||(t=0);let n=t,i=[];for(let o=0;o<r.length;o++){let s=Ri(r[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=Bc(i[o]);e[t]=o,t+=1,e[t]=s.length,t+=1,mt(s,e,t,0,s.length),t+=s.length}return St.encode.bytes=t-n,e},decode(r,e,t){e||(e=0);let n=e,i=[];for(;e-n<t;){let o=r[e];e+=1;let s=r[e];e+=1;for(let c=0;c<s;c++){let u=r[e+c];for(let d=0;d<8;d++)if(u&1<<7-d){let a=Ho(o<<8|c<<3|d);i.push(a)}}e+=s}return St.decode.bytes=e-n,i},encodingLength(r){let e=[];for(let n=0;n<r.length;n++){let i=Ri(r[n]);e[i>>8]=Math.max(e[i>>8]||0,i&255)}let t=0;for(let n=0;n<e.length;n++)e[n]!==void 0&&(t+=2+Math.ceil((e[n]+1)/8));return t}}),Jo=Ee({encode(r,e,t){e||(e=new Uint8Array(Jo.encodingLength(r))),t||(t=0);let n=t;return t+=2,$.encode(r.nextDomain,e,t),t+=$.encode.bytes,St.encode(r.rrtypes,e,t),t+=St.encode.bytes,Jo.encode.bytes=t-n,q(e,Jo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=se(r,e);return e+=2,n.nextDomain=$.decode(r,e),e+=$.decode.bytes,n.rrtypes=St.decode(r,e,i-(e-t)),e+=St.decode.bytes,Jo.decode.bytes=e-t,n},encodingLength(r){return 2+$.encodingLength(r.nextDomain)+St.encodingLength(r.rrtypes)}}),Go=Ee({encode(r,e,t){e||(e=new Uint8Array(Go.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!un(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!un(o))throw new Error("nextDomain must be a Buffer");return t+=2,e[t]=r.algorithm,t+=1,e[t]=r.flags,t+=1,q(e,r.iterations,t),t+=2,e[t]=i.length,t+=1,mt(i,e,t,0,i.length),t+=i.length,e[t]=o.length,t+=1,mt(o,e,t,0,o.length),t+=o.length,St.encode(r.rrtypes,e,t),t+=St.encode.bytes,Go.encode.bytes=t-n,q(e,Go.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=se(r,e);e+=2,n.algorithm=r[e],e+=1,n.flags=r[e],e+=1,n.iterations=se(r,e),e+=2;let o=r[e];e+=1,n.salt=r.slice(e,e+o),e+=o;let s=r[e];return e+=1,n.nextDomain=r.slice(e,e+s),e+=s,n.rrtypes=St.decode(r,e,i-(e-t)),e+=St.decode.bytes,Go.decode.bytes=e-t,n},encodingLength(r){return 8+r.salt.length+r.nextDomain.length+St.encodingLength(r.rrtypes)}}),Wo=Ee({encode(r,e,t){e||(e=new Uint8Array(Wo.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!un(i))throw new Error("Digest must be a Buffer");return t+=2,q(e,r.keyTag,t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.digestType,t+=1,mt(i,e,t,0,i.length),t+=i.length,Wo.encode.bytes=t-n,q(e,Wo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=se(r,e);return e+=2,n.keyTag=se(r,e),e+=2,n.algorithm=r[e],e+=1,n.digestType=r[e],e+=1,n.digest=r.slice(e,t+i+2),e+=n.digest.length,Wo.decode.bytes=e-t,n},encodingLength(r){return 6+Lr(r.digest)}}),Ni=Ee({encode(r,e,t){e||(e=new Uint8Array(Ni.encodingLength(r))),t||(t=0);let n=t;t+=2,e[t]=r.algorithm,t+=1,e[t]=r.hash,t+=1;let i=pd(r.fingerprint),o=gd(r.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${r.fingerprint}" for hashType=${r.hash}: ${i} != ${o}`);return fp(e,r.fingerprint,t,t+=i),Ni.encode.bytes=t-n,q(e,Ni.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={};e+=2,n.algorithm=r[e],e+=1,n.hash=r[e],e+=1;let i=gd(n.hash);return n.fingerprint=hp(r,e,e+i),e+=i,Ni.decode.bytes=e-t,n},encodingLength(r){return 4+pd(r.fingerprint)}});function gd(r){if(r===1)return 20;if(r===2)return 32;throw new Error(`Invalid hashType=${r}, supported=1,2`)}Ni.getFingerprintLengthForHashType=gd;function yd(r){switch(r.toUpperCase()){case"A":return gp;case"PTR":return Vi;case"CNAME":return Vi;case"DNAME":return Vi;case"TXT":return Kc;case"NULL":return _c;case"AAAA":return Pc;case"SRV":return Cc;case"HINFO":return kc;case"CAA":return dn;case"NS":return Uc;case"SOA":return Oc;case"MX":return Rc;case"OPT":return ln;case"DNSKEY":return lr;case"RRSIG":return jo;case"RP":return zo;case"NSEC":return Jo;case"NSEC3":return Go;case"SSHFP":return Ni;case"DS":return Wo}return Dc}var Vt=Ee({encode(r,e,t){e||(e=new Uint8Array(Vt.encodingLength(r))),t||(t=0);let n=t;if($.encode(r.name,e,t),t+=$.encode.bytes,q(e,Ri(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");q(e,r.udpPayloadSize||4096,t+2),e[t+4]=r.extendedRcode||0,e[t+5]=r.ednsVersion||0,q(e,r.flags||0,t+6),t+=8,ln.encode(r.options||[],e,t),t+=ln.encode.bytes}else{let i=ld(r.class===void 0?"IN":r.class);r.flush&&(i|=md),q(e,i,t+2),dr(e,r.ttl||0,t+4),t+=8;let o=yd(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Vt.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={},n=e;if(t.name=$.decode(r,e),e+=$.decode.bytes,t.type=Ho(se(r,e)),t.type==="OPT")t.udpPayloadSize=se(r,e+2),t.extendedRcode=r[e+4],t.ednsVersion=r[e+5],t.flags=se(r,e+6),t.flag_do=(t.flags>>15&1)===1,t.options=ln.decode(r,e+8),e+=8+ln.decode.bytes;else{let i=se(r,e+2);t.ttl=ur(r,e+4),t.class=dd(i&lx),t.flush=!!(i&md);let o=yd(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Vt.decode.bytes=e-n,t},encodingLength(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return $.encodingLength(r.name)+8+yd(r.type).encodingLength(e)}}),Fi=Ee({encode(r,e,t){e||(e=new Uint8Array(Fi.encodingLength(r))),t||(t=0);let n=t;return $.encode(r.name,e,t),t+=$.encode.bytes,q(e,Ri(r.type),t),t+=2,q(e,ld(r.class===void 0?"IN":r.class),t),t+=2,Fi.encode.bytes=t-n,r},decode(r,e){e||(e=0);let t=e,n={};return n.name=$.decode(r,e),e+=$.decode.bytes,n.type=Ho(se(r,e)),e+=2,n.class=dd(se(r,e)),e+=2,!!(n.class&mp)&&(n.class&=hx),Fi.decode.bytes=e-t,n},encodingLength(r){return $.encodingLength(r.name)+4}});var wp=1024;var tt={encode:function(r,e,t){let n=!e;n&&(e=new Uint8Array(fx(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),Mi.encode(r,e,t),t+=Mi.encode.bytes,t=Yo(r.questions,Fi,e,t),t=Yo(r.answers,Vt,e,t),t=Yo(r.authorities,Vt,e,t),t=Yo(r.additionals,Vt,e,t),tt.encode.bytes=t-i,n&&Xo.bytes!==e.length?e.slice(0,Xo.bytes):e},decode:function(r,e){e||(e=0);let t=e,n=Mi.decode(r,e);return e+=Mi.decode.bytes,e=Ic(n.questions,Fi,r,e),e=Ic(n.answers,Vt,r,e),e=Ic(n.authorities,Vt,r,e),e=Ic(n.additionals,Vt,r,e),tt.decode.bytes=e-t,n},encodingLength:function(r){return Mi.encodingLength(r)+$i(r.questions||[],Fi)+$i(r.answers||[],Vt)+$i(r.authorities||[],Vt)+$i(r.additionals||[],Vt)}};tt.encode.bytes=0;tt.decode.bytes=0;function Lc(r,e){if(r.questions)throw new Error("Only one .question object expected instead of a .questions array!");let t=Object.assign({type:e},r);return t.question&&(t.questions=[t.question],delete t.question),t}var Mc={encode:function(r,e,t){return e=tt.encode(Lc(r,"query"),e,t),Mc.encode.bytes=tt.encode.bytes,e},decode:function(r,e){let t=tt.decode(r,e);return Mc.decode.bytes=tt.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return tt.encodingLength(Lc(r,"query"))}};Mc.encode.bytes=0;Mc.decode.bytes=0;var Nc={encode:function(r,e,t){return e=tt.encode(Lc(r,"response"),e,t),Nc.encode.bytes=tt.encode.bytes,e},decode:function(r,e){let t=tt.decode(r,e);return Nc.decode.bytes=tt.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return tt.encodingLength(Lc(r,"response"))}};Nc.encode.bytes=0;Nc.decode.bytes=0;var Xo=tt.encode,$c=tt.decode,fx=tt.encodingLength;function xp(r){let e=Xo(r),t=new Uint8Array(2+e.byteLength);return q(t,e.byteLength),mt(e,t,2,0,e.length),xp.bytes=t.byteLength,t}xp.bytes=0;function bp(r){let e=se(r,0);if(r.byteLength<e+2)return null;let t=$c(r.slice(2));return bp.bytes=$c.bytes,t}bp.bytes=0;function $i(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function Yo(r,e,t,n){for(let i=0;i<r.length;i++)e.encode(r[i],t,n),n+=e.encode.bytes;return n}function Ic(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}var qB=h(f(),1),It=class{static async getSigningMethod(e){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")}static async resolve(e,t){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")}};var vp=process.env.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",px=0,hn=7200,Vc=";",at=",",wd=(u=>(u[u.Discoverable=0]="Discoverable",u[u.Organization=1]="Organization",u[u.Government=2]="Government",u[u.Corporation=3]="Corporation",u[u.LocalBusiness=4]="LocalBusiness",u[u.SoftwarePackage=5]="SoftwarePackage",u[u.WebApp=6]="WebApp",u[u.FinancialInstitution=7]="FinancialInstitution",u))(wd||{}),Fc=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(Fc||{}),xd=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(xd||{}),Ap={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},Ep={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"},Zo=class Zo extends It{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(a=>!(a.algorithm in Ap)))throw new Error("One or more verification method algorithms are not supported");let n=t.verificationMethods?.filter(a=>"id"in a).map(a=>a.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(t.services?.some(a=>!a.id||!a.type||!a.serviceEndpoint))throw new Error("One or more services are missing required properties");let i=await e.generateKey({algorithm:"Ed25519"}),o=await e.getPublicKey({keyUri:i}),s=await He.identityKeyToIdentifier({identityKey:o}),c={id:s,...t.alsoKnownAs&&{alsoKnownAs:t.alsoKnownAs},...t.controllers&&{controller:t.controllers}},u=[...t.verificationMethods??[]];u?.some(a=>a.id?.split("#").pop()==="0")||u.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let a of u){let l=a.id&&a.id.split("#").pop()==="0"?i:await e.generateKey({algorithm:a.algorithm}),g=await e.getPublicKey({keyUri:l}),b=a.id??g.kid??await te({jwk:g});b=`${s}#${yt(b)}`,c.verificationMethod??=[],c.verificationMethod.push({id:b,type:"JsonWebKey",controller:a.controller??s,publicKeyJwk:g});for(let m of a.purposes??[])c[m]??=[],c[m].push(b)}t.services?.forEach(a=>{c.service??=[],a.id=`${s}#${a.id.split("#").pop()}`,c.service.push(a)});let d=new ct({uri:s,document:c,metadata:{published:!1,...t.types&&{types:t.types}},keyManager:e});if(t.publish??!0){let a=await Zo.publish({did:d,gatewayUri:t.gatewayUri});d.metadata=a.didDocumentMetadata}return d}static async import({portableDid:e,keyManager:t=new ot}){if(Oe.parse(e.uri)?.method!==Zo.methodName)throw new F("methodNotSupported","Method not supported");let i=await ct.import({portableDid:e,keyManager:t});if(!i.document.verificationMethod?.some(o=>o.id?.split("#").pop()==="0"))throw new F("invalidDidDocument","DID document must contain an Identity Key");return i}static async getSigningMethod({didDocument:e,methodId:t="#0"}){let n=Oe.parse(e.id);if(n&&n.method!==this.methodName)throw new F("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>yt(o.id)===(yt(t)??yt(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new F("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:t=vp}){return await es.put({did:e,gatewayUri:t})}static async resolve(e,t={}){let n=t?.gatewayUri??vp;try{await He.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await es.get({didUri:e,gatewayUri:n});return{...Ue,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof F))throw new Error(i);return{...Ue,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};Zo.methodName="dht";var Qo=Zo,es=class r{static async get({didUri:e,gatewayUri:t}){let n=He.identifierToIdentityKeyBytes({didUri:e}),i=await r.pkarrGet({gatewayUri:t,publicKeyBytes:n}),o=await He.parseBep44GetMessage({bep44Message:i}),s=await r.fromDnsPacket({didUri:e,dnsPacket:o});return s.didDocumentMetadata.versionId=i.seq.toString(),s}static async put({did:e,gatewayUri:t}){let n=await r.toDnsPacket({didDocument:e.document,didMetadata:e.metadata,authoritativeGatewayUris:[t]}),i=await He.createBep44PutMessage({dnsPacket:n,publicKeyBytes:He.identifierToIdentityKeyBytes({didUri:e.uri}),signer:await e.getSigner({methodId:"0"})}),o=await r.pkarrPut({gatewayUri:t,bep44Message:i});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:o,versionId:i.seq.toString()},didRegistrationMetadata:{}}}static async pkarrGet({gatewayUri:e,publicKeyBytes:t}){let n=M.uint8Array(t).toBase32Z(),i=new URL(n,e).href,o;try{if(o=await fetch(i,{method:"GET"}),!o.ok)throw new F("notFound",`Pkarr record not found for: ${n}`)}catch(u){throw u instanceof F?u:new F("internalError",`Failed to fetch Pkarr record: ${u.message}`)}let s=await o.arrayBuffer();if(!s)throw new F("notFound",`Pkarr record not found for: ${n}`);if(s.byteLength<72)throw new F("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${s.byteLength}`);if(s.byteLength>1072)throw new F("invalidDidDocumentLength",`Pkarr response exceeds 1000 byte limit: ${s.byteLength}`);return{k:t,seq:Number(new DataView(s).getBigUint64(64)),sig:new Uint8Array(s,0,64),v:new Uint8Array(s,72)}}static async pkarrPut({gatewayUri:e,bep44Message:t}){let n=M.uint8Array(t.k).toBase32Z(),i=new URL(n,e).href,o=new Uint8Array(t.v.length+72);o.set(t.sig,0),new DataView(o.buffer).setBigUint64(t.sig.length,BigInt(t.seq)),o.set(t.v,t.sig.length+8);let s;try{s=await fetch(i,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:o})}catch(c){throw new F("internalError",`Failed to put Pkarr record for identifier ${n}: ${c.message}`)}return s.ok}static async fromDnsPacket({didUri:e,dnsPacket:t}){let n={id:e},i={published:!0},o=new Map;for(let s of t?.answers??[]){if(s.type!=="TXT")continue;let c=s.name.split(".")[0].substring(1);switch(!0){case c.startsWith("aka"):{let u=He.parseTxtDataToString(s.data);n.alsoKnownAs=u.split(at);break}case c.startsWith("cnt"):{let u=He.parseTxtDataToString(s.data);n.controller=u.includes(at)?u.split(at):u;break}case c.startsWith("k"):{let{id:u,t:d,k:a,c:l,a:g}=He.parseTxtDataToObject(s.data),b=M.base64Url(a).toUint8Array(),m=Fc[Number(d)],x=await He.keyConverter(m).bytesToPublicKey({publicKeyBytes:b});x.alg=g||Ep[Number(d)];let E=c==="k0"?"0":u!==void 0?u:await te({jwk:x});n.verificationMethod??=[];let S=`${e}#${E}`;n.verificationMethod.push({id:S,type:"JsonWebKey",controller:l??e,publicKeyJwk:x}),o.set(c,S);break}case c.startsWith("s"):{let{id:u,t:d,se:a,...l}=He.parseTxtDataToObject(s.data),g=a.includes(at)?a.split(at):[a],b=Object.fromEntries(Object.entries(l).map(([m,x])=>[m,x.includes(at)?x.split(at):x]));n.service??=[],n.service.push({...b,id:`${e}#${u}`,type:d,serviceEndpoint:g});break}case c.startsWith("typ"):{let{id:u}=He.parseTxtDataToObject(s.data);i.types=u.split(at).map(d=>Number(d));break}case c.startsWith("did"):{let u=m=>m.split(at).map(x=>o.get(x)).filter(x=>typeof x=="string"),{auth:d,asm:a,del:l,inv:g,agm:b}=He.parseTxtDataToObject(s.data);d&&(n.authentication=u(d)),a&&(n.assertionMethod=u(a)),l&&(n.capabilityDelegation=u(l)),g&&(n.capabilityInvocation=u(g)),b&&(n.keyAgreement=u(b));break}}}return{didDocument:n,didDocumentMetadata:i,didResolutionMetadata:{}}}static async toDnsPacket({didDocument:e,didMetadata:t,authoritativeGatewayUris:n,previousDidProof:i}){let o=[],s=[],c=new Map,u=[],d=[];if(i!==void 0){let{signature:g,previousDid:b}=i;await He.validatePreviousDidProof({newDid:e.id,previousDidProof:i}),o.push({type:"TXT",name:"_prv._did.",ttl:hn,data:`id=${b};s=${g}`})}if(e.alsoKnownAs&&o.push({type:"TXT",name:"_aka._did.",ttl:hn,data:e.alsoKnownAs.join(at)}),e.controller){let g=Array.isArray(e.controller)?e.controller.join(at):e.controller;o.push({type:"TXT",name:"_cnt._did.",ttl:hn,data:g})}for(let[g,b]of e.verificationMethod?.entries()??[]){let m=`k${g}`;d.push(m);let x=b.id.split("#").pop();c.set(x,m);let E=b.publicKeyJwk;if(!(E?.crv&&E.crv in Ap))throw new F("invalidPublicKeyType",`Verification method '${b.id}' contains an unsupported key type: ${E?.crv??"undefined"}`);let S=Fc[E.crv],U=await He.keyConverter(E.crv).publicKeyToBytes({publicKey:E}),T=M.uint8Array(U).toBase64Url(),_=[`t=${S}`,`k=${T}`];x!=="0"&&await te({jwk:E})!==x&&_.unshift(`id=${x}`),E.alg!==Ep[S]&&_.push(`a=${E.alg}`),b.controller!==e.id&&_.push(`c=${b.controller}`),o.push({type:"TXT",name:`_${m}._did.`,ttl:hn,data:_.join(Vc)})}e.service?.forEach((g,b)=>{let m=`s${b}`;u.push(m);let{id:x,type:E,serviceEndpoint:S,...U}=g;x=yt(x),S=Array.isArray(S)?S.join(","):S;let _=Object.entries({id:x,t:E,se:S,...U}).map(([k,C])=>`${k}=${C}`).join(Vc),D=He.chunkDataIfNeeded(_);o.push({type:"TXT",name:`_${m}._did.`,ttl:hn,data:D})});let a=[`v=${px}`];if(d.length&&a.push(`vm=${d.join(at)}`),Object.keys(En).forEach(g=>{let b=e[g]?.map(m=>c.get(m.split("#").pop()));if(b){let m=xd[g];a.push(`${m}=${b.join(at)}`)}}),u.length&&a.push(`svc=${u.join(at)}`),t.types?.length){let b=t.types.map(m=>typeof m=="string"?wd[m]:m);o.push({type:"TXT",name:"_typ._did.",ttl:hn,data:`id=${b.join(at)}`})}o.push({type:"TXT",name:"_did."+r.getUniqueDidSuffix(e.id)+".",ttl:hn,data:a.join(Vc)});for(let g of n||[])s.push({type:"NS",name:"_did."+r.getUniqueDidSuffix(e.id)+".",ttl:hn,data:g+"."});return{id:0,type:"response",flags:wp,answers:[...o,...s]}}static getUniqueDidSuffix(e){return e.split(":")[2]}},He=class r{static async createBep44PutMessage({dnsPacket:e,publicKeyBytes:t,signer:n}){let i=Math.ceil(Date.now()/1e3),o=Xo(e),s=ud.encode({seq:i,v:o}).subarray(1,-1);if(s.length>1e3)throw new F("invalidDidDocumentLength",`DNS packet exceeds the 1000 byte maximum size: ${s.length} bytes`);let c=await n.sign({data:s});return{k:t,seq:i,sig:c,v:o}}static async identifierToIdentityKey({didUri:e}){let t=r.identifierToIdentityKeyBytes({didUri:e});return await Ge.bytesToPublicKey({publicKeyBytes:t})}static identifierToIdentityKeyBytes({didUri:e}){let t=Oe.parse(e);if(!t)throw new F("invalidDid",`Invalid DID URI: ${e}`);if(t.method!==Qo.methodName)throw new F("methodNotSupported",`Method not supported: ${t.method}`);let n;try{n=M.base32Z(t.id).toUint8Array()}catch{throw new F("invalidPublicKey","Failed to decode method-specific identifier")}if(n.length!==32)throw new F("invalidPublicKeyLength",`Invalid public key length: ${n.length}`);return n}static async identityKeyToIdentifier({identityKey:e}){let t=await Ge.publicKeyToBytes({publicKey:e}),n=M.uint8Array(t).toBase32Z();return`did:${Qo.methodName}:${n}`}static keyConverter(e){let n={Ed25519:Ge,"P-256":{publicKeyToBytes:async({publicKey:i})=>{let o=await et.publicKeyToBytes({publicKey:i});return await et.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:et.bytesToPublicKey,privateKeyToBytes:et.privateKeyToBytes,bytesToPrivateKey:et.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:i})=>{let o=await Je.publicKeyToBytes({publicKey:i});return await Je.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:Je.bytesToPublicKey,privateKeyToBytes:Je.privateKeyToBytes,bytesToPrivateKey:Je.bytesToPrivateKey},X25519:bc}[e];if(!n)throw new F("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async parseBep44GetMessage({bep44Message:e}){let t=await Ge.bytesToPublicKey({publicKeyBytes:e.k}),n=ud.encode({seq:e.seq,v:e.v}).subarray(1,-1);if(!await Ge.verify({key:t,signature:e.sig,data:n}))throw new F("invalidSignature","Invalid signature for DHT BEP44 message");return $c(e.v)}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split(Vc).reduce((t,n)=>{let[i,o]=n.split("=");return t[i]=o,t},{})}static parseTxtDataToString(e){if(typeof e=="string")return e;if(e instanceof Uint8Array)return M.uint8Array(e).toString();if(Array.isArray(e))return e.map(t=>this.parseTxtDataToString(t)).join("");throw new F("internalError","Pkarr returned DNS TXT record with invalid data type")}static async validatePreviousDidProof({newDid:e,previousDidProof:t}){let n=await r.identifierToIdentityKey({didUri:t.previousDid}),i=r.identifierToIdentityKeyBytes({didUri:e}),o=M.base64Url(t.signature).toUint8Array();if(!await Ge.verify({key:n,data:i,signature:o}))throw new F("invalidPreviousDidProof","The previous DID proof is invalid.")}static chunkDataIfNeeded(e){if(e.length<=255)return e;let t=[];for(let n=0;n<e.length;n+=255)t.push(e.slice(n,n+255));return t}};var II=h(f(),1);var gI=h(f(),1);var P8=h(f(),1);var OS=h(f(),1);var oS=h(f(),1),Se={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"};var cS=h(f(),1),be=class extends Error{constructor(e,t){super(`${e}: ${t}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};var BS=h(f(),1);var xS=h(f(),1);var uS=h(f(),1);var hS=h(f(),1),dS=new Uint8Array(0);var bd=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var fS=h(f(),1);var vd=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ed=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.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 Tp(this,e)}},Ad=class{constructor(e){this.decoders=e}or(e){return Tp(this,e)}decode(e){let t=e[0],n=this.decoders[t];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`)}},Tp=(r,e)=>new Ad({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),Td=class{constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new vd(e,t,n),this.decoder=new Ed(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},yx=({name:r,prefix:e,encode:t,decode:n})=>new Td(r,e,t,n);var mx=(r,e,t,n)=>{let i={};for(let a=0;a<e.length;++a)i[e[a]]=a;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),c=0,u=0,d=0;for(let a=0;a<o;++a){let l=i[r[a]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|l,c+=t,c>=8&&(c-=8,s[d++]=255&u>>c)}if(c>=t||255&u<<8-c)throw new SyntaxError("Unexpected end of data");return s},gx=(r,e,t)=>{let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,c=0;for(let u=0;u<r.length;++u)for(c=c<<8|r[u],s+=8;s>t;)s-=t,o+=e[i&c>>s];if(s&&(o+=e[i&c<<t-s]),n)for(;o.length*t&7;)o+="=";return o},ts=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>yx({prefix:e,name:r,encode(i){return gx(i,n,t)},decode(i){return mx(i,n,t,r)}});var vS=ts({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ES=ts({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rs=ts({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),AS=ts({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gt=class r{static encode(e){return rs.baseEncode(e)}static decodeAsBytes(e,t){if(!r.isBase64UrlString(e))throw new be(Se.EncodedStringIncorrectEncoding,`Given ${t} must be base64url string.`);return rs.baseDecode(e)}static decodeAsString(e,t){let n=r.decodeAsBytes(e,t);return r.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)}};var U8=h(f(),1),Rp=h(Sp(),1);var NS=h(f(),1);var kS=h(f(),1),Bd;(function(r){r.Public="public",r.Private="private"})(Bd||(Bd={}));var Dt=Bd;var qe=class{static validateEs256kOperationKey(e,t){let n=new Set(["kty","crv","x","y"]);t===Dt.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new be(Se.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new be(Se.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new be(Se.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new be(Se.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new be(Se.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(t===Dt.Private&&(e.d===void 0||e.d.length!==43))throw new be(Se.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new be(Se.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!gt.isBase64UrlString(e))throw new be(Se.IdNotUsingBase64UrlCharacterSet,`Key ID '${e}' is not a Base64URL string.`)}static validatePublicKeyPurposes(e){if(e===void 0)return;let t=new Set;for(let n of e){if(t.has(n))throw new be(Se.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);t.add(n)}}};var VS=h(f(),1),ns=class{};ns.hashAlgorithmInMultihashCode=18;ns.maxCanonicalizedDeltaSizeInBytes=1e3;var ut=ns;var zS=h(f(),1),Up=h(Dp(),1);var Xt=class r{static canonicalizeAsBytes(e){let t=r.removeAllUndefinedProperties(e),n=Up.default(t);return gt.stringToBytes(n)}static removeAllUndefinedProperties(e){for(let t in e)typeof e[t]=="object"?r.removeAllUndefinedProperties(e[t]):e[t]===void 0&&delete e[t];return e}};var p8=h(f(),1);var QS=h(f(),1);var YS=h(f(),1);var GS=h(f(),1),wx=_p,Op=128,xx=127,bx=~xx,vx=Math.pow(2,31);function _p(r,e,t){e=e||[],t=t||0;for(var n=t;r>=vx;)e[t++]=r&255|Op,r/=128;for(;r&bx;)e[t++]=r&255|Op,r>>>=7;return e[t]=r|0,_p.bytes=t-n+1,e}var Ex=Sd,Ax=128,Kp=127;function Sd(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Sd.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Kp)<<i:(s&Kp)*Math.pow(2,i),i+=7}while(s>=Ax);return Sd.bytes=o-n,t}var Tx=Math.pow(2,7),Bx=Math.pow(2,14),Sx=Math.pow(2,21),Ix=Math.pow(2,28),Dx=Math.pow(2,35),Ux=Math.pow(2,42),Ox=Math.pow(2,49),Kx=Math.pow(2,56),_x=Math.pow(2,63),kx=function(r){return r<Tx?1:r<Bx?2:r<Sx?3:r<Ix?4:r<Dx?5:r<Ux?6:r<Ox?7:r<Kx?8:r<_x?9:10},Cx={encode:wx,decode:Ex,encodingLength:kx},Rx=Cx,is=Rx;var Id=(r,e=0)=>[is.decode(r,e),is.decode.bytes],Dd=(r,e,t=0)=>(is.encode(r,e,t),e),Ud=r=>is.encodingLength(r);var Od=(r,e)=>{let t=e.byteLength,n=Ud(r),i=n+Ud(t),o=new Uint8Array(i+t);return Dd(r,o,0),Dd(t,o,n),o.set(e,i),new qc(r,t,e,o)},kp=r=>{let e=bd(r),[t,n]=Id(e),[i,o]=Id(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new qc(t,i,s,e)};var qc=class{constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var o8=h(f(),1);var t8=h(f(),1);var _d=({name:r,code:e,encode:t})=>new Kd(r,e,t),Kd=class{constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?Od(this.code,t):t.then(n=>Od(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Cp=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),jc=_d({name:"sha2-256",code:18,encode:Cp("SHA-256")}),n8=_d({name:"sha2-512",code:19,encode:Cp("SHA-512")});var os=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},We=class r{static hash(e,t){return os(this,void 0,void 0,function*(){let n;switch(t){case 18:n=(yield jc.digest(e)).bytes;break;default:throw new be(Se.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${t} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,t){return os(this,void 0,void 0,function*(){let n;switch(t){case 18:n=yield jc.encode(e);break;default:throw new be(Se.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${t} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,t){return os(this,void 0,void 0,function*(){let n=Xt.canonicalizeAsBytes(e);return yield r.hashThenEncode(n,t)})}static canonicalizeThenDoubleHashThenEncode(e,t){return os(this,void 0,void 0,function*(){let n=Xt.canonicalizeAsBytes(e),i=yield r.hashAsNonMultihashBytes(n,t);return yield r.hashThenEncode(i,t)})}static hashThenEncode(e,t){return os(this,void 0,void 0,function*(){let n=yield r.hash(e,t);return gt.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,t){let n,i=gt.decodeAsBytes(e,t);try{n=kp(i)}catch{throw new be(Se.MultihashStringNotAMultihash,`Given ${t} string '${e}' is not a multihash after decoding.`)}let o=ut.hashAlgorithmInMultihashCode;if(o!==n.code)throw new be(Se.MultihashUnsupportedHashAlgorithm,`Given ${t} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};var m8=h(f(),1),kd;(function(r){r.Create="create",r.Update="update",r.Deactivate="deactivate",r.Recover="recover"})(kd||(kd={}));var ss=kd;var w8=h(f(),1),Cd;(function(r){r.Replace="replace",r.AddPublicKeys="add-public-keys",r.RemovePublicKeys="remove-public-keys",r.AddServices="add-services",r.RemoveServices="remove-services"})(Cd||(Cd={}));var jn=Cd;var zc=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},fn=class r{static createCreateRequest(e){return zc(this,void 0,void 0,function*(){let t=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;qe.validateEs256kOperationKey(t,Dt.Public),qe.validateEs256kOperationKey(n,Dt.Public),r.validateDidDocumentKeys(i),r.validateServices(o);let s=ut.hashAlgorithmInMultihashCode,c=[{action:jn.Replace,document:e.document}],u={updateCommitment:yield We.canonicalizeThenDoubleHashThenEncode(n,s),patches:c};r.validateDeltaSize(u);let a={deltaHash:yield We.canonicalizeThenHashThenEncode(u,s),recoveryCommitment:yield We.canonicalizeThenDoubleHashThenEncode(t,s)};return{type:ss.Create,suffixData:a,delta:u}})}static createDeactivateRequest(e){return zc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),qe.validateEs256kOperationKey(e.recoveryPublicKey,Dt.Public);let t=ut.hashAlgorithmInMultihashCode,n=yield We.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:ss.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return zc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),qe.validateEs256kOperationKey(e.recoveryPublicKey,Dt.Public),qe.validateEs256kOperationKey(e.nextRecoveryPublicKey,Dt.Public),qe.validateEs256kOperationKey(e.nextUpdatePublicKey,Dt.Public),r.validateDidDocumentKeys(e.document.publicKeys),r.validateServices(e.document.services);let t=ut.hashAlgorithmInMultihashCode,n=yield We.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i=[{action:jn.Replace,document:e.document}],o=yield We.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,t),s={patches:i,updateCommitment:o},c=yield We.canonicalizeThenHashThenEncode(s,t),d={recoveryCommitment:yield We.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,t),recoveryKey:e.recoveryPublicKey,deltaHash:c},a=yield e.signer.sign({alg:"ES256K"},d);return{type:ss.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:a}})}static createUpdateRequest(e){return zc(this,void 0,void 0,function*(){if(r.validateDidSuffix(e.didSuffix),qe.validateEs256kOperationKey(e.updatePublicKey,Dt.Public),qe.validateEs256kOperationKey(e.nextUpdatePublicKey,Dt.Public),r.validateServices(e.servicesToAdd),r.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let m of e.idsOfServicesToRemove)qe.validateId(m);if(e.idsOfPublicKeysToRemove!==void 0)for(let m of e.idsOfPublicKeysToRemove)qe.validateId(m);let t=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let m={action:jn.AddServices,services:n};t.push(m)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let m={action:jn.RemoveServices,ids:i};t.push(m)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let m={action:jn.AddPublicKeys,publicKeys:o};t.push(m)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let m={action:jn.RemovePublicKeys,ids:s};t.push(m)}let c=ut.hashAlgorithmInMultihashCode,u=yield We.canonicalizeThenHashThenEncode(e.updatePublicKey,c),d=yield We.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,c),a={patches:t,updateCommitment:d},l=yield We.canonicalizeThenHashThenEncode(a,c),g={updateKey:e.updatePublicKey,deltaHash:l},b=yield e.signer.sign({alg:"ES256K"},g);return{type:ss.Update,didSuffix:e.didSuffix,revealValue:u,delta:a,signedData:b}})}static validateDidSuffix(e){We.validateEncodedHashComputedUsingSupportedHashAlgorithm(e,"didSuffix")}static validateDidDocumentKeys(e){if(e===void 0)return;let t=new Set;for(let n of e){if(Array.isArray(n.publicKeyJwk))throw new be(Se.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(qe.validateId(n.id),t.has(n.id))throw new be(Se.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);t.add(n.id),qe.validatePublicKeyPurposes(n.purposes)}}static validateServices(e){if(e!==void 0&&e.length!==0){let t=new Set;for(let n of e){if(r.validateService(n),t.has(n.id))throw new be(Se.DidDocumentServiceIdDuplicated,"Service id has to be unique");t.add(n.id)}}}static validateService(e){qe.validateId(e.id);let t=30;if(e.type.length>t){let n=`Service endpoint type length ${e.type.length} exceeds max allowed length of ${t}.`;throw new be(Se.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new be(Se.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&Rp.parse(e.serviceEndpoint).error!==void 0)throw new be(Se.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let t=Xt.canonicalizeAsBytes(e);if(t.length>ut.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${t.length} bytes exceeded limit of ${ut.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new be(Se.DeltaExceedsMaximumSize,n)}}};var Pp=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},Hi=class r{static createLongFormDid(e){return Pp(this,void 0,void 0,function*(){let t=yield fn.createCreateRequest(e),n=yield r.computeDidUniqueSuffix(t.suffixData),i;ut.network===void 0||ut.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${ut.network}:${n}`;let o={suffixData:t.suffixData,delta:t.delta},s=Xt.canonicalizeAsBytes(o),c=gt.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return Pp(this,void 0,void 0,function*(){let t=Xt.canonicalizeAsBytes(e),n=yield We.hash(t,ut.hashAlgorithmInMultihashCode);return gt.encode(n)})}};var z8=h(f(),1);var L8=h(f(),1);var rt=2n**255n-19n,Gc=2n**252n+27742317777372353535851937790883648493n,Pd=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Ld=0x6666666666666666666666666666666666666666666666666666666666666658n,Jc={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:rt,n:Gc,h:8,Gx:Pd,Gy:Ld},wt=(r="")=>{throw new Error(r)},Fp=r=>typeof r=="string",Md=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?wt("Uint8Array expected"):r,qi=r=>new Uint8Array(r),Mx=(r,e)=>Md(Fp(r)?$d(r):qi(r),e),z=(r,e=rt)=>{let t=r%e;return t>=0n?t:e+t},Lp=r=>r instanceof pn?r:wt("Point expected"),Mp,pn=class r{constructor(e,t,n,i){this.ex=e,this.ey=t,this.ez=n,this.et=i}static fromAffine(e){return new r(e.x,e.y,1n,z(e.x*e.y))}static fromHex(e,t=!0){let{d:n}=Jc;e=Mx(e,32);let i=e.slice();i[31]=e[31]&-129;let o=$x(i);o===0n||(t&&!(0n<o&&o<rt)&&wt("bad y coord 1"),!t&&!(0n<o&&o<2n**256n)&&wt("bad y coord 2"));let s=z(o*o),c=z(s-1n),u=z(n*s+1n),{isValid:d,value:a}=Fx(c,u);d||wt("bad y coordinate 3");let l=(a&1n)===1n;return(e[31]&128)!==0!==l&&(a=z(-a)),new r(a,o,1n,z(a*o))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:t,ey:n,ez:i}=this,{ex:o,ey:s,ez:c}=Lp(e),u=z(t*c),d=z(o*i),a=z(n*c),l=z(s*i);return u===d&&a===l}is0(){return this.equals(Wc)}negate(){return new r(z(-this.ex),this.ey,this.ez,z(-this.et))}double(){let{ex:e,ey:t,ez:n}=this,{a:i}=Jc,o=z(e*e),s=z(t*t),c=z(2n*z(n*n)),u=z(i*o),d=e+t,a=z(z(d*d)-o-s),l=u+s,g=l-c,b=u-s,m=z(a*g),x=z(l*b),E=z(a*b),S=z(g*l);return new r(m,x,S,E)}add(e){let{ex:t,ey:n,ez:i,et:o}=this,{ex:s,ey:c,ez:u,et:d}=Lp(e),{a,d:l}=Jc,g=z(t*s),b=z(n*c),m=z(o*l*d),x=z(i*u),E=z((t+n)*(s+c)-g-b),S=z(x-m),U=z(x+m),T=z(b-a*g),_=z(E*S),D=z(U*T),k=z(E*T),C=z(S*U);return new r(_,D,C,k)}mul(e,t=!0){if(e===0n)return t===!0?wt("cannot multiply by 0"):Wc;if(typeof e=="bigint"&&0n<e&&e<Gc||wt("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Yc))return qx(e).p;let n=Wc,i=Yc;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):t&&(i=i.add(o));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(Jc.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(Gc/2n,!1).double();return Gc%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:t,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=qp(n);return z(n*i)!==1n&&wt("invalid inverse"),{x:z(e*i),y:z(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=Nx(t);return n[31]|=e&1n?128:0,n}toHex(){return Nd(this.toRawBytes())}};pn.BASE=new pn(Pd,Ld,1n,z(Pd*Ld));pn.ZERO=new pn(0n,1n,1n,0n);var{BASE:Yc,ZERO:Wc}=pn,Hp=(r,e)=>r.toString(16).padStart(e,"0"),Nd=r=>Array.from(r).map(e=>Hp(e,2)).join(""),$d=r=>{let e=r.length;(!Fp(r)||e%2)&&wt("hex invalid 1");let t=qi(e/2);for(let n=0;n<t.length;n++){let i=n*2,o=r.slice(i,i+2),s=Number.parseInt(o,16);(Number.isNaN(s)||s<0)&&wt("hex invalid 2"),t[n]=s}return t},Nx=r=>$d(Hp(r,32*2)).reverse(),$x=r=>BigInt("0x"+Nd(qi(Md(r)).reverse())),Np=(...r)=>{let e=qi(r.reduce((n,i)=>n+Md(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},qp=(r,e=rt)=>{(r===0n||e<=0n)&&wt("no inverse n="+r+" mod="+e);let t=z(r,e),n=e,i=0n,o=1n,s=1n,c=0n;for(;t!==0n;){let u=n/t,d=n%t,a=i-s*u,l=o-c*u;n=t,t=d,i=s,o=c,s=a,c=l}return n===1n?z(i,e):wt("no inverse")},hr=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=rt;return t},Vx=r=>{let t=r*r%rt*r%rt,n=hr(t,2n)*t%rt,i=hr(n,1n)*r%rt,o=hr(i,5n)*i%rt,s=hr(o,10n)*o%rt,c=hr(s,20n)*s%rt,u=hr(c,40n)*c%rt,d=hr(u,80n)*u%rt,a=hr(d,80n)*u%rt,l=hr(a,10n)*o%rt;return{pow_p_5_8:hr(l,2n)*r%rt,b2:t}},$p=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Fx=(r,e)=>{let t=z(e*e*e),n=z(t*t*e),i=Vx(r*n).pow_p_5_8,o=z(r*t*i),s=z(e*o*o),c=o,u=z(o*$p),d=s===r,a=s===z(-r),l=s===z(-r*$p);return d&&(o=c),(a||l)&&(o=u),(z(o)&1n)===1n&&(o=z(-o)),{isValid:d||a,value:o}};var Rd;var Vp=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,jp={bytesToHex:Nd,hexToBytes:$d,concatBytes:Np,mod:z,invert:qp,randomBytes:r=>{let e=Vp();return e||wt("crypto.getRandomValues must be defined"),e.getRandomValues(qi(r))},sha512Async:async(...r)=>{let e=Vp();e||wt("crypto.subtle or etc.sha512Async must be defined");let t=Np(...r);return qi(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(jp,{sha512Sync:{configurable:!1,get(){return Rd},set(r){Rd||(Rd=r)}}});var zn=8,Hx=()=>{let r=[],e=256/zn+1,t=Yc,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(zn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},qx=r=>{let e=Mp||(Mp=Hx()),t=(a,l)=>{let g=l.negate();return a?g:l},n=Wc,i=Yc,o=1+256/zn,s=2**(zn-1),c=BigInt(2**zn-1),u=2**zn,d=BigInt(zn);for(let a=0;a<o;a++){let l=a*s,g=Number(r&c);r>>=d,g>s&&(g-=u,r+=1n);let b=l,m=l+Math.abs(g)-1,x=a%2!==0,E=g<0;g===0?i=i.add(t(x,e[b])):n=n.add(t(E,e[m]))}return{p:n,f:i}};var M8=h(f(),1);var Fd=2n**256n,Gn=Fd-0x1000003d1n,Hd=Fd-0x14551231950b75fc4402da1732fc9bebfn,Qp=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,ey=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,ty={p:Gn,n:Hd,a:0n,b:7n,Gx:Qp,Gy:ey},ji=32,zp=r=>H(H(r*r)*r+ty.b),Ye=(r="")=>{throw new Error(r)},Qc=r=>typeof r=="bigint",ry=r=>typeof r=="string",Vd=r=>Qc(r)&&0n<r&&r<Gn,ny=r=>Qc(r)&&0n<r&&r<Hd,iy=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?Ye("Uint8Array expected"):r,as=r=>new Uint8Array(r),qd=(r,e)=>iy(ry(r)?ea(r):as(r),e),H=(r,e=Gn)=>{let t=r%e;return t>=0n?t:e+t},Jp=r=>r instanceof Nr?r:Ye("Point expected"),Gp,Nr=class r{constructor(e,t,n){this.px=e,this.py=t,this.pz=n}static fromAffine(e){return new r(e.x,e.y,1n)}static fromHex(e){e=qd(e);let t,n=e[0],i=e.subarray(1),o=Wp(i,0,ji),s=e.length;if(s===33&&[2,3].includes(n)){Vd(o)||Ye("Point hex invalid: x not FE");let c=zx(zp(o)),u=(c&1n)===1n;(n&1)===1!==u&&(c=H(-c)),t=new r(o,c,1n)}return s===65&&n===4&&(t=new r(o,Wp(i,ji,2*ji),1n)),t?t.ok():Ye("Point is not on curve")}static fromPrivateKey(e){return cs.mul(Jx(e))}get x(){return this.aff().x}get y(){return this.aff().y}equals(e){let{px:t,py:n,pz:i}=this,{px:o,py:s,pz:c}=Jp(e),u=H(t*c),d=H(o*i),a=H(n*c),l=H(s*i);return u===d&&a===l}negate(){return new r(this.px,H(-this.py),this.pz)}double(){return this.add(this)}add(e){let{px:t,py:n,pz:i}=this,{px:o,py:s,pz:c}=Jp(e),{a:u,b:d}=ty,a=0n,l=0n,g=0n,b=H(d*3n),m=H(t*o),x=H(n*s),E=H(i*c),S=H(t+n),U=H(o+s);S=H(S*U),U=H(m+x),S=H(S-U),U=H(t+i);let T=H(o+c);return U=H(U*T),T=H(m+E),U=H(U-T),T=H(n+i),a=H(s+c),T=H(T*a),a=H(x+E),T=H(T-a),g=H(u*U),a=H(b*E),g=H(a+g),a=H(x-g),g=H(x+g),l=H(a*g),x=H(m+m),x=H(x+m),E=H(u*E),U=H(b*U),x=H(x+E),E=H(m-E),E=H(u*E),U=H(U+E),m=H(x*U),l=H(l+m),m=H(T*U),a=H(S*a),a=H(a-m),m=H(S*x),g=H(T*g),g=H(g+m),new r(a,l,g)}mul(e,t=!0){if(!t&&e===0n)return Xc;if(ny(e)||Ye("invalid scalar"),this.equals(cs))return Yx(e).p;let n=Xc,i=cs;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):t&&(i=i.add(o));return n}mulAddQUns(e,t,n){return this.mul(t,!1).add(e.mul(n,!1)).ok()}toAffine(){let{px:e,py:t,pz:n}=this;if(this.equals(Xc))return{x:0n,y:0n};if(n===1n)return{x:e,y:t};let i=sy(n);return H(n*i)!==1n&&Ye("invalid inverse"),{x:H(e*i),y:H(t*i)}}assertValidity(){let{x:e,y:t}=this.aff();return(!Vd(e)||!Vd(t))&&Ye("Point invalid: x or y"),H(t*t)===zp(e)?this:Ye("Point invalid: not on curve")}multiply(e){return this.mul(e)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(e=!0){let{x:t,y:n}=this.aff();return(e?(n&1n)===0n?"02":"03":"04")+Yp(t)+(e?"":Yp(n))}toRawBytes(e=!0){return ea(this.toHex(e))}};Nr.BASE=new Nr(Qp,ey,1n);Nr.ZERO=new Nr(0n,1n,0n);var{BASE:cs,ZERO:Xc}=Nr,oy=(r,e)=>r.toString(16).padStart(e,"0"),jd=r=>Array.from(r).map(e=>oy(e,2)).join(""),ea=r=>{let e=r.length;(!ry(r)||e%2)&&Ye("hex invalid 1");let t=as(e/2);for(let n=0;n<t.length;n++){let i=n*2,o=r.slice(i,i+2),s=Number.parseInt(o,16);(Number.isNaN(s)||s<0)&&Ye("hex invalid 2"),t[n]=s}return t},ta=r=>BigInt("0x"+(jd(r)||"0")),Wp=(r,e,t)=>ta(r.slice(e,t)),zd=r=>Qc(r)&&r>=0n&&r<Fd?ea(oy(r,2*ji)):Ye("bigint expected"),Yp=r=>jd(zd(r)),Xp=(...r)=>{let e=as(r.reduce((n,i)=>n+iy(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},sy=(r,e=Gn)=>{(r===0n||e<=0n)&&Ye("no inverse n="+r+" mod="+e);let t=H(r,e),n=e,i=0n,o=1n,s=1n,c=0n;for(;t!==0n;){let u=n/t,d=n%t,a=i-s*u,l=o-c*u;n=t,t=d,i=s,o=c,s=a,c=l}return n===1n?H(i,e):Ye("no inverse")},zx=r=>{let e=1n;for(let t=r,n=(Gn+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*t%Gn),t=t*t%Gn;return H(e*e)===r?e:Ye("sqrt invalid")},Jx=r=>(Qc(r)||(r=ta(qd(r,ji))),ny(r)?r:Ye("private key out of range"));var Zp=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Zc;function Gx(r){r=qd(r);let e=ji+8;(r.length<e||r.length>1024)&&Ye("expected proper params");let t=H(ta(r),Hd-1n)+1n;return zd(t)}var cy={hexToBytes:ea,bytesToHex:jd,concatBytes:Xp,bytesToNumberBE:ta,numberToBytesBE:zd,mod:H,invert:sy,hmacSha256Async:async(r,...e)=>{let t=Zp();if(!t)return Ye("etc.hmacSha256Async not set");let n=t.subtle,i=await n.importKey("raw",r,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return as(await n.sign("HMAC",i,Xp(...e)))},hmacSha256Sync:Zc,hashToPrivateKey:Gx,randomBytes:r=>{let e=Zp();return e||Ye("crypto.getRandomValues must be defined"),e.getRandomValues(as(r))}};Object.defineProperties(cy,{hmacSha256Sync:{configurable:!1,get(){return Zc},set(r){Zc||(Zc=r)}}});var Jn=8,Wx=()=>{let r=[],e=256/Jn+1,t=cs,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(Jn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Yx=r=>{let e=Gp||(Gp=Wx()),t=(a,l)=>{let g=l.negate();return a?g:l},n=Xc,i=cs,o=1+256/Jn,s=2**(Jn-1),c=BigInt(2**Jn-1),u=2**Jn,d=BigInt(Jn);for(let a=0;a<o;a++){let l=a*s,g=Number(r&c);r>>=d,g>s&&(g-=u,r+=1n);let b=l,m=l+Math.abs(g)-1,x=a%2!==0,E=g<0;g===0?i=i.add(t(x,e[b])):n=n.add(t(E,e[m]))}return{p:n,f:i}};var G8=h(f(),1),uy;(function(r){r.Mainnet="mainnet",r.Testnet="test"})(uy||(uy={}));var Y8=h(f(),1),dy;(function(r){r.Authentication="authentication",r.AssertionMethod="assertionMethod",r.CapabilityInvocation="capabilityInvocation",r.CapabilityDelegation="capabilityDelegation",r.KeyAgreement="keyAgreement"})(dy||(dy={}));var iI=h(f(),1);var hy=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(hy||{}),Xx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},ly="https://ion.tbd.engineering",Wn=class Wn extends It{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(m=>!(m.algorithm in Xx)))throw new Error("One or more verification method algorithms are not supported");let n=t.verificationMethods?.filter(m=>"id"in m).map(m=>m.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(t.services?.some(m=>!m.id||!m.type||!m.serviceEndpoint))throw new Error("One or more services are missing required properties");let i={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},o=[];for(let m of t.verificationMethods??[i]){let x=await e.generateKey({algorithm:m.algorithm}),E=await e.getPublicKey({keyUri:x});o.push({id:m.id,publicKeyJwk:E,purposes:m.purposes??["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let s=await e.generateKey({algorithm:"secp256k1"}),c=await e.getPublicKey({keyUri:s}),u=await e.generateKey({algorithm:"secp256k1"}),d=await e.getPublicKey({keyUri:u}),a=await yn.computeLongFormDidUri({recoveryKey:c,updateKey:d,services:t.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:g}=await Wn.resolve(a,{gatewayUri:t.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${g?.error}`);let b=new ct({uri:a,document:l,metadata:{published:!1,canonicalId:a.split(":",3).join(":"),recoveryKey:c,updateKey:d},keyManager:e});if(t.publish??!0){let m=await Wn.publish({did:b,gatewayUri:t.gatewayUri});b.metadata=m.didDocumentMetadata}return b}static async getSigningMethod({didDocument:e,methodId:t}){let n=Oe.parse(e.id);if(n&&n.method!==this.methodName)throw new F("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>o.id===(t??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new F("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:t=new ot}){if(Oe.parse(e.uri)?.method!==Wn.methodName)throw new F("methodNotSupported","Method not supported");return await ct.import({portableDid:e,keyManager:t})}static async publish({did:e,gatewayUri:t=ly}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:ed({didDocument:e.document,methodId:s.id})}))??[],i=await yn.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await yn.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=yn.appendPathToUrl({baseUrl:t,path:"/operations"}),c=await fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:c.ok},didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:"internalError",errorMessage:`Failed to publish DID document for: ${e.uri}`}}}}static async resolve(e,t={}){let n=Oe.parse(e);if(!n)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Wn.methodName)return{...Ue,didResolutionMetadata:{error:"methodNotSupported"}};let i=t?.gatewayUri??ly;try{let o=yn.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(o);if(!s.ok)throw new F("notFound",`Unable to find DID document for: ${e}`);let{didDocument:c,didDocumentMetadata:u}=await s.json();return{...Ue,...c&&{didDocument:c},didDocumentMetadata:{published:u?.method?.published,...u}}}catch(o){if(!(o instanceof F))throw new Error(o);return{...Ue,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};Wn.methodName="ion";var Jd=Wn,yn=class r{static appendPathToUrl({baseUrl:e,path:t}){let n=new URL(e);return n.pathname=n.pathname.endsWith("/")?n.pathname:n.pathname+"/",n.pathname+=t.startsWith("/")?t.substring(1):t,n.toString()}static async computeLongFormDidUri({recoveryKey:e,updateKey:t,services:n,verificationMethods:i}){let o=await r.createIonDocument({services:n,verificationMethods:i}),s=r.normalizeJwk(e),c=r.normalizeJwk(t);return await Hi.createLongFormDid({document:o,recoveryKey:s,updateKey:c})}static async constructCreateRequest({ionDocument:e,recoveryKey:t,updateKey:n}){return await fn.createCreateRequest({document:e,recoveryKey:r.normalizeJwk(t),updateKey:r.normalizeJwk(n)})}static async createIonDocument({services:e,verificationMethods:t}){let n=[];for(let s of t){let c=s.id??s.publicKeyJwk.kid??await te({jwk:s.publicKeyJwk});c=`${c.split("#").pop()}`;let u={id:c,publicKeyJwk:r.normalizeJwk(s.publicKeyJwk),purposes:s.purposes,type:"JsonWebKey2020"};n.push(u)}let i=e.map(s=>({...s,id:`${s.id.split("#").pop()}`}));return{publicKeys:n,services:i}}static normalizeJwk(e){let t=e.kty,n;if(t==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(t==="oct")n={k:e.k,kty:e.kty};else if(t==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(t==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${t}`);return n}};var PI=h(f(),1);var Yn=class Yn extends It{static async create({keyManager:e=new ot,options:t={}}={}){if(t.algorithm&&t.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(t.verificationMethods&&t.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=t.algorithm??t.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),o=await e.getPublicKey({keyUri:i}),s=M.object(o).toBase64Url(),c=`did:${Yn.methodName}:${s}`,d=(await Yn.resolve(c)).didDocument;return new ct({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Oe.parse(e.id);if(t&&t.method!==this.methodName)throw new F("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new F("internalError","A verification method intended for signing could not be determined from the DID Document");return n}static async import({portableDid:e,keyManager:t=new ot}){if(Oe.parse(e.uri)?.method!==Yn.methodName)throw new F("methodNotSupported","Method not supported");let i=await ct.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new F("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){let n=Oe.parse(e),i;try{i=n?M.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Yn.methodName)return{...Ue,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{...Ue,didDocument:o}}};Yn.methodName="jwk";var Gd=Yn;var zI=h(f(),1);var fy=(n=>(n.Ed25519="Ed25519",n.secp256k1="secp256k1",n.secp256r1="secp256r1",n))(fy||{}),Wd={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},Zx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},fr=class fr extends It{static async create({keyManager:e=new ot,options:t={}}={}){if(t.algorithm&&t.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(t.verificationMethods&&t.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=t.algorithm??t.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),o=await e.getPublicKey({keyUri:i}),s=await Xn.publicKeyToMultibaseId({publicKey:o}),c=`did:${fr.methodName}:${s}`,d=(await fr.resolve(c,t)).didDocument;return new ct({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Oe.parse(e.id);if(t&&t.method!==this.methodName)throw new F("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(o=>o.id===n);if(!(i&&i.publicKeyJwk))throw new F("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:t=new ot}){if(Oe.parse(e.uri)?.method!==fr.methodName)throw new F("methodNotSupported","Method not supported");let i=await ct.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new F("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){try{let n=await fr.createDocument({didUri:e,options:t});return{...Ue,didDocument:n}}catch(n){if(!(n instanceof F))throw new Error(n);return{...Ue,didResolutionMetadata:{error:n.code,...n.message&&{errorMessage:n.message}}}}}static async createDocument({didUri:e,options:t={}}){let{defaultContext:n="https://www.w3.org/ns/did/v1",enableExperimentalPublicKeyTypes:i=!1,publicKeyFormat:o="JsonWebKey2020"}=t,s={id:""},c=Oe.parse(e);if(!c)throw new F("invalidDid",`Invalid DID URI: ${e}`);let u=c.id;if(c.method!==fr.methodName)throw new F("methodNotSupported",`Method not supported: ${c.method}`);if(!fr.validateIdentifier(c))throw new F("invalidDid",`Invalid DID URI: ${e}`);let d=await fr.createSignatureMethod({didUri:e,multibaseValue:u,options:{enableExperimentalPublicKeyTypes:i,publicKeyFormat:o}});s.id=c.uri,s.verificationMethod=[d],s.authentication=[d.id],s.assertionMethod=[d.id],s.capabilityInvocation=[d.id],s.capabilityDelegation=[d.id];let a=[n];return Qu({didDocument:s}).forEach(g=>{let b=Wd[g];a.push(b)}),s["@context"]=a,s}static async createSignatureMethod({didUri:e,multibaseValue:t,options:n}){let{enableExperimentalPublicKeyTypes:i,publicKeyFormat:o}=n,s={id:"",type:"",controller:""},{keyBytes:c,multicodecCode:u,multicodecName:d}=rd({multibaseKeyId:t}),a=c.byteLength,l=Xn.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(a!==l)throw new F("invalidPublicKeyLength",`Expected ${a} bytes. Actual: ${l}`);let g=!1;switch(d){case"secp256k1-pub":g=await Je.validatePublicKey({publicKeyBytes:c});break;case"ed25519-pub":g=await Ge.validatePublicKey({publicKeyBytes:c});break}if(!g)throw new F("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${t}`;try{new URL(s.id)}catch{throw new F("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in Wd))throw new F("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(o))throw new F("invalidPublicKeyType",`Specified '${o}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=o,s.controller=e,o==="Ed25519VerificationKey2020"&&(s.publicKeyMultibase=t),o==="JsonWebKey2020"){let{crv:m}=await Xn.multicodecToJwk({code:u});s.publicKeyJwk=await Xn.keyConverter(m).bytesToPublicKey({publicKeyBytes:c})}return s}static validateIdentifier(e){let{method:t,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&t==="key"&&Number("1")>0&&hi(n)==="String"&&n.startsWith("z")}};fr.methodName="key";var Yd=fr,pr=class pr{static async jwkToMulticodec({jwk:e}){let t=[];e.crv&&(t.push(e.crv),e.d?t.push("private"):t.push("public"));let n=t.join(":"),i=pr.JWK_TO_MULTICODEC[n];if(i===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${n}'`);return{code:nt.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let n={"P-256":et.compressPublicKey,secp256k1:Je.compressPublicKey}[e];if(!n)throw new F("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Ge,"P-256":et,secp256k1:Je}[e];if(!n)throw new F("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async multicodecToJwk({code:e,name:t}){if(!(t?!e:e))throw new Error("Either 'name' or 'code' must be defined, but not both.");t=t===void 0?nt.getNameFromCode({code:e}):t;let n=t,i=pr.MULTICODEC_TO_JWK[n];if(i===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return{...i}}static async publicKeyToMultibaseId({publicKey:e}){if(!(e?.crv&&e.crv in Zx))throw new F("invalidPublicKeyType",`Public key contains an unsupported key type: ${e?.crv??"undefined"}`);let t=await pr.keyConverter(e.crv).publicKeyToBytes({publicKey:e});/^(secp256k1|P-256|P-384|P-521)$/.test(e.crv)&&(t=await pr.keyCompressor(e.crv)({publicKeyBytes:t}));let{name:n}=await pr.jwkToMulticodec({jwk:e});return td({keyBytes:t,multicodecName:n})}};pr.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv"},pr.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,237:32},pr.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:""}};var Xn=pr;var XI=h(f(),1);var ra=class ra extends It{static async resolve(e,t){let n=Oe.parse(e);if(!n)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ra.methodName)return{...Ue,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=await fetch(o);if(!s.ok)throw new Error("HTTP error status code returned");let c=await s.json();return{...Ue,didDocument:c}}catch{return{...Ue,didResolutionMetadata:{error:"notFound"}}}}};ra.methodName="web";var Xd=ra;var t5=h(f(),1),my=h(Su(),1),gy=h(yy(),1),Zd=class{constructor({db:e,location:t="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new my.Level(t),this.ttl=(0,gy.default)(n)}async get(e){try{let t=await this.cache.get(e),n=JSON.parse(t);if(Date.now()>=n.ttlMillis){this.cache.nextTick(()=>this.cache.del(e));return}else return n.value}catch(t){if(t.notFound)return;throw t}}set(e,t){let n={ttlMillis:Date.now()+this.ttl,value:t},i=JSON.stringify(n);return this.cache.put(e,i)}delete(e){return this.cache.del(e)}clear(){return this.cache.clear()}close(){return this.cache.close()}};var n5=h(f(),1),Qd={get(r){return Promise.resolve(void 0)},set(r,e){return Promise.resolve()},delete(r){return Promise.resolve()},clear(){return Promise.resolve()},close(){return Promise.resolve()}};var u5=h(f(),1);var el=class{constructor({cache:e,didResolvers:t}){this.didResolvers=new Map;this.cache=e||Qd;for(let n of t)this.didResolvers.set(n.methodName,n)}async resolve(e,t){let n=Oe.parse(e);if(!n)return{...Ue,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${e}`}};let i=this.didResolvers.get(n.method);if(!i)return{...Ue,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${n.method}`}};let o=await this.cache.get(n.uri);if(o)return o;{let s=await i.resolve(n.uri,t);return s.didResolutionMetadata.error||await this.cache.set(n.uri,s),s}}async dereference(e,t){let n=Oe.parse(e);if(!n)return{dereferencingMetadata:{error:"invalidDidUrl"},contentStream:null,contentMetadata:{}};let{didDocument:i,didResolutionMetadata:o,didDocumentMetadata:s}=await this.resolve(n.uri);if(!i)return{dereferencingMetadata:{error:o.error},contentStream:null,contentMetadata:{}};if(!n.fragment||n.query)return{dereferencingMetadata:{contentType:"application/did+json"},contentStream:i,contentMetadata:s};let{service:c=[],verificationMethod:u=[]}=i,d=new Set([e,n.fragment,`#${n.fragment}`]),a;for(let l of u)if(d.has(l.id)){a=l;break}for(let l of c)if(d.has(l.id)){a=l;break}return a?{dereferencingMetadata:{contentType:"application/did+json"},contentStream:a,contentMetadata:o}:{dereferencingMetadata:{error:"notFound"},contentStream:null,contentMetadata:{}}}};return Vy(ib);})();
3
2
  /*! Bundled license information:
4
3
 
5
4
  ieee754/index.js:
@@ -19,21 +18,15 @@ queue-microtask/index.js:
19
18
  run-parallel-limit/index.js:
20
19
  (*! run-parallel-limit. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
21
20
 
22
- safe-buffer/index.js:
23
- (*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
24
-
25
21
  uri-js/dist/es5/uri.all.js:
26
22
  (** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js *)
27
23
 
28
- @noble/hashes/esm/utils.js:
29
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
24
+ @noble/curves/esm/abstract/utils.js:
25
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
30
26
 
31
27
  @noble/hashes/esm/utils.js:
32
28
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
33
29
 
34
- @noble/curves/esm/abstract/utils.js:
35
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
36
-
37
30
  @noble/curves/esm/abstract/modular.js:
38
31
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
39
32
 
@@ -49,6 +42,9 @@ uri-js/dist/es5/uri.all.js:
49
42
  @noble/curves/esm/secp256k1.js:
50
43
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
51
44
 
45
+ @noble/hashes/esm/utils.js:
46
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
47
+
52
48
  @noble/curves/esm/p256.js:
53
49
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
54
50