@enbox/dids 0.0.4 → 0.0.6

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 (55) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/methods/did-dht-dns.js +455 -0
  4. package/dist/esm/methods/did-dht-dns.js.map +1 -0
  5. package/dist/esm/methods/did-dht-pkarr.js +168 -0
  6. package/dist/esm/methods/did-dht-pkarr.js.map +1 -0
  7. package/dist/esm/methods/did-dht-types.js +116 -0
  8. package/dist/esm/methods/did-dht-types.js.map +1 -0
  9. package/dist/esm/methods/did-dht-utils.js +143 -0
  10. package/dist/esm/methods/did-dht-utils.js.map +1 -0
  11. package/dist/esm/methods/did-dht.js +65 -842
  12. package/dist/esm/methods/did-dht.js.map +1 -1
  13. package/dist/esm/methods/did-ion-utils.js +161 -0
  14. package/dist/esm/methods/did-ion-utils.js.map +1 -0
  15. package/dist/esm/methods/did-ion.js +4 -151
  16. package/dist/esm/methods/did-ion.js.map +1 -1
  17. package/dist/esm/methods/did-key-utils.js +235 -0
  18. package/dist/esm/methods/did-key-utils.js.map +1 -0
  19. package/dist/esm/methods/did-key.js +6 -222
  20. package/dist/esm/methods/did-key.js.map +1 -1
  21. package/dist/esm/utils.js +15 -19
  22. package/dist/esm/utils.js.map +1 -1
  23. package/dist/types/methods/did-dht-dns.d.ts +114 -0
  24. package/dist/types/methods/did-dht-dns.d.ts.map +1 -0
  25. package/dist/types/methods/did-dht-pkarr.d.ts +56 -0
  26. package/dist/types/methods/did-dht-pkarr.d.ts.map +1 -0
  27. package/dist/types/methods/did-dht-types.d.ts +286 -0
  28. package/dist/types/methods/did-dht-types.d.ts.map +1 -0
  29. package/dist/types/methods/did-dht-utils.d.ts +54 -0
  30. package/dist/types/methods/did-dht-utils.d.ts.map +1 -0
  31. package/dist/types/methods/did-dht.d.ts +42 -457
  32. package/dist/types/methods/did-dht.d.ts.map +1 -1
  33. package/dist/types/methods/did-ion-utils.d.ts +86 -0
  34. package/dist/types/methods/did-ion-utils.d.ts.map +1 -0
  35. package/dist/types/methods/did-ion.d.ts +2 -82
  36. package/dist/types/methods/did-ion.d.ts.map +1 -1
  37. package/dist/types/methods/did-key-utils.d.ts +138 -0
  38. package/dist/types/methods/did-key-utils.d.ts.map +1 -0
  39. package/dist/types/methods/did-key.d.ts +3 -124
  40. package/dist/types/methods/did-key.d.ts.map +1 -1
  41. package/dist/types/utils.d.ts +25 -25
  42. package/dist/types/utils.d.ts.map +1 -1
  43. package/dist/utils.js +1 -1
  44. package/dist/utils.js.map +4 -4
  45. package/package.json +4 -4
  46. package/src/methods/did-dht-dns.ts +516 -0
  47. package/src/methods/did-dht-pkarr.ts +192 -0
  48. package/src/methods/did-dht-types.ts +316 -0
  49. package/src/methods/did-dht-utils.ts +157 -0
  50. package/src/methods/did-dht.ts +122 -1128
  51. package/src/methods/did-ion-utils.ts +186 -0
  52. package/src/methods/did-ion.ts +14 -190
  53. package/src/methods/did-key-utils.ts +258 -0
  54. package/src/methods/did-key.ts +14 -266
  55. package/src/utils.ts +31 -30
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Ky=Object.create;var ua=Object.defineProperty;var _y=Object.getOwnPropertyDescriptor;var Uy=Object.getOwnPropertyNames;var Oy=Object.getPrototypeOf,ky=Object.prototype.hasOwnProperty;var se=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),da=(r,e)=>{for(var t in e)ua(r,t,{get:e[t],enumerable:!0})},Cy=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Uy(e))!ky.call(r,i)&&i!==t&&ua(r,i,{get:()=>e[i],enumerable:!(n=_y(e,i))||n.enumerable});return r};var An=(r,e,t)=>(t=r!=null?Ky(Oy(r)):{},Cy(e||!r||!r.__esModule?ua(t,"default",{value:r,enumerable:!0}):t,r));var il=se((cb,nl)=>{var Ry=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,xs=()=>Ry.now(),Py=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),la=r=>r===1/0||Py(r),ha=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&&!la(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!la(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(!la(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()}};nl.exports=ha});var vl=se(bl=>{"use strict";bl.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((ov,El)=>{"use strict";El.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 Sl=se(vs=>{"use strict";vs.byteLength=y0;vs.toByteArray=g0;vs.fromByteArray=b0;var ir=[],Rt=[],p0=typeof Uint8Array<"u"?Uint8Array:Array,Ia="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(In=0,Al=Ia.length;In<Al;++In)ir[In]=Ia[In],Rt[Ia.charCodeAt(In)]=In;var In,Al;Rt[45]=62;Rt[95]=63;function Tl(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 y0(r){var e=Tl(r),t=e[0],n=e[1];return(t+n)*3/4-n}function m0(r,e,t){return(e+t)*3/4-t}function g0(r){var e,t=Tl(r),n=t[0],i=t[1],o=new p0(m0(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=Rt[r.charCodeAt(u)]<<18|Rt[r.charCodeAt(u+1)]<<12|Rt[r.charCodeAt(u+2)]<<6|Rt[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Rt[r.charCodeAt(u)]<<2|Rt[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=Rt[r.charCodeAt(u)]<<10|Rt[r.charCodeAt(u+1)]<<4|Rt[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function w0(r){return ir[r>>18&63]+ir[r>>12&63]+ir[r>>6&63]+ir[r&63]}function x0(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(w0(n));return i.join("")}function b0(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(x0(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 Bl=se(Da=>{Da.read=function(r,e,t,n,i){var o,s,c=i*8-n-1,u=(1<<c)-1,d=u>>1,a=-7,l=t?i-1:0,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)};Da.write=function(r,e,t,n,i,o){var s,c,u,d=o*8-i-1,a=(1<<d)-1,l=a>>1,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 Ts=se(gi=>{"use strict";var Ka=Sl(),yi=Bl(),Il=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;gi.Buffer=A;gi.SlowBuffer=B0;gi.INSPECT_MAX_BYTES=50;var Es=2147483647;gi.kMaxLength=Es;A.TYPED_ARRAY_SUPPORT=v0();!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 v0(){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 Er(r){if(r>Es)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 ka(r)}return Ul(r,e,t)}A.poolSize=8192;function Ul(r,e,t){if(typeof r=="string")return A0(r,e);if(ArrayBuffer.isView(r))return T0(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 Ua(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=S0(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 Ul(r,e,t)};Object.setPrototypeOf(A.prototype,Uint8Array.prototype);Object.setPrototypeOf(A,Uint8Array);function Ol(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 E0(r,e,t){return Ol(r),r<=0?Er(r):e!==void 0?typeof t=="string"?Er(r).fill(e,t):Er(r).fill(e):Er(r)}A.alloc=function(r,e,t){return E0(r,e,t)};function ka(r){return Ol(r),Er(r<0?0:Ca(r)|0)}A.allocUnsafe=function(r){return ka(r)};A.allocUnsafeSlow=function(r){return ka(r)};function A0(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!A.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=kl(r,e)|0,n=Er(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function _a(r){let e=r.length<0?0:Ca(r.length)|0,t=Er(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function T0(r){if(or(r,Uint8Array)){let e=new Uint8Array(r);return Ua(e.buffer,e.byteOffset,e.byteLength)}return _a(r)}function Ua(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 S0(r){if(A.isBuffer(r)){let e=Ca(r.length)|0,t=Er(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Pa(r.length)?Er(0):_a(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _a(r.data)}function Ca(r){if(r>=Es)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Es.toString(16)+" bytes");return r|0}function B0(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 kl(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 Oa(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Hl(r).length;default:if(i)return n?-1:Oa(r).length;e=(""+e).toLowerCase(),i=!0}}A.byteLength=kl;function I0(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 M0(this,e,t);case"utf8":case"utf-8":return Rl(this,e,t);case"ascii":return R0(this,e,t);case"latin1":case"binary":return P0(this,e,t);case"base64":return k0(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L0(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}A.prototype._isBuffer=!0;function Dn(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)Dn(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)Dn(this,t,t+3),Dn(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)Dn(this,t,t+7),Dn(this,t+1,t+6),Dn(this,t+2,t+5),Dn(this,t+3,t+4);return this};A.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Rl(this,0,e):I0.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=gi.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};Il&&(A.prototype[Il]=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 Cl(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,Pa(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:Dl(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):Dl(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function Dl(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 Cl(this,e,t,n,!0)};A.prototype.lastIndexOf=function(e,t,n){return Cl(this,e,t,n,!1)};function D0(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(Pa(c))return s;r[t+s]=c}return s}function K0(r,e,t,n){return As(Oa(e,r.length-t),r,t,n)}function _0(r,e,t,n){return As(H0(e),r,t,n)}function U0(r,e,t,n){return As(Hl(e),r,t,n)}function O0(r,e,t,n){return As(F0(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 D0(this,e,t,n);case"utf8":case"utf-8":return K0(this,e,t,n);case"ascii":case"latin1":case"binary":return _0(this,e,t,n);case"base64":return U0(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O0(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 k0(r,e,t){return e===0&&t===r.length?Ka.fromByteArray(r):Ka.fromByteArray(r.slice(e,t))}function Rl(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 C0(n)}var Kl=4096;function C0(r){let e=r.length;if(e<=Kl)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Kl));return t}function R0(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 P0(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 M0(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+=q0[r[o]];return i}function L0(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=Jr(function(e){e=e>>>0,mi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fo(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=Jr(function(e){e=e>>>0,mi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fo(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=Jr(function(e){e=e>>>0,mi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fo(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=Jr(function(e){e=e>>>0,mi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fo(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),yi.read(this,e,!0,23,4)};A.prototype.readFloatBE=function(e,t){return e=e>>>0,t||Je(e,4,this.length),yi.read(this,e,!1,23,4)};A.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||Je(e,8,this.length),yi.read(this,e,!0,52,8)};A.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||Je(e,8,this.length),yi.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 Pl(r,e,t,n,i){Vl(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 Ml(r,e,t,n,i){Vl(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=Jr(function(e,t=0){return Pl(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});A.prototype.writeBigUInt64BE=Jr(function(e,t=0){return Ml(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=Jr(function(e,t=0){return Pl(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});A.prototype.writeBigInt64BE=Jr(function(e,t=0){return Ml(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ll(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 Nl(r,e,t,n,i){return e=+e,t=t>>>0,i||Ll(r,e,t,4,34028234663852886e22,-34028234663852886e22),yi.write(r,e,t,n,23,4),t+4}A.prototype.writeFloatLE=function(e,t,n){return Nl(this,e,t,!0,n)};A.prototype.writeFloatBE=function(e,t,n){return Nl(this,e,t,!1,n)};function $l(r,e,t,n,i){return e=+e,t=t>>>0,i||Ll(r,e,t,8,17976931348623157e292,-17976931348623157e292),yi.write(r,e,t,n,52,8),t+8}A.prototype.writeDoubleLE=function(e,t,n){return $l(this,e,t,!0,n)};A.prototype.writeDoubleBE=function(e,t,n){return $l(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 pi={};function Ra(r,e,t){pi[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}`}}}Ra("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Ra("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Ra("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=_l(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=_l(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function _l(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 N0(r,e,t){mi(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&fo(e,r.length-(t+1))}function Vl(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 pi.ERR_OUT_OF_RANGE("value",c,r)}N0(n,i,o)}function mi(r,e){if(typeof r!="number")throw new pi.ERR_INVALID_ARG_TYPE(e,"number",r)}function fo(r,e,t){throw Math.floor(r)!==r?(mi(r,t),new pi.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new pi.ERR_BUFFER_OUT_OF_BOUNDS:new pi.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var $0=/[^+/0-9A-Za-z-_]/g;function V0(r){if(r=r.split("=")[0],r=r.trim().replace($0,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Oa(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 H0(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function F0(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 Hl(r){return Ka.toByteArray(V0(r))}function As(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 Pa(r){return r!==r}var q0=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 Jr(r){return typeof BigInt>"u"?j0:r}function j0(){throw new Error("BigInt not supported")}});var La=se((dv,Fl)=>{"use strict";var Ma=null;Fl.exports=function(){return Ma===null&&(Ma={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ma}});var Va=se(ql=>{"use strict";var Na=jt(),z0=new Set(["buffer","view","utf8"]),$a=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 Na(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Na(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Na(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ql.Encoding=$a});var ja=se(Ss=>{"use strict";var{Buffer:Fa}=Ts()||{},{Encoding:qa}=Va(),J0=La(),po=class extends qa{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new yo({encode:this.encode,decode:e=>this.decode(Fa.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},yo=class extends qa{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new po({encode:e=>{let t=this.encode(e);return Fa.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Ha=class extends qa{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new po({encode:e=>Fa.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=J0();return new yo({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};Ss.BufferFormat=po;Ss.ViewFormat=yo;Ss.UTF8Format=Ha});var Gl=se(Kn=>{"use strict";var{Buffer:nt}=Ts()||{Buffer:{isBuffer:()=>!1}},{textEncoder:zl,textDecoder:jl}=La()(),{BufferFormat:mo,ViewFormat:za,UTF8Format:Jl}=ja(),Bs=r=>r;Kn.utf8=new Jl({encode:function(r){return nt.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?jl.decode(r):String(r)},decode:Bs,name:"utf8",createViewTranscoder(){return new za({encode:function(r){return ArrayBuffer.isView(r)?r:zl.encode(r)},decode:function(r){return jl.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new mo({encode:function(r){return nt.isBuffer(r)?r:ArrayBuffer.isView(r)?nt.from(r.buffer,r.byteOffset,r.byteLength):nt.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Kn.json=new Jl({encode:JSON.stringify,decode:JSON.parse,name:"json"});Kn.buffer=new mo({encode:function(r){return nt.isBuffer(r)?r:ArrayBuffer.isView(r)?nt.from(r.buffer,r.byteOffset,r.byteLength):nt.from(String(r),"utf8")},decode:Bs,name:"buffer",createViewTranscoder(){return new za({encode:function(r){return ArrayBuffer.isView(r)?r:nt.from(String(r),"utf8")},decode:function(r){return nt.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Kn.view=new za({encode:function(r){return ArrayBuffer.isView(r)?r:zl.encode(r)},decode:Bs,name:"view",createBufferTranscoder(){return new mo({encode:function(r){return nt.isBuffer(r)?r:ArrayBuffer.isView(r)?nt.from(r.buffer,r.byteOffset,r.byteLength):nt.from(String(r),"utf8")},decode:Bs,name:`${this.name}+buffer`})}});Kn.hex=new mo({encode:function(r){return nt.isBuffer(r)?r:nt.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Kn.base64=new mo({encode:function(r){return nt.isBuffer(r)?r:nt.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var Xl=se(Yl=>{"use strict";var Wl=jt(),Ds=Gl(),{Encoding:G0}=Va(),{BufferFormat:W0,ViewFormat:Y0,UTF8Format:X0}=ja(),go=Symbol("formats"),Is=Symbol("encodings"),Z0=new Set(["buffer","view","utf8"]),Ja=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>Z0.has(t)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[Is]=new Map,this[go]=new Set(e);for(let t in Ds)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Is].values()))}encoding(e){let t=this[Is].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=rm[e],!t)throw new Wl(`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=Q0(e)}let{name:n,format:i}=t;if(!this[go].has(i))if(this[go].has("view"))t=t.createViewTranscoder();else if(this[go].has("buffer"))t=t.createBufferTranscoder();else if(this[go].has("utf8"))t=t.createUTF8Transcoder();else throw new Wl(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[Is].set(o,t)}return t}};Yl.Transcoder=Ja;function Q0(r){if(r instanceof G0)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${nm++}`;switch(em(r)){case"view":return new Y0({...r,name:t});case"utf8":return new X0({...r,name:t});case"buffer":return new W0({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function em(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 tm={binary:Ds.buffer,"utf-8":Ds.utf8},rm={...Ds,...tm},nm=0});var Ql=se((yv,Ga)=>{"use strict";var im=Object.prototype.hasOwnProperty,ct="~";function wo(){}Object.create&&(wo.prototype=Object.create(null),new wo().__proto__||(ct=!1));function om(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Zl(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new om(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 Ks(r,e){--r._eventsCount===0?r._events=new wo:delete r._events[e]}function it(){this._events=new wo,this._eventsCount=0}it.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)im.call(t,n)&&e.push(ct?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};it.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};it.prototype.listenerCount=function(e){var t=ct?ct+e:e,n=this._events[t];return n?n.fn?1:n.length:0};it.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};it.prototype.on=function(e,t,n){return Zl(this,e,t,n,!1)};it.prototype.once=function(e,t,n){return Zl(this,e,t,n,!0)};it.prototype.removeListener=function(e,t,n,i){var o=ct?ct+e:e;if(!this._events[o])return this;if(!t)return Ks(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&Ks(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:Ks(this,o)}return this};it.prototype.removeAllListeners=function(e){var t;return e?(t=ct?ct+e:e,this._events[t]&&Ks(this,t)):(this._events=new wo,this._eventsCount=0),this};it.prototype.off=it.prototype.removeListener;it.prototype.addListener=it.prototype.on;it.prefixed=ct;it.EventEmitter=it;typeof Ga<"u"&&(Ga.exports=it)});var th=se((mv,eh)=>{eh.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var xo=se(Wa=>{"use strict";var rh=th();Wa.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};Wa.fromPromise=function(r,e){if(e===void 0)return r;r.then(function(t){rh(()=>e(null,t))}).catch(function(t){rh(()=>e(t))})}});var _s=se(Ya=>{"use strict";Ya.getCallback=function(r,e){return typeof r=="function"?r:e};Ya.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var Qr=se(Cs=>{"use strict";var{fromCallback:Xa}=xo(),At=jt(),{getOptions:Za,getCallback:nh}=_s(),_n=Symbol("promise"),wi=Symbol("callback"),sr=Symbol("working"),Un=Symbol("handleOne"),Ar=Symbol("handleMany"),Qa=Symbol("autoClose"),Xr=Symbol("finishWork"),cr=Symbol("returnMany"),Gr=Symbol("closing"),bo=Symbol("handleClose"),Us=Symbol("closed"),vo=Symbol("closeCallbacks"),Yr=Symbol("keyEncoding"),On=Symbol("valueEncoding"),eu=Symbol("abortOnClose"),Os=Symbol("legacy"),tu=Symbol("keys"),ru=Symbol("values"),Wr=Symbol("limit"),Pt=Symbol("count"),ks=Object.freeze({}),sm=()=>{},ih=!1,Eo=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[Us]=!1,this[vo]=[],this[sr]=!1,this[Gr]=!1,this[Qa]=!1,this[wi]=null,this[Un]=this[Un].bind(this),this[Ar]=this[Ar].bind(this),this[bo]=this[bo].bind(this),this[Yr]=t[Yr],this[On]=t[On],this[Os]=n,this[Wr]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[Pt]=0,this[eu]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Pt]}get limit(){return this[Wr]}next(e){let t;if(e===void 0)t=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[Os]?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[Gr]?this.nextTick(e,new At("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(e,new At("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[sr]=!0,this[wi]=e,this[Pt]>=this[Wr]?this.nextTick(this[Un],null):this._next(this[Un])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=nh(t,n),n=Xa(n,_n),t=Za(t,ks),Number.isInteger(e)?(this[Gr]?this.nextTick(n,new At("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(n,new At("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[Wr]<1/0&&(e=Math.min(e,this[Wr]-this[Pt])),this[sr]=!0,this[wi]=n,e<=0?this.nextTick(this[Ar],null,[]):this._nextv(e,t,this[Ar])),n[_n]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[_n])}_nextv(e,t,n){let i=[],o=(s,c,u)=>{if(s)return n(s);if(this[Os]?c===void 0&&u===void 0:c===void 0)return n(null,i);i.push(this[Os]?[c,u]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=nh(e,t),t=Xa(t,_n),e=Za(e,ks),this[Gr]?this.nextTick(t,new At("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[sr]?this.nextTick(t,new At("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[sr]=!0,this[wi]=t,this[Qa]=!0,this[Pt]>=this[Wr]?this.nextTick(this[Ar],null,[]):this._all(e,this[Ar])),t[_n]}_all(e,t){let n=this[Pt],i=[],o=()=>{let c=this[Wr]<1/0?Math.min(1e3,this[Wr]-n):1e3;c<=0?this.nextTick(t,null,i):this._nextv(c,ks,s)},s=(c,u)=>{c?t(c):u.length===0?t(null,i):(i.push.apply(i,u),n+=u.length,o())};o()}[Xr](){let e=this[wi];return this[eu]&&e===null?sm:(this[sr]=!1,this[wi]=null,this[Gr]&&this._close(this[bo]),e)}[cr](e,t,n){this[Qa]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=Za(t,ks),!this[Gr]){if(this[sr])throw new At("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[Yr]),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 At("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=Xa(e,_n),this[Us]?this.nextTick(e):this[Gr]?this[vo].push(e):(this[Gr]=!0,this[vo].push(e),this[sr]?this[eu]&&this[Xr]()(new At("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[bo])),e[_n]}_close(e){this.nextTick(e)}[bo](){this[Us]=!0,this.db.detachResource(this);let e=this[vo];this[vo]=[];for(let t of e)t()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Us]||await this.close()}}},xi=class extends Eo{constructor(e,t){super(e,t,!0),this[tu]=t.keys!==!1,this[ru]=t.values!==!1}[Un](e,t,n){let i=this[Xr]();if(e)return i(e);try{t=this[tu]&&t!==void 0?this[Yr].decode(t):void 0,n=this[ru]&&n!==void 0?this[On].decode(n):void 0}catch(o){return i(new Zr("entry",o))}t===void 0&&n===void 0||this[Pt]++,i(null,t,n)}[Ar](e,t){let n=this[Xr]();if(e)return this[cr](n,e);try{for(let i of t){let o=i[0],s=i[1];i[0]=this[tu]&&o!==void 0?this[Yr].decode(o):void 0,i[1]=this[ru]&&s!==void 0?this[On].decode(s):void 0}}catch(i){return this[cr](n,new Zr("entries",i))}this[Pt]+=t.length,this[cr](n,null,t)}end(e){return!ih&&typeof console<"u"&&(ih=!0,console.warn(new At("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)}},nu=class extends Eo{constructor(e,t){super(e,t,!1)}[Un](e,t){let n=this[Xr]();if(e)return n(e);try{t=t!==void 0?this[Yr].decode(t):void 0}catch(i){return n(new Zr("key",i))}t!==void 0&&this[Pt]++,n(null,t)}[Ar](e,t){let n=this[Xr]();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[Yr].decode(o):void 0}}catch(i){return this[cr](n,new Zr("keys",i))}this[Pt]+=t.length,this[cr](n,null,t)}},iu=class extends Eo{constructor(e,t){super(e,t,!1)}[Un](e,t){let n=this[Xr]();if(e)return n(e);try{t=t!==void 0?this[On].decode(t):void 0}catch(i){return n(new Zr("value",i))}t!==void 0&&this[Pt]++,n(null,t)}[Ar](e,t){let n=this[Xr]();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[On].decode(o):void 0}}catch(i){return this[cr](n,new Zr("values",i))}this[Pt]+=t.length,this[cr](n,null,t)}},Zr=class extends At{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(xi.prototype,r.split(" ")[0],{get(){throw new At(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new At(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});xi.keyEncoding=Yr;xi.valueEncoding=On;Cs.AbstractIterator=xi;Cs.AbstractKeyIterator=nu;Cs.AbstractValueIterator=iu});var oh=se(ou=>{"use strict";var{AbstractKeyIterator:cm,AbstractValueIterator:am}=Qr(),kn=Symbol("iterator"),Ao=Symbol("callback"),bi=Symbol("handleOne"),Cn=Symbol("handleMany"),To=class extends cm{constructor(e,t){super(e,t),this[kn]=e.iterator({...t,keys:!0,values:!1}),this[bi]=this[bi].bind(this),this[Cn]=this[Cn].bind(this)}},Rs=class extends am{constructor(e,t){super(e,t),this[kn]=e.iterator({...t,keys:!1,values:!0}),this[bi]=this[bi].bind(this),this[Cn]=this[Cn].bind(this)}};for(let r of[To,Rs]){let e=r===To,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[Ao]=n,this[kn].next(this[bi])},r.prototype[bi]=function(n,i,o){let s=this[Ao];n?s(n):s(null,e?i:o)},r.prototype._nextv=function(n,i,o){this[Ao]=o,this[kn].nextv(n,i,this[Cn])},r.prototype._all=function(n,i){this[Ao]=i,this[kn].all(n,this[Cn])},r.prototype[Cn]=function(n,i){let o=this[Ao];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[kn].seek(n,i)},r.prototype._close=function(n){this[kn].close(n)}}ou.DefaultKeyIterator=To;ou.DefaultValueIterator=Rs});var sh=se(Vs=>{"use strict";var{AbstractIterator:um,AbstractKeyIterator:dm,AbstractValueIterator:lm}=Qr(),su=jt(),ft=Symbol("nut"),Ns=Symbol("undefer"),$s=Symbol("factory"),Ps=class extends um{constructor(e,t){super(e,t),this[ft]=null,this[$s]=()=>e.iterator(t),this.db.defer(()=>this[Ns]())}},Ms=class extends dm{constructor(e,t){super(e,t),this[ft]=null,this[$s]=()=>e.keys(t),this.db.defer(()=>this[Ns]())}},Ls=class extends lm{constructor(e,t){super(e,t),this[ft]=null,this[$s]=()=>e.values(t),this.db.defer(()=>this[Ns]())}};for(let r of[Ps,Ms,Ls])r.prototype[Ns]=function(){this.db.status==="open"&&(this[ft]=this[$s]())},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 su("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 su("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 su("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)};Vs.DeferredIterator=Ps;Vs.DeferredKeyIterator=Ms;Vs.DeferredValueIterator=Ls});var au=se(ah=>{"use strict";var{fromCallback:ch}=xo(),Hs=jt(),{getCallback:hm,getOptions:fm}=_s(),Fs=Symbol("promise"),Mt=Symbol("status"),vi=Symbol("operations"),So=Symbol("finishClose"),Ei=Symbol("closeCallbacks"),cu=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[vi]=[],this[Ei]=[],this[Mt]="open",this[So]=this[So].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[vi].length}put(e,t,n){if(this[Mt]!=="open")throw new Hs("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(e)||this.db._checkValue(t);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),u=o.valueEncoding(n&&n.valueEncoding),d=c.format;n={...n,keyEncoding:d,valueEncoding:u.format},o!==this.db&&(n.sublevel=null);let a=o.prefixKey(c.encode(e),d),l=u.encode(t);return this._put(a,l,n),this[vi].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[Mt]!=="open")throw new Hs("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(e);if(n)throw n;let i=t&&t.sublevel!=null?t.sublevel:this.db,o=t,s=i.keyEncoding(t&&t.keyEncoding),c=s.format;return t={...t,keyEncoding:c},i!==this.db&&(t.sublevel=null),this._del(i.prefixKey(s.encode(e),c),t),this[vi].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[Mt]!=="open")throw new Hs("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[vi]=[],this}_clear(){}write(e,t){return t=hm(e,t),t=ch(t,Fs),e=fm(e),this[Mt]!=="open"?this.nextTick(t,new Hs("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[Mt]="writing",this._write(e,n=>{this[Mt]="closing",this[Ei].push(()=>t(n)),n||this.db.emit("batch",this[vi]),this._close(this[So])})),t[Fs]}_write(e,t){}close(e){return e=ch(e,Fs),this[Mt]==="closing"?this[Ei].push(e):this[Mt]==="closed"?this.nextTick(e):(this[Ei].push(e),this[Mt]!=="writing"&&(this[Mt]="closing",this._close(this[So]))),e[Fs]}_close(e){this.nextTick(e)}[So](){this[Mt]="closed",this.db.detachResource(this);let e=this[Ei];this[Ei]=[];for(let t of e)t()}};ah.AbstractChainedBatch=cu});var dh=se(uh=>{"use strict";var{AbstractChainedBatch:pm}=au(),ym=jt(),Ai=Symbol("encoded"),uu=class extends pm{constructor(e){super(e),this[Ai]=[]}_put(e,t,n){this[Ai].push({...n,type:"put",key:e,value:t})}_del(e,t){this[Ai].push({...t,type:"del",key:e})}_clear(){this[Ai]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[Ai].length===0?this.nextTick(t):this.db._batch(this[Ai],e,t):this.nextTick(t,new ym("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};uh.DefaultChainedBatch=uu});var fh=se((Tv,hh)=>{"use strict";var lh=jt(),mm=Object.prototype.hasOwnProperty,gm=new Set(["lt","lte","gt","gte"]);hh.exports=function(r,e){let t={};for(let n in r)if(mm.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new lh(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new lh("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});gm.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 du=se((Sv,yh)=>{var ph;yh.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(ph||(ph=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var wh=se((Bv,gh)=>{"use strict";var mh=du();gh.exports=function(r,...e){e.length===0?mh(r):mh(()=>r(...e))}});var xh=se(qs=>{"use strict";var{AbstractIterator:wm,AbstractKeyIterator:xm,AbstractValueIterator:bm}=Qr(),Ti=Symbol("unfix"),zt=Symbol("iterator"),Rn=Symbol("handleOne"),en=Symbol("handleMany"),Tr=Symbol("callback"),Bo=class extends wm{constructor(e,t,n,i){super(e,t),this[zt]=n,this[Ti]=i,this[Rn]=this[Rn].bind(this),this[en]=this[en].bind(this),this[Tr]=null}[Rn](e,t,n){let i=this[Tr];if(e)return i(e);t!==void 0&&(t=this[Ti](t)),i(e,t,n)}[en](e,t){let n=this[Tr];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[Ti](o))}n(e,t)}},Io=class extends xm{constructor(e,t,n,i){super(e,t),this[zt]=n,this[Ti]=i,this[Rn]=this[Rn].bind(this),this[en]=this[en].bind(this),this[Tr]=null}[Rn](e,t){let n=this[Tr];if(e)return n(e);t!==void 0&&(t=this[Ti](t)),n(e,t)}[en](e,t){let n=this[Tr];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[Ti](o))}n(e,t)}},Do=class extends bm{constructor(e,t,n){super(e,t),this[zt]=n}};for(let r of[Bo,Io])r.prototype._next=function(e){this[Tr]=e,this[zt].next(this[Rn])},r.prototype._nextv=function(e,t,n){this[Tr]=n,this[zt].nextv(e,t,this[en])},r.prototype._all=function(e,t){this[Tr]=t,this[zt].all(e,this[en])};for(let r of[Do])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[Bo,Io,Do])r.prototype._seek=function(e,t){this[zt].seek(e,t)},r.prototype._close=function(e){this[zt].close(e)};qs.AbstractSublevelIterator=Bo;qs.AbstractSublevelKeyIterator=Io;qs.AbstractSublevelValueIterator=Do});var Ah=se((Dv,Eh)=>{"use strict";var lu=jt(),{Buffer:pu}=Ts()||{},{AbstractSublevelIterator:vm,AbstractSublevelKeyIterator:Em,AbstractSublevelValueIterator:Am}=xh(),Sr=Symbol("prefix"),bh=Symbol("upperBound"),Ko=Symbol("prefixRange"),Tt=Symbol("parent"),hu=Symbol("unfix"),vh=new TextEncoder,Tm={separator:"!"};Eh.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new lu("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new lu("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?Tm:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...u}=e.defaults(o);i=Bm(i,s);let d=s.charCodeAt(0)+1,a=n[Tt]||n;if(!vh.encode(i).every(w=>w>d&&w<127))throw new lu(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Sm(a,c),u);let l=(n.prefix||"")+s+i+s,y=l.slice(0,-1)+String.fromCharCode(d);this[Tt]=a,this[Sr]=new js(l),this[bh]=new js(y),this[hu]=new yu,this.nextTick=a.nextTick}prefixKey(n,i){if(i==="utf8")return this[Sr].utf8+n;if(n.byteLength===0)return this[Sr][i];if(i==="view"){let o=this[Sr].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Sr].buffer;return pu.concat([o,n],o.byteLength+n.byteLength)}}[Ko](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[Sr][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[bh][i]}get prefix(){return this[Sr].utf8}get db(){return this[Tt]}_open(n,i){this[Tt].open({passive:!0},i)}_put(n,i,o,s){this[Tt].put(n,i,o,s)}_get(n,i,o){this[Tt].get(n,i,o)}_getMany(n,i,o){this[Tt].getMany(n,i,o)}_del(n,i,o){this[Tt].del(n,i,o)}_batch(n,i,o){this[Tt].batch(n,i,o)}_clear(n,i){this[Ko](n,n.keyEncoding),this[Tt].clear(n,i)}_iterator(n){this[Ko](n,n.keyEncoding);let i=this[Tt].iterator(n),o=this[hu].get(this[Sr].utf8.length,n.keyEncoding);return new vm(this,n,i,o)}_keys(n){this[Ko](n,n.keyEncoding);let i=this[Tt].keys(n),o=this[hu].get(this[Sr].utf8.length,n.keyEncoding);return new Em(this,n,i,o)}_values(n){this[Ko](n,n.keyEncoding);let i=this[Tt].values(n);return new Am(this,n,i)}}return{AbstractSublevel:e}};var Sm=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:fu(r,"utf8"),buffer:fu(r,"buffer"),view:fu(r,"view")}}},fu=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},js=class{constructor(e){this.utf8=e,this.view=vh.encode(e),this.buffer=pu?pu.from(this.view.buffer,0,this.view.byteLength):{}}},yu=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}},Bm=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 bu=se(xu=>{"use strict";var{supports:Im}=vl(),{Transcoder:Dm}=Xl(),{EventEmitter:Km}=Ql(),{fromCallback:tn}=xo(),Jt=jt(),{AbstractIterator:Pn}=Qr(),{DefaultKeyIterator:_m,DefaultValueIterator:Um}=oh(),{DeferredIterator:Om,DeferredKeyIterator:km,DeferredValueIterator:Cm}=sh(),{DefaultChainedBatch:Th}=dh(),{getCallback:Mn,getOptions:rn}=_s(),zs=fh(),oe=Symbol("promise"),Br=Symbol("landed"),Ln=Symbol("resources"),mu=Symbol("closeResources"),_o=Symbol("operations"),Uo=Symbol("undefer"),Js=Symbol("deferOpen"),Sh=Symbol("options"),ce=Symbol("status"),Nn=Symbol("defaultOptions"),Si=Symbol("transcoder"),Gs=Symbol("keyEncoding"),gu=Symbol("valueEncoding"),Rm=()=>{},Oo=class extends Km{constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=rn(t);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=t;this[Ln]=new Set,this[_o]=[],this[Js]=!0,this[Sh]=s,this[ce]="opening",this.supports=Im(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[Si]=new Dm(Pm(this)),this[Gs]=this[Si].encoding(n||"utf8"),this[gu]=this[Si].encoding(i||"utf8");for(let c of this[Si].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Nn]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[Gs].commonName,valueEncoding:this[gu].commonName}),key:Object.freeze({keyEncoding:this[Gs].commonName})},this.nextTick(()=>{this[Js]&&this.open({passive:!1},Rm)})}get status(){return this[ce]}keyEncoding(e){return this[Si].encoding(e??this[Gs])}valueEncoding(e){return this[Si].encoding(e??this[gu])}open(e,t){t=Mn(e,t),t=tn(t,oe),e={...this[Sh],...rn(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[ce]==="closing"||this[ce]==="opening"?this.once(Br,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(Br,n):this.nextTick(n):this[ce]==="closed"||this[Js]?(this[Js]=!1,this[ce]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[ce]="closed",this[mu](()=>{this.emit(Br),n(i)}),this[Uo]();return}this[ce]="open",this[Uo](),this.emit(Br),this[ce]==="open"&&this.emit("open"),this[ce]==="open"&&this.emit("ready"),n()})):this[ce]==="open"?this.nextTick(n):this.once(Br,()=>this.open(e,t)),t[oe]}_open(e,t){this.nextTick(t)}close(e){e=tn(e,oe);let t=n=>{this[ce]==="opening"||this[ce]==="closing"?this.once(Br,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[Uo](),this.emit(Br),t(i)};this[mu](()=>{this._close(i=>{if(i)return n(i);this[ce]="closed",this[Uo](),this.emit(Br),this[ce]==="closed"&&this.emit("closed"),t()})})}else this[ce]==="closed"?this.nextTick(t):this.once(Br,()=>this.close(e));return e[oe]}[mu](e){if(this[Ln].size===0)return this.nextTick(e);let t=this[Ln].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[Ln])o.close(i);n=!1,this[Ln].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=Mn(t,n),n=tn(n,oe),t=rn(t,this[Nn].entry),this[ce]==="opening")return this.defer(()=>this.get(e,t,n)),n[oe];if(Bi(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=Mn(t,n),n=tn(n,oe),t=rn(t,this[Nn].entry),this[ce]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[oe];if(Bi(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=Mn(n,i),i=tn(i,oe),n=rn(n,this[Nn].entry),this[ce]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[oe];if(Bi(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=Mn(t,n),n=tn(n,oe),t=rn(t,this[Nn].key),this[ce]==="opening")return this.defer(()=>this.del(e,t,n)),n[oe];if(Bi(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 Th(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=Mn(t,n),n=tn(n,oe),t=rn(t,this[Nn].empty),this[ce]==="opening")return this.defer(()=>this.batch(e,t,n)),n[oe];if(Bi(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,wu.defaults(t))}_sublevel(e,t){return new wu(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=Mn(e,t),t=tn(t,oe),e=rn(e,this[Nn].empty),this[ce]==="opening")return this.defer(()=>this.clear(e,t)),t[oe];if(Bi(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[Pn.keyEncoding]=t,e[Pn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new Om(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 Pn(this,e)}keys(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=zs(e,t),e[Pn.keyEncoding]=t,e[Pn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new km(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 _m(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=zs(e,t),e[Pn.keyEncoding]=t,e[Pn.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ce]==="opening")return new Cm(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 Um(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[_o].push(e)}[Uo](){if(this[_o].length===0)return;let e=this[_o];this[_o]=[];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[Ln].add(e)}detachResource(e){this[Ln].delete(e)}_chainedBatch(){return new Th(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"})}};Oo.prototype.nextTick=wh();var{AbstractSublevel:wu}=Ah()({AbstractLevel:Oo});xu.AbstractLevel=Oo;xu.AbstractSublevel=wu;var Bi=function(r,e){return r[ce]!=="open"?(r.nextTick(e,new Jt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},Pm=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var vu=se($n=>{"use strict";$n.AbstractLevel=bu().AbstractLevel;$n.AbstractSublevel=bu().AbstractSublevel;$n.AbstractIterator=Qr().AbstractIterator;$n.AbstractKeyIterator=Qr().AbstractKeyIterator;$n.AbstractValueIterator=Qr().AbstractValueIterator;$n.AbstractChainedBatch=au().AbstractChainedBatch});var Ih=se((Uv,Bh)=>{Bh.exports=Lm;var Mm=du();function Lm(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?Mm(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(b,T){l(g,b,T)})):(g=d,d+=1,r[g](function(b,T){l(g,b,T)}))}}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 Eu=se((Ov,Dh)=>{"use strict";Dh.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 Au=se((kv,Kh)=>{"use strict";var Nm=new TextEncoder;Kh.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):Nm.encode(r)}});var Ch=se(kh=>{"use strict";var{AbstractIterator:$m}=vu(),_h=Eu(),Ws=Au(),ar=Symbol("cache"),Ir=Symbol("finished"),St=Symbol("options"),Dr=Symbol("currentOptions"),Vn=Symbol("position"),Tu=Symbol("location"),Ii=Symbol("first"),Uh={},Su=class extends $m{constructor(e,t,n){super(e,n),this[ar]=[],this[Ir]=this.limit===0,this[St]=n,this[Dr]={...n},this[Vn]=void 0,this[Tu]=t,this[Ii]=!0}_nextv(e,t,n){if(this[Ii]=!1,this[Ir])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[Vn]!==void 0&&(this[St].reverse?(this[Dr].lt=this[Vn],this[Dr].lte=void 0):(this[Dr].gt=this[Vn],this[Dr].gte=void 0));let i;try{i=_h(this[Dr])}catch{return this[Ir]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Tu]],"readonly"),s=o.objectStore(this[Tu]),c=[];if(this[St].reverse){let u=!this[St].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[Vn]=l,c.push([this[St].keys&&l!==void 0?Ws(l):void 0,this[St].values&&y!==void 0?Ws(y):void 0]),c.length<e?a.continue():Oh(o)}else this[Ir]=!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[Ir]=!0:this[Vn]=u[l-1],c.length=l;for(let y=0;y<l;y++){let w=u[y],p=d[y];c[y]=[this[St].keys&&w!==void 0?Ws(w):void 0,this[St].values&&p!==void 0?Ws(p):void 0]}Oh(o)};this[St].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[St].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[Ir])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[Ii]&&(this[Ii]=!1,t=1),this._nextv(t,Uh,(n,i)=>{if(n)return e(n);this[ar]=i,this._next(e)})}}_all(e,t){this[Ii]=!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,Uh,(o,s)=>{if(o)return t(o);n.length>0&&(s=n.concat(s)),t(null,s)})}_seek(e,t){this[Ii]=!0,this[ar]=[],this[Ir]=!1,this[Vn]=void 0,this[Dr]={...this[St]};let n;try{n=_h(this[St])}catch{this[Ir]=!0;return}n!==null&&!n.includes(e)?this[Ir]=!0:this[St].reverse?this[Dr].lte=e:this[Dr].gte=e}};kh.Iterator=Su;function Oh(r){typeof r.commit=="function"&&r.commit()}});var Ph=se((Rv,Rh)=>{"use strict";Rh.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 Hh=se(Vh=>{"use strict";var{AbstractLevel:Vm}=vu(),Mh=jt(),Hm=Ih(),{fromCallback:Fm}=xo(),{Iterator:qm}=Ch(),Lh=Au(),jm=Ph(),zm=Eu(),$h="level-js-",ko=Symbol("idb"),Bu=Symbol("namePrefix"),Kr=Symbol("location"),Iu=Symbol("version"),Hn=Symbol("store"),Co=Symbol("onComplete"),Nh=Symbol("promise"),Ys=class extends Vm{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new Mh("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[Kr]=e,this[Bu]=i??$h,this[Iu]=parseInt(o||1,10),this[ko]=null}get location(){return this[Kr]}get namePrefix(){return this[Bu]}get version(){return this[Iu]}get db(){return this[ko]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Bu]+this[Kr],this[Iu]);n.onerror=function(){t(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[ko]=n.result,t()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Kr])||o.createObjectStore(this[Kr])}}[Hn](e){return this[ko].transaction([this[Kr]],e).objectStore(this[Kr])}[Co](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[Hn]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[Co](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new Mh("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,Lh(c))})}_getMany(e,t,n){let i=this[Hn]("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:Lh(d))},u.onerror=d=>{d.stopPropagation(),c(u.error)}});Hm(o,16,n)}_del(e,t,n){let i=this[Hn]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[Co](o,n)}_put(e,t,n,i){let o=this[Hn]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[Co](s,i)}_iterator(e){return new qm(this,this[Kr],e)}_batch(e,t,n){let i=this[Hn]("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=zm(e)}catch{return this.nextTick(t)}if(e.limit>=0)return jm(this,this[Kr],n,e,t);try{let o=this[Hn]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(t,o)}this[Co](i,t)}_close(e){this[ko].close(),this.nextTick(e)}};Ys.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=$h),t=Fm(t,Nh);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[Nh]};Vh.BrowserLevel=Ys});var Du=se(Fh=>{Fh.Level=Hh().BrowserLevel});var hp=se((Fc,lp)=>{(function(r,e){typeof Fc=="object"&&typeof lp<"u"?e(Fc):typeof define=="function"&&define.amd?define(["exports"],e):e(r.URI=r.URI||{})})(Fc,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,v=1;v<x;++v)h[v]=h[v].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]",v="[\\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="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",Ie=e(Me,de),Le=f?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",Se=f?"[\\uE000-\\uF8FF]":"[]",he=e(h,x,"[\\-\\.\\_\\~]",Le),De=t(h+e(h,x,"[\\+\\-\\.]")+"*"),me=t(t(ye+"|"+e(he,de,"[\\:]"))+"*"),bn=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("[1-9]"+x)+"|"+x),vt=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("0?[1-9]"+x)+"|0?0?"+x),kt=t(vt+"\\."+vt+"\\."+vt+"\\."+vt),we=t(R+"{1,4}"),Et=t(t(we+"\\:"+we)+"|"+kt),Ct=t(t(we+"\\:")+"{6}"+Et),rr=t("\\:\\:"+t(we+"\\:")+"{5}"+Et),vn=t(t(we)+"?\\:\\:"+t(we+"\\:")+"{4}"+Et),wr=t(t(t(we+"\\:")+"{0,1}"+we)+"?\\:\\:"+t(we+"\\:")+"{3}"+Et),ro=t(t(t(we+"\\:")+"{0,2}"+we)+"?\\:\\:"+t(we+"\\:")+"{2}"+Et),ms=t(t(t(we+"\\:")+"{0,3}"+we)+"?\\:\\:"+we+"\\:"+Et),gs=t(t(t(we+"\\:")+"{0,4}"+we)+"?\\:\\:"+Et),ni=t(t(t(we+"\\:")+"{0,5}"+we)+"?\\:\\:"+we),ii=t(t(t(we+"\\:")+"{0,6}"+we)+"?\\:\\:"),xr=t([Ct,rr,vn,wr,ro,ms,gs,ni,ii].join("|")),oi=t(t(he+"|"+ye)+"+"),ca=t(xr+"\\%25"+oi),En=t(xr+t("\\%25|\\%(?!"+R+"{2})")+oi),Ey=t("[vV]"+R+"+\\."+e(he,de,"[\\:]")+"+"),Ay=t("\\["+t(En+"|"+xr+"|"+Ey)+"\\]"),Qd=t(t(ye+"|"+e(he,de))+"*"),no=t(Ay+"|"+kt+"(?!"+Qd+")|"+Qd),io=t(x+"*"),el=t(t(me+"@")+"?"+no+t("\\:"+io)+"?"),oo=t(ye+"|"+e(he,de,"[\\:\\@]")),Ty=t(oo+"*"),tl=t(oo+"+"),Sy=t(t(ye+"|"+e(he,de,"[\\@]"))+"+"),br=t(t("\\/"+Ty)+"*"),si=t("\\/"+t(tl+br)+"?"),aa=t(Sy+br),ws=t(tl+br),ci="(?!"+oo+")",Jx=t(br+"|"+si+"|"+aa+"|"+ws+"|"+ci),ai=t(t(oo+"|"+e("[\\/\\?]",Se))+"*"),so=t(t(oo+"|[\\/\\?]")+"*"),rl=t(t("\\/\\/"+el+br)+"|"+si+"|"+ws+"|"+ci),By=t(De+"\\:"+rl+t("\\?"+ai)+"?"+t("\\#"+so)+"?"),Iy=t(t("\\/\\/"+el+br)+"|"+si+"|"+aa+"|"+ci),Dy=t(Iy+t("\\?"+ai)+"?"+t("\\#"+so)+"?"),Gx=t(By+"|"+Dy),Wx=t(De+"\\:"+rl+t("\\?"+ai)+"?"),Yx="^("+De+")\\:"+t(t("\\/\\/("+t("("+me+")@")+"?("+no+")"+t("\\:("+io+")")+"?)")+"?("+br+"|"+si+"|"+ws+"|"+ci+")")+t("\\?("+ai+")")+"?"+t("\\#("+so+")")+"?$",Xx="^(){0}"+t(t("\\/\\/("+t("("+me+")@")+"?("+no+")"+t("\\:("+io+")")+"?)")+"?("+br+"|"+si+"|"+aa+"|"+ci+")")+t("\\?("+ai+")")+"?"+t("\\#("+so+")")+"?$",Zx="^("+De+")\\:"+t(t("\\/\\/("+t("("+me+")@")+"?("+no+")"+t("\\:("+io+")")+"?)")+"?("+br+"|"+si+"|"+ws+"|"+ci+")")+t("\\?("+ai+")")+"?$",Qx="^"+t("\\#("+so+")")+"?$",eb="^"+t("("+me+")@")+"?("+no+")"+t("\\:("+io+")")+"?$";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,Ie),"g"),PCT_ENCODED:new RegExp(ye,"g"),IPV4ADDRESS:new RegExp("^("+kt+")$"),IPV6ADDRESS:new RegExp("^\\[?("+xr+")"+t(t("\\%25|\\%(?!"+R+"{2})")+"("+oi+")")+"?\\]?$")}}var u=c(!1),d=c(!0),a=function(){function f(h,m){var x=[],v=!0,R=!1,re=void 0;try{for(var le=h[Symbol.iterator](),ye;!(v=(ye=le.next()).done)&&(x.push(ye.value),!(m&&x.length===m));v=!0);}catch(Me){R=!0,re=Me}finally{try{!v&&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,b=38,T=700,I=72,E=128,_="-",B=/^xn--/,U=/[^\0-\x7E]/,O=/[\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"},Z=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 Xe(f,h){var m=f.split("@"),x="";m.length>1&&(x=m[0]+"@",f=m[1]),f=f.replace(O,".");var v=f.split("."),R=ae(v,h).join(".");return x+R}function D(f){for(var h=[],m=0,x=f.length;m<x;){var v=f.charCodeAt(m++);if(v>=55296&&v<=56319&&m<x){var R=f.charCodeAt(m++);(R&64512)==56320?h.push(((v&1023)<<10)+(R&1023)+65536):(h.push(v),m--)}else h.push(v)}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)},S=function(h,m,x){var v=0;for(h=x?F(h/T):h>>1,h+=F(h/m);h>Z*g>>1;v+=w)h=F(h/Z);return F(v+(Z+1)*h/(h+b))},C=function(h){var m=[],x=h.length,v=0,R=E,re=I,le=h.lastIndexOf(_);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=v,Ie=1,Le=w;;Le+=w){Me>=x&&ue("invalid-input");var Se=X(h.charCodeAt(Me++));(Se>=w||Se>F((y-v)/Ie))&&ue("overflow"),v+=Se*Ie;var he=Le<=re?p:Le>=re+g?g:Le-re;if(Se<he)break;var De=w-he;Ie>F(y/De)&&ue("overflow"),Ie*=De}var me=m.length+1;re=S(v-de,me,de==0),F(v/me)>y-R&&ue("overflow"),R+=F(v/me),v%=me,m.splice(v++,0,R)}return String.fromCodePoint.apply(String,m)},N=function(h){var m=[];h=D(h);var x=h.length,v=E,R=0,re=I,le=!0,ye=!1,Me=void 0;try{for(var de=h[Symbol.iterator](),Ie;!(le=(Ie=de.next()).done);le=!0){var Le=Ie.value;Le<128&&m.push(j(Le))}}catch(En){ye=!0,Me=En}finally{try{!le&&de.return&&de.return()}finally{if(ye)throw Me}}var Se=m.length,he=Se;for(Se&&m.push(_);he<x;){var De=y,me=!0,bn=!1,vt=void 0;try{for(var kt=h[Symbol.iterator](),we;!(me=(we=kt.next()).done);me=!0){var Et=we.value;Et>=v&&Et<De&&(De=Et)}}catch(En){bn=!0,vt=En}finally{try{!me&&kt.return&&kt.return()}finally{if(bn)throw vt}}var Ct=he+1;De-v>F((y-R)/Ct)&&ue("overflow"),R+=(De-v)*Ct,v=De;var rr=!0,vn=!1,wr=void 0;try{for(var ro=h[Symbol.iterator](),ms;!(rr=(ms=ro.next()).done);rr=!0){var gs=ms.value;if(gs<v&&++R>y&&ue("overflow"),gs==v){for(var ni=R,ii=w;;ii+=w){var xr=ii<=re?p:ii>=re+g?g:ii-re;if(ni<xr)break;var oi=ni-xr,ca=w-xr;m.push(j(K(xr+oi%ca,0))),ni=F(oi/ca)}m.push(j(K(ni,0))),re=S(R,Ct,he==Se),R=0,++he}}}catch(En){vn=!0,wr=En}finally{try{!rr&&ro.return&&ro.return()}finally{if(vn)throw wr}}++R,++v}return m.join("")},J=function(h){return Xe(h,function(m){return B.test(m)?C(m.slice(4).toLowerCase()):m})},ee=function(h){return Xe(h,function(m){return U.test(m)?"xn--"+N(m):m})},W={version:"2.1.0",ucs2:{decode:D,encode:M},decode:C,encode:N,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 v=parseInt(f.substr(m+1,2),16);if(v<128)h+=String.fromCharCode(v),m+=3;else if(v>=194&&v<224){if(x-m>=6){var R=parseInt(f.substr(m+4,2),16);h+=String.fromCharCode((v&31)<<6|R&63)}else h+=f.substr(m,6);m+=6}else if(v>=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((v&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 v=te(x);return v.match(h.UNRESERVED)?v: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),v=x[1];return v?v.split(".").map(be).join("."):f}function Pe(f,h){var m=f.match(h.IPV6ADDRESS)||[],x=a(m,3),v=x[1],R=x[2];if(v){for(var re=v.toLowerCase().split("::").reverse(),le=a(re,2),ye=le[0],Me=le[1],de=Me?Me.split(":").map(be):[],Ie=ye.split(":").map(be),Le=h.IPV4ADDRESS.test(Ie[Ie.length-1]),Se=Le?7:8,he=Ie.length-Se,De=Array(Se),me=0;me<Se;++me)De[me]=de[me]||Ie[he+me]||"";Le&&(De[Se-1]=ke(De[Se-1],h));var bn=De.reduce(function(Ct,rr,vn){if(!rr||rr==="0"){var wr=Ct[Ct.length-1];wr&&wr.index+wr.length===vn?wr.length++:Ct.push({index:vn,length:1})}return Ct},[]),vt=bn.sort(function(Ct,rr){return rr.length-Ct.length})[0],kt=void 0;if(vt&&vt.length>1){var we=De.slice(0,vt.index),Et=De.slice(vt.index+vt.length);kt=we.join(":")+"::"+Et.join(":")}else kt=De.join(":");return R&&(kt+="%"+R),kt}else return f}var Ce=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\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 v=f.match(Ce);if(v){qe?(m.scheme=v[1],m.userinfo=v[3],m.host=v[4],m.port=parseInt(v[5],10),m.path=v[6]||"",m.query=v[7],m.fragment=v[8],isNaN(m.port)&&(m.port=v[5])):(m.scheme=v[1]||void 0,m.userinfo=f.indexOf("@")!==-1?v[3]:void 0,m.host=f.indexOf("//")!==-1?v[4]:void 0,m.port=parseInt(v[5],10),m.path=v[6]||"",m.query=f.indexOf("?")!==-1?v[7]:void 0,m.fragment=f.indexOf("#")!==-1?v[8]:void 0,isNaN(m.port)&&(m.port=f.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?v[4]:void 0)),m.host&&(m.host=Pe(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 gr(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(Pe(ke(String(f.host),m),m).replace(m.IPV6ADDRESS,function(v,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 Fr=/^\.\.?\//,Zi=/^\/\.(\/|$)/,ds=/^\/\.\.(\/|$)/,ia=/^\/?(?:.|\n)*?(?=\/|$)/;function qr(f){for(var h=[];f.length;)if(f.match(Fr))f=f.replace(Fr,"");else if(f.match(Zi))f=f.replace(Zi,"/");else if(f.match(ds))f=f.replace(ds,"/"),h.pop();else if(f==="."||f==="..")f="";else{var m=f.match(ia);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 Ut(f){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m=h.iri?d:u,x=[],v=Y[(h.scheme||f.scheme||"").toLowerCase()];if(v&&v.serialize&&v.serialize(f,h),f.host&&!m.IPV6ADDRESS.test(f.host)){if(h.domainHost||v&&v.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=gr(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&&(!v||!v.absolutePath)&&(re=qr(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 Qi(f,h){var m=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},x=arguments[3],v={};return x||(f=Ne(Ut(f,m),m),h=Ne(Ut(h,m),m)),m=m||{},!m.tolerant&&h.scheme?(v.scheme=h.scheme,v.userinfo=h.userinfo,v.host=h.host,v.port=h.port,v.path=qr(h.path||""),v.query=h.query):(h.userinfo!==void 0||h.host!==void 0||h.port!==void 0?(v.userinfo=h.userinfo,v.host=h.host,v.port=h.port,v.path=qr(h.path||""),v.query=h.query):(h.path?(h.path.charAt(0)==="/"?v.path=qr(h.path):((f.userinfo!==void 0||f.host!==void 0||f.port!==void 0)&&!f.path?v.path="/"+h.path:f.path?v.path=f.path.slice(0,f.path.lastIndexOf("/")+1)+h.path:v.path=h.path,v.path=qr(v.path)),v.query=h.query):(v.path=f.path,h.query!==void 0?v.query=h.query:v.query=f.query),v.userinfo=f.userinfo,v.host=f.host,v.port=f.port),v.scheme=f.scheme),v.fragment=h.fragment,v}function ls(f,h,m){var x=s({scheme:"null"},m);return Ut(Qi(Ne(f,x),Ne(h,x),x,!0),x)}function eo(f,h){return typeof f=="string"?f=Ut(Ne(f,h),h):n(f)==="object"&&(f=Ne(Ut(f,h),h)),f}function hs(f,h,m){return typeof f=="string"?f=Ut(Ne(f,m),m):n(f)==="object"&&(f=Ut(f,m)),typeof h=="string"?h=Ut(Ne(h,m),m):n(h)==="object"&&(h=Ut(h,m)),f===h}function fs(f,h){return f&&f.toString().replace(!h||!h.iri?u.ESCAPE:d.ESCAPE,G)}function Ot(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}},to={scheme:"https",domainHost:jr.domainHost,parse:jr.parse,serialize:jr.serialize};function ps(f){return typeof f.secure=="boolean"?f.secure:String(f.scheme).toLowerCase()==="wss"}var xn={scheme:"ws",domainHost:!0,parse:function(h,m){var x=h;return x.secure=ps(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===(ps(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("?"),v=a(x,2),R=v[0],re=v[1];h.path=R&&R!=="/"?R:void 0,h.query=re,h.resourceName=void 0}return h.fragment=void 0,h}},ys={scheme:"wss",domainHost:xn.domainHost,parse:xn.parse,serialize:xn.serialize},oa={},ly=!0,Gd="[A-Za-z0-9\\-\\.\\_\\~"+(ly?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",tr="[0-9A-Fa-f]",hy=t(t("%[EFef]"+tr+"%"+tr+tr+"%"+tr+tr)+"|"+t("%[89A-Fa-f]"+tr+"%"+tr+tr)+"|"+t("%"+tr+tr)),fy="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",py="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",yy=e(py,'[\\"\\\\]'),my="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",gy=new RegExp(Gd,"g"),ri=new RegExp(hy,"g"),wy=new RegExp(e("[^]",fy,"[\\.]",'[\\"]',yy),"g"),Wd=new RegExp(e("[^]",Gd,my),"g"),xy=Wd;function sa(f){var h=te(f);return h.match(gy)?h:f}var Yd={scheme:"mailto",parse:function(h,m){var x=h,v=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 Ie=de[1].split(","),Le=0,Se=Ie.length;Le<Se;++Le)v.push(Ie[Le]);break;case"subject":x.subject=Ot(de[1],m);break;case"body":x.body=Ot(de[1],m);break;default:R=!0,re[Ot(de[0],m)]=Ot(de[1],m);break}}R&&(x.headers=re)}x.query=void 0;for(var he=0,De=v.length;he<De;++he){var me=v[he].split("@");if(me[0]=Ot(me[0]),m.unicodeSupport)me[1]=Ot(me[1],m).toLowerCase();else try{me[1]=W.toASCII(Ot(me[1],m).toLowerCase())}catch(bn){x.error=x.error||"Email address's domain name can not be converted to ASCII via punycode: "+bn}v[he]=me.join("@")}return x},serialize:function(h,m){var x=h,v=o(h.to);if(v){for(var R=0,re=v.length;R<re;++R){var le=String(v[R]),ye=le.lastIndexOf("@"),Me=le.slice(0,ye).replace(ri,sa).replace(ri,i).replace(wy,G),de=le.slice(ye+1);try{de=m.iri?W.toUnicode(de):W.toASCII(Ot(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}v[R]=Me+"@"+de}x.path=v.join(",")}var Ie=h.headers=h.headers||{};h.subject&&(Ie.subject=h.subject),h.body&&(Ie.body=h.body);var Le=[];for(var Se in Ie)Ie[Se]!==oa[Se]&&Le.push(Se.replace(ri,sa).replace(ri,i).replace(Wd,G)+"="+Ie[Se].replace(ri,sa).replace(ri,i).replace(xy,G));return Le.length&&(x.query=Le.join("&")),x}},by=/^([^\:]+)\:(.*)/,Xd={scheme:"urn",parse:function(h,m){var x=h.path&&h.path.match(by),v=h;if(x){var R=m.scheme||v.scheme||"urn",re=x[1].toLowerCase(),le=x[2],ye=R+":"+(m.nid||re),Me=Y[ye];v.nid=re,v.nss=le,v.path=void 0,Me&&(v=Me.parse(v,m))}else v.error=v.error||"URN can not be parsed.";return v},serialize:function(h,m){var x=m.scheme||h.scheme||"urn",v=h.nid,R=x+":"+(m.nid||v),re=Y[R];re&&(h=re.serialize(h,m));var le=h,ye=h.nss;return le.path=(v||m.nid)+":"+ye,le}},vy=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,Zd={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(vy))&&(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[to.scheme]=to,Y[xn.scheme]=xn,Y[ys.scheme]=ys,Y[Yd.scheme]=Yd,Y[Xd.scheme]=Xd,Y[Zd.scheme]=Zd,r.SCHEMES=Y,r.pctEncChar=G,r.pctDecChars=te,r.parse=Ne,r.removeDotSegments=qr,r.serialize=Ut,r.resolveComponents=Qi,r.resolve=ls,r.normalize=eo,r.equal=hs,r.escapeComponent=fs,r.unescapeComponent=Ot,Object.defineProperty(r,"__esModule",{value:!0})})});var pp=se((l6,fp)=>{"use strict";fp.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 Jd=se((ZS,ny)=>{var Wi=1e3,Yi=Wi*60,Xi=Yi*60,ti=Xi*24,Hx=ti*7,Fx=ti*365.25;ny.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return qx(r);if(t==="number"&&isFinite(r))return e.long?zx(r):jx(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function qx(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*Fx;case"weeks":case"week":case"w":return t*Hx;case"days":case"day":case"d":return t*ti;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Xi;case"minutes":case"minute":case"mins":case"min":case"m":return t*Yi;case"seconds":case"second":case"secs":case"sec":case"s":return t*Wi;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function jx(r){var e=Math.abs(r);return e>=ti?Math.round(r/ti)+"d":e>=Xi?Math.round(r/Xi)+"h":e>=Yi?Math.round(r/Yi)+"m":e>=Wi?Math.round(r/Wi)+"s":r+"ms"}function zx(r){var e=Math.abs(r);return e>=ti?na(r,e,ti,"day"):e>=Xi?na(r,e,Xi,"hour"):e>=Yi?na(r,e,Yi,"minute"):e>=Wi?na(r,e,Wi,"second"):r+" ms"}function na(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var ui=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(ui||{});var Ke={"@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 _e=$e;var $=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)}},zr=(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))(zr||{});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 fa=An(il(),1);var ub=new Uint8Array(0);function ol(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")}function Ly(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,b=0,T=0,I=p.length;T!==I&&p[T]===0;)T++,g++;for(var E=(I-T)*a+1>>>0,_=new Uint8Array(E);T!==I;){for(var B=p[T],U=0,O=E-1;(B!==0||U<b)&&O!==-1;O--,U++)B+=256*_[O]>>>0,_[O]=B%c>>>0,B=B/c>>>0;if(B!==0)throw new Error("Non-zero carry");b=U,T++}for(var k=E-b;k!==E&&_[k]===0;)k++;for(var Z=u.repeat(g);k<E;++k)Z+=r.charAt(_[k]);return Z}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 b=0,T=0;p[g]===u;)b++,g++;for(var I=(p.length-g)*d+1>>>0,E=new Uint8Array(I);p[g];){var _=t[p.charCodeAt(g)];if(_===255)return;for(var B=0,U=I-1;(_!==0||B<T)&&U!==-1;U--,B++)_+=c*E[U]>>>0,E[U]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");T=B,g++}if(p[g]!==" "){for(var O=I-T;O!==I&&E[O]===0;)O++;for(var k=new Uint8Array(b+(I-O)),Z=b;O!==I;)k[Z++]=E[O++];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 Ny=Ly,$y=Ny,sl=$y;var pa=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")}},ya=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 cl(this,e)}},ma=class{decoders;constructor(e){this.decoders=e}or(e){return cl(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 cl(r,e){return new ma({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ga=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 pa(e,t,n),this.decoder=new ya(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function al({name:r,prefix:e,encode:t,decode:n}){return new ga(r,e,t,n)}function wa({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=sl(t,r);return al({prefix:e,name:r,encode:n,decode:o=>di(i(o))})}function Vy(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 Hy(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 al({prefix:e,name:r,encode(i){return Hy(i,n,t)},decode(i){return Vy(i,n,t,r)}})}var co=st({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),yb=st({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mb=st({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gb=st({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wb=st({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xb=st({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bb=st({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vb=st({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xa=st({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var lt=wa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tb=wa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ib=st({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Db=st({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nr=st({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kb=st({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function ul(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function dl(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 ao=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())})},ll=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,Tn=new TextDecoder,P=class r{constructor(e,t){this.data=e,this.format=t}static arrayBuffer(e){return new r(e,"ArrayBuffer")}static asyncIterable(e){if(!dl(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(li(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return ul(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 ao(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 xa.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 ao(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u=[];try{for(var o=!0,s=ll(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=Tn.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Tn.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return ao(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 Tn.decode(this.data);case"Base64Url":{let e=nr.baseDecode(this.data);return Tn.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Tn.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return ao(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u="";try{for(var o=!0,s=ll(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+=Tn.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+=Tn.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 xa.baseDecode(this.data);case"Base58Btc":return lt.baseDecode(this.data);case"Base64Url":return nr.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 ao(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 uo;(function(r){r.Debug="debug",r.Silent="silent"})(uo||(uo={}));var ba=class{constructor(){this.logLevel=uo.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==uo.Silent&&console.info(e)}error(e){this.logLevel!==uo.Silent&&console.error(e)}},Fy=new ba;typeof window<"u"&&(window.web5logger=Fy);var vr={};da(vr,{decode:()=>hi,encodeTo:()=>Sn,encodingLength:()=>Bn});var qy=pl,hl=128,jy=127,zy=~jy,Jy=Math.pow(2,31);function pl(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Jy;)e[t++]=r&255|hl,r/=128;for(;r&zy;)e[t++]=r&255|hl,r>>>=7;return e[t]=r|0,pl.bytes=t-n+1,e}var Gy=va,Wy=128,fl=127;function va(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw va.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&fl)<<i:(s&fl)*Math.pow(2,i),i+=7}while(s>=Wy);return va.bytes=o-n,t}var Yy=Math.pow(2,7),Xy=Math.pow(2,14),Zy=Math.pow(2,21),Qy=Math.pow(2,28),e0=Math.pow(2,35),t0=Math.pow(2,42),r0=Math.pow(2,49),n0=Math.pow(2,56),i0=Math.pow(2,63),o0=function(r){return r<Yy?1:r<Xy?2:r<Zy?3:r<Qy?4:r<e0?5:r<t0?6:r<r0?7:r<n0?8:r<i0?9:10},s0={encode:qy,decode:Gy,encodingLength:o0},c0=s0,lo=c0;function hi(r,e=0){return[lo.decode(r,e),lo.decode.bytes]}function Sn(r,e,t=0){return lo.encode(r,e,t),e}function Bn(r){return lo.encodingLength(r)}function Ea(r,e){let t=e.byteLength,n=Bn(r),i=n+Bn(t),o=new Uint8Array(i+t);return Sn(r,o,0),Sn(t,o,n),o.set(e,i),new fi(r,t,e,o)}function yl(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 ml(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ol(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}};function gl(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return u0(t,Ta(r),e??lt.encoder);default:return d0(t,Ta(r),e??co.encoder)}}var wl=new WeakMap;function Ta(r){let e=wl.get(r);if(e==null){let t=new Map;return wl.set(r,t),t}return e}var Sa=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!==ho)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==l0)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=Ea(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&&ml(e.multihash,n.multihash)}toString(e){return gl(this,e)}toJSON(){return{"/":gl(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??xl(n,i,o.bytes))}else if(t[h0]===!0){let{version:n,multihash:i,code:o}=t,s=yl(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!==ho)throw new Error(`Version 0 CID must use dag-pb (code: ${ho}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=xl(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ho,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,y]=hi(e.subarray(t));return t+=y,l},i=n(),o=ho;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]=a0(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 Ta(o).set(n,e),o}};function a0(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 co.prefix:{let t=e??co;return[co.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 u0(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 ho=112,l0=18;function xl(r,e,t){let n=Bn(r),i=n+Bn(e),o=new Uint8Array(i+t.byteLength);return Sn(r,o,0),Sn(e,o,n),o.set(t,i),o}var h0=Symbol.for("@ipld/js-cid/CID");var rt=class r{static addPrefix(e){var t;let{code:n,data:i,name:o}=e;if(!(o?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=r.codeToName.has(n)?n:r.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(t=e.name)!==null&&t!==void 0?t:e.code}`);let s=vr.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),vr.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=vr.decode(t);return n}static getCodeFromName(e){let{name:t}=e,n=r.nameToCode.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static getNameFromCode(e){let{code:t}=e,n=r.codeToName.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static registerCodec(e){r.codeToName.set(e.code,e.name),r.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:t}=e,[n,i]=vr.decode(t),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:t.slice(i),name:o}}};rt.codeToName=new Map;rt.nameToCode=new Map;rt.registerCodec({code:237,name:"ed25519-pub"});rt.registerCodec({code:4864,name:"ed25519-priv"});rt.registerCodec({code:236,name:"x25519-pub"});rt.registerCodec({code:4866,name:"x25519-priv"});rt.registerCodec({code:231,name:"secp256k1-pub"});rt.registerCodec({code:4865,name:"secp256k1-priv"});function Ba(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&Ba(r[e])})}var Jm=An(Du(),1),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())})};var Xs=class{constructor(){this.store=new Map}clear(){return Fn(this,void 0,void 0,function*(){this.store.clear()})}close(){return Fn(this,void 0,void 0,function*(){})}delete(e){return Fn(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return Fn(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return Fn(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return Fn(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return Fn(this,void 0,void 0,function*(){this.store.set(e,t)})}};var at=class{};var Qs={};da(Qs,{bitGet:()=>eg,bitLen:()=>Qm,bitMask:()=>Ro,bitSet:()=>tg,bytesToHex:()=>Ur,bytesToNumberBE:()=>Or,bytesToNumberLE:()=>Wt,concatBytes:()=>Cr,createHmacDrbg:()=>Uu,ensureBytes:()=>ve,equalBytes:()=>Xm,hexToBytes:()=>qn,hexToNumber:()=>_u,isBytes:()=>Gt,numberToBytesBE:()=>pt,numberToBytesLE:()=>kr,numberToHexUnpadded:()=>Jh,numberToVarBytesBE:()=>Ym,utf8ToBytes:()=>Zm,validateObject:()=>Lt});var zh=BigInt(0),Zs=BigInt(1),Gm=BigInt(2);function Gt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Wm=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Ur(r){if(!Gt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=Wm[r[t]];return e}function Jh(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function _u(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var _r={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function qh(r){if(r>=_r._0&&r<=_r._9)return r-_r._0;if(r>=_r._A&&r<=_r._F)return r-(_r._A-10);if(r>=_r._a&&r<=_r._f)return r-(_r._a-10)}function qn(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=qh(r.charCodeAt(o)),c=qh(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 _u(Ur(r))}function Wt(r){if(!Gt(r))throw new Error("Uint8Array expected");return _u(Ur(Uint8Array.from(r).reverse()))}function pt(r,e){return qn(r.toString(16).padStart(e*2,"0"))}function kr(r,e){return pt(r,e).reverse()}function Ym(r){return qn(Jh(r))}function ve(r,e,t){let n;if(typeof e=="string")try{n=qn(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 Xm(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 Zm(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Qm(r){let e;for(e=0;r>zh;r>>=Zs,e+=1);return e}function eg(r,e){return r>>BigInt(e)&Zs}var tg=(r,e,t)=>r|(t?Zs:zh)<<BigInt(e),Ro=r=>(Gm<<BigInt(r-1))-Zs,Ku=r=>new Uint8Array(r),jh=r=>Uint8Array.from(r);function Uu(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=Ku(r),i=Ku(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),u=(l=Ku())=>{i=c(jh([0]),l),n=c(),l.length!==0&&(i=c(jh([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 rg={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=rg[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 Gh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function ng(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ou(r,...e){if(!ng(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 Wh(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Gh(r.outputLen),Gh(r.blockLen)}function Di(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 Yh(r,e){Ou(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var ec=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Xh(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var tc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Yt=(r,e)=>r<<32-e|r>>>e,ig=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ig)throw new Error("Non little-endian hardware is not supported");function ku(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Po(r){if(typeof r=="string"&&(r=ku(r)),!Xh(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function rc(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Xh(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 Ki=class{clone(){return this._cloneInto()}},e1={}.toString;function nc(r){let e=n=>r().update(Po(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Mo(r=32){if(ec&&typeof ec.getRandomValues=="function")return ec.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function og(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 _i=class extends Ki{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=tc(this.buffer)}update(e){Di(this);let{view:t,buffer:n,blockLen:i}=this;e=Po(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=tc(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){Di(this),Yh(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;og(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=tc(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 sg=(r,e,t)=>r&e^~r&t,cg=(r,e,t)=>r&e^r&t^e&t,ag=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]),nn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),on=new Uint32Array(64),Cu=class extends _i{constructor(){super(64,32,8,!1),this.A=nn[0]|0,this.B=nn[1]|0,this.C=nn[2]|0,this.D=nn[3]|0,this.E=nn[4]|0,this.F=nn[5]|0,this.G=nn[6]|0,this.H=nn[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)on[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=on[l-15],w=on[l-2],p=Yt(y,7)^Yt(y,18)^y>>>3,g=Yt(w,17)^Yt(w,19)^w>>>10;on[l]=g+on[l-7]+p+on[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+sg(c,u,d)+ag[l]+on[l]|0,g=(Yt(n,2)^Yt(n,13)^Yt(n,22))+cg(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(){on.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ic=nc(()=>new Cu);var Ve=BigInt(0),Be=BigInt(1),jn=BigInt(2),ug=BigInt(3),Ru=BigInt(4),Zh=BigInt(5),Qh=BigInt(8),dg=BigInt(9),lg=BigInt(16);function fe(r,e){let t=r%e;return t>=Ve?t:e+t}function Pu(r,e,t){if(t<=Ve||e<Ve)throw new Error("Expected power/modulo > 0");if(t===Be)return Ve;let n=Be;for(;e>Ve;)e&Be&&(n=n*r%t),r=r*r%t,e>>=Be;return n}function Ee(r,e,t){let n=r;for(;e-- >Ve;)n*=n,n%=t;return n}function oc(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=Be,s=Be,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!==Be)throw new Error("invert: does not exist");return fe(i,e)}function hg(r){let e=(r-Be)/jn,t,n,i;for(t=r-Be,n=0;t%jn===Ve;t/=jn,n++);for(i=jn;i<r&&Pu(i,e,r)!==r-Be;i++);if(n===1){let s=(r+Be)/Ru;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+Be)/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,Be<<BigInt(d-w-1));a=c.sqr(p),l=c.mul(l,p),y=c.mul(y,a),d=w}return l}}function fg(r){if(r%Ru===ug){let e=(r+Be)/Ru;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%Qh===Zh){let e=(r-Zh)/Qh;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%lg,hg(r)}var ef=(r,e)=>(fe(r,e)&Be)===Be,pg=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mu(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=pg.reduce((n,i)=>(n[i]="function",n),e);return Lt(r,t)}function yg(r,e,t){if(t<Ve)throw new Error("Expected power > 0");if(t===Ve)return r.ONE;if(t===Be)return e;let n=r.ONE,i=e;for(;t>Ve;)t&Be&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Be;return n}function mg(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 Lu(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Ui(r,e,t=!1,n={}){if(r<=Ve)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Lu(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=fg(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Ro(i),ZERO:Ve,ONE:Be,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&Be)===Be,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)=>yg(c,u,d),div:(u,d)=>fe(u*oc(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>oc(u,r),sqrt:n.sqrt||(u=>s(c,u)),invertBatch:u=>mg(c,u),cmov:(u,d,a)=>a?d:u,toBytes:u=>t?kr(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):Or(u)}});return Object.freeze(c)}function tf(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 rf(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 Nu(r){let e=rf(r);return e+Math.ceil(e/2)}function nf(r,e,t=!1){let n=r.length,i=rf(e),o=Nu(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Or(r):Wt(r),c=fe(s,e-Be)+Be;return t?kr(c,i):pt(c,i)}var wg=BigInt(0),$u=BigInt(1);function sc(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>wg;)o&$u&&(s=s.add(c)),c=c.double(),o>>=$u;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,b=Number(s&l);s>>=w,b>u&&(b-=y,s+=$u);let T=g,I=g+Math.abs(b)-1,E=p%2!==0,_=b<0;b===0?a=a.add(t(E,o[T])):d=d.add(t(_,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 Lo(r){return Mu(r.Fp),Lt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Lu(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function xg(r){let e=Lo(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:bg,hexToBytes:vg}=Qs,zn={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=zn;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:bg(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=zn,t=typeof r=="string"?vg(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}=zn._parseInt(t.subarray(2)),{d:s,l:c}=zn._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),y1=BigInt(2),of=BigInt(3),m1=BigInt(4);function Eg(r){let e=xg(r),{Fp:t}=e,n=e.toBytes||((p,g,b)=>{let T=g.toAffine();return Cr(Uint8Array.from([4]),t.toBytes(T.x),t.toBytes(T.y))}),i=e.fromBytes||(p=>{let g=p.subarray(1),b=t.fromBytes(g.subarray(0,t.BYTES)),T=t.fromBytes(g.subarray(t.BYTES,2*t.BYTES));return{x:b,y:T}});function o(p){let{a:g,b}=e,T=t.sqr(p),I=t.mul(T,p);return t.add(t.add(I,t.mul(p,g)),b)}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:b,wrapPrivateKey:T,n:I}=e;if(g&&typeof p!="bigint"){if(Gt(p)&&(p=Ur(p)),typeof p!="string"||!g.includes(p.length))throw new Error("Invalid key");p=p.padStart(b*2,"0")}let E;try{E=typeof p=="bigint"?p:Or(ve("private key",p,b))}catch{throw new Error(`private key must be ${b} bytes, hex or bigint, not ${typeof p}`)}return T&&(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,b,T){if(this.px=g,this.py=b,this.pz=T,g==null||!t.isValid(g))throw new Error("x required");if(b==null||!t.isValid(b))throw new Error("y required");if(T==null||!t.isValid(T))throw new Error("z required")}static fromAffine(g){let{x:b,y:T}=g||{};if(!g||!t.isValid(b)||!t.isValid(T))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(b)&&I(T)?l.ZERO:new l(b,T,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){let b=t.invertBatch(g.map(T=>T.pz));return g.map((T,I)=>T.toAffine(b[I])).map(l.fromAffine)}static fromHex(g){let b=l.fromAffine(i(ve("pointHex",g)));return b.assertValidity(),b}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:b}=this.toAffine();if(!t.isValid(g)||!t.isValid(b))throw new Error("bad point: x or y not FE");let T=t.sqr(b),I=o(g);if(!t.eql(T,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:b,py:T,pz:I}=this,{px:E,py:_,pz:B}=g,U=t.eql(t.mul(b,B),t.mul(E,I)),O=t.eql(t.mul(T,B),t.mul(_,I));return U&&O}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b}=e,T=t.mul(b,of),{px:I,py:E,pz:_}=this,B=t.ZERO,U=t.ZERO,O=t.ZERO,k=t.mul(I,I),Z=t.mul(E,E),F=t.mul(_,_),j=t.mul(I,E);return j=t.add(j,j),O=t.mul(I,_),O=t.add(O,O),B=t.mul(g,O),U=t.mul(T,F),U=t.add(B,U),B=t.sub(Z,U),U=t.add(Z,U),U=t.mul(B,U),B=t.mul(j,B),O=t.mul(T,O),F=t.mul(g,F),j=t.sub(k,F),j=t.mul(g,j),j=t.add(j,O),O=t.add(k,k),k=t.add(O,k),k=t.add(k,F),k=t.mul(k,j),U=t.add(U,k),F=t.mul(E,_),F=t.add(F,F),k=t.mul(F,j),B=t.sub(B,k),O=t.mul(F,Z),O=t.add(O,O),O=t.add(O,O),new l(B,U,O)}add(g){a(g);let{px:b,py:T,pz:I}=this,{px:E,py:_,pz:B}=g,U=t.ZERO,O=t.ZERO,k=t.ZERO,Z=e.a,F=t.mul(e.b,of),j=t.mul(b,E),ue=t.mul(T,_),ae=t.mul(I,B),Xe=t.add(b,T),D=t.add(E,_);Xe=t.mul(Xe,D),D=t.add(j,ue),Xe=t.sub(Xe,D),D=t.add(b,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(T,I),U=t.add(_,B),M=t.mul(M,U),U=t.add(ue,ae),M=t.sub(M,U),k=t.mul(Z,D),U=t.mul(F,ae),k=t.add(U,k),U=t.sub(ue,k),k=t.add(ue,k),O=t.mul(U,k),ue=t.add(j,j),ue=t.add(ue,j),ae=t.mul(Z,ae),D=t.mul(F,D),ue=t.add(ue,ae),ae=t.sub(j,ae),ae=t.mul(Z,ae),D=t.add(D,ae),j=t.mul(ue,D),O=t.add(O,j),j=t.mul(M,D),U=t.mul(Xe,U),U=t.sub(U,j),j=t.mul(Xe,ue),k=t.mul(M,k),k=t.add(k,j),new l(U,O,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return w.wNAFCached(this,d,g,b=>{let T=t.invertBatch(b.map(I=>I.pz));return b.map((I,E)=>I.toAffine(T[E])).map(l.fromAffine)})}multiplyUnsafe(g){let b=l.ZERO;if(g===Rr)return b;if(c(g),g===Nt)return this;let{endo:T}=e;if(!T)return w.unsafeLadder(this,g);let{k1neg:I,k1:E,k2neg:_,k2:B}=T.splitScalar(g),U=b,O=b,k=this;for(;E>Rr||B>Rr;)E&Nt&&(U=U.add(k)),B&Nt&&(O=O.add(k)),k=k.double(),E>>=Nt,B>>=Nt;return I&&(U=U.negate()),_&&(O=O.negate()),O=new l(t.mul(O.px,T.beta),O.py,O.pz),U.add(O)}multiply(g){c(g);let b=g,T,I,{endo:E}=e;if(E){let{k1neg:_,k1:B,k2neg:U,k2:O}=E.splitScalar(b),{p:k,f:Z}=this.wNAF(B),{p:F,f:j}=this.wNAF(O);k=w.constTimeNegate(_,k),F=w.constTimeNegate(U,F),F=new l(t.mul(F.px,E.beta),F.py,F.pz),T=k.add(F),I=Z.add(j)}else{let{p:_,f:B}=this.wNAF(b);T=_,I=B}return l.normalizeZ([T,I])[0]}multiplyAndAddUnsafe(g,b,T){let I=l.BASE,E=(B,U)=>U===Rr||U===Nt||!B.equals(I)?B.multiplyUnsafe(U):B.multiply(U),_=E(this,b).add(E(g,T));return _.is0()?void 0:_}toAffine(g){let{px:b,py:T,pz:I}=this,E=this.is0();g==null&&(g=E?t.ONE:t.inv(I));let _=t.mul(b,g),B=t.mul(T,g),U=t.mul(I,g);if(E)return{x:t.ZERO,y:t.ZERO};if(!t.eql(U,t.ONE))throw new Error("invZ was invalid");return{x:_,y:B}}isTorsionFree(){let{h:g,isTorsionFree:b}=e;if(g===Nt)return!0;if(b)return b(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:g,clearCofactor:b}=e;return g===Nt?this:b?b(l,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return this.assertValidity(),n(l,this,g)}toHex(g=!0){return Ur(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=sc(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:o,isWithinCurveOrder:s}}function Ag(r){let e=Lo(r);return Lt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function sf(r){let e=Ag(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 oc(D,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:y}=Eg({...e,toBytes(D,M,X){let K=M.toAffine(),S=t.toBytes(K.x),C=Cr;return X?C(Uint8Array.from([M.hasEvenY()?2:3]),S):C(Uint8Array.from([4]),S,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 S=Or(K);if(!s(S))throw new Error("Point is not on curve");let C=l(S),N=t.sqrt(C),J=(N&Nt)===Nt;return(X&1)===1!==J&&(N=t.neg(N)),{x:S,y:N}}else if(M===o&&X===4){let S=t.fromBytes(K.subarray(0,t.BYTES)),C=t.fromBytes(K.subarray(t.BYTES,2*t.BYTES));return{x:S,y:C}}else throw new Error(`Point of length ${M} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),w=D=>Ur(pt(D,e.nByteLength));function p(D){let M=n>>Nt;return D>M}function g(D){return p(D)?c(-D):D}let b=(D,M,X)=>Or(D.slice(M,X));class T{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 T(b(M,0,X),b(M,X,2*X))}static fromDER(M){let{r:X,s:K}=zn.toSig(ve("DER",M));return new T(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 T(this.r,this.s,M)}recoverPublicKey(M){let{r:X,s:K,recovery:S}=this,C=O(ve("msgHash",M));if(S==null||![0,1,2,3].includes(S))throw new Error("recovery id invalid");let N=S===2||S===3?X+e.n:X;if(N>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let J=S&1?"03":"02",ee=d.fromHex(J+w(N)),W=u(N),Y=c(-C*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 T(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return qn(this.toDERHex())}toDERHex(){return zn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return qn(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=Nu(e.n);return nf(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 _(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(_(D))throw new Error("first arg must be private key");if(!_(M))throw new Error("second arg must be public key");return d.fromHex(M).multiply(a(D)).toRawBytes(X)}let U=e.bits2int||function(D){let M=Or(D),X=D.length*8-e.nBitLength;return X>0?M>>BigInt(X):M},O=e.bits2int_modN||function(D){return c(U(D))},k=Ro(e.nBitLength);function Z(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:S}=e,{lowS:C,prehash:N,extraEntropy:J}=X;C==null&&(C=!0),D=ve("msgHash",D),N&&(D=ve("prehashed msgHash",K(D)));let ee=O(D),W=a(M),Y=[Z(W),Z(ee)];if(J!=null){let be=J===!0?S(t.BYTES):J;Y.push(ve("extraEntropy",be))}let G=Cr(...Y),te=ee;function Te(be){let ke=U(be);if(!y(ke))return;let Pe=u(ke),Ce=d.BASE.multiply(ke).toAffine(),qe=c(Ce.x);if(qe===Rr)return;let Ne=c(Pe*c(te+qe*W));if(Ne===Rr)return;let gr=(Ce.x===qe?0:2)|Number(Ce.y&Nt),Fr=Ne;return C&&p(Ne)&&(Fr=g(Ne),gr^=1),new T(qe,Fr,gr)}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:S}=F(D,M,X),C=e;return Uu(C.hash.outputLen,C.nByteLength,C.hmac)(K,S)}d.BASE._setWindowSize(8);function Xe(D,M,X,K=ue){let S=D;if(M=ve("msgHash",M),X=ve("publicKey",X),"strict"in K)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:N}=K,J,ee;try{if(typeof S=="string"||Gt(S))try{J=T.fromDER(S)}catch(Ce){if(!(Ce instanceof zn.Err))throw Ce;J=T.fromCompact(S)}else if(typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint"){let{r:Ce,s:qe}=S;J=new T(Ce,qe)}else throw new Error("PARSE");ee=d.fromHex(X)}catch(Ce){if(Ce.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&J.hasHighS())return!1;N&&(M=e.hash(M));let{r:W,s:Y}=J,G=O(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:Xe,ProjectivePoint:d,Signature:T,utils:I}}var cc=class extends Ki{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Wh(e);let n=Po(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 Di(this),this.iHash.update(e),this}digestInto(e){Di(this),Ou(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vu=(r,e,t)=>new cc(r,e).update(t).digest();Vu.create=(r,e)=>new cc(r,e);function Tg(r){return{hash:r,hmac:(e,...t)=>Vu(r,e,rc(...t)),randomBytes:Mo}}function ac(r,e){let t=n=>sf({...r,...Tg(n)});return Object.freeze({...t(e),create:t})}var uf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),cf=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Sg=BigInt(1),Hu=BigInt(2),af=(r,e)=>(r+e/Hu)/e;function Bg(r){let e=uf,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,Hu,e)*d%e,p=Ee(w,i,e)*w%e,g=Ee(p,o,e)*p%e,b=Ee(g,c,e)*g%e,T=Ee(b,u,e)*b%e,I=Ee(T,c,e)*g%e,E=Ee(I,t,e)*a%e,_=Ee(E,s,e)*p%e,B=Ee(_,n,e)*d%e,U=Ee(B,Hu,e);if(!Fu.eql(Fu.sqr(U),r))throw new Error("Cannot find square root");return U}var Fu=Ui(uf,void 0,void 0,{sqrt:Bg}),yt=ac({a:BigInt(0),b:BigInt(7),Fp:Fu,n:cf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=cf,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Sg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=af(o*r,e),u=af(-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}}}},ic),D1=BigInt(0);var K1=yt.ProjectivePoint;function Ig(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function qu(r,...e){if(!Ig(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 ju(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function df(r,e){qu(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Oi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var dc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Xt=(r,e)=>r<<32-e|r>>>e;var R1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Dg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function zu(r){return typeof r=="string"&&(r=Dg(r)),qu(r),r}var uc=class{clone(){return this._cloneInto()}},P1={}.toString;function lf(r){let e=n=>r().update(zu(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function hf(r=32){if(Oi&&typeof Oi.getRandomValues=="function")return Oi.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Kg(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 ff=(r,e,t)=>r&e^~r&t,pf=(r,e,t)=>r&e^r&t^e&t,lc=class extends uc{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=dc(this.buffer)}update(e){ju(this);let{view:t,buffer:n,blockLen:i}=this;e=zu(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=dc(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){ju(this),df(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;Kg(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=dc(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]),sn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),cn=new Uint32Array(64),Ju=class extends lc{constructor(){super(64,32,8,!1),this.A=sn[0]|0,this.B=sn[1]|0,this.C=sn[2]|0,this.D=sn[3]|0,this.E=sn[4]|0,this.F=sn[5]|0,this.G=sn[6]|0,this.H=sn[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)cn[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=cn[l-15],w=cn[l-2],p=Xt(y,7)^Xt(y,18)^y>>>3,g=Xt(w,17)^Xt(w,19)^w>>>10;cn[l]=g+cn[l-7]+p+cn[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+ff(c,u,d)+_g[l]+cn[l]|0,g=(Xt(n,2)^Xt(n,13)^Xt(n,22))+pf(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(){cn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var an=lf(()=>new Ju);function yf(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 Ug=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},ki=class{static digest(e){return Ug(this,arguments,void 0,function*({data:t}){return an(t)})}};var Og=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())})},Gu="urn:jwk:";function Q(r){return Og(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}`);Ba(n);let i=yf(n),o=P.string(i).toUint8Array(),s=yield ki.digest({data:o});return P.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 Ci(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 Bt(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 Ri(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 mf(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())})},kg=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},Ue=class r{static adjustSignatureToLowS(e){return Ze(this,arguments,void 0,function*({signature:t}){let n=yt.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:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield Q({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:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield Q({jwk:i}),i})}static compressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return yt.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:P.uint8Array(i.x).toBase64Url(),y:P.uint8Array(i.y).toBase64Url()};return o.kid=yield Q({jwk:o}),o})}static convertDerToCompactSignature(e){return Ze(this,arguments,void 0,function*({derSignature:t}){return yt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){return yt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Ze(this,void 0,void 0,function*(){let e=yt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Q({jwk:t}),t})}static getPublicKey(e){return Ze(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=kg(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Q({jwk:o})),o})}static privateKeyToBytes(e){return Ze(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 P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Ze(this,arguments,void 0,function*({publicKey:t}){if(!(Ci(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=P.base64Url(t.x).toUint8Array(),o=P.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 yt.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=an(t);return yt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ze(this,arguments,void 0,function*({privateKeyBytes:t}){return yt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Ze(this,arguments,void 0,function*({publicKeyBytes:t}){try{yt.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=an(i);return yt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Ze(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 gf=Ui(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),Cg=gf.create(BigInt("-3")),Rg=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Pg=ac({a:Cg,b:Rg,Fp:gf,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},ic),It=Pg;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())})},Mg=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},Re=class r{static adjustSignatureToLowS(e){return Qe(this,arguments,void 0,function*({signature:t}){let n=It.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:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield Q({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:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield Q({jwk:i}),i})}static compressPublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){return It.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:P.uint8Array(i.x).toBase64Url(),y:P.uint8Array(i.y).toBase64Url()};return o.kid=yield Q({jwk:o}),o})}static convertDerToCompactSignature(e){return Qe(this,arguments,void 0,function*({derSignature:t}){return It.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){return It.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return Qe(this,void 0,void 0,function*(){let e=It.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Q({jwk:t}),t})}static getPublicKey(e){return Qe(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=Mg(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Q({jwk:o})),o})}static privateKeyToBytes(e){return Qe(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 P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Qe(this,arguments,void 0,function*({publicKey:t}){if(!(Ci(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=P.base64Url(t.x).toUint8Array(),o=P.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 It.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=an(t);return It.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return Qe(this,arguments,void 0,function*({privateKeyBytes:t}){return It.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return Qe(this,arguments,void 0,function*({publicKeyBytes:t}){try{It.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=an(i);return It.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return Qe(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=It.getPublicKey(t));let n=It.ProjectivePoint.fromHex(t),i=pt(n.x,32),o=pt(n.y,32);return{x:i,y:o}})}};var Pr=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())})},No=class extends at{bytesToPrivateKey(e){return Pr(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Ue.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Re.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}bytesToPublicKey(e){return Pr(this,arguments,void 0,function*({algorithm:t,publicKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Ue.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Re.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return Pr(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 Ue.computePublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Re.computePublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return Pr(this,arguments,void 0,function*({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let n=yield Ue.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield Re.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return Pr(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 Ue.getPublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Re.getPublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return Pr(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 Ue.sign({key:t,data:n});case"P-256":return yield Re.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return Pr(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!Ci(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return yield Ue.verify({key:t,signature:n,data:i});case"P-256":return yield Re.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return Pr(this,arguments,void 0,function*({privateKey:t}){switch(t.crv){case"secp256k1":return yield Ue.privateKeyToBytes({privateKey:t});case"P-256":return yield Re.privateKeyToBytes({privateKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}publicKeyToBytes(e){return Pr(this,arguments,void 0,function*({publicKey:t}){switch(t.crv){case"secp256k1":return yield Ue.publicKeyToBytes({publicKey:t});case"P-256":return yield Re.publicKeyToBytes({publicKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var hc=BigInt(4294967295),Wu=BigInt(32);function wf(r,e=!1){return e?{h:Number(r&hc),l:Number(r>>Wu&hc)}:{h:Number(r>>Wu&hc)|0,l:Number(r&hc)|0}}function Lg(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}=wf(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var Ng=(r,e)=>BigInt(r>>>0)<<Wu|BigInt(e>>>0),$g=(r,e,t)=>r>>>t,Vg=(r,e,t)=>r<<32-t|e>>>t,Hg=(r,e,t)=>r>>>t|e<<32-t,Fg=(r,e,t)=>r<<32-t|e>>>t,qg=(r,e,t)=>r<<64-t|e>>>t-32,jg=(r,e,t)=>r>>>t-32|e<<64-t,zg=(r,e)=>e,Jg=(r,e)=>r,Gg=(r,e,t)=>r<<t|e>>>32-t,Wg=(r,e,t)=>e<<t|r>>>32-t,Yg=(r,e,t)=>e<<t-32|r>>>64-t,Xg=(r,e,t)=>r<<t-32|e>>>64-t;function Zg(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Qg=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ew=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,tw=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),rw=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,nw=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),iw=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var ow={fromBig:wf,split:Lg,toBig:Ng,shrSH:$g,shrSL:Vg,rotrSH:Hg,rotrSL:Fg,rotrBH:qg,rotrBL:jg,rotr32H:zg,rotr32L:Jg,rotlSH:Gg,rotlSL:Wg,rotlBH:Yg,rotlBL:Xg,add:Zg,add3L:Qg,add3H:ew,add4L:tw,add4H:rw,add5H:iw,add5L:nw},ne=ow;var[sw,cw]=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))),un=new Uint32Array(80),dn=new Uint32Array(80),Yu=class extends _i{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:b}=this;return[e,t,n,i,o,s,c,u,d,a,l,y,w,p,g,b]}set(e,t,n,i,o,s,c,u,d,a,l,y,w,p,g,b){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=b|0}process(e,t){for(let E=0;E<16;E++,t+=4)un[E]=e.getUint32(t),dn[E]=e.getUint32(t+=4);for(let E=16;E<80;E++){let _=un[E-15]|0,B=dn[E-15]|0,U=ne.rotrSH(_,B,1)^ne.rotrSH(_,B,8)^ne.shrSH(_,B,7),O=ne.rotrSL(_,B,1)^ne.rotrSL(_,B,8)^ne.shrSL(_,B,7),k=un[E-2]|0,Z=dn[E-2]|0,F=ne.rotrSH(k,Z,19)^ne.rotrBH(k,Z,61)^ne.shrSH(k,Z,6),j=ne.rotrSL(k,Z,19)^ne.rotrBL(k,Z,61)^ne.shrSL(k,Z,6),ue=ne.add4L(O,j,dn[E-7],dn[E-16]),ae=ne.add4H(ue,U,F,un[E-7],un[E-16]);un[E]=ae|0,dn[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:b,Hh:T,Hl:I}=this;for(let E=0;E<80;E++){let _=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),U=l&w^~l&g,O=y&p^~y&b,k=ne.add5L(I,B,O,cw[E],dn[E]),Z=ne.add5H(k,T,_,U,sw[E],un[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,Xe=i&s^i&u^s&u;T=g|0,I=b|0,g=w|0,b=p|0,w=l|0,p=y|0,{h:l,l:y}=ne.add(d|0,a|0,Z|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,Xe);n=ne.add3H(D,Z,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:b}=ne.add(this.Gh|0,this.Gl|0,g|0,b|0),{h:T,l:I}=ne.add(this.Hh|0,this.Hl|0,T|0,I|0),this.set(n,i,o,s,c,u,d,a,l,y,w,p,g,b,T,I)}roundClean(){un.fill(0),dn.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 Xu=nc(()=>new Yu);var Zt=BigInt(0),Dt=BigInt(1),fc=BigInt(2),aw=BigInt(8),uw={zip215:!0};function dw(r){let e=Lo(r);return Lt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function pc(r){let e=dw(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:u}=e,d=fc<<BigInt(c*8)-Dt,a=t.create,l=e.uvRatio||((K,S)=>{try{return{isValid:!0,value:t.sqrt(K*t.inv(S))}}catch{return{isValid:!1,value:Zt}}}),y=e.adjustScalarBytes||(K=>K),w=e.domain||((K,S,C)=>{if(S.length||C)throw new Error("Contexts/pre-hash are not supported");return K}),p=K=>typeof K=="bigint"&&Zt<K,g=(K,S)=>p(K)&&p(S)&&K<S,b=K=>K===Zt||g(K,d);function T(K,S){if(g(K,S))return K;throw new Error(`Expected valid scalar < ${S}, got ${typeof K} ${K}`)}function I(K){return K===Zt?K:T(K,n)}let E=new Map;function _(K){if(!(K instanceof B))throw new Error("ExtendedPoint expected")}class B{constructor(S,C,N,J){if(this.ex=S,this.ey=C,this.ez=N,this.et=J,!b(S))throw new Error("x required");if(!b(C))throw new Error("y required");if(!b(N))throw new Error("z required");if(!b(J))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(S){if(S instanceof B)throw new Error("extended point not allowed");let{x:C,y:N}=S||{};if(!b(C)||!b(N))throw new Error("invalid affine point");return new B(C,N,Dt,a(C*N))}static normalizeZ(S){let C=t.invertBatch(S.map(N=>N.ez));return S.map((N,J)=>N.toAffine(C[J])).map(B.fromAffine)}_setWindowSize(S){this._WINDOW_SIZE=S,E.delete(this)}assertValidity(){let{a:S,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:N,ey:J,ez:ee,et:W}=this,Y=a(N*N),G=a(J*J),te=a(ee*ee),Te=a(te*te),be=a(Y*S),ke=a(te*a(be+G)),Pe=a(Te+a(C*a(Y*G)));if(ke!==Pe)throw new Error("bad point: equation left != right (1)");let Ce=a(N*J),qe=a(ee*W);if(Ce!==qe)throw new Error("bad point: equation left != right (2)")}equals(S){_(S);let{ex:C,ey:N,ez:J}=this,{ex:ee,ey:W,ez:Y}=S,G=a(C*Y),te=a(ee*J),Te=a(N*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:S}=e,{ex:C,ey:N,ez:J}=this,ee=a(C*C),W=a(N*N),Y=a(fc*a(J*J)),G=a(S*ee),te=C+N,Te=a(a(te*te)-ee-W),be=G+W,ke=be-Y,Pe=G-W,Ce=a(Te*ke),qe=a(be*Pe),Ne=a(Te*Pe),gr=a(ke*be);return new B(Ce,qe,gr,Ne)}add(S){_(S);let{a:C,d:N}=e,{ex:J,ey:ee,ez:W,et:Y}=this,{ex:G,ey:te,ez:Te,et:be}=S;if(C===BigInt(-1)){let Qi=a((ee-J)*(te+G)),ls=a((ee+J)*(te-G)),eo=a(ls-Qi);if(eo===Zt)return this.double();let hs=a(W*fc*be),fs=a(Y*fc*Te),Ot=fs+hs,jr=ls+Qi,to=fs-hs,ps=a(Ot*eo),xn=a(jr*to),ys=a(Ot*to),oa=a(eo*jr);return new B(ps,xn,oa,ys)}let ke=a(J*G),Pe=a(ee*te),Ce=a(Y*N*be),qe=a(W*Te),Ne=a((J+ee)*(G+te)-ke-Pe),gr=qe-Ce,Fr=qe+Ce,Zi=a(Pe-C*ke),ds=a(Ne*gr),ia=a(Fr*Zi),qr=a(Ne*Zi),Ut=a(gr*Fr);return new B(ds,ia,Ut,qr)}subtract(S){return this.add(S.negate())}wNAF(S){return k.wNAFCached(this,E,S,B.normalizeZ)}multiply(S){let{p:C,f:N}=this.wNAF(T(S,n));return B.normalizeZ([C,N])[0]}multiplyUnsafe(S){let C=I(S);return C===Zt?O:this.equals(O)||C===Dt?this:this.equals(U)?this.wNAF(C).p:k.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return k.unsafeLadder(this,n).is0()}toAffine(S){let{ex:C,ey:N,ez:J}=this,ee=this.is0();S==null&&(S=ee?aw:t.inv(J));let W=a(C*S),Y=a(N*S),G=a(J*S);if(ee)return{x:Zt,y:Dt};if(G!==Dt)throw new Error("invZ was invalid");return{x:W,y:Y}}clearCofactor(){let{h:S}=e;return S===Dt?this:this.multiplyUnsafe(S)}static fromHex(S,C=!1){let{d:N,a:J}=e,ee=t.BYTES;S=ve("pointHex",S,ee);let W=S.slice(),Y=S[ee-1];W[ee-1]=Y&-129;let G=Wt(W);G===Zt||(C?T(G,d):T(G,t.ORDER));let te=a(G*G),Te=a(te-Dt),be=a(N*te-J),{isValid:ke,value:Pe}=l(Te,be);if(!ke)throw new Error("Point.fromHex: invalid y coordinate");let Ce=(Pe&Dt)===Dt,qe=(Y&128)!==0;if(!C&&Pe===Zt&&qe)throw new Error("Point.fromHex: x=0 and x_0=1");return qe!==Ce&&(Pe=a(-Pe)),B.fromAffine({x:Pe,y:G})}static fromPrivateKey(S){return j(S).point}toRawBytes(){let{x:S,y:C}=this.toAffine(),N=kr(C,t.BYTES);return N[N.length-1]|=S&Dt?128:0,N}toHex(){return Ur(this.toRawBytes())}}B.BASE=new B(e.Gx,e.Gy,Dt,a(e.Gx*e.Gy)),B.ZERO=new B(Zt,Dt,Dt,Zt);let{BASE:U,ZERO:O}=B,k=sc(B,c*8);function Z(K){return fe(K,n)}function F(K){return Z(Wt(K))}function j(K){let S=c;K=ve("private key",K,S);let C=ve("hashed private key",o(K),2*S),N=y(C.slice(0,S)),J=C.slice(S,2*S),ee=F(N),W=U.multiply(ee),Y=W.toRawBytes();return{head:N,prefix:J,scalar:ee,point:W,pointBytes:Y}}function ue(K){return j(K).pointBytes}function ae(K=new Uint8Array,...S){let C=Cr(...S);return F(o(w(C,ve("context",K),!!i)))}function Xe(K,S,C={}){K=ve("message",K),i&&(K=i(K));let{prefix:N,scalar:J,pointBytes:ee}=j(S),W=ae(C.context,N,K),Y=U.multiply(W).toRawBytes(),G=ae(C.context,Y,ee,K),te=Z(W+G*J);I(te);let Te=Cr(Y,kr(te,t.BYTES));return ve("result",Te,c*2)}let D=uw;function M(K,S,C,N=D){let{context:J,zip215:ee}=N,W=t.BYTES;K=ve("signature",K,2*W),S=ve("message",S),i&&(S=i(S));let Y=Wt(K.slice(W,2*W)),G,te,Te;try{G=B.fromHex(C,ee),te=B.fromHex(K.slice(0,W),ee),Te=U.multiplyUnsafe(Y)}catch{return!1}if(!ee&&G.isSmallOrder())return!1;let be=ae(J,te.toRawBytes(),G.toRawBytes(),S);return te.add(G.multiplyUnsafe(be)).subtract(Te).clearCofactor().equals(B.ZERO)}return U._setWindowSize(8),{CURVE:e,getPublicKey:ue,sign:Xe,verify:M,ExtendedPoint:B,utils:{getExtendedPublicKey:j,randomPrivateKey:()=>s(t.BYTES),precompute(K=8,S=B.BASE){return S._setWindowSize(K),S.multiply(BigInt(3)),S}}}}var $o=BigInt(0),Zu=BigInt(1);function lw(r){return Lt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function xf(r){let e=lw(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=>Pu(E,t-BigInt(2),t));function d(E,_,B){let U=n(E*(_-B));return _=n(_-U),B=n(B+U),[_,B]}function a(E){if(typeof E=="bigint"&&$o<=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,_){let B=a(E),U=a(_),O=B,k=Zu,Z=$o,F=B,j=Zu,ue=$o,ae;for(let D=BigInt(i-1);D>=$o;D--){let M=U>>D&Zu;ue^=M,ae=d(ue,k,F),k=ae[0],F=ae[1],ae=d(ue,Z,j),Z=ae[0],j=ae[1],ue=M;let X=k+Z,K=n(X*X),S=k-Z,C=n(S*S),N=K-C,J=F+j,ee=F-j,W=n(ee*X),Y=n(J*S),G=W+Y,te=W-Y;F=n(G*G),j=n(O*n(te*te)),k=n(K*C),Z=n(N*(K+n(l*N)))}ae=d(ue,k,F),k=ae[0],F=ae[1],ae=d(ue,Z,j),Z=ae[0],j=ae[1];let Xe=u(Z);return n(k*Xe)}function w(E){return kr(n(E),o)}function p(E){let _=ve("u coordinate",E,o);return s===32&&(_[31]&=127),Wt(_)}function g(E){let _=ve("scalar",E),B=_.length;if(B!==o&&B!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${B}`);return Wt(c(_))}function b(E,_){let B=p(_),U=g(E),O=y(B,U);if(O===$o)throw new Error("Invalid private or public key received");return w(O)}let T=w(e.Gu);function I(E){return b(E,T)}return{scalarMult:b,scalarMultBase:I,getSharedSecret:(E,_)=>b(E,_),getPublicKey:E=>I(E),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:T}}var Vo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),bf=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),PE=BigInt(0),hw=BigInt(1),Qu=BigInt(2),fw=BigInt(5),vf=BigInt(10),pw=BigInt(20),yw=BigInt(40),Ef=BigInt(80);function Af(r){let e=Vo,n=r*r%e*r%e,i=Ee(n,Qu,e)*n%e,o=Ee(i,hw,e)*r%e,s=Ee(o,fw,e)*o%e,c=Ee(s,vf,e)*s%e,u=Ee(c,pw,e)*c%e,d=Ee(u,yw,e)*u%e,a=Ee(d,Ef,e)*d%e,l=Ee(a,Ef,e)*d%e,y=Ee(l,vf,e)*s%e;return{pow_p_5_8:Ee(y,Qu,e)*r%e,b2:n}}function Tf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function mw(r,e){let t=Vo,n=fe(e*e*e,t),i=fe(n*n*e,t),o=Af(r*i).pow_p_5_8,s=fe(r*n*o,t),c=fe(e*s*s,t),u=s,d=fe(s*bf,t),a=c===r,l=c===fe(-r,t),y=c===fe(-r*bf,t);return a&&(s=u),(l||y)&&(s=d),ef(s,t)&&(s=fe(-s,t)),{isValid:a||l,value:s}}var $t=Ui(Vo,void 0,!0),Ho={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:$t,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Xu,randomBytes:Mo,adjustScalarBytes:Tf,uvRatio:mw},ln=pc(Ho);function Sf(r,e,t){if(e.length>255)throw new Error("Context is too big");return rc(ku("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var ME=pc({...Ho,domain:Sf}),LE=pc({...Ho,domain:Sf,prehash:Xu}),Jn=xf({P:Vo,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=Vo,{pow_p_5_8:t,b2:n}=Af(r);return fe(Ee(t,BigInt(3),e)*n,e)},adjustScalarBytes:Tf,randomBytes:Mo});function Bf(r){let{y:e}=ln.ExtendedPoint.fromHex(r),t=BigInt(1);return $t.toBytes($t.create((t+e)*$t.inv(t-e)))}function If(r){let e=Ho.hash(r.subarray(0,32));return Ho.adjustScalarBytes(e).subarray(0,32)}var gw=($t.ORDER+BigInt(3))/BigInt(8),NE=$t.pow(Qu,gw),$E=$t.sqrt($t.neg($t.ONE)),VE=($t.ORDER-BigInt(5))/BigInt(8),HE=BigInt(486662);var FE=tf($t,$t.neg(BigInt(486664)));var qE=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jE=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),zE=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),JE=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var GE=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())})},ww=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 bytesToPrivateKey(e){return Vt(this,arguments,void 0,function*({privateKeyBytes:t}){let n=ln.getPublicKey(t),i={crv:"Ed25519",d:P.uint8Array(t).toBase64Url(),kty:"OKP",x:P.uint8Array(n).toBase64Url()};return i.kid=yield Q({jwk:i}),i})}static bytesToPublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"Ed25519",x:P.uint8Array(t).toBase64Url()};return n.kid=yield Q({jwk:n}),n})}static computePublicKey(e){return Vt(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=ln.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:P.uint8Array(i).toBase64Url()};return o.kid=yield Q({jwk:o}),o})}static convertPrivateKeyToX25519(e){return Vt(this,arguments,void 0,function*({privateKey:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=If(n),o=Jn.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:P.uint8Array(i).toBase64Url(),x:P.uint8Array(o).toBase64Url()};return s.kid=yield Q({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=Bf(n),s={kty:"OKP",crv:"X25519",x:P.uint8Array(o).toBase64Url()};return s.kid=yield Q({jwk:s}),s})}static generateKey(){return Vt(this,void 0,void 0,function*(){let e=ln.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Q({jwk:t}),t})}static getPublicKey(e){return Vt(this,arguments,void 0,function*({key:t}){var n;if(!(Bt(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=t,o=ww(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Q({jwk:o})),o})}static privateKeyToBytes(e){return Vt(this,arguments,void 0,function*({privateKey:t}){if(!Bt(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return Vt(this,arguments,void 0,function*({publicKey:t}){if(!Ri(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return P.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 ln.sign(n,i)})}static validatePublicKey(e){return Vt(this,arguments,void 0,function*({publicKeyBytes:t}){try{ln.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 ln.verify(n,i,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())})},yc=class extends at{bytesToPrivateKey(e){return Mr(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"Ed25519":{let i=yield Oe.bytesToPrivateKey({privateKeyBytes:n});return i.alg="EdDSA",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"Ed25519":{let i=yield Oe.bytesToPublicKey({publicKeyBytes:n});return i.alg="EdDSA",i}default:throw new je(ze.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return Mr(this,arguments,void 0,function*({key:t}){if(!Bt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield Oe.computePublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return Mr(this,arguments,void 0,function*({algorithm:t}){switch(t){case"Ed25519":{let n=yield Oe.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return Mr(this,arguments,void 0,function*({key:t}){if(!Bt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let n=yield Oe.getPublicKey({key:t});return n.alg="EdDSA",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return Mr(this,arguments,void 0,function*({key:t,data:n}){if(!Bt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return yield Oe.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(!Ri(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return yield Oe.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"Ed25519":return yield Oe.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"Ed25519":return yield Oe.publicKeyToBytes({publicKey:t});default:throw new je(ze.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var xw=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},mc=class extends at{digest(e){return xw(this,arguments,void 0,function*({algorithm:t,data:n}){switch(t){case"SHA-256":return yield ki.digest({data:n})}})}};var hn=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())})},bw=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 hn(this,arguments,void 0,function*({privateKeyBytes:t}){let n=Jn.getPublicKey(t),i={kty:"OKP",crv:"X25519",d:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n).toBase64Url()};return i.kid=yield Q({jwk:i}),i})}static bytesToPublicKey(e){return hn(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"X25519",x:P.uint8Array(t).toBase64Url()};return n.kid=yield Q({jwk:n}),n})}static computePublicKey(e){return hn(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=Jn.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:P.uint8Array(i).toBase64Url()};return o.kid=yield Q({jwk:o}),o})}static generateKey(){return hn(this,void 0,void 0,function*(){let e=Jn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield Q({jwk:t}),t})}static getPublicKey(e){return hn(this,arguments,void 0,function*({key:t}){var n;if(!(Bt(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=t,o=bw(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield Q({jwk:o})),o})}static privateKeyToBytes(e){return hn(this,arguments,void 0,function*({privateKey:t}){if(!Bt(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return hn(this,arguments,void 0,function*({publicKey:t}){if(!Ri(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return P.base64Url(t.x).toUint8Array()})}static sharedSecret(e){return hn(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 Jn.getSharedSecret(i,o)})}};var Fo=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},gc=class extends at{bytesToPrivateKey(e){return Fo(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 Fo(this,arguments,void 0,function*({key:t}){if(!Bt(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 Fo(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 Fo(this,arguments,void 0,function*({key:t}){if(!Bt(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 Fo(this,arguments,void 0,function*({privateKey:t}){return dr.privateKeyToBytes({privateKey:t})})}};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())})},ed={Ed25519:{implementation:yc,names:["Ed25519"]},secp256k1:{implementation:No,names:["ES256K","secp256k1"]},secp256r1:{implementation:No,names:["ES256","secp256r1"]},"SHA-256":{implementation:mc,names:["SHA-256"]},X25519:{implementation:gc,names:["X25519"]}},ot=class{constructor(e){var t;this._algorithmInstances=new Map,this._keyStore=(t=e?.keyStore)!==null&&t!==void 0?t:new Xs}digest(e){return Lr(this,arguments,void 0,function*({algorithm:t,data:n}){return yield this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:n})})}exportKey(e){return Lr(this,arguments,void 0,function*({keyUri:t}){return yield this.getPrivateKey({keyUri:t})})}generateKey(e){return Lr(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=`${Gu}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return Lr(this,arguments,void 0,function*({key:t}){let n=yield Q({jwk:t});return`${Gu}${n}`})}getPublicKey(e){return Lr(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 Lr(this,arguments,void 0,function*({key:t}){var n;if(!mf(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 Q({jwk:i}));let o=yield this.getKeyUri({key:i});return yield this._keyStore.set(o,i),o})}sign(e){return Lr(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 Lr(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=ed[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 ed){let o=ed[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 Lr(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 wc=class r{static getJoseSignatureAlgorithmFromPublicKey(e){let t={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(t).includes(e.alg))return e.alg;if(e.crv&&Object.keys(t).includes(e.crv))return t[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(t).join(", ")}. Supported 'crv' values: ${Object.keys(t).join(", ")}.`)}static randomBytes(e){return hf(e)}static randomUuid(){return Oi.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let t=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let o=r.randomBytes(Math.ceil(e/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>t)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>t)}return n.toString().padStart(e,"0")}};var _f={};da(_f,{extractDidFragment:()=>mt,getServices:()=>vw,getVerificationMethodByKey:()=>Ew,getVerificationMethodTypes:()=>td,getVerificationMethods:()=>qo,getVerificationRelationshipsById:()=>rd,isDidService:()=>Df,isDidVerificationMethod:()=>bc,isDwnDidService:()=>Aw,isPortableDid:()=>Kf,keyBytesToMultibaseId:()=>nd,multibaseIdToKeyBytes:()=>id});function mt(r){if(typeof r=="string"&&r.length!==0)return r.split("#").pop()}function vw({didDocument:r,id:e,type:t}){return r?.service?.filter(n=>!(e&&n.id!==e||t&&n.type!==t))??[]}async function Ew({didDocument:r,publicKeyJwk:e,publicKeyMultibase:t}){let n=qo({didDocument:r});for(let i of n)if(e&&i.publicKeyJwk){if(await Q({jwk:e})===await Q({jwk:i.publicKeyJwk}))return i}else if(t&&i.publicKeyMultibase&&t===i.publicKeyMultibase)return i;return null}function qo({didDocument:r}){if(!r)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...r.verificationMethod?.filter(bc)??[]),Object.keys(ui).forEach(t=>{e.push(...r[t]?.filter(bc)??[])}),e}function td({didDocument:r}){let t=qo({didDocument:r}).map(n=>n.type);return[...new Set(t)]}function rd({didDocument:r,methodId:e}){let t=[];return Object.keys(ui).forEach(n=>{if(Array.isArray(r[n])){let i=r[n],o=mt(e);i.some(c=>{let u=mt(c)===o,d=bc(c)&&mt(c.id)===o;return u||d})&&t.push(n)}}),t}function Df(r){return!r||typeof r!="object"||r===null?!1:"id"in r&&"type"in r&&"serviceEndpoint"in r}function Aw(r){if(!Df(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 Kf(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 nd({keyBytes:r,multicodecCode:e,multicodecName:t}){let n=rt.addPrefix({code:e,data:r,name:t}),i=P.uint8Array(n).toBase58Btc();return P.base58Btc(i).toMultibase()}function id({multibaseKeyId:r}){try{let e=P.multibase(r).toBase58Btc(),t=P.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=rt.removePrefix({prefixedData:t});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new $("invalidDid",`Invalid multibase identifier: ${r}`)}}var gt=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=>mt(c.id)===(mt(e?.methodId)??mt(this.document.assertionMethod?.[0])));if(!(t&&t.publicKeyJwk))throw new $("internalError","A verification method intended for signing could not be determined from the DID Document");let n=await this.keyManager.getKeyUri({key:t.publicKeyJwk}),i=await this.keyManager.getPublicKey({keyUri:n}),o=this.keyManager;return{algorithm:wc.getJoseSignatureAlgorithmFromPublicKey(i),keyId:t.id,async sign({data:c}){return await o.sign({data:c,keyUri:n})},async verify({data:c,signature:u}){return await o.verify({data:c,key:i,signature:u})}}}static async import({portableDid:e,keyManager:t=new ot}){let n=qo({didDocument:e.document});if(n.length===0)throw new $("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 od="0123456789abcdef",Of=[],Uf=[];for(let r=0;r<256;r++)Of[r]=od[r>>4&15]+od[r&15],r<16&&(r<10?Uf[48+r]=r:Uf[87+r]=r);var sd=r=>{let e=r.length,t="",n=0;for(;n<e;)t+=Of[r[n++]];return t};var kf=(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 Cf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Tw=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(jo=0;jo<Cf.length;jo++)Tw[Cf.charCodeAt(jo)]=jo;var jo;var Sw=new TextDecoder,cd=(r,e)=>e?new TextDecoder(e).decode(r):Sw.decode(r),Bw=new TextEncoder,Ht=r=>Bw.encode(r);var Rf=typeof window<"u"?window:self,Pf=Rf.crypto||Rf.msCrypto||{},uT=Pf.subtle||Pf.webkitSubtle;function Pi(r){let e=r<0?1:0;return r=Math.abs(Number(r||1)),Math.floor(Math.log10(r))+1+e}function vc(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=kf(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(vc(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 Ec=new Uint8Array([101]),Mf=new Uint8Array([100]),Lf=new Uint8Array([108]);pe.buffer=function(r,e){r.push(Ht(e.length+":"),e)};pe.string=function(r,e){r.push(Ht(Ht(e).byteLength+":"+e))};pe.number=function(r,e){if(Number.isInteger(e))return r.push(Ht("i"+BigInt(e)+"e"));let t=2147483648,n=e/t<<0,i=e%t<<0,o=n*t+i;r.push(Ht("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(Mf);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(Ec)};pe.dictMap=function(r,e){r.push(Mf);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(Ec)};pe.list=function(r,e){let t=0,n=e.length;for(r.push(Lf);t<n;t++)e[t]!=null&&pe._encode(r,e[t]);r.push(Ec)};pe.listSet=function(r,e){r.push(Lf);for(let t of e)t!=null&&pe._encode(r,t);r.push(Ec)};var Nf=pe;var Iw=105,Dw=58,Kw=100,_w=108,ad=101;function $f(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)):Ht(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 Kw:return z.dictionary();case _w:return z.list();case Iw: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]!==ad;){let e=z.buffer(),t=cd(e);t.includes("\uFFFD")&&(t=sd(e)),r[t]=z.next()}return z.position++,r};z.list=function(){z.position++;let r=[];for(;z.data[z.position]!==ad;)r.push(z.next());return z.position++,r};z.integer=function(){let r=z.find(ad),e=$f(z.data,z.position+1,r);return z.position+=r+1-z.position,e};z.buffer=function(){let r=z.find(Dw),e=$f(z.data,z.position,r),t=++r+e;return z.position=t,z.encoding?cd(z.data.slice(r,t)):z.data.slice(r,t)};var Vf=z;function Uw(r){let e=2;for(let t of r)e+=Ac(t);return e}function Ow(r){let e=2;for(let[t,n]of r){let i=Ht(t).byteLength;e+=Pi(i)+1+i,e+=Ac(n)}return e}function kw(r){let e=2,t=Object.keys(r);for(let n=0;n<t.length;n++){let i=Ht(t[n]).byteLength;e+=Pi(i)+1+i,e+=Ac(r[t[n]])}return e}function Cw(r){let e=Ht(r).byteLength;return Pi(e)+1+e}function Rw(r){let e=r.byteLength-r.byteOffset;return Pi(e)+1+e}function Ac(r){if(r==null)return 0;let t=vc(r);switch(t){case"arraybufferview":return Rw(r);case"string":return Cw(r);case"array":case"set":return Uw(r);case"number":return 1+Pi(Math.floor(r))+1;case"bigint":return 1+r.toString().length+1;case"object":return kw(r);case"map":return Ow(r);default:throw new TypeError(`Unsupported value of type "${t}"`)}}var ud=Ac;var Pw=ud,dd={encode:Nf,decode:Vf,byteLength:ud,encodingLength:Pw};var Mw=/^(\d{1,3}\.){3,3}\d{1,3}$/;var Lw=/^(::)?(((\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=>Mw.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]}`}},Nr={name:"v6",size:16,isFormat:r=>r.length>0&&Lw.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 Hf(r){if(Qt.isFormat(r))return Qt.size;if(Nr.isFormat(r))return Nr.size;throw Error(`Invalid ip address: ${r}`)}function Ff(r){return Hf(r)===Qt.size?1:2}function qf(r,e,t){t=~~t;let n=Hf(r);return typeof e=="function"&&(e=e(t+n)),n===Qt.size?Qt.encode(r,e,t):Nr.encode(r,e,t)}function jf(r,e,t){if(e=~~e,t=t||r.length-e,t===Qt.size)return Qt.decode(r,e,t);if(t===Nr.size)return Nr.decode(r,e,t);throw Error(`Invalid buffer size needs to be ${Qt.size} for v4 or ${Nr.size} for v6.`)}function zo(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 Mi(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 zf(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 Jf(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 ld(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 hd(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 Gf(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 fd(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 pd(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 Li(r,e,t){let n=r.length;t==null&&(t=0),e===void 0&&(e=new Uint8Array(pd(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 Li.bytes=i-t,e}Li.bytes=0;function Ni(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 Ni.bytes=t-e,n}Ni.bytes=0;var fn=r=>r instanceof Uint8Array;function $r(r){return typeof r=="string"?pd(r):r.byteLength}function Tc(r){return r instanceof Uint8Array?r:Array.isArray(r)?new Uint8Array(r):Li(r)}function Sc(r,e,t){if(typeof e!="string")throw new Error("unknown input type");return Li(e,r,t),Li.bytes}var Jo={},Wf=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}`;Wf[s]=c,Jo[c]=s,Jo[`${t}${i}`]=s,Jo[`${e}${o}`]=s,Jo[`${t}${o}`]=s}}function Yf(r,e,t){let n="";for(let i=e;i<t;){let o=r[i++];n+=Wf[o]}return n}function yd(r){return r.length>>>1}function Xf(r,e,t,n){let i=0;for(;t<n;){let o=e.substr(i,2),s=Jo[o];if(s===void 0)return;r[t++]=s,i+=2}return r}var zw=Math.pow(2,24),Jw=Math.pow(2,16),Gw=Math.pow(2,8),lr=(r,e)=>r[e]*zw+r[e+1]*Jw+r[e+2]*Gw+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 wt(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:Ww(r,e,t,n,i)}function Ww(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 Xw=0,Zf=32768,gd=32768,Zw=~gd,ep=32768,Qw=~ep;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=Sc(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(Ni(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:$r(r.replace(/^\.|\.$/gm,""))+2}}),He=xe({encode(r,e,t){e||(e=new Uint8Array(He.encodingLength(r))),t||(t=0);let n=Sc(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=Ni(r,e+1,e+1+t);return He.decode.bytes=t+1,n},encodingLength(r){return $r(r)+1}}),$i=xe({bytes:12,encode(r,e,t){e||(e=new Uint8Array($i.encodingLength(r))),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?Zf:Xw;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&Zf?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:Jf(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:zf(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}}),Ic=xe({encode(r,e,t){e||(e=new Uint8Array(Ic.encodingLength(r))),t||(t=0);let n=r.length;return H(e,n,t),wt(r,e,t+2,0,n),Ic.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 Ic.decode.bytes=t+2,n},encodingLength(r){return r.length+2}}),Dc=xe({encode(r,e,t){return e||(e=new Uint8Array(Dc.encodingLength(r))),t||(t=0),L.encode(r,e,t+2),H(e,L.encode.bytes,t),Dc.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 Dc.decode.bytes=t+2,n},encodingLength(r){return L.encodingLength(r)+2}}),Kc=xe({encode(r,e,t){e||(e=new Uint8Array(Kc.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),Kc.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,Kc.decode.bytes=e-t,n},encodingLength(r){return 22+L.encodingLength(r.mname)+L.encodingLength(r.rname)}}),_c=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]=Tc(r[i])),!fn(r[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(_c.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,wt(i,e,t,0,i.length),t+=i.length}),H(e,t-n-2,n),_c.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 _c.decode.bytes=e-t,i},encodingLength(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=$r(t)+1:e+=t.length+1}),e}}),Uc=xe({encode(r,e,t){e||(e=new Uint8Array(Uc.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=Tc(r)),r||(r=new Uint8Array(0));let n=t;t+=2;let i=r.length;return wt(r,e,t,0,i),t+=i,H(e,t-n-2,n),Uc.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,Uc.decode.bytes=e-t,i},encodingLength(r){return r?(fn(r)?r.length:$r(r))+2:2}}),Oc=xe({encode(r,e,t){e||(e=new Uint8Array(Oc.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),Oc.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,Oc.decode.bytes=e-t,n},encodingLength(r){return He.encodingLength(r.cpu)+He.encodingLength(r.os)+2}}),Fi=xe({encode(r,e,t){return e||(e=new Uint8Array(Fi.encodingLength(r))),t||(t=0),L.encode(r,e,t+2),H(e,L.encode.bytes,t),Fi.encode.bytes=L.encode.bytes+2,e},decode(r,e){e||(e=0);let t=L.decode(r,e+2);return Fi.decode.bytes=L.decode.bytes+2,t},encodingLength(r){return L.encodingLength(r)+2}}),kc=xe({encode(r,e,t){e||(e=new Uint8Array(kc.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),kc.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),kc.decode.bytes=t+2,n},encodingLength(r){return 8+L.encodingLength(r.target)}}),pn=xe({encode(r,e,t){let n=pn.encodingLength(r);return e||(e=new Uint8Array(pn.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=pn.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,Sc(e,r.value,t),t+=$r(r.value),pn.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=Ni(r,e,n+t),i.issuerCritical=!!(i.flags&pn.ISSUER_CRITICAL),pn.decode.bytes=t+2,i},encodingLength(r){return He.encodingLength(r.tag)+He.encodingLength(r.value)+2}});pn.ISSUER_CRITICAL=128;var Cc=xe({encode(r,e,t){e||(e=new Uint8Array(Cc.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),Cc.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,Cc.decode.bytes=e-t,n},encodingLength(r){return 4+L.encodingLength(r.exchange)}}),tp=xe({encode(r,e,t){return e||(e=new Uint8Array(tp.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}),Rc=xe({encode(r,e,t){return e||(e=new Uint8Array(Rc.encodingLength(r))),t||(t=0),H(e,16,t),t+=2,Nr.encode(r,e,t),Rc.encode.bytes=18,e},decode(r,e){e||(e=0),e+=2;let t=Nr.decode(r,e);return Rc.decode.bytes=18,t},bytes:18}),Qf=r=>new Uint8Array(r),Vr=xe({encode(r,e,t){e||(e=new Uint8Array(Vr.encodingLength(r))),t||(t=0);let n=t,i=fd(r.code);if(H(e,i,t),t+=2,r.data)H(e,r.data.length,t),t+=2,wt(r.data,e,t),t+=r.data.length;else switch(i){case 8:{let o=r.sourcePrefixLength||0,s=r.family||Ff(r.ip,Qf),c=qf(r.ip,Qf),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,wt(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 Vr.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={};t.code=ie(r,e),t.type=Gf(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);wt(r,i,0,e,e+n-4),t.ip=jf(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 Vr.decode.bytes=n+4,t},encodingLength(r){if(r.data)return r.data.length+4;switch(fd(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}`)}}),yn=xe({encode(r,e,t){e||(e=new Uint8Array(yn.encodingLength(r))),t||(t=0);let n=t,i=Hi(r,Vr);return H(e,i,t),t=Qo(r,Vr,e,t+2),yn.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++]=Vr.decode(r,e),e+=Vr.decode.bytes,i-=Vr.decode.bytes;return yn.decode.bytes=e-t,n},encodingLength(r){return 2+Hi(r||[],Vr)}}),fr=xe({encode(r,e,t){e||(e=new Uint8Array(fr.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!fn(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,wt(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+$r(r.key)}});fr.PROTOCOL_DNSSEC=3;fr.ZONE_KEY=128;fr.SECURE_ENTRYPOINT=32768;var Go=xe({encode(r,e,t){e||(e=new Uint8Array(Go.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!fn(i))throw new Error("Signature must be a Buffer");return t+=2,H(e,Mi(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,wt(i,e,t,0,i.length),t+=i.length,Go.encode.bytes=t-n,H(e,Go.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ie(r,e);return e+=2,n.typeCovered=zo(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,Go.decode.bytes=e-t,n},encodingLength(r){return 20+L.encodingLength(r.signersName)+$r(r.signature)}}),Wo=xe({encode(r,e,t){e||(e=new Uint8Array(Wo.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,Wo.encode.bytes=t-n,H(e,Wo.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,Wo.decode.bytes=e-t,n},encodingLength(r){return 2+L.encodingLength(r.mbox||".")+L.encodingLength(r.txt||".")}}),Kt=xe({encode(r,e,t){e||(e=new Uint8Array(Kt.encodingLength(r))),t||(t=0);let n=t,i=[];for(let o=0;o<r.length;o++){let s=Mi(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=Tc(i[o]);e[t]=o,t+=1,e[t]=s.length,t+=1,wt(s,e,t,0,s.length),t+=s.length}return Kt.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=zo(o<<8|c<<3|d);i.push(a)}}e+=s}return Kt.decode.bytes=e-n,i},encodingLength(r){let e=[];for(let n=0;n<r.length;n++){let i=Mi(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}}),Yo=xe({encode(r,e,t){e||(e=new Uint8Array(Yo.encodingLength(r))),t||(t=0);let n=t;return t+=2,L.encode(r.nextDomain,e,t),t+=L.encode.bytes,Kt.encode(r.rrtypes,e,t),t+=Kt.encode.bytes,Yo.encode.bytes=t-n,H(e,Yo.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=Kt.decode(r,e,i-(e-t)),e+=Kt.decode.bytes,Yo.decode.bytes=e-t,n},encodingLength(r){return 2+L.encodingLength(r.nextDomain)+Kt.encodingLength(r.rrtypes)}}),Xo=xe({encode(r,e,t){e||(e=new Uint8Array(Xo.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!fn(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!fn(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,wt(i,e,t,0,i.length),t+=i.length,e[t]=o.length,t+=1,wt(o,e,t,0,o.length),t+=o.length,Kt.encode(r.rrtypes,e,t),t+=Kt.encode.bytes,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);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=Kt.decode(r,e,i-(e-t)),e+=Kt.decode.bytes,Xo.decode.bytes=e-t,n},encodingLength(r){return 8+r.salt.length+r.nextDomain.length+Kt.encodingLength(r.rrtypes)}}),Zo=xe({encode(r,e,t){e||(e=new Uint8Array(Zo.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!fn(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,wt(i,e,t,0,i.length),t+=i.length,Zo.encode.bytes=t-n,H(e,Zo.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,Zo.decode.bytes=e-t,n},encodingLength(r){return 6+$r(r.digest)}}),Vi=xe({encode(r,e,t){e||(e=new Uint8Array(Vi.encodingLength(r))),t||(t=0);let n=t;t+=2,e[t]=r.algorithm,t+=1,e[t]=r.hash,t+=1;let i=yd(r.fingerprint),o=wd(r.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${r.fingerprint}" for hashType=${r.hash}: ${i} != ${o}`);return Xf(e,r.fingerprint,t,t+=i),Vi.encode.bytes=t-n,H(e,Vi.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=wd(n.hash);return n.fingerprint=Yf(r,e,e+i),e+=i,Vi.decode.bytes=e-t,n},encodingLength(r){return 4+yd(r.fingerprint)}});function wd(r){if(r===1)return 20;if(r===2)return 32;throw new Error(`Invalid hashType=${r}, supported=1,2`)}Vi.getFingerprintLengthForHashType=wd;function md(r){switch(r.toUpperCase()){case"A":return tp;case"PTR":return Fi;case"CNAME":return Fi;case"DNAME":return Fi;case"TXT":return _c;case"NULL":return Uc;case"AAAA":return Rc;case"SRV":return kc;case"HINFO":return Oc;case"CAA":return pn;case"NS":return Dc;case"SOA":return Kc;case"MX":return Cc;case"OPT":return yn;case"DNSKEY":return fr;case"RRSIG":return Go;case"RP":return Wo;case"NSEC":return Yo;case"NSEC3":return Xo;case"SSHFP":return Vi;case"DS":return Zo}return Ic}var Ft=xe({encode(r,e,t){e||(e=new Uint8Array(Ft.encodingLength(r))),t||(t=0);let n=t;if(L.encode(r.name,e,t),t+=L.encode.bytes,H(e,Mi(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,yn.encode(r.options||[],e,t),t+=yn.encode.bytes}else{let i=hd(r.class===void 0?"IN":r.class);r.flush&&(i|=gd),H(e,i,t+2),hr(e,r.ttl||0,t+4),t+=8;let o=md(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return Ft.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=zo(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=yn.decode(r,e+8),e+=8+yn.decode.bytes;else{let i=ie(r,e+2);t.ttl=lr(r,e+4),t.class=ld(i&Zw),t.flush=!!(i&gd);let o=md(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return Ft.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+md(r.type).encodingLength(e)}}),qi=xe({encode(r,e,t){e||(e=new Uint8Array(qi.encodingLength(r))),t||(t=0);let n=t;return L.encode(r.name,e,t),t+=L.encode.bytes,H(e,Mi(r.type),t),t+=2,H(e,hd(r.class===void 0?"IN":r.class),t),t+=2,qi.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=zo(ie(r,e)),e+=2,n.class=ld(ie(r,e)),e+=2,!!(n.class&ep)&&(n.class&=Qw),qi.decode.bytes=e-t,n},encodingLength(r){return L.encodingLength(r.name)+4}});var rp=1024;var et={encode:function(r,e,t){let n=!e;n&&(e=new Uint8Array(ex(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),$i.encode(r,e,t),t+=$i.encode.bytes,t=Qo(r.questions,qi,e,t),t=Qo(r.answers,Ft,e,t),t=Qo(r.authorities,Ft,e,t),t=Qo(r.additionals,Ft,e,t),et.encode.bytes=t-i,n&&es.bytes!==e.length?e.slice(0,es.bytes):e},decode:function(r,e){e||(e=0);let t=e,n=$i.decode(r,e);return e+=$i.decode.bytes,e=Bc(n.questions,qi,r,e),e=Bc(n.answers,Ft,r,e),e=Bc(n.authorities,Ft,r,e),e=Bc(n.additionals,Ft,r,e),et.decode.bytes=e-t,n},encodingLength:function(r){return $i.encodingLength(r)+Hi(r.questions||[],qi)+Hi(r.answers||[],Ft)+Hi(r.authorities||[],Ft)+Hi(r.additionals||[],Ft)}};et.encode.bytes=0;et.decode.bytes=0;function Pc(r,e){if(r.questions)throw new Error("Only one .question object expected instead of a .questions array!");let t=Object.assign({type:e},r);return t.question&&(t.questions=[t.question],delete t.question),t}var Mc={encode:function(r,e,t){return e=et.encode(Pc(r,"query"),e,t),Mc.encode.bytes=et.encode.bytes,e},decode:function(r,e){let t=et.decode(r,e);return Mc.decode.bytes=et.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return et.encodingLength(Pc(r,"query"))}};Mc.encode.bytes=0;Mc.decode.bytes=0;var Lc={encode:function(r,e,t){return e=et.encode(Pc(r,"response"),e,t),Lc.encode.bytes=et.encode.bytes,e},decode:function(r,e){let t=et.decode(r,e);return Lc.decode.bytes=et.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return et.encodingLength(Pc(r,"response"))}};Lc.encode.bytes=0;Lc.decode.bytes=0;var es=et.encode,Nc=et.decode,ex=et.encodingLength;function np(r){let e=es(r),t=new Uint8Array(2+e.byteLength);return H(t,e.byteLength),wt(e,t,2,0,e.length),np.bytes=t.byteLength,t}np.bytes=0;function ip(r){let e=ie(r,0);if(r.byteLength<e+2)return null;let t=Nc(r.slice(2));return ip.bytes=Nc.bytes,t}ip.bytes=0;function Hi(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function Qo(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 Bc(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 qt=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 op=process.env.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",tx=0,mn=7200,$c=";",ut=",",cp=(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))(cp||{}),xd=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(xd||{}),ap=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(ap||{}),up={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},sp={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"},ts=class ts extends qt{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(a=>!(a.algorithm in up)))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}),y=await e.getPublicKey({keyUri:l}),w=a.id??y.kid??await Q({jwk:y});w=`${s}#${mt(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 gt({uri:s,document:c,metadata:{published:!1,...t.types&&{types:t.types}},keyManager:e});if(t.publish??!0){let a=await ts.publish({did:d,gatewayUri:t.gatewayUri});d.metadata=a.didDocumentMetadata}return d}static async import({portableDid:e,keyManager:t=new ot}){if(_e.parse(e.uri)?.method!==ts.methodName)throw new $("methodNotSupported","Method not supported");let i=await gt.import({portableDid:e,keyManager:t});if(!i.document.verificationMethod?.some(o=>o.id?.split("#").pop()==="0"))throw new $("invalidDidDocument","DID document must contain an Identity Key");return i}static async getSigningMethod({didDocument:e,methodId:t="#0"}){let n=_e.parse(e.id);if(n&&n.method!==this.methodName)throw new $("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>mt(o.id)===(mt(t)??mt(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new $("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:t=op}){return await Hc.put({did:e,gatewayUri:t})}static async resolve(e,t={}){let n=t?.gatewayUri??op;try{await Ge.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await Hc.get({didUri:e,gatewayUri:n});return{...Ke,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof $))throw new Error(i);return{...Ke,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};ts.methodName="dht";var Vc=ts,Hc=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=P.uint8Array(t).toBase32Z(),i=new URL(n,e).href,o;try{if(o=await fetch(i,{method:"GET"}),!o.ok)throw new $("notFound",`Pkarr record not found for: ${n}`)}catch(u){throw u instanceof $?u:new $("internalError",`Failed to fetch Pkarr record: ${u.message}`)}let s=await o.arrayBuffer();if(!s)throw new $("notFound",`Pkarr record not found for: ${n}`);if(s.byteLength<72)throw new $("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${s.byteLength}`);if(s.byteLength>1072)throw new $("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=P.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 $("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(ut);break}case c.startsWith("cnt"):{let u=Ge.parseTxtDataToString(s.data);n.controller=u.includes(ut)?u.split(ut):u;break}case c.startsWith("k"):{let{id:u,t:d,k:a,c:l,a:y}=Ge.parseTxtDataToObject(s.data),w=P.base64Url(a).toUint8Array(),p=xd[Number(d)],g=await Ge.keyConverter(p).bytesToPublicKey({publicKeyBytes:w});g.alg=y||sp[Number(d)];let b=c==="k0"?"0":u!==void 0?u:await Q({jwk:g});n.verificationMethod??=[];let T=`${e}#${b}`;n.verificationMethod.push({id:T,type:"JsonWebKey",controller:l??e,publicKeyJwk:g}),o.set(c,T);break}case c.startsWith("s"):{let{id:u,t:d,se:a,...l}=Ge.parseTxtDataToObject(s.data),y=a.includes(ut)?a.split(ut):[a],w=Object.fromEntries(Object.entries(l).map(([p,g])=>[p,g.includes(ut)?g.split(ut):g]));n.service??=[],n.service.push({...w,id:`${e}#${u}`,type:d,serviceEndpoint:y});break}case c.startsWith("typ"):{let{id:u}=Ge.parseTxtDataToObject(s.data);i.types=u.split(ut).map(d=>Number(d));break}case c.startsWith("did"):{let u=p=>p.split(ut).map(g=>o.get(g)).filter(g=>typeof g=="string"),{auth:d,asm:a,del:l,inv:y,agm:w}=Ge.parseTxtDataToObject(s.data);d&&(n.authentication=u(d)),a&&(n.assertionMethod=u(a)),l&&(n.capabilityDelegation=u(l)),y&&(n.capabilityInvocation=u(y)),w&&(n.keyAgreement=u(w));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:y,previousDid:w}=i;await Ge.validatePreviousDidProof({newDid:e.id,previousDidProof:i}),o.push({type:"TXT",name:"_prv._did.",ttl:mn,data:`id=${w};s=${y}`})}if(e.alsoKnownAs&&o.push({type:"TXT",name:"_aka._did.",ttl:mn,data:e.alsoKnownAs.join(ut)}),e.controller){let y=Array.isArray(e.controller)?e.controller.join(ut):e.controller;o.push({type:"TXT",name:"_cnt._did.",ttl:mn,data:y})}for(let[y,w]of e.verificationMethod?.entries()??[]){let p=`k${y}`;d.push(p);let g=w.id.split("#").pop();c.set(g,p);let b=w.publicKeyJwk;if(!(b?.crv&&b.crv in up))throw new $("invalidPublicKeyType",`Verification method '${w.id}' contains an unsupported key type: ${b?.crv??"undefined"}`);let T=xd[b.crv],I=await Ge.keyConverter(b.crv).publicKeyToBytes({publicKey:b}),E=P.uint8Array(I).toBase64Url(),_=[`t=${T}`,`k=${E}`];g!=="0"&&await Q({jwk:b})!==g&&_.unshift(`id=${g}`),b.alg!==sp[T]&&_.push(`a=${b.alg}`),w.controller!==e.id&&_.push(`c=${w.controller}`),o.push({type:"TXT",name:`_${p}._did.`,ttl:mn,data:_.join($c)})}e.service?.forEach((y,w)=>{let p=`s${w}`;u.push(p);let{id:g,type:b,serviceEndpoint:T,...I}=y;g=mt(g),T=Array.isArray(T)?T.join(","):T;let _=Object.entries({id:g,t:b,se:T,...I}).map(([U,O])=>`${U}=${O}`).join($c),B=Ge.chunkDataIfNeeded(_);o.push({type:"TXT",name:`_${p}._did.`,ttl:mn,data:B})});let a=[`v=${tx}`];if(d.length&&a.push(`vm=${d.join(ut)}`),Object.keys(ui).forEach(y=>{let w=e[y]?.map(p=>c.get(p.split("#").pop()));if(w){let p=ap[y];a.push(`${p}=${w.join(ut)}`)}}),u.length&&a.push(`svc=${u.join(ut)}`),t.types?.length){let w=t.types.map(p=>typeof p=="string"?cp[p]:p);o.push({type:"TXT",name:"_typ._did.",ttl:mn,data:`id=${w.join(ut)}`})}o.push({type:"TXT",name:"_did."+r.getUniqueDidSuffix(e.id)+".",ttl:mn,data:a.join($c)});for(let y of n||[])s.push({type:"NS",name:"_did."+r.getUniqueDidSuffix(e.id)+".",ttl:mn,data:y+"."});return{id:0,type:"response",flags:rp,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=es(e),s=dd.encode({seq:i,v:o}).subarray(1,-1);if(s.length>1e3)throw new $("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 Oe.bytesToPublicKey({publicKeyBytes:t})}static identifierToIdentityKeyBytes({didUri:e}){let t=_e.parse(e);if(!t)throw new $("invalidDid",`Invalid DID URI: ${e}`);if(t.method!==Vc.methodName)throw new $("methodNotSupported",`Method not supported: ${t.method}`);let n;try{n=P.base32Z(t.id).toUint8Array()}catch{throw new $("invalidPublicKey","Failed to decode method-specific identifier")}if(n.length!==32)throw new $("invalidPublicKeyLength",`Invalid public key length: ${n.length}`);return n}static async identityKeyToIdentifier({identityKey:e}){let t=await Oe.publicKeyToBytes({publicKey:e}),n=P.uint8Array(t).toBase32Z();return`did:${Vc.methodName}:${n}`}static keyConverter(e){let n={Ed25519:Oe,"P-256":{publicKeyToBytes:async({publicKey:i})=>{let o=await Re.publicKeyToBytes({publicKey:i});return await Re.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:Re.bytesToPublicKey,privateKeyToBytes:Re.privateKeyToBytes,bytesToPrivateKey:Re.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:i})=>{let o=await Ue.publicKeyToBytes({publicKey:i});return await Ue.compressPublicKey({publicKeyBytes:o})},bytesToPublicKey:Ue.bytesToPublicKey,privateKeyToBytes:Ue.privateKeyToBytes,bytesToPrivateKey:Ue.bytesToPrivateKey},X25519:dr}[e];if(!n)throw new $("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static async parseBep44GetMessage({bep44Message:e}){let t=await Oe.bytesToPublicKey({publicKeyBytes:e.k}),n=dd.encode({seq:e.seq,v:e.v}).subarray(1,-1);if(!await Oe.verify({key:t,signature:e.sig,data:n}))throw new $("invalidSignature","Invalid signature for DHT BEP44 message");return Nc(e.v)}static parseTxtDataToObject(e){return this.parseTxtDataToString(e).split($c).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 P.uint8Array(e).toString();if(Array.isArray(e))return e.map(t=>this.parseTxtDataToString(t)).join("");throw new $("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=P.base64Url(t.signature).toUint8Array();if(!await Oe.verify({key:n,data:i,signature:o}))throw new $("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 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 FT=new Uint8Array(0);var bd=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var vd=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ed=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return dp(this,e)}},Ad=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 Ad({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),Td=class{constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new vd(e,t,n),this.decoder=new Ed(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},rx=({name:r,prefix:e,encode:t,decode:n})=>new Td(r,e,t,n);var nx=(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},ix=(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},rs=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>rx({prefix:e,name:r,encode(i){return ix(i,n,t)},decode(i){return nx(i,n,t,r)}});var YT=rs({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),XT=rs({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ns=rs({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ZT=rs({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xt=class r{static encode(e){return ns.baseEncode(e)}static decodeAsBytes(e,t){if(!r.isBase64UrlString(e))throw new ge(Ae.EncodedStringIncorrectEncoding,`Given ${t} must be base64url string.`);return ns.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 vp=An(hp(),1);var Sd;(function(r){r.Public="public",r.Private="private"})(Sd||(Sd={}));var _t=Sd;var Fe=class{static validateEs256kOperationKey(e,t){let n=new Set(["kty","crv","x","y"]);t===_t.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===_t.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(!xt.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 is=class{};is.hashAlgorithmInMultihashCode=18;is.maxCanonicalizedDeltaSizeInBytes=1e3;var dt=is;var yp=An(pp(),1);var er=class r{static canonicalizeAsBytes(e){let t=r.removeAllUndefinedProperties(e),n=yp.default(t);return xt.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 ox=wp,mp=128,sx=127,cx=~sx,ax=Math.pow(2,31);function wp(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ax;)e[t++]=r&255|mp,r/=128;for(;r&cx;)e[t++]=r&255|mp,r>>>=7;return e[t]=r|0,wp.bytes=t-n+1,e}var ux=Bd,dx=128,gp=127;function Bd(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Bd.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&gp)<<i:(s&gp)*Math.pow(2,i),i+=7}while(s>=dx);return Bd.bytes=o-n,t}var lx=Math.pow(2,7),hx=Math.pow(2,14),fx=Math.pow(2,21),px=Math.pow(2,28),yx=Math.pow(2,35),mx=Math.pow(2,42),gx=Math.pow(2,49),wx=Math.pow(2,56),xx=Math.pow(2,63),bx=function(r){return r<lx?1:r<hx?2:r<fx?3:r<px?4:r<yx?5:r<mx?6:r<gx?7:r<wx?8:r<xx?9:10},vx={encode:ox,decode:ux,encodingLength:bx},Ex=vx,os=Ex;var Id=(r,e=0)=>[os.decode(r,e),os.decode.bytes],Dd=(r,e,t=0)=>(os.encode(r,e,t),e),Kd=r=>os.encodingLength(r);var _d=(r,e)=>{let t=e.byteLength,n=Kd(r),i=n+Kd(t),o=new Uint8Array(i+t);return Dd(r,o,0),Dd(t,o,n),o.set(e,i),new qc(r,t,e,o)},xp=r=>{let e=bd(r),[t,n]=Id(e),[i,o]=Id(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new qc(t,i,s,e)};var qc=class{constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Od=({name:r,code:e,encode:t})=>new Ud(r,e,t),Ud=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?_d(this.code,t):t.then(n=>_d(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)),jc=Od({name:"sha2-256",code:18,encode:bp("SHA-256")}),b6=Od({name:"sha2-512",code:19,encode:bp("SHA-512")});var ss=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 ss(this,void 0,void 0,function*(){let n;switch(t){case 18:n=(yield jc.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 ss(this,void 0,void 0,function*(){let n;switch(t){case 18:n=yield jc.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 ss(this,void 0,void 0,function*(){let n=er.canonicalizeAsBytes(e);return yield r.hashThenEncode(n,t)})}static canonicalizeThenDoubleHashThenEncode(e,t){return ss(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 ss(this,void 0,void 0,function*(){let n=yield r.hash(e,t);return xt.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,t){let n,i=xt.decodeAsBytes(e,t);try{n=xp(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 kd;(function(r){r.Create="create",r.Update="update",r.Deactivate="deactivate",r.Recover="recover"})(kd||(kd={}));var cs=kd;var Cd;(function(r){r.Replace="replace",r.AddPublicKeys="add-public-keys",r.RemovePublicKeys="remove-public-keys",r.AddServices="add-services",r.RemoveServices="remove-services"})(Cd||(Cd={}));var Gn=Cd;var zc=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(a){try{d(n.next(a))}catch(l){s(l)}}function u(a){try{d(n.throw(a))}catch(l){s(l)}}function d(a){a.done?o(a.value):i(a.value).then(c,u)}d((n=n.apply(r,e||[])).next())})},gn=class r{static createCreateRequest(e){return zc(this,void 0,void 0,function*(){let t=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;Fe.validateEs256kOperationKey(t,_t.Public),Fe.validateEs256kOperationKey(n,_t.Public),r.validateDidDocumentKeys(i),r.validateServices(o);let s=dt.hashAlgorithmInMultihashCode,c=[{action:Gn.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:cs.Create,suffixData:a,delta:u}})}static createDeactivateRequest(e){return zc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.recoveryPublicKey,_t.Public);let t=dt.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:cs.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return zc(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.recoveryPublicKey,_t.Public),Fe.validateEs256kOperationKey(e.nextRecoveryPublicKey,_t.Public),Fe.validateEs256kOperationKey(e.nextUpdatePublicKey,_t.Public),r.validateDidDocumentKeys(e.document.publicKeys),r.validateServices(e.document.services);let t=dt.hashAlgorithmInMultihashCode,n=yield We.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i=[{action:Gn.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:cs.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:a}})}static createUpdateRequest(e){return zc(this,void 0,void 0,function*(){if(r.validateDidSuffix(e.didSuffix),Fe.validateEs256kOperationKey(e.updatePublicKey,_t.Public),Fe.validateEs256kOperationKey(e.nextUpdatePublicKey,_t.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:Gn.AddServices,services:n};t.push(p)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let p={action:Gn.RemoveServices,ids:i};t.push(p)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let p={action:Gn.AddPublicKeys,publicKeys:o};t.push(p)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let p={action:Gn.RemovePublicKeys,ids:s};t.push(p)}let c=dt.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),y={updateKey:e.updatePublicKey,deltaHash:l},w=yield e.signer.sign({alg:"ES256K"},y);return{type:cs.Update,didSuffix:e.didSuffix,revealValue:u,delta:a,signedData:w}})}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 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"&&vp.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 Ep=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())})},ji=class r{static createLongFormDid(e){return Ep(this,void 0,void 0,function*(){let t=yield gn.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=xt.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return Ep(this,void 0,void 0,function*(){let t=er.canonicalizeAsBytes(e),n=yield We.hash(t,dt.hashAlgorithmInMultihashCode);return xt.encode(n)})}};var tt=2n**255n-19n,Gc=2n**252n+27742317777372353535851937790883648493n,Pd=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Md=0x6666666666666666666666666666666666666666666666666666666666666658n,Jc={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:tt,n:Gc,h:8,Gx:Pd,Gy:Md},bt=(r="")=>{throw new Error(r)},Dp=r=>typeof r=="string",Ld=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?bt("Uint8Array expected"):r,zi=r=>new Uint8Array(r),Sx=(r,e)=>Ld(Dp(r)?$d(r):zi(r),e),q=(r,e=tt)=>{let t=r%e;return t>=0n?t:e+t},Ap=r=>r instanceof wn?r:bt("Point expected"),Tp,wn=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}=Jc;e=Sx(e,32);let i=e.slice();i[31]=e[31]&-129;let o=Ix(i);o===0n||(t&&!(0n<o&&o<tt)&&bt("bad y coord 1"),!t&&!(0n<o&&o<2n**256n)&&bt("bad y coord 2"));let s=q(o*o),c=q(s-1n),u=q(n*s+1n),{isValid:d,value:a}=Kx(c,u);d||bt("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}=Ap(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(Wc)}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}=Jc,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),b=q(a*w),T=q(y*l);return new r(p,g,T,b)}add(e){let{ex:t,ey:n,ez:i,et:o}=this,{ex:s,ey:c,ez:u,et:d}=Ap(e),{a,d:l}=Jc,y=q(t*s),w=q(n*c),p=q(o*l*d),g=q(i*u),b=q((t+n)*(s+c)-y-w),T=q(g-p),I=q(g+p),E=q(w-a*y),_=q(b*T),B=q(I*E),U=q(b*E),O=q(T*I);return new r(_,B,O,U)}mul(e,t=!0){if(e===0n)return t===!0?bt("cannot multiply by 0"):Wc;if(typeof e=="bigint"&&0n<e&&e<Gc||bt("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Yc))return Ux(e).p;let n=Wc,i=Yc;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):t&&(i=i.add(o));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(Jc.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(Gc/2n,!1).double();return Gc%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:t,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=_p(n);return q(n*i)!==1n&&bt("invalid inverse"),{x:q(e*i),y:q(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=Bx(t);return n[31]|=e&1n?128:0,n}toHex(){return Nd(this.toRawBytes())}};wn.BASE=new wn(Pd,Md,1n,q(Pd*Md));wn.ZERO=new wn(0n,1n,1n,0n);var{BASE:Yc,ZERO:Wc}=wn,Kp=(r,e)=>r.toString(16).padStart(e,"0"),Nd=r=>Array.from(r).map(e=>Kp(e,2)).join(""),$d=r=>{let e=r.length;(!Dp(r)||e%2)&&bt("hex invalid 1");let t=zi(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)&&bt("hex invalid 2"),t[n]=s}return t},Bx=r=>$d(Kp(r,32*2)).reverse(),Ix=r=>BigInt("0x"+Nd(zi(Ld(r)).reverse())),Sp=(...r)=>{let e=zi(r.reduce((n,i)=>n+Ld(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},_p=(r,e=tt)=>{(r===0n||e<=0n)&&bt("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):bt("no inverse")},pr=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=tt;return t},Dx=r=>{let t=r*r%tt*r%tt,n=pr(t,2n)*t%tt,i=pr(n,1n)*r%tt,o=pr(i,5n)*i%tt,s=pr(o,10n)*o%tt,c=pr(s,20n)*s%tt,u=pr(c,40n)*c%tt,d=pr(u,80n)*u%tt,a=pr(d,80n)*u%tt,l=pr(a,10n)*o%tt;return{pow_p_5_8:pr(l,2n)*r%tt,b2:t}},Bp=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Kx=(r,e)=>{let t=q(e*e*e),n=q(t*t*e),i=Dx(r*n).pow_p_5_8,o=q(r*t*i),s=q(e*o*o),c=o,u=q(o*Bp),d=s===r,a=s===q(-r),l=s===q(-r*Bp);return d&&(o=c),(a||l)&&(o=u),(q(o)&1n)===1n&&(o=q(-o)),{isValid:d||a,value:o}};var Rd;var Ip=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Up={bytesToHex:Nd,hexToBytes:$d,concatBytes:Sp,mod:q,invert:_p,randomBytes:r=>{let e=Ip();return e||bt("crypto.getRandomValues must be defined"),e.getRandomValues(zi(r))},sha512Async:async(...r)=>{let e=Ip();e||bt("crypto.subtle or etc.sha512Async must be defined");let t=Sp(...r);return zi(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(Up,{sha512Sync:{configurable:!1,get(){return Rd},set(r){Rd||(Rd=r)}}});var Wn=8,_x=()=>{let r=[],e=256/Wn+1,t=Yc,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(Wn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Ux=r=>{let e=Tp||(Tp=_x()),t=(a,l)=>{let y=l.negate();return a?y:l},n=Wc,i=Yc,o=1+256/Wn,s=2**(Wn-1),c=BigInt(2**Wn-1),u=2**Wn,d=BigInt(Wn);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,b=y<0;y===0?i=i.add(t(g,e[w])):n=n.add(t(b,e[p]))}return{p:n,f:i}};var Hd=2n**256n,Xn=Hd-0x1000003d1n,Fd=Hd-0x14551231950b75fc4402da1732fc9bebfn,Np=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,$p=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,Vp={p:Xn,n:Fd,a:0n,b:7n,Gx:Np,Gy:$p},Ji=32,Op=r=>V(V(r*r)*r+Vp.b),Ye=(r="")=>{throw new Error(r)},Qc=r=>typeof r=="bigint",Hp=r=>typeof r=="string",Vd=r=>Qc(r)&&0n<r&&r<Xn,Fp=r=>Qc(r)&&0n<r&&r<Fd,qp=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?Ye("Uint8Array expected"):r,us=r=>new Uint8Array(r),qd=(r,e)=>qp(Hp(r)?ea(r):us(r),e),V=(r,e=Xn)=>{let t=r%e;return t>=0n?t:e+t},kp=r=>r instanceof Hr?r:Ye("Point expected"),Cp,Hr=class r{constructor(e,t,n){this.px=e,this.py=t,this.pz=n}static fromAffine(e){return new r(e.x,e.y,1n)}static fromHex(e){e=qd(e);let t,n=e[0],i=e.subarray(1),o=Rp(i,0,Ji),s=e.length;if(s===33&&[2,3].includes(n)){Vd(o)||Ye("Point hex invalid: x not FE");let c=kx(Op(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,Rp(i,Ji,2*Ji),1n)),t?t.ok():Ye("Point is not on curve")}static fromPrivateKey(e){return as.mul(Cx(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}=kp(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}=kp(e),{a:u,b:d}=Vp,a=0n,l=0n,y=0n,w=V(d*3n),p=V(t*o),g=V(n*s),b=V(i*c),T=V(t+n),I=V(o+s);T=V(T*I),I=V(p+g),T=V(T-I),I=V(t+i);let E=V(o+c);return I=V(I*E),E=V(p+b),I=V(I-E),E=V(n+i),a=V(s+c),E=V(E*a),a=V(g+b),E=V(E-a),y=V(u*I),a=V(w*b),y=V(a+y),a=V(g-y),y=V(g+y),l=V(a*y),g=V(p+p),g=V(g+p),b=V(u*b),I=V(w*I),g=V(g+b),b=V(p-b),b=V(u*b),I=V(I+b),p=V(g*I),l=V(l+p),p=V(E*I),a=V(T*a),a=V(a-p),p=V(T*g),y=V(E*y),y=V(y+p),new r(a,l,y)}mul(e,t=!0){if(!t&&e===0n)return Xc;if(Fp(e)||Ye("invalid scalar"),this.equals(as))return Mx(e).p;let n=Xc,i=as;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?n=n.add(o):t&&(i=i.add(o));return n}mulAddQUns(e,t,n){return this.mul(t,!1).add(e.mul(n,!1)).ok()}toAffine(){let{px:e,py:t,pz:n}=this;if(this.equals(Xc))return{x:0n,y:0n};if(n===1n)return{x:e,y:t};let i=zp(n);return V(n*i)!==1n&&Ye("invalid inverse"),{x:V(e*i),y:V(t*i)}}assertValidity(){let{x:e,y:t}=this.aff();return(!Vd(e)||!Vd(t))&&Ye("Point invalid: x or y"),V(t*t)===Op(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")+Pp(t)+(e?"":Pp(n))}toRawBytes(e=!0){return ea(this.toHex(e))}};Hr.BASE=new Hr(Np,$p,1n);Hr.ZERO=new Hr(0n,1n,0n);var{BASE:as,ZERO:Xc}=Hr,jp=(r,e)=>r.toString(16).padStart(e,"0"),jd=r=>Array.from(r).map(e=>jp(e,2)).join(""),ea=r=>{let e=r.length;(!Hp(r)||e%2)&&Ye("hex invalid 1");let t=us(e/2);for(let n=0;n<t.length;n++){let i=n*2,o=r.slice(i,i+2),s=Number.parseInt(o,16);(Number.isNaN(s)||s<0)&&Ye("hex invalid 2"),t[n]=s}return t},ta=r=>BigInt("0x"+(jd(r)||"0")),Rp=(r,e,t)=>ta(r.slice(e,t)),zd=r=>Qc(r)&&r>=0n&&r<Hd?ea(jp(r,2*Ji)):Ye("bigint expected"),Pp=r=>jd(zd(r)),Mp=(...r)=>{let e=us(r.reduce((n,i)=>n+qp(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},zp=(r,e=Xn)=>{(r===0n||e<=0n)&&Ye("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):Ye("no inverse")},kx=r=>{let e=1n;for(let t=r,n=(Xn+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*t%Xn),t=t*t%Xn;return V(e*e)===r?e:Ye("sqrt invalid")},Cx=r=>(Qc(r)||(r=ta(qd(r,Ji))),Fp(r)?r:Ye("private key out of range"));var Lp=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Zc;function Rx(r){r=qd(r);let e=Ji+8;(r.length<e||r.length>1024)&&Ye("expected proper params");let t=V(ta(r),Fd-1n)+1n;return zd(t)}var Jp={hexToBytes:ea,bytesToHex:jd,concatBytes:Mp,bytesToNumberBE:ta,numberToBytesBE:zd,mod:V,invert:zp,hmacSha256Async:async(r,...e)=>{let t=Lp();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 us(await n.sign("HMAC",i,Mp(...e)))},hmacSha256Sync:Zc,hashToPrivateKey:Rx,randomBytes:r=>{let e=Lp();return e||Ye("crypto.getRandomValues must be defined"),e.getRandomValues(us(r))}};Object.defineProperties(Jp,{hmacSha256Sync:{configurable:!1,get(){return Zc},set(r){Zc||(Zc=r)}}});var Yn=8,Px=()=>{let r=[],e=256/Yn+1,t=as,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(Yn-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Mx=r=>{let e=Cp||(Cp=Px()),t=(a,l)=>{let y=l.negate();return a?y:l},n=Xc,i=as,o=1+256/Yn,s=2**(Yn-1),c=BigInt(2**Yn-1),u=2**Yn,d=BigInt(Yn);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,b=y<0;y===0?i=i.add(t(g,e[w])):n=n.add(t(b,e[p]))}return{p:n,f:i}};var Wp;(function(r){r.Mainnet="mainnet",r.Testnet="test"})(Wp||(Wp={}));var Yp;(function(r){r.Authentication="authentication",r.AssertionMethod="assertionMethod",r.CapabilityInvocation="capabilityInvocation",r.CapabilityDelegation="capabilityDelegation",r.KeyAgreement="keyAgreement"})(Yp||(Yp={}));var Lx=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(Lx||{}),Nx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},Xp="https://ion.tbd.engineering",Qn=class Qn extends qt{static async create({keyManager:e=new ot,options:t={}}={}){if(t.verificationMethods?.some(p=>!(p.algorithm in Nx)))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}),b=await e.getPublicKey({keyUri:g});o.push({id:p.id,publicKeyJwk:b,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 Zn.computeLongFormDidUri({recoveryKey:c,updateKey:d,services:t.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:y}=await Qn.resolve(a,{gatewayUri:t.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${y?.error}`);let w=new gt({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 Qn.publish({did:w,gatewayUri:t.gatewayUri});w.metadata=p.didDocumentMetadata}return w}static async getSigningMethod({didDocument:e,methodId:t}){let n=_e.parse(e.id);if(n&&n.method!==this.methodName)throw new $("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>o.id===(t??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new $("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(_e.parse(e.uri)?.method!==Qn.methodName)throw new $("methodNotSupported","Method not supported");return await gt.import({portableDid:e,keyManager:t})}static async publish({did:e,gatewayUri:t=Xp}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:rd({didDocument:e.document,methodId:s.id})}))??[],i=await Zn.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await Zn.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=Zn.appendPathToUrl({baseUrl: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=_e.parse(e);if(!n)return{...Ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Qn.methodName)return{...Ke,didResolutionMetadata:{error:"methodNotSupported"}};let i=t?.gatewayUri??Xp;try{let o=Zn.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(o);if(!s.ok)throw new $("notFound",`Unable to find DID document for: ${e}`);let{didDocument:c,didDocumentMetadata:u}=await s.json();return{...Ke,...c&&{didDocument:c},didDocumentMetadata:{published:u?.method?.published,...u}}}catch(o){if(!(o instanceof $))throw new Error(o);return{...Ke,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};Qn.methodName="ion";var Zp=Qn,Zn=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 ji.createLongFormDid({document:o,recoveryKey:s,updateKey:c})}static async constructCreateRequest({ionDocument:e,recoveryKey:t,updateKey:n}){return await gn.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 Q({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 ei=class ei extends qt{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=P.object(o).toBase64Url(),c=`did:${ei.methodName}:${s}`,d=(await ei.resolve(c)).didDocument;return new gt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=_e.parse(e.id);if(t&&t.method!==this.methodName)throw new $("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new $("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(_e.parse(e.uri)?.method!==ei.methodName)throw new $("methodNotSupported","Method not supported");let i=await gt.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new $("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){let n=_e.parse(e),i;try{i=n?P.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...Ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ei.methodName)return{...Ke,didResolutionMetadata:{error:"methodNotSupported"}};let o={"@context":["https://www.w3.org/ns/did/v1"],id:n.uri},s=`${o.id}#0`;switch(o.verificationMethod=[{id:s,type:"JsonWebKey",controller:o.id,publicKeyJwk:i}],o.authentication=[s],o.assertionMethod=[s],o.capabilityInvocation=[s],o.capabilityDelegation=[s],o.keyAgreement=[s],i.use){case"sig":{delete o.keyAgreement;break}case"enc":{delete o.authentication,delete o.assertionMethod,delete o.capabilityInvocation,delete o.capabilityDelegation;break}}return{...Ke,didDocument:o}}};ei.methodName="jwk";var Qp=ei;var $x=(n=>(n.Ed25519="Ed25519",n.secp256k1="secp256k1",n.secp256r1="secp256r1",n))($x||{}),ey={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},Vx={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},yr=class yr extends qt{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 Gi.publicKeyToMultibaseId({publicKey:o}),c=`did:${yr.methodName}:${s}`,d=(await yr.resolve(c,t)).didDocument;return new gt({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=_e.parse(e.id);if(t&&t.method!==this.methodName)throw new $("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(o=>o.id===n);if(!(i&&i.publicKeyJwk))throw new $("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(_e.parse(e.uri)?.method!==yr.methodName)throw new $("methodNotSupported","Method not supported");let i=await gt.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new $("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){try{let n=await yr.createDocument({didUri:e,options:t});return{...Ke,didDocument:n}}catch(n){if(!(n instanceof $))throw new Error(n);return{...Ke,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=_e.parse(e);if(!c)throw new $("invalidDid",`Invalid DID URI: ${e}`);let u=c.id;if(c.method!==yr.methodName)throw new $("methodNotSupported",`Method not supported: ${c.method}`);if(!yr.validateIdentifier(c))throw new $("invalidDid",`Invalid DID URI: ${e}`);let d=await yr.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 td({didDocument:s}).forEach(y=>{let w=ey[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}=id({multibaseKeyId:t}),a=c.byteLength,l=Gi.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(a!==l)throw new $("invalidPublicKeyLength",`Expected ${a} bytes. Actual: ${l}`);let y=!1;switch(d){case"secp256k1-pub":y=await Ue.validatePublicKey({publicKeyBytes:c});break;case"ed25519-pub":y=await Oe.validatePublicKey({publicKeyBytes:c});break}if(!y)throw new $("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${t}`;try{new URL(s.id)}catch{throw new $("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in ey))throw new $("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(o))throw new $("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 Gi.multicodecToJwk({code:u});s.publicKeyJwk=await Gi.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&&li(n)==="String"&&n.startsWith("z")}};yr.methodName="key";var ty=yr,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:rt.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let n={"P-256":Re.compressPublicKey,secp256k1:Ue.compressPublicKey}[e];if(!n)throw new $("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:Oe,"P-256":Re,secp256k1:Ue}[e];if(!n)throw new $("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?rt.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 Vx))throw new $("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 nd({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 Gi=mr;var ra=class ra extends qt{static async resolve(e,t){let n=_e.parse(e);if(!n)return{...Ke,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==ra.methodName)return{...Ke,didResolutionMetadata:{error:"methodNotSupported"}};let i=`https://${n.id.replace(/:/g,"/")}`;i=decodeURIComponent(i);let o=n.id.includes(":")?`${i}/did.json`:`${i}/.well-known/did.json`;try{let s=await fetch(o);if(!s.ok)throw new Error("HTTP error status code returned");let c=await s.json();return{...Ke,didDocument:c}}catch{return{...Ke,didResolutionMetadata:{error:"notFound"}}}}};ra.methodName="web";var ry=ra;var oy=An(Du(),1),sy=An(Jd(),1),iy=class{constructor({db:e,location:t="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new oy.Level(t),this.ttl=(0,sy.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 ay=An(Jd(),1);var cy=class{constructor({ttl:e="15m"}={}){this.cache=new fa.default({ttl:(0,ay.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 uy={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||uy;for(let n of t)this.didResolvers.set(n.methodName,n)}async resolve(e,t){let n=_e.parse(e);if(!n)return{...Ke,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${e}`}};let i=this.didResolvers.get(n.method);if(!i)return{...Ke,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${n.method}`}};let o=await this.cache.get(n.uri);if(o)return o;{let s=await i.resolve(n.uri,t);return s.didResolutionMetadata.error||await this.cache.set(n.uri,s),s}}async dereference(e,t){let n=_e.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{gt as BearerDid,_e as Did,Vc as DidDht,Hc as DidDhtDocument,cp as DidDhtRegisteredDidType,xd as DidDhtRegisteredKeyType,Ge as DidDhtUtils,ap as DidDhtVerificationRelationship,$ as DidError,zr as DidErrorCode,Zp as DidIon,Lx as DidIonRegisteredKeyType,Zn as DidIonUtils,Qp as DidJwk,ty as DidKey,$x as DidKeyRegisteredKeyType,Gi as DidKeyUtils,ey as DidKeyVerificationMethodType,qt as DidMethod,iy as DidResolverCacheLevel,cy as DidResolverCacheMemory,uy as DidResolverCacheNoop,ui as DidVerificationRelationship,ry as DidWeb,Ke as EMPTY_DID_RESOLUTION_RESULT,dy as UniversalResolver,Kf as isPortableDid,_f as utils};
1
+ var tg=Object.create;var su=Object.defineProperty;var rg=Object.getOwnPropertyDescriptor;var ng=Object.getOwnPropertyNames;var ig=Object.getPrototypeOf,og=Object.prototype.hasOwnProperty;var ue=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),cu=(r,e)=>{for(var t in e)su(r,t,{get:e[t],enumerable:!0})},sg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ng(e))!og.call(r,i)&&i!==t&&su(r,i,{get:()=>e[i],enumerable:!(n=rg(e,i))||n.enumerable});return r};var zn=(r,e,t)=>(t=r!=null?tg(ig(r)):{},sg(e||!r||!r.__esModule?su(t,"default",{value:r,enumerable:!0}):t,r));var vf=ue((oE,bf)=>{var cg=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,tc=()=>cg.now(),ag=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),au=r=>r===1/0||ag(r),uu=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&&!au(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!au(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-tc());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(tc()+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(!au(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-tc())):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(tc());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()}};bf.exports=uu});var Nf=ue(Mf=>{"use strict";Mf.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 sr=ue((n2,Lf)=>{"use strict";Lf.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 Hf=ue(nc=>{"use strict";nc.byteLength=Fg;nc.toByteArray=Vg;nc.fromByteArray=zg;var br=[],Gt=[],$g=typeof Uint8Array<"u"?Uint8Array:Array,Su="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Yn=0,$f=Su.length;Yn<$f;++Yn)br[Yn]=Su[Yn],Gt[Su.charCodeAt(Yn)]=Yn;var Yn,$f;Gt[45]=62;Gt[95]=63;function Ff(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 Fg(r){var e=Ff(r),t=e[0],n=e[1];return(t+n)*3/4-n}function Hg(r,e,t){return(e+t)*3/4-t}function Vg(r){var e,t=Ff(r),n=t[0],i=t[1],o=new $g(Hg(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=Gt[r.charCodeAt(u)]<<18|Gt[r.charCodeAt(u+1)]<<12|Gt[r.charCodeAt(u+2)]<<6|Gt[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Gt[r.charCodeAt(u)]<<2|Gt[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=Gt[r.charCodeAt(u)]<<10|Gt[r.charCodeAt(u+1)]<<4|Gt[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function qg(r){return br[r>>18&63]+br[r>>12&63]+br[r>>6&63]+br[r&63]}function jg(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(qg(n));return i.join("")}function zg(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(jg(r,s,s+o>c?c:s+o));return n===1?(e=r[t-1],i.push(br[e>>2]+br[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(br[e>>10]+br[e>>4&63]+br[e<<2&63]+"=")),i.join("")}});var Vf=ue(Tu=>{Tu.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)};Tu.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 sc=ue(Hi=>{"use strict";var Bu=Hf(),$i=Vf(),qf=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Hi.Buffer=S;Hi.SlowBuffer=Zg;Hi.INSPECT_MAX_BYTES=50;var ic=2147483647;Hi.kMaxLength=ic;S.TYPED_ARRAY_SUPPORT=Jg();!S.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 Jg(){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(S.prototype,"parent",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.buffer}});Object.defineProperty(S.prototype,"offset",{enumerable:!0,get:function(){if(S.isBuffer(this))return this.byteOffset}});function Fr(r){if(r>ic)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,S.prototype),e}function S(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 _u(r)}return Gf(r,e,t)}S.poolSize=8192;function Gf(r,e,t){if(typeof r=="string")return Wg(r,e);if(ArrayBuffer.isView(r))return Yg(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(vr(r,ArrayBuffer)||r&&vr(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(vr(r,SharedArrayBuffer)||r&&vr(r.buffer,SharedArrayBuffer)))return Du(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 S.from(n,e,t);let i=Xg(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return S.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)}S.from=function(r,e,t){return Gf(r,e,t)};Object.setPrototypeOf(S.prototype,Uint8Array.prototype);Object.setPrototypeOf(S,Uint8Array);function Wf(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 Gg(r,e,t){return Wf(r),r<=0?Fr(r):e!==void 0?typeof t=="string"?Fr(r).fill(e,t):Fr(r).fill(e):Fr(r)}S.alloc=function(r,e,t){return Gg(r,e,t)};function _u(r){return Wf(r),Fr(r<0?0:ku(r)|0)}S.allocUnsafe=function(r){return _u(r)};S.allocUnsafeSlow=function(r){return _u(r)};function Wg(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!S.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=Yf(r,e)|0,n=Fr(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Iu(r){let e=r.length<0?0:ku(r.length)|0,t=Fr(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Yg(r){if(vr(r,Uint8Array)){let e=new Uint8Array(r);return Du(e.buffer,e.byteOffset,e.byteLength)}return Iu(r)}function Du(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,S.prototype),n}function Xg(r){if(S.isBuffer(r)){let e=ku(r.length)|0,t=Fr(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ku(r.length)?Fr(0):Iu(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Iu(r.data)}function ku(r){if(r>=ic)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ic.toString(16)+" bytes");return r|0}function Zg(r){return+r!=r&&(r=0),S.alloc(+r)}S.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==S.prototype};S.compare=function(e,t){if(vr(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),vr(t,Uint8Array)&&(t=S.from(t,t.offset,t.byteLength)),!S.isBuffer(e)||!S.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};S.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}};S.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return S.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=S.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(vr(s,Uint8Array))o+s.length>i.length?(S.isBuffer(s)||(s=S.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(S.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Yf(r,e){if(S.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||vr(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 Uu(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:Uu(r).length;e=(""+e).toLowerCase(),i=!0}}S.byteLength=Yf;function Qg(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 uw(this,e,t);case"utf8":case"utf-8":return Zf(this,e,t);case"ascii":return cw(this,e,t);case"latin1":case"binary":return aw(this,e,t);case"base64":return ow(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return dw(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}S.prototype._isBuffer=!0;function Xn(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}S.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)Xn(this,t,t+1);return this};S.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)Xn(this,t,t+3),Xn(this,t+1,t+2);return this};S.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)Xn(this,t,t+7),Xn(this,t+1,t+6),Xn(this,t+2,t+5),Xn(this,t+3,t+4);return this};S.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Zf(this,0,e):Qg.apply(this,arguments)};S.prototype.toLocaleString=S.prototype.toString;S.prototype.equals=function(e){if(!S.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:S.compare(this,e)===0};S.prototype.inspect=function(){let e="",t=Hi.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};qf&&(S.prototype[qf]=S.prototype.inspect);S.prototype.compare=function(e,t,n,i,o){if(vr(e,Uint8Array)&&(e=S.from(e,e.offset,e.byteLength)),!S.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 Xf(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,Ku(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=S.from(e,n)),S.isBuffer(e))return e.length===0?-1:jf(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):jf(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function jf(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}S.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};S.prototype.indexOf=function(e,t,n){return Xf(this,e,t,n,!0)};S.prototype.lastIndexOf=function(e,t,n){return Xf(this,e,t,n,!1)};function ew(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(Ku(c))return s;r[t+s]=c}return s}function tw(r,e,t,n){return oc(Uu(e,r.length-t),r,t,n)}function rw(r,e,t,n){return oc(pw(e),r,t,n)}function nw(r,e,t,n){return oc(oh(e),r,t,n)}function iw(r,e,t,n){return oc(yw(e,r.length-t),r,t,n)}S.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 ew(this,e,t,n);case"utf8":case"utf-8":return tw(this,e,t,n);case"ascii":case"latin1":case"binary":return rw(this,e,t,n);case"base64":return nw(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return iw(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};S.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ow(r,e,t){return e===0&&t===r.length?Bu.fromByteArray(r):Bu.fromByteArray(r.slice(e,t))}function Zf(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 sw(n)}var zf=4096;function sw(r){let e=r.length;if(e<=zf)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=zf));return t}function cw(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 aw(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 uw(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+=mw[r[o]];return i}function dw(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}S.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,S.prototype),i};function Ze(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}S.prototype.readUintLE=S.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||Ze(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};S.prototype.readUintBE=S.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||Ze(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};S.prototype.readUint8=S.prototype.readUInt8=function(e,t){return e=e>>>0,t||Ze(e,1,this.length),this[e]};S.prototype.readUint16LE=S.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||Ze(e,2,this.length),this[e]|this[e+1]<<8};S.prototype.readUint16BE=S.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||Ze(e,2,this.length),this[e]<<8|this[e+1]};S.prototype.readUint32LE=S.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};S.prototype.readUint32BE=S.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};S.prototype.readBigUInt64LE=pn(function(e){e=e>>>0,Fi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Fo(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))});S.prototype.readBigUInt64BE=pn(function(e){e=e>>>0,Fi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Fo(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)});S.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||Ze(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};S.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||Ze(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};S.prototype.readInt8=function(e,t){return e=e>>>0,t||Ze(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};S.prototype.readInt16LE=function(e,t){e=e>>>0,t||Ze(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};S.prototype.readInt16BE=function(e,t){e=e>>>0,t||Ze(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};S.prototype.readInt32LE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};S.prototype.readInt32BE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};S.prototype.readBigInt64LE=pn(function(e){e=e>>>0,Fi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Fo(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)});S.prototype.readBigInt64BE=pn(function(e){e=e>>>0,Fi(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Fo(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)});S.prototype.readFloatLE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),$i.read(this,e,!0,23,4)};S.prototype.readFloatBE=function(e,t){return e=e>>>0,t||Ze(e,4,this.length),$i.read(this,e,!1,23,4)};S.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||Ze(e,8,this.length),$i.read(this,e,!0,52,8)};S.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||Ze(e,8,this.length),$i.read(this,e,!1,52,8)};function bt(r,e,t,n,i,o){if(!S.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")}S.prototype.writeUintLE=S.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;bt(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};S.prototype.writeUintBE=S.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;bt(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};S.prototype.writeUint8=S.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,1,255,0),this[t]=e&255,t+1};S.prototype.writeUint16LE=S.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeUint16BE=S.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeUint32LE=S.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||bt(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};S.prototype.writeUint32BE=S.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||bt(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 Qf(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}S.prototype.writeBigUInt64LE=pn(function(e,t=0){return Qf(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeBigUInt64BE=pn(function(e,t=0){return eh(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});S.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);bt(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};S.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);bt(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};S.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};S.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};S.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||bt(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};S.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||bt(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};S.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||bt(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};S.prototype.writeBigInt64LE=pn(function(e,t=0){return Qf(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});S.prototype.writeBigInt64BE=pn(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),$i.write(r,e,t,n,23,4),t+4}S.prototype.writeFloatLE=function(e,t,n){return rh(this,e,t,!0,n)};S.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),$i.write(r,e,t,n,52,8),t+8}S.prototype.writeDoubleLE=function(e,t,n){return nh(this,e,t,!0,n)};S.prototype.writeDoubleBE=function(e,t,n){return nh(this,e,t,!1,n)};S.prototype.copy=function(e,t,n,i){if(!S.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};S.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"&&!S.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=S.isBuffer(e)?e:S.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 Li={};function Ou(r,e,t){Li[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}`}}}Ou("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Ou("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Ou("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=Jf(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=Jf(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Jf(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 lw(r,e,t){Fi(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&Fo(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 Li.ERR_OUT_OF_RANGE("value",c,r)}lw(n,i,o)}function Fi(r,e){if(typeof r!="number")throw new Li.ERR_INVALID_ARG_TYPE(e,"number",r)}function Fo(r,e,t){throw Math.floor(r)!==r?(Fi(r,t),new Li.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new Li.ERR_BUFFER_OUT_OF_BOUNDS:new Li.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var fw=/[^+/0-9A-Za-z-_]/g;function hw(r){if(r=r.split("=")[0],r=r.trim().replace(fw,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Uu(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 pw(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function yw(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 Bu.toByteArray(hw(r))}function oc(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 vr(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ku(r){return r!==r}var mw=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 pn(r){return typeof BigInt>"u"?gw:r}function gw(){throw new Error("BigInt not supported")}});var Ru=ue((a2,sh)=>{"use strict";var Pu=null;sh.exports=function(){return Pu===null&&(Pu={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Pu}});var Nu=ue(ch=>{"use strict";var Cu=sr(),ww=new Set(["buffer","view","utf8"]),Mu=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"||!ww.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 Cu(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Cu(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Cu(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ch.Encoding=Mu});var Hu=ue(cc=>{"use strict";var{Buffer:$u}=sc()||{},{Encoding:Fu}=Nu(),xw=Ru(),Ho=class extends Fu{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new Vo({encode:this.encode,decode:e=>this.decode($u.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},Vo=class extends Fu{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new Ho({encode:e=>{let t=this.encode(e);return $u.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Lu=class extends Fu{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new Ho({encode:e=>$u.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=xw();return new Vo({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};cc.BufferFormat=Ho;cc.ViewFormat=Vo;cc.UTF8Format=Lu});var lh=ue(Zn=>{"use strict";var{Buffer:ut}=sc()||{Buffer:{isBuffer:()=>!1}},{textEncoder:uh,textDecoder:ah}=Ru()(),{BufferFormat:qo,ViewFormat:Vu,UTF8Format:dh}=Hu(),ac=r=>r;Zn.utf8=new dh({encode:function(r){return ut.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?ah.decode(r):String(r)},decode:ac,name:"utf8",createViewTranscoder(){return new Vu({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 qo({encode:function(r){return ut.isBuffer(r)?r:ArrayBuffer.isView(r)?ut.from(r.buffer,r.byteOffset,r.byteLength):ut.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Zn.json=new dh({encode:JSON.stringify,decode:JSON.parse,name:"json"});Zn.buffer=new qo({encode:function(r){return ut.isBuffer(r)?r:ArrayBuffer.isView(r)?ut.from(r.buffer,r.byteOffset,r.byteLength):ut.from(String(r),"utf8")},decode:ac,name:"buffer",createViewTranscoder(){return new Vu({encode:function(r){return ArrayBuffer.isView(r)?r:ut.from(String(r),"utf8")},decode:function(r){return ut.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Zn.view=new Vu({encode:function(r){return ArrayBuffer.isView(r)?r:uh.encode(r)},decode:ac,name:"view",createBufferTranscoder(){return new qo({encode:function(r){return ut.isBuffer(r)?r:ArrayBuffer.isView(r)?ut.from(r.buffer,r.byteOffset,r.byteLength):ut.from(String(r),"utf8")},decode:ac,name:`${this.name}+buffer`})}});Zn.hex=new qo({encode:function(r){return ut.isBuffer(r)?r:ut.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Zn.base64=new qo({encode:function(r){return ut.isBuffer(r)?r:ut.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var ph=ue(hh=>{"use strict";var fh=sr(),dc=lh(),{Encoding:bw}=Nu(),{BufferFormat:vw,ViewFormat:Ew,UTF8Format:Aw}=Hu(),jo=Symbol("formats"),uc=Symbol("encodings"),Sw=new Set(["buffer","view","utf8"]),qu=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>Sw.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[uc]=new Map,this[jo]=new Set(e);for(let t in dc)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[uc].values()))}encoding(e){let t=this[uc].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=Dw[e],!t)throw new fh(`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=Tw(e)}let{name:n,format:i}=t;if(!this[jo].has(i))if(this[jo].has("view"))t=t.createViewTranscoder();else if(this[jo].has("buffer"))t=t.createBufferTranscoder();else if(this[jo].has("utf8"))t=t.createUTF8Transcoder();else throw new fh(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[uc].set(o,t)}return t}};hh.Transcoder=qu;function Tw(r){if(r instanceof bw)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${Uw++}`;switch(Bw(r)){case"view":return new Ew({...r,name:t});case"utf8":return new Aw({...r,name:t});case"buffer":return new vw({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function Bw(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 Iw={binary:dc.buffer,"utf-8":dc.utf8},Dw={...dc,...Iw},Uw=0});var mh=ue((h2,ju)=>{"use strict";var _w=Object.prototype.hasOwnProperty,yt="~";function zo(){}Object.create&&(zo.prototype=Object.create(null),new zo().__proto__||(yt=!1));function kw(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 kw(t,n||r,i),s=yt?yt+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 lc(r,e){--r._eventsCount===0?r._events=new zo:delete r._events[e]}function dt(){this._events=new zo,this._eventsCount=0}dt.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)_w.call(t,n)&&e.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};dt.prototype.listeners=function(e){var t=yt?yt+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};dt.prototype.listenerCount=function(e){var t=yt?yt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};dt.prototype.emit=function(e,t,n,i,o,s){var c=yt?yt+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};dt.prototype.on=function(e,t,n){return yh(this,e,t,n,!1)};dt.prototype.once=function(e,t,n){return yh(this,e,t,n,!0)};dt.prototype.removeListener=function(e,t,n,i){var o=yt?yt+e:e;if(!this._events[o])return this;if(!t)return lc(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&lc(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:lc(this,o)}return this};dt.prototype.removeAllListeners=function(e){var t;return e?(t=yt?yt+e:e,this._events[t]&&lc(this,t)):(this._events=new zo,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=yt;dt.EventEmitter=dt;typeof ju<"u"&&(ju.exports=dt)});var wh=ue((p2,gh)=>{gh.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var Jo=ue(zu=>{"use strict";var xh=wh();zu.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};zu.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 fc=ue(Ju=>{"use strict";Ju.getCallback=function(r,e){return typeof r=="function"?r:e};Ju.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var bn=ue(mc=>{"use strict";var{fromCallback:Gu}=Jo(),_t=sr(),{getOptions:Wu,getCallback:bh}=fc(),Qn=Symbol("promise"),Vi=Symbol("callback"),Er=Symbol("working"),ei=Symbol("handleOne"),Hr=Symbol("handleMany"),Yu=Symbol("autoClose"),wn=Symbol("finishWork"),Ar=Symbol("returnMany"),yn=Symbol("closing"),Go=Symbol("handleClose"),hc=Symbol("closed"),Wo=Symbol("closeCallbacks"),gn=Symbol("keyEncoding"),ti=Symbol("valueEncoding"),Xu=Symbol("abortOnClose"),pc=Symbol("legacy"),Zu=Symbol("keys"),Qu=Symbol("values"),mn=Symbol("limit"),Wt=Symbol("count"),yc=Object.freeze({}),Ow=()=>{},vh=!1,Yo=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[hc]=!1,this[Wo]=[],this[Er]=!1,this[yn]=!1,this[Yu]=!1,this[Vi]=null,this[ei]=this[ei].bind(this),this[Hr]=this[Hr].bind(this),this[Go]=this[Go].bind(this),this[gn]=t[gn],this[ti]=t[ti],this[pc]=n,this[mn]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[Wt]=0,this[Xu]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[Wt]}get limit(){return this[mn]}next(e){let t;if(e===void 0)t=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[pc]?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[yn]?this.nextTick(e,new _t("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Er]?this.nextTick(e,new _t("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Er]=!0,this[Vi]=e,this[Wt]>=this[mn]?this.nextTick(this[ei],null):this._next(this[ei])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=bh(t,n),n=Gu(n,Qn),t=Wu(t,yc),Number.isInteger(e)?(this[yn]?this.nextTick(n,new _t("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Er]?this.nextTick(n,new _t("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[mn]<1/0&&(e=Math.min(e,this[mn]-this[Wt])),this[Er]=!0,this[Vi]=n,e<=0?this.nextTick(this[Hr],null,[]):this._nextv(e,t,this[Hr])),n[Qn]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[Qn])}_nextv(e,t,n){let i=[],o=(s,c,u)=>{if(s)return n(s);if(this[pc]?c===void 0&&u===void 0:c===void 0)return n(null,i);i.push(this[pc]?[c,u]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=bh(e,t),t=Gu(t,Qn),e=Wu(e,yc),this[yn]?this.nextTick(t,new _t("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Er]?this.nextTick(t,new _t("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Er]=!0,this[Vi]=t,this[Yu]=!0,this[Wt]>=this[mn]?this.nextTick(this[Hr],null,[]):this._all(e,this[Hr])),t[Qn]}_all(e,t){let n=this[Wt],i=[],o=()=>{let c=this[mn]<1/0?Math.min(1e3,this[mn]-n):1e3;c<=0?this.nextTick(t,null,i):this._nextv(c,yc,s)},s=(c,u)=>{c?t(c):u.length===0?t(null,i):(i.push.apply(i,u),n+=u.length,o())};o()}[wn](){let e=this[Vi];return this[Xu]&&e===null?Ow:(this[Er]=!1,this[Vi]=null,this[yn]&&this._close(this[Go]),e)}[Ar](e,t,n){this[Yu]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=Wu(t,yc),!this[yn]){if(this[Er])throw new _t("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[gn]),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 _t("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=Gu(e,Qn),this[hc]?this.nextTick(e):this[yn]?this[Wo].push(e):(this[yn]=!0,this[Wo].push(e),this[Er]?this[Xu]&&this[wn]()(new _t("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[Go])),e[Qn]}_close(e){this.nextTick(e)}[Go](){this[hc]=!0,this.db.detachResource(this);let e=this[Wo];this[Wo]=[];for(let t of e)t()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[hc]||await this.close()}}},qi=class extends Yo{constructor(e,t){super(e,t,!0),this[Zu]=t.keys!==!1,this[Qu]=t.values!==!1}[ei](e,t,n){let i=this[wn]();if(e)return i(e);try{t=this[Zu]&&t!==void 0?this[gn].decode(t):void 0,n=this[Qu]&&n!==void 0?this[ti].decode(n):void 0}catch(o){return i(new xn("entry",o))}t===void 0&&n===void 0||this[Wt]++,i(null,t,n)}[Hr](e,t){let n=this[wn]();if(e)return this[Ar](n,e);try{for(let i of t){let o=i[0],s=i[1];i[0]=this[Zu]&&o!==void 0?this[gn].decode(o):void 0,i[1]=this[Qu]&&s!==void 0?this[ti].decode(s):void 0}}catch(i){return this[Ar](n,new xn("entries",i))}this[Wt]+=t.length,this[Ar](n,null,t)}end(e){return!vh&&typeof console<"u"&&(vh=!0,console.warn(new _t("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)}},ed=class extends Yo{constructor(e,t){super(e,t,!1)}[ei](e,t){let n=this[wn]();if(e)return n(e);try{t=t!==void 0?this[gn].decode(t):void 0}catch(i){return n(new xn("key",i))}t!==void 0&&this[Wt]++,n(null,t)}[Hr](e,t){let n=this[wn]();if(e)return this[Ar](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[gn].decode(o):void 0}}catch(i){return this[Ar](n,new xn("keys",i))}this[Wt]+=t.length,this[Ar](n,null,t)}},td=class extends Yo{constructor(e,t){super(e,t,!1)}[ei](e,t){let n=this[wn]();if(e)return n(e);try{t=t!==void 0?this[ti].decode(t):void 0}catch(i){return n(new xn("value",i))}t!==void 0&&this[Wt]++,n(null,t)}[Hr](e,t){let n=this[wn]();if(e)return this[Ar](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[ti].decode(o):void 0}}catch(i){return this[Ar](n,new xn("values",i))}this[Wt]+=t.length,this[Ar](n,null,t)}},xn=class extends _t{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(qi.prototype,r.split(" ")[0],{get(){throw new _t(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new _t(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});qi.keyEncoding=gn;qi.valueEncoding=ti;mc.AbstractIterator=qi;mc.AbstractKeyIterator=ed;mc.AbstractValueIterator=td});var Eh=ue(rd=>{"use strict";var{AbstractKeyIterator:Kw,AbstractValueIterator:Pw}=bn(),ri=Symbol("iterator"),Xo=Symbol("callback"),ji=Symbol("handleOne"),ni=Symbol("handleMany"),Zo=class extends Kw{constructor(e,t){super(e,t),this[ri]=e.iterator({...t,keys:!0,values:!1}),this[ji]=this[ji].bind(this),this[ni]=this[ni].bind(this)}},gc=class extends Pw{constructor(e,t){super(e,t),this[ri]=e.iterator({...t,keys:!1,values:!0}),this[ji]=this[ji].bind(this),this[ni]=this[ni].bind(this)}};for(let r of[Zo,gc]){let e=r===Zo,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[Xo]=n,this[ri].next(this[ji])},r.prototype[ji]=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[ri].nextv(n,i,this[ni])},r.prototype._all=function(n,i){this[Xo]=i,this[ri].all(n,this[ni])},r.prototype[ni]=function(n,i){let o=this[Xo];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[ri].seek(n,i)},r.prototype._close=function(n){this[ri].close(n)}}rd.DefaultKeyIterator=Zo;rd.DefaultValueIterator=gc});var Ah=ue(Ac=>{"use strict";var{AbstractIterator:Rw,AbstractKeyIterator:Cw,AbstractValueIterator:Mw}=bn(),nd=sr(),vt=Symbol("nut"),vc=Symbol("undefer"),Ec=Symbol("factory"),wc=class extends Rw{constructor(e,t){super(e,t),this[vt]=null,this[Ec]=()=>e.iterator(t),this.db.defer(()=>this[vc]())}},xc=class extends Cw{constructor(e,t){super(e,t),this[vt]=null,this[Ec]=()=>e.keys(t),this.db.defer(()=>this[vc]())}},bc=class extends Mw{constructor(e,t){super(e,t),this[vt]=null,this[Ec]=()=>e.values(t),this.db.defer(()=>this[vc]())}};for(let r of[wc,xc,bc])r.prototype[vc]=function(){this.db.status==="open"&&(this[vt]=this[Ec]())},r.prototype._next=function(e){this[vt]!==null?this[vt].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new nd("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(e,t,n){this[vt]!==null?this[vt].nextv(e,t,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,t,n)):this.nextTick(n,new nd("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(e,t){this[vt]!==null?this[vt].all(t):this.db.status==="opening"?this.db.defer(()=>this._all(e,t)):this.nextTick(t,new nd("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(e,t){this[vt]!==null?this[vt]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t))},r.prototype._close=function(e){this[vt]!==null?this[vt].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};Ac.DeferredIterator=wc;Ac.DeferredKeyIterator=xc;Ac.DeferredValueIterator=bc});var od=ue(Th=>{"use strict";var{fromCallback:Sh}=Jo(),Sc=sr(),{getCallback:Nw,getOptions:Lw}=fc(),Tc=Symbol("promise"),Yt=Symbol("status"),zi=Symbol("operations"),Qo=Symbol("finishClose"),Ji=Symbol("closeCallbacks"),id=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[zi]=[],this[Ji]=[],this[Yt]="open",this[Qo]=this[Qo].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[zi].length}put(e,t,n){if(this[Yt]!=="open")throw new Sc("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[zi].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[Yt]!=="open")throw new Sc("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[zi].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[Yt]!=="open")throw new Sc("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[zi]=[],this}_clear(){}write(e,t){return t=Nw(e,t),t=Sh(t,Tc),e=Lw(e),this[Yt]!=="open"?this.nextTick(t,new Sc("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[Yt]="writing",this._write(e,n=>{this[Yt]="closing",this[Ji].push(()=>t(n)),n||this.db.emit("batch",this[zi]),this._close(this[Qo])})),t[Tc]}_write(e,t){}close(e){return e=Sh(e,Tc),this[Yt]==="closing"?this[Ji].push(e):this[Yt]==="closed"?this.nextTick(e):(this[Ji].push(e),this[Yt]!=="writing"&&(this[Yt]="closing",this._close(this[Qo]))),e[Tc]}_close(e){this.nextTick(e)}[Qo](){this[Yt]="closed",this.db.detachResource(this);let e=this[Ji];this[Ji]=[];for(let t of e)t()}};Th.AbstractChainedBatch=id});var Ih=ue(Bh=>{"use strict";var{AbstractChainedBatch:$w}=od(),Fw=sr(),Gi=Symbol("encoded"),sd=class extends $w{constructor(e){super(e),this[Gi]=[]}_put(e,t,n){this[Gi].push({...n,type:"put",key:e,value:t})}_del(e,t){this[Gi].push({...t,type:"del",key:e})}_clear(){this[Gi]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[Gi].length===0?this.nextTick(t):this.db._batch(this[Gi],e,t):this.nextTick(t,new Fw("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};Bh.DefaultChainedBatch=sd});var _h=ue((E2,Uh)=>{"use strict";var Dh=sr(),Hw=Object.prototype.hasOwnProperty,Vw=new Set(["lt","lte","gt","gte"]);Uh.exports=function(r,e){let t={};for(let n in r)if(Hw.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"});Vw.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 cd=ue((A2,Oh)=>{var kh;Oh.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(kh||(kh=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var Rh=ue((S2,Ph)=>{"use strict";var Kh=cd();Ph.exports=function(r,...e){e.length===0?Kh(r):Kh(()=>r(...e))}});var Ch=ue(Bc=>{"use strict";var{AbstractIterator:qw,AbstractKeyIterator:jw,AbstractValueIterator:zw}=bn(),Wi=Symbol("unfix"),cr=Symbol("iterator"),ii=Symbol("handleOne"),vn=Symbol("handleMany"),Vr=Symbol("callback"),es=class extends qw{constructor(e,t,n,i){super(e,t),this[cr]=n,this[Wi]=i,this[ii]=this[ii].bind(this),this[vn]=this[vn].bind(this),this[Vr]=null}[ii](e,t,n){let i=this[Vr];if(e)return i(e);t!==void 0&&(t=this[Wi](t)),i(e,t,n)}[vn](e,t){let n=this[Vr];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[Wi](o))}n(e,t)}},ts=class extends jw{constructor(e,t,n,i){super(e,t),this[cr]=n,this[Wi]=i,this[ii]=this[ii].bind(this),this[vn]=this[vn].bind(this),this[Vr]=null}[ii](e,t){let n=this[Vr];if(e)return n(e);t!==void 0&&(t=this[Wi](t)),n(e,t)}[vn](e,t){let n=this[Vr];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[Wi](o))}n(e,t)}},rs=class extends zw{constructor(e,t,n){super(e,t),this[cr]=n}};for(let r of[es,ts])r.prototype._next=function(e){this[Vr]=e,this[cr].next(this[ii])},r.prototype._nextv=function(e,t,n){this[Vr]=n,this[cr].nextv(e,t,this[vn])},r.prototype._all=function(e,t){this[Vr]=t,this[cr].all(e,this[vn])};for(let r of[rs])r.prototype._next=function(e){this[cr].next(e)},r.prototype._nextv=function(e,t,n){this[cr].nextv(e,t,n)},r.prototype._all=function(e,t){this[cr].all(e,t)};for(let r of[es,ts,rs])r.prototype._seek=function(e,t){this[cr].seek(e,t)},r.prototype._close=function(e){this[cr].close(e)};Bc.AbstractSublevelIterator=es;Bc.AbstractSublevelKeyIterator=ts;Bc.AbstractSublevelValueIterator=rs});var $h=ue((B2,Lh)=>{"use strict";var ad=sr(),{Buffer:ld}=sc()||{},{AbstractSublevelIterator:Jw,AbstractSublevelKeyIterator:Gw,AbstractSublevelValueIterator:Ww}=Ch(),qr=Symbol("prefix"),Mh=Symbol("upperBound"),ns=Symbol("prefixRange"),kt=Symbol("parent"),ud=Symbol("unfix"),Nh=new TextEncoder,Yw={separator:"!"};Lh.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new ad("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new ad("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?Yw:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...u}=e.defaults(o);i=Zw(i,s);let d=s.charCodeAt(0)+1,a=n[kt]||n;if(!Nh.encode(i).every(w=>w>d&&w<127))throw new ad(`Prefix must use bytes > ${d} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Xw(a,c),u);let l=(n.prefix||"")+s+i+s,y=l.slice(0,-1)+String.fromCharCode(d);this[kt]=a,this[qr]=new Ic(l),this[Mh]=new Ic(y),this[ud]=new fd,this.nextTick=a.nextTick}prefixKey(n,i){if(i==="utf8")return this[qr].utf8+n;if(n.byteLength===0)return this[qr][i];if(i==="view"){let o=this[qr].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[qr].buffer;return ld.concat([o,n],o.byteLength+n.byteLength)}}[ns](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[qr][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[qr].utf8}get db(){return this[kt]}_open(n,i){this[kt].open({passive:!0},i)}_put(n,i,o,s){this[kt].put(n,i,o,s)}_get(n,i,o){this[kt].get(n,i,o)}_getMany(n,i,o){this[kt].getMany(n,i,o)}_del(n,i,o){this[kt].del(n,i,o)}_batch(n,i,o){this[kt].batch(n,i,o)}_clear(n,i){this[ns](n,n.keyEncoding),this[kt].clear(n,i)}_iterator(n){this[ns](n,n.keyEncoding);let i=this[kt].iterator(n),o=this[ud].get(this[qr].utf8.length,n.keyEncoding);return new Jw(this,n,i,o)}_keys(n){this[ns](n,n.keyEncoding);let i=this[kt].keys(n),o=this[ud].get(this[qr].utf8.length,n.keyEncoding);return new Gw(this,n,i,o)}_values(n){this[ns](n,n.keyEncoding);let i=this[kt].values(n);return new Ww(this,n,i)}}return{AbstractSublevel:e}};var Xw=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:dd(r,"utf8"),buffer:dd(r,"buffer"),view:dd(r,"view")}}},dd=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},Ic=class{constructor(e){this.utf8=e,this.view=Nh.encode(e),this.buffer=ld?ld.from(this.view.buffer,0,this.view.byteLength):{}}},fd=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}},Zw=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 gd=ue(md=>{"use strict";var{supports:Qw}=Nf(),{Transcoder:ex}=ph(),{EventEmitter:tx}=mh(),{fromCallback:En}=Jo(),ar=sr(),{AbstractIterator:oi}=bn(),{DefaultKeyIterator:rx,DefaultValueIterator:nx}=Eh(),{DeferredIterator:ix,DeferredKeyIterator:ox,DeferredValueIterator:sx}=Ah(),{DefaultChainedBatch:Fh}=Ih(),{getCallback:si,getOptions:An}=fc(),Dc=_h(),ae=Symbol("promise"),jr=Symbol("landed"),ci=Symbol("resources"),hd=Symbol("closeResources"),is=Symbol("operations"),os=Symbol("undefer"),Uc=Symbol("deferOpen"),Hh=Symbol("options"),de=Symbol("status"),ai=Symbol("defaultOptions"),Yi=Symbol("transcoder"),_c=Symbol("keyEncoding"),pd=Symbol("valueEncoding"),cx=()=>{},ss=class extends tx{constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=An(t);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=t;this[ci]=new Set,this[is]=[],this[Uc]=!0,this[Hh]=s,this[de]="opening",this.supports=Qw(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[Yi]=new ex(ax(this)),this[_c]=this[Yi].encoding(n||"utf8"),this[pd]=this[Yi].encoding(i||"utf8");for(let c of this[Yi].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[ai]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[_c].commonName,valueEncoding:this[pd].commonName}),key:Object.freeze({keyEncoding:this[_c].commonName})},this.nextTick(()=>{this[Uc]&&this.open({passive:!1},cx)})}get status(){return this[de]}keyEncoding(e){return this[Yi].encoding(e??this[_c])}valueEncoding(e){return this[Yi].encoding(e??this[pd])}open(e,t){t=si(e,t),t=En(t,ae),e={...this[Hh],...An(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[de]==="closing"||this[de]==="opening"?this.once(jr,i?()=>n(i):n):this[de]!=="open"?t(new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):t()};return e.passive?this[de]==="opening"?this.once(jr,n):this.nextTick(n):this[de]==="closed"||this[Uc]?(this[Uc]=!1,this[de]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[de]="closed",this[hd](()=>{this.emit(jr),n(i)}),this[os]();return}this[de]="open",this[os](),this.emit(jr),this[de]==="open"&&this.emit("open"),this[de]==="open"&&this.emit("ready"),n()})):this[de]==="open"?this.nextTick(n):this.once(jr,()=>this.open(e,t)),t[ae]}_open(e,t){this.nextTick(t)}close(e){e=En(e,ae);let t=n=>{this[de]==="opening"||this[de]==="closing"?this.once(jr,n?t(n):t):this[de]!=="closed"?e(new ar("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[de]==="open"){this[de]="closing",this.emit("closing");let n=i=>{this[de]="open",this[os](),this.emit(jr),t(i)};this[hd](()=>{this._close(i=>{if(i)return n(i);this[de]="closed",this[os](),this.emit(jr),this[de]==="closed"&&this.emit("closed"),t()})})}else this[de]==="closed"?this.nextTick(t):this.once(jr,()=>this.close(e));return e[ae]}[hd](e){if(this[ci].size===0)return this.nextTick(e);let t=this[ci].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[ci])o.close(i);n=!1,this[ci].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=si(t,n),n=En(n,ae),t=An(t,this[ai].entry),this[de]==="opening")return this.defer(()=>this.get(e,t,n)),n[ae];if(Xi(this,n))return n[ae];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ae];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 ar("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[ae]}_get(e,t,n){this.nextTick(n,new Error("NotFound"))}getMany(e,t,n){if(n=si(t,n),n=En(n,ae),t=An(t,this[ai].entry),this[de]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[ae];if(Xi(this,n))return n[ae];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[ae];if(e.length===0)return this.nextTick(n,null,[]),n[ae];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[ae];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 ar(`Could not decode one or more of ${a.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,a)}),n[ae]}_getMany(e,t,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,t,n,i){if(i=si(n,i),i=En(i,ae),n=An(n,this[ai].entry),this[de]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[ae];if(Xi(this,i))return i[ae];let o=this._checkKey(e)||this._checkValue(t);if(o)return this.nextTick(i,o),i[ae];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[ae]}_put(e,t,n,i){this.nextTick(i)}del(e,t,n){if(n=si(t,n),n=En(n,ae),t=An(t,this[ai].key),this[de]==="opening")return this.defer(()=>this.del(e,t,n)),n[ae];if(Xi(this,n))return n[ae];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[ae];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[ae]}_del(e,t,n){this.nextTick(n)}batch(e,t,n){if(!arguments.length){if(this[de]==="opening")return new Fh(this);if(this[de]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=si(t,n),n=En(n,ae),t=An(t,this[ai].empty),this[de]==="opening")return this.defer(()=>this.batch(e,t,n)),n[ae];if(Xi(this,n))return n[ae];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[ae];if(e.length===0)return this.nextTick(n),n[ae];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[ae];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[ae];let a=this._checkKey(d.key);if(a)return this.nextTick(n,a),n[ae];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[ae];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[ae]}_batch(e,t,n){this.nextTick(n)}sublevel(e,t){return this._sublevel(e,yd.defaults(t))}_sublevel(e,t){return new yd(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=si(e,t),t=En(t,ae),e=An(e,this[ai].empty),this[de]==="opening")return this.defer(()=>this.clear(e,t)),t[ae];if(Xi(this,t))return t[ae];let n=e,i=this.keyEncoding(e.keyEncoding);return e=Dc(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[ae]}_clear(e,t){this.nextTick(t)}iterator(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Dc(e,t),e.keys=e.keys!==!1,e.values=e.values!==!1,e[oi.keyEncoding]=t,e[oi.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[de]==="opening")return new ix(this,e);if(this[de]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new oi(this,e)}keys(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Dc(e,t),e[oi.keyEncoding]=t,e[oi.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[de]==="opening")return new ox(this,e);if(this[de]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new rx(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=Dc(e,t),e[oi.keyEncoding]=t,e[oi.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[de]==="opening")return new sx(this,e);if(this[de]!=="open")throw new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new nx(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[is].push(e)}[os](){if(this[is].length===0)return;let e=this[is];this[is]=[];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[ci].add(e)}detachResource(e){this[ci].delete(e)}_chainedBatch(){return new Fh(this)}_checkKey(e){if(e==null)return new ar("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new ar("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};ss.prototype.nextTick=Rh();var{AbstractSublevel:yd}=$h()({AbstractLevel:ss});md.AbstractLevel=ss;md.AbstractSublevel=yd;var Xi=function(r,e){return r[de]!=="open"?(r.nextTick(e,new ar("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},ax=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var wd=ue(ui=>{"use strict";ui.AbstractLevel=gd().AbstractLevel;ui.AbstractSublevel=gd().AbstractSublevel;ui.AbstractIterator=bn().AbstractIterator;ui.AbstractKeyIterator=bn().AbstractKeyIterator;ui.AbstractValueIterator=bn().AbstractValueIterator;ui.AbstractChainedBatch=od().AbstractChainedBatch});var qh=ue((U2,Vh)=>{Vh.exports=dx;var ux=cd();function dx(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?ux(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,B){l(g,v,B)})):(g=d,d+=1,r[g](function(v,B){l(g,v,B)}))}}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 xd=ue((_2,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 bd=ue((k2,zh)=>{"use strict";var lx=new TextEncoder;zh.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):lx.encode(r)}});var Xh=ue(Yh=>{"use strict";var{AbstractIterator:fx}=wd(),Jh=xd(),kc=bd(),Sr=Symbol("cache"),zr=Symbol("finished"),Ot=Symbol("options"),Jr=Symbol("currentOptions"),di=Symbol("position"),vd=Symbol("location"),Zi=Symbol("first"),Gh={},Ed=class extends fx{constructor(e,t,n){super(e,n),this[Sr]=[],this[zr]=this.limit===0,this[Ot]=n,this[Jr]={...n},this[di]=void 0,this[vd]=t,this[Zi]=!0}_nextv(e,t,n){if(this[Zi]=!1,this[zr])return this.nextTick(n,null,[]);if(this[Sr].length>0)return e=Math.min(e,this[Sr].length),this.nextTick(n,null,this[Sr].splice(0,e));this[di]!==void 0&&(this[Ot].reverse?(this[Jr].lt=this[di],this[Jr].lte=void 0):(this[Jr].gt=this[di],this[Jr].gte=void 0));let i;try{i=Jh(this[Jr])}catch{return this[zr]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[vd]],"readonly"),s=o.objectStore(this[vd]),c=[];if(this[Ot].reverse){let u=!this[Ot].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[di]=l,c.push([this[Ot].keys&&l!==void 0?kc(l):void 0,this[Ot].values&&y!==void 0?kc(y):void 0]),c.length<e?a.continue():Wh(o)}else this[zr]=!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[zr]=!0:this[di]=u[l-1],c.length=l;for(let y=0;y<l;y++){let w=u[y],p=d[y];c[y]=[this[Ot].keys&&w!==void 0?kc(w):void 0,this[Ot].values&&p!==void 0?kc(p):void 0]}Wh(o)};this[Ot].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[Ot].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[Sr].length>0){let[t,n]=this[Sr].shift();this.nextTick(e,null,t,n)}else if(this[zr])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[Zi]&&(this[Zi]=!1,t=1),this._nextv(t,Gh,(n,i)=>{if(n)return e(n);this[Sr]=i,this._next(e)})}}_all(e,t){this[Zi]=!1;let n=this[Sr].splice(0,this[Sr].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[Zi]=!0,this[Sr]=[],this[zr]=!1,this[di]=void 0,this[Jr]={...this[Ot]};let n;try{n=Jh(this[Ot])}catch{this[zr]=!0;return}n!==null&&!n.includes(e)?this[zr]=!0:this[Ot].reverse?this[Jr].lte=e:this[Jr].gte=e}};Yh.Iterator=Ed;function Wh(r){typeof r.commit=="function"&&r.commit()}});var Qh=ue((K2,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 op=ue(ip=>{"use strict";var{AbstractLevel:hx}=wd(),ep=sr(),px=qh(),{fromCallback:yx}=Jo(),{Iterator:mx}=Xh(),tp=bd(),gx=Qh(),wx=xd(),np="level-js-",cs=Symbol("idb"),Ad=Symbol("namePrefix"),Gr=Symbol("location"),Sd=Symbol("version"),li=Symbol("store"),as=Symbol("onComplete"),rp=Symbol("promise"),Oc=class extends hx{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new ep("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[Gr]=e,this[Ad]=i??np,this[Sd]=parseInt(o||1,10),this[cs]=null}get location(){return this[Gr]}get namePrefix(){return this[Ad]}get version(){return this[Sd]}get db(){return this[cs]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Ad]+this[Gr],this[Sd]);n.onerror=function(){t(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[cs]=n.result,t()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Gr])||o.createObjectStore(this[Gr])}}[li](e){return this[cs].transaction([this[Gr]],e).objectStore(this[Gr])}[as](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[li]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[as](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new ep("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,tp(c))})}_getMany(e,t,n){let i=this[li]("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:tp(d))},u.onerror=d=>{d.stopPropagation(),c(u.error)}});px(o,16,n)}_del(e,t,n){let i=this[li]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[as](o,n)}_put(e,t,n,i){let o=this[li]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[as](s,i)}_iterator(e){return new mx(this,this[Gr],e)}_batch(e,t,n){let i=this[li]("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=wx(e)}catch{return this.nextTick(t)}if(e.limit>=0)return gx(this,this[Gr],n,e,t);try{let o=this[li]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(t,o)}this[as](i,t)}_close(e){this[cs].close(),this.nextTick(e)}};Oc.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=np),t=yx(t,rp);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[rp]};ip.BrowserLevel=Oc});var Td=ue(sp=>{sp.Level=op().BrowserLevel});var N0=ue(($a,M0)=>{(function(r,e){typeof $a=="object"&&typeof M0<"u"?e($a):typeof define=="function"&&define.amd?define(["exports"],e):e(r.URI=r.URI||{})})($a,function(r){"use strict";function e(){for(var h=arguments.length,f=Array(h),m=0;m<h;m++)f[m]=arguments[m];if(f.length>1){f[0]=f[0].slice(0,-1);for(var x=f.length-1,b=1;b<x;++b)f[b]=f[b].slice(1,-1);return f[x]=f[x].slice(1),f.join("")}else return f[0]}function t(h){return"(?:"+h+")"}function n(h){return h===void 0?"undefined":h===null?"null":Object.prototype.toString.call(h).split(" ").pop().split("]").shift().toLowerCase()}function i(h){return h.toUpperCase()}function o(h){return h!=null?h instanceof Array?h:typeof h.length!="number"||h.split||h.setInterval||h.call?[h]:Array.prototype.slice.call(h):[]}function s(h,f){var m=h;if(f)for(var x in f)m[x]=f[x];return m}function c(h){var f="[A-Za-z]",m="[\\x0D]",x="[0-9]",b="[\\x22]",N=e(x,"[A-Fa-f]"),oe="[\\x0A]",pe="[\\x20]",be=t(t("%[EFef]"+N+"%"+N+N+"%"+N+N)+"|"+t("%[89A-Fa-f]"+N+"%"+N+N)+"|"+t("%"+N+N)),qe="[\\:\\/\\?\\#\\[\\]\\@]",he="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",Pe=e(qe,he),je=h?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",ke=h?"[\\uE000-\\uF8FF]":"[]",ye=e(f,x,"[\\-\\.\\_\\~]",je),Re=t(f+e(f,x,"[\\+\\-\\.]")+"*"),ve=t(t(be+"|"+e(ye,he,"[\\:]"))+"*"),Vn=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("[1-9]"+x)+"|"+x),Dt=t(t("25[0-5]")+"|"+t("2[0-4]"+x)+"|"+t("1"+x+x)+"|"+t("0?[1-9]"+x)+"|0?0?"+x),jt=t(Dt+"\\."+Dt+"\\."+Dt+"\\."+Dt),Ae=t(N+"{1,4}"),Ut=t(t(Ae+"\\:"+Ae)+"|"+jt),zt=t(t(Ae+"\\:")+"{6}"+Ut),wr=t("\\:\\:"+t(Ae+"\\:")+"{5}"+Ut),qn=t(t(Ae)+"?\\:\\:"+t(Ae+"\\:")+"{4}"+Ut),Mr=t(t(t(Ae+"\\:")+"{0,1}"+Ae)+"?\\:\\:"+t(Ae+"\\:")+"{3}"+Ut),ko=t(t(t(Ae+"\\:")+"{0,2}"+Ae)+"?\\:\\:"+t(Ae+"\\:")+"{2}"+Ut),Zs=t(t(t(Ae+"\\:")+"{0,3}"+Ae)+"?\\:\\:"+Ae+"\\:"+Ut),Qs=t(t(t(Ae+"\\:")+"{0,4}"+Ae)+"?\\:\\:"+Ut),Di=t(t(t(Ae+"\\:")+"{0,5}"+Ae)+"?\\:\\:"+Ae),Ui=t(t(t(Ae+"\\:")+"{0,6}"+Ae)+"?\\:\\:"),Nr=t([zt,wr,qn,Mr,ko,Zs,Qs,Di,Ui].join("|")),_i=t(t(ye+"|"+be)+"+"),iu=t(Nr+"\\%25"+_i),jn=t(Nr+t("\\%25|\\%(?!"+N+"{2})")+_i),Gm=t("[vV]"+N+"+\\."+e(ye,he,"[\\:]")+"+"),Wm=t("\\["+t(jn+"|"+Nr+"|"+Gm)+"\\]"),mf=t(t(be+"|"+e(ye,he))+"*"),Oo=t(Wm+"|"+jt+"(?!"+mf+")|"+mf),Ko=t(x+"*"),gf=t(t(ve+"@")+"?"+Oo+t("\\:"+Ko)+"?"),Po=t(be+"|"+e(ye,he,"[\\:\\@]")),Ym=t(Po+"*"),wf=t(Po+"+"),Xm=t(t(be+"|"+e(ye,he,"[\\@]"))+"+"),Lr=t(t("\\/"+Ym)+"*"),ki=t("\\/"+t(wf+Lr)+"?"),ou=t(Xm+Lr),ec=t(wf+Lr),Oi="(?!"+Po+")",jv=t(Lr+"|"+ki+"|"+ou+"|"+ec+"|"+Oi),Ki=t(t(Po+"|"+e("[\\/\\?]",ke))+"*"),Ro=t(t(Po+"|[\\/\\?]")+"*"),xf=t(t("\\/\\/"+gf+Lr)+"|"+ki+"|"+ec+"|"+Oi),Zm=t(Re+"\\:"+xf+t("\\?"+Ki)+"?"+t("\\#"+Ro)+"?"),Qm=t(t("\\/\\/"+gf+Lr)+"|"+ki+"|"+ou+"|"+Oi),eg=t(Qm+t("\\?"+Ki)+"?"+t("\\#"+Ro)+"?"),zv=t(Zm+"|"+eg),Jv=t(Re+"\\:"+xf+t("\\?"+Ki)+"?"),Gv="^("+Re+")\\:"+t(t("\\/\\/("+t("("+ve+")@")+"?("+Oo+")"+t("\\:("+Ko+")")+"?)")+"?("+Lr+"|"+ki+"|"+ec+"|"+Oi+")")+t("\\?("+Ki+")")+"?"+t("\\#("+Ro+")")+"?$",Wv="^(){0}"+t(t("\\/\\/("+t("("+ve+")@")+"?("+Oo+")"+t("\\:("+Ko+")")+"?)")+"?("+Lr+"|"+ki+"|"+ou+"|"+Oi+")")+t("\\?("+Ki+")")+"?"+t("\\#("+Ro+")")+"?$",Yv="^("+Re+")\\:"+t(t("\\/\\/("+t("("+ve+")@")+"?("+Oo+")"+t("\\:("+Ko+")")+"?)")+"?("+Lr+"|"+ki+"|"+ec+"|"+Oi+")")+t("\\?("+Ki+")")+"?$",Xv="^"+t("\\#("+Ro+")")+"?$",Zv="^"+t("("+ve+")@")+"?("+Oo+")"+t("\\:("+Ko+")")+"?$";return{NOT_SCHEME:new RegExp(e("[^]",f,x,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(e("[^\\%\\:]",ye,he),"g"),NOT_HOST:new RegExp(e("[^\\%\\[\\]\\:]",ye,he),"g"),NOT_PATH:new RegExp(e("[^\\%\\/\\:\\@]",ye,he),"g"),NOT_PATH_NOSCHEME:new RegExp(e("[^\\%\\/\\@]",ye,he),"g"),NOT_QUERY:new RegExp(e("[^\\%]",ye,he,"[\\:\\@\\/\\?]",ke),"g"),NOT_FRAGMENT:new RegExp(e("[^\\%]",ye,he,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(e("[^]",ye,he),"g"),UNRESERVED:new RegExp(ye,"g"),OTHER_CHARS:new RegExp(e("[^\\%]",ye,Pe),"g"),PCT_ENCODED:new RegExp(be,"g"),IPV4ADDRESS:new RegExp("^("+jt+")$"),IPV6ADDRESS:new RegExp("^\\[?("+Nr+")"+t(t("\\%25|\\%(?!"+N+"{2})")+"("+_i+")")+"?\\]?$")}}var u=c(!1),d=c(!0),a=function(){function h(f,m){var x=[],b=!0,N=!1,oe=void 0;try{for(var pe=f[Symbol.iterator](),be;!(b=(be=pe.next()).done)&&(x.push(be.value),!(m&&x.length===m));b=!0);}catch(qe){N=!0,oe=qe}finally{try{!b&&pe.return&&pe.return()}finally{if(N)throw oe}}return x}return function(f,m){if(Array.isArray(f))return f;if(Symbol.iterator in Object(f))return h(f,m);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=function(h){if(Array.isArray(h)){for(var f=0,m=Array(h.length);f<h.length;f++)m[f]=h[f];return m}else return Array.from(h)},y=2147483647,w=36,p=1,g=26,v=38,B=700,D=72,E=128,O="-",I=/^xn--/,k=/[^\0-\x7E]/,M=/[\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"},re=w-p,z=Math.floor,G=String.fromCharCode;function fe(h){throw new RangeError(R[h])}function le(h,f){for(var m=[],x=h.length;x--;)m[x]=f(h[x]);return m}function nt(h,f){var m=h.split("@"),x="";m.length>1&&(x=m[0]+"@",h=m[1]),h=h.replace(M,".");var b=h.split("."),N=le(b,f).join(".");return x+N}function U(h){for(var f=[],m=0,x=h.length;m<x;){var b=h.charCodeAt(m++);if(b>=55296&&b<=56319&&m<x){var N=h.charCodeAt(m++);(N&64512)==56320?f.push(((b&1023)<<10)+(N&1023)+65536):(f.push(b),m--)}else f.push(b)}return f}var $=function(f){return String.fromCodePoint.apply(String,l(f))},ee=function(f){return f-48<10?f-22:f-65<26?f-65:f-97<26?f-97:w},_=function(f,m){return f+22+75*(f<26)-((m!=0)<<5)},T=function(f,m,x){var b=0;for(f=x?z(f/B):f>>1,f+=z(f/m);f>re*g>>1;b+=w)f=z(f/re);return z(b+(re+1)*f/(f+v))},C=function(f){var m=[],x=f.length,b=0,N=E,oe=D,pe=f.lastIndexOf(O);pe<0&&(pe=0);for(var be=0;be<pe;++be)f.charCodeAt(be)>=128&&fe("not-basic"),m.push(f.charCodeAt(be));for(var qe=pe>0?pe+1:0;qe<x;){for(var he=b,Pe=1,je=w;;je+=w){qe>=x&&fe("invalid-input");var ke=ee(f.charCodeAt(qe++));(ke>=w||ke>z((y-b)/Pe))&&fe("overflow"),b+=ke*Pe;var ye=je<=oe?p:je>=oe+g?g:je-oe;if(ke<ye)break;var Re=w-ye;Pe>z(y/Re)&&fe("overflow"),Pe*=Re}var ve=m.length+1;oe=T(b-he,ve,he==0),z(b/ve)>y-N&&fe("overflow"),N+=z(b/ve),b%=ve,m.splice(b++,0,N)}return String.fromCodePoint.apply(String,m)},V=function(f){var m=[];f=U(f);var x=f.length,b=E,N=0,oe=D,pe=!0,be=!1,qe=void 0;try{for(var he=f[Symbol.iterator](),Pe;!(pe=(Pe=he.next()).done);pe=!0){var je=Pe.value;je<128&&m.push(G(je))}}catch(jn){be=!0,qe=jn}finally{try{!pe&&he.return&&he.return()}finally{if(be)throw qe}}var ke=m.length,ye=ke;for(ke&&m.push(O);ye<x;){var Re=y,ve=!0,Vn=!1,Dt=void 0;try{for(var jt=f[Symbol.iterator](),Ae;!(ve=(Ae=jt.next()).done);ve=!0){var Ut=Ae.value;Ut>=b&&Ut<Re&&(Re=Ut)}}catch(jn){Vn=!0,Dt=jn}finally{try{!ve&&jt.return&&jt.return()}finally{if(Vn)throw Dt}}var zt=ye+1;Re-b>z((y-N)/zt)&&fe("overflow"),N+=(Re-b)*zt,b=Re;var wr=!0,qn=!1,Mr=void 0;try{for(var ko=f[Symbol.iterator](),Zs;!(wr=(Zs=ko.next()).done);wr=!0){var Qs=Zs.value;if(Qs<b&&++N>y&&fe("overflow"),Qs==b){for(var Di=N,Ui=w;;Ui+=w){var Nr=Ui<=oe?p:Ui>=oe+g?g:Ui-oe;if(Di<Nr)break;var _i=Di-Nr,iu=w-Nr;m.push(G(_(Nr+_i%iu,0))),Di=z(_i/iu)}m.push(G(_(Di,0))),oe=T(N,zt,ye==ke),N=0,++ye}}}catch(jn){qn=!0,Mr=jn}finally{try{!wr&&ko.return&&ko.return()}finally{if(qn)throw Mr}}++N,++b}return m.join("")},Y=function(f){return nt(f,function(m){return I.test(m)?C(m.slice(4).toLowerCase()):m})},ne=function(f){return nt(f,function(m){return k.test(m)?"xn--"+V(m):m})},Z={version:"2.1.0",ucs2:{decode:U,encode:$},decode:C,encode:V,toASCII:ne,toUnicode:Y},Q={};function X(h){var f=h.charCodeAt(0),m=void 0;return f<16?m="%0"+f.toString(16).toUpperCase():f<128?m="%"+f.toString(16).toUpperCase():f<2048?m="%"+(f>>6|192).toString(16).toUpperCase()+"%"+(f&63|128).toString(16).toUpperCase():m="%"+(f>>12|224).toString(16).toUpperCase()+"%"+(f>>6&63|128).toString(16).toUpperCase()+"%"+(f&63|128).toString(16).toUpperCase(),m}function ie(h){for(var f="",m=0,x=h.length;m<x;){var b=parseInt(h.substr(m+1,2),16);if(b<128)f+=String.fromCharCode(b),m+=3;else if(b>=194&&b<224){if(x-m>=6){var N=parseInt(h.substr(m+4,2),16);f+=String.fromCharCode((b&31)<<6|N&63)}else f+=h.substr(m,6);m+=6}else if(b>=224){if(x-m>=9){var oe=parseInt(h.substr(m+4,2),16),pe=parseInt(h.substr(m+7,2),16);f+=String.fromCharCode((b&15)<<12|(oe&63)<<6|pe&63)}else f+=h.substr(m,9);m+=9}else f+=h.substr(m,3),m+=3}return f}function _e(h,f){function m(x){var b=ie(x);return b.match(f.UNRESERVED)?b:x}return h.scheme&&(h.scheme=String(h.scheme).replace(f.PCT_ENCODED,m).toLowerCase().replace(f.NOT_SCHEME,"")),h.userinfo!==void 0&&(h.userinfo=String(h.userinfo).replace(f.PCT_ENCODED,m).replace(f.NOT_USERINFO,X).replace(f.PCT_ENCODED,i)),h.host!==void 0&&(h.host=String(h.host).replace(f.PCT_ENCODED,m).toLowerCase().replace(f.NOT_HOST,X).replace(f.PCT_ENCODED,i)),h.path!==void 0&&(h.path=String(h.path).replace(f.PCT_ENCODED,m).replace(h.scheme?f.NOT_PATH:f.NOT_PATH_NOSCHEME,X).replace(f.PCT_ENCODED,i)),h.query!==void 0&&(h.query=String(h.query).replace(f.PCT_ENCODED,m).replace(f.NOT_QUERY,X).replace(f.PCT_ENCODED,i)),h.fragment!==void 0&&(h.fragment=String(h.fragment).replace(f.PCT_ENCODED,m).replace(f.NOT_FRAGMENT,X).replace(f.PCT_ENCODED,i)),h}function Te(h){return h.replace(/^0*(.*)/,"$1")||"0"}function Le(h,f){var m=h.match(f.IPV4ADDRESS)||[],x=a(m,2),b=x[1];return b?b.split(".").map(Te).join("."):h}function Ve(h,f){var m=h.match(f.IPV6ADDRESS)||[],x=a(m,3),b=x[1],N=x[2];if(b){for(var oe=b.toLowerCase().split("::").reverse(),pe=a(oe,2),be=pe[0],qe=pe[1],he=qe?qe.split(":").map(Te):[],Pe=be.split(":").map(Te),je=f.IPV4ADDRESS.test(Pe[Pe.length-1]),ke=je?7:8,ye=Pe.length-ke,Re=Array(ke),ve=0;ve<ke;++ve)Re[ve]=he[ve]||Pe[ye+ve]||"";je&&(Re[ke-1]=Le(Re[ke-1],f));var Vn=Re.reduce(function(zt,wr,qn){if(!wr||wr==="0"){var Mr=zt[zt.length-1];Mr&&Mr.index+Mr.length===qn?Mr.length++:zt.push({index:qn,length:1})}return zt},[]),Dt=Vn.sort(function(zt,wr){return wr.length-zt.length})[0],jt=void 0;if(Dt&&Dt.length>1){var Ae=Re.slice(0,Dt.index),Ut=Re.slice(Dt.index+Dt.length);jt=Ae.join(":")+"::"+Ut.join(":")}else jt=Re.join(":");return N&&(jt+="%"+N),jt}else return h}var $e=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Xe="".match(/(){0}/)[1]===void 0;function ze(h){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m={},x=f.iri!==!1?d:u;f.reference==="suffix"&&(h=(f.scheme?f.scheme+":":"")+"//"+h);var b=h.match($e);if(b){Xe?(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=h.indexOf("@")!==-1?b[3]:void 0,m.host=h.indexOf("//")!==-1?b[4]:void 0,m.port=parseInt(b[5],10),m.path=b[6]||"",m.query=h.indexOf("?")!==-1?b[7]:void 0,m.fragment=h.indexOf("#")!==-1?b[8]:void 0,isNaN(m.port)&&(m.port=h.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?b[4]:void 0)),m.host&&(m.host=Ve(Le(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",f.reference&&f.reference!=="suffix"&&f.reference!==m.reference&&(m.error=m.error||"URI is not a "+f.reference+" reference.");var N=Q[(f.scheme||m.scheme||"").toLowerCase()];if(!f.unicodeSupport&&(!N||!N.unicodeSupport)){if(m.host&&(f.domainHost||N&&N.domainHost))try{m.host=Z.toASCII(m.host.replace(x.PCT_ENCODED,ie).toLowerCase())}catch(oe){m.error=m.error||"Host's domain name can not be converted to ASCII via punycode: "+oe}_e(m,u)}else _e(m,x);N&&N.parse&&N.parse(m,f)}else m.error=m.error||"URI can not be parsed.";return m}function Cr(h,f){var m=f.iri!==!1?d:u,x=[];return h.userinfo!==void 0&&(x.push(h.userinfo),x.push("@")),h.host!==void 0&&x.push(Ve(Le(String(h.host),m),m).replace(m.IPV6ADDRESS,function(b,N,oe){return"["+N+(oe?"%25"+oe:"")+"]"})),(typeof h.port=="number"||typeof h.port=="string")&&(x.push(":"),x.push(String(h.port))),x.length?x.join(""):void 0}var ln=/^\.\.?\//,Io=/^\/\.(\/|$)/,zs=/^\/\.\.(\/|$)/,tu=/^\/?(?:.|\n)*?(?=\/|$)/;function fn(h){for(var f=[];h.length;)if(h.match(ln))h=h.replace(ln,"");else if(h.match(Io))h=h.replace(Io,"/");else if(h.match(zs))h=h.replace(zs,"/"),f.pop();else if(h==="."||h==="..")h="";else{var m=h.match(tu);if(m){var x=m[0];h=h.slice(x.length),f.push(x)}else throw new Error("Unexpected dot segment condition")}return f.join("")}function Vt(h){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},m=f.iri?d:u,x=[],b=Q[(f.scheme||h.scheme||"").toLowerCase()];if(b&&b.serialize&&b.serialize(h,f),h.host&&!m.IPV6ADDRESS.test(h.host)){if(f.domainHost||b&&b.domainHost)try{h.host=f.iri?Z.toUnicode(h.host):Z.toASCII(h.host.replace(m.PCT_ENCODED,ie).toLowerCase())}catch(pe){h.error=h.error||"Host's domain name can not be converted to "+(f.iri?"Unicode":"ASCII")+" via punycode: "+pe}}_e(h,m),f.reference!=="suffix"&&h.scheme&&(x.push(h.scheme),x.push(":"));var N=Cr(h,f);if(N!==void 0&&(f.reference!=="suffix"&&x.push("//"),x.push(N),h.path&&h.path.charAt(0)!=="/"&&x.push("/")),h.path!==void 0){var oe=h.path;!f.absolutePath&&(!b||!b.absolutePath)&&(oe=fn(oe)),N===void 0&&(oe=oe.replace(/^\/\//,"/%2F")),x.push(oe)}return h.query!==void 0&&(x.push("?"),x.push(h.query)),h.fragment!==void 0&&(x.push("#"),x.push(h.fragment)),x.join("")}function Do(h,f){var m=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},x=arguments[3],b={};return x||(h=ze(Vt(h,m),m),f=ze(Vt(f,m),m)),m=m||{},!m.tolerant&&f.scheme?(b.scheme=f.scheme,b.userinfo=f.userinfo,b.host=f.host,b.port=f.port,b.path=fn(f.path||""),b.query=f.query):(f.userinfo!==void 0||f.host!==void 0||f.port!==void 0?(b.userinfo=f.userinfo,b.host=f.host,b.port=f.port,b.path=fn(f.path||""),b.query=f.query):(f.path?(f.path.charAt(0)==="/"?b.path=fn(f.path):((h.userinfo!==void 0||h.host!==void 0||h.port!==void 0)&&!h.path?b.path="/"+f.path:h.path?b.path=h.path.slice(0,h.path.lastIndexOf("/")+1)+f.path:b.path=f.path,b.path=fn(b.path)),b.query=f.query):(b.path=h.path,f.query!==void 0?b.query=f.query:b.query=h.query),b.userinfo=h.userinfo,b.host=h.host,b.port=h.port),b.scheme=h.scheme),b.fragment=f.fragment,b}function Js(h,f,m){var x=s({scheme:"null"},m);return Vt(Do(ze(h,x),ze(f,x),x,!0),x)}function Uo(h,f){return typeof h=="string"?h=Vt(ze(h,f),f):n(h)==="object"&&(h=ze(Vt(h,f),f)),h}function Gs(h,f,m){return typeof h=="string"?h=Vt(ze(h,m),m):n(h)==="object"&&(h=Vt(h,m)),typeof f=="string"?f=Vt(ze(f,m),m):n(f)==="object"&&(f=Vt(f,m)),h===f}function Ws(h,f){return h&&h.toString().replace(!f||!f.iri?u.ESCAPE:d.ESCAPE,X)}function qt(h,f){return h&&h.toString().replace(!f||!f.iri?u.PCT_ENCODED:d.PCT_ENCODED,ie)}var hn={scheme:"http",domainHost:!0,parse:function(f,m){return f.host||(f.error=f.error||"HTTP URIs must have a host."),f},serialize:function(f,m){var x=String(f.scheme).toLowerCase()==="https";return(f.port===(x?443:80)||f.port==="")&&(f.port=void 0),f.path||(f.path="/"),f}},_o={scheme:"https",domainHost:hn.domainHost,parse:hn.parse,serialize:hn.serialize};function Ys(h){return typeof h.secure=="boolean"?h.secure:String(h.scheme).toLowerCase()==="wss"}var Hn={scheme:"ws",domainHost:!0,parse:function(f,m){var x=f;return x.secure=Ys(x),x.resourceName=(x.path||"/")+(x.query?"?"+x.query:""),x.path=void 0,x.query=void 0,x},serialize:function(f,m){if((f.port===(Ys(f)?443:80)||f.port==="")&&(f.port=void 0),typeof f.secure=="boolean"&&(f.scheme=f.secure?"wss":"ws",f.secure=void 0),f.resourceName){var x=f.resourceName.split("?"),b=a(x,2),N=b[0],oe=b[1];f.path=N&&N!=="/"?N:void 0,f.query=oe,f.resourceName=void 0}return f.fragment=void 0,f}},Xs={scheme:"wss",domainHost:Hn.domainHost,parse:Hn.parse,serialize:Hn.serialize},ru={},Mm=!0,lf="[A-Za-z0-9\\-\\.\\_\\~"+(Mm?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",gr="[0-9A-Fa-f]",Nm=t(t("%[EFef]"+gr+"%"+gr+gr+"%"+gr+gr)+"|"+t("%[89A-Fa-f]"+gr+"%"+gr+gr)+"|"+t("%"+gr+gr)),Lm="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",$m="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",Fm=e($m,'[\\"\\\\]'),Hm="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Vm=new RegExp(lf,"g"),Ii=new RegExp(Nm,"g"),qm=new RegExp(e("[^]",Lm,"[\\.]",'[\\"]',Fm),"g"),ff=new RegExp(e("[^]",lf,Hm),"g"),jm=ff;function nu(h){var f=ie(h);return f.match(Vm)?f:h}var hf={scheme:"mailto",parse:function(f,m){var x=f,b=x.to=x.path?x.path.split(","):[];if(x.path=void 0,x.query){for(var N=!1,oe={},pe=x.query.split("&"),be=0,qe=pe.length;be<qe;++be){var he=pe[be].split("=");switch(he[0]){case"to":for(var Pe=he[1].split(","),je=0,ke=Pe.length;je<ke;++je)b.push(Pe[je]);break;case"subject":x.subject=qt(he[1],m);break;case"body":x.body=qt(he[1],m);break;default:N=!0,oe[qt(he[0],m)]=qt(he[1],m);break}}N&&(x.headers=oe)}x.query=void 0;for(var ye=0,Re=b.length;ye<Re;++ye){var ve=b[ye].split("@");if(ve[0]=qt(ve[0]),m.unicodeSupport)ve[1]=qt(ve[1],m).toLowerCase();else try{ve[1]=Z.toASCII(qt(ve[1],m).toLowerCase())}catch(Vn){x.error=x.error||"Email address's domain name can not be converted to ASCII via punycode: "+Vn}b[ye]=ve.join("@")}return x},serialize:function(f,m){var x=f,b=o(f.to);if(b){for(var N=0,oe=b.length;N<oe;++N){var pe=String(b[N]),be=pe.lastIndexOf("@"),qe=pe.slice(0,be).replace(Ii,nu).replace(Ii,i).replace(qm,X),he=pe.slice(be+1);try{he=m.iri?Z.toUnicode(he):Z.toASCII(qt(he,m).toLowerCase())}catch(ye){x.error=x.error||"Email address's domain name can not be converted to "+(m.iri?"Unicode":"ASCII")+" via punycode: "+ye}b[N]=qe+"@"+he}x.path=b.join(",")}var Pe=f.headers=f.headers||{};f.subject&&(Pe.subject=f.subject),f.body&&(Pe.body=f.body);var je=[];for(var ke in Pe)Pe[ke]!==ru[ke]&&je.push(ke.replace(Ii,nu).replace(Ii,i).replace(ff,X)+"="+Pe[ke].replace(Ii,nu).replace(Ii,i).replace(jm,X));return je.length&&(x.query=je.join("&")),x}},zm=/^([^\:]+)\:(.*)/,pf={scheme:"urn",parse:function(f,m){var x=f.path&&f.path.match(zm),b=f;if(x){var N=m.scheme||b.scheme||"urn",oe=x[1].toLowerCase(),pe=x[2],be=N+":"+(m.nid||oe),qe=Q[be];b.nid=oe,b.nss=pe,b.path=void 0,qe&&(b=qe.parse(b,m))}else b.error=b.error||"URN can not be parsed.";return b},serialize:function(f,m){var x=m.scheme||f.scheme||"urn",b=f.nid,N=x+":"+(m.nid||b),oe=Q[N];oe&&(f=oe.serialize(f,m));var pe=f,be=f.nss;return pe.path=(b||m.nid)+":"+be,pe}},Jm=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,yf={scheme:"urn:uuid",parse:function(f,m){var x=f;return x.uuid=x.nss,x.nss=void 0,!m.tolerant&&(!x.uuid||!x.uuid.match(Jm))&&(x.error=x.error||"UUID is not valid."),x},serialize:function(f,m){var x=f;return x.nss=(f.uuid||"").toLowerCase(),x}};Q[hn.scheme]=hn,Q[_o.scheme]=_o,Q[Hn.scheme]=Hn,Q[Xs.scheme]=Xs,Q[hf.scheme]=hf,Q[pf.scheme]=pf,Q[yf.scheme]=yf,r.SCHEMES=Q,r.pctEncChar=X,r.pctDecChars=ie,r.parse=ze,r.removeDotSegments=fn,r.serialize=Vt,r.resolveComponents=Do,r.resolve=Js,r.normalize=Uo,r.equal=Gs,r.escapeComponent=Ws,r.unescapeComponent=qt,Object.defineProperty(r,"__esModule",{value:!0})})});var $0=ue((xI,L0)=>{"use strict";L0.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 df=ue((gU,Um)=>{var So=1e3,To=So*60,Bo=To*60,Bi=Bo*24,$v=Bi*7,Fv=Bi*365.25;Um.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Hv(r);if(t==="number"&&isFinite(r))return e.long?qv(r):Vv(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Hv(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*Fv;case"weeks":case"week":case"w":return t*$v;case"days":case"day":case"d":return t*Bi;case"hours":case"hour":case"hrs":case"hr":case"h":return t*Bo;case"minutes":case"minute":case"mins":case"min":case"m":return t*To;case"seconds":case"second":case"secs":case"sec":case"s":return t*So;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function Vv(r){var e=Math.abs(r);return e>=Bi?Math.round(r/Bi)+"d":e>=Bo?Math.round(r/Bo)+"h":e>=To?Math.round(r/To)+"m":e>=So?Math.round(r/So)+"s":r+"ms"}function qv(r){var e=Math.abs(r);return e>=Bi?eu(r,e,Bi,"day"):e>=Bo?eu(r,e,Bo,"hour"):e>=To?eu(r,e,To,"minute"):e>=So?eu(r,e,So,"second"):r+" ms"}function eu(r,e,t,n){var i=e>=t*1.5;return Math.round(r/t)+" "+n+(i?"s":"")}});var Pi=(o=>(o.authentication="authentication",o.assertionMethod="assertionMethod",o.keyAgreement="keyAgreement",o.capabilityInvocation="capabilityInvocation",o.capabilityDelegation="capabilityDelegation",o))(Pi||{});var Ce={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};var Je=class Je{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=Je.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}};Je.METHOD_PATTERN="([a-z0-9]+)",Je.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})",Je.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${Je.PCT_ENCODED_PATTERN})`,Je.METHOD_ID_PATTERN=`((?:${Je.ID_CHAR_PATTERN}*:)*(${Je.ID_CHAR_PATTERN}+))`,Je.PATH_PATTERN="(/[^#?]*)?",Je.QUERY_PATTERN="([?][^#]*)?",Je.FRAGMENT_PATTERN="(#.*)?",Je.DID_URI_PATTERN=new RegExp("^did:(?<method>"+Je.METHOD_PATTERN+"):(?<id>"+Je.METHOD_ID_PATTERN+")(?<path>"+Je.PATH_PATTERN+")(?<query>"+Je.QUERY_PATTERN+")(?<fragment>"+Je.FRAGMENT_PATTERN+")$");var Oe=Je;var H=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)}},Jt=(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))(Jt||{});var Fe=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)}},He;(function(r){r.AlgorithmNotSupported="algorithmNotSupported",r.EncodingError="encodingError",r.InvalidCoseSign1="invalidCoseSign1",r.InvalidEat="invalidEat",r.InvalidJwe="invalidJwe",r.InvalidJwk="invalidJwk",r.OperationNotSupported="operationNotSupported"})(He||(He={}));var du=zn(vf(),1);var cE=new Uint8Array(0);function Ef(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 Ri(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 dg(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,B=0,D=p.length;B!==D&&p[B]===0;)B++,g++;for(var E=(D-B)*a+1>>>0,O=new Uint8Array(E);B!==D;){for(var I=p[B],k=0,M=E-1;(I!==0||k<v)&&M!==-1;M--,k++)I+=256*O[M]>>>0,O[M]=I%c>>>0,I=I/c>>>0;if(I!==0)throw new Error("Non-zero carry");v=k,B++}for(var R=E-v;R!==E&&O[R]===0;)R++;for(var re=u.repeat(g);R<E;++R)re+=r.charAt(O[R]);return re}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,B=0;p[g]===u;)v++,g++;for(var D=(p.length-g)*d+1>>>0,E=new Uint8Array(D);p[g];){var O=t[p.charCodeAt(g)];if(O===255)return;for(var I=0,k=D-1;(O!==0||I<B)&&k!==-1;k--,I++)O+=c*E[k]>>>0,E[k]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");B=I,g++}if(p[g]!==" "){for(var M=D-B;M!==D&&E[M]===0;)M++;for(var R=new Uint8Array(v+(D-M)),re=v;M!==D;)R[re++]=E[M++];return R}}}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 lg=dg,fg=lg,Af=fg;var lu=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")}},fu=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 Sf(this,e)}},hu=class{decoders;constructor(e){this.decoders=e}or(e){return Sf(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 Sf(r,e){return new hu({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var pu=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 lu(e,t,n),this.decoder=new fu(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Tf({name:r,prefix:e,encode:t,decode:n}){return new pu(r,e,t,n)}function yu({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Af(t,r);return Tf({prefix:e,name:r,encode:n,decode:o=>Ri(i(o))})}function hg(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 pg(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 pt({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Tf({prefix:e,name:r,encode(i){return pg(i,n,t)},decode(i){return hg(i,n,t,r)}})}var Co=pt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hE=pt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pE=pt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yE=pt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mE=pt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gE=pt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wE=pt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xE=pt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mu=pt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xt=yu({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),EE=yu({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var TE=pt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),BE=pt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xr=pt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),IE=pt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Bf(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function If(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function Ci(r){let t=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=t;return i}var Mo=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())})},Df=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)}},rc=new TextEncoder,Jn=new TextDecoder,P=class r{constructor(e,t){this.data=e,this.format=t}static arrayBuffer(e){return new r(e,"ArrayBuffer")}static asyncIterable(e){if(!If(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 xt.baseDecode(this.data).buffer;case"Base64Url":return xr.baseDecode(this.data).buffer;case"BufferSource":{if(Ci(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Bf(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 Mo(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 mu.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 xt.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return xt.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 xr.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return xr.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),t=rc.encode(e);return xr.baseEncode(t)}case"String":{let e=rc.encode(this.data);return xr.baseEncode(e)}case"Uint8Array":return xr.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return Mo(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u=[];try{for(var o=!0,s=Df(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=xr.baseDecode(this.data),t=Jn.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Jn.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return Mo(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 Jn.decode(this.data);case"Base64Url":{let e=xr.baseDecode(this.data);return Jn.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Jn.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return Mo(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let u="";try{for(var o=!0,s=Df(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+=Jn.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+=Jn.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 mu.baseDecode(this.data);case"Base58Btc":return xt.baseDecode(this.data);case"Base64Url":return xr.baseDecode(this.data);case"BufferSource":{let e=Ci(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 rc.encode(e)}case"String":return rc.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return Mo(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 No;(function(r){r.Debug="debug",r.Silent="silent"})(No||(No={}));var gu=class{constructor(){this.logLevel=No.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==No.Silent&&console.info(e)}error(e){this.logLevel!==No.Silent&&console.error(e)}},yg=new gu;typeof window<"u"&&(window.web5logger=yg);var $r={};cu($r,{decode:()=>Mi,encodeTo:()=>Gn,encodingLength:()=>Wn});var mg=kf,Uf=128,gg=127,wg=~gg,xg=Math.pow(2,31);function kf(r,e,t){e=e||[],t=t||0;for(var n=t;r>=xg;)e[t++]=r&255|Uf,r/=128;for(;r&wg;)e[t++]=r&255|Uf,r>>>=7;return e[t]=r|0,kf.bytes=t-n+1,e}var bg=wu,vg=128,_f=127;function wu(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw wu.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&_f)<<i:(s&_f)*Math.pow(2,i),i+=7}while(s>=vg);return wu.bytes=o-n,t}var Eg=Math.pow(2,7),Ag=Math.pow(2,14),Sg=Math.pow(2,21),Tg=Math.pow(2,28),Bg=Math.pow(2,35),Ig=Math.pow(2,42),Dg=Math.pow(2,49),Ug=Math.pow(2,56),_g=Math.pow(2,63),kg=function(r){return r<Eg?1:r<Ag?2:r<Sg?3:r<Tg?4:r<Bg?5:r<Ig?6:r<Dg?7:r<Ug?8:r<_g?9:10},Og={encode:mg,decode:bg,encodingLength:kg},Kg=Og,Lo=Kg;function Mi(r,e=0){return[Lo.decode(r,e),Lo.decode.bytes]}function Gn(r,e,t=0){return Lo.encode(r,e,t),e}function Wn(r){return Lo.encodingLength(r)}function xu(r,e){let t=e.byteLength,n=Wn(r),i=n+Wn(t),o=new Uint8Array(i+t);return Gn(r,o,0),Gn(t,o,n),o.set(e,i),new Ni(r,t,e,o)}function Of(r){let e=Ri(r),[t,n]=Mi(e),[i,o]=Mi(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ni(t,i,s,e)}function Kf(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ef(r.bytes,t.bytes)}}var Ni=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function Pf(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Rg(t,vu(r),e??xt.encoder);default:return Cg(t,vu(r),e??Co.encoder)}}var Rf=new WeakMap;function vu(r){let e=Rf.get(r);if(e==null){let t=new Map;return Rf.set(r,t),t}return e}var Eu=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!==$o)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Mg)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=xu(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&&Kf(e.multihash,n.multihash)}toString(e){return Pf(this,e)}toJSON(){return{"/":Pf(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??Cf(n,i,o.bytes))}else if(t[Ng]===!0){let{version:n,multihash:i,code:o}=t,s=Of(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!==$o)throw new Error(`Version 0 CID must use dag-pb (code: ${$o}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=Cf(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,$o,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=Ri(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 Ni(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]=Mi(e.subarray(t));return t+=y,l},i=n(),o=$o;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]=Pg(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 vu(o).set(n,e),o}};function Pg(r,e){switch(r[0]){case"Q":{let t=e??xt;return[xt.prefix,t.decode(`${xt.prefix}${r}`)]}case xt.prefix:{let t=e??xt;return[xt.prefix,t.decode(r)]}case Co.prefix:{let t=e??Co;return[Co.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 Rg(r,e,t){let{prefix:n}=t;if(n!==xt.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 Cg(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 $o=112,Mg=18;function Cf(r,e,t){let n=Wn(r),i=n+Wn(e),o=new Uint8Array(i+t.byteLength);return Gn(r,o,0),Gn(e,o,n),o.set(t,i),o}var Ng=Symbol.for("@ipld/js-cid/CID");var at=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=$r.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),$r.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=$r.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]=$r.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}}};at.codeToName=new Map;at.nameToCode=new Map;at.registerCodec({code:237,name:"ed25519-pub"});at.registerCodec({code:4864,name:"ed25519-priv"});at.registerCodec({code:236,name:"x25519-pub"});at.registerCodec({code:4866,name:"x25519-priv"});at.registerCodec({code:231,name:"secp256k1-pub"});at.registerCodec({code:4865,name:"secp256k1-priv"});function Au(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&Au(r[e])})}var xx=zn(Td(),1),fi=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 Kc=class{constructor(){this.store=new Map}clear(){return fi(this,void 0,void 0,function*(){this.store.clear()})}close(){return fi(this,void 0,void 0,function*(){})}delete(e){return fi(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return fi(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return fi(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return fi(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return fi(this,void 0,void 0,function*(){this.store.set(e,t)})}};var mt=class{};var Rc={};cu(Rc,{bitGet:()=>Bx,bitLen:()=>Tx,bitMask:()=>us,bitSet:()=>Ix,bytesToHex:()=>Yr,bytesToNumberBE:()=>Xr,bytesToNumberLE:()=>dr,concatBytes:()=>Qr,createHmacDrbg:()=>Dd,ensureBytes:()=>Be,equalBytes:()=>Ax,hexToBytes:()=>hi,hexToNumber:()=>Id,isBytes:()=>ur,numberToBytesBE:()=>Et,numberToBytesLE:()=>Zr,numberToHexUnpadded:()=>dp,numberToVarBytesBE:()=>Ex,utf8ToBytes:()=>Sx,validateObject:()=>Xt});var up=BigInt(0),Pc=BigInt(1),bx=BigInt(2);function ur(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var vx=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Yr(r){if(!ur(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=vx[r[t]];return e}function dp(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Id(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Wr={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function cp(r){if(r>=Wr._0&&r<=Wr._9)return r-Wr._0;if(r>=Wr._A&&r<=Wr._F)return r-(Wr._A-10);if(r>=Wr._a&&r<=Wr._f)return r-(Wr._a-10)}function hi(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=cp(r.charCodeAt(o)),c=cp(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 Xr(r){return Id(Yr(r))}function dr(r){if(!ur(r))throw new Error("Uint8Array expected");return Id(Yr(Uint8Array.from(r).reverse()))}function Et(r,e){return hi(r.toString(16).padStart(e*2,"0"))}function Zr(r,e){return Et(r,e).reverse()}function Ex(r){return hi(dp(r))}function Be(r,e,t){let n;if(typeof e=="string")try{n=hi(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(ur(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 Qr(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!ur(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 Ax(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 Sx(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Tx(r){let e;for(e=0;r>up;r>>=Pc,e+=1);return e}function Bx(r,e){return r>>BigInt(e)&Pc}var Ix=(r,e,t)=>r|(t?Pc:up)<<BigInt(e),us=r=>(bx<<BigInt(r-1))-Pc,Bd=r=>new Uint8Array(r),ap=r=>Uint8Array.from(r);function Dd(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=Bd(r),i=Bd(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),u=(l=Bd())=>{i=c(ap([0]),l),n=c(),l.length!==0&&(i=c(ap([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 Qr(...y)};return(l,y)=>{s(),u(l);let w;for(;!(w=y(d()));)u();return s(),w}}var Dx={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"||ur(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 Xt(r,e,t={}){let n=(i,o,s)=>{let c=Dx[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 lp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Ux(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ud(r,...e){if(!Ux(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 fp(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");lp(r.outputLen),lp(r.blockLen)}function Qi(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 hp(r,e){Ud(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Cc=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function pp(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Mc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),lr=(r,e)=>r<<32-e|r>>>e,_x=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!_x)throw new Error("Non little-endian hardware is not supported");function _d(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ds(r){if(typeof r=="string"&&(r=_d(r)),!pp(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Nc(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!pp(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 eo=class{clone(){return this._cloneInto()}},Z2={}.toString;function Lc(r){let e=n=>r().update(ds(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ls(r=32){if(Cc&&typeof Cc.getRandomValues=="function")return Cc.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function kx(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 to=class extends eo{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){Qi(this);let{view:t,buffer:n,blockLen:i}=this;e=ds(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){Qi(this),hp(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;kx(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 Ox=(r,e,t)=>r&e^~r&t,Kx=(r,e,t)=>r&e^r&t^e&t,Px=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]),Sn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tn=new Uint32Array(64),kd=class extends to{constructor(){super(64,32,8,!1),this.A=Sn[0]|0,this.B=Sn[1]|0,this.C=Sn[2]|0,this.D=Sn[3]|0,this.E=Sn[4]|0,this.F=Sn[5]|0,this.G=Sn[6]|0,this.H=Sn[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)Tn[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=Tn[l-15],w=Tn[l-2],p=lr(y,7)^lr(y,18)^y>>>3,g=lr(w,17)^lr(w,19)^w>>>10;Tn[l]=g+Tn[l-7]+p+Tn[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=lr(c,6)^lr(c,11)^lr(c,25),w=a+y+Ox(c,u,d)+Px[l]+Tn[l]|0,g=(lr(n,2)^lr(n,13)^lr(n,22))+Kx(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(){Tn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var $c=Lc(()=>new kd);var Ge=BigInt(0),Ke=BigInt(1),pi=BigInt(2),Rx=BigInt(3),Od=BigInt(4),yp=BigInt(5),mp=BigInt(8),Cx=BigInt(9),Mx=BigInt(16);function we(r,e){let t=r%e;return t>=Ge?t:e+t}function Kd(r,e,t){if(t<=Ge||e<Ge)throw new Error("Expected power/modulo > 0");if(t===Ke)return Ge;let n=Ke;for(;e>Ge;)e&Ke&&(n=n*r%t),r=r*r%t,e>>=Ke;return n}function Ie(r,e,t){let n=r;for(;e-- >Ge;)n*=n,n%=t;return n}function Fc(r,e){if(r===Ge||e<=Ge)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=we(r,e),n=e,i=Ge,o=Ke,s=Ke,c=Ge;for(;t!==Ge;){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!==Ke)throw new Error("invert: does not exist");return we(i,e)}function Nx(r){let e=(r-Ke)/pi,t,n,i;for(t=r-Ke,n=0;t%pi===Ge;t/=pi,n++);for(i=pi;i<r&&Kd(i,e,r)!==r-Ke;i++);if(n===1){let s=(r+Ke)/Od;return function(u,d){let a=u.pow(d,s);if(!u.eql(u.sqr(a),d))throw new Error("Cannot find square root");return a}}let o=(t+Ke)/pi;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,Ke<<BigInt(d-w-1));a=c.sqr(p),l=c.mul(l,p),y=c.mul(y,a),d=w}return l}}function Lx(r){if(r%Od===Rx){let e=(r+Ke)/Od;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%mp===yp){let e=(r-yp)/mp;return function(n,i){let o=n.mul(i,pi),s=n.pow(o,e),c=n.mul(i,s),u=n.mul(n.mul(c,pi),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%Mx,Nx(r)}var gp=(r,e)=>(we(r,e)&Ke)===Ke,$x=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pd(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=$x.reduce((n,i)=>(n[i]="function",n),e);return Xt(r,t)}function Fx(r,e,t){if(t<Ge)throw new Error("Expected power > 0");if(t===Ge)return r.ONE;if(t===Ke)return e;let n=r.ONE,i=e;for(;t>Ge;)t&Ke&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Ke;return n}function Hx(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 Rd(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function ro(r,e,t=!1,n={}){if(r<=Ge)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Rd(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Lx(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:us(i),ZERO:Ge,ONE:Ke,create:u=>we(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof u}`);return Ge<=u&&u<r},is0:u=>u===Ge,isOdd:u=>(u&Ke)===Ke,neg:u=>we(-u,r),eql:(u,d)=>u===d,sqr:u=>we(u*u,r),add:(u,d)=>we(u+d,r),sub:(u,d)=>we(u-d,r),mul:(u,d)=>we(u*d,r),pow:(u,d)=>Fx(c,u,d),div:(u,d)=>we(u*Fc(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>Fc(u,r),sqrt:n.sqrt||(u=>s(c,u)),invertBatch:u=>Hx(c,u),cmov:(u,d,a)=>a?d:u,toBytes:u=>t?Zr(u,o):Et(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return t?dr(u):Xr(u)}});return Object.freeze(c)}function wp(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 xp(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 Cd(r){let e=xp(r);return e+Math.ceil(e/2)}function bp(r,e,t=!1){let n=r.length,i=xp(e),o=Cd(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?Xr(r):dr(r),c=we(s,e-Ke)+Ke;return t?Zr(c,i):Et(c,i)}var qx=BigInt(0),Md=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>qx;)o&Md&&(s=s.add(c)),c=c.double(),o>>=Md;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+=Md);let B=g,D=g+Math.abs(v)-1,E=p%2!==0,O=v<0;v===0?a=a.add(t(E,o[B])):d=d.add(t(O,o[D]))}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 fs(r){return Pd(r.Fp),Xt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rd(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function jx(r){let e=fs(r);Xt(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:zx,hexToBytes:Jx}=Rc,yi={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=yi;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:zx(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=yi,t=typeof r=="string"?Jx(r):r;if(!ur(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}=yi._parseInt(t.subarray(2)),{d:s,l:c}=yi._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}`}},en=BigInt(0),Zt=BigInt(1),hA=BigInt(2),vp=BigInt(3),pA=BigInt(4);function Gx(r){let e=jx(r),{Fp:t}=e,n=e.toBytes||((p,g,v)=>{let B=g.toAffine();return Qr(Uint8Array.from([4]),t.toBytes(B.x),t.toBytes(B.y))}),i=e.fromBytes||(p=>{let g=p.subarray(1),v=t.fromBytes(g.subarray(0,t.BYTES)),B=t.fromBytes(g.subarray(t.BYTES,2*t.BYTES));return{x:v,y:B}});function o(p){let{a:g,b:v}=e,B=t.sqr(p),D=t.mul(B,p);return t.add(t.add(D,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"&&en<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:B,n:D}=e;if(g&&typeof p!="bigint"){if(ur(p)&&(p=Yr(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:Xr(Be("private key",p,v))}catch{throw new Error(`private key must be ${v} bytes, hex or bigint, not ${typeof p}`)}return B&&(E=we(E,D)),c(E),E}let d=new Map;function a(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(g,v,B){if(this.px=g,this.py=v,this.pz=B,g==null||!t.isValid(g))throw new Error("x required");if(v==null||!t.isValid(v))throw new Error("y required");if(B==null||!t.isValid(B))throw new Error("z required")}static fromAffine(g){let{x:v,y:B}=g||{};if(!g||!t.isValid(v)||!t.isValid(B))throw new Error("invalid affine point");if(g instanceof l)throw new Error("projective point not allowed");let D=E=>t.eql(E,t.ZERO);return D(v)&&D(B)?l.ZERO:new l(v,B,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){let v=t.invertBatch(g.map(B=>B.pz));return g.map((B,D)=>B.toAffine(v[D])).map(l.fromAffine)}static fromHex(g){let v=l.fromAffine(i(Be("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 B=t.sqr(v),D=o(g);if(!t.eql(B,D))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y: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:B,pz:D}=this,{px:E,py:O,pz:I}=g,k=t.eql(t.mul(v,I),t.mul(E,D)),M=t.eql(t.mul(B,I),t.mul(O,D));return k&&M}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:v}=e,B=t.mul(v,vp),{px:D,py:E,pz:O}=this,I=t.ZERO,k=t.ZERO,M=t.ZERO,R=t.mul(D,D),re=t.mul(E,E),z=t.mul(O,O),G=t.mul(D,E);return G=t.add(G,G),M=t.mul(D,O),M=t.add(M,M),I=t.mul(g,M),k=t.mul(B,z),k=t.add(I,k),I=t.sub(re,k),k=t.add(re,k),k=t.mul(I,k),I=t.mul(G,I),M=t.mul(B,M),z=t.mul(g,z),G=t.sub(R,z),G=t.mul(g,G),G=t.add(G,M),M=t.add(R,R),R=t.add(M,R),R=t.add(R,z),R=t.mul(R,G),k=t.add(k,R),z=t.mul(E,O),z=t.add(z,z),R=t.mul(z,G),I=t.sub(I,R),M=t.mul(z,re),M=t.add(M,M),M=t.add(M,M),new l(I,k,M)}add(g){a(g);let{px:v,py:B,pz:D}=this,{px:E,py:O,pz:I}=g,k=t.ZERO,M=t.ZERO,R=t.ZERO,re=e.a,z=t.mul(e.b,vp),G=t.mul(v,E),fe=t.mul(B,O),le=t.mul(D,I),nt=t.add(v,B),U=t.add(E,O);nt=t.mul(nt,U),U=t.add(G,fe),nt=t.sub(nt,U),U=t.add(v,D);let $=t.add(E,I);return U=t.mul(U,$),$=t.add(G,le),U=t.sub(U,$),$=t.add(B,D),k=t.add(O,I),$=t.mul($,k),k=t.add(fe,le),$=t.sub($,k),R=t.mul(re,U),k=t.mul(z,le),R=t.add(k,R),k=t.sub(fe,R),R=t.add(fe,R),M=t.mul(k,R),fe=t.add(G,G),fe=t.add(fe,G),le=t.mul(re,le),U=t.mul(z,U),fe=t.add(fe,le),le=t.sub(G,le),le=t.mul(re,le),U=t.add(U,le),G=t.mul(fe,U),M=t.add(M,G),G=t.mul($,U),k=t.mul(nt,k),k=t.sub(k,G),G=t.mul(nt,fe),R=t.mul($,R),R=t.add(R,G),new l(k,M,R)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return w.wNAFCached(this,d,g,v=>{let B=t.invertBatch(v.map(D=>D.pz));return v.map((D,E)=>D.toAffine(B[E])).map(l.fromAffine)})}multiplyUnsafe(g){let v=l.ZERO;if(g===en)return v;if(c(g),g===Zt)return this;let{endo:B}=e;if(!B)return w.unsafeLadder(this,g);let{k1neg:D,k1:E,k2neg:O,k2:I}=B.splitScalar(g),k=v,M=v,R=this;for(;E>en||I>en;)E&Zt&&(k=k.add(R)),I&Zt&&(M=M.add(R)),R=R.double(),E>>=Zt,I>>=Zt;return D&&(k=k.negate()),O&&(M=M.negate()),M=new l(t.mul(M.px,B.beta),M.py,M.pz),k.add(M)}multiply(g){c(g);let v=g,B,D,{endo:E}=e;if(E){let{k1neg:O,k1:I,k2neg:k,k2:M}=E.splitScalar(v),{p:R,f:re}=this.wNAF(I),{p:z,f:G}=this.wNAF(M);R=w.constTimeNegate(O,R),z=w.constTimeNegate(k,z),z=new l(t.mul(z.px,E.beta),z.py,z.pz),B=R.add(z),D=re.add(G)}else{let{p:O,f:I}=this.wNAF(v);B=O,D=I}return l.normalizeZ([B,D])[0]}multiplyAndAddUnsafe(g,v,B){let D=l.BASE,E=(I,k)=>k===en||k===Zt||!I.equals(D)?I.multiplyUnsafe(k):I.multiply(k),O=E(this,v).add(E(g,B));return O.is0()?void 0:O}toAffine(g){let{px:v,py:B,pz:D}=this,E=this.is0();g==null&&(g=E?t.ONE:t.inv(D));let O=t.mul(v,g),I=t.mul(B,g),k=t.mul(D,g);if(E)return{x:t.ZERO,y:t.ZERO};if(!t.eql(k,t.ONE))throw new Error("invZ was invalid");return{x:O,y:I}}isTorsionFree(){let{h:g,isTorsionFree:v}=e;if(g===Zt)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===Zt?this:v?v(l,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return this.assertValidity(),n(l,this,g)}toHex(g=!0){return Yr(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 Wx(r){let e=fs(r);return Xt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Ep(r){let e=Wx(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(U){return en<U&&U<t.ORDER}function c(U){return we(U,n)}function u(U){return Fc(U,n)}let{ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:y}=Gx({...e,toBytes(U,$,ee){let _=$.toAffine(),T=t.toBytes(_.x),C=Qr;return ee?C(Uint8Array.from([$.hasEvenY()?2:3]),T):C(Uint8Array.from([4]),T,t.toBytes(_.y))},fromBytes(U){let $=U.length,ee=U[0],_=U.subarray(1);if($===i&&(ee===2||ee===3)){let T=Xr(_);if(!s(T))throw new Error("Point is not on curve");let C=l(T),V=t.sqrt(C),Y=(V&Zt)===Zt;return(ee&1)===1!==Y&&(V=t.neg(V)),{x:T,y:V}}else if($===o&&ee===4){let T=t.fromBytes(_.subarray(0,t.BYTES)),C=t.fromBytes(_.subarray(t.BYTES,2*t.BYTES));return{x:T,y:C}}else throw new Error(`Point of length ${$} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),w=U=>Yr(Et(U,e.nByteLength));function p(U){let $=n>>Zt;return U>$}function g(U){return p(U)?c(-U):U}let v=(U,$,ee)=>Xr(U.slice($,ee));class B{constructor($,ee,_){this.r=$,this.s=ee,this.recovery=_,this.assertValidity()}static fromCompact($){let ee=e.nByteLength;return $=Be("compactSignature",$,ee*2),new B(v($,0,ee),v($,ee,2*ee))}static fromDER($){let{r:ee,s:_}=yi.toSig(Be("DER",$));return new B(ee,_)}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($){return new B(this.r,this.s,$)}recoverPublicKey($){let{r:ee,s:_,recovery:T}=this,C=M(Be("msgHash",$));if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");let V=T===2||T===3?ee+e.n:ee;if(V>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let Y=T&1?"03":"02",ne=d.fromHex(Y+w(V)),Z=u(V),Q=c(-C*Z),X=c(_*Z),ie=d.BASE.multiplyAndAddUnsafe(ne,Q,X);if(!ie)throw new Error("point at infinify");return ie.assertValidity(),ie}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new B(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return hi(this.toDERHex())}toDERHex(){return yi.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hi(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}let D={isValidPrivateKey(U){try{return a(U),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let U=Cd(e.n);return bp(e.randomBytes(U),e.n)},precompute(U=8,$=d.BASE){return $._setWindowSize(U),$.multiply(BigInt(3)),$}};function E(U,$=!0){return d.fromPrivateKey(U).toRawBytes($)}function O(U){let $=ur(U),ee=typeof U=="string",_=($||ee)&&U.length;return $?_===i||_===o:ee?_===2*i||_===2*o:U instanceof d}function I(U,$,ee=!0){if(O(U))throw new Error("first arg must be private key");if(!O($))throw new Error("second arg must be public key");return d.fromHex($).multiply(a(U)).toRawBytes(ee)}let k=e.bits2int||function(U){let $=Xr(U),ee=U.length*8-e.nBitLength;return ee>0?$>>BigInt(ee):$},M=e.bits2int_modN||function(U){return c(k(U))},R=us(e.nBitLength);function re(U){if(typeof U!="bigint")throw new Error("bigint expected");if(!(en<=U&&U<R))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Et(U,e.nByteLength)}function z(U,$,ee=G){if(["recovered","canonical"].some(Te=>Te in ee))throw new Error("sign() legacy options not supported");let{hash:_,randomBytes:T}=e,{lowS:C,prehash:V,extraEntropy:Y}=ee;C==null&&(C=!0),U=Be("msgHash",U),V&&(U=Be("prehashed msgHash",_(U)));let ne=M(U),Z=a($),Q=[re(Z),re(ne)];if(Y!=null){let Te=Y===!0?T(t.BYTES):Y;Q.push(Be("extraEntropy",Te))}let X=Qr(...Q),ie=ne;function _e(Te){let Le=k(Te);if(!y(Le))return;let Ve=u(Le),$e=d.BASE.multiply(Le).toAffine(),Xe=c($e.x);if(Xe===en)return;let ze=c(Ve*c(ie+Xe*Z));if(ze===en)return;let Cr=($e.x===Xe?0:2)|Number($e.y&Zt),ln=ze;return C&&p(ze)&&(ln=g(ze),Cr^=1),new B(Xe,ln,Cr)}return{seed:X,k2sig:_e}}let G={lowS:e.lowS,prehash:!1},fe={lowS:e.lowS,prehash:!1};function le(U,$,ee=G){let{seed:_,k2sig:T}=z(U,$,ee),C=e;return Dd(C.hash.outputLen,C.nByteLength,C.hmac)(_,T)}d.BASE._setWindowSize(8);function nt(U,$,ee,_=fe){let T=U;if($=Be("msgHash",$),ee=Be("publicKey",ee),"strict"in _)throw new Error("options.strict was renamed to lowS");let{lowS:C,prehash:V}=_,Y,ne;try{if(typeof T=="string"||ur(T))try{Y=B.fromDER(T)}catch($e){if(!($e instanceof yi.Err))throw $e;Y=B.fromCompact(T)}else if(typeof T=="object"&&typeof T.r=="bigint"&&typeof T.s=="bigint"){let{r:$e,s:Xe}=T;Y=new B($e,Xe)}else throw new Error("PARSE");ne=d.fromHex(ee)}catch($e){if($e.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&Y.hasHighS())return!1;V&&($=e.hash($));let{r:Z,s:Q}=Y,X=M($),ie=u(Q),_e=c(X*ie),Te=c(Z*ie),Le=d.BASE.multiplyAndAddUnsafe(ne,_e,Te)?.toAffine();return Le?c(Le.x)===Z:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:I,sign:le,verify:nt,ProjectivePoint:d,Signature:B,utils:D}}var Vc=class extends eo{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,fp(e);let n=ds(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 Qi(this),this.iHash.update(e),this}digestInto(e){Qi(this),Ud(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()}},Nd=(r,e,t)=>new Vc(r,e).update(t).digest();Nd.create=(r,e)=>new Vc(r,e);function Yx(r){return{hash:r,hmac:(e,...t)=>Nd(r,e,Nc(...t)),randomBytes:ls}}function qc(r,e){let t=n=>Ep({...r,...Yx(n)});return Object.freeze({...t(e),create:t})}var Tp=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ap=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Xx=BigInt(1),Ld=BigInt(2),Sp=(r,e)=>(r+e/Ld)/e;function Zx(r){let e=Tp,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=Ie(a,t,e)*a%e,y=Ie(l,t,e)*a%e,w=Ie(y,Ld,e)*d%e,p=Ie(w,i,e)*w%e,g=Ie(p,o,e)*p%e,v=Ie(g,c,e)*g%e,B=Ie(v,u,e)*v%e,D=Ie(B,c,e)*g%e,E=Ie(D,t,e)*a%e,O=Ie(E,s,e)*p%e,I=Ie(O,n,e)*d%e,k=Ie(I,Ld,e);if(!$d.eql($d.sqr(k),r))throw new Error("Cannot find square root");return k}var $d=ro(Tp,void 0,void 0,{sqrt:Zx}),At=qc({a:BigInt(0),b:BigInt(7),Fp:$d,n:Ap,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Ap,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Xx*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=Sp(o*r,e),u=Sp(-n*r,e),d=we(r-c*t-u*i,e),a=we(-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}}}},$c),BA=BigInt(0);var IA=At.ProjectivePoint;function Qx(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Fd(r,...e){if(!Qx(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 Hd(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 Bp(r,e){Fd(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var no=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var zc=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),fr=(r,e)=>r<<32-e|r>>>e;var KA=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function eb(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Vd(r){return typeof r=="string"&&(r=eb(r)),Fd(r),r}var jc=class{clone(){return this._cloneInto()}},PA={}.toString;function Ip(r){let e=n=>r().update(Vd(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Dp(r=32){if(no&&typeof no.getRandomValues=="function")return no.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function tb(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 Up=(r,e,t)=>r&e^~r&t,_p=(r,e,t)=>r&e^r&t^e&t,Jc=class extends jc{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=zc(this.buffer)}update(e){Hd(this);let{view:t,buffer:n,blockLen:i}=this;e=Vd(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=zc(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){Hd(this),Bp(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;tb(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=zc(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 rb=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]),Bn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),In=new Uint32Array(64),qd=class extends Jc{constructor(){super(64,32,8,!1),this.A=Bn[0]|0,this.B=Bn[1]|0,this.C=Bn[2]|0,this.D=Bn[3]|0,this.E=Bn[4]|0,this.F=Bn[5]|0,this.G=Bn[6]|0,this.H=Bn[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)In[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let y=In[l-15],w=In[l-2],p=fr(y,7)^fr(y,18)^y>>>3,g=fr(w,17)^fr(w,19)^w>>>10;In[l]=g+In[l-7]+p+In[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=fr(c,6)^fr(c,11)^fr(c,25),w=a+y+Up(c,u,d)+rb[l]+In[l]|0,g=(fr(n,2)^fr(n,13)^fr(n,22))+_p(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(){In.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Dn=Ip(()=>new qd);function kp(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 nb=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())})},io=class{static digest(e){return nb(this,arguments,void 0,function*({data:t}){return Dn(t)})}};var ib=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())})},jd="urn:jwk:";function te(r){return ib(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}`);Au(n);let i=kp(n),o=P.string(i).toUint8Array(),s=yield io.digest({data:o});return P.uint8Array(s).toBase64Url()})}function Tr(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 oo(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 Kt(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 so(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 Op(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 it=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())})},ob=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},Me=class r{static adjustSignatureToLowS(e){return it(this,arguments,void 0,function*({signature:t}){let n=At.Signature.fromCompact(t);return n.hasHighS()?n.normalizeS().toCompactRawBytes():t})}static bytesToPrivateKey(e){return it(this,arguments,void 0,function*({privateKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",d:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return it(this,arguments,void 0,function*({publicKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static compressPublicKey(e){return it(this,arguments,void 0,function*({publicKeyBytes:t}){return At.ProjectivePoint.fromHex(t).toRawBytes(!0)})}static computePublicKey(e){return it(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:P.uint8Array(i.x).toBase64Url(),y:P.uint8Array(i.y).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertDerToCompactSignature(e){return it(this,arguments,void 0,function*({derSignature:t}){return At.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return it(this,arguments,void 0,function*({publicKeyBytes:t}){return At.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return it(this,void 0,void 0,function*(){let e=At.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return it(this,arguments,void 0,function*({key:t}){var n;if(!(Tr(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=t,o=ob(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return it(this,arguments,void 0,function*({privateKey:t}){if(!Tr(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return it(this,arguments,void 0,function*({publicKey:t}){if(!(oo(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=P.base64Url(t.x).toUint8Array(),o=P.base64Url(t.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return it(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 At.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return it(this,arguments,void 0,function*({data:t,key:n}){let i=yield r.privateKeyToBytes({privateKey:n}),o=Dn(t);return At.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return it(this,arguments,void 0,function*({privateKeyBytes:t}){return At.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return it(this,arguments,void 0,function*({publicKeyBytes:t}){try{At.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return it(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t}),s=Dn(i);return At.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return it(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=At.getPublicKey(t));let n=At.ProjectivePoint.fromHex(t),i=Et(n.x,32),o=Et(n.y,32);return{x:i,y:o}})}};var Kp=ro(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),sb=Kp.create(BigInt("-3")),cb=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),ab=qc({a:sb,b:cb,Fp:Kp,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},$c),Pt=ab;var ot=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())})},ub=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},Ne=class r{static adjustSignatureToLowS(e){return ot(this,arguments,void 0,function*({signature:t}){let n=Pt.Signature.fromCompact(t);return n.hasHighS()?n.normalizeS().toCompactRawBytes():t})}static bytesToPrivateKey(e){return ot(this,arguments,void 0,function*({privateKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"P-256",d:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return ot(this,arguments,void 0,function*({publicKeyBytes:t}){let n=yield r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"P-256",x:P.uint8Array(n.x).toBase64Url(),y:P.uint8Array(n.y).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static compressPublicKey(e){return ot(this,arguments,void 0,function*({publicKeyBytes:t}){return Pt.ProjectivePoint.fromHex(t).toRawBytes(!0)})}static computePublicKey(e){return ot(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:P.uint8Array(i.x).toBase64Url(),y:P.uint8Array(i.y).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertDerToCompactSignature(e){return ot(this,arguments,void 0,function*({derSignature:t}){return Pt.Signature.fromDER(t).toCompactRawBytes()})}static decompressPublicKey(e){return ot(this,arguments,void 0,function*({publicKeyBytes:t}){return Pt.ProjectivePoint.fromHex(t).toRawBytes(!1)})}static generateKey(){return ot(this,void 0,void 0,function*(){let e=Pt.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return ot(this,arguments,void 0,function*({key:t}){var n;if(!(Tr(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=t,o=ub(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return ot(this,arguments,void 0,function*({privateKey:t}){if(!Tr(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return ot(this,arguments,void 0,function*({publicKey:t}){if(!(oo(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=P.base64Url(t.x).toUint8Array(),o=P.base64Url(t.y).toUint8Array();return new Uint8Array([...n,...i,...o])})}static sharedSecret(e){return ot(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 Pt.getSharedSecret(i,o,!0).slice(1)})}static sign(e){return ot(this,arguments,void 0,function*({data:t,key:n}){let i=yield r.privateKeyToBytes({privateKey:n}),o=Dn(t);return Pt.sign(o,i).toCompactRawBytes()})}static validatePrivateKey(e){return ot(this,arguments,void 0,function*({privateKeyBytes:t}){return Pt.utils.isValidPrivateKey(t)})}static validatePublicKey(e){return ot(this,arguments,void 0,function*({publicKeyBytes:t}){try{Pt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return ot(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t}),s=Dn(i);return Pt.verify(n,s,o,{lowS:!1})})}static getCurvePoint(e){return ot(this,arguments,void 0,function*({keyBytes:t}){t.byteLength===32&&(t=Pt.getPublicKey(t));let n=Pt.ProjectivePoint.fromHex(t),i=Et(n.x,32),o=Et(n.y,32);return{x:i,y:o}})}};var tn=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())})},hs=class extends mt{bytesToPrivateKey(e){return tn(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Me.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Ne.bytesToPrivateKey({privateKeyBytes:n});return i.alg="ES256",i}default:throw new Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}bytesToPublicKey(e){return tn(this,arguments,void 0,function*({algorithm:t,publicKeyBytes:n}){switch(t){case"ES256K":case"secp256k1":{let i=yield Me.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256K",i}case"ES256":case"secp256r1":{let i=yield Ne.bytesToPublicKey({publicKeyBytes:n});return i.alg="ES256",i}default:throw new Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return tn(this,arguments,void 0,function*({key:t}){if(!Tr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Me.computePublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Ne.computePublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}generateKey(e){return tn(this,arguments,void 0,function*({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let n=yield Me.generateKey();return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield Ne.generateKey();return n.alg="ES256",n}}})}getPublicKey(e){return tn(this,arguments,void 0,function*({key:t}){if(!Tr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let n=yield Me.getPublicKey({key:t});return n.alg="ES256K",n}case"P-256":{let n=yield Ne.getPublicKey({key:t});return n.alg="ES256",n}default:throw new Error(`Unsupported curve: ${t.crv}`)}})}sign(e){return tn(this,arguments,void 0,function*({key:t,data:n}){if(!Tr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return yield Me.sign({key:t,data:n});case"P-256":return yield Ne.sign({key:t,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}verify(e){return tn(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!oo(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return yield Me.verify({key:t,signature:n,data:i});case"P-256":return yield Ne.verify({key:t,signature:n,data:i});default:throw new Error(`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return tn(this,arguments,void 0,function*({privateKey:t}){switch(t.crv){case"secp256k1":return yield Me.privateKeyToBytes({privateKey:t});case"P-256":return yield Ne.privateKeyToBytes({privateKey:t});default:throw new Fe(He.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}publicKeyToBytes(e){return tn(this,arguments,void 0,function*({publicKey:t}){switch(t.crv){case"secp256k1":return yield Me.publicKeyToBytes({publicKey:t});case"P-256":return yield Ne.publicKeyToBytes({publicKey:t});default:throw new Fe(He.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var Gc=BigInt(4294967295),zd=BigInt(32);function Pp(r,e=!1){return e?{h:Number(r&Gc),l:Number(r>>zd&Gc)}:{h:Number(r>>zd&Gc)|0,l:Number(r&Gc)|0}}function db(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}=Pp(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var lb=(r,e)=>BigInt(r>>>0)<<zd|BigInt(e>>>0),fb=(r,e,t)=>r>>>t,hb=(r,e,t)=>r<<32-t|e>>>t,pb=(r,e,t)=>r>>>t|e<<32-t,yb=(r,e,t)=>r<<32-t|e>>>t,mb=(r,e,t)=>r<<64-t|e>>>t-32,gb=(r,e,t)=>r>>>t-32|e<<64-t,wb=(r,e)=>e,xb=(r,e)=>r,bb=(r,e,t)=>r<<t|e>>>32-t,vb=(r,e,t)=>e<<t|r>>>32-t,Eb=(r,e,t)=>e<<t-32|r>>>64-t,Ab=(r,e,t)=>r<<t-32|e>>>64-t;function Sb(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Tb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Bb=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Ib=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Db=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,Ub=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),_b=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var kb={fromBig:Pp,split:db,toBig:lb,shrSH:fb,shrSL:hb,rotrSH:pb,rotrSL:yb,rotrBH:mb,rotrBL:gb,rotr32H:wb,rotr32L:xb,rotlSH:bb,rotlSL:vb,rotlBH:Eb,rotlBL:Ab,add:Sb,add3L:Tb,add3H:Bb,add4L:Ib,add4H:Db,add5H:_b,add5L:Ub},se=kb;var[Ob,Kb]=se.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))),Un=new Uint32Array(80),_n=new Uint32Array(80),Jd=class extends to{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)Un[E]=e.getUint32(t),_n[E]=e.getUint32(t+=4);for(let E=16;E<80;E++){let O=Un[E-15]|0,I=_n[E-15]|0,k=se.rotrSH(O,I,1)^se.rotrSH(O,I,8)^se.shrSH(O,I,7),M=se.rotrSL(O,I,1)^se.rotrSL(O,I,8)^se.shrSL(O,I,7),R=Un[E-2]|0,re=_n[E-2]|0,z=se.rotrSH(R,re,19)^se.rotrBH(R,re,61)^se.shrSH(R,re,6),G=se.rotrSL(R,re,19)^se.rotrBL(R,re,61)^se.shrSL(R,re,6),fe=se.add4L(M,G,_n[E-7],_n[E-16]),le=se.add4H(fe,k,z,Un[E-7],Un[E-16]);Un[E]=le|0,_n[E]=fe|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:B,Hl:D}=this;for(let E=0;E<80;E++){let O=se.rotrSH(l,y,14)^se.rotrSH(l,y,18)^se.rotrBH(l,y,41),I=se.rotrSL(l,y,14)^se.rotrSL(l,y,18)^se.rotrBL(l,y,41),k=l&w^~l&g,M=y&p^~y&v,R=se.add5L(D,I,M,Kb[E],_n[E]),re=se.add5H(R,B,O,k,Ob[E],Un[E]),z=R|0,G=se.rotrSH(n,i,28)^se.rotrBH(n,i,34)^se.rotrBH(n,i,39),fe=se.rotrSL(n,i,28)^se.rotrBL(n,i,34)^se.rotrBL(n,i,39),le=n&o^n&c^o&c,nt=i&s^i&u^s&u;B=g|0,D=v|0,g=w|0,v=p|0,w=l|0,p=y|0,{h:l,l:y}=se.add(d|0,a|0,re|0,z|0),d=c|0,a=u|0,c=o|0,u=s|0,o=n|0,s=i|0;let U=se.add3L(z,fe,nt);n=se.add3H(U,re,G,le),i=U|0}({h:n,l:i}=se.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=se.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:u}=se.add(this.Ch|0,this.Cl|0,c|0,u|0),{h:d,l:a}=se.add(this.Dh|0,this.Dl|0,d|0,a|0),{h:l,l:y}=se.add(this.Eh|0,this.El|0,l|0,y|0),{h:w,l:p}=se.add(this.Fh|0,this.Fl|0,w|0,p|0),{h:g,l:v}=se.add(this.Gh|0,this.Gl|0,g|0,v|0),{h:B,l:D}=se.add(this.Hh|0,this.Hl|0,B|0,D|0),this.set(n,i,o,s,c,u,d,a,l,y,w,p,g,v,B,D)}roundClean(){Un.fill(0),_n.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 Gd=Lc(()=>new Jd);var hr=BigInt(0),Rt=BigInt(1),Wc=BigInt(2),Pb=BigInt(8),Rb={zip215:!0};function Cb(r){let e=fs(r);return Xt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Yc(r){let e=Cb(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:u}=e,d=Wc<<BigInt(c*8)-Rt,a=t.create,l=e.uvRatio||((_,T)=>{try{return{isValid:!0,value:t.sqrt(_*t.inv(T))}}catch{return{isValid:!1,value:hr}}}),y=e.adjustScalarBytes||(_=>_),w=e.domain||((_,T,C)=>{if(T.length||C)throw new Error("Contexts/pre-hash are not supported");return _}),p=_=>typeof _=="bigint"&&hr<_,g=(_,T)=>p(_)&&p(T)&&_<T,v=_=>_===hr||g(_,d);function B(_,T){if(g(_,T))return _;throw new Error(`Expected valid scalar < ${T}, got ${typeof _} ${_}`)}function D(_){return _===hr?_:B(_,n)}let E=new Map;function O(_){if(!(_ instanceof I))throw new Error("ExtendedPoint expected")}class I{constructor(T,C,V,Y){if(this.ex=T,this.ey=C,this.ez=V,this.et=Y,!v(T))throw new Error("x required");if(!v(C))throw new Error("y required");if(!v(V))throw new Error("z required");if(!v(Y))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(T){if(T instanceof I)throw new Error("extended point not allowed");let{x:C,y:V}=T||{};if(!v(C)||!v(V))throw new Error("invalid affine point");return new I(C,V,Rt,a(C*V))}static normalizeZ(T){let C=t.invertBatch(T.map(V=>V.ez));return T.map((V,Y)=>V.toAffine(C[Y])).map(I.fromAffine)}_setWindowSize(T){this._WINDOW_SIZE=T,E.delete(this)}assertValidity(){let{a:T,d:C}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:V,ey:Y,ez:ne,et:Z}=this,Q=a(V*V),X=a(Y*Y),ie=a(ne*ne),_e=a(ie*ie),Te=a(Q*T),Le=a(ie*a(Te+X)),Ve=a(_e+a(C*a(Q*X)));if(Le!==Ve)throw new Error("bad point: equation left != right (1)");let $e=a(V*Y),Xe=a(ne*Z);if($e!==Xe)throw new Error("bad point: equation left != right (2)")}equals(T){O(T);let{ex:C,ey:V,ez:Y}=this,{ex:ne,ey:Z,ez:Q}=T,X=a(C*Q),ie=a(ne*Y),_e=a(V*Q),Te=a(Z*Y);return X===ie&&_e===Te}is0(){return this.equals(I.ZERO)}negate(){return new I(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:T}=e,{ex:C,ey:V,ez:Y}=this,ne=a(C*C),Z=a(V*V),Q=a(Wc*a(Y*Y)),X=a(T*ne),ie=C+V,_e=a(a(ie*ie)-ne-Z),Te=X+Z,Le=Te-Q,Ve=X-Z,$e=a(_e*Le),Xe=a(Te*Ve),ze=a(_e*Ve),Cr=a(Le*Te);return new I($e,Xe,Cr,ze)}add(T){O(T);let{a:C,d:V}=e,{ex:Y,ey:ne,ez:Z,et:Q}=this,{ex:X,ey:ie,ez:_e,et:Te}=T;if(C===BigInt(-1)){let Do=a((ne-Y)*(ie+X)),Js=a((ne+Y)*(ie-X)),Uo=a(Js-Do);if(Uo===hr)return this.double();let Gs=a(Z*Wc*Te),Ws=a(Q*Wc*_e),qt=Ws+Gs,hn=Js+Do,_o=Ws-Gs,Ys=a(qt*Uo),Hn=a(hn*_o),Xs=a(qt*_o),ru=a(Uo*hn);return new I(Ys,Hn,ru,Xs)}let Le=a(Y*X),Ve=a(ne*ie),$e=a(Q*V*Te),Xe=a(Z*_e),ze=a((Y+ne)*(X+ie)-Le-Ve),Cr=Xe-$e,ln=Xe+$e,Io=a(Ve-C*Le),zs=a(ze*Cr),tu=a(ln*Io),fn=a(ze*Io),Vt=a(Cr*ln);return new I(zs,tu,Vt,fn)}subtract(T){return this.add(T.negate())}wNAF(T){return R.wNAFCached(this,E,T,I.normalizeZ)}multiply(T){let{p:C,f:V}=this.wNAF(B(T,n));return I.normalizeZ([C,V])[0]}multiplyUnsafe(T){let C=D(T);return C===hr?M:this.equals(M)||C===Rt?this:this.equals(k)?this.wNAF(C).p:R.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(T){let{ex:C,ey:V,ez:Y}=this,ne=this.is0();T==null&&(T=ne?Pb:t.inv(Y));let Z=a(C*T),Q=a(V*T),X=a(Y*T);if(ne)return{x:hr,y:Rt};if(X!==Rt)throw new Error("invZ was invalid");return{x:Z,y:Q}}clearCofactor(){let{h:T}=e;return T===Rt?this:this.multiplyUnsafe(T)}static fromHex(T,C=!1){let{d:V,a:Y}=e,ne=t.BYTES;T=Be("pointHex",T,ne);let Z=T.slice(),Q=T[ne-1];Z[ne-1]=Q&-129;let X=dr(Z);X===hr||(C?B(X,d):B(X,t.ORDER));let ie=a(X*X),_e=a(ie-Rt),Te=a(V*ie-Y),{isValid:Le,value:Ve}=l(_e,Te);if(!Le)throw new Error("Point.fromHex: invalid y coordinate");let $e=(Ve&Rt)===Rt,Xe=(Q&128)!==0;if(!C&&Ve===hr&&Xe)throw new Error("Point.fromHex: x=0 and x_0=1");return Xe!==$e&&(Ve=a(-Ve)),I.fromAffine({x:Ve,y:X})}static fromPrivateKey(T){return G(T).point}toRawBytes(){let{x:T,y:C}=this.toAffine(),V=Zr(C,t.BYTES);return V[V.length-1]|=T&Rt?128:0,V}toHex(){return Yr(this.toRawBytes())}}I.BASE=new I(e.Gx,e.Gy,Rt,a(e.Gx*e.Gy)),I.ZERO=new I(hr,Rt,Rt,hr);let{BASE:k,ZERO:M}=I,R=Hc(I,c*8);function re(_){return we(_,n)}function z(_){return re(dr(_))}function G(_){let T=c;_=Be("private key",_,T);let C=Be("hashed private key",o(_),2*T),V=y(C.slice(0,T)),Y=C.slice(T,2*T),ne=z(V),Z=k.multiply(ne),Q=Z.toRawBytes();return{head:V,prefix:Y,scalar:ne,point:Z,pointBytes:Q}}function fe(_){return G(_).pointBytes}function le(_=new Uint8Array,...T){let C=Qr(...T);return z(o(w(C,Be("context",_),!!i)))}function nt(_,T,C={}){_=Be("message",_),i&&(_=i(_));let{prefix:V,scalar:Y,pointBytes:ne}=G(T),Z=le(C.context,V,_),Q=k.multiply(Z).toRawBytes(),X=le(C.context,Q,ne,_),ie=re(Z+X*Y);D(ie);let _e=Qr(Q,Zr(ie,t.BYTES));return Be("result",_e,c*2)}let U=Rb;function $(_,T,C,V=U){let{context:Y,zip215:ne}=V,Z=t.BYTES;_=Be("signature",_,2*Z),T=Be("message",T),i&&(T=i(T));let Q=dr(_.slice(Z,2*Z)),X,ie,_e;try{X=I.fromHex(C,ne),ie=I.fromHex(_.slice(0,Z),ne),_e=k.multiplyUnsafe(Q)}catch{return!1}if(!ne&&X.isSmallOrder())return!1;let Te=le(Y,ie.toRawBytes(),X.toRawBytes(),T);return ie.add(X.multiplyUnsafe(Te)).subtract(_e).clearCofactor().equals(I.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:fe,sign:nt,verify:$,ExtendedPoint:I,utils:{getExtendedPublicKey:G,randomPrivateKey:()=>s(t.BYTES),precompute(_=8,T=I.BASE){return T._setWindowSize(_),T.multiply(BigInt(3)),T}}}}var ps=BigInt(0),Wd=BigInt(1);function Mb(r){return Xt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Rp(r){let e=Mb(r),{P:t}=e,n=E=>we(E,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(E=>E),u=e.powPminus2||(E=>Kd(E,t-BigInt(2),t));function d(E,O,I){let k=n(E*(O-I));return O=n(O-k),I=n(I+k),[O,I]}function a(E){if(typeof E=="bigint"&&ps<=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,O){let I=a(E),k=a(O),M=I,R=Wd,re=ps,z=I,G=Wd,fe=ps,le;for(let U=BigInt(i-1);U>=ps;U--){let $=k>>U&Wd;fe^=$,le=d(fe,R,z),R=le[0],z=le[1],le=d(fe,re,G),re=le[0],G=le[1],fe=$;let ee=R+re,_=n(ee*ee),T=R-re,C=n(T*T),V=_-C,Y=z+G,ne=z-G,Z=n(ne*ee),Q=n(Y*T),X=Z+Q,ie=Z-Q;z=n(X*X),G=n(M*n(ie*ie)),R=n(_*C),re=n(V*(_+n(l*V)))}le=d(fe,R,z),R=le[0],z=le[1],le=d(fe,re,G),re=le[0],G=le[1];let nt=u(re);return n(R*nt)}function w(E){return Zr(n(E),o)}function p(E){let O=Be("u coordinate",E,o);return s===32&&(O[31]&=127),dr(O)}function g(E){let O=Be("scalar",E),I=O.length;if(I!==o&&I!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${I}`);return dr(c(O))}function v(E,O){let I=p(O),k=g(E),M=y(I,k);if(M===ps)throw new Error("Invalid private or public key received");return w(M)}let B=w(e.Gu);function D(E){return v(E,B)}return{scalarMult:v,scalarMultBase:D,getSharedSecret:(E,O)=>v(E,O),getPublicKey:E=>D(E),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:B}}var ys=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Cp=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),P6=BigInt(0),Nb=BigInt(1),Yd=BigInt(2),Lb=BigInt(5),Mp=BigInt(10),$b=BigInt(20),Fb=BigInt(40),Np=BigInt(80);function Lp(r){let e=ys,n=r*r%e*r%e,i=Ie(n,Yd,e)*n%e,o=Ie(i,Nb,e)*r%e,s=Ie(o,Lb,e)*o%e,c=Ie(s,Mp,e)*s%e,u=Ie(c,$b,e)*c%e,d=Ie(u,Fb,e)*u%e,a=Ie(d,Np,e)*d%e,l=Ie(a,Np,e)*d%e,y=Ie(l,Mp,e)*s%e;return{pow_p_5_8:Ie(y,Yd,e)*r%e,b2:n}}function $p(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Hb(r,e){let t=ys,n=we(e*e*e,t),i=we(n*n*e,t),o=Lp(r*i).pow_p_5_8,s=we(r*n*o,t),c=we(e*s*s,t),u=s,d=we(s*Cp,t),a=c===r,l=c===we(-r,t),y=c===we(-r*Cp,t);return a&&(s=u),(l||y)&&(s=d),gp(s,t)&&(s=we(-s,t)),{isValid:a||l,value:s}}var Qt=ro(ys,void 0,!0),ms={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Qt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Gd,randomBytes:ls,adjustScalarBytes:$p,uvRatio:Hb},kn=Yc(ms);function Fp(r,e,t){if(e.length>255)throw new Error("Context is too big");return Nc(_d("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var R6=Yc({...ms,domain:Fp}),C6=Yc({...ms,domain:Fp,prehash:Gd}),mi=Rp({P:ys,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=ys,{pow_p_5_8:t,b2:n}=Lp(r);return we(Ie(t,BigInt(3),e)*n,e)},adjustScalarBytes:$p,randomBytes:ls});function Hp(r){let{y:e}=kn.ExtendedPoint.fromHex(r),t=BigInt(1);return Qt.toBytes(Qt.create((t+e)*Qt.inv(t-e)))}function Vp(r){let e=ms.hash(r.subarray(0,32));return ms.adjustScalarBytes(e).subarray(0,32)}var Vb=(Qt.ORDER+BigInt(3))/BigInt(8),M6=Qt.pow(Yd,Vb),N6=Qt.sqrt(Qt.neg(Qt.ONE)),L6=(Qt.ORDER-BigInt(5))/BigInt(8),$6=BigInt(486662);var F6=wp(Qt,Qt.neg(BigInt(486664)));var H6=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),V6=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),q6=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),j6=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var z6=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var er=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())})},qb=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 er(this,arguments,void 0,function*({privateKeyBytes:t}){let n=kn.getPublicKey(t),i={crv:"Ed25519",d:P.uint8Array(t).toBase64Url(),kty:"OKP",x:P.uint8Array(n).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return er(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"Ed25519",x:P.uint8Array(t).toBase64Url()};return n.kid=yield te({jwk:n}),n})}static computePublicKey(e){return er(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=kn.getPublicKey(n),o={kty:"OKP",crv:"Ed25519",x:P.uint8Array(i).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static convertPrivateKeyToX25519(e){return er(this,arguments,void 0,function*({privateKey:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=Vp(n),o=mi.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:P.uint8Array(i).toBase64Url(),x:P.uint8Array(o).toBase64Url()};return s.kid=yield te({jwk:s}),s})}static convertPublicKeyToX25519(e){return er(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=Hp(n),s={kty:"OKP",crv:"X25519",x:P.uint8Array(o).toBase64Url()};return s.kid=yield te({jwk:s}),s})}static generateKey(){return er(this,void 0,void 0,function*(){let e=kn.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return er(this,arguments,void 0,function*({key:t}){var n;if(!(Kt(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=t,o=qb(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return er(this,arguments,void 0,function*({privateKey:t}){if(!Kt(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return er(this,arguments,void 0,function*({publicKey:t}){if(!so(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return P.base64Url(t.x).toUint8Array()})}static sign(e){return er(this,arguments,void 0,function*({key:t,data:n}){let i=yield r.privateKeyToBytes({privateKey:t});return kn.sign(n,i)})}static validatePublicKey(e){return er(this,arguments,void 0,function*({publicKeyBytes:t}){try{kn.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0})}static verify(e){return er(this,arguments,void 0,function*({key:t,signature:n,data:i}){let o=yield r.publicKeyToBytes({publicKey:t});return kn.verify(n,i,o)})}};var rn=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())})},Xc=class extends mt{bytesToPrivateKey(e){return rn(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 Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}bytesToPublicKey(e){return rn(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 Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return rn(this,arguments,void 0,function*({key:t}){if(!Kt(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 rn(this,arguments,void 0,function*({algorithm:t}){switch(t){case"Ed25519":{let n=yield De.generateKey();return n.alg="EdDSA",n}}})}getPublicKey(e){return rn(this,arguments,void 0,function*({key:t}){if(!Kt(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 rn(this,arguments,void 0,function*({key:t,data:n}){if(!Kt(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 rn(this,arguments,void 0,function*({key:t,signature:n,data:i}){if(!so(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 rn(this,arguments,void 0,function*({privateKey:t}){switch(t.crv){case"Ed25519":return yield De.privateKeyToBytes({privateKey:t});default:throw new Fe(He.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}publicKeyToBytes(e){return rn(this,arguments,void 0,function*({publicKey:t}){switch(t.crv){case"Ed25519":return yield De.publicKeyToBytes({publicKey:t});default:throw new Fe(He.AlgorithmNotSupported,`Curve not supported: ${t.crv}`)}})}};var jb=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())})},Zc=class extends mt{digest(e){return jb(this,arguments,void 0,function*({algorithm:t,data:n}){switch(t){case"SHA-256":return yield io.digest({data:n})}})}};var On=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())})},zb=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},Br=class r{static bytesToPrivateKey(e){return On(this,arguments,void 0,function*({privateKeyBytes:t}){let n=mi.getPublicKey(t),i={kty:"OKP",crv:"X25519",d:P.uint8Array(t).toBase64Url(),x:P.uint8Array(n).toBase64Url()};return i.kid=yield te({jwk:i}),i})}static bytesToPublicKey(e){return On(this,arguments,void 0,function*({publicKeyBytes:t}){let n={kty:"OKP",crv:"X25519",x:P.uint8Array(t).toBase64Url()};return n.kid=yield te({jwk:n}),n})}static computePublicKey(e){return On(this,arguments,void 0,function*({key:t}){let n=yield r.privateKeyToBytes({privateKey:t}),i=mi.getPublicKey(n),o={kty:"OKP",crv:"X25519",x:P.uint8Array(i).toBase64Url()};return o.kid=yield te({jwk:o}),o})}static generateKey(){return On(this,void 0,void 0,function*(){let e=mi.utils.randomPrivateKey(),t=yield r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=yield te({jwk:t}),t})}static getPublicKey(e){return On(this,arguments,void 0,function*({key:t}){var n;if(!(Kt(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=t,o=zb(t,["d"]);return(n=o.kid)!==null&&n!==void 0||(o.kid=yield te({jwk:o})),o})}static privateKeyToBytes(e){return On(this,arguments,void 0,function*({privateKey:t}){if(!Kt(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return P.base64Url(t.d).toUint8Array()})}static publicKeyToBytes(e){return On(this,arguments,void 0,function*({publicKey:t}){if(!so(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return P.base64Url(t.x).toUint8Array()})}static sharedSecret(e){return On(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 mi.getSharedSecret(i,o)})}};var gs=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())})},Qc=class extends mt{bytesToPrivateKey(e){return gs(this,arguments,void 0,function*({algorithm:t,privateKeyBytes:n}){switch(t){case"X25519":return Br.bytesToPrivateKey({privateKeyBytes:n});default:throw new Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}computePublicKey(e){return gs(this,arguments,void 0,function*({key:t}){if(!Kt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return Br.computePublicKey({key:t});default:throw new Fe(He.AlgorithmNotSupported,`Unsupported curve: ${t.crv}`)}})}generateKey(e){return gs(this,arguments,void 0,function*({algorithm:t}){switch(t){case"X25519":return Br.generateKey();default:throw new Fe(He.AlgorithmNotSupported,`Algorithm not supported: ${t}`)}})}getPublicKey(e){return gs(this,arguments,void 0,function*({key:t}){if(!Kt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return Br.getPublicKey({key:t});default:throw new Fe(He.AlgorithmNotSupported,`Unsupported curve: ${t.crv}`)}})}privateKeyToBytes(e){return gs(this,arguments,void 0,function*({privateKey:t}){return Br.privateKeyToBytes({privateKey:t})})}};var nn=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())})},Xd={Ed25519:{implementation:Xc,names:["Ed25519"]},secp256k1:{implementation:hs,names:["ES256K","secp256k1"]},secp256r1:{implementation:hs,names:["ES256","secp256r1"]},"SHA-256":{implementation:Zc,names:["SHA-256"]},X25519:{implementation:Qc,names:["X25519"]}},lt=class{constructor(e){var t;this._algorithmInstances=new Map,this._keyStore=(t=e?.keyStore)!==null&&t!==void 0?t:new Kc}digest(e){return nn(this,arguments,void 0,function*({algorithm:t,data:n}){return yield this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:n})})}exportKey(e){return nn(this,arguments,void 0,function*({keyUri:t}){return yield this.getPrivateKey({keyUri:t})})}generateKey(e){return nn(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=`${jd}${i.kid}`;return yield this._keyStore.set(o,i),o})}getKeyUri(e){return nn(this,arguments,void 0,function*({key:t}){let n=yield te({jwk:t});return`${jd}${n}`})}getPublicKey(e){return nn(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 nn(this,arguments,void 0,function*({key:t}){var n;if(!Op(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 nn(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 nn(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=Xd[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 Xd){let o=Xd[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 nn(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 ea=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 Dp(e)}static randomUuid(){return no.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 Jb=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function qp(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(r instanceof Uint8Array)return"Uint8Array";if(r.constructor===Object)return"Object";let t=Gb(r);return t||"Object"}function Gb(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Jb.includes(e))return e}var A=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,t){return e===t||e.major===t.major&&e.name===t.name}};A.uint=new A(0,"uint",!0);A.negint=new A(1,"negint",!0);A.bytes=new A(2,"bytes",!0);A.string=new A(3,"string",!0);A.array=new A(4,"array",!1);A.map=new A(5,"map",!1);A.tag=new A(6,"tag",!1);A.float=new A(7,"float",!0);A.false=new A(7,"false",!0);A.true=new A(7,"true",!0);A.null=new A(7,"null",!0);A.undefined=new A(7,"undefined",!0);A.break=new A(7,"break",!0);var L=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ws=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Wb=new TextEncoder;function ta(r){return ws&&globalThis.Buffer.isBuffer(r)}function ra(r){return r instanceof Uint8Array?ta(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Yb=24,Xb=200,Zd=ws?r=>r.length>=Yb?globalThis.Buffer.from(r):jp(r):r=>r.length>=Xb?Wb.encode(r):jp(r),Ir=r=>Uint8Array.from(r),zp=ws?(r,e,t)=>ta(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Jp=ws?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),ra(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},Gp=ws?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function na(r,e){if(ta(r)&&ta(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function jp(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}var Zb=256,xs=class{constructor(e=Zb){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Gp(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=zp(n,0,this.cursor)}else t=Jp(this.chunks,this.cursor);return e&&this.reset(),t}},ia=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let t=this.dest.subarray(0,this.cursor);return e&&this.reset(),t}};var me="CBOR decode error:",Qd="CBOR encode error:",bs=[];bs[23]=1;bs[24]=2;bs[25]=3;bs[26]=5;bs[27]=9;function on(r,e,t){if(r.length-e<t)throw new Error(`${me} not enough data for type`)}var Qe=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Ct(r,e,t){on(r,e,1);let n=r[e];if(t.strict===!0&&n<Qe[0])throw new Error(`${me} integer encoded in more bytes than necessary (strict decode)`);return n}function Mt(r,e,t){on(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<Qe[1])throw new Error(`${me} integer encoded in more bytes than necessary (strict decode)`);return n}function Nt(r,e,t){on(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<Qe[2])throw new Error(`${me} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(r,e,t){on(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<Qe[3])throw new Error(`${me} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${me} integers outside of the safe integer range are not supported`)}function Wp(r,e,t,n){return new L(A.uint,Ct(r,e+1,n),2)}function Yp(r,e,t,n){return new L(A.uint,Mt(r,e+1,n),3)}function Xp(r,e,t,n){return new L(A.uint,Nt(r,e+1,n),5)}function Zp(r,e,t,n){return new L(A.uint,Lt(r,e+1,n),9)}function tr(r,e){return et(r,0,e.value)}function et(r,e,t){if(t<Qe[0]){let n=Number(t);r.push([e|n])}else if(t<Qe[1]){let n=Number(t);r.push([e|24,n])}else if(t<Qe[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<Qe[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<Qe[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${me} encountered BigInt larger than allowable range`)}}tr.encodedSize=function(e){return et.encodedSize(e.value)};et.encodedSize=function(e){return e<Qe[0]?1:e<Qe[1]?2:e<Qe[2]?3:e<Qe[3]?5:9};tr.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Qp(r,e,t,n){return new L(A.negint,-1-Ct(r,e+1,n),2)}function ey(r,e,t,n){return new L(A.negint,-1-Mt(r,e+1,n),3)}function ty(r,e,t,n){return new L(A.negint,-1-Nt(r,e+1,n),5)}var el=BigInt(-1),ry=BigInt(1);function ny(r,e,t,n){let i=Lt(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new L(A.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${me} integers outside of the safe integer range are not supported`);return new L(A.negint,el-BigInt(i),9)}function oa(r,e){let t=e.value,n=typeof t=="bigint"?t*el-ry:t*-1-1;et(r,e.type.majorEncoded,n)}oa.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*el-ry:t*-1-1;return n<Qe[0]?1:n<Qe[1]?2:n<Qe[2]?3:n<Qe[3]?5:9};oa.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function vs(r,e,t,n){on(r,e,t+n);let i=r.slice(e+t,e+t+n);return new L(A.bytes,i,t+n)}function iy(r,e,t,n){return vs(r,e,1,t)}function oy(r,e,t,n){return vs(r,e,2,Ct(r,e+1,n))}function sy(r,e,t,n){return vs(r,e,3,Mt(r,e+1,n))}function cy(r,e,t,n){return vs(r,e,5,Nt(r,e+1,n))}function ay(r,e,t,n){let i=Lt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${me} 64-bit integer bytes lengths not supported`);return vs(r,e,9,i)}function sa(r){return r.encodedBytes===void 0&&(r.encodedBytes=A.equals(r.type,A.string)?Zd(r.value):r.value),r.encodedBytes}function co(r,e){let t=sa(e);et(r,e.type.majorEncoded,t.length),r.push(t)}co.encodedSize=function(e){let t=sa(e);return et.encodedSize(t.length)+t.length};co.compareTokens=function(e,t){return e1(sa(e),sa(t))};function e1(r,e){return r.length<e.length?-1:r.length>e.length?1:na(r,e)}var uy=new TextDecoder,r1=32;function n1(r,e,t){if(t-e<r1){let i="";for(let o=e;o<t;o++){let s=r[o];if(s&128)return uy.decode(r.subarray(e,t));i+=String.fromCharCode(s)}return i}return uy.decode(r.subarray(e,t))}function Es(r,e,t,n,i){let o=t+n;on(r,e,o);let s=new L(A.string,n1(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=r.slice(e+t,e+o)),s}function dy(r,e,t,n){return Es(r,e,1,t,n)}function ly(r,e,t,n){return Es(r,e,2,Ct(r,e+1,n),n)}function fy(r,e,t,n){return Es(r,e,3,Mt(r,e+1,n),n)}function hy(r,e,t,n){return Es(r,e,5,Nt(r,e+1,n),n)}function py(r,e,t,n){let i=Lt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${me} 64-bit integer string lengths not supported`);return Es(r,e,9,i,n)}var yy=co;function ao(r,e,t,n){return new L(A.array,n,t)}function my(r,e,t,n){return ao(r,e,1,t)}function gy(r,e,t,n){return ao(r,e,2,Ct(r,e+1,n))}function wy(r,e,t,n){return ao(r,e,3,Mt(r,e+1,n))}function xy(r,e,t,n){return ao(r,e,5,Nt(r,e+1,n))}function by(r,e,t,n){let i=Lt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${me} 64-bit integer array lengths not supported`);return ao(r,e,9,i)}function vy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${me} indefinite length items not allowed`);return ao(r,e,1,1/0)}function ca(r,e){et(r,A.array.majorEncoded,e.value)}ca.compareTokens=tr.compareTokens;ca.encodedSize=function(e){return et.encodedSize(e.value)};function uo(r,e,t,n){return new L(A.map,n,t)}function Ey(r,e,t,n){return uo(r,e,1,t)}function Ay(r,e,t,n){return uo(r,e,2,Ct(r,e+1,n))}function Sy(r,e,t,n){return uo(r,e,3,Mt(r,e+1,n))}function Ty(r,e,t,n){return uo(r,e,5,Nt(r,e+1,n))}function By(r,e,t,n){let i=Lt(r,e+1,n);if(typeof i=="bigint")throw new Error(`${me} 64-bit integer map lengths not supported`);return uo(r,e,9,i)}function Iy(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${me} indefinite length items not allowed`);return uo(r,e,1,1/0)}function aa(r,e){et(r,A.map.majorEncoded,e.value)}aa.compareTokens=tr.compareTokens;aa.encodedSize=function(e){return et.encodedSize(e.value)};function Dy(r,e,t,n){return new L(A.tag,t,1)}function Uy(r,e,t,n){return new L(A.tag,Ct(r,e+1,n),2)}function _y(r,e,t,n){return new L(A.tag,Mt(r,e+1,n),3)}function ky(r,e,t,n){return new L(A.tag,Nt(r,e+1,n),5)}function Oy(r,e,t,n){return new L(A.tag,Lt(r,e+1,n),9)}function ua(r,e){et(r,A.tag.majorEncoded,e.value)}ua.compareTokens=tr.compareTokens;ua.encodedSize=function(e){return et.encodedSize(e.value)};var tl=20,rl=21,nl=22,il=23;function Ky(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${me} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(A.null,null,1):new L(A.undefined,void 0,1)}function Py(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${me} indefinite length items not allowed`);return new L(A.break,void 0,1)}function ol(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${me} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${me} Infinity values are not supported`)}return new L(A.float,r,e)}function Ry(r,e,t,n){return ol(sl(r,e+1),3,n)}function Cy(r,e,t,n){return ol(cl(r,e+1),5,n)}function My(r,e,t,n){return ol(Fy(r,e+1),9,n)}function da(r,e,t){let n=e.value;if(n===!1)r.push([A.float.majorEncoded|tl]);else if(n===!0)r.push([A.float.majorEncoded|rl]);else if(n===null)r.push([A.float.majorEncoded|nl]);else if(n===void 0)r.push([A.float.majorEncoded|il]);else{let i,o=!1;(!t||t.float64!==!0)&&(Ly(n),i=sl(pr,1),n===i||Number.isNaN(n)?(pr[0]=249,r.push(pr.slice(0,3)),o=!0):($y(n),i=cl(pr,1),n===i&&(pr[0]=250,r.push(pr.slice(0,5)),o=!0))),o||(a1(n),i=Fy(pr,1),pr[0]=251,r.push(pr.slice(0,9)))}}da.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Ly(n);let i=sl(pr,1);if(n===i||Number.isNaN(n))return 3;if($y(n),i=cl(pr,1),n===i)return 5}return 9};var Ny=new ArrayBuffer(9),rr=new DataView(Ny,1),pr=new Uint8Array(Ny,0);function Ly(r){if(r===1/0)rr.setUint16(0,31744,!1);else if(r===-1/0)rr.setUint16(0,64512,!1);else if(Number.isNaN(r))rr.setUint16(0,32256,!1);else{rr.setFloat32(0,r);let e=rr.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)rr.setUint16(0,31744,!1);else if(t===0)rr.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?rr.setUint16(0,0):i<-14?rr.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):rr.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function sl(r,e){if(r.length-e<2)throw new Error(`${me} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function $y(r){rr.setFloat32(0,r,!1)}function cl(r,e){if(r.length-e<4)throw new Error(`${me} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function a1(r){rr.setFloat64(0,r,!1)}function Fy(r,e){if(r.length-e<8)throw new Error(`${me} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}da.compareTokens=tr.compareTokens;function ge(r,e,t){throw new Error(`${me} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function la(r){return()=>{throw new Error(`${me} ${r}`)}}var K=[];for(let r=0;r<=23;r++)K[r]=ge;K[24]=Wp;K[25]=Yp;K[26]=Xp;K[27]=Zp;K[28]=ge;K[29]=ge;K[30]=ge;K[31]=ge;for(let r=32;r<=55;r++)K[r]=ge;K[56]=Qp;K[57]=ey;K[58]=ty;K[59]=ny;K[60]=ge;K[61]=ge;K[62]=ge;K[63]=ge;for(let r=64;r<=87;r++)K[r]=iy;K[88]=oy;K[89]=sy;K[90]=cy;K[91]=ay;K[92]=ge;K[93]=ge;K[94]=ge;K[95]=la("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)K[r]=dy;K[120]=ly;K[121]=fy;K[122]=hy;K[123]=py;K[124]=ge;K[125]=ge;K[126]=ge;K[127]=la("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)K[r]=my;K[152]=gy;K[153]=wy;K[154]=xy;K[155]=by;K[156]=ge;K[157]=ge;K[158]=ge;K[159]=vy;for(let r=160;r<=183;r++)K[r]=Ey;K[184]=Ay;K[185]=Sy;K[186]=Ty;K[187]=By;K[188]=ge;K[189]=ge;K[190]=ge;K[191]=Iy;for(let r=192;r<=215;r++)K[r]=Dy;K[216]=Uy;K[217]=_y;K[218]=ky;K[219]=Oy;K[220]=ge;K[221]=ge;K[222]=ge;K[223]=ge;for(let r=224;r<=243;r++)K[r]=la("simple values are not supported");K[244]=ge;K[245]=ge;K[246]=ge;K[247]=Ky;K[248]=la("simple values are not supported");K[249]=Ry;K[250]=Cy;K[251]=My;K[252]=ge;K[253]=ge;K[254]=ge;K[255]=Py;var Dr=[];for(let r=0;r<24;r++)Dr[r]=new L(A.uint,r,1);for(let r=-1;r>=-24;r--)Dr[31-r]=new L(A.negint,r,1);Dr[64]=new L(A.bytes,new Uint8Array(0),1);Dr[96]=new L(A.string,"",1);Dr[128]=new L(A.array,0,1);Dr[160]=new L(A.map,0,1);Dr[244]=new L(A.false,!1,1);Dr[245]=new L(A.true,!0,1);Dr[246]=new L(A.null,null,1);function Hy(r){switch(r.type){case A.false:return Ir([244]);case A.true:return Ir([245]);case A.null:return Ir([246]);case A.bytes:return r.value.length?void 0:Ir([64]);case A.string:return r.value===""?Ir([96]):void 0;case A.array:return r.value===0?Ir([128]):void 0;case A.map:return r.value===0?Ir([160]):void 0;case A.uint:return r.value<24?Ir([Number(r.value)]):void 0;case A.negint:if(r.value>=-24)return Ir([31-Number(r.value)])}}var qy=Object.freeze({float64:!0,mapSorter:p1,quickEncodeToken:Hy});function d1(){let r=[];return r[A.uint.major]=tr,r[A.negint.major]=oa,r[A.bytes.major]=co,r[A.string.major]=yy,r[A.array.major]=ca,r[A.map.major]=aa,r[A.tag.major]=ua,r[A.float.major]=da,r}var l1=d1(),f1=new xs,ha=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${Qd} object contains circular references`);return new r(t,e)}},Kn={null:new L(A.null,null),undefined:new L(A.undefined,void 0),true:new L(A.true,!0),false:new L(A.false,!1),emptyArray:new L(A.array,0),emptyMap:new L(A.map,0)},Pn={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new L(A.float,r):r>=0?new L(A.uint,r):new L(A.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new L(A.uint,r):new L(A.negint,r)},Uint8Array(r,e,t,n){return new L(A.bytes,r)},string(r,e,t,n){return new L(A.string,r)},boolean(r,e,t,n){return r?Kn.true:Kn.false},null(r,e,t,n){return Kn.null},undefined(r,e,t,n){return Kn.undefined},ArrayBuffer(r,e,t,n){return new L(A.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new L(A.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[Kn.emptyArray,new L(A.break)]:Kn.emptyArray;n=ha.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=fa(s,t,n);return t.addBreakTokens?[new L(A.array,r.length),i,new L(A.break)]:[new L(A.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length,c;if(s){c=new Array(s),n=ha.createCheck(n,r);let u=!i&&t.ignoreUndefinedProperties,d=0;for(let a of o){let l=i?r.get(a):r[a];u&&l===void 0||(c[d++]=[fa(a,t,n),fa(l,t,n)])}d<s&&(c.length=d)}return c?.length?(h1(c,t),t.addBreakTokens?[new L(A.map,c.length),c,new L(A.break)]:[new L(A.map,c.length),c]):t.addBreakTokens===!0?[Kn.emptyMap,new L(A.break)]:Kn.emptyMap}};Pn.Map=Pn.Object;Pn.Buffer=Pn.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Pn[`${r}Array`]=Pn.DataView;function fa(r,e={},t){let n=qp(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||Pn[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=Pn[n];if(!o)throw new Error(`${Qd} unsupported type: ${n}`);return o(r,n,e,t)}function h1(r,e){e.mapSorter&&r.sort(e.mapSorter)}function p1(r,e){if(r[0]instanceof L&&e[0]instanceof L){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=Vy(t.value)),n._keyBytes||(n._keyBytes=Vy(n.value)),na(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Vy(r){return y1(r,l1,qy)}function jy(r,e,t,n){if(Array.isArray(e))for(let i of e)jy(r,i,t,n);else t[e.type.major](r,e,n)}var hT=A.uint.majorEncoded,pT=A.negint.majorEncoded,yT=A.bytes.majorEncoded,mT=A.string.majorEncoded,gT=A.array.majorEncoded,wT=A.float.majorEncoded|tl,xT=A.float.majorEncoded|rl,bT=A.float.majorEncoded|nl,vT=A.float.majorEncoded|il,ET=BigInt(-1),AT=BigInt(1);function y1(r,e,t,n){let i=n instanceof Uint8Array,o=i?new ia(n):f1,s=fa(r,t);if(!Array.isArray(s)&&t.quickEncodeToken){let c=t.quickEncodeToken(s);if(c)return i?(o.push(c),o.toBytes()):c;let u=e[s.type.major];if(u.encodedSize){let d=u.encodedSize(s,t);if(i||(o=new xs(d)),u(o,s,t),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():ra(o.chunks[0])}}return o.reset(),jy(o,s,e,t),o.toBytes(!0)}var UT=Symbol.for("DONE"),_T=Symbol.for("BREAK");var zy;(function(r){r[r.OKP=1]="OKP",r[r.EC2=2]="EC2",r[r.Symmetric=4]="Symmetric"})(zy||(zy={}));var ft;(function(r){r[r.P256=1]="P256",r[r.P384=2]="P384",r[r.P521=3]="P521",r[r.X25519=4]="X25519",r[r.X448=5]="X448",r[r.Ed25519=6]="Ed25519",r[r.Ed448=7]="Ed448",r[r.Secp256k1=8]="Secp256k1"})(ft||(ft={}));var $t;(function(r){r[r.EdDSA=-8]="EdDSA",r[r.ES256=-7]="ES256",r[r.ES384=-35]="ES384",r[r.ES512=-36]="ES512",r[r.ES256K=-47]="ES256K"})($t||($t={}));var Jy;(function(r){r[r.Kty=1]="Kty",r[r.Kid=2]="Kid",r[r.Alg=3]="Alg",r[r.KeyOps=4]="KeyOps",r[r.BaseIv=5]="BaseIv"})(Jy||(Jy={}));var Gy;(function(r){r[r.Crv=-1]="Crv",r[r.X=-2]="X",r[r.Y=-3]="Y",r[r.D=-4]="D"})(Gy||(Gy={}));var qT={"P-256":ft.P256,"P-384":ft.P384,"P-521":ft.P521,X25519:ft.X25519,Ed25519:ft.Ed25519,Ed448:ft.Ed448,secp256k1:ft.Secp256k1},jT={[ft.P256]:"P-256",[ft.P384]:"P-384",[ft.P521]:"P-521",[ft.X25519]:"X25519",[ft.Ed25519]:"Ed25519",[ft.Ed448]:"Ed448",[ft.Secp256k1]:"secp256k1"},zT={EdDSA:$t.EdDSA,ES256:$t.ES256,ES384:$t.ES384,ES512:$t.ES512,ES256K:$t.ES256K},JT={[$t.EdDSA]:"EdDSA",[$t.ES256]:"ES256",[$t.ES384]:"ES384",[$t.ES512]:"ES512",[$t.ES256K]:"ES256K"};var Wy;(function(r){r[r.Alg=1]="Alg",r[r.Crit=2]="Crit",r[r.ContentType=3]="ContentType",r[r.Kid=4]="Kid"})(Wy||(Wy={}));var Yy;(function(r){r[r.Iss=1]="Iss",r[r.Sub=2]="Sub",r[r.Aud=3]="Aud",r[r.Exp=4]="Exp",r[r.Nbf=5]="Nbf",r[r.Iat=6]="Iat",r[r.Cti=7]="Cti",r[r.Nonce=10]="Nonce",r[r.Ueid=256]="Ueid",r[r.Sueids=257]="Sueids",r[r.Oemid=258]="Oemid",r[r.Hwmodel=259]="Hwmodel",r[r.Hwversion=260]="Hwversion",r[r.Secboot=262]="Secboot",r[r.Dbgstat=263]="Dbgstat",r[r.Location=264]="Location",r[r.Profile=265]="Profile",r[r.Submods=266]="Submods",r[r.Measres=272]="Measres",r[r.Intuse=268]="Intuse"})(Yy||(Yy={}));var Xy;(function(r){r[r.Enabled=0]="Enabled",r[r.Disabled=1]="Disabled",r[r.DisabledSinceBoot=2]="DisabledSinceBoot",r[r.DisabledPermanently=3]="DisabledPermanently",r[r.DisabledFullyAndPermanently=4]="DisabledFullyAndPermanently"})(Xy||(Xy={}));var Zy;(function(r){r[r.Unrestricted=1]="Unrestricted",r[r.Restricted=2]="Restricted",r[r.SecureRestricted=3]="SecureRestricted",r[r.Hardware=4]="Hardware"})(Zy||(Zy={}));var t0={};cu(t0,{extractDidFragment:()=>gt,getServices:()=>x1,getVerificationMethodByKey:()=>b1,getVerificationMethodTypes:()=>al,getVerificationMethods:()=>As,getVerificationRelationshipsById:()=>ul,isDidService:()=>Qy,isDidVerificationMethod:()=>ya,isDwnDidService:()=>v1,isPortableDid:()=>e0,keyBytesToMultibaseId:()=>dl,multibaseIdToKeyBytes:()=>ll});function gt(r){if(typeof r=="string"&&r.length!==0)return r.split("#").pop()}function x1({didDocument:r,id:e,type:t}){return r?.service?.filter(n=>!(e&&n.id!==e||t&&n.type!==t))??[]}async function b1({didDocument:r,publicKeyJwk:e,publicKeyMultibase:t}){let n=As({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 As({didDocument:r}){if(!r)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...r.verificationMethod?.filter(ya)??[]),Object.keys(Pi).forEach(t=>{e.push(...r[t]?.filter(ya)??[])}),e}function al({didDocument:r}){let t=As({didDocument:r}).map(n=>n.type);return[...new Set(t)]}function ul({didDocument:r,methodId:e}){let t=[];return Object.keys(Pi).forEach(n=>{if(Array.isArray(r[n])){let i=r[n],o=gt(e);i.some(c=>{let u=gt(c)===o,d=ya(c)&&gt(c.id)===o;return u||d})&&t.push(n)}}),t}function Qy(r){return!r||typeof r!="object"||r===null?!1:"id"in r&&"type"in r&&"serviceEndpoint"in r}function v1(r){if(!Qy(r)||r.type!=="DecentralizedWebNode")return!1;let e=t=>typeof t=="string"||Array.isArray(t)&&t.every(n=>typeof n=="string");return!("enc"in r&&r.enc!==void 0&&!e(r.enc)||"sig"in r&&r.sig!==void 0&&!e(r.sig))}function ya(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 e0(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 dl({keyBytes:r,multicodecCode:e,multicodecName:t}){let n=at.addPrefix({code:e,data:r,name:t}),i=P.uint8Array(n).toBase58Btc();return P.base58Btc(i).toMultibase()}function ll({multibaseKeyId:r}){try{let e=P.multibase(r).toBase58Btc(),t=P.base58Btc(e).toUint8Array(),{code:n,data:i,name:o}=at.removePrefix({prefixedData:t});return{keyBytes:i,multicodecCode:n,multicodecName:o}}catch{throw new H("invalidDid",`Invalid multibase identifier: ${r}`)}}var St=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=>gt(c.id)===(gt(e?.methodId)??gt(this.document.assertionMethod?.[0])));if(!(t&&t.publicKeyJwk))throw new H("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:ea.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 lt}){let n=As({didDocument:e.document});if(n.length===0)throw new H("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 nr=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 fl=(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))(fl||{}),ma=(i=>(i[i.Ed25519=0]="Ed25519",i[i.secp256k1=1]="secp256k1",i[i.secp256r1=2]="secp256r1",i[i.X25519=3]="X25519",i))(ma||{}),hl=(o=>(o.authentication="auth",o.assertionMethod="asm",o.capabilityDelegation="del",o.capabilityInvocation="inv",o.keyAgreement="agm",o))(hl||{});var pl="0123456789abcdef",n0=[],r0=[];for(let r=0;r<256;r++)n0[r]=pl[r>>4&15]+pl[r&15],r<16&&(r<10?r0[48+r]=r:r0[87+r]=r);var yl=r=>{let e=r.length,t="",n=0;for(;n<e;)t+=n0[r[n++]];return t};var i0=(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 o0="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",E1=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(Ss=0;Ss<o0.length;Ss++)E1[o0.charCodeAt(Ss)]=Ss;var Ss;var A1=new TextDecoder,ml=(r,e)=>e?new TextDecoder(e).decode(r):A1.decode(r),S1=new TextEncoder,ir=r=>S1.encode(r);var s0=typeof window<"u"?window:self,c0=s0.crypto||s0.msCrypto||{},W8=c0.subtle||c0.webkitSubtle;function lo(r){let e=r<0?1:0;return r=Math.abs(Number(r||1)),Math.floor(Math.log10(r))+1+e}function ga(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 xe(r,e,t){let n=[],i=null;return xe._encode(n,r),i=i0(n),xe.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,t),e):i}xe.bytes=-1;xe._floatConversionDetected=!1;xe._encode=function(r,e){if(e!=null)switch(ga(e)){case"object":xe.dict(r,e);break;case"map":xe.dictMap(r,e);break;case"array":xe.list(r,e);break;case"set":xe.listSet(r,e);break;case"string":xe.string(r,e);break;case"number":xe.number(r,e);break;case"boolean":xe.number(r,e);break;case"arraybufferview":xe.buffer(r,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":xe.buffer(r,new Uint8Array(e));break}};var wa=new Uint8Array([101]),a0=new Uint8Array([100]),u0=new Uint8Array([108]);xe.buffer=function(r,e){r.push(ir(e.length+":"),e)};xe.string=function(r,e){r.push(ir(ir(e).byteLength+":"+e))};xe.number=function(r,e){if(Number.isInteger(e))return r.push(ir("i"+BigInt(e)+"e"));let t=2147483648,n=e/t<<0,i=e%t<<0,o=n*t+i;r.push(ir("i"+o+"e")),o!==e&&!xe._floatConversionDetected&&(xe._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())};xe.dict=function(r,e){r.push(a0);let t=0,n,i=Object.keys(e).sort(),o=i.length;for(;t<o;t++)n=i[t],e[n]!=null&&(xe.string(r,n),xe._encode(r,e[n]));r.push(wa)};xe.dictMap=function(r,e){r.push(a0);let t=Array.from(e.keys()).sort();for(let n of t)e.get(n)!=null&&(ArrayBuffer.isView(n)?xe._encode(r,n):xe.string(r,String(n)),xe._encode(r,e.get(n)));r.push(wa)};xe.list=function(r,e){let t=0,n=e.length;for(r.push(u0);t<n;t++)e[t]!=null&&xe._encode(r,e[t]);r.push(wa)};xe.listSet=function(r,e){r.push(u0);for(let t of e)t!=null&&xe._encode(r,t);r.push(wa)};var d0=xe;var T1=105,B1=58,I1=100,D1=108,gl=101;function l0(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 W(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),W.position=0,W.encoding=n||null,W.data=ArrayBuffer.isView(r)?new Uint8Array(r.slice(e,t)):ir(r),W.bytes=W.data.length,W.next())}W.bytes=0;W.position=0;W.data=null;W.encoding=null;W.next=function(){switch(W.data[W.position]){case I1:return W.dictionary();case D1:return W.list();case T1:return W.integer();default:return W.buffer()}};W.find=function(r){let e=W.position,t=W.data.length,n=W.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)+"]")};W.dictionary=function(){W.position++;let r={};for(;W.data[W.position]!==gl;){let e=W.buffer(),t=ml(e);t.includes("\uFFFD")&&(t=yl(e)),r[t]=W.next()}return W.position++,r};W.list=function(){W.position++;let r=[];for(;W.data[W.position]!==gl;)r.push(W.next());return W.position++,r};W.integer=function(){let r=W.find(gl),e=l0(W.data,W.position+1,r);return W.position+=r+1-W.position,e};W.buffer=function(){let r=W.find(B1),e=l0(W.data,W.position,r),t=++r+e;return W.position=t,W.encoding?ml(W.data.slice(r,t)):W.data.slice(r,t)};var f0=W;function U1(r){let e=2;for(let t of r)e+=xa(t);return e}function _1(r){let e=2;for(let[t,n]of r){let i=ir(t).byteLength;e+=lo(i)+1+i,e+=xa(n)}return e}function k1(r){let e=2,t=Object.keys(r);for(let n=0;n<t.length;n++){let i=ir(t[n]).byteLength;e+=lo(i)+1+i,e+=xa(r[t[n]])}return e}function O1(r){let e=ir(r).byteLength;return lo(e)+1+e}function K1(r){let e=r.byteLength-r.byteOffset;return lo(e)+1+e}function xa(r){if(r==null)return 0;let t=ga(r);switch(t){case"arraybufferview":return K1(r);case"string":return O1(r);case"array":case"set":return U1(r);case"number":return 1+lo(Math.floor(r))+1;case"bigint":return 1+r.toString().length+1;case"object":return k1(r);case"map":return _1(r);default:throw new TypeError(`Unsupported value of type "${t}"`)}}var wl=xa;var P1=wl,xl={encode:d0,decode:f0,byteLength:wl,encodingLength:P1};var R1=/^(\d{1,3}\.){3,3}\d{1,3}$/;var C1=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;var yr={name:"v4",size:4,isFormat:r=>R1.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]}`}},sn={name:"v6",size:16,isFormat:r=>r.length>0&&C1.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 h0(r){if(yr.isFormat(r))return yr.size;if(sn.isFormat(r))return sn.size;throw Error(`Invalid ip address: ${r}`)}function p0(r){return h0(r)===yr.size?1:2}function y0(r,e,t){t=~~t;let n=h0(r);return typeof e=="function"&&(e=e(t+n)),n===yr.size?yr.encode(r,e,t):sn.encode(r,e,t)}function m0(r,e,t){if(e=~~e,t=t||r.length-e,t===yr.size)return yr.decode(r,e,t);if(t===sn.size)return sn.decode(r,e,t);throw Error(`Invalid buffer size needs to be ${yr.size} for v4 or ${sn.size} for v6.`)}function Ts(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 fo(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 g0(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 w0(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 bl(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 vl(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 x0(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 El(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 Al(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 ho(r,e,t){let n=r.length;t==null&&(t=0),e===void 0&&(e=new Uint8Array(Al(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 ho.bytes=i-t,e}ho.bytes=0;function po(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 po.bytes=t-e,n}po.bytes=0;var Rn=r=>r instanceof Uint8Array;function cn(r){return typeof r=="string"?Al(r):r.byteLength}function ba(r){return r instanceof Uint8Array?r:Array.isArray(r)?new Uint8Array(r):ho(r)}function va(r,e,t){if(typeof e!="string")throw new Error("unknown input type");return ho(e,r,t),ho.bytes}var Bs={},b0=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}`;b0[s]=c,Bs[c]=s,Bs[`${t}${i}`]=s,Bs[`${e}${o}`]=s,Bs[`${t}${o}`]=s}}function v0(r,e,t){let n="";for(let i=e;i<t;){let o=r[i++];n+=b0[o]}return n}function Sl(r){return r.length>>>1}function E0(r,e,t,n){let i=0;for(;t<n;){let o=e.substr(i,2),s=Bs[o];if(s===void 0)return;r[t++]=s,i+=2}return r}var q1=Math.pow(2,24),j1=Math.pow(2,16),z1=Math.pow(2,8),Ur=(r,e)=>r[e]*q1+r[e+1]*j1+r[e+2]*z1+r[e+3],ce=(r,e)=>r[e]<<8|r[e+1],_r=(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),j=(r,e,t)=>(r[t]=e>>8,r[t+1]=e&255,t+2);function Tt(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:J1(r,e,t,n,i)}function J1(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 W1=0,A0=32768,Bl=32768,Y1=~Bl,T0=32768,X1=~T0;function Se({bytes:r=0,encode:e,decode:t,encodingLength:n}){return e.bytes=r,t.bytes=r,{encode:e,decode:t,encodingLength:n||(()=>r)}}var F=Se({encode(r,e,t){e||(e=new Uint8Array(F.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=va(e,o[s],t+1);e[t]=c,t+=c+1}}return e[t++]=0,F.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=ce(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(po(r,e,e+c)),e+=c,o+=s?0:c}}return F.decode.bytes=o,t.length===0?".":t.join(".")},encodingLength(r){return r==="."||r===".."?1:cn(r.replace(/^\.|\.$/gm,""))+2}}),We=Se({encode(r,e,t){e||(e=new Uint8Array(We.encodingLength(r))),t||(t=0);let n=va(e,r,t+1);return e[t]=n,We.encode.bytes=n+1,e},decode(r,e){e||(e=0);let t=r[e],n=po(r,e+1,e+1+t);return We.decode.bytes=t+1,n},encodingLength(r){return cn(r)+1}}),yo=Se({bytes:12,encode(r,e,t){e||(e=new Uint8Array(yo.encodingLength(r))),t||(t=0);let n=(r.flags||0)&32767,i=r.type==="response"?A0:W1;return j(e,r.id||0,t),j(e,n|i,t+2),j(e,r.questions.length,t+4),j(e,r.answers.length,t+6),j(e,r.authorities.length,t+8),j(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=ce(r,e+2);return{id:ce(r,e),type:t&A0?"response":"query",flags:t&32767,flag_qr:(t>>15&1)===1,opcode:w0(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:g0(t&15),questions:new Array(ce(r,e+4)),answers:new Array(ce(r,e+6)),authorities:new Array(ce(r,e+8)),additionals:new Array(ce(r,e+10))}},encodingLength(){return 12}}),Aa=Se({encode(r,e,t){e||(e=new Uint8Array(Aa.encodingLength(r))),t||(t=0);let n=r.length;return j(e,n,t),Tt(r,e,t+2,0,n),Aa.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=ce(r,e),n=r.slice(e+2,e+2+t);return Aa.decode.bytes=t+2,n},encodingLength(r){return r.length+2}}),Sa=Se({encode(r,e,t){return e||(e=new Uint8Array(Sa.encodingLength(r))),t||(t=0),F.encode(r,e,t+2),j(e,F.encode.bytes,t),Sa.encode.bytes=F.encode.bytes+2,e},decode(r,e){e||(e=0);let t=ce(r,e),n=F.decode(r,e+2);return Sa.decode.bytes=t+2,n},encodingLength(r){return F.encodingLength(r)+2}}),Ta=Se({encode(r,e,t){e||(e=new Uint8Array(Ta.encodingLength(r))),t||(t=0);let n=t;return t+=2,F.encode(r.mname,e,t),t+=F.encode.bytes,F.encode(r.rname,e,t),t+=F.encode.bytes,_r(e,r.serial||0,t),t+=4,_r(e,r.refresh||0,t),t+=4,_r(e,r.retry||0,t),t+=4,_r(e,r.expire||0,t),t+=4,_r(e,r.minimum||0,t),t+=4,j(e,t-n-2,n),Ta.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.mname=F.decode(r,e),e+=F.decode.bytes,n.rname=F.decode(r,e),e+=F.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,Ta.decode.bytes=e-t,n},encodingLength(r){return 22+F.encodingLength(r.mname)+F.encodingLength(r.rname)}}),Ba=Se({encode(r,e,t){Array.isArray(r)||(r=[r]);for(let i=0;i<r.length;i++)if(typeof r[i]=="string"&&(r[i]=ba(r[i])),!Rn(r[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(Ba.encodingLength(r))),t||(t=0);let n=t;return t+=2,r.forEach(function(i){e[t++]=i.length,Tt(i,e,t,0,i.length),t+=i.length}),j(e,t-n-2,n),Ba.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=ce(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 Ba.decode.bytes=e-t,i},encodingLength(r){Array.isArray(r)||(r=[r]);let e=2;return r.forEach(function(t){typeof t=="string"?e+=cn(t)+1:e+=t.length+1}),e}}),Ia=Se({encode(r,e,t){e||(e=new Uint8Array(Ia.encodingLength(r))),t||(t=0),typeof r=="string"&&(r=ba(r)),r||(r=new Uint8Array(0));let n=t;t+=2;let i=r.length;return Tt(r,e,t,0,i),t+=i,j(e,t-n-2,n),Ia.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=ce(r,e);e+=2;let i=r.slice(e,e+n);return e+=n,Ia.decode.bytes=e-t,i},encodingLength(r){return r?(Rn(r)?r.length:cn(r))+2:2}}),Da=Se({encode(r,e,t){e||(e=new Uint8Array(Da.encodingLength(r))),t||(t=0);let n=t;return t+=2,We.encode(r.cpu,e,t),t+=We.encode.bytes,We.encode(r.os,e,t),t+=We.encode.bytes,j(e,t-n-2,n),Da.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.cpu=We.decode(r,e),e+=We.decode.bytes,n.os=We.decode(r,e),e+=We.decode.bytes,Da.decode.bytes=e-t,n},encodingLength(r){return We.encodingLength(r.cpu)+We.encodingLength(r.os)+2}}),wo=Se({encode(r,e,t){return e||(e=new Uint8Array(wo.encodingLength(r))),t||(t=0),F.encode(r,e,t+2),j(e,F.encode.bytes,t),wo.encode.bytes=F.encode.bytes+2,e},decode(r,e){e||(e=0);let t=F.decode(r,e+2);return wo.decode.bytes=F.decode.bytes+2,t},encodingLength(r){return F.encodingLength(r)+2}}),Ua=Se({encode(r,e,t){e||(e=new Uint8Array(Ua.encodingLength(r))),t||(t=0),j(e,r.priority||0,t+2),j(e,r.weight||0,t+4),j(e,r.port||0,t+6),F.encode(r.target,e,t+8);let n=F.encode.bytes+6;return j(e,n,t),Ua.encode.bytes=n+2,e},decode(r,e){e||(e=0);let t=ce(r,e),n={};return n.priority=ce(r,e+2),n.weight=ce(r,e+4),n.port=ce(r,e+6),n.target=F.decode(r,e+8),Ua.decode.bytes=t+2,n},encodingLength(r){return 8+F.encodingLength(r.target)}}),Cn=Se({encode(r,e,t){let n=Cn.encodingLength(r);return e||(e=new Uint8Array(Cn.encodingLength(r))),t||(t=0),r.issuerCritical&&(r.flags=Cn.ISSUER_CRITICAL),j(e,n-2,t),t+=2,e[t]=r.flags||0,t+=1,We.encode(r.tag,e,t),t+=We.encode.bytes,va(e,r.value,t),t+=cn(r.value),Cn.encode.bytes=n,e},decode(r,e){e||(e=0);let t=ce(r,e);e+=2;let n=e,i={};return i.flags=r[e],e+=1,i.tag=We.decode(r,e),e+=We.decode.bytes,i.value=po(r,e,n+t),i.issuerCritical=!!(i.flags&Cn.ISSUER_CRITICAL),Cn.decode.bytes=t+2,i},encodingLength(r){return We.encodingLength(r.tag)+We.encodingLength(r.value)+2}});Cn.ISSUER_CRITICAL=128;var _a=Se({encode(r,e,t){e||(e=new Uint8Array(_a.encodingLength(r))),t||(t=0);let n=t;return t+=2,j(e,r.preference||0,t),t+=2,F.encode(r.exchange,e,t),t+=F.encode.bytes,j(e,t-n-2,n),_a.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.preference=ce(r,e),e+=2,n.exchange=F.decode(r,e),e+=F.decode.bytes,_a.decode.bytes=e-t,n},encodingLength(r){return 4+F.encodingLength(r.exchange)}}),B0=Se({encode(r,e,t){return e||(e=new Uint8Array(B0.encodingLength(r))),t||(t=0),j(e,4,t),t+=2,yr.encode(r,e,t),e},decode(r,e){return e||(e=0),e+=2,yr.decode(r,e)},bytes:6}),ka=Se({encode(r,e,t){return e||(e=new Uint8Array(ka.encodingLength(r))),t||(t=0),j(e,16,t),t+=2,sn.encode(r,e,t),ka.encode.bytes=18,e},decode(r,e){e||(e=0),e+=2;let t=sn.decode(r,e);return ka.decode.bytes=18,t},bytes:18}),S0=r=>new Uint8Array(r),an=Se({encode(r,e,t){e||(e=new Uint8Array(an.encodingLength(r))),t||(t=0);let n=t,i=El(r.code);if(j(e,i,t),t+=2,r.data)j(e,r.data.length,t),t+=2,Tt(r.data,e,t),t+=r.data.length;else switch(i){case 8:{let o=r.sourcePrefixLength||0,s=r.family||p0(r.ip,S0),c=y0(r.ip,S0),u=Math.ceil(o/8);j(e,u+4,t),t+=2,j(e,s,t),t+=2,e[t++]=o,e[t++]=r.scopePrefixLength||0,Tt(c,e,t,0,u),t+=u}break;case 11:r.timeout?(j(e,2,t),t+=2,j(e,r.timeout,t),t+=2):(j(e,0,t),t+=2);break;case 12:{let o=r.length||0;j(e,o,t),t+=2,e.fill(0,t,t+o),t+=o}break;case 14:{let o=r.tags.length*2;j(e,o,t),t+=2;for(let s of r.tags)j(e,s,t),t+=2}break;default:throw new Error(`Unknown roption code: ${r.code}`)}return an.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={};t.code=ce(r,e),t.type=x0(t.code),e+=2;let n=ce(r,e);switch(e+=2,t.data=r.slice(e,e+n),t.code){case 8:t.family=ce(r,e),e+=2,t.sourcePrefixLength=r[e++],t.scopePrefixLength=r[e++];{let i=new Uint8Array(t.family===1?4:16);Tt(r,i,0,e,e+n-4),t.ip=m0(i)}break;case 11:n>0&&(t.timeout=ce(r,e),e+=2);break;case 14:t.tags=[];for(let i=0;i<n;i+=2)t.tags.push(ce(r,e)),e+=2}return an.decode.bytes=n+4,t},encodingLength(r){if(r.data)return r.data.length+4;switch(El(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=Se({encode(r,e,t){e||(e=new Uint8Array(Mn.encodingLength(r))),t||(t=0);let n=t,i=go(r,an);return j(e,i,t),t=Os(r,an,e,t+2),Mn.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t=e,n=[],i=ce(r,e);e+=2;let o=0;for(;i>0;)n[o++]=an.decode(r,e),e+=an.decode.bytes,i-=an.decode.bytes;return Mn.decode.bytes=e-t,n},encodingLength(r){return 2+go(r||[],an)}}),kr=Se({encode(r,e,t){e||(e=new Uint8Array(kr.encodingLength(r))),t||(t=0);let n=t,i=r.key;if(!Rn(i))throw new Error("Key must be a Buffer");return t+=2,j(e,r.flags,t),t+=2,e[t]=kr.PROTOCOL_DNSSEC,t+=1,e[t]=r.algorithm,t+=1,Tt(i,e,t,0,i.length),t+=i.length,kr.encode.bytes=t-n,j(e,kr.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ce(r,e);if(e+=2,n.flags=ce(r,e),e+=2,r[e]!==kr.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,kr.decode.bytes=e-t,n},encodingLength(r){return 6+cn(r.key)}});kr.PROTOCOL_DNSSEC=3;kr.ZONE_KEY=128;kr.SECURE_ENTRYPOINT=32768;var Is=Se({encode(r,e,t){e||(e=new Uint8Array(Is.encodingLength(r))),t||(t=0);let n=t,i=r.signature;if(!Rn(i))throw new Error("Signature must be a Buffer");return t+=2,j(e,fo(r.typeCovered),t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.labels,t+=1,_r(e,r.originalTTL,t),t+=4,_r(e,r.expiration,t),t+=4,_r(e,r.inception,t),t+=4,j(e,r.keyTag,t),t+=2,F.encode(r.signersName,e,t),t+=F.encode.bytes,Tt(i,e,t,0,i.length),t+=i.length,Is.encode.bytes=t-n,j(e,Is.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ce(r,e);return e+=2,n.typeCovered=Ts(ce(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=ce(r,e),e+=2,n.signersName=F.decode(r,e),e+=F.decode.bytes,n.signature=r.slice(e,t+i+2),e+=n.signature.length,Is.decode.bytes=e-t,n},encodingLength(r){return 20+F.encodingLength(r.signersName)+cn(r.signature)}}),Ds=Se({encode(r,e,t){e||(e=new Uint8Array(Ds.encodingLength(r))),t||(t=0);let n=t;return t+=2,F.encode(r.mbox||".",e,t),t+=F.encode.bytes,F.encode(r.txt||".",e,t),t+=F.encode.bytes,Ds.encode.bytes=t-n,j(e,Ds.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={};return e+=2,n.mbox=F.decode(r,e)||".",e+=F.decode.bytes,n.txt=F.decode(r,e)||".",e+=F.decode.bytes,Ds.decode.bytes=e-t,n},encodingLength(r){return 2+F.encodingLength(r.mbox||".")+F.encodingLength(r.txt||".")}}),Ft=Se({encode(r,e,t){e||(e=new Uint8Array(Ft.encodingLength(r))),t||(t=0);let n=t,i=[];for(let o=0;o<r.length;o++){let s=fo(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=ba(i[o]);e[t]=o,t+=1,e[t]=s.length,t+=1,Tt(s,e,t,0,s.length),t+=s.length}return Ft.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=Ts(o<<8|c<<3|d);i.push(a)}}e+=s}return Ft.decode.bytes=e-n,i},encodingLength(r){let e=[];for(let n=0;n<r.length;n++){let i=fo(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}}),Us=Se({encode(r,e,t){e||(e=new Uint8Array(Us.encodingLength(r))),t||(t=0);let n=t;return t+=2,F.encode(r.nextDomain,e,t),t+=F.encode.bytes,Ft.encode(r.rrtypes,e,t),t+=Ft.encode.bytes,Us.encode.bytes=t-n,j(e,Us.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ce(r,e);return e+=2,n.nextDomain=F.decode(r,e),e+=F.decode.bytes,n.rrtypes=Ft.decode(r,e,i-(e-t)),e+=Ft.decode.bytes,Us.decode.bytes=e-t,n},encodingLength(r){return 2+F.encodingLength(r.nextDomain)+Ft.encodingLength(r.rrtypes)}}),_s=Se({encode(r,e,t){e||(e=new Uint8Array(_s.encodingLength(r))),t||(t=0);let n=t,i=r.salt;if(!Rn(i))throw new Error("salt must be a Buffer");let o=r.nextDomain;if(!Rn(o))throw new Error("nextDomain must be a Buffer");return t+=2,e[t]=r.algorithm,t+=1,e[t]=r.flags,t+=1,j(e,r.iterations,t),t+=2,e[t]=i.length,t+=1,Tt(i,e,t,0,i.length),t+=i.length,e[t]=o.length,t+=1,Tt(o,e,t,0,o.length),t+=o.length,Ft.encode(r.rrtypes,e,t),t+=Ft.encode.bytes,_s.encode.bytes=t-n,j(e,_s.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ce(r,e);e+=2,n.algorithm=r[e],e+=1,n.flags=r[e],e+=1,n.iterations=ce(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=Ft.decode(r,e,i-(e-t)),e+=Ft.decode.bytes,_s.decode.bytes=e-t,n},encodingLength(r){return 8+r.salt.length+r.nextDomain.length+Ft.encodingLength(r.rrtypes)}}),ks=Se({encode(r,e,t){e||(e=new Uint8Array(ks.encodingLength(r))),t||(t=0);let n=t,i=r.digest;if(!Rn(i))throw new Error("Digest must be a Buffer");return t+=2,j(e,r.keyTag,t),t+=2,e[t]=r.algorithm,t+=1,e[t]=r.digestType,t+=1,Tt(i,e,t,0,i.length),t+=i.length,ks.encode.bytes=t-n,j(e,ks.encode.bytes-2,n),e},decode(r,e){e||(e=0);let t=e,n={},i=ce(r,e);return e+=2,n.keyTag=ce(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,ks.decode.bytes=e-t,n},encodingLength(r){return 6+cn(r.digest)}}),mo=Se({encode(r,e,t){e||(e=new Uint8Array(mo.encodingLength(r))),t||(t=0);let n=t;t+=2,e[t]=r.algorithm,t+=1,e[t]=r.hash,t+=1;let i=Sl(r.fingerprint),o=Il(r.hash);if(i!==o)throw new Error(`Invalid length of fingerprint "${r.fingerprint}" for hashType=${r.hash}: ${i} != ${o}`);return E0(e,r.fingerprint,t,t+=i),mo.encode.bytes=t-n,j(e,mo.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=Il(n.hash);return n.fingerprint=v0(r,e,e+i),e+=i,mo.decode.bytes=e-t,n},encodingLength(r){return 4+Sl(r.fingerprint)}});function Il(r){if(r===1)return 20;if(r===2)return 32;throw new Error(`Invalid hashType=${r}, supported=1,2`)}mo.getFingerprintLengthForHashType=Il;function Tl(r){switch(r.toUpperCase()){case"A":return B0;case"PTR":return wo;case"CNAME":return wo;case"DNAME":return wo;case"TXT":return Ba;case"NULL":return Ia;case"AAAA":return ka;case"SRV":return Ua;case"HINFO":return Da;case"CAA":return Cn;case"NS":return Sa;case"SOA":return Ta;case"MX":return _a;case"OPT":return Mn;case"DNSKEY":return kr;case"RRSIG":return Is;case"RP":return Ds;case"NSEC":return Us;case"NSEC3":return _s;case"SSHFP":return mo;case"DS":return ks}return Aa}var or=Se({encode(r,e,t){e||(e=new Uint8Array(or.encodingLength(r))),t||(t=0);let n=t;if(F.encode(r.name,e,t),t+=F.encode.bytes,j(e,fo(r.type),t),r.type.toUpperCase()==="OPT"){if(r.name!==".")throw new Error("OPT name must be root.");j(e,r.udpPayloadSize||4096,t+2),e[t+4]=r.extendedRcode||0,e[t+5]=r.ednsVersion||0,j(e,r.flags||0,t+6),t+=8,Mn.encode(r.options||[],e,t),t+=Mn.encode.bytes}else{let i=vl(r.class===void 0?"IN":r.class);r.flush&&(i|=Bl),j(e,i,t+2),_r(e,r.ttl||0,t+4),t+=8;let o=Tl(r.type);o.encode(r.data,e,t),t+=o.encode.bytes}return or.encode.bytes=t-n,e},decode(r,e){e||(e=0);let t={},n=e;if(t.name=F.decode(r,e),e+=F.decode.bytes,t.type=Ts(ce(r,e)),t.type==="OPT")t.udpPayloadSize=ce(r,e+2),t.extendedRcode=r[e+4],t.ednsVersion=r[e+5],t.flags=ce(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=ce(r,e+2);t.ttl=Ur(r,e+4),t.class=bl(i&Y1),t.flush=!!(i&Bl);let o=Tl(t.type);t.data=o.decode(r,e+8),e+=8+o.decode.bytes}return or.decode.bytes=e-n,t},encodingLength(r){let e=r.data!==null&&r.data!==void 0?r.data:r.options;return F.encodingLength(r.name)+8+Tl(r.type).encodingLength(e)}}),xo=Se({encode(r,e,t){e||(e=new Uint8Array(xo.encodingLength(r))),t||(t=0);let n=t;return F.encode(r.name,e,t),t+=F.encode.bytes,j(e,fo(r.type),t),t+=2,j(e,vl(r.class===void 0?"IN":r.class),t),t+=2,xo.encode.bytes=t-n,r},decode(r,e){e||(e=0);let t=e,n={};return n.name=F.decode(r,e),e+=F.decode.bytes,n.type=Ts(ce(r,e)),e+=2,n.class=bl(ce(r,e)),e+=2,!!(n.class&T0)&&(n.class&=X1),xo.decode.bytes=e-t,n},encodingLength(r){return F.encodingLength(r.name)+4}});var I0=1024;var st={encode:function(r,e,t){let n=!e;n&&(e=new Uint8Array(Z1(r))),t||(t=0);let i=t;return r.questions||(r.questions=[]),r.answers||(r.answers=[]),r.authorities||(r.authorities=[]),r.additionals||(r.additionals=[]),yo.encode(r,e,t),t+=yo.encode.bytes,t=Os(r.questions,xo,e,t),t=Os(r.answers,or,e,t),t=Os(r.authorities,or,e,t),t=Os(r.additionals,or,e,t),st.encode.bytes=t-i,n&&Ks.bytes!==e.length?e.slice(0,Ks.bytes):e},decode:function(r,e){e||(e=0);let t=e,n=yo.decode(r,e);return e+=yo.decode.bytes,e=Ea(n.questions,xo,r,e),e=Ea(n.answers,or,r,e),e=Ea(n.authorities,or,r,e),e=Ea(n.additionals,or,r,e),st.decode.bytes=e-t,n},encodingLength:function(r){return yo.encodingLength(r)+go(r.questions||[],xo)+go(r.answers||[],or)+go(r.authorities||[],or)+go(r.additionals||[],or)}};st.encode.bytes=0;st.decode.bytes=0;function Oa(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 Ka={encode:function(r,e,t){return e=st.encode(Oa(r,"query"),e,t),Ka.encode.bytes=st.encode.bytes,e},decode:function(r,e){let t=st.decode(r,e);return Ka.decode.bytes=st.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return st.encodingLength(Oa(r,"query"))}};Ka.encode.bytes=0;Ka.decode.bytes=0;var Pa={encode:function(r,e,t){return e=st.encode(Oa(r,"response"),e,t),Pa.encode.bytes=st.encode.bytes,e},decode:function(r,e){let t=st.decode(r,e);return Pa.decode.bytes=st.decode.bytes,t.questions&&(t.question=t.questions[0],delete t.questions),t},encodingLength:function(r){return st.encodingLength(Oa(r,"response"))}};Pa.encode.bytes=0;Pa.decode.bytes=0;var Ks=st.encode,Ra=st.decode,Z1=st.encodingLength;function D0(r){let e=Ks(r),t=new Uint8Array(2+e.byteLength);return j(t,e.byteLength),Tt(e,t,2,0,e.length),D0.bytes=t.byteLength,t}D0.bytes=0;function U0(r){let e=ce(r,0);if(r.byteLength<e+2)return null;let t=Ra(r.slice(2));return U0.bytes=Ra.bytes,t}U0.bytes=0;function go(r,e){let t=0;for(let n=0;n<r.length;n++)t+=e.encodingLength(r[n]);return t}function Os(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 Ea(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 _0(r,e){let t=P.uint8Array(r).toBase32Z();return new URL(t,e).href}async function Dl({gatewayUri:r,publicKeyBytes:e}){let t=P.uint8Array(e).toBase32Z(),n=_0(e,r),i;try{if(i=await fetch(n,{method:"GET"}),!i.ok)throw new H("notFound",`Pkarr record not found for: ${t}`)}catch(c){throw c instanceof H?c:new H("internalError",`Failed to fetch Pkarr record: ${c.message}`)}let o=await i.arrayBuffer();if(!o)throw new H("notFound",`Pkarr record not found for: ${t}`);if(o.byteLength<72)throw new H("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${o.byteLength}`);if(o.byteLength>1072)throw new H("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 Ul({gatewayUri:r,bep44Message:e}){let t=P.uint8Array(e.k).toBase32Z(),n=_0(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 H("internalError",`Failed to put Pkarr record for identifier ${t}: ${s.message}`)}return o.ok}async function _l({dnsPacket:r,publicKeyBytes:e,signer:t}){let n=Math.ceil(Date.now()/1e3),i=Ks(r),o=xl.encode({seq:n,v:i}).subarray(1,-1);if(o.length>1e3)throw new H("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 kl({bep44Message:r}){let e=await De.bytesToPublicKey({publicKeyBytes:r.k}),t=xl.encode({seq:r.seq,v:r.v}).subarray(1,-1);if(!await De.verify({key:e,signature:r.sig,data:t}))throw new H("invalidSignature","Invalid signature for DHT BEP44 message");return Ra(r.v)}var k0="dht";async function Ca({didUri:r}){let e=Ps({didUri:r});return await De.bytesToPublicKey({publicKeyBytes:e})}function Ps({didUri:r}){let e=Oe.parse(r);if(!e)throw new H("invalidDid",`Invalid DID URI: ${r}`);if(e.method!==k0)throw new H("methodNotSupported",`Method not supported: ${e.method}`);let t;try{t=P.base32Z(e.id).toUint8Array()}catch{throw new H("invalidPublicKey","Failed to decode method-specific identifier")}if(t.length!==32)throw new H("invalidPublicKeyLength",`Invalid public key length: ${t.length}`);return t}async function Ol({identityKey:r}){let e=await De.publicKeyToBytes({publicKey:r}),t=P.uint8Array(e).toBase32Z();return`did:${k0}:${t}`}function bo(r){let t={Ed25519:De,"P-256":{publicKeyToBytes:async({publicKey:n})=>{let i=await Ne.publicKeyToBytes({publicKey:n});return await Ne.compressPublicKey({publicKeyBytes:i})},bytesToPublicKey:Ne.bytesToPublicKey,privateKeyToBytes:Ne.privateKeyToBytes,bytesToPrivateKey:Ne.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:n})=>{let i=await Me.publicKeyToBytes({publicKey:n});return await Me.compressPublicKey({publicKeyBytes:i})},bytesToPublicKey:Me.bytesToPublicKey,privateKeyToBytes:Me.privateKeyToBytes,bytesToPrivateKey:Me.bytesToPrivateKey},X25519:Br}[r];if(!t)throw new H("invalidPublicKeyType",`Unsupported curve: ${r}`);return t}async function Rs({newDid:r,previousDidProof:e}){let t=await Ca({didUri:e.previousDid}),n=Ps({didUri:r}),i=P.base64Url(e.signature).toUint8Array();if(!await De.verify({key:t,data:n,signature:i}))throw new H("invalidPreviousDidProof","The previous DID proof is invalid.")}var K0=0,Or=7200,Cs=";",ht=",",Ma={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},Kl={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"};function Q1(r,e){return{type:"TXT",name:r,ttl:Or,data:e}}function xi(r){if(typeof r=="string")return r;if(r instanceof Uint8Array)return P.uint8Array(r).toString();if(Array.isArray(r))return r.map(e=>xi(e)).join("");throw new H("internalError","Pkarr returned DNS TXT record with invalid data type")}function wi(r){return xi(r).split(Cs).reduce((e,t)=>{let[n,i]=t.split("=");return e[n]=i,e},{})}function Na(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 Pl({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=xi(o.data);t.alsoKnownAs=c.split(ht);break}case s.startsWith("cnt"):{let c=xi(o.data);t.controller=c.includes(ht)?c.split(ht):c;break}case s.startsWith("k"):{let{id:c,t:u,k:d,c:a,a:l}=wi(o.data),y=P.base64Url(d).toUint8Array(),w=ma[Number(u)],p=await bo(w).bytesToPublicKey({publicKeyBytes:y});p.alg=l||Kl[Number(u)];let g=s==="k0"?"0":c!==void 0?c:await te({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}=wi(o.data),l=d.includes(ht)?d.split(ht):[d],y=Object.fromEntries(Object.entries(a).map(([w,p])=>[w,p.includes(ht)?p.split(ht):p]));t.service??=[],t.service.push({...y,id:`${r}#${c}`,type:u,serviceEndpoint:l});break}case s.startsWith("typ"):{let{id:c}=wi(o.data);n.types=c.split(ht).map(u=>Number(u));break}case s.startsWith("did"):{let c=w=>w.split(ht).map(p=>i.get(p)).filter(p=>typeof p=="string"),{auth:u,asm:d,del:a,inv:l,agm:y}=wi(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 Rl({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 Rs({newDid:r.id,previousDidProof:n}),i.push({type:"TXT",name:"_prv._did.",ttl:Or,data:`id=${y};s=${l}`})}if(r.alsoKnownAs&&i.push({type:"TXT",name:"_aka._did.",ttl:Or,data:r.alsoKnownAs.join(ht)}),r.controller){let l=Array.isArray(r.controller)?r.controller.join(ht):r.controller;i.push({type:"TXT",name:"_cnt._did.",ttl:Or,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 Ma))throw new H("invalidPublicKeyType",`Verification method '${y.id}' contains an unsupported key type: ${g?.crv??"undefined"}`);let v=ma[g.crv],B=await bo(g.crv).publicKeyToBytes({publicKey:g}),D=P.uint8Array(B).toBase64Url(),E=[`t=${v}`,`k=${D}`];p!=="0"&&await te({jwk:g})!==p&&E.unshift(`id=${p}`),g.alg!==Kl[v]&&E.push(`a=${g.alg}`),y.controller!==r.id&&E.push(`c=${y.controller}`),i.push({type:"TXT",name:`_${w}._did.`,ttl:Or,data:E.join(Cs)})}r.service?.forEach((l,y)=>{let w=`s${y}`;c.push(w);let{id:p,type:g,serviceEndpoint:v,...B}=l;p=gt(p),v=Array.isArray(v)?v.join(","):v;let E=Object.entries({id:p,t:g,se:v,...B}).map(([I,k])=>`${I}=${k}`).join(Cs),O=Na(E);i.push({type:"TXT",name:`_${w}._did.`,ttl:Or,data:O})});let d=[`v=${K0}`];if(u.length&&d.push(`vm=${u.join(ht)}`),Object.keys(Pi).forEach(l=>{let y=r[l]?.map(w=>s.get(w.split("#").pop()));if(y){let w=hl[l];d.push(`${w}=${y.join(ht)}`)}}),c.length&&d.push(`svc=${c.join(ht)}`),e.types?.length){let y=e.types.map(w=>typeof w=="string"?fl[w]:w);i.push({type:"TXT",name:"_typ._did.",ttl:Or,data:`id=${y.join(ht)}`})}i.push({type:"TXT",name:"_did."+O0(r.id)+".",ttl:Or,data:d.join(Cs)});for(let l of t||[])o.push({type:"NS",name:"_did."+O0(r.id)+".",ttl:Or,data:l+"."});return{id:0,type:"response",flags:I0,answers:[...i,...o]}}function O0(r){return r.split(":")[2]}var P0=process.env.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",Ms=class Ms extends nr{static async create({keyManager:e=new lt,options:t={}}={}){if(t.verificationMethods?.some(a=>!(a.algorithm in Ma)))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 Nn.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 te({jwk:y});w=`${s}#${gt(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 St({uri:s,document:c,metadata:{published:!1,...t.types&&{types:t.types}},keyManager:e});if(t.publish??!0){let a=await Ms.publish({did:d,gatewayUri:t.gatewayUri});d.metadata=a.didDocumentMetadata}return d}static async import({portableDid:e,keyManager:t=new lt}){if(Oe.parse(e.uri)?.method!==Ms.methodName)throw new H("methodNotSupported","Method not supported");let i=await St.import({portableDid:e,keyManager:t});if(!i.document.verificationMethod?.some(o=>o.id?.split("#").pop()==="0"))throw new H("invalidDidDocument","DID document must contain an Identity Key");return i}static async getSigningMethod({didDocument:e,methodId:t="#0"}){let n=Oe.parse(e.id);if(n&&n.method!==this.methodName)throw new H("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>gt(o.id)===(gt(t)??gt(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new H("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:t=P0}){return await La.put({did:e,gatewayUri:t})}static async resolve(e,t={}){let n=t?.gatewayUri??P0;try{await Nn.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:o}=await La.get({didUri:e,gatewayUri:n});return{...Ce,didDocument:i,didDocumentMetadata:o}}catch(i){if(!(i instanceof H))throw new Error(i);return{...Ce,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};Ms.methodName="dht";var R0=Ms,La=class r{static async get({didUri:e,gatewayUri:t}){let n=Nn.identifierToIdentityKeyBytes({didUri:e}),i=await r.pkarrGet({gatewayUri:t,publicKeyBytes:n}),o=await Nn.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 Nn.createBep44PutMessage({dnsPacket:n,publicKeyBytes:Nn.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 Dl(e)}static async pkarrPut(e){return Ul(e)}static async fromDnsPacket(e){return Pl(e)}static async toDnsPacket(e){return Rl(e)}static getUniqueDidSuffix(e){return e.split(":")[2]}},Nn=class{static async createBep44PutMessage(e){return _l(e)}static async identifierToIdentityKey(e){return Ca(e)}static identifierToIdentityKeyBytes(e){return Ps(e)}static async identityKeyToIdentifier(e){return Ol(e)}static keyConverter(e){return bo(e)}static async parseBep44GetMessage(e){return kl(e)}static parseTxtDataToObject(e){return wi(e)}static parseTxtDataToString(e){return xi(e)}static async validatePreviousDidProof(e){return Rs(e)}static chunkDataIfNeeded(e){return Na(e)}};var Ue={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 Ee=class extends Error{constructor(e,t){super(`${e}: ${t}`),this.code=e,Object.setPrototypeOf(this,new.target.prototype)}};var X5=new Uint8Array(0);var Cl=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 Ml=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")}},Nl=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 C0(this,e)}},Ll=class{constructor(e){this.decoders=e}or(e){return C0(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`)}},C0=(r,e)=>new Ll({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),$l=class{constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ml(e,t,n),this.decoder=new Nl(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ev=({name:r,prefix:e,encode:t,decode:n})=>new $l(r,e,t,n);var tv=(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},rv=(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},Ns=({name:r,prefix:e,bitsPerChar:t,alphabet:n})=>ev({prefix:e,name:r,encode(i){return rv(i,n,t)},decode(i){return tv(i,n,t,r)}});var iI=Ns({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),oI=Ns({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ls=Ns({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sI=Ns({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bt=class r{static encode(e){return Ls.baseEncode(e)}static decodeAsBytes(e,t){if(!r.isBase64UrlString(e))throw new Ee(Ue.EncodedStringIncorrectEncoding,`Given ${t} must be base64url string.`);return Ls.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 J0=zn(N0(),1);var Fl;(function(r){r.Public="public",r.Private="private"})(Fl||(Fl={}));var Ht=Fl;var Ye=class{static validateEs256kOperationKey(e,t){let n=new Set(["kty","crv","x","y"]);t===Ht.Private&&n.add("d");for(let i in e)if(!n.has(i))throw new Ee(Ue.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${i}'.`);if(e.crv!=="secp256k1")throw new Ee(Ue.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${e.crv}.'`);if(e.kty!=="EC")throw new Ee(Ue.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${e.kty}.'`);if(e.x.length!==43)throw new Ee(Ue.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(e.y.length!==43)throw new Ee(Ue.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(t===Ht.Private&&(e.d===void 0||e.d.length!==43))throw new Ee(Ue.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(e){if(e.length>50)throw new Ee(Ue.IdTooLong,`Key ID length ${e.length} exceed max allowed length of 50.`);if(!Bt.isBase64UrlString(e))throw new Ee(Ue.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 Ee(Ue.PublicKeyPurposeDuplicated,`Public key purpose '${n}' already specified.`);t.add(n)}}};var $s=class{};$s.hashAlgorithmInMultihashCode=18;$s.maxCanonicalizedDeltaSizeInBytes=1e3;var wt=$s;var F0=zn($0(),1);var mr=class r{static canonicalizeAsBytes(e){let t=r.removeAllUndefinedProperties(e),n=F0.default(t);return Bt.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 nv=q0,H0=128,iv=127,ov=~iv,sv=Math.pow(2,31);function q0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sv;)e[t++]=r&255|H0,r/=128;for(;r&ov;)e[t++]=r&255|H0,r>>>=7;return e[t]=r|0,q0.bytes=t-n+1,e}var cv=Hl,av=128,V0=127;function Hl(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Hl.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&V0)<<i:(s&V0)*Math.pow(2,i),i+=7}while(s>=av);return Hl.bytes=o-n,t}var uv=Math.pow(2,7),dv=Math.pow(2,14),lv=Math.pow(2,21),fv=Math.pow(2,28),hv=Math.pow(2,35),pv=Math.pow(2,42),yv=Math.pow(2,49),mv=Math.pow(2,56),gv=Math.pow(2,63),wv=function(r){return r<uv?1:r<dv?2:r<lv?3:r<fv?4:r<hv?5:r<pv?6:r<yv?7:r<mv?8:r<gv?9:10},xv={encode:nv,decode:cv,encodingLength:wv},bv=xv,Fs=bv;var Vl=(r,e=0)=>[Fs.decode(r,e),Fs.decode.bytes],ql=(r,e,t=0)=>(Fs.encode(r,e,t),e),jl=r=>Fs.encodingLength(r);var zl=(r,e)=>{let t=e.byteLength,n=jl(r),i=n+jl(t),o=new Uint8Array(i+t);return ql(r,o,0),ql(t,o,n),o.set(e,i),new Fa(r,t,e,o)},j0=r=>{let e=Cl(r),[t,n]=Vl(e),[i,o]=Vl(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Fa(t,i,s,e)};var Fa=class{constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Gl=({name:r,code:e,encode:t})=>new Jl(r,e,t),Jl=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?zl(this.code,t):t.then(n=>zl(this.code,n))}else throw Error("Unknown type, must be binary type")}};var z0=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),Ha=Gl({name:"sha2-256",code:18,encode:z0("SHA-256")}),DI=Gl({name:"sha2-512",code:19,encode:z0("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())})},tt=class r{static hash(e,t){return Hs(this,void 0,void 0,function*(){let n;switch(t){case 18:n=(yield Ha.digest(e)).bytes;break;default:throw new Ee(Ue.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 Ha.encode(e);break;default:throw new Ee(Ue.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=mr.canonicalizeAsBytes(e);return yield r.hashThenEncode(n,t)})}static canonicalizeThenDoubleHashThenEncode(e,t){return Hs(this,void 0,void 0,function*(){let n=mr.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 Bt.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,t){let n,i=Bt.decodeAsBytes(e,t);try{n=j0(i)}catch{throw new Ee(Ue.MultihashStringNotAMultihash,`Given ${t} string '${e}' is not a multihash after decoding.`)}let o=wt.hashAlgorithmInMultihashCode;if(o!==n.code)throw new Ee(Ue.MultihashUnsupportedHashAlgorithm,`Given ${t} uses unsupported multihash algorithm with code ${n.code}, should use ${o} or change IonSdkConfig to desired hashing algorithm.`)}};var Wl;(function(r){r.Create="create",r.Update="update",r.Deactivate="deactivate",r.Recover="recover"})(Wl||(Wl={}));var Vs=Wl;var Yl;(function(r){r.Replace="replace",r.AddPublicKeys="add-public-keys",r.RemovePublicKeys="remove-public-keys",r.AddServices="add-services",r.RemoveServices="remove-services"})(Yl||(Yl={}));var bi=Yl;var Va=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())})},Ln=class r{static createCreateRequest(e){return Va(this,void 0,void 0,function*(){let t=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,o=e.document.services;Ye.validateEs256kOperationKey(t,Ht.Public),Ye.validateEs256kOperationKey(n,Ht.Public),r.validateDidDocumentKeys(i),r.validateServices(o);let s=wt.hashAlgorithmInMultihashCode,c=[{action:bi.Replace,document:e.document}],u={updateCommitment:yield tt.canonicalizeThenDoubleHashThenEncode(n,s),patches:c};r.validateDeltaSize(u);let a={deltaHash:yield tt.canonicalizeThenHashThenEncode(u,s),recoveryCommitment:yield tt.canonicalizeThenDoubleHashThenEncode(t,s)};return{type:Vs.Create,suffixData:a,delta:u}})}static createDeactivateRequest(e){return Va(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Ye.validateEs256kOperationKey(e.recoveryPublicKey,Ht.Public);let t=wt.hashAlgorithmInMultihashCode,n=yield tt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},o=yield e.signer.sign({alg:"ES256K"},i);return{type:Vs.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:o}})}static createRecoverRequest(e){return Va(this,void 0,void 0,function*(){r.validateDidSuffix(e.didSuffix),Ye.validateEs256kOperationKey(e.recoveryPublicKey,Ht.Public),Ye.validateEs256kOperationKey(e.nextRecoveryPublicKey,Ht.Public),Ye.validateEs256kOperationKey(e.nextUpdatePublicKey,Ht.Public),r.validateDidDocumentKeys(e.document.publicKeys),r.validateServices(e.document.services);let t=wt.hashAlgorithmInMultihashCode,n=yield tt.canonicalizeThenHashThenEncode(e.recoveryPublicKey,t),i=[{action:bi.Replace,document:e.document}],o=yield tt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,t),s={patches:i,updateCommitment:o},c=yield tt.canonicalizeThenHashThenEncode(s,t),d={recoveryCommitment:yield tt.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,t),recoveryKey:e.recoveryPublicKey,deltaHash:c},a=yield e.signer.sign({alg:"ES256K"},d);return{type:Vs.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:a}})}static createUpdateRequest(e){return Va(this,void 0,void 0,function*(){if(r.validateDidSuffix(e.didSuffix),Ye.validateEs256kOperationKey(e.updatePublicKey,Ht.Public),Ye.validateEs256kOperationKey(e.nextUpdatePublicKey,Ht.Public),r.validateServices(e.servicesToAdd),r.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let p of e.idsOfServicesToRemove)Ye.validateId(p);if(e.idsOfPublicKeysToRemove!==void 0)for(let p of e.idsOfPublicKeysToRemove)Ye.validateId(p);let t=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let p={action:bi.AddServices,services:n};t.push(p)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let p={action:bi.RemoveServices,ids:i};t.push(p)}let o=e.publicKeysToAdd;if(o!==void 0&&o.length>0){let p={action:bi.AddPublicKeys,publicKeys:o};t.push(p)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let p={action:bi.RemovePublicKeys,ids:s};t.push(p)}let c=wt.hashAlgorithmInMultihashCode,u=yield tt.canonicalizeThenHashThenEncode(e.updatePublicKey,c),d=yield tt.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,c),a={patches:t,updateCommitment:d},l=yield tt.canonicalizeThenHashThenEncode(a,c),y={updateKey:e.updatePublicKey,deltaHash:l},w=yield e.signer.sign({alg:"ES256K"},y);return{type:Vs.Update,didSuffix:e.didSuffix,revealValue:u,delta:a,signedData:w}})}static validateDidSuffix(e){tt.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 Ee(Ue.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(Ye.validateId(n.id),t.has(n.id))throw new Ee(Ue.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);t.add(n.id),Ye.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 Ee(Ue.DidDocumentServiceIdDuplicated,"Service id has to be unique");t.add(n.id)}}}static validateService(e){Ye.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 Ee(Ue.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new Ee(Ue.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&J0.parse(e.serviceEndpoint).error!==void 0)throw new Ee(Ue.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let t=mr.canonicalizeAsBytes(e);if(t.length>wt.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${t.length} bytes exceeded limit of ${wt.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new Ee(Ue.DeltaExceedsMaximumSize,n)}}};var G0=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())})},vo=class r{static createLongFormDid(e){return G0(this,void 0,void 0,function*(){let t=yield Ln.createCreateRequest(e),n=yield r.computeDidUniqueSuffix(t.suffixData),i;wt.network===void 0||wt.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${wt.network}:${n}`;let o={suffixData:t.suffixData,delta:t.delta},s=mr.canonicalizeAsBytes(o),c=Bt.encode(s);return`${i}:${c}`})}static computeDidUniqueSuffix(e){return G0(this,void 0,void 0,function*(){let t=mr.canonicalizeAsBytes(e),n=yield tt.hash(t,wt.hashAlgorithmInMultihashCode);return Bt.encode(n)})}};var ct=2n**255n-19n,ja=2n**252n+27742317777372353535851937790883648493n,Zl=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Ql=0x6666666666666666666666666666666666666666666666666666666666666658n,qa={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:ct,n:ja,h:8,Gx:Zl,Gy:Ql},It=(r="")=>{throw new Error(r)},em=r=>typeof r=="string",ef=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?It("Uint8Array expected"):r,Eo=r=>new Uint8Array(r),Av=(r,e)=>ef(em(r)?rf(r):Eo(r),e),J=(r,e=ct)=>{let t=r%e;return t>=0n?t:e+t},W0=r=>r instanceof $n?r:It("Point expected"),Y0,$n=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,J(e.x*e.y))}static fromHex(e,t=!0){let{d:n}=qa;e=Av(e,32);let i=e.slice();i[31]=e[31]&-129;let o=Tv(i);o===0n||(t&&!(0n<o&&o<ct)&&It("bad y coord 1"),!t&&!(0n<o&&o<2n**256n)&&It("bad y coord 2"));let s=J(o*o),c=J(s-1n),u=J(n*s+1n),{isValid:d,value:a}=Iv(c,u);d||It("bad y coordinate 3");let l=(a&1n)===1n;return(e[31]&128)!==0!==l&&(a=J(-a)),new r(a,o,1n,J(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}=W0(e),u=J(t*c),d=J(o*i),a=J(n*c),l=J(s*i);return u===d&&a===l}is0(){return this.equals(za)}negate(){return new r(J(-this.ex),this.ey,this.ez,J(-this.et))}double(){let{ex:e,ey:t,ez:n}=this,{a:i}=qa,o=J(e*e),s=J(t*t),c=J(2n*J(n*n)),u=J(i*o),d=e+t,a=J(J(d*d)-o-s),l=u+s,y=l-c,w=u-s,p=J(a*y),g=J(l*w),v=J(a*w),B=J(y*l);return new r(p,g,B,v)}add(e){let{ex:t,ey:n,ez:i,et:o}=this,{ex:s,ey:c,ez:u,et:d}=W0(e),{a,d:l}=qa,y=J(t*s),w=J(n*c),p=J(o*l*d),g=J(i*u),v=J((t+n)*(s+c)-y-w),B=J(g-p),D=J(g+p),E=J(w-a*y),O=J(v*B),I=J(D*E),k=J(v*E),M=J(B*D);return new r(O,I,M,k)}mul(e,t=!0){if(e===0n)return t===!0?It("cannot multiply by 0"):za;if(typeof e=="bigint"&&0n<e&&e<ja||It("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Ja))return Uv(e).p;let n=za,i=Ja;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(qa.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(ja/2n,!1).double();return ja%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=rm(n);return J(n*i)!==1n&&It("invalid inverse"),{x:J(e*i),y:J(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=Sv(t);return n[31]|=e&1n?128:0,n}toHex(){return tf(this.toRawBytes())}};$n.BASE=new $n(Zl,Ql,1n,J(Zl*Ql));$n.ZERO=new $n(0n,1n,1n,0n);var{BASE:Ja,ZERO:za}=$n,tm=(r,e)=>r.toString(16).padStart(e,"0"),tf=r=>Array.from(r).map(e=>tm(e,2)).join(""),rf=r=>{let e=r.length;(!em(r)||e%2)&&It("hex invalid 1");let t=Eo(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)&&It("hex invalid 2"),t[n]=s}return t},Sv=r=>rf(tm(r,32*2)).reverse(),Tv=r=>BigInt("0x"+tf(Eo(ef(r)).reverse())),X0=(...r)=>{let e=Eo(r.reduce((n,i)=>n+ef(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},rm=(r,e=ct)=>{(r===0n||e<=0n)&&It("no inverse n="+r+" mod="+e);let t=J(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?J(i,e):It("no inverse")},Kr=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=ct;return t},Bv=r=>{let t=r*r%ct*r%ct,n=Kr(t,2n)*t%ct,i=Kr(n,1n)*r%ct,o=Kr(i,5n)*i%ct,s=Kr(o,10n)*o%ct,c=Kr(s,20n)*s%ct,u=Kr(c,40n)*c%ct,d=Kr(u,80n)*u%ct,a=Kr(d,80n)*u%ct,l=Kr(a,10n)*o%ct;return{pow_p_5_8:Kr(l,2n)*r%ct,b2:t}},Z0=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Iv=(r,e)=>{let t=J(e*e*e),n=J(t*t*e),i=Bv(r*n).pow_p_5_8,o=J(r*t*i),s=J(e*o*o),c=o,u=J(o*Z0),d=s===r,a=s===J(-r),l=s===J(-r*Z0);return d&&(o=c),(a||l)&&(o=u),(J(o)&1n)===1n&&(o=J(-o)),{isValid:d||a,value:o}};var Xl;var Q0=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,nm={bytesToHex:tf,hexToBytes:rf,concatBytes:X0,mod:J,invert:rm,randomBytes:r=>{let e=Q0();return e||It("crypto.getRandomValues must be defined"),e.getRandomValues(Eo(r))},sha512Async:async(...r)=>{let e=Q0();e||It("crypto.subtle or etc.sha512Async must be defined");let t=X0(...r);return Eo(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(nm,{sha512Sync:{configurable:!1,get(){return Xl},set(r){Xl||(Xl=r)}}});var vi=8,Dv=()=>{let r=[],e=256/vi+1,t=Ja,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let o=1;o<2**(vi-1);o++)n=n.add(t),r.push(n);t=n.double()}return r},Uv=r=>{let e=Y0||(Y0=Dv()),t=(a,l)=>{let y=l.negate();return a?y:l},n=za,i=Ja,o=1+256/vi,s=2**(vi-1),c=BigInt(2**vi-1),u=2**vi,d=BigInt(vi);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 of=2n**256n,Ai=of-0x1000003d1n,sf=of-0x14551231950b75fc4402da1732fc9bebfn,lm=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,fm=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,hm={p:Ai,n:sf,a:0n,b:7n,Gx:lm,Gy:fm},Ao=32,im=r=>q(q(r*r)*r+hm.b),rt=(r="")=>{throw new Error(r)},Ya=r=>typeof r=="bigint",pm=r=>typeof r=="string",nf=r=>Ya(r)&&0n<r&&r<Ai,ym=r=>Ya(r)&&0n<r&&r<sf,mm=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?rt("Uint8Array expected"):r,js=r=>new Uint8Array(r),cf=(r,e)=>mm(pm(r)?Xa(r):js(r),e),q=(r,e=Ai)=>{let t=r%e;return t>=0n?t:e+t},om=r=>r instanceof un?r:rt("Point expected"),sm,un=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=cf(e);let t,n=e[0],i=e.subarray(1),o=cm(i,0,Ao),s=e.length;if(s===33&&[2,3].includes(n)){nf(o)||rt("Point hex invalid: x not FE");let c=kv(im(o)),u=(c&1n)===1n;(n&1)===1!==u&&(c=q(-c)),t=new r(o,c,1n)}return s===65&&n===4&&(t=new r(o,cm(i,Ao,2*Ao),1n)),t?t.ok():rt("Point is not on curve")}static fromPrivateKey(e){return qs.mul(Ov(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}=om(e),u=q(t*c),d=q(o*i),a=q(n*c),l=q(s*i);return u===d&&a===l}negate(){return new r(this.px,q(-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}=om(e),{a:u,b:d}=hm,a=0n,l=0n,y=0n,w=q(d*3n),p=q(t*o),g=q(n*s),v=q(i*c),B=q(t+n),D=q(o+s);B=q(B*D),D=q(p+g),B=q(B-D),D=q(t+i);let E=q(o+c);return D=q(D*E),E=q(p+v),D=q(D-E),E=q(n+i),a=q(s+c),E=q(E*a),a=q(g+v),E=q(E-a),y=q(u*D),a=q(w*v),y=q(a+y),a=q(g-y),y=q(g+y),l=q(a*y),g=q(p+p),g=q(g+p),v=q(u*v),D=q(w*D),g=q(g+v),v=q(p-v),v=q(u*v),D=q(D+v),p=q(g*D),l=q(l+p),p=q(E*D),a=q(B*a),a=q(a-p),p=q(B*g),y=q(E*y),y=q(y+p),new r(a,l,y)}mul(e,t=!0){if(!t&&e===0n)return Ga;if(ym(e)||rt("invalid scalar"),this.equals(qs))return Rv(e).p;let n=Ga,i=qs;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(Ga))return{x:0n,y:0n};if(n===1n)return{x:e,y:t};let i=wm(n);return q(n*i)!==1n&&rt("invalid inverse"),{x:q(e*i),y:q(t*i)}}assertValidity(){let{x:e,y:t}=this.aff();return(!nf(e)||!nf(t))&&rt("Point invalid: x or y"),q(t*t)===im(e)?this:rt("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")+am(t)+(e?"":am(n))}toRawBytes(e=!0){return Xa(this.toHex(e))}};un.BASE=new un(lm,fm,1n);un.ZERO=new un(0n,1n,0n);var{BASE:qs,ZERO:Ga}=un,gm=(r,e)=>r.toString(16).padStart(e,"0"),af=r=>Array.from(r).map(e=>gm(e,2)).join(""),Xa=r=>{let e=r.length;(!pm(r)||e%2)&&rt("hex invalid 1");let t=js(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)&&rt("hex invalid 2"),t[n]=s}return t},Za=r=>BigInt("0x"+(af(r)||"0")),cm=(r,e,t)=>Za(r.slice(e,t)),uf=r=>Ya(r)&&r>=0n&&r<of?Xa(gm(r,2*Ao)):rt("bigint expected"),am=r=>af(uf(r)),um=(...r)=>{let e=js(r.reduce((n,i)=>n+mm(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},wm=(r,e=Ai)=>{(r===0n||e<=0n)&&rt("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):rt("no inverse")},kv=r=>{let e=1n;for(let t=r,n=(Ai+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*t%Ai),t=t*t%Ai;return q(e*e)===r?e:rt("sqrt invalid")},Ov=r=>(Ya(r)||(r=Za(cf(r,Ao))),ym(r)?r:rt("private key out of range"));var dm=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Wa;function Kv(r){r=cf(r);let e=Ao+8;(r.length<e||r.length>1024)&&rt("expected proper params");let t=q(Za(r),sf-1n)+1n;return uf(t)}var xm={hexToBytes:Xa,bytesToHex:af,concatBytes:um,bytesToNumberBE:Za,numberToBytesBE:uf,mod:q,invert:wm,hmacSha256Async:async(r,...e)=>{let t=dm();if(!t)return rt("etc.hmacSha256Async not set");let n=t.subtle,i=await n.importKey("raw",r,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return js(await n.sign("HMAC",i,um(...e)))},hmacSha256Sync:Wa,hashToPrivateKey:Kv,randomBytes:r=>{let e=dm();return e||rt("crypto.getRandomValues must be defined"),e.getRandomValues(js(r))}};Object.defineProperties(xm,{hmacSha256Sync:{configurable:!1,get(){return Wa},set(r){Wa||(Wa=r)}}});var Ei=8,Pv=()=>{let r=[],e=256/Ei+1,t=qs,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},Rv=r=>{let e=sm||(sm=Pv()),t=(a,l)=>{let y=l.negate();return a?y:l},n=Ga,i=qs,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 vm;(function(r){r.Mainnet="mainnet",r.Testnet="test"})(vm||(vm={}));var Em;(function(r){r.Authentication="authentication",r.AssertionMethod="assertionMethod",r.CapabilityInvocation="capabilityInvocation",r.CapabilityDelegation="capabilityDelegation",r.KeyAgreement="keyAgreement"})(Em||(Em={}));var dn=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 vo.createLongFormDid({document:o,recoveryKey:s,updateKey:c})}static async constructCreateRequest({ionDocument:e,recoveryKey:t,updateKey:n}){return await Ln.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 Cv=(i=>(i.Ed25519="Ed25519",i.secp256k1="secp256k1",i.secp256r1="secp256r1",i.X25519="X25519",i))(Cv||{}),Mv={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},Am="https://ion.tbd.engineering",Si=class Si extends nr{static async create({keyManager:e=new lt,options:t={}}={}){if(t.verificationMethods?.some(p=>!(p.algorithm in Mv)))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 dn.computeLongFormDidUri({recoveryKey:c,updateKey:d,services:t.services??[],verificationMethods:o}),{didDocument:l,didResolutionMetadata:y}=await Si.resolve(a,{gatewayUri:t.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${y?.error}`);let w=new St({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 Si.publish({did:w,gatewayUri:t.gatewayUri});w.metadata=p.didDocumentMetadata}return w}static async getSigningMethod({didDocument:e,methodId:t}){let n=Oe.parse(e.id);if(n&&n.method!==this.methodName)throw new H("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(o=>o.id===(t??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new H("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 lt}){if(Oe.parse(e.uri)?.method!==Si.methodName)throw new H("methodNotSupported","Method not supported");return await St.import({portableDid:e,keyManager:t})}static async publish({did:e,gatewayUri:t=Am}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:ul({didDocument:e.document,methodId:s.id})}))??[],i=await dn.createIonDocument({services:e.document.service??[],verificationMethods:n}),o=await dn.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=dn.appendPathToUrl({baseUrl:t,path:"/operations"}),c=await fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:c.ok},didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:"internalError",errorMessage:`Failed to publish DID document for: ${e.uri}`}}}}static async resolve(e,t={}){let n=Oe.parse(e);if(!n)return{...Ce,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Si.methodName)return{...Ce,didResolutionMetadata:{error:"methodNotSupported"}};let i=t?.gatewayUri??Am;try{let o=dn.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(o);if(!s.ok)throw new H("notFound",`Unable to find DID document for: ${e}`);let{didDocument:c,didDocumentMetadata:u}=await s.json();return{...Ce,...c&&{didDocument:c},didDocumentMetadata:{published:u?.method?.published,...u}}}catch(o){if(!(o instanceof H))throw new Error(o);return{...Ce,didResolutionMetadata:{error:o.code,...o.message&&{errorMessage:o.message}}}}}};Si.methodName="ion";var Sm=Si;var Ti=class Ti extends nr{static async create({keyManager:e=new lt,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=P.object(o).toBase64Url(),c=`did:${Ti.methodName}:${s}`,d=(await Ti.resolve(c)).didDocument;return new St({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Oe.parse(e.id);if(t&&t.method!==this.methodName)throw new H("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new H("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 lt}){if(Oe.parse(e.uri)?.method!==Ti.methodName)throw new H("methodNotSupported","Method not supported");let i=await St.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new H("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){let n=Oe.parse(e),i;try{i=n?P.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...Ce,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Ti.methodName)return{...Ce,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{...Ce,didDocument:o}}};Ti.methodName="jwk";var Tm=Ti;var Nv={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},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:at.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let n={"P-256":Ne.compressPublicKey,secp256k1:Me.compressPublicKey}[e];if(!n)throw new H("invalidPublicKeyType",`Unsupported curve: ${e}`);return n}static keyConverter(e){let n={Ed25519:De,"P-256":Ne,secp256k1:Me}[e];if(!n)throw new H("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?at.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 Nv))throw new H("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 dl({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 Fn=Pr;var Lv=(n=>(n.Ed25519="Ed25519",n.secp256k1="secp256k1",n.secp256r1="secp256r1",n))(Lv||{}),Bm={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},Rr=class Rr extends nr{static async create({keyManager:e=new lt,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 Fn.publicKeyToMultibaseId({publicKey:o}),c=`did:${Rr.methodName}:${s}`,d=(await Rr.resolve(c,t)).didDocument;return new St({uri:c,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let t=Oe.parse(e.id);if(t&&t.method!==this.methodName)throw new H("methodNotSupported",`Method not supported: ${t.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(o=>o.id===n);if(!(i&&i.publicKeyJwk))throw new H("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 lt}){if(Oe.parse(e.uri)?.method!==Rr.methodName)throw new H("methodNotSupported","Method not supported");let i=await St.import({portableDid:e,keyManager:t});if(i.document.verificationMethod.length!==1)throw new H("invalidDidDocument","DID document must contain exactly one verification method");return i}static async resolve(e,t){try{let n=await Rr.createDocument({didUri:e,options:t});return{...Ce,didDocument:n}}catch(n){if(!(n instanceof H))throw new Error(n);return{...Ce,didResolutionMetadata:{error:n.code,...n.message&&{errorMessage:n.message}}}}}static async createDocument({didUri:e,options:t={}}){let{defaultContext:n="https://www.w3.org/ns/did/v1",enableExperimentalPublicKeyTypes:i=!1,publicKeyFormat:o="JsonWebKey2020"}=t,s={id:""},c=Oe.parse(e);if(!c)throw new H("invalidDid",`Invalid DID URI: ${e}`);let u=c.id;if(c.method!==Rr.methodName)throw new H("methodNotSupported",`Method not supported: ${c.method}`);if(!Rr.validateIdentifier(c))throw new H("invalidDid",`Invalid DID URI: ${e}`);let d=await Rr.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 al({didDocument:s}).forEach(y=>{let w=Bm[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}=ll({multibaseKeyId:t}),a=c.byteLength,l=Fn.MULTICODEC_PUBLIC_KEY_LENGTH[u];if(a!==l)throw new H("invalidPublicKeyLength",`Expected ${a} bytes. Actual: ${l}`);let y=!1;switch(d){case"secp256k1-pub":y=await Me.validatePublicKey({publicKeyBytes:c});break;case"ed25519-pub":y=await De.validatePublicKey({publicKeyBytes:c});break}if(!y)throw new H("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${t}`;try{new URL(s.id)}catch{throw new H("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(o in Bm))throw new H("unsupportedPublicKeyType",`Unsupported format: ${o}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(o))throw new H("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 Fn.multicodecToJwk({code:u});s.publicKeyJwk=await Fn.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&&Ci(n)==="String"&&n.startsWith("z")}};Rr.methodName="key";var Im=Rr;var Qa=class Qa extends nr{static async resolve(e,t){let n=Oe.parse(e);if(!n)return{...Ce,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Qa.methodName)return{...Ce,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{...Ce,didDocument:c}}catch{return{...Ce,didResolutionMetadata:{error:"notFound"}}}}};Qa.methodName="web";var Dm=Qa;var km=zn(Td(),1),Om=zn(df(),1),_m=class{constructor({db:e,location:t="DATA/DID_RESOLVERCACHE",ttl:n="15m"}={}){this.cache=e??new km.Level(t),this.ttl=(0,Om.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 Pm=zn(df(),1);var Km=class{constructor({ttl:e="15m"}={}){this.cache=new du.default({ttl:(0,Pm.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 Rm={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 Cm=class{constructor({cache:e,didResolvers:t}){this.didResolvers=new Map;this.cache=e||Rm;for(let n of t)this.didResolvers.set(n.methodName,n)}async resolve(e,t){let n=Oe.parse(e);if(!n)return{...Ce,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${e}`}};let i=this.didResolvers.get(n.method);if(!i)return{...Ce,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${n.method}`}};let o=await this.cache.get(n.uri);if(o)return o;{let s=await i.resolve(n.uri,t);return s.didResolutionMetadata.error||await this.cache.set(n.uri,s),s}}async dereference(e,t){let n=Oe.parse(e);if(!n)return{dereferencingMetadata:{error:"invalidDidUrl"},contentStream:null,contentMetadata:{}};let{didDocument:i,didResolutionMetadata:o,didDocumentMetadata:s}=await this.resolve(n.uri);if(!i)return{dereferencingMetadata:{error:o.error},contentStream:null,contentMetadata:{}};if(!n.fragment||n.query)return{dereferencingMetadata:{contentType:"application/did+json"},contentStream:i,contentMetadata:s};let{service:c=[],verificationMethod:u=[]}=i,d=new Set([e,n.fragment,`#${n.fragment}`]),a;for(let l of u)if(d.has(l.id)){a=l;break}for(let l of c)if(d.has(l.id)){a=l;break}return a?{dereferencingMetadata:{contentType:"application/did+json"},contentStream:a,contentMetadata:o}:{dereferencingMetadata:{error:"notFound"},contentStream:null,contentMetadata:{}}}};export{Ma as AlgorithmToKeyTypeMap,St as BearerDid,K0 as DID_DHT_SPECIFICATION_VERSION,Or as DNS_RECORD_TTL,Oe as Did,R0 as DidDht,La as DidDhtDocument,fl as DidDhtRegisteredDidType,ma as DidDhtRegisteredKeyType,Nn as DidDhtUtils,hl as DidDhtVerificationRelationship,H as DidError,Jt as DidErrorCode,Sm as DidIon,Cv as DidIonRegisteredKeyType,dn as DidIonUtils,Tm as DidJwk,Im as DidKey,Lv as DidKeyRegisteredKeyType,Fn as DidKeyUtils,Bm as DidKeyVerificationMethodType,nr as DidMethod,_m as DidResolverCacheLevel,Km as DidResolverCacheMemory,Rm as DidResolverCacheNoop,Pi as DidVerificationRelationship,Dm as DidWeb,Ce as EMPTY_DID_RESOLUTION_RESULT,Kl as KeyTypeToDefaultAlgorithmMap,Cs as PROPERTY_SEPARATOR,Cm as UniversalResolver,ht as VALUE_SEPARATOR,Na as chunkDataIfNeeded,_l as createBep44PutMessage,Q1 as createTxtRecord,Pl as fromDnsPacket,Ca as identifierToIdentityKey,Ps as identifierToIdentityKeyBytes,Ol as identityKeyToIdentifier,e0 as isPortableDid,bo as keyConverter,kl as parseBep44GetMessage,wi as parseTxtDataToObject,xi as parseTxtDataToString,Dl as pkarrGet,Ul as pkarrPut,Rl as toDnsPacket,t0 as utils,Rs as validatePreviousDidProof};
2
2
  /*! Bundled license information:
3
3
 
4
4
  ieee754/index.js: