@enbox/crypto 0.0.3 → 0.0.4

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 (91) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/algorithms/aes-ctr.js +1 -1
  4. package/dist/esm/algorithms/aes-gcm.js +34 -1
  5. package/dist/esm/algorithms/aes-gcm.js.map +1 -1
  6. package/dist/esm/algorithms/aes-kw.js +154 -0
  7. package/dist/esm/algorithms/aes-kw.js.map +1 -0
  8. package/dist/esm/algorithms/ecdsa.js +110 -1
  9. package/dist/esm/algorithms/ecdsa.js.map +1 -1
  10. package/dist/esm/algorithms/eddsa.js +90 -1
  11. package/dist/esm/algorithms/eddsa.js.map +1 -1
  12. package/dist/esm/algorithms/hkdf.js +53 -0
  13. package/dist/esm/algorithms/hkdf.js.map +1 -0
  14. package/dist/esm/algorithms/pbkdf2.js +55 -0
  15. package/dist/esm/algorithms/pbkdf2.js.map +1 -0
  16. package/dist/esm/algorithms/sha-2.js +1 -1
  17. package/dist/esm/algorithms/x25519.js +125 -0
  18. package/dist/esm/algorithms/x25519.js.map +1 -0
  19. package/dist/esm/index.js +5 -0
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/local-key-manager.js +6 -1
  22. package/dist/esm/local-key-manager.js.map +1 -1
  23. package/dist/esm/primitives/ecies-secp256k1.js +79 -0
  24. package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
  25. package/dist/esm/primitives/x25519.js +9 -16
  26. package/dist/esm/primitives/x25519.js.map +1 -1
  27. package/dist/esm/utils.js +30 -0
  28. package/dist/esm/utils.js.map +1 -1
  29. package/dist/types/algorithms/aes-ctr.d.ts +1 -1
  30. package/dist/types/algorithms/aes-gcm.d.ts +23 -3
  31. package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
  32. package/dist/types/algorithms/aes-kw.d.ts +129 -0
  33. package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
  34. package/dist/types/algorithms/ecdsa.d.ts +48 -3
  35. package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
  36. package/dist/types/algorithms/eddsa.d.ts +48 -3
  37. package/dist/types/algorithms/eddsa.d.ts.map +1 -1
  38. package/dist/types/algorithms/hkdf.d.ts +35 -0
  39. package/dist/types/algorithms/hkdf.d.ts.map +1 -0
  40. package/dist/types/algorithms/pbkdf2.d.ts +35 -0
  41. package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
  42. package/dist/types/algorithms/sha-2.d.ts +1 -1
  43. package/dist/types/algorithms/x25519.d.ts +76 -0
  44. package/dist/types/algorithms/x25519.d.ts.map +1 -0
  45. package/dist/types/index.d.ts +5 -0
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/dist/types/local-key-manager.d.ts +4 -4
  48. package/dist/types/local-key-manager.d.ts.map +1 -1
  49. package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
  50. package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
  51. package/dist/types/primitives/x25519.d.ts +9 -16
  52. package/dist/types/primitives/x25519.d.ts.map +1 -1
  53. package/dist/types/types/crypto-api.d.ts +52 -4
  54. package/dist/types/types/crypto-api.d.ts.map +1 -1
  55. package/dist/types/types/key-converter.d.ts +37 -15
  56. package/dist/types/types/key-converter.d.ts.map +1 -1
  57. package/dist/types/types/key-deriver.d.ts +41 -0
  58. package/dist/types/types/key-deriver.d.ts.map +1 -1
  59. package/dist/types/types/key-io.d.ts +37 -0
  60. package/dist/types/types/key-io.d.ts.map +1 -1
  61. package/dist/types/types/params-direct.d.ts +17 -0
  62. package/dist/types/types/params-direct.d.ts.map +1 -1
  63. package/dist/types/types/params-kms.d.ts +55 -0
  64. package/dist/types/types/params-kms.d.ts.map +1 -1
  65. package/dist/types/utils.d.ts +19 -0
  66. package/dist/types/utils.d.ts.map +1 -1
  67. package/dist/utils.js +1 -1
  68. package/dist/utils.js.map +3 -3
  69. package/package.json +10 -13
  70. package/src/algorithms/aes-ctr.ts +1 -1
  71. package/src/algorithms/aes-gcm.ts +38 -2
  72. package/src/algorithms/aes-kw.ts +182 -0
  73. package/src/algorithms/ecdsa.ts +132 -1
  74. package/src/algorithms/eddsa.ts +108 -1
  75. package/src/algorithms/hkdf.ts +54 -0
  76. package/src/algorithms/pbkdf2.ts +57 -0
  77. package/src/algorithms/sha-2.ts +1 -1
  78. package/src/algorithms/x25519.ts +153 -0
  79. package/src/index.ts +5 -0
  80. package/src/local-key-manager.ts +9 -4
  81. package/src/primitives/ecies-secp256k1.ts +113 -0
  82. package/src/primitives/x25519.ts +9 -16
  83. package/src/types/crypto-api.ts +124 -6
  84. package/src/types/key-converter.ts +33 -7
  85. package/src/types/key-deriver.ts +49 -0
  86. package/src/types/key-io.ts +40 -0
  87. package/src/types/params-direct.ts +21 -0
  88. package/src/types/params-kms.ts +67 -0
  89. package/src/utils.ts +53 -0
  90. package/dist/browser.js +0 -60
  91. package/dist/browser.js.map +0 -7
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var nu=Object.create;var Ui=Object.defineProperty;var iu=Object.getOwnPropertyDescriptor;var ou=Object.getOwnPropertyNames;var su=Object.getPrototypeOf,cu=Object.prototype.hasOwnProperty;var Y=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Ns=(r,t)=>{for(var e in t)Ui(r,e,{get:t[e],enumerable:!0})},au=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ou(t))!cu.call(r,i)&&i!==e&&Ui(r,i,{get:()=>t[i],enumerable:!(n=iu(t,i))||n.enumerable});return r};var Ds=(r,t,e)=>(e=r!=null?nu(su(r)):{},au(t||!r||!r.__esModule?Ui(e,"default",{value:r,enumerable:!0}):e,r));var Js=Y((ap,js)=>{var fu=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,En=()=>fu.now(),uu=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),Ki=r=>r===1/0||uu(r),Ii=class r{constructor({max:t=1/0,ttl:e,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,e!==void 0&&!Ki(e))throw new TypeError("ttl must be positive integer or Infinity if set");if(!Ki(t))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=e,this.max=t,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(t,e){if(this.timerExpiration<t)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-En());break}},e);n.unref&&n.unref(),this.timerExpiration=t,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 t=this.dispose!==r.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[e,n]of t)this.dispose(n,e,"delete")}setTTL(t,e=this.ttl){let n=this.expirationMap.get(t);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==t)}if(e!==1/0){let i=Math.floor(En()+e);this.expirationMap.set(t,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,e)),this.expirations[i].push(t)}else this.expirationMap.set(t,1/0)}set(t,e,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!Ki(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(t)){i||this.setTTL(t,n);let s=this.data.get(t);s!==e&&(this.data.set(t,e),o||this.dispose(s,t,"set"))}else this.setTTL(t,n),this.data.set(t,e);for(;this.size>this.max;)this.purgeToCapacity();return this}has(t){return this.data.has(t)}getRemainingTTL(t){let e=this.expirationMap.get(t);return e===1/0?e:e!==void 0?Math.max(0,Math.ceil(e-En())):0}get(t,{updateAgeOnGet:e=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(t);if(i&&this.getRemainingTTL(t)===0){this.delete(t);return}return e&&this.setTTL(t,n),o}dispose(t,e){}delete(t){let e=this.expirationMap.get(t);if(e!==void 0){let n=this.data.get(t);this.data.delete(t),this.expirationMap.delete(t);let i=this.expirations[e];return i&&(i.length<=1?delete this.expirations[e]:this.expirations[e]=i.filter(o=>o!==t)),this.dispose(n,t,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let t in this.expirations){let e=this.expirations[t];if(this.size-e.length>=this.max){delete this.expirations[t];let n=[];for(let i of e)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 e.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 t=Math.ceil(En());for(let e in this.expirations){if(e==="Infinity"||e>t)return;let n=[...this.expirations[e]||[]],i=[];delete this.expirations[e];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 t in this.expirations)for(let e of this.expirations[t])yield[e,this.data.get(e)]}*keys(){for(let t in this.expirations)for(let e of this.expirations[t])yield e}*values(){for(let t in this.expirations)for(let e of this.expirations[t])yield this.data.get(e)}[Symbol.iterator](){return this.entries()}};js.exports=Ii});var ic=Y(nc=>{"use strict";nc.supports=function(...t){let e=t.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(e,{snapshots:e.snapshots||!1,permanence:e.permanence||!1,seek:e.seek||!1,clear:e.clear||!1,getMany:e.getMany||!1,keyIterator:e.keyIterator||!1,valueIterator:e.valueIterator||!1,iteratorNextv:e.iteratorNextv||!1,iteratorAll:e.iteratorAll||!1,status:e.status||!1,createIfMissing:e.createIfMissing||!1,errorIfExists:e.errorIfExists||!1,deferredOpen:e.deferredOpen||!1,promises:e.promises||!1,streams:e.streams||!1,encodings:Object.assign({},e.encodings),events:Object.assign({},e.events),additionalMethods:Object.assign({},e.additionalMethods)})}});var Ct=Y((sy,oc)=>{"use strict";oc.exports=class extends Error{constructor(t,e){super(t||""),typeof e=="object"&&e!==null&&(e.code&&(this.code=String(e.code)),e.expected&&(this.expected=!0),e.transient&&(this.transient=!0),e.cause&&(this.cause=e.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var ac=Y(An=>{"use strict";An.byteLength=Gu;An.toByteArray=Fu;An.fromByteArray=zu;var Gt=[],St=[],Hu=typeof Uint8Array<"u"?Uint8Array:Array,qi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ve=0,sc=qi.length;Ve<sc;++Ve)Gt[Ve]=qi[Ve],St[qi.charCodeAt(Ve)]=Ve;var Ve,sc;St[45]=62;St[95]=63;function cc(r){var t=r.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");e===-1&&(e=t);var n=e===t?0:4-e%4;return[e,n]}function Gu(r){var t=cc(r),e=t[0],n=t[1];return(e+n)*3/4-n}function qu(r,t,e){return(t+e)*3/4-e}function Fu(r){var t,e=cc(r),n=e[0],i=e[1],o=new Hu(qu(r,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)t=St[r.charCodeAt(a)]<<18|St[r.charCodeAt(a+1)]<<12|St[r.charCodeAt(a+2)]<<6|St[r.charCodeAt(a+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=St[r.charCodeAt(a)]<<2|St[r.charCodeAt(a+1)]>>4,o[s++]=t&255),i===1&&(t=St[r.charCodeAt(a)]<<10|St[r.charCodeAt(a+1)]<<4|St[r.charCodeAt(a+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function $u(r){return Gt[r>>18&63]+Gt[r>>12&63]+Gt[r>>6&63]+Gt[r&63]}function Wu(r,t,e){for(var n,i=[],o=t;o<e;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push($u(n));return i.join("")}function zu(r){for(var t,e=r.length,n=e%3,i=[],o=16383,s=0,c=e-n;s<c;s+=o)i.push(Wu(r,s,s+o>c?c:s+o));return n===1?(t=r[e-1],i.push(Gt[t>>2]+Gt[t<<4&63]+"==")):n===2&&(t=(r[e-2]<<8)+r[e-1],i.push(Gt[t>>10]+Gt[t>>4&63]+Gt[t<<2&63]+"=")),i.join("")}});var fc=Y(Fi=>{Fi.read=function(r,t,e,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,f=a>>1,u=-7,h=e?i-1:0,y=e?-1:1,x=r[t+h];for(h+=y,o=x&(1<<-u)-1,x>>=-u,u+=c;u>0;o=o*256+r[t+h],h+=y,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=n;u>0;s=s*256+r[t+h],h+=y,u-=8);if(o===0)o=1-f;else{if(o===a)return s?NaN:(x?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-f}return(x?-1:1)*s*Math.pow(2,o-n)};Fi.write=function(r,t,e,n,i,o){var s,c,a,f=o*8-i-1,u=(1<<f)-1,h=u>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=n?0:o-1,p=n?1:-1,l=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+h>=1?t+=y/a:t+=y*Math.pow(2,1-h),t*a>=2&&(s++,a/=2),s+h>=u?(c=0,s=u):s+h>=1?(c=(t*a-1)*Math.pow(2,i),s=s+h):(c=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;r[e+x]=c&255,x+=p,c/=256,i-=8);for(s=s<<i|c,f+=i;f>0;r[e+x]=s&255,x+=p,s/=256,f-=8);r[e+x-p]|=l*128}});var Sn=Y(yr=>{"use strict";var $i=ac(),dr=fc(),uc=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;yr.Buffer=g;yr.SlowBuffer=eh;yr.INSPECT_MAX_BYTES=50;var Bn=2147483647;yr.kMaxLength=Bn;g.TYPED_ARRAY_SUPPORT=Zu();!g.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 Zu(){try{let r=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(r,t),r.foo()===42}catch{return!1}}Object.defineProperty(g.prototype,"parent",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.buffer}});Object.defineProperty(g.prototype,"offset",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.byteOffset}});function re(r){if(r>Bn)throw new RangeError('The value "'+r+'" is invalid for option "size"');let t=new Uint8Array(r);return Object.setPrototypeOf(t,g.prototype),t}function g(r,t,e){if(typeof r=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Yi(r)}return pc(r,t,e)}g.poolSize=8192;function pc(r,t,e){if(typeof r=="string")return Xu(r,t);if(ArrayBuffer.isView(r))return Qu(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(qt(r,ArrayBuffer)||r&&qt(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qt(r,SharedArrayBuffer)||r&&qt(r.buffer,SharedArrayBuffer)))return zi(r,t,e);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 g.from(n,t,e);let i=th(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return g.from(r[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}g.from=function(r,t,e){return pc(r,t,e)};Object.setPrototypeOf(g.prototype,Uint8Array.prototype);Object.setPrototypeOf(g,Uint8Array);function yc(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 Yu(r,t,e){return yc(r),r<=0?re(r):t!==void 0?typeof e=="string"?re(r).fill(t,e):re(r).fill(t):re(r)}g.alloc=function(r,t,e){return Yu(r,t,e)};function Yi(r){return yc(r),re(r<0?0:Xi(r)|0)}g.allocUnsafe=function(r){return Yi(r)};g.allocUnsafeSlow=function(r){return Yi(r)};function Xu(r,t){if((typeof t!="string"||t==="")&&(t="utf8"),!g.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let e=mc(r,t)|0,n=re(e),i=n.write(r,t);return i!==e&&(n=n.slice(0,i)),n}function Wi(r){let t=r.length<0?0:Xi(r.length)|0,e=re(t);for(let n=0;n<t;n+=1)e[n]=r[n]&255;return e}function Qu(r){if(qt(r,Uint8Array)){let t=new Uint8Array(r);return zi(t.buffer,t.byteOffset,t.byteLength)}return Wi(r)}function zi(r,t,e){if(t<0||r.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');let n;return t===void 0&&e===void 0?n=new Uint8Array(r):e===void 0?n=new Uint8Array(r,t):n=new Uint8Array(r,t,e),Object.setPrototypeOf(n,g.prototype),n}function th(r){if(g.isBuffer(r)){let t=Xi(r.length)|0,e=re(t);return e.length===0||r.copy(e,0,0,t),e}if(r.length!==void 0)return typeof r.length!="number"||to(r.length)?re(0):Wi(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Wi(r.data)}function Xi(r){if(r>=Bn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Bn.toString(16)+" bytes");return r|0}function eh(r){return+r!=r&&(r=0),g.alloc(+r)}g.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==g.prototype};g.compare=function(t,e){if(qt(t,Uint8Array)&&(t=g.from(t,t.offset,t.byteLength)),qt(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),!g.isBuffer(t)||!g.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,i=e.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(t[o]!==e[o]){n=t[o],i=e[o];break}return n<i?-1:i<n?1:0};g.isEncoding=function(t){switch(String(t).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}};g.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return g.alloc(0);let n;if(e===void 0)for(e=0,n=0;n<t.length;++n)e+=t[n].length;let i=g.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){let s=t[n];if(qt(s,Uint8Array))o+s.length>i.length?(g.isBuffer(s)||(s=g.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(g.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function mc(r,t){if(g.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||qt(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 e=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&e===0)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Zi(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return Tc(r).length;default:if(i)return n?-1:Zi(r).length;t=(""+t).toLowerCase(),i=!0}}g.byteLength=mc;function rh(r,t,e){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return lh(this,t,e);case"utf8":case"utf-8":return gc(this,t,e);case"ascii":return uh(this,t,e);case"latin1":case"binary":return hh(this,t,e);case"base64":return ah(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return dh(this,t,e);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}g.prototype._isBuffer=!0;function He(r,t,e){let n=r[t];r[t]=r[e],r[e]=n}g.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)He(this,e,e+1);return this};g.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)He(this,e,e+3),He(this,e+1,e+2);return this};g.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)He(this,e,e+7),He(this,e+1,e+6),He(this,e+2,e+5),He(this,e+3,e+4);return this};g.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?gc(this,0,t):rh.apply(this,arguments)};g.prototype.toLocaleString=g.prototype.toString;g.prototype.equals=function(t){if(!g.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:g.compare(this,t)===0};g.prototype.inspect=function(){let t="",e=yr.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"};uc&&(g.prototype[uc]=g.prototype.inspect);g.prototype.compare=function(t,e,n,i,o){if(qt(t,Uint8Array)&&(t=g.from(t,t.offset,t.byteLength)),!g.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),e<0||n>t.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,i>>>=0,o>>>=0,this===t)return 0;let s=o-i,c=n-e,a=Math.min(s,c),f=this.slice(i,o),u=t.slice(e,n);for(let h=0;h<a;++h)if(f[h]!==u[h]){s=f[h],c=u[h];break}return s<c?-1:c<s?1:0};function wc(r,t,e,n,i){if(r.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,to(e)&&(e=i?0:r.length-1),e<0&&(e=r.length+e),e>=r.length){if(i)return-1;e=r.length-1}else if(e<0)if(i)e=0;else return-1;if(typeof t=="string"&&(t=g.from(t,n)),g.isBuffer(t))return t.length===0?-1:hc(r,t,e,n,i);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,t,e):Uint8Array.prototype.lastIndexOf.call(r,t,e):hc(r,[t],e,n,i);throw new TypeError("val must be string, number or Buffer")}function hc(r,t,e,n,i){let o=1,s=r.length,c=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||t.length<2)return-1;o=2,s/=2,c/=2,e/=2}function a(u,h){return o===1?u[h]:u.readUInt16BE(h*o)}let f;if(i){let u=-1;for(f=e;f<s;f++)if(a(r,f)===a(t,u===-1?0:f-u)){if(u===-1&&(u=f),f-u+1===c)return u*o}else u!==-1&&(f-=f-u),u=-1}else for(e+c>s&&(e=s-c),f=e;f>=0;f--){let u=!0;for(let h=0;h<c;h++)if(a(r,f+h)!==a(t,h)){u=!1;break}if(u)return f}return-1}g.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1};g.prototype.indexOf=function(t,e,n){return wc(this,t,e,n,!0)};g.prototype.lastIndexOf=function(t,e,n){return wc(this,t,e,n,!1)};function nh(r,t,e,n){e=Number(e)||0;let i=r.length-e;n?(n=Number(n),n>i&&(n=i)):n=i;let o=t.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(t.substr(s*2,2),16);if(to(c))return s;r[e+s]=c}return s}function ih(r,t,e,n){return Tn(Zi(t,r.length-e),r,e,n)}function oh(r,t,e,n){return Tn(wh(t),r,e,n)}function sh(r,t,e,n){return Tn(Tc(t),r,e,n)}function ch(r,t,e,n){return Tn(gh(t,r.length-e),r,e,n)}g.prototype.write=function(t,e,n,i){if(e===void 0)i="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")i=e,n=this.length,e=0;else if(isFinite(e))e=e>>>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-e;if((n===void 0||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return nh(this,t,e,n);case"utf8":case"utf-8":return ih(this,t,e,n);case"ascii":case"latin1":case"binary":return oh(this,t,e,n);case"base64":return sh(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ch(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ah(r,t,e){return t===0&&e===r.length?$i.fromByteArray(r):$i.fromByteArray(r.slice(t,e))}function gc(r,t,e){e=Math.min(r.length,e);let n=[],i=t;for(;i<e;){let o=r[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=e){let a,f,u,h;switch(c){case 1:o<128&&(s=o);break;case 2:a=r[i+1],(a&192)===128&&(h=(o&31)<<6|a&63,h>127&&(s=h));break;case 3:a=r[i+1],f=r[i+2],(a&192)===128&&(f&192)===128&&(h=(o&15)<<12|(a&63)<<6|f&63,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:a=r[i+1],f=r[i+2],u=r[i+3],(a&192)===128&&(f&192)===128&&(u&192)===128&&(h=(o&15)<<18|(a&63)<<12|(f&63)<<6|u&63,h>65535&&h<1114112&&(s=h))}}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 fh(n)}var lc=4096;function fh(r){let t=r.length;if(t<=lc)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=lc));return e}function uh(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]&127);return n}function hh(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]);return n}function lh(r,t,e){let n=r.length;(!t||t<0)&&(t=0),(!e||e<0||e>n)&&(e=n);let i="";for(let o=t;o<e;++o)i+=xh[r[o]];return i}function dh(r,t,e){let n=r.slice(t,e),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}g.prototype.slice=function(t,e){let n=this.length;t=~~t,e=e===void 0?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);let i=this.subarray(t,e);return Object.setPrototypeOf(i,g.prototype),i};function ft(r,t,e){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>e)throw new RangeError("Trying to access beyond buffer length")}g.prototype.readUintLE=g.prototype.readUIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ft(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return i};g.prototype.readUintBE=g.prototype.readUIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ft(t,e,this.length);let i=this[t+--e],o=1;for(;e>0&&(o*=256);)i+=this[t+--e]*o;return i};g.prototype.readUint8=g.prototype.readUInt8=function(t,e){return t=t>>>0,e||ft(t,1,this.length),this[t]};g.prototype.readUint16LE=g.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||ft(t,2,this.length),this[t]|this[t+1]<<8};g.prototype.readUint16BE=g.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||ft(t,2,this.length),this[t]<<8|this[t+1]};g.prototype.readUint32LE=g.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};g.prototype.readUint32BE=g.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};g.prototype.readBigUInt64LE=ge(function(t){t=t>>>0,pr(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&Hr(t,this.length-8);let i=e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});g.prototype.readBigUInt64BE=ge(function(t){t=t>>>0,pr(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&Hr(t,this.length-8);let i=e*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});g.prototype.readIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ft(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i};g.prototype.readIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ft(t,e,this.length);let i=e,o=1,s=this[t+--i];for(;i>0&&(o*=256);)s+=this[t+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*e)),s};g.prototype.readInt8=function(t,e){return t=t>>>0,e||ft(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};g.prototype.readInt16LE=function(t,e){t=t>>>0,e||ft(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};g.prototype.readInt16BE=function(t,e){t=t>>>0,e||ft(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};g.prototype.readInt32LE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};g.prototype.readInt32BE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};g.prototype.readBigInt64LE=ge(function(t){t=t>>>0,pr(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&Hr(t,this.length-8);let i=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});g.prototype.readBigInt64BE=ge(function(t){t=t>>>0,pr(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&Hr(t,this.length-8);let i=(e<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n)});g.prototype.readFloatLE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),dr.read(this,t,!0,23,4)};g.prototype.readFloatBE=function(t,e){return t=t>>>0,e||ft(t,4,this.length),dr.read(this,t,!1,23,4)};g.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||ft(t,8,this.length),dr.read(this,t,!0,52,8)};g.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||ft(t,8,this.length),dr.read(this,t,!1,52,8)};function wt(r,t,e,n,i,o){if(!g.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(e+n>r.length)throw new RangeError("Index out of range")}g.prototype.writeUintLE=g.prototype.writeUIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;wt(this,t,e,n,c,0)}let o=1,s=0;for(this[e]=t&255;++s<n&&(o*=256);)this[e+s]=t/o&255;return e+n};g.prototype.writeUintBE=g.prototype.writeUIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;wt(this,t,e,n,c,0)}let o=n-1,s=1;for(this[e+o]=t&255;--o>=0&&(s*=256);)this[e+o]=t/s&255;return e+n};g.prototype.writeUint8=g.prototype.writeUInt8=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,1,255,0),this[e]=t&255,e+1};g.prototype.writeUint16LE=g.prototype.writeUInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2};g.prototype.writeUint16BE=g.prototype.writeUInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2};g.prototype.writeUint32LE=g.prototype.writeUInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4};g.prototype.writeUint32BE=g.prototype.writeUInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function xc(r,t,e,n,i){Bc(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,e}function bc(r,t,e,n,i){Bc(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e+7]=o,o=o>>8,r[e+6]=o,o=o>>8,r[e+5]=o,o=o>>8,r[e+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e+3]=s,s=s>>8,r[e+2]=s,s=s>>8,r[e+1]=s,s=s>>8,r[e]=s,e+8}g.prototype.writeBigUInt64LE=ge(function(t,e=0){return xc(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeBigUInt64BE=ge(function(t,e=0){return bc(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);wt(this,t,e,n,a-1,-a)}let o=0,s=1,c=0;for(this[e]=t&255;++o<n&&(s*=256);)t<0&&c===0&&this[e+o-1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};g.prototype.writeIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);wt(this,t,e,n,a-1,-a)}let o=n-1,s=1,c=0;for(this[e+o]=t&255;--o>=0&&(s*=256);)t<0&&c===0&&this[e+o+1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};g.prototype.writeInt8=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1};g.prototype.writeInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2};g.prototype.writeInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2};g.prototype.writeInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4};g.prototype.writeInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||wt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};g.prototype.writeBigInt64LE=ge(function(t,e=0){return xc(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});g.prototype.writeBigInt64BE=ge(function(t,e=0){return bc(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ec(r,t,e,n,i,o){if(e+n>r.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function vc(r,t,e,n,i){return t=+t,e=e>>>0,i||Ec(r,t,e,4,34028234663852886e22,-34028234663852886e22),dr.write(r,t,e,n,23,4),e+4}g.prototype.writeFloatLE=function(t,e,n){return vc(this,t,e,!0,n)};g.prototype.writeFloatBE=function(t,e,n){return vc(this,t,e,!1,n)};function Ac(r,t,e,n,i){return t=+t,e=e>>>0,i||Ec(r,t,e,8,17976931348623157e292,-17976931348623157e292),dr.write(r,t,e,n,52,8),e+8}g.prototype.writeDoubleLE=function(t,e,n){return Ac(this,t,e,!0,n)};g.prototype.writeDoubleBE=function(t,e,n){return Ac(this,t,e,!1,n)};g.prototype.copy=function(t,e,n,i){if(!g.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(e<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),t.length-e<i-n&&(i=t.length-e+n);let o=i-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),e),o};g.prototype.fill=function(t,e,n,i){if(typeof t=="string"){if(typeof e=="string"?(i=e,e=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"&&!g.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(t.length===1){let s=t.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e=e>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let o;if(typeof t=="number")for(o=e;o<n;++o)this[o]=t;else{let s=g.isBuffer(t)?t:g.from(t,i),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<n-e;++o)this[o+e]=s[o%c]}return this};var lr={};function Qi(r,t,e){lr[r]=class extends e{constructor(){super(),Object.defineProperty(this,"message",{value:t.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}`}}}Qi("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Qi("ERR_INVALID_ARG_TYPE",function(r,t){return`The "${r}" argument must be of type number. Received type ${typeof t}`},TypeError);Qi("ERR_OUT_OF_RANGE",function(r,t,e){let n=`The value of "${r}" is out of range.`,i=e;return Number.isInteger(e)&&Math.abs(e)>2**32?i=dc(String(e)):typeof e=="bigint"&&(i=String(e),(e>BigInt(2)**BigInt(32)||e<-(BigInt(2)**BigInt(32)))&&(i=dc(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);function dc(r){let t="",e=r.length,n=r[0]==="-"?1:0;for(;e>=n+4;e-=3)t=`_${r.slice(e-3,e)}${t}`;return`${r.slice(0,e)}${t}`}function ph(r,t,e){pr(t,"offset"),(r[t]===void 0||r[t+e]===void 0)&&Hr(t,r.length-(e+1))}function Bc(r,t,e,n,i,o){if(r>e||r<t){let s=typeof t=="bigint"?"n":"",c;throw o>3?t===0||t===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=`>= ${t}${s} and <= ${e}${s}`,new lr.ERR_OUT_OF_RANGE("value",c,r)}ph(n,i,o)}function pr(r,t){if(typeof r!="number")throw new lr.ERR_INVALID_ARG_TYPE(t,"number",r)}function Hr(r,t,e){throw Math.floor(r)!==r?(pr(r,e),new lr.ERR_OUT_OF_RANGE(e||"offset","an integer",r)):t<0?new lr.ERR_BUFFER_OUT_OF_BOUNDS:new lr.ERR_OUT_OF_RANGE(e||"offset",`>= ${e?1:0} and <= ${t}`,r)}var yh=/[^+/0-9A-Za-z-_]/g;function mh(r){if(r=r.split("=")[0],r=r.trim().replace(yh,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Zi(r,t){t=t||1/0;let e,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(e=r.charCodeAt(s),e>55295&&e<57344){if(!i){if(e>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(t-=3)>-1&&o.push(239,191,189),i=e;continue}e=(i-55296<<10|e-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((t-=1)<0)break;o.push(e)}else if(e<2048){if((t-=2)<0)break;o.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;o.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return o}function wh(r){let t=[];for(let e=0;e<r.length;++e)t.push(r.charCodeAt(e)&255);return t}function gh(r,t){let e,n,i,o=[];for(let s=0;s<r.length&&!((t-=2)<0);++s)e=r.charCodeAt(s),n=e>>8,i=e%256,o.push(i),o.push(n);return o}function Tc(r){return $i.toByteArray(mh(r))}function Tn(r,t,e,n){let i;for(i=0;i<n&&!(i+e>=t.length||i>=r.length);++i)t[i+e]=r[i];return i}function qt(r,t){return r instanceof t||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===t.name}function to(r){return r!==r}var xh=function(){let r="0123456789abcdef",t=new Array(256);for(let e=0;e<16;++e){let n=e*16;for(let i=0;i<16;++i)t[n+i]=r[e]+r[i]}return t}();function ge(r){return typeof BigInt>"u"?bh:r}function bh(){throw new Error("BigInt not supported")}});var ro=Y((hy,Sc)=>{"use strict";var eo=null;Sc.exports=function(){return eo===null&&(eo={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),eo}});var oo=Y(kc=>{"use strict";var no=Ct(),Eh=new Set(["buffer","view","utf8"]),io=class{constructor(t){if(this.encode=t.encode||this.encode,this.decode=t.decode||this.decode,this.name=t.name||this.name,this.format=t.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"||!Eh.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");t.createViewTranscoder&&(this.createViewTranscoder=t.createViewTranscoder),t.createBufferTranscoder&&(this.createBufferTranscoder=t.createBufferTranscoder),t.createUTF8Transcoder&&(this.createUTF8Transcoder=t.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new no(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new no(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new no(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};kc.Encoding=io});var fo=Y(kn=>{"use strict";var{Buffer:co}=Sn()||{},{Encoding:ao}=oo(),vh=ro(),Gr=class extends ao{constructor(t){super({...t,format:"buffer"})}createViewTranscoder(){return new qr({encode:this.encode,decode:t=>this.decode(co.from(t.buffer,t.byteOffset,t.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},qr=class extends ao{constructor(t){super({...t,format:"view"})}createBufferTranscoder(){return new Gr({encode:t=>{let e=this.encode(t);return co.from(e.buffer,e.byteOffset,e.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},so=class extends ao{constructor(t){super({...t,format:"utf8"})}createBufferTranscoder(){return new Gr({encode:t=>co.from(this.encode(t),"utf8"),decode:t=>this.decode(t.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:t,textDecoder:e}=vh();return new qr({encode:n=>t.encode(this.encode(n)),decode:n=>this.decode(e.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};kn.BufferFormat=Gr;kn.ViewFormat=qr;kn.UTF8Format=so});var Ic=Y(Ge=>{"use strict";var{Buffer:pt}=Sn()||{Buffer:{isBuffer:()=>!1}},{textEncoder:Uc,textDecoder:Pc}=ro()(),{BufferFormat:Fr,ViewFormat:uo,UTF8Format:Kc}=fo(),Pn=r=>r;Ge.utf8=new Kc({encode:function(r){return pt.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?Pc.decode(r):String(r)},decode:Pn,name:"utf8",createViewTranscoder(){return new uo({encode:function(r){return ArrayBuffer.isView(r)?r:Uc.encode(r)},decode:function(r){return Pc.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new Fr({encode:function(r){return pt.isBuffer(r)?r:ArrayBuffer.isView(r)?pt.from(r.buffer,r.byteOffset,r.byteLength):pt.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Ge.json=new Kc({encode:JSON.stringify,decode:JSON.parse,name:"json"});Ge.buffer=new Fr({encode:function(r){return pt.isBuffer(r)?r:ArrayBuffer.isView(r)?pt.from(r.buffer,r.byteOffset,r.byteLength):pt.from(String(r),"utf8")},decode:Pn,name:"buffer",createViewTranscoder(){return new uo({encode:function(r){return ArrayBuffer.isView(r)?r:pt.from(String(r),"utf8")},decode:function(r){return pt.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Ge.view=new uo({encode:function(r){return ArrayBuffer.isView(r)?r:Uc.encode(r)},decode:Pn,name:"view",createBufferTranscoder(){return new Fr({encode:function(r){return pt.isBuffer(r)?r:ArrayBuffer.isView(r)?pt.from(r.buffer,r.byteOffset,r.byteLength):pt.from(String(r),"utf8")},decode:Pn,name:`${this.name}+buffer`})}});Ge.hex=new Fr({encode:function(r){return pt.isBuffer(r)?r:pt.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Ge.base64=new Fr({encode:function(r){return pt.isBuffer(r)?r:pt.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var Lc=Y(Cc=>{"use strict";var _c=Ct(),Kn=Ic(),{Encoding:Ah}=oo(),{BufferFormat:Bh,ViewFormat:Th,UTF8Format:Sh}=fo(),$r=Symbol("formats"),Un=Symbol("encodings"),kh=new Set(["buffer","view","utf8"]),ho=class{constructor(t){if(Array.isArray(t)){if(!t.every(e=>kh.has(e)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[Un]=new Map,this[$r]=new Set(t);for(let e in Kn)try{this.encoding(e)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Un].values()))}encoding(t){let e=this[Un].get(t);if(e===void 0){if(typeof t=="string"&&t!==""){if(e=Ih[t],!e)throw new _c(`Encoding '${t}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof t!="object"||t===null)throw new TypeError("First argument 'encoding' must be a string or object");e=Ph(t)}let{name:n,format:i}=e;if(!this[$r].has(i))if(this[$r].has("view"))e=e.createViewTranscoder();else if(this[$r].has("buffer"))e=e.createBufferTranscoder();else if(this[$r].has("utf8"))e=e.createUTF8Transcoder();else throw new _c(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[t,n,e.name,e.commonName])this[Un].set(o,e)}return e}};Cc.Transcoder=ho;function Ph(r){if(r instanceof Ah)return r;let t="type"in r&&typeof r.type=="string"?r.type:void 0,e=r.name||t||`anonymous-${_h++}`;switch(Uh(r)){case"view":return new Th({...r,name:e});case"utf8":return new Sh({...r,name:e});case"buffer":return new Bh({...r,name:e});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function Uh(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 Kh={binary:Kn.buffer,"utf-8":Kn.utf8},Ih={...Kn,...Kh},_h=0});var qc=Y((my,lo)=>{"use strict";var mr=typeof Reflect=="object"?Reflect:null,Oc=mr&&typeof mr.apply=="function"?mr.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)},In;mr&&typeof mr.ownKeys=="function"?In=mr.ownKeys:Object.getOwnPropertySymbols?In=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:In=function(t){return Object.getOwnPropertyNames(t)};function Ch(r){console&&console.warn&&console.warn(r)}var Nc=Number.isNaN||function(t){return t!==t};function tt(){tt.init.call(this)}lo.exports=tt;lo.exports.once=Nh;tt.EventEmitter=tt;tt.prototype._events=void 0;tt.prototype._eventsCount=0;tt.prototype._maxListeners=void 0;var Rc=10;function _n(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(tt,"defaultMaxListeners",{enumerable:!0,get:function(){return Rc},set:function(r){if(typeof r!="number"||r<0||Nc(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");Rc=r}});tt.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};tt.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Nc(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Dc(r){return r._maxListeners===void 0?tt.defaultMaxListeners:r._maxListeners}tt.prototype.getMaxListeners=function(){return Dc(this)};tt.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var i=t==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var a=o[t];if(a===void 0)return!1;if(typeof a=="function")Oc(a,this,e);else for(var f=a.length,u=Hc(a,f),n=0;n<f;++n)Oc(u[n],this,e);return!0};function Mc(r,t,e,n){var i,o,s;if(_n(e),o=r._events,o===void 0?(o=r._events=Object.create(null),r._eventsCount=0):(o.newListener!==void 0&&(r.emit("newListener",t,e.listener?e.listener:e),o=r._events),s=o[t]),s===void 0)s=o[t]=e,++r._eventsCount;else if(typeof s=="function"?s=o[t]=n?[e,s]:[s,e]:n?s.unshift(e):s.push(e),i=Dc(r),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=r,c.type=t,c.count=s.length,Ch(c)}return r}tt.prototype.addListener=function(t,e){return Mc(this,t,e,!1)};tt.prototype.on=tt.prototype.addListener;tt.prototype.prependListener=function(t,e){return Mc(this,t,e,!0)};function Lh(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function jc(r,t,e){var n={fired:!1,wrapFn:void 0,target:r,type:t,listener:e},i=Lh.bind(n);return i.listener=e,n.wrapFn=i,i}tt.prototype.once=function(t,e){return _n(e),this.on(t,jc(this,t,e)),this};tt.prototype.prependOnceListener=function(t,e){return _n(e),this.prependListener(t,jc(this,t,e)),this};tt.prototype.removeListener=function(t,e){var n,i,o,s,c;if(_n(e),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===e||n.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||e));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===e||n[s].listener===e){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Oh(n,o),n.length===1&&(i[t]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",t,c||e)}return this};tt.prototype.off=tt.prototype.removeListener;tt.prototype.removeAllListeners=function(t){var e,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=n[t],typeof e=="function")this.removeListener(t,e);else if(e!==void 0)for(i=e.length-1;i>=0;i--)this.removeListener(t,e[i]);return this};function Jc(r,t,e){var n=r._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?e?[i.listener||i]:[i]:e?Rh(i):Hc(i,i.length)}tt.prototype.listeners=function(t){return Jc(this,t,!0)};tt.prototype.rawListeners=function(t){return Jc(this,t,!1)};tt.listenerCount=function(r,t){return typeof r.listenerCount=="function"?r.listenerCount(t):Vc.call(r,t)};tt.prototype.listenerCount=Vc;function Vc(r){var t=this._events;if(t!==void 0){var e=t[r];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}tt.prototype.eventNames=function(){return this._eventsCount>0?In(this._events):[]};function Hc(r,t){for(var e=new Array(t),n=0;n<t;++n)e[n]=r[n];return e}function Oh(r,t){for(;t+1<r.length;t++)r[t]=r[t+1];r.pop()}function Rh(r){for(var t=new Array(r.length),e=0;e<t.length;++e)t[e]=r[e].listener||r[e];return t}function Nh(r,t){return new Promise(function(e,n){function i(s){r.removeListener(t,o),n(s)}function o(){typeof r.removeListener=="function"&&r.removeListener("error",i),e([].slice.call(arguments))}Gc(r,t,o,{once:!0}),t!=="error"&&Dh(r,i,{once:!0})})}function Dh(r,t,e){typeof r.on=="function"&&Gc(r,"error",t,e)}function Gc(r,t,e,n){if(typeof r.on=="function")n.once?r.once(t,e):r.on(t,e);else if(typeof r.addEventListener=="function")r.addEventListener(t,function i(o){n.once&&r.removeEventListener(t,i),e(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r)}});var $c=Y((wy,Fc)=>{Fc.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var Wr=Y(po=>{"use strict";var Wc=$c();po.fromCallback=function(r,t){if(r===void 0){var e=new Promise(function(n,i){r=function(o,s){o?i(o):n(s)}});r[t!==void 0?t:"promise"]=e}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r};po.fromPromise=function(r,t){if(t===void 0)return r;r.then(function(e){Wc(()=>t(null,e))}).catch(function(e){Wc(()=>t(e))})}});var Cn=Y(yo=>{"use strict";yo.getCallback=function(r,t){return typeof r=="function"?r:t};yo.getOptions=function(r,t){return typeof r=="object"&&r!==null?r:t!==void 0?t:{}}});var Be=Y(Nn=>{"use strict";var{fromCallback:mo}=Wr(),Et=Ct(),{getOptions:wo,getCallback:zc}=Cn(),qe=Symbol("promise"),wr=Symbol("callback"),Ft=Symbol("working"),Fe=Symbol("handleOne"),ne=Symbol("handleMany"),go=Symbol("autoClose"),ve=Symbol("finishWork"),$t=Symbol("returnMany"),xe=Symbol("closing"),zr=Symbol("handleClose"),Ln=Symbol("closed"),Zr=Symbol("closeCallbacks"),Ee=Symbol("keyEncoding"),$e=Symbol("valueEncoding"),xo=Symbol("abortOnClose"),On=Symbol("legacy"),bo=Symbol("keys"),Eo=Symbol("values"),be=Symbol("limit"),kt=Symbol("count"),Rn=Object.freeze({}),Mh=()=>{},Zc=!1,Yr=class{constructor(t,e,n){if(typeof t!="object"||t===null){let i=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof e!="object"||e===null)throw new TypeError("The second argument must be an options object");this[Ln]=!1,this[Zr]=[],this[Ft]=!1,this[xe]=!1,this[go]=!1,this[wr]=null,this[Fe]=this[Fe].bind(this),this[ne]=this[ne].bind(this),this[zr]=this[zr].bind(this),this[Ee]=e[Ee],this[$e]=e[$e],this[On]=n,this[be]=Number.isInteger(e.limit)&&e.limit>=0?e.limit:1/0,this[kt]=0,this[xo]=!!e.abortOnClose,this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get count(){return this[kt]}get limit(){return this[be]}next(t){let e;if(t===void 0)e=new Promise((n,i)=>{t=(o,s,c)=>{o?i(o):this[On]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof t!="function")throw new TypeError("Callback must be a function");return this[xe]?this.nextTick(t,new Et("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Ft]?this.nextTick(t,new Et("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Ft]=!0,this[wr]=t,this[kt]>=this[be]?this.nextTick(this[Fe],null):this._next(this[Fe])),e}_next(t){this.nextTick(t)}nextv(t,e,n){return n=zc(e,n),n=mo(n,qe),e=wo(e,Rn),Number.isInteger(t)?(this[xe]?this.nextTick(n,new Et("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Ft]?this.nextTick(n,new Et("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(t<1&&(t=1),this[be]<1/0&&(t=Math.min(t,this[be]-this[kt])),this[Ft]=!0,this[wr]=n,t<=0?this.nextTick(this[ne],null,[]):this._nextv(t,e,this[ne])),n[qe]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[qe])}_nextv(t,e,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[On]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[On]?[c,a]:c),i.length===t?n(null,i):this._next(o)};this._next(o)}all(t,e){return e=zc(t,e),e=mo(e,qe),t=wo(t,Rn),this[xe]?this.nextTick(e,new Et("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[Ft]?this.nextTick(e,new Et("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[Ft]=!0,this[wr]=e,this[go]=!0,this[kt]>=this[be]?this.nextTick(this[ne],null,[]):this._all(t,this[ne])),e[qe]}_all(t,e){let n=this[kt],i=[],o=()=>{let c=this[be]<1/0?Math.min(1e3,this[be]-n):1e3;c<=0?this.nextTick(e,null,i):this._nextv(c,Rn,s)},s=(c,a)=>{c?e(c):a.length===0?e(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[ve](){let t=this[wr];return this[xo]&&t===null?Mh:(this[Ft]=!1,this[wr]=null,this[xe]&&this._close(this[zr]),t)}[$t](t,e,n){this[go]?this.close(t.bind(null,e,n)):t(e,n)}seek(t,e){if(e=wo(e,Rn),!this[xe]){if(this[Ft])throw new Et("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(e.keyEncoding||this[Ee]),i=n.format;e.keyEncoding!==i&&(e={...e,keyEncoding:i});let o=this.db.prefixKey(n.encode(t),i);this._seek(o,e)}}}_seek(t,e){throw new Et("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(t){return t=mo(t,qe),this[Ln]?this.nextTick(t):this[xe]?this[Zr].push(t):(this[xe]=!0,this[Zr].push(t),this[Ft]?this[xo]&&this[ve]()(new Et("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[zr])),t[qe]}_close(t){this.nextTick(t)}[zr](){this[Ln]=!0,this.db.detachResource(this);let t=this[Zr];this[Zr]=[];for(let e of t)e()}async*[Symbol.asyncIterator](){try{let t;for(;(t=await this.next())!==void 0;)yield t}finally{this[Ln]||await this.close()}}},gr=class extends Yr{constructor(t,e){super(t,e,!0),this[bo]=e.keys!==!1,this[Eo]=e.values!==!1}[Fe](t,e,n){let i=this[ve]();if(t)return i(t);try{e=this[bo]&&e!==void 0?this[Ee].decode(e):void 0,n=this[Eo]&&n!==void 0?this[$e].decode(n):void 0}catch(o){return i(new Ae("entry",o))}e===void 0&&n===void 0||this[kt]++,i(null,e,n)}[ne](t,e){let n=this[ve]();if(t)return this[$t](n,t);try{for(let i of e){let o=i[0],s=i[1];i[0]=this[bo]&&o!==void 0?this[Ee].decode(o):void 0,i[1]=this[Eo]&&s!==void 0?this[$e].decode(s):void 0}}catch(i){return this[$t](n,new Ae("entries",i))}this[kt]+=e.length,this[$t](n,null,e)}end(t){return!Zc&&typeof console<"u"&&(Zc=!0,console.warn(new Et("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(t)}},vo=class extends Yr{constructor(t,e){super(t,e,!1)}[Fe](t,e){let n=this[ve]();if(t)return n(t);try{e=e!==void 0?this[Ee].decode(e):void 0}catch(i){return n(new Ae("key",i))}e!==void 0&&this[kt]++,n(null,e)}[ne](t,e){let n=this[ve]();if(t)return this[$t](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[Ee].decode(o):void 0}}catch(i){return this[$t](n,new Ae("keys",i))}this[kt]+=e.length,this[$t](n,null,e)}},Ao=class extends Yr{constructor(t,e){super(t,e,!1)}[Fe](t,e){let n=this[ve]();if(t)return n(t);try{e=e!==void 0?this[$e].decode(e):void 0}catch(i){return n(new Ae("value",i))}e!==void 0&&this[kt]++,n(null,e)}[ne](t,e){let n=this[ve]();if(t)return this[$t](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[$e].decode(o):void 0}}catch(i){return this[$t](n,new Ae("values",i))}this[kt]+=e.length,this[$t](n,null,e)}},Ae=class extends Et{constructor(t,e){super(`Iterator could not decode ${t}`,{code:"LEVEL_DECODE_ERROR",cause:e})}};for(let r of["_ended property","_nexting property","_end method"])Object.defineProperty(gr.prototype,r.split(" ")[0],{get(){throw new Et(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Et(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});gr.keyEncoding=Ee;gr.valueEncoding=$e;Nn.AbstractIterator=gr;Nn.AbstractKeyIterator=vo;Nn.AbstractValueIterator=Ao});var Yc=Y(Bo=>{"use strict";var{AbstractKeyIterator:jh,AbstractValueIterator:Jh}=Be(),We=Symbol("iterator"),Xr=Symbol("callback"),xr=Symbol("handleOne"),ze=Symbol("handleMany"),Qr=class extends jh{constructor(t,e){super(t,e),this[We]=t.iterator({...e,keys:!0,values:!1}),this[xr]=this[xr].bind(this),this[ze]=this[ze].bind(this)}},Dn=class extends Jh{constructor(t,e){super(t,e),this[We]=t.iterator({...e,keys:!1,values:!0}),this[xr]=this[xr].bind(this),this[ze]=this[ze].bind(this)}};for(let r of[Qr,Dn]){let t=r===Qr,e=t?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[Xr]=n,this[We].next(this[xr])},r.prototype[xr]=function(n,i,o){let s=this[Xr];n?s(n):s(null,t?i:o)},r.prototype._nextv=function(n,i,o){this[Xr]=o,this[We].nextv(n,i,this[ze])},r.prototype._all=function(n,i){this[Xr]=i,this[We].all(n,this[ze])},r.prototype[ze]=function(n,i){let o=this[Xr];n?o(n):o(null,i.map(e))},r.prototype._seek=function(n,i){this[We].seek(n,i)},r.prototype._close=function(n){this[We].close(n)}}Bo.DefaultKeyIterator=Qr;Bo.DefaultValueIterator=Dn});var Xc=Y(Gn=>{"use strict";var{AbstractIterator:Vh,AbstractKeyIterator:Hh,AbstractValueIterator:Gh}=Be(),To=Ct(),gt=Symbol("nut"),Vn=Symbol("undefer"),Hn=Symbol("factory"),Mn=class extends Vh{constructor(t,e){super(t,e),this[gt]=null,this[Hn]=()=>t.iterator(e),this.db.defer(()=>this[Vn]())}},jn=class extends Hh{constructor(t,e){super(t,e),this[gt]=null,this[Hn]=()=>t.keys(e),this.db.defer(()=>this[Vn]())}},Jn=class extends Gh{constructor(t,e){super(t,e),this[gt]=null,this[Hn]=()=>t.values(e),this.db.defer(()=>this[Vn]())}};for(let r of[Mn,jn,Jn])r.prototype[Vn]=function(){this.db.status==="open"&&(this[gt]=this[Hn]())},r.prototype._next=function(t){this[gt]!==null?this[gt].next(t):this.db.status==="opening"?this.db.defer(()=>this._next(t)):this.nextTick(t,new To("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(t,e,n){this[gt]!==null?this[gt].nextv(t,e,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(t,e,n)):this.nextTick(n,new To("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(t,e){this[gt]!==null?this[gt].all(e):this.db.status==="opening"?this.db.defer(()=>this._all(t,e)):this.nextTick(e,new To("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(t,e){this[gt]!==null?this[gt]._seek(t,e):this.db.status==="opening"&&this.db.defer(()=>this._seek(t,e))},r.prototype._close=function(t){this[gt]!==null?this[gt].close(t):this.db.status==="opening"?this.db.defer(()=>this._close(t)):this.nextTick(t)};Gn.DeferredIterator=Mn;Gn.DeferredKeyIterator=jn;Gn.DeferredValueIterator=Jn});var ko=Y(ta=>{"use strict";var{fromCallback:Qc}=Wr(),qn=Ct(),{getCallback:qh,getOptions:Fh}=Cn(),Fn=Symbol("promise"),Pt=Symbol("status"),br=Symbol("operations"),tn=Symbol("finishClose"),Er=Symbol("closeCallbacks"),So=class{constructor(t){if(typeof t!="object"||t===null){let e=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${e}`)}this[br]=[],this[Er]=[],this[Pt]="open",this[tn]=this[tn].bind(this),this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get length(){return this[br].length}put(t,e,n){if(this[Pt]!=="open")throw new qn("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(t)||this.db._checkValue(e);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),a=o.valueEncoding(n&&n.valueEncoding),f=c.format;n={...n,keyEncoding:f,valueEncoding:a.format},o!==this.db&&(n.sublevel=null);let u=o.prefixKey(c.encode(t),f),h=a.encode(e);return this._put(u,h,n),this[br].push({...s,type:"put",key:t,value:e}),this}_put(t,e,n){}del(t,e){if(this[Pt]!=="open")throw new qn("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(t);if(n)throw n;let i=e&&e.sublevel!=null?e.sublevel:this.db,o=e,s=i.keyEncoding(e&&e.keyEncoding),c=s.format;return e={...e,keyEncoding:c},i!==this.db&&(e.sublevel=null),this._del(i.prefixKey(s.encode(t),c),e),this[br].push({...o,type:"del",key:t}),this}_del(t,e){}clear(){if(this[Pt]!=="open")throw new qn("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[br]=[],this}_clear(){}write(t,e){return e=qh(t,e),e=Qc(e,Fn),t=Fh(t),this[Pt]!=="open"?this.nextTick(e,new qn("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(e):(this[Pt]="writing",this._write(t,n=>{this[Pt]="closing",this[Er].push(()=>e(n)),n||this.db.emit("batch",this[br]),this._close(this[tn])})),e[Fn]}_write(t,e){}close(t){return t=Qc(t,Fn),this[Pt]==="closing"?this[Er].push(t):this[Pt]==="closed"?this.nextTick(t):(this[Er].push(t),this[Pt]!=="writing"&&(this[Pt]="closing",this._close(this[tn]))),t[Fn]}_close(t){this.nextTick(t)}[tn](){this[Pt]="closed",this.db.detachResource(this);let t=this[Er];this[Er]=[];for(let e of t)e()}};ta.AbstractChainedBatch=So});var ra=Y(ea=>{"use strict";var{AbstractChainedBatch:$h}=ko(),Wh=Ct(),vr=Symbol("encoded"),Po=class extends $h{constructor(t){super(t),this[vr]=[]}_put(t,e,n){this[vr].push({...n,type:"put",key:t,value:e})}_del(t,e){this[vr].push({...e,type:"del",key:t})}_clear(){this[vr]=[]}_write(t,e){this.db.status==="opening"?this.db.defer(()=>this._write(t,e)):this.db.status==="open"?this[vr].length===0?this.nextTick(e):this.db._batch(this[vr],t,e):this.nextTick(e,new Wh("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};ea.DefaultChainedBatch=Po});var oa=Y((Ty,ia)=>{"use strict";var na=Ct(),zh=Object.prototype.hasOwnProperty,Zh=new Set(["lt","lte","gt","gte"]);ia.exports=function(r,t){let e={};for(let n in r)if(zh.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new na(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new na("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});Zh.has(n)?e[n]=t.encode(r[n]):e[n]=r[n]}return e.reverse=!!e.reverse,e.limit=Number.isInteger(e.limit)&&e.limit>=0?e.limit:-1,e}});var Uo=Y((Sy,ca)=>{var sa;ca.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(sa||(sa=Promise.resolve())).then(r).catch(t=>setTimeout(()=>{throw t},0))});var ua=Y((ky,fa)=>{"use strict";var aa=Uo();fa.exports=function(r,...t){t.length===0?aa(r):aa(()=>r(...t))}});var ha=Y($n=>{"use strict";var{AbstractIterator:Yh,AbstractKeyIterator:Xh,AbstractValueIterator:Qh}=Be(),Ar=Symbol("unfix"),Lt=Symbol("iterator"),Ze=Symbol("handleOne"),Te=Symbol("handleMany"),ie=Symbol("callback"),en=class extends Yh{constructor(t,e,n,i){super(t,e),this[Lt]=n,this[Ar]=i,this[Ze]=this[Ze].bind(this),this[Te]=this[Te].bind(this),this[ie]=null}[Ze](t,e,n){let i=this[ie];if(t)return i(t);e!==void 0&&(e=this[Ar](e)),i(t,e,n)}[Te](t,e){let n=this[ie];if(t)return n(t);for(let i of e){let o=i[0];o!==void 0&&(i[0]=this[Ar](o))}n(t,e)}},rn=class extends Xh{constructor(t,e,n,i){super(t,e),this[Lt]=n,this[Ar]=i,this[Ze]=this[Ze].bind(this),this[Te]=this[Te].bind(this),this[ie]=null}[Ze](t,e){let n=this[ie];if(t)return n(t);e!==void 0&&(e=this[Ar](e)),n(t,e)}[Te](t,e){let n=this[ie];if(t)return n(t);for(let i=0;i<e.length;i++){let o=e[i];o!==void 0&&(e[i]=this[Ar](o))}n(t,e)}},nn=class extends Qh{constructor(t,e,n){super(t,e),this[Lt]=n}};for(let r of[en,rn])r.prototype._next=function(t){this[ie]=t,this[Lt].next(this[Ze])},r.prototype._nextv=function(t,e,n){this[ie]=n,this[Lt].nextv(t,e,this[Te])},r.prototype._all=function(t,e){this[ie]=e,this[Lt].all(t,this[Te])};for(let r of[nn])r.prototype._next=function(t){this[Lt].next(t)},r.prototype._nextv=function(t,e,n){this[Lt].nextv(t,e,n)},r.prototype._all=function(t,e){this[Lt].all(t,e)};for(let r of[en,rn,nn])r.prototype._seek=function(t,e){this[Lt].seek(t,e)},r.prototype._close=function(t){this[Lt].close(t)};$n.AbstractSublevelIterator=en;$n.AbstractSublevelKeyIterator=rn;$n.AbstractSublevelValueIterator=nn});var ya=Y((Uy,pa)=>{"use strict";var Ko=Ct(),{Buffer:Co}=Sn()||{},{AbstractSublevelIterator:tl,AbstractSublevelKeyIterator:el,AbstractSublevelValueIterator:rl}=ha(),oe=Symbol("prefix"),la=Symbol("upperBound"),on=Symbol("prefixRange"),vt=Symbol("parent"),Io=Symbol("unfix"),da=new TextEncoder,nl={separator:"!"};pa.exports=function({AbstractLevel:r}){class t extends r{static defaults(n){if(typeof n=="string")throw new Ko("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new Ko("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?nl:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=t.defaults(o);i=ol(i,s);let f=s.charCodeAt(0)+1,u=n[vt]||n;if(!da.encode(i).every(x=>x>f&&x<127))throw new Ko(`Prefix must use bytes > ${f} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(il(u,c),a);let h=(n.prefix||"")+s+i+s,y=h.slice(0,-1)+String.fromCharCode(f);this[vt]=u,this[oe]=new Wn(h),this[la]=new Wn(y),this[Io]=new Lo,this.nextTick=u.nextTick}prefixKey(n,i){if(i==="utf8")return this[oe].utf8+n;if(n.byteLength===0)return this[oe][i];if(i==="view"){let o=this[oe].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[oe].buffer;return Co.concat([o,n],o.byteLength+n.byteLength)}}[on](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[oe][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[la][i]}get prefix(){return this[oe].utf8}get db(){return this[vt]}_open(n,i){this[vt].open({passive:!0},i)}_put(n,i,o,s){this[vt].put(n,i,o,s)}_get(n,i,o){this[vt].get(n,i,o)}_getMany(n,i,o){this[vt].getMany(n,i,o)}_del(n,i,o){this[vt].del(n,i,o)}_batch(n,i,o){this[vt].batch(n,i,o)}_clear(n,i){this[on](n,n.keyEncoding),this[vt].clear(n,i)}_iterator(n){this[on](n,n.keyEncoding);let i=this[vt].iterator(n),o=this[Io].get(this[oe].utf8.length,n.keyEncoding);return new tl(this,n,i,o)}_keys(n){this[on](n,n.keyEncoding);let i=this[vt].keys(n),o=this[Io].get(this[oe].utf8.length,n.keyEncoding);return new el(this,n,i,o)}_values(n){this[on](n,n.keyEncoding);let i=this[vt].values(n);return new rl(this,n,i)}}return{AbstractSublevel:t}};var il=function(r,t){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...t,encodings:{utf8:_o(r,"utf8"),buffer:_o(r,"buffer"),view:_o(r,"view")}}},_o=function(r,t){return r.supports.encodings[t]?r.keyEncoding(t).name===t:!1},Wn=class{constructor(t){this.utf8=t,this.view=da.encode(t),this.buffer=Co?Co.from(this.view.buffer,0,this.view.byteLength):{}}},Lo=class{constructor(){this.cache=new Map}get(t,e){let n=this.cache.get(e);return n===void 0&&(e==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,t):n=(function(i,o){return o.slice(i)}).bind(null,t),this.cache.set(e,n)),n}},ol=function(r,t){let e=0,n=r.length;for(;e<n&&r[e]===t;)e++;for(;n>e&&r[n-1]===t;)n--;return r.slice(e,n)}});var Mo=Y(Do=>{"use strict";var{supports:sl}=ic(),{Transcoder:cl}=Lc(),{EventEmitter:al}=qc(),{fromCallback:Se}=Wr(),Ot=Ct(),{AbstractIterator:Ye}=Be(),{DefaultKeyIterator:fl,DefaultValueIterator:ul}=Yc(),{DeferredIterator:hl,DeferredKeyIterator:ll,DeferredValueIterator:dl}=Xc(),{DefaultChainedBatch:ma}=ra(),{getCallback:Xe,getOptions:ke}=Cn(),zn=oa(),$=Symbol("promise"),se=Symbol("landed"),Qe=Symbol("resources"),Oo=Symbol("closeResources"),sn=Symbol("operations"),cn=Symbol("undefer"),Zn=Symbol("deferOpen"),wa=Symbol("options"),Z=Symbol("status"),tr=Symbol("defaultOptions"),Br=Symbol("transcoder"),Yn=Symbol("keyEncoding"),Ro=Symbol("valueEncoding"),pl=()=>{},an=class extends al{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new TypeError("The first argument 'manifest' must be an object");e=ke(e);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=e;this[Qe]=new Set,this[sn]=[],this[Zn]=!0,this[wa]=s,this[Z]="opening",this.supports=sl(t,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:t.snapshots!==!1,permanence:t.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:t.encodings||{},events:Object.assign({},t.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[Br]=new cl(yl(this)),this[Yn]=this[Br].encoding(n||"utf8"),this[Ro]=this[Br].encoding(i||"utf8");for(let c of this[Br].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[tr]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[Yn].commonName,valueEncoding:this[Ro].commonName}),key:Object.freeze({keyEncoding:this[Yn].commonName})},this.nextTick(()=>{this[Zn]&&this.open({passive:!1},pl)})}get status(){return this[Z]}keyEncoding(t){return this[Br].encoding(t??this[Yn])}valueEncoding(t){return this[Br].encoding(t??this[Ro])}open(t,e){e=Xe(t,e),e=Se(e,$),t={...this[wa],...ke(t)},t.createIfMissing=t.createIfMissing!==!1,t.errorIfExists=!!t.errorIfExists;let n=i=>{this[Z]==="closing"||this[Z]==="opening"?this.once(se,i?()=>n(i):n):this[Z]!=="open"?e(new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):e()};return t.passive?this[Z]==="opening"?this.once(se,n):this.nextTick(n):this[Z]==="closed"||this[Zn]?(this[Zn]=!1,this[Z]="opening",this.emit("opening"),this._open(t,i=>{if(i){this[Z]="closed",this[Oo](()=>{this.emit(se),n(i)}),this[cn]();return}this[Z]="open",this[cn](),this.emit(se),this[Z]==="open"&&this.emit("open"),this[Z]==="open"&&this.emit("ready"),n()})):this[Z]==="open"?this.nextTick(n):this.once(se,()=>this.open(t,e)),e[$]}_open(t,e){this.nextTick(e)}close(t){t=Se(t,$);let e=n=>{this[Z]==="opening"||this[Z]==="closing"?this.once(se,n?e(n):e):this[Z]!=="closed"?t(new Ot("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):t()};if(this[Z]==="open"){this[Z]="closing",this.emit("closing");let n=i=>{this[Z]="open",this[cn](),this.emit(se),e(i)};this[Oo](()=>{this._close(i=>{if(i)return n(i);this[Z]="closed",this[cn](),this.emit(se),this[Z]==="closed"&&this.emit("closed"),e()})})}else this[Z]==="closed"?this.nextTick(e):this.once(se,()=>this.close(t));return t[$]}[Oo](t){if(this[Qe].size===0)return this.nextTick(t);let e=this[Qe].size,n=!0,i=()=>{--e===0&&(n?this.nextTick(t):t())};for(let o of this[Qe])o.close(i);n=!1,this[Qe].clear()}_close(t){this.nextTick(t)}get(t,e,n){if(n=Xe(e,n),n=Se(n,$),e=ke(e,this[tr].entry),this[Z]==="opening")return this.defer(()=>this.get(t,e,n)),n[$];if(Tr(this,n))return n[$];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[$];let o=this.keyEncoding(e.keyEncoding),s=this.valueEncoding(e.valueEncoding),c=o.format,a=s.format;return(e.keyEncoding!==c||e.valueEncoding!==a)&&(e=Object.assign({},e,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(t),c),e,(f,u)=>{if(f)return(f.code==="LEVEL_NOT_FOUND"||f.notFound||/NotFound/i.test(f))&&(f.code||(f.code="LEVEL_NOT_FOUND"),f.notFound||(f.notFound=!0),f.status||(f.status=404)),n(f);try{u=s.decode(u)}catch(h){return n(new Ot("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:h}))}n(null,u)}),n[$]}_get(t,e,n){this.nextTick(n,new Error("NotFound"))}getMany(t,e,n){if(n=Xe(e,n),n=Se(n,$),e=ke(e,this[tr].entry),this[Z]==="opening")return this.defer(()=>this.getMany(t,e,n)),n[$];if(Tr(this,n))return n[$];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[$];if(t.length===0)return this.nextTick(n,null,[]),n[$];let i=this.keyEncoding(e.keyEncoding),o=this.valueEncoding(e.valueEncoding),s=i.format,c=o.format;(e.keyEncoding!==s||e.valueEncoding!==c)&&(e=Object.assign({},e,{keyEncoding:s,valueEncoding:c}));let a=new Array(t.length);for(let f=0;f<t.length;f++){let u=t[f],h=this._checkKey(u);if(h)return this.nextTick(n,h),n[$];a[f]=this.prefixKey(i.encode(u),s)}return this._getMany(a,e,(f,u)=>{if(f)return n(f);try{for(let h=0;h<u.length;h++)u[h]!==void 0&&(u[h]=o.decode(u[h]))}catch(h){return n(new Ot(`Could not decode one or more of ${u.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:h}))}n(null,u)}),n[$]}_getMany(t,e,n){this.nextTick(n,null,new Array(t.length).fill(void 0))}put(t,e,n,i){if(i=Xe(n,i),i=Se(i,$),n=ke(n,this[tr].entry),this[Z]==="opening")return this.defer(()=>this.put(t,e,n,i)),i[$];if(Tr(this,i))return i[$];let o=this._checkKey(t)||this._checkValue(e);if(o)return this.nextTick(i,o),i[$];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),a=s.format,f=c.format;(n.keyEncoding!==a||n.valueEncoding!==f)&&(n=Object.assign({},n,{keyEncoding:a,valueEncoding:f}));let u=this.prefixKey(s.encode(t),a),h=c.encode(e);return this._put(u,h,n,y=>{if(y)return i(y);this.emit("put",t,e),i()}),i[$]}_put(t,e,n,i){this.nextTick(i)}del(t,e,n){if(n=Xe(e,n),n=Se(n,$),e=ke(e,this[tr].key),this[Z]==="opening")return this.defer(()=>this.del(t,e,n)),n[$];if(Tr(this,n))return n[$];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[$];let o=this.keyEncoding(e.keyEncoding),s=o.format;return e.keyEncoding!==s&&(e=Object.assign({},e,{keyEncoding:s})),this._del(this.prefixKey(o.encode(t),s),e,c=>{if(c)return n(c);this.emit("del",t),n()}),n[$]}_del(t,e,n){this.nextTick(n)}batch(t,e,n){if(!arguments.length){if(this[Z]==="opening")return new ma(this);if(this[Z]!=="open")throw new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof t=="function"?n=t:n=Xe(e,n),n=Se(n,$),e=ke(e,this[tr].empty),this[Z]==="opening")return this.defer(()=>this.batch(t,e,n)),n[$];if(Tr(this,n))return n[$];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[$];if(t.length===0)return this.nextTick(n),n[$];let i=new Array(t.length),{keyEncoding:o,valueEncoding:s,...c}=e;for(let a=0;a<t.length;a++){if(typeof t[a]!="object"||t[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[$];let f=Object.assign({},t[a]);if(f.type!=="put"&&f.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[$];let u=this._checkKey(f.key);if(u)return this.nextTick(n,u),n[$];let h=f.sublevel!=null?f.sublevel:this,y=h.keyEncoding(f.keyEncoding||o),x=y.format;if(f.key=h.prefixKey(y.encode(f.key),x),f.keyEncoding=x,f.type==="put"){let p=this._checkValue(f.value);if(p)return this.nextTick(n,p),n[$];let l=h.valueEncoding(f.valueEncoding||s);f.value=l.encode(f.value),f.valueEncoding=l.format}h!==this&&(f.sublevel=null),i[a]=f}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",t),n()}),n[$]}_batch(t,e,n){this.nextTick(n)}sublevel(t,e){return this._sublevel(t,No.defaults(e))}_sublevel(t,e){return new No(this,t,e)}prefixKey(t,e){return t}clear(t,e){if(e=Xe(t,e),e=Se(e,$),t=ke(t,this[tr].empty),this[Z]==="opening")return this.defer(()=>this.clear(t,e)),e[$];if(Tr(this,e))return e[$];let n=t,i=this.keyEncoding(t.keyEncoding);return t=zn(t,i),t.keyEncoding=i.format,t.limit===0?this.nextTick(e):this._clear(t,o=>{if(o)return e(o);this.emit("clear",n),e()}),e[$]}_clear(t,e){this.nextTick(e)}iterator(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=zn(t,e),t.keys=t.keys!==!1,t.values=t.values!==!1,t[Ye.keyEncoding]=e,t[Ye.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[Z]==="opening")return new hl(this,t);if(this[Z]!=="open")throw new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(t)}_iterator(t){return new Ye(this,t)}keys(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=zn(t,e),t[Ye.keyEncoding]=e,t[Ye.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[Z]==="opening")return new ll(this,t);if(this[Z]!=="open")throw new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(t)}_keys(t){return new fl(this,t)}values(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=zn(t,e),t[Ye.keyEncoding]=e,t[Ye.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[Z]==="opening")return new dl(this,t);if(this[Z]!=="open")throw new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(t)}_values(t){return new ul(this,t)}defer(t){if(typeof t!="function")throw new TypeError("The first argument must be a function");this[sn].push(t)}[cn](){if(this[sn].length===0)return;let t=this[sn];this[sn]=[];for(let e of t)e()}attachResource(t){if(typeof t!="object"||t===null||typeof t.close!="function")throw new TypeError("The first argument must be a resource object");this[Qe].add(t)}detachResource(t){this[Qe].delete(t)}_chainedBatch(){return new ma(this)}_checkKey(t){if(t==null)return new Ot("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(t){if(t==null)return new Ot("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};an.prototype.nextTick=ua();var{AbstractSublevel:No}=ya()({AbstractLevel:an});Do.AbstractLevel=an;Do.AbstractSublevel=No;var Tr=function(r,t){return r[Z]!=="open"?(r.nextTick(t,new Ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},yl=function(r){return Object.keys(r.supports.encodings).filter(t=>!!r.supports.encodings[t])}});var jo=Y(er=>{"use strict";er.AbstractLevel=Mo().AbstractLevel;er.AbstractSublevel=Mo().AbstractSublevel;er.AbstractIterator=Be().AbstractIterator;er.AbstractKeyIterator=Be().AbstractKeyIterator;er.AbstractValueIterator=Be().AbstractValueIterator;er.AbstractChainedBatch=ko().AbstractChainedBatch});var xa=Y((_y,ga)=>{ga.exports=wl;var ml=Uo();function wl(r,t,e){if(typeof t!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,a=!0,f;Array.isArray(r)?(n=[],o=i=r.length):(s=Object.keys(r),n={},o=i=s.length);function u(y){function x(){e&&e(y,n),e=null}a?ml(x):x()}function h(y,x,p){if(n[y]=p,x&&(c=!0),--o===0||x)u(x);else if(!c&&f<i){let l;s?(l=s[f],f+=1,r[l](function(m,b){h(l,m,b)})):(l=f,f+=1,r[l](function(m,b){h(l,m,b)}))}}f=t,o?s?s.some(function(y,x){return r[y](function(p,l){h(y,p,l)}),x===t-1}):r.some(function(y,x){return y(function(p,l){h(x,p,l)}),x===t-1}):u(null),a=!1}});var Jo=Y((Cy,ba)=>{"use strict";ba.exports=function(t){let e=t.gte!==void 0?t.gte:t.gt!==void 0?t.gt:void 0,n=t.lte!==void 0?t.lte:t.lt!==void 0?t.lt:void 0,i=t.gte===void 0,o=t.lte===void 0;return e!==void 0&&n!==void 0?IDBKeyRange.bound(e,n,i,o):e!==void 0?IDBKeyRange.lowerBound(e,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var Vo=Y((Ly,Ea)=>{"use strict";var gl=new TextEncoder;Ea.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):gl.encode(r)}});var Sa=Y(Ta=>{"use strict";var{AbstractIterator:xl}=jo(),va=Jo(),Xn=Vo(),Wt=Symbol("cache"),ce=Symbol("finished"),At=Symbol("options"),ae=Symbol("currentOptions"),rr=Symbol("position"),Ho=Symbol("location"),Sr=Symbol("first"),Aa={},Go=class extends xl{constructor(t,e,n){super(t,n),this[Wt]=[],this[ce]=this.limit===0,this[At]=n,this[ae]={...n},this[rr]=void 0,this[Ho]=e,this[Sr]=!0}_nextv(t,e,n){if(this[Sr]=!1,this[ce])return this.nextTick(n,null,[]);if(this[Wt].length>0)return t=Math.min(t,this[Wt].length),this.nextTick(n,null,this[Wt].splice(0,t));this[rr]!==void 0&&(this[At].reverse?(this[ae].lt=this[rr],this[ae].lte=void 0):(this[ae].gt=this[rr],this[ae].gte=void 0));let i;try{i=va(this[ae])}catch{return this[ce]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[Ho]],"readonly"),s=o.objectStore(this[Ho]),c=[];if(this[At].reverse){let a=!this[At].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=f=>{let u=f.target.result;if(u){let{key:h,value:y}=u;this[rr]=h,c.push([this[At].keys&&h!==void 0?Xn(h):void 0,this[At].values&&y!==void 0?Xn(y):void 0]),c.length<t?u.continue():Ba(o)}else this[ce]=!0}}else{let a,f,u=()=>{if(a===void 0||f===void 0)return;let h=Math.max(a.length,f.length);h===0||t===1/0?this[ce]=!0:this[rr]=a[h-1],c.length=h;for(let y=0;y<h;y++){let x=a[y],p=f[y];c[y]=[this[At].keys&&x!==void 0?Xn(x):void 0,this[At].values&&p!==void 0?Xn(p):void 0]}Ba(o)};this[At].keys||t<1/0?s.getAllKeys(i,t<1/0?t:void 0).onsuccess=h=>{a=h.target.result,u()}:(a=[],this.nextTick(u)),this[At].values?s.getAll(i,t<1/0?t:void 0).onsuccess=h=>{f=h.target.result,u()}:(f=[],this.nextTick(u))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(t){if(this[Wt].length>0){let[e,n]=this[Wt].shift();this.nextTick(t,null,e,n)}else if(this[ce])this.nextTick(t);else{let e=Math.min(100,this.limit-this.count);this[Sr]&&(this[Sr]=!1,e=1),this._nextv(e,Aa,(n,i)=>{if(n)return t(n);this[Wt]=i,this._next(t)})}}_all(t,e){this[Sr]=!1;let n=this[Wt].splice(0,this[Wt].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(e,null,n);this._nextv(i,Aa,(o,s)=>{if(o)return e(o);n.length>0&&(s=n.concat(s)),e(null,s)})}_seek(t,e){this[Sr]=!0,this[Wt]=[],this[ce]=!1,this[rr]=void 0,this[ae]={...this[At]};let n;try{n=va(this[At])}catch{this[ce]=!0;return}n!==null&&!n.includes(t)?this[ce]=!0:this[At].reverse?this[ae].lte=t:this[ae].gte=t}};Ta.Iterator=Go;function Ba(r){typeof r.commit=="function"&&r.commit()}});var Pa=Y((Ry,ka)=>{"use strict";ka.exports=function(t,e,n,i,o){if(i.limit===0)return t.nextTick(o);let s=t.db.transaction([e],"readwrite"),c=s.objectStore(e),a=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let f=c.openKeyCursor?"openKeyCursor":"openCursor",u=i.reverse?"prev":"next";c[f](n,u).onsuccess=function(h){let y=h.target.result;y&&(c.delete(y.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&y.continue()})}}});var La=Y(Ca=>{"use strict";var{AbstractLevel:bl}=jo(),Ua=Ct(),El=xa(),{fromCallback:vl}=Wr(),{Iterator:Al}=Sa(),Ka=Vo(),Bl=Pa(),Tl=Jo(),_a="level-js-",fn=Symbol("idb"),qo=Symbol("namePrefix"),fe=Symbol("location"),Fo=Symbol("version"),nr=Symbol("store"),un=Symbol("onComplete"),Ia=Symbol("promise"),Qn=class extends bl{constructor(t,e,n){if(typeof e=="function"||typeof n=="function")throw new Ua("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=e||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof t!="string")throw new Error("constructor requires a location string argument");this[fe]=t,this[qo]=i??_a,this[Fo]=parseInt(o||1,10),this[fn]=null}get location(){return this[fe]}get namePrefix(){return this[qo]}get version(){return this[Fo]}get db(){return this[fn]}get type(){return"browser-level"}_open(t,e){let n=indexedDB.open(this[qo]+this[fe],this[Fo]);n.onerror=function(){e(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[fn]=n.result,e()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[fe])||o.createObjectStore(this[fe])}}[nr](t){return this[fn].transaction([this[fe]],t).objectStore(this[fe])}[un](t,e){let n=t.transaction;n.onabort=function(){e(n.error||new Error("aborted by user"))},n.oncomplete=function(){e(null,t.result)}}_get(t,e,n){let i=this[nr]("readonly"),o;try{o=i.get(t)}catch(s){return this.nextTick(n,s)}this[un](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new Ua("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,Ka(c))})}_getMany(t,e,n){let i=this[nr]("readonly"),o=t.map(s=>c=>{let a;try{a=i.get(s)}catch(f){return c(f)}a.onsuccess=()=>{let f=a.result;c(null,f===void 0?f:Ka(f))},a.onerror=f=>{f.stopPropagation(),c(a.error)}});El(o,16,n)}_del(t,e,n){let i=this[nr]("readwrite"),o;try{o=i.delete(t)}catch(s){return this.nextTick(n,s)}this[un](o,n)}_put(t,e,n,i){let o=this[nr]("readwrite"),s;try{s=o.put(e,t)}catch(c){return this.nextTick(i,c)}this[un](s,i)}_iterator(t){return new Al(this,this[fe],t)}_batch(t,e,n){let i=this[nr]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let f=t[s++],u=f.key,h;try{h=f.type==="del"?i.delete(u):i.put(f.value,u)}catch(y){c=y,o.abort();return}s<t.length?h.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(t,e){let n,i;try{n=Tl(t)}catch{return this.nextTick(e)}if(t.limit>=0)return Bl(this,this[fe],n,t,e);try{let o=this[nr]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(e,o)}this[un](i,e)}_close(t){this[fn].close(),this.nextTick(t)}};Qn.destroy=function(r,t,e){typeof t=="function"&&(e=t,t=_a),e=vl(e,Ia);let n=indexedDB.deleteDatabase(t+r);return n.onsuccess=function(){e()},n.onerror=function(i){e(i)},e[Ia]};Ca.BrowserLevel=Qn});var Ra=Y(Oa=>{Oa.Level=La().BrowserLevel});var Jt=class r extends Error{constructor(e,n){super(n);this.code=e;this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},Ms=(o=>(o.AlgorithmNotSupported="algorithmNotSupported",o.EncodingError="encodingError",o.InvalidJwe="invalidJwe",o.InvalidJwk="invalidJwk",o.OperationNotSupported="operationNotSupported",o))(Ms||{});var hu=Ds(Js(),1);var up=new Uint8Array(0);function Vs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function fr(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 du(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var c=r.length,a=r.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function h(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 l=0,m=0,b=0,B=p.length;b!==B&&p[b]===0;)b++,l++;for(var w=(B-b)*u+1>>>0,P=new Uint8Array(w);b!==B;){for(var A=p[b],T=0,K=w-1;(A!==0||T<m)&&K!==-1;K--,T++)A+=256*P[K]>>>0,P[K]=A%c>>>0,A=A/c>>>0;if(A!==0)throw new Error("Non-zero carry");m=T,b++}for(var U=w-m;U!==w&&P[U]===0;)U++;for(var D=a.repeat(l);U<w;++U)D+=r.charAt(P[U]);return D}function y(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var l=0;if(p[l]!==" "){for(var m=0,b=0;p[l]===a;)m++,l++;for(var B=(p.length-l)*f+1>>>0,w=new Uint8Array(B);p[l];){var P=e[p.charCodeAt(l)];if(P===255)return;for(var A=0,T=B-1;(P!==0||A<b)&&T!==-1;T--,A++)P+=c*w[T]>>>0,w[T]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");b=A,l++}if(p[l]!==" "){for(var K=B-b;K!==B&&w[K]===0;)K++;for(var U=new Uint8Array(m+(B-K)),D=m;K!==B;)U[D++]=w[K++];return U}}}function x(p){var l=y(p);if(l)return l;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:y,decode:x}}var pu=du,yu=pu,Hs=yu;var _i=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ci=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Gs(this,t)}},Li=class{decoders;constructor(t){this.decoders=t}or(t){return Gs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Gs(r,t){return new Li({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Oi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new _i(t,e,n),this.decoder=new Ci(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function qs({name:r,prefix:t,encode:e,decode:n}){return new Oi(r,t,e,n)}function Ri({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Hs(e,r);return qs({prefix:t,name:r,encode:n,decode:o=>fr(i(o))})}function mu(r,t,e,n){let i={};for(let u=0;u<t.length;++u)i[t[u]]=u;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),c=0,a=0,f=0;for(let u=0;u<o;++u){let h=i[r[u]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|h,c+=e,c>=8&&(c-=8,s[f++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function wu(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,o+=t[i&c>>s];if(s!==0&&(o+=t[i&c<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function yt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return qs({prefix:t,name:r,encode(i){return wu(i,n,e)},decode(i){return mu(i,n,e,r)}})}var Nr=yt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mp=yt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),wp=yt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gp=yt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xp=yt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bp=yt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ep=yt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vp=yt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ni=yt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mt=Ri({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tp=Ri({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Pp=yt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Up=yt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vt=yt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kp=yt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Fs(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function $s(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function Dr(r){let e=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=e;return i}var Mr=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(u){try{f(n.next(u))}catch(h){s(h)}}function a(u){try{f(n.throw(u))}catch(h){s(h)}}function f(u){u.done?o(u.value):i(u.value).then(c,a)}f((n=n.apply(r,t||[])).next())})},Ws=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=r[o]&&function(s){return new Promise(function(c,a){s=r[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(f){o({value:f,done:c})},s)}},vn=new TextEncoder,Me=new TextDecoder,R=class r{constructor(t,e){this.data=t,this.format=e}static arrayBuffer(t){return new r(t,"ArrayBuffer")}static asyncIterable(t){if(!$s(t))throw new TypeError("Input must be of type AsyncIterable.");return new r(t,"AsyncIterable")}static base32Z(t){return new r(t,"Base32Z")}static base58Btc(t){return new r(t,"Base58Btc")}static base64Url(t){return new r(t,"Base64Url")}static bufferSource(t){return new r(t,"BufferSource")}static hex(t){if(typeof t!="string")throw new TypeError("Hex input must be a string.");if(t.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new r(t,"Hex")}static multibase(t){return new r(t,"Multibase")}static object(t){return new r(t,"Object")}static string(t){return new r(t,"String")}static uint8Array(t){return new r(t,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return mt.baseDecode(this.data).buffer;case"Base64Url":return Vt.baseDecode(this.data).buffer;case"BufferSource":{if(Dr(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Fs(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 Mr(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 Ni.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return mt.baseEncode(t)}case"Multibase":return this.data.substring(1);case"Uint8Array":return mt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return Vt.baseEncode(t)}case"BufferSource":{let t=this.toUint8Array();return Vt.baseEncode(t)}case"Object":{let t=JSON.stringify(this.data),e=vn.encode(t);return Vt.baseEncode(e)}case"String":{let t=vn.encode(this.data);return Vt.baseEncode(t)}case"Uint8Array":return Vt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return Mr(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=Ws(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let u=i;a.push(u)}}catch(u){e={error:u}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let t=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Base64Url":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Uint8Array":{let e="";for(let n=0;n<this.data.length;n++)e+=t[this.data[n]];return e}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 t=Vt.baseDecode(this.data),e=Me.decode(t);return JSON.parse(e)}case"String":return JSON.parse(this.data);case"Uint8Array":{let t=Me.decode(this.data);return JSON.parse(t)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return Mr(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toStringAsync();return JSON.parse(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return Me.decode(this.data);case"Base64Url":{let t=Vt.baseDecode(this.data);return Me.decode(t)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Me.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return Mr(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=Ws(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let f=i;typeof f=="string"?a+=f:a+=Me.decode(f,{stream:!0})}}catch(f){e={error:f}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return a+=Me.decode(void 0,{stream:!1}),a}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return Ni.baseDecode(this.data);case"Base58Btc":return mt.baseDecode(this.data);case"Base64Url":return Vt.baseDecode(this.data);case"BufferSource":{let t=Dr(this.data);if(t==="Uint8Array")return this.data;if(t==="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 t=new Uint8Array(this.data.length/2);for(let e=0;e<this.data.length;e+=2){let n=parseInt(this.data.substring(e,e+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");t[e/2]=n}return t}case"Object":{let t=JSON.stringify(this.data);return vn.encode(t)}case"String":return vn.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return Mr(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toArrayBufferAsync();return new Uint8Array(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};var jr;(function(r){r.Debug="debug",r.Silent="silent"})(jr||(jr={}));var Di=class{constructor(){this.logLevel=jr.Silent}setLogLevel(t){this.logLevel=t}log(t){this.info(t)}info(t){this.logLevel!==jr.Silent&&console.info(t)}error(t){this.logLevel!==jr.Silent&&console.error(t)}},gu=new Di;typeof window<"u"&&(window.web5logger=gu);var ee={};Ns(ee,{decode:()=>ur,encodeTo:()=>je,encodingLength:()=>Je});var xu=Ys,zs=128,bu=127,Eu=~bu,vu=Math.pow(2,31);function Ys(r,t,e){t=t||[],e=e||0;for(var n=e;r>=vu;)t[e++]=r&255|zs,r/=128;for(;r&Eu;)t[e++]=r&255|zs,r>>>=7;return t[e]=r|0,Ys.bytes=e-n+1,t}var Au=Mi,Bu=128,Zs=127;function Mi(r,n){var e=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw Mi.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Zs)<<i:(s&Zs)*Math.pow(2,i),i+=7}while(s>=Bu);return Mi.bytes=o-n,e}var Tu=Math.pow(2,7),Su=Math.pow(2,14),ku=Math.pow(2,21),Pu=Math.pow(2,28),Uu=Math.pow(2,35),Ku=Math.pow(2,42),Iu=Math.pow(2,49),_u=Math.pow(2,56),Cu=Math.pow(2,63),Lu=function(r){return r<Tu?1:r<Su?2:r<ku?3:r<Pu?4:r<Uu?5:r<Ku?6:r<Iu?7:r<_u?8:r<Cu?9:10},Ou={encode:xu,decode:Au,encodingLength:Lu},Ru=Ou,Jr=Ru;function ur(r,t=0){return[Jr.decode(r,t),Jr.decode.bytes]}function je(r,t,e=0){return Jr.encode(r,t,e),t}function Je(r){return Jr.encodingLength(r)}function ji(r,t){let e=t.byteLength,n=Je(r),i=n+Je(e),o=new Uint8Array(i+e);return je(r,o,0),je(e,o,n),o.set(t,i),new hr(r,e,t,o)}function Xs(r){let t=fr(r),[e,n]=ur(t),[i,o]=ur(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new hr(e,i,s,t)}function Qs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Vs(r.bytes,e.bytes)}}var hr=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function tc(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Du(e,Vi(r),t??mt.encoder);default:return Mu(e,Vi(r),t??Nr.encoder)}}var ec=new WeakMap;function Vi(r){let t=ec.get(r);if(t==null){let e=new Map;return ec.set(r,e),e}return t}var Hi=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==Vr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ju)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=ji(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Qs(t.multihash,n.multihash)}toString(t){return tc(this,t)}toJSON(){return{"/":tc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??rc(n,i,o.bytes))}else if(e[Ju]===!0){let{version:n,multihash:i,code:o}=e,s=Xs(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Vr)throw new Error(`Version 0 CID must use dag-pb (code: ${Vr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=rc(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Vr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=fr(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new hr(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,y]=ur(t.subarray(e));return e+=y,h},i=n(),o=Vr;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,c=n(),a=n(),f=e+a,u=f-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[n,i]=Nu(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Vi(o).set(n,t),o}};function Nu(r,t){switch(r[0]){case"Q":{let e=t??mt;return[mt.prefix,e.decode(`${mt.prefix}${r}`)]}case mt.prefix:{let e=t??mt;return[mt.prefix,e.decode(r)]}case Nr.prefix:{let e=t??Nr;return[Nr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Du(r,t,e){let{prefix:n}=e;if(n!==mt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function Mu(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var Vr=112,ju=18;function rc(r,t,e){let n=Je(r),i=n+Je(t),o=new Uint8Array(i+e.byteLength);return je(r,o,0),je(t,o,n),o.set(e,i),o}var Ju=Symbol.for("@ipld/js-cid/CID");var Ht=class r{static addPrefix(t){var e;let{code:n,data:i,name:o}=t;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: ${(e=t.name)!==null&&e!==void 0?e:t.code}`);let s=ee.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),ee.encodeTo(n,c),c}static getCodeFromData(t){let{prefixedData:e}=t,[n,i]=ee.decode(e);return n}static getCodeFromName(t){let{name:e}=t,n=r.nameToCode.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static getNameFromCode(t){let{code:e}=t,n=r.codeToName.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static registerCodec(t){r.codeToName.set(t.code,t.name),r.nameToCode.set(t.name,t.code)}static removePrefix(t){let{prefixedData:e}=t,[n,i]=ee.decode(e),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:e.slice(i),name:o}}};Ht.codeToName=new Map;Ht.nameToCode=new Map;Ht.registerCodec({code:237,name:"ed25519-pub"});Ht.registerCodec({code:4864,name:"ed25519-priv"});Ht.registerCodec({code:236,name:"x25519-pub"});Ht.registerCodec({code:4866,name:"x25519-priv"});Ht.registerCodec({code:231,name:"secp256k1-pub"});Ht.registerCodec({code:4865,name:"secp256k1-priv"});function Gi(r){Object.keys(r).forEach(t=>{r[t]===void 0?delete r[t]:typeof r[t]=="object"&&Gi(r[t])})}var Sl=Ds(Ra(),1),ir=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(u){try{f(n.next(u))}catch(h){s(h)}}function a(u){try{f(n.throw(u))}catch(h){s(h)}}function f(u){u.done?o(u.value):i(u.value).then(c,a)}f((n=n.apply(r,t||[])).next())})};var ti=class{constructor(){this.store=new Map}clear(){return ir(this,void 0,void 0,function*(){this.store.clear()})}close(){return ir(this,void 0,void 0,function*(){})}delete(t){return ir(this,void 0,void 0,function*(){return this.store.delete(t)})}get(t){return ir(this,void 0,void 0,function*(){return this.store.get(t)})}has(t){return ir(this,void 0,void 0,function*(){return this.store.has(t)})}list(){return ir(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(t,e){return ir(this,void 0,void 0,function*(){this.store.set(t,e)})}};var Ut=class{};var ri={};Ns(ri,{bitGet:()=>Cl,bitLen:()=>_l,bitMask:()=>hn,bitSet:()=>Ll,bytesToHex:()=>he,bytesToNumberBE:()=>le,bytesToNumberLE:()=>Nt,concatBytes:()=>pe,createHmacDrbg:()=>zo,ensureBytes:()=>rt,equalBytes:()=>Kl,hexToBytes:()=>or,hexToNumber:()=>Wo,isBytes:()=>Rt,numberToBytesBE:()=>xt,numberToBytesLE:()=>de,numberToHexUnpadded:()=>ja,numberToVarBytesBE:()=>Ul,utf8ToBytes:()=>Il,validateObject:()=>Kt});var Ma=BigInt(0),ei=BigInt(1),kl=BigInt(2);function Rt(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Pl=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function he(r){if(!Rt(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=Pl[r[e]];return t}function ja(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Wo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ue={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Na(r){if(r>=ue._0&&r<=ue._9)return r-ue._0;if(r>=ue._A&&r<=ue._F)return r-(ue._A-10);if(r>=ue._a&&r<=ue._f)return r-(ue._a-10)}function or(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let i=0,o=0;i<e;i++,o+=2){let s=Na(r.charCodeAt(o)),c=Na(r.charCodeAt(o+1));if(s===void 0||c===void 0){let a=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function le(r){return Wo(he(r))}function Nt(r){if(!Rt(r))throw new Error("Uint8Array expected");return Wo(he(Uint8Array.from(r).reverse()))}function xt(r,t){return or(r.toString(16).padStart(t*2,"0"))}function de(r,t){return xt(r,t).reverse()}function Ul(r){return or(ja(r))}function rt(r,t,e){let n;if(typeof t=="string")try{n=or(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Rt(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof e=="number"&&i!==e)throw new Error(`${r} expected ${e} bytes, got ${i}`);return n}function pe(...r){let t=0;for(let i=0;i<r.length;i++){let o=r[i];if(!Rt(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let i=0;i<r.length;i++){let o=r[i];e.set(o,n),n+=o.length}return e}function Kl(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Il(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function _l(r){let t;for(t=0;r>Ma;r>>=ei,t+=1);return t}function Cl(r,t){return r>>BigInt(t)&ei}var Ll=(r,t,e)=>r|(e?ei:Ma)<<BigInt(t),hn=r=>(kl<<BigInt(r-1))-ei,$o=r=>new Uint8Array(r),Da=r=>Uint8Array.from(r);function zo(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=$o(r),i=$o(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...h)=>e(i,n,...h),a=(h=$o())=>{i=c(Da([0]),h),n=c(),h.length!==0&&(i=c(Da([1]),h),n=c())},f=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,y=[];for(;h<t;){n=c();let x=n.slice();y.push(x),h+=n.length}return pe(...y)};return(h,y)=>{s(),a(h);let x;for(;!(x=y(f()));)a();return s(),x}}var Ol={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"||Rt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Kt(r,t,e={}){let n=(i,o,s)=>{let c=Ol[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let a=r[i];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(let[i,o]of Object.entries(t))n(i,o,!1);for(let[i,o]of Object.entries(e))n(i,o,!0);return r}function Ja(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Rl(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Zo(r,...t){if(!Rl(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function Va(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ja(r.outputLen),Ja(r.blockLen)}function kr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ha(r,t){Zo(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var ni=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ga(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ii=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Dt=(r,t)=>r<<32-t|r>>>t,Nl=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Nl)throw new Error("Non little-endian hardware is not supported");function Yo(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ln(r){if(typeof r=="string"&&(r=Yo(r)),!Ga(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function oi(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Ga(i))throw new Error("Uint8Array expected");t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var Pr=class{clone(){return this._cloneInto()}},e0={}.toString;function si(r){let t=n=>r().update(ln(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function dn(r=32){if(ni&&typeof ni.getRandomValues=="function")return ni.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Dl(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,f=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+f,c,n)}var Ur=class extends Pr{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=ii(this.buffer)}update(t){kr(this);let{view:e,buffer:n,blockLen:i}=this;t=ln(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=ii(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){kr(this),Ha(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)e[h]=0;Dl(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=ii(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)c.setUint32(4*h,u[h],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var Ml=(r,t,e)=>r&t^~r&e,jl=(r,t,e)=>r&t^r&e^t&e,Jl=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]),Pe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ue=new Uint32Array(64),Xo=class extends Ur{constructor(){super(64,32,8,!1),this.A=Pe[0]|0,this.B=Pe[1]|0,this.C=Pe[2]|0,this.D=Pe[3]|0,this.E=Pe[4]|0,this.F=Pe[5]|0,this.G=Pe[6]|0,this.H=Pe[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let h=0;h<16;h++,e+=4)Ue[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let y=Ue[h-15],x=Ue[h-2],p=Dt(y,7)^Dt(y,18)^y>>>3,l=Dt(x,17)^Dt(x,19)^x>>>10;Ue[h]=l+Ue[h-7]+p+Ue[h-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:f,H:u}=this;for(let h=0;h<64;h++){let y=Dt(c,6)^Dt(c,11)^Dt(c,25),x=u+y+Ml(c,a,f)+Jl[h]+Ue[h]|0,l=(Dt(n,2)^Dt(n,13)^Dt(n,22))+jl(n,i,o)|0;u=f,f=a,a=c,c=s+x|0,s=o,o=i,i=n,n=x+l|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,i,o,s,c,a,f,u)}roundClean(){Ue.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ci=si(()=>new Xo);var ct=BigInt(0),it=BigInt(1),sr=BigInt(2),Vl=BigInt(3),Qo=BigInt(4),qa=BigInt(5),Fa=BigInt(8),Hl=BigInt(9),Gl=BigInt(16);function X(r,t){let e=r%t;return e>=ct?e:t+e}function ts(r,t,e){if(e<=ct||t<ct)throw new Error("Expected power/modulo > 0");if(e===it)return ct;let n=it;for(;t>ct;)t&it&&(n=n*r%e),r=r*r%e,t>>=it;return n}function nt(r,t,e){let n=r;for(;t-- >ct;)n*=n,n%=e;return n}function ai(r,t){if(r===ct||t<=ct)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=X(r,t),n=t,i=ct,o=it,s=it,c=ct;for(;e!==ct;){let f=n/e,u=n%e,h=i-s*f,y=o-c*f;n=e,e=u,i=s,o=c,s=h,c=y}if(n!==it)throw new Error("invert: does not exist");return X(i,t)}function ql(r){let t=(r-it)/sr,e,n,i;for(e=r-it,n=0;e%sr===ct;e/=sr,n++);for(i=sr;i<r&&ts(i,t,r)!==r-it;i++);if(n===1){let s=(r+it)/Qo;return function(a,f){let u=a.pow(f,s);if(!a.eql(a.sqr(u),f))throw new Error("Cannot find square root");return u}}let o=(e+it)/sr;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let f=n,u=c.pow(c.mul(c.ONE,i),e),h=c.pow(a,o),y=c.pow(a,e);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let x=1;for(let l=c.sqr(y);x<f&&!c.eql(l,c.ONE);x++)l=c.sqr(l);let p=c.pow(u,it<<BigInt(f-x-1));u=c.sqr(p),h=c.mul(h,p),y=c.mul(y,u),f=x}return h}}function Fl(r){if(r%Qo===Vl){let t=(r+it)/Qo;return function(n,i){let o=n.pow(i,t);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Fa===qa){let t=(r-qa)/Fa;return function(n,i){let o=n.mul(i,sr),s=n.pow(o,t),c=n.mul(i,s),a=n.mul(n.mul(c,sr),s),f=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(f),i))throw new Error("Cannot find square root");return f}}return r%Gl,ql(r)}var $a=(r,t)=>(X(r,t)&it)===it,$l=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function es(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=$l.reduce((n,i)=>(n[i]="function",n),t);return Kt(r,e)}function Wl(r,t,e){if(e<ct)throw new Error("Expected power > 0");if(e===ct)return r.ONE;if(e===it)return t;let n=r.ONE,i=t;for(;e>ct;)e&it&&(n=r.mul(n,i)),i=r.sqr(i),e>>=it;return n}function zl(r,t){let e=new Array(t.length),n=t.reduce((o,s,c)=>r.is0(s)?o:(e[c]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return t.reduceRight((o,s,c)=>r.is0(s)?o:(e[c]=r.mul(o,e[c]),r.mul(o,s)),i),e}function rs(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Kr(r,t,e=!1,n={}){if(r<=ct)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=rs(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Fl(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:hn(i),ZERO:ct,ONE:it,create:a=>X(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return ct<=a&&a<r},is0:a=>a===ct,isOdd:a=>(a&it)===it,neg:a=>X(-a,r),eql:(a,f)=>a===f,sqr:a=>X(a*a,r),add:(a,f)=>X(a+f,r),sub:(a,f)=>X(a-f,r),mul:(a,f)=>X(a*f,r),pow:(a,f)=>Wl(c,a,f),div:(a,f)=>X(a*ai(f,r),r),sqrN:a=>a*a,addN:(a,f)=>a+f,subN:(a,f)=>a-f,mulN:(a,f)=>a*f,inv:a=>ai(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>zl(c,a),cmov:(a,f,u)=>u?f:a,toBytes:a=>e?de(a,o):xt(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return e?Nt(a):le(a)}});return Object.freeze(c)}function Wa(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function za(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function ns(r){let t=za(r);return t+Math.ceil(t/2)}function Za(r,t,e=!1){let n=r.length,i=za(t),o=ns(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=e?le(r):Nt(r),c=X(s,t-it)+it;return e?de(c,i):xt(c,i)}var Yl=BigInt(0),is=BigInt(1);function fi(r,t){let e=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(t/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:e,unsafeLadder(i,o){let s=r.ZERO,c=i;for(;o>Yl;)o&is&&(s=s.add(c)),c=c.double(),o>>=is;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),a=[],f=i,u=f;for(let h=0;h<s;h++){u=f,a.push(u);for(let y=1;y<c;y++)u=u.add(f),a.push(u);f=u.double()}return a},wNAF(i,o,s){let{windows:c,windowSize:a}=n(i),f=r.ZERO,u=r.BASE,h=BigInt(2**i-1),y=2**i,x=BigInt(i);for(let p=0;p<c;p++){let l=p*a,m=Number(s&h);s>>=x,m>a&&(m-=y,s+=is);let b=l,B=l+Math.abs(m)-1,w=p%2!==0,P=m<0;m===0?u=u.add(e(w,o[b])):f=f.add(e(P,o[B]))}return{p:f,f:u}},wNAFCached(i,o,s,c){let a=i._WINDOW_SIZE||1,f=o.get(i);return f||(f=this.precomputeWindow(i,a),a!==1&&o.set(i,c(f))),this.wNAF(a,f,s)}}}function pn(r){return es(r.Fp),Kt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...rs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Xl(r){let t=pn(r);Kt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:i}=t;if(e){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Ql,hexToBytes:td}=ri,cr={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=cr;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Ql(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=cr,e=typeof r=="string"?td(r):r;if(!Rt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:i,l:o}=cr._parseInt(e.subarray(2)),{d:s,l:c}=cr._parseInt(o);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let t=f=>Number.parseInt(f[0],16)&8?"00"+f:f,e=f=>{let u=f.toString(16);return u.length&1?`0${u}`:u},n=t(e(r.s)),i=t(e(r.r)),o=n.length/2,s=i.length/2,c=e(o),a=e(s);return`30${e(s+o+4)}02${a}${i}02${c}${n}`}},ye=BigInt(0),It=BigInt(1),m0=BigInt(2),Ya=BigInt(3),w0=BigInt(4);function ed(r){let t=Xl(r),{Fp:e}=t,n=t.toBytes||((p,l,m)=>{let b=l.toAffine();return pe(Uint8Array.from([4]),e.toBytes(b.x),e.toBytes(b.y))}),i=t.fromBytes||(p=>{let l=p.subarray(1),m=e.fromBytes(l.subarray(0,e.BYTES)),b=e.fromBytes(l.subarray(e.BYTES,2*e.BYTES));return{x:m,y:b}});function o(p){let{a:l,b:m}=t,b=e.sqr(p),B=e.mul(b,p);return e.add(e.add(B,e.mul(p,l)),m)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&ye<p&&p<t.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){let{allowedPrivateKeyLengths:l,nByteLength:m,wrapPrivateKey:b,n:B}=t;if(l&&typeof p!="bigint"){if(Rt(p)&&(p=he(p)),typeof p!="string"||!l.includes(p.length))throw new Error("Invalid key");p=p.padStart(m*2,"0")}let w;try{w=typeof p=="bigint"?p:le(rt("private key",p,m))}catch{throw new Error(`private key must be ${m} bytes, hex or bigint, not ${typeof p}`)}return b&&(w=X(w,B)),c(w),w}let f=new Map;function u(p){if(!(p instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(l,m,b){if(this.px=l,this.py=m,this.pz=b,l==null||!e.isValid(l))throw new Error("x required");if(m==null||!e.isValid(m))throw new Error("y required");if(b==null||!e.isValid(b))throw new Error("z required")}static fromAffine(l){let{x:m,y:b}=l||{};if(!l||!e.isValid(m)||!e.isValid(b))throw new Error("invalid affine point");if(l instanceof h)throw new Error("projective point not allowed");let B=w=>e.eql(w,e.ZERO);return B(m)&&B(b)?h.ZERO:new h(m,b,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(l){let m=e.invertBatch(l.map(b=>b.pz));return l.map((b,B)=>b.toAffine(m[B])).map(h.fromAffine)}static fromHex(l){let m=h.fromAffine(i(rt("pointHex",l)));return m.assertValidity(),m}static fromPrivateKey(l){return h.BASE.multiply(a(l))}_setWindowSize(l){this._WINDOW_SIZE=l,f.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:l,y:m}=this.toAffine();if(!e.isValid(l)||!e.isValid(m))throw new Error("bad point: x or y not FE");let b=e.sqr(m),B=o(l);if(!e.eql(b,B))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:l}=this.toAffine();if(e.isOdd)return!e.isOdd(l);throw new Error("Field doesn't support isOdd")}equals(l){u(l);let{px:m,py:b,pz:B}=this,{px:w,py:P,pz:A}=l,T=e.eql(e.mul(m,A),e.mul(w,B)),K=e.eql(e.mul(b,A),e.mul(P,B));return T&&K}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:l,b:m}=t,b=e.mul(m,Ya),{px:B,py:w,pz:P}=this,A=e.ZERO,T=e.ZERO,K=e.ZERO,U=e.mul(B,B),D=e.mul(w,w),O=e.mul(P,P),_=e.mul(B,w);return _=e.add(_,_),K=e.mul(B,P),K=e.add(K,K),A=e.mul(l,K),T=e.mul(b,O),T=e.add(A,T),A=e.sub(D,T),T=e.add(D,T),T=e.mul(A,T),A=e.mul(_,A),K=e.mul(b,K),O=e.mul(l,O),_=e.sub(U,O),_=e.mul(l,_),_=e.add(_,K),K=e.add(U,U),U=e.add(K,U),U=e.add(U,O),U=e.mul(U,_),T=e.add(T,U),O=e.mul(w,P),O=e.add(O,O),U=e.mul(O,_),A=e.sub(A,U),K=e.mul(O,D),K=e.add(K,K),K=e.add(K,K),new h(A,T,K)}add(l){u(l);let{px:m,py:b,pz:B}=this,{px:w,py:P,pz:A}=l,T=e.ZERO,K=e.ZERO,U=e.ZERO,D=t.a,O=e.mul(t.b,Ya),_=e.mul(m,w),j=e.mul(b,P),M=e.mul(B,A),W=e.add(m,b),E=e.add(w,P);W=e.mul(W,E),E=e.add(_,j),W=e.sub(W,E),E=e.add(m,B);let k=e.add(w,A);return E=e.mul(E,k),k=e.add(_,M),E=e.sub(E,k),k=e.add(b,B),T=e.add(P,A),k=e.mul(k,T),T=e.add(j,M),k=e.sub(k,T),U=e.mul(D,E),T=e.mul(O,M),U=e.add(T,U),T=e.sub(j,U),U=e.add(j,U),K=e.mul(T,U),j=e.add(_,_),j=e.add(j,_),M=e.mul(D,M),E=e.mul(O,E),j=e.add(j,M),M=e.sub(_,M),M=e.mul(D,M),E=e.add(E,M),_=e.mul(j,E),K=e.add(K,_),_=e.mul(k,E),T=e.mul(W,T),T=e.sub(T,_),_=e.mul(W,j),U=e.mul(k,U),U=e.add(U,_),new h(T,K,U)}subtract(l){return this.add(l.negate())}is0(){return this.equals(h.ZERO)}wNAF(l){return x.wNAFCached(this,f,l,m=>{let b=e.invertBatch(m.map(B=>B.pz));return m.map((B,w)=>B.toAffine(b[w])).map(h.fromAffine)})}multiplyUnsafe(l){let m=h.ZERO;if(l===ye)return m;if(c(l),l===It)return this;let{endo:b}=t;if(!b)return x.unsafeLadder(this,l);let{k1neg:B,k1:w,k2neg:P,k2:A}=b.splitScalar(l),T=m,K=m,U=this;for(;w>ye||A>ye;)w&It&&(T=T.add(U)),A&It&&(K=K.add(U)),U=U.double(),w>>=It,A>>=It;return B&&(T=T.negate()),P&&(K=K.negate()),K=new h(e.mul(K.px,b.beta),K.py,K.pz),T.add(K)}multiply(l){c(l);let m=l,b,B,{endo:w}=t;if(w){let{k1neg:P,k1:A,k2neg:T,k2:K}=w.splitScalar(m),{p:U,f:D}=this.wNAF(A),{p:O,f:_}=this.wNAF(K);U=x.constTimeNegate(P,U),O=x.constTimeNegate(T,O),O=new h(e.mul(O.px,w.beta),O.py,O.pz),b=U.add(O),B=D.add(_)}else{let{p:P,f:A}=this.wNAF(m);b=P,B=A}return h.normalizeZ([b,B])[0]}multiplyAndAddUnsafe(l,m,b){let B=h.BASE,w=(A,T)=>T===ye||T===It||!A.equals(B)?A.multiplyUnsafe(T):A.multiply(T),P=w(this,m).add(w(l,b));return P.is0()?void 0:P}toAffine(l){let{px:m,py:b,pz:B}=this,w=this.is0();l==null&&(l=w?e.ONE:e.inv(B));let P=e.mul(m,l),A=e.mul(b,l),T=e.mul(B,l);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:P,y:A}}isTorsionFree(){let{h:l,isTorsionFree:m}=t;if(l===It)return!0;if(m)return m(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:l,clearCofactor:m}=t;return l===It?this:m?m(h,this):this.multiplyUnsafe(t.h)}toRawBytes(l=!0){return this.assertValidity(),n(h,this,l)}toHex(l=!0){return he(this.toRawBytes(l))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,x=fi(h,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function rd(r){let t=pn(r);return Kt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Xa(r){let t=rd(r),{Fp:e,n}=t,i=e.BYTES+1,o=2*e.BYTES+1;function s(E){return ye<E&&E<e.ORDER}function c(E){return X(E,n)}function a(E){return ai(E,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:u,weierstrassEquation:h,isWithinCurveOrder:y}=ed({...t,toBytes(E,k,L){let v=k.toAffine(),d=e.toBytes(v.x),S=pe;return L?S(Uint8Array.from([k.hasEvenY()?2:3]),d):S(Uint8Array.from([4]),d,e.toBytes(v.y))},fromBytes(E){let k=E.length,L=E[0],v=E.subarray(1);if(k===i&&(L===2||L===3)){let d=le(v);if(!s(d))throw new Error("Point is not on curve");let S=h(d),I=e.sqrt(S),C=(I&It)===It;return(L&1)===1!==C&&(I=e.neg(I)),{x:d,y:I}}else if(k===o&&L===4){let d=e.fromBytes(v.subarray(0,e.BYTES)),S=e.fromBytes(v.subarray(e.BYTES,2*e.BYTES));return{x:d,y:S}}else throw new Error(`Point of length ${k} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),x=E=>he(xt(E,t.nByteLength));function p(E){let k=n>>It;return E>k}function l(E){return p(E)?c(-E):E}let m=(E,k,L)=>le(E.slice(k,L));class b{constructor(k,L,v){this.r=k,this.s=L,this.recovery=v,this.assertValidity()}static fromCompact(k){let L=t.nByteLength;return k=rt("compactSignature",k,L*2),new b(m(k,0,L),m(k,L,2*L))}static fromDER(k){let{r:L,s:v}=cr.toSig(rt("DER",k));return new b(L,v)}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(k){return new b(this.r,this.s,k)}recoverPublicKey(k){let{r:L,s:v,recovery:d}=this,S=K(rt("msgHash",k));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let I=d===2||d===3?L+t.n:L;if(I>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=d&1?"03":"02",J=f.fromHex(C+x(I)),V=a(I),z=c(-S*V),G=c(v*V),q=f.BASE.multiplyAndAddUnsafe(J,z,G);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return cr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){return x(this.r)+x(this.s)}}let B={isValidPrivateKey(E){try{return u(E),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let E=ns(t.n);return Za(t.randomBytes(E),t.n)},precompute(E=8,k=f.BASE){return k._setWindowSize(E),k.multiply(BigInt(3)),k}};function w(E,k=!0){return f.fromPrivateKey(E).toRawBytes(k)}function P(E){let k=Rt(E),L=typeof E=="string",v=(k||L)&&E.length;return k?v===i||v===o:L?v===2*i||v===2*o:E instanceof f}function A(E,k,L=!0){if(P(E))throw new Error("first arg must be private key");if(!P(k))throw new Error("second arg must be public key");return f.fromHex(k).multiply(u(E)).toRawBytes(L)}let T=t.bits2int||function(E){let k=le(E),L=E.length*8-t.nBitLength;return L>0?k>>BigInt(L):k},K=t.bits2int_modN||function(E){return c(T(E))},U=hn(t.nBitLength);function D(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(ye<=E&&E<U))throw new Error(`bigint expected < 2^${t.nBitLength}`);return xt(E,t.nByteLength)}function O(E,k,L=_){if(["recovered","canonical"].some(Q=>Q in L))throw new Error("sign() legacy options not supported");let{hash:v,randomBytes:d}=t,{lowS:S,prehash:I,extraEntropy:C}=L;S==null&&(S=!0),E=rt("msgHash",E),I&&(E=rt("prehashed msgHash",v(E)));let J=K(E),V=u(k),z=[D(V),D(J)];if(C!=null){let Q=C===!0?d(e.BYTES):C;z.push(rt("extraEntropy",Q))}let G=pe(...z),q=J;function et(Q){let ut=T(Q);if(!y(ut))return;let ht=a(ut),st=f.BASE.multiply(ut).toAffine(),dt=c(st.x);if(dt===ye)return;let te=c(ht*c(q+dt*V));if(te===ye)return;let De=(st.x===dt?0:2)|Number(st.y&It),Rr=te;return S&&p(te)&&(Rr=l(te),De^=1),new b(dt,Rr,De)}return{seed:G,k2sig:et}}let _={lowS:t.lowS,prehash:!1},j={lowS:t.lowS,prehash:!1};function M(E,k,L=_){let{seed:v,k2sig:d}=O(E,k,L),S=t;return zo(S.hash.outputLen,S.nByteLength,S.hmac)(v,d)}f.BASE._setWindowSize(8);function W(E,k,L,v=j){let d=E;if(k=rt("msgHash",k),L=rt("publicKey",L),"strict"in v)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:I}=v,C,J;try{if(typeof d=="string"||Rt(d))try{C=b.fromDER(d)}catch(st){if(!(st instanceof cr.Err))throw st;C=b.fromCompact(d)}else if(typeof d=="object"&&typeof d.r=="bigint"&&typeof d.s=="bigint"){let{r:st,s:dt}=d;C=new b(st,dt)}else throw new Error("PARSE");J=f.fromHex(L)}catch(st){if(st.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&C.hasHighS())return!1;I&&(k=t.hash(k));let{r:V,s:z}=C,G=K(k),q=a(z),et=c(G*q),Q=c(V*q),ut=f.BASE.multiplyAndAddUnsafe(J,et,Q)?.toAffine();return ut?c(ut.x)===V:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:A,sign:M,verify:W,ProjectivePoint:f,Signature:b,utils:B}}var ui=class extends Pr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Va(t);let n=ln(e);if(this.iHash=t.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?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return kr(this),this.iHash.update(t),this}digestInto(t){kr(this),Zo(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},os=(r,t,e)=>new ui(r,t).update(e).digest();os.create=(r,t)=>new ui(r,t);function nd(r){return{hash:r,hmac:(t,...e)=>os(r,t,oi(...e)),randomBytes:dn}}function hi(r,t){let e=n=>Xa({...r,...nd(n)});return Object.freeze({...e(t),create:e})}var ef=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Qa=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),id=BigInt(1),ss=BigInt(2),tf=(r,t)=>(r+t/ss)/t;function od(r){let t=ef,e=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=r*r*r%t,u=f*f*r%t,h=nt(u,e,t)*u%t,y=nt(h,e,t)*u%t,x=nt(y,ss,t)*f%t,p=nt(x,i,t)*x%t,l=nt(p,o,t)*p%t,m=nt(l,c,t)*l%t,b=nt(m,a,t)*m%t,B=nt(b,c,t)*l%t,w=nt(B,e,t)*u%t,P=nt(w,s,t)*p%t,A=nt(P,n,t)*f%t,T=nt(A,ss,t);if(!cs.eql(cs.sqr(T),r))throw new Error("Cannot find square root");return T}var cs=Kr(ef,void 0,void 0,{sqrt:od}),bt=hi({a:BigInt(0),b:BigInt(7),Fp:cs,n:Qa,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Qa,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-id*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,s=BigInt("0x100000000000000000000000000000000"),c=tf(o*r,t),a=tf(-n*r,t),f=X(r-c*e-a*i,t),u=X(-c*n-a*o,t),h=f>s,y=u>s;if(h&&(f=t-f),y&&(u=t-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:h,k1:f,k2neg:y,k2:u}}}},ci),U0=BigInt(0);var K0=bt.ProjectivePoint;function sd(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function li(r,...t){if(!sd(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function as(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function rf(r,t){li(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var me=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var pi=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Mt=(r,t)=>r<<32-t|r>>>t;var R0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function cd(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function fs(r){return typeof r=="string"&&(r=cd(r)),li(r),r}function us(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];li(i),t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var di=class{clone(){return this._cloneInto()}},N0={}.toString;function nf(r){let t=n=>r().update(fs(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function of(r=32){if(me&&typeof me.getRandomValues=="function")return me.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function ad(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,f=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+f,c,n)}var sf=(r,t,e)=>r&t^~r&e,cf=(r,t,e)=>r&t^r&e^t&e,yi=class extends di{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=pi(this.buffer)}update(t){as(this);let{view:e,buffer:n,blockLen:i}=this;t=fs(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=pi(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){as(this),rf(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let h=s;h<i;h++)e[h]=0;ad(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=pi(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)c.setUint32(4*h,u[h],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var fd=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]),Ke=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ie=new Uint32Array(64),hs=class extends yi{constructor(){super(64,32,8,!1),this.A=Ke[0]|0,this.B=Ke[1]|0,this.C=Ke[2]|0,this.D=Ke[3]|0,this.E=Ke[4]|0,this.F=Ke[5]|0,this.G=Ke[6]|0,this.H=Ke[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let h=0;h<16;h++,e+=4)Ie[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let y=Ie[h-15],x=Ie[h-2],p=Mt(y,7)^Mt(y,18)^y>>>3,l=Mt(x,17)^Mt(x,19)^x>>>10;Ie[h]=l+Ie[h-7]+p+Ie[h-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:f,H:u}=this;for(let h=0;h<64;h++){let y=Mt(c,6)^Mt(c,11)^Mt(c,25),x=u+y+sf(c,a,f)+fd[h]+Ie[h]|0,l=(Mt(n,2)^Mt(n,13)^Mt(n,22))+cf(n,i,o)|0;u=f,f=a,a=c,c=s+x|0,s=o,o=i,i=n,n=x+l|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,i,o,s,c,a,f,u)}roundClean(){Ie.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var zt=nf(()=>new hs);function af(r){let t=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=t(n[s]);return o}return n},e=t(r);return JSON.stringify(e)}var Ir=class{static async digest({data:t}){return zt(t)}};var ls="urn:jwk:";async function H({jwk:r}){let t=r.kty,e;if(t==="EC")e={crv:r.crv,kty:r.kty,x:r.x,y:r.y};else if(t==="oct")e={k:r.k,kty:r.kty};else if(t==="OKP")e={crv:r.crv,kty:r.kty,x:r.x};else if(t==="RSA")e={e:r.e,kty:r.kty,n:r.n};else throw new Error(`Unsupported key type: ${t}`);Gi(e);let n=af(e),i=R.string(n).toUint8Array(),o=await Ir.digest({data:i});return R.uint8Array(o).toBase64Url()}function Zt(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 _r(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 Yt(r){return!(!r||typeof r!="object"||!("kty"in r&&"k"in r)||r.kty!=="oct"||typeof r.k!="string")}function Xt(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 Cr(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 ff(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}}function Y0(r){if(!r||typeof r!="object")return!1;switch(r.kty){case"EC":case"OKP":return"x"in r&&!("d"in r);case"RSA":return"n"in r&&"e"in r&&!("d"in r);default:return!1}}var _e=class r{static async adjustSignatureToLowS({signature:t}){let e=bt.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",d:R.uint8Array(t).toBase64Url(),x:R.uint8Array(e.x).toBase64Url(),y:R.uint8Array(e.y).toBase64Url()};return n.kid=await H({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",x:R.uint8Array(e.x).toBase64Url(),y:R.uint8Array(e.y).toBase64Url()};return n.kid=await H({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return bt.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"secp256k1",x:R.uint8Array(n.x).toBase64Url(),y:R.uint8Array(n.y).toBase64Url()};return i.kid=await H({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return bt.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return bt.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=bt.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await H({jwk:e}),e}static async getPublicKey({key:t}){if(!(Zt(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:e,...n}=t;return n.kid??=await H({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Zt(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return R.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(_r(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=R.base64Url(t.x).toUint8Array(),i=R.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return bt.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=zt(t);return bt.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return bt.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{bt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=zt(n);return bt.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=bt.getPublicKey(t));let e=bt.ProjectivePoint.fromHex(t),n=xt(e.x,32),i=xt(e.y,32);return{x:n,y:i}}};var uf=Kr(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),ud=uf.create(BigInt("-3")),hd=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),ld=hi({a:ud,b:hd,Fp:uf,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},ci),Bt=ld;var Ce=class r{static async adjustSignatureToLowS({signature:t}){let e=Bt.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",d:R.uint8Array(t).toBase64Url(),x:R.uint8Array(e.x).toBase64Url(),y:R.uint8Array(e.y).toBase64Url()};return n.kid=await H({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",x:R.uint8Array(e.x).toBase64Url(),y:R.uint8Array(e.y).toBase64Url()};return n.kid=await H({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return Bt.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"P-256",x:R.uint8Array(n.x).toBase64Url(),y:R.uint8Array(n.y).toBase64Url()};return i.kid=await H({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return Bt.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return Bt.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=Bt.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await H({jwk:e}),e}static async getPublicKey({key:t}){if(!(Zt(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:e,...n}=t;return n.kid??=await H({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Zt(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return R.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(_r(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=R.base64Url(t.x).toUint8Array(),i=R.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return Bt.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=zt(t);return Bt.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return Bt.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{Bt.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=zt(n);return Bt.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=Bt.getPublicKey(t));let e=Bt.ProjectivePoint.fromHex(t),n=xt(e.x,32),i=xt(e.y,32);return{x:n,y:i}}};var yn=class extends Ut{async computePublicKey({key:t}){if(!Zt(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await _e.computePublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Ce.computePublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let e=await _e.generateKey();return e.alg="ES256K",e}case"ES256":case"secp256r1":{let e=await Ce.generateKey();return e.alg="ES256",e}}}async getPublicKey({key:t}){if(!Zt(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await _e.getPublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Ce.getPublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!Zt(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return await _e.sign({key:t,data:e});case"P-256":return await Ce.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!_r(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return await _e.verify({key:t,signature:e,data:n});case"P-256":return await Ce.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}};var mi=BigInt(4294967295),ds=BigInt(32);function hf(r,t=!1){return t?{h:Number(r&mi),l:Number(r>>ds&mi)}:{h:Number(r>>ds&mi)|0,l:Number(r&mi)|0}}function dd(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=hf(r[i],t);[e[i],n[i]]=[o,s]}return[e,n]}var pd=(r,t)=>BigInt(r>>>0)<<ds|BigInt(t>>>0),yd=(r,t,e)=>r>>>e,md=(r,t,e)=>r<<32-e|t>>>e,wd=(r,t,e)=>r>>>e|t<<32-e,gd=(r,t,e)=>r<<32-e|t>>>e,xd=(r,t,e)=>r<<64-e|t>>>e-32,bd=(r,t,e)=>r>>>e-32|t<<64-e,Ed=(r,t)=>t,vd=(r,t)=>r,Ad=(r,t,e)=>r<<e|t>>>32-e,Bd=(r,t,e)=>t<<e|r>>>32-e,Td=(r,t,e)=>t<<e-32|r>>>64-e,Sd=(r,t,e)=>r<<e-32|t>>>64-e;function kd(r,t,e,n){let i=(t>>>0)+(n>>>0);return{h:r+e+(i/2**32|0)|0,l:i|0}}var Pd=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ud=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Kd=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Id=(r,t,e,n,i)=>t+e+n+i+(r/2**32|0)|0,_d=(r,t,e,n,i)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(i>>>0),Cd=(r,t,e,n,i,o)=>t+e+n+i+o+(r/2**32|0)|0;var Ld={fromBig:hf,split:dd,toBig:pd,shrSH:yd,shrSL:md,rotrSH:wd,rotrSL:gd,rotrBH:xd,rotrBL:bd,rotr32H:Ed,rotr32L:vd,rotlSH:Ad,rotlSL:Bd,rotlBH:Td,rotlBL:Sd,add:kd,add3L:Pd,add3H:Ud,add4L:Kd,add4H:Id,add5H:Cd,add5L:_d},F=Ld;var[Od,Rd]=F.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))),Le=new Uint32Array(80),Oe=new Uint32Array(80),ps=class extends Ur{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:t,Al:e,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:f,El:u,Fh:h,Fl:y,Gh:x,Gl:p,Hh:l,Hl:m}=this;return[t,e,n,i,o,s,c,a,f,u,h,y,x,p,l,m]}set(t,e,n,i,o,s,c,a,f,u,h,y,x,p,l,m){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=y|0,this.Gh=x|0,this.Gl=p|0,this.Hh=l|0,this.Hl=m|0}process(t,e){for(let w=0;w<16;w++,e+=4)Le[w]=t.getUint32(e),Oe[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let P=Le[w-15]|0,A=Oe[w-15]|0,T=F.rotrSH(P,A,1)^F.rotrSH(P,A,8)^F.shrSH(P,A,7),K=F.rotrSL(P,A,1)^F.rotrSL(P,A,8)^F.shrSL(P,A,7),U=Le[w-2]|0,D=Oe[w-2]|0,O=F.rotrSH(U,D,19)^F.rotrBH(U,D,61)^F.shrSH(U,D,6),_=F.rotrSL(U,D,19)^F.rotrBL(U,D,61)^F.shrSL(U,D,6),j=F.add4L(K,_,Oe[w-7],Oe[w-16]),M=F.add4H(j,T,O,Le[w-7],Le[w-16]);Le[w]=M|0,Oe[w]=j|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:f,Dl:u,Eh:h,El:y,Fh:x,Fl:p,Gh:l,Gl:m,Hh:b,Hl:B}=this;for(let w=0;w<80;w++){let P=F.rotrSH(h,y,14)^F.rotrSH(h,y,18)^F.rotrBH(h,y,41),A=F.rotrSL(h,y,14)^F.rotrSL(h,y,18)^F.rotrBL(h,y,41),T=h&x^~h&l,K=y&p^~y&m,U=F.add5L(B,A,K,Rd[w],Oe[w]),D=F.add5H(U,b,P,T,Od[w],Le[w]),O=U|0,_=F.rotrSH(n,i,28)^F.rotrBH(n,i,34)^F.rotrBH(n,i,39),j=F.rotrSL(n,i,28)^F.rotrBL(n,i,34)^F.rotrBL(n,i,39),M=n&o^n&c^o&c,W=i&s^i&a^s&a;b=l|0,B=m|0,l=x|0,m=p|0,x=h|0,p=y|0,{h,l:y}=F.add(f|0,u|0,D|0,O|0),f=c|0,u=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let E=F.add3L(O,j,W);n=F.add3H(E,D,_,M),i=E|0}({h:n,l:i}=F.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=F.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=F.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=F.add(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:y}=F.add(this.Eh|0,this.El|0,h|0,y|0),{h:x,l:p}=F.add(this.Fh|0,this.Fl|0,x|0,p|0),{h:l,l:m}=F.add(this.Gh|0,this.Gl|0,l|0,m|0),{h:b,l:B}=F.add(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,i,o,s,c,a,f,u,h,y,x,p,l,m,b,B)}roundClean(){Le.fill(0),Oe.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 ys=si(()=>new ps);var jt=BigInt(0),Tt=BigInt(1),wi=BigInt(2),Nd=BigInt(8),Dd={zip215:!0};function Md(r){let t=pn(r);return Kt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function gi(r){let t=Md(r),{Fp:e,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=t,f=wi<<BigInt(c*8)-Tt,u=e.create,h=t.uvRatio||((v,d)=>{try{return{isValid:!0,value:e.sqrt(v*e.inv(d))}}catch{return{isValid:!1,value:jt}}}),y=t.adjustScalarBytes||(v=>v),x=t.domain||((v,d,S)=>{if(d.length||S)throw new Error("Contexts/pre-hash are not supported");return v}),p=v=>typeof v=="bigint"&&jt<v,l=(v,d)=>p(v)&&p(d)&&v<d,m=v=>v===jt||l(v,f);function b(v,d){if(l(v,d))return v;throw new Error(`Expected valid scalar < ${d}, got ${typeof v} ${v}`)}function B(v){return v===jt?v:b(v,n)}let w=new Map;function P(v){if(!(v instanceof A))throw new Error("ExtendedPoint expected")}class A{constructor(d,S,I,C){if(this.ex=d,this.ey=S,this.ez=I,this.et=C,!m(d))throw new Error("x required");if(!m(S))throw new Error("y required");if(!m(I))throw new Error("z required");if(!m(C))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof A)throw new Error("extended point not allowed");let{x:S,y:I}=d||{};if(!m(S)||!m(I))throw new Error("invalid affine point");return new A(S,I,Tt,u(S*I))}static normalizeZ(d){let S=e.invertBatch(d.map(I=>I.ez));return d.map((I,C)=>I.toAffine(S[C])).map(A.fromAffine)}_setWindowSize(d){this._WINDOW_SIZE=d,w.delete(this)}assertValidity(){let{a:d,d:S}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:I,ey:C,ez:J,et:V}=this,z=u(I*I),G=u(C*C),q=u(J*J),et=u(q*q),Q=u(z*d),ut=u(q*u(Q+G)),ht=u(et+u(S*u(z*G)));if(ut!==ht)throw new Error("bad point: equation left != right (1)");let st=u(I*C),dt=u(J*V);if(st!==dt)throw new Error("bad point: equation left != right (2)")}equals(d){P(d);let{ex:S,ey:I,ez:C}=this,{ex:J,ey:V,ez:z}=d,G=u(S*z),q=u(J*C),et=u(I*z),Q=u(V*C);return G===q&&et===Q}is0(){return this.equals(A.ZERO)}negate(){return new A(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:S,ey:I,ez:C}=this,J=u(S*S),V=u(I*I),z=u(wi*u(C*C)),G=u(d*J),q=S+I,et=u(u(q*q)-J-V),Q=G+V,ut=Q-z,ht=G-V,st=u(et*ut),dt=u(Q*ht),te=u(et*ht),De=u(ut*Q);return new A(st,dt,De,te)}add(d){P(d);let{a:S,d:I}=t,{ex:C,ey:J,ez:V,et:z}=this,{ex:G,ey:q,ez:et,et:Q}=d;if(S===BigInt(-1)){let Ks=u((J-C)*(q+G)),Is=u((J+C)*(q-G)),Pi=u(Is-Ks);if(Pi===jt)return this.double();let _s=u(V*wi*Q),Cs=u(z*wi*et),Ls=Cs+_s,Os=Is+Ks,Rs=Cs-_s,Qf=u(Ls*Pi),tu=u(Os*Rs),eu=u(Ls*Rs),ru=u(Pi*Os);return new A(Qf,tu,ru,eu)}let ut=u(C*G),ht=u(J*q),st=u(z*I*Q),dt=u(V*et),te=u((C+J)*(G+q)-ut-ht),De=dt-st,Rr=dt+st,Us=u(ht-S*ut),zf=u(te*De),Zf=u(Rr*Us),Yf=u(te*Us),Xf=u(De*Rr);return new A(zf,Zf,Xf,Yf)}subtract(d){return this.add(d.negate())}wNAF(d){return U.wNAFCached(this,w,d,A.normalizeZ)}multiply(d){let{p:S,f:I}=this.wNAF(b(d,n));return A.normalizeZ([S,I])[0]}multiplyUnsafe(d){let S=B(d);return S===jt?K:this.equals(K)||S===Tt?this:this.equals(T)?this.wNAF(S).p:U.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(d){let{ex:S,ey:I,ez:C}=this,J=this.is0();d==null&&(d=J?Nd:e.inv(C));let V=u(S*d),z=u(I*d),G=u(C*d);if(J)return{x:jt,y:Tt};if(G!==Tt)throw new Error("invZ was invalid");return{x:V,y:z}}clearCofactor(){let{h:d}=t;return d===Tt?this:this.multiplyUnsafe(d)}static fromHex(d,S=!1){let{d:I,a:C}=t,J=e.BYTES;d=rt("pointHex",d,J);let V=d.slice(),z=d[J-1];V[J-1]=z&-129;let G=Nt(V);G===jt||(S?b(G,f):b(G,e.ORDER));let q=u(G*G),et=u(q-Tt),Q=u(I*q-C),{isValid:ut,value:ht}=h(et,Q);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let st=(ht&Tt)===Tt,dt=(z&128)!==0;if(!S&&ht===jt&&dt)throw new Error("Point.fromHex: x=0 and x_0=1");return dt!==st&&(ht=u(-ht)),A.fromAffine({x:ht,y:G})}static fromPrivateKey(d){return _(d).point}toRawBytes(){let{x:d,y:S}=this.toAffine(),I=de(S,e.BYTES);return I[I.length-1]|=d&Tt?128:0,I}toHex(){return he(this.toRawBytes())}}A.BASE=new A(t.Gx,t.Gy,Tt,u(t.Gx*t.Gy)),A.ZERO=new A(jt,Tt,Tt,jt);let{BASE:T,ZERO:K}=A,U=fi(A,c*8);function D(v){return X(v,n)}function O(v){return D(Nt(v))}function _(v){let d=c;v=rt("private key",v,d);let S=rt("hashed private key",o(v),2*d),I=y(S.slice(0,d)),C=S.slice(d,2*d),J=O(I),V=T.multiply(J),z=V.toRawBytes();return{head:I,prefix:C,scalar:J,point:V,pointBytes:z}}function j(v){return _(v).pointBytes}function M(v=new Uint8Array,...d){let S=pe(...d);return O(o(x(S,rt("context",v),!!i)))}function W(v,d,S={}){v=rt("message",v),i&&(v=i(v));let{prefix:I,scalar:C,pointBytes:J}=_(d),V=M(S.context,I,v),z=T.multiply(V).toRawBytes(),G=M(S.context,z,J,v),q=D(V+G*C);B(q);let et=pe(z,de(q,e.BYTES));return rt("result",et,c*2)}let E=Dd;function k(v,d,S,I=E){let{context:C,zip215:J}=I,V=e.BYTES;v=rt("signature",v,2*V),d=rt("message",d),i&&(d=i(d));let z=Nt(v.slice(V,2*V)),G,q,et;try{G=A.fromHex(S,J),q=A.fromHex(v.slice(0,V),J),et=T.multiplyUnsafe(z)}catch{return!1}if(!J&&G.isSmallOrder())return!1;let Q=M(C,q.toRawBytes(),G.toRawBytes(),d);return q.add(G.multiplyUnsafe(Q)).subtract(et).clearCofactor().equals(A.ZERO)}return T._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:W,verify:k,ExtendedPoint:A,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>s(e.BYTES),precompute(v=8,d=A.BASE){return d._setWindowSize(v),d.multiply(BigInt(3)),d}}}}var mn=BigInt(0),ms=BigInt(1);function jd(r){return Kt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function lf(r){let t=jd(r),{P:e}=t,n=w=>X(w,e),i=t.montgomeryBits,o=Math.ceil(i/8),s=t.nByteLength,c=t.adjustScalarBytes||(w=>w),a=t.powPminus2||(w=>ts(w,e-BigInt(2),e));function f(w,P,A){let T=n(w*(P-A));return P=n(P-T),A=n(A+T),[P,A]}function u(w){if(typeof w=="bigint"&&mn<=w&&w<e)return w;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let h=(t.a-BigInt(2))/BigInt(4);function y(w,P){let A=u(w),T=u(P),K=A,U=ms,D=mn,O=A,_=ms,j=mn,M;for(let E=BigInt(i-1);E>=mn;E--){let k=T>>E&ms;j^=k,M=f(j,U,O),U=M[0],O=M[1],M=f(j,D,_),D=M[0],_=M[1],j=k;let L=U+D,v=n(L*L),d=U-D,S=n(d*d),I=v-S,C=O+_,J=O-_,V=n(J*L),z=n(C*d),G=V+z,q=V-z;O=n(G*G),_=n(K*n(q*q)),U=n(v*S),D=n(I*(v+n(h*I)))}M=f(j,U,O),U=M[0],O=M[1],M=f(j,D,_),D=M[0],_=M[1];let W=a(D);return n(U*W)}function x(w){return de(n(w),o)}function p(w){let P=rt("u coordinate",w,o);return s===32&&(P[31]&=127),Nt(P)}function l(w){let P=rt("scalar",w),A=P.length;if(A!==o&&A!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${A}`);return Nt(c(P))}function m(w,P){let A=p(P),T=l(w),K=y(A,T);if(K===mn)throw new Error("Invalid private or public key received");return x(K)}let b=x(t.Gu);function B(w){return m(w,b)}return{scalarMult:m,scalarMultBase:B,getSharedSecret:(w,P)=>m(w,P),getPublicKey:w=>B(w),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:b}}var wn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),df=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Nm=BigInt(0),Jd=BigInt(1),ws=BigInt(2),Vd=BigInt(5),pf=BigInt(10),Hd=BigInt(20),Gd=BigInt(40),yf=BigInt(80);function mf(r){let t=wn,n=r*r%t*r%t,i=nt(n,ws,t)*n%t,o=nt(i,Jd,t)*r%t,s=nt(o,Vd,t)*o%t,c=nt(s,pf,t)*s%t,a=nt(c,Hd,t)*c%t,f=nt(a,Gd,t)*a%t,u=nt(f,yf,t)*f%t,h=nt(u,yf,t)*f%t,y=nt(h,pf,t)*s%t;return{pow_p_5_8:nt(y,ws,t)*r%t,b2:n}}function wf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function qd(r,t){let e=wn,n=X(t*t*t,e),i=X(n*n*t,e),o=mf(r*i).pow_p_5_8,s=X(r*n*o,e),c=X(t*s*s,e),a=s,f=X(s*df,e),u=c===r,h=c===X(-r,e),y=c===X(-r*df,e);return u&&(s=a),(h||y)&&(s=f),$a(s,e)&&(s=X(-s,e)),{isValid:u||h,value:s}}var _t=Kr(wn,void 0,!0),gn={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:_t,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ys,randomBytes:dn,adjustScalarBytes:wf,uvRatio:qd},Re=gi(gn);function gf(r,t,e){if(t.length>255)throw new Error("Context is too big");return oi(Yo("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Dm=gi({...gn,domain:gf}),Mm=gi({...gn,domain:gf,prehash:ys}),ar=lf({P:wn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let t=wn,{pow_p_5_8:e,b2:n}=mf(r);return X(nt(e,BigInt(3),t)*n,t)},adjustScalarBytes:wf,randomBytes:dn});function xf(r){let{y:t}=Re.ExtendedPoint.fromHex(r),e=BigInt(1);return _t.toBytes(_t.create((e+t)*_t.inv(e-t)))}function bf(r){let t=gn.hash(r.subarray(0,32));return gn.adjustScalarBytes(t).subarray(0,32)}var Fd=(_t.ORDER+BigInt(3))/BigInt(8),jm=_t.pow(ws,Fd),Jm=_t.sqrt(_t.neg(_t.ONE)),Vm=(_t.ORDER-BigInt(5))/BigInt(8),Hm=BigInt(486662);var Gm=Wa(_t,_t.neg(BigInt(486664)));var qm=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Fm=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$m=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Wm=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var zm=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ne=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=Re.getPublicKey(t),n={crv:"Ed25519",d:R.uint8Array(t).toBase64Url(),kty:"OKP",x:R.uint8Array(e).toBase64Url()};return n.kid=await H({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"Ed25519",x:R.uint8Array(t).toBase64Url()};return e.kid=await H({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=Re.getPublicKey(e),i={kty:"OKP",crv:"Ed25519",x:R.uint8Array(n).toBase64Url()};return i.kid=await H({jwk:i}),i}static async convertPrivateKeyToX25519({privateKey:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=bf(e),i=ar.getPublicKey(n),o={kty:"OKP",crv:"X25519",d:R.uint8Array(n).toBase64Url(),x:R.uint8Array(i).toBase64Url()};return o.kid=await H({jwk:o}),o}static async convertPublicKeyToX25519({publicKey:t}){let e=await r.publicKeyToBytes({publicKey:t});if(!await r.validatePublicKey({publicKeyBytes:e}))throw new Error("Ed25519: Invalid public key.");let i=xf(e),o={kty:"OKP",crv:"X25519",x:R.uint8Array(i).toBase64Url()};return o.kid=await H({jwk:o}),o}static async generateKey(){let t=Re.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await H({jwk:e}),e}static async getPublicKey({key:t}){if(!(Xt(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:e,...n}=t;return n.kid??=await H({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Xt(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return R.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!Cr(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return R.base64Url(t.x).toUint8Array()}static async sign({key:t,data:e}){let n=await r.privateKeyToBytes({privateKey:t});return Re.sign(e,n)}static async validatePublicKey({publicKeyBytes:t}){try{Re.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t});return Re.verify(e,n,i)}};var xi=class extends Ut{async computePublicKey({key:t}){if(!Xt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ne.computePublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"Ed25519":{let e=await Ne.generateKey();return e.alg="EdDSA",e}}}async getPublicKey({key:t}){if(!Xt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ne.getPublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!Xt(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return await Ne.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!Cr(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return await Ne.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}};var bi=class extends Ut{async digest({algorithm:t,data:e}){switch(t){case"SHA-256":return await Ir.digest({data:e})}}};var gs={Ed25519:{implementation:xi,names:["Ed25519"]},secp256k1:{implementation:yn,names:["ES256K","secp256k1"]},secp256r1:{implementation:yn,names:["ES256","secp256r1"]},"SHA-256":{implementation:bi,names:["SHA-256"]}},Ef=class{constructor(t){this._algorithmInstances=new Map;this._keyStore=t?.keyStore??new ti}async digest({algorithm:t,data:e}){return await this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:e})}async exportKey({keyUri:t}){return await this.getPrivateKey({keyUri:t})}async generateKey({algorithm:t}){let n=await this.getAlgorithm({algorithm:t}).generateKey({algorithm:t});if(n?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let i=`${ls}${n.kid}`;return await this._keyStore.set(i,n),i}async getKeyUri({key:t}){let e=await H({jwk:t});return`${ls}${e}`}async getPublicKey({keyUri:t}){let e=await this.getPrivateKey({keyUri:t}),n=this.getAlgorithmName({key:e});return await this.getAlgorithm({algorithm:n}).getPublicKey({key:e})}async importKey({key:t}){if(!ff(t))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let e=structuredClone(t);e.kid??=await H({jwk:e});let n=await this.getKeyUri({key:e});return await this._keyStore.set(n,e),n}async sign({keyUri:t,data:e}){let n=await this.getPrivateKey({keyUri:t}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:e,key:n})}async verify({key:t,signature:e,data:n}){let i=this.getAlgorithmName({key:t});return this.getAlgorithm({algorithm:i}).verify({key:t,signature:e,data:n})}getAlgorithm({algorithm:t}){let e=gs[t]?.implementation;if(!e)throw new Error(`Algorithm not supported: ${t}`);return this._algorithmInstances.has(e)||this._algorithmInstances.set(e,new e),this._algorithmInstances.get(e)}getAlgorithmName({key:t}){let e=t.alg,n=t.crv;for(let i in gs){let o=gs[i];if(e&&o.names.includes(e))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${e}, crv=${n}`)}async getPrivateKey({keyUri:t}){let e=await this._keyStore.get(t);if(!e)throw new Error(`Key not found: ${t}`);return e}};var vf=class r{static getJoseSignatureAlgorithmFromPublicKey(t){let e={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(t.alg&&Object.values(e).includes(t.alg))return t.alg;if(t.crv&&Object.keys(e).includes(t.crv))return e[t.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${t.alg}, crv=${t.crv}. Supported 'alg' values: ${Object.values(e).join(", ")}. Supported 'crv' values: ${Object.keys(e).join(", ")}.`)}static randomBytes(t){return of(t)}static randomUuid(){return me.randomUUID()}static randomPin({length:t}){if(3>t||t>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let e=Math.pow(10,t)-1,n;if(t<=6){let i=Math.pow(10,t);do{let o=r.randomBytes(Math.ceil(t/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>e)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>e)}return n.toString().padStart(t,"0")}};var Ei=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ot(){if(Ei&&typeof Ei.subtle=="object"&&Ei.subtle!=null)return Ei.subtle;throw new Error("crypto.subtle must be defined")}var xn=128,Af=[128,192,256],vi=xn,Lr=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:R.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await H({jwk:e}),e}static async decrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==xn/8)throw new TypeError(`The counter must be ${xn} bits in length`);if(i===0||i>vi)throw new TypeError(`The 'length' property must be in the range 1 to ${vi}`);let o=ot(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["decrypt"]),c=await o.decrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async encrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==xn/8)throw new TypeError(`The counter must be ${xn} bits in length`);if(i===0||i>vi)throw new TypeError(`The 'length' property must be in the range 1 to ${vi}`);let o=ot(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["encrypt","decrypt"]),c=await o.encrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async generateKey({length:t}){if(!Af.includes(t))throw new RangeError(`The key length is invalid: Must be ${Af.join(", ")} bits`);let e=ot(),n=await e.generateKey({name:"AES-CTR",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await H({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!Yt(t))throw new Error("AesCtr: The provided key is not a valid oct private key.");return R.base64Url(t.k).toUint8Array()}};var Bf=class extends Ut{async decrypt(t){return Lr.decrypt(t)}async encrypt(t){return Lr.encrypt(t)}async generateKey({algorithm:t}){let e={A128CTR:128,A192CTR:192,A256CTR:256}[t],n=await Lr.generateKey({length:e});return n.alg=t,n}};function bn(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function xs(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function bs(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function at(r,...t){if(!bs(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Es(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Tf(r,t){at(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var we=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Sf=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),$d=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!$d)throw new Error("Non little-endian hardware is not supported");function Wd(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ai(r){if(typeof r=="string")r=Wd(r);else if(bs(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function kf(r,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(r,t)}function Pf(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var vs=(r,t)=>(Object.assign(t,r),t);function As(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,f=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+f,c,n)}var Uf={async encrypt(r,t,e,n){let i=ot(),o=await i.importKey("raw",r,t,!0,["encrypt"]),s=await i.encrypt(e,o,n);return new Uint8Array(s)},async decrypt(r,t,e,n){let i=ot(),o=await i.importKey("raw",r,t,!0,["decrypt"]),s=await i.decrypt(e,o,n);return new Uint8Array(s)}},Qt={CBC:"AES-CBC",CTR:"AES-CTR",GCM:"AES-GCM"};function zd(r,t,e){if(r===Qt.CBC)return{name:Qt.CBC,iv:t};if(r===Qt.CTR)return{name:Qt.CTR,counter:t,length:64};if(r===Qt.GCM)return e?{name:Qt.GCM,iv:t,additionalData:e}:{name:Qt.GCM,iv:t};throw new Error("unknown aes block mode")}function Bs(r){return(t,e,n)=>{at(t),at(e);let i={name:r,length:t.length*8},o=zd(r,e,n);return{encrypt(s){return at(s),Uf.encrypt(t,i,o,s)},decrypt(s){return at(s),Uf.decrypt(t,i,o,s)}}}}var Iw=Bs(Qt.CBC),_w=Bs(Qt.CTR),Cw=Bs(Qt.GCM);var Bi=96,Kf=[128,192,256],Ti=[96,104,112,120,128],Or=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:R.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await H({jwk:e}),e}static async decrypt({key:t,data:e,iv:n,additionalData:i,tagLength:o}){if(n.byteLength!==Bi/8)throw new TypeError(`The initialization vector must be ${Bi} bits in length`);if(o&&!Ti.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Ti.join(", ")} bits`);let s=ot(),c=await s.importKey("jwk",t,{name:"AES-GCM"},!0,["decrypt"]),a={name:"AES-GCM",iv:n,...o&&{tagLength:o},...i&&{additionalData:i}},f=await s.decrypt(a,c,e);return new Uint8Array(f)}static async encrypt({data:t,iv:e,key:n,additionalData:i,tagLength:o}){if(e.byteLength!==Bi/8)throw new TypeError(`The initialization vector must be ${Bi} bits in length`);if(o&&!Ti.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Ti.join(", ")} bits`);let s=ot(),c=await s.importKey("jwk",n,{name:"AES-GCM"},!0,["encrypt"]),a={name:"AES-GCM",iv:e,...o&&{tagLength:o},...i&&{additionalData:i}},f=await s.encrypt(a,c,t);return new Uint8Array(f)}static async generateKey({length:t}){if(!Kf.includes(t))throw new RangeError(`The key length is invalid: Must be ${Kf.join(", ")} bits`);let e=ot(),n=await e.generateKey({name:"AES-GCM",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await H({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!Yt(t))throw new Error("AesGcm: The provided key is not a valid oct private key.");return R.base64Url(t.k).toUint8Array()}};var If=class extends Ut{async decrypt(t){return Or.decrypt(t)}async encrypt(t){return Or.encrypt(t)}async generateKey({algorithm:t}){let e={A128GCM:128,A192GCM:192,A256GCM:256}[t],n=await Or.generateKey({length:e});return n.alg=t,n}};var _f=[128,192,256],Cf=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:R.uint8Array(t).toBase64Url(),kty:"oct"};e.kid=await H({jwk:e});let n=t.length*8;return e.alg={128:"A128KW",192:"A192KW",256:"A256KW"}[n],e}static async generateKey({length:t}){if(!_f.includes(t))throw new RangeError(`The key length is invalid: Must be ${_f.join(", ")} bits`);let e=ot(),n=await e.generateKey({name:"AES-KW",length:t},!0,["wrapKey","unwrapKey"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await H({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!Yt(t))throw new Error("AesKw: The provided key is not a valid oct private key.");return R.base64Url(t.k).toUint8Array()}static async unwrapKey({wrappedKeyBytes:t,wrappedKeyAlgorithm:e,decryptionKey:n}){if(!("alg"in n&&n.alg))throw new Jt("invalidJwk","The decryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(n.alg))throw new Jt("algorithmNotSupported",`The 'decryptionKey' algorithm is not supported: ${n.alg}`);let i=ot(),o=await i.importKey("jwk",n,{name:"AES-KW"},!0,["unwrapKey"]),s={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[e];if(!s)throw new Jt("algorithmNotSupported",`The 'wrappedKeyAlgorithm' is not supported: ${e}`);let c=await i.unwrapKey("raw",t.buffer,o,"AES-KW",{name:s},!0,["unwrapKey"]),{ext:a,key_ops:f,...u}=await i.exportKey("jwk",c),h=u;return h.kid=await H({jwk:h}),h}static async wrapKey({unwrappedKey:t,encryptionKey:e}){if(!("alg"in e&&e.alg))throw new Jt("invalidJwk","The encryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(e.alg))throw new Jt("algorithmNotSupported",`The 'encryptionKey' algorithm is not supported: ${e.alg}`);if(!("alg"in t&&t.alg))throw new Jt("invalidJwk","The private key to wrap is missing the 'alg' property.");let n=ot(),i=await n.importKey("jwk",e,{name:"AES-KW"},!0,["wrapKey"]),o={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[t.alg];if(!o)throw new Jt("algorithmNotSupported",`The 'unwrappedKey' algorithm is not supported: ${t.alg}`);let s=await n.importKey("jwk",t,{name:o},!0,["unwrapKey"]),c=await n.wrapKey("raw",s,i,"AES-KW");return new Uint8Array(c)}};var Lf=class r{static async deriveKey({keyDataLen:t,fixedInfo:e,sharedSecret:n}){let o=Math.ceil(t/256);if(o!==1)throw new Error(`Concat KDF with ${o} rounds not supported.`);let s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,o);let c=r.computeFixedInfo(e);return zt(us(s,n,c)).slice(0,t/8)}static computeFixedInfo(t){let e=r.toDataLenData({data:t.algorithmId}),n=r.toDataLenData({data:t.partyUInfo}),i=r.toDataLenData({data:t.partyVInfo}),o=r.toDataLenData({data:t.suppPubInfo,variableLength:!1}),s=r.toDataLenData({data:t.suppPrivInfo});return us(e,n,i,o,s)}static toDataLenData({data:t,variableLength:e=!0}){let n,i=Dr(t);if(i==="Undefined")return new Uint8Array(0);if(e){let o=i==="Uint8Array"?t:new R(t,i).toUint8Array(),s=o.length;n=new Uint8Array(4+s),new DataView(n.buffer).setUint32(0,s),n.set(o,4)}else{if(typeof t!="number")throw TypeError("Fixed length input must be a number.");n=new Uint8Array(4),new DataView(n.buffer).setUint32(0,t)}return n}};var Of=class{static async deriveKeyBytes({baseKeyBytes:t,length:e,hash:n,salt:i,info:o=new Uint8Array}){let s=ot(),c=await s.importKey("raw",t,{name:"HKDF"},!1,["deriveBits"]),a=typeof i=="string"?R.string(i).toUint8Array():i,f=typeof o=="string"?R.string(o).toUint8Array():o,u=await s.deriveBits({name:"HKDF",hash:n,salt:a,info:f},c,e);return new Uint8Array(u)}};var Rf=class{static async deriveKey({hash:t,password:e,salt:n,iterations:i,length:o}){let s=await me.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"]),c=await me.subtle.deriveBits({name:"PBKDF2",hash:t,salt:n,iterations:i},s,o);return new Uint8Array(c)}static async deriveKeyBytes({baseKeyBytes:t,hash:e,salt:n,iterations:i,length:o}){let s=ot(),c=await s.importKey("raw",t,{name:"PBKDF2"},!1,["deriveBits"]),a=await s.deriveBits({name:"PBKDF2",hash:e,salt:n,iterations:i},c,o);return new Uint8Array(a)}};var Nf=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=ar.getPublicKey(t),n={kty:"OKP",crv:"X25519",d:R.uint8Array(t).toBase64Url(),x:R.uint8Array(e).toBase64Url()};return n.kid=await H({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"X25519",x:R.uint8Array(t).toBase64Url()};return e.kid=await H({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=ar.getPublicKey(e),i={kty:"OKP",crv:"X25519",x:R.uint8Array(n).toBase64Url()};return i.kid=await H({jwk:i}),i}static async generateKey(){let t=ar.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await H({jwk:e}),e}static async getPublicKey({key:t}){if(!(Xt(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:e,...n}=t;return n.kid??=await H({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Xt(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return R.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!Cr(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return R.base64Url(t.x).toUint8Array()}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return ar.getSharedSecret(n,i)}};var lt=(r,t)=>r[t++]&255|(r[t++]&255)<<8,Ts=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=Ai(t),at(t,32);let e=lt(t,0),n=lt(t,2),i=lt(t,4),o=lt(t,6),s=lt(t,8),c=lt(t,10),a=lt(t,12),f=lt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=lt(t,16+2*u)}process(t,e,n=!1){let i=n?0:2048,{h:o,r:s}=this,c=s[0],a=s[1],f=s[2],u=s[3],h=s[4],y=s[5],x=s[6],p=s[7],l=s[8],m=s[9],b=lt(t,e+0),B=lt(t,e+2),w=lt(t,e+4),P=lt(t,e+6),A=lt(t,e+8),T=lt(t,e+10),K=lt(t,e+12),U=lt(t,e+14),D=o[0]+(b&8191),O=o[1]+((b>>>13|B<<3)&8191),_=o[2]+((B>>>10|w<<6)&8191),j=o[3]+((w>>>7|P<<9)&8191),M=o[4]+((P>>>4|A<<12)&8191),W=o[5]+(A>>>1&8191),E=o[6]+((A>>>14|T<<2)&8191),k=o[7]+((T>>>11|K<<5)&8191),L=o[8]+((K>>>8|U<<8)&8191),v=o[9]+(U>>>5|i),d=0,S=d+D*c+O*(5*m)+_*(5*l)+j*(5*p)+M*(5*x);d=S>>>13,S&=8191,S+=W*(5*y)+E*(5*h)+k*(5*u)+L*(5*f)+v*(5*a),d+=S>>>13,S&=8191;let I=d+D*a+O*c+_*(5*m)+j*(5*l)+M*(5*p);d=I>>>13,I&=8191,I+=W*(5*x)+E*(5*y)+k*(5*h)+L*(5*u)+v*(5*f),d+=I>>>13,I&=8191;let C=d+D*f+O*a+_*c+j*(5*m)+M*(5*l);d=C>>>13,C&=8191,C+=W*(5*p)+E*(5*x)+k*(5*y)+L*(5*h)+v*(5*u),d+=C>>>13,C&=8191;let J=d+D*u+O*f+_*a+j*c+M*(5*m);d=J>>>13,J&=8191,J+=W*(5*l)+E*(5*p)+k*(5*x)+L*(5*y)+v*(5*h),d+=J>>>13,J&=8191;let V=d+D*h+O*u+_*f+j*a+M*c;d=V>>>13,V&=8191,V+=W*(5*m)+E*(5*l)+k*(5*p)+L*(5*x)+v*(5*y),d+=V>>>13,V&=8191;let z=d+D*y+O*h+_*u+j*f+M*a;d=z>>>13,z&=8191,z+=W*c+E*(5*m)+k*(5*l)+L*(5*p)+v*(5*x),d+=z>>>13,z&=8191;let G=d+D*x+O*y+_*h+j*u+M*f;d=G>>>13,G&=8191,G+=W*a+E*c+k*(5*m)+L*(5*l)+v*(5*p),d+=G>>>13,G&=8191;let q=d+D*p+O*x+_*y+j*h+M*u;d=q>>>13,q&=8191,q+=W*f+E*a+k*c+L*(5*m)+v*(5*l),d+=q>>>13,q&=8191;let et=d+D*l+O*p+_*x+j*y+M*h;d=et>>>13,et&=8191,et+=W*u+E*f+k*a+L*c+v*(5*m),d+=et>>>13,et&=8191;let Q=d+D*m+O*l+_*p+j*x+M*y;d=Q>>>13,Q&=8191,Q+=W*h+E*u+k*f+L*a+v*c,d+=Q>>>13,Q&=8191,d=(d<<2)+d|0,d=d+S|0,S=d&8191,d=d>>>13,I+=d,o[0]=S,o[1]=I,o[2]=C,o[3]=J,o[4]=V,o[5]=z,o[6]=G,o[7]=q,o[8]=et,o[9]=Q}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),i=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=i,i=t[c]>>>13,t[c]&=8191;t[0]+=i*5,i=t[0]>>>13,t[0]&=8191,t[1]+=i,i=t[1]>>>13,t[1]&=8191,t[2]+=i,n[0]=t[0]+5,i=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+i,i=n[c]>>>13,n[c]&=8191;n[9]-=8192;let o=(i^1)-1;for(let c=0;c<10;c++)n[c]&=o;o=~o;for(let c=0;c<10;c++)t[c]=t[c]&o|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let s=t[0]+e[0];t[0]=s&65535;for(let c=1;c<8;c++)s=(t[c]+e[c]|0)+(s>>>16)|0,t[c]=s&65535}update(t){Es(this);let{buffer:e,blockLen:n}=this;t=Ai(t);let i=t.length;for(let o=0;o<i;){let s=Math.min(n-this.pos,i-o);if(s===n){for(;n<=i-o;o+=n)this.process(t,o);continue}e.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){Es(this),Tf(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:i}=this;if(i){for(e[i++]=1;i<16;i++)e[i]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)t[o++]=n[s]>>>0,t[o++]=n[s]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function Zd(r){let t=(n,i)=>r(i).update(Ai(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var Df=Zd(r=>new Ts(r));var jf=r=>Uint8Array.from(r.split("").map(t=>t.charCodeAt(0))),Yd=jf("expand 16-byte k"),Xd=jf("expand 32-byte k"),Qd=we(Yd),Jf=we(Xd),lg=Jf.slice();function N(r,t){return r<<t|r>>>32-t}function Ss(r){return r.byteOffset%4===0}var Si=64,tp=16,Vf=2**32-1,Mf=new Uint32Array;function ep(r,t,e,n,i,o,s,c){let a=i.length,f=new Uint8Array(Si),u=we(f),h=Ss(i)&&Ss(o),y=h?we(i):Mf,x=h?we(o):Mf;for(let p=0;p<a;s++){if(r(t,e,n,u,s,c),s>=Vf)throw new Error("arx: counter overflow");let l=Math.min(Si,a-p);if(h&&l===Si){let m=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let b=0,B;b<tp;b++)B=m+b,x[B]=y[B]^u[b];p+=Si;continue}for(let m=0,b;m<l;m++)b=p+m,o[b]=i[b]^f[m];p+=l}}function ks(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=kf({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return bn(i),bn(s),xs(o),xs(e),(c,a,f,u,h=0)=>{at(c),at(a),at(f);let y=f.length;if(u||(u=new Uint8Array(y)),at(u),bn(h),h<0||h>=Vf)throw new Error("arx: counter overflow");if(u.length<y)throw new Error(`arx: output (${u.length}) is shorter than data (${y})`);let x=[],p=c.length,l,m;if(p===32)l=c.slice(),x.push(l),m=Jf;else if(p===16&&e)l=new Uint8Array(32),l.set(c),l.set(c,16),m=Qd,x.push(l);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Ss(a)||(a=a.slice(),x.push(a));let b=we(l);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(m,b,we(a.subarray(0,16)),b),a=a.subarray(16)}let B=16-i;if(B!==a.length)throw new Error(`arx: nonce must be ${B} or 16 bytes`);if(B!==12){let P=new Uint8Array(12);P.set(a,o?0:12-a.length),a=P,x.push(a)}let w=we(a);for(ep(r,m,b,w,f,u,h,s);x.length>0;)x.pop().fill(0);return u}}function qf(r,t,e,n,i,o=20){let s=r[0],c=r[1],a=r[2],f=r[3],u=t[0],h=t[1],y=t[2],x=t[3],p=t[4],l=t[5],m=t[6],b=t[7],B=i,w=e[0],P=e[1],A=e[2],T=s,K=c,U=a,D=f,O=u,_=h,j=y,M=x,W=p,E=l,k=m,L=b,v=B,d=w,S=P,I=A;for(let J=0;J<o;J+=2)T=T+O|0,v=N(v^T,16),W=W+v|0,O=N(O^W,12),T=T+O|0,v=N(v^T,8),W=W+v|0,O=N(O^W,7),K=K+_|0,d=N(d^K,16),E=E+d|0,_=N(_^E,12),K=K+_|0,d=N(d^K,8),E=E+d|0,_=N(_^E,7),U=U+j|0,S=N(S^U,16),k=k+S|0,j=N(j^k,12),U=U+j|0,S=N(S^U,8),k=k+S|0,j=N(j^k,7),D=D+M|0,I=N(I^D,16),L=L+I|0,M=N(M^L,12),D=D+M|0,I=N(I^D,8),L=L+I|0,M=N(M^L,7),T=T+_|0,I=N(I^T,16),k=k+I|0,_=N(_^k,12),T=T+_|0,I=N(I^T,8),k=k+I|0,_=N(_^k,7),K=K+j|0,v=N(v^K,16),L=L+v|0,j=N(j^L,12),K=K+j|0,v=N(v^K,8),L=L+v|0,j=N(j^L,7),U=U+M|0,d=N(d^U,16),W=W+d|0,M=N(M^W,12),U=U+M|0,d=N(d^U,8),W=W+d|0,M=N(M^W,7),D=D+O|0,S=N(S^D,16),E=E+S|0,O=N(O^E,12),D=D+O|0,S=N(S^D,8),E=E+S|0,O=N(O^E,7);let C=0;n[C++]=s+T|0,n[C++]=c+K|0,n[C++]=a+U|0,n[C++]=f+D|0,n[C++]=u+O|0,n[C++]=h+_|0,n[C++]=y+j|0,n[C++]=x+M|0,n[C++]=p+W|0,n[C++]=l+E|0,n[C++]=m+k|0,n[C++]=b+L|0,n[C++]=B+v|0,n[C++]=w+d|0,n[C++]=P+S|0,n[C++]=A+I|0}function rp(r,t,e,n){let i=r[0],o=r[1],s=r[2],c=r[3],a=t[0],f=t[1],u=t[2],h=t[3],y=t[4],x=t[5],p=t[6],l=t[7],m=e[0],b=e[1],B=e[2],w=e[3];for(let A=0;A<20;A+=2)i=i+a|0,m=N(m^i,16),y=y+m|0,a=N(a^y,12),i=i+a|0,m=N(m^i,8),y=y+m|0,a=N(a^y,7),o=o+f|0,b=N(b^o,16),x=x+b|0,f=N(f^x,12),o=o+f|0,b=N(b^o,8),x=x+b|0,f=N(f^x,7),s=s+u|0,B=N(B^s,16),p=p+B|0,u=N(u^p,12),s=s+u|0,B=N(B^s,8),p=p+B|0,u=N(u^p,7),c=c+h|0,w=N(w^c,16),l=l+w|0,h=N(h^l,12),c=c+h|0,w=N(w^c,8),l=l+w|0,h=N(h^l,7),i=i+f|0,w=N(w^i,16),p=p+w|0,f=N(f^p,12),i=i+f|0,w=N(w^i,8),p=p+w|0,f=N(f^p,7),o=o+u|0,m=N(m^o,16),l=l+m|0,u=N(u^l,12),o=o+u|0,m=N(m^o,8),l=l+m|0,u=N(u^l,7),s=s+h|0,b=N(b^s,16),y=y+b|0,h=N(h^y,12),s=s+h|0,b=N(b^s,8),y=y+b|0,h=N(h^y,7),c=c+a|0,B=N(B^c,16),x=x+B|0,a=N(a^x,12),c=c+a|0,B=N(B^c,8),x=x+B|0,a=N(a^x,7);let P=0;n[P++]=i,n[P++]=o,n[P++]=s,n[P++]=c,n[P++]=m,n[P++]=b,n[P++]=B,n[P++]=w}var np=ks(qf,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ki=ks(qf,{counterRight:!1,counterLength:8,extendNonceFn:rp,allowShortKeys:!1});var ip=new Uint8Array(16),Hf=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(ip.subarray(e))},op=new Uint8Array(32);function Gf(r,t,e,n,i){let o=r(t,e,op),s=Df.create(o);i&&Hf(s,i),Hf(s,n);let c=new Uint8Array(16),a=Sf(c);As(a,0,BigInt(i?i.length:0),!0),As(a,8,BigInt(n.length),!0),s.update(c);let f=s.digest();return o.fill(0),f}var Ff=r=>(t,e,n)=>(at(t,32),at(e),{encrypt:(o,s)=>{let c=o.length,a=c+16;s?at(s,a):s=new Uint8Array(a),r(t,e,o,s,1);let f=Gf(r,t,e,s.subarray(0,-16),n);return s.set(f,c),s},decrypt:(o,s)=>{let c=o.length,a=c-16;if(c<16)throw new Error("encrypted data must be at least 16 bytes");s?at(s,a):s=new Uint8Array(a);let f=o.subarray(0,-16),u=o.subarray(-16),h=Gf(r,t,e,f,n);if(!Pf(u,h))throw new Error("invalid tag");return r(t,e,f,s,1),s}}),gg=vs({blockSize:64,nonceLength:12,tagLength:16},Ff(np)),Ps=vs({blockSize:64,nonceLength:24,tagLength:16},Ff(ki));var $f=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:R.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await H({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return ki(i,n,t)}static async encrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return ki(i,n,t)}static async generateKey(){let t=ot(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await H({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!Yt(t))throw new Error("XChaCha20: The provided key is not a valid oct private key.");return R.base64Url(t.k).toUint8Array()}};var Ug=16,Wf=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:R.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await H({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.decryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async decryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return Ps(e,n,i).decrypt(t)}static async encrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.encryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async encryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return Ps(e,n,i).encrypt(t)}static async generateKey(){let t=ot(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await H({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!Yt(t))throw new Error("XChaCha20Poly1305: The provided key is not a valid oct private key.");return R.base64Url(t.k).toUint8Array()}};export{Ti as AES_GCM_TAG_LENGTHS,Lr as AesCtr,Bf as AesCtrAlgorithm,Or as AesGcm,If as AesGcmAlgorithm,Cf as AesKw,Lf as ConcatKdf,Ut as CryptoAlgorithm,Jt as CryptoError,Ms as CryptoErrorCode,vf as CryptoUtils,yn as EcdsaAlgorithm,Ne as Ed25519,xi as EdDsaAlgorithm,Of as Hkdf,ls as KEY_URI_PREFIX_JWK,Ef as LocalKeyManager,Ce as P256,Ug as POLY1305_TAG_LENGTH,Rf as Pbkdf2,_e as Secp256k1,Ce as Secp256r1,Ir as Sha256,bi as Sha2Algorithm,Nf as X25519,$f as XChaCha20,Wf as XChaCha20Poly1305,af as canonicalize,H as computeJwkThumbprint,Zt as isEcPrivateJwk,_r as isEcPublicJwk,Yt as isOctPrivateJwk,Xt as isOkpPrivateJwk,Cr as isOkpPublicJwk,ff as isPrivateJwk,Y0 as isPublicJwk};
1
+ var Vf=Object.create;var uo=Object.defineProperty;var qf=Object.getOwnPropertyDescriptor;var Ff=Object.getOwnPropertyNames;var $f=Object.getPrototypeOf,Wf=Object.prototype.hasOwnProperty;var Q=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Bc=(r,t)=>{for(var e in t)uo(r,e,{get:t[e],enumerable:!0})},zf=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ff(t))!Wf.call(r,i)&&i!==e&&uo(r,i,{get:()=>t[i],enumerable:!(n=qf(t,i))||n.enumerable});return r};var Pc=(r,t,e)=>(e=r!=null?Vf($f(r)):{},zf(t||!r||!r.__esModule?uo(e,"default",{value:r,enumerable:!0}):e,r));var Tc=Q((nd,Kc)=>{var Zf=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,zn=()=>Zf.now(),Yf=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),fo=r=>r===1/0||Yf(r),lo=class r{constructor({max:t=1/0,ttl:e,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,e!==void 0&&!fo(e))throw new TypeError("ttl must be positive integer or Infinity if set");if(!fo(t))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=e,this.max=t,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(t,e){if(this.timerExpiration<t)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-zn());break}},e);n.unref&&n.unref(),this.timerExpiration=t,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 t=this.dispose!==r.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[e,n]of t)this.dispose(n,e,"delete")}setTTL(t,e=this.ttl){let n=this.expirationMap.get(t);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==t)}if(e!==1/0){let i=Math.floor(zn()+e);this.expirationMap.set(t,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,e)),this.expirations[i].push(t)}else this.expirationMap.set(t,1/0)}set(t,e,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!fo(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(t)){i||this.setTTL(t,n);let s=this.data.get(t);s!==e&&(this.data.set(t,e),o||this.dispose(s,t,"set"))}else this.setTTL(t,n),this.data.set(t,e);for(;this.size>this.max;)this.purgeToCapacity();return this}has(t){return this.data.has(t)}getRemainingTTL(t){let e=this.expirationMap.get(t);return e===1/0?e:e!==void 0?Math.max(0,Math.ceil(e-zn())):0}get(t,{updateAgeOnGet:e=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(t);if(i&&this.getRemainingTTL(t)===0){this.delete(t);return}return e&&this.setTTL(t,n),o}dispose(t,e){}delete(t){let e=this.expirationMap.get(t);if(e!==void 0){let n=this.data.get(t);this.data.delete(t),this.expirationMap.delete(t);let i=this.expirations[e];return i&&(i.length<=1?delete this.expirations[e]:this.expirations[e]=i.filter(o=>o!==t)),this.dispose(n,t,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let t in this.expirations){let e=this.expirations[t];if(this.size-e.length>=this.max){delete this.expirations[t];let n=[];for(let i of e)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 e.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 t=Math.ceil(zn());for(let e in this.expirations){if(e==="Infinity"||e>t)return;let n=[...this.expirations[e]||[]],i=[];delete this.expirations[e];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 t in this.expirations)for(let e of this.expirations[t])yield[e,this.data.get(e)]}*keys(){for(let t in this.expirations)for(let e of this.expirations[t])yield e}*values(){for(let t in this.expirations)for(let e of this.expirations[t])yield this.data.get(e)}[Symbol.iterator](){return this.entries()}};Kc.exports=lo});var Vc=Q(Gc=>{"use strict";Gc.supports=function(...t){let e=t.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(e,{snapshots:e.snapshots||!1,permanence:e.permanence||!1,seek:e.seek||!1,clear:e.clear||!1,getMany:e.getMany||!1,keyIterator:e.keyIterator||!1,valueIterator:e.valueIterator||!1,iteratorNextv:e.iteratorNextv||!1,iteratorAll:e.iteratorAll||!1,status:e.status||!1,createIfMissing:e.createIfMissing||!1,errorIfExists:e.errorIfExists||!1,deferredOpen:e.deferredOpen||!1,promises:e.promises||!1,streams:e.streams||!1,encodings:Object.assign({},e.encodings),events:Object.assign({},e.events),additionalMethods:Object.assign({},e.additionalMethods)})}});var Vt=Q((e0,qc)=>{"use strict";qc.exports=class extends Error{constructor(t,e){super(t||""),typeof e=="object"&&e!==null&&(e.code&&(this.code=String(e.code)),e.expected&&(this.expected=!0),e.transient&&(this.transient=!0),e.cause&&(this.cause=e.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var Wc=Q(Yn=>{"use strict";Yn.byteLength=Il;Yn.toByteArray=_l;Yn.fromByteArray=Rl;var te=[],_t=[],Ul=typeof Uint8Array<"u"?Uint8Array:Array,Ko="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(or=0,Fc=Ko.length;or<Fc;++or)te[or]=Ko[or],_t[Ko.charCodeAt(or)]=or;var or,Fc;_t[45]=62;_t[95]=63;function $c(r){var t=r.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");e===-1&&(e=t);var n=e===t?0:4-e%4;return[e,n]}function Il(r){var t=$c(r),e=t[0],n=t[1];return(e+n)*3/4-n}function Cl(r,t,e){return(t+e)*3/4-e}function _l(r){var t,e=$c(r),n=e[0],i=e[1],o=new Ul(Cl(r,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)t=_t[r.charCodeAt(a)]<<18|_t[r.charCodeAt(a+1)]<<12|_t[r.charCodeAt(a+2)]<<6|_t[r.charCodeAt(a+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=_t[r.charCodeAt(a)]<<2|_t[r.charCodeAt(a+1)]>>4,o[s++]=t&255),i===1&&(t=_t[r.charCodeAt(a)]<<10|_t[r.charCodeAt(a+1)]<<4|_t[r.charCodeAt(a+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function Ll(r){return te[r>>18&63]+te[r>>12&63]+te[r>>6&63]+te[r&63]}function Ol(r,t,e){for(var n,i=[],o=t;o<e;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(Ll(n));return i.join("")}function Rl(r){for(var t,e=r.length,n=e%3,i=[],o=16383,s=0,c=e-n;s<c;s+=o)i.push(Ol(r,s,s+o>c?c:s+o));return n===1?(t=r[e-1],i.push(te[t>>2]+te[t<<4&63]+"==")):n===2&&(t=(r[e-2]<<8)+r[e-1],i.push(te[t>>10]+te[t>>4&63]+te[t<<2&63]+"=")),i.join("")}});var zc=Q(To=>{To.read=function(r,t,e,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,u=a>>1,f=-7,l=e?i-1:0,y=e?-1:1,m=r[t+l];for(l+=y,o=m&(1<<-f)-1,m>>=-f,f+=c;f>0;o=o*256+r[t+l],l+=y,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=s*256+r[t+l],l+=y,f-=8);if(o===0)o=1-u;else{if(o===a)return s?NaN:(m?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(m?-1:1)*s*Math.pow(2,o-n)};To.write=function(r,t,e,n,i,o){var s,c,a,u=o*8-i-1,f=(1<<u)-1,l=f>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,m=n?0:o-1,p=n?1:-1,h=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+l>=1?t+=y/a:t+=y*Math.pow(2,1-l),t*a>=2&&(s++,a/=2),s+l>=f?(c=0,s=f):s+l>=1?(c=(t*a-1)*Math.pow(2,i),s=s+l):(c=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;r[e+m]=c&255,m+=p,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;r[e+m]=s&255,m+=p,s/=256,u-=8);r[e+m-p]|=h*128}});var ti=Q(Lr=>{"use strict";var So=Wc(),Cr=zc(),Zc=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Lr.Buffer=E;Lr.SlowBuffer=Jl;Lr.INSPECT_MAX_BYTES=50;var Xn=2147483647;Lr.kMaxLength=Xn;E.TYPED_ARRAY_SUPPORT=Nl();!E.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 Nl(){try{let r=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(r,t),r.foo()===42}catch{return!1}}Object.defineProperty(E.prototype,"parent",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.buffer}});Object.defineProperty(E.prototype,"offset",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.byteOffset}});function pe(r){if(r>Xn)throw new RangeError('The value "'+r+'" is invalid for option "size"');let t=new Uint8Array(r);return Object.setPrototypeOf(t,E.prototype),t}function E(r,t,e){if(typeof r=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Co(r)}return ta(r,t,e)}E.poolSize=8192;function ta(r,t,e){if(typeof r=="string")return Ml(r,t);if(ArrayBuffer.isView(r))return jl(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(ee(r,ArrayBuffer)||r&&ee(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(ee(r,SharedArrayBuffer)||r&&ee(r.buffer,SharedArrayBuffer)))return Uo(r,t,e);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 E.from(n,t,e);let i=Hl(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return E.from(r[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}E.from=function(r,t,e){return ta(r,t,e)};Object.setPrototypeOf(E.prototype,Uint8Array.prototype);Object.setPrototypeOf(E,Uint8Array);function ea(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 Dl(r,t,e){return ea(r),r<=0?pe(r):t!==void 0?typeof e=="string"?pe(r).fill(t,e):pe(r).fill(t):pe(r)}E.alloc=function(r,t,e){return Dl(r,t,e)};function Co(r){return ea(r),pe(r<0?0:_o(r)|0)}E.allocUnsafe=function(r){return Co(r)};E.allocUnsafeSlow=function(r){return Co(r)};function Ml(r,t){if((typeof t!="string"||t==="")&&(t="utf8"),!E.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let e=ra(r,t)|0,n=pe(e),i=n.write(r,t);return i!==e&&(n=n.slice(0,i)),n}function ko(r){let t=r.length<0?0:_o(r.length)|0,e=pe(t);for(let n=0;n<t;n+=1)e[n]=r[n]&255;return e}function jl(r){if(ee(r,Uint8Array)){let t=new Uint8Array(r);return Uo(t.buffer,t.byteOffset,t.byteLength)}return ko(r)}function Uo(r,t,e){if(t<0||r.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');let n;return t===void 0&&e===void 0?n=new Uint8Array(r):e===void 0?n=new Uint8Array(r,t):n=new Uint8Array(r,t,e),Object.setPrototypeOf(n,E.prototype),n}function Hl(r){if(E.isBuffer(r)){let t=_o(r.length)|0,e=pe(t);return e.length===0||r.copy(e,0,0,t),e}if(r.length!==void 0)return typeof r.length!="number"||Oo(r.length)?pe(0):ko(r);if(r.type==="Buffer"&&Array.isArray(r.data))return ko(r.data)}function _o(r){if(r>=Xn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xn.toString(16)+" bytes");return r|0}function Jl(r){return+r!=r&&(r=0),E.alloc(+r)}E.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==E.prototype};E.compare=function(t,e){if(ee(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),ee(e,Uint8Array)&&(e=E.from(e,e.offset,e.byteLength)),!E.isBuffer(t)||!E.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,i=e.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(t[o]!==e[o]){n=t[o],i=e[o];break}return n<i?-1:i<n?1:0};E.isEncoding=function(t){switch(String(t).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}};E.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return E.alloc(0);let n;if(e===void 0)for(e=0,n=0;n<t.length;++n)e+=t[n].length;let i=E.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){let s=t[n];if(ee(s,Uint8Array))o+s.length>i.length?(E.isBuffer(s)||(s=E.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(E.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function ra(r,t){if(E.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||ee(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 e=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&e===0)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Io(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return la(r).length;default:if(i)return n?-1:Io(r).length;t=(""+t).toLowerCase(),i=!0}}E.byteLength=ra;function Gl(r,t,e){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return Ql(this,t,e);case"utf8":case"utf-8":return ia(this,t,e);case"ascii":return Yl(this,t,e);case"latin1":case"binary":return Xl(this,t,e);case"base64":return zl(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return th(this,t,e);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}E.prototype._isBuffer=!0;function sr(r,t,e){let n=r[t];r[t]=r[e],r[e]=n}E.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)sr(this,e,e+1);return this};E.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)sr(this,e,e+3),sr(this,e+1,e+2);return this};E.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)sr(this,e,e+7),sr(this,e+1,e+6),sr(this,e+2,e+5),sr(this,e+3,e+4);return this};E.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?ia(this,0,t):Gl.apply(this,arguments)};E.prototype.toLocaleString=E.prototype.toString;E.prototype.equals=function(t){if(!E.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:E.compare(this,t)===0};E.prototype.inspect=function(){let t="",e=Lr.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"};Zc&&(E.prototype[Zc]=E.prototype.inspect);E.prototype.compare=function(t,e,n,i,o){if(ee(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),!E.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),e<0||n>t.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,i>>>=0,o>>>=0,this===t)return 0;let s=o-i,c=n-e,a=Math.min(s,c),u=this.slice(i,o),f=t.slice(e,n);for(let l=0;l<a;++l)if(u[l]!==f[l]){s=u[l],c=f[l];break}return s<c?-1:c<s?1:0};function na(r,t,e,n,i){if(r.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,Oo(e)&&(e=i?0:r.length-1),e<0&&(e=r.length+e),e>=r.length){if(i)return-1;e=r.length-1}else if(e<0)if(i)e=0;else return-1;if(typeof t=="string"&&(t=E.from(t,n)),E.isBuffer(t))return t.length===0?-1:Yc(r,t,e,n,i);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,t,e):Uint8Array.prototype.lastIndexOf.call(r,t,e):Yc(r,[t],e,n,i);throw new TypeError("val must be string, number or Buffer")}function Yc(r,t,e,n,i){let o=1,s=r.length,c=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||t.length<2)return-1;o=2,s/=2,c/=2,e/=2}function a(f,l){return o===1?f[l]:f.readUInt16BE(l*o)}let u;if(i){let f=-1;for(u=e;u<s;u++)if(a(r,u)===a(t,f===-1?0:u-f)){if(f===-1&&(f=u),u-f+1===c)return f*o}else f!==-1&&(u-=u-f),f=-1}else for(e+c>s&&(e=s-c),u=e;u>=0;u--){let f=!0;for(let l=0;l<c;l++)if(a(r,u+l)!==a(t,l)){f=!1;break}if(f)return u}return-1}E.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1};E.prototype.indexOf=function(t,e,n){return na(this,t,e,n,!0)};E.prototype.lastIndexOf=function(t,e,n){return na(this,t,e,n,!1)};function Vl(r,t,e,n){e=Number(e)||0;let i=r.length-e;n?(n=Number(n),n>i&&(n=i)):n=i;let o=t.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(t.substr(s*2,2),16);if(Oo(c))return s;r[e+s]=c}return s}function ql(r,t,e,n){return Qn(Io(t,r.length-e),r,e,n)}function Fl(r,t,e,n){return Qn(ih(t),r,e,n)}function $l(r,t,e,n){return Qn(la(t),r,e,n)}function Wl(r,t,e,n){return Qn(oh(t,r.length-e),r,e,n)}E.prototype.write=function(t,e,n,i){if(e===void 0)i="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")i=e,n=this.length,e=0;else if(isFinite(e))e=e>>>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-e;if((n===void 0||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Vl(this,t,e,n);case"utf8":case"utf-8":return ql(this,t,e,n);case"ascii":case"latin1":case"binary":return Fl(this,t,e,n);case"base64":return $l(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Wl(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};E.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function zl(r,t,e){return t===0&&e===r.length?So.fromByteArray(r):So.fromByteArray(r.slice(t,e))}function ia(r,t,e){e=Math.min(r.length,e);let n=[],i=t;for(;i<e;){let o=r[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=e){let a,u,f,l;switch(c){case 1:o<128&&(s=o);break;case 2:a=r[i+1],(a&192)===128&&(l=(o&31)<<6|a&63,l>127&&(s=l));break;case 3:a=r[i+1],u=r[i+2],(a&192)===128&&(u&192)===128&&(l=(o&15)<<12|(a&63)<<6|u&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:a=r[i+1],u=r[i+2],f=r[i+3],(a&192)===128&&(u&192)===128&&(f&192)===128&&(l=(o&15)<<18|(a&63)<<12|(u&63)<<6|f&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 Zl(n)}var Xc=4096;function Zl(r){let t=r.length;if(t<=Xc)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=Xc));return e}function Yl(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]&127);return n}function Xl(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]);return n}function Ql(r,t,e){let n=r.length;(!t||t<0)&&(t=0),(!e||e<0||e>n)&&(e=n);let i="";for(let o=t;o<e;++o)i+=sh[r[o]];return i}function th(r,t,e){let n=r.slice(t,e),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}E.prototype.slice=function(t,e){let n=this.length;t=~~t,e=e===void 0?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);let i=this.subarray(t,e);return Object.setPrototypeOf(i,E.prototype),i};function ht(r,t,e){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>e)throw new RangeError("Trying to access beyond buffer length")}E.prototype.readUintLE=E.prototype.readUIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return i};E.prototype.readUintBE=E.prototype.readUIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t+--e],o=1;for(;e>0&&(o*=256);)i+=this[t+--e]*o;return i};E.prototype.readUint8=E.prototype.readUInt8=function(t,e){return t=t>>>0,e||ht(t,1,this.length),this[t]};E.prototype.readUint16LE=E.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||ht(t,2,this.length),this[t]|this[t+1]<<8};E.prototype.readUint16BE=E.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||ht(t,2,this.length),this[t]<<8|this[t+1]};E.prototype.readUint32LE=E.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};E.prototype.readUint32BE=E.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};E.prototype.readBigUInt64LE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});E.prototype.readBigUInt64BE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=e*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});E.prototype.readIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i};E.prototype.readIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=e,o=1,s=this[t+--i];for(;i>0&&(o*=256);)s+=this[t+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*e)),s};E.prototype.readInt8=function(t,e){return t=t>>>0,e||ht(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};E.prototype.readInt16LE=function(t,e){t=t>>>0,e||ht(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};E.prototype.readInt16BE=function(t,e){t=t>>>0,e||ht(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};E.prototype.readInt32LE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};E.prototype.readInt32BE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};E.prototype.readBigInt64LE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});E.prototype.readBigInt64BE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=(e<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n)});E.prototype.readFloatLE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),Cr.read(this,t,!0,23,4)};E.prototype.readFloatBE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),Cr.read(this,t,!1,23,4)};E.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||ht(t,8,this.length),Cr.read(this,t,!0,52,8)};E.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||ht(t,8,this.length),Cr.read(this,t,!1,52,8)};function At(r,t,e,n,i,o){if(!E.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(e+n>r.length)throw new RangeError("Index out of range")}E.prototype.writeUintLE=E.prototype.writeUIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;At(this,t,e,n,c,0)}let o=1,s=0;for(this[e]=t&255;++s<n&&(o*=256);)this[e+s]=t/o&255;return e+n};E.prototype.writeUintBE=E.prototype.writeUIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;At(this,t,e,n,c,0)}let o=n-1,s=1;for(this[e+o]=t&255;--o>=0&&(s*=256);)this[e+o]=t/s&255;return e+n};E.prototype.writeUint8=E.prototype.writeUInt8=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,1,255,0),this[e]=t&255,e+1};E.prototype.writeUint16LE=E.prototype.writeUInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeUint16BE=E.prototype.writeUInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeUint32LE=E.prototype.writeUInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4};E.prototype.writeUint32BE=E.prototype.writeUInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function oa(r,t,e,n,i){fa(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,e}function sa(r,t,e,n,i){fa(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e+7]=o,o=o>>8,r[e+6]=o,o=o>>8,r[e+5]=o,o=o>>8,r[e+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e+3]=s,s=s>>8,r[e+2]=s,s=s>>8,r[e+1]=s,s=s>>8,r[e]=s,e+8}E.prototype.writeBigUInt64LE=Ue(function(t,e=0){return oa(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeBigUInt64BE=Ue(function(t,e=0){return sa(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);At(this,t,e,n,a-1,-a)}let o=0,s=1,c=0;for(this[e]=t&255;++o<n&&(s*=256);)t<0&&c===0&&this[e+o-1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};E.prototype.writeIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);At(this,t,e,n,a-1,-a)}let o=n-1,s=1,c=0;for(this[e+o]=t&255;--o>=0&&(s*=256);)t<0&&c===0&&this[e+o+1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};E.prototype.writeInt8=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1};E.prototype.writeInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4};E.prototype.writeInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};E.prototype.writeBigInt64LE=Ue(function(t,e=0){return oa(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});E.prototype.writeBigInt64BE=Ue(function(t,e=0){return sa(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ca(r,t,e,n,i,o){if(e+n>r.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function aa(r,t,e,n,i){return t=+t,e=e>>>0,i||ca(r,t,e,4,34028234663852886e22,-34028234663852886e22),Cr.write(r,t,e,n,23,4),e+4}E.prototype.writeFloatLE=function(t,e,n){return aa(this,t,e,!0,n)};E.prototype.writeFloatBE=function(t,e,n){return aa(this,t,e,!1,n)};function ua(r,t,e,n,i){return t=+t,e=e>>>0,i||ca(r,t,e,8,17976931348623157e292,-17976931348623157e292),Cr.write(r,t,e,n,52,8),e+8}E.prototype.writeDoubleLE=function(t,e,n){return ua(this,t,e,!0,n)};E.prototype.writeDoubleBE=function(t,e,n){return ua(this,t,e,!1,n)};E.prototype.copy=function(t,e,n,i){if(!E.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(e<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),t.length-e<i-n&&(i=t.length-e+n);let o=i-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),e),o};E.prototype.fill=function(t,e,n,i){if(typeof t=="string"){if(typeof e=="string"?(i=e,e=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"&&!E.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(t.length===1){let s=t.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e=e>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let o;if(typeof t=="number")for(o=e;o<n;++o)this[o]=t;else{let s=E.isBuffer(t)?t:E.from(t,i),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<n-e;++o)this[o+e]=s[o%c]}return this};var Ir={};function Lo(r,t,e){Ir[r]=class extends e{constructor(){super(),Object.defineProperty(this,"message",{value:t.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}`}}}Lo("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Lo("ERR_INVALID_ARG_TYPE",function(r,t){return`The "${r}" argument must be of type number. Received type ${typeof t}`},TypeError);Lo("ERR_OUT_OF_RANGE",function(r,t,e){let n=`The value of "${r}" is out of range.`,i=e;return Number.isInteger(e)&&Math.abs(e)>2**32?i=Qc(String(e)):typeof e=="bigint"&&(i=String(e),(e>BigInt(2)**BigInt(32)||e<-(BigInt(2)**BigInt(32)))&&(i=Qc(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);function Qc(r){let t="",e=r.length,n=r[0]==="-"?1:0;for(;e>=n+4;e-=3)t=`_${r.slice(e-3,e)}${t}`;return`${r.slice(0,e)}${t}`}function eh(r,t,e){_r(t,"offset"),(r[t]===void 0||r[t+e]===void 0)&&yn(t,r.length-(e+1))}function fa(r,t,e,n,i,o){if(r>e||r<t){let s=typeof t=="bigint"?"n":"",c;throw o>3?t===0||t===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=`>= ${t}${s} and <= ${e}${s}`,new Ir.ERR_OUT_OF_RANGE("value",c,r)}eh(n,i,o)}function _r(r,t){if(typeof r!="number")throw new Ir.ERR_INVALID_ARG_TYPE(t,"number",r)}function yn(r,t,e){throw Math.floor(r)!==r?(_r(r,e),new Ir.ERR_OUT_OF_RANGE(e||"offset","an integer",r)):t<0?new Ir.ERR_BUFFER_OUT_OF_BOUNDS:new Ir.ERR_OUT_OF_RANGE(e||"offset",`>= ${e?1:0} and <= ${t}`,r)}var rh=/[^+/0-9A-Za-z-_]/g;function nh(r){if(r=r.split("=")[0],r=r.trim().replace(rh,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Io(r,t){t=t||1/0;let e,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(e=r.charCodeAt(s),e>55295&&e<57344){if(!i){if(e>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(t-=3)>-1&&o.push(239,191,189),i=e;continue}e=(i-55296<<10|e-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((t-=1)<0)break;o.push(e)}else if(e<2048){if((t-=2)<0)break;o.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;o.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return o}function ih(r){let t=[];for(let e=0;e<r.length;++e)t.push(r.charCodeAt(e)&255);return t}function oh(r,t){let e,n,i,o=[];for(let s=0;s<r.length&&!((t-=2)<0);++s)e=r.charCodeAt(s),n=e>>8,i=e%256,o.push(i),o.push(n);return o}function la(r){return So.toByteArray(nh(r))}function Qn(r,t,e,n){let i;for(i=0;i<n&&!(i+e>=t.length||i>=r.length);++i)t[i+e]=r[i];return i}function ee(r,t){return r instanceof t||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===t.name}function Oo(r){return r!==r}var sh=function(){let r="0123456789abcdef",t=new Array(256);for(let e=0;e<16;++e){let n=e*16;for(let i=0;i<16;++i)t[n+i]=r[e]+r[i]}return t}();function Ue(r){return typeof BigInt>"u"?ch:r}function ch(){throw new Error("BigInt not supported")}});var No=Q((s0,ha)=>{"use strict";var Ro=null;ha.exports=function(){return Ro===null&&(Ro={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ro}});var jo=Q(ya=>{"use strict";var Do=Vt(),ah=new Set(["buffer","view","utf8"]),Mo=class{constructor(t){if(this.encode=t.encode||this.encode,this.decode=t.decode||this.decode,this.name=t.name||this.name,this.format=t.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"||!ah.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");t.createViewTranscoder&&(this.createViewTranscoder=t.createViewTranscoder),t.createBufferTranscoder&&(this.createBufferTranscoder=t.createBufferTranscoder),t.createUTF8Transcoder&&(this.createUTF8Transcoder=t.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ya.Encoding=Mo});var Vo=Q(ei=>{"use strict";var{Buffer:Jo}=ti()||{},{Encoding:Go}=jo(),uh=No(),pn=class extends Go{constructor(t){super({...t,format:"buffer"})}createViewTranscoder(){return new dn({encode:this.encode,decode:t=>this.decode(Jo.from(t.buffer,t.byteOffset,t.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},dn=class extends Go{constructor(t){super({...t,format:"view"})}createBufferTranscoder(){return new pn({encode:t=>{let e=this.encode(t);return Jo.from(e.buffer,e.byteOffset,e.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Ho=class extends Go{constructor(t){super({...t,format:"utf8"})}createBufferTranscoder(){return new pn({encode:t=>Jo.from(this.encode(t),"utf8"),decode:t=>this.decode(t.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:t,textDecoder:e}=uh();return new dn({encode:n=>t.encode(this.encode(n)),decode:n=>this.decode(e.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};ei.BufferFormat=pn;ei.ViewFormat=dn;ei.UTF8Format=Ho});var wa=Q(cr=>{"use strict";var{Buffer:wt}=ti()||{Buffer:{isBuffer:()=>!1}},{textEncoder:da,textDecoder:pa}=No()(),{BufferFormat:mn,ViewFormat:qo,UTF8Format:ma}=Vo(),ri=r=>r;cr.utf8=new ma({encode:function(r){return wt.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?pa.decode(r):String(r)},decode:ri,name:"utf8",createViewTranscoder(){return new qo({encode:function(r){return ArrayBuffer.isView(r)?r:da.encode(r)},decode:function(r){return pa.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});cr.json=new ma({encode:JSON.stringify,decode:JSON.parse,name:"json"});cr.buffer=new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:ri,name:"buffer",createViewTranscoder(){return new qo({encode:function(r){return ArrayBuffer.isView(r)?r:wt.from(String(r),"utf8")},decode:function(r){return wt.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});cr.view=new qo({encode:function(r){return ArrayBuffer.isView(r)?r:da.encode(r)},decode:ri,name:"view",createBufferTranscoder(){return new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:ri,name:`${this.name}+buffer`})}});cr.hex=new mn({encode:function(r){return wt.isBuffer(r)?r:wt.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});cr.base64=new mn({encode:function(r){return wt.isBuffer(r)?r:wt.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var ba=Q(xa=>{"use strict";var ga=Vt(),ii=wa(),{Encoding:fh}=jo(),{BufferFormat:lh,ViewFormat:hh,UTF8Format:yh}=Vo(),wn=Symbol("formats"),ni=Symbol("encodings"),ph=new Set(["buffer","view","utf8"]),Fo=class{constructor(t){if(Array.isArray(t)){if(!t.every(e=>ph.has(e)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[ni]=new Map,this[wn]=new Set(t);for(let e in ii)try{this.encoding(e)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[ni].values()))}encoding(t){let e=this[ni].get(t);if(e===void 0){if(typeof t=="string"&&t!==""){if(e=gh[t],!e)throw new ga(`Encoding '${t}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof t!="object"||t===null)throw new TypeError("First argument 'encoding' must be a string or object");e=dh(t)}let{name:n,format:i}=e;if(!this[wn].has(i))if(this[wn].has("view"))e=e.createViewTranscoder();else if(this[wn].has("buffer"))e=e.createBufferTranscoder();else if(this[wn].has("utf8"))e=e.createUTF8Transcoder();else throw new ga(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[t,n,e.name,e.commonName])this[ni].set(o,e)}return e}};xa.Transcoder=Fo;function dh(r){if(r instanceof fh)return r;let t="type"in r&&typeof r.type=="string"?r.type:void 0,e=r.name||t||`anonymous-${xh++}`;switch(mh(r)){case"view":return new hh({...r,name:e});case"utf8":return new yh({...r,name:e});case"buffer":return new lh({...r,name:e});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function mh(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 wh={binary:ii.buffer,"utf-8":ii.utf8},gh={...ii,...wh},xh=0});var va=Q((l0,$o)=>{"use strict";var bh=Object.prototype.hasOwnProperty,bt="~";function gn(){}Object.create&&(gn.prototype=Object.create(null),new gn().__proto__||(bt=!1));function Eh(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ea(r,t,e,n,i){if(typeof e!="function")throw new TypeError("The listener must be a function");var o=new Eh(e,n||r,i),s=bt?bt+t:t;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 oi(r,t){--r._eventsCount===0?r._events=new gn:delete r._events[t]}function gt(){this._events=new gn,this._eventsCount=0}gt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)bh.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};gt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];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};gt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};gt.prototype.emit=function(t,e,n,i,o,s){var c=bt?bt+t:t;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,i),!0;case 5:return a.fn.call(a.context,e,n,i,o),!0;case 6:return a.fn.call(a.context,e,n,i,o,s),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];a.fn.apply(a.context,f)}else{var y=a.length,m;for(l=0;l<y;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),u){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,e);break;case 3:a[l].fn.call(a[l].context,e,n);break;case 4:a[l].fn.call(a[l].context,e,n,i);break;default:if(!f)for(m=1,f=new Array(u-1);m<u;m++)f[m-1]=arguments[m];a[l].fn.apply(a[l].context,f)}}return!0};gt.prototype.on=function(t,e,n){return Ea(this,t,e,n,!1)};gt.prototype.once=function(t,e,n){return Ea(this,t,e,n,!0)};gt.prototype.removeListener=function(t,e,n,i){var o=bt?bt+t:t;if(!this._events[o])return this;if(!e)return oi(this,o),this;var s=this._events[o];if(s.fn)s.fn===e&&(!i||s.once)&&(!n||s.context===n)&&oi(this,o);else{for(var c=0,a=[],u=s.length;c<u;c++)(s[c].fn!==e||i&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[o]=a.length===1?a[0]:a:oi(this,o)}return this};gt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&oi(this,e)):(this._events=new gn,this._eventsCount=0),this};gt.prototype.off=gt.prototype.removeListener;gt.prototype.addListener=gt.prototype.on;gt.prefixed=bt;gt.EventEmitter=gt;typeof $o<"u"&&($o.exports=gt)});var Ba=Q((h0,Aa)=>{Aa.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var xn=Q(Wo=>{"use strict";var Pa=Ba();Wo.fromCallback=function(r,t){if(r===void 0){var e=new Promise(function(n,i){r=function(o,s){o?i(o):n(s)}});r[t!==void 0?t:"promise"]=e}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r};Wo.fromPromise=function(r,t){if(t===void 0)return r;r.then(function(e){Pa(()=>t(null,e))}).catch(function(e){Pa(()=>t(e))})}});var si=Q(zo=>{"use strict";zo.getCallback=function(r,t){return typeof r=="function"?r:t};zo.getOptions=function(r,t){return typeof r=="object"&&r!==null?r:t!==void 0?t:{}}});var Re=Q(fi=>{"use strict";var{fromCallback:Zo}=xn(),Kt=Vt(),{getOptions:Yo,getCallback:Ka}=si(),ar=Symbol("promise"),Or=Symbol("callback"),re=Symbol("working"),ur=Symbol("handleOne"),de=Symbol("handleMany"),Xo=Symbol("autoClose"),Le=Symbol("finishWork"),ne=Symbol("returnMany"),Ie=Symbol("closing"),bn=Symbol("handleClose"),ci=Symbol("closed"),En=Symbol("closeCallbacks"),_e=Symbol("keyEncoding"),fr=Symbol("valueEncoding"),Qo=Symbol("abortOnClose"),ai=Symbol("legacy"),ts=Symbol("keys"),es=Symbol("values"),Ce=Symbol("limit"),Lt=Symbol("count"),ui=Object.freeze({}),vh=()=>{},Ta=!1,vn=class{constructor(t,e,n){if(typeof t!="object"||t===null){let i=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof e!="object"||e===null)throw new TypeError("The second argument must be an options object");this[ci]=!1,this[En]=[],this[re]=!1,this[Ie]=!1,this[Xo]=!1,this[Or]=null,this[ur]=this[ur].bind(this),this[de]=this[de].bind(this),this[bn]=this[bn].bind(this),this[_e]=e[_e],this[fr]=e[fr],this[ai]=n,this[Ce]=Number.isInteger(e.limit)&&e.limit>=0?e.limit:1/0,this[Lt]=0,this[Qo]=!!e.abortOnClose,this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get count(){return this[Lt]}get limit(){return this[Ce]}next(t){let e;if(t===void 0)e=new Promise((n,i)=>{t=(o,s,c)=>{o?i(o):this[ai]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof t!="function")throw new TypeError("Callback must be a function");return this[Ie]?this.nextTick(t,new Kt("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(t,new Kt("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[re]=!0,this[Or]=t,this[Lt]>=this[Ce]?this.nextTick(this[ur],null):this._next(this[ur])),e}_next(t){this.nextTick(t)}nextv(t,e,n){return n=Ka(e,n),n=Zo(n,ar),e=Yo(e,ui),Number.isInteger(t)?(this[Ie]?this.nextTick(n,new Kt("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(n,new Kt("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(t<1&&(t=1),this[Ce]<1/0&&(t=Math.min(t,this[Ce]-this[Lt])),this[re]=!0,this[Or]=n,t<=0?this.nextTick(this[de],null,[]):this._nextv(t,e,this[de])),n[ar]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[ar])}_nextv(t,e,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[ai]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[ai]?[c,a]:c),i.length===t?n(null,i):this._next(o)};this._next(o)}all(t,e){return e=Ka(t,e),e=Zo(e,ar),t=Yo(t,ui),this[Ie]?this.nextTick(e,new Kt("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(e,new Kt("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[re]=!0,this[Or]=e,this[Xo]=!0,this[Lt]>=this[Ce]?this.nextTick(this[de],null,[]):this._all(t,this[de])),e[ar]}_all(t,e){let n=this[Lt],i=[],o=()=>{let c=this[Ce]<1/0?Math.min(1e3,this[Ce]-n):1e3;c<=0?this.nextTick(e,null,i):this._nextv(c,ui,s)},s=(c,a)=>{c?e(c):a.length===0?e(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[Le](){let t=this[Or];return this[Qo]&&t===null?vh:(this[re]=!1,this[Or]=null,this[Ie]&&this._close(this[bn]),t)}[ne](t,e,n){this[Xo]?this.close(t.bind(null,e,n)):t(e,n)}seek(t,e){if(e=Yo(e,ui),!this[Ie]){if(this[re])throw new Kt("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(e.keyEncoding||this[_e]),i=n.format;e.keyEncoding!==i&&(e={...e,keyEncoding:i});let o=this.db.prefixKey(n.encode(t),i);this._seek(o,e)}}}_seek(t,e){throw new Kt("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(t){return t=Zo(t,ar),this[ci]?this.nextTick(t):this[Ie]?this[En].push(t):(this[Ie]=!0,this[En].push(t),this[re]?this[Qo]&&this[Le]()(new Kt("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[bn])),t[ar]}_close(t){this.nextTick(t)}[bn](){this[ci]=!0,this.db.detachResource(this);let t=this[En];this[En]=[];for(let e of t)e()}async*[Symbol.asyncIterator](){try{let t;for(;(t=await this.next())!==void 0;)yield t}finally{this[ci]||await this.close()}}},Rr=class extends vn{constructor(t,e){super(t,e,!0),this[ts]=e.keys!==!1,this[es]=e.values!==!1}[ur](t,e,n){let i=this[Le]();if(t)return i(t);try{e=this[ts]&&e!==void 0?this[_e].decode(e):void 0,n=this[es]&&n!==void 0?this[fr].decode(n):void 0}catch(o){return i(new Oe("entry",o))}e===void 0&&n===void 0||this[Lt]++,i(null,e,n)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i of e){let o=i[0],s=i[1];i[0]=this[ts]&&o!==void 0?this[_e].decode(o):void 0,i[1]=this[es]&&s!==void 0?this[fr].decode(s):void 0}}catch(i){return this[ne](n,new Oe("entries",i))}this[Lt]+=e.length,this[ne](n,null,e)}end(t){return!Ta&&typeof console<"u"&&(Ta=!0,console.warn(new Kt("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(t)}},rs=class extends vn{constructor(t,e){super(t,e,!1)}[ur](t,e){let n=this[Le]();if(t)return n(t);try{e=e!==void 0?this[_e].decode(e):void 0}catch(i){return n(new Oe("key",i))}e!==void 0&&this[Lt]++,n(null,e)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[_e].decode(o):void 0}}catch(i){return this[ne](n,new Oe("keys",i))}this[Lt]+=e.length,this[ne](n,null,e)}},ns=class extends vn{constructor(t,e){super(t,e,!1)}[ur](t,e){let n=this[Le]();if(t)return n(t);try{e=e!==void 0?this[fr].decode(e):void 0}catch(i){return n(new Oe("value",i))}e!==void 0&&this[Lt]++,n(null,e)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[fr].decode(o):void 0}}catch(i){return this[ne](n,new Oe("values",i))}this[Lt]+=e.length,this[ne](n,null,e)}},Oe=class extends Kt{constructor(t,e){super(`Iterator could not decode ${t}`,{code:"LEVEL_DECODE_ERROR",cause:e})}};for(let r of["_ended property","_nexting property","_end method"])Object.defineProperty(Rr.prototype,r.split(" ")[0],{get(){throw new Kt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Kt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});Rr.keyEncoding=_e;Rr.valueEncoding=fr;fi.AbstractIterator=Rr;fi.AbstractKeyIterator=rs;fi.AbstractValueIterator=ns});var Sa=Q(is=>{"use strict";var{AbstractKeyIterator:Ah,AbstractValueIterator:Bh}=Re(),lr=Symbol("iterator"),An=Symbol("callback"),Nr=Symbol("handleOne"),hr=Symbol("handleMany"),Bn=class extends Ah{constructor(t,e){super(t,e),this[lr]=t.iterator({...e,keys:!0,values:!1}),this[Nr]=this[Nr].bind(this),this[hr]=this[hr].bind(this)}},li=class extends Bh{constructor(t,e){super(t,e),this[lr]=t.iterator({...e,keys:!1,values:!0}),this[Nr]=this[Nr].bind(this),this[hr]=this[hr].bind(this)}};for(let r of[Bn,li]){let t=r===Bn,e=t?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[An]=n,this[lr].next(this[Nr])},r.prototype[Nr]=function(n,i,o){let s=this[An];n?s(n):s(null,t?i:o)},r.prototype._nextv=function(n,i,o){this[An]=o,this[lr].nextv(n,i,this[hr])},r.prototype._all=function(n,i){this[An]=i,this[lr].all(n,this[hr])},r.prototype[hr]=function(n,i){let o=this[An];n?o(n):o(null,i.map(e))},r.prototype._seek=function(n,i){this[lr].seek(n,i)},r.prototype._close=function(n){this[lr].close(n)}}is.DefaultKeyIterator=Bn;is.DefaultValueIterator=li});var ka=Q(wi=>{"use strict";var{AbstractIterator:Ph,AbstractKeyIterator:Kh,AbstractValueIterator:Th}=Re(),os=Vt(),Bt=Symbol("nut"),di=Symbol("undefer"),mi=Symbol("factory"),hi=class extends Ph{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.iterator(e),this.db.defer(()=>this[di]())}},yi=class extends Kh{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.keys(e),this.db.defer(()=>this[di]())}},pi=class extends Th{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.values(e),this.db.defer(()=>this[di]())}};for(let r of[hi,yi,pi])r.prototype[di]=function(){this.db.status==="open"&&(this[Bt]=this[mi]())},r.prototype._next=function(t){this[Bt]!==null?this[Bt].next(t):this.db.status==="opening"?this.db.defer(()=>this._next(t)):this.nextTick(t,new os("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(t,e,n){this[Bt]!==null?this[Bt].nextv(t,e,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(t,e,n)):this.nextTick(n,new os("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(t,e){this[Bt]!==null?this[Bt].all(e):this.db.status==="opening"?this.db.defer(()=>this._all(t,e)):this.nextTick(e,new os("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(t,e){this[Bt]!==null?this[Bt]._seek(t,e):this.db.status==="opening"&&this.db.defer(()=>this._seek(t,e))},r.prototype._close=function(t){this[Bt]!==null?this[Bt].close(t):this.db.status==="opening"?this.db.defer(()=>this._close(t)):this.nextTick(t)};wi.DeferredIterator=hi;wi.DeferredKeyIterator=yi;wi.DeferredValueIterator=pi});var cs=Q(Ia=>{"use strict";var{fromCallback:Ua}=xn(),gi=Vt(),{getCallback:Sh,getOptions:kh}=si(),xi=Symbol("promise"),Ot=Symbol("status"),Dr=Symbol("operations"),Pn=Symbol("finishClose"),Mr=Symbol("closeCallbacks"),ss=class{constructor(t){if(typeof t!="object"||t===null){let e=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${e}`)}this[Dr]=[],this[Mr]=[],this[Ot]="open",this[Pn]=this[Pn].bind(this),this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get length(){return this[Dr].length}put(t,e,n){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(t)||this.db._checkValue(e);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),a=o.valueEncoding(n&&n.valueEncoding),u=c.format;n={...n,keyEncoding:u,valueEncoding:a.format},o!==this.db&&(n.sublevel=null);let f=o.prefixKey(c.encode(t),u),l=a.encode(e);return this._put(f,l,n),this[Dr].push({...s,type:"put",key:t,value:e}),this}_put(t,e,n){}del(t,e){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(t);if(n)throw n;let i=e&&e.sublevel!=null?e.sublevel:this.db,o=e,s=i.keyEncoding(e&&e.keyEncoding),c=s.format;return e={...e,keyEncoding:c},i!==this.db&&(e.sublevel=null),this._del(i.prefixKey(s.encode(t),c),e),this[Dr].push({...o,type:"del",key:t}),this}_del(t,e){}clear(){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[Dr]=[],this}_clear(){}write(t,e){return e=Sh(t,e),e=Ua(e,xi),t=kh(t),this[Ot]!=="open"?this.nextTick(e,new gi("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(e):(this[Ot]="writing",this._write(t,n=>{this[Ot]="closing",this[Mr].push(()=>e(n)),n||this.db.emit("batch",this[Dr]),this._close(this[Pn])})),e[xi]}_write(t,e){}close(t){return t=Ua(t,xi),this[Ot]==="closing"?this[Mr].push(t):this[Ot]==="closed"?this.nextTick(t):(this[Mr].push(t),this[Ot]!=="writing"&&(this[Ot]="closing",this._close(this[Pn]))),t[xi]}_close(t){this.nextTick(t)}[Pn](){this[Ot]="closed",this.db.detachResource(this);let t=this[Mr];this[Mr]=[];for(let e of t)e()}};Ia.AbstractChainedBatch=ss});var _a=Q(Ca=>{"use strict";var{AbstractChainedBatch:Uh}=cs(),Ih=Vt(),jr=Symbol("encoded"),as=class extends Uh{constructor(t){super(t),this[jr]=[]}_put(t,e,n){this[jr].push({...n,type:"put",key:t,value:e})}_del(t,e){this[jr].push({...e,type:"del",key:t})}_clear(){this[jr]=[]}_write(t,e){this.db.status==="opening"?this.db.defer(()=>this._write(t,e)):this.db.status==="open"?this[jr].length===0?this.nextTick(e):this.db._batch(this[jr],t,e):this.nextTick(e,new Ih("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};Ca.DefaultChainedBatch=as});var Ra=Q((b0,Oa)=>{"use strict";var La=Vt(),Ch=Object.prototype.hasOwnProperty,_h=new Set(["lt","lte","gt","gte"]);Oa.exports=function(r,t){let e={};for(let n in r)if(Ch.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new La(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new La("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});_h.has(n)?e[n]=t.encode(r[n]):e[n]=r[n]}return e.reverse=!!e.reverse,e.limit=Number.isInteger(e.limit)&&e.limit>=0?e.limit:-1,e}});var us=Q((E0,Da)=>{var Na;Da.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(Na||(Na=Promise.resolve())).then(r).catch(t=>setTimeout(()=>{throw t},0))});var Ha=Q((v0,ja)=>{"use strict";var Ma=us();ja.exports=function(r,...t){t.length===0?Ma(r):Ma(()=>r(...t))}});var Ja=Q(bi=>{"use strict";var{AbstractIterator:Lh,AbstractKeyIterator:Oh,AbstractValueIterator:Rh}=Re(),Hr=Symbol("unfix"),qt=Symbol("iterator"),yr=Symbol("handleOne"),Ne=Symbol("handleMany"),me=Symbol("callback"),Kn=class extends Lh{constructor(t,e,n,i){super(t,e),this[qt]=n,this[Hr]=i,this[yr]=this[yr].bind(this),this[Ne]=this[Ne].bind(this),this[me]=null}[yr](t,e,n){let i=this[me];if(t)return i(t);e!==void 0&&(e=this[Hr](e)),i(t,e,n)}[Ne](t,e){let n=this[me];if(t)return n(t);for(let i of e){let o=i[0];o!==void 0&&(i[0]=this[Hr](o))}n(t,e)}},Tn=class extends Oh{constructor(t,e,n,i){super(t,e),this[qt]=n,this[Hr]=i,this[yr]=this[yr].bind(this),this[Ne]=this[Ne].bind(this),this[me]=null}[yr](t,e){let n=this[me];if(t)return n(t);e!==void 0&&(e=this[Hr](e)),n(t,e)}[Ne](t,e){let n=this[me];if(t)return n(t);for(let i=0;i<e.length;i++){let o=e[i];o!==void 0&&(e[i]=this[Hr](o))}n(t,e)}},Sn=class extends Rh{constructor(t,e,n){super(t,e),this[qt]=n}};for(let r of[Kn,Tn])r.prototype._next=function(t){this[me]=t,this[qt].next(this[yr])},r.prototype._nextv=function(t,e,n){this[me]=n,this[qt].nextv(t,e,this[Ne])},r.prototype._all=function(t,e){this[me]=e,this[qt].all(t,this[Ne])};for(let r of[Sn])r.prototype._next=function(t){this[qt].next(t)},r.prototype._nextv=function(t,e,n){this[qt].nextv(t,e,n)},r.prototype._all=function(t,e){this[qt].all(t,e)};for(let r of[Kn,Tn,Sn])r.prototype._seek=function(t,e){this[qt].seek(t,e)},r.prototype._close=function(t){this[qt].close(t)};bi.AbstractSublevelIterator=Kn;bi.AbstractSublevelKeyIterator=Tn;bi.AbstractSublevelValueIterator=Sn});var Fa=Q((B0,qa)=>{"use strict";var fs=Vt(),{Buffer:ys}=ti()||{},{AbstractSublevelIterator:Nh,AbstractSublevelKeyIterator:Dh,AbstractSublevelValueIterator:Mh}=Ja(),we=Symbol("prefix"),Ga=Symbol("upperBound"),kn=Symbol("prefixRange"),Tt=Symbol("parent"),ls=Symbol("unfix"),Va=new TextEncoder,jh={separator:"!"};qa.exports=function({AbstractLevel:r}){class t extends r{static defaults(n){if(typeof n=="string")throw new fs("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new fs("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?jh:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=t.defaults(o);i=Jh(i,s);let u=s.charCodeAt(0)+1,f=n[Tt]||n;if(!Va.encode(i).every(m=>m>u&&m<127))throw new fs(`Prefix must use bytes > ${u} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Hh(f,c),a);let l=(n.prefix||"")+s+i+s,y=l.slice(0,-1)+String.fromCharCode(u);this[Tt]=f,this[we]=new Ei(l),this[Ga]=new Ei(y),this[ls]=new ps,this.nextTick=f.nextTick}prefixKey(n,i){if(i==="utf8")return this[we].utf8+n;if(n.byteLength===0)return this[we][i];if(i==="view"){let o=this[we].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[we].buffer;return ys.concat([o,n],o.byteLength+n.byteLength)}}[kn](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[we][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[Ga][i]}get prefix(){return this[we].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[kn](n,n.keyEncoding),this[Tt].clear(n,i)}_iterator(n){this[kn](n,n.keyEncoding);let i=this[Tt].iterator(n),o=this[ls].get(this[we].utf8.length,n.keyEncoding);return new Nh(this,n,i,o)}_keys(n){this[kn](n,n.keyEncoding);let i=this[Tt].keys(n),o=this[ls].get(this[we].utf8.length,n.keyEncoding);return new Dh(this,n,i,o)}_values(n){this[kn](n,n.keyEncoding);let i=this[Tt].values(n);return new Mh(this,n,i)}}return{AbstractSublevel:t}};var Hh=function(r,t){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...t,encodings:{utf8:hs(r,"utf8"),buffer:hs(r,"buffer"),view:hs(r,"view")}}},hs=function(r,t){return r.supports.encodings[t]?r.keyEncoding(t).name===t:!1},Ei=class{constructor(t){this.utf8=t,this.view=Va.encode(t),this.buffer=ys?ys.from(this.view.buffer,0,this.view.byteLength):{}}},ps=class{constructor(){this.cache=new Map}get(t,e){let n=this.cache.get(e);return n===void 0&&(e==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,t):n=(function(i,o){return o.slice(i)}).bind(null,t),this.cache.set(e,n)),n}},Jh=function(r,t){let e=0,n=r.length;for(;e<n&&r[e]===t;)e++;for(;n>e&&r[n-1]===t;)n--;return r.slice(e,n)}});var xs=Q(gs=>{"use strict";var{supports:Gh}=Vc(),{Transcoder:Vh}=ba(),{EventEmitter:qh}=va(),{fromCallback:De}=xn(),Ft=Vt(),{AbstractIterator:pr}=Re(),{DefaultKeyIterator:Fh,DefaultValueIterator:$h}=Sa(),{DeferredIterator:Wh,DeferredKeyIterator:zh,DeferredValueIterator:Zh}=ka(),{DefaultChainedBatch:$a}=_a(),{getCallback:dr,getOptions:Me}=si(),vi=Ra(),W=Symbol("promise"),ge=Symbol("landed"),mr=Symbol("resources"),ds=Symbol("closeResources"),Un=Symbol("operations"),In=Symbol("undefer"),Ai=Symbol("deferOpen"),Wa=Symbol("options"),X=Symbol("status"),wr=Symbol("defaultOptions"),Jr=Symbol("transcoder"),Bi=Symbol("keyEncoding"),ms=Symbol("valueEncoding"),Yh=()=>{},Cn=class extends qh{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new TypeError("The first argument 'manifest' must be an object");e=Me(e);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=e;this[mr]=new Set,this[Un]=[],this[Ai]=!0,this[Wa]=s,this[X]="opening",this.supports=Gh(t,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:t.snapshots!==!1,permanence:t.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:t.encodings||{},events:Object.assign({},t.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[Jr]=new Vh(Xh(this)),this[Bi]=this[Jr].encoding(n||"utf8"),this[ms]=this[Jr].encoding(i||"utf8");for(let c of this[Jr].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[wr]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[Bi].commonName,valueEncoding:this[ms].commonName}),key:Object.freeze({keyEncoding:this[Bi].commonName})},this.nextTick(()=>{this[Ai]&&this.open({passive:!1},Yh)})}get status(){return this[X]}keyEncoding(t){return this[Jr].encoding(t??this[Bi])}valueEncoding(t){return this[Jr].encoding(t??this[ms])}open(t,e){e=dr(t,e),e=De(e,W),t={...this[Wa],...Me(t)},t.createIfMissing=t.createIfMissing!==!1,t.errorIfExists=!!t.errorIfExists;let n=i=>{this[X]==="closing"||this[X]==="opening"?this.once(ge,i?()=>n(i):n):this[X]!=="open"?e(new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):e()};return t.passive?this[X]==="opening"?this.once(ge,n):this.nextTick(n):this[X]==="closed"||this[Ai]?(this[Ai]=!1,this[X]="opening",this.emit("opening"),this._open(t,i=>{if(i){this[X]="closed",this[ds](()=>{this.emit(ge),n(i)}),this[In]();return}this[X]="open",this[In](),this.emit(ge),this[X]==="open"&&this.emit("open"),this[X]==="open"&&this.emit("ready"),n()})):this[X]==="open"?this.nextTick(n):this.once(ge,()=>this.open(t,e)),e[W]}_open(t,e){this.nextTick(e)}close(t){t=De(t,W);let e=n=>{this[X]==="opening"||this[X]==="closing"?this.once(ge,n?e(n):e):this[X]!=="closed"?t(new Ft("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):t()};if(this[X]==="open"){this[X]="closing",this.emit("closing");let n=i=>{this[X]="open",this[In](),this.emit(ge),e(i)};this[ds](()=>{this._close(i=>{if(i)return n(i);this[X]="closed",this[In](),this.emit(ge),this[X]==="closed"&&this.emit("closed"),e()})})}else this[X]==="closed"?this.nextTick(e):this.once(ge,()=>this.close(t));return t[W]}[ds](t){if(this[mr].size===0)return this.nextTick(t);let e=this[mr].size,n=!0,i=()=>{--e===0&&(n?this.nextTick(t):t())};for(let o of this[mr])o.close(i);n=!1,this[mr].clear()}_close(t){this.nextTick(t)}get(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].entry),this[X]==="opening")return this.defer(()=>this.get(t,e,n)),n[W];if(Gr(this,n))return n[W];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[W];let o=this.keyEncoding(e.keyEncoding),s=this.valueEncoding(e.valueEncoding),c=o.format,a=s.format;return(e.keyEncoding!==c||e.valueEncoding!==a)&&(e=Object.assign({},e,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(t),c),e,(u,f)=>{if(u)return(u.code==="LEVEL_NOT_FOUND"||u.notFound||/NotFound/i.test(u))&&(u.code||(u.code="LEVEL_NOT_FOUND"),u.notFound||(u.notFound=!0),u.status||(u.status=404)),n(u);try{f=s.decode(f)}catch(l){return n(new Ft("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[W]}_get(t,e,n){this.nextTick(n,new Error("NotFound"))}getMany(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].entry),this[X]==="opening")return this.defer(()=>this.getMany(t,e,n)),n[W];if(Gr(this,n))return n[W];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[W];if(t.length===0)return this.nextTick(n,null,[]),n[W];let i=this.keyEncoding(e.keyEncoding),o=this.valueEncoding(e.valueEncoding),s=i.format,c=o.format;(e.keyEncoding!==s||e.valueEncoding!==c)&&(e=Object.assign({},e,{keyEncoding:s,valueEncoding:c}));let a=new Array(t.length);for(let u=0;u<t.length;u++){let f=t[u],l=this._checkKey(f);if(l)return this.nextTick(n,l),n[W];a[u]=this.prefixKey(i.encode(f),s)}return this._getMany(a,e,(u,f)=>{if(u)return n(u);try{for(let l=0;l<f.length;l++)f[l]!==void 0&&(f[l]=o.decode(f[l]))}catch(l){return n(new Ft(`Could not decode one or more of ${f.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[W]}_getMany(t,e,n){this.nextTick(n,null,new Array(t.length).fill(void 0))}put(t,e,n,i){if(i=dr(n,i),i=De(i,W),n=Me(n,this[wr].entry),this[X]==="opening")return this.defer(()=>this.put(t,e,n,i)),i[W];if(Gr(this,i))return i[W];let o=this._checkKey(t)||this._checkValue(e);if(o)return this.nextTick(i,o),i[W];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),a=s.format,u=c.format;(n.keyEncoding!==a||n.valueEncoding!==u)&&(n=Object.assign({},n,{keyEncoding:a,valueEncoding:u}));let f=this.prefixKey(s.encode(t),a),l=c.encode(e);return this._put(f,l,n,y=>{if(y)return i(y);this.emit("put",t,e),i()}),i[W]}_put(t,e,n,i){this.nextTick(i)}del(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].key),this[X]==="opening")return this.defer(()=>this.del(t,e,n)),n[W];if(Gr(this,n))return n[W];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[W];let o=this.keyEncoding(e.keyEncoding),s=o.format;return e.keyEncoding!==s&&(e=Object.assign({},e,{keyEncoding:s})),this._del(this.prefixKey(o.encode(t),s),e,c=>{if(c)return n(c);this.emit("del",t),n()}),n[W]}_del(t,e,n){this.nextTick(n)}batch(t,e,n){if(!arguments.length){if(this[X]==="opening")return new $a(this);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof t=="function"?n=t:n=dr(e,n),n=De(n,W),e=Me(e,this[wr].empty),this[X]==="opening")return this.defer(()=>this.batch(t,e,n)),n[W];if(Gr(this,n))return n[W];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[W];if(t.length===0)return this.nextTick(n),n[W];let i=new Array(t.length),{keyEncoding:o,valueEncoding:s,...c}=e;for(let a=0;a<t.length;a++){if(typeof t[a]!="object"||t[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[W];let u=Object.assign({},t[a]);if(u.type!=="put"&&u.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[W];let f=this._checkKey(u.key);if(f)return this.nextTick(n,f),n[W];let l=u.sublevel!=null?u.sublevel:this,y=l.keyEncoding(u.keyEncoding||o),m=y.format;if(u.key=l.prefixKey(y.encode(u.key),m),u.keyEncoding=m,u.type==="put"){let p=this._checkValue(u.value);if(p)return this.nextTick(n,p),n[W];let h=l.valueEncoding(u.valueEncoding||s);u.value=h.encode(u.value),u.valueEncoding=h.format}l!==this&&(u.sublevel=null),i[a]=u}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",t),n()}),n[W]}_batch(t,e,n){this.nextTick(n)}sublevel(t,e){return this._sublevel(t,ws.defaults(e))}_sublevel(t,e){return new ws(this,t,e)}prefixKey(t,e){return t}clear(t,e){if(e=dr(t,e),e=De(e,W),t=Me(t,this[wr].empty),this[X]==="opening")return this.defer(()=>this.clear(t,e)),e[W];if(Gr(this,e))return e[W];let n=t,i=this.keyEncoding(t.keyEncoding);return t=vi(t,i),t.keyEncoding=i.format,t.limit===0?this.nextTick(e):this._clear(t,o=>{if(o)return e(o);this.emit("clear",n),e()}),e[W]}_clear(t,e){this.nextTick(e)}iterator(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t.keys=t.keys!==!1,t.values=t.values!==!1,t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new Wh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(t)}_iterator(t){return new pr(this,t)}keys(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new zh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(t)}_keys(t){return new Fh(this,t)}values(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new Zh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(t)}_values(t){return new $h(this,t)}defer(t){if(typeof t!="function")throw new TypeError("The first argument must be a function");this[Un].push(t)}[In](){if(this[Un].length===0)return;let t=this[Un];this[Un]=[];for(let e of t)e()}attachResource(t){if(typeof t!="object"||t===null||typeof t.close!="function")throw new TypeError("The first argument must be a resource object");this[mr].add(t)}detachResource(t){this[mr].delete(t)}_chainedBatch(){return new $a(this)}_checkKey(t){if(t==null)return new Ft("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(t){if(t==null)return new Ft("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Cn.prototype.nextTick=Ha();var{AbstractSublevel:ws}=Fa()({AbstractLevel:Cn});gs.AbstractLevel=Cn;gs.AbstractSublevel=ws;var Gr=function(r,t){return r[X]!=="open"?(r.nextTick(t,new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},Xh=function(r){return Object.keys(r.supports.encodings).filter(t=>!!r.supports.encodings[t])}});var bs=Q(gr=>{"use strict";gr.AbstractLevel=xs().AbstractLevel;gr.AbstractSublevel=xs().AbstractSublevel;gr.AbstractIterator=Re().AbstractIterator;gr.AbstractKeyIterator=Re().AbstractKeyIterator;gr.AbstractValueIterator=Re().AbstractValueIterator;gr.AbstractChainedBatch=cs().AbstractChainedBatch});var Za=Q((T0,za)=>{za.exports=ty;var Qh=us();function ty(r,t,e){if(typeof t!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,a=!0,u;Array.isArray(r)?(n=[],o=i=r.length):(s=Object.keys(r),n={},o=i=s.length);function f(y){function m(){e&&e(y,n),e=null}a?Qh(m):m()}function l(y,m,p){if(n[y]=p,m&&(c=!0),--o===0||m)f(m);else if(!c&&u<i){let h;s?(h=s[u],u+=1,r[h](function(d,g){l(h,d,g)})):(h=u,u+=1,r[h](function(d,g){l(h,d,g)}))}}u=t,o?s?s.some(function(y,m){return r[y](function(p,h){l(y,p,h)}),m===t-1}):r.some(function(y,m){return y(function(p,h){l(m,p,h)}),m===t-1}):f(null),a=!1}});var Es=Q((S0,Ya)=>{"use strict";Ya.exports=function(t){let e=t.gte!==void 0?t.gte:t.gt!==void 0?t.gt:void 0,n=t.lte!==void 0?t.lte:t.lt!==void 0?t.lt:void 0,i=t.gte===void 0,o=t.lte===void 0;return e!==void 0&&n!==void 0?IDBKeyRange.bound(e,n,i,o):e!==void 0?IDBKeyRange.lowerBound(e,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var vs=Q((k0,Xa)=>{"use strict";var ey=new TextEncoder;Xa.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):ey.encode(r)}});var nu=Q(ru=>{"use strict";var{AbstractIterator:ry}=bs(),Qa=Es(),Pi=vs(),ie=Symbol("cache"),xe=Symbol("finished"),St=Symbol("options"),be=Symbol("currentOptions"),xr=Symbol("position"),As=Symbol("location"),Vr=Symbol("first"),tu={},Bs=class extends ry{constructor(t,e,n){super(t,n),this[ie]=[],this[xe]=this.limit===0,this[St]=n,this[be]={...n},this[xr]=void 0,this[As]=e,this[Vr]=!0}_nextv(t,e,n){if(this[Vr]=!1,this[xe])return this.nextTick(n,null,[]);if(this[ie].length>0)return t=Math.min(t,this[ie].length),this.nextTick(n,null,this[ie].splice(0,t));this[xr]!==void 0&&(this[St].reverse?(this[be].lt=this[xr],this[be].lte=void 0):(this[be].gt=this[xr],this[be].gte=void 0));let i;try{i=Qa(this[be])}catch{return this[xe]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[As]],"readonly"),s=o.objectStore(this[As]),c=[];if(this[St].reverse){let a=!this[St].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=u=>{let f=u.target.result;if(f){let{key:l,value:y}=f;this[xr]=l,c.push([this[St].keys&&l!==void 0?Pi(l):void 0,this[St].values&&y!==void 0?Pi(y):void 0]),c.length<t?f.continue():eu(o)}else this[xe]=!0}}else{let a,u,f=()=>{if(a===void 0||u===void 0)return;let l=Math.max(a.length,u.length);l===0||t===1/0?this[xe]=!0:this[xr]=a[l-1],c.length=l;for(let y=0;y<l;y++){let m=a[y],p=u[y];c[y]=[this[St].keys&&m!==void 0?Pi(m):void 0,this[St].values&&p!==void 0?Pi(p):void 0]}eu(o)};this[St].keys||t<1/0?s.getAllKeys(i,t<1/0?t:void 0).onsuccess=l=>{a=l.target.result,f()}:(a=[],this.nextTick(f)),this[St].values?s.getAll(i,t<1/0?t:void 0).onsuccess=l=>{u=l.target.result,f()}:(u=[],this.nextTick(f))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(t){if(this[ie].length>0){let[e,n]=this[ie].shift();this.nextTick(t,null,e,n)}else if(this[xe])this.nextTick(t);else{let e=Math.min(100,this.limit-this.count);this[Vr]&&(this[Vr]=!1,e=1),this._nextv(e,tu,(n,i)=>{if(n)return t(n);this[ie]=i,this._next(t)})}}_all(t,e){this[Vr]=!1;let n=this[ie].splice(0,this[ie].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(e,null,n);this._nextv(i,tu,(o,s)=>{if(o)return e(o);n.length>0&&(s=n.concat(s)),e(null,s)})}_seek(t,e){this[Vr]=!0,this[ie]=[],this[xe]=!1,this[xr]=void 0,this[be]={...this[St]};let n;try{n=Qa(this[St])}catch{this[xe]=!0;return}n!==null&&!n.includes(t)?this[xe]=!0:this[St].reverse?this[be].lte=t:this[be].gte=t}};ru.Iterator=Bs;function eu(r){typeof r.commit=="function"&&r.commit()}});var ou=Q((I0,iu)=>{"use strict";iu.exports=function(t,e,n,i,o){if(i.limit===0)return t.nextTick(o);let s=t.db.transaction([e],"readwrite"),c=s.objectStore(e),a=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let u=c.openKeyCursor?"openKeyCursor":"openCursor",f=i.reverse?"prev":"next";c[u](n,f).onsuccess=function(l){let y=l.target.result;y&&(c.delete(y.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&y.continue()})}}});var lu=Q(fu=>{"use strict";var{AbstractLevel:ny}=bs(),su=Vt(),iy=Za(),{fromCallback:oy}=xn(),{Iterator:sy}=nu(),cu=vs(),cy=ou(),ay=Es(),uu="level-js-",_n=Symbol("idb"),Ps=Symbol("namePrefix"),Ee=Symbol("location"),Ks=Symbol("version"),br=Symbol("store"),Ln=Symbol("onComplete"),au=Symbol("promise"),Ki=class extends ny{constructor(t,e,n){if(typeof e=="function"||typeof n=="function")throw new su("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=e||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof t!="string")throw new Error("constructor requires a location string argument");this[Ee]=t,this[Ps]=i??uu,this[Ks]=parseInt(o||1,10),this[_n]=null}get location(){return this[Ee]}get namePrefix(){return this[Ps]}get version(){return this[Ks]}get db(){return this[_n]}get type(){return"browser-level"}_open(t,e){let n=indexedDB.open(this[Ps]+this[Ee],this[Ks]);n.onerror=function(){e(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[_n]=n.result,e()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Ee])||o.createObjectStore(this[Ee])}}[br](t){return this[_n].transaction([this[Ee]],t).objectStore(this[Ee])}[Ln](t,e){let n=t.transaction;n.onabort=function(){e(n.error||new Error("aborted by user"))},n.oncomplete=function(){e(null,t.result)}}_get(t,e,n){let i=this[br]("readonly"),o;try{o=i.get(t)}catch(s){return this.nextTick(n,s)}this[Ln](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new su("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,cu(c))})}_getMany(t,e,n){let i=this[br]("readonly"),o=t.map(s=>c=>{let a;try{a=i.get(s)}catch(u){return c(u)}a.onsuccess=()=>{let u=a.result;c(null,u===void 0?u:cu(u))},a.onerror=u=>{u.stopPropagation(),c(a.error)}});iy(o,16,n)}_del(t,e,n){let i=this[br]("readwrite"),o;try{o=i.delete(t)}catch(s){return this.nextTick(n,s)}this[Ln](o,n)}_put(t,e,n,i){let o=this[br]("readwrite"),s;try{s=o.put(e,t)}catch(c){return this.nextTick(i,c)}this[Ln](s,i)}_iterator(t){return new sy(this,this[Ee],t)}_batch(t,e,n){let i=this[br]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let u=t[s++],f=u.key,l;try{l=u.type==="del"?i.delete(f):i.put(u.value,f)}catch(y){c=y,o.abort();return}s<t.length?l.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(t,e){let n,i;try{n=ay(t)}catch{return this.nextTick(e)}if(t.limit>=0)return cy(this,this[Ee],n,t,e);try{let o=this[br]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(e,o)}this[Ln](i,e)}_close(t){this[_n].close(),this.nextTick(t)}};Ki.destroy=function(r,t,e){typeof t=="function"&&(e=t,t=uu),e=oy(e,au);let n=indexedDB.deleteDatabase(t+r);return n.onsuccess=function(){e()},n.onerror=function(i){e(i)},e[au]};fu.BrowserLevel=Ki});var yu=Q(hu=>{hu.Level=lu().BrowserLevel});var nt=class r extends Error{constructor(e,n){super(n);this.code=e;this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},sn=(o=>(o.AlgorithmNotSupported="algorithmNotSupported",o.EncodingError="encodingError",o.InvalidJwe="invalidJwe",o.InvalidJwk="invalidJwk",o.OperationNotSupported="operationNotSupported",o))(sn||{});var Xf=Pc(Tc(),1);var od=new Uint8Array(0);function Sc(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Sr(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 tl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),f=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 h=0,d=0,g=0,b=p.length;g!==b&&p[g]===0;)g++,h++;for(var x=(b-g)*f+1>>>0,A=new Uint8Array(x);g!==b;){for(var v=p[g],K=0,k=x-1;(v!==0||K<d)&&k!==-1;k--,K++)v+=256*A[k]>>>0,A[k]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");d=K,g++}for(var T=x-d;T!==x&&A[T]===0;)T++;for(var L=a.repeat(h);T<x;++T)L+=r.charAt(A[T]);return L}function y(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,g=0;p[h]===a;)d++,h++;for(var b=(p.length-h)*u+1>>>0,x=new Uint8Array(b);p[h];){var A=e[p.charCodeAt(h)];if(A===255)return;for(var v=0,K=b-1;(A!==0||v<g)&&K!==-1;K--,v++)A+=c*x[K]>>>0,x[K]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");g=v,h++}if(p[h]!==" "){for(var k=b-g;k!==b&&x[k]===0;)k++;for(var T=new Uint8Array(d+(b-k)),L=d;k!==b;)T[L++]=x[k++];return T}}}function m(p){var h=y(p);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:m}}var el=tl,rl=el,kc=rl;var ho=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Uc(this,t)}},po=class{decoders;constructor(t){this.decoders=t}or(t){return Uc(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Uc(r,t){return new po({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var mo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new ho(t,e,n),this.decoder=new yo(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ic({name:r,prefix:t,encode:e,decode:n}){return new mo(r,t,e,n)}function wo({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=kc(e,r);return Ic({prefix:t,name:r,encode:n,decode:o=>Sr(i(o))})}function nl(r,t,e,n){let i={};for(let f=0;f<t.length;++f)i[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),c=0,a=0,u=0;for(let f=0;f<o;++f){let l=i[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function il(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,o+=t[i&c>>s];if(s!==0&&(o+=t[i&c<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function xt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ic({prefix:t,name:r,encode(i){return il(i,n,e)},decode(i){return nl(i,n,e,r)}})}var cn=xt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ld=xt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hd=xt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yd=xt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pd=xt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dd=xt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),md=xt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wd=xt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),go=xt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vt=wo({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bd=wo({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ad=xt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bd=xt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xt=xt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pd=xt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Cc(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function _c(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function an(r){let e=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=e;return i}var un=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{u(n.next(f))}catch(l){s(l)}}function a(f){try{u(n.throw(f))}catch(l){s(l)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((n=n.apply(r,t||[])).next())})},Lc=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=r[o]&&function(s){return new Promise(function(c,a){s=r[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(u){o({value:u,done:c})},s)}},Zn=new TextEncoder,rr=new TextDecoder,N=class r{constructor(t,e){this.data=t,this.format=e}static arrayBuffer(t){return new r(t,"ArrayBuffer")}static asyncIterable(t){if(!_c(t))throw new TypeError("Input must be of type AsyncIterable.");return new r(t,"AsyncIterable")}static base32Z(t){return new r(t,"Base32Z")}static base58Btc(t){return new r(t,"Base58Btc")}static base64Url(t){return new r(t,"Base64Url")}static bufferSource(t){return new r(t,"BufferSource")}static hex(t){if(typeof t!="string")throw new TypeError("Hex input must be a string.");if(t.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new r(t,"Hex")}static multibase(t){return new r(t,"Multibase")}static object(t){return new r(t,"Object")}static string(t){return new r(t,"String")}static uint8Array(t){return new r(t,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return vt.baseDecode(this.data).buffer;case"Base64Url":return Xt.baseDecode(this.data).buffer;case"BufferSource":{if(an(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Cc(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 un(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 go.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return vt.baseEncode(t)}case"Multibase":return this.data.substring(1);case"Uint8Array":return vt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return Xt.baseEncode(t)}case"BufferSource":{let t=this.toUint8Array();return Xt.baseEncode(t)}case"Object":{let t=JSON.stringify(this.data),e=Zn.encode(t);return Xt.baseEncode(e)}case"String":{let t=Zn.encode(this.data);return Xt.baseEncode(t)}case"Uint8Array":return Xt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return un(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=Lc(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let f=i;a.push(f)}}catch(f){e={error:f}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let t=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Base64Url":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Uint8Array":{let e="";for(let n=0;n<this.data.length;n++)e+=t[this.data[n]];return e}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 t=Xt.baseDecode(this.data),e=rr.decode(t);return JSON.parse(e)}case"String":return JSON.parse(this.data);case"Uint8Array":{let t=rr.decode(this.data);return JSON.parse(t)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return un(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toStringAsync();return JSON.parse(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return rr.decode(this.data);case"Base64Url":{let t=Xt.baseDecode(this.data);return rr.decode(t)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return rr.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return un(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=Lc(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let u=i;typeof u=="string"?a+=u:a+=rr.decode(u,{stream:!0})}}catch(u){e={error:u}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return a+=rr.decode(void 0,{stream:!1}),a}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return go.baseDecode(this.data);case"Base58Btc":return vt.baseDecode(this.data);case"Base64Url":return Xt.baseDecode(this.data);case"BufferSource":{let t=an(this.data);if(t==="Uint8Array")return this.data;if(t==="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 t=new Uint8Array(this.data.length/2);for(let e=0;e<this.data.length;e+=2){let n=parseInt(this.data.substring(e,e+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");t[e/2]=n}return t}case"Object":{let t=JSON.stringify(this.data);return Zn.encode(t)}case"String":return Zn.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return un(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toArrayBufferAsync();return new Uint8Array(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};var fn;(function(r){r.Debug="debug",r.Silent="silent"})(fn||(fn={}));var xo=class{constructor(){this.logLevel=fn.Silent}setLogLevel(t){this.logLevel=t}log(t){this.info(t)}info(t){this.logLevel!==fn.Silent&&console.info(t)}error(t){this.logLevel!==fn.Silent&&console.error(t)}},ol=new xo;typeof window<"u"&&(window.web5logger=ol);var ye={};Bc(ye,{decode:()=>kr,encodeTo:()=>nr,encodingLength:()=>ir});var sl=Nc,Oc=128,cl=127,al=~cl,ul=Math.pow(2,31);function Nc(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ul;)t[e++]=r&255|Oc,r/=128;for(;r&al;)t[e++]=r&255|Oc,r>>>=7;return t[e]=r|0,Nc.bytes=e-n+1,t}var fl=bo,ll=128,Rc=127;function bo(r,n){var e=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw bo.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Rc)<<i:(s&Rc)*Math.pow(2,i),i+=7}while(s>=ll);return bo.bytes=o-n,e}var hl=Math.pow(2,7),yl=Math.pow(2,14),pl=Math.pow(2,21),dl=Math.pow(2,28),ml=Math.pow(2,35),wl=Math.pow(2,42),gl=Math.pow(2,49),xl=Math.pow(2,56),bl=Math.pow(2,63),El=function(r){return r<hl?1:r<yl?2:r<pl?3:r<dl?4:r<ml?5:r<wl?6:r<gl?7:r<xl?8:r<bl?9:10},vl={encode:sl,decode:fl,encodingLength:El},Al=vl,ln=Al;function kr(r,t=0){return[ln.decode(r,t),ln.decode.bytes]}function nr(r,t,e=0){return ln.encode(r,t,e),t}function ir(r){return ln.encodingLength(r)}function Eo(r,t){let e=t.byteLength,n=ir(r),i=n+ir(e),o=new Uint8Array(i+e);return nr(r,o,0),nr(e,o,n),o.set(t,i),new Ur(r,e,t,o)}function Dc(r){let t=Sr(r),[e,n]=kr(t),[i,o]=kr(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ur(e,i,s,t)}function Mc(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Sc(r.bytes,e.bytes)}}var Ur=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function jc(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Pl(e,Ao(r),t??vt.encoder);default:return Kl(e,Ao(r),t??cn.encoder)}}var Hc=new WeakMap;function Ao(r){let t=Hc.get(r);if(t==null){let e=new Map;return Hc.set(r,e),e}return t}var Bo=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==hn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Tl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=Eo(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Mc(t.multihash,n.multihash)}toString(t){return jc(this,t)}toJSON(){return{"/":jc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??Jc(n,i,o.bytes))}else if(e[Sl]===!0){let{version:n,multihash:i,code:o}=e,s=Dc(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==hn)throw new Error(`Version 0 CID must use dag-pb (code: ${hn}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Jc(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,hn,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=Sr(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new Ur(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,y]=kr(t.subarray(e));return e+=y,l},i=n(),o=hn;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,c=n(),a=n(),u=e+a,f=u-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,e){let[n,i]=Bl(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ao(o).set(n,t),o}};function Bl(r,t){switch(r[0]){case"Q":{let e=t??vt;return[vt.prefix,e.decode(`${vt.prefix}${r}`)]}case vt.prefix:{let e=t??vt;return[vt.prefix,e.decode(r)]}case cn.prefix:{let e=t??cn;return[cn.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Pl(r,t,e){let{prefix:n}=e;if(n!==vt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function Kl(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var hn=112,Tl=18;function Jc(r,t,e){let n=ir(r),i=n+ir(t),o=new Uint8Array(i+e.byteLength);return nr(r,o,0),nr(t,o,n),o.set(e,i),o}var Sl=Symbol.for("@ipld/js-cid/CID");var Qt=class r{static addPrefix(t){var e;let{code:n,data:i,name:o}=t;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: ${(e=t.name)!==null&&e!==void 0?e:t.code}`);let s=ye.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),ye.encodeTo(n,c),c}static getCodeFromData(t){let{prefixedData:e}=t,[n,i]=ye.decode(e);return n}static getCodeFromName(t){let{name:e}=t,n=r.nameToCode.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static getNameFromCode(t){let{code:e}=t,n=r.codeToName.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static registerCodec(t){r.codeToName.set(t.code,t.name),r.nameToCode.set(t.name,t.code)}static removePrefix(t){let{prefixedData:e}=t,[n,i]=ye.decode(e),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:e.slice(i),name:o}}};Qt.codeToName=new Map;Qt.nameToCode=new Map;Qt.registerCodec({code:237,name:"ed25519-pub"});Qt.registerCodec({code:4864,name:"ed25519-priv"});Qt.registerCodec({code:236,name:"x25519-pub"});Qt.registerCodec({code:4866,name:"x25519-priv"});Qt.registerCodec({code:231,name:"secp256k1-pub"});Qt.registerCodec({code:4865,name:"secp256k1-priv"});function Po(r){Object.keys(r).forEach(t=>{r[t]===void 0?delete r[t]:typeof r[t]=="object"&&Po(r[t])})}var uy=Pc(yu(),1),Er=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{u(n.next(f))}catch(l){s(l)}}function a(f){try{u(n.throw(f))}catch(l){s(l)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((n=n.apply(r,t||[])).next())})};var Ti=class{constructor(){this.store=new Map}clear(){return Er(this,void 0,void 0,function*(){this.store.clear()})}close(){return Er(this,void 0,void 0,function*(){})}delete(t){return Er(this,void 0,void 0,function*(){return this.store.delete(t)})}get(t){return Er(this,void 0,void 0,function*(){return this.store.get(t)})}has(t){return Er(this,void 0,void 0,function*(){return this.store.has(t)})}list(){return Er(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(t,e){return Er(this,void 0,void 0,function*(){this.store.set(t,e)})}};var ut=class{};var ki={};Bc(ki,{bitGet:()=>my,bitLen:()=>dy,bitMask:()=>On,bitSet:()=>wy,bytesToHex:()=>Ae,bytesToNumberBE:()=>Be,bytesToNumberLE:()=>Wt,concatBytes:()=>Ke,createHmacDrbg:()=>ks,ensureBytes:()=>it,equalBytes:()=>yy,hexToBytes:()=>vr,hexToNumber:()=>Ss,isBytes:()=>$t,numberToBytesBE:()=>Pt,numberToBytesLE:()=>Pe,numberToHexUnpadded:()=>wu,numberToVarBytesBE:()=>hy,utf8ToBytes:()=>py,validateObject:()=>Rt});var mu=BigInt(0),Si=BigInt(1),fy=BigInt(2);function $t(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ly=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ae(r){if(!$t(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=ly[r[e]];return t}function wu(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Ss(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ve={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function pu(r){if(r>=ve._0&&r<=ve._9)return r-ve._0;if(r>=ve._A&&r<=ve._F)return r-(ve._A-10);if(r>=ve._a&&r<=ve._f)return r-(ve._a-10)}function vr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let i=0,o=0;i<e;i++,o+=2){let s=pu(r.charCodeAt(o)),c=pu(r.charCodeAt(o+1));if(s===void 0||c===void 0){let a=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function Be(r){return Ss(Ae(r))}function Wt(r){if(!$t(r))throw new Error("Uint8Array expected");return Ss(Ae(Uint8Array.from(r).reverse()))}function Pt(r,t){return vr(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return Pt(r,t).reverse()}function hy(r){return vr(wu(r))}function it(r,t,e){let n;if(typeof t=="string")try{n=vr(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if($t(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof e=="number"&&i!==e)throw new Error(`${r} expected ${e} bytes, got ${i}`);return n}function Ke(...r){let t=0;for(let i=0;i<r.length;i++){let o=r[i];if(!$t(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let i=0;i<r.length;i++){let o=r[i];e.set(o,n),n+=o.length}return e}function yy(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function py(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function dy(r){let t;for(t=0;r>mu;r>>=Si,t+=1);return t}function my(r,t){return r>>BigInt(t)&Si}var wy=(r,t,e)=>r|(e?Si:mu)<<BigInt(t),On=r=>(fy<<BigInt(r-1))-Si,Ts=r=>new Uint8Array(r),du=r=>Uint8Array.from(r);function ks(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Ts(r),i=Ts(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>e(i,n,...l),a=(l=Ts())=>{i=c(du([0]),l),n=c(),l.length!==0&&(i=c(du([1]),l),n=c())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<t;){n=c();let m=n.slice();y.push(m),l+=n.length}return Ke(...y)};return(l,y)=>{s(),a(l);let m;for(;!(m=y(u()));)a();return s(),m}}var gy={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"||$t(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Rt(r,t,e={}){let n=(i,o,s)=>{let c=gy[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let a=r[i];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(let[i,o]of Object.entries(t))n(i,o,!1);for(let[i,o]of Object.entries(e))n(i,o,!0);return r}function gu(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function xy(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Us(r,...t){if(!xy(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function xu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");gu(r.outputLen),gu(r.blockLen)}function qr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function bu(r,t){Us(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Ui=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Eu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Ii=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),zt=(r,t)=>r<<32-t|r>>>t,by=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!by)throw new Error("Non little-endian hardware is not supported");function Is(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Rn(r){if(typeof r=="string"&&(r=Is(r)),!Eu(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ci(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Eu(i))throw new Error("Uint8Array expected");t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var Fr=class{clone(){return this._cloneInto()}},Z0={}.toString;function _i(r){let t=n=>r().update(Rn(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Nn(r=32){if(Ui&&typeof Ui.getRandomValues=="function")return Ui.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ey(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var $r=class extends Fr{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ii(this.buffer)}update(t){qr(this);let{view:e,buffer:n,blockLen:i}=this;t=Rn(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Ii(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){qr(this),bu(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[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++)e[l]=0;Ey(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Ii(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var vy=(r,t,e)=>r&t^~r&e,Ay=(r,t,e)=>r&t^r&e^t&e,By=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]),je=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),He=new Uint32Array(64),Cs=class extends $r{constructor(){super(64,32,8,!1),this.A=je[0]|0,this.B=je[1]|0,this.C=je[2]|0,this.D=je[3]|0,this.E=je[4]|0,this.F=je[5]|0,this.G=je[6]|0,this.H=je[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)He[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let y=He[l-15],m=He[l-2],p=zt(y,7)^zt(y,18)^y>>>3,h=zt(m,17)^zt(m,19)^m>>>10;He[l]=h+He[l-7]+p+He[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let y=zt(c,6)^zt(c,11)^zt(c,25),m=f+y+vy(c,a,u)+By[l]+He[l]|0,h=(zt(n,2)^zt(n,13)^zt(n,22))+Ay(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+h|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,c,a,u,f)}roundClean(){He.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Li=_i(()=>new Cs);var lt=BigInt(0),st=BigInt(1),Ar=BigInt(2),Py=BigInt(3),_s=BigInt(4),vu=BigInt(5),Au=BigInt(8),Ky=BigInt(9),Ty=BigInt(16);function tt(r,t){let e=r%t;return e>=lt?e:t+e}function Ls(r,t,e){if(e<=lt||t<lt)throw new Error("Expected power/modulo > 0");if(e===st)return lt;let n=st;for(;t>lt;)t&st&&(n=n*r%e),r=r*r%e,t>>=st;return n}function ot(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Oi(r,t){if(r===lt||t<=lt)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=tt(r,t),n=t,i=lt,o=st,s=st,c=lt;for(;e!==lt;){let u=n/e,f=n%e,l=i-s*u,y=o-c*u;n=e,e=f,i=s,o=c,s=l,c=y}if(n!==st)throw new Error("invert: does not exist");return tt(i,t)}function Sy(r){let t=(r-st)/Ar,e,n,i;for(e=r-st,n=0;e%Ar===lt;e/=Ar,n++);for(i=Ar;i<r&&Ls(i,t,r)!==r-st;i++);if(n===1){let s=(r+st)/_s;return function(a,u){let f=a.pow(u,s);if(!a.eql(a.sqr(f),u))throw new Error("Cannot find square root");return f}}let o=(e+st)/Ar;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,f=c.pow(c.mul(c.ONE,i),e),l=c.pow(a,o),y=c.pow(a,e);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let m=1;for(let h=c.sqr(y);m<u&&!c.eql(h,c.ONE);m++)h=c.sqr(h);let p=c.pow(f,st<<BigInt(u-m-1));f=c.sqr(p),l=c.mul(l,p),y=c.mul(y,f),u=m}return l}}function ky(r){if(r%_s===Py){let t=(r+st)/_s;return function(n,i){let o=n.pow(i,t);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Au===vu){let t=(r-vu)/Au;return function(n,i){let o=n.mul(i,Ar),s=n.pow(o,t),c=n.mul(i,s),a=n.mul(n.mul(c,Ar),s),u=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%Ty,Sy(r)}var Bu=(r,t)=>(tt(r,t)&st)===st,Uy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Os(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Uy.reduce((n,i)=>(n[i]="function",n),t);return Rt(r,e)}function Iy(r,t,e){if(e<lt)throw new Error("Expected power > 0");if(e===lt)return r.ONE;if(e===st)return t;let n=r.ONE,i=t;for(;e>lt;)e&st&&(n=r.mul(n,i)),i=r.sqr(i),e>>=st;return n}function Cy(r,t){let e=new Array(t.length),n=t.reduce((o,s,c)=>r.is0(s)?o:(e[c]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return t.reduceRight((o,s,c)=>r.is0(s)?o:(e[c]=r.mul(o,e[c]),r.mul(o,s)),i),e}function Rs(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Wr(r,t,e=!1,n={}){if(r<=lt)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Rs(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=ky(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:On(i),ZERO:lt,ONE:st,create:a=>tt(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return lt<=a&&a<r},is0:a=>a===lt,isOdd:a=>(a&st)===st,neg:a=>tt(-a,r),eql:(a,u)=>a===u,sqr:a=>tt(a*a,r),add:(a,u)=>tt(a+u,r),sub:(a,u)=>tt(a-u,r),mul:(a,u)=>tt(a*u,r),pow:(a,u)=>Iy(c,a,u),div:(a,u)=>tt(a*Oi(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Oi(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>Cy(c,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>e?Pe(a,o):Pt(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return e?Wt(a):Be(a)}});return Object.freeze(c)}function Pu(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function Ku(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Ns(r){let t=Ku(r);return t+Math.ceil(t/2)}function Tu(r,t,e=!1){let n=r.length,i=Ku(t),o=Ns(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=e?Be(r):Wt(r),c=tt(s,t-st)+st;return e?Pe(c,i):Pt(c,i)}var Ly=BigInt(0),Ds=BigInt(1);function Ri(r,t){let e=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(t/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:e,unsafeLadder(i,o){let s=r.ZERO,c=i;for(;o>Ly;)o&Ds&&(s=s.add(c)),c=c.double(),o>>=Ds;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),a=[],u=i,f=u;for(let l=0;l<s;l++){f=u,a.push(f);for(let y=1;y<c;y++)f=f.add(u),a.push(f);u=f.double()}return a},wNAF(i,o,s){let{windows:c,windowSize:a}=n(i),u=r.ZERO,f=r.BASE,l=BigInt(2**i-1),y=2**i,m=BigInt(i);for(let p=0;p<c;p++){let h=p*a,d=Number(s&l);s>>=m,d>a&&(d-=y,s+=Ds);let g=h,b=h+Math.abs(d)-1,x=p%2!==0,A=d<0;d===0?f=f.add(e(x,o[g])):u=u.add(e(A,o[b]))}return{p:u,f}},wNAFCached(i,o,s,c){let a=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&o.set(i,c(u))),this.wNAF(a,u,s)}}}function Dn(r){return Os(r.Fp),Rt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Oy(r){let t=Dn(r);Rt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:i}=t;if(e){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Ry,hexToBytes:Ny}=ki,Br={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Br;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Ry(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Br,e=typeof r=="string"?Ny(r):r;if(!$t(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:i,l:o}=Br._parseInt(e.subarray(2)),{d:s,l:c}=Br._parseInt(o);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,e=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),i=t(e(r.r)),o=n.length/2,s=i.length/2,c=e(o),a=e(s);return`30${e(s+o+4)}02${a}${i}02${c}${n}`}},Te=BigInt(0),Nt=BigInt(1),lm=BigInt(2),Su=BigInt(3),hm=BigInt(4);function Dy(r){let t=Oy(r),{Fp:e}=t,n=t.toBytes||((p,h,d)=>{let g=h.toAffine();return Ke(Uint8Array.from([4]),e.toBytes(g.x),e.toBytes(g.y))}),i=t.fromBytes||(p=>{let h=p.subarray(1),d=e.fromBytes(h.subarray(0,e.BYTES)),g=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:d,y:g}});function o(p){let{a:h,b:d}=t,g=e.sqr(p),b=e.mul(g,p);return e.add(e.add(b,e.mul(p,h)),d)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Te<p&&p<t.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:g,n:b}=t;if(h&&typeof p!="bigint"){if($t(p)&&(p=Ae(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let x;try{x=typeof p=="bigint"?p:Be(it("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return g&&(x=tt(x,b)),c(x),x}let u=new Map;function f(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,d,g){if(this.px=h,this.py=d,this.pz=g,h==null||!e.isValid(h))throw new Error("x required");if(d==null||!e.isValid(d))throw new Error("y required");if(g==null||!e.isValid(g))throw new Error("z required")}static fromAffine(h){let{x:d,y:g}=h||{};if(!h||!e.isValid(d)||!e.isValid(g))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let b=x=>e.eql(x,e.ZERO);return b(d)&&b(g)?l.ZERO:new l(d,g,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=e.invertBatch(h.map(g=>g.pz));return h.map((g,b)=>g.toAffine(d[b])).map(l.fromAffine)}static fromHex(h){let d=l.fromAffine(i(it("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=this.toAffine();if(!e.isValid(h)||!e.isValid(d))throw new Error("bad point: x or y not FE");let g=e.sqr(d),b=o(h);if(!e.eql(g,b))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:d,py:g,pz:b}=this,{px:x,py:A,pz:v}=h,K=e.eql(e.mul(d,v),e.mul(x,b)),k=e.eql(e.mul(g,v),e.mul(A,b));return K&&k}negate(){return new l(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:d}=t,g=e.mul(d,Su),{px:b,py:x,pz:A}=this,v=e.ZERO,K=e.ZERO,k=e.ZERO,T=e.mul(b,b),L=e.mul(x,x),O=e.mul(A,A),C=e.mul(b,x);return C=e.add(C,C),k=e.mul(b,A),k=e.add(k,k),v=e.mul(h,k),K=e.mul(g,O),K=e.add(v,K),v=e.sub(L,K),K=e.add(L,K),K=e.mul(v,K),v=e.mul(C,v),k=e.mul(g,k),O=e.mul(h,O),C=e.sub(T,O),C=e.mul(h,C),C=e.add(C,k),k=e.add(T,T),T=e.add(k,T),T=e.add(T,O),T=e.mul(T,C),K=e.add(K,T),O=e.mul(x,A),O=e.add(O,O),T=e.mul(O,C),v=e.sub(v,T),k=e.mul(O,L),k=e.add(k,k),k=e.add(k,k),new l(v,K,k)}add(h){f(h);let{px:d,py:g,pz:b}=this,{px:x,py:A,pz:v}=h,K=e.ZERO,k=e.ZERO,T=e.ZERO,L=t.a,O=e.mul(t.b,Su),C=e.mul(d,x),j=e.mul(g,A),M=e.mul(b,v),z=e.add(d,g),B=e.add(x,A);z=e.mul(z,B),B=e.add(C,j),z=e.sub(z,B),B=e.add(d,b);let U=e.add(x,v);return B=e.mul(B,U),U=e.add(C,M),B=e.sub(B,U),U=e.add(g,b),K=e.add(A,v),U=e.mul(U,K),K=e.add(j,M),U=e.sub(U,K),T=e.mul(L,B),K=e.mul(O,M),T=e.add(K,T),K=e.sub(j,T),T=e.add(j,T),k=e.mul(K,T),j=e.add(C,C),j=e.add(j,C),M=e.mul(L,M),B=e.mul(O,B),j=e.add(j,M),M=e.sub(C,M),M=e.mul(L,M),B=e.add(B,M),C=e.mul(j,B),k=e.add(k,C),C=e.mul(U,B),K=e.mul(z,K),K=e.sub(K,C),C=e.mul(z,j),T=e.mul(U,T),T=e.add(T,C),new l(K,k,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return m.wNAFCached(this,u,h,d=>{let g=e.invertBatch(d.map(b=>b.pz));return d.map((b,x)=>b.toAffine(g[x])).map(l.fromAffine)})}multiplyUnsafe(h){let d=l.ZERO;if(h===Te)return d;if(c(h),h===Nt)return this;let{endo:g}=t;if(!g)return m.unsafeLadder(this,h);let{k1neg:b,k1:x,k2neg:A,k2:v}=g.splitScalar(h),K=d,k=d,T=this;for(;x>Te||v>Te;)x&Nt&&(K=K.add(T)),v&Nt&&(k=k.add(T)),T=T.double(),x>>=Nt,v>>=Nt;return b&&(K=K.negate()),A&&(k=k.negate()),k=new l(e.mul(k.px,g.beta),k.py,k.pz),K.add(k)}multiply(h){c(h);let d=h,g,b,{endo:x}=t;if(x){let{k1neg:A,k1:v,k2neg:K,k2:k}=x.splitScalar(d),{p:T,f:L}=this.wNAF(v),{p:O,f:C}=this.wNAF(k);T=m.constTimeNegate(A,T),O=m.constTimeNegate(K,O),O=new l(e.mul(O.px,x.beta),O.py,O.pz),g=T.add(O),b=L.add(C)}else{let{p:A,f:v}=this.wNAF(d);g=A,b=v}return l.normalizeZ([g,b])[0]}multiplyAndAddUnsafe(h,d,g){let b=l.BASE,x=(v,K)=>K===Te||K===Nt||!v.equals(b)?v.multiplyUnsafe(K):v.multiply(K),A=x(this,d).add(x(h,g));return A.is0()?void 0:A}toAffine(h){let{px:d,py:g,pz:b}=this,x=this.is0();h==null&&(h=x?e.ONE:e.inv(b));let A=e.mul(d,h),v=e.mul(g,h),K=e.mul(b,h);if(x)return{x:e.ZERO,y:e.ZERO};if(!e.eql(K,e.ONE))throw new Error("invZ was invalid");return{x:A,y:v}}isTorsionFree(){let{h,isTorsionFree:d}=t;if(h===Nt)return!0;if(d)return d(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=t;return h===Nt?this:d?d(l,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(l,this,h)}toHex(h=!0){return Ae(this.toRawBytes(h))}}l.BASE=new l(t.Gx,t.Gy,e.ONE),l.ZERO=new l(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,m=Ri(l,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function My(r){let t=Dn(r);return Rt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ku(r){let t=My(r),{Fp:e,n}=t,i=e.BYTES+1,o=2*e.BYTES+1;function s(B){return Te<B&&B<e.ORDER}function c(B){return tt(B,n)}function a(B){return Oi(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:y}=Dy({...t,toBytes(B,U,R){let P=U.toAffine(),w=e.toBytes(P.x),S=Ke;return R?S(Uint8Array.from([U.hasEvenY()?2:3]),w):S(Uint8Array.from([4]),w,e.toBytes(P.y))},fromBytes(B){let U=B.length,R=B[0],P=B.subarray(1);if(U===i&&(R===2||R===3)){let w=Be(P);if(!s(w))throw new Error("Point is not on curve");let S=l(w),I=e.sqrt(S),_=(I&Nt)===Nt;return(R&1)===1!==_&&(I=e.neg(I)),{x:w,y:I}}else if(U===o&&R===4){let w=e.fromBytes(P.subarray(0,e.BYTES)),S=e.fromBytes(P.subarray(e.BYTES,2*e.BYTES));return{x:w,y:S}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),m=B=>Ae(Pt(B,t.nByteLength));function p(B){let U=n>>Nt;return B>U}function h(B){return p(B)?c(-B):B}let d=(B,U,R)=>Be(B.slice(U,R));class g{constructor(U,R,P){this.r=U,this.s=R,this.recovery=P,this.assertValidity()}static fromCompact(U){let R=t.nByteLength;return U=it("compactSignature",U,R*2),new g(d(U,0,R),d(U,R,2*R))}static fromDER(U){let{r:R,s:P}=Br.toSig(it("DER",U));return new g(R,P)}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(U){return new g(this.r,this.s,U)}recoverPublicKey(U){let{r:R,s:P,recovery:w}=this,S=k(it("msgHash",U));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let I=w===2||w===3?R+t.n:R;if(I>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=w&1?"03":"02",H=u.fromHex(_+m(I)),J=a(I),Z=c(-S*J),q=c(P*J),F=u.BASE.multiplyAndAddUnsafe(H,Z,q);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return vr(this.toDERHex())}toDERHex(){return Br.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return vr(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let b={isValidPrivateKey(B){try{return f(B),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let B=Ns(t.n);return Tu(t.randomBytes(B),t.n)},precompute(B=8,U=u.BASE){return U._setWindowSize(B),U.multiply(BigInt(3)),U}};function x(B,U=!0){return u.fromPrivateKey(B).toRawBytes(U)}function A(B){let U=$t(B),R=typeof B=="string",P=(U||R)&&B.length;return U?P===i||P===o:R?P===2*i||P===2*o:B instanceof u}function v(B,U,R=!0){if(A(B))throw new Error("first arg must be private key");if(!A(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(f(B)).toRawBytes(R)}let K=t.bits2int||function(B){let U=Be(B),R=B.length*8-t.nBitLength;return R>0?U>>BigInt(R):U},k=t.bits2int_modN||function(B){return c(K(B))},T=On(t.nBitLength);function L(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!(Te<=B&&B<T))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Pt(B,t.nByteLength)}function O(B,U,R=C){if(["recovered","canonical"].some(et=>et in R))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:w}=t,{lowS:S,prehash:I,extraEntropy:_}=R;S==null&&(S=!0),B=it("msgHash",B),I&&(B=it("prehashed msgHash",P(B)));let H=k(B),J=f(U),Z=[L(J),L(H)];if(_!=null){let et=_===!0?w(e.BYTES):_;Z.push(it("extraEntropy",et))}let q=Ke(...Z),F=H;function rt(et){let yt=K(et);if(!y(yt))return;let pt=a(yt),ft=u.BASE.multiply(yt).toAffine(),mt=c(ft.x);if(mt===Te)return;let he=c(pt*c(F+mt*J));if(he===Te)return;let er=(ft.x===mt?0:2)|Number(ft.y&Nt),on=he;return S&&p(he)&&(on=h(he),er^=1),new g(mt,on,er)}return{seed:q,k2sig:rt}}let C={lowS:t.lowS,prehash:!1},j={lowS:t.lowS,prehash:!1};function M(B,U,R=C){let{seed:P,k2sig:w}=O(B,U,R),S=t;return ks(S.hash.outputLen,S.nByteLength,S.hmac)(P,w)}u.BASE._setWindowSize(8);function z(B,U,R,P=j){let w=B;if(U=it("msgHash",U),R=it("publicKey",R),"strict"in P)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:I}=P,_,H;try{if(typeof w=="string"||$t(w))try{_=g.fromDER(w)}catch(ft){if(!(ft instanceof Br.Err))throw ft;_=g.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:ft,s:mt}=w;_=new g(ft,mt)}else throw new Error("PARSE");H=u.fromHex(R)}catch(ft){if(ft.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&_.hasHighS())return!1;I&&(U=t.hash(U));let{r:J,s:Z}=_,q=k(U),F=a(Z),rt=c(q*F),et=c(J*F),yt=u.BASE.multiplyAndAddUnsafe(H,rt,et)?.toAffine();return yt?c(yt.x)===J:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:v,sign:M,verify:z,ProjectivePoint:u,Signature:g,utils:b}}var Ni=class extends Fr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,xu(t);let n=Rn(e);if(this.iHash=t.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?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return qr(this),this.iHash.update(t),this}digestInto(t){qr(this),Us(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ms=(r,t,e)=>new Ni(r,t).update(e).digest();Ms.create=(r,t)=>new Ni(r,t);function jy(r){return{hash:r,hmac:(t,...e)=>Ms(r,t,Ci(...e)),randomBytes:Nn}}function Di(r,t){let e=n=>ku({...r,...jy(n)});return Object.freeze({...e(t),create:e})}var Cu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Uu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Hy=BigInt(1),js=BigInt(2),Iu=(r,t)=>(r+t/js)/t;function Jy(r){let t=Cu,e=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=ot(f,e,t)*f%t,y=ot(l,e,t)*f%t,m=ot(y,js,t)*u%t,p=ot(m,i,t)*m%t,h=ot(p,o,t)*p%t,d=ot(h,c,t)*h%t,g=ot(d,a,t)*d%t,b=ot(g,c,t)*h%t,x=ot(b,e,t)*f%t,A=ot(x,s,t)*p%t,v=ot(A,n,t)*u%t,K=ot(v,js,t);if(!Hs.eql(Hs.sqr(K),r))throw new Error("Cannot find square root");return K}var Hs=Wr(Cu,void 0,void 0,{sqrt:Jy}),at=Di({a:BigInt(0),b:BigInt(7),Fp:Hs,n:Uu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Uu,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Hy*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,s=BigInt("0x100000000000000000000000000000000"),c=Iu(o*r,t),a=Iu(-n*r,t),u=tt(r-c*e-a*i,t),f=tt(-c*n-a*o,t),l=u>s,y=f>s;if(l&&(u=t-u),y&&(f=t-f),u>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:y,k2:f}}}},Li),Bm=BigInt(0);var Pm=at.ProjectivePoint;function Mi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Gy(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function zr(r,...t){if(!Gy(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Mn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Mi(r.outputLen),Mi(r.blockLen)}function Zr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function _u(r,t){zr(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Se=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var ji=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Zt=(r,t)=>r<<32-t|r>>>t;var Im=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Vy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Je(r){return typeof r=="string"&&(r=Vy(r)),zr(r),r}function Js(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];zr(i),t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var Yr=class{clone(){return this._cloneInto()}},Cm={}.toString;function Lu(r){let t=n=>r().update(Je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ou(r=32){if(Se&&typeof Se.getRandomValues=="function")return Se.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function qy(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var Ru=(r,t,e)=>r&t^~r&e,Nu=(r,t,e)=>r&t^r&e^t&e,Hi=class extends Yr{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=ji(this.buffer)}update(t){Zr(this);let{view:e,buffer:n,blockLen:i}=this;t=Je(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=ji(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Zr(this),_u(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[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++)e[l]=0;qy(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=ji(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var Fy=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]),Ge=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ve=new Uint32Array(64),Gs=class extends Hi{constructor(){super(64,32,8,!1),this.A=Ge[0]|0,this.B=Ge[1]|0,this.C=Ge[2]|0,this.D=Ge[3]|0,this.E=Ge[4]|0,this.F=Ge[5]|0,this.G=Ge[6]|0,this.H=Ge[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)Ve[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let y=Ve[l-15],m=Ve[l-2],p=Zt(y,7)^Zt(y,18)^y>>>3,h=Zt(m,17)^Zt(m,19)^m>>>10;Ve[l]=h+Ve[l-7]+p+Ve[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Zt(c,6)^Zt(c,11)^Zt(c,25),m=f+y+Ru(c,a,u)+Fy[l]+Ve[l]|0,h=(Zt(n,2)^Zt(n,13)^Zt(n,22))+Nu(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+h|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,c,a,u,f)}roundClean(){Ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var kt=Lu(()=>new Gs);function Du(r){let t=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=t(n[s]);return o}return n},e=t(r);return JSON.stringify(e)}var Xr=class{static async digest({data:t}){return kt(t)}};var Vs="urn:jwk:";async function G({jwk:r}){let t=r.kty,e;if(t==="EC")e={crv:r.crv,kty:r.kty,x:r.x,y:r.y};else if(t==="oct")e={k:r.k,kty:r.kty};else if(t==="OKP")e={crv:r.crv,kty:r.kty,x:r.x};else if(t==="RSA")e={e:r.e,kty:r.kty,n:r.n};else throw new Error(`Unsupported key type: ${t}`);Po(e);let n=Du(e),i=N.string(n).toUint8Array(),o=await Xr.digest({data:i});return N.uint8Array(o).toBase64Url()}function oe(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 Qr(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 se(r){return!(!r||typeof r!="object"||!("kty"in r&&"k"in r)||r.kty!=="oct"||typeof r.k!="string")}function Ut(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 tn(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 Mu(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}}function Fm(r){if(!r||typeof r!="object")return!1;switch(r.kty){case"EC":case"OKP":return"x"in r&&!("d"in r);case"RSA":return"n"in r&&"e"in r&&!("d"in r);default:return!1}}var Dt=class r{static async adjustSignatureToLowS({signature:t}){let e=at.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return at.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"secp256k1",x:N.uint8Array(n.x).toBase64Url(),y:N.uint8Array(n.y).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return at.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return at.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=at.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(oe(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!oe(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(Qr(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=N.base64Url(t.x).toUint8Array(),i=N.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return at.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=kt(t);return at.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return at.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{at.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=kt(n);return at.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=at.getPublicKey(t));let e=at.ProjectivePoint.fromHex(t),n=Pt(e.x,32),i=Pt(e.y,32);return{x:n,y:i}}};var ju=Wr(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),$y=ju.create(BigInt("-3")),Wy=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),zy=Di({a:$y,b:Wy,Fp:ju,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Li),It=zy;var Mt=class r{static async adjustSignatureToLowS({signature:t}){let e=It.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return It.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"P-256",x:N.uint8Array(n.x).toBase64Url(),y:N.uint8Array(n.y).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return It.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return It.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=It.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(oe(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!oe(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(Qr(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=N.base64Url(t.x).toUint8Array(),i=N.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return It.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=kt(t);return It.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return It.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{It.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=kt(n);return It.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=It.getPublicKey(t));let e=It.ProjectivePoint.fromHex(t),n=Pt(e.x,32),i=Pt(e.y,32);return{x:n,y:i}}};var jn=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"ES256K":case"secp256k1":{let n=await Dt.bytesToPrivateKey({privateKeyBytes:e});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Mt.bytesToPrivateKey({privateKeyBytes:e});return n.alg="ES256",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async bytesToPublicKey({algorithm:t,publicKeyBytes:e}){switch(t){case"ES256K":case"secp256k1":{let n=await Dt.bytesToPublicKey({publicKeyBytes:e});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Mt.bytesToPublicKey({publicKeyBytes:e});return n.alg="ES256",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await Dt.computePublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Mt.computePublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let e=await Dt.generateKey();return e.alg="ES256K",e}case"ES256":case"secp256r1":{let e=await Mt.generateKey();return e.alg="ES256",e}}}async getPublicKey({key:t}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await Dt.getPublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Mt.getPublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return await Dt.sign({key:t,data:e});case"P-256":return await Mt.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!Qr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return await Dt.verify({key:t,signature:e,data:n});case"P-256":return await Mt.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){switch(t.crv){case"secp256k1":return await Dt.privateKeyToBytes({privateKey:t});case"P-256":return await Mt.privateKeyToBytes({privateKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}async publicKeyToBytes({publicKey:t}){switch(t.crv){case"secp256k1":return await Dt.publicKeyToBytes({publicKey:t});case"P-256":return await Mt.publicKeyToBytes({publicKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}};var Ji=BigInt(4294967295),qs=BigInt(32);function Hu(r,t=!1){return t?{h:Number(r&Ji),l:Number(r>>qs&Ji)}:{h:Number(r>>qs&Ji)|0,l:Number(r&Ji)|0}}function Zy(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=Hu(r[i],t);[e[i],n[i]]=[o,s]}return[e,n]}var Yy=(r,t)=>BigInt(r>>>0)<<qs|BigInt(t>>>0),Xy=(r,t,e)=>r>>>e,Qy=(r,t,e)=>r<<32-e|t>>>e,tp=(r,t,e)=>r>>>e|t<<32-e,ep=(r,t,e)=>r<<32-e|t>>>e,rp=(r,t,e)=>r<<64-e|t>>>e-32,np=(r,t,e)=>r>>>e-32|t<<64-e,ip=(r,t)=>t,op=(r,t)=>r,sp=(r,t,e)=>r<<e|t>>>32-e,cp=(r,t,e)=>t<<e|r>>>32-e,ap=(r,t,e)=>t<<e-32|r>>>64-e,up=(r,t,e)=>r<<e-32|t>>>64-e;function fp(r,t,e,n){let i=(t>>>0)+(n>>>0);return{h:r+e+(i/2**32|0)|0,l:i|0}}var lp=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),hp=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,yp=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),pp=(r,t,e,n,i)=>t+e+n+i+(r/2**32|0)|0,dp=(r,t,e,n,i)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(i>>>0),mp=(r,t,e,n,i,o)=>t+e+n+i+o+(r/2**32|0)|0;var wp={fromBig:Hu,split:Zy,toBig:Yy,shrSH:Xy,shrSL:Qy,rotrSH:tp,rotrSL:ep,rotrBH:rp,rotrBL:np,rotr32H:ip,rotr32L:op,rotlSH:sp,rotlSL:cp,rotlBH:ap,rotlBL:up,add:fp,add3L:lp,add3H:hp,add4L:yp,add4H:pp,add5H:mp,add5L:dp},$=wp;var[gp,xp]=$.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))),qe=new Uint32Array(80),Fe=new Uint32Array(80),Fs=class extends $r{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:t,Al:e,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:y,Gh:m,Gl:p,Hh:h,Hl:d}=this;return[t,e,n,i,o,s,c,a,u,f,l,y,m,p,h,d]}set(t,e,n,i,o,s,c,a,u,f,l,y,m,p,h,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=m|0,this.Gl=p|0,this.Hh=h|0,this.Hl=d|0}process(t,e){for(let x=0;x<16;x++,e+=4)qe[x]=t.getUint32(e),Fe[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let A=qe[x-15]|0,v=Fe[x-15]|0,K=$.rotrSH(A,v,1)^$.rotrSH(A,v,8)^$.shrSH(A,v,7),k=$.rotrSL(A,v,1)^$.rotrSL(A,v,8)^$.shrSL(A,v,7),T=qe[x-2]|0,L=Fe[x-2]|0,O=$.rotrSH(T,L,19)^$.rotrBH(T,L,61)^$.shrSH(T,L,6),C=$.rotrSL(T,L,19)^$.rotrBL(T,L,61)^$.shrSL(T,L,6),j=$.add4L(k,C,Fe[x-7],Fe[x-16]),M=$.add4H(j,K,O,qe[x-7],qe[x-16]);qe[x]=M|0,Fe[x]=j|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:y,Fh:m,Fl:p,Gh:h,Gl:d,Hh:g,Hl:b}=this;for(let x=0;x<80;x++){let A=$.rotrSH(l,y,14)^$.rotrSH(l,y,18)^$.rotrBH(l,y,41),v=$.rotrSL(l,y,14)^$.rotrSL(l,y,18)^$.rotrBL(l,y,41),K=l&m^~l&h,k=y&p^~y&d,T=$.add5L(b,v,k,xp[x],Fe[x]),L=$.add5H(T,g,A,K,gp[x],qe[x]),O=T|0,C=$.rotrSH(n,i,28)^$.rotrBH(n,i,34)^$.rotrBH(n,i,39),j=$.rotrSL(n,i,28)^$.rotrBL(n,i,34)^$.rotrBL(n,i,39),M=n&o^n&c^o&c,z=i&s^i&a^s&a;g=h|0,b=d|0,h=m|0,d=p|0,m=l|0,p=y|0,{h:l,l:y}=$.add(u|0,f|0,L|0,O|0),u=c|0,f=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let B=$.add3L(O,j,z);n=$.add3H(B,L,C,M),i=B|0}({h:n,l:i}=$.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=$.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=$.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=$.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=$.add(this.Eh|0,this.El|0,l|0,y|0),{h:m,l:p}=$.add(this.Fh|0,this.Fl|0,m|0,p|0),{h,l:d}=$.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:g,l:b}=$.add(this.Hh|0,this.Hl|0,g|0,b|0),this.set(n,i,o,s,c,a,u,f,l,y,m,p,h,d,g,b)}roundClean(){qe.fill(0),Fe.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 $s=_i(()=>new Fs);var Yt=BigInt(0),Ct=BigInt(1),Gi=BigInt(2),bp=BigInt(8),Ep={zip215:!0};function vp(r){let t=Dn(r);return Rt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Vi(r){let t=vp(r),{Fp:e,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=t,u=Gi<<BigInt(c*8)-Ct,f=e.create,l=t.uvRatio||((P,w)=>{try{return{isValid:!0,value:e.sqrt(P*e.inv(w))}}catch{return{isValid:!1,value:Yt}}}),y=t.adjustScalarBytes||(P=>P),m=t.domain||((P,w,S)=>{if(w.length||S)throw new Error("Contexts/pre-hash are not supported");return P}),p=P=>typeof P=="bigint"&&Yt<P,h=(P,w)=>p(P)&&p(w)&&P<w,d=P=>P===Yt||h(P,u);function g(P,w){if(h(P,w))return P;throw new Error(`Expected valid scalar < ${w}, got ${typeof P} ${P}`)}function b(P){return P===Yt?P:g(P,n)}let x=new Map;function A(P){if(!(P instanceof v))throw new Error("ExtendedPoint expected")}class v{constructor(w,S,I,_){if(this.ex=w,this.ey=S,this.ez=I,this.et=_,!d(w))throw new Error("x required");if(!d(S))throw new Error("y required");if(!d(I))throw new Error("z required");if(!d(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof v)throw new Error("extended point not allowed");let{x:S,y:I}=w||{};if(!d(S)||!d(I))throw new Error("invalid affine point");return new v(S,I,Ct,f(S*I))}static normalizeZ(w){let S=e.invertBatch(w.map(I=>I.ez));return w.map((I,_)=>I.toAffine(S[_])).map(v.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,x.delete(this)}assertValidity(){let{a:w,d:S}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:I,ey:_,ez:H,et:J}=this,Z=f(I*I),q=f(_*_),F=f(H*H),rt=f(F*F),et=f(Z*w),yt=f(F*f(et+q)),pt=f(rt+f(S*f(Z*q)));if(yt!==pt)throw new Error("bad point: equation left != right (1)");let ft=f(I*_),mt=f(H*J);if(ft!==mt)throw new Error("bad point: equation left != right (2)")}equals(w){A(w);let{ex:S,ey:I,ez:_}=this,{ex:H,ey:J,ez:Z}=w,q=f(S*Z),F=f(H*_),rt=f(I*Z),et=f(J*_);return q===F&&rt===et}is0(){return this.equals(v.ZERO)}negate(){return new v(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:w}=t,{ex:S,ey:I,ez:_}=this,H=f(S*S),J=f(I*I),Z=f(Gi*f(_*_)),q=f(w*H),F=S+I,rt=f(f(F*F)-H-J),et=q+J,yt=et-Z,pt=q-J,ft=f(rt*yt),mt=f(et*pt),he=f(rt*pt),er=f(yt*et);return new v(ft,mt,er,he)}add(w){A(w);let{a:S,d:I}=t,{ex:_,ey:H,ez:J,et:Z}=this,{ex:q,ey:F,ez:rt,et}=w;if(S===BigInt(-1)){let wc=f((H-_)*(F+q)),gc=f((H+_)*(F-q)),ao=f(gc-wc);if(ao===Yt)return this.double();let xc=f(J*Gi*et),bc=f(Z*Gi*rt),Ec=bc+xc,vc=gc+wc,Ac=bc-xc,jf=f(Ec*ao),Hf=f(vc*Ac),Jf=f(Ec*Ac),Gf=f(ao*vc);return new v(jf,Hf,Gf,Jf)}let yt=f(_*q),pt=f(H*F),ft=f(Z*I*et),mt=f(J*rt),he=f((_+H)*(q+F)-yt-pt),er=mt-ft,on=mt+ft,mc=f(pt-S*yt),Rf=f(he*er),Nf=f(on*mc),Df=f(he*mc),Mf=f(er*on);return new v(Rf,Nf,Mf,Df)}subtract(w){return this.add(w.negate())}wNAF(w){return T.wNAFCached(this,x,w,v.normalizeZ)}multiply(w){let{p:S,f:I}=this.wNAF(g(w,n));return v.normalizeZ([S,I])[0]}multiplyUnsafe(w){let S=b(w);return S===Yt?k:this.equals(k)||S===Ct?this:this.equals(K)?this.wNAF(S).p:T.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(w){let{ex:S,ey:I,ez:_}=this,H=this.is0();w==null&&(w=H?bp:e.inv(_));let J=f(S*w),Z=f(I*w),q=f(_*w);if(H)return{x:Yt,y:Ct};if(q!==Ct)throw new Error("invZ was invalid");return{x:J,y:Z}}clearCofactor(){let{h:w}=t;return w===Ct?this:this.multiplyUnsafe(w)}static fromHex(w,S=!1){let{d:I,a:_}=t,H=e.BYTES;w=it("pointHex",w,H);let J=w.slice(),Z=w[H-1];J[H-1]=Z&-129;let q=Wt(J);q===Yt||(S?g(q,u):g(q,e.ORDER));let F=f(q*q),rt=f(F-Ct),et=f(I*F-_),{isValid:yt,value:pt}=l(rt,et);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(pt&Ct)===Ct,mt=(Z&128)!==0;if(!S&&pt===Yt&&mt)throw new Error("Point.fromHex: x=0 and x_0=1");return mt!==ft&&(pt=f(-pt)),v.fromAffine({x:pt,y:q})}static fromPrivateKey(w){return C(w).point}toRawBytes(){let{x:w,y:S}=this.toAffine(),I=Pe(S,e.BYTES);return I[I.length-1]|=w&Ct?128:0,I}toHex(){return Ae(this.toRawBytes())}}v.BASE=new v(t.Gx,t.Gy,Ct,f(t.Gx*t.Gy)),v.ZERO=new v(Yt,Ct,Ct,Yt);let{BASE:K,ZERO:k}=v,T=Ri(v,c*8);function L(P){return tt(P,n)}function O(P){return L(Wt(P))}function C(P){let w=c;P=it("private key",P,w);let S=it("hashed private key",o(P),2*w),I=y(S.slice(0,w)),_=S.slice(w,2*w),H=O(I),J=K.multiply(H),Z=J.toRawBytes();return{head:I,prefix:_,scalar:H,point:J,pointBytes:Z}}function j(P){return C(P).pointBytes}function M(P=new Uint8Array,...w){let S=Ke(...w);return O(o(m(S,it("context",P),!!i)))}function z(P,w,S={}){P=it("message",P),i&&(P=i(P));let{prefix:I,scalar:_,pointBytes:H}=C(w),J=M(S.context,I,P),Z=K.multiply(J).toRawBytes(),q=M(S.context,Z,H,P),F=L(J+q*_);b(F);let rt=Ke(Z,Pe(F,e.BYTES));return it("result",rt,c*2)}let B=Ep;function U(P,w,S,I=B){let{context:_,zip215:H}=I,J=e.BYTES;P=it("signature",P,2*J),w=it("message",w),i&&(w=i(w));let Z=Wt(P.slice(J,2*J)),q,F,rt;try{q=v.fromHex(S,H),F=v.fromHex(P.slice(0,J),H),rt=K.multiplyUnsafe(Z)}catch{return!1}if(!H&&q.isSmallOrder())return!1;let et=M(_,F.toRawBytes(),q.toRawBytes(),w);return F.add(q.multiplyUnsafe(et)).subtract(rt).clearCofactor().equals(v.ZERO)}return K._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:z,verify:U,ExtendedPoint:v,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>s(e.BYTES),precompute(P=8,w=v.BASE){return w._setWindowSize(P),w.multiply(BigInt(3)),w}}}}var Hn=BigInt(0),Ws=BigInt(1);function Ap(r){return Rt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Ju(r){let t=Ap(r),{P:e}=t,n=x=>tt(x,e),i=t.montgomeryBits,o=Math.ceil(i/8),s=t.nByteLength,c=t.adjustScalarBytes||(x=>x),a=t.powPminus2||(x=>Ls(x,e-BigInt(2),e));function u(x,A,v){let K=n(x*(A-v));return A=n(A-K),v=n(v+K),[A,v]}function f(x){if(typeof x=="bigint"&&Hn<=x&&x<e)return x;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(t.a-BigInt(2))/BigInt(4);function y(x,A){let v=f(x),K=f(A),k=v,T=Ws,L=Hn,O=v,C=Ws,j=Hn,M;for(let B=BigInt(i-1);B>=Hn;B--){let U=K>>B&Ws;j^=U,M=u(j,T,O),T=M[0],O=M[1],M=u(j,L,C),L=M[0],C=M[1],j=U;let R=T+L,P=n(R*R),w=T-L,S=n(w*w),I=P-S,_=O+C,H=O-C,J=n(H*R),Z=n(_*w),q=J+Z,F=J-Z;O=n(q*q),C=n(k*n(F*F)),T=n(P*S),L=n(I*(P+n(l*I)))}M=u(j,T,O),T=M[0],O=M[1],M=u(j,L,C),L=M[0],C=M[1];let z=a(L);return n(T*z)}function m(x){return Pe(n(x),o)}function p(x){let A=it("u coordinate",x,o);return s===32&&(A[31]&=127),Wt(A)}function h(x){let A=it("scalar",x),v=A.length;if(v!==o&&v!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${v}`);return Wt(c(A))}function d(x,A){let v=p(A),K=h(x),k=y(v,K);if(k===Hn)throw new Error("Invalid private or public key received");return m(k)}let g=m(t.Gu);function b(x){return d(x,g)}return{scalarMult:d,scalarMultBase:b,getSharedSecret:(x,A)=>d(x,A),getPublicKey:x=>b(x),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:g}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Gu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),_w=BigInt(0),Bp=BigInt(1),zs=BigInt(2),Pp=BigInt(5),Vu=BigInt(10),Kp=BigInt(20),Tp=BigInt(40),qu=BigInt(80);function Fu(r){let t=Jn,n=r*r%t*r%t,i=ot(n,zs,t)*n%t,o=ot(i,Bp,t)*r%t,s=ot(o,Pp,t)*o%t,c=ot(s,Vu,t)*s%t,a=ot(c,Kp,t)*c%t,u=ot(a,Tp,t)*a%t,f=ot(u,qu,t)*u%t,l=ot(f,qu,t)*u%t,y=ot(l,Vu,t)*s%t;return{pow_p_5_8:ot(y,zs,t)*r%t,b2:n}}function $u(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Sp(r,t){let e=Jn,n=tt(t*t*t,e),i=tt(n*n*t,e),o=Fu(r*i).pow_p_5_8,s=tt(r*n*o,e),c=tt(t*s*s,e),a=s,u=tt(s*Gu,e),f=c===r,l=c===tt(-r,e),y=c===tt(-r*Gu,e);return f&&(s=a),(l||y)&&(s=u),Bu(s,e)&&(s=tt(-s,e)),{isValid:f||l,value:s}}var jt=Wr(Jn,void 0,!0),Gn={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:jt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:$s,randomBytes:Nn,adjustScalarBytes:$u,uvRatio:Sp},$e=Vi(Gn);function Wu(r,t,e){if(t.length>255)throw new Error("Context is too big");return Ci(Is("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Lw=Vi({...Gn,domain:Wu}),Ow=Vi({...Gn,domain:Wu,prehash:$s}),Pr=Ju({P:Jn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let t=Jn,{pow_p_5_8:e,b2:n}=Fu(r);return tt(ot(e,BigInt(3),t)*n,t)},adjustScalarBytes:$u,randomBytes:Nn});function zu(r){let{y:t}=$e.ExtendedPoint.fromHex(r),e=BigInt(1);return jt.toBytes(jt.create((e+t)*jt.inv(e-t)))}function Zu(r){let t=Gn.hash(r.subarray(0,32));return Gn.adjustScalarBytes(t).subarray(0,32)}var kp=(jt.ORDER+BigInt(3))/BigInt(8),Rw=jt.pow(zs,kp),Nw=jt.sqrt(jt.neg(jt.ONE)),Dw=(jt.ORDER-BigInt(5))/BigInt(8),Mw=BigInt(486662);var jw=Pu(jt,jt.neg(BigInt(486664)));var Hw=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Jw=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Gw=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vw=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var qw=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ht=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=$e.getPublicKey(t),n={crv:"Ed25519",d:N.uint8Array(t).toBase64Url(),kty:"OKP",x:N.uint8Array(e).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"Ed25519",x:N.uint8Array(t).toBase64Url()};return e.kid=await G({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=$e.getPublicKey(e),i={kty:"OKP",crv:"Ed25519",x:N.uint8Array(n).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertPrivateKeyToX25519({privateKey:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=Zu(e),i=Pr.getPublicKey(n),o={kty:"OKP",crv:"X25519",d:N.uint8Array(n).toBase64Url(),x:N.uint8Array(i).toBase64Url()};return o.kid=await G({jwk:o}),o}static async convertPublicKeyToX25519({publicKey:t}){let e=await r.publicKeyToBytes({publicKey:t});if(!await r.validatePublicKey({publicKeyBytes:e}))throw new Error("Ed25519: Invalid public key.");let i=zu(e),o={kty:"OKP",crv:"X25519",x:N.uint8Array(i).toBase64Url()};return o.kid=await G({jwk:o}),o}static async generateKey(){let t=$e.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(Ut(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Ut(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!tn(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return N.base64Url(t.x).toUint8Array()}static async sign({key:t,data:e}){let n=await r.privateKeyToBytes({privateKey:t});return $e.sign(e,n)}static async validatePublicKey({publicKeyBytes:t}){try{$e.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t});return $e.verify(e,n,i)}};var qi=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"Ed25519":{let n=await Ht.bytesToPrivateKey({privateKeyBytes:e});return n.alg="EdDSA",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async bytesToPublicKey({algorithm:t,publicKeyBytes:e}){switch(t){case"Ed25519":{let n=await Ht.bytesToPublicKey({publicKeyBytes:e});return n.alg="EdDSA",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ht.computePublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"Ed25519":{let e=await Ht.generateKey();return e.alg="EdDSA",e}}}async getPublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ht.getPublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return await Ht.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!tn(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return await Ht.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){switch(t.crv){case"Ed25519":return await Ht.privateKeyToBytes({privateKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}async publicKeyToBytes({publicKey:t}){switch(t.crv){case"Ed25519":return await Ht.publicKeyToBytes({publicKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}};var Fi=class extends ut{async digest({algorithm:t,data:e}){switch(t){case"SHA-256":return await Xr.digest({data:e})}}};var We=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=Pr.getPublicKey(t),n={kty:"OKP",crv:"X25519",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"X25519",x:N.uint8Array(t).toBase64Url()};return e.kid=await G({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=Pr.getPublicKey(e),i={kty:"OKP",crv:"X25519",x:N.uint8Array(n).toBase64Url()};return i.kid=await G({jwk:i}),i}static async generateKey(){let t=Pr.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(Ut(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Ut(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!tn(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return N.base64Url(t.x).toUint8Array()}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return Pr.getSharedSecret(n,i)}};var $i=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"X25519":return We.bytesToPrivateKey({privateKeyBytes:e});default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return We.computePublicKey({key:t});default:throw new nt("algorithmNotSupported",`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"X25519":return We.generateKey();default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async getPublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return We.getPublicKey({key:t});default:throw new nt("algorithmNotSupported",`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){return We.privateKeyToBytes({privateKey:t})}};var Zs={Ed25519:{implementation:qi,names:["Ed25519"]},secp256k1:{implementation:jn,names:["ES256K","secp256k1"]},secp256r1:{implementation:jn,names:["ES256","secp256r1"]},"SHA-256":{implementation:Fi,names:["SHA-256"]},X25519:{implementation:$i,names:["X25519"]}},Yu=class{constructor(t){this._algorithmInstances=new Map;this._keyStore=t?.keyStore??new Ti}async digest({algorithm:t,data:e}){return await this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:e})}async exportKey({keyUri:t}){return await this.getPrivateKey({keyUri:t})}async generateKey({algorithm:t}){let n=await this.getAlgorithm({algorithm:t}).generateKey({algorithm:t});if(n?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let i=`${Vs}${n.kid}`;return await this._keyStore.set(i,n),i}async getKeyUri({key:t}){let e=await G({jwk:t});return`${Vs}${e}`}async getPublicKey({keyUri:t}){let e=await this.getPrivateKey({keyUri:t}),n=this.getAlgorithmName({key:e});return await this.getAlgorithm({algorithm:n}).getPublicKey({key:e})}async importKey({key:t}){if(!Mu(t))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let e=structuredClone(t);e.kid??=await G({jwk:e});let n=await this.getKeyUri({key:e});return await this._keyStore.set(n,e),n}async sign({keyUri:t,data:e}){let n=await this.getPrivateKey({keyUri:t}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:e,key:n})}async verify({key:t,signature:e,data:n}){let i=this.getAlgorithmName({key:t});return this.getAlgorithm({algorithm:i}).verify({key:t,signature:e,data:n})}getAlgorithm({algorithm:t}){let e=Zs[t]?.implementation;if(!e)throw new Error(`Algorithm not supported: ${t}`);return this._algorithmInstances.has(e)||this._algorithmInstances.set(e,new e),this._algorithmInstances.get(e)}getAlgorithmName({key:t}){let e=t.alg,n=t.crv;for(let i in Zs){let o=Zs[i];if(e&&o.names.includes(e))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${e}, crv=${n}`)}async getPrivateKey({keyUri:t}){let e=await this._keyStore.get(t);if(!e)throw new Error(`Key not found: ${t}`);return e}};var Xu=class r{static getJoseSignatureAlgorithmFromPublicKey(t){let e={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(t.alg&&Object.values(e).includes(t.alg))return t.alg;if(t.crv&&Object.keys(e).includes(t.crv))return e[t.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${t.alg}, crv=${t.crv}. Supported 'alg' values: ${Object.values(e).join(", ")}. Supported 'crv' values: ${Object.keys(e).join(", ")}.`)}static randomBytes(t){return Ou(t)}static randomUuid(){return Se.randomUUID()}static randomPin({length:t}){if(3>t||t>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let e=Math.pow(10,t)-1,n;if(t<=6){let i=Math.pow(10,t);do{let o=r.randomBytes(Math.ceil(t/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>e)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>e)}return n.toString().padStart(t,"0")}};function Ag(r){return r!==null&&typeof r=="object"&&"encrypt"in r&&typeof r.encrypt=="function"&&"decrypt"in r&&typeof r.decrypt=="function"}function Bg(r){return r!==null&&typeof r=="object"&&"exportKey"in r&&typeof r.exportKey=="function"}function Pg(r){return r!==null&&typeof r=="object"&&"importKey"in r&&typeof r.importKey=="function"}function Kg(r){return r!==null&&typeof r=="object"&&"wrapKey"in r&&typeof r.wrapKey=="function"&&"unwrapKey"in r&&typeof r.unwrapKey=="function"}var Kr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ys(r=32){if(Kr&&typeof Kr.getRandomValues=="function")return Kr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function ct(){if(Kr&&typeof Kr.subtle=="object"&&Kr.subtle!=null)return Kr.subtle;throw new Error("crypto.subtle must be defined")}var Vn=128,Qu=[128,192,256],Wi=Vn,en=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==Vn/8)throw new TypeError(`The counter must be ${Vn} bits in length`);if(i===0||i>Wi)throw new TypeError(`The 'length' property must be in the range 1 to ${Wi}`);let o=ct(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["decrypt"]),c=await o.decrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async encrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==Vn/8)throw new TypeError(`The counter must be ${Vn} bits in length`);if(i===0||i>Wi)throw new TypeError(`The 'length' property must be in the range 1 to ${Wi}`);let o=ct(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["encrypt","decrypt"]),c=await o.encrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async generateKey({length:t}){if(!Qu.includes(t))throw new RangeError(`The key length is invalid: Must be ${Qu.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-CTR",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesCtr: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var tf=class extends ut{async decrypt(t){return en.decrypt(t)}async encrypt(t){return en.encrypt(t)}async generateKey({algorithm:t}){let e={A128CTR:128,A192CTR:192,A256CTR:256}[t],n=await en.generateKey({length:e});return n.alg=t,n}};function qn(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Xs(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Qs(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function V(r,...t){if(!Qs(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function ze(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Fn(r,t){V(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var zi=r=>new Uint8Array(r.buffer,r.byteOffset,r.byteLength);var Y=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Ze=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Up=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Up)throw new Error("Non little-endian hardware is not supported");function Ip(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ce(r){if(typeof r=="string")r=Ip(r);else if(Qs(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Zi(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];V(i),t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}function ef(r,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(r,t)}function $n(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var ae=(r,t)=>(Object.assign(t,r),t);function Tr(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var rf={async encrypt(r,t,e,n){let i=ct(),o=await i.importKey("raw",r,t,!0,["encrypt"]),s=await i.encrypt(e,o,n);return new Uint8Array(s)},async decrypt(r,t,e,n){let i=ct(),o=await i.importKey("raw",r,t,!0,["decrypt"]),s=await i.decrypt(e,o,n);return new Uint8Array(s)}},ue={CBC:"AES-CBC",CTR:"AES-CTR",GCM:"AES-GCM"};function Cp(r,t,e){if(r===ue.CBC)return{name:ue.CBC,iv:t};if(r===ue.CTR)return{name:ue.CTR,counter:t,length:64};if(r===ue.GCM)return e?{name:ue.GCM,iv:t,additionalData:e}:{name:ue.GCM,iv:t};throw new Error("unknown aes block mode")}function tc(r){return(t,e,n)=>{V(t),V(e);let i={name:r,length:t.length*8},o=Cp(r,e,n);return{encrypt(s){return V(s),rf.encrypt(t,i,o,s)},decrypt(s){return V(s),rf.decrypt(t,i,o,s)}}}}var Hg=tc(ue.CBC),Jg=tc(ue.CTR),Gg=tc(ue.GCM);var Yi=96,nf=[128,192,256],Xi=[96,104,112,120,128],Ye=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({key:t,data:e,iv:n,additionalData:i,tagLength:o}){if(n.byteLength!==Yi/8)throw new TypeError(`The initialization vector must be ${Yi} bits in length`);if(o&&!Xi.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Xi.join(", ")} bits`);let s=ct(),c=await s.importKey("jwk",t,{name:"AES-GCM"},!0,["decrypt"]),a={name:"AES-GCM",iv:n,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.decrypt(a,c,e);return new Uint8Array(u)}static async encrypt({data:t,iv:e,key:n,additionalData:i,tagLength:o}){if(e.byteLength!==Yi/8)throw new TypeError(`The initialization vector must be ${Yi} bits in length`);if(o&&!Xi.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Xi.join(", ")} bits`);let s=ct(),c=await s.importKey("jwk",n,{name:"AES-GCM"},!0,["encrypt"]),a={name:"AES-GCM",iv:e,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.encrypt(a,c,t);return new Uint8Array(u)}static async generateKey({length:t}){if(!nf.includes(t))throw new RangeError(`The key length is invalid: Must be ${nf.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-GCM",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesGcm: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var of=class extends ut{async bytesToPrivateKey({privateKeyBytes:t}){let e=await Ye.bytesToPrivateKey({privateKeyBytes:t});return e.alg={16:"A128GCM",24:"A192GCM",32:"A256GCM"}[t.length],e}async decrypt(t){return Ye.decrypt(t)}async encrypt(t){return Ye.encrypt(t)}async generateKey({algorithm:t}){let e={A128GCM:128,A192GCM:192,A256GCM:256}[t],n=await Ye.generateKey({length:e});return n.alg=t,n}async privateKeyToBytes({privateKey:t}){return await Ye.privateKeyToBytes({privateKey:t})}};var sf=[128,192,256],Xe=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};e.kid=await G({jwk:e});let n=t.length*8;return e.alg={128:"A128KW",192:"A192KW",256:"A256KW"}[n],e}static async generateKey({length:t}){if(!sf.includes(t))throw new RangeError(`The key length is invalid: Must be ${sf.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-KW",length:t},!0,["wrapKey","unwrapKey"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesKw: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}static async unwrapKey({wrappedKeyBytes:t,wrappedKeyAlgorithm:e,decryptionKey:n}){if(!("alg"in n&&n.alg))throw new nt("invalidJwk","The decryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(n.alg))throw new nt("algorithmNotSupported",`The 'decryptionKey' algorithm is not supported: ${n.alg}`);let i=ct(),o=await i.importKey("jwk",n,{name:"AES-KW"},!0,["unwrapKey"]),s={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[e];if(!s)throw new nt("algorithmNotSupported",`The 'wrappedKeyAlgorithm' is not supported: ${e}`);let c=await i.unwrapKey("raw",t.buffer,o,"AES-KW",{name:s},!0,["unwrapKey"]),{ext:a,key_ops:u,...f}=await i.exportKey("jwk",c),l=f;return l.kid=await G({jwk:l}),l}static async wrapKey({unwrappedKey:t,encryptionKey:e}){if(!("alg"in e&&e.alg))throw new nt("invalidJwk","The encryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(e.alg))throw new nt("algorithmNotSupported",`The 'encryptionKey' algorithm is not supported: ${e.alg}`);if(!("alg"in t&&t.alg))throw new nt("invalidJwk","The private key to wrap is missing the 'alg' property.");let n=ct(),i=await n.importKey("jwk",e,{name:"AES-KW"},!0,["wrapKey"]),o={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[t.alg];if(!o)throw new nt("algorithmNotSupported",`The 'unwrappedKey' algorithm is not supported: ${t.alg}`);let s=await n.importKey("jwk",t,{name:o},!0,["unwrapKey"]),c=await n.wrapKey("raw",s,i,"AES-KW");return new Uint8Array(c)}};var cf=class extends ut{async bytesToPrivateKey({privateKeyBytes:t}){let e=await Xe.bytesToPrivateKey({privateKeyBytes:t});return e.alg={16:"A128KW",24:"A192KW",32:"A256KW"}[t.length],e}async generateKey({algorithm:t}){let e={A128KW:128,A192KW:192,A256KW:256}[t],n=await Xe.generateKey({length:e});return n.alg=t,n}async privateKeyToBytes({privateKey:t}){return await Xe.privateKeyToBytes({privateKey:t})}async unwrapKey(t){return await Xe.unwrapKey(t)}async wrapKey(t){return Xe.wrapKey(t)}};var Qi=class{static async deriveKeyBytes({baseKeyBytes:t,length:e,hash:n,salt:i,info:o=new Uint8Array}){let s=ct(),c=await s.importKey("raw",t,{name:"HKDF"},!1,["deriveBits"]),a=typeof i=="string"?N.string(i).toUint8Array():i,u=typeof o=="string"?N.string(o).toUint8Array():o,f=await s.deriveBits({name:"HKDF",hash:n,salt:a,info:u},c,e);return new Uint8Array(f)}};var af=class extends ut{async deriveKeyBytes({algorithm:t,...e}){let n={"HKDF-256":"SHA-256","HKDF-384":"SHA-384","HKDF-512":"SHA-512"}[t];return await Qi.deriveKeyBytes({...e,hash:n})}};var to=class{static async deriveKey({hash:t,password:e,salt:n,iterations:i,length:o}){let s=await Se.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"]),c=await Se.subtle.deriveBits({name:"PBKDF2",hash:t,salt:n,iterations:i},s,o);return new Uint8Array(c)}static async deriveKeyBytes({baseKeyBytes:t,hash:e,salt:n,iterations:i,length:o}){let s=ct(),c=await s.importKey("raw",t,{name:"PBKDF2"},!1,["deriveBits"]),a=await s.deriveBits({name:"PBKDF2",hash:e,salt:n,iterations:i},c,o);return new Uint8Array(a)}};var uf=class extends ut{async deriveKeyBytes({algorithm:t,...e}){let[,n]=t.split(/[-+]/),i={HS256:"SHA-256",HS384:"SHA-384",HS512:"SHA-512"}[n];return await to.deriveKeyBytes({...e,hash:i})}};var ff=class r{static async deriveKey({keyDataLen:t,fixedInfo:e,sharedSecret:n}){let o=Math.ceil(t/256);if(o!==1)throw new Error(`Concat KDF with ${o} rounds not supported.`);let s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,o);let c=r.computeFixedInfo(e);return kt(Js(s,n,c)).slice(0,t/8)}static computeFixedInfo(t){let e=r.toDataLenData({data:t.algorithmId}),n=r.toDataLenData({data:t.partyUInfo}),i=r.toDataLenData({data:t.partyVInfo}),o=r.toDataLenData({data:t.suppPubInfo,variableLength:!1}),s=r.toDataLenData({data:t.suppPrivInfo});return Js(e,n,i,o,s)}static toDataLenData({data:t,variableLength:e=!0}){let n,i=an(t);if(i==="Undefined")return new Uint8Array(0);if(e){let o=i==="Uint8Array"?t:new N(t,i).toUint8Array(),s=o.length;n=new Uint8Array(4+s),new DataView(n.buffer).setUint32(0,s),n.set(o,4)}else{if(typeof t!="number")throw TypeError("Fixed length input must be a number.");n=new Uint8Array(4),new DataView(n.buffer).setUint32(0,t)}return n}};var ke=16,rc=new Uint8Array(16),fe=Y(rc),_p=225,Lp=(r,t,e,n)=>{let i=n&1;return{s3:e<<31|n>>>1,s2:t<<31|e>>>1,s1:r<<31|t>>>1,s0:r>>>1^_p<<24&-(i&1)}},Jt=r=>(r>>>0&255)<<24|(r>>>8&255)<<16|(r>>>16&255)<<8|r>>>24&255|0;function Op(r){r.reverse();let t=r[15]&1,e=0;for(let n=0;n<r.length;n++){let i=r[n];r[n]=i>>>1|e,e=(i&1)<<7}return r[0]^=-t&225,r}var Rp=r=>r>64*1024?8:r>1024?4:2,eo=class{constructor(t,e){this.blockLen=ke,this.outputLen=ke,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,t=ce(t),V(t,16);let n=Ze(t),i=n.getUint32(0,!1),o=n.getUint32(4,!1),s=n.getUint32(8,!1),c=n.getUint32(12,!1),a=[];for(let p=0;p<128;p++)a.push({s0:Jt(i),s1:Jt(o),s2:Jt(s),s3:Jt(c)}),{s0:i,s1:o,s2:s,s3:c}=Lp(i,o,s,c);let u=Rp(e||1024);if(![1,2,4,8].includes(u))throw new Error(`ghash: wrong window size=${u}, should be 2, 4 or 8`);this.W=u;let l=128/u,y=this.windowSize=2**u,m=[];for(let p=0;p<l;p++)for(let h=0;h<y;h++){let d=0,g=0,b=0,x=0;for(let A=0;A<u;A++){if(!(h>>>u-A-1&1))continue;let{s0:K,s1:k,s2:T,s3:L}=a[u*p+A];d^=K,g^=k,b^=T,x^=L}m.push({s0:d,s1:g,s2:b,s3:x})}this.t=m}_updateBlock(t,e,n,i){t^=this.s0,e^=this.s1,n^=this.s2,i^=this.s3;let{W:o,t:s,windowSize:c}=this,a=0,u=0,f=0,l=0,y=(1<<o)-1,m=0;for(let p of[t,e,n,i])for(let h=0;h<4;h++){let d=p>>>8*h&255;for(let g=8/o-1;g>=0;g--){let b=d>>>o*g&y,{s0:x,s1:A,s2:v,s3:K}=s[m*c+b];a^=x,u^=A,f^=v,l^=K,m+=1}}this.s0=a,this.s1=u,this.s2=f,this.s3=l}update(t){t=ce(t),ze(this);let e=Y(t),n=Math.floor(t.length/ke),i=t.length%ke;for(let o=0;o<n;o++)this._updateBlock(e[o*4+0],e[o*4+1],e[o*4+2],e[o*4+3]);return i&&(rc.set(t.subarray(n*ke)),this._updateBlock(fe[0],fe[1],fe[2],fe[3]),fe.fill(0)),this}destroy(){let{t}=this;for(let e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{s0:e,s1:n,s2:i,s3:o}=this,s=Y(t);return s[0]=e,s[1]=n,s[2]=i,s[3]=o,t}digest(){let t=new Uint8Array(ke);return this.digestInto(t),this.destroy(),t}},ec=class extends eo{constructor(t,e){t=ce(t);let n=Op(t.slice());super(n,e),n.fill(0)}update(t){t=ce(t),ze(this);let e=Y(t),n=t.length%ke,i=Math.floor(t.length/ke);for(let o=0;o<i;o++)this._updateBlock(Jt(e[o*4+3]),Jt(e[o*4+2]),Jt(e[o*4+1]),Jt(e[o*4+0]));return n&&(rc.set(t.subarray(i*ke)),this._updateBlock(Jt(fe[3]),Jt(fe[2]),Jt(fe[1]),Jt(fe[0])),fe.fill(0)),this}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{s0:e,s1:n,s2:i,s3:o}=this,s=Y(t);return s[0]=e,s[1]=n,s[2]=i,s[3]=o,t.reverse()}};function lf(r){let t=(n,i)=>r(i,n.length).update(ce(n)).digest(),e=r(new Uint8Array(16),0);return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=(n,i)=>r(n,i),t}var nc=lf((r,t)=>new eo(r,t)),hf=lf((r,t)=>new ec(r,t));var Et=16,sc=4,ro=new Uint8Array(Et),Np=283;function cc(r){return r<<1^Np&-(r>>7)}function rn(r,t){let e=0;for(;t>0;t>>=1)e^=r&-(t&1),r=cc(r);return e}var oc=(()=>{let r=new Uint8Array(256);for(let e=0,n=1;e<256;e++,n^=cc(n))r[e]=n;let t=new Uint8Array(256);t[0]=99;for(let e=0;e<255;e++){let n=r[255-e];n|=n<<8,t[r[e]]=(n^n>>4^n>>5^n>>6^n>>7^99)&255}return t})(),Dp=oc.map((r,t)=>oc.indexOf(t)),Mp=r=>r<<24|r>>>8,ic=r=>r<<8|r>>>24;function yf(r,t){if(r.length!==256)throw new Error("Wrong sbox length");let e=new Uint32Array(256).map((u,f)=>t(r[f])),n=e.map(ic),i=n.map(ic),o=i.map(ic),s=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let u=0;u<256;u++)for(let f=0;f<256;f++){let l=u*256+f;s[l]=e[u]^n[f],c[l]=i[u]^o[f],a[l]=r[u]<<8|r[f]}return{sbox:r,sbox2:a,T0:e,T1:n,T2:i,T3:o,T01:s,T23:c}}var ac=yf(oc,r=>rn(r,3)<<24|r<<16|r<<8|rn(r,2)),pf=yf(Dp,r=>rn(r,11)<<24|rn(r,13)<<16|rn(r,9)<<8|rn(r,14)),jp=(()=>{let r=new Uint8Array(16);for(let t=0,e=1;t<16;t++,e=cc(e))r[t]=e;return r})();function tr(r){V(r);let t=r.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);let{sbox2:e}=ac,n=Y(r),i=n.length,o=c=>le(e,c,c,c,c),s=new Uint32Array(t+28);s.set(n);for(let c=i;c<s.length;c++){let a=s[c-1];c%i===0?a=o(Mp(a))^jp[c/i-1]:i>6&&c%i===4&&(a=o(a)),s[c]=s[c-i]^a}return s}function df(r){let t=tr(r),e=t.slice(),n=t.length,{sbox2:i}=ac,{T0:o,T1:s,T2:c,T3:a}=pf;for(let u=0;u<n;u+=4)for(let f=0;f<4;f++)e[u+f]=t[n-u-4+f];t.fill(0);for(let u=4;u<n-4;u++){let f=e[u],l=le(i,f,f,f,f);e[u]=o[l&255]^s[l>>>8&255]^c[l>>>16&255]^a[l>>>24]}return e}function Qe(r,t,e,n,i,o){return r[e<<8&65280|n>>>8&255]^t[i>>>8&65280|o>>>24&255]}function le(r,t,e,n,i){return r[t&255|e&65280]|r[n>>>16&255|i>>>16&65280]<<16}function Gt(r,t,e,n,i){let{sbox2:o,T01:s,T23:c}=ac,a=0;t^=r[a++],e^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let h=r[a++]^Qe(s,c,t,e,n,i),d=r[a++]^Qe(s,c,e,n,i,t),g=r[a++]^Qe(s,c,n,i,t,e),b=r[a++]^Qe(s,c,i,t,e,n);t=h,e=d,n=g,i=b}let f=r[a++]^le(o,t,e,n,i),l=r[a++]^le(o,e,n,i,t),y=r[a++]^le(o,n,i,t,e),m=r[a++]^le(o,i,t,e,n);return{s0:f,s1:l,s2:y,s3:m}}function mf(r,t,e,n,i){let{sbox2:o,T01:s,T23:c}=pf,a=0;t^=r[a++],e^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let h=r[a++]^Qe(s,c,t,i,n,e),d=r[a++]^Qe(s,c,e,t,i,n),g=r[a++]^Qe(s,c,n,e,t,i),b=r[a++]^Qe(s,c,i,n,e,t);t=h,e=d,n=g,i=b}let f=r[a++]^le(o,t,i,n,e),l=r[a++]^le(o,e,t,i,n),y=r[a++]^le(o,n,e,t,i),m=r[a++]^le(o,i,n,e,t);return{s0:f,s1:l,s2:y,s3:m}}function nn(r,t){if(!t)return new Uint8Array(r);if(V(t),t.length<r)throw new Error(`aes: wrong destination length, expected at least ${r}, got: ${t.length}`);return t}function Hp(r,t,e,n){V(t,Et),V(e);let i=e.length;n=nn(i,n);let o=t,s=Y(o),{s0:c,s1:a,s2:u,s3:f}=Gt(r,s[0],s[1],s[2],s[3]),l=Y(e),y=Y(n);for(let p=0;p+4<=l.length;p+=4){y[p+0]=l[p+0]^c,y[p+1]=l[p+1]^a,y[p+2]=l[p+2]^u,y[p+3]=l[p+3]^f;let h=1;for(let d=o.length-1;d>=0;d--)h=h+(o[d]&255)|0,o[d]=h&255,h>>>=8;({s0:c,s1:a,s2:u,s3:f}=Gt(r,s[0],s[1],s[2],s[3]))}let m=Et*Math.floor(l.length/sc);if(m<i){let p=new Uint32Array([c,a,u,f]),h=zi(p);for(let d=m,g=0;d<i;d++,g++)n[d]=e[d]^h[g]}return n}function Wn(r,t,e,n,i){V(e,Et),V(n),i=nn(n.length,i);let o=e,s=Y(o),c=Ze(o),a=Y(n),u=Y(i),f=t?0:12,l=n.length,y=c.getUint32(f,t),{s0:m,s1:p,s2:h,s3:d}=Gt(r,s[0],s[1],s[2],s[3]);for(let b=0;b+4<=a.length;b+=4)u[b+0]=a[b+0]^m,u[b+1]=a[b+1]^p,u[b+2]=a[b+2]^h,u[b+3]=a[b+3]^d,y=y+1>>>0,c.setUint32(f,y,t),{s0:m,s1:p,s2:h,s3:d}=Gt(r,s[0],s[1],s[2],s[3]);let g=Et*Math.floor(a.length/sc);if(g<l){let b=new Uint32Array([m,p,h,d]),x=zi(b);for(let A=g,v=0;A<l;A++,v++)i[A]=n[A]^x[v]}return i}var Sx=ae({blockSize:16,nonceLength:16},function(t,e){V(t),V(e,Et);function n(i,o){let s=tr(t),c=e.slice(),a=Hp(s,c,i,o);return s.fill(0),c.fill(0),a}return{encrypt:(i,o)=>n(i,o),decrypt:(i,o)=>n(i,o)}});function wf(r){if(V(r),r.length%Et!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Et}`)}function gf(r,t,e){let n=r.length,i=n%Et;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");let o=Y(r);if(t){let a=Et-i;a||(a=Et),n=n+a}let s=nn(n,e),c=Y(s);return{b:o,o:c,out:s}}function xf(r,t){if(!t)return r;let e=r.length;if(!e)throw new Error("aes/pcks5: empty ciphertext not allowed");let n=r[e-1];if(n<=0||n>16)throw new Error(`aes/pcks5: wrong padding byte: ${n}`);let i=r.subarray(0,-n);for(let o=0;o<n;o++)if(r[e-o-1]!==n)throw new Error("aes/pcks5: wrong padding");return i}function bf(r){let t=new Uint8Array(16),e=Y(t);t.set(r);let n=Et-r.length;for(let i=Et-n;i<Et;i++)t[i]=n;return e}var kx=ae({blockSize:16},function(t,e={}){V(t);let n=!e.disablePadding;return{encrypt:(i,o)=>{V(i);let{b:s,o:c,out:a}=gf(i,n,o),u=tr(t),f=0;for(;f+4<=s.length;){let{s0:l,s1:y,s2:m,s3:p}=Gt(u,s[f+0],s[f+1],s[f+2],s[f+3]);c[f++]=l,c[f++]=y,c[f++]=m,c[f++]=p}if(n){let l=bf(i.subarray(f*4)),{s0:y,s1:m,s2:p,s3:h}=Gt(u,l[0],l[1],l[2],l[3]);c[f++]=y,c[f++]=m,c[f++]=p,c[f++]=h}return u.fill(0),a},decrypt:(i,o)=>{wf(i);let s=df(t),c=nn(i.length,o),a=Y(i),u=Y(c);for(let f=0;f+4<=a.length;){let{s0:l,s1:y,s2:m,s3:p}=mf(s,a[f+0],a[f+1],a[f+2],a[f+3]);u[f++]=l,u[f++]=y,u[f++]=m,u[f++]=p}return s.fill(0),xf(c,n)}}}),Ux=ae({blockSize:16,nonceLength:16},function(t,e,n={}){V(t),V(e,16);let i=!n.disablePadding;return{encrypt:(o,s)=>{let c=tr(t),{b:a,o:u,out:f}=gf(o,i,s),l=Y(e),y=l[0],m=l[1],p=l[2],h=l[3],d=0;for(;d+4<=a.length;)y^=a[d+0],m^=a[d+1],p^=a[d+2],h^=a[d+3],{s0:y,s1:m,s2:p,s3:h}=Gt(c,y,m,p,h),u[d++]=y,u[d++]=m,u[d++]=p,u[d++]=h;if(i){let g=bf(o.subarray(d*4));y^=g[0],m^=g[1],p^=g[2],h^=g[3],{s0:y,s1:m,s2:p,s3:h}=Gt(c,y,m,p,h),u[d++]=y,u[d++]=m,u[d++]=p,u[d++]=h}return c.fill(0),f},decrypt:(o,s)=>{wf(o);let c=df(t),a=Y(e),u=nn(o.length,s),f=Y(o),l=Y(u),y=a[0],m=a[1],p=a[2],h=a[3];for(let d=0;d+4<=f.length;){let g=y,b=m,x=p,A=h;y=f[d+0],m=f[d+1],p=f[d+2],h=f[d+3];let{s0:v,s1:K,s2:k,s3:T}=mf(c,y,m,p,h);l[d++]=v^g,l[d++]=K^b,l[d++]=k^x,l[d++]=T^A}return c.fill(0),xf(u,i)}}}),Ix=ae({blockSize:16,nonceLength:16},function(t,e){V(t),V(e,16);function n(i,o,s){let c=tr(t),a=i.length;s=nn(a,s);let u=Y(i),f=Y(s),l=o?f:u,y=Y(e),m=y[0],p=y[1],h=y[2],d=y[3];for(let b=0;b+4<=u.length;){let{s0:x,s1:A,s2:v,s3:K}=Gt(c,m,p,h,d);f[b+0]=u[b+0]^x,f[b+1]=u[b+1]^A,f[b+2]=u[b+2]^v,f[b+3]=u[b+3]^K,m=l[b++],p=l[b++],h=l[b++],d=l[b++]}let g=Et*Math.floor(u.length/sc);if(g<a){({s0:m,s1:p,s2:h,s3:d}=Gt(c,m,p,h,d));let b=zi(new Uint32Array([m,p,h,d]));for(let x=g,A=0;x<a;x++,A++)s[x]=i[x]^b[A];b.fill(0)}return c.fill(0),s}return{encrypt:(i,o)=>n(i,!0,o),decrypt:(i,o)=>n(i,!1,o)}});function Ef(r,t,e,n,i){let o=r.create(e,n.length+(i?.length||0));i&&o.update(i),o.update(n);let s=new Uint8Array(16),c=Ze(s);return i&&Tr(c,0,BigInt(i.length*8),t),Tr(c,8,BigInt(n.length*8),t),o.update(s),o.digest()}var uc=ae({blockSize:16,nonceLength:12,tagLength:16},function(t,e,n){if(V(e),e.length===0)throw new Error("aes/gcm: empty nonce");let i=16;function o(c,a,u){let f=Ef(nc,!1,c,u,n);for(let l=0;l<a.length;l++)f[l]^=a[l];return f}function s(){let c=tr(t),a=ro.slice(),u=ro.slice();if(Wn(c,!1,u,u,a),e.length===12)u.set(e);else{let l=ro.slice(),y=Ze(l);Tr(y,8,BigInt(e.length*8),!1),nc.create(a).update(e).update(l).digestInto(u)}let f=Wn(c,!1,u,ro);return{xk:c,authKey:a,counter:u,tagMask:f}}return{encrypt:c=>{V(c);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),y=new Uint8Array(c.length+i);Wn(a,!1,f,c,y);let m=o(u,l,y.subarray(0,y.length-i));return y.set(m,c.length),a.fill(0),y},decrypt:c=>{if(V(c),c.length<i)throw new Error(`aes/gcm: ciphertext less than tagLen (${i})`);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),y=c.subarray(0,-i),m=c.subarray(-i),p=o(u,l,y);if(!$n(p,m))throw new Error("aes/gcm: invalid ghash tag");let h=Wn(a,!1,f,y);return u.fill(0),l.fill(0),a.fill(0),h}}}),no=(r,t,e)=>n=>{if(!Number.isSafeInteger(n)||t>n||n>e)throw new Error(`${r}: invalid value=${n}, must be [${t}..${e}]`)},Cx=ae({blockSize:16,nonceLength:12,tagLength:16},function(t,e,n){let o=no("AAD",0,68719476736),s=no("plaintext",0,2**36),c=no("nonce",12,12),a=no("ciphertext",16,2**36+16);V(e),c(e.length),n&&(V(n),o(n.length));function u(){let y=t.length;if(y!==16&&y!==24&&y!==32)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${y} bytes`);let m=tr(t),p=new Uint8Array(y),h=new Uint8Array(16),d=Y(e),g=0,b=d[0],x=d[1],A=d[2],v=0;for(let K of[h,p].map(Y)){let k=Y(K);for(let T=0;T<k.length;T+=2){let{s0:L,s1:O}=Gt(m,g,b,x,A);k[T+0]=L,k[T+1]=O,g=++v}}return m.fill(0),{authKey:h,encKey:tr(p)}}function f(y,m,p){let h=Ef(hf,!0,m,p,n);for(let v=0;v<12;v++)h[v]^=e[v];h[15]&=127;let d=Y(h),g=d[0],b=d[1],x=d[2],A=d[3];return{s0:g,s1:b,s2:x,s3:A}=Gt(y,g,b,x,A),d[0]=g,d[1]=b,d[2]=x,d[3]=A,h}function l(y,m,p){let h=m.slice();return h[15]|=128,Wn(y,!0,h,p)}return{encrypt:y=>{V(y),s(y.length);let{encKey:m,authKey:p}=u(),h=f(m,p,y),d=new Uint8Array(y.length+16);return d.set(h,y.length),d.set(l(m,h,y)),m.fill(0),p.fill(0),d},decrypt:y=>{V(y),a(y.length);let m=y.subarray(-16),{encKey:p,authKey:h}=u(),d=l(p,m,y.subarray(0,-16)),g=f(p,h,d);if(p.fill(0),h.fill(0),!$n(m,g))throw new Error("invalid polyval tag");return d}}});var io=class extends Yr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Mn(t);let n=Je(e);if(this.iHash=t.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?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return Zr(this),this.iHash.update(t),this}digestInto(t){Zr(this),zr(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},oo=(r,t,e)=>new io(r,t).update(e).digest();oo.create=(r,t)=>new io(r,t);function Jp(r,t,e){return Mn(r),e===void 0&&(e=new Uint8Array(r.outputLen)),oo(r,Je(e),Je(t))}var fc=new Uint8Array([0]),vf=new Uint8Array;function Gp(r,t,e,n=32){if(Mn(r),Mi(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/r.outputLen);e===void 0&&(e=vf);let o=new Uint8Array(i*r.outputLen),s=oo.create(r,t),c=s._cloneInto(),a=new Uint8Array(s.outputLen);for(let u=0;u<i;u++)fc[0]=u+1,c.update(u===0?vf:a).update(e).update(fc).digestInto(a),o.set(a,r.outputLen*u),s._cloneInto(c);return s.destroy(),c.destroy(),a.fill(0),fc.fill(0),o.slice(0,n)}var lc=(r,t,e,n,i)=>Gp(r,Jp(r,t,e),n,i);var Af=16,Vp=16,Bf=class{static encrypt(t,e){let n=at.utils.randomPrivateKey(),i=at.getPublicKey(n,!0),o=at.getPublicKey(n,!1),s=at.getSharedSecret(n,t,!1),c=lc(kt,Zi(o,s),void 0,void 0,32),a=Ys(Vp),u=uc(c,a).encrypt(e);return{ephemeralPublicKey:i,initializationVector:a,messageAuthenticationCode:u.subarray(u.length-Af),ciphertext:u.subarray(0,u.length-Af)}}static decrypt(t){let{privateKey:e,ephemeralPublicKey:n,initializationVector:i,messageAuthenticationCode:o,ciphertext:s}=t,c=at.ProjectivePoint.fromHex(n).toRawBytes(!1),a=at.getSharedSecret(e,n,!1),u=lc(kt,Zi(c,a),void 0,void 0,32),f=Zi(s,o);return uc(u,Uint8Array.from(i)).decrypt(f)}static get isEphemeralKeyCompressed(){return!0}};var dt=(r,t)=>r[t++]&255|(r[t++]&255)<<8,hc=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=ce(t),V(t,32);let e=dt(t,0),n=dt(t,2),i=dt(t,4),o=dt(t,6),s=dt(t,8),c=dt(t,10),a=dt(t,12),u=dt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=dt(t,16+2*f)}process(t,e,n=!1){let i=n?0:2048,{h:o,r:s}=this,c=s[0],a=s[1],u=s[2],f=s[3],l=s[4],y=s[5],m=s[6],p=s[7],h=s[8],d=s[9],g=dt(t,e+0),b=dt(t,e+2),x=dt(t,e+4),A=dt(t,e+6),v=dt(t,e+8),K=dt(t,e+10),k=dt(t,e+12),T=dt(t,e+14),L=o[0]+(g&8191),O=o[1]+((g>>>13|b<<3)&8191),C=o[2]+((b>>>10|x<<6)&8191),j=o[3]+((x>>>7|A<<9)&8191),M=o[4]+((A>>>4|v<<12)&8191),z=o[5]+(v>>>1&8191),B=o[6]+((v>>>14|K<<2)&8191),U=o[7]+((K>>>11|k<<5)&8191),R=o[8]+((k>>>8|T<<8)&8191),P=o[9]+(T>>>5|i),w=0,S=w+L*c+O*(5*d)+C*(5*h)+j*(5*p)+M*(5*m);w=S>>>13,S&=8191,S+=z*(5*y)+B*(5*l)+U*(5*f)+R*(5*u)+P*(5*a),w+=S>>>13,S&=8191;let I=w+L*a+O*c+C*(5*d)+j*(5*h)+M*(5*p);w=I>>>13,I&=8191,I+=z*(5*m)+B*(5*y)+U*(5*l)+R*(5*f)+P*(5*u),w+=I>>>13,I&=8191;let _=w+L*u+O*a+C*c+j*(5*d)+M*(5*h);w=_>>>13,_&=8191,_+=z*(5*p)+B*(5*m)+U*(5*y)+R*(5*l)+P*(5*f),w+=_>>>13,_&=8191;let H=w+L*f+O*u+C*a+j*c+M*(5*d);w=H>>>13,H&=8191,H+=z*(5*h)+B*(5*p)+U*(5*m)+R*(5*y)+P*(5*l),w+=H>>>13,H&=8191;let J=w+L*l+O*f+C*u+j*a+M*c;w=J>>>13,J&=8191,J+=z*(5*d)+B*(5*h)+U*(5*p)+R*(5*m)+P*(5*y),w+=J>>>13,J&=8191;let Z=w+L*y+O*l+C*f+j*u+M*a;w=Z>>>13,Z&=8191,Z+=z*c+B*(5*d)+U*(5*h)+R*(5*p)+P*(5*m),w+=Z>>>13,Z&=8191;let q=w+L*m+O*y+C*l+j*f+M*u;w=q>>>13,q&=8191,q+=z*a+B*c+U*(5*d)+R*(5*h)+P*(5*p),w+=q>>>13,q&=8191;let F=w+L*p+O*m+C*y+j*l+M*f;w=F>>>13,F&=8191,F+=z*u+B*a+U*c+R*(5*d)+P*(5*h),w+=F>>>13,F&=8191;let rt=w+L*h+O*p+C*m+j*y+M*l;w=rt>>>13,rt&=8191,rt+=z*f+B*u+U*a+R*c+P*(5*d),w+=rt>>>13,rt&=8191;let et=w+L*d+O*h+C*p+j*m+M*y;w=et>>>13,et&=8191,et+=z*l+B*f+U*u+R*a+P*c,w+=et>>>13,et&=8191,w=(w<<2)+w|0,w=w+S|0,S=w&8191,w=w>>>13,I+=w,o[0]=S,o[1]=I,o[2]=_,o[3]=H,o[4]=J,o[5]=Z,o[6]=q,o[7]=F,o[8]=rt,o[9]=et}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),i=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=i,i=t[c]>>>13,t[c]&=8191;t[0]+=i*5,i=t[0]>>>13,t[0]&=8191,t[1]+=i,i=t[1]>>>13,t[1]&=8191,t[2]+=i,n[0]=t[0]+5,i=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+i,i=n[c]>>>13,n[c]&=8191;n[9]-=8192;let o=(i^1)-1;for(let c=0;c<10;c++)n[c]&=o;o=~o;for(let c=0;c<10;c++)t[c]=t[c]&o|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let s=t[0]+e[0];t[0]=s&65535;for(let c=1;c<8;c++)s=(t[c]+e[c]|0)+(s>>>16)|0,t[c]=s&65535}update(t){ze(this);let{buffer:e,blockLen:n}=this;t=ce(t);let i=t.length;for(let o=0;o<i;){let s=Math.min(n-this.pos,i-o);if(s===n){for(;n<=i-o;o+=n)this.process(t,o);continue}e.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:i}=this;if(i){for(e[i++]=1;i<16;i++)e[i]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)t[o++]=n[s]>>>0,t[o++]=n[s]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function qp(r){let t=(n,i)=>r(i).update(ce(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var Pf=qp(r=>new hc(r));var Tf=r=>Uint8Array.from(r.split("").map(t=>t.charCodeAt(0))),Fp=Tf("expand 16-byte k"),$p=Tf("expand 32-byte k"),Wp=Y(Fp),Sf=Y($p),Qx=Sf.slice();function D(r,t){return r<<t|r>>>32-t}function yc(r){return r.byteOffset%4===0}var so=64,zp=16,kf=2**32-1,Kf=new Uint32Array;function Zp(r,t,e,n,i,o,s,c){let a=i.length,u=new Uint8Array(so),f=Y(u),l=yc(i)&&yc(o),y=l?Y(i):Kf,m=l?Y(o):Kf;for(let p=0;p<a;s++){if(r(t,e,n,f,s,c),s>=kf)throw new Error("arx: counter overflow");let h=Math.min(so,a-p);if(l&&h===so){let d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let g=0,b;g<zp;g++)b=d+g,m[b]=y[b]^f[g];p+=so;continue}for(let d=0,g;d<h;d++)g=p+d,o[g]=i[g]^u[d];p+=h}}function pc(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=ef({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return qn(i),qn(s),Xs(o),Xs(e),(c,a,u,f,l=0)=>{V(c),V(a),V(u);let y=u.length;if(f||(f=new Uint8Array(y)),V(f),qn(l),l<0||l>=kf)throw new Error("arx: counter overflow");if(f.length<y)throw new Error(`arx: output (${f.length}) is shorter than data (${y})`);let m=[],p=c.length,h,d;if(p===32)h=c.slice(),m.push(h),d=Sf;else if(p===16&&e)h=new Uint8Array(32),h.set(c),h.set(c,16),d=Wp,m.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);yc(a)||(a=a.slice(),m.push(a));let g=Y(h);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,g,Y(a.subarray(0,16)),g),a=a.subarray(16)}let b=16-i;if(b!==a.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){let A=new Uint8Array(12);A.set(a,o?0:12-a.length),a=A,m.push(a)}let x=Y(a);for(Zp(r,d,g,x,u,f,l,s);m.length>0;)m.pop().fill(0);return f}}function Cf(r,t,e,n,i,o=20){let s=r[0],c=r[1],a=r[2],u=r[3],f=t[0],l=t[1],y=t[2],m=t[3],p=t[4],h=t[5],d=t[6],g=t[7],b=i,x=e[0],A=e[1],v=e[2],K=s,k=c,T=a,L=u,O=f,C=l,j=y,M=m,z=p,B=h,U=d,R=g,P=b,w=x,S=A,I=v;for(let H=0;H<o;H+=2)K=K+O|0,P=D(P^K,16),z=z+P|0,O=D(O^z,12),K=K+O|0,P=D(P^K,8),z=z+P|0,O=D(O^z,7),k=k+C|0,w=D(w^k,16),B=B+w|0,C=D(C^B,12),k=k+C|0,w=D(w^k,8),B=B+w|0,C=D(C^B,7),T=T+j|0,S=D(S^T,16),U=U+S|0,j=D(j^U,12),T=T+j|0,S=D(S^T,8),U=U+S|0,j=D(j^U,7),L=L+M|0,I=D(I^L,16),R=R+I|0,M=D(M^R,12),L=L+M|0,I=D(I^L,8),R=R+I|0,M=D(M^R,7),K=K+C|0,I=D(I^K,16),U=U+I|0,C=D(C^U,12),K=K+C|0,I=D(I^K,8),U=U+I|0,C=D(C^U,7),k=k+j|0,P=D(P^k,16),R=R+P|0,j=D(j^R,12),k=k+j|0,P=D(P^k,8),R=R+P|0,j=D(j^R,7),T=T+M|0,w=D(w^T,16),z=z+w|0,M=D(M^z,12),T=T+M|0,w=D(w^T,8),z=z+w|0,M=D(M^z,7),L=L+O|0,S=D(S^L,16),B=B+S|0,O=D(O^B,12),L=L+O|0,S=D(S^L,8),B=B+S|0,O=D(O^B,7);let _=0;n[_++]=s+K|0,n[_++]=c+k|0,n[_++]=a+T|0,n[_++]=u+L|0,n[_++]=f+O|0,n[_++]=l+C|0,n[_++]=y+j|0,n[_++]=m+M|0,n[_++]=p+z|0,n[_++]=h+B|0,n[_++]=d+U|0,n[_++]=g+R|0,n[_++]=b+P|0,n[_++]=x+w|0,n[_++]=A+S|0,n[_++]=v+I|0}function Yp(r,t,e,n){let i=r[0],o=r[1],s=r[2],c=r[3],a=t[0],u=t[1],f=t[2],l=t[3],y=t[4],m=t[5],p=t[6],h=t[7],d=e[0],g=e[1],b=e[2],x=e[3];for(let v=0;v<20;v+=2)i=i+a|0,d=D(d^i,16),y=y+d|0,a=D(a^y,12),i=i+a|0,d=D(d^i,8),y=y+d|0,a=D(a^y,7),o=o+u|0,g=D(g^o,16),m=m+g|0,u=D(u^m,12),o=o+u|0,g=D(g^o,8),m=m+g|0,u=D(u^m,7),s=s+f|0,b=D(b^s,16),p=p+b|0,f=D(f^p,12),s=s+f|0,b=D(b^s,8),p=p+b|0,f=D(f^p,7),c=c+l|0,x=D(x^c,16),h=h+x|0,l=D(l^h,12),c=c+l|0,x=D(x^c,8),h=h+x|0,l=D(l^h,7),i=i+u|0,x=D(x^i,16),p=p+x|0,u=D(u^p,12),i=i+u|0,x=D(x^i,8),p=p+x|0,u=D(u^p,7),o=o+f|0,d=D(d^o,16),h=h+d|0,f=D(f^h,12),o=o+f|0,d=D(d^o,8),h=h+d|0,f=D(f^h,7),s=s+l|0,g=D(g^s,16),y=y+g|0,l=D(l^y,12),s=s+l|0,g=D(g^s,8),y=y+g|0,l=D(l^y,7),c=c+a|0,b=D(b^c,16),m=m+b|0,a=D(a^m,12),c=c+a|0,b=D(b^c,8),m=m+b|0,a=D(a^m,7);let A=0;n[A++]=i,n[A++]=o,n[A++]=s,n[A++]=c,n[A++]=d,n[A++]=g,n[A++]=b,n[A++]=x}var Xp=pc(Cf,{counterRight:!1,counterLength:4,allowShortKeys:!1}),co=pc(Cf,{counterRight:!1,counterLength:8,extendNonceFn:Yp,allowShortKeys:!1});var Qp=new Uint8Array(16),Uf=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(Qp.subarray(e))},td=new Uint8Array(32);function If(r,t,e,n,i){let o=r(t,e,td),s=Pf.create(o);i&&Uf(s,i),Uf(s,n);let c=new Uint8Array(16),a=Ze(c);Tr(a,0,BigInt(i?i.length:0),!0),Tr(a,8,BigInt(n.length),!0),s.update(c);let u=s.digest();return o.fill(0),u}var _f=r=>(t,e,n)=>(V(t,32),V(e),{encrypt:(o,s)=>{let c=o.length,a=c+16;s?V(s,a):s=new Uint8Array(a),r(t,e,o,s,1);let u=If(r,t,e,s.subarray(0,-16),n);return s.set(u,c),s},decrypt:(o,s)=>{let c=o.length,a=c-16;if(c<16)throw new Error("encrypted data must be at least 16 bytes");s?V(s,a):s=new Uint8Array(a);let u=o.subarray(0,-16),f=o.subarray(-16),l=If(r,t,e,u,n);if(!$n(f,l))throw new Error("invalid tag");return r(t,e,u,s,1),s}}),ob=ae({blockSize:64,nonceLength:12,tagLength:16},_f(Xp)),dc=ae({blockSize:64,nonceLength:24,tagLength:16},_f(co));var Lf=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return co(i,n,t)}static async encrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return co(i,n,t)}static async generateKey(){let t=ct(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("XChaCha20: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var mb=16,Of=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.decryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async decryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return dc(e,n,i).decrypt(t)}static async encrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.encryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async encryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return dc(e,n,i).encrypt(t)}static async generateKey(){let t=ct(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("XChaCha20Poly1305: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};export{Xi as AES_GCM_TAG_LENGTHS,en as AesCtr,tf as AesCtrAlgorithm,Ye as AesGcm,of as AesGcmAlgorithm,Xe as AesKw,cf as AesKwAlgorithm,ff as ConcatKdf,ut as CryptoAlgorithm,nt as CryptoError,sn as CryptoErrorCode,Xu as CryptoUtils,jn as EcdsaAlgorithm,Bf as EciesSecp256k1,Ht as Ed25519,qi as EdDsaAlgorithm,Qi as Hkdf,af as HkdfAlgorithm,Vs as KEY_URI_PREFIX_JWK,Yu as LocalKeyManager,Mt as P256,mb as POLY1305_TAG_LENGTH,to as Pbkdf2,uf as Pbkdf2Algorithm,Dt as Secp256k1,Mt as Secp256r1,Xr as Sha256,Fi as Sha2Algorithm,We as X25519,$i as X25519Algorithm,Lf as XChaCha20,Of as XChaCha20Poly1305,Du as canonicalize,G as computeJwkThumbprint,Ag as isCipher,oe as isEcPrivateJwk,Qr as isEcPublicJwk,Bg as isKeyExporter,Pg as isKeyImporter,Kg as isKeyWrapper,se as isOctPrivateJwk,Ut as isOkpPrivateJwk,tn as isOkpPublicJwk,Mu as isPrivateJwk,Fm as isPublicJwk};
2
2
  /*! Bundled license information:
3
3
 
4
4
  ieee754/index.js: