@enbox/dids 0.0.3 → 0.0.5

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 (77) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/index.js +2 -0
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/methods/did-dht-dns.js +455 -0
  6. package/dist/esm/methods/did-dht-dns.js.map +1 -0
  7. package/dist/esm/methods/did-dht-pkarr.js +168 -0
  8. package/dist/esm/methods/did-dht-pkarr.js.map +1 -0
  9. package/dist/esm/methods/did-dht-types.js +116 -0
  10. package/dist/esm/methods/did-dht-types.js.map +1 -0
  11. package/dist/esm/methods/did-dht-utils.js +143 -0
  12. package/dist/esm/methods/did-dht-utils.js.map +1 -0
  13. package/dist/esm/methods/did-dht.js +65 -842
  14. package/dist/esm/methods/did-dht.js.map +1 -1
  15. package/dist/esm/methods/did-ion-utils.js +161 -0
  16. package/dist/esm/methods/did-ion-utils.js.map +1 -0
  17. package/dist/esm/methods/did-ion.js +4 -151
  18. package/dist/esm/methods/did-ion.js.map +1 -1
  19. package/dist/esm/methods/did-jwk.js.map +1 -1
  20. package/dist/esm/methods/did-key-utils.js +235 -0
  21. package/dist/esm/methods/did-key-utils.js.map +1 -0
  22. package/dist/esm/methods/did-key.js +6 -222
  23. package/dist/esm/methods/did-key.js.map +1 -1
  24. package/dist/esm/resolver/resolver-cache-memory.js +77 -0
  25. package/dist/esm/resolver/resolver-cache-memory.js.map +1 -0
  26. package/dist/esm/utils.js +25 -0
  27. package/dist/esm/utils.js.map +1 -1
  28. package/dist/types/bearer-did.d.ts +4 -4
  29. package/dist/types/bearer-did.d.ts.map +1 -1
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/methods/did-dht-dns.d.ts +114 -0
  33. package/dist/types/methods/did-dht-dns.d.ts.map +1 -0
  34. package/dist/types/methods/did-dht-pkarr.d.ts +56 -0
  35. package/dist/types/methods/did-dht-pkarr.d.ts.map +1 -0
  36. package/dist/types/methods/did-dht-types.d.ts +286 -0
  37. package/dist/types/methods/did-dht-types.d.ts.map +1 -0
  38. package/dist/types/methods/did-dht-utils.d.ts +54 -0
  39. package/dist/types/methods/did-dht-utils.d.ts.map +1 -0
  40. package/dist/types/methods/did-dht.d.ts +45 -460
  41. package/dist/types/methods/did-dht.d.ts.map +1 -1
  42. package/dist/types/methods/did-ion-utils.d.ts +86 -0
  43. package/dist/types/methods/did-ion-utils.d.ts.map +1 -0
  44. package/dist/types/methods/did-ion.d.ts +4 -84
  45. package/dist/types/methods/did-ion.d.ts.map +1 -1
  46. package/dist/types/methods/did-jwk.d.ts +4 -4
  47. package/dist/types/methods/did-jwk.d.ts.map +1 -1
  48. package/dist/types/methods/did-key-utils.d.ts +138 -0
  49. package/dist/types/methods/did-key-utils.d.ts.map +1 -0
  50. package/dist/types/methods/did-key.d.ts +6 -127
  51. package/dist/types/methods/did-key.d.ts.map +1 -1
  52. package/dist/types/methods/did-method.d.ts +3 -3
  53. package/dist/types/methods/did-method.d.ts.map +1 -1
  54. package/dist/types/resolver/resolver-cache-memory.d.ts +58 -0
  55. package/dist/types/resolver/resolver-cache-memory.d.ts.map +1 -0
  56. package/dist/types/utils.d.ts +19 -0
  57. package/dist/types/utils.d.ts.map +1 -1
  58. package/dist/utils.js +1 -1
  59. package/dist/utils.js.map +4 -4
  60. package/package.json +11 -13
  61. package/src/bearer-did.ts +4 -4
  62. package/src/index.ts +2 -0
  63. package/src/methods/did-dht-dns.ts +516 -0
  64. package/src/methods/did-dht-pkarr.ts +192 -0
  65. package/src/methods/did-dht-types.ts +316 -0
  66. package/src/methods/did-dht-utils.ts +157 -0
  67. package/src/methods/did-dht.ts +125 -1131
  68. package/src/methods/did-ion-utils.ts +186 -0
  69. package/src/methods/did-ion.ts +16 -185
  70. package/src/methods/did-jwk.ts +4 -4
  71. package/src/methods/did-key-utils.ts +258 -0
  72. package/src/methods/did-key.ts +20 -272
  73. package/src/methods/did-method.ts +3 -3
  74. package/src/resolver/resolver-cache-memory.ts +84 -0
  75. package/src/utils.ts +27 -0
  76. package/dist/browser.js +0 -73
  77. package/dist/browser.js.map +0 -7
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var ky=Object.create;var sa=Object.defineProperty;var Cy=Object.getOwnPropertyDescriptor;var Ry=Object.getOwnPropertyNames;var Py=Object.getPrototypeOf,Ly=Object.prototype.hasOwnProperty;var ae=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ca=(r,e)=>{for(var t in e)sa(r,t,{get:e[t],enumerable:!0})},My=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ry(e))!Ly.call(r,i)&&i!==t&&sa(r,i,{get:()=>e[i],enumerable:!(n=Cy(e,i))||n.enumerable});return r};var h=(r,e,t)=>(t=r!=null?ky(Py(r)):{},My(e||!r||!r.__esModule?sa(t,"default",{value:r,enumerable:!0}):t,r));var tl=ae(ms=>{"use strict";var fb=h(f());ms.byteLength=$y;ms.toByteArray=Fy;ms.fromByteArray=jy;var er=[],_t=[],Ny=typeof Uint8Array<"u"?Uint8Array:Array,aa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(xn=0,Qd=aa.length;xn<Qd;++xn)er[xn]=aa[xn],_t[aa.charCodeAt(xn)]=xn;var xn,Qd;_t[45]=62;_t[95]=63;function el(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 $y(r){var e=el(r),t=e[0],n=e[1];return(t+n)*3/4-n}function Vy(r,e,t){return(e+t)*3/4-t}function Fy(r){var e,t=el(r),n=t[0],i=t[1],o=new Ny(Vy(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=_t[r.charCodeAt(u)]<<18|_t[r.charCodeAt(u+1)]<<12|_t[r.charCodeAt(u+2)]<<6|_t[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=_t[r.charCodeAt(u)]<<2|_t[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=_t[r.charCodeAt(u)]<<10|_t[r.charCodeAt(u+1)]<<4|_t[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Hy(r){return er[r>>18&63]+er[r>>12&63]+er[r>>6&63]+er[r&63]}function qy(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(Hy(n));return i.join("")}function jy(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(qy(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 rl=ae(ua=>{var yb=h(f());ua.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)};ua.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 ai=ae(ci=>{"use strict";var wb=h(f());var da=tl(),oi=rl(),nl=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ci.Buffer=B;ci.SlowBuffer=Xy;ci.INSPECT_MAX_BYTES=50;var gs=2147483647;ci.kMaxLength=gs;B.TYPED_ARRAY_SUPPORT=zy();!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 zy(){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>gs)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 pa(r)}return cl(r,e,t)}B.poolSize=8192;function cl(r,e,t){if(typeof r=="string")return Gy(r,e);if(ArrayBuffer.isView(r))return Wy(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 ha(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=Yy(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 cl(r,e,t)};Object.setPrototypeOf(B.prototype,Uint8Array.prototype);Object.setPrototypeOf(B,Uint8Array);function al(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 Jy(r,e,t){return al(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 Jy(r,e,t)};function pa(r){return al(r),xr(r<0?0:ya(r)|0)}B.allocUnsafe=function(r){return pa(r)};B.allocUnsafeSlow=function(r){return pa(r)};function Gy(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!B.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=ul(r,e)|0,n=xr(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function la(r){let e=r.length<0?0:ya(r.length)|0,t=xr(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Wy(r){if(tr(r,Uint8Array)){let e=new Uint8Array(r);return ha(e.buffer,e.byteOffset,e.byteLength)}return la(r)}function ha(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 Yy(r){if(B.isBuffer(r)){let e=ya(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"||ga(r.length)?xr(0):la(r);if(r.type==="Buffer"&&Array.isArray(r.data))return la(r.data)}function ya(r){if(r>=gs)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+gs.toString(16)+" bytes");return r|0}function Xy(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 ul(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 fa(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return wl(r).length;default:if(i)return n?-1:fa(r).length;e=(""+e).toLowerCase(),i=!0}}B.byteLength=ul;function Zy(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 a0(this,e,t);case"utf8":case"utf-8":return ll(this,e,t);case"ascii":return s0(this,e,t);case"latin1":case"binary":return c0(this,e,t);case"base64":return i0(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u0(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}B.prototype._isBuffer=!0;function bn(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)bn(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)bn(this,t,t+3),bn(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)bn(this,t,t+7),bn(this,t+1,t+6),bn(this,t+2,t+5),bn(this,t+3,t+4);return this};B.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?ll(this,0,e):Zy.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=ci.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};nl&&(B.prototype[nl]=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 dl(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,ga(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:il(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):il(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function il(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 dl(this,e,t,n,!0)};B.prototype.lastIndexOf=function(e,t,n){return dl(this,e,t,n,!1)};function Qy(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(ga(c))return s;r[t+s]=c}return s}function e0(r,e,t,n){return ws(fa(e,r.length-t),r,t,n)}function t0(r,e,t,n){return ws(f0(e),r,t,n)}function r0(r,e,t,n){return ws(wl(e),r,t,n)}function n0(r,e,t,n){return ws(p0(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 Qy(this,e,t,n);case"utf8":case"utf-8":return e0(this,e,t,n);case"ascii":case"latin1":case"binary":return t0(this,e,t,n);case"base64":return r0(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n0(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 i0(r,e,t){return e===0&&t===r.length?da.fromByteArray(r):da.fromByteArray(r.slice(e,t))}function ll(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 o0(n)}var ol=4096;function o0(r){let e=r.length;if(e<=ol)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=ol));return t}function s0(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 c0(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 a0(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+=y0[r[o]];return i}function u0(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 je(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||je(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||je(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||je(e,1,this.length),this[e]};B.prototype.readUint16LE=B.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||je(e,2,this.length),this[e]|this[e+1]<<8};B.prototype.readUint16BE=B.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||je(e,2,this.length),this[e]<<8|this[e+1]};B.prototype.readUint32LE=B.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||je(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||je(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};B.prototype.readBigUInt64LE=Fr(function(e){e=e>>>0,si(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=Fr(function(e){e=e>>>0,si(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||je(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||je(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||je(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};B.prototype.readInt16LE=function(e,t){e=e>>>0,t||je(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||je(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||je(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||je(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};B.prototype.readBigInt64LE=Fr(function(e){e=e>>>0,si(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=Fr(function(e){e=e>>>0,si(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||je(e,4,this.length),oi.read(this,e,!0,23,4)};B.prototype.readFloatBE=function(e,t){return e=e>>>0,t||je(e,4,this.length),oi.read(this,e,!1,23,4)};B.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||je(e,8,this.length),oi.read(this,e,!0,52,8)};B.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||je(e,8,this.length),oi.read(this,e,!1,52,8)};function ut(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;ut(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;ut(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||ut(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||ut(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||ut(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||ut(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||ut(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 hl(r,e,t,n,i){gl(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 fl(r,e,t,n,i){gl(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=Fr(function(e,t=0){return hl(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});B.prototype.writeBigUInt64BE=Fr(function(e,t=0){return fl(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);ut(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);ut(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||ut(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||ut(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||ut(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||ut(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||ut(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=Fr(function(e,t=0){return hl(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});B.prototype.writeBigInt64BE=Fr(function(e,t=0){return fl(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function pl(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 yl(r,e,t,n,i){return e=+e,t=t>>>0,i||pl(r,e,t,4,34028234663852886e22,-34028234663852886e22),oi.write(r,e,t,n,23,4),t+4}B.prototype.writeFloatLE=function(e,t,n){return yl(this,e,t,!0,n)};B.prototype.writeFloatBE=function(e,t,n){return yl(this,e,t,!1,n)};function ml(r,e,t,n,i){return e=+e,t=t>>>0,i||pl(r,e,t,8,17976931348623157e292,-17976931348623157e292),oi.write(r,e,t,n,52,8),t+8}B.prototype.writeDoubleLE=function(e,t,n){return ml(this,e,t,!0,n)};B.prototype.writeDoubleBE=function(e,t,n){return ml(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 ii={};function ma(r,e,t){ii[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}`}}}ma("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);ma("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);ma("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=sl(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=sl(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function sl(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 d0(r,e,t){si(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&io(e,r.length-(t+1))}function gl(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 ii.ERR_OUT_OF_RANGE("value",c,r)}d0(n,i,o)}function si(r,e){if(typeof r!="number")throw new ii.ERR_INVALID_ARG_TYPE(e,"number",r)}function io(r,e,t){throw Math.floor(r)!==r?(si(r,t),new ii.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ii.ERR_BUFFER_OUT_OF_BOUNDS:new ii.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var l0=/[^+/0-9A-Za-z-_]/g;function h0(r){if(r=r.split("=")[0],r=r.trim().replace(l0,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function fa(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 f0(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function p0(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 wl(r){return da.toByteArray(h0(r))}function ws(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 ga(r){return r!==r}var y0=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 Fr(r){return typeof BigInt>"u"?m0:r}function m0(){throw new Error("BigInt not supported")}});var f=ae(()=>{"use strict";var xl=ai().Buffer,{Buffer:g0}=ai();xl.prototype.writeBigUInt64BE=g0.prototype.writeBigUInt64BE;globalThis.Buffer=xl});var vl=ae((Kb,bl)=>{var _b=h(f()),w0=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,xs=()=>w0.now(),x0=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),xa=r=>r===1/0||x0(r),ba=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&&!xa(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!xa(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-xs());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(xs()+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(!xa(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-xs())):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(xs());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()}};bl.exports=ba});var Ml=ae(Ll=>{"use strict";var Qv=h(f());Ll.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((t1,Nl)=>{"use strict";var r1=h(f());Nl.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 Ra=ae((n1,$l)=>{"use strict";var i1=h(f()),Ca=null;$l.exports=function(){return Ca===null&&(Ca={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ca}});var Ma=ae(Vl=>{"use strict";var s1=h(f()),Pa=Ft(),Z0=new Set(["buffer","view","utf8"]),La=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"||!Z0.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 Pa(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Pa(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Pa(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};Vl.Encoding=La});var Fa=ae(vs=>{"use strict";var a1=h(f()),{Buffer:$a}=ai()||{},{Encoding:Va}=Ma(),Q0=Ra(),lo=class extends Va{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new ho({encode:this.encode,decode:e=>this.decode($a.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},ho=class extends Va{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new lo({encode:e=>{let t=this.encode(e);return $a.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Na=class extends Va{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new lo({encode:e=>$a.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=Q0();return new ho({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};vs.BufferFormat=lo;vs.ViewFormat=ho;vs.UTF8Format=Na});var jl=ae(Tn=>{"use strict";var d1=h(f()),{Buffer:it}=ai()||{Buffer:{isBuffer:()=>!1}},{textEncoder:Hl,textDecoder:Fl}=Ra()(),{BufferFormat:fo,ViewFormat:Ha,UTF8Format:ql}=Fa(),Es=r=>r;Tn.utf8=new ql({encode:function(r){return it.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?Fl.decode(r):String(r)},decode:Es,name:"utf8",createViewTranscoder(){return new Ha({encode:function(r){return ArrayBuffer.isView(r)?r:Hl.encode(r)},decode:function(r){return Fl.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`})}});Tn.json=new ql({encode:JSON.stringify,decode:JSON.parse,name:"json"});Tn.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:Es,name:"buffer",createViewTranscoder(){return new Ha({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`})}});Tn.view=new Ha({encode:function(r){return ArrayBuffer.isView(r)?r:Hl.encode(r)},decode:Es,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:Es,name:`${this.name}+buffer`})}});Tn.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"});Tn.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 Gl=ae(Jl=>{"use strict";var h1=h(f()),zl=Ft(),Ts=jl(),{Encoding:em}=Ma(),{BufferFormat:tm,ViewFormat:rm,UTF8Format:nm}=Fa(),po=Symbol("formats"),As=Symbol("encodings"),im=new Set(["buffer","view","utf8"]),qa=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>im.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[As]=new Map,this[po]=new Set(e);for(let t in Ts)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[As].values()))}encoding(e){let t=this[As].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=am[e],!t)throw new zl(`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=om(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 zl(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[As].set(o,t)}return t}};Jl.Transcoder=qa;function om(r){if(r instanceof em)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${um++}`;switch(sm(r)){case"view":return new rm({...r,name:t});case"utf8":return new nm({...r,name:t});case"buffer":return new tm({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function sm(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 cm={binary:Ts.buffer,"utf-8":Ts.utf8},am={...Ts,...cm},um=0});var oh=ae((f1,ja)=>{"use strict";var p1=h(f()),pi=typeof Reflect=="object"?Reflect:null,Wl=pi&&typeof pi.apply=="function"?pi.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},Bs;pi&&typeof pi.ownKeys=="function"?Bs=pi.ownKeys:Object.getOwnPropertySymbols?Bs=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Bs=function(e){return Object.getOwnPropertyNames(e)};function dm(r){console&&console.warn&&console.warn(r)}var Xl=Number.isNaN||function(e){return e!==e};function xe(){xe.init.call(this)}ja.exports=xe;ja.exports.once=pm;xe.EventEmitter=xe;xe.prototype._events=void 0;xe.prototype._eventsCount=0;xe.prototype._maxListeners=void 0;var Yl=10;function Ss(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 Yl},set:function(r){if(typeof r!="number"||r<0||Xl(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");Yl=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||Xl(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 Zl(r){return r._maxListeners===void 0?xe.defaultMaxListeners:r._maxListeners}xe.prototype.getMaxListeners=function(){return Zl(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")Wl(u,this,t);else for(var d=u.length,a=nh(u,d),n=0;n<d;++n)Wl(a[n],this,t);return!0};function Ql(r,e,t,n){var i,o,s;if(Ss(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=Zl(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,dm(c)}return r}xe.prototype.addListener=function(e,t){return Ql(this,e,t,!1)};xe.prototype.on=xe.prototype.addListener;xe.prototype.prependListener=function(e,t){return Ql(this,e,t,!0)};function lm(){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 eh(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},i=lm.bind(n);return i.listener=t,n.wrapFn=i,i}xe.prototype.once=function(e,t){return Ss(t),this.on(e,eh(this,e,t)),this};xe.prototype.prependOnceListener=function(e,t){return Ss(t),this.prependListener(e,eh(this,e,t)),this};xe.prototype.removeListener=function(e,t){var n,i,o,s,c;if(Ss(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():hm(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 th(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?fm(i):nh(i,i.length)}xe.prototype.listeners=function(e){return th(this,e,!0)};xe.prototype.rawListeners=function(e){return th(this,e,!1)};xe.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):rh.call(r,e)};xe.prototype.listenerCount=rh;function rh(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?Bs(this._events):[]};function nh(r,e){for(var t=new Array(e),n=0;n<e;++n)t[n]=r[n];return t}function hm(r,e){for(;e+1<r.length;e++)r[e]=r[e+1];r.pop()}function fm(r){for(var e=new Array(r.length),t=0;t<e.length;++t)e[t]=r[t].listener||r[t];return e}function pm(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))}ih(r,e,o,{once:!0}),e!=="error"&&ym(r,i,{once:!0})})}function ym(r,e,t){typeof r.on=="function"&&ih(r,"error",e,t)}function ih(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 ch=ae((y1,sh)=>{var m1=h(f());sh.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var yo=ae(za=>{"use strict";var w1=h(f()),ah=ch();za.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};za.fromPromise=function(r,e){if(e===void 0)return r;r.then(function(t){ah(()=>e(null,t))}).catch(function(t){ah(()=>e(t))})}});var Is=ae(Ja=>{"use strict";var b1=h(f());Ja.getCallback=function(r,e){return typeof r=="function"?r:e};Ja.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var Wr=ae(Ks=>{"use strict";var E1=h(f()),{fromCallback:Ga}=yo(),vt=Ft(),{getOptions:Wa,getCallback:uh}=Is(),Bn=Symbol("promise"),yi=Symbol("callback"),nr=Symbol("working"),Sn=Symbol("handleOne"),vr=Symbol("handleMany"),Ya=Symbol("autoClose"),Jr=Symbol("finishWork"),ir=Symbol("returnMany"),qr=Symbol("closing"),mo=Symbol("handleClose"),Ds=Symbol("closed"),go=Symbol("closeCallbacks"),zr=Symbol("keyEncoding"),In=Symbol("valueEncoding"),Xa=Symbol("abortOnClose"),Us=Symbol("legacy"),Za=Symbol("keys"),Qa=Symbol("values"),jr=Symbol("limit"),kt=Symbol("count"),Os=Object.freeze({}),mm=()=>{},dh=!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[Ds]=!1,this[go]=[],this[nr]=!1,this[qr]=!1,this[Ya]=!1,this[yi]=null,this[Sn]=this[Sn].bind(this),this[vr]=this[vr].bind(this),this[mo]=this[mo].bind(this),this[zr]=t[zr],this[In]=t[In],this[Us]=n,this[jr]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[kt]=0,this[Xa]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[kt]}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[Us]?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[yi]=e,this[kt]>=this[jr]?this.nextTick(this[Sn],null):this._next(this[Sn])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=uh(t,n),n=Ga(n,Bn),t=Wa(t,Os),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[kt])),this[nr]=!0,this[yi]=n,e<=0?this.nextTick(this[vr],null,[]):this._nextv(e,t,this[vr])),n[Bn]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[Bn])}_nextv(e,t,n){let i=[],o=(s,c,u)=>{if(s)return n(s);if(this[Us]?c===void 0&&u===void 0:c===void 0)return n(null,i);i.push(this[Us]?[c,u]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=uh(e,t),t=Ga(t,Bn),e=Wa(e,Os),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[yi]=t,this[Ya]=!0,this[kt]>=this[jr]?this.nextTick(this[vr],null,[]):this._all(e,this[vr])),t[Bn]}_all(e,t){let n=this[kt],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,Os,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[yi];return this[Xa]&&e===null?mm:(this[nr]=!1,this[yi]=null,this[qr]&&this._close(this[mo]),e)}[ir](e,t,n){this[Ya]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=Wa(t,Os),!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=Ga(e,Bn),this[Ds]?this.nextTick(e):this[qr]?this[go].push(e):(this[qr]=!0,this[go].push(e),this[nr]?this[Xa]&&this[Jr]()(new vt("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[mo])),e[Bn]}_close(e){this.nextTick(e)}[mo](){this[Ds]=!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[Ds]||await this.close()}}},mi=class extends wo{constructor(e,t){super(e,t,!0),this[Za]=t.keys!==!1,this[Qa]=t.values!==!1}[Sn](e,t,n){let i=this[Jr]();if(e)return i(e);try{t=this[Za]&&t!==void 0?this[zr].decode(t):void 0,n=this[Qa]&&n!==void 0?this[In].decode(n):void 0}catch(o){return i(new Gr("entry",o))}t===void 0&&n===void 0||this[kt]++,i(null,t,n)}[vr](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[Za]&&o!==void 0?this[zr].decode(o):void 0,i[1]=this[Qa]&&s!==void 0?this[In].decode(s):void 0}}catch(i){return this[ir](n,new Gr("entries",i))}this[kt]+=t.length,this[ir](n,null,t)}end(e){return!dh&&typeof console<"u"&&(dh=!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)}},eu=class extends wo{constructor(e,t){super(e,t,!1)}[Sn](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[kt]++,n(null,t)}[vr](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[kt]+=t.length,this[ir](n,null,t)}},tu=class extends wo{constructor(e,t){super(e,t,!1)}[Sn](e,t){let n=this[Jr]();if(e)return n(e);try{t=t!==void 0?this[In].decode(t):void 0}catch(i){return n(new Gr("value",i))}t!==void 0&&this[kt]++,n(null,t)}[vr](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[In].decode(o):void 0}}catch(i){return this[ir](n,new Gr("values",i))}this[kt]+=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(mi.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"})}});mi.keyEncoding=zr;mi.valueEncoding=In;Ks.AbstractIterator=mi;Ks.AbstractKeyIterator=eu;Ks.AbstractValueIterator=tu});var lh=ae(ru=>{"use strict";var T1=h(f()),{AbstractKeyIterator:gm,AbstractValueIterator:wm}=Wr(),Dn=Symbol("iterator"),xo=Symbol("callback"),gi=Symbol("handleOne"),Un=Symbol("handleMany"),bo=class extends gm{constructor(e,t){super(e,t),this[Dn]=e.iterator({...t,keys:!0,values:!1}),this[gi]=this[gi].bind(this),this[Un]=this[Un].bind(this)}},_s=class extends wm{constructor(e,t){super(e,t),this[Dn]=e.iterator({...t,keys:!1,values:!0}),this[gi]=this[gi].bind(this),this[Un]=this[Un].bind(this)}};for(let r of[bo,_s]){let e=r===bo,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[xo]=n,this[Dn].next(this[gi])},r.prototype[gi]=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[Dn].nextv(n,i,this[Un])},r.prototype._all=function(n,i){this[xo]=i,this[Dn].all(n,this[Un])},r.prototype[Un]=function(n,i){let o=this[xo];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[Dn].seek(n,i)},r.prototype._close=function(n){this[Dn].close(n)}}ru.DefaultKeyIterator=bo;ru.DefaultValueIterator=_s});var hh=ae(Ms=>{"use strict";var S1=h(f()),{AbstractIterator:xm,AbstractKeyIterator:bm,AbstractValueIterator:vm}=Wr(),nu=Ft(),lt=Symbol("nut"),Ps=Symbol("undefer"),Ls=Symbol("factory"),ks=class extends xm{constructor(e,t){super(e,t),this[lt]=null,this[Ls]=()=>e.iterator(t),this.db.defer(()=>this[Ps]())}},Cs=class extends bm{constructor(e,t){super(e,t),this[lt]=null,this[Ls]=()=>e.keys(t),this.db.defer(()=>this[Ps]())}},Rs=class extends vm{constructor(e,t){super(e,t),this[lt]=null,this[Ls]=()=>e.values(t),this.db.defer(()=>this[Ps]())}};for(let r of[ks,Cs,Rs])r.prototype[Ps]=function(){this.db.status==="open"&&(this[lt]=this[Ls]())},r.prototype._next=function(e){this[lt]!==null?this[lt].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new nu("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(e,t,n){this[lt]!==null?this[lt].nextv(e,t,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,t,n)):this.nextTick(n,new nu("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(e,t){this[lt]!==null?this[lt].all(t):this.db.status==="opening"?this.db.defer(()=>this._all(e,t)):this.nextTick(t,new nu("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(e,t){this[lt]!==null?this[lt]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t))},r.prototype._close=function(e){this[lt]!==null?this[lt].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};Ms.DeferredIterator=ks;Ms.DeferredKeyIterator=Cs;Ms.DeferredValueIterator=Rs});var ou=ae(ph=>{"use strict";var D1=h(f()),{fromCallback:fh}=yo(),Ns=Ft(),{getCallback:Em,getOptions:Am}=Is(),$s=Symbol("promise"),Ct=Symbol("status"),wi=Symbol("operations"),vo=Symbol("finishClose"),xi=Symbol("closeCallbacks"),iu=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[wi]=[],this[xi]=[],this[Ct]="open",this[vo]=this[vo].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[wi].length}put(e,t,n){if(this[Ct]!=="open")throw new Ns("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[wi].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[Ct]!=="open")throw new Ns("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[wi].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[Ct]!=="open")throw new Ns("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[wi]=[],this}_clear(){}write(e,t){return t=Em(e,t),t=fh(t,$s),e=Am(e),this[Ct]!=="open"?this.nextTick(t,new Ns("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[Ct]="writing",this._write(e,n=>{this[Ct]="closing",this[xi].push(()=>t(n)),n||this.db.emit("batch",this[wi]),this._close(this[vo])})),t[$s]}_write(e,t){}close(e){return e=fh(e,$s),this[Ct]==="closing"?this[xi].push(e):this[Ct]==="closed"?this.nextTick(e):(this[xi].push(e),this[Ct]!=="writing"&&(this[Ct]="closing",this._close(this[vo]))),e[$s]}_close(e){this.nextTick(e)}[vo](){this[Ct]="closed",this.db.detachResource(this);let e=this[xi];this[xi]=[];for(let t of e)t()}};ph.AbstractChainedBatch=iu});var mh=ae(yh=>{"use strict";var O1=h(f()),{AbstractChainedBatch:Tm}=ou(),Bm=Ft(),bi=Symbol("encoded"),su=class extends Tm{constructor(e){super(e),this[bi]=[]}_put(e,t,n){this[bi].push({...n,type:"put",key:e,value:t})}_del(e,t){this[bi].push({...t,type:"del",key:e})}_clear(){this[bi]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[bi].length===0?this.nextTick(t):this.db._batch(this[bi],e,t):this.nextTick(t,new Bm("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};yh.DefaultChainedBatch=su});var xh=ae((K1,wh)=>{"use strict";var _1=h(f()),gh=Ft(),Sm=Object.prototype.hasOwnProperty,Im=new Set(["lt","lte","gt","gte"]);wh.exports=function(r,e){let t={};for(let n in r)if(Sm.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new gh(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new gh("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});Im.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 cu=ae((k1,vh)=>{var C1=h(f());var bh;vh.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(bh||(bh=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var Th=ae((R1,Ah)=>{"use strict";var P1=h(f()),Eh=cu();Ah.exports=function(r,...e){e.length===0?Eh(r):Eh(()=>r(...e))}});var Bh=ae(Vs=>{"use strict";var M1=h(f()),{AbstractIterator:Dm,AbstractKeyIterator:Um,AbstractValueIterator:Om}=Wr(),vi=Symbol("unfix"),Ht=Symbol("iterator"),On=Symbol("handleOne"),Yr=Symbol("handleMany"),Er=Symbol("callback"),Eo=class extends Dm{constructor(e,t,n,i){super(e,t),this[Ht]=n,this[vi]=i,this[On]=this[On].bind(this),this[Yr]=this[Yr].bind(this),this[Er]=null}[On](e,t,n){let i=this[Er];if(e)return i(e);t!==void 0&&(t=this[vi](t)),i(e,t,n)}[Yr](e,t){let n=this[Er];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[vi](o))}n(e,t)}},Ao=class extends Um{constructor(e,t,n,i){super(e,t),this[Ht]=n,this[vi]=i,this[On]=this[On].bind(this),this[Yr]=this[Yr].bind(this),this[Er]=null}[On](e,t){let n=this[Er];if(e)return n(e);t!==void 0&&(t=this[vi](t)),n(e,t)}[Yr](e,t){let n=this[Er];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[vi](o))}n(e,t)}},To=class extends Om{constructor(e,t,n){super(e,t),this[Ht]=n}};for(let r of[Eo,Ao])r.prototype._next=function(e){this[Er]=e,this[Ht].next(this[On])},r.prototype._nextv=function(e,t,n){this[Er]=n,this[Ht].nextv(e,t,this[Yr])},r.prototype._all=function(e,t){this[Er]=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)};Vs.AbstractSublevelIterator=Eo;Vs.AbstractSublevelKeyIterator=Ao;Vs.AbstractSublevelValueIterator=To});var Uh=ae((N1,Dh)=>{"use strict";var $1=h(f()),au=Ft(),{Buffer:lu}=ai()||{},{AbstractSublevelIterator:Km,AbstractSublevelKeyIterator:_m,AbstractSublevelValueIterator:km}=Bh(),Ar=Symbol("prefix"),Sh=Symbol("upperBound"),Bo=Symbol("prefixRange"),Et=Symbol("parent"),uu=Symbol("unfix"),Ih=new TextEncoder,Cm={separator:"!"};Dh.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new au("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new au("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?Cm:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...u}=e.defaults(o);i=Pm(i,s);let d=s.charCodeAt(0)+1,a=n[Et]||n;if(!Ih.encode(i).every(b=>b>d&&b<127))throw new au(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Rm(a,c),u);let l=(n.prefix||"")+s+i+s,g=l.slice(0,-1)+String.fromCharCode(d);this[Et]=a,this[Ar]=new Fs(l),this[Sh]=new Fs(g),this[uu]=new hu,this.nextTick=a.nextTick}prefixKey(n,i){if(i==="utf8")return this[Ar].utf8+n;if(n.byteLength===0)return this[Ar][i];if(i==="view"){let o=this[Ar].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Ar].buffer;return lu.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[Ar][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[Sh][i]}get prefix(){return this[Ar].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[uu].get(this[Ar].utf8.length,n.keyEncoding);return new Km(this,n,i,o)}_keys(n){this[Bo](n,n.keyEncoding);let i=this[Et].keys(n),o=this[uu].get(this[Ar].utf8.length,n.keyEncoding);return new _m(this,n,i,o)}_values(n){this[Bo](n,n.keyEncoding);let i=this[Et].values(n);return new km(this,n,i)}}return{AbstractSublevel:e}};var Rm=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:du(r,"utf8"),buffer:du(r,"buffer"),view:du(r,"view")}}},du=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},Fs=class{constructor(e){this.utf8=e,this.view=Ih.encode(e),this.buffer=lu?lu.from(this.view.buffer,0,this.view.byteLength):{}}},hu=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}},Pm=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 gu=ae(mu=>{"use strict";var F1=h(f()),{supports:Lm}=Ml(),{Transcoder:Mm}=Gl(),{EventEmitter:Nm}=oh(),{fromCallback:Xr}=yo(),qt=Ft(),{AbstractIterator:Kn}=Wr(),{DefaultKeyIterator:$m,DefaultValueIterator:Vm}=lh(),{DeferredIterator:Fm,DeferredKeyIterator:Hm,DeferredValueIterator:qm}=hh(),{DefaultChainedBatch:Oh}=mh(),{getCallback:_n,getOptions:Zr}=Is(),Hs=xh(),ce=Symbol("promise"),Tr=Symbol("landed"),kn=Symbol("resources"),fu=Symbol("closeResources"),So=Symbol("operations"),Io=Symbol("undefer"),qs=Symbol("deferOpen"),Kh=Symbol("options"),ue=Symbol("status"),Cn=Symbol("defaultOptions"),Ei=Symbol("transcoder"),js=Symbol("keyEncoding"),pu=Symbol("valueEncoding"),jm=()=>{},Do=class extends Nm{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[kn]=new Set,this[So]=[],this[qs]=!0,this[Kh]=s,this[ue]="opening",this.supports=Lm(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[Ei]=new Mm(zm(this)),this[js]=this[Ei].encoding(n||"utf8"),this[pu]=this[Ei].encoding(i||"utf8");for(let c of this[Ei].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Cn]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[js].commonName,valueEncoding:this[pu].commonName}),key:Object.freeze({keyEncoding:this[js].commonName})},this.nextTick(()=>{this[qs]&&this.open({passive:!1},jm)})}get status(){return this[ue]}keyEncoding(e){return this[Ei].encoding(e??this[js])}valueEncoding(e){return this[Ei].encoding(e??this[pu])}open(e,t){t=_n(e,t),t=Xr(t,ce),e={...this[Kh],...Zr(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[ue]==="closing"||this[ue]==="opening"?this.once(Tr,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(Tr,n):this.nextTick(n):this[ue]==="closed"||this[qs]?(this[qs]=!1,this[ue]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[ue]="closed",this[fu](()=>{this.emit(Tr),n(i)}),this[Io]();return}this[ue]="open",this[Io](),this.emit(Tr),this[ue]==="open"&&this.emit("open"),this[ue]==="open"&&this.emit("ready"),n()})):this[ue]==="open"?this.nextTick(n):this.once(Tr,()=>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(Tr,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(Tr),t(i)};this[fu](()=>{this._close(i=>{if(i)return n(i);this[ue]="closed",this[Io](),this.emit(Tr),this[ue]==="closed"&&this.emit("closed"),t()})})}else this[ue]==="closed"?this.nextTick(t):this.once(Tr,()=>this.close(e));return e[ce]}[fu](e){if(this[kn].size===0)return this.nextTick(e);let t=this[kn].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[kn])o.close(i);n=!1,this[kn].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=_n(t,n),n=Xr(n,ce),t=Zr(t,this[Cn].entry),this[ue]==="opening")return this.defer(()=>this.get(e,t,n)),n[ce];if(Ai(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=_n(t,n),n=Xr(n,ce),t=Zr(t,this[Cn].entry),this[ue]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[ce];if(Ai(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=_n(n,i),i=Xr(i,ce),n=Zr(n,this[Cn].entry),this[ue]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[ce];if(Ai(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=_n(t,n),n=Xr(n,ce),t=Zr(t,this[Cn].key),this[ue]==="opening")return this.defer(()=>this.del(e,t,n)),n[ce];if(Ai(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 Oh(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=_n(t,n),n=Xr(n,ce),t=Zr(t,this[Cn].empty),this[ue]==="opening")return this.defer(()=>this.batch(e,t,n)),n[ce];if(Ai(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,yu.defaults(t))}_sublevel(e,t){return new yu(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=_n(e,t),t=Xr(t,ce),e=Zr(e,this[Cn].empty),this[ue]==="opening")return this.defer(()=>this.clear(e,t)),t[ce];if(Ai(this,t))return t[ce];let n=e,i=this.keyEncoding(e.keyEncoding);return e=Hs(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=Hs(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 Fm(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=Hs(e,t),e[Kn.keyEncoding]=t,e[Kn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ue]==="opening")return new Hm(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 $m(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Hs(e,t),e[Kn.keyEncoding]=t,e[Kn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ue]==="opening")return new qm(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 Vm(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[kn].add(e)}detachResource(e){this[kn].delete(e)}_chainedBatch(){return new Oh(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=Th();var{AbstractSublevel:yu}=Uh()({AbstractLevel:Do});mu.AbstractLevel=Do;mu.AbstractSublevel=yu;var Ai=function(r,e){return r[ue]!=="open"?(r.nextTick(e,new qt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},zm=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var wu=ae(Rn=>{"use strict";var q1=h(f());Rn.AbstractLevel=gu().AbstractLevel;Rn.AbstractSublevel=gu().AbstractSublevel;Rn.AbstractIterator=Wr().AbstractIterator;Rn.AbstractKeyIterator=Wr().AbstractKeyIterator;Rn.AbstractValueIterator=Wr().AbstractValueIterator;Rn.AbstractChainedBatch=ou().AbstractChainedBatch});var kh=ae((j1,_h)=>{var z1=h(f());_h.exports=Gm;var Jm=cu();function Gm(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?Jm(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 xu=ae((J1,Ch)=>{"use strict";var G1=h(f());Ch.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 bu=ae((W1,Rh)=>{"use strict";var Y1=h(f()),Wm=new TextEncoder;Rh.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):Wm.encode(r)}});var $h=ae(Nh=>{"use strict";var Z1=h(f()),{AbstractIterator:Ym}=wu(),Ph=xu(),zs=bu(),or=Symbol("cache"),Br=Symbol("finished"),At=Symbol("options"),Sr=Symbol("currentOptions"),Pn=Symbol("position"),vu=Symbol("location"),Ti=Symbol("first"),Lh={},Eu=class extends Ym{constructor(e,t,n){super(e,n),this[or]=[],this[Br]=this.limit===0,this[At]=n,this[Sr]={...n},this[Pn]=void 0,this[vu]=t,this[Ti]=!0}_nextv(e,t,n){if(this[Ti]=!1,this[Br])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[Pn]!==void 0&&(this[At].reverse?(this[Sr].lt=this[Pn],this[Sr].lte=void 0):(this[Sr].gt=this[Pn],this[Sr].gte=void 0));let i;try{i=Ph(this[Sr])}catch{return this[Br]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[vu]],"readonly"),s=o.objectStore(this[vu]),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[Pn]=l,c.push([this[At].keys&&l!==void 0?zs(l):void 0,this[At].values&&g!==void 0?zs(g):void 0]),c.length<e?a.continue():Mh(o)}else this[Br]=!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[Br]=!0:this[Pn]=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?zs(b):void 0,this[At].values&&m!==void 0?zs(m):void 0]}Mh(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[Br])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[Ti]&&(this[Ti]=!1,t=1),this._nextv(t,Lh,(n,i)=>{if(n)return e(n);this[or]=i,this._next(e)})}}_all(e,t){this[Ti]=!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,Lh,(o,s)=>{if(o)return t(o);n.length>0&&(s=n.concat(s)),t(null,s)})}_seek(e,t){this[Ti]=!0,this[or]=[],this[Br]=!1,this[Pn]=void 0,this[Sr]={...this[At]};let n;try{n=Ph(this[At])}catch{this[Br]=!0;return}n!==null&&!n.includes(e)?this[Br]=!0:this[At].reverse?this[Sr].lte=e:this[Sr].gte=e}};Nh.Iterator=Eu;function Mh(r){typeof r.commit=="function"&&r.commit()}});var Fh=ae((Q1,Vh)=>{"use strict";var eE=h(f());Vh.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 Gh=ae(Jh=>{"use strict";var rE=h(f()),{AbstractLevel:Xm}=wu(),Hh=Ft(),Zm=kh(),{fromCallback:Qm}=yo(),{Iterator:eg}=$h(),qh=bu(),tg=Fh(),rg=xu(),zh="level-js-",Uo=Symbol("idb"),Au=Symbol("namePrefix"),Ir=Symbol("location"),Tu=Symbol("version"),Ln=Symbol("store"),Oo=Symbol("onComplete"),jh=Symbol("promise"),Js=class extends Xm{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new Hh("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[Ir]=e,this[Au]=i??zh,this[Tu]=parseInt(o||1,10),this[Uo]=null}get location(){return this[Ir]}get namePrefix(){return this[Au]}get version(){return this[Tu]}get db(){return this[Uo]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Au]+this[Ir],this[Tu]);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[Ir])||o.createObjectStore(this[Ir])}}[Ln](e){return this[Uo].transaction([this[Ir]],e).objectStore(this[Ir])}[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[Ln]("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 Hh("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,qh(c))})}_getMany(e,t,n){let i=this[Ln]("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:qh(d))},u.onerror=d=>{d.stopPropagation(),c(u.error)}});Zm(o,16,n)}_del(e,t,n){let i=this[Ln]("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[Ln]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[Oo](s,i)}_iterator(e){return new eg(this,this[Ir],e)}_batch(e,t,n){let i=this[Ln]("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=rg(e)}catch{return this.nextTick(t)}if(e.limit>=0)return tg(this,this[Ir],n,e,t);try{let o=this[Ln]("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)}};Js.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=zh),t=Qm(t,jh);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[jh]};Jh.BrowserLevel=Js});var Bu=ae(Wh=>{var iE=h(f());Wh.Level=Gh().BrowserLevel});var gp=ae(($c,mp)=>{var US=h(f());(function(r,e){typeof $c=="object"&&typeof mp<"u"?e($c):typeof define=="function"&&define.amd?define(["exports"],e):e(r.URI=r.URI||{})})($c,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="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",Oe=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,"[\\:]"))+"*"),mn=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),Ot=t(xt+"\\."+xt+"\\."+xt+"\\."+xt),ve=t(L+"{1,4}"),bt=t(t(ve+"\\:"+ve)+"|"+Ot),Kt=t(t(ve+"\\:")+"{6}"+bt),Qt=t("\\:\\:"+t(ve+"\\:")+"{5}"+bt),gn=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),fs=t(t(t(ve+"\\:")+"{0,3}"+ve)+"?\\:\\:"+ve+"\\:"+bt),ps=t(t(t(ve+"\\:")+"{0,4}"+ve)+"?\\:\\:"+bt),Zn=t(t(t(ve+"\\:")+"{0,5}"+ve)+"?\\:\\:"+ve),Qn=t(t(t(ve+"\\:")+"{0,6}"+ve)+"?\\:\\:"),gr=t([Kt,Qt,gn,mr,Qi,fs,ps,Zn,Qn].join("|")),ei=t(t(pe+"|"+ge)+"+"),ia=t(gr+"\\%25"+ei),wn=t(gr+t("\\%25|\\%(?!"+L+"{2})")+ei),Sy=t("[vV]"+L+"+\\."+e(pe,he,"[\\:]")+"+"),Iy=t("\\["+t(wn+"|"+gr+"|"+Sy)+"\\]"),Wd=t(t(ge+"|"+e(pe,he))+"*"),eo=t(Iy+"|"+Ot+"(?!"+Wd+")|"+Wd),to=t(v+"*"),Yd=t(t(we+"@")+"?"+eo+t("\\:"+to)+"?"),ro=t(ge+"|"+e(pe,he,"[\\:\\@]")),Dy=t(ro+"*"),Xd=t(ro+"+"),Uy=t(t(ge+"|"+e(pe,he,"[\\@]"))+"+"),wr=t(t("\\/"+Dy)+"*"),ti=t("\\/"+t(Xd+wr)+"?"),oa=t(Uy+wr),ys=t(Xd+wr),ri="(?!"+ro+")",nb=t(wr+"|"+ti+"|"+oa+"|"+ys+"|"+ri),ni=t(t(ro+"|"+e("[\\/\\?]",De))+"*"),no=t(t(ro+"|[\\/\\?]")+"*"),Zd=t(t("\\/\\/"+Yd+wr)+"|"+ti+"|"+ys+"|"+ri),Oy=t(Ke+"\\:"+Zd+t("\\?"+ni)+"?"+t("\\#"+no)+"?"),Ky=t(t("\\/\\/"+Yd+wr)+"|"+ti+"|"+oa+"|"+ri),_y=t(Ky+t("\\?"+ni)+"?"+t("\\#"+no)+"?"),ib=t(Oy+"|"+_y),ob=t(Ke+"\\:"+Zd+t("\\?"+ni)+"?"),sb="^("+Ke+")\\:"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ti+"|"+ys+"|"+ri+")")+t("\\?("+ni+")")+"?"+t("\\#("+no+")")+"?$",cb="^(){0}"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ti+"|"+oa+"|"+ri+")")+t("\\?("+ni+")")+"?"+t("\\#("+no+")")+"?$",ab="^("+Ke+")\\:"+t(t("\\/\\/("+t("("+we+")@")+"?("+eo+")"+t("\\:("+to+")")+"?)")+"?("+wr+"|"+ti+"|"+ys+"|"+ri+")")+t("\\?("+ni+")")+"?$",ub="^"+t("\\#("+no+")")+"?$",db="^"+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,Oe),"g"),PCT_ENCODED:new RegExp(ge,"g"),IPV4ADDRESS:new RegExp("^("+Ot+")$"),IPV6ADDRESS:new RegExp("^\\[?("+gr+")"+t(t("\\%25|\\%(?!"+L+"{2})")+"("+ei+")")+"?\\]?$")}}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,Oe=1,Me=b;;Me+=b){Le>=v&&le("invalid-input");var De=Q(p.charCodeAt(Le++));(De>=b||De>j((g-A)/Oe))&&le("overflow"),A+=De*Oe;var pe=Me<=ie?m:Me>=ie+x?x:Me-ie;if(De<pe)break;var Ke=b-pe;Oe>j(g/Ke)&&le("overflow"),Oe*=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](),Oe;!(fe=(Oe=he.next()).done);fe=!0){var Me=Oe.value;Me<128&&w.push(J(Me))}}catch(wn){ge=!0,Le=wn}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,mn=!1,xt=void 0;try{for(var Ot=p[Symbol.iterator](),ve;!(we=(ve=Ot.next()).done);we=!0){var bt=ve.value;bt>=A&&bt<Ke&&(Ke=bt)}}catch(wn){mn=!0,xt=wn}finally{try{!we&&Ot.return&&Ot.return()}finally{if(mn)throw xt}}var Kt=pe+1;Ke-A>j((g-L)/Kt)&&le("overflow"),L+=(Ke-A)*Kt,A=Ke;var Qt=!0,gn=!1,mr=void 0;try{for(var Qi=p[Symbol.iterator](),fs;!(Qt=(fs=Qi.next()).done);Qt=!0){var ps=fs.value;if(ps<A&&++L>g&&le("overflow"),ps==A){for(var Zn=L,Qn=b;;Qn+=b){var gr=Qn<=ie?m:Qn>=ie+x?x:Qn-ie;if(Zn<gr)break;var ei=Zn-gr,ia=b-gr;w.push(J(K(gr+ei%ia,0))),Zn=j(ei/ia)}w.push(J(K(Zn,0))),ie=I(L,Kt,pe==De),L=0,++pe}}}catch(wn){gn=!0,mr=wn}finally{try{!Qt&&Qi.return&&Qi.return()}finally{if(gn)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):[],Oe=ge.split(":").map(Ae),Me=p.IPV4ADDRESS.test(Oe[Oe.length-1]),De=Me?7:8,pe=Oe.length-De,Ke=Array(De),we=0;we<De;++we)Ke[we]=he[we]||Oe[pe+we]||"";Me&&(Ke[De-1]=Ce(Ke[De-1],p));var mn=Ke.reduce(function(Kt,Qt,gn){if(!Qt||Qt==="0"){var mr=Kt[Kt.length-1];mr&&mr.index+mr.length===gn?mr.length++:Kt.push({index:gn,length:1})}return Kt},[]),xt=mn.sort(function(Kt,Qt){return Qt.length-Kt.length})[0],Ot=void 0;if(xt&&xt.length>1){var ve=Ke.slice(0,xt.index),bt=Ke.slice(xt.index+xt.length);Ot=ve.join(":")+"::"+bt.join(":")}else Ot=Ke.join(":");return L&&(Ot+="%"+L),Ot}else return y}var Re=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,qe="".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){qe?(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 Nr=/^\.\.?\//,Wi=/^\/\.(\/|$)/,cs=/^\/\.\.(\/|$)/,ta=/^\/?(?:.|\n)*?(?=\/|$)/;function $r(y){for(var p=[];y.length;)if(y.match(Nr))y=y.replace(Nr,"");else if(y.match(Wi))y=y.replace(Wi,"/");else if(y.match(cs))y=y.replace(cs,"/"),p.pop();else if(y==="."||y==="..")y="";else{var w=y.match(ta);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 Dt(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=$r(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(Dt(y,w),w),p=Ne(Dt(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=$r(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=$r(p.path||""),A.query=p.query):(p.path?(p.path.charAt(0)==="/"?A.path=$r(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=$r(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 as(y,p,w){var v=s({scheme:"null"},w);return Dt(Yi(Ne(y,v),Ne(p,v),v,!0),v)}function Xi(y,p){return typeof y=="string"?y=Dt(Ne(y,p),p):n(y)==="object"&&(y=Ne(Dt(y,p),p)),y}function us(y,p,w){return typeof y=="string"?y=Dt(Ne(y,w),w):n(y)==="object"&&(y=Dt(y,w)),typeof p=="string"?p=Dt(Ne(p,w),w):n(p)==="object"&&(p=Dt(p,w)),y===p}function ds(y,p){return y&&y.toString().replace(!p||!p.iri?u.ESCAPE:d.ESCAPE,Y)}function Ut(y,p){return y&&y.toString().replace(!p||!p.iri?u.PCT_ENCODED:d.PCT_ENCODED,ne)}var Vr={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:Vr.domainHost,parse:Vr.parse,serialize:Vr.serialize};function ls(y){return typeof y.secure=="boolean"?y.secure:String(y.scheme).toLowerCase()==="wss"}var yn={scheme:"ws",domainHost:!0,parse:function(p,w){var v=p;return v.secure=ls(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===(ls(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}},hs={scheme:"wss",domainHost:yn.domainHost,parse:yn.parse,serialize:yn.serialize},ra={},yy=!0,qd="[A-Za-z0-9\\-\\.\\_\\~"+(yy?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",Zt="[0-9A-Fa-f]",my=t(t("%[EFef]"+Zt+"%"+Zt+Zt+"%"+Zt+Zt)+"|"+t("%[89A-Fa-f]"+Zt+"%"+Zt+Zt)+"|"+t("%"+Zt+Zt)),gy="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",wy="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",xy=e(wy,'[\\"\\\\]'),by="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",vy=new RegExp(qd,"g"),Xn=new RegExp(my,"g"),Ey=new RegExp(e("[^]",gy,"[\\.]",'[\\"]',xy),"g"),jd=new RegExp(e("[^]",qd,by),"g"),Ay=jd;function na(y){var p=ne(y);return p.match(vy)?p:y}var zd={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 Oe=he[1].split(","),Me=0,De=Oe.length;Me<De;++Me)A.push(Oe[Me]);break;case"subject":v.subject=Ut(he[1],w);break;case"body":v.body=Ut(he[1],w);break;default:L=!0,ie[Ut(he[0],w)]=Ut(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]=Ut(we[0]),w.unicodeSupport)we[1]=Ut(we[1],w).toLowerCase();else try{we[1]=X.toASCII(Ut(we[1],w).toLowerCase())}catch(mn){v.error=v.error||"Email address's domain name can not be converted to ASCII via punycode: "+mn}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(Xn,na).replace(Xn,i).replace(Ey,Y),he=fe.slice(ge+1);try{he=w.iri?X.toUnicode(he):X.toASCII(Ut(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 Oe=p.headers=p.headers||{};p.subject&&(Oe.subject=p.subject),p.body&&(Oe.body=p.body);var Me=[];for(var De in Oe)Oe[De]!==ra[De]&&Me.push(De.replace(Xn,na).replace(Xn,i).replace(jd,Y)+"="+Oe[De].replace(Xn,na).replace(Xn,i).replace(Ay,Y));return Me.length&&(v.query=Me.join("&")),v}},Ty=/^([^\:]+)\:(.*)/,Jd={scheme:"urn",parse:function(p,w){var v=p.path&&p.path.match(Ty),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}},By=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,Gd={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(By))&&(v.error=v.error||"UUID is not valid."),v},serialize:function(p,w){var v=p;return v.nss=(p.uuid||"").toLowerCase(),v}};Z[Vr.scheme]=Vr,Z[Zi.scheme]=Zi,Z[yn.scheme]=yn,Z[hs.scheme]=hs,Z[zd.scheme]=zd,Z[Jd.scheme]=Jd,Z[Gd.scheme]=Gd,r.SCHEMES=Z,r.pctEncChar=Y,r.pctDecChars=ne,r.parse=Ne,r.removeDotSegments=$r,r.serialize=Dt,r.resolveComponents=Yi,r.resolve=as,r.normalize=Xi,r.equal=us,r.escapeComponent=ds,r.unescapeComponent=Ut,Object.defineProperty(r,"__esModule",{value:!0})})});var xp=ae(($S,wp)=>{"use strict";var VS=h(f());wp.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 uy=ae((YI,ay)=>{var XI=h(f()),zi=1e3,Ji=zi*60,Gi=Ji*60,Yn=Gi*24,Zx=Yn*7,Qx=Yn*365.25;ay.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return eb(r);if(t==="number"&&isFinite(r))return e.long?rb(r):tb(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function eb(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*Qx;case"weeks":case"week":case"w":return t*Zx;case"days":case"day":case"d":return t*Yn;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 tb(r){var e=Math.abs(r);return e>=Yn?Math.round(r/Yn)+"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 rb(r){var e=Math.abs(r);return e>=Yn?ea(r,e,Yn,"day"):e>=Gi?ea(r,e,Gi,"hour"):e>=Ji?ea(r,e,Ji,"minute"):e>=zi?ea(r,e,zi,"second"):r+" ms"}function ea(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var u5=h(f(),1);var Eb=h(f(),1),ui=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(ui||{});var Tb=h(f(),1),_e={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};var Sb=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 ke=$e;var Db=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)}},Hr=(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))(Hr||{});var Z6=h(f(),1);var y6=h(f(),1);var Ob=h(f(),1);var wa;(function(r){r.AlgorithmNotSupported="algorithmNotSupported",r.EncodingError="encodingError",r.InvalidJwe="invalidJwe",r.InvalidJwk="invalidJwk",r.OperationNotSupported="operationNotSupported"})(wa||(wa={}));var yT=h(f(),1);var lE=h(f(),1);var Cb=h(f(),1),b0=h(vl(),1);var mv=h(f(),1);var Zb=h(f(),1);var Fb=h(f(),1);var Pb=h(f(),1),Rb=new Uint8Array(0);function El(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 di(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 Mb=h(f(),1);function E0(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 A0=E0,T0=A0,Al=T0;var va=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")}},Ea=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 Tl(this,e)}},Aa=class{decoders;constructor(e){this.decoders=e}or(e){return Tl(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 Tl(r,e){return new Aa({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ta=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 va(e,t,n),this.decoder=new Ea(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Bl({name:r,prefix:e,encode:t,decode:n}){return new Ta(r,e,t,n)}function Ba({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Al(t,r);return Bl({prefix:e,name:r,encode:n,decode:o=>di(i(o))})}function B0(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 S0(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 Bl({prefix:e,name:r,encode(i){return S0(i,n,t)},decode(i){return B0(i,n,t,r)}})}var oo=st({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qb=st({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jb=st({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zb=st({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Jb=st({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Gb=st({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wb=st({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yb=st({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Sa=st({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var rv=h(f(),1);var dt=Ba({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ev=Ba({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var av=h(f(),1);var iv=st({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ov=st({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rr=st({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sv=st({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var dv=h(f(),1);function Sl(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function Il(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function li(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())})},Dl=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)}},bs=new TextEncoder,vn=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(!Il(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 dt.baseDecode(this.data).buffer;case"Base64Url":return rr.baseDecode(this.data).buffer;case"BufferSource":{if(li(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Sl(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 Sa.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 dt.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return dt.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=bs.encode(e);return rr.baseEncode(t)}case"String":{let e=bs.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=Dl(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=vn.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=vn.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 vn.decode(this.data);case"Base64Url":{let e=rr.baseDecode(this.data);return vn.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return vn.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=Dl(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+=vn.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+=vn.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 Sa.baseDecode(this.data);case"Base58Btc":return dt.baseDecode(this.data);case"Base64Url":return rr.baseDecode(this.data);case"BufferSource":{let e=li(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 bs.encode(e)}case"String":return bs.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 wv=h(f(),1),co;(function(r){r.Debug="debug",r.Silent="silent"})(co||(co={}));var Ia=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)}},I0=new Ia;typeof window<"u"&&(window.web5logger=I0);var Wv=h(f(),1);var jv=h(f(),1);var Ov=h(f(),1);var Tv=h(f(),1);var br={};ca(br,{decode:()=>hi,encodeTo:()=>En,encodingLength:()=>An});var Ev=h(f(),1);var bv=h(f(),1),D0=Kl,Ul=128,U0=127,O0=~U0,K0=Math.pow(2,31);function Kl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=K0;)e[t++]=r&255|Ul,r/=128;for(;r&O0;)e[t++]=r&255|Ul,r>>>=7;return e[t]=r|0,Kl.bytes=t-n+1,e}var _0=Da,k0=128,Ol=127;function Da(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Da.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Ol)<<i:(s&Ol)*Math.pow(2,i),i+=7}while(s>=k0);return Da.bytes=o-n,t}var C0=Math.pow(2,7),R0=Math.pow(2,14),P0=Math.pow(2,21),L0=Math.pow(2,28),M0=Math.pow(2,35),N0=Math.pow(2,42),$0=Math.pow(2,49),V0=Math.pow(2,56),F0=Math.pow(2,63),H0=function(r){return r<C0?1:r<R0?2:r<P0?3:r<L0?4:r<M0?5:r<N0?6:r<$0?7:r<V0?8:r<F0?9:10},q0={encode:D0,decode:_0,encodingLength:H0},j0=q0,ao=j0;function hi(r,e=0){return[ao.decode(r,e),ao.decode.bytes]}function En(r,e,t=0){return ao.encode(r,e,t),e}function An(r){return ao.encodingLength(r)}function Ua(r,e){let t=e.byteLength,n=An(r),i=n+An(t),o=new Uint8Array(i+t);return En(r,o,0),En(t,o,n),o.set(e,i),new fi(r,t,e,o)}function _l(r){let e=di(r),[t,n]=hi(e),[i,o]=hi(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new fi(t,i,s,e)}function kl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&El(r.bytes,t.bytes)}}var fi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Bv=h(f(),1);function Cl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return J0(t,Ka(r),e??dt.encoder);default:return G0(t,Ka(r),e??oo.encoder)}}var Rl=new WeakMap;function Ka(r){let e=Rl.get(r);if(e==null){let t=new Map;return Rl.set(r,t),t}return e}var _a=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!==W0)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=Ua(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&&kl(e.multihash,n.multihash)}toString(e){return Cl(this,e)}toJSON(){return{"/":Cl(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??Pl(n,i,o.bytes))}else if(t[Y0]===!0){let{version:n,multihash:i,code:o}=t,s=_l(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=Pl(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=di(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 fi(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]=hi(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]=z0(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 Ka(o).set(n,e),o}};function z0(r,e){switch(r[0]){case"Q":{let t=e??dt;return[dt.prefix,t.decode(`${dt.prefix}${r}`)]}case dt.prefix:{let t=e??dt;return[dt.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 J0(r,e,t){let{prefix:n}=t;if(n!==dt.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 G0(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,W0=18;function Pl(r,e,t){let n=An(r),i=n+An(e),o=new Uint8Array(i+t.byteLength);return En(r,o,0),En(e,o,n),o.set(t,i),o}var Y0=Symbol.for("@ipld/js-cid/CID");var _v=h(f(),1);var Lv=h(f(),1);var kv=h(f(),1);var Cv=h(f(),1);var Rv=h(f(),1);var Pv=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=br.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),br.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=br.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]=br.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 Xv=h(f(),1);function ka(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&ka(r[e])})}var sE=h(f(),1),ng=h(Bu(),1),Mn=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 Gs=class{constructor(){this.store=new Map}clear(){return Mn(this,void 0,void 0,function*(){this.store.clear()})}close(){return Mn(this,void 0,void 0,function*(){})}delete(e){return Mn(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return Mn(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return Mn(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return Mn(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return Mn(this,void 0,void 0,function*(){this.store.set(e,t)})}};var uE=h(f(),1);var hA=h(f(),1);var vE=h(f(),1),sr=class{};var G2=h(f(),1);var Ys={};ca(Ys,{bitGet:()=>dg,bitLen:()=>ug,bitMask:()=>Ko,bitSet:()=>lg,bytesToHex:()=>Ur,bytesToNumberBE:()=>Or,bytesToNumberLE:()=>zt,concatBytes:()=>_r,createHmacDrbg:()=>Du,ensureBytes:()=>Te,equalBytes:()=>cg,hexToBytes:()=>Nn,hexToNumber:()=>Iu,isBytes:()=>jt,numberToBytesBE:()=>ht,numberToBytesLE:()=>Kr,numberToHexUnpadded:()=>Qh,numberToVarBytesBE:()=>sg,utf8ToBytes:()=>ag,validateObject:()=>Rt});var EE=h(f(),1);var Zh=BigInt(0),Ws=BigInt(1),ig=BigInt(2);function jt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var og=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Ur(r){if(!jt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=og[r[t]];return e}function Qh(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Iu(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Dr={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Yh(r){if(r>=Dr._0&&r<=Dr._9)return r-Dr._0;if(r>=Dr._A&&r<=Dr._F)return r-(Dr._A-10);if(r>=Dr._a&&r<=Dr._f)return r-(Dr._a-10)}function Nn(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=Yh(r.charCodeAt(o)),c=Yh(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 Or(r){return Iu(Ur(r))}function zt(r){if(!jt(r))throw new Error("Uint8Array expected");return Iu(Ur(Uint8Array.from(r).reverse()))}function ht(r,e){return Nn(r.toString(16).padStart(e*2,"0"))}function Kr(r,e){return ht(r,e).reverse()}function sg(r){return Nn(Qh(r))}function Te(r,e,t){let n;if(typeof e=="string")try{n=Nn(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 _r(...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 cg(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 ag(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ug(r){let e;for(e=0;r>Zh;r>>=Ws,e+=1);return e}function dg(r,e){return r>>BigInt(e)&Ws}var lg=(r,e,t)=>r|(t?Ws:Zh)<<BigInt(e),Ko=r=>(ig<<BigInt(r-1))-Ws,Su=r=>new Uint8Array(r),Xh=r=>Uint8Array.from(r);function Du(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=Su(r),i=Su(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),u=(l=Su())=>{i=c(Xh([0]),l),n=c(),l.length!==0&&(i=c(Xh([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 _r(...g)};return(l,g)=>{s(),u(l);let b;for(;!(b=g(d()));)u();return s(),b}}var hg={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 Rt(r,e,t={}){let n=(i,o,s)=>{let c=hg[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 f2=h(f(),1);var ME=h(f(),1);var CE=h(f(),1);var TE=h(f(),1);function ef(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function fg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Uu(r,...e){if(!fg(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 tf(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ef(r.outputLen),ef(r.blockLen)}function Bi(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 rf(r,e){Uu(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var OE=h(f(),1);var SE=h(f(),1),Xs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function nf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Zs=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Jt=(r,e)=>r<<32-e|r>>>e,pg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!pg)throw new Error("Non little-endian hardware is not supported");function Ou(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=Ou(r)),!nf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Qs(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!nf(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 Si=class{clone(){return this._cloneInto()}},DE={}.toString;function ec(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(Xs&&typeof Xs.getRandomValues=="function")return Xs.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function yg(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 Ii=class extends Si{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=Zs(this.buffer)}update(e){Bi(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=Zs(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){Bi(this),rf(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;yg(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Zs(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 mg=(r,e,t)=>r&e^~r&t,gg=(r,e,t)=>r&e^r&t^e&t,wg=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),Ku=class extends Ii{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+mg(c,u,d)+wg[l]+en[l]|0,x=(Jt(n,2)^Jt(n,13)^Jt(n,22))+gg(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 tc=ec(()=>new Ku);var $E=h(f(),1);var Ve=BigInt(0),Ue=BigInt(1),$n=BigInt(2),xg=BigInt(3),_u=BigInt(4),of=BigInt(5),sf=BigInt(8),bg=BigInt(9),vg=BigInt(16);function ye(r,e){let t=r%e;return t>=Ve?t:e+t}function ku(r,e,t){if(t<=Ve||e<Ve)throw new Error("Expected power/modulo > 0");if(t===Ue)return Ve;let n=Ue;for(;e>Ve;)e&Ue&&(n=n*r%t),r=r*r%t,e>>=Ue;return n}function Be(r,e,t){let n=r;for(;e-- >Ve;)n*=n,n%=t;return n}function rc(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=Ue,s=Ue,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!==Ue)throw new Error("invert: does not exist");return ye(i,e)}function Eg(r){let e=(r-Ue)/$n,t,n,i;for(t=r-Ue,n=0;t%$n===Ve;t/=$n,n++);for(i=$n;i<r&&ku(i,e,r)!==r-Ue;i++);if(n===1){let s=(r+Ue)/_u;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+Ue)/$n;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,Ue<<BigInt(d-b-1));a=c.sqr(m),l=c.mul(l,m),g=c.mul(g,a),d=b}return l}}function Ag(r){if(r%_u===xg){let e=(r+Ue)/_u;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%sf===of){let e=(r-of)/sf;return function(n,i){let o=n.mul(i,$n),s=n.pow(o,e),c=n.mul(i,s),u=n.mul(n.mul(c,$n),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%vg,Eg(r)}var cf=(r,e)=>(ye(r,e)&Ue)===Ue,Tg=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Cu(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Tg.reduce((n,i)=>(n[i]="function",n),e);return Rt(r,t)}function Bg(r,e,t){if(t<Ve)throw new Error("Expected power > 0");if(t===Ve)return r.ONE;if(t===Ue)return e;let n=r.ONE,i=e;for(;t>Ve;)t&Ue&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ue;return n}function Sg(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 Ru(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Di(r,e,t=!1,n={}){if(r<=Ve)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Ru(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Ag(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Ko(i),ZERO:Ve,ONE:Ue,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&Ue)===Ue,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)=>Bg(c,u,d),div:(u,d)=>ye(u*rc(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>rc(u,r),sqrt:n.sqrt||(u=>s(c,u)),invertBatch:u=>Sg(c,u),cmov:(u,d,a)=>a?d:u,toBytes:u=>t?Kr(u,o):ht(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return t?zt(u):Or(u)}});return Object.freeze(c)}function af(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 uf(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 Pu(r){let e=uf(r);return e+Math.ceil(e/2)}function df(r,e,t=!1){let n=r.length,i=uf(e),o=Pu(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Or(r):zt(r),c=ye(s,e-Ue)+Ue;return t?Kr(c,i):ht(c,i)}var XE=h(f(),1);var qE=h(f(),1);var Dg=BigInt(0),Lu=BigInt(1);function nc(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>Dg;)o&Lu&&(s=s.add(c)),c=c.double(),o>>=Lu;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+=Lu);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 Cu(r.Fp),Rt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ru(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Ug(r){let e=Co(r);Rt(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:Og,hexToBytes:Kg}=Ys,Vn={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Vn;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:Og(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Vn,t=typeof r=="string"?Kg(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}=Vn._parseInt(t.subarray(2)),{d:s,l:c}=Vn._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}`}},kr=BigInt(0),Pt=BigInt(1),GE=BigInt(2),lf=BigInt(3),WE=BigInt(4);function _g(r){let e=Ug(r),{Fp:t}=e,n=e.toBytes||((m,x,E)=>{let S=x.toAffine();return _r(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"&&kr<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=Ur(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:Or(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,lf),{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,lf),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===kr)return E;if(c(x),x===Pt)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>kr||D>kr;)T&Pt&&(k=k.add(R)),D&Pt&&(C=C.add(R)),R=R.double(),T>>=Pt,D>>=Pt;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===kr||k===Pt||!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===Pt)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===Pt?this:E?E(l,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return this.assertValidity(),n(l,this,x)}toHex(x=!0){return Ur(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=nc(l,e.endo?Math.ceil(g/2):g);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:o,isWithinCurveOrder:s}}function kg(r){let e=Co(r);return Rt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function hf(r){let e=kg(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(O){return kr<O&&O<t.ORDER}function c(O){return ye(O,n)}function u(O){return rc(O,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:g}=_g({...e,toBytes(O,N,Q){let K=N.toAffine(),I=t.toBytes(K.x),P=_r;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=Or(K);if(!s(I))throw new Error("Point is not on curve");let P=l(I),V=t.sqrt(P),W=(V&Pt)===Pt;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=>Ur(ht(O,e.nByteLength));function m(O){let N=n>>Pt;return O>N}function x(O){return m(O)?c(-O):O}let E=(O,N,Q)=>Or(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}=Vn.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 Nn(this.toDERHex())}toDERHex(){return Vn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Nn(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=Pu(e.n);return df(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=Or(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(!(kr<=O&&O<R))throw new Error(`bigint expected < 2^${e.nBitLength}`);return ht(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=_r(...Z),ne=re;function Ie(Ae){let Ce=k(Ae);if(!g(Ce))return;let Pe=u(Ce),Re=d.BASE.multiply(Ce).toAffine(),qe=c(Re.x);if(qe===kr)return;let Ne=c(Pe*c(ne+qe*X));if(Ne===kr)return;let yr=(Re.x===qe?0:2)|Number(Re.y&Pt),Nr=Ne;return P&&m(Ne)&&(Nr=x(Ne),yr^=1),new S(qe,Nr,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 Du(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 Vn.Err))throw Re;W=S.fromCompact(I)}else if(typeof I=="object"&&typeof I.r=="bigint"&&typeof I.s=="bigint"){let{r:Re,s:qe}=I;W=new S(Re,qe)}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 s2=h(f(),1);var t2=h(f(),1);var ic=class extends Si{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,tf(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 Bi(this),this.iHash.update(e),this}digestInto(e){Bi(this),Uu(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()}},Mu=(r,e,t)=>new ic(r,e).update(t).digest();Mu.create=(r,e)=>new ic(r,e);function Cg(r){return{hash:r,hmac:(e,...t)=>Mu(r,e,Qs(...t)),randomBytes:ko}}function oc(r,e){let t=n=>hf({...r,...Cg(n)});return Object.freeze({...t(e),create:t})}var yf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ff=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Rg=BigInt(1),Nu=BigInt(2),pf=(r,e)=>(r+e/Nu)/e;function Pg(r){let e=yf,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,Nu,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,Nu,e);if(!$u.eql($u.sqr(k),r))throw new Error("Cannot find square root");return k}var $u=Di(yf,void 0,void 0,{sqrt:Pg}),ft=oc({a:BigInt(0),b:BigInt(7),Fp:$u,n:ff,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=ff,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Rg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=pf(o*r,e),u=pf(-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}}}},tc),d2=BigInt(0);var l2=ft.ProjectivePoint;var K2=h(f(),1);var I2=h(f(),1);var y2=h(f(),1);function Lg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Vu(r,...e){if(!Lg(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 Fu(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 mf(r,e){Vu(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var A2=h(f(),1);var g2=h(f(),1),Ui=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var cc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Gt=(r,e)=>r<<32-e|r>>>e;var b2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Mg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Hu(r){return typeof r=="string"&&(r=Mg(r)),Vu(r),r}var sc=class{clone(){return this._cloneInto()}},v2={}.toString;function gf(r){let e=n=>r().update(Hu(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function wf(r=32){if(Ui&&typeof Ui.getRandomValues=="function")return Ui.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ng(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 xf=(r,e,t)=>r&e^~r&t,bf=(r,e,t)=>r&e^r&t^e&t,ac=class extends sc{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=cc(this.buffer)}update(e){Fu(this);let{view:t,buffer:n,blockLen:i}=this;e=Hu(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=cc(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){Fu(this),mf(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;Ng(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=cc(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 $g=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),qu=class extends ac{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+xf(c,u,d)+$g[l]+rn[l]|0,x=(Gt(n,2)^Gt(n,13)^Gt(n,22))+bf(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=gf(()=>new qu);var V2=h(f(),1);var k2=h(f(),1);function vf(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 P2=h(f(),1);var Vg=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())})},Oi=class{static digest(e){return Vg(this,arguments,void 0,function*({data:t}){return nn(t)})}};var Fg=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())})},ju="urn:jwk:";function te(r){return Fg(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}`);ka(n);let i=vf(n),o=M.string(i).toUint8Array(),s=yield Oi.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 Ki(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 _i(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 Ef(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())})},Hg=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},ze=class r{static adjustSignatureToLowS(e){return Ze(this,arguments,void 0,function*({signature:t}){let n=ft.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 ft.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 ft.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return ft.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Ze(this,void 0,void 0,function*(){let e=ft.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=Hg(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(!(Ki(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 ft.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 ft.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ze(this,arguments,void 0,function*({privateKeyBytes:t}){return ft.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){try{ft.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 ft.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Ze(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=ft.getPublicKey(t));let n=ft.ProjectivePoint.fromHex(t),i=ht(n.x,32),o=ht(n.y,32);return{x:i,y:o}})}};var sA=h(f(),1);var Q2=h(f(),1);var Af=Di(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),qg=Af.create(BigInt("-3")),jg=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),zg=oc({a:qg,b:jg,Fp:Af,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},tc),Tt=zg;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())})},Jg=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=Jg(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(!(Ki(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=ht(n.x,32),o=ht(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 ze.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 ze.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 ze.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 ze.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(!Ki(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return yield ze.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 iT=h(f(),1);var QA=h(f(),1);var GA=h(f(),1);var xA=h(f(),1);var pA=h(f(),1),uc=BigInt(4294967295),zu=BigInt(32);function Tf(r,e=!1){return e?{h:Number(r&uc),l:Number(r>>zu&uc)}:{h:Number(r>>zu&uc)|0,l:Number(r&uc)|0}}function Gg(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}=Tf(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var Wg=(r,e)=>BigInt(r>>>0)<<zu|BigInt(e>>>0),Yg=(r,e,t)=>r>>>t,Xg=(r,e,t)=>r<<32-t|e>>>t,Zg=(r,e,t)=>r>>>t|e<<32-t,Qg=(r,e,t)=>r<<32-t|e>>>t,ew=(r,e,t)=>r<<64-t|e>>>t-32,tw=(r,e,t)=>r>>>t-32|e<<64-t,rw=(r,e)=>e,nw=(r,e)=>r,iw=(r,e,t)=>r<<t|e>>>32-t,ow=(r,e,t)=>e<<t|r>>>32-t,sw=(r,e,t)=>e<<t-32|r>>>64-t,cw=(r,e,t)=>r<<t-32|e>>>64-t;function aw(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var uw=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),dw=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,lw=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),hw=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,fw=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),pw=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var yw={fromBig:Tf,split:Gg,toBig:Wg,shrSH:Yg,shrSL:Xg,rotrSH:Zg,rotrSL:Qg,rotrBH:ew,rotrBL:tw,rotr32H:rw,rotr32L:nw,rotlSH:iw,rotlSL:ow,rotlBH:sw,rotlBL:cw,add:aw,add3L:uw,add3H:dw,add4L:lw,add4H:hw,add5H:pw,add5L:fw},oe=yw;var[mw,gw]=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),Ju=class extends Ii{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,gw[T],sn[T]),ee=oe.add5H(R,S,_,k,mw[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 Gu=ec(()=>new Ju);var TA=h(f(),1);var Wt=BigInt(0),Bt=BigInt(1),dc=BigInt(2),ww=BigInt(8),xw={zip215:!0};function bw(r){let e=Co(r);return Rt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function lc(r){let e=bw(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:u}=e,d=dc<<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),qe=a(re*X);if(Re!==qe)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(dc*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),qe=a(Ae*Pe),Ne=a(Ie*Pe),yr=a(Ce*Ae);return new D(Re,qe,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)),as=a((re+W)*(ne-Y)),Xi=a(as-Yi);if(Xi===Wt)return this.double();let us=a(X*dc*Ae),ds=a(Z*dc*Ie),Ut=ds+us,Vr=as+Yi,Zi=ds-us,ls=a(Ut*Xi),yn=a(Vr*Zi),hs=a(Ut*Zi),ra=a(Xi*Vr);return new D(ls,yn,ra,hs)}let Ce=a(W*Y),Pe=a(re*ne),Re=a(Z*V*Ae),qe=a(X*Ie),Ne=a((W+re)*(Y+ne)-Ce-Pe),yr=qe-Re,Nr=qe+Re,Wi=a(Pe-P*Ce),cs=a(Ne*yr),ta=a(Nr*Wi),$r=a(Ne*Wi),Dt=a(yr*Nr);return new D(cs,ta,Dt,$r)}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?ww: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,qe=(Z&128)!==0;if(!P&&Pe===Wt&&qe)throw new Error("Point.fromHex: x=0 and x_0=1");return qe!==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=Kr(P,t.BYTES);return V[V.length-1]|=I&Bt?128:0,V}toHex(){return Ur(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=nc(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=_r(...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=_r(Z,Kr(ne,t.BYTES));return Te("result",Ie,c*2)}let O=xw;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 DA=h(f(),1);var Lo=BigInt(0),Wu=BigInt(1);function vw(r){return Rt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Bf(r){let e=vw(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=>ku(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=Wu,ee=Lo,j=D,J=Wu,le=Lo,de;for(let O=BigInt(i-1);O>=Lo;O--){let N=k>>O&Wu;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 Kr(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"),Sf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),CA=BigInt(0),Ew=BigInt(1),Yu=BigInt(2),Aw=BigInt(5),If=BigInt(10),Tw=BigInt(20),Bw=BigInt(40),Df=BigInt(80);function Uf(r){let e=Mo,n=r*r%e*r%e,i=Be(n,Yu,e)*n%e,o=Be(i,Ew,e)*r%e,s=Be(o,Aw,e)*o%e,c=Be(s,If,e)*s%e,u=Be(c,Tw,e)*c%e,d=Be(u,Bw,e)*u%e,a=Be(d,Df,e)*d%e,l=Be(a,Df,e)*d%e,g=Be(l,If,e)*s%e;return{pow_p_5_8:Be(g,Yu,e)*r%e,b2:n}}function Of(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Sw(r,e){let t=Mo,n=ye(e*e*e,t),i=ye(n*n*e,t),o=Uf(r*i).pow_p_5_8,s=ye(r*n*o,t),c=ye(e*s*s,t),u=s,d=ye(s*Sf,t),a=c===r,l=c===ye(-r,t),g=c===ye(-r*Sf,t);return a&&(s=u),(l||g)&&(s=d),cf(s,t)&&(s=ye(-s,t)),{isValid:a||l,value:s}}var Lt=Di(Mo,void 0,!0),No={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Lt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Gu,randomBytes:ko,adjustScalarBytes:Of,uvRatio:Sw},cn=lc(No);function Kf(r,e,t){if(e.length>255)throw new Error("Context is too big");return Qs(Ou("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var RA=lc({...No,domain:Kf}),PA=lc({...No,domain:Kf,prehash:Gu}),Fn=Bf({P:Mo,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Mo,{pow_p_5_8:t,b2:n}=Uf(r);return ye(Be(t,BigInt(3),e)*n,e)},adjustScalarBytes:Of,randomBytes:ko});function _f(r){let{y:e}=cn.ExtendedPoint.fromHex(r),t=BigInt(1);return Lt.toBytes(Lt.create((t+e)*Lt.inv(t-e)))}function kf(r){let e=No.hash(r.subarray(0,32));return No.adjustScalarBytes(e).subarray(0,32)}var Iw=(Lt.ORDER+BigInt(3))/BigInt(8),LA=Lt.pow(Yu,Iw),MA=Lt.sqrt(Lt.neg(Lt.ONE)),NA=(Lt.ORDER-BigInt(5))/BigInt(8),$A=BigInt(486662);var VA=af(Lt,Lt.neg(BigInt(486664)));var FA=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),HA=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),qA=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),jA=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var zA=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Mt=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())})},Dw=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 bytesToPrivateKey(e){return Mt(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 Mt(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 Mt(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 Mt(this,arguments,void 0,function*({privateKey:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=kf(n),o=Fn.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 Mt(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=_f(n),s={kty:"OKP",crv:"X25519",x:M.uint8Array(o).toBase64Url()};return s.kid=yield te({jwk:s}),s})}static generateKey(){return Mt(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 Mt(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=Dw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return Mt(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 Mt(this,arguments,void 0,function*({publicKey:t}){if(!_i(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 Mt(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 Mt(this,arguments,void 0,function*({publicKeyBytes:t}){try{cn.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Mt(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())})},hc=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 Je.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 Je.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 Je.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 Je.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(!_i(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return yield Je.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}};var aT=h(f(),1);var Uw=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())})},fc=class extends sr{digest(e){return Uw(this,arguments,void 0,function*({algorithm:t,data:n}){switch(t){case"SHA-256":return yield Oi.digest({data:n})}})}};var Cr=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())})},Xu={Ed25519:{implementation:hc,names:["Ed25519"]},secp256k1:{implementation:Po,names:["ES256K","secp256k1"]},secp256r1:{implementation:Po,names:["ES256","secp256r1"]},"SHA-256":{implementation:fc,names:["SHA-256"]}},ot=class{constructor(e){var t;this._algorithmInstances=new Map,this._keyStore=(t=e?.keyStore)!==null&&t!==void 0?t:new Gs}digest(e){return Cr(this,arguments,void 0,function*({algorithm:t,data:n}){return yield this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:n})})}exportKey(e){return Cr(this,arguments,void 0,function*({keyUri:t}){return yield this.getPrivateKey({keyUri:t})})}generateKey(e){return Cr(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=`${ju}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return Cr(this,arguments,void 0,function*({key:t}){let n=yield te({jwk:t});return`${ju}${n}`})}getPublicKey(e){return Cr(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 Cr(this,arguments,void 0,function*({key:t}){var n;if(!Ef(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 Cr(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 Cr(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=Xu[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 Xu){let o=Xu[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 Cr(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 xT=h(f(),1);var pc=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 wf(e)}static randomUuid(){return Ui.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 DT=h(f(),1);var AT=h(f(),1);var LT=h(f(),1);var _T=h(f(),1);var MT=h(f(),1);var NT=h(f(),1);var $T=h(f(),1);var zT=h(f(),1);var WT=h(f(),1);var ZT=h(f(),1);var e6=h(f(),1);var o6=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())})},Ow=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},mc=class r{static bytesToPrivateKey(e){return an(this,arguments,void 0,function*({privateKeyBytes:t}){let n=Fn.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=Fn.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=Fn.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=Ow(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(!_i(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 Fn.getSharedSecret(i,o)})}};var u6=h(f(),1);var f6=h(f(),1);var Rf={};ca(Rf,{extractDidFragment:()=>pt,getServices:()=>Kw,getVerificationMethodByKey:()=>_w,getVerificationMethodTypes:()=>Zu,getVerificationMethods:()=>Vo,getVerificationRelationshipsById:()=>Qu,isDidService:()=>Cf,isDidVerificationMethod:()=>gc,isDwnDidService:()=>kw,keyBytesToMultibaseId:()=>ed,multibaseIdToKeyBytes:()=>td});var J6=h(f(),1);function pt(r){if(typeof r=="string"&&r.length!==0)return r.split("#").pop()}function Kw({didDocument:r,id:e,type:t}){return r?.service?.filter(n=>!(e&&n.id!==e||t&&n.type!==t))??[]}async function _w({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(gc)??[]),Object.keys(ui).forEach(t=>{e.push(...r[t]?.filter(gc)??[])}),e}function Zu({didDocument:r}){let t=Vo({didDocument:r}).map(n=>n.type);return[...new Set(t)]}function Qu({didDocument:r,methodId:e}){let t=[];return Object.keys(ui).forEach(n=>{if(Array.isArray(r[n])){let i=r[n],o=pt(e);i.some(c=>{let u=pt(c)===o,d=gc(c)&&pt(c.id)===o;return u||d})&&t.push(n)}}),t}function Cf(r){return!r||typeof r!="object"||r===null?!1:"id"in r&&"type"in r&&"serviceEndpoint"in r}function kw(r){if(!Cf(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 gc(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 ed({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 td({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 yt=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=>pt(c.id)===(pt(e?.methodId)??pt(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:pc.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 tS=h(f(),1);var UB=h(f(),1);var gB=h(f(),1);var dB=h(f(),1);var eB=h(f(),1);var rd="0123456789abcdef",Lf=[],Pf=[];for(let r=0;r<256;r++)Lf[r]=rd[r>>4&15]+rd[r&15],r<16&&(r<10?Pf[48+r]=r:Pf[87+r]=r);var nd=r=>{let e=r.length,t="",n=0;for(;n<e;)t+=Lf[r[n++]];return t};var Mf=(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 rB=h(f()),Nf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cw=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Fo=0;Fo<Nf.length;Fo++)Cw[Nf.charCodeAt(Fo)]=Fo;var Fo;var Rw=new TextDecoder,id=(r,e)=>e?new TextDecoder(e).decode(r):Rw.decode(r),Pw=new TextEncoder,Nt=r=>Pw.encode(r);var $f=typeof window<"u"?window:self,Vf=$f.crypto||$f.msCrypto||{},aB=Vf.subtle||Vf.webkitSubtle;var fB=h(f(),1);function ki(r){let e=r<0?1:0;return r=Math.abs(Number(r||1)),Math.floor(Math.log10(r))+1+e}function wc(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=Mf(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(wc(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 xc=new Uint8Array([101]),Ff=new Uint8Array([100]),Hf=new Uint8Array([108]);me.buffer=function(r,e){r.push(Nt(e.length+":"),e)};me.string=function(r,e){r.push(Nt(Nt(e).byteLength+":"+e))};me.number=function(r,e){if(Number.isInteger(e))return r.push(Nt("i"+BigInt(e)+"e"));let t=2147483648,n=e/t<<0,i=e%t<<0,o=n*t+i;r.push(Nt("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(Ff);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(xc)};me.dictMap=function(r,e){r.push(Ff);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(xc)};me.list=function(r,e){let t=0,n=e.length;for(r.push(Hf);t<n;t++)e[t]!=null&&me._encode(r,e[t]);r.push(xc)};me.listSet=function(r,e){r.push(Hf);for(let t of e)t!=null&&me._encode(r,t);r.push(xc)};var qf=me;var bB=h(f(),1);var Lw=105,Mw=58,Nw=100,$w=108,od=101;function jf(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)):Nt(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 Nw:return G.dictionary();case $w:return G.list();case Lw: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]!==od;){let e=G.buffer(),t=id(e);t.includes("\uFFFD")&&(t=nd(e)),r[t]=G.next()}return G.position++,r};G.list=function(){G.position++;let r=[];for(;G.data[G.position]!==od;)r.push(G.next());return G.position++,r};G.integer=function(){let r=G.find(od),e=jf(G.data,G.position+1,r);return G.position+=r+1-G.position,e};G.buffer=function(){let r=G.find(Mw),e=jf(G.data,G.position,r),t=++r+e;return G.position=t,G.encoding?id(G.data.slice(r,t)):G.data.slice(r,t)};var zf=G;var TB=h(f(),1);function Vw(r){let e=2;for(let t of r)e+=bc(t);return e}function Fw(r){let e=2;for(let[t,n]of r){let i=Nt(t).byteLength;e+=ki(i)+1+i,e+=bc(n)}return e}function Hw(r){let e=2,t=Object.keys(r);for(let n=0;n<t.length;n++){let i=Nt(t[n]).byteLength;e+=ki(i)+1+i,e+=bc(r[t[n]])}return e}function qw(r){let e=Nt(r).byteLength;return ki(e)+1+e}function jw(r){let e=r.byteLength-r.byteOffset;return ki(e)+1+e}function bc(r){if(r==null)return 0;let t=wc(r);switch(t){case"arraybufferview":return jw(r);case"string":return qw(r);case"array":case"set":return Vw(r);case"number":return 1+ki(Math.floor(r))+1;case"bigint":return 1+r.toString().length+1;case"object":return Hw(r);case"map":return Fw(r);default:throw new TypeError(`Unsupported value of type "${t}"`)}}var sd=bc;var zw=sd,cd={encode:qf,decode:zf,byteLength:sd,encodingLength:zw};var $B=h(f(),1);var OB=h(f(),1),Jw=/^(\d{1,3}\.){3,3}\d{1,3}$/;var Gw=/^(::)?(((\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=>Jw.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]}`}},Rr={name:"v6",size:16,isFormat:r=>r.length>0&&Gw.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 Jf(r){if(Yt.isFormat(r))return Yt.size;if(Rr.isFormat(r))return Rr.size;throw Error(`Invalid ip address: ${r}`)}function Gf(r){return Jf(r)===Yt.size?1:2}function Wf(r,e,t){t=~~t;let n=Jf(r);return typeof e=="function"&&(e=e(t+n)),n===Yt.size?Yt.encode(r,e,t):Rr.encode(r,e,t)}function Yf(r,e,t){if(e=~~e,t=t||r.length-e,t===Yt.size)return Yt.decode(r,e,t);if(t===Rr.size)return Rr.decode(r,e,t);throw Error(`Invalid buffer size needs to be ${Yt.size} for v4 or ${Rr.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 Ci(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 _B=h(f(),1);function Xf(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 kB=h(f(),1);function Zf(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 CB=h(f(),1);function ad(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 ud(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 RB=h(f(),1);function Qf(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 dd(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 LB=h(f(),1);var PB=h(f(),1);function ld(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 Ri(r,e,t){let n=r.length;t==null&&(t=0),e===void 0&&(e=new Uint8Array(ld(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 Ri.bytes=i-t,e}Ri.bytes=0;function Pi(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 Pi.bytes=t-e,n}Pi.bytes=0;var un=r=>r instanceof Uint8Array;function Pr(r){return typeof r=="string"?ld(r):r.byteLength}function vc(r){return r instanceof Uint8Array?r:Array.isArray(r)?new Uint8Array(r):Ri(r)}function Ec(r,e,t){if(typeof e!="string")throw new Error("unknown input type");return Ri(e,r,t),Ri.bytes}var qo={},ep=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}`;ep[s]=c,qo[c]=s,qo[`${t}${i}`]=s,qo[`${e}${o}`]=s,qo[`${t}${o}`]=s}}function tp(r,e,t){let n="";for(let i=e;i<t;){let o=r[i++];n+=ep[o]}return n}function hd(r){return r.length>>>1}function rp(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 rx=Math.pow(2,24),nx=Math.pow(2,16),ix=Math.pow(2,8),ur=(r,e)=>r[e]*rx+r[e+1]*nx+r[e+2]*ix+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:ox(r,e,t,n,i)}function ox(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 cx=0,np=32768,pd=32768,ax=~pd,op=32768,ux=~op;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=Ec(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(Pi(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:Pr(r.replace(/^\.|\.$/gm,""))+2}}),Fe=Ee({encode(r,e,t){e||(e=new Uint8Array(Fe.encodingLength(r))),t||(t=0);let n=Ec(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=Pi(r,e+1,e+1+t);return Fe.decode.bytes=t+1,n},encodingLength(r){return Pr(r)+1}}),Li=Ee({bytes:12,encode(r,e,t){e||(e=new Uint8Array(Li.encodingLength(r))),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?np:cx;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&np?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:Zf(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:Xf(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}}),Tc=Ee({encode(r,e,t){e||(e=new Uint8Array(Tc.encodingLength(r))),t||(t=0);let n=r.length;return q(e,n,t),mt(r,e,t+2,0,n),Tc.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 Tc.decode.bytes=t+2,n},encodingLength(r){return r.length+2}}),Bc=Ee({encode(r,e,t){return e||(e=new Uint8Array(Bc.encodingLength(r))),t||(t=0),$.encode(r,e,t+2),q(e,$.encode.bytes,t),Bc.encode.bytes=$.encode.bytes+2,e},decode(r,e){e||(e=0);let t=se(r,e),n=$.decode(r,e+2);return Bc.decode.bytes=t+2,n},encodingLength(r){return $.encodingLength(r)+2}}),Sc=Ee({encode(r,e,t){e||(e=new Uint8Array(Sc.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),Sc.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,Sc.decode.bytes=e-t,n},encodingLength(r){return 22+$.encodingLength(r.mname)+$.encodingLength(r.rname)}}),Ic=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]=vc(r[i])),!un(r[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Ic.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),Ic.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 Ic.decode.bytes=e-t,i},encodingLength(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=Pr(t)+1:e+=t.length+1}),e}}),Dc=Ee({encode(r,e,t){e||(e=new Uint8Array(Dc.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=vc(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),Dc.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,Dc.decode.bytes=e-t,i},encodingLength(r){return r?(un(r)?r.length:Pr(r))+2:2}}),Uc=Ee({encode(r,e,t){e||(e=new Uint8Array(Uc.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),Uc.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,Uc.decode.bytes=e-t,n},encodingLength(r){return Fe.encodingLength(r.cpu)+Fe.encodingLength(r.os)+2}}),$i=Ee({encode(r,e,t){return e||(e=new Uint8Array($i.encodingLength(r))),t||(t=0),$.encode(r,e,t+2),q(e,$.encode.bytes,t),$i.encode.bytes=$.encode.bytes+2,e},decode(r,e){e||(e=0);let t=$.decode(r,e+2);return $i.decode.bytes=$.decode.bytes+2,t},encodingLength(r){return $.encodingLength(r)+2}}),Oc=Ee({encode(r,e,t){e||(e=new Uint8Array(Oc.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),Oc.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),Oc.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,Ec(e,r.value,t),t+=Pr(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=Pi(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 Kc=Ee({encode(r,e,t){e||(e=new Uint8Array(Kc.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),Kc.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,Kc.decode.bytes=e-t,n},encodingLength(r){return 4+$.encodingLength(r.exchange)}}),sp=Ee({encode(r,e,t){return e||(e=new Uint8Array(sp.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}),_c=Ee({encode(r,e,t){return e||(e=new Uint8Array(_c.encodingLength(r))),t||(t=0),q(e,16,t),t+=2,Rr.encode(r,e,t),_c.encode.bytes=18,e},decode(r,e){e||(e=0),e+=2;let t=Rr.decode(r,e);return _c.decode.bytes=18,t},bytes:18}),ip=r=>new Uint8Array(r),Lr=Ee({encode(r,e,t){e||(e=new Uint8Array(Lr.encodingLength(r))),t||(t=0);let n=t,i=dd(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||Gf(r.ip,ip),c=Wf(r.ip,ip),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 Lr.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={};t.code=se(r,e),t.type=Qf(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=Yf(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 Lr.decode.bytes=n+4,t},encodingLength(r){if(r.data)return r.data.length+4;switch(dd(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=Ni(r,Lr);return q(e,i,t),t=Yo(r,Lr,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++]=Lr.decode(r,e),e+=Lr.decode.bytes,i-=Lr.decode.bytes;return ln.decode.bytes=e-t,n},encodingLength(r){return 2+Ni(r||[],Lr)}}),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+Pr(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,Ci(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)+Pr(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=Ci(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=vc(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=Ci(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+Pr(r.digest)}}),Mi=Ee({encode(r,e,t){e||(e=new Uint8Array(Mi.encodingLength(r))),t||(t=0);let n=t;t+=2,e[t]=r.algorithm,t+=1,e[t]=r.hash,t+=1;let i=hd(r.fingerprint),o=yd(r.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${r.fingerprint}" for hashType=${r.hash}: ${i} != ${o}`);return rp(e,r.fingerprint,t,t+=i),Mi.encode.bytes=t-n,q(e,Mi.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=yd(n.hash);return n.fingerprint=tp(r,e,e+i),e+=i,Mi.decode.bytes=e-t,n},encodingLength(r){return 4+hd(r.fingerprint)}});function yd(r){if(r===1)return 20;if(r===2)return 32;throw new Error(`Invalid hashType=${r}, supported=1,2`)}Mi.getFingerprintLengthForHashType=yd;function fd(r){switch(r.toUpperCase()){case"A":return sp;case"PTR":return $i;case"CNAME":return $i;case"DNAME":return $i;case"TXT":return Ic;case"NULL":return Dc;case"AAAA":return _c;case"SRV":return Oc;case"HINFO":return Uc;case"CAA":return dn;case"NS":return Bc;case"SOA":return Sc;case"MX":return Kc;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 Mi;case"DS":return Wo}return Tc}var $t=Ee({encode(r,e,t){e||(e=new Uint8Array($t.encodingLength(r))),t||(t=0);let n=t;if($.encode(r.name,e,t),t+=$.encode.bytes,q(e,Ci(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=ud(r.class===void 0?"IN":r.class);r.flush&&(i|=pd),q(e,i,t+2),dr(e,r.ttl||0,t+4),t+=8;let o=fd(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return $t.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=ad(i&ax),t.flush=!!(i&pd);let o=fd(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return $t.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+fd(r.type).encodingLength(e)}}),Vi=Ee({encode(r,e,t){e||(e=new Uint8Array(Vi.encodingLength(r))),t||(t=0);let n=t;return $.encode(r.name,e,t),t+=$.encode.bytes,q(e,Ci(r.type),t),t+=2,q(e,ud(r.class===void 0?"IN":r.class),t),t+=2,Vi.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=ad(se(r,e)),e+=2,!!(n.class&op)&&(n.class&=ux),Vi.decode.bytes=e-t,n},encodingLength(r){return $.encodingLength(r.name)+4}});var cp=1024;var tt={encode:function(r,e,t){let n=!e;n&&(e=new Uint8Array(dx(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),Li.encode(r,e,t),t+=Li.encode.bytes,t=Yo(r.questions,Vi,e,t),t=Yo(r.answers,$t,e,t),t=Yo(r.authorities,$t,e,t),t=Yo(r.additionals,$t,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=Li.decode(r,e);return e+=Li.decode.bytes,e=Ac(n.questions,Vi,r,e),e=Ac(n.answers,$t,r,e),e=Ac(n.authorities,$t,r,e),e=Ac(n.additionals,$t,r,e),tt.decode.bytes=e-t,n},encodingLength:function(r){return Li.encodingLength(r)+Ni(r.questions||[],Vi)+Ni(r.answers||[],$t)+Ni(r.authorities||[],$t)+Ni(r.additionals||[],$t)}};tt.encode.bytes=0;tt.decode.bytes=0;function kc(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 Cc={encode:function(r,e,t){return e=tt.encode(kc(r,"query"),e,t),Cc.encode.bytes=tt.encode.bytes,e},decode:function(r,e){let t=tt.decode(r,e);return Cc.decode.bytes=tt.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return tt.encodingLength(kc(r,"query"))}};Cc.encode.bytes=0;Cc.decode.bytes=0;var Rc={encode:function(r,e,t){return e=tt.encode(kc(r,"response"),e,t),Rc.encode.bytes=tt.encode.bytes,e},decode:function(r,e){let t=tt.decode(r,e);return Rc.decode.bytes=tt.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return tt.encodingLength(kc(r,"response"))}};Rc.encode.bytes=0;Rc.decode.bytes=0;var Xo=tt.encode,Pc=tt.decode,dx=tt.encodingLength;function ap(r){let e=Xo(r),t=new Uint8Array(2+e.byteLength);return q(t,e.byteLength),mt(e,t,2,0,e.length),ap.bytes=t.byteLength,t}ap.bytes=0;function up(r){let e=se(r,0);if(r.byteLength<e+2)return null;let t=Pc(r.slice(2));return up.bytes=Pc.bytes,t}up.bytes=0;function Ni(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 Ac(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 FB=h(f(),1),Vt=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 dp=process.env.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",lx=0,hn=7200,Lc=";",ct=",",hp=(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))(hp||{}),md=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(md||{}),fp=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(fp||{}),pp={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},lp={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"},Zo=class Zo extends Vt{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(a=>!(a.algorithm in pp)))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 Ge.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}#${pt(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 yt({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(ke.parse(e.uri)?.method!==Zo.methodName)throw new F("methodNotSupported","Method not supported");let i=await yt.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=ke.parse(e.id);if(n&&n.method!==this.methodName)throw new F("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>pt(o.id)===(pt(t)??pt(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=dp}){return await Nc.put({did:e,gatewayUri:t})}static async resolve(e,t={}){let n=t?.gatewayUri??dp;try{await Ge.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await Nc.get({didUri:e,gatewayUri:n});return{..._e,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof F))throw new Error(i);return{..._e,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};Zo.methodName="dht";var Mc=Zo,Nc=class r{static async get({didUri:e,gatewayUri:t}){let n=Ge.identifierToIdentityKeyBytes({didUri:e}),i=await r.pkarrGet({gatewayUri:t,publicKeyBytes:n}),o=await Ge.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 Ge.createBep44PutMessage({dnsPacket:n,publicKeyBytes:Ge.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=Ge.parseTxtDataToString(s.data);n.alsoKnownAs=u.split(ct);break}case c.startsWith("cnt"):{let u=Ge.parseTxtDataToString(s.data);n.controller=u.includes(ct)?u.split(ct):u;break}case c.startsWith("k"):{let{id:u,t:d,k:a,c:l,a:g}=Ge.parseTxtDataToObject(s.data),b=M.base64Url(a).toUint8Array(),m=md[Number(d)],x=await Ge.keyConverter(m).bytesToPublicKey({publicKeyBytes:b});x.alg=g||lp[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}=Ge.parseTxtDataToObject(s.data),g=a.includes(ct)?a.split(ct):[a],b=Object.fromEntries(Object.entries(l).map(([m,x])=>[m,x.includes(ct)?x.split(ct):x]));n.service??=[],n.service.push({...b,id:`${e}#${u}`,type:d,serviceEndpoint:g});break}case c.startsWith("typ"):{let{id:u}=Ge.parseTxtDataToObject(s.data);i.types=u.split(ct).map(d=>Number(d));break}case c.startsWith("did"):{let u=m=>m.split(ct).map(x=>o.get(x)).filter(x=>typeof x=="string"),{auth:d,asm:a,del:l,inv:g,agm:b}=Ge.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 Ge.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(ct)}),e.controller){let g=Array.isArray(e.controller)?e.controller.join(ct):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 pp))throw new F("invalidPublicKeyType",`Verification method '${b.id}' contains an unsupported key type: ${E?.crv??"undefined"}`);let S=md[E.crv],U=await Ge.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!==lp[S]&&_.push(`a=${E.alg}`),b.controller!==e.id&&_.push(`c=${b.controller}`),o.push({type:"TXT",name:`_${m}._did.`,ttl:hn,data:_.join(Lc)})}e.service?.forEach((g,b)=>{let m=`s${b}`;u.push(m);let{id:x,type:E,serviceEndpoint:S,...U}=g;x=pt(x),S=Array.isArray(S)?S.join(","):S;let _=Object.entries({id:x,t:E,se:S,...U}).map(([k,C])=>`${k}=${C}`).join(Lc),D=Ge.chunkDataIfNeeded(_);o.push({type:"TXT",name:`_${m}._did.`,ttl:hn,data:D})});let a=[`v=${lx}`];if(d.length&&a.push(`vm=${d.join(ct)}`),Object.keys(ui).forEach(g=>{let b=e[g]?.map(m=>c.get(m.split("#").pop()));if(b){let m=fp[g];a.push(`${m}=${b.join(ct)}`)}}),u.length&&a.push(`svc=${u.join(ct)}`),t.types?.length){let b=t.types.map(m=>typeof m=="string"?hp[m]:m);o.push({type:"TXT",name:"_typ._did.",ttl:hn,data:`id=${b.join(ct)}`})}o.push({type:"TXT",name:"_did."+r.getUniqueDidSuffix(e.id)+".",ttl:hn,data:a.join(Lc)});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:cp,answers:[...o,...s]}}static getUniqueDidSuffix(e){return e.split(":")[2]}},Ge=class r{static async createBep44PutMessage({dnsPacket:e,publicKeyBytes:t,signer:n}){let i=Math.ceil(Date.now()/1e3),o=Xo(e),s=cd.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 Je.bytesToPublicKey({publicKeyBytes:t})}static identifierToIdentityKeyBytes({didUri:e}){let t=ke.parse(e);if(!t)throw new F("invalidDid",`Invalid DID URI: ${e}`);if(t.method!==Mc.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 Je.publicKeyToBytes({publicKey:e}),n=M.uint8Array(t).toBase32Z();return`did:${Mc.methodName}:${n}`}static keyConverter(e){let n={Ed25519:Je,"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 ze.publicKeyToBytes({publicKey:i});return await ze.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:ze.bytesToPublicKey,privateKeyToBytes:ze.privateKeyToBytes,bytesToPrivateKey:ze.bytesToPrivateKey},X25519:mc}[e];if(!n)throw new F("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async parseBep44GetMessage({bep44Message:e}){let t=await Je.bytesToPublicKey({publicKeyBytes:e.k}),n=cd.encode({seq:e.seq,v:e.v}).subarray(1,-1);if(!await Je.verify({key:t,signature:e.sig,data:n}))throw new F("invalidSignature","Invalid signature for DHT BEP44 message");return Pc(e.v)}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split(Lc).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 Je.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 BI=h(f(),1);var yI=h(f(),1);var C8=h(f(),1);var DS=h(f(),1);var nS=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 oS=h(f(),1),be=class extends Error{constructor(e,t){super(`${e}: ${t}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};var AS=h(f(),1);var gS=h(f(),1);var cS=h(f(),1);var dS=h(f(),1),aS=new Uint8Array(0);var gd=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 lS=h(f(),1);var wd=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")}},xd=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 yp(this,e)}},bd=class{constructor(e){this.decoders=e}or(e){return yp(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`)}},yp=(r,e)=>new bd({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),vd=class{constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new wd(e,t,n),this.decoder=new xd(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},hx=({name:r,prefix:e,encode:t,decode:n})=>new vd(r,e,t,n);var fx=(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},px=(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},Qo=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>hx({prefix:e,name:r,encode(i){return px(i,n,t)},decode(i){return fx(i,n,t,r)}});var xS=Qo({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bS=Qo({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),es=Qo({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vS=Qo({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gt=class r{static encode(e){return es.baseEncode(e)}static decodeAsBytes(e,t){if(!r.isBase64UrlString(e))throw new be(Se.EncodedStringIncorrectEncoding,`Given ${t} must be base64url string.`);return es.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 I8=h(f(),1),Sp=h(gp(),1);var LS=h(f(),1);var KS=h(f(),1),Ed;(function(r){r.Public="public",r.Private="private"})(Ed||(Ed={}));var It=Ed;var He=class{static validateEs256kOperationKey(e,t){let n=new Set(["kty","crv","x","y"]);t===It.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===It.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 NS=h(f(),1),ts=class{};ts.hashAlgorithmInMultihashCode=18;ts.maxCanonicalizedDeltaSizeInBytes=1e3;var at=ts;var qS=h(f(),1),bp=h(xp(),1);var Xt=class r{static canonicalizeAsBytes(e){let t=r.removeAllUndefinedProperties(e),n=bp.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 h8=h(f(),1);var XS=h(f(),1);var GS=h(f(),1);var zS=h(f(),1),yx=Ap,vp=128,mx=127,gx=~mx,wx=Math.pow(2,31);function Ap(r,e,t){e=e||[],t=t||0;for(var n=t;r>=wx;)e[t++]=r&255|vp,r/=128;for(;r&gx;)e[t++]=r&255|vp,r>>>=7;return e[t]=r|0,Ap.bytes=t-n+1,e}var xx=Ad,bx=128,Ep=127;function Ad(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Ad.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Ep)<<i:(s&Ep)*Math.pow(2,i),i+=7}while(s>=bx);return Ad.bytes=o-n,t}var vx=Math.pow(2,7),Ex=Math.pow(2,14),Ax=Math.pow(2,21),Tx=Math.pow(2,28),Bx=Math.pow(2,35),Sx=Math.pow(2,42),Ix=Math.pow(2,49),Dx=Math.pow(2,56),Ux=Math.pow(2,63),Ox=function(r){return r<vx?1:r<Ex?2:r<Ax?3:r<Tx?4:r<Bx?5:r<Sx?6:r<Ix?7:r<Dx?8:r<Ux?9:10},Kx={encode:yx,decode:xx,encodingLength:Ox},_x=Kx,rs=_x;var Td=(r,e=0)=>[rs.decode(r,e),rs.decode.bytes],Bd=(r,e,t=0)=>(rs.encode(r,e,t),e),Sd=r=>rs.encodingLength(r);var Id=(r,e)=>{let t=e.byteLength,n=Sd(r),i=n+Sd(t),o=new Uint8Array(i+t);return Bd(r,o,0),Bd(t,o,n),o.set(e,i),new Vc(r,t,e,o)},Tp=r=>{let e=gd(r),[t,n]=Td(e),[i,o]=Td(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Vc(t,i,s,e)};var Vc=class{constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var n8=h(f(),1);var QS=h(f(),1);var Ud=({name:r,code:e,encode:t})=>new Dd(r,e,t),Dd=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?Id(this.code,t):t.then(n=>Id(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Bp=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),Fc=Ud({name:"sha2-256",code:18,encode:Bp("SHA-256")}),t8=Ud({name:"sha2-512",code:19,encode:Bp("SHA-512")});var ns=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 ns(this,void 0,void 0,function*(){let n;switch(t){case 18:n=(yield Fc.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 ns(this,void 0,void 0,function*(){let n;switch(t){case 18:n=yield Fc.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 ns(this,void 0,void 0,function*(){let n=Xt.canonicalizeAsBytes(e);return yield r.hashThenEncode(n,t)})}static canonicalizeThenDoubleHashThenEncode(e,t){return ns(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 ns(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=Tp(i)}catch{throw new be(Se.MultihashStringNotAMultihash,`Given ${t} string '${e}' is not a multihash after decoding.`)}let o=at.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 p8=h(f(),1),Od;(function(r){r.Create="create",r.Update="update",r.Deactivate="deactivate",r.Recover="recover"})(Od||(Od={}));var is=Od;var m8=h(f(),1),Kd;(function(r){r.Replace="replace",r.AddPublicKeys="add-public-keys",r.RemovePublicKeys="remove-public-keys",r.AddServices="add-services",r.RemoveServices="remove-services"})(Kd||(Kd={}));var Hn=Kd;var Hc=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 Hc(this,void 0,void 0,function*(){let t=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;He.validateEs256kOperationKey(t,It.Public),He.validateEs256kOperationKey(n,It.Public),r.validateDidDocumentKeys(i),r.validateServices(o);let s=at.hashAlgorithmInMultihashCode,c=[{action:Hn.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:is.Create,suffixData:a,delta:u}})}static createDeactivateRequest(e){return Hc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),He.validateEs256kOperationKey(e.recoveryPublicKey,It.Public);let t=at.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:is.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return Hc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),He.validateEs256kOperationKey(e.recoveryPublicKey,It.Public),He.validateEs256kOperationKey(e.nextRecoveryPublicKey,It.Public),He.validateEs256kOperationKey(e.nextUpdatePublicKey,It.Public),r.validateDidDocumentKeys(e.document.publicKeys),r.validateServices(e.document.services);let t=at.hashAlgorithmInMultihashCode,n=yield We.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i=[{action:Hn.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:is.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:a}})}static createUpdateRequest(e){return Hc(this,void 0,void 0,function*(){if(r.validateDidSuffix(e.didSuffix),He.validateEs256kOperationKey(e.updatePublicKey,It.Public),He.validateEs256kOperationKey(e.nextUpdatePublicKey,It.Public),r.validateServices(e.servicesToAdd),r.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let m of e.idsOfServicesToRemove)He.validateId(m);if(e.idsOfPublicKeysToRemove!==void 0)for(let m of e.idsOfPublicKeysToRemove)He.validateId(m);let t=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let m={action:Hn.AddServices,services:n};t.push(m)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let m={action:Hn.RemoveServices,ids:i};t.push(m)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let m={action:Hn.AddPublicKeys,publicKeys:o};t.push(m)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let m={action:Hn.RemovePublicKeys,ids:s};t.push(m)}let c=at.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:is.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(He.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),He.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){He.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"&&Sp.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>at.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${t.length} bytes exceeded limit of ${at.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new be(Se.DeltaExceedsMaximumSize,n)}}};var Ip=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())})},Fi=class r{static createLongFormDid(e){return Ip(this,void 0,void 0,function*(){let t=yield fn.createCreateRequest(e),n=yield r.computeDidUniqueSuffix(t.suffixData),i;at.network===void 0||at.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${at.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 Ip(this,void 0,void 0,function*(){let t=Xt.canonicalizeAsBytes(e),n=yield We.hash(t,at.hashAlgorithmInMultihashCode);return gt.encode(n)})}};var q8=h(f(),1);var R8=h(f(),1);var rt=2n**255n-19n,jc=2n**252n+27742317777372353535851937790883648493n,kd=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Cd=0x6666666666666666666666666666666666666666666666666666666666666658n,qc={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:rt,n:jc,h:8,Gx:kd,Gy:Cd},wt=(r="")=>{throw new Error(r)},kp=r=>typeof r=="string",Rd=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?wt("Uint8Array expected"):r,Hi=r=>new Uint8Array(r),Rx=(r,e)=>Rd(kp(r)?Ld(r):Hi(r),e),z=(r,e=rt)=>{let t=r%e;return t>=0n?t:e+t},Dp=r=>r instanceof pn?r:wt("Point expected"),Up,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}=qc;e=Rx(e,32);let i=e.slice();i[31]=e[31]&-129;let o=Lx(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}=Nx(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}=Dp(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(zc)}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}=qc,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}=Dp(e),{a,d:l}=qc,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"):zc;if(typeof e=="bigint"&&0n<e&&e<jc||wt("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Jc))return Vx(e).p;let n=zc,i=Jc;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(qc.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(jc/2n,!1).double();return jc%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=Rp(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=Px(t);return n[31]|=e&1n?128:0,n}toHex(){return Pd(this.toRawBytes())}};pn.BASE=new pn(kd,Cd,1n,z(kd*Cd));pn.ZERO=new pn(0n,1n,1n,0n);var{BASE:Jc,ZERO:zc}=pn,Cp=(r,e)=>r.toString(16).padStart(e,"0"),Pd=r=>Array.from(r).map(e=>Cp(e,2)).join(""),Ld=r=>{let e=r.length;(!kp(r)||e%2)&&wt("hex invalid 1");let t=Hi(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},Px=r=>Ld(Cp(r,32*2)).reverse(),Lx=r=>BigInt("0x"+Pd(Hi(Rd(r)).reverse())),Op=(...r)=>{let e=Hi(r.reduce((n,i)=>n+Rd(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},Rp=(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},Mx=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}},Kp=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Nx=(r,e)=>{let t=z(e*e*e),n=z(t*t*e),i=Mx(r*n).pow_p_5_8,o=z(r*t*i),s=z(e*o*o),c=o,u=z(o*Kp),d=s===r,a=s===z(-r),l=s===z(-r*Kp);return d&&(o=c),(a||l)&&(o=u),(z(o)&1n)===1n&&(o=z(-o)),{isValid:d||a,value:o}};var _d;var _p=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Pp={bytesToHex:Pd,hexToBytes:Ld,concatBytes:Op,mod:z,invert:Rp,randomBytes:r=>{let e=_p();return e||wt("crypto.getRandomValues must be defined"),e.getRandomValues(Hi(r))},sha512Async:async(...r)=>{let e=_p();e||wt("crypto.subtle or etc.sha512Async must be defined");let t=Op(...r);return Hi(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(Pp,{sha512Sync:{configurable:!1,get(){return _d},set(r){_d||(_d=r)}}});var qn=8,$x=()=>{let r=[],e=256/qn+1,t=Jc,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(qn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Vx=r=>{let e=Up||(Up=$x()),t=(a,l)=>{let g=l.negate();return a?g:l},n=zc,i=Jc,o=1+256/qn,s=2**(qn-1),c=BigInt(2**qn-1),u=2**qn,d=BigInt(qn);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 P8=h(f(),1);var Nd=2n**256n,zn=Nd-0x1000003d1n,$d=Nd-0x14551231950b75fc4402da1732fc9bebfn,qp=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,jp=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,zp={p:zn,n:$d,a:0n,b:7n,Gx:qp,Gy:jp},qi=32,Lp=r=>H(H(r*r)*r+zp.b),Ye=(r="")=>{throw new Error(r)},Yc=r=>typeof r=="bigint",Jp=r=>typeof r=="string",Md=r=>Yc(r)&&0n<r&&r<zn,Gp=r=>Yc(r)&&0n<r&&r<$d,Wp=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?Ye("Uint8Array expected"):r,ss=r=>new Uint8Array(r),Vd=(r,e)=>Wp(Jp(r)?Xc(r):ss(r),e),H=(r,e=zn)=>{let t=r%e;return t>=0n?t:e+t},Mp=r=>r instanceof Mr?r:Ye("Point expected"),Np,Mr=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=Vd(e);let t,n=e[0],i=e.subarray(1),o=$p(i,0,qi),s=e.length;if(s===33&&[2,3].includes(n)){Md(o)||Ye("Point hex invalid: x not FE");let c=Hx(Lp(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,$p(i,qi,2*qi),1n)),t?t.ok():Ye("Point is not on curve")}static fromPrivateKey(e){return os.mul(qx(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}=Mp(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}=Mp(e),{a:u,b:d}=zp,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 Gc;if(Gp(e)||Ye("invalid scalar"),this.equals(os))return Jx(e).p;let n=Gc,i=os;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(Gc))return{x:0n,y:0n};if(n===1n)return{x:e,y:t};let i=Xp(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(!Md(e)||!Md(t))&&Ye("Point invalid: x or y"),H(t*t)===Lp(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")+Vp(t)+(e?"":Vp(n))}toRawBytes(e=!0){return Xc(this.toHex(e))}};Mr.BASE=new Mr(qp,jp,1n);Mr.ZERO=new Mr(0n,1n,0n);var{BASE:os,ZERO:Gc}=Mr,Yp=(r,e)=>r.toString(16).padStart(e,"0"),Fd=r=>Array.from(r).map(e=>Yp(e,2)).join(""),Xc=r=>{let e=r.length;(!Jp(r)||e%2)&&Ye("hex invalid 1");let t=ss(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},Zc=r=>BigInt("0x"+(Fd(r)||"0")),$p=(r,e,t)=>Zc(r.slice(e,t)),Hd=r=>Yc(r)&&r>=0n&&r<Nd?Xc(Yp(r,2*qi)):Ye("bigint expected"),Vp=r=>Fd(Hd(r)),Fp=(...r)=>{let e=ss(r.reduce((n,i)=>n+Wp(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},Xp=(r,e=zn)=>{(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")},Hx=r=>{let e=1n;for(let t=r,n=(zn+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*t%zn),t=t*t%zn;return H(e*e)===r?e:Ye("sqrt invalid")},qx=r=>(Yc(r)||(r=Zc(Vd(r,qi))),Gp(r)?r:Ye("private key out of range"));var Hp=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Wc;function jx(r){r=Vd(r);let e=qi+8;(r.length<e||r.length>1024)&&Ye("expected proper params");let t=H(Zc(r),$d-1n)+1n;return Hd(t)}var Zp={hexToBytes:Xc,bytesToHex:Fd,concatBytes:Fp,bytesToNumberBE:Zc,numberToBytesBE:Hd,mod:H,invert:Xp,hmacSha256Async:async(r,...e)=>{let t=Hp();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 ss(await n.sign("HMAC",i,Fp(...e)))},hmacSha256Sync:Wc,hashToPrivateKey:jx,randomBytes:r=>{let e=Hp();return e||Ye("crypto.getRandomValues must be defined"),e.getRandomValues(ss(r))}};Object.defineProperties(Zp,{hmacSha256Sync:{configurable:!1,get(){return Wc},set(r){Wc||(Wc=r)}}});var jn=8,zx=()=>{let r=[],e=256/jn+1,t=os,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},Jx=r=>{let e=Np||(Np=zx()),t=(a,l)=>{let g=l.negate();return a?g:l},n=Gc,i=os,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 z8=h(f(),1),ey;(function(r){r.Mainnet="mainnet",r.Testnet="test"})(ey||(ey={}));var G8=h(f(),1),ty;(function(r){r.Authentication="authentication",r.AssertionMethod="assertionMethod",r.CapabilityInvocation="capabilityInvocation",r.CapabilityDelegation="capabilityDelegation",r.KeyAgreement="keyAgreement"})(ty||(ty={}));var rI=h(f(),1);var Gx=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(Gx||{}),Wx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},ry="https://ion.tbd.engineering",Gn=class Gn extends Vt{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(m=>!(m.algorithm in Wx)))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 Jn.computeLongFormDidUri({recoveryKey:c,updateKey:d,services:t.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:g}=await Gn.resolve(a,{gatewayUri:t.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${g?.error}`);let b=new yt({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 Gn.publish({did:b,gatewayUri:t.gatewayUri});b.metadata=m.didDocumentMetadata}return b}static async getSigningMethod({didDocument:e,methodId:t}){let n=ke.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(ke.parse(e.uri)?.method!==Gn.methodName)throw new F("methodNotSupported","Method not supported");return await yt.import({portableDid:e,keyManager:t})}static async publish({did:e,gatewayUri:t=ry}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:Qu({didDocument:e.document,methodId:s.id})}))??[],i=await Jn.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await Jn.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=Jn.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=ke.parse(e);if(!n)return{..._e,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Gn.methodName)return{..._e,didResolutionMetadata:{error:"methodNotSupported"}};let i=t?.gatewayUri??ry;try{let o=Jn.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{..._e,...c&&{didDocument:c},didDocumentMetadata:{published:u?.method?.published,...u}}}catch(o){if(!(o instanceof F))throw new Error(o);return{..._e,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};Gn.methodName="ion";var ny=Gn,Jn=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 Fi.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 CI=h(f(),1);var Wn=class Wn extends Vt{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:${Wn.methodName}:${s}`,d=(await Wn.resolve(c)).didDocument;return new yt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=ke.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(ke.parse(e.uri)?.method!==Wn.methodName)throw new F("methodNotSupported","Method not supported");let i=await yt.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=ke.parse(e),i;try{i=n?M.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{..._e,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Wn.methodName)return{..._e,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{..._e,didDocument:o}}};Wn.methodName="jwk";var iy=Wn;var qI=h(f(),1);var Yx=(n=>(n.Ed25519="Ed25519",n.secp256k1="secp256k1",n.secp256r1="secp256r1",n))(Yx||{}),oy={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},Xx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},fr=class fr extends Vt{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 ji.publicKeyToMultibaseId({publicKey:o}),c=`did:${fr.methodName}:${s}`,d=(await fr.resolve(c,t)).didDocument;return new yt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=ke.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(ke.parse(e.uri)?.method!==fr.methodName)throw new F("methodNotSupported","Method not supported");let i=await yt.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{..._e,didDocument:n}}catch(n){if(!(n instanceof F))throw new Error(n);return{..._e,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=ke.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 Zu({didDocument:s}).forEach(g=>{let b=oy[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}=td({multibaseKeyId:t}),a=c.byteLength,l=ji.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 ze.validatePublicKey({publicKeyBytes:c});break;case"ed25519-pub":g=await Je.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 oy))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 ji.multicodecToJwk({code:u});s.publicKeyJwk=await ji.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&&li(n)==="String"&&n.startsWith("z")}};fr.methodName="key";var sy=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:ze.compressPublicKey}[e];if(!n)throw new F("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Je,"P-256":et,secp256k1:ze}[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 Xx))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 ed({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 ji=pr;var WI=h(f(),1);var Qc=class Qc extends Vt{static async resolve(e,t){let n=ke.parse(e);if(!n)return{..._e,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Qc.methodName)return{..._e,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{..._e,didDocument:c}}catch{return{..._e,didResolutionMetadata:{error:"notFound"}}}}};Qc.methodName="web";var cy=Qc;var QI=h(f(),1),ly=h(Bu(),1),hy=h(uy(),1),dy=class{constructor({db:e,location:t="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new ly.Level(t),this.ttl=(0,hy.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 t5=h(f(),1),fy={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 c5=h(f(),1);var py=class{constructor({cache:e,didResolvers:t}){this.didResolvers=new Map;this.cache=e||fy;for(let n of t)this.didResolvers.set(n.methodName,n)}async resolve(e,t){let n=ke.parse(e);if(!n)return{..._e,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${e}`}};let i=this.didResolvers.get(n.method);if(!i)return{..._e,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=ke.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:{}}}};export{yt as BearerDid,ke as Did,Mc as DidDht,Nc as DidDhtDocument,hp as DidDhtRegisteredDidType,md as DidDhtRegisteredKeyType,Ge as DidDhtUtils,fp as DidDhtVerificationRelationship,F as DidError,Hr as DidErrorCode,ny as DidIon,Gx as DidIonRegisteredKeyType,Jn as DidIonUtils,iy as DidJwk,sy as DidKey,Yx as DidKeyRegisteredKeyType,ji as DidKeyUtils,oy as DidKeyVerificationMethodType,Vt as DidMethod,dy as DidResolverCacheLevel,fy as DidResolverCacheNoop,ui as DidVerificationRelationship,cy as DidWeb,_e as EMPTY_DID_RESOLUTION_RESULT,py as UniversalResolver,Rf as utils};
1
+ var Jy=Object.create;var ga=Object.defineProperty;var Gy=Object.getOwnPropertyDescriptor;var Wy=Object.getOwnPropertyNames;var Yy=Object.getPrototypeOf,Xy=Object.prototype.hasOwnProperty;var se=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),wa=(r,e)=>{for(var t in e)ga(r,t,{get:e[t],enumerable:!0})},Zy=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Wy(e))!Xy.call(r,i)&&i!==t&&ga(r,i,{get:()=>e[i],enumerable:!(n=Gy(e,i))||n.enumerable});return r};var Sn=(r,e,t)=>(t=r!=null?Jy(Yy(r)):{},Zy(e||!r||!r.__esModule?ga(t,"default",{value:r,enumerable:!0}):t,r));var vl=se((Sb,bl)=>{var Qy=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Ss=()=>Qy.now(),e0=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),xa=r=>r===1/0||e0(r),ba=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&&!xa(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!xa(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-Ss());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(Ss()+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(!xa(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-Ss())):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(Ss());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()}};bl.exports=ba});var Ll=se(Ml=>{"use strict";Ml.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 jt=se((Av,Nl)=>{"use strict";Nl.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 Hl=se(Is=>{"use strict";Is.byteLength=k0;Is.toByteArray=C0;Is.fromByteArray=L0;var ir=[],Ct=[],O0=typeof Uint8Array<"u"?Uint8Array:Array,Ca="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Kn=0,$l=Ca.length;Kn<$l;++Kn)ir[Kn]=Ca[Kn],Ct[Ca.charCodeAt(Kn)]=Kn;var Kn,$l;Ct[45]=62;Ct[95]=63;function Vl(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 k0(r){var e=Vl(r),t=e[0],n=e[1];return(t+n)*3/4-n}function P0(r,e,t){return(e+t)*3/4-t}function C0(r){var e,t=Vl(r),n=t[0],i=t[1],o=new O0(P0(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=Ct[r.charCodeAt(u)]<<18|Ct[r.charCodeAt(u+1)]<<12|Ct[r.charCodeAt(u+2)]<<6|Ct[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Ct[r.charCodeAt(u)]<<2|Ct[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=Ct[r.charCodeAt(u)]<<10|Ct[r.charCodeAt(u+1)]<<4|Ct[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function R0(r){return ir[r>>18&63]+ir[r>>12&63]+ir[r>>6&63]+ir[r&63]}function M0(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(R0(n));return i.join("")}function L0(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(M0(r,s,s+o>c?c:s+o));return n===1?(e=r[t-1],i.push(ir[e>>2]+ir[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(ir[e>>10]+ir[e>>4&63]+ir[e<<2&63]+"=")),i.join("")}});var Fl=se(Ra=>{Ra.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,y=t?-1:1,w=r[e+l];for(l+=y,o=w&(1<<-a)-1,w>>=-a,a+=c;a>0;o=o*256+r[e+l],l+=y,a-=8);for(s=o&(1<<-a)-1,o>>=-a,a+=n;a>0;s=s*256+r[e+l],l+=y,a-=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)};Ra.write=function(r,e,t,n,i,o){var s,c,u,d=o*8-i-1,a=(1<<d)-1,l=a>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=n?0:o-1,p=n?1:-1,g=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+=y/u:e+=y*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+w]=c&255,w+=p,c/=256,i-=8);for(s=s<<i|c,d+=i;d>0;r[t+w]=s&255,w+=p,s/=256,d-=8);r[t+w-p]|=g*128}});var _s=se(bi=>{"use strict";var Ma=Hl(),wi=Fl(),ql=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;bi.Buffer=A;bi.SlowBuffer=q0;bi.INSPECT_MAX_BYTES=50;var Ds=2147483647;bi.kMaxLength=Ds;A.TYPED_ARRAY_SUPPORT=N0();!A.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 N0(){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(A.prototype,"parent",{enumerable:!0,get:function(){if(A.isBuffer(this))return this.buffer}});Object.defineProperty(A.prototype,"offset",{enumerable:!0,get:function(){if(A.isBuffer(this))return this.byteOffset}});function Ar(r){if(r>Ds)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,A.prototype),e}function A(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 Va(r)}return Gl(r,e,t)}A.poolSize=8192;function Gl(r,e,t){if(typeof r=="string")return V0(r,e);if(ArrayBuffer.isView(r))return H0(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(or(r,ArrayBuffer)||r&&or(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(or(r,SharedArrayBuffer)||r&&or(r.buffer,SharedArrayBuffer)))return Na(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 A.from(n,e,t);let i=F0(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return A.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)}A.from=function(r,e,t){return Gl(r,e,t)};Object.setPrototypeOf(A.prototype,Uint8Array.prototype);Object.setPrototypeOf(A,Uint8Array);function Wl(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 $0(r,e,t){return Wl(r),r<=0?Ar(r):e!==void 0?typeof t=="string"?Ar(r).fill(e,t):Ar(r).fill(e):Ar(r)}A.alloc=function(r,e,t){return $0(r,e,t)};function Va(r){return Wl(r),Ar(r<0?0:Ha(r)|0)}A.allocUnsafe=function(r){return Va(r)};A.allocUnsafeSlow=function(r){return Va(r)};function V0(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!A.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=Yl(r,e)|0,n=Ar(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function La(r){let e=r.length<0?0:Ha(r.length)|0,t=Ar(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function H0(r){if(or(r,Uint8Array)){let e=new Uint8Array(r);return Na(e.buffer,e.byteOffset,e.byteLength)}return La(r)}function Na(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,A.prototype),n}function F0(r){if(A.isBuffer(r)){let e=Ha(r.length)|0,t=Ar(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||qa(r.length)?Ar(0):La(r);if(r.type==="Buffer"&&Array.isArray(r.data))return La(r.data)}function Ha(r){if(r>=Ds)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ds.toString(16)+" bytes");return r|0}function q0(r){return+r!=r&&(r=0),A.alloc(+r)}A.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==A.prototype};A.compare=function(e,t){if(or(e,Uint8Array)&&(e=A.from(e,e.offset,e.byteLength)),or(t,Uint8Array)&&(t=A.from(t,t.offset,t.byteLength)),!A.isBuffer(e)||!A.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};A.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}};A.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return A.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=A.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(or(s,Uint8Array))o+s.length>i.length?(A.isBuffer(s)||(s=A.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(A.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Yl(r,e){if(A.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||or(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 $a(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return oh(r).length;default:if(i)return n?-1:$a(r).length;e=(""+e).toLowerCase(),i=!0}}A.byteLength=Yl;function j0(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 tm(this,e,t);case"utf8":case"utf-8":return Zl(this,e,t);case"ascii":return Q0(this,e,t);case"latin1":case"binary":return em(this,e,t);case"base64":return X0(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rm(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}A.prototype._isBuffer=!0;function _n(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}A.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)_n(this,t,t+1);return this};A.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)_n(this,t,t+3),_n(this,t+1,t+2);return this};A.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)_n(this,t,t+7),_n(this,t+1,t+6),_n(this,t+2,t+5),_n(this,t+3,t+4);return this};A.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Zl(this,0,e):j0.apply(this,arguments)};A.prototype.toLocaleString=A.prototype.toString;A.prototype.equals=function(e){if(!A.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:A.compare(this,e)===0};A.prototype.inspect=function(){let e="",t=bi.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};ql&&(A.prototype[ql]=A.prototype.inspect);A.prototype.compare=function(e,t,n,i,o){if(or(e,Uint8Array)&&(e=A.from(e,e.offset,e.byteLength)),!A.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 Xl(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,qa(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=A.from(e,n)),A.isBuffer(e))return e.length===0?-1:jl(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):jl(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function jl(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}A.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};A.prototype.indexOf=function(e,t,n){return Xl(this,e,t,n,!0)};A.prototype.lastIndexOf=function(e,t,n){return Xl(this,e,t,n,!1)};function z0(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(qa(c))return s;r[t+s]=c}return s}function J0(r,e,t,n){return Ks($a(e,r.length-t),r,t,n)}function G0(r,e,t,n){return Ks(sm(e),r,t,n)}function W0(r,e,t,n){return Ks(oh(e),r,t,n)}function Y0(r,e,t,n){return Ks(cm(e,r.length-t),r,t,n)}A.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 z0(this,e,t,n);case"utf8":case"utf-8":return J0(this,e,t,n);case"ascii":case"latin1":case"binary":return G0(this,e,t,n);case"base64":return W0(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Y0(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};A.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function X0(r,e,t){return e===0&&t===r.length?Ma.fromByteArray(r):Ma.fromByteArray(r.slice(e,t))}function Zl(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 Z0(n)}var zl=4096;function Z0(r){let e=r.length;if(e<=zl)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=zl));return t}function Q0(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 em(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 tm(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+=am[r[o]];return i}function rm(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}A.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,A.prototype),i};function Je(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")}A.prototype.readUintLE=A.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||Je(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};A.prototype.readUintBE=A.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||Je(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};A.prototype.readUint8=A.prototype.readUInt8=function(e,t){return e=e>>>0,t||Je(e,1,this.length),this[e]};A.prototype.readUint16LE=A.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||Je(e,2,this.length),this[e]|this[e+1]<<8};A.prototype.readUint16BE=A.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||Je(e,2,this.length),this[e]<<8|this[e+1]};A.prototype.readUint32LE=A.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};A.prototype.readUint32BE=A.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};A.prototype.readBigUInt64LE=Gr(function(e){e=e>>>0,xi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mo(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))});A.prototype.readBigUInt64BE=Gr(function(e){e=e>>>0,xi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mo(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)});A.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||Je(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};A.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||Je(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};A.prototype.readInt8=function(e,t){return e=e>>>0,t||Je(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};A.prototype.readInt16LE=function(e,t){e=e>>>0,t||Je(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};A.prototype.readInt16BE=function(e,t){e=e>>>0,t||Je(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};A.prototype.readInt32LE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};A.prototype.readInt32BE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};A.prototype.readBigInt64LE=Gr(function(e){e=e>>>0,xi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mo(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)});A.prototype.readBigInt64BE=Gr(function(e){e=e>>>0,xi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mo(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)});A.prototype.readFloatLE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),wi.read(this,e,!0,23,4)};A.prototype.readFloatBE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),wi.read(this,e,!1,23,4)};A.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||Je(e,8,this.length),wi.read(this,e,!0,52,8)};A.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||Je(e,8,this.length),wi.read(this,e,!1,52,8)};function ht(r,e,t,n,i,o){if(!A.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")}A.prototype.writeUintLE=A.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;ht(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};A.prototype.writeUintBE=A.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;ht(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};A.prototype.writeUint8=A.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,1,255,0),this[t]=e&255,t+1};A.prototype.writeUint16LE=A.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};A.prototype.writeUint16BE=A.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};A.prototype.writeUint32LE=A.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||ht(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};A.prototype.writeUint32BE=A.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||ht(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 Ql(r,e,t,n,i){ih(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 eh(r,e,t,n,i){ih(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}A.prototype.writeBigUInt64LE=Gr(function(e,t=0){return Ql(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});A.prototype.writeBigUInt64BE=Gr(function(e,t=0){return eh(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});A.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);ht(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};A.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);ht(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};A.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};A.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};A.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||ht(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};A.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||ht(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};A.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||ht(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};A.prototype.writeBigInt64LE=Gr(function(e,t=0){return Ql(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});A.prototype.writeBigInt64BE=Gr(function(e,t=0){return eh(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function th(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 rh(r,e,t,n,i){return e=+e,t=t>>>0,i||th(r,e,t,4,34028234663852886e22,-34028234663852886e22),wi.write(r,e,t,n,23,4),t+4}A.prototype.writeFloatLE=function(e,t,n){return rh(this,e,t,!0,n)};A.prototype.writeFloatBE=function(e,t,n){return rh(this,e,t,!1,n)};function nh(r,e,t,n,i){return e=+e,t=t>>>0,i||th(r,e,t,8,17976931348623157e292,-17976931348623157e292),wi.write(r,e,t,n,52,8),t+8}A.prototype.writeDoubleLE=function(e,t,n){return nh(this,e,t,!0,n)};A.prototype.writeDoubleBE=function(e,t,n){return nh(this,e,t,!1,n)};A.prototype.copy=function(e,t,n,i){if(!A.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};A.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"&&!A.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=A.isBuffer(e)?e:A.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 gi={};function Fa(r,e,t){gi[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}`}}}Fa("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Fa("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Fa("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=Jl(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=Jl(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Jl(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 nm(r,e,t){xi(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&mo(e,r.length-(t+1))}function ih(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 gi.ERR_OUT_OF_RANGE("value",c,r)}nm(n,i,o)}function xi(r,e){if(typeof r!="number")throw new gi.ERR_INVALID_ARG_TYPE(e,"number",r)}function mo(r,e,t){throw Math.floor(r)!==r?(xi(r,t),new gi.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new gi.ERR_BUFFER_OUT_OF_BOUNDS:new gi.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var im=/[^+/0-9A-Za-z-_]/g;function om(r){if(r=r.split("=")[0],r=r.trim().replace(im,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function $a(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 sm(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function cm(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 oh(r){return Ma.toByteArray(om(r))}function Ks(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 or(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function qa(r){return r!==r}var am=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 Gr(r){return typeof BigInt>"u"?um:r}function um(){throw new Error("BigInt not supported")}});var za=se((Dv,sh)=>{"use strict";var ja=null;sh.exports=function(){return ja===null&&(ja={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),ja}});var Wa=se(ch=>{"use strict";var Ja=jt(),dm=new Set(["buffer","view","utf8"]),Ga=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"||!dm.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 Ja(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Ja(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Ja(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ch.Encoding=Ga});var Qa=se(Us=>{"use strict";var{Buffer:Xa}=_s()||{},{Encoding:Za}=Wa(),lm=za(),go=class extends Za{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new wo({encode:this.encode,decode:e=>this.decode(Xa.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},wo=class extends Za{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new go({encode:e=>{let t=this.encode(e);return Xa.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Ya=class extends Za{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new go({encode:e=>Xa.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=lm();return new wo({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};Us.BufferFormat=go;Us.ViewFormat=wo;Us.UTF8Format=Ya});var lh=se(Un=>{"use strict";var{Buffer:rt}=_s()||{Buffer:{isBuffer:()=>!1}},{textEncoder:uh,textDecoder:ah}=za()(),{BufferFormat:xo,ViewFormat:eu,UTF8Format:dh}=Qa(),Os=r=>r;Un.utf8=new dh({encode:function(r){return rt.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?ah.decode(r):String(r)},decode:Os,name:"utf8",createViewTranscoder(){return new eu({encode:function(r){return ArrayBuffer.isView(r)?r:uh.encode(r)},decode:function(r){return ah.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new xo({encode:function(r){return rt.isBuffer(r)?r:ArrayBuffer.isView(r)?rt.from(r.buffer,r.byteOffset,r.byteLength):rt.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Un.json=new dh({encode:JSON.stringify,decode:JSON.parse,name:"json"});Un.buffer=new xo({encode:function(r){return rt.isBuffer(r)?r:ArrayBuffer.isView(r)?rt.from(r.buffer,r.byteOffset,r.byteLength):rt.from(String(r),"utf8")},decode:Os,name:"buffer",createViewTranscoder(){return new eu({encode:function(r){return ArrayBuffer.isView(r)?r:rt.from(String(r),"utf8")},decode:function(r){return rt.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Un.view=new eu({encode:function(r){return ArrayBuffer.isView(r)?r:uh.encode(r)},decode:Os,name:"view",createBufferTranscoder(){return new xo({encode:function(r){return rt.isBuffer(r)?r:ArrayBuffer.isView(r)?rt.from(r.buffer,r.byteOffset,r.byteLength):rt.from(String(r),"utf8")},decode:Os,name:`${this.name}+buffer`})}});Un.hex=new xo({encode:function(r){return rt.isBuffer(r)?r:rt.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Un.base64=new xo({encode:function(r){return rt.isBuffer(r)?r:rt.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var ph=se(fh=>{"use strict";var hh=jt(),Ps=lh(),{Encoding:hm}=Wa(),{BufferFormat:fm,ViewFormat:pm,UTF8Format:ym}=Qa(),bo=Symbol("formats"),ks=Symbol("encodings"),mm=new Set(["buffer","view","utf8"]),tu=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>mm.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[ks]=new Map,this[bo]=new Set(e);for(let t in Ps)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[ks].values()))}encoding(e){let t=this[ks].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=bm[e],!t)throw new hh(`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=gm(e)}let{name:n,format:i}=t;if(!this[bo].has(i))if(this[bo].has("view"))t=t.createViewTranscoder();else if(this[bo].has("buffer"))t=t.createBufferTranscoder();else if(this[bo].has("utf8"))t=t.createUTF8Transcoder();else throw new hh(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[ks].set(o,t)}return t}};fh.Transcoder=tu;function gm(r){if(r instanceof hm)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${vm++}`;switch(wm(r)){case"view":return new pm({...r,name:t});case"utf8":return new ym({...r,name:t});case"buffer":return new fm({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function wm(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 xm={binary:Ps.buffer,"utf-8":Ps.utf8},bm={...Ps,...xm},vm=0});var mh=se((kv,ru)=>{"use strict";var Em=Object.prototype.hasOwnProperty,ct="~";function vo(){}Object.create&&(vo.prototype=Object.create(null),new vo().__proto__||(ct=!1));function Am(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function yh(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Am(t,n||r,i),s=ct?ct+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function Cs(r,e){--r._eventsCount===0?r._events=new vo:delete r._events[e]}function nt(){this._events=new vo,this._eventsCount=0}nt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Em.call(t,n)&&e.push(ct?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};nt.prototype.listeners=function(e){var t=ct?ct+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};nt.prototype.listenerCount=function(e){var t=ct?ct+e:e,n=this._events[t];return n?n.fn?1:n.length:0};nt.prototype.emit=function(e,t,n,i,o,s){var c=ct?ct+e:e;if(!this._events[c])return!1;var u=this._events[c],d=arguments.length,a,l;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),d){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,n),!0;case 4:return u.fn.call(u.context,t,n,i),!0;case 5:return u.fn.call(u.context,t,n,i,o),!0;case 6:return u.fn.call(u.context,t,n,i,o,s),!0}for(l=1,a=new Array(d-1);l<d;l++)a[l-1]=arguments[l];u.fn.apply(u.context,a)}else{var y=u.length,w;for(l=0;l<y;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),d){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,t);break;case 3:u[l].fn.call(u[l].context,t,n);break;case 4:u[l].fn.call(u[l].context,t,n,i);break;default:if(!a)for(w=1,a=new Array(d-1);w<d;w++)a[w-1]=arguments[w];u[l].fn.apply(u[l].context,a)}}return!0};nt.prototype.on=function(e,t,n){return yh(this,e,t,n,!1)};nt.prototype.once=function(e,t,n){return yh(this,e,t,n,!0)};nt.prototype.removeListener=function(e,t,n,i){var o=ct?ct+e:e;if(!this._events[o])return this;if(!t)return Cs(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&Cs(this,o);else{for(var c=0,u=[],d=s.length;c<d;c++)(s[c].fn!==t||i&&!s[c].once||n&&s[c].context!==n)&&u.push(s[c]);u.length?this._events[o]=u.length===1?u[0]:u:Cs(this,o)}return this};nt.prototype.removeAllListeners=function(e){var t;return e?(t=ct?ct+e:e,this._events[t]&&Cs(this,t)):(this._events=new vo,this._eventsCount=0),this};nt.prototype.off=nt.prototype.removeListener;nt.prototype.addListener=nt.prototype.on;nt.prefixed=ct;nt.EventEmitter=nt;typeof ru<"u"&&(ru.exports=nt)});var wh=se((Pv,gh)=>{gh.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var Eo=se(nu=>{"use strict";var xh=wh();nu.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};nu.fromPromise=function(r,e){if(e===void 0)return r;r.then(function(t){xh(()=>e(null,t))}).catch(function(t){xh(()=>e(t))})}});var Rs=se(iu=>{"use strict";iu.getCallback=function(r,e){return typeof r=="function"?r:e};iu.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var en=se($s=>{"use strict";var{fromCallback:ou}=Eo(),Et=jt(),{getOptions:su,getCallback:bh}=Rs(),On=Symbol("promise"),vi=Symbol("callback"),sr=Symbol("working"),kn=Symbol("handleOne"),Tr=Symbol("handleMany"),cu=Symbol("autoClose"),Zr=Symbol("finishWork"),cr=Symbol("returnMany"),Wr=Symbol("closing"),Ao=Symbol("handleClose"),Ms=Symbol("closed"),To=Symbol("closeCallbacks"),Xr=Symbol("keyEncoding"),Pn=Symbol("valueEncoding"),au=Symbol("abortOnClose"),Ls=Symbol("legacy"),uu=Symbol("keys"),du=Symbol("values"),Yr=Symbol("limit"),Rt=Symbol("count"),Ns=Object.freeze({}),Tm=()=>{},vh=!1,So=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[Ms]=!1,this[To]=[],this[sr]=!1,this[Wr]=!1,this[cu]=!1,this[vi]=null,this[kn]=this[kn].bind(this),this[Tr]=this[Tr].bind(this),this[Ao]=this[Ao].bind(this),this[Xr]=t[Xr],this[Pn]=t[Pn],this[Ls]=n,this[Yr]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[Rt]=0,this[au]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Rt]}get limit(){return this[Yr]}next(e){let t;if(e===void 0)t=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[Ls]?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[Wr]?this.nextTick(e,new Et("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(e,new Et("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[sr]=!0,this[vi]=e,this[Rt]>=this[Yr]?this.nextTick(this[kn],null):this._next(this[kn])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=bh(t,n),n=ou(n,On),t=su(t,Ns),Number.isInteger(e)?(this[Wr]?this.nextTick(n,new Et("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(n,new Et("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[Yr]<1/0&&(e=Math.min(e,this[Yr]-this[Rt])),this[sr]=!0,this[vi]=n,e<=0?this.nextTick(this[Tr],null,[]):this._nextv(e,t,this[Tr])),n[On]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[On])}_nextv(e,t,n){let i=[],o=(s,c,u)=>{if(s)return n(s);if(this[Ls]?c===void 0&&u===void 0:c===void 0)return n(null,i);i.push(this[Ls]?[c,u]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=bh(e,t),t=ou(t,On),e=su(e,Ns),this[Wr]?this.nextTick(t,new Et("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(t,new Et("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[sr]=!0,this[vi]=t,this[cu]=!0,this[Rt]>=this[Yr]?this.nextTick(this[Tr],null,[]):this._all(e,this[Tr])),t[On]}_all(e,t){let n=this[Rt],i=[],o=()=>{let c=this[Yr]<1/0?Math.min(1e3,this[Yr]-n):1e3;c<=0?this.nextTick(t,null,i):this._nextv(c,Ns,s)},s=(c,u)=>{c?t(c):u.length===0?t(null,i):(i.push.apply(i,u),n+=u.length,o())};o()}[Zr](){let e=this[vi];return this[au]&&e===null?Tm:(this[sr]=!1,this[vi]=null,this[Wr]&&this._close(this[Ao]),e)}[cr](e,t,n){this[cu]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=su(t,Ns),!this[Wr]){if(this[sr])throw new Et("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[Xr]),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 Et("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=ou(e,On),this[Ms]?this.nextTick(e):this[Wr]?this[To].push(e):(this[Wr]=!0,this[To].push(e),this[sr]?this[au]&&this[Zr]()(new Et("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[Ao])),e[On]}_close(e){this.nextTick(e)}[Ao](){this[Ms]=!0,this.db.detachResource(this);let e=this[To];this[To]=[];for(let t of e)t()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Ms]||await this.close()}}},Ei=class extends So{constructor(e,t){super(e,t,!0),this[uu]=t.keys!==!1,this[du]=t.values!==!1}[kn](e,t,n){let i=this[Zr]();if(e)return i(e);try{t=this[uu]&&t!==void 0?this[Xr].decode(t):void 0,n=this[du]&&n!==void 0?this[Pn].decode(n):void 0}catch(o){return i(new Qr("entry",o))}t===void 0&&n===void 0||this[Rt]++,i(null,t,n)}[Tr](e,t){let n=this[Zr]();if(e)return this[cr](n,e);try{for(let i of t){let o=i[0],s=i[1];i[0]=this[uu]&&o!==void 0?this[Xr].decode(o):void 0,i[1]=this[du]&&s!==void 0?this[Pn].decode(s):void 0}}catch(i){return this[cr](n,new Qr("entries",i))}this[Rt]+=t.length,this[cr](n,null,t)}end(e){return!vh&&typeof console<"u"&&(vh=!0,console.warn(new Et("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)}},lu=class extends So{constructor(e,t){super(e,t,!1)}[kn](e,t){let n=this[Zr]();if(e)return n(e);try{t=t!==void 0?this[Xr].decode(t):void 0}catch(i){return n(new Qr("key",i))}t!==void 0&&this[Rt]++,n(null,t)}[Tr](e,t){let n=this[Zr]();if(e)return this[cr](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[Xr].decode(o):void 0}}catch(i){return this[cr](n,new Qr("keys",i))}this[Rt]+=t.length,this[cr](n,null,t)}},hu=class extends So{constructor(e,t){super(e,t,!1)}[kn](e,t){let n=this[Zr]();if(e)return n(e);try{t=t!==void 0?this[Pn].decode(t):void 0}catch(i){return n(new Qr("value",i))}t!==void 0&&this[Rt]++,n(null,t)}[Tr](e,t){let n=this[Zr]();if(e)return this[cr](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[Pn].decode(o):void 0}}catch(i){return this[cr](n,new Qr("values",i))}this[Rt]+=t.length,this[cr](n,null,t)}},Qr=class extends Et{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(Ei.prototype,r.split(" ")[0],{get(){throw new Et(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Et(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});Ei.keyEncoding=Xr;Ei.valueEncoding=Pn;$s.AbstractIterator=Ei;$s.AbstractKeyIterator=lu;$s.AbstractValueIterator=hu});var Eh=se(fu=>{"use strict";var{AbstractKeyIterator:Sm,AbstractValueIterator:Bm}=en(),Cn=Symbol("iterator"),Bo=Symbol("callback"),Ai=Symbol("handleOne"),Rn=Symbol("handleMany"),Io=class extends Sm{constructor(e,t){super(e,t),this[Cn]=e.iterator({...t,keys:!0,values:!1}),this[Ai]=this[Ai].bind(this),this[Rn]=this[Rn].bind(this)}},Vs=class extends Bm{constructor(e,t){super(e,t),this[Cn]=e.iterator({...t,keys:!1,values:!0}),this[Ai]=this[Ai].bind(this),this[Rn]=this[Rn].bind(this)}};for(let r of[Io,Vs]){let e=r===Io,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[Bo]=n,this[Cn].next(this[Ai])},r.prototype[Ai]=function(n,i,o){let s=this[Bo];n?s(n):s(null,e?i:o)},r.prototype._nextv=function(n,i,o){this[Bo]=o,this[Cn].nextv(n,i,this[Rn])},r.prototype._all=function(n,i){this[Bo]=i,this[Cn].all(n,this[Rn])},r.prototype[Rn]=function(n,i){let o=this[Bo];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[Cn].seek(n,i)},r.prototype._close=function(n){this[Cn].close(n)}}fu.DefaultKeyIterator=Io;fu.DefaultValueIterator=Vs});var Ah=se(Js=>{"use strict";var{AbstractIterator:Im,AbstractKeyIterator:Dm,AbstractValueIterator:Km}=en(),pu=jt(),ft=Symbol("nut"),js=Symbol("undefer"),zs=Symbol("factory"),Hs=class extends Im{constructor(e,t){super(e,t),this[ft]=null,this[zs]=()=>e.iterator(t),this.db.defer(()=>this[js]())}},Fs=class extends Dm{constructor(e,t){super(e,t),this[ft]=null,this[zs]=()=>e.keys(t),this.db.defer(()=>this[js]())}},qs=class extends Km{constructor(e,t){super(e,t),this[ft]=null,this[zs]=()=>e.values(t),this.db.defer(()=>this[js]())}};for(let r of[Hs,Fs,qs])r.prototype[js]=function(){this.db.status==="open"&&(this[ft]=this[zs]())},r.prototype._next=function(e){this[ft]!==null?this[ft].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new pu("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(e,t,n){this[ft]!==null?this[ft].nextv(e,t,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,t,n)):this.nextTick(n,new pu("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(e,t){this[ft]!==null?this[ft].all(t):this.db.status==="opening"?this.db.defer(()=>this._all(e,t)):this.nextTick(t,new pu("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(e,t){this[ft]!==null?this[ft]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t))},r.prototype._close=function(e){this[ft]!==null?this[ft].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};Js.DeferredIterator=Hs;Js.DeferredKeyIterator=Fs;Js.DeferredValueIterator=qs});var mu=se(Sh=>{"use strict";var{fromCallback:Th}=Eo(),Gs=jt(),{getCallback:_m,getOptions:Um}=Rs(),Ws=Symbol("promise"),Mt=Symbol("status"),Ti=Symbol("operations"),Do=Symbol("finishClose"),Si=Symbol("closeCallbacks"),yu=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[Ti]=[],this[Si]=[],this[Mt]="open",this[Do]=this[Do].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[Ti].length}put(e,t,n){if(this[Mt]!=="open")throw new Gs("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[Ti].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[Mt]!=="open")throw new Gs("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[Ti].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[Mt]!=="open")throw new Gs("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[Ti]=[],this}_clear(){}write(e,t){return t=_m(e,t),t=Th(t,Ws),e=Um(e),this[Mt]!=="open"?this.nextTick(t,new Gs("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[Mt]="writing",this._write(e,n=>{this[Mt]="closing",this[Si].push(()=>t(n)),n||this.db.emit("batch",this[Ti]),this._close(this[Do])})),t[Ws]}_write(e,t){}close(e){return e=Th(e,Ws),this[Mt]==="closing"?this[Si].push(e):this[Mt]==="closed"?this.nextTick(e):(this[Si].push(e),this[Mt]!=="writing"&&(this[Mt]="closing",this._close(this[Do]))),e[Ws]}_close(e){this.nextTick(e)}[Do](){this[Mt]="closed",this.db.detachResource(this);let e=this[Si];this[Si]=[];for(let t of e)t()}};Sh.AbstractChainedBatch=yu});var Ih=se(Bh=>{"use strict";var{AbstractChainedBatch:Om}=mu(),km=jt(),Bi=Symbol("encoded"),gu=class extends Om{constructor(e){super(e),this[Bi]=[]}_put(e,t,n){this[Bi].push({...n,type:"put",key:e,value:t})}_del(e,t){this[Bi].push({...t,type:"del",key:e})}_clear(){this[Bi]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[Bi].length===0?this.nextTick(t):this.db._batch(this[Bi],e,t):this.nextTick(t,new km("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};Bh.DefaultChainedBatch=gu});var _h=se((Hv,Kh)=>{"use strict";var Dh=jt(),Pm=Object.prototype.hasOwnProperty,Cm=new Set(["lt","lte","gt","gte"]);Kh.exports=function(r,e){let t={};for(let n in r)if(Pm.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new Dh(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new Dh("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});Cm.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 wu=se((Fv,Oh)=>{var Uh;Oh.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(Uh||(Uh=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var Ch=se((qv,Ph)=>{"use strict";var kh=wu();Ph.exports=function(r,...e){e.length===0?kh(r):kh(()=>r(...e))}});var Rh=se(Ys=>{"use strict";var{AbstractIterator:Rm,AbstractKeyIterator:Mm,AbstractValueIterator:Lm}=en(),Ii=Symbol("unfix"),zt=Symbol("iterator"),Mn=Symbol("handleOne"),tn=Symbol("handleMany"),Sr=Symbol("callback"),Ko=class extends Rm{constructor(e,t,n,i){super(e,t),this[zt]=n,this[Ii]=i,this[Mn]=this[Mn].bind(this),this[tn]=this[tn].bind(this),this[Sr]=null}[Mn](e,t,n){let i=this[Sr];if(e)return i(e);t!==void 0&&(t=this[Ii](t)),i(e,t,n)}[tn](e,t){let n=this[Sr];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[Ii](o))}n(e,t)}},_o=class extends Mm{constructor(e,t,n,i){super(e,t),this[zt]=n,this[Ii]=i,this[Mn]=this[Mn].bind(this),this[tn]=this[tn].bind(this),this[Sr]=null}[Mn](e,t){let n=this[Sr];if(e)return n(e);t!==void 0&&(t=this[Ii](t)),n(e,t)}[tn](e,t){let n=this[Sr];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[Ii](o))}n(e,t)}},Uo=class extends Lm{constructor(e,t,n){super(e,t),this[zt]=n}};for(let r of[Ko,_o])r.prototype._next=function(e){this[Sr]=e,this[zt].next(this[Mn])},r.prototype._nextv=function(e,t,n){this[Sr]=n,this[zt].nextv(e,t,this[tn])},r.prototype._all=function(e,t){this[Sr]=t,this[zt].all(e,this[tn])};for(let r of[Uo])r.prototype._next=function(e){this[zt].next(e)},r.prototype._nextv=function(e,t,n){this[zt].nextv(e,t,n)},r.prototype._all=function(e,t){this[zt].all(e,t)};for(let r of[Ko,_o,Uo])r.prototype._seek=function(e,t){this[zt].seek(e,t)},r.prototype._close=function(e){this[zt].close(e)};Ys.AbstractSublevelIterator=Ko;Ys.AbstractSublevelKeyIterator=_o;Ys.AbstractSublevelValueIterator=Uo});var $h=se((zv,Nh)=>{"use strict";var xu=jt(),{Buffer:Eu}=_s()||{},{AbstractSublevelIterator:Nm,AbstractSublevelKeyIterator:$m,AbstractSublevelValueIterator:Vm}=Rh(),Br=Symbol("prefix"),Mh=Symbol("upperBound"),Oo=Symbol("prefixRange"),At=Symbol("parent"),bu=Symbol("unfix"),Lh=new TextEncoder,Hm={separator:"!"};Nh.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new xu("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new xu("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?Hm:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...u}=e.defaults(o);i=qm(i,s);let d=s.charCodeAt(0)+1,a=n[At]||n;if(!Lh.encode(i).every(w=>w>d&&w<127))throw new xu(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Fm(a,c),u);let l=(n.prefix||"")+s+i+s,y=l.slice(0,-1)+String.fromCharCode(d);this[At]=a,this[Br]=new Xs(l),this[Mh]=new Xs(y),this[bu]=new Au,this.nextTick=a.nextTick}prefixKey(n,i){if(i==="utf8")return this[Br].utf8+n;if(n.byteLength===0)return this[Br][i];if(i==="view"){let o=this[Br].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Br].buffer;return Eu.concat([o,n],o.byteLength+n.byteLength)}}[Oo](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[Br][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[Br].utf8}get db(){return this[At]}_open(n,i){this[At].open({passive:!0},i)}_put(n,i,o,s){this[At].put(n,i,o,s)}_get(n,i,o){this[At].get(n,i,o)}_getMany(n,i,o){this[At].getMany(n,i,o)}_del(n,i,o){this[At].del(n,i,o)}_batch(n,i,o){this[At].batch(n,i,o)}_clear(n,i){this[Oo](n,n.keyEncoding),this[At].clear(n,i)}_iterator(n){this[Oo](n,n.keyEncoding);let i=this[At].iterator(n),o=this[bu].get(this[Br].utf8.length,n.keyEncoding);return new Nm(this,n,i,o)}_keys(n){this[Oo](n,n.keyEncoding);let i=this[At].keys(n),o=this[bu].get(this[Br].utf8.length,n.keyEncoding);return new $m(this,n,i,o)}_values(n){this[Oo](n,n.keyEncoding);let i=this[At].values(n);return new Vm(this,n,i)}}return{AbstractSublevel:e}};var Fm=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:vu(r,"utf8"),buffer:vu(r,"buffer"),view:vu(r,"view")}}},vu=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},Xs=class{constructor(e){this.utf8=e,this.view=Lh.encode(e),this.buffer=Eu?Eu.from(this.view.buffer,0,this.view.byteLength):{}}},Au=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}},qm=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 Du=se(Iu=>{"use strict";var{supports:jm}=Ll(),{Transcoder:zm}=ph(),{EventEmitter:Jm}=mh(),{fromCallback:rn}=Eo(),Jt=jt(),{AbstractIterator:Ln}=en(),{DefaultKeyIterator:Gm,DefaultValueIterator:Wm}=Eh(),{DeferredIterator:Ym,DeferredKeyIterator:Xm,DeferredValueIterator:Zm}=Ah(),{DefaultChainedBatch:Vh}=Ih(),{getCallback:Nn,getOptions:nn}=Rs(),Zs=_h(),oe=Symbol("promise"),Ir=Symbol("landed"),$n=Symbol("resources"),Tu=Symbol("closeResources"),ko=Symbol("operations"),Po=Symbol("undefer"),Qs=Symbol("deferOpen"),Hh=Symbol("options"),ce=Symbol("status"),Vn=Symbol("defaultOptions"),Di=Symbol("transcoder"),ec=Symbol("keyEncoding"),Su=Symbol("valueEncoding"),Qm=()=>{},Co=class extends Jm{constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=nn(t);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=t;this[$n]=new Set,this[ko]=[],this[Qs]=!0,this[Hh]=s,this[ce]="opening",this.supports=jm(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[Di]=new zm(eg(this)),this[ec]=this[Di].encoding(n||"utf8"),this[Su]=this[Di].encoding(i||"utf8");for(let c of this[Di].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Vn]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[ec].commonName,valueEncoding:this[Su].commonName}),key:Object.freeze({keyEncoding:this[ec].commonName})},this.nextTick(()=>{this[Qs]&&this.open({passive:!1},Qm)})}get status(){return this[ce]}keyEncoding(e){return this[Di].encoding(e??this[ec])}valueEncoding(e){return this[Di].encoding(e??this[Su])}open(e,t){t=Nn(e,t),t=rn(t,oe),e={...this[Hh],...nn(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[ce]==="closing"||this[ce]==="opening"?this.once(Ir,i?()=>n(i):n):this[ce]!=="open"?t(new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):t()};return e.passive?this[ce]==="opening"?this.once(Ir,n):this.nextTick(n):this[ce]==="closed"||this[Qs]?(this[Qs]=!1,this[ce]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[ce]="closed",this[Tu](()=>{this.emit(Ir),n(i)}),this[Po]();return}this[ce]="open",this[Po](),this.emit(Ir),this[ce]==="open"&&this.emit("open"),this[ce]==="open"&&this.emit("ready"),n()})):this[ce]==="open"?this.nextTick(n):this.once(Ir,()=>this.open(e,t)),t[oe]}_open(e,t){this.nextTick(t)}close(e){e=rn(e,oe);let t=n=>{this[ce]==="opening"||this[ce]==="closing"?this.once(Ir,n?t(n):t):this[ce]!=="closed"?e(new Jt("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[ce]==="open"){this[ce]="closing",this.emit("closing");let n=i=>{this[ce]="open",this[Po](),this.emit(Ir),t(i)};this[Tu](()=>{this._close(i=>{if(i)return n(i);this[ce]="closed",this[Po](),this.emit(Ir),this[ce]==="closed"&&this.emit("closed"),t()})})}else this[ce]==="closed"?this.nextTick(t):this.once(Ir,()=>this.close(e));return e[oe]}[Tu](e){if(this[$n].size===0)return this.nextTick(e);let t=this[$n].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[$n])o.close(i);n=!1,this[$n].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=Nn(t,n),n=rn(n,oe),t=nn(t,this[Vn].entry),this[ce]==="opening")return this.defer(()=>this.get(e,t,n)),n[oe];if(Ki(this,n))return n[oe];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[oe];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 Jt("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[oe]}_get(e,t,n){this.nextTick(n,new Error("NotFound"))}getMany(e,t,n){if(n=Nn(t,n),n=rn(n,oe),t=nn(t,this[Vn].entry),this[ce]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[oe];if(Ki(this,n))return n[oe];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[oe];if(e.length===0)return this.nextTick(n,null,[]),n[oe];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[oe];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 Jt(`Could not decode one or more of ${a.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[oe]}_getMany(e,t,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,t,n,i){if(i=Nn(n,i),i=rn(i,oe),n=nn(n,this[Vn].entry),this[ce]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[oe];if(Ki(this,i))return i[oe];let o=this._checkKey(e)||this._checkValue(t);if(o)return this.nextTick(i,o),i[oe];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,y=>{if(y)return i(y);this.emit("put",e,t),i()}),i[oe]}_put(e,t,n,i){this.nextTick(i)}del(e,t,n){if(n=Nn(t,n),n=rn(n,oe),t=nn(t,this[Vn].key),this[ce]==="opening")return this.defer(()=>this.del(e,t,n)),n[oe];if(Ki(this,n))return n[oe];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[oe];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[oe]}_del(e,t,n){this.nextTick(n)}batch(e,t,n){if(!arguments.length){if(this[ce]==="opening")return new Vh(this);if(this[ce]!=="open")throw new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=Nn(t,n),n=rn(n,oe),t=nn(t,this[Vn].empty),this[ce]==="opening")return this.defer(()=>this.batch(e,t,n)),n[oe];if(Ki(this,n))return n[oe];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[oe];if(e.length===0)return this.nextTick(n),n[oe];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[oe];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[oe];let a=this._checkKey(d.key);if(a)return this.nextTick(n,a),n[oe];let l=d.sublevel!=null?d.sublevel:this,y=l.keyEncoding(d.keyEncoding||o),w=y.format;if(d.key=l.prefixKey(y.encode(d.key),w),d.keyEncoding=w,d.type==="put"){let p=this._checkValue(d.value);if(p)return this.nextTick(n,p),n[oe];let g=l.valueEncoding(d.valueEncoding||s);d.value=g.encode(d.value),d.valueEncoding=g.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[oe]}_batch(e,t,n){this.nextTick(n)}sublevel(e,t){return this._sublevel(e,Bu.defaults(t))}_sublevel(e,t){return new Bu(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=Nn(e,t),t=rn(t,oe),e=nn(e,this[Vn].empty),this[ce]==="opening")return this.defer(()=>this.clear(e,t)),t[oe];if(Ki(this,t))return t[oe];let n=e,i=this.keyEncoding(e.keyEncoding);return e=Zs(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[oe]}_clear(e,t){this.nextTick(t)}iterator(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Zs(e,t),e.keys=e.keys!==!1,e.values=e.values!==!1,e[Ln.keyEncoding]=t,e[Ln.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new Ym(this,e);if(this[ce]!=="open")throw new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new Ln(this,e)}keys(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Zs(e,t),e[Ln.keyEncoding]=t,e[Ln.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new Xm(this,e);if(this[ce]!=="open")throw new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new Gm(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Zs(e,t),e[Ln.keyEncoding]=t,e[Ln.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new Zm(this,e);if(this[ce]!=="open")throw new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new Wm(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[ko].push(e)}[Po](){if(this[ko].length===0)return;let e=this[ko];this[ko]=[];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[$n].add(e)}detachResource(e){this[$n].delete(e)}_chainedBatch(){return new Vh(this)}_checkKey(e){if(e==null)return new Jt("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new Jt("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Co.prototype.nextTick=Ch();var{AbstractSublevel:Bu}=$h()({AbstractLevel:Co});Iu.AbstractLevel=Co;Iu.AbstractSublevel=Bu;var Ki=function(r,e){return r[ce]!=="open"?(r.nextTick(e,new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},eg=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var Ku=se(Hn=>{"use strict";Hn.AbstractLevel=Du().AbstractLevel;Hn.AbstractSublevel=Du().AbstractSublevel;Hn.AbstractIterator=en().AbstractIterator;Hn.AbstractKeyIterator=en().AbstractKeyIterator;Hn.AbstractValueIterator=en().AbstractValueIterator;Hn.AbstractChainedBatch=mu().AbstractChainedBatch});var qh=se((Wv,Fh)=>{Fh.exports=rg;var tg=wu();function rg(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(y){function w(){t&&t(y,n),t=null}u?tg(w):w()}function l(y,w,p){if(n[y]=p,w&&(c=!0),--o===0||w)a(w);else if(!c&&d<i){let g;s?(g=s[d],d+=1,r[g](function(v,S){l(g,v,S)})):(g=d,d+=1,r[g](function(v,S){l(g,v,S)}))}}d=e,o?s?s.some(function(y,w){return r[y](function(p,g){l(y,p,g)}),w===e-1}):r.some(function(y,w){return y(function(p,g){l(w,p,g)}),w===e-1}):a(null),u=!1}});var _u=se((Yv,jh)=>{"use strict";jh.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 Uu=se((Xv,zh)=>{"use strict";var ng=new TextEncoder;zh.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):ng.encode(r)}});var Xh=se(Yh=>{"use strict";var{AbstractIterator:ig}=Ku(),Jh=_u(),tc=Uu(),ar=Symbol("cache"),Dr=Symbol("finished"),Tt=Symbol("options"),Kr=Symbol("currentOptions"),Fn=Symbol("position"),Ou=Symbol("location"),_i=Symbol("first"),Gh={},ku=class extends ig{constructor(e,t,n){super(e,n),this[ar]=[],this[Dr]=this.limit===0,this[Tt]=n,this[Kr]={...n},this[Fn]=void 0,this[Ou]=t,this[_i]=!0}_nextv(e,t,n){if(this[_i]=!1,this[Dr])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[Fn]!==void 0&&(this[Tt].reverse?(this[Kr].lt=this[Fn],this[Kr].lte=void 0):(this[Kr].gt=this[Fn],this[Kr].gte=void 0));let i;try{i=Jh(this[Kr])}catch{return this[Dr]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Ou]],"readonly"),s=o.objectStore(this[Ou]),c=[];if(this[Tt].reverse){let u=!this[Tt].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[u](i,"prev").onsuccess=d=>{let a=d.target.result;if(a){let{key:l,value:y}=a;this[Fn]=l,c.push([this[Tt].keys&&l!==void 0?tc(l):void 0,this[Tt].values&&y!==void 0?tc(y):void 0]),c.length<e?a.continue():Wh(o)}else this[Dr]=!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[Dr]=!0:this[Fn]=u[l-1],c.length=l;for(let y=0;y<l;y++){let w=u[y],p=d[y];c[y]=[this[Tt].keys&&w!==void 0?tc(w):void 0,this[Tt].values&&p!==void 0?tc(p):void 0]}Wh(o)};this[Tt].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[Tt].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[ar].length>0){let[t,n]=this[ar].shift();this.nextTick(e,null,t,n)}else if(this[Dr])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[_i]&&(this[_i]=!1,t=1),this._nextv(t,Gh,(n,i)=>{if(n)return e(n);this[ar]=i,this._next(e)})}}_all(e,t){this[_i]=!1;let n=this[ar].splice(0,this[ar].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(t,null,n);this._nextv(i,Gh,(o,s)=>{if(o)return t(o);n.length>0&&(s=n.concat(s)),t(null,s)})}_seek(e,t){this[_i]=!0,this[ar]=[],this[Dr]=!1,this[Fn]=void 0,this[Kr]={...this[Tt]};let n;try{n=Jh(this[Tt])}catch{this[Dr]=!0;return}n!==null&&!n.includes(e)?this[Dr]=!0:this[Tt].reverse?this[Kr].lte=e:this[Kr].gte=e}};Yh.Iterator=ku;function Wh(r){typeof r.commit=="function"&&r.commit()}});var Qh=se((Qv,Zh)=>{"use strict";Zh.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 y=l.target.result;y&&(c.delete(y.key).onsuccess=function(){(i.limit<=0||++u<i.limit)&&y.continue()})}}});var sf=se(of=>{"use strict";var{AbstractLevel:og}=Ku(),ef=jt(),sg=qh(),{fromCallback:cg}=Eo(),{Iterator:ag}=Xh(),tf=Uu(),ug=Qh(),dg=_u(),nf="level-js-",Ro=Symbol("idb"),Pu=Symbol("namePrefix"),_r=Symbol("location"),Cu=Symbol("version"),qn=Symbol("store"),Mo=Symbol("onComplete"),rf=Symbol("promise"),rc=class extends og{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new ef("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[_r]=e,this[Pu]=i??nf,this[Cu]=parseInt(o||1,10),this[Ro]=null}get location(){return this[_r]}get namePrefix(){return this[Pu]}get version(){return this[Cu]}get db(){return this[Ro]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Pu]+this[_r],this[Cu]);n.onerror=function(){t(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[Ro]=n.result,t()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[_r])||o.createObjectStore(this[_r])}}[qn](e){return this[Ro].transaction([this[_r]],e).objectStore(this[_r])}[Mo](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[qn]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Mo](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new ef("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,tf(c))})}_getMany(e,t,n){let i=this[qn]("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:tf(d))},u.onerror=d=>{d.stopPropagation(),c(u.error)}});sg(o,16,n)}_del(e,t,n){let i=this[qn]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Mo](o,n)}_put(e,t,n,i){let o=this[qn]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[Mo](s,i)}_iterator(e){return new ag(this,this[_r],e)}_batch(e,t,n){let i=this[qn]("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(y){c=y,o.abort();return}s<e.length?l.onsuccess=u:typeof o.commit=="function"&&o.commit()}u()}_clear(e,t){let n,i;try{n=dg(e)}catch{return this.nextTick(t)}if(e.limit>=0)return ug(this,this[_r],n,e,t);try{let o=this[qn]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(t,o)}this[Mo](i,t)}_close(e){this[Ro].close(),this.nextTick(e)}};rc.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=nf),t=cg(t,rf);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[rf]};of.BrowserLevel=rc});var Ru=se(cf=>{cf.Level=sf().BrowserLevel});var _p=se((Xc,Kp)=>{(function(r,e){typeof Xc=="object"&&typeof Kp<"u"?e(Xc):typeof define=="function"&&define.amd?define(["exports"],e):e(r.URI=r.URI||{})})(Xc,function(r){"use strict";function e(){for(var f=arguments.length,h=Array(f),m=0;m<f;m++)h[m]=arguments[m];if(h.length>1){h[0]=h[0].slice(0,-1);for(var x=h.length-1,b=1;b<x;++b)h[b]=h[b].slice(1,-1);return h[x]=h[x].slice(1),h.join("")}else return h[0]}function t(f){return"(?:"+f+")"}function n(f){return f===void 0?"undefined":f===null?"null":Object.prototype.toString.call(f).split(" ").pop().split("]").shift().toLowerCase()}function i(f){return f.toUpperCase()}function o(f){return f!=null?f instanceof Array?f:typeof f.length!="number"||f.split||f.setInterval||f.call?[f]:Array.prototype.slice.call(f):[]}function s(f,h){var m=f;if(h)for(var x in h)m[x]=h[x];return m}function c(f){var h="[A-Za-z]",m="[\\x0D]",x="[0-9]",b="[\\x22]",R=e(x,"[A-Fa-f]"),re="[\\x0A]",le="[\\x20]",ye=t(t("%[EFef]"+R+"%"+R+R+"%"+R+R)+"|"+t("%[89A-Fa-f]"+R+"%"+R+R)+"|"+t("%"+R+R)),Me="[\\:\\/\\?\\#\\[\\]\\@]",de="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",Ke=e(Me,de),Le=f?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",Se=f?"[\\uE000-\\uF8FF]":"[]",he=e(h,x,"[\\-\\.\\_\\~]",Le),_e=t(h+e(h,x,"[\\+\\-\\.]")+"*"),me=t(t(ye+"|"+e(he,de,"[\\:]"))+"*"),En=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("[1-9]"+x)+"|"+x),bt=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("0?[1-9]"+x)+"|0?0?"+x),Ot=t(bt+"\\."+bt+"\\."+bt+"\\."+bt),we=t(R+"{1,4}"),vt=t(t(we+"\\:"+we)+"|"+Ot),kt=t(t(we+"\\:")+"{6}"+vt),rr=t("\\:\\:"+t(we+"\\:")+"{5}"+vt),An=t(t(we)+"?\\:\\:"+t(we+"\\:")+"{4}"+vt),xr=t(t(t(we+"\\:")+"{0,1}"+we)+"?\\:\\:"+t(we+"\\:")+"{3}"+vt),oo=t(t(t(we+"\\:")+"{0,2}"+we)+"?\\:\\:"+t(we+"\\:")+"{2}"+vt),Es=t(t(t(we+"\\:")+"{0,3}"+we)+"?\\:\\:"+we+"\\:"+vt),As=t(t(t(we+"\\:")+"{0,4}"+we)+"?\\:\\:"+vt),si=t(t(t(we+"\\:")+"{0,5}"+we)+"?\\:\\:"+we),ci=t(t(t(we+"\\:")+"{0,6}"+we)+"?\\:\\:"),br=t([kt,rr,An,xr,oo,Es,As,si,ci].join("|")),ai=t(t(he+"|"+ye)+"+"),ya=t(br+"\\%25"+ai),Tn=t(br+t("\\%25|\\%(?!"+R+"{2})")+ai),$y=t("[vV]"+R+"+\\."+e(he,de,"[\\:]")+"+"),Vy=t("\\["+t(Tn+"|"+br+"|"+$y)+"\\]"),ml=t(t(ye+"|"+e(he,de))+"*"),so=t(Vy+"|"+Ot+"(?!"+ml+")|"+ml),co=t(x+"*"),gl=t(t(me+"@")+"?"+so+t("\\:"+co)+"?"),ao=t(ye+"|"+e(he,de,"[\\:\\@]")),Hy=t(ao+"*"),wl=t(ao+"+"),Fy=t(t(ye+"|"+e(he,de,"[\\@]"))+"+"),vr=t(t("\\/"+Hy)+"*"),ui=t("\\/"+t(wl+vr)+"?"),ma=t(Fy+vr),Ts=t(wl+vr),di="(?!"+ao+")",lb=t(vr+"|"+ui+"|"+ma+"|"+Ts+"|"+di),li=t(t(ao+"|"+e("[\\/\\?]",Se))+"*"),uo=t(t(ao+"|[\\/\\?]")+"*"),xl=t(t("\\/\\/"+gl+vr)+"|"+ui+"|"+Ts+"|"+di),qy=t(_e+"\\:"+xl+t("\\?"+li)+"?"+t("\\#"+uo)+"?"),jy=t(t("\\/\\/"+gl+vr)+"|"+ui+"|"+ma+"|"+di),zy=t(jy+t("\\?"+li)+"?"+t("\\#"+uo)+"?"),hb=t(qy+"|"+zy),fb=t(_e+"\\:"+xl+t("\\?"+li)+"?"),pb="^("+_e+")\\:"+t(t("\\/\\/("+t("("+me+")@")+"?("+so+")"+t("\\:("+co+")")+"?)")+"?("+vr+"|"+ui+"|"+Ts+"|"+di+")")+t("\\?("+li+")")+"?"+t("\\#("+uo+")")+"?$",yb="^(){0}"+t(t("\\/\\/("+t("("+me+")@")+"?("+so+")"+t("\\:("+co+")")+"?)")+"?("+vr+"|"+ui+"|"+ma+"|"+di+")")+t("\\?("+li+")")+"?"+t("\\#("+uo+")")+"?$",mb="^("+_e+")\\:"+t(t("\\/\\/("+t("("+me+")@")+"?("+so+")"+t("\\:("+co+")")+"?)")+"?("+vr+"|"+ui+"|"+Ts+"|"+di+")")+t("\\?("+li+")")+"?$",gb="^"+t("\\#("+uo+")")+"?$",wb="^"+t("("+me+")@")+"?("+so+")"+t("\\:("+co+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",h,x,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",he,de),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",he,de),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",he,de),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",he,de),"g"),NOT_QUERY:new RegExp(e("[^\\%]",he,de,"[\\:\\@\\/\\?]",Se),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",he,de,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",he,de),"g"),UNRESERVED:new RegExp(he,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",he,Ke),"g"),PCT_ENCODED:new RegExp(ye,"g"),IPV4ADDRESS:new RegExp("^("+Ot+")$"),IPV6ADDRESS:new RegExp("^\\[?("+br+")"+t(t("\\%25|\\%(?!"+R+"{2})")+"("+ai+")")+"?\\]?$")}}var u=c(!1),d=c(!0),a=function(){function f(h,m){var x=[],b=!0,R=!1,re=void 0;try{for(var le=h[Symbol.iterator](),ye;!(b=(ye=le.next()).done)&&(x.push(ye.value),!(m&&x.length===m));b=!0);}catch(Me){R=!0,re=Me}finally{try{!b&&le.return&&le.return()}finally{if(R)throw re}}return x}return function(h,m){if(Array.isArray(h))return h;if(Symbol.iterator in Object(h))return f(h,m);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=function(f){if(Array.isArray(f)){for(var h=0,m=Array(f.length);h<f.length;h++)m[h]=f[h];return m}else return Array.from(f)},y=2147483647,w=36,p=1,g=26,v=38,S=700,I=72,E=128,U="-",B=/^xn--/,_=/[^\0-\x7E]/,C=/[\x2E\u3002\uFF0E\uFF61]/g,k={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},Q=w-p,F=Math.floor,j=String.fromCharCode;function ue(f){throw new RangeError(k[f])}function ae(f,h){for(var m=[],x=f.length;x--;)m[x]=h(f[x]);return m}function Ye(f,h){var m=f.split("@"),x="";m.length>1&&(x=m[0]+"@",f=m[1]),f=f.replace(C,".");var b=f.split("."),R=ae(b,h).join(".");return x+R}function D(f){for(var h=[],m=0,x=f.length;m<x;){var b=f.charCodeAt(m++);if(b>=55296&&b<=56319&&m<x){var R=f.charCodeAt(m++);(R&64512)==56320?h.push(((b&1023)<<10)+(R&1023)+65536):(h.push(b),m--)}else h.push(b)}return h}var M=function(h){return String.fromCodePoint.apply(String,l(h))},X=function(h){return h-48<10?h-22:h-65<26?h-65:h-97<26?h-97:w},K=function(h,m){return h+22+75*(h<26)-((m!=0)<<5)},T=function(h,m,x){var b=0;for(h=x?F(h/S):h>>1,h+=F(h/m);h>Q*g>>1;b+=w)h=F(h/Q);return F(b+(Q+1)*h/(h+v))},P=function(h){var m=[],x=h.length,b=0,R=E,re=I,le=h.lastIndexOf(U);le<0&&(le=0);for(var ye=0;ye<le;++ye)h.charCodeAt(ye)>=128&&ue("not-basic"),m.push(h.charCodeAt(ye));for(var Me=le>0?le+1:0;Me<x;){for(var de=b,Ke=1,Le=w;;Le+=w){Me>=x&&ue("invalid-input");var Se=X(h.charCodeAt(Me++));(Se>=w||Se>F((y-b)/Ke))&&ue("overflow"),b+=Se*Ke;var he=Le<=re?p:Le>=re+g?g:Le-re;if(Se<he)break;var _e=w-he;Ke>F(y/_e)&&ue("overflow"),Ke*=_e}var me=m.length+1;re=T(b-de,me,de==0),F(b/me)>y-R&&ue("overflow"),R+=F(b/me),b%=me,m.splice(b++,0,R)}return String.fromCodePoint.apply(String,m)},$=function(h){var m=[];h=D(h);var x=h.length,b=E,R=0,re=I,le=!0,ye=!1,Me=void 0;try{for(var de=h[Symbol.iterator](),Ke;!(le=(Ke=de.next()).done);le=!0){var Le=Ke.value;Le<128&&m.push(j(Le))}}catch(Tn){ye=!0,Me=Tn}finally{try{!le&&de.return&&de.return()}finally{if(ye)throw Me}}var Se=m.length,he=Se;for(Se&&m.push(U);he<x;){var _e=y,me=!0,En=!1,bt=void 0;try{for(var Ot=h[Symbol.iterator](),we;!(me=(we=Ot.next()).done);me=!0){var vt=we.value;vt>=b&&vt<_e&&(_e=vt)}}catch(Tn){En=!0,bt=Tn}finally{try{!me&&Ot.return&&Ot.return()}finally{if(En)throw bt}}var kt=he+1;_e-b>F((y-R)/kt)&&ue("overflow"),R+=(_e-b)*kt,b=_e;var rr=!0,An=!1,xr=void 0;try{for(var oo=h[Symbol.iterator](),Es;!(rr=(Es=oo.next()).done);rr=!0){var As=Es.value;if(As<b&&++R>y&&ue("overflow"),As==b){for(var si=R,ci=w;;ci+=w){var br=ci<=re?p:ci>=re+g?g:ci-re;if(si<br)break;var ai=si-br,ya=w-br;m.push(j(K(br+ai%ya,0))),si=F(ai/ya)}m.push(j(K(si,0))),re=T(R,kt,he==Se),R=0,++he}}}catch(Tn){An=!0,xr=Tn}finally{try{!rr&&oo.return&&oo.return()}finally{if(An)throw xr}}++R,++b}return m.join("")},J=function(h){return Ye(h,function(m){return B.test(m)?P(m.slice(4).toLowerCase()):m})},ee=function(h){return Ye(h,function(m){return _.test(m)?"xn--"+$(m):m})},W={version:"2.1.0",ucs2:{decode:D,encode:M},decode:P,encode:$,toASCII:ee,toUnicode:J},Y={};function G(f){var h=f.charCodeAt(0),m=void 0;return h<16?m="%0"+h.toString(16).toUpperCase():h<128?m="%"+h.toString(16).toUpperCase():h<2048?m="%"+(h>>6|192).toString(16).toUpperCase()+"%"+(h&63|128).toString(16).toUpperCase():m="%"+(h>>12|224).toString(16).toUpperCase()+"%"+(h>>6&63|128).toString(16).toUpperCase()+"%"+(h&63|128).toString(16).toUpperCase(),m}function te(f){for(var h="",m=0,x=f.length;m<x;){var b=parseInt(f.substr(m+1,2),16);if(b<128)h+=String.fromCharCode(b),m+=3;else if(b>=194&&b<224){if(x-m>=6){var R=parseInt(f.substr(m+4,2),16);h+=String.fromCharCode((b&31)<<6|R&63)}else h+=f.substr(m,6);m+=6}else if(b>=224){if(x-m>=9){var re=parseInt(f.substr(m+4,2),16),le=parseInt(f.substr(m+7,2),16);h+=String.fromCharCode((b&15)<<12|(re&63)<<6|le&63)}else h+=f.substr(m,9);m+=9}else h+=f.substr(m,3),m+=3}return h}function Te(f,h){function m(x){var b=te(x);return b.match(h.UNRESERVED)?b:x}return f.scheme&&(f.scheme=String(f.scheme).replace(h.PCT_ENCODED,m).toLowerCase().replace(h.NOT_SCHEME,"")),f.userinfo!==void 0&&(f.userinfo=String(f.userinfo).replace(h.PCT_ENCODED,m).replace(h.NOT_USERINFO,G).replace(h.PCT_ENCODED,i)),f.host!==void 0&&(f.host=String(f.host).replace(h.PCT_ENCODED,m).toLowerCase().replace(h.NOT_HOST,G).replace(h.PCT_ENCODED,i)),f.path!==void 0&&(f.path=String(f.path).replace(h.PCT_ENCODED,m).replace(f.scheme?h.NOT_PATH:h.NOT_PATH_NOSCHEME,G).replace(h.PCT_ENCODED,i)),f.query!==void 0&&(f.query=String(f.query).replace(h.PCT_ENCODED,m).replace(h.NOT_QUERY,G).replace(h.PCT_ENCODED,i)),f.fragment!==void 0&&(f.fragment=String(f.fragment).replace(h.PCT_ENCODED,m).replace(h.NOT_FRAGMENT,G).replace(h.PCT_ENCODED,i)),f}function be(f){return f.replace(/^0*(.*)/,"$1")||"0"}function ke(f,h){var m=f.match(h.IPV4ADDRESS)||[],x=a(m,2),b=x[1];return b?b.split(".").map(be).join("."):f}function Re(f,h){var m=f.match(h.IPV6ADDRESS)||[],x=a(m,3),b=x[1],R=x[2];if(b){for(var re=b.toLowerCase().split("::").reverse(),le=a(re,2),ye=le[0],Me=le[1],de=Me?Me.split(":").map(be):[],Ke=ye.split(":").map(be),Le=h.IPV4ADDRESS.test(Ke[Ke.length-1]),Se=Le?7:8,he=Ke.length-Se,_e=Array(Se),me=0;me<Se;++me)_e[me]=de[me]||Ke[he+me]||"";Le&&(_e[Se-1]=ke(_e[Se-1],h));var En=_e.reduce(function(kt,rr,An){if(!rr||rr==="0"){var xr=kt[kt.length-1];xr&&xr.index+xr.length===An?xr.length++:kt.push({index:An,length:1})}return kt},[]),bt=En.sort(function(kt,rr){return rr.length-kt.length})[0],Ot=void 0;if(bt&&bt.length>1){var we=_e.slice(0,bt.index),vt=_e.slice(bt.index+bt.length);Ot=we.join(":")+"::"+vt.join(":")}else Ot=_e.join(":");return R&&(Ot+="%"+R),Ot}else return f}var Pe=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,qe="".match(/(){0}/)[1]===void 0;function Ne(f){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m={},x=h.iri!==!1?d:u;h.reference==="suffix"&&(f=(h.scheme?h.scheme+":":"")+"//"+f);var b=f.match(Pe);if(b){qe?(m.scheme=b[1],m.userinfo=b[3],m.host=b[4],m.port=parseInt(b[5],10),m.path=b[6]||"",m.query=b[7],m.fragment=b[8],isNaN(m.port)&&(m.port=b[5])):(m.scheme=b[1]||void 0,m.userinfo=f.indexOf("@")!==-1?b[3]:void 0,m.host=f.indexOf("//")!==-1?b[4]:void 0,m.port=parseInt(b[5],10),m.path=b[6]||"",m.query=f.indexOf("?")!==-1?b[7]:void 0,m.fragment=f.indexOf("#")!==-1?b[8]:void 0,isNaN(m.port)&&(m.port=f.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?b[4]:void 0)),m.host&&(m.host=Re(ke(m.host,x),x)),m.scheme===void 0&&m.userinfo===void 0&&m.host===void 0&&m.port===void 0&&!m.path&&m.query===void 0?m.reference="same-document":m.scheme===void 0?m.reference="relative":m.fragment===void 0?m.reference="absolute":m.reference="uri",h.reference&&h.reference!=="suffix"&&h.reference!==m.reference&&(m.error=m.error||"URI is not a "+h.reference+" reference.");var R=Y[(h.scheme||m.scheme||"").toLowerCase()];if(!h.unicodeSupport&&(!R||!R.unicodeSupport)){if(m.host&&(h.domainHost||R&&R.domainHost))try{m.host=W.toASCII(m.host.replace(x.PCT_ENCODED,te).toLowerCase())}catch(re){m.error=m.error||"Host's domain name can not be converted to ASCII via punycode: "+re}Te(m,u)}else Te(m,x);R&&R.parse&&R.parse(m,h)}else m.error=m.error||"URI can not be parsed.";return m}function wr(f,h){var m=h.iri!==!1?d:u,x=[];return f.userinfo!==void 0&&(x.push(f.userinfo),x.push("@")),f.host!==void 0&&x.push(Re(ke(String(f.host),m),m).replace(m.IPV6ADDRESS,function(b,R,re){return"["+R+(re?"%25"+re:"")+"]"})),(typeof f.port=="number"||typeof f.port=="string")&&(x.push(":"),x.push(String(f.port))),x.length?x.join(""):void 0}var jr=/^\.\.?\//,to=/^\/\.(\/|$)/,ms=/^\/\.\.(\/|$)/,ha=/^\/?(?:.|\n)*?(?=\/|$)/;function zr(f){for(var h=[];f.length;)if(f.match(jr))f=f.replace(jr,"");else if(f.match(to))f=f.replace(to,"/");else if(f.match(ms))f=f.replace(ms,"/"),h.pop();else if(f==="."||f==="..")f="";else{var m=f.match(ha);if(m){var x=m[0];f=f.slice(x.length),h.push(x)}else throw new Error("Unexpected dot segment condition")}return h.join("")}function _t(f){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m=h.iri?d:u,x=[],b=Y[(h.scheme||f.scheme||"").toLowerCase()];if(b&&b.serialize&&b.serialize(f,h),f.host&&!m.IPV6ADDRESS.test(f.host)){if(h.domainHost||b&&b.domainHost)try{f.host=h.iri?W.toUnicode(f.host):W.toASCII(f.host.replace(m.PCT_ENCODED,te).toLowerCase())}catch(le){f.error=f.error||"Host's domain name can not be converted to "+(h.iri?"Unicode":"ASCII")+" via punycode: "+le}}Te(f,m),h.reference!=="suffix"&&f.scheme&&(x.push(f.scheme),x.push(":"));var R=wr(f,h);if(R!==void 0&&(h.reference!=="suffix"&&x.push("//"),x.push(R),f.path&&f.path.charAt(0)!=="/"&&x.push("/")),f.path!==void 0){var re=f.path;!h.absolutePath&&(!b||!b.absolutePath)&&(re=zr(re)),R===void 0&&(re=re.replace(/^\/\//,"/%2F")),x.push(re)}return f.query!==void 0&&(x.push("?"),x.push(f.query)),f.fragment!==void 0&&(x.push("#"),x.push(f.fragment)),x.join("")}function ro(f,h){var m=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},x=arguments[3],b={};return x||(f=Ne(_t(f,m),m),h=Ne(_t(h,m),m)),m=m||{},!m.tolerant&&h.scheme?(b.scheme=h.scheme,b.userinfo=h.userinfo,b.host=h.host,b.port=h.port,b.path=zr(h.path||""),b.query=h.query):(h.userinfo!==void 0||h.host!==void 0||h.port!==void 0?(b.userinfo=h.userinfo,b.host=h.host,b.port=h.port,b.path=zr(h.path||""),b.query=h.query):(h.path?(h.path.charAt(0)==="/"?b.path=zr(h.path):((f.userinfo!==void 0||f.host!==void 0||f.port!==void 0)&&!f.path?b.path="/"+h.path:f.path?b.path=f.path.slice(0,f.path.lastIndexOf("/")+1)+h.path:b.path=h.path,b.path=zr(b.path)),b.query=h.query):(b.path=f.path,h.query!==void 0?b.query=h.query:b.query=f.query),b.userinfo=f.userinfo,b.host=f.host,b.port=f.port),b.scheme=f.scheme),b.fragment=h.fragment,b}function gs(f,h,m){var x=s({scheme:"null"},m);return _t(ro(Ne(f,x),Ne(h,x),x,!0),x)}function no(f,h){return typeof f=="string"?f=_t(Ne(f,h),h):n(f)==="object"&&(f=Ne(_t(f,h),h)),f}function ws(f,h,m){return typeof f=="string"?f=_t(Ne(f,m),m):n(f)==="object"&&(f=_t(f,m)),typeof h=="string"?h=_t(Ne(h,m),m):n(h)==="object"&&(h=_t(h,m)),f===h}function xs(f,h){return f&&f.toString().replace(!h||!h.iri?u.ESCAPE:d.ESCAPE,G)}function Ut(f,h){return f&&f.toString().replace(!h||!h.iri?u.PCT_ENCODED:d.PCT_ENCODED,te)}var Jr={scheme:"http",domainHost:!0,parse:function(h,m){return h.host||(h.error=h.error||"HTTP URIs must have a host."),h},serialize:function(h,m){var x=String(h.scheme).toLowerCase()==="https";return(h.port===(x?443:80)||h.port==="")&&(h.port=void 0),h.path||(h.path="/"),h}},io={scheme:"https",domainHost:Jr.domainHost,parse:Jr.parse,serialize:Jr.serialize};function bs(f){return typeof f.secure=="boolean"?f.secure:String(f.scheme).toLowerCase()==="wss"}var vn={scheme:"ws",domainHost:!0,parse:function(h,m){var x=h;return x.secure=bs(x),x.resourceName=(x.path||"/")+(x.query?"?"+x.query:""),x.path=void 0,x.query=void 0,x},serialize:function(h,m){if((h.port===(bs(h)?443:80)||h.port==="")&&(h.port=void 0),typeof h.secure=="boolean"&&(h.scheme=h.secure?"wss":"ws",h.secure=void 0),h.resourceName){var x=h.resourceName.split("?"),b=a(x,2),R=b[0],re=b[1];h.path=R&&R!=="/"?R:void 0,h.query=re,h.resourceName=void 0}return h.fragment=void 0,h}},vs={scheme:"wss",domainHost:vn.domainHost,parse:vn.parse,serialize:vn.serialize},fa={},Ky=!0,ll="[A-Za-z0-9\\-\\.\\_\\~"+(Ky?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",tr="[0-9A-Fa-f]",_y=t(t("%[EFef]"+tr+"%"+tr+tr+"%"+tr+tr)+"|"+t("%[89A-Fa-f]"+tr+"%"+tr+tr)+"|"+t("%"+tr+tr)),Uy="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",Oy="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",ky=e(Oy,'[\\"\\\\]'),Py="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Cy=new RegExp(ll,"g"),oi=new RegExp(_y,"g"),Ry=new RegExp(e("[^]",Uy,"[\\.]",'[\\"]',ky),"g"),hl=new RegExp(e("[^]",ll,Py),"g"),My=hl;function pa(f){var h=te(f);return h.match(Cy)?h:f}var fl={scheme:"mailto",parse:function(h,m){var x=h,b=x.to=x.path?x.path.split(","):[];if(x.path=void 0,x.query){for(var R=!1,re={},le=x.query.split("&"),ye=0,Me=le.length;ye<Me;++ye){var de=le[ye].split("=");switch(de[0]){case"to":for(var Ke=de[1].split(","),Le=0,Se=Ke.length;Le<Se;++Le)b.push(Ke[Le]);break;case"subject":x.subject=Ut(de[1],m);break;case"body":x.body=Ut(de[1],m);break;default:R=!0,re[Ut(de[0],m)]=Ut(de[1],m);break}}R&&(x.headers=re)}x.query=void 0;for(var he=0,_e=b.length;he<_e;++he){var me=b[he].split("@");if(me[0]=Ut(me[0]),m.unicodeSupport)me[1]=Ut(me[1],m).toLowerCase();else try{me[1]=W.toASCII(Ut(me[1],m).toLowerCase())}catch(En){x.error=x.error||"Email address's domain name can not be converted to ASCII via punycode: "+En}b[he]=me.join("@")}return x},serialize:function(h,m){var x=h,b=o(h.to);if(b){for(var R=0,re=b.length;R<re;++R){var le=String(b[R]),ye=le.lastIndexOf("@"),Me=le.slice(0,ye).replace(oi,pa).replace(oi,i).replace(Ry,G),de=le.slice(ye+1);try{de=m.iri?W.toUnicode(de):W.toASCII(Ut(de,m).toLowerCase())}catch(he){x.error=x.error||"Email address's domain name can not be converted to "+(m.iri?"Unicode":"ASCII")+" via punycode: "+he}b[R]=Me+"@"+de}x.path=b.join(",")}var Ke=h.headers=h.headers||{};h.subject&&(Ke.subject=h.subject),h.body&&(Ke.body=h.body);var Le=[];for(var Se in Ke)Ke[Se]!==fa[Se]&&Le.push(Se.replace(oi,pa).replace(oi,i).replace(hl,G)+"="+Ke[Se].replace(oi,pa).replace(oi,i).replace(My,G));return Le.length&&(x.query=Le.join("&")),x}},Ly=/^([^\:]+)\:(.*)/,pl={scheme:"urn",parse:function(h,m){var x=h.path&&h.path.match(Ly),b=h;if(x){var R=m.scheme||b.scheme||"urn",re=x[1].toLowerCase(),le=x[2],ye=R+":"+(m.nid||re),Me=Y[ye];b.nid=re,b.nss=le,b.path=void 0,Me&&(b=Me.parse(b,m))}else b.error=b.error||"URN can not be parsed.";return b},serialize:function(h,m){var x=m.scheme||h.scheme||"urn",b=h.nid,R=x+":"+(m.nid||b),re=Y[R];re&&(h=re.serialize(h,m));var le=h,ye=h.nss;return le.path=(b||m.nid)+":"+ye,le}},Ny=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,yl={scheme:"urn:uuid",parse:function(h,m){var x=h;return x.uuid=x.nss,x.nss=void 0,!m.tolerant&&(!x.uuid||!x.uuid.match(Ny))&&(x.error=x.error||"UUID is not valid."),x},serialize:function(h,m){var x=h;return x.nss=(h.uuid||"").toLowerCase(),x}};Y[Jr.scheme]=Jr,Y[io.scheme]=io,Y[vn.scheme]=vn,Y[vs.scheme]=vs,Y[fl.scheme]=fl,Y[pl.scheme]=pl,Y[yl.scheme]=yl,r.SCHEMES=Y,r.pctEncChar=G,r.pctDecChars=te,r.parse=Ne,r.removeDotSegments=zr,r.serialize=_t,r.resolveComponents=ro,r.resolve=gs,r.normalize=no,r.equal=ws,r.escapeComponent=xs,r.unescapeComponent=Ut,Object.defineProperty(r,"__esModule",{value:!0})})});var Op=se((Q6,Up)=>{"use strict";Up.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 dl=se((XB,vy)=>{var Zi=1e3,Qi=Zi*60,eo=Qi*60,ii=eo*24,sb=ii*7,cb=ii*365.25;vy.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return ab(r);if(t==="number"&&isFinite(r))return e.long?db(r):ub(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function ab(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*cb;case"weeks":case"week":case"w":return t*sb;case"days":case"day":case"d":return t*ii;case"hours":case"hour":case"hrs":case"hr":case"h":return t*eo;case"minutes":case"minute":case"mins":case"min":case"m":return t*Qi;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 ub(r){var e=Math.abs(r);return e>=ii?Math.round(r/ii)+"d":e>=eo?Math.round(r/eo)+"h":e>=Qi?Math.round(r/Qi)+"m":e>=Zi?Math.round(r/Zi)+"s":r+"ms"}function db(r){var e=Math.abs(r);return e>=ii?la(r,e,ii,"day"):e>=eo?la(r,e,eo,"hour"):e>=Qi?la(r,e,Qi,"minute"):e>=Zi?la(r,e,Zi,"second"):r+" ms"}function la(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var hi=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(hi||{});var Ue={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};var $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[y,w]=l.split("=");d[y]=w}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 Be=$e;var N=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)}},Pt=(p=>(p.InvalidDid="invalidDid",p.MethodNotSupported="methodNotSupported",p.InternalError="internalError",p.InvalidDidDocument="invalidDidDocument",p.InvalidDidDocumentLength="invalidDidDocumentLength",p.InvalidDidUrl="invalidDidUrl",p.InvalidPreviousDidProof="invalidPreviousDidProof",p.InvalidPublicKey="invalidPublicKey",p.InvalidPublicKeyLength="invalidPublicKeyLength",p.InvalidPublicKeyType="invalidPublicKeyType",p.InvalidSignature="invalidSignature",p.NotFound="notFound",p.RepresentationNotSupported="representationNotSupported",p.UnsupportedPublicKeyType="unsupportedPublicKeyType",p))(Pt||{});var je=class r extends Error{constructor(e,t){super(t),this.code=e,this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},ze;(function(r){r.AlgorithmNotSupported="algorithmNotSupported",r.EncodingError="encodingError",r.InvalidJwe="invalidJwe",r.InvalidJwk="invalidJwk",r.OperationNotSupported="operationNotSupported"})(ze||(ze={}));var va=Sn(vl(),1);var Ib=new Uint8Array(0);function El(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 fi(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")}function r0(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(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,S=0,I=p.length;S!==I&&p[S]===0;)S++,g++;for(var E=(I-S)*a+1>>>0,U=new Uint8Array(E);S!==I;){for(var B=p[S],_=0,C=E-1;(B!==0||_<v)&&C!==-1;C--,_++)B+=256*U[C]>>>0,U[C]=B%c>>>0,B=B/c>>>0;if(B!==0)throw new Error("Non-zero carry");v=_,S++}for(var k=E-v;k!==E&&U[k]===0;)k++;for(var Q=u.repeat(g);k<E;++k)Q+=r.charAt(U[k]);return Q}function y(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var v=0,S=0;p[g]===u;)v++,g++;for(var I=(p.length-g)*d+1>>>0,E=new Uint8Array(I);p[g];){var U=t[p.charCodeAt(g)];if(U===255)return;for(var B=0,_=I-1;(U!==0||B<S)&&_!==-1;_--,B++)U+=c*E[_]>>>0,E[_]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");S=B,g++}if(p[g]!==" "){for(var C=I-S;C!==I&&E[C]===0;)C++;for(var k=new Uint8Array(v+(I-C)),Q=v;C!==I;)k[Q++]=E[C++];return k}}}function w(p){var g=y(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:y,decode:w}}var n0=r0,i0=n0,Al=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 Tl(this,e)}},Ta=class{decoders;constructor(e){this.decoders=e}or(e){return Tl(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 Tl(r,e){return new Ta({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Sa=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 Sl({name:r,prefix:e,encode:t,decode:n}){return new Sa(r,e,t,n)}function Ba({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Al(t,r);return Sl({prefix:e,name:r,encode:n,decode:o=>fi(i(o))})}function o0(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 s0(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 Sl({prefix:e,name:r,encode(i){return s0(i,n,t)},decode(i){return o0(i,n,t,r)}})}var lo=st({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),kb=st({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pb=st({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Cb=st({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rb=st({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mb=st({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Lb=st({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nb=st({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ia=st({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var lt=Ba({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hb=Ba({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var jb=st({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zb=st({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nr=st({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Jb=st({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Bl(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function Il(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function pi(r){let t=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=t;return i}var ho=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())})},Dl=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)}},Bs=new TextEncoder,Bn=new TextDecoder,O=class r{constructor(e,t){this.data=e,this.format=t}static arrayBuffer(e){return new r(e,"ArrayBuffer")}static asyncIterable(e){if(!Il(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 nr.baseDecode(this.data).buffer;case"BufferSource":{if(pi(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Bl(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 ho(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 nr.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return nr.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),t=Bs.encode(e);return nr.baseEncode(t)}case"String":{let e=Bs.encode(this.data);return nr.baseEncode(e)}case"Uint8Array":return nr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return ho(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u=[];try{for(var o=!0,s=Dl(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=nr.baseDecode(this.data),t=Bn.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Bn.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return ho(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 Bn.decode(this.data);case"Base64Url":{let e=nr.baseDecode(this.data);return Bn.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Bn.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return ho(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u="";try{for(var o=!0,s=Dl(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+=Bn.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+=Bn.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 nr.baseDecode(this.data);case"BufferSource":{let e=pi(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 Bs.encode(e)}case"String":return Bs.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return ho(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 fo;(function(r){r.Debug="debug",r.Silent="silent"})(fo||(fo={}));var Da=class{constructor(){this.logLevel=fo.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==fo.Silent&&console.info(e)}error(e){this.logLevel!==fo.Silent&&console.error(e)}},c0=new Da;typeof window<"u"&&(window.web5logger=c0);var Er={};wa(Er,{decode:()=>yi,encodeTo:()=>In,encodingLength:()=>Dn});var a0=Ul,Kl=128,u0=127,d0=~u0,l0=Math.pow(2,31);function Ul(r,e,t){e=e||[],t=t||0;for(var n=t;r>=l0;)e[t++]=r&255|Kl,r/=128;for(;r&d0;)e[t++]=r&255|Kl,r>>>=7;return e[t]=r|0,Ul.bytes=t-n+1,e}var h0=Ka,f0=128,_l=127;function Ka(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Ka.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&_l)<<i:(s&_l)*Math.pow(2,i),i+=7}while(s>=f0);return Ka.bytes=o-n,t}var p0=Math.pow(2,7),y0=Math.pow(2,14),m0=Math.pow(2,21),g0=Math.pow(2,28),w0=Math.pow(2,35),x0=Math.pow(2,42),b0=Math.pow(2,49),v0=Math.pow(2,56),E0=Math.pow(2,63),A0=function(r){return r<p0?1:r<y0?2:r<m0?3:r<g0?4:r<w0?5:r<x0?6:r<b0?7:r<v0?8:r<E0?9:10},T0={encode:a0,decode:h0,encodingLength:A0},S0=T0,po=S0;function yi(r,e=0){return[po.decode(r,e),po.decode.bytes]}function In(r,e,t=0){return po.encode(r,e,t),e}function Dn(r){return po.encodingLength(r)}function _a(r,e){let t=e.byteLength,n=Dn(r),i=n+Dn(t),o=new Uint8Array(i+t);return In(r,o,0),In(t,o,n),o.set(e,i),new mi(r,t,e,o)}function Ol(r){let e=fi(r),[t,n]=yi(e),[i,o]=yi(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new mi(t,i,s,e)}function kl(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&El(r.bytes,t.bytes)}}var mi=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function Pl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return I0(t,Oa(r),e??lt.encoder);default:return D0(t,Oa(r),e??lo.encoder)}}var Cl=new WeakMap;function Oa(r){let e=Cl.get(r);if(e==null){let t=new Map;return Cl.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!==yo)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==K0)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=_a(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&&kl(e.multihash,n.multihash)}toString(e){return Pl(this,e)}toJSON(){return{"/":Pl(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??Rl(n,i,o.bytes))}else if(t[_0]===!0){let{version:n,multihash:i,code:o}=t,s=Ol(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!==yo)throw new Error(`Version 0 CID must use dag-pb (code: ${yo}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=Rl(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,yo,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=fi(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 mi(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,y]=yi(e.subarray(t));return t+=y,l},i=n(),o=yo;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]=B0(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 Oa(o).set(n,e),o}};function B0(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 lo.prefix:{let t=e??lo;return[lo.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 I0(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 D0(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 yo=112,K0=18;function Rl(r,e,t){let n=Dn(r),i=n+Dn(e),o=new Uint8Array(i+t.byteLength);return In(r,o,0),In(e,o,n),o.set(t,i),o}var _0=Symbol.for("@ipld/js-cid/CID");var tt=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=Er.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),Er.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=Er.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]=Er.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}}};tt.codeToName=new Map;tt.nameToCode=new Map;tt.registerCodec({code:237,name:"ed25519-pub"});tt.registerCodec({code:4864,name:"ed25519-priv"});tt.registerCodec({code:236,name:"x25519-pub"});tt.registerCodec({code:4866,name:"x25519-priv"});tt.registerCodec({code:231,name:"secp256k1-pub"});tt.registerCodec({code:4865,name:"secp256k1-priv"});function Pa(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&Pa(r[e])})}var lg=Sn(Ru(),1),jn=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 nc=class{constructor(){this.store=new Map}clear(){return jn(this,void 0,void 0,function*(){this.store.clear()})}close(){return jn(this,void 0,void 0,function*(){})}delete(e){return jn(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return jn(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return jn(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return jn(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return jn(this,void 0,void 0,function*(){this.store.set(e,t)})}};var at=class{};var oc={};wa(oc,{bitGet:()=>wg,bitLen:()=>gg,bitMask:()=>Lo,bitSet:()=>xg,bytesToHex:()=>Or,bytesToNumberBE:()=>kr,bytesToNumberLE:()=>Wt,concatBytes:()=>Cr,createHmacDrbg:()=>Nu,ensureBytes:()=>ve,equalBytes:()=>yg,hexToBytes:()=>zn,hexToNumber:()=>Lu,isBytes:()=>Gt,numberToBytesBE:()=>pt,numberToBytesLE:()=>Pr,numberToHexUnpadded:()=>lf,numberToVarBytesBE:()=>pg,utf8ToBytes:()=>mg,validateObject:()=>Lt});var df=BigInt(0),ic=BigInt(1),hg=BigInt(2);function Gt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var fg=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Or(r){if(!Gt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=fg[r[t]];return e}function lf(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Lu(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 af(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 zn(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=af(r.charCodeAt(o)),c=af(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 Lu(Or(r))}function Wt(r){if(!Gt(r))throw new Error("Uint8Array expected");return Lu(Or(Uint8Array.from(r).reverse()))}function pt(r,e){return zn(r.toString(16).padStart(e*2,"0"))}function Pr(r,e){return pt(r,e).reverse()}function pg(r){return zn(lf(r))}function ve(r,e,t){let n;if(typeof e=="string")try{n=zn(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Gt(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 Cr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!Gt(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 yg(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 mg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function gg(r){let e;for(e=0;r>df;r>>=ic,e+=1);return e}function wg(r,e){return r>>BigInt(e)&ic}var xg=(r,e,t)=>r|(t?ic:df)<<BigInt(e),Lo=r=>(hg<<BigInt(r-1))-ic,Mu=r=>new Uint8Array(r),uf=r=>Uint8Array.from(r);function Nu(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=Mu(r),i=Mu(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),u=(l=Mu())=>{i=c(uf([0]),l),n=c(),l.length!==0&&(i=c(uf([1]),l),n=c())},d=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<e;){n=c();let w=n.slice();y.push(w),l+=n.length}return Cr(...y)};return(l,y)=>{s(),u(l);let w;for(;!(w=y(d()));)u();return s(),w}}var bg={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"||Gt(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 Lt(r,e,t={}){let n=(i,o,s)=>{let c=bg[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}function hf(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function vg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function $u(r,...e){if(!vg(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 ff(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");hf(r.outputLen),hf(r.blockLen)}function Ui(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 pf(r,e){$u(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var sc=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function yf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var cc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Yt=(r,e)=>r<<32-e|r>>>e,Eg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Eg)throw new Error("Non little-endian hardware is not supported");function Vu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function No(r){if(typeof r=="string"&&(r=Vu(r)),!yf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function ac(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!yf(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 Oi=class{clone(){return this._cloneInto()}},w1={}.toString;function uc(r){let e=n=>r().update(No(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function $o(r=32){if(sc&&typeof sc.getRandomValues=="function")return sc.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ag(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 ki=class extends Oi{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=cc(this.buffer)}update(e){Ui(this);let{view:t,buffer:n,blockLen:i}=this;e=No(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=cc(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){Ui(this),pf(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;Ag(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=cc(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 Tg=(r,e,t)=>r&e^~r&t,Sg=(r,e,t)=>r&e^r&t^e&t,Bg=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]),on=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),sn=new Uint32Array(64),Hu=class extends ki{constructor(){super(64,32,8,!1),this.A=on[0]|0,this.B=on[1]|0,this.C=on[2]|0,this.D=on[3]|0,this.E=on[4]|0,this.F=on[5]|0,this.G=on[6]|0,this.H=on[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)sn[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=sn[l-15],w=sn[l-2],p=Yt(y,7)^Yt(y,18)^y>>>3,g=Yt(w,17)^Yt(w,19)^w>>>10;sn[l]=g+sn[l-7]+p+sn[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 y=Yt(c,6)^Yt(c,11)^Yt(c,25),w=a+y+Tg(c,u,d)+Bg[l]+sn[l]|0,g=(Yt(n,2)^Yt(n,13)^Yt(n,22))+Sg(n,i,o)|0;a=d,d=u,u=c,c=s+w|0,s=o,o=i,i=n,n=w+g|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(){sn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var dc=uc(()=>new Hu);var Ve=BigInt(0),Ie=BigInt(1),Jn=BigInt(2),Ig=BigInt(3),Fu=BigInt(4),mf=BigInt(5),gf=BigInt(8),Dg=BigInt(9),Kg=BigInt(16);function fe(r,e){let t=r%e;return t>=Ve?t:e+t}function qu(r,e,t){if(t<=Ve||e<Ve)throw new Error("Expected power/modulo > 0");if(t===Ie)return Ve;let n=Ie;for(;e>Ve;)e&Ie&&(n=n*r%t),r=r*r%t,e>>=Ie;return n}function Ee(r,e,t){let n=r;for(;e-- >Ve;)n*=n,n%=t;return n}function lc(r,e){if(r===Ve||e<=Ve)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=fe(r,e),n=e,i=Ve,o=Ie,s=Ie,c=Ve;for(;t!==Ve;){let d=n/t,a=n%t,l=i-s*d,y=o-c*d;n=t,t=a,i=s,o=c,s=l,c=y}if(n!==Ie)throw new Error("invert: does not exist");return fe(i,e)}function _g(r){let e=(r-Ie)/Jn,t,n,i;for(t=r-Ie,n=0;t%Jn===Ve;t/=Jn,n++);for(i=Jn;i<r&&qu(i,e,r)!==r-Ie;i++);if(n===1){let s=(r+Ie)/Fu;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+Ie)/Jn;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),y=c.pow(u,t);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let w=1;for(let g=c.sqr(y);w<d&&!c.eql(g,c.ONE);w++)g=c.sqr(g);let p=c.pow(a,Ie<<BigInt(d-w-1));a=c.sqr(p),l=c.mul(l,p),y=c.mul(y,a),d=w}return l}}function Ug(r){if(r%Fu===Ig){let e=(r+Ie)/Fu;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%gf===mf){let e=(r-mf)/gf;return function(n,i){let o=n.mul(i,Jn),s=n.pow(o,e),c=n.mul(i,s),u=n.mul(n.mul(c,Jn),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%Kg,_g(r)}var wf=(r,e)=>(fe(r,e)&Ie)===Ie,Og=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ju(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Og.reduce((n,i)=>(n[i]="function",n),e);return Lt(r,t)}function kg(r,e,t){if(t<Ve)throw new Error("Expected power > 0");if(t===Ve)return r.ONE;if(t===Ie)return e;let n=r.ONE,i=e;for(;t>Ve;)t&Ie&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ie;return n}function Pg(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 zu(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Pi(r,e,t=!1,n={}){if(r<=Ve)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=zu(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Ug(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Lo(i),ZERO:Ve,ONE:Ie,create:u=>fe(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&Ie)===Ie,neg:u=>fe(-u,r),eql:(u,d)=>u===d,sqr:u=>fe(u*u,r),add:(u,d)=>fe(u+d,r),sub:(u,d)=>fe(u-d,r),mul:(u,d)=>fe(u*d,r),pow:(u,d)=>kg(c,u,d),div:(u,d)=>fe(u*lc(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>lc(u,r),sqrt:n.sqrt||(u=>s(c,u)),invertBatch:u=>Pg(c,u),cmov:(u,d,a)=>a?d:u,toBytes:u=>t?Pr(u,o):pt(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return t?Wt(u):kr(u)}});return Object.freeze(c)}function xf(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 bf(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 Ju(r){let e=bf(r);return e+Math.ceil(e/2)}function vf(r,e,t=!1){let n=r.length,i=bf(e),o=Ju(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?kr(r):Wt(r),c=fe(s,e-Ie)+Ie;return t?Pr(c,i):pt(c,i)}var Rg=BigInt(0),Gu=BigInt(1);function hc(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>Rg;)o&Gu&&(s=s.add(c)),c=c.double(),o>>=Gu;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 y=1;y<c;y++)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),y=2**i,w=BigInt(i);for(let p=0;p<c;p++){let g=p*u,v=Number(s&l);s>>=w,v>u&&(v-=y,s+=Gu);let S=g,I=g+Math.abs(v)-1,E=p%2!==0,U=v<0;v===0?a=a.add(t(E,o[S])):d=d.add(t(U,o[I]))}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 Vo(r){return ju(r.Fp),Lt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...zu(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Mg(r){let e=Vo(r);Lt(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:Lg,hexToBytes:Ng}=oc,Gn={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Gn;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:Lg(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Gn,t=typeof r=="string"?Ng(r):r;if(!Gt(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}=Gn._parseInt(t.subarray(2)),{d:s,l:c}=Gn._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}`}},Rr=BigInt(0),Nt=BigInt(1),k1=BigInt(2),Ef=BigInt(3),P1=BigInt(4);function $g(r){let e=Mg(r),{Fp:t}=e,n=e.toBytes||((p,g,v)=>{let S=g.toAffine();return Cr(Uint8Array.from([4]),t.toBytes(S.x),t.toBytes(S.y))}),i=e.fromBytes||(p=>{let g=p.subarray(1),v=t.fromBytes(g.subarray(0,t.BYTES)),S=t.fromBytes(g.subarray(t.BYTES,2*t.BYTES));return{x:v,y:S}});function o(p){let{a:g,b:v}=e,S=t.sqr(p),I=t.mul(S,p);return t.add(t.add(I,t.mul(p,g)),v)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Rr<p&&p<e.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function u(p){let{allowedPrivateKeyLengths:g,nByteLength:v,wrapPrivateKey:S,n:I}=e;if(g&&typeof p!="bigint"){if(Gt(p)&&(p=Or(p)),typeof p!="string"||!g.includes(p.length))throw new Error("Invalid key");p=p.padStart(v*2,"0")}let E;try{E=typeof p=="bigint"?p:kr(ve("private key",p,v))}catch{throw new Error(`private key must be ${v} bytes, hex or bigint, not ${typeof p}`)}return S&&(E=fe(E,I)),c(E),E}let d=new Map;function a(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(g,v,S){if(this.px=g,this.py=v,this.pz=S,g==null||!t.isValid(g))throw new Error("x required");if(v==null||!t.isValid(v))throw new Error("y required");if(S==null||!t.isValid(S))throw new Error("z required")}static fromAffine(g){let{x:v,y:S}=g||{};if(!g||!t.isValid(v)||!t.isValid(S))throw new Error("invalid affine point");if(g instanceof l)throw new Error("projective point not allowed");let I=E=>t.eql(E,t.ZERO);return I(v)&&I(S)?l.ZERO:new l(v,S,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){let v=t.invertBatch(g.map(S=>S.pz));return g.map((S,I)=>S.toAffine(v[I])).map(l.fromAffine)}static fromHex(g){let v=l.fromAffine(i(ve("pointHex",g)));return v.assertValidity(),v}static fromPrivateKey(g){return l.BASE.multiply(u(g))}_setWindowSize(g){this._WINDOW_SIZE=g,d.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:g,y:v}=this.toAffine();if(!t.isValid(g)||!t.isValid(v))throw new Error("bad point: x or y not FE");let S=t.sqr(v),I=o(g);if(!t.eql(S,I))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(t.isOdd)return!t.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){a(g);let{px:v,py:S,pz:I}=this,{px:E,py:U,pz:B}=g,_=t.eql(t.mul(v,B),t.mul(E,I)),C=t.eql(t.mul(S,B),t.mul(U,I));return _&&C}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:v}=e,S=t.mul(v,Ef),{px:I,py:E,pz:U}=this,B=t.ZERO,_=t.ZERO,C=t.ZERO,k=t.mul(I,I),Q=t.mul(E,E),F=t.mul(U,U),j=t.mul(I,E);return j=t.add(j,j),C=t.mul(I,U),C=t.add(C,C),B=t.mul(g,C),_=t.mul(S,F),_=t.add(B,_),B=t.sub(Q,_),_=t.add(Q,_),_=t.mul(B,_),B=t.mul(j,B),C=t.mul(S,C),F=t.mul(g,F),j=t.sub(k,F),j=t.mul(g,j),j=t.add(j,C),C=t.add(k,k),k=t.add(C,k),k=t.add(k,F),k=t.mul(k,j),_=t.add(_,k),F=t.mul(E,U),F=t.add(F,F),k=t.mul(F,j),B=t.sub(B,k),C=t.mul(F,Q),C=t.add(C,C),C=t.add(C,C),new l(B,_,C)}add(g){a(g);let{px:v,py:S,pz:I}=this,{px:E,py:U,pz:B}=g,_=t.ZERO,C=t.ZERO,k=t.ZERO,Q=e.a,F=t.mul(e.b,Ef),j=t.mul(v,E),ue=t.mul(S,U),ae=t.mul(I,B),Ye=t.add(v,S),D=t.add(E,U);Ye=t.mul(Ye,D),D=t.add(j,ue),Ye=t.sub(Ye,D),D=t.add(v,I);let M=t.add(E,B);return D=t.mul(D,M),M=t.add(j,ae),D=t.sub(D,M),M=t.add(S,I),_=t.add(U,B),M=t.mul(M,_),_=t.add(ue,ae),M=t.sub(M,_),k=t.mul(Q,D),_=t.mul(F,ae),k=t.add(_,k),_=t.sub(ue,k),k=t.add(ue,k),C=t.mul(_,k),ue=t.add(j,j),ue=t.add(ue,j),ae=t.mul(Q,ae),D=t.mul(F,D),ue=t.add(ue,ae),ae=t.sub(j,ae),ae=t.mul(Q,ae),D=t.add(D,ae),j=t.mul(ue,D),C=t.add(C,j),j=t.mul(M,D),_=t.mul(Ye,_),_=t.sub(_,j),j=t.mul(Ye,ue),k=t.mul(M,k),k=t.add(k,j),new l(_,C,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return w.wNAFCached(this,d,g,v=>{let S=t.invertBatch(v.map(I=>I.pz));return v.map((I,E)=>I.toAffine(S[E])).map(l.fromAffine)})}multiplyUnsafe(g){let v=l.ZERO;if(g===Rr)return v;if(c(g),g===Nt)return this;let{endo:S}=e;if(!S)return w.unsafeLadder(this,g);let{k1neg:I,k1:E,k2neg:U,k2:B}=S.splitScalar(g),_=v,C=v,k=this;for(;E>Rr||B>Rr;)E&Nt&&(_=_.add(k)),B&Nt&&(C=C.add(k)),k=k.double(),E>>=Nt,B>>=Nt;return I&&(_=_.negate()),U&&(C=C.negate()),C=new l(t.mul(C.px,S.beta),C.py,C.pz),_.add(C)}multiply(g){c(g);let v=g,S,I,{endo:E}=e;if(E){let{k1neg:U,k1:B,k2neg:_,k2:C}=E.splitScalar(v),{p:k,f:Q}=this.wNAF(B),{p:F,f:j}=this.wNAF(C);k=w.constTimeNegate(U,k),F=w.constTimeNegate(_,F),F=new l(t.mul(F.px,E.beta),F.py,F.pz),S=k.add(F),I=Q.add(j)}else{let{p:U,f:B}=this.wNAF(v);S=U,I=B}return l.normalizeZ([S,I])[0]}multiplyAndAddUnsafe(g,v,S){let I=l.BASE,E=(B,_)=>_===Rr||_===Nt||!B.equals(I)?B.multiplyUnsafe(_):B.multiply(_),U=E(this,v).add(E(g,S));return U.is0()?void 0:U}toAffine(g){let{px:v,py:S,pz:I}=this,E=this.is0();g==null&&(g=E?t.ONE:t.inv(I));let U=t.mul(v,g),B=t.mul(S,g),_=t.mul(I,g);if(E)return{x:t.ZERO,y:t.ZERO};if(!t.eql(_,t.ONE))throw new Error("invZ was invalid");return{x:U,y:B}}isTorsionFree(){let{h:g,isTorsionFree:v}=e;if(g===Nt)return!0;if(v)return v(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:g,clearCofactor:v}=e;return g===Nt?this:v?v(l,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return this.assertValidity(),n(l,this,g)}toHex(g=!0){return Or(this.toRawBytes(g))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let y=e.nBitLength,w=hc(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:o,isWithinCurveOrder:s}}function Vg(r){let e=Vo(r);return Lt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Af(r){let e=Vg(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(D){return Rr<D&&D<t.ORDER}function c(D){return fe(D,n)}function u(D){return lc(D,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:y}=$g({...e,toBytes(D,M,X){let K=M.toAffine(),T=t.toBytes(K.x),P=Cr;return X?P(Uint8Array.from([M.hasEvenY()?2:3]),T):P(Uint8Array.from([4]),T,t.toBytes(K.y))},fromBytes(D){let M=D.length,X=D[0],K=D.subarray(1);if(M===i&&(X===2||X===3)){let T=kr(K);if(!s(T))throw new Error("Point is not on curve");let P=l(T),$=t.sqrt(P),J=($&Nt)===Nt;return(X&1)===1!==J&&($=t.neg($)),{x:T,y:$}}else if(M===o&&X===4){let T=t.fromBytes(K.subarray(0,t.BYTES)),P=t.fromBytes(K.subarray(t.BYTES,2*t.BYTES));return{x:T,y:P}}else throw new Error(`Point of length ${M} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),w=D=>Or(pt(D,e.nByteLength));function p(D){let M=n>>Nt;return D>M}function g(D){return p(D)?c(-D):D}let v=(D,M,X)=>kr(D.slice(M,X));class S{constructor(M,X,K){this.r=M,this.s=X,this.recovery=K,this.assertValidity()}static fromCompact(M){let X=e.nByteLength;return M=ve("compactSignature",M,X*2),new S(v(M,0,X),v(M,X,2*X))}static fromDER(M){let{r:X,s:K}=Gn.toSig(ve("DER",M));return new S(X,K)}assertValidity(){if(!y(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!y(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(M){return new S(this.r,this.s,M)}recoverPublicKey(M){let{r:X,s:K,recovery:T}=this,P=C(ve("msgHash",M));if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");let $=T===2||T===3?X+e.n:X;if($>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let J=T&1?"03":"02",ee=d.fromHex(J+w($)),W=u($),Y=c(-P*W),G=c(K*W),te=d.BASE.multiplyAndAddUnsafe(ee,Y,G);if(!te)throw new Error("point at infinify");return te.assertValidity(),te}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new S(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return zn(this.toDERHex())}toDERHex(){return Gn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return zn(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}let I={isValidPrivateKey(D){try{return a(D),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let D=Ju(e.n);return vf(e.randomBytes(D),e.n)},precompute(D=8,M=d.BASE){return M._setWindowSize(D),M.multiply(BigInt(3)),M}};function E(D,M=!0){return d.fromPrivateKey(D).toRawBytes(M)}function U(D){let M=Gt(D),X=typeof D=="string",K=(M||X)&&D.length;return M?K===i||K===o:X?K===2*i||K===2*o:D instanceof d}function B(D,M,X=!0){if(U(D))throw new Error("first arg must be private key");if(!U(M))throw new Error("second arg must be public key");return d.fromHex(M).multiply(a(D)).toRawBytes(X)}let _=e.bits2int||function(D){let M=kr(D),X=D.length*8-e.nBitLength;return X>0?M>>BigInt(X):M},C=e.bits2int_modN||function(D){return c(_(D))},k=Lo(e.nBitLength);function Q(D){if(typeof D!="bigint")throw new Error("bigint expected");if(!(Rr<=D&&D<k))throw new Error(`bigint expected < 2^${e.nBitLength}`);return pt(D,e.nByteLength)}function F(D,M,X=j){if(["recovered","canonical"].some(be=>be in X))throw new Error("sign() legacy options not supported");let{hash:K,randomBytes:T}=e,{lowS:P,prehash:$,extraEntropy:J}=X;P==null&&(P=!0),D=ve("msgHash",D),$&&(D=ve("prehashed msgHash",K(D)));let ee=C(D),W=a(M),Y=[Q(W),Q(ee)];if(J!=null){let be=J===!0?T(t.BYTES):J;Y.push(ve("extraEntropy",be))}let G=Cr(...Y),te=ee;function Te(be){let ke=_(be);if(!y(ke))return;let Re=u(ke),Pe=d.BASE.multiply(ke).toAffine(),qe=c(Pe.x);if(qe===Rr)return;let Ne=c(Re*c(te+qe*W));if(Ne===Rr)return;let wr=(Pe.x===qe?0:2)|Number(Pe.y&Nt),jr=Ne;return P&&p(Ne)&&(jr=g(Ne),wr^=1),new S(qe,jr,wr)}return{seed:G,k2sig:Te}}let j={lowS:e.lowS,prehash:!1},ue={lowS:e.lowS,prehash:!1};function ae(D,M,X=j){let{seed:K,k2sig:T}=F(D,M,X),P=e;return Nu(P.hash.outputLen,P.nByteLength,P.hmac)(K,T)}d.BASE._setWindowSize(8);function Ye(D,M,X,K=ue){let T=D;if(M=ve("msgHash",M),X=ve("publicKey",X),"strict"in K)throw new Error("options.strict was renamed to lowS");let{lowS:P,prehash:$}=K,J,ee;try{if(typeof T=="string"||Gt(T))try{J=S.fromDER(T)}catch(Pe){if(!(Pe instanceof Gn.Err))throw Pe;J=S.fromCompact(T)}else if(typeof T=="object"&&typeof T.r=="bigint"&&typeof T.s=="bigint"){let{r:Pe,s:qe}=T;J=new S(Pe,qe)}else throw new Error("PARSE");ee=d.fromHex(X)}catch(Pe){if(Pe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&J.hasHighS())return!1;$&&(M=e.hash(M));let{r:W,s:Y}=J,G=C(M),te=u(Y),Te=c(G*te),be=c(W*te),ke=d.BASE.multiplyAndAddUnsafe(ee,Te,be)?.toAffine();return ke?c(ke.x)===W:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:B,sign:ae,verify:Ye,ProjectivePoint:d,Signature:S,utils:I}}var fc=class extends Oi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ff(e);let n=No(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 Ui(this),this.iHash.update(e),this}digestInto(e){Ui(this),$u(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()}},Wu=(r,e,t)=>new fc(r,e).update(t).digest();Wu.create=(r,e)=>new fc(r,e);function Hg(r){return{hash:r,hmac:(e,...t)=>Wu(r,e,ac(...t)),randomBytes:$o}}function pc(r,e){let t=n=>Af({...r,...Hg(n)});return Object.freeze({...t(e),create:t})}var Bf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Tf=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Fg=BigInt(1),Yu=BigInt(2),Sf=(r,e)=>(r+e/Yu)/e;function qg(r){let e=Bf,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=Ee(a,t,e)*a%e,y=Ee(l,t,e)*a%e,w=Ee(y,Yu,e)*d%e,p=Ee(w,i,e)*w%e,g=Ee(p,o,e)*p%e,v=Ee(g,c,e)*g%e,S=Ee(v,u,e)*v%e,I=Ee(S,c,e)*g%e,E=Ee(I,t,e)*a%e,U=Ee(E,s,e)*p%e,B=Ee(U,n,e)*d%e,_=Ee(B,Yu,e);if(!Xu.eql(Xu.sqr(_),r))throw new Error("Cannot find square root");return _}var Xu=Pi(Bf,void 0,void 0,{sqrt:qg}),yt=pc({a:BigInt(0),b:BigInt(7),Fp:Xu,n:Tf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Tf,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Fg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=Sf(o*r,e),u=Sf(-n*r,e),d=fe(r-c*t-u*i,e),a=fe(-c*n-u*o,e),l=d>s,y=a>s;if(l&&(d=e-d),y&&(a=e-a),d>s||a>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:d,k2neg:y,k2:a}}}},dc),z1=BigInt(0);var J1=yt.ProjectivePoint;function jg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Zu(r,...e){if(!jg(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 Qu(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 If(r,e){Zu(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Ci=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var mc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Xt=(r,e)=>r<<32-e|r>>>e;var Q1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function zg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ed(r){return typeof r=="string"&&(r=zg(r)),Zu(r),r}var yc=class{clone(){return this._cloneInto()}},eE={}.toString;function Df(r){let e=n=>r().update(ed(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Kf(r=32){if(Ci&&typeof Ci.getRandomValues=="function")return Ci.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Jg(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 _f=(r,e,t)=>r&e^~r&t,Uf=(r,e,t)=>r&e^r&t^e&t,gc=class extends yc{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=mc(this.buffer)}update(e){Qu(this);let{view:t,buffer:n,blockLen:i}=this;e=ed(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=mc(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){Qu(this),If(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;Jg(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=mc(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 Gg=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]),cn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),an=new Uint32Array(64),td=class extends gc{constructor(){super(64,32,8,!1),this.A=cn[0]|0,this.B=cn[1]|0,this.C=cn[2]|0,this.D=cn[3]|0,this.E=cn[4]|0,this.F=cn[5]|0,this.G=cn[6]|0,this.H=cn[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)an[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=an[l-15],w=an[l-2],p=Xt(y,7)^Xt(y,18)^y>>>3,g=Xt(w,17)^Xt(w,19)^w>>>10;an[l]=g+an[l-7]+p+an[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 y=Xt(c,6)^Xt(c,11)^Xt(c,25),w=a+y+_f(c,u,d)+Gg[l]+an[l]|0,g=(Xt(n,2)^Xt(n,13)^Xt(n,22))+Uf(n,i,o)|0;a=d,d=u,u=c,c=s+w|0,s=o,o=i,i=n,n=w+g|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(){an.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var un=Df(()=>new td);function Of(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 Wg=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())})},Ri=class{static digest(e){return Wg(this,arguments,void 0,function*({data:t}){return un(t)})}};var Yg=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())})},rd="urn:jwk:";function Z(r){return Yg(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}`);Pa(n);let i=Of(n),o=O.string(i).toUint8Array(),s=yield Ri.digest({data:o});return O.uint8Array(s).toBase64Url()})}function ur(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 Mi(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 St(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 Li(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 kf(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 Xe=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())})},Xg=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},Oe=class r{static adjustSignatureToLowS(e){return Xe(this,arguments,void 0,function*({signature:t}){let n=yt.Signature.fromCompact(t);return n.hasHighS()?n.normalizeS().toCompactRawBytes():t})}static bytesToPrivateKey(e){return Xe(this,arguments,void 0,function*({privateKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",d:O.uint8Array(t).toBase64Url(),x:O.uint8Array(n.x).toBase64Url(),y:O.uint8Array(n.y).toBase64Url()};return i.kid=yield Z({jwk:i}),i})}static bytesToPublicKey(e){return Xe(this,arguments,void 0,function*({publicKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",x:O.uint8Array(n.x).toBase64Url(),y:O.uint8Array(n.y).toBase64Url()};return i.kid=yield Z({jwk:i}),i})}static compressPublicKey(e){return Xe(this,arguments,void 0,function*({publicKeyBytes:t}){return yt.ProjectivePoint.fromHex(t).toRawBytes(!0)})}static computePublicKey(e){return Xe(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:O.uint8Array(i.x).toBase64Url(),y:O.uint8Array(i.y).toBase64Url()};return o.kid=yield Z({jwk:o}),o})}static convertDerToCompactSignature(e){return Xe(this,arguments,void 0,function*({derSignature:t}){return yt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Xe(this,arguments,void 0,function*({publicKeyBytes:t}){return yt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Xe(this,void 0,void 0,function*(){let e=yt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Z({jwk:t}),t})}static getPublicKey(e){return Xe(this,arguments,void 0,function*({key:t}){var n;if(!(ur(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=t,o=Xg(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Z({jwk:o})),o})}static privateKeyToBytes(e){return Xe(this,arguments,void 0,function*({privateKey:t}){if(!ur(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return O.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Xe(this,arguments,void 0,function*({publicKey:t}){if(!(Mi(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=O.base64Url(t.x).toUint8Array(),o=O.base64Url(t.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return Xe(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 yt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return Xe(this,arguments,void 0,function*({data:t,key:n}){let i=yield r.privateKeyToBytes({privateKey:n}),o=un(t);return yt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Xe(this,arguments,void 0,function*({privateKeyBytes:t}){return yt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Xe(this,arguments,void 0,function*({publicKeyBytes:t}){try{yt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Xe(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t}),s=un(i);return yt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Xe(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=yt.getPublicKey(t));let n=yt.ProjectivePoint.fromHex(t),i=pt(n.x,32),o=pt(n.y,32);return{x:i,y:o}})}};var Pf=Pi(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),Zg=Pf.create(BigInt("-3")),Qg=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),ew=pc({a:Zg,b:Qg,Fp:Pf,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},dc),Bt=ew;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())})},tw=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},Ce=class r{static adjustSignatureToLowS(e){return Ze(this,arguments,void 0,function*({signature:t}){let n=Bt.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:"P-256",d:O.uint8Array(t).toBase64Url(),x:O.uint8Array(n.x).toBase64Url(),y:O.uint8Array(n.y).toBase64Url()};return i.kid=yield Z({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:"P-256",x:O.uint8Array(n.x).toBase64Url(),y:O.uint8Array(n.y).toBase64Url()};return i.kid=yield Z({jwk:i}),i})}static compressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return Bt.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:"P-256",x:O.uint8Array(i.x).toBase64Url(),y:O.uint8Array(i.y).toBase64Url()};return o.kid=yield Z({jwk:o}),o})}static convertDerToCompactSignature(e){return Ze(this,arguments,void 0,function*({derSignature:t}){return Bt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return Bt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Ze(this,void 0,void 0,function*(){let e=Bt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Z({jwk:t}),t})}static getPublicKey(e){return Ze(this,arguments,void 0,function*({key:t}){var n;if(!(ur(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=t,o=tw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Z({jwk:o})),o})}static privateKeyToBytes(e){return Ze(this,arguments,void 0,function*({privateKey:t}){if(!ur(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return O.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Ze(this,arguments,void 0,function*({publicKey:t}){if(!(Mi(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=O.base64Url(t.x).toUint8Array(),o=O.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("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 Bt.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=un(t);return Bt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ze(this,arguments,void 0,function*({privateKeyBytes:t}){return Bt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){try{Bt.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=un(i);return Bt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Ze(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=Bt.getPublicKey(t));let n=Bt.ProjectivePoint.fromHex(t),i=pt(n.x,32),o=pt(n.y,32);return{x:i,y:o}})}};var Mr=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())})},Ho=class extends at{bytesToPrivateKey(e){return Mr(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Oe.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Ce.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}bytesToPublicKey(e){return Mr(this,arguments,void 0,function*({algorithm:t,publicKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Oe.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Ce.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return Mr(this,arguments,void 0,function*({key:t}){if(!ur(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Oe.computePublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Ce.computePublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return Mr(this,arguments,void 0,function*({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let n=yield Oe.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield Ce.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return Mr(this,arguments,void 0,function*({key:t}){if(!ur(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Oe.getPublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Ce.getPublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return Mr(this,arguments,void 0,function*({key:t,data:n}){if(!ur(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return yield Oe.sign({key:t,data:n});case"P-256":return yield Ce.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return Mr(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!Mi(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return yield Oe.verify({key:t,signature:n,data:i});case"P-256":return yield Ce.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return Mr(this,arguments,void 0,function*({privateKey:t}){switch(t.crv){case"secp256k1":return yield Oe.privateKeyToBytes({privateKey:t});case"P-256":return yield Ce.privateKeyToBytes({privateKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}publicKeyToBytes(e){return Mr(this,arguments,void 0,function*({publicKey:t}){switch(t.crv){case"secp256k1":return yield Oe.publicKeyToBytes({publicKey:t});case"P-256":return yield Ce.publicKeyToBytes({publicKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var wc=BigInt(4294967295),nd=BigInt(32);function Cf(r,e=!1){return e?{h:Number(r&wc),l:Number(r>>nd&wc)}:{h:Number(r>>nd&wc)|0,l:Number(r&wc)|0}}function rw(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}=Cf(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var nw=(r,e)=>BigInt(r>>>0)<<nd|BigInt(e>>>0),iw=(r,e,t)=>r>>>t,ow=(r,e,t)=>r<<32-t|e>>>t,sw=(r,e,t)=>r>>>t|e<<32-t,cw=(r,e,t)=>r<<32-t|e>>>t,aw=(r,e,t)=>r<<64-t|e>>>t-32,uw=(r,e,t)=>r>>>t-32|e<<64-t,dw=(r,e)=>e,lw=(r,e)=>r,hw=(r,e,t)=>r<<t|e>>>32-t,fw=(r,e,t)=>e<<t|r>>>32-t,pw=(r,e,t)=>e<<t-32|r>>>64-t,yw=(r,e,t)=>r<<t-32|e>>>64-t;function mw(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var gw=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ww=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,xw=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),bw=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,vw=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),Ew=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var Aw={fromBig:Cf,split:rw,toBig:nw,shrSH:iw,shrSL:ow,rotrSH:sw,rotrSL:cw,rotrBH:aw,rotrBL:uw,rotr32H:dw,rotr32L:lw,rotlSH:hw,rotlSL:fw,rotlBH:pw,rotlBL:yw,add:mw,add3L:gw,add3H:ww,add4L:xw,add4H:bw,add5H:Ew,add5L:vw},ne=Aw;var[Tw,Sw]=ne.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))),dn=new Uint32Array(80),ln=new Uint32Array(80),id=class extends ki{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:y,Gh:w,Gl:p,Hh:g,Hl:v}=this;return[e,t,n,i,o,s,c,u,d,a,l,y,w,p,g,v]}set(e,t,n,i,o,s,c,u,d,a,l,y,w,p,g,v){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=y|0,this.Gh=w|0,this.Gl=p|0,this.Hh=g|0,this.Hl=v|0}process(e,t){for(let E=0;E<16;E++,t+=4)dn[E]=e.getUint32(t),ln[E]=e.getUint32(t+=4);for(let E=16;E<80;E++){let U=dn[E-15]|0,B=ln[E-15]|0,_=ne.rotrSH(U,B,1)^ne.rotrSH(U,B,8)^ne.shrSH(U,B,7),C=ne.rotrSL(U,B,1)^ne.rotrSL(U,B,8)^ne.shrSL(U,B,7),k=dn[E-2]|0,Q=ln[E-2]|0,F=ne.rotrSH(k,Q,19)^ne.rotrBH(k,Q,61)^ne.shrSH(k,Q,6),j=ne.rotrSL(k,Q,19)^ne.rotrBL(k,Q,61)^ne.shrSL(k,Q,6),ue=ne.add4L(C,j,ln[E-7],ln[E-16]),ae=ne.add4H(ue,_,F,dn[E-7],dn[E-16]);dn[E]=ae|0,ln[E]=ue|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:u,Dh:d,Dl:a,Eh:l,El:y,Fh:w,Fl:p,Gh:g,Gl:v,Hh:S,Hl:I}=this;for(let E=0;E<80;E++){let U=ne.rotrSH(l,y,14)^ne.rotrSH(l,y,18)^ne.rotrBH(l,y,41),B=ne.rotrSL(l,y,14)^ne.rotrSL(l,y,18)^ne.rotrBL(l,y,41),_=l&w^~l&g,C=y&p^~y&v,k=ne.add5L(I,B,C,Sw[E],ln[E]),Q=ne.add5H(k,S,U,_,Tw[E],dn[E]),F=k|0,j=ne.rotrSH(n,i,28)^ne.rotrBH(n,i,34)^ne.rotrBH(n,i,39),ue=ne.rotrSL(n,i,28)^ne.rotrBL(n,i,34)^ne.rotrBL(n,i,39),ae=n&o^n&c^o&c,Ye=i&s^i&u^s&u;S=g|0,I=v|0,g=w|0,v=p|0,w=l|0,p=y|0,{h:l,l:y}=ne.add(d|0,a|0,Q|0,F|0),d=c|0,a=u|0,c=o|0,u=s|0,o=n|0,s=i|0;let D=ne.add3L(F,ue,Ye);n=ne.add3H(D,Q,j,ae),i=D|0}({h:n,l:i}=ne.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=ne.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:u}=ne.add(this.Ch|0,this.Cl|0,c|0,u|0),{h:d,l:a}=ne.add(this.Dh|0,this.Dl|0,d|0,a|0),{h:l,l:y}=ne.add(this.Eh|0,this.El|0,l|0,y|0),{h:w,l:p}=ne.add(this.Fh|0,this.Fl|0,w|0,p|0),{h:g,l:v}=ne.add(this.Gh|0,this.Gl|0,g|0,v|0),{h:S,l:I}=ne.add(this.Hh|0,this.Hl|0,S|0,I|0),this.set(n,i,o,s,c,u,d,a,l,y,w,p,g,v,S,I)}roundClean(){dn.fill(0),ln.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 od=uc(()=>new id);var Zt=BigInt(0),It=BigInt(1),xc=BigInt(2),Bw=BigInt(8),Iw={zip215:!0};function Dw(r){let e=Vo(r);return Lt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function bc(r){let e=Dw(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:u}=e,d=xc<<BigInt(c*8)-It,a=t.create,l=e.uvRatio||((K,T)=>{try{return{isValid:!0,value:t.sqrt(K*t.inv(T))}}catch{return{isValid:!1,value:Zt}}}),y=e.adjustScalarBytes||(K=>K),w=e.domain||((K,T,P)=>{if(T.length||P)throw new Error("Contexts/pre-hash are not supported");return K}),p=K=>typeof K=="bigint"&&Zt<K,g=(K,T)=>p(K)&&p(T)&&K<T,v=K=>K===Zt||g(K,d);function S(K,T){if(g(K,T))return K;throw new Error(`Expected valid scalar < ${T}, got ${typeof K} ${K}`)}function I(K){return K===Zt?K:S(K,n)}let E=new Map;function U(K){if(!(K instanceof B))throw new Error("ExtendedPoint expected")}class B{constructor(T,P,$,J){if(this.ex=T,this.ey=P,this.ez=$,this.et=J,!v(T))throw new Error("x required");if(!v(P))throw new Error("y required");if(!v($))throw new Error("z required");if(!v(J))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(T){if(T instanceof B)throw new Error("extended point not allowed");let{x:P,y:$}=T||{};if(!v(P)||!v($))throw new Error("invalid affine point");return new B(P,$,It,a(P*$))}static normalizeZ(T){let P=t.invertBatch(T.map($=>$.ez));return T.map(($,J)=>$.toAffine(P[J])).map(B.fromAffine)}_setWindowSize(T){this._WINDOW_SIZE=T,E.delete(this)}assertValidity(){let{a:T,d:P}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:$,ey:J,ez:ee,et:W}=this,Y=a($*$),G=a(J*J),te=a(ee*ee),Te=a(te*te),be=a(Y*T),ke=a(te*a(be+G)),Re=a(Te+a(P*a(Y*G)));if(ke!==Re)throw new Error("bad point: equation left != right (1)");let Pe=a($*J),qe=a(ee*W);if(Pe!==qe)throw new Error("bad point: equation left != right (2)")}equals(T){U(T);let{ex:P,ey:$,ez:J}=this,{ex:ee,ey:W,ez:Y}=T,G=a(P*Y),te=a(ee*J),Te=a($*Y),be=a(W*J);return G===te&&Te===be}is0(){return this.equals(B.ZERO)}negate(){return new B(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:T}=e,{ex:P,ey:$,ez:J}=this,ee=a(P*P),W=a($*$),Y=a(xc*a(J*J)),G=a(T*ee),te=P+$,Te=a(a(te*te)-ee-W),be=G+W,ke=be-Y,Re=G-W,Pe=a(Te*ke),qe=a(be*Re),Ne=a(Te*Re),wr=a(ke*be);return new B(Pe,qe,wr,Ne)}add(T){U(T);let{a:P,d:$}=e,{ex:J,ey:ee,ez:W,et:Y}=this,{ex:G,ey:te,ez:Te,et:be}=T;if(P===BigInt(-1)){let ro=a((ee-J)*(te+G)),gs=a((ee+J)*(te-G)),no=a(gs-ro);if(no===Zt)return this.double();let ws=a(W*xc*be),xs=a(Y*xc*Te),Ut=xs+ws,Jr=gs+ro,io=xs-ws,bs=a(Ut*no),vn=a(Jr*io),vs=a(Ut*io),fa=a(no*Jr);return new B(bs,vn,fa,vs)}let ke=a(J*G),Re=a(ee*te),Pe=a(Y*$*be),qe=a(W*Te),Ne=a((J+ee)*(G+te)-ke-Re),wr=qe-Pe,jr=qe+Pe,to=a(Re-P*ke),ms=a(Ne*wr),ha=a(jr*to),zr=a(Ne*to),_t=a(wr*jr);return new B(ms,ha,_t,zr)}subtract(T){return this.add(T.negate())}wNAF(T){return k.wNAFCached(this,E,T,B.normalizeZ)}multiply(T){let{p:P,f:$}=this.wNAF(S(T,n));return B.normalizeZ([P,$])[0]}multiplyUnsafe(T){let P=I(T);return P===Zt?C:this.equals(C)||P===It?this:this.equals(_)?this.wNAF(P).p:k.unsafeLadder(this,P)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return k.unsafeLadder(this,n).is0()}toAffine(T){let{ex:P,ey:$,ez:J}=this,ee=this.is0();T==null&&(T=ee?Bw:t.inv(J));let W=a(P*T),Y=a($*T),G=a(J*T);if(ee)return{x:Zt,y:It};if(G!==It)throw new Error("invZ was invalid");return{x:W,y:Y}}clearCofactor(){let{h:T}=e;return T===It?this:this.multiplyUnsafe(T)}static fromHex(T,P=!1){let{d:$,a:J}=e,ee=t.BYTES;T=ve("pointHex",T,ee);let W=T.slice(),Y=T[ee-1];W[ee-1]=Y&-129;let G=Wt(W);G===Zt||(P?S(G,d):S(G,t.ORDER));let te=a(G*G),Te=a(te-It),be=a($*te-J),{isValid:ke,value:Re}=l(Te,be);if(!ke)throw new Error("Point.fromHex: invalid y coordinate");let Pe=(Re&It)===It,qe=(Y&128)!==0;if(!P&&Re===Zt&&qe)throw new Error("Point.fromHex: x=0 and x_0=1");return qe!==Pe&&(Re=a(-Re)),B.fromAffine({x:Re,y:G})}static fromPrivateKey(T){return j(T).point}toRawBytes(){let{x:T,y:P}=this.toAffine(),$=Pr(P,t.BYTES);return $[$.length-1]|=T&It?128:0,$}toHex(){return Or(this.toRawBytes())}}B.BASE=new B(e.Gx,e.Gy,It,a(e.Gx*e.Gy)),B.ZERO=new B(Zt,It,It,Zt);let{BASE:_,ZERO:C}=B,k=hc(B,c*8);function Q(K){return fe(K,n)}function F(K){return Q(Wt(K))}function j(K){let T=c;K=ve("private key",K,T);let P=ve("hashed private key",o(K),2*T),$=y(P.slice(0,T)),J=P.slice(T,2*T),ee=F($),W=_.multiply(ee),Y=W.toRawBytes();return{head:$,prefix:J,scalar:ee,point:W,pointBytes:Y}}function ue(K){return j(K).pointBytes}function ae(K=new Uint8Array,...T){let P=Cr(...T);return F(o(w(P,ve("context",K),!!i)))}function Ye(K,T,P={}){K=ve("message",K),i&&(K=i(K));let{prefix:$,scalar:J,pointBytes:ee}=j(T),W=ae(P.context,$,K),Y=_.multiply(W).toRawBytes(),G=ae(P.context,Y,ee,K),te=Q(W+G*J);I(te);let Te=Cr(Y,Pr(te,t.BYTES));return ve("result",Te,c*2)}let D=Iw;function M(K,T,P,$=D){let{context:J,zip215:ee}=$,W=t.BYTES;K=ve("signature",K,2*W),T=ve("message",T),i&&(T=i(T));let Y=Wt(K.slice(W,2*W)),G,te,Te;try{G=B.fromHex(P,ee),te=B.fromHex(K.slice(0,W),ee),Te=_.multiplyUnsafe(Y)}catch{return!1}if(!ee&&G.isSmallOrder())return!1;let be=ae(J,te.toRawBytes(),G.toRawBytes(),T);return te.add(G.multiplyUnsafe(be)).subtract(Te).clearCofactor().equals(B.ZERO)}return _._setWindowSize(8),{CURVE:e,getPublicKey:ue,sign:Ye,verify:M,ExtendedPoint:B,utils:{getExtendedPublicKey:j,randomPrivateKey:()=>s(t.BYTES),precompute(K=8,T=B.BASE){return T._setWindowSize(K),T.multiply(BigInt(3)),T}}}}var Fo=BigInt(0),sd=BigInt(1);function Kw(r){return Lt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Rf(r){let e=Kw(r),{P:t}=e,n=E=>fe(E,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(E=>E),u=e.powPminus2||(E=>qu(E,t-BigInt(2),t));function d(E,U,B){let _=n(E*(U-B));return U=n(U-_),B=n(B+_),[U,B]}function a(E){if(typeof E=="bigint"&&Fo<=E&&E<t)return E;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function y(E,U){let B=a(E),_=a(U),C=B,k=sd,Q=Fo,F=B,j=sd,ue=Fo,ae;for(let D=BigInt(i-1);D>=Fo;D--){let M=_>>D&sd;ue^=M,ae=d(ue,k,F),k=ae[0],F=ae[1],ae=d(ue,Q,j),Q=ae[0],j=ae[1],ue=M;let X=k+Q,K=n(X*X),T=k-Q,P=n(T*T),$=K-P,J=F+j,ee=F-j,W=n(ee*X),Y=n(J*T),G=W+Y,te=W-Y;F=n(G*G),j=n(C*n(te*te)),k=n(K*P),Q=n($*(K+n(l*$)))}ae=d(ue,k,F),k=ae[0],F=ae[1],ae=d(ue,Q,j),Q=ae[0],j=ae[1];let Ye=u(Q);return n(k*Ye)}function w(E){return Pr(n(E),o)}function p(E){let U=ve("u coordinate",E,o);return s===32&&(U[31]&=127),Wt(U)}function g(E){let U=ve("scalar",E),B=U.length;if(B!==o&&B!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${B}`);return Wt(c(U))}function v(E,U){let B=p(U),_=g(E),C=y(B,_);if(C===Fo)throw new Error("Invalid private or public key received");return w(C)}let S=w(e.Gu);function I(E){return v(E,S)}return{scalarMult:v,scalarMultBase:I,getSharedSecret:(E,U)=>v(E,U),getPublicKey:E=>I(E),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:S}}var qo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Mf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),e2=BigInt(0),_w=BigInt(1),cd=BigInt(2),Uw=BigInt(5),Lf=BigInt(10),Ow=BigInt(20),kw=BigInt(40),Nf=BigInt(80);function $f(r){let e=qo,n=r*r%e*r%e,i=Ee(n,cd,e)*n%e,o=Ee(i,_w,e)*r%e,s=Ee(o,Uw,e)*o%e,c=Ee(s,Lf,e)*s%e,u=Ee(c,Ow,e)*c%e,d=Ee(u,kw,e)*u%e,a=Ee(d,Nf,e)*d%e,l=Ee(a,Nf,e)*d%e,y=Ee(l,Lf,e)*s%e;return{pow_p_5_8:Ee(y,cd,e)*r%e,b2:n}}function Vf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Pw(r,e){let t=qo,n=fe(e*e*e,t),i=fe(n*n*e,t),o=$f(r*i).pow_p_5_8,s=fe(r*n*o,t),c=fe(e*s*s,t),u=s,d=fe(s*Mf,t),a=c===r,l=c===fe(-r,t),y=c===fe(-r*Mf,t);return a&&(s=u),(l||y)&&(s=d),wf(s,t)&&(s=fe(-s,t)),{isValid:a||l,value:s}}var $t=Pi(qo,void 0,!0),jo={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:$t,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:od,randomBytes:$o,adjustScalarBytes:Vf,uvRatio:Pw},hn=bc(jo);function Hf(r,e,t){if(e.length>255)throw new Error("Context is too big");return ac(Vu("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var t2=bc({...jo,domain:Hf}),r2=bc({...jo,domain:Hf,prehash:od}),Wn=Rf({P:qo,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=qo,{pow_p_5_8:t,b2:n}=$f(r);return fe(Ee(t,BigInt(3),e)*n,e)},adjustScalarBytes:Vf,randomBytes:$o});function Ff(r){let{y:e}=hn.ExtendedPoint.fromHex(r),t=BigInt(1);return $t.toBytes($t.create((t+e)*$t.inv(t-e)))}function qf(r){let e=jo.hash(r.subarray(0,32));return jo.adjustScalarBytes(e).subarray(0,32)}var Cw=($t.ORDER+BigInt(3))/BigInt(8),n2=$t.pow(cd,Cw),i2=$t.sqrt($t.neg($t.ONE)),o2=($t.ORDER-BigInt(5))/BigInt(8),s2=BigInt(486662);var c2=xf($t,$t.neg(BigInt(486664)));var a2=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),u2=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),d2=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),l2=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var h2=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Vt=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())})},Rw=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},De=class r{static bytesToPrivateKey(e){return Vt(this,arguments,void 0,function*({privateKeyBytes:t}){let n=hn.getPublicKey(t),i={crv:"Ed25519",d:O.uint8Array(t).toBase64Url(),kty:"OKP",x:O.uint8Array(n).toBase64Url()};return i.kid=yield Z({jwk:i}),i})}static bytesToPublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"Ed25519",x:O.uint8Array(t).toBase64Url()};return n.kid=yield Z({jwk:n}),n})}static computePublicKey(e){return Vt(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=hn.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:O.uint8Array(i).toBase64Url()};return o.kid=yield Z({jwk:o}),o})}static convertPrivateKeyToX25519(e){return Vt(this,arguments,void 0,function*({privateKey:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=qf(n),o=Wn.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:O.uint8Array(i).toBase64Url(),x:O.uint8Array(o).toBase64Url()};return s.kid=yield Z({jwk:s}),s})}static convertPublicKeyToX25519(e){return Vt(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=Ff(n),s={kty:"OKP",crv:"X25519",x:O.uint8Array(o).toBase64Url()};return s.kid=yield Z({jwk:s}),s})}static generateKey(){return Vt(this,void 0,void 0,function*(){let e=hn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Z({jwk:t}),t})}static getPublicKey(e){return Vt(this,arguments,void 0,function*({key:t}){var n;if(!(St(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=t,o=Rw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Z({jwk:o})),o})}static privateKeyToBytes(e){return Vt(this,arguments,void 0,function*({privateKey:t}){if(!St(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return O.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Vt(this,arguments,void 0,function*({publicKey:t}){if(!Li(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return O.base64Url(t.x).toUint8Array()})}static sign(e){return Vt(this,arguments,void 0,function*({key:t,data:n}){let i=yield r.privateKeyToBytes({privateKey:t});return hn.sign(n,i)})}static validatePublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:t}){try{hn.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return Vt(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t});return hn.verify(n,i,o)})}};var Lr=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())})},vc=class extends at{bytesToPrivateKey(e){return Lr(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"Ed25519":{let i=yield De.bytesToPrivateKey({privateKeyBytes:n});return i.alg="EdDSA",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}bytesToPublicKey(e){return Lr(this,arguments,void 0,function*({algorithm:t,publicKeyBytes:n}){switch(t){case"Ed25519":{let i=yield De.bytesToPublicKey({publicKeyBytes:n});return i.alg="EdDSA",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return Lr(this,arguments,void 0,function*({key:t}){if(!St(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield De.computePublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return Lr(this,arguments,void 0,function*({algorithm:t}){switch(t){case"Ed25519":{let n=yield De.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return Lr(this,arguments,void 0,function*({key:t}){if(!St(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield De.getPublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return Lr(this,arguments,void 0,function*({key:t,data:n}){if(!St(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return yield De.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return Lr(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!Li(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return yield De.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return Lr(this,arguments,void 0,function*({privateKey:t}){switch(t.crv){case"Ed25519":return yield De.privateKeyToBytes({privateKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}publicKeyToBytes(e){return Lr(this,arguments,void 0,function*({publicKey:t}){switch(t.crv){case"Ed25519":return yield De.publicKeyToBytes({publicKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var Mw=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())})},Ec=class extends at{digest(e){return Mw(this,arguments,void 0,function*({algorithm:t,data:n}){switch(t){case"SHA-256":return yield Ri.digest({data:n})}})}};var fn=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())})},Lw=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},dr=class r{static bytesToPrivateKey(e){return fn(this,arguments,void 0,function*({privateKeyBytes:t}){let n=Wn.getPublicKey(t),i={kty:"OKP",crv:"X25519",d:O.uint8Array(t).toBase64Url(),x:O.uint8Array(n).toBase64Url()};return i.kid=yield Z({jwk:i}),i})}static bytesToPublicKey(e){return fn(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"X25519",x:O.uint8Array(t).toBase64Url()};return n.kid=yield Z({jwk:n}),n})}static computePublicKey(e){return fn(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=Wn.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:O.uint8Array(i).toBase64Url()};return o.kid=yield Z({jwk:o}),o})}static generateKey(){return fn(this,void 0,void 0,function*(){let e=Wn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Z({jwk:t}),t})}static getPublicKey(e){return fn(this,arguments,void 0,function*({key:t}){var n;if(!(St(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=t,o=Lw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Z({jwk:o})),o})}static privateKeyToBytes(e){return fn(this,arguments,void 0,function*({privateKey:t}){if(!St(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return O.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return fn(this,arguments,void 0,function*({publicKey:t}){if(!Li(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return O.base64Url(t.x).toUint8Array()})}static sharedSecret(e){return fn(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 Wn.getSharedSecret(i,o)})}};var zo=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())})},Ac=class extends at{bytesToPrivateKey(e){return zo(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"X25519":return dr.bytesToPrivateKey({privateKeyBytes:n});default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return zo(this,arguments,void 0,function*({key:t}){if(!St(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return dr.computePublicKey({key:t});default:throw new je(ze.AlgorithmNotSupported,`Unsupported curve: ${t.crv}`)}})}generateKey(e){return zo(this,arguments,void 0,function*({algorithm:t}){switch(t){case"X25519":return dr.generateKey();default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}getPublicKey(e){return zo(this,arguments,void 0,function*({key:t}){if(!St(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return dr.getPublicKey({key:t});default:throw new je(ze.AlgorithmNotSupported,`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return zo(this,arguments,void 0,function*({privateKey:t}){return dr.privateKeyToBytes({privateKey:t})})}};var Nr=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())})},ad={Ed25519:{implementation:vc,names:["Ed25519"]},secp256k1:{implementation:Ho,names:["ES256K","secp256k1"]},secp256r1:{implementation:Ho,names:["ES256","secp256r1"]},"SHA-256":{implementation:Ec,names:["SHA-256"]},X25519:{implementation:Ac,names:["X25519"]}},it=class{constructor(e){var t;this._algorithmInstances=new Map,this._keyStore=(t=e?.keyStore)!==null&&t!==void 0?t:new nc}digest(e){return Nr(this,arguments,void 0,function*({algorithm:t,data:n}){return yield this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:n})})}exportKey(e){return Nr(this,arguments,void 0,function*({keyUri:t}){return yield this.getPrivateKey({keyUri:t})})}generateKey(e){return Nr(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=`${rd}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return Nr(this,arguments,void 0,function*({key:t}){let n=yield Z({jwk:t});return`${rd}${n}`})}getPublicKey(e){return Nr(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 Nr(this,arguments,void 0,function*({key:t}){var n;if(!kf(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 Z({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return Nr(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 Nr(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=ad[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 ad){let o=ad[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 Nr(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 Tc=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 Kf(e)}static randomUuid(){return Ci.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 Jf={};wa(Jf,{extractDidFragment:()=>ut,getServices:()=>Nw,getVerificationMethodByKey:()=>$w,getVerificationMethodTypes:()=>ud,getVerificationMethods:()=>Jo,getVerificationRelationshipsById:()=>dd,isDidService:()=>jf,isDidVerificationMethod:()=>Bc,isDwnDidService:()=>Vw,isPortableDid:()=>zf,keyBytesToMultibaseId:()=>ld,multibaseIdToKeyBytes:()=>hd});function ut(r){if(typeof r=="string"&&r.length!==0)return r.split("#").pop()}function Nw({didDocument:r,id:e,type:t}){return r?.service?.filter(n=>!(e&&n.id!==e||t&&n.type!==t))??[]}async function $w({didDocument:r,publicKeyJwk:e,publicKeyMultibase:t}){let n=Jo({didDocument:r});for(let i of n)if(e&&i.publicKeyJwk){if(await Z({jwk:e})===await Z({jwk:i.publicKeyJwk}))return i}else if(t&&i.publicKeyMultibase&&t===i.publicKeyMultibase)return i;return null}function Jo({didDocument:r}){if(!r)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...r.verificationMethod?.filter(Bc)??[]),Object.keys(hi).forEach(t=>{e.push(...r[t]?.filter(Bc)??[])}),e}function ud({didDocument:r}){let t=Jo({didDocument:r}).map(n=>n.type);return[...new Set(t)]}function dd({didDocument:r,methodId:e}){let t=[];return Object.keys(hi).forEach(n=>{if(Array.isArray(r[n])){let i=r[n],o=ut(e);i.some(c=>{let u=ut(c)===o,d=Bc(c)&&ut(c.id)===o;return u||d})&&t.push(n)}}),t}function jf(r){return!r||typeof r!="object"||r===null?!1:"id"in r&&"type"in r&&"serviceEndpoint"in r}function Vw(r){if(!jf(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 Bc(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 zf(r){return!(!r||typeof r!="object"||r===null)&&"uri"in r&&"document"in r&&"metadata"in r&&(!("keyManager"in r)||r.keyManager===void 0)}function ld({keyBytes:r,multicodecCode:e,multicodecName:t}){let n=tt.addPrefix({code:e,data:r,name:t}),i=O.uint8Array(n).toBase58Btc();return O.base58Btc(i).toMultibase()}function hd({multibaseKeyId:r}){try{let e=O.multibase(r).toBase58Btc(),t=O.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=tt.removePrefix({prefixedData:t});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new N("invalidDid",`Invalid multibase identifier: ${r}`)}}var mt=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=>ut(c.id)===(ut(e?.methodId)??ut(this.document.assertionMethod?.[0])));if(!(t&&t.publicKeyJwk))throw new N("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:Tc.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 it}){let n=Jo({didDocument:e.document});if(n.length===0)throw new N("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 Ht=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 fd=(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))(fd||{}),Ic=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(Ic||{}),pd=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(pd||{});var yd="0123456789abcdef",Wf=[],Gf=[];for(let r=0;r<256;r++)Wf[r]=yd[r>>4&15]+yd[r&15],r<16&&(r<10?Gf[48+r]=r:Gf[87+r]=r);var md=r=>{let e=r.length,t="",n=0;for(;n<e;)t+=Wf[r[n++]];return t};var Yf=(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 Xf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Hw=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Go=0;Go<Xf.length;Go++)Hw[Xf.charCodeAt(Go)]=Go;var Go;var Fw=new TextDecoder,gd=(r,e)=>e?new TextDecoder(e).decode(r):Fw.decode(r),qw=new TextEncoder,Ft=r=>qw.encode(r);var Zf=typeof window<"u"?window:self,Qf=Zf.crypto||Zf.msCrypto||{},KT=Qf.subtle||Qf.webkitSubtle;function Ni(r){let e=r<0?1:0;return r=Math.abs(Number(r||1)),Math.floor(Math.log10(r))+1+e}function Dc(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 pe(r,e,t){let n=[],i=null;return pe._encode(n,r),i=Yf(n),pe.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,t),e):i}pe.bytes=-1;pe._floatConversionDetected=!1;pe._encode=function(r,e){if(e!=null)switch(Dc(e)){case"object":pe.dict(r,e);break;case"map":pe.dictMap(r,e);break;case"array":pe.list(r,e);break;case"set":pe.listSet(r,e);break;case"string":pe.string(r,e);break;case"number":pe.number(r,e);break;case"boolean":pe.number(r,e);break;case"arraybufferview":pe.buffer(r,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":pe.buffer(r,new Uint8Array(e));break}};var Kc=new Uint8Array([101]),ep=new Uint8Array([100]),tp=new Uint8Array([108]);pe.buffer=function(r,e){r.push(Ft(e.length+":"),e)};pe.string=function(r,e){r.push(Ft(Ft(e).byteLength+":"+e))};pe.number=function(r,e){if(Number.isInteger(e))return r.push(Ft("i"+BigInt(e)+"e"));let t=2147483648,n=e/t<<0,i=e%t<<0,o=n*t+i;r.push(Ft("i"+o+"e")),o!==e&&!pe._floatConversionDetected&&(pe._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())};pe.dict=function(r,e){r.push(ep);let t=0,n,i=Object.keys(e).sort(),o=i.length;for(;t<o;t++)n=i[t],e[n]!=null&&(pe.string(r,n),pe._encode(r,e[n]));r.push(Kc)};pe.dictMap=function(r,e){r.push(ep);let t=Array.from(e.keys()).sort();for(let n of t)e.get(n)!=null&&(ArrayBuffer.isView(n)?pe._encode(r,n):pe.string(r,String(n)),pe._encode(r,e.get(n)));r.push(Kc)};pe.list=function(r,e){let t=0,n=e.length;for(r.push(tp);t<n;t++)e[t]!=null&&pe._encode(r,e[t]);r.push(Kc)};pe.listSet=function(r,e){r.push(tp);for(let t of e)t!=null&&pe._encode(r,t);r.push(Kc)};var rp=pe;var jw=105,zw=58,Jw=100,Gw=108,wd=101;function np(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 z(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),z.position=0,z.encoding=n||null,z.data=ArrayBuffer.isView(r)?new Uint8Array(r.slice(e,t)):Ft(r),z.bytes=z.data.length,z.next())}z.bytes=0;z.position=0;z.data=null;z.encoding=null;z.next=function(){switch(z.data[z.position]){case Jw:return z.dictionary();case Gw:return z.list();case jw:return z.integer();default:return z.buffer()}};z.find=function(r){let e=z.position,t=z.data.length,n=z.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)+"]")};z.dictionary=function(){z.position++;let r={};for(;z.data[z.position]!==wd;){let e=z.buffer(),t=gd(e);t.includes("\uFFFD")&&(t=md(e)),r[t]=z.next()}return z.position++,r};z.list=function(){z.position++;let r=[];for(;z.data[z.position]!==wd;)r.push(z.next());return z.position++,r};z.integer=function(){let r=z.find(wd),e=np(z.data,z.position+1,r);return z.position+=r+1-z.position,e};z.buffer=function(){let r=z.find(zw),e=np(z.data,z.position,r),t=++r+e;return z.position=t,z.encoding?gd(z.data.slice(r,t)):z.data.slice(r,t)};var ip=z;function Ww(r){let e=2;for(let t of r)e+=_c(t);return e}function Yw(r){let e=2;for(let[t,n]of r){let i=Ft(t).byteLength;e+=Ni(i)+1+i,e+=_c(n)}return e}function Xw(r){let e=2,t=Object.keys(r);for(let n=0;n<t.length;n++){let i=Ft(t[n]).byteLength;e+=Ni(i)+1+i,e+=_c(r[t[n]])}return e}function Zw(r){let e=Ft(r).byteLength;return Ni(e)+1+e}function Qw(r){let e=r.byteLength-r.byteOffset;return Ni(e)+1+e}function _c(r){if(r==null)return 0;let t=Dc(r);switch(t){case"arraybufferview":return Qw(r);case"string":return Zw(r);case"array":case"set":return Ww(r);case"number":return 1+Ni(Math.floor(r))+1;case"bigint":return 1+r.toString().length+1;case"object":return Xw(r);case"map":return Yw(r);default:throw new TypeError(`Unsupported value of type "${t}"`)}}var xd=_c;var ex=xd,bd={encode:rp,decode:ip,byteLength:xd,encodingLength:ex};var tx=/^(\d{1,3}\.){3,3}\d{1,3}$/;var rx=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var Qt={name:"v4",size:4,isFormat:r=>tx.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]}`}},$r={name:"v6",size:16,isFormat:r=>r.length>0&&rx.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 op(r){if(Qt.isFormat(r))return Qt.size;if($r.isFormat(r))return $r.size;throw Error(`Invalid ip address: ${r}`)}function sp(r){return op(r)===Qt.size?1:2}function cp(r,e,t){t=~~t;let n=op(r);return typeof e=="function"&&(e=e(t+n)),n===Qt.size?Qt.encode(r,e,t):$r.encode(r,e,t)}function ap(r,e,t){if(e=~~e,t=t||r.length-e,t===Qt.size)return Qt.decode(r,e,t);if(t===$r.size)return $r.decode(r,e,t);throw Error(`Invalid buffer size needs to be ${Qt.size} for v4 or ${$r.size} for v6.`)}function Wo(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 $i(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}function up(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}function dp(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}function vd(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 Ed(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}function lp(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 Ad(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}function Td(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 Vi(r,e,t){let n=r.length;t==null&&(t=0),e===void 0&&(e=new Uint8Array(Td(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 Vi.bytes=i-t,e}Vi.bytes=0;function Hi(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 Hi.bytes=t-e,n}Hi.bytes=0;var pn=r=>r instanceof Uint8Array;function Vr(r){return typeof r=="string"?Td(r):r.byteLength}function Uc(r){return r instanceof Uint8Array?r:Array.isArray(r)?new Uint8Array(r):Vi(r)}function Oc(r,e,t){if(typeof e!="string")throw new Error("unknown input type");return Vi(e,r,t),Vi.bytes}var Yo={},hp=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}`;hp[s]=c,Yo[c]=s,Yo[`${t}${i}`]=s,Yo[`${e}${o}`]=s,Yo[`${t}${o}`]=s}}function fp(r,e,t){let n="";for(let i=e;i<t;){let o=r[i++];n+=hp[o]}return n}function Sd(r){return r.length>>>1}function pp(r,e,t,n){let i=0;for(;t<n;){let o=e.substr(i,2),s=Yo[o];if(s===void 0)return;r[t++]=s,i+=2}return r}var dx=Math.pow(2,24),lx=Math.pow(2,16),hx=Math.pow(2,8),lr=(r,e)=>r[e]*dx+r[e+1]*lx+r[e+2]*hx+r[e+3],ie=(r,e)=>r[e]<<8|r[e+1],hr=(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),H=(r,e,t)=>(r[t]=e>>8,r[t+1]=e&255,t+2);function gt(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:fx(r,e,t,n,i)}function fx(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 yx=0,yp=32768,Id=32768,mx=~Id,gp=32768,gx=~gp;function xe({bytes:r=0,encode:e,decode:t,encodingLength:n}){return e.bytes=r,t.bytes=r,{encode:e,decode:t,encodingLength:n||(()=>r)}}var L=xe({encode(r,e,t){e||(e=new Uint8Array(L.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=Oc(e,o[s],t+1);e[t]=c,t+=c+1}}return e[t++]=0,L.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=ie(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(Hi(r,e,e+c)),e+=c,o+=s?0:c}}return L.decode.bytes=o,t.length===0?".":t.join(".")},encodingLength(r){return r==="."||r===".."?1:Vr(r.replace(/^\.|\.$/gm,""))+2}}),He=xe({encode(r,e,t){e||(e=new Uint8Array(He.encodingLength(r))),t||(t=0);let n=Oc(e,r,t+1);return e[t]=n,He.encode.bytes=n+1,e},decode(r,e){e||(e=0);let t=r[e],n=Hi(r,e+1,e+1+t);return He.decode.bytes=t+1,n},encodingLength(r){return Vr(r)+1}}),Fi=xe({bytes:12,encode(r,e,t){e||(e=new Uint8Array(Fi.encodingLength(r))),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?yp:yx;return H(e,r.id||0,t),H(e,n|i,t+2),H(e,r.questions.length,t+4),H(e,r.answers.length,t+6),H(e,r.authorities.length,t+8),H(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=ie(r,e+2);return{id:ie(r,e),type:t&yp?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:dp(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:up(t&15),questions:new Array(ie(r,e+4)),answers:new Array(ie(r,e+6)),authorities:new Array(ie(r,e+8)),additionals:new Array(ie(r,e+10))}},encodingLength(){return 12}}),Pc=xe({encode(r,e,t){e||(e=new Uint8Array(Pc.encodingLength(r))),t||(t=0);let n=r.length;return H(e,n,t),gt(r,e,t+2,0,n),Pc.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=ie(r,e),n=r.slice(e+2,e+2+t);return Pc.decode.bytes=t+2,n},encodingLength(r){return r.length+2}}),Cc=xe({encode(r,e,t){return e||(e=new Uint8Array(Cc.encodingLength(r))),t||(t=0),L.encode(r,e,t+2),H(e,L.encode.bytes,t),Cc.encode.bytes=L.encode.bytes+2,e},decode(r,e){e||(e=0);let t=ie(r,e),n=L.decode(r,e+2);return Cc.decode.bytes=t+2,n},encodingLength(r){return L.encodingLength(r)+2}}),Rc=xe({encode(r,e,t){e||(e=new Uint8Array(Rc.encodingLength(r))),t||(t=0);let n=t;return t+=2,L.encode(r.mname,e,t),t+=L.encode.bytes,L.encode(r.rname,e,t),t+=L.encode.bytes,hr(e,r.serial||0,t),t+=4,hr(e,r.refresh||0,t),t+=4,hr(e,r.retry||0,t),t+=4,hr(e,r.expire||0,t),t+=4,hr(e,r.minimum||0,t),t+=4,H(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.mname=L.decode(r,e),e+=L.decode.bytes,n.rname=L.decode(r,e),e+=L.decode.bytes,n.serial=lr(r,e),e+=4,n.refresh=lr(r,e),e+=4,n.retry=lr(r,e),e+=4,n.expire=lr(r,e),e+=4,n.minimum=lr(r,e),e+=4,Rc.decode.bytes=e-t,n},encodingLength(r){return 22+L.encodingLength(r.mname)+L.encodingLength(r.rname)}}),Mc=xe({encode(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=Uc(r[i])),!pn(r[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Mc.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,gt(i,e,t,0,i.length),t+=i.length}),H(e,t-n-2,n),Mc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=ie(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 Mc.decode.bytes=e-t,i},encodingLength(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=Vr(t)+1:e+=t.length+1}),e}}),Lc=xe({encode(r,e,t){e||(e=new Uint8Array(Lc.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=Uc(r)),r||(r=new Uint8Array(0));let n=t;t+=2;let i=r.length;return gt(r,e,t,0,i),t+=i,H(e,t-n-2,n),Lc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=ie(r,e);e+=2;let i=r.slice(e,e+n);return e+=n,Lc.decode.bytes=e-t,i},encodingLength(r){return r?(pn(r)?r.length:Vr(r))+2:2}}),Nc=xe({encode(r,e,t){e||(e=new Uint8Array(Nc.encodingLength(r))),t||(t=0);let n=t;return t+=2,He.encode(r.cpu,e,t),t+=He.encode.bytes,He.encode(r.os,e,t),t+=He.encode.bytes,H(e,t-n-2,n),Nc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=He.decode(r,e),e+=He.decode.bytes,n.os=He.decode(r,e),e+=He.decode.bytes,Nc.decode.bytes=e-t,n},encodingLength(r){return He.encodingLength(r.cpu)+He.encodingLength(r.os)+2}}),zi=xe({encode(r,e,t){return e||(e=new Uint8Array(zi.encodingLength(r))),t||(t=0),L.encode(r,e,t+2),H(e,L.encode.bytes,t),zi.encode.bytes=L.encode.bytes+2,e},decode(r,e){e||(e=0);let t=L.decode(r,e+2);return zi.decode.bytes=L.decode.bytes+2,t},encodingLength(r){return L.encodingLength(r)+2}}),$c=xe({encode(r,e,t){e||(e=new Uint8Array($c.encodingLength(r))),t||(t=0),H(e,r.priority||0,t+2),H(e,r.weight||0,t+4),H(e,r.port||0,t+6),L.encode(r.target,e,t+8);let n=L.encode.bytes+6;return H(e,n,t),$c.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=ie(r,e),n={};return n.priority=ie(r,e+2),n.weight=ie(r,e+4),n.port=ie(r,e+6),n.target=L.decode(r,e+8),$c.decode.bytes=t+2,n},encodingLength(r){return 8+L.encodingLength(r.target)}}),yn=xe({encode(r,e,t){let n=yn.encodingLength(r);return e||(e=new Uint8Array(yn.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=yn.ISSUER_CRITICAL),H(e,n-2,t),t+=2,e[t]=r.flags||0,t+=1,He.encode(r.tag,e,t),t+=He.encode.bytes,Oc(e,r.value,t),t+=Vr(r.value),yn.encode.bytes=n,e},decode(r,e){e||(e=0);let t=ie(r,e);e+=2;let n=e,i={};return i.flags=r[e],e+=1,i.tag=He.decode(r,e),e+=He.decode.bytes,i.value=Hi(r,e,n+t),i.issuerCritical=!!(i.flags&yn.ISSUER_CRITICAL),yn.decode.bytes=t+2,i},encodingLength(r){return He.encodingLength(r.tag)+He.encodingLength(r.value)+2}});yn.ISSUER_CRITICAL=128;var Vc=xe({encode(r,e,t){e||(e=new Uint8Array(Vc.encodingLength(r))),t||(t=0);let n=t;return t+=2,H(e,r.preference||0,t),t+=2,L.encode(r.exchange,e,t),t+=L.encode.bytes,H(e,t-n-2,n),Vc.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=ie(r,e),e+=2,n.exchange=L.decode(r,e),e+=L.decode.bytes,Vc.decode.bytes=e-t,n},encodingLength(r){return 4+L.encodingLength(r.exchange)}}),wp=xe({encode(r,e,t){return e||(e=new Uint8Array(wp.encodingLength(r))),t||(t=0),H(e,4,t),t+=2,Qt.encode(r,e,t),e},decode(r,e){return e||(e=0),e+=2,Qt.decode(r,e)},bytes:6}),Hc=xe({encode(r,e,t){return e||(e=new Uint8Array(Hc.encodingLength(r))),t||(t=0),H(e,16,t),t+=2,$r.encode(r,e,t),Hc.encode.bytes=18,e},decode(r,e){e||(e=0),e+=2;let t=$r.decode(r,e);return Hc.decode.bytes=18,t},bytes:18}),mp=r=>new Uint8Array(r),Hr=xe({encode(r,e,t){e||(e=new Uint8Array(Hr.encodingLength(r))),t||(t=0);let n=t,i=Ad(r.code);if(H(e,i,t),t+=2,r.data)H(e,r.data.length,t),t+=2,gt(r.data,e,t),t+=r.data.length;else switch(i){case 8:{let o=r.sourcePrefixLength||0,s=r.family||sp(r.ip,mp),c=cp(r.ip,mp),u=Math.ceil(o/8);H(e,u+4,t),t+=2,H(e,s,t),t+=2,e[t++]=o,e[t++]=r.scopePrefixLength||0,gt(c,e,t,0,u),t+=u}break;case 11:r.timeout?(H(e,2,t),t+=2,H(e,r.timeout,t),t+=2):(H(e,0,t),t+=2);break;case 12:{let o=r.length||0;H(e,o,t),t+=2,e.fill(0,t,t+o),t+=o}break;case 14:{let o=r.tags.length*2;H(e,o,t),t+=2;for(let s of r.tags)H(e,s,t),t+=2}break;default:throw new Error(`Unknown roption code: ${r.code}`)}return Hr.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={};t.code=ie(r,e),t.type=lp(t.code),e+=2;let n=ie(r,e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=ie(r,e),e+=2,t.sourcePrefixLength=r[e++],t.scopePrefixLength=r[e++];{let i=new Uint8Array(t.family===1?4:16);gt(r,i,0,e,e+n-4),t.ip=ap(i)}break;case 11:n>0&&(t.timeout=ie(r,e),e+=2);break;case 14:t.tags=[];for(let i=0;i<n;i+=2)t.tags.push(ie(r,e)),e+=2}return Hr.decode.bytes=n+4,t},encodingLength(r){if(r.data)return r.data.length+4;switch(Ad(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}`)}}),mn=xe({encode(r,e,t){e||(e=new Uint8Array(mn.encodingLength(r))),t||(t=0);let n=t,i=ji(r,Hr);return H(e,i,t),t=rs(r,Hr,e,t+2),mn.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=[],i=ie(r,e);e+=2;let o=0;for(;i>0;)n[o++]=Hr.decode(r,e),e+=Hr.decode.bytes,i-=Hr.decode.bytes;return mn.decode.bytes=e-t,n},encodingLength(r){return 2+ji(r||[],Hr)}}),fr=xe({encode(r,e,t){e||(e=new Uint8Array(fr.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!pn(i))throw new Error("Key must be a Buffer");return t+=2,H(e,r.flags,t),t+=2,e[t]=fr.PROTOCOL_DNSSEC,t+=1,e[t]=r.algorithm,t+=1,gt(i,e,t,0,i.length),t+=i.length,fr.encode.bytes=t-n,H(e,fr.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);if(e+=2,n.flags=ie(r,e),e+=2,r[e]!==fr.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,fr.decode.bytes=e-t,n},encodingLength(r){return 6+Vr(r.key)}});fr.PROTOCOL_DNSSEC=3;fr.ZONE_KEY=128;fr.SECURE_ENTRYPOINT=32768;var Xo=xe({encode(r,e,t){e||(e=new Uint8Array(Xo.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!pn(i))throw new Error("Signature must be a Buffer");return t+=2,H(e,$i(r.typeCovered),t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.labels,t+=1,hr(e,r.originalTTL,t),t+=4,hr(e,r.expiration,t),t+=4,hr(e,r.inception,t),t+=4,H(e,r.keyTag,t),t+=2,L.encode(r.signersName,e,t),t+=L.encode.bytes,gt(i,e,t,0,i.length),t+=i.length,Xo.encode.bytes=t-n,H(e,Xo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);return e+=2,n.typeCovered=Wo(ie(r,e)),e+=2,n.algorithm=r[e],e+=1,n.labels=r[e],e+=1,n.originalTTL=lr(r,e),e+=4,n.expiration=lr(r,e),e+=4,n.inception=lr(r,e),e+=4,n.keyTag=ie(r,e),e+=2,n.signersName=L.decode(r,e),e+=L.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,Xo.decode.bytes=e-t,n},encodingLength(r){return 20+L.encodingLength(r.signersName)+Vr(r.signature)}}),Zo=xe({encode(r,e,t){e||(e=new Uint8Array(Zo.encodingLength(r))),t||(t=0);let n=t;return t+=2,L.encode(r.mbox||".",e,t),t+=L.encode.bytes,L.encode(r.txt||".",e,t),t+=L.encode.bytes,Zo.encode.bytes=t-n,H(e,Zo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=L.decode(r,e)||".",e+=L.decode.bytes,n.txt=L.decode(r,e)||".",e+=L.decode.bytes,Zo.decode.bytes=e-t,n},encodingLength(r){return 2+L.encodingLength(r.mbox||".")+L.encodingLength(r.txt||".")}}),Dt=xe({encode(r,e,t){e||(e=new Uint8Array(Dt.encodingLength(r))),t||(t=0);let n=t,i=[];for(let o=0;o<r.length;o++){let s=$i(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=Uc(i[o]);e[t]=o,t+=1,e[t]=s.length,t+=1,gt(s,e,t,0,s.length),t+=s.length}return Dt.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=Wo(o<<8|c<<3|d);i.push(a)}}e+=s}return Dt.decode.bytes=e-n,i},encodingLength(r){let e=[];for(let n=0;n<r.length;n++){let i=$i(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}}),Qo=xe({encode(r,e,t){e||(e=new Uint8Array(Qo.encodingLength(r))),t||(t=0);let n=t;return t+=2,L.encode(r.nextDomain,e,t),t+=L.encode.bytes,Dt.encode(r.rrtypes,e,t),t+=Dt.encode.bytes,Qo.encode.bytes=t-n,H(e,Qo.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);return e+=2,n.nextDomain=L.decode(r,e),e+=L.decode.bytes,n.rrtypes=Dt.decode(r,e,i-(e-t)),e+=Dt.decode.bytes,Qo.decode.bytes=e-t,n},encodingLength(r){return 2+L.encodingLength(r.nextDomain)+Dt.encodingLength(r.rrtypes)}}),es=xe({encode(r,e,t){e||(e=new Uint8Array(es.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!pn(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!pn(o))throw new Error("nextDomain must be a Buffer");return t+=2,e[t]=r.algorithm,t+=1,e[t]=r.flags,t+=1,H(e,r.iterations,t),t+=2,e[t]=i.length,t+=1,gt(i,e,t,0,i.length),t+=i.length,e[t]=o.length,t+=1,gt(o,e,t,0,o.length),t+=o.length,Dt.encode(r.rrtypes,e,t),t+=Dt.encode.bytes,es.encode.bytes=t-n,H(e,es.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);e+=2,n.algorithm=r[e],e+=1,n.flags=r[e],e+=1,n.iterations=ie(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=Dt.decode(r,e,i-(e-t)),e+=Dt.decode.bytes,es.decode.bytes=e-t,n},encodingLength(r){return 8+r.salt.length+r.nextDomain.length+Dt.encodingLength(r.rrtypes)}}),ts=xe({encode(r,e,t){e||(e=new Uint8Array(ts.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!pn(i))throw new Error("Digest must be a Buffer");return t+=2,H(e,r.keyTag,t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.digestType,t+=1,gt(i,e,t,0,i.length),t+=i.length,ts.encode.bytes=t-n,H(e,ts.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);return e+=2,n.keyTag=ie(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,ts.decode.bytes=e-t,n},encodingLength(r){return 6+Vr(r.digest)}}),qi=xe({encode(r,e,t){e||(e=new Uint8Array(qi.encodingLength(r))),t||(t=0);let n=t;t+=2,e[t]=r.algorithm,t+=1,e[t]=r.hash,t+=1;let i=Sd(r.fingerprint),o=Dd(r.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${r.fingerprint}" for hashType=${r.hash}: ${i} != ${o}`);return pp(e,r.fingerprint,t,t+=i),qi.encode.bytes=t-n,H(e,qi.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=Dd(n.hash);return n.fingerprint=fp(r,e,e+i),e+=i,qi.decode.bytes=e-t,n},encodingLength(r){return 4+Sd(r.fingerprint)}});function Dd(r){if(r===1)return 20;if(r===2)return 32;throw new Error(`Invalid hashType=${r}, supported=1,2`)}qi.getFingerprintLengthForHashType=Dd;function Bd(r){switch(r.toUpperCase()){case"A":return wp;case"PTR":return zi;case"CNAME":return zi;case"DNAME":return zi;case"TXT":return Mc;case"NULL":return Lc;case"AAAA":return Hc;case"SRV":return $c;case"HINFO":return Nc;case"CAA":return yn;case"NS":return Cc;case"SOA":return Rc;case"MX":return Vc;case"OPT":return mn;case"DNSKEY":return fr;case"RRSIG":return Xo;case"RP":return Zo;case"NSEC":return Qo;case"NSEC3":return es;case"SSHFP":return qi;case"DS":return ts}return Pc}var qt=xe({encode(r,e,t){e||(e=new Uint8Array(qt.encodingLength(r))),t||(t=0);let n=t;if(L.encode(r.name,e,t),t+=L.encode.bytes,H(e,$i(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");H(e,r.udpPayloadSize||4096,t+2),e[t+4]=r.extendedRcode||0,e[t+5]=r.ednsVersion||0,H(e,r.flags||0,t+6),t+=8,mn.encode(r.options||[],e,t),t+=mn.encode.bytes}else{let i=Ed(r.class===void 0?"IN":r.class);r.flush&&(i|=Id),H(e,i,t+2),hr(e,r.ttl||0,t+4),t+=8;let o=Bd(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return qt.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={},n=e;if(t.name=L.decode(r,e),e+=L.decode.bytes,t.type=Wo(ie(r,e)),t.type==="OPT")t.udpPayloadSize=ie(r,e+2),t.extendedRcode=r[e+4],t.ednsVersion=r[e+5],t.flags=ie(r,e+6),t.flag_do=(t.flags>>15&1)===1,t.options=mn.decode(r,e+8),e+=8+mn.decode.bytes;else{let i=ie(r,e+2);t.ttl=lr(r,e+4),t.class=vd(i&mx),t.flush=!!(i&Id);let o=Bd(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return qt.decode.bytes=e-n,t},encodingLength(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return L.encodingLength(r.name)+8+Bd(r.type).encodingLength(e)}}),Ji=xe({encode(r,e,t){e||(e=new Uint8Array(Ji.encodingLength(r))),t||(t=0);let n=t;return L.encode(r.name,e,t),t+=L.encode.bytes,H(e,$i(r.type),t),t+=2,H(e,Ed(r.class===void 0?"IN":r.class),t),t+=2,Ji.encode.bytes=t-n,r},decode(r,e){e||(e=0);let t=e,n={};return n.name=L.decode(r,e),e+=L.decode.bytes,n.type=Wo(ie(r,e)),e+=2,n.class=vd(ie(r,e)),e+=2,!!(n.class&gp)&&(n.class&=gx),Ji.decode.bytes=e-t,n},encodingLength(r){return L.encodingLength(r.name)+4}});var xp=1024;var Qe={encode:function(r,e,t){let n=!e;n&&(e=new Uint8Array(wx(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),Fi.encode(r,e,t),t+=Fi.encode.bytes,t=rs(r.questions,Ji,e,t),t=rs(r.answers,qt,e,t),t=rs(r.authorities,qt,e,t),t=rs(r.additionals,qt,e,t),Qe.encode.bytes=t-i,n&&ns.bytes!==e.length?e.slice(0,ns.bytes):e},decode:function(r,e){e||(e=0);let t=e,n=Fi.decode(r,e);return e+=Fi.decode.bytes,e=kc(n.questions,Ji,r,e),e=kc(n.answers,qt,r,e),e=kc(n.authorities,qt,r,e),e=kc(n.additionals,qt,r,e),Qe.decode.bytes=e-t,n},encodingLength:function(r){return Fi.encodingLength(r)+ji(r.questions||[],Ji)+ji(r.answers||[],qt)+ji(r.authorities||[],qt)+ji(r.additionals||[],qt)}};Qe.encode.bytes=0;Qe.decode.bytes=0;function Fc(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 qc={encode:function(r,e,t){return e=Qe.encode(Fc(r,"query"),e,t),qc.encode.bytes=Qe.encode.bytes,e},decode:function(r,e){let t=Qe.decode(r,e);return qc.decode.bytes=Qe.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return Qe.encodingLength(Fc(r,"query"))}};qc.encode.bytes=0;qc.decode.bytes=0;var jc={encode:function(r,e,t){return e=Qe.encode(Fc(r,"response"),e,t),jc.encode.bytes=Qe.encode.bytes,e},decode:function(r,e){let t=Qe.decode(r,e);return jc.decode.bytes=Qe.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return Qe.encodingLength(Fc(r,"response"))}};jc.encode.bytes=0;jc.decode.bytes=0;var ns=Qe.encode,zc=Qe.decode,wx=Qe.encodingLength;function bp(r){let e=ns(r),t=new Uint8Array(2+e.byteLength);return H(t,e.byteLength),gt(e,t,2,0,e.length),bp.bytes=t.byteLength,t}bp.bytes=0;function vp(r){let e=ie(r,0);if(r.byteLength<e+2)return null;let t=zc(r.slice(2));return vp.bytes=zc.bytes,t}vp.bytes=0;function ji(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function rs(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 kc(r,e,t,n){for(let i=0;i<r.length;i++)r[i]=e.decode(t,n),n+=e.decode.bytes;return n}function Ep(r,e){let t=O.uint8Array(r).toBase32Z();return new URL(t,e).href}async function Kd({gatewayUri:r,publicKeyBytes:e}){let t=O.uint8Array(e).toBase32Z(),n=Ep(e,r),i;try{if(i=await fetch(n,{method:"GET"}),!i.ok)throw new N("notFound",`Pkarr record not found for: ${t}`)}catch(c){throw c instanceof N?c:new N("internalError",`Failed to fetch Pkarr record: ${c.message}`)}let o=await i.arrayBuffer();if(!o)throw new N("notFound",`Pkarr record not found for: ${t}`);if(o.byteLength<72)throw new N("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${o.byteLength}`);if(o.byteLength>1072)throw new N("invalidDidDocumentLength",`Pkarr response exceeds 1000 byte limit: ${o.byteLength}`);return{k:e,seq:Number(new DataView(o).getBigUint64(64)),sig:new Uint8Array(o,0,64),v:new Uint8Array(o,72)}}async function _d({gatewayUri:r,bep44Message:e}){let t=O.uint8Array(e.k).toBase32Z(),n=Ep(e.k,r),i=new Uint8Array(e.v.length+72);i.set(e.sig,0),new DataView(i.buffer).setBigUint64(e.sig.length,BigInt(e.seq)),i.set(e.v,e.sig.length+8);let o;try{o=await fetch(n,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:i})}catch(s){throw new N("internalError",`Failed to put Pkarr record for identifier ${t}: ${s.message}`)}return o.ok}async function Ud({dnsPacket:r,publicKeyBytes:e,signer:t}){let n=Math.ceil(Date.now()/1e3),i=ns(r),o=bd.encode({seq:n,v:i}).subarray(1,-1);if(o.length>1e3)throw new N("invalidDidDocumentLength",`DNS packet exceeds the 1000 byte maximum size: ${o.length} bytes`);let s=await t.sign({data:o});return{k:e,seq:n,sig:s,v:i}}async function Od({bep44Message:r}){let e=await De.bytesToPublicKey({publicKeyBytes:r.k}),t=bd.encode({seq:r.seq,v:r.v}).subarray(1,-1);if(!await De.verify({key:e,signature:r.sig,data:t}))throw new N("invalidSignature","Invalid signature for DHT BEP44 message");return zc(r.v)}var Ap="dht";async function Jc({didUri:r}){let e=is({didUri:r});return await De.bytesToPublicKey({publicKeyBytes:e})}function is({didUri:r}){let e=Be.parse(r);if(!e)throw new N("invalidDid",`Invalid DID URI: ${r}`);if(e.method!==Ap)throw new N("methodNotSupported",`Method not supported: ${e.method}`);let t;try{t=O.base32Z(e.id).toUint8Array()}catch{throw new N("invalidPublicKey","Failed to decode method-specific identifier")}if(t.length!==32)throw new N("invalidPublicKeyLength",`Invalid public key length: ${t.length}`);return t}async function kd({identityKey:r}){let e=await De.publicKeyToBytes({publicKey:r}),t=O.uint8Array(e).toBase32Z();return`did:${Ap}:${t}`}function Gi(r){let t={Ed25519:De,"P-256":{publicKeyToBytes:async({publicKey:n})=>{let i=await Ce.publicKeyToBytes({publicKey:n});return await Ce.compressPublicKey({publicKeyBytes:i})},bytesToPublicKey:Ce.bytesToPublicKey,privateKeyToBytes:Ce.privateKeyToBytes,bytesToPrivateKey:Ce.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:n})=>{let i=await Oe.publicKeyToBytes({publicKey:n});return await Oe.compressPublicKey({publicKeyBytes:i})},bytesToPublicKey:Oe.bytesToPublicKey,privateKeyToBytes:Oe.privateKeyToBytes,bytesToPrivateKey:Oe.bytesToPrivateKey},X25519:dr}[r];if(!t)throw new N("invalidPublicKeyType",`Unsupported curve: ${r}`);return t}async function os({newDid:r,previousDidProof:e}){let t=await Jc({didUri:e.previousDid}),n=is({didUri:r}),i=O.base64Url(e.signature).toUint8Array();if(!await De.verify({key:t,data:n,signature:i}))throw new N("invalidPreviousDidProof","The previous DID proof is invalid.")}var Sp=0,pr=7200,ss=";",ot=",",Gc={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},Pd={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"};function xx(r,e){return{type:"TXT",name:r,ttl:pr,data:e}}function Xn(r){if(typeof r=="string")return r;if(r instanceof Uint8Array)return O.uint8Array(r).toString();if(Array.isArray(r))return r.map(e=>Xn(e)).join("");throw new N("internalError","Pkarr returned DNS TXT record with invalid data type")}function Yn(r){return Xn(r).split(ss).reduce((e,t)=>{let[n,i]=t.split("=");return e[n]=i,e},{})}function Wc(r){if(r.length<=255)return r;let e=[];for(let t=0;t<r.length;t+=255)e.push(r.slice(t,t+255));return e}async function Cd({didUri:r,dnsPacket:e}){let t={id:r},n={published:!0},i=new Map;for(let o of e?.answers??[]){if(o.type!=="TXT")continue;let s=o.name.split(".")[0].substring(1);switch(!0){case s.startsWith("aka"):{let c=Xn(o.data);t.alsoKnownAs=c.split(ot);break}case s.startsWith("cnt"):{let c=Xn(o.data);t.controller=c.includes(ot)?c.split(ot):c;break}case s.startsWith("k"):{let{id:c,t:u,k:d,c:a,a:l}=Yn(o.data),y=O.base64Url(d).toUint8Array(),w=Ic[Number(u)],p=await Gi(w).bytesToPublicKey({publicKeyBytes:y});p.alg=l||Pd[Number(u)];let g=s==="k0"?"0":c!==void 0?c:await Z({jwk:p});t.verificationMethod??=[];let v=`${r}#${g}`;t.verificationMethod.push({id:v,type:"JsonWebKey",controller:a??r,publicKeyJwk:p}),i.set(s,v);break}case s.startsWith("s"):{let{id:c,t:u,se:d,...a}=Yn(o.data),l=d.includes(ot)?d.split(ot):[d],y=Object.fromEntries(Object.entries(a).map(([w,p])=>[w,p.includes(ot)?p.split(ot):p]));t.service??=[],t.service.push({...y,id:`${r}#${c}`,type:u,serviceEndpoint:l});break}case s.startsWith("typ"):{let{id:c}=Yn(o.data);n.types=c.split(ot).map(u=>Number(u));break}case s.startsWith("did"):{let c=w=>w.split(ot).map(p=>i.get(p)).filter(p=>typeof p=="string"),{auth:u,asm:d,del:a,inv:l,agm:y}=Yn(o.data);u&&(t.authentication=c(u)),d&&(t.assertionMethod=c(d)),a&&(t.capabilityDelegation=c(a)),l&&(t.capabilityInvocation=c(l)),y&&(t.keyAgreement=c(y));break}}}return{didDocument:t,didDocumentMetadata:n,didResolutionMetadata:{}}}async function Rd({didDocument:r,didMetadata:e,authoritativeGatewayUris:t,previousDidProof:n}){let i=[],o=[],s=new Map,c=[],u=[];if(n!==void 0){let{signature:l,previousDid:y}=n;await os({newDid:r.id,previousDidProof:n}),i.push({type:"TXT",name:"_prv._did.",ttl:pr,data:`id=${y};s=${l}`})}if(r.alsoKnownAs&&i.push({type:"TXT",name:"_aka._did.",ttl:pr,data:r.alsoKnownAs.join(ot)}),r.controller){let l=Array.isArray(r.controller)?r.controller.join(ot):r.controller;i.push({type:"TXT",name:"_cnt._did.",ttl:pr,data:l})}for(let[l,y]of r.verificationMethod?.entries()??[]){let w=`k${l}`;u.push(w);let p=y.id.split("#").pop();s.set(p,w);let g=y.publicKeyJwk;if(!(g?.crv&&g.crv in Gc))throw new N("invalidPublicKeyType",`Verification method '${y.id}' contains an unsupported key type: ${g?.crv??"undefined"}`);let v=Ic[g.crv],S=await Gi(g.crv).publicKeyToBytes({publicKey:g}),I=O.uint8Array(S).toBase64Url(),E=[`t=${v}`,`k=${I}`];p!=="0"&&await Z({jwk:g})!==p&&E.unshift(`id=${p}`),g.alg!==Pd[v]&&E.push(`a=${g.alg}`),y.controller!==r.id&&E.push(`c=${y.controller}`),i.push({type:"TXT",name:`_${w}._did.`,ttl:pr,data:E.join(ss)})}r.service?.forEach((l,y)=>{let w=`s${y}`;c.push(w);let{id:p,type:g,serviceEndpoint:v,...S}=l;p=ut(p),v=Array.isArray(v)?v.join(","):v;let E=Object.entries({id:p,t:g,se:v,...S}).map(([B,_])=>`${B}=${_}`).join(ss),U=Wc(E);i.push({type:"TXT",name:`_${w}._did.`,ttl:pr,data:U})});let d=[`v=${Sp}`];if(u.length&&d.push(`vm=${u.join(ot)}`),Object.keys(hi).forEach(l=>{let y=r[l]?.map(w=>s.get(w.split("#").pop()));if(y){let w=pd[l];d.push(`${w}=${y.join(ot)}`)}}),c.length&&d.push(`svc=${c.join(ot)}`),e.types?.length){let y=e.types.map(w=>typeof w=="string"?fd[w]:w);i.push({type:"TXT",name:"_typ._did.",ttl:pr,data:`id=${y.join(ot)}`})}i.push({type:"TXT",name:"_did."+Tp(r.id)+".",ttl:pr,data:d.join(ss)});for(let l of t||[])o.push({type:"NS",name:"_did."+Tp(r.id)+".",ttl:pr,data:l+"."});return{id:0,type:"response",flags:xp,answers:[...i,...o]}}function Tp(r){return r.split(":")[2]}var Bp=process.env.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",cs=class cs extends Ht{static async create({keyManager:e=new it,options:t={}}={}){if(t.verificationMethods?.some(a=>!(a.algorithm in Gc)))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 gn.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}),y=await e.getPublicKey({keyUri:l}),w=a.id??y.kid??await Z({jwk:y});w=`${s}#${ut(w)}`,c.verificationMethod??=[],c.verificationMethod.push({id:w,type:"JsonWebKey",controller:a.controller??s,publicKeyJwk:y});for(let p of a.purposes??[])c[p]??=[],c[p].push(w)}t.services?.forEach(a=>{c.service??=[],a.id=`${s}#${a.id.split("#").pop()}`,c.service.push(a)});let d=new mt({uri:s,document:c,metadata:{published:!1,...t.types&&{types:t.types}},keyManager:e});if(t.publish??!0){let a=await cs.publish({did:d,gatewayUri:t.gatewayUri});d.metadata=a.didDocumentMetadata}return d}static async import({portableDid:e,keyManager:t=new it}){if(Be.parse(e.uri)?.method!==cs.methodName)throw new N("methodNotSupported","Method not supported");let i=await mt.import({portableDid:e,keyManager:t});if(!i.document.verificationMethod?.some(o=>o.id?.split("#").pop()==="0"))throw new N("invalidDidDocument","DID document must contain an Identity Key");return i}static async getSigningMethod({didDocument:e,methodId:t="#0"}){let n=Be.parse(e.id);if(n&&n.method!==this.methodName)throw new N("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>ut(o.id)===(ut(t)??ut(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new N("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:t=Bp}){return await Yc.put({did:e,gatewayUri:t})}static async resolve(e,t={}){let n=t?.gatewayUri??Bp;try{await gn.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await Yc.get({didUri:e,gatewayUri:n});return{...Ue,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof N))throw new Error(i);return{...Ue,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};cs.methodName="dht";var Ip=cs,Yc=class r{static async get({didUri:e,gatewayUri:t}){let n=gn.identifierToIdentityKeyBytes({didUri:e}),i=await r.pkarrGet({gatewayUri:t,publicKeyBytes:n}),o=await gn.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 gn.createBep44PutMessage({dnsPacket:n,publicKeyBytes:gn.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(e){return Kd(e)}static async pkarrPut(e){return _d(e)}static async fromDnsPacket(e){return Cd(e)}static async toDnsPacket(e){return Rd(e)}static getUniqueDidSuffix(e){return e.split(":")[2]}},gn=class{static async createBep44PutMessage(e){return Ud(e)}static async identifierToIdentityKey(e){return Jc(e)}static identifierToIdentityKeyBytes(e){return is(e)}static async identityKeyToIdentifier(e){return kd(e)}static keyConverter(e){return Gi(e)}static async parseBep44GetMessage(e){return Od(e)}static parseTxtDataToObject(e){return Yn(e)}static parseTxtDataToString(e){return Xn(e)}static async validatePreviousDidProof(e){return os(e)}static chunkDataIfNeeded(e){return Wc(e)}};var Ae={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 ge=class extends Error{constructor(e,t){super(`${e}: ${t}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};var U6=new Uint8Array(0);var Md=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 Ld=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")}},Nd=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 Dp(this,e)}},$d=class{constructor(e){this.decoders=e}or(e){return Dp(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`)}},Dp=(r,e)=>new $d({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),Vd=class{constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ld(e,t,n),this.decoder=new Nd(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},bx=({name:r,prefix:e,encode:t,decode:n})=>new Vd(r,e,t,n);var vx=(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},Ex=(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},as=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>bx({prefix:e,name:r,encode(i){return Ex(i,n,t)},decode(i){return vx(i,n,t,r)}});var L6=as({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),N6=as({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),us=as({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$6=as({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wt=class r{static encode(e){return us.baseEncode(e)}static decodeAsBytes(e,t){if(!r.isBase64UrlString(e))throw new ge(Ae.EncodedStringIncorrectEncoding,`Given ${t} must be base64url string.`);return us.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 Np=Sn(_p(),1);var Hd;(function(r){r.Public="public",r.Private="private"})(Hd||(Hd={}));var Kt=Hd;var Fe=class{static validateEs256kOperationKey(e,t){let n=new Set(["kty","crv","x","y"]);t===Kt.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new ge(Ae.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new ge(Ae.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new ge(Ae.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new ge(Ae.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new ge(Ae.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(t===Kt.Private&&(e.d===void 0||e.d.length!==43))throw new ge(Ae.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new ge(Ae.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!wt.isBase64UrlString(e))throw new ge(Ae.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 ge(Ae.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);t.add(n)}}};var ds=class{};ds.hashAlgorithmInMultihashCode=18;ds.maxCanonicalizedDeltaSizeInBytes=1e3;var dt=ds;var kp=Sn(Op(),1);var er=class r{static canonicalizeAsBytes(e){let t=r.removeAllUndefinedProperties(e),n=kp.default(t);return wt.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 Ax=Rp,Pp=128,Tx=127,Sx=~Tx,Bx=Math.pow(2,31);function Rp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Bx;)e[t++]=r&255|Pp,r/=128;for(;r&Sx;)e[t++]=r&255|Pp,r>>>=7;return e[t]=r|0,Rp.bytes=t-n+1,e}var Ix=Fd,Dx=128,Cp=127;function Fd(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Fd.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Cp)<<i:(s&Cp)*Math.pow(2,i),i+=7}while(s>=Dx);return Fd.bytes=o-n,t}var Kx=Math.pow(2,7),_x=Math.pow(2,14),Ux=Math.pow(2,21),Ox=Math.pow(2,28),kx=Math.pow(2,35),Px=Math.pow(2,42),Cx=Math.pow(2,49),Rx=Math.pow(2,56),Mx=Math.pow(2,63),Lx=function(r){return r<Kx?1:r<_x?2:r<Ux?3:r<Ox?4:r<kx?5:r<Px?6:r<Cx?7:r<Rx?8:r<Mx?9:10},Nx={encode:Ax,decode:Ix,encodingLength:Lx},$x=Nx,ls=$x;var qd=(r,e=0)=>[ls.decode(r,e),ls.decode.bytes],jd=(r,e,t=0)=>(ls.encode(r,e,t),e),zd=r=>ls.encodingLength(r);var Jd=(r,e)=>{let t=e.byteLength,n=zd(r),i=n+zd(t),o=new Uint8Array(i+t);return jd(r,o,0),jd(t,o,n),o.set(e,i),new Zc(r,t,e,o)},Mp=r=>{let e=Md(r),[t,n]=qd(e),[i,o]=qd(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Zc(t,i,s,e)};var Zc=class{constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Wd=({name:r,code:e,encode:t})=>new Gd(r,e,t),Gd=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?Jd(this.code,t):t.then(n=>Jd(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Lp=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),Qc=Wd({name:"sha2-256",code:18,encode:Lp("SHA-256")}),aS=Wd({name:"sha2-512",code:19,encode:Lp("SHA-512")});var hs=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())})},Ge=class r{static hash(e,t){return hs(this,void 0,void 0,function*(){let n;switch(t){case 18:n=(yield Qc.digest(e)).bytes;break;default:throw new ge(Ae.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${t} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,t){return hs(this,void 0,void 0,function*(){let n;switch(t){case 18:n=yield Qc.encode(e);break;default:throw new ge(Ae.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${t} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,t){return hs(this,void 0,void 0,function*(){let n=er.canonicalizeAsBytes(e);return yield r.hashThenEncode(n,t)})}static canonicalizeThenDoubleHashThenEncode(e,t){return hs(this,void 0,void 0,function*(){let n=er.canonicalizeAsBytes(e),i=yield r.hashAsNonMultihashBytes(n,t);return yield r.hashThenEncode(i,t)})}static hashThenEncode(e,t){return hs(this,void 0,void 0,function*(){let n=yield r.hash(e,t);return wt.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,t){let n,i=wt.decodeAsBytes(e,t);try{n=Mp(i)}catch{throw new ge(Ae.MultihashStringNotAMultihash,`Given ${t} string '${e}' is not a multihash after decoding.`)}let o=dt.hashAlgorithmInMultihashCode;if(o!==n.code)throw new ge(Ae.MultihashUnsupportedHashAlgorithm,`Given ${t} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};var Yd;(function(r){r.Create="create",r.Update="update",r.Deactivate="deactivate",r.Recover="recover"})(Yd||(Yd={}));var fs=Yd;var Xd;(function(r){r.Replace="replace",r.AddPublicKeys="add-public-keys",r.RemovePublicKeys="remove-public-keys",r.AddServices="add-services",r.RemoveServices="remove-services"})(Xd||(Xd={}));var Zn=Xd;var ea=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())})},wn=class r{static createCreateRequest(e){return ea(this,void 0,void 0,function*(){let t=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;Fe.validateEs256kOperationKey(t,Kt.Public),Fe.validateEs256kOperationKey(n,Kt.Public),r.validateDidDocumentKeys(i),r.validateServices(o);let s=dt.hashAlgorithmInMultihashCode,c=[{action:Zn.Replace,document:e.document}],u={updateCommitment:yield Ge.canonicalizeThenDoubleHashThenEncode(n,s),patches:c};r.validateDeltaSize(u);let a={deltaHash:yield Ge.canonicalizeThenHashThenEncode(u,s),recoveryCommitment:yield Ge.canonicalizeThenDoubleHashThenEncode(t,s)};return{type:fs.Create,suffixData:a,delta:u}})}static createDeactivateRequest(e){return ea(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.recoveryPublicKey,Kt.Public);let t=dt.hashAlgorithmInMultihashCode,n=yield Ge.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:fs.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return ea(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.recoveryPublicKey,Kt.Public),Fe.validateEs256kOperationKey(e.nextRecoveryPublicKey,Kt.Public),Fe.validateEs256kOperationKey(e.nextUpdatePublicKey,Kt.Public),r.validateDidDocumentKeys(e.document.publicKeys),r.validateServices(e.document.services);let t=dt.hashAlgorithmInMultihashCode,n=yield Ge.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i=[{action:Zn.Replace,document:e.document}],o=yield Ge.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,t),s={patches:i,updateCommitment:o},c=yield Ge.canonicalizeThenHashThenEncode(s,t),d={recoveryCommitment:yield Ge.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,t),recoveryKey:e.recoveryPublicKey,deltaHash:c},a=yield e.signer.sign({alg:"ES256K"},d);return{type:fs.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:a}})}static createUpdateRequest(e){return ea(this,void 0,void 0,function*(){if(r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.updatePublicKey,Kt.Public),Fe.validateEs256kOperationKey(e.nextUpdatePublicKey,Kt.Public),r.validateServices(e.servicesToAdd),r.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let p of e.idsOfServicesToRemove)Fe.validateId(p);if(e.idsOfPublicKeysToRemove!==void 0)for(let p of e.idsOfPublicKeysToRemove)Fe.validateId(p);let t=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let p={action:Zn.AddServices,services:n};t.push(p)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let p={action:Zn.RemoveServices,ids:i};t.push(p)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let p={action:Zn.AddPublicKeys,publicKeys:o};t.push(p)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let p={action:Zn.RemovePublicKeys,ids:s};t.push(p)}let c=dt.hashAlgorithmInMultihashCode,u=yield Ge.canonicalizeThenHashThenEncode(e.updatePublicKey,c),d=yield Ge.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,c),a={patches:t,updateCommitment:d},l=yield Ge.canonicalizeThenHashThenEncode(a,c),y={updateKey:e.updatePublicKey,deltaHash:l},w=yield e.signer.sign({alg:"ES256K"},y);return{type:fs.Update,didSuffix:e.didSuffix,revealValue:u,delta:a,signedData:w}})}static validateDidSuffix(e){Ge.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 ge(Ae.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(Fe.validateId(n.id),t.has(n.id))throw new ge(Ae.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);t.add(n.id),Fe.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 ge(Ae.DidDocumentServiceIdDuplicated,"Service id has to be unique");t.add(n.id)}}}static validateService(e){Fe.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 ge(Ae.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new ge(Ae.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&Np.parse(e.serviceEndpoint).error!==void 0)throw new ge(Ae.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let t=er.canonicalizeAsBytes(e);if(t.length>dt.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${t.length} bytes exceeded limit of ${dt.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new ge(Ae.DeltaExceedsMaximumSize,n)}}};var $p=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())})},Wi=class r{static createLongFormDid(e){return $p(this,void 0,void 0,function*(){let t=yield wn.createCreateRequest(e),n=yield r.computeDidUniqueSuffix(t.suffixData),i;dt.network===void 0||dt.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${dt.network}:${n}`;let o={suffixData:t.suffixData,delta:t.delta},s=er.canonicalizeAsBytes(o),c=wt.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return $p(this,void 0,void 0,function*(){let t=er.canonicalizeAsBytes(e),n=yield Ge.hash(t,dt.hashAlgorithmInMultihashCode);return wt.encode(n)})}};var et=2n**255n-19n,ra=2n**252n+27742317777372353535851937790883648493n,Qd=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,el=0x6666666666666666666666666666666666666666666666666666666666666658n,ta={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:et,n:ra,h:8,Gx:Qd,Gy:el},xt=(r="")=>{throw new Error(r)},zp=r=>typeof r=="string",tl=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?xt("Uint8Array expected"):r,Yi=r=>new Uint8Array(r),Fx=(r,e)=>tl(zp(r)?nl(r):Yi(r),e),q=(r,e=et)=>{let t=r%e;return t>=0n?t:e+t},Vp=r=>r instanceof xn?r:xt("Point expected"),Hp,xn=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,q(e.x*e.y))}static fromHex(e,t=!0){let{d:n}=ta;e=Fx(e,32);let i=e.slice();i[31]=e[31]&-129;let o=jx(i);o===0n||(t&&!(0n<o&&o<et)&&xt("bad y coord 1"),!t&&!(0n<o&&o<2n**256n)&&xt("bad y coord 2"));let s=q(o*o),c=q(s-1n),u=q(n*s+1n),{isValid:d,value:a}=Jx(c,u);d||xt("bad y coordinate 3");let l=(a&1n)===1n;return(e[31]&128)!==0!==l&&(a=q(-a)),new r(a,o,1n,q(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}=Vp(e),u=q(t*c),d=q(o*i),a=q(n*c),l=q(s*i);return u===d&&a===l}is0(){return this.equals(na)}negate(){return new r(q(-this.ex),this.ey,this.ez,q(-this.et))}double(){let{ex:e,ey:t,ez:n}=this,{a:i}=ta,o=q(e*e),s=q(t*t),c=q(2n*q(n*n)),u=q(i*o),d=e+t,a=q(q(d*d)-o-s),l=u+s,y=l-c,w=u-s,p=q(a*y),g=q(l*w),v=q(a*w),S=q(y*l);return new r(p,g,S,v)}add(e){let{ex:t,ey:n,ez:i,et:o}=this,{ex:s,ey:c,ez:u,et:d}=Vp(e),{a,d:l}=ta,y=q(t*s),w=q(n*c),p=q(o*l*d),g=q(i*u),v=q((t+n)*(s+c)-y-w),S=q(g-p),I=q(g+p),E=q(w-a*y),U=q(v*S),B=q(I*E),_=q(v*E),C=q(S*I);return new r(U,B,C,_)}mul(e,t=!0){if(e===0n)return t===!0?xt("cannot multiply by 0"):na;if(typeof e=="bigint"&&0n<e&&e<ra||xt("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(ia))return Wx(e).p;let n=na,i=ia;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(ta.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(ra/2n,!1).double();return ra%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=Gp(n);return q(n*i)!==1n&&xt("invalid inverse"),{x:q(e*i),y:q(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=qx(t);return n[31]|=e&1n?128:0,n}toHex(){return rl(this.toRawBytes())}};xn.BASE=new xn(Qd,el,1n,q(Qd*el));xn.ZERO=new xn(0n,1n,1n,0n);var{BASE:ia,ZERO:na}=xn,Jp=(r,e)=>r.toString(16).padStart(e,"0"),rl=r=>Array.from(r).map(e=>Jp(e,2)).join(""),nl=r=>{let e=r.length;(!zp(r)||e%2)&&xt("hex invalid 1");let t=Yi(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)&&xt("hex invalid 2"),t[n]=s}return t},qx=r=>nl(Jp(r,32*2)).reverse(),jx=r=>BigInt("0x"+rl(Yi(tl(r)).reverse())),Fp=(...r)=>{let e=Yi(r.reduce((n,i)=>n+tl(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},Gp=(r,e=et)=>{(r===0n||e<=0n)&&xt("no inverse n="+r+" mod="+e);let t=q(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?q(i,e):xt("no inverse")},yr=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=et;return t},zx=r=>{let t=r*r%et*r%et,n=yr(t,2n)*t%et,i=yr(n,1n)*r%et,o=yr(i,5n)*i%et,s=yr(o,10n)*o%et,c=yr(s,20n)*s%et,u=yr(c,40n)*c%et,d=yr(u,80n)*u%et,a=yr(d,80n)*u%et,l=yr(a,10n)*o%et;return{pow_p_5_8:yr(l,2n)*r%et,b2:t}},qp=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Jx=(r,e)=>{let t=q(e*e*e),n=q(t*t*e),i=zx(r*n).pow_p_5_8,o=q(r*t*i),s=q(e*o*o),c=o,u=q(o*qp),d=s===r,a=s===q(-r),l=s===q(-r*qp);return d&&(o=c),(a||l)&&(o=u),(q(o)&1n)===1n&&(o=q(-o)),{isValid:d||a,value:o}};var Zd;var jp=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Wp={bytesToHex:rl,hexToBytes:nl,concatBytes:Fp,mod:q,invert:Gp,randomBytes:r=>{let e=jp();return e||xt("crypto.getRandomValues must be defined"),e.getRandomValues(Yi(r))},sha512Async:async(...r)=>{let e=jp();e||xt("crypto.subtle or etc.sha512Async must be defined");let t=Fp(...r);return Yi(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(Wp,{sha512Sync:{configurable:!1,get(){return Zd},set(r){Zd||(Zd=r)}}});var Qn=8,Gx=()=>{let r=[],e=256/Qn+1,t=ia,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(Qn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Wx=r=>{let e=Hp||(Hp=Gx()),t=(a,l)=>{let y=l.negate();return a?y:l},n=na,i=ia,o=1+256/Qn,s=2**(Qn-1),c=BigInt(2**Qn-1),u=2**Qn,d=BigInt(Qn);for(let a=0;a<o;a++){let l=a*s,y=Number(r&c);r>>=d,y>s&&(y-=u,r+=1n);let w=l,p=l+Math.abs(y)-1,g=a%2!==0,v=y<0;y===0?i=i.add(t(g,e[w])):n=n.add(t(v,e[p]))}return{p:n,f:i}};var ol=2n**256n,ti=ol-0x1000003d1n,sl=ol-0x14551231950b75fc4402da1732fc9bebfn,ny=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,iy=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,oy={p:ti,n:sl,a:0n,b:7n,Gx:ny,Gy:iy},Xi=32,Yp=r=>V(V(r*r)*r+oy.b),We=(r="")=>{throw new Error(r)},ca=r=>typeof r=="bigint",sy=r=>typeof r=="string",il=r=>ca(r)&&0n<r&&r<ti,cy=r=>ca(r)&&0n<r&&r<sl,ay=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?We("Uint8Array expected"):r,ys=r=>new Uint8Array(r),cl=(r,e)=>ay(sy(r)?aa(r):ys(r),e),V=(r,e=ti)=>{let t=r%e;return t>=0n?t:e+t},Xp=r=>r instanceof Fr?r:We("Point expected"),Zp,Fr=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=cl(e);let t,n=e[0],i=e.subarray(1),o=Qp(i,0,Xi),s=e.length;if(s===33&&[2,3].includes(n)){il(o)||We("Point hex invalid: x not FE");let c=Xx(Yp(o)),u=(c&1n)===1n;(n&1)===1!==u&&(c=V(-c)),t=new r(o,c,1n)}return s===65&&n===4&&(t=new r(o,Qp(i,Xi,2*Xi),1n)),t?t.ok():We("Point is not on curve")}static fromPrivateKey(e){return ps.mul(Zx(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}=Xp(e),u=V(t*c),d=V(o*i),a=V(n*c),l=V(s*i);return u===d&&a===l}negate(){return new r(this.px,V(-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}=Xp(e),{a:u,b:d}=oy,a=0n,l=0n,y=0n,w=V(d*3n),p=V(t*o),g=V(n*s),v=V(i*c),S=V(t+n),I=V(o+s);S=V(S*I),I=V(p+g),S=V(S-I),I=V(t+i);let E=V(o+c);return I=V(I*E),E=V(p+v),I=V(I-E),E=V(n+i),a=V(s+c),E=V(E*a),a=V(g+v),E=V(E-a),y=V(u*I),a=V(w*v),y=V(a+y),a=V(g-y),y=V(g+y),l=V(a*y),g=V(p+p),g=V(g+p),v=V(u*v),I=V(w*I),g=V(g+v),v=V(p-v),v=V(u*v),I=V(I+v),p=V(g*I),l=V(l+p),p=V(E*I),a=V(S*a),a=V(a-p),p=V(S*g),y=V(E*y),y=V(y+p),new r(a,l,y)}mul(e,t=!0){if(!t&&e===0n)return oa;if(cy(e)||We("invalid scalar"),this.equals(ps))return tb(e).p;let n=oa,i=ps;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(oa))return{x:0n,y:0n};if(n===1n)return{x:e,y:t};let i=dy(n);return V(n*i)!==1n&&We("invalid inverse"),{x:V(e*i),y:V(t*i)}}assertValidity(){let{x:e,y:t}=this.aff();return(!il(e)||!il(t))&&We("Point invalid: x or y"),V(t*t)===Yp(e)?this:We("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")+ey(t)+(e?"":ey(n))}toRawBytes(e=!0){return aa(this.toHex(e))}};Fr.BASE=new Fr(ny,iy,1n);Fr.ZERO=new Fr(0n,1n,0n);var{BASE:ps,ZERO:oa}=Fr,uy=(r,e)=>r.toString(16).padStart(e,"0"),al=r=>Array.from(r).map(e=>uy(e,2)).join(""),aa=r=>{let e=r.length;(!sy(r)||e%2)&&We("hex invalid 1");let t=ys(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)&&We("hex invalid 2"),t[n]=s}return t},ua=r=>BigInt("0x"+(al(r)||"0")),Qp=(r,e,t)=>ua(r.slice(e,t)),ul=r=>ca(r)&&r>=0n&&r<ol?aa(uy(r,2*Xi)):We("bigint expected"),ey=r=>al(ul(r)),ty=(...r)=>{let e=ys(r.reduce((n,i)=>n+ay(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},dy=(r,e=ti)=>{(r===0n||e<=0n)&&We("no inverse n="+r+" mod="+e);let t=V(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?V(i,e):We("no inverse")},Xx=r=>{let e=1n;for(let t=r,n=(ti+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*t%ti),t=t*t%ti;return V(e*e)===r?e:We("sqrt invalid")},Zx=r=>(ca(r)||(r=ua(cl(r,Xi))),cy(r)?r:We("private key out of range"));var ry=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,sa;function Qx(r){r=cl(r);let e=Xi+8;(r.length<e||r.length>1024)&&We("expected proper params");let t=V(ua(r),sl-1n)+1n;return ul(t)}var ly={hexToBytes:aa,bytesToHex:al,concatBytes:ty,bytesToNumberBE:ua,numberToBytesBE:ul,mod:V,invert:dy,hmacSha256Async:async(r,...e)=>{let t=ry();if(!t)return We("etc.hmacSha256Async not set");let n=t.subtle,i=await n.importKey("raw",r,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return ys(await n.sign("HMAC",i,ty(...e)))},hmacSha256Sync:sa,hashToPrivateKey:Qx,randomBytes:r=>{let e=ry();return e||We("crypto.getRandomValues must be defined"),e.getRandomValues(ys(r))}};Object.defineProperties(ly,{hmacSha256Sync:{configurable:!1,get(){return sa},set(r){sa||(sa=r)}}});var ei=8,eb=()=>{let r=[],e=256/ei+1,t=ps,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(ei-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},tb=r=>{let e=Zp||(Zp=eb()),t=(a,l)=>{let y=l.negate();return a?y:l},n=oa,i=ps,o=1+256/ei,s=2**(ei-1),c=BigInt(2**ei-1),u=2**ei,d=BigInt(ei);for(let a=0;a<o;a++){let l=a*s,y=Number(r&c);r>>=d,y>s&&(y-=u,r+=1n);let w=l,p=l+Math.abs(y)-1,g=a%2!==0,v=y<0;y===0?i=i.add(t(g,e[w])):n=n.add(t(v,e[p]))}return{p:n,f:i}};var fy;(function(r){r.Mainnet="mainnet",r.Testnet="test"})(fy||(fy={}));var py;(function(r){r.Authentication="authentication",r.AssertionMethod="assertionMethod",r.CapabilityInvocation="capabilityInvocation",r.CapabilityDelegation="capabilityDelegation",r.KeyAgreement="keyAgreement"})(py||(py={}));var qr=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 Wi.createLongFormDid({document:o,recoveryKey:s,updateKey:c})}static async constructCreateRequest({ionDocument:e,recoveryKey:t,updateKey:n}){return await wn.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 Z({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 rb=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(rb||{}),nb={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},yy="https://ion.tbd.engineering",ri=class ri extends Ht{static async create({keyManager:e=new it,options:t={}}={}){if(t.verificationMethods?.some(p=>!(p.algorithm in nb)))throw new Error("One or more verification method algorithms are not supported");let n=t.verificationMethods?.filter(p=>"id"in p).map(p=>p.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(p=>!p.id||!p.type||!p.serviceEndpoint))throw new Error("One or more services are missing required properties");let i={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},o=[];for(let p of t.verificationMethods??[i]){let g=await e.generateKey({algorithm:p.algorithm}),v=await e.getPublicKey({keyUri:g});o.push({id:p.id,publicKeyJwk:v,purposes:p.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 qr.computeLongFormDidUri({recoveryKey:c,updateKey:d,services:t.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:y}=await ri.resolve(a,{gatewayUri:t.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${y?.error}`);let w=new mt({uri:a,document:l,metadata:{published:!1,canonicalId:a.split(":",3).join(":"),recoveryKey:c,updateKey:d},keyManager:e});if(t.publish??!0){let p=await ri.publish({did:w,gatewayUri:t.gatewayUri});w.metadata=p.didDocumentMetadata}return w}static async getSigningMethod({didDocument:e,methodId:t}){let n=Be.parse(e.id);if(n&&n.method!==this.methodName)throw new N("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>o.id===(t??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new N("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 it}){if(Be.parse(e.uri)?.method!==ri.methodName)throw new N("methodNotSupported","Method not supported");return await mt.import({portableDid:e,keyManager:t})}static async publish({did:e,gatewayUri:t=yy}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:dd({didDocument:e.document,methodId:s.id})}))??[],i=await qr.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await qr.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=qr.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=Be.parse(e);if(!n)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ri.methodName)return{...Ue,didResolutionMetadata:{error:"methodNotSupported"}};let i=t?.gatewayUri??yy;try{let o=qr.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(o);if(!s.ok)throw new N("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 N))throw new Error(o);return{...Ue,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};ri.methodName="ion";var my=ri;var ni=class ni extends Ht{static async create({keyManager:e=new it,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=O.object(o).toBase64Url(),c=`did:${ni.methodName}:${s}`,d=(await ni.resolve(c)).didDocument;return new mt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Be.parse(e.id);if(t&&t.method!==this.methodName)throw new N("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new N("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 it}){if(Be.parse(e.uri)?.method!==ni.methodName)throw new N("methodNotSupported","Method not supported");let i=await mt.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new N("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){let n=Be.parse(e),i;try{i=n?O.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ni.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}}};ni.methodName="jwk";var gy=ni;var ib={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},mr=class mr{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=mr.JWK_TO_MULTICODEC[n];if(i===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${n}'`);return{code:tt.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let n={"P-256":Ce.compressPublicKey,secp256k1:Oe.compressPublicKey}[e];if(!n)throw new N("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:De,"P-256":Ce,secp256k1:Oe}[e];if(!n)throw new N("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?tt.getNameFromCode({code:e}):t;let n=t,i=mr.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 ib))throw new N("invalidPublicKeyType",`Public key contains an unsupported key type: ${e?.crv??"undefined"}`);let t=await mr.keyConverter(e.crv).publicKeyToBytes({publicKey:e});/^(secp256k1|P-256|P-384|P-521)$/.test(e.crv)&&(t=await mr.keyCompressor(e.crv)({publicKeyBytes:t}));let{name:n}=await mr.jwkToMulticodec({jwk:e});return ld({keyBytes:t,multicodecName:n})}};mr.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv"},mr.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,237:32},mr.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 bn=mr;var ob=(n=>(n.Ed25519="Ed25519",n.secp256k1="secp256k1",n.secp256r1="secp256r1",n))(ob||{}),wy={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},gr=class gr extends Ht{static async create({keyManager:e=new it,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 bn.publicKeyToMultibaseId({publicKey:o}),c=`did:${gr.methodName}:${s}`,d=(await gr.resolve(c,t)).didDocument;return new mt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Be.parse(e.id);if(t&&t.method!==this.methodName)throw new N("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(o=>o.id===n);if(!(i&&i.publicKeyJwk))throw new N("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 it}){if(Be.parse(e.uri)?.method!==gr.methodName)throw new N("methodNotSupported","Method not supported");let i=await mt.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new N("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){try{let n=await gr.createDocument({didUri:e,options:t});return{...Ue,didDocument:n}}catch(n){if(!(n instanceof N))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=Be.parse(e);if(!c)throw new N("invalidDid",`Invalid DID URI: ${e}`);let u=c.id;if(c.method!==gr.methodName)throw new N("methodNotSupported",`Method not supported: ${c.method}`);if(!gr.validateIdentifier(c))throw new N("invalidDid",`Invalid DID URI: ${e}`);let d=await gr.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 ud({didDocument:s}).forEach(y=>{let w=wy[y];a.push(w)}),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}=hd({multibaseKeyId:t}),a=c.byteLength,l=bn.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(a!==l)throw new N("invalidPublicKeyLength",`Expected ${a} bytes. Actual: ${l}`);let y=!1;switch(d){case"secp256k1-pub":y=await Oe.validatePublicKey({publicKeyBytes:c});break;case"ed25519-pub":y=await De.validatePublicKey({publicKeyBytes:c});break}if(!y)throw new N("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${t}`;try{new URL(s.id)}catch{throw new N("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in wy))throw new N("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(o))throw new N("invalidPublicKeyType",`Specified '${o}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=o,s.controller=e,o==="Ed25519VerificationKey2020"&&(s.publicKeyMultibase=t),o==="JsonWebKey2020"){let{crv:p}=await bn.multicodecToJwk({code:u});s.publicKeyJwk=await bn.keyConverter(p).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&&pi(n)==="String"&&n.startsWith("z")}};gr.methodName="key";var xy=gr;var da=class da extends Ht{static async resolve(e,t){let n=Be.parse(e);if(!n)return{...Ue,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==da.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"}}}}};da.methodName="web";var by=da;var Ay=Sn(Ru(),1),Ty=Sn(dl(),1),Ey=class{constructor({db:e,location:t="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new Ay.Level(t),this.ttl=(0,Ty.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 By=Sn(dl(),1);var Sy=class{constructor({ttl:e="15m"}={}){this.cache=new va.default({ttl:(0,By.default)(e)})}async get(e){if(!e)throw new Error("Key cannot be null or undefined");return this.cache.get(e)}async set(e,t){this.cache.set(e,t)}async delete(e){this.cache.delete(e)}async clear(){this.cache.clear()}async close(){}};var Iy={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 Dy=class{constructor({cache:e,didResolvers:t}){this.didResolvers=new Map;this.cache=e||Iy;for(let n of t)this.didResolvers.set(n.methodName,n)}async resolve(e,t){let n=Be.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=Be.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:{}}}};export{Gc as AlgorithmToKeyTypeMap,mt as BearerDid,Sp as DID_DHT_SPECIFICATION_VERSION,pr as DNS_RECORD_TTL,Be as Did,Ip as DidDht,Yc as DidDhtDocument,fd as DidDhtRegisteredDidType,Ic as DidDhtRegisteredKeyType,gn as DidDhtUtils,pd as DidDhtVerificationRelationship,N as DidError,Pt as DidErrorCode,my as DidIon,rb as DidIonRegisteredKeyType,qr as DidIonUtils,gy as DidJwk,xy as DidKey,ob as DidKeyRegisteredKeyType,bn as DidKeyUtils,wy as DidKeyVerificationMethodType,Ht as DidMethod,Ey as DidResolverCacheLevel,Sy as DidResolverCacheMemory,Iy as DidResolverCacheNoop,hi as DidVerificationRelationship,by as DidWeb,Ue as EMPTY_DID_RESOLUTION_RESULT,Pd as KeyTypeToDefaultAlgorithmMap,ss as PROPERTY_SEPARATOR,Dy as UniversalResolver,ot as VALUE_SEPARATOR,Wc as chunkDataIfNeeded,Ud as createBep44PutMessage,xx as createTxtRecord,Cd as fromDnsPacket,Jc as identifierToIdentityKey,is as identifierToIdentityKeyBytes,kd as identityKeyToIdentifier,zf as isPortableDid,Gi as keyConverter,Od as parseBep44GetMessage,Yn as parseTxtDataToObject,Xn as parseTxtDataToString,Kd as pkarrGet,_d as pkarrPut,Rd as toDnsPacket,Jf as utils,os as validatePreviousDidProof};
2
2
  /*! Bundled license information:
3
3
 
4
4
  ieee754/index.js: