@enbox/crypto 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/algorithms/aes-ctr.js +1 -1
- package/dist/esm/algorithms/aes-gcm.js +34 -1
- package/dist/esm/algorithms/aes-gcm.js.map +1 -1
- package/dist/esm/algorithms/aes-kw.js +154 -0
- package/dist/esm/algorithms/aes-kw.js.map +1 -0
- package/dist/esm/algorithms/ecdsa.js +110 -1
- package/dist/esm/algorithms/ecdsa.js.map +1 -1
- package/dist/esm/algorithms/eddsa.js +90 -1
- package/dist/esm/algorithms/eddsa.js.map +1 -1
- package/dist/esm/algorithms/hkdf.js +53 -0
- package/dist/esm/algorithms/hkdf.js.map +1 -0
- package/dist/esm/algorithms/pbkdf2.js +55 -0
- package/dist/esm/algorithms/pbkdf2.js.map +1 -0
- package/dist/esm/algorithms/sha-2.js +1 -1
- package/dist/esm/algorithms/x25519.js +125 -0
- package/dist/esm/algorithms/x25519.js.map +1 -0
- package/dist/esm/cose/cbor.js +35 -0
- package/dist/esm/cose/cbor.js.map +1 -0
- package/dist/esm/cose/cose-key.js +312 -0
- package/dist/esm/cose/cose-key.js.map +1 -0
- package/dist/esm/cose/cose-sign1.js +283 -0
- package/dist/esm/cose/cose-sign1.js.map +1 -0
- package/dist/esm/cose/eat.js +254 -0
- package/dist/esm/cose/eat.js.map +1 -0
- package/dist/esm/crypto-error.js +4 -0
- package/dist/esm/crypto-error.js.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/local-key-manager.js +6 -1
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/primitives/ecies-secp256k1.js +79 -0
- package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
- package/dist/esm/primitives/x25519.js +9 -16
- package/dist/esm/primitives/x25519.js.map +1 -1
- package/dist/esm/utils.js +30 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/algorithms/aes-ctr.d.ts +1 -1
- package/dist/types/algorithms/aes-gcm.d.ts +23 -3
- package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
- package/dist/types/algorithms/aes-kw.d.ts +129 -0
- package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
- package/dist/types/algorithms/ecdsa.d.ts +48 -3
- package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
- package/dist/types/algorithms/eddsa.d.ts +48 -3
- package/dist/types/algorithms/eddsa.d.ts.map +1 -1
- package/dist/types/algorithms/hkdf.d.ts +35 -0
- package/dist/types/algorithms/hkdf.d.ts.map +1 -0
- package/dist/types/algorithms/pbkdf2.d.ts +35 -0
- package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
- package/dist/types/algorithms/sha-2.d.ts +1 -1
- package/dist/types/algorithms/x25519.d.ts +76 -0
- package/dist/types/algorithms/x25519.d.ts.map +1 -0
- package/dist/types/cose/cbor.d.ts +30 -0
- package/dist/types/cose/cbor.d.ts.map +1 -0
- package/dist/types/cose/cose-key.d.ts +106 -0
- package/dist/types/cose/cose-key.d.ts.map +1 -0
- package/dist/types/cose/cose-sign1.d.ts +195 -0
- package/dist/types/cose/cose-sign1.d.ts.map +1 -0
- package/dist/types/cose/eat.d.ts +203 -0
- package/dist/types/cose/eat.d.ts.map +1 -0
- package/dist/types/crypto-error.d.ts +4 -0
- package/dist/types/crypto-error.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +4 -4
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
- package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
- package/dist/types/primitives/x25519.d.ts +9 -16
- package/dist/types/primitives/x25519.d.ts.map +1 -1
- package/dist/types/types/crypto-api.d.ts +52 -4
- package/dist/types/types/crypto-api.d.ts.map +1 -1
- package/dist/types/types/key-converter.d.ts +37 -15
- package/dist/types/types/key-converter.d.ts.map +1 -1
- package/dist/types/types/key-deriver.d.ts +41 -0
- package/dist/types/types/key-deriver.d.ts.map +1 -1
- package/dist/types/types/key-io.d.ts +37 -0
- package/dist/types/types/key-io.d.ts.map +1 -1
- package/dist/types/types/params-direct.d.ts +17 -0
- package/dist/types/types/params-direct.d.ts.map +1 -1
- package/dist/types/types/params-kms.d.ts +55 -0
- package/dist/types/types/params-kms.d.ts.map +1 -1
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +3 -3
- package/package.json +12 -14
- package/src/algorithms/aes-ctr.ts +1 -1
- package/src/algorithms/aes-gcm.ts +38 -2
- package/src/algorithms/aes-kw.ts +182 -0
- package/src/algorithms/ecdsa.ts +132 -1
- package/src/algorithms/eddsa.ts +108 -1
- package/src/algorithms/hkdf.ts +54 -0
- package/src/algorithms/pbkdf2.ts +57 -0
- package/src/algorithms/sha-2.ts +1 -1
- package/src/algorithms/x25519.ts +153 -0
- package/src/cose/cbor.ts +36 -0
- package/src/cose/cose-key.ts +344 -0
- package/src/cose/cose-sign1.ts +473 -0
- package/src/cose/eat.ts +368 -0
- package/src/crypto-error.ts +6 -0
- package/src/index.ts +10 -0
- package/src/local-key-manager.ts +9 -4
- package/src/primitives/ecies-secp256k1.ts +113 -0
- package/src/primitives/x25519.ts +9 -16
- package/src/types/crypto-api.ts +124 -6
- package/src/types/key-converter.ts +33 -7
- package/src/types/key-deriver.ts +49 -0
- package/src/types/key-io.ts +40 -0
- package/src/types/params-direct.ts +21 -0
- package/src/types/params-kms.ts +67 -0
- package/src/utils.ts +53 -0
- package/dist/browser.js +0 -60
- 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 dh=Object.create;var hs=Object.defineProperty;var hh=Object.getOwnPropertyDescriptor;var ph=Object.getOwnPropertyNames;var yh=Object.getPrototypeOf,mh=Object.prototype.hasOwnProperty;var ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Da=(r,e)=>{for(var t in e)hs(r,t,{get:e[t],enumerable:!0})},wh=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ph(e))!mh.call(r,i)&&i!==t&&hs(r,i,{get:()=>e[i],enumerable:!(n=hh(e,i))||n.enumerable});return r};var Ha=(r,e,t)=>(t=r!=null?dh(yh(r)):{},wh(e||!r||!r.__esModule?hs(t,"default",{value:r,enumerable:!0}):t,r));var $a=ie((fw,ja)=>{var gh=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Ci=()=>gh.now(),xh=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),ps=r=>r===1/0||xh(r),ys=class r{constructor({max:e=1/0,ttl:t,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:o=!1,dispose:s,noDisposeOnSet:c=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,t!==void 0&&!ps(t))throw new TypeError("ttl must be positive integer or Infinity if set");if(!ps(e))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=t,this.max=e,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!o,this.noDisposeOnSet=!!c,s!==void 0){if(typeof s!="function")throw new TypeError("dispose must be function if set");this.dispose=s}this.timer=void 0,this.timerExpiration=void 0}setTimer(e,t){if(this.timerExpiration<e)return;this.timer&&clearTimeout(this.timer);let n=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let i in this.expirations){this.setTimer(i,i-Ci());break}},t);n.unref&&n.unref(),this.timerExpiration=e,this.timer=n}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let e=this.dispose!==r.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[t,n]of e)this.dispose(n,t,"delete")}setTTL(e,t=this.ttl){let n=this.expirationMap.get(e);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==e)}if(t!==1/0){let i=Math.floor(Ci()+t);this.expirationMap.set(e,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,t)),this.expirations[i].push(e)}else this.expirationMap.set(e,1/0)}set(e,t,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!ps(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(e)){i||this.setTTL(e,n);let s=this.data.get(e);s!==t&&(this.data.set(e,t),o||this.dispose(s,e,"set"))}else this.setTTL(e,n),this.data.set(e,t);for(;this.size>this.max;)this.purgeToCapacity();return this}has(e){return this.data.has(e)}getRemainingTTL(e){let t=this.expirationMap.get(e);return t===1/0?t:t!==void 0?Math.max(0,Math.ceil(t-Ci())):0}get(e,{updateAgeOnGet:t=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(e);if(i&&this.getRemainingTTL(e)===0){this.delete(e);return}return t&&this.setTTL(e,n),o}dispose(e,t){}delete(e){let t=this.expirationMap.get(e);if(t!==void 0){let n=this.data.get(e);this.data.delete(e),this.expirationMap.delete(e);let i=this.expirations[t];return i&&(i.length<=1?delete this.expirations[t]:this.expirations[t]=i.filter(o=>o!==e)),this.dispose(n,e,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let e in this.expirations){let t=this.expirations[e];if(this.size-t.length>=this.max){delete this.expirations[e];let n=[];for(let i of t)n.push([i,this.data.get(i)]),this.data.delete(i),this.expirationMap.delete(i);for(let[i,o]of n)this.dispose(o,i,"evict")}else{let n=this.size-this.max,i=[];for(let o of t.splice(0,n))i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"evict");return}}}get size(){return this.data.size}purgeStale(){let e=Math.ceil(Ci());for(let t in this.expirations){if(t==="Infinity"||t>e)return;let n=[...this.expirations[t]||[]],i=[];delete this.expirations[t];for(let o of n)i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let e in this.expirations)for(let t of this.expirations[e])yield[t,this.data.get(t)]}*keys(){for(let e in this.expirations)for(let t of this.expirations[e])yield t}*values(){for(let e in this.expirations)for(let t of this.expirations[e])yield this.data.get(t)}[Symbol.iterator](){return this.entries()}};ja.exports=ys});var ou=ie(iu=>{"use strict";iu.supports=function(...e){let t=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(t,{snapshots:t.snapshots||!1,permanence:t.permanence||!1,seek:t.seek||!1,clear:t.clear||!1,getMany:t.getMany||!1,keyIterator:t.keyIterator||!1,valueIterator:t.valueIterator||!1,iteratorNextv:t.iteratorNextv||!1,iteratorAll:t.iteratorAll||!1,status:t.status||!1,createIfMissing:t.createIfMissing||!1,errorIfExists:t.errorIfExists||!1,deferredOpen:t.deferredOpen||!1,promises:t.promises||!1,streams:t.streams||!1,encodings:Object.assign({},t.encodings),events:Object.assign({},t.events),additionalMethods:Object.assign({},t.additionalMethods)})}});var nt=ie((ag,su)=>{"use strict";su.exports=class extends Error{constructor(e,t){super(e||""),typeof t=="object"&&t!==null&&(t.code&&(this.code=String(t.code)),t.expected&&(this.expected=!0),t.transient&&(this.transient=!0),t.cause&&(this.cause=t.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var uu=ie(Oi=>{"use strict";Oi.byteLength=Qh;Oi.toByteArray=tp;Oi.fromByteArray=ip;var mt=[],Ge=[],Yh=typeof Uint8Array<"u"?Uint8Array:Array,Us="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(kr=0,cu=Us.length;kr<cu;++kr)mt[kr]=Us[kr],Ge[Us.charCodeAt(kr)]=kr;var kr,cu;Ge[45]=62;Ge[95]=63;function au(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function Qh(r){var e=au(r),t=e[0],n=e[1];return(t+n)*3/4-n}function ep(r,e,t){return(e+t)*3/4-t}function tp(r){var e,t=au(r),n=t[0],i=t[1],o=new Yh(ep(r,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)e=Ge[r.charCodeAt(a)]<<18|Ge[r.charCodeAt(a+1)]<<12|Ge[r.charCodeAt(a+2)]<<6|Ge[r.charCodeAt(a+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Ge[r.charCodeAt(a)]<<2|Ge[r.charCodeAt(a+1)]>>4,o[s++]=e&255),i===1&&(e=Ge[r.charCodeAt(a)]<<10|Ge[r.charCodeAt(a+1)]<<4|Ge[r.charCodeAt(a+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function rp(r){return mt[r>>18&63]+mt[r>>12&63]+mt[r>>6&63]+mt[r&63]}function np(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(rp(n));return i.join("")}function ip(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,c=t-n;s<c;s+=o)i.push(np(r,s,s+o>c?c:s+o));return n===1?(e=r[t-1],i.push(mt[e>>2]+mt[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(mt[e>>10]+mt[e>>4&63]+mt[e<<2&63]+"=")),i.join("")}});var fu=ie(Ks=>{Ks.read=function(r,e,t,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,u=a>>1,f=-7,l=t?i-1:0,h=t?-1:1,m=r[e+l];for(l+=h,o=m&(1<<-f)-1,m>>=-f,f+=c;f>0;o=o*256+r[e+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=s*256+r[e+l],l+=h,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)};Ks.write=function(r,e,t,n,i,o){var s,c,a,u=o*8-i-1,f=(1<<u)-1,l=f>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,m=n?0:o-1,p=n?1:-1,d=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+l>=1?e+=h/a:e+=h*Math.pow(2,1-l),e*a>=2&&(s++,a/=2),s+l>=f?(c=0,s=f):s+l>=1?(c=(e*a-1)*Math.pow(2,i),s=s+l):(c=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;r[t+m]=c&255,m+=p,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;r[t+m]=s&255,m+=p,s/=256,u-=8);r[t+m-p]|=d*128}});var Ri=ie(rn=>{"use strict";var Is=uu(),en=fu(),lu=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;rn.Buffer=v;rn.SlowBuffer=fp;rn.INSPECT_MAX_BYTES=50;var Li=2147483647;rn.kMaxLength=Li;v.TYPED_ARRAY_SUPPORT=op();!v.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 op(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(v.prototype,"parent",{enumerable:!0,get:function(){if(v.isBuffer(this))return this.buffer}});Object.defineProperty(v.prototype,"offset",{enumerable:!0,get:function(){if(v.isBuffer(this))return this.byteOffset}});function Ct(r){if(r>Li)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,v.prototype),e}function v(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ls(r)}return yu(r,e,t)}v.poolSize=8192;function yu(r,e,t){if(typeof r=="string")return cp(r,e);if(ArrayBuffer.isView(r))return ap(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(wt(r,ArrayBuffer)||r&&wt(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(wt(r,SharedArrayBuffer)||r&&wt(r.buffer,SharedArrayBuffer)))return _s(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return v.from(n,e,t);let i=up(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return v.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}v.from=function(r,e,t){return yu(r,e,t)};Object.setPrototypeOf(v.prototype,Uint8Array.prototype);Object.setPrototypeOf(v,Uint8Array);function mu(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 sp(r,e,t){return mu(r),r<=0?Ct(r):e!==void 0?typeof t=="string"?Ct(r).fill(e,t):Ct(r).fill(e):Ct(r)}v.alloc=function(r,e,t){return sp(r,e,t)};function Ls(r){return mu(r),Ct(r<0?0:Ns(r)|0)}v.allocUnsafe=function(r){return Ls(r)};v.allocUnsafeSlow=function(r){return Ls(r)};function cp(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!v.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=wu(r,e)|0,n=Ct(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Cs(r){let e=r.length<0?0:Ns(r.length)|0,t=Ct(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function ap(r){if(wt(r,Uint8Array)){let e=new Uint8Array(r);return _s(e.buffer,e.byteOffset,e.byteLength)}return Cs(r)}function _s(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,v.prototype),n}function up(r){if(v.isBuffer(r)){let e=Ns(r.length)|0,t=Ct(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ms(r.length)?Ct(0):Cs(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Cs(r.data)}function Ns(r){if(r>=Li)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Li.toString(16)+" bytes");return r|0}function fp(r){return+r!=r&&(r=0),v.alloc(+r)}v.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==v.prototype};v.compare=function(e,t){if(wt(e,Uint8Array)&&(e=v.from(e,e.offset,e.byteLength)),wt(t,Uint8Array)&&(t=v.from(t,t.offset,t.byteLength)),!v.isBuffer(e)||!v.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};v.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};v.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return v.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=v.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(wt(s,Uint8Array))o+s.length>i.length?(v.isBuffer(s)||(s=v.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(v.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function wu(r,e){if(v.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||wt(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Os(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ku(r).length;default:if(i)return n?-1:Os(r).length;e=(""+e).toLowerCase(),i=!0}}v.byteLength=wu;function lp(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return Ep(this,e,t);case"utf8":case"utf-8":return xu(this,e,t);case"ascii":return xp(this,e,t);case"latin1":case"binary":return bp(this,e,t);case"base64":return wp(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ap(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}v.prototype._isBuffer=!0;function Tr(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}v.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Tr(this,t,t+1);return this};v.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Tr(this,t,t+3),Tr(this,t+1,t+2);return this};v.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Tr(this,t,t+7),Tr(this,t+1,t+6),Tr(this,t+2,t+5),Tr(this,t+3,t+4);return this};v.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?xu(this,0,e):lp.apply(this,arguments)};v.prototype.toLocaleString=v.prototype.toString;v.prototype.equals=function(e){if(!v.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:v.compare(this,e)===0};v.prototype.inspect=function(){let e="",t=rn.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};lu&&(v.prototype[lu]=v.prototype.inspect);v.prototype.compare=function(e,t,n,i,o){if(wt(e,Uint8Array)&&(e=v.from(e,e.offset,e.byteLength)),!v.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,c=n-t,a=Math.min(s,c),u=this.slice(i,o),f=e.slice(t,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 gu(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Ms(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=v.from(e,n)),v.isBuffer(e))return e.length===0?-1:du(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):du(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function du(r,e,t,n,i){let o=1,s=r.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,c/=2,t/=2}function a(f,l){return o===1?f[l]:f.readUInt16BE(l*o)}let u;if(i){let f=-1;for(u=t;u<s;u++)if(a(r,u)===a(e,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(t+c>s&&(t=s-c),u=t;u>=0;u--){let f=!0;for(let l=0;l<c;l++)if(a(r,u+l)!==a(e,l)){f=!1;break}if(f)return u}return-1}v.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};v.prototype.indexOf=function(e,t,n){return gu(this,e,t,n,!0)};v.prototype.lastIndexOf=function(e,t,n){return gu(this,e,t,n,!1)};function dp(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(e.substr(s*2,2),16);if(Ms(c))return s;r[t+s]=c}return s}function hp(r,e,t,n){return Ni(Os(e,r.length-t),r,t,n)}function pp(r,e,t,n){return Ni(kp(e),r,t,n)}function yp(r,e,t,n){return Ni(ku(e),r,t,n)}function mp(r,e,t,n){return Ni(Tp(e,r.length-t),r,t,n)}v.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return dp(this,e,t,n);case"utf8":case"utf-8":return hp(this,e,t,n);case"ascii":case"latin1":case"binary":return pp(this,e,t,n);case"base64":return yp(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mp(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};v.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function wp(r,e,t){return e===0&&t===r.length?Is.fromByteArray(r):Is.fromByteArray(r.slice(e,t))}function xu(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=t){let 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 gp(n)}var hu=4096;function gp(r){let e=r.length;if(e<=hu)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=hu));return t}function xp(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function bp(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function Ep(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=Pp[r[o]];return i}function Ap(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}v.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,v.prototype),i};function ge(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}v.prototype.readUintLE=v.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||ge(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};v.prototype.readUintBE=v.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||ge(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};v.prototype.readUint8=v.prototype.readUInt8=function(e,t){return e=e>>>0,t||ge(e,1,this.length),this[e]};v.prototype.readUint16LE=v.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||ge(e,2,this.length),this[e]|this[e+1]<<8};v.prototype.readUint16BE=v.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||ge(e,2,this.length),this[e]<<8|this[e+1]};v.prototype.readUint32LE=v.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};v.prototype.readUint32BE=v.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};v.prototype.readBigUInt64LE=Xt(function(e){e=e>>>0,tn(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Dn(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});v.prototype.readBigUInt64BE=Xt(function(e){e=e>>>0,tn(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Dn(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});v.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||ge(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};v.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||ge(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};v.prototype.readInt8=function(e,t){return e=e>>>0,t||ge(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};v.prototype.readInt16LE=function(e,t){e=e>>>0,t||ge(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};v.prototype.readInt16BE=function(e,t){e=e>>>0,t||ge(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};v.prototype.readInt32LE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};v.prototype.readInt32BE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};v.prototype.readBigInt64LE=Xt(function(e){e=e>>>0,tn(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Dn(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});v.prototype.readBigInt64BE=Xt(function(e){e=e>>>0,tn(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&Dn(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});v.prototype.readFloatLE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),en.read(this,e,!0,23,4)};v.prototype.readFloatBE=function(e,t){return e=e>>>0,t||ge(e,4,this.length),en.read(this,e,!1,23,4)};v.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||ge(e,8,this.length),en.read(this,e,!0,52,8)};v.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||ge(e,8,this.length),en.read(this,e,!1,52,8)};function Ce(r,e,t,n,i,o){if(!v.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}v.prototype.writeUintLE=v.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;Ce(this,e,t,n,c,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};v.prototype.writeUintBE=v.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;Ce(this,e,t,n,c,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};v.prototype.writeUint8=v.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,1,255,0),this[t]=e&255,t+1};v.prototype.writeUint16LE=v.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};v.prototype.writeUint16BE=v.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};v.prototype.writeUint32LE=v.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};v.prototype.writeUint32BE=v.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function bu(r,e,t,n,i){Su(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function Eu(r,e,t,n,i){Su(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}v.prototype.writeBigUInt64LE=Xt(function(e,t=0){return bu(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});v.prototype.writeBigUInt64BE=Xt(function(e,t=0){return Eu(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});v.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let a=Math.pow(2,8*n-1);Ce(this,e,t,n,a-1,-a)}let o=0,s=1,c=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&c===0&&this[t+o-1]!==0&&(c=1),this[t+o]=(e/s>>0)-c&255;return t+n};v.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let a=Math.pow(2,8*n-1);Ce(this,e,t,n,a-1,-a)}let o=n-1,s=1,c=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&c===0&&this[t+o+1]!==0&&(c=1),this[t+o]=(e/s>>0)-c&255;return t+n};v.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};v.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};v.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};v.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};v.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||Ce(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};v.prototype.writeBigInt64LE=Xt(function(e,t=0){return bu(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});v.prototype.writeBigInt64BE=Xt(function(e,t=0){return Eu(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Au(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function vu(r,e,t,n,i){return e=+e,t=t>>>0,i||Au(r,e,t,4,34028234663852886e22,-34028234663852886e22),en.write(r,e,t,n,23,4),t+4}v.prototype.writeFloatLE=function(e,t,n){return vu(this,e,t,!0,n)};v.prototype.writeFloatBE=function(e,t,n){return vu(this,e,t,!1,n)};function Bu(r,e,t,n,i){return e=+e,t=t>>>0,i||Au(r,e,t,8,17976931348623157e292,-17976931348623157e292),en.write(r,e,t,n,52,8),t+8}v.prototype.writeDoubleLE=function(e,t,n){return Bu(this,e,t,!0,n)};v.prototype.writeDoubleBE=function(e,t,n){return Bu(this,e,t,!1,n)};v.prototype.copy=function(e,t,n,i){if(!v.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};v.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!v.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=v.isBuffer(e)?e:v.from(e,i),c=s.length;if(c===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%c]}return this};var Qr={};function Rs(r,e,t){Qr[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Rs("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Rs("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);Rs("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=pu(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=pu(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function pu(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function vp(r,e,t){tn(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&Dn(e,r.length-(t+1))}function Su(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",c;throw o>3?e===0||e===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:c=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:c=`>= ${e}${s} and <= ${t}${s}`,new Qr.ERR_OUT_OF_RANGE("value",c,r)}vp(n,i,o)}function tn(r,e){if(typeof r!="number")throw new Qr.ERR_INVALID_ARG_TYPE(e,"number",r)}function Dn(r,e,t){throw Math.floor(r)!==r?(tn(r,t),new Qr.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new Qr.ERR_BUFFER_OUT_OF_BOUNDS:new Qr.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var Bp=/[^+/0-9A-Za-z-_]/g;function Sp(r){if(r=r.split("=")[0],r=r.trim().replace(Bp,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Os(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function kp(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function Tp(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function ku(r){return Is.toByteArray(Sp(r))}function Ni(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function wt(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ms(r){return r!==r}var Pp=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function Xt(r){return typeof BigInt>"u"?Up:r}function Up(){throw new Error("BigInt not supported")}});var Hs=ie((hg,Tu)=>{"use strict";var Ds=null;Tu.exports=function(){return Ds===null&&(Ds={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ds}});var Js=ie(Pu=>{"use strict";var js=nt(),Kp=new Set(["buffer","view","utf8"]),$s=class{constructor(e){if(this.encode=e.encode||this.encode,this.decode=e.decode||this.decode,this.name=e.name||this.name,this.format=e.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!Kp.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");e.createViewTranscoder&&(this.createViewTranscoder=e.createViewTranscoder),e.createBufferTranscoder&&(this.createBufferTranscoder=e.createBufferTranscoder),e.createUTF8Transcoder&&(this.createUTF8Transcoder=e.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new js(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new js(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new js(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};Pu.Encoding=$s});var qs=ie(Mi=>{"use strict";var{Buffer:Vs}=Ri()||{},{Encoding:Gs}=Js(),Ip=Hs(),Hn=class extends Gs{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new jn({encode:this.encode,decode:e=>this.decode(Vs.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},jn=class extends Gs{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new Hn({encode:e=>{let t=this.encode(e);return Vs.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Fs=class extends Gs{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new Hn({encode:e=>Vs.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=Ip();return new jn({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};Mi.BufferFormat=Hn;Mi.ViewFormat=jn;Mi.UTF8Format=Fs});var Cu=ie(Pr=>{"use strict";var{Buffer:Be}=Ri()||{Buffer:{isBuffer:()=>!1}},{textEncoder:Ku,textDecoder:Uu}=Hs()(),{BufferFormat:$n,ViewFormat:zs,UTF8Format:Iu}=qs(),Di=r=>r;Pr.utf8=new Iu({encode:function(r){return Be.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?Uu.decode(r):String(r)},decode:Di,name:"utf8",createViewTranscoder(){return new zs({encode:function(r){return ArrayBuffer.isView(r)?r:Ku.encode(r)},decode:function(r){return Uu.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new $n({encode:function(r){return Be.isBuffer(r)?r:ArrayBuffer.isView(r)?Be.from(r.buffer,r.byteOffset,r.byteLength):Be.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});Pr.json=new Iu({encode:JSON.stringify,decode:JSON.parse,name:"json"});Pr.buffer=new $n({encode:function(r){return Be.isBuffer(r)?r:ArrayBuffer.isView(r)?Be.from(r.buffer,r.byteOffset,r.byteLength):Be.from(String(r),"utf8")},decode:Di,name:"buffer",createViewTranscoder(){return new zs({encode:function(r){return ArrayBuffer.isView(r)?r:Be.from(String(r),"utf8")},decode:function(r){return Be.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});Pr.view=new zs({encode:function(r){return ArrayBuffer.isView(r)?r:Ku.encode(r)},decode:Di,name:"view",createBufferTranscoder(){return new $n({encode:function(r){return Be.isBuffer(r)?r:ArrayBuffer.isView(r)?Be.from(r.buffer,r.byteOffset,r.byteLength):Be.from(String(r),"utf8")},decode:Di,name:`${this.name}+buffer`})}});Pr.hex=new $n({encode:function(r){return Be.isBuffer(r)?r:Be.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});Pr.base64=new $n({encode:function(r){return Be.isBuffer(r)?r:Be.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var Lu=ie(Ou=>{"use strict";var _u=nt(),ji=Cu(),{Encoding:Cp}=Js(),{BufferFormat:_p,ViewFormat:Op,UTF8Format:Lp}=qs(),Jn=Symbol("formats"),Hi=Symbol("encodings"),Np=new Set(["buffer","view","utf8"]),Ws=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>Np.has(t)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[Hi]=new Map,this[Jn]=new Set(e);for(let t in ji)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[Hi].values()))}encoding(e){let t=this[Hi].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=Hp[e],!t)throw new _u(`Encoding '${e}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof e!="object"||e===null)throw new TypeError("First argument 'encoding' must be a string or object");t=Rp(e)}let{name:n,format:i}=t;if(!this[Jn].has(i))if(this[Jn].has("view"))t=t.createViewTranscoder();else if(this[Jn].has("buffer"))t=t.createBufferTranscoder();else if(this[Jn].has("utf8"))t=t.createUTF8Transcoder();else throw new _u(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[e,n,t.name,t.commonName])this[Hi].set(o,t)}return t}};Ou.Transcoder=Ws;function Rp(r){if(r instanceof Cp)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${jp++}`;switch(Mp(r)){case"view":return new Op({...r,name:t});case"utf8":return new Lp({...r,name:t});case"buffer":return new _p({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function Mp(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 Dp={binary:ji.buffer,"utf-8":ji.utf8},Hp={...ji,...Dp},jp=0});var Ru=ie((gg,Xs)=>{"use strict";var $p=Object.prototype.hasOwnProperty,Te="~";function Fn(){}Object.create&&(Fn.prototype=Object.create(null),new Fn().__proto__||(Te=!1));function Jp(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Nu(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Jp(t,n||r,i),s=Te?Te+e:e;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function $i(r,e){--r._eventsCount===0?r._events=new Fn:delete r._events[e]}function Se(){this._events=new Fn,this._eventsCount=0}Se.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)$p.call(t,n)&&e.push(Te?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};Se.prototype.listeners=function(e){var t=Te?Te+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};Se.prototype.listenerCount=function(e){var t=Te?Te+e:e,n=this._events[t];return n?n.fn?1:n.length:0};Se.prototype.emit=function(e,t,n,i,o,s){var c=Te?Te+e:e;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,l;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void 0,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,t),!0;case 3:return a.fn.call(a.context,t,n),!0;case 4:return a.fn.call(a.context,t,n,i),!0;case 5:return a.fn.call(a.context,t,n,i,o),!0;case 6:return a.fn.call(a.context,t,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 h=a.length,m;for(l=0;l<h;l++)switch(a[l].once&&this.removeListener(e,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,t);break;case 3:a[l].fn.call(a[l].context,t,n);break;case 4:a[l].fn.call(a[l].context,t,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};Se.prototype.on=function(e,t,n){return Nu(this,e,t,n,!1)};Se.prototype.once=function(e,t,n){return Nu(this,e,t,n,!0)};Se.prototype.removeListener=function(e,t,n,i){var o=Te?Te+e:e;if(!this._events[o])return this;if(!t)return $i(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!n||s.context===n)&&$i(this,o);else{for(var c=0,a=[],u=s.length;c<u;c++)(s[c].fn!==t||i&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[o]=a.length===1?a[0]:a:$i(this,o)}return this};Se.prototype.removeAllListeners=function(e){var t;return e?(t=Te?Te+e:e,this._events[t]&&$i(this,t)):(this._events=new Fn,this._eventsCount=0),this};Se.prototype.off=Se.prototype.removeListener;Se.prototype.addListener=Se.prototype.on;Se.prefixed=Te;Se.EventEmitter=Se;typeof Xs<"u"&&(Xs.exports=Se)});var Du=ie((xg,Mu)=>{Mu.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var Vn=ie(Zs=>{"use strict";var Hu=Du();Zs.fromCallback=function(r,e){if(r===void 0){var t=new Promise(function(n,i){r=function(o,s){o?i(o):n(s)}});r[e!==void 0?e:"promise"]=t}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r};Zs.fromPromise=function(r,e){if(e===void 0)return r;r.then(function(t){Hu(()=>e(null,t))}).catch(function(t){Hu(()=>e(t))})}});var Ji=ie(Ys=>{"use strict";Ys.getCallback=function(r,e){return typeof r=="function"?r:e};Ys.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}}});var rr=ie(qi=>{"use strict";var{fromCallback:Qs}=Vn(),Le=nt(),{getOptions:ec,getCallback:ju}=Ji(),Ur=Symbol("promise"),nn=Symbol("callback"),gt=Symbol("working"),Kr=Symbol("handleOne"),_t=Symbol("handleMany"),tc=Symbol("autoClose"),er=Symbol("finishWork"),xt=Symbol("returnMany"),Zt=Symbol("closing"),Gn=Symbol("handleClose"),Fi=Symbol("closed"),qn=Symbol("closeCallbacks"),Qt=Symbol("keyEncoding"),Ir=Symbol("valueEncoding"),rc=Symbol("abortOnClose"),Vi=Symbol("legacy"),nc=Symbol("keys"),ic=Symbol("values"),Yt=Symbol("limit"),qe=Symbol("count"),Gi=Object.freeze({}),Fp=()=>{},$u=!1,zn=class{constructor(e,t,n){if(typeof e!="object"||e===null){let i=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof t!="object"||t===null)throw new TypeError("The second argument must be an options object");this[Fi]=!1,this[qn]=[],this[gt]=!1,this[Zt]=!1,this[tc]=!1,this[nn]=null,this[Kr]=this[Kr].bind(this),this[_t]=this[_t].bind(this),this[Gn]=this[Gn].bind(this),this[Qt]=t[Qt],this[Ir]=t[Ir],this[Vi]=n,this[Yt]=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this[qe]=0,this[rc]=!!t.abortOnClose,this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get count(){return this[qe]}get limit(){return this[Yt]}next(e){let t;if(e===void 0)t=new Promise((n,i)=>{e=(o,s,c)=>{o?i(o):this[Vi]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof e!="function")throw new TypeError("Callback must be a function");return this[Zt]?this.nextTick(e,new Le("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[gt]?this.nextTick(e,new Le("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[gt]=!0,this[nn]=e,this[qe]>=this[Yt]?this.nextTick(this[Kr],null):this._next(this[Kr])),t}_next(e){this.nextTick(e)}nextv(e,t,n){return n=ju(t,n),n=Qs(n,Ur),t=ec(t,Gi),Number.isInteger(e)?(this[Zt]?this.nextTick(n,new Le("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[gt]?this.nextTick(n,new Le("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(e<1&&(e=1),this[Yt]<1/0&&(e=Math.min(e,this[Yt]-this[qe])),this[gt]=!0,this[nn]=n,e<=0?this.nextTick(this[_t],null,[]):this._nextv(e,t,this[_t])),n[Ur]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[Ur])}_nextv(e,t,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[Vi]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[Vi]?[c,a]:c),i.length===e?n(null,i):this._next(o)};this._next(o)}all(e,t){return t=ju(e,t),t=Qs(t,Ur),e=ec(e,Gi),this[Zt]?this.nextTick(t,new Le("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[gt]?this.nextTick(t,new Le("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[gt]=!0,this[nn]=t,this[tc]=!0,this[qe]>=this[Yt]?this.nextTick(this[_t],null,[]):this._all(e,this[_t])),t[Ur]}_all(e,t){let n=this[qe],i=[],o=()=>{let c=this[Yt]<1/0?Math.min(1e3,this[Yt]-n):1e3;c<=0?this.nextTick(t,null,i):this._nextv(c,Gi,s)},s=(c,a)=>{c?t(c):a.length===0?t(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[er](){let e=this[nn];return this[rc]&&e===null?Fp:(this[gt]=!1,this[nn]=null,this[Zt]&&this._close(this[Gn]),e)}[xt](e,t,n){this[tc]?this.close(e.bind(null,t,n)):e(t,n)}seek(e,t){if(t=ec(t,Gi),!this[Zt]){if(this[gt])throw new Le("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[Qt]),i=n.format;t.keyEncoding!==i&&(t={...t,keyEncoding:i});let o=this.db.prefixKey(n.encode(e),i);this._seek(o,t)}}}_seek(e,t){throw new Le("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(e){return e=Qs(e,Ur),this[Fi]?this.nextTick(e):this[Zt]?this[qn].push(e):(this[Zt]=!0,this[qn].push(e),this[gt]?this[rc]&&this[er]()(new Le("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[Gn])),e[Ur]}_close(e){this.nextTick(e)}[Gn](){this[Fi]=!0,this.db.detachResource(this);let e=this[qn];this[qn]=[];for(let t of e)t()}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}finally{this[Fi]||await this.close()}}},on=class extends zn{constructor(e,t){super(e,t,!0),this[nc]=t.keys!==!1,this[ic]=t.values!==!1}[Kr](e,t,n){let i=this[er]();if(e)return i(e);try{t=this[nc]&&t!==void 0?this[Qt].decode(t):void 0,n=this[ic]&&n!==void 0?this[Ir].decode(n):void 0}catch(o){return i(new tr("entry",o))}t===void 0&&n===void 0||this[qe]++,i(null,t,n)}[_t](e,t){let n=this[er]();if(e)return this[xt](n,e);try{for(let i of t){let o=i[0],s=i[1];i[0]=this[nc]&&o!==void 0?this[Qt].decode(o):void 0,i[1]=this[ic]&&s!==void 0?this[Ir].decode(s):void 0}}catch(i){return this[xt](n,new tr("entries",i))}this[qe]+=t.length,this[xt](n,null,t)}end(e){return!$u&&typeof console<"u"&&($u=!0,console.warn(new Le("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(e)}},oc=class extends zn{constructor(e,t){super(e,t,!1)}[Kr](e,t){let n=this[er]();if(e)return n(e);try{t=t!==void 0?this[Qt].decode(t):void 0}catch(i){return n(new tr("key",i))}t!==void 0&&this[qe]++,n(null,t)}[_t](e,t){let n=this[er]();if(e)return this[xt](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[Qt].decode(o):void 0}}catch(i){return this[xt](n,new tr("keys",i))}this[qe]+=t.length,this[xt](n,null,t)}},sc=class extends zn{constructor(e,t){super(e,t,!1)}[Kr](e,t){let n=this[er]();if(e)return n(e);try{t=t!==void 0?this[Ir].decode(t):void 0}catch(i){return n(new tr("value",i))}t!==void 0&&this[qe]++,n(null,t)}[_t](e,t){let n=this[er]();if(e)return this[xt](n,e);try{for(let i=0;i<t.length;i++){let o=t[i];t[i]=o!==void 0?this[Ir].decode(o):void 0}}catch(i){return this[xt](n,new tr("values",i))}this[qe]+=t.length,this[xt](n,null,t)}},tr=class extends Le{constructor(e,t){super(`Iterator could not decode ${e}`,{code:"LEVEL_DECODE_ERROR",cause:t})}};for(let r of["_ended property","_nexting property","_end method"])Object.defineProperty(on.prototype,r.split(" ")[0],{get(){throw new Le(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Le(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});on.keyEncoding=Qt;on.valueEncoding=Ir;qi.AbstractIterator=on;qi.AbstractKeyIterator=oc;qi.AbstractValueIterator=sc});var Ju=ie(cc=>{"use strict";var{AbstractKeyIterator:Vp,AbstractValueIterator:Gp}=rr(),Cr=Symbol("iterator"),Wn=Symbol("callback"),sn=Symbol("handleOne"),_r=Symbol("handleMany"),Xn=class extends Vp{constructor(e,t){super(e,t),this[Cr]=e.iterator({...t,keys:!0,values:!1}),this[sn]=this[sn].bind(this),this[_r]=this[_r].bind(this)}},zi=class extends Gp{constructor(e,t){super(e,t),this[Cr]=e.iterator({...t,keys:!1,values:!0}),this[sn]=this[sn].bind(this),this[_r]=this[_r].bind(this)}};for(let r of[Xn,zi]){let e=r===Xn,t=e?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[Wn]=n,this[Cr].next(this[sn])},r.prototype[sn]=function(n,i,o){let s=this[Wn];n?s(n):s(null,e?i:o)},r.prototype._nextv=function(n,i,o){this[Wn]=o,this[Cr].nextv(n,i,this[_r])},r.prototype._all=function(n,i){this[Wn]=i,this[Cr].all(n,this[_r])},r.prototype[_r]=function(n,i){let o=this[Wn];n?o(n):o(null,i.map(t))},r.prototype._seek=function(n,i){this[Cr].seek(n,i)},r.prototype._close=function(n){this[Cr].close(n)}}cc.DefaultKeyIterator=Xn;cc.DefaultValueIterator=zi});var Fu=ie(eo=>{"use strict";var{AbstractIterator:qp,AbstractKeyIterator:zp,AbstractValueIterator:Wp}=rr(),ac=nt(),_e=Symbol("nut"),Yi=Symbol("undefer"),Qi=Symbol("factory"),Wi=class extends qp{constructor(e,t){super(e,t),this[_e]=null,this[Qi]=()=>e.iterator(t),this.db.defer(()=>this[Yi]())}},Xi=class extends zp{constructor(e,t){super(e,t),this[_e]=null,this[Qi]=()=>e.keys(t),this.db.defer(()=>this[Yi]())}},Zi=class extends Wp{constructor(e,t){super(e,t),this[_e]=null,this[Qi]=()=>e.values(t),this.db.defer(()=>this[Yi]())}};for(let r of[Wi,Xi,Zi])r.prototype[Yi]=function(){this.db.status==="open"&&(this[_e]=this[Qi]())},r.prototype._next=function(e){this[_e]!==null?this[_e].next(e):this.db.status==="opening"?this.db.defer(()=>this._next(e)):this.nextTick(e,new ac("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(e,t,n){this[_e]!==null?this[_e].nextv(e,t,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(e,t,n)):this.nextTick(n,new ac("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(e,t){this[_e]!==null?this[_e].all(t):this.db.status==="opening"?this.db.defer(()=>this._all(e,t)):this.nextTick(t,new ac("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(e,t){this[_e]!==null?this[_e]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t))},r.prototype._close=function(e){this[_e]!==null?this[_e].close(e):this.db.status==="opening"?this.db.defer(()=>this._close(e)):this.nextTick(e)};eo.DeferredIterator=Wi;eo.DeferredKeyIterator=Xi;eo.DeferredValueIterator=Zi});var fc=ie(Gu=>{"use strict";var{fromCallback:Vu}=Vn(),to=nt(),{getCallback:Xp,getOptions:Zp}=Ji(),ro=Symbol("promise"),ze=Symbol("status"),cn=Symbol("operations"),Zn=Symbol("finishClose"),an=Symbol("closeCallbacks"),uc=class{constructor(e){if(typeof e!="object"||e===null){let t=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${t}`)}this[cn]=[],this[an]=[],this[ze]="open",this[Zn]=this[Zn].bind(this),this.db=e,this.db.attachResource(this),this.nextTick=e.nextTick}get length(){return this[cn].length}put(e,t,n){if(this[ze]!=="open")throw new to("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(e)||this.db._checkValue(t);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),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(e),u),l=a.encode(t);return this._put(f,l,n),this[cn].push({...s,type:"put",key:e,value:t}),this}_put(e,t,n){}del(e,t){if(this[ze]!=="open")throw new to("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(e);if(n)throw n;let i=t&&t.sublevel!=null?t.sublevel:this.db,o=t,s=i.keyEncoding(t&&t.keyEncoding),c=s.format;return t={...t,keyEncoding:c},i!==this.db&&(t.sublevel=null),this._del(i.prefixKey(s.encode(e),c),t),this[cn].push({...o,type:"del",key:e}),this}_del(e,t){}clear(){if(this[ze]!=="open")throw new to("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[cn]=[],this}_clear(){}write(e,t){return t=Xp(e,t),t=Vu(t,ro),e=Zp(e),this[ze]!=="open"?this.nextTick(t,new to("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(t):(this[ze]="writing",this._write(e,n=>{this[ze]="closing",this[an].push(()=>t(n)),n||this.db.emit("batch",this[cn]),this._close(this[Zn])})),t[ro]}_write(e,t){}close(e){return e=Vu(e,ro),this[ze]==="closing"?this[an].push(e):this[ze]==="closed"?this.nextTick(e):(this[an].push(e),this[ze]!=="writing"&&(this[ze]="closing",this._close(this[Zn]))),e[ro]}_close(e){this.nextTick(e)}[Zn](){this[ze]="closed",this.db.detachResource(this);let e=this[an];this[an]=[];for(let t of e)t()}};Gu.AbstractChainedBatch=uc});var zu=ie(qu=>{"use strict";var{AbstractChainedBatch:Yp}=fc(),Qp=nt(),un=Symbol("encoded"),lc=class extends Yp{constructor(e){super(e),this[un]=[]}_put(e,t,n){this[un].push({...n,type:"put",key:e,value:t})}_del(e,t){this[un].push({...t,type:"del",key:e})}_clear(){this[un]=[]}_write(e,t){this.db.status==="opening"?this.db.defer(()=>this._write(e,t)):this.db.status==="open"?this[un].length===0?this.nextTick(t):this.db._batch(this[un],e,t):this.nextTick(t,new Qp("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};qu.DefaultChainedBatch=lc});var Zu=ie((Tg,Xu)=>{"use strict";var Wu=nt(),ey=Object.prototype.hasOwnProperty,ty=new Set(["lt","lte","gt","gte"]);Xu.exports=function(r,e){let t={};for(let n in r)if(ey.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new Wu(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new Wu("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});ty.has(n)?t[n]=e.encode(r[n]):t[n]=r[n]}return t.reverse=!!t.reverse,t.limit=Number.isInteger(t.limit)&&t.limit>=0?t.limit:-1,t}});var dc=ie((Pg,Qu)=>{var Yu;Qu.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(Yu||(Yu=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0))});var rf=ie((Ug,tf)=>{"use strict";var ef=dc();tf.exports=function(r,...e){e.length===0?ef(r):ef(()=>r(...e))}});var nf=ie(no=>{"use strict";var{AbstractIterator:ry,AbstractKeyIterator:ny,AbstractValueIterator:iy}=rr(),fn=Symbol("unfix"),it=Symbol("iterator"),Or=Symbol("handleOne"),nr=Symbol("handleMany"),Ot=Symbol("callback"),Yn=class extends ry{constructor(e,t,n,i){super(e,t),this[it]=n,this[fn]=i,this[Or]=this[Or].bind(this),this[nr]=this[nr].bind(this),this[Ot]=null}[Or](e,t,n){let i=this[Ot];if(e)return i(e);t!==void 0&&(t=this[fn](t)),i(e,t,n)}[nr](e,t){let n=this[Ot];if(e)return n(e);for(let i of t){let o=i[0];o!==void 0&&(i[0]=this[fn](o))}n(e,t)}},Qn=class extends ny{constructor(e,t,n,i){super(e,t),this[it]=n,this[fn]=i,this[Or]=this[Or].bind(this),this[nr]=this[nr].bind(this),this[Ot]=null}[Or](e,t){let n=this[Ot];if(e)return n(e);t!==void 0&&(t=this[fn](t)),n(e,t)}[nr](e,t){let n=this[Ot];if(e)return n(e);for(let i=0;i<t.length;i++){let o=t[i];o!==void 0&&(t[i]=this[fn](o))}n(e,t)}},ei=class extends iy{constructor(e,t,n){super(e,t),this[it]=n}};for(let r of[Yn,Qn])r.prototype._next=function(e){this[Ot]=e,this[it].next(this[Or])},r.prototype._nextv=function(e,t,n){this[Ot]=n,this[it].nextv(e,t,this[nr])},r.prototype._all=function(e,t){this[Ot]=t,this[it].all(e,this[nr])};for(let r of[ei])r.prototype._next=function(e){this[it].next(e)},r.prototype._nextv=function(e,t,n){this[it].nextv(e,t,n)},r.prototype._all=function(e,t){this[it].all(e,t)};for(let r of[Yn,Qn,ei])r.prototype._seek=function(e,t){this[it].seek(e,t)},r.prototype._close=function(e){this[it].close(e)};no.AbstractSublevelIterator=Yn;no.AbstractSublevelKeyIterator=Qn;no.AbstractSublevelValueIterator=ei});var af=ie((Ig,cf)=>{"use strict";var hc=nt(),{Buffer:mc}=Ri()||{},{AbstractSublevelIterator:oy,AbstractSublevelKeyIterator:sy,AbstractSublevelValueIterator:cy}=nf(),Lt=Symbol("prefix"),of=Symbol("upperBound"),ti=Symbol("prefixRange"),Ne=Symbol("parent"),pc=Symbol("unfix"),sf=new TextEncoder,ay={separator:"!"};cf.exports=function({AbstractLevel:r}){class e extends r{static defaults(n){if(typeof n=="string")throw new hc("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new hc("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?ay:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=e.defaults(o);i=fy(i,s);let u=s.charCodeAt(0)+1,f=n[Ne]||n;if(!sf.encode(i).every(m=>m>u&&m<127))throw new hc(`Prefix must use bytes > ${u} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(uy(f,c),a);let l=(n.prefix||"")+s+i+s,h=l.slice(0,-1)+String.fromCharCode(u);this[Ne]=f,this[Lt]=new io(l),this[of]=new io(h),this[pc]=new wc,this.nextTick=f.nextTick}prefixKey(n,i){if(i==="utf8")return this[Lt].utf8+n;if(n.byteLength===0)return this[Lt][i];if(i==="view"){let o=this[Lt].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[Lt].buffer;return mc.concat([o,n],o.byteLength+n.byteLength)}}[ti](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[Lt][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[of][i]}get prefix(){return this[Lt].utf8}get db(){return this[Ne]}_open(n,i){this[Ne].open({passive:!0},i)}_put(n,i,o,s){this[Ne].put(n,i,o,s)}_get(n,i,o){this[Ne].get(n,i,o)}_getMany(n,i,o){this[Ne].getMany(n,i,o)}_del(n,i,o){this[Ne].del(n,i,o)}_batch(n,i,o){this[Ne].batch(n,i,o)}_clear(n,i){this[ti](n,n.keyEncoding),this[Ne].clear(n,i)}_iterator(n){this[ti](n,n.keyEncoding);let i=this[Ne].iterator(n),o=this[pc].get(this[Lt].utf8.length,n.keyEncoding);return new oy(this,n,i,o)}_keys(n){this[ti](n,n.keyEncoding);let i=this[Ne].keys(n),o=this[pc].get(this[Lt].utf8.length,n.keyEncoding);return new sy(this,n,i,o)}_values(n){this[ti](n,n.keyEncoding);let i=this[Ne].values(n);return new cy(this,n,i)}}return{AbstractSublevel:e}};var uy=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:yc(r,"utf8"),buffer:yc(r,"buffer"),view:yc(r,"view")}}},yc=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},io=class{constructor(e){this.utf8=e,this.view=sf.encode(e),this.buffer=mc?mc.from(this.view.buffer,0,this.view.byteLength):{}}},wc=class{constructor(){this.cache=new Map}get(e,t){let n=this.cache.get(t);return n===void 0&&(t==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,e):n=(function(i,o){return o.slice(i)}).bind(null,e),this.cache.set(t,n)),n}},fy=function(r,e){let t=0,n=r.length;for(;t<n&&r[t]===e;)t++;for(;n>t&&r[n-1]===e;)n--;return r.slice(t,n)}});var Ac=ie(Ec=>{"use strict";var{supports:ly}=ou(),{Transcoder:dy}=Lu(),{EventEmitter:hy}=Ru(),{fromCallback:ir}=Vn(),ot=nt(),{AbstractIterator:Lr}=rr(),{DefaultKeyIterator:py,DefaultValueIterator:yy}=Ju(),{DeferredIterator:my,DeferredKeyIterator:wy,DeferredValueIterator:gy}=Fu(),{DefaultChainedBatch:uf}=zu(),{getCallback:Nr,getOptions:or}=Ji(),oo=Zu(),Q=Symbol("promise"),Nt=Symbol("landed"),Rr=Symbol("resources"),gc=Symbol("closeResources"),ri=Symbol("operations"),ni=Symbol("undefer"),so=Symbol("deferOpen"),ff=Symbol("options"),ne=Symbol("status"),Mr=Symbol("defaultOptions"),ln=Symbol("transcoder"),co=Symbol("keyEncoding"),xc=Symbol("valueEncoding"),xy=()=>{},ii=class extends hy{constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=or(t);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=t;this[Rr]=new Set,this[ri]=[],this[so]=!0,this[ff]=s,this[ne]="opening",this.supports=ly(e,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:e.snapshots!==!1,permanence:e.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:e.encodings||{},events:Object.assign({},e.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[ln]=new dy(by(this)),this[co]=this[ln].encoding(n||"utf8"),this[xc]=this[ln].encoding(i||"utf8");for(let c of this[ln].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[Mr]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[co].commonName,valueEncoding:this[xc].commonName}),key:Object.freeze({keyEncoding:this[co].commonName})},this.nextTick(()=>{this[so]&&this.open({passive:!1},xy)})}get status(){return this[ne]}keyEncoding(e){return this[ln].encoding(e??this[co])}valueEncoding(e){return this[ln].encoding(e??this[xc])}open(e,t){t=Nr(e,t),t=ir(t,Q),e={...this[ff],...or(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let n=i=>{this[ne]==="closing"||this[ne]==="opening"?this.once(Nt,i?()=>n(i):n):this[ne]!=="open"?t(new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):t()};return e.passive?this[ne]==="opening"?this.once(Nt,n):this.nextTick(n):this[ne]==="closed"||this[so]?(this[so]=!1,this[ne]="opening",this.emit("opening"),this._open(e,i=>{if(i){this[ne]="closed",this[gc](()=>{this.emit(Nt),n(i)}),this[ni]();return}this[ne]="open",this[ni](),this.emit(Nt),this[ne]==="open"&&this.emit("open"),this[ne]==="open"&&this.emit("ready"),n()})):this[ne]==="open"?this.nextTick(n):this.once(Nt,()=>this.open(e,t)),t[Q]}_open(e,t){this.nextTick(t)}close(e){e=ir(e,Q);let t=n=>{this[ne]==="opening"||this[ne]==="closing"?this.once(Nt,n?t(n):t):this[ne]!=="closed"?e(new ot("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):e()};if(this[ne]==="open"){this[ne]="closing",this.emit("closing");let n=i=>{this[ne]="open",this[ni](),this.emit(Nt),t(i)};this[gc](()=>{this._close(i=>{if(i)return n(i);this[ne]="closed",this[ni](),this.emit(Nt),this[ne]==="closed"&&this.emit("closed"),t()})})}else this[ne]==="closed"?this.nextTick(t):this.once(Nt,()=>this.close(e));return e[Q]}[gc](e){if(this[Rr].size===0)return this.nextTick(e);let t=this[Rr].size,n=!0,i=()=>{--t===0&&(n?this.nextTick(e):e())};for(let o of this[Rr])o.close(i);n=!1,this[Rr].clear()}_close(e){this.nextTick(e)}get(e,t,n){if(n=Nr(t,n),n=ir(n,Q),t=or(t,this[Mr].entry),this[ne]==="opening")return this.defer(()=>this.get(e,t,n)),n[Q];if(dn(this,n))return n[Q];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[Q];let o=this.keyEncoding(t.keyEncoding),s=this.valueEncoding(t.valueEncoding),c=o.format,a=s.format;return(t.keyEncoding!==c||t.valueEncoding!==a)&&(t=Object.assign({},t,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(e),c),t,(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 ot("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[Q]}_get(e,t,n){this.nextTick(n,new Error("NotFound"))}getMany(e,t,n){if(n=Nr(t,n),n=ir(n,Q),t=or(t,this[Mr].entry),this[ne]==="opening")return this.defer(()=>this.getMany(e,t,n)),n[Q];if(dn(this,n))return n[Q];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[Q];if(e.length===0)return this.nextTick(n,null,[]),n[Q];let i=this.keyEncoding(t.keyEncoding),o=this.valueEncoding(t.valueEncoding),s=i.format,c=o.format;(t.keyEncoding!==s||t.valueEncoding!==c)&&(t=Object.assign({},t,{keyEncoding:s,valueEncoding:c}));let a=new Array(e.length);for(let u=0;u<e.length;u++){let f=e[u],l=this._checkKey(f);if(l)return this.nextTick(n,l),n[Q];a[u]=this.prefixKey(i.encode(f),s)}return this._getMany(a,t,(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 ot(`Could not decode one or more of ${f.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[Q]}_getMany(e,t,n){this.nextTick(n,null,new Array(e.length).fill(void 0))}put(e,t,n,i){if(i=Nr(n,i),i=ir(i,Q),n=or(n,this[Mr].entry),this[ne]==="opening")return this.defer(()=>this.put(e,t,n,i)),i[Q];if(dn(this,i))return i[Q];let o=this._checkKey(e)||this._checkValue(t);if(o)return this.nextTick(i,o),i[Q];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(e),a),l=c.encode(t);return this._put(f,l,n,h=>{if(h)return i(h);this.emit("put",e,t),i()}),i[Q]}_put(e,t,n,i){this.nextTick(i)}del(e,t,n){if(n=Nr(t,n),n=ir(n,Q),t=or(t,this[Mr].key),this[ne]==="opening")return this.defer(()=>this.del(e,t,n)),n[Q];if(dn(this,n))return n[Q];let i=this._checkKey(e);if(i)return this.nextTick(n,i),n[Q];let o=this.keyEncoding(t.keyEncoding),s=o.format;return t.keyEncoding!==s&&(t=Object.assign({},t,{keyEncoding:s})),this._del(this.prefixKey(o.encode(e),s),t,c=>{if(c)return n(c);this.emit("del",e),n()}),n[Q]}_del(e,t,n){this.nextTick(n)}batch(e,t,n){if(!arguments.length){if(this[ne]==="opening")return new uf(this);if(this[ne]!=="open")throw new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof e=="function"?n=e:n=Nr(t,n),n=ir(n,Q),t=or(t,this[Mr].empty),this[ne]==="opening")return this.defer(()=>this.batch(e,t,n)),n[Q];if(dn(this,n))return n[Q];if(!Array.isArray(e))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[Q];if(e.length===0)return this.nextTick(n),n[Q];let i=new Array(e.length),{keyEncoding:o,valueEncoding:s,...c}=t;for(let a=0;a<e.length;a++){if(typeof e[a]!="object"||e[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[Q];let u=Object.assign({},e[a]);if(u.type!=="put"&&u.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[Q];let f=this._checkKey(u.key);if(f)return this.nextTick(n,f),n[Q];let l=u.sublevel!=null?u.sublevel:this,h=l.keyEncoding(u.keyEncoding||o),m=h.format;if(u.key=l.prefixKey(h.encode(u.key),m),u.keyEncoding=m,u.type==="put"){let p=this._checkValue(u.value);if(p)return this.nextTick(n,p),n[Q];let d=l.valueEncoding(u.valueEncoding||s);u.value=d.encode(u.value),u.valueEncoding=d.format}l!==this&&(u.sublevel=null),i[a]=u}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",e),n()}),n[Q]}_batch(e,t,n){this.nextTick(n)}sublevel(e,t){return this._sublevel(e,bc.defaults(t))}_sublevel(e,t){return new bc(this,e,t)}prefixKey(e,t){return e}clear(e,t){if(t=Nr(e,t),t=ir(t,Q),e=or(e,this[Mr].empty),this[ne]==="opening")return this.defer(()=>this.clear(e,t)),t[Q];if(dn(this,t))return t[Q];let n=e,i=this.keyEncoding(e.keyEncoding);return e=oo(e,i),e.keyEncoding=i.format,e.limit===0?this.nextTick(t):this._clear(e,o=>{if(o)return t(o);this.emit("clear",n),t()}),t[Q]}_clear(e,t){this.nextTick(t)}iterator(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=oo(e,t),e.keys=e.keys!==!1,e.values=e.values!==!1,e[Lr.keyEncoding]=t,e[Lr.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ne]==="opening")return new my(this,e);if(this[ne]!=="open")throw new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(e)}_iterator(e){return new Lr(this,e)}keys(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=oo(e,t),e[Lr.keyEncoding]=t,e[Lr.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ne]==="opening")return new wy(this,e);if(this[ne]!=="open")throw new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(e)}_keys(e){return new py(this,e)}values(e){let t=this.keyEncoding(e&&e.keyEncoding),n=this.valueEncoding(e&&e.valueEncoding);if(e=oo(e,t),e[Lr.keyEncoding]=t,e[Lr.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this[ne]==="opening")return new gy(this,e);if(this[ne]!=="open")throw new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(e)}_values(e){return new yy(this,e)}defer(e){if(typeof e!="function")throw new TypeError("The first argument must be a function");this[ri].push(e)}[ni](){if(this[ri].length===0)return;let e=this[ri];this[ri]=[];for(let t of e)t()}attachResource(e){if(typeof e!="object"||e===null||typeof e.close!="function")throw new TypeError("The first argument must be a resource object");this[Rr].add(e)}detachResource(e){this[Rr].delete(e)}_chainedBatch(){return new uf(this)}_checkKey(e){if(e==null)return new ot("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(e){if(e==null)return new ot("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};ii.prototype.nextTick=rf();var{AbstractSublevel:bc}=af()({AbstractLevel:ii});Ec.AbstractLevel=ii;Ec.AbstractSublevel=bc;var dn=function(r,e){return r[ne]!=="open"?(r.nextTick(e,new ot("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},by=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])}});var vc=ie(Dr=>{"use strict";Dr.AbstractLevel=Ac().AbstractLevel;Dr.AbstractSublevel=Ac().AbstractSublevel;Dr.AbstractIterator=rr().AbstractIterator;Dr.AbstractKeyIterator=rr().AbstractKeyIterator;Dr.AbstractValueIterator=rr().AbstractValueIterator;Dr.AbstractChainedBatch=fc().AbstractChainedBatch});var df=ie((Og,lf)=>{lf.exports=Ay;var Ey=dc();function Ay(r,e,t){if(typeof e!="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(h){function m(){t&&t(h,n),t=null}a?Ey(m):m()}function l(h,m,p){if(n[h]=p,m&&(c=!0),--o===0||m)f(m);else if(!c&&u<i){let d;s?(d=s[u],u+=1,r[d](function(y,w){l(d,y,w)})):(d=u,u+=1,r[d](function(y,w){l(d,y,w)}))}}u=e,o?s?s.some(function(h,m){return r[h](function(p,d){l(h,p,d)}),m===e-1}):r.some(function(h,m){return h(function(p,d){l(m,p,d)}),m===e-1}):f(null),a=!1}});var Bc=ie((Lg,hf)=>{"use strict";hf.exports=function(e){let t=e.gte!==void 0?e.gte:e.gt!==void 0?e.gt:void 0,n=e.lte!==void 0?e.lte:e.lt!==void 0?e.lt:void 0,i=e.gte===void 0,o=e.lte===void 0;return t!==void 0&&n!==void 0?IDBKeyRange.bound(t,n,i,o):t!==void 0?IDBKeyRange.lowerBound(t,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var Sc=ie((Ng,pf)=>{"use strict";var vy=new TextEncoder;pf.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):vy.encode(r)}});var xf=ie(gf=>{"use strict";var{AbstractIterator:By}=vc(),yf=Bc(),ao=Sc(),bt=Symbol("cache"),Rt=Symbol("finished"),Re=Symbol("options"),Mt=Symbol("currentOptions"),Hr=Symbol("position"),kc=Symbol("location"),hn=Symbol("first"),mf={},Tc=class extends By{constructor(e,t,n){super(e,n),this[bt]=[],this[Rt]=this.limit===0,this[Re]=n,this[Mt]={...n},this[Hr]=void 0,this[kc]=t,this[hn]=!0}_nextv(e,t,n){if(this[hn]=!1,this[Rt])return this.nextTick(n,null,[]);if(this[bt].length>0)return e=Math.min(e,this[bt].length),this.nextTick(n,null,this[bt].splice(0,e));this[Hr]!==void 0&&(this[Re].reverse?(this[Mt].lt=this[Hr],this[Mt].lte=void 0):(this[Mt].gt=this[Hr],this[Mt].gte=void 0));let i;try{i=yf(this[Mt])}catch{return this[Rt]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[kc]],"readonly"),s=o.objectStore(this[kc]),c=[];if(this[Re].reverse){let a=!this[Re].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=u=>{let f=u.target.result;if(f){let{key:l,value:h}=f;this[Hr]=l,c.push([this[Re].keys&&l!==void 0?ao(l):void 0,this[Re].values&&h!==void 0?ao(h):void 0]),c.length<e?f.continue():wf(o)}else this[Rt]=!0}}else{let a,u,f=()=>{if(a===void 0||u===void 0)return;let l=Math.max(a.length,u.length);l===0||e===1/0?this[Rt]=!0:this[Hr]=a[l-1],c.length=l;for(let h=0;h<l;h++){let m=a[h],p=u[h];c[h]=[this[Re].keys&&m!==void 0?ao(m):void 0,this[Re].values&&p!==void 0?ao(p):void 0]}wf(o)};this[Re].keys||e<1/0?s.getAllKeys(i,e<1/0?e:void 0).onsuccess=l=>{a=l.target.result,f()}:(a=[],this.nextTick(f)),this[Re].values?s.getAll(i,e<1/0?e: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(e){if(this[bt].length>0){let[t,n]=this[bt].shift();this.nextTick(e,null,t,n)}else if(this[Rt])this.nextTick(e);else{let t=Math.min(100,this.limit-this.count);this[hn]&&(this[hn]=!1,t=1),this._nextv(t,mf,(n,i)=>{if(n)return e(n);this[bt]=i,this._next(e)})}}_all(e,t){this[hn]=!1;let n=this[bt].splice(0,this[bt].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(t,null,n);this._nextv(i,mf,(o,s)=>{if(o)return t(o);n.length>0&&(s=n.concat(s)),t(null,s)})}_seek(e,t){this[hn]=!0,this[bt]=[],this[Rt]=!1,this[Hr]=void 0,this[Mt]={...this[Re]};let n;try{n=yf(this[Re])}catch{this[Rt]=!0;return}n!==null&&!n.includes(e)?this[Rt]=!0:this[Re].reverse?this[Mt].lte=e:this[Mt].gte=e}};gf.Iterator=Tc;function wf(r){typeof r.commit=="function"&&r.commit()}});var Ef=ie((Mg,bf)=>{"use strict";bf.exports=function(e,t,n,i,o){if(i.limit===0)return e.nextTick(o);let s=e.db.transaction([t],"readwrite"),c=s.objectStore(t),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 h=l.target.result;h&&(c.delete(h.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&h.continue()})}}});var Tf=ie(kf=>{"use strict";var{AbstractLevel:Sy}=vc(),Af=nt(),ky=df(),{fromCallback:Ty}=Vn(),{Iterator:Py}=xf(),vf=Sc(),Uy=Ef(),Ky=Bc(),Sf="level-js-",oi=Symbol("idb"),Pc=Symbol("namePrefix"),Dt=Symbol("location"),Uc=Symbol("version"),jr=Symbol("store"),si=Symbol("onComplete"),Bf=Symbol("promise"),uo=class extends Sy{constructor(e,t,n){if(typeof t=="function"||typeof n=="function")throw new Af("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=t||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof e!="string")throw new Error("constructor requires a location string argument");this[Dt]=e,this[Pc]=i??Sf,this[Uc]=parseInt(o||1,10),this[oi]=null}get location(){return this[Dt]}get namePrefix(){return this[Pc]}get version(){return this[Uc]}get db(){return this[oi]}get type(){return"browser-level"}_open(e,t){let n=indexedDB.open(this[Pc]+this[Dt],this[Uc]);n.onerror=function(){t(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[oi]=n.result,t()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Dt])||o.createObjectStore(this[Dt])}}[jr](e){return this[oi].transaction([this[Dt]],e).objectStore(this[Dt])}[si](e,t){let n=e.transaction;n.onabort=function(){t(n.error||new Error("aborted by user"))},n.oncomplete=function(){t(null,e.result)}}_get(e,t,n){let i=this[jr]("readonly"),o;try{o=i.get(e)}catch(s){return this.nextTick(n,s)}this[si](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new Af("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,vf(c))})}_getMany(e,t,n){let i=this[jr]("readonly"),o=e.map(s=>c=>{let a;try{a=i.get(s)}catch(u){return c(u)}a.onsuccess=()=>{let u=a.result;c(null,u===void 0?u:vf(u))},a.onerror=u=>{u.stopPropagation(),c(a.error)}});ky(o,16,n)}_del(e,t,n){let i=this[jr]("readwrite"),o;try{o=i.delete(e)}catch(s){return this.nextTick(n,s)}this[si](o,n)}_put(e,t,n,i){let o=this[jr]("readwrite"),s;try{s=o.put(t,e)}catch(c){return this.nextTick(i,c)}this[si](s,i)}_iterator(e){return new Py(this,this[Dt],e)}_batch(e,t,n){let i=this[jr]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let u=e[s++],f=u.key,l;try{l=u.type==="del"?i.delete(f):i.put(u.value,f)}catch(h){c=h,o.abort();return}s<e.length?l.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(e,t){let n,i;try{n=Ky(e)}catch{return this.nextTick(t)}if(e.limit>=0)return Uy(this,this[Dt],n,e,t);try{let o=this[jr]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(t,o)}this[si](i,t)}_close(e){this[oi].close(),this.nextTick(e)}};uo.destroy=function(r,e,t){typeof e=="function"&&(t=e,e=Sf),t=Ty(t,Bf);let n=indexedDB.deleteDatabase(e+r);return n.onsuccess=function(){t()},n.onerror=function(i){t(i)},t[Bf]};kf.BrowserLevel=uo});var Uf=ie(Pf=>{Pf.Level=Tf().BrowserLevel});var V=class r extends Error{constructor(t,n){super(n);this.code=t;this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},Wt=(c=>(c.AlgorithmNotSupported="algorithmNotSupported",c.EncodingError="encodingError",c.InvalidCoseSign1="invalidCoseSign1",c.InvalidEat="invalidEat",c.InvalidJwe="invalidJwe",c.InvalidJwk="invalidJwk",c.OperationNotSupported="operationNotSupported",c))(Wt||{});var bh=Ha($a(),1);var dw=new Uint8Array(0);function Ja(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Xr(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 Ah(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(t[s]!==255)throw new TypeError(o+" is ambiguous");t[s]=i}var c=r.length,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 d=0,y=0,w=0,E=p.length;w!==E&&p[w]===0;)w++,d++;for(var b=(E-w)*f+1>>>0,x=new Uint8Array(b);w!==E;){for(var B=p[w],T=0,K=b-1;(B!==0||T<y)&&K!==-1;K--,T++)B+=256*x[K]>>>0,x[K]=B%c>>>0,B=B/c>>>0;if(B!==0)throw new Error("Non-zero carry");y=T,w++}for(var P=b-y;P!==b&&x[P]===0;)P++;for(var M=a.repeat(d);P<b;++P)M+=r.charAt(x[P]);return M}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var d=0;if(p[d]!==" "){for(var y=0,w=0;p[d]===a;)y++,d++;for(var E=(p.length-d)*u+1>>>0,b=new Uint8Array(E);p[d];){var x=t[p.charCodeAt(d)];if(x===255)return;for(var B=0,T=E-1;(x!==0||B<w)&&T!==-1;T--,B++)x+=c*b[T]>>>0,b[T]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");w=B,d++}if(p[d]!==" "){for(var K=E-w;K!==E&&b[K]===0;)K++;for(var P=new Uint8Array(y+(E-K)),M=y;K!==E;)P[M++]=b[K++];return P}}}function m(p){var d=h(p);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:m}}var vh=Ah,Bh=vh,Fa=Bh;var ms=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ws=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Va(this,e)}},gs=class{decoders;constructor(e){this.decoders=e}or(e){return Va(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Va(r,e){return new gs({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var xs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new ms(e,t,n),this.decoder=new ws(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ga({name:r,prefix:e,encode:t,decode:n}){return new xs(r,e,t,n)}function bs({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Fa(t,r);return Ga({prefix:e,name:r,encode:n,decode:o=>Xr(i(o))})}function Sh(r,e,t,n){let i={};for(let f=0;f<e.length;++f)i[e[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/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<<t|l,c+=t,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=t||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function kh(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>t;)s-=t,o+=e[i&c>>s];if(s!==0&&(o+=e[i&c<<t-s]),n)for(;o.length*t&7;)o+="=";return o}function ke({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ga({prefix:e,name:r,encode(i){return kh(i,n,t)},decode(i){return Sh(i,n,t,r)}})}var _n=ke({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),gw=ke({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),xw=ke({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bw=ke({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ew=ke({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Aw=ke({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),vw=ke({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bw=ke({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Es=ke({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ie=bs({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Tw=bs({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Kw=ke({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Iw=ke({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pt=ke({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cw=ke({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function qa(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function za(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function On(r){let t=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=t;return i}var Ln=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(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,e||[])).next())})},Wa=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=r[o]&&function(s){return new Promise(function(c,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)}},_i=new TextEncoder,vr=new TextDecoder,_=class r{constructor(e,t){this.data=e,this.format=t}static arrayBuffer(e){return new r(e,"ArrayBuffer")}static asyncIterable(e){if(!za(e))throw new TypeError("Input must be of type AsyncIterable.");return new r(e,"AsyncIterable")}static base32Z(e){return new r(e,"Base32Z")}static base58Btc(e){return new r(e,"Base58Btc")}static base64Url(e){return new r(e,"Base64Url")}static bufferSource(e){return new r(e,"BufferSource")}static hex(e){if(typeof e!="string")throw new TypeError("Hex input must be a string.");if(e.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new r(e,"Hex")}static multibase(e){return new r(e,"Multibase")}static object(e){return new r(e,"Object")}static string(e){return new r(e,"String")}static uint8Array(e){return new r(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return Ie.baseDecode(this.data).buffer;case"Base64Url":return pt.baseDecode(this.data).buffer;case"BufferSource":{if(On(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return qa(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 Ln(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 Es.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Ie.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return Ie.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return pt.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return pt.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),t=_i.encode(e);return pt.baseEncode(t)}case"String":{let e=_i.encode(this.data);return pt.baseEncode(e)}case"Uint8Array":return pt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return Ln(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=Wa(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let f=i;a.push(f)}}catch(f){t={error:f}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(t)throw t.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(t,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let t=this.toUint8Array();return r.uint8Array(t).toHex()}case"Base64Url":{let t=this.toUint8Array();return r.uint8Array(t).toHex()}case"Uint8Array":{let t="";for(let n=0;n<this.data.length;n++)t+=e[this.data[n]];return t}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let e=pt.baseDecode(this.data),t=vr.decode(e);return JSON.parse(t)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=vr.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return Ln(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toStringAsync();return JSON.parse(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return vr.decode(this.data);case"Base64Url":{let e=pt.baseDecode(this.data);return vr.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return vr.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return Ln(this,void 0,void 0,function*(){var e,t,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=Wa(this.data),c;c=yield s.next(),e=c.done,!e;o=!0){i=c.value,o=!1;let u=i;typeof u=="string"?a+=u:a+=vr.decode(u,{stream:!0})}}catch(u){t={error:u}}finally{try{!o&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(t)throw t.error}}return a+=vr.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 Es.baseDecode(this.data);case"Base58Btc":return Ie.baseDecode(this.data);case"Base64Url":return pt.baseDecode(this.data);case"BufferSource":{let e=On(this.data);if(e==="Uint8Array")return this.data;if(e==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let e=new Uint8Array(this.data.length/2);for(let t=0;t<this.data.length;t+=2){let n=parseInt(this.data.substring(t,t+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[t/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return _i.encode(e)}case"String":return _i.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return Ln(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toArrayBufferAsync();return new Uint8Array(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};var Nn;(function(r){r.Debug="debug",r.Silent="silent"})(Nn||(Nn={}));var As=class{constructor(){this.logLevel=Nn.Silent}setLogLevel(e){this.logLevel=e}log(e){this.info(e)}info(e){this.logLevel!==Nn.Silent&&console.info(e)}error(e){this.logLevel!==Nn.Silent&&console.error(e)}},Th=new As;typeof window<"u"&&(window.web5logger=Th);var It={};Da(It,{decode:()=>Zr,encodeTo:()=>Br,encodingLength:()=>Sr});var Ph=Ya,Xa=128,Uh=127,Kh=~Uh,Ih=Math.pow(2,31);function Ya(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Ih;)e[t++]=r&255|Xa,r/=128;for(;r&Kh;)e[t++]=r&255|Xa,r>>>=7;return e[t]=r|0,Ya.bytes=t-n+1,e}var Ch=vs,_h=128,Za=127;function vs(r,n){var t=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw vs.bytes=0,new RangeError("Could not decode varint");s=r[o++],t+=i<28?(s&Za)<<i:(s&Za)*Math.pow(2,i),i+=7}while(s>=_h);return vs.bytes=o-n,t}var Oh=Math.pow(2,7),Lh=Math.pow(2,14),Nh=Math.pow(2,21),Rh=Math.pow(2,28),Mh=Math.pow(2,35),Dh=Math.pow(2,42),Hh=Math.pow(2,49),jh=Math.pow(2,56),$h=Math.pow(2,63),Jh=function(r){return r<Oh?1:r<Lh?2:r<Nh?3:r<Rh?4:r<Mh?5:r<Dh?6:r<Hh?7:r<jh?8:r<$h?9:10},Fh={encode:Ph,decode:Ch,encodingLength:Jh},Vh=Fh,Rn=Vh;function Zr(r,e=0){return[Rn.decode(r,e),Rn.decode.bytes]}function Br(r,e,t=0){return Rn.encode(r,e,t),e}function Sr(r){return Rn.encodingLength(r)}function Bs(r,e){let t=e.byteLength,n=Sr(r),i=n+Sr(t),o=new Uint8Array(i+t);return Br(r,o,0),Br(t,o,n),o.set(e,i),new Yr(r,t,e,o)}function Qa(r){let e=Xr(r),[t,n]=Zr(e),[i,o]=Zr(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Yr(t,i,s,e)}function eu(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ja(r.bytes,t.bytes)}}var Yr=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};function tu(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return qh(t,ks(r),e??Ie.encoder);default:return zh(t,ks(r),e??_n.encoder)}}var ru=new WeakMap;function ks(r){let e=ru.get(r);if(e==null){let t=new Map;return ru.set(r,t),t}return e}var Ts=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Mn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Wh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=Bs(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&eu(e.multihash,n.multihash)}toString(e){return tu(this,e)}toJSON(){return{"/":tu(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:s}=t;return new r(n,i,o,s??nu(n,i,o.bytes))}else if(t[Xh]===!0){let{version:n,multihash:i,code:o}=t,s=Qa(i);return r.create(n,o,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Mn)throw new Error(`Version 0 CID must use dag-pb (code: ${Mn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=nu(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Mn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=Xr(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),s=new Yr(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[l,h]=Zr(e.subarray(t));return t+=h,l},i=n(),o=Mn;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=t,c=n(),a=n(),u=t+a,f=u-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(e,t){let[n,i]=Gh(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ks(o).set(n,e),o}};function Gh(r,e){switch(r[0]){case"Q":{let t=e??Ie;return[Ie.prefix,t.decode(`${Ie.prefix}${r}`)]}case Ie.prefix:{let t=e??Ie;return[Ie.prefix,t.decode(r)]}case _n.prefix:{let t=e??_n;return[_n.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function qh(r,e,t){let{prefix:n}=t;if(n!==Ie.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}function zh(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}var Mn=112,Wh=18;function nu(r,e,t){let n=Sr(r),i=n+Sr(e),o=new Uint8Array(i+t.byteLength);return Br(r,o,0),Br(e,o,n),o.set(t,i),o}var Xh=Symbol.for("@ipld/js-cid/CID");var yt=class r{static addPrefix(e){var t;let{code:n,data:i,name:o}=e;if(!(o?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=r.codeToName.has(n)?n:r.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(t=e.name)!==null&&t!==void 0?t:e.code}`);let s=It.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),It.encodeTo(n,c),c}static getCodeFromData(e){let{prefixedData:t}=e,[n,i]=It.decode(t);return n}static getCodeFromName(e){let{name:t}=e,n=r.nameToCode.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static getNameFromCode(e){let{code:t}=e,n=r.codeToName.get(t);if(n===void 0)throw new Error(`Unsupported multicodec: ${t}`);return n}static registerCodec(e){r.codeToName.set(e.code,e.name),r.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:t}=e,[n,i]=It.decode(t),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:t.slice(i),name:o}}};yt.codeToName=new Map;yt.nameToCode=new Map;yt.registerCodec({code:237,name:"ed25519-pub"});yt.registerCodec({code:4864,name:"ed25519-priv"});yt.registerCodec({code:236,name:"x25519-pub"});yt.registerCodec({code:4866,name:"x25519-priv"});yt.registerCodec({code:231,name:"secp256k1-pub"});yt.registerCodec({code:4865,name:"secp256k1-priv"});function Ps(r){Object.keys(r).forEach(e=>{r[e]===void 0?delete r[e]:typeof r[e]=="object"&&Ps(r[e])})}var Iy=Ha(Uf(),1),$r=function(r,e,t,n){function i(o){return o instanceof t?o:new t(function(s){s(o)})}return new(t||(t=Promise))(function(o,s){function c(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,e||[])).next())})};var fo=class{constructor(){this.store=new Map}clear(){return $r(this,void 0,void 0,function*(){this.store.clear()})}close(){return $r(this,void 0,void 0,function*(){})}delete(e){return $r(this,void 0,void 0,function*(){return this.store.delete(e)})}get(e){return $r(this,void 0,void 0,function*(){return this.store.get(e)})}has(e){return $r(this,void 0,void 0,function*(){return this.store.has(e)})}list(){return $r(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(e,t){return $r(this,void 0,void 0,function*(){this.store.set(e,t)})}};var ye=class{};var ho={};Da(ho,{bitGet:()=>My,bitLen:()=>Ry,bitMask:()=>ci,bitSet:()=>Dy,bytesToHex:()=>jt,bytesToNumberBE:()=>$t,bytesToNumberLE:()=>ct,concatBytes:()=>Ft,createHmacDrbg:()=>Cc,ensureBytes:()=>ue,equalBytes:()=>Ly,hexToBytes:()=>Jr,hexToNumber:()=>Ic,isBytes:()=>st,numberToBytesBE:()=>Oe,numberToBytesLE:()=>Jt,numberToHexUnpadded:()=>_f,numberToVarBytesBE:()=>Oy,utf8ToBytes:()=>Ny,validateObject:()=>We});var Cf=BigInt(0),lo=BigInt(1),Cy=BigInt(2);function st(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var _y=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function jt(r){if(!st(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=_y[r[t]];return e}function _f(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Ic(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Ht={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function Kf(r){if(r>=Ht._0&&r<=Ht._9)return r-Ht._0;if(r>=Ht._A&&r<=Ht._F)return r-(Ht._A-10);if(r>=Ht._a&&r<=Ht._f)return r-(Ht._a-10)}function Jr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=Kf(r.charCodeAt(o)),c=Kf(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 $t(r){return Ic(jt(r))}function ct(r){if(!st(r))throw new Error("Uint8Array expected");return Ic(jt(Uint8Array.from(r).reverse()))}function Oe(r,e){return Jr(r.toString(16).padStart(e*2,"0"))}function Jt(r,e){return Oe(r,e).reverse()}function Oy(r){return Jr(_f(r))}function ue(r,e,t){let n;if(typeof e=="string")try{n=Jr(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(st(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function Ft(...r){let e=0;for(let i=0;i<r.length;i++){let o=r[i];if(!st(o))throw new Error("Uint8Array expected");e+=o.length}let t=new Uint8Array(e),n=0;for(let i=0;i<r.length;i++){let o=r[i];t.set(o,n),n+=o.length}return t}function Ly(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function Ny(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ry(r){let e;for(e=0;r>Cf;r>>=lo,e+=1);return e}function My(r,e){return r>>BigInt(e)&lo}var Dy=(r,e,t)=>r|(t?lo:Cf)<<BigInt(e),ci=r=>(Cy<<BigInt(r-1))-lo,Kc=r=>new Uint8Array(r),If=r=>Uint8Array.from(r);function Cc(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=Kc(r),i=Kc(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>t(i,n,...l),a=(l=Kc())=>{i=c(If([0]),l),n=c(),l.length!==0&&(i=c(If([1]),l),n=c())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<e;){n=c();let m=n.slice();h.push(m),l+=n.length}return Ft(...h)};return(l,h)=>{s(),a(l);let m;for(;!(m=h(u()));)a();return s(),m}}var Hy={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"||st(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function We(r,e,t={}){let n=(i,o,s)=>{let c=Hy[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(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}function Of(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function jy(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function _c(r,...e){if(!jy(r))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Lf(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Of(r.outputLen),Of(r.blockLen)}function pn(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Nf(r,e){_c(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var po=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Rf(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var yo=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),at=(r,e)=>r<<32-e|r>>>e,$y=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!$y)throw new Error("Non little-endian hardware is not supported");function Oc(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ai(r){if(typeof r=="string"&&(r=Oc(r)),!Rf(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function mo(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Rf(i))throw new Error("Uint8Array expected");e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var yn=class{clone(){return this._cloneInto()}},nx={}.toString;function wo(r){let e=n=>r().update(ai(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ui(r=32){if(po&&typeof po.getRandomValues=="function")return po.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Jy(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),c=Number(t&o),a=n?4:0,u=n?0:4;r.setUint32(e+a,s,n),r.setUint32(e+u,c,n)}var mn=class extends yn{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=yo(this.buffer)}update(e){pn(this);let{view:t,buffer:n,blockLen:i}=this;e=ai(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=yo(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){pn(this),Nf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;Jy(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=yo(e),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:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var Fy=(r,e,t)=>r&e^~r&t,Vy=(r,e,t)=>r&e^r&t^e&t,Gy=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]),sr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),cr=new Uint32Array(64),Lc=class extends mn{constructor(){super(64,32,8,!1),this.A=sr[0]|0,this.B=sr[1]|0,this.C=sr[2]|0,this.D=sr[3]|0,this.E=sr[4]|0,this.F=sr[5]|0,this.G=sr[6]|0,this.H=sr[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,t,n,i,o,s,c,a]}set(e,t,n,i,o,s,c,a){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,t){for(let l=0;l<16;l++,t+=4)cr[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=cr[l-15],m=cr[l-2],p=at(h,7)^at(h,18)^h>>>3,d=at(m,17)^at(m,19)^m>>>10;cr[l]=d+cr[l-7]+p+cr[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 h=at(c,6)^at(c,11)^at(c,25),m=f+h+Fy(c,a,u)+Gy[l]+cr[l]|0,d=(at(n,2)^at(n,13)^at(n,22))+Vy(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+d|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(){cr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var go=wo(()=>new Lc);var we=BigInt(0),de=BigInt(1),Fr=BigInt(2),qy=BigInt(3),Nc=BigInt(4),Mf=BigInt(5),Df=BigInt(8),zy=BigInt(9),Wy=BigInt(16);function se(r,e){let t=r%e;return t>=we?t:e+t}function Rc(r,e,t){if(t<=we||e<we)throw new Error("Expected power/modulo > 0");if(t===de)return we;let n=de;for(;e>we;)e&de&&(n=n*r%t),r=r*r%t,e>>=de;return n}function fe(r,e,t){let n=r;for(;e-- >we;)n*=n,n%=t;return n}function xo(r,e){if(r===we||e<=we)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=se(r,e),n=e,i=we,o=de,s=de,c=we;for(;t!==we;){let u=n/t,f=n%t,l=i-s*u,h=o-c*u;n=t,t=f,i=s,o=c,s=l,c=h}if(n!==de)throw new Error("invert: does not exist");return se(i,e)}function Xy(r){let e=(r-de)/Fr,t,n,i;for(t=r-de,n=0;t%Fr===we;t/=Fr,n++);for(i=Fr;i<r&&Rc(i,e,r)!==r-de;i++);if(n===1){let s=(r+de)/Nc;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=(t+de)/Fr;return function(c,a){if(c.pow(a,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,f=c.pow(c.mul(c.ONE,i),t),l=c.pow(a,o),h=c.pow(a,t);for(;!c.eql(h,c.ONE);){if(c.eql(h,c.ZERO))return c.ZERO;let m=1;for(let d=c.sqr(h);m<u&&!c.eql(d,c.ONE);m++)d=c.sqr(d);let p=c.pow(f,de<<BigInt(u-m-1));f=c.sqr(p),l=c.mul(l,p),h=c.mul(h,f),u=m}return l}}function Zy(r){if(r%Nc===qy){let e=(r+de)/Nc;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Df===Mf){let e=(r-Mf)/Df;return function(n,i){let o=n.mul(i,Fr),s=n.pow(o,e),c=n.mul(i,s),a=n.mul(n.mul(c,Fr),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%Wy,Xy(r)}var Hf=(r,e)=>(se(r,e)&de)===de,Yy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mc(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Yy.reduce((n,i)=>(n[i]="function",n),e);return We(r,t)}function Qy(r,e,t){if(t<we)throw new Error("Expected power > 0");if(t===we)return r.ONE;if(t===de)return e;let n=r.ONE,i=e;for(;t>we;)t&de&&(n=r.mul(n,i)),i=r.sqr(i),t>>=de;return n}function e0(r,e){let t=new Array(e.length),n=e.reduce((o,s,c)=>r.is0(s)?o:(t[c]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,c)=>r.is0(s)?o:(t[c]=r.mul(o,t[c]),r.mul(o,s)),i),t}function Dc(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function wn(r,e,t=!1,n={}){if(r<=we)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Dc(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Zy(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:ci(i),ZERO:we,ONE:de,create:a=>se(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return we<=a&&a<r},is0:a=>a===we,isOdd:a=>(a&de)===de,neg:a=>se(-a,r),eql:(a,u)=>a===u,sqr:a=>se(a*a,r),add:(a,u)=>se(a+u,r),sub:(a,u)=>se(a-u,r),mul:(a,u)=>se(a*u,r),pow:(a,u)=>Qy(c,a,u),div:(a,u)=>se(a*xo(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>xo(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>e0(c,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>t?Jt(a,o):Oe(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return t?ct(a):$t(a)}});return Object.freeze(c)}function jf(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}function $f(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Hc(r){let e=$f(r);return e+Math.ceil(e/2)}function Jf(r,e,t=!1){let n=r.length,i=$f(e),o=Hc(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=t?$t(r):ct(r),c=se(s,e-de)+de;return t?Jt(c,i):Oe(c,i)}var r0=BigInt(0),jc=BigInt(1);function bo(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,c=i;for(;o>r0;)o&jc&&(s=s.add(c)),c=c.double(),o>>=jc;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 h=1;h<c;h++)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),h=2**i,m=BigInt(i);for(let p=0;p<c;p++){let d=p*a,y=Number(s&l);s>>=m,y>a&&(y-=h,s+=jc);let w=d,E=d+Math.abs(y)-1,b=p%2!==0,x=y<0;y===0?f=f.add(t(b,o[w])):u=u.add(t(x,o[E]))}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 fi(r){return Mc(r.Fp),We(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Dc(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function n0(r){let e=fi(r);We(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:i}=e;if(t){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:i0,hexToBytes:o0}=ho,Vr={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=Vr;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:i0(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=Vr,t=typeof r=="string"?o0(r):r;if(!st(t))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=Vr._parseInt(t.subarray(2)),{d:s,l:c}=Vr._parseInt(o);if(c.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=e(t(r.s)),i=e(t(r.r)),o=n.length/2,s=i.length/2,c=t(o),a=t(s);return`30${t(s+o+4)}02${a}${i}02${c}${n}`}},Vt=BigInt(0),Xe=BigInt(1),gx=BigInt(2),Ff=BigInt(3),xx=BigInt(4);function s0(r){let e=n0(r),{Fp:t}=e,n=e.toBytes||((p,d,y)=>{let w=d.toAffine();return Ft(Uint8Array.from([4]),t.toBytes(w.x),t.toBytes(w.y))}),i=e.fromBytes||(p=>{let d=p.subarray(1),y=t.fromBytes(d.subarray(0,t.BYTES)),w=t.fromBytes(d.subarray(t.BYTES,2*t.BYTES));return{x:y,y:w}});function o(p){let{a:d,b:y}=e,w=t.sqr(p),E=t.mul(w,p);return t.add(t.add(E,t.mul(p,d)),y)}if(!t.eql(t.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Vt<p&&p<e.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){let{allowedPrivateKeyLengths:d,nByteLength:y,wrapPrivateKey:w,n:E}=e;if(d&&typeof p!="bigint"){if(st(p)&&(p=jt(p)),typeof p!="string"||!d.includes(p.length))throw new Error("Invalid key");p=p.padStart(y*2,"0")}let b;try{b=typeof p=="bigint"?p:$t(ue("private key",p,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof p}`)}return w&&(b=se(b,E)),c(b),b}let u=new Map;function f(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(d,y,w){if(this.px=d,this.py=y,this.pz=w,d==null||!t.isValid(d))throw new Error("x required");if(y==null||!t.isValid(y))throw new Error("y required");if(w==null||!t.isValid(w))throw new Error("z required")}static fromAffine(d){let{x:y,y:w}=d||{};if(!d||!t.isValid(y)||!t.isValid(w))throw new Error("invalid affine point");if(d instanceof l)throw new Error("projective point not allowed");let E=b=>t.eql(b,t.ZERO);return E(y)&&E(w)?l.ZERO:new l(y,w,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let y=t.invertBatch(d.map(w=>w.pz));return d.map((w,E)=>w.toAffine(y[E])).map(l.fromAffine)}static fromHex(d){let y=l.fromAffine(i(ue("pointHex",d)));return y.assertValidity(),y}static fromPrivateKey(d){return l.BASE.multiply(a(d))}_setWindowSize(d){this._WINDOW_SIZE=d,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:d,y}=this.toAffine();if(!t.isValid(d)||!t.isValid(y))throw new Error("bad point: x or y not FE");let w=t.sqr(y),E=o(d);if(!t.eql(w,E))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(t.isOdd)return!t.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:y,py:w,pz:E}=this,{px:b,py:x,pz:B}=d,T=t.eql(t.mul(y,B),t.mul(b,E)),K=t.eql(t.mul(w,B),t.mul(x,E));return T&&K}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:d,b:y}=e,w=t.mul(y,Ff),{px:E,py:b,pz:x}=this,B=t.ZERO,T=t.ZERO,K=t.ZERO,P=t.mul(E,E),M=t.mul(b,b),D=t.mul(x,x),L=t.mul(E,b);return L=t.add(L,L),K=t.mul(E,x),K=t.add(K,K),B=t.mul(d,K),T=t.mul(w,D),T=t.add(B,T),B=t.sub(M,T),T=t.add(M,T),T=t.mul(B,T),B=t.mul(L,B),K=t.mul(w,K),D=t.mul(d,D),L=t.sub(P,D),L=t.mul(d,L),L=t.add(L,K),K=t.add(P,P),P=t.add(K,P),P=t.add(P,D),P=t.mul(P,L),T=t.add(T,P),D=t.mul(b,x),D=t.add(D,D),P=t.mul(D,L),B=t.sub(B,P),K=t.mul(D,M),K=t.add(K,K),K=t.add(K,K),new l(B,T,K)}add(d){f(d);let{px:y,py:w,pz:E}=this,{px:b,py:x,pz:B}=d,T=t.ZERO,K=t.ZERO,P=t.ZERO,M=e.a,D=t.mul(e.b,Ff),L=t.mul(y,b),J=t.mul(w,x),$=t.mul(E,B),ee=t.add(y,w),S=t.add(b,x);ee=t.mul(ee,S),S=t.add(L,J),ee=t.sub(ee,S),S=t.add(y,E);let I=t.add(b,B);return S=t.mul(S,I),I=t.add(L,$),S=t.sub(S,I),I=t.add(w,E),T=t.add(x,B),I=t.mul(I,T),T=t.add(J,$),I=t.sub(I,T),P=t.mul(M,S),T=t.mul(D,$),P=t.add(T,P),T=t.sub(J,P),P=t.add(J,P),K=t.mul(T,P),J=t.add(L,L),J=t.add(J,L),$=t.mul(M,$),S=t.mul(D,S),J=t.add(J,$),$=t.sub(L,$),$=t.mul(M,$),S=t.add(S,$),L=t.mul(J,S),K=t.add(K,L),L=t.mul(I,S),T=t.mul(ee,T),T=t.sub(T,L),L=t.mul(ee,J),P=t.mul(I,P),P=t.add(P,L),new l(T,K,P)}subtract(d){return this.add(d.negate())}is0(){return this.equals(l.ZERO)}wNAF(d){return m.wNAFCached(this,u,d,y=>{let w=t.invertBatch(y.map(E=>E.pz));return y.map((E,b)=>E.toAffine(w[b])).map(l.fromAffine)})}multiplyUnsafe(d){let y=l.ZERO;if(d===Vt)return y;if(c(d),d===Xe)return this;let{endo:w}=e;if(!w)return m.unsafeLadder(this,d);let{k1neg:E,k1:b,k2neg:x,k2:B}=w.splitScalar(d),T=y,K=y,P=this;for(;b>Vt||B>Vt;)b&Xe&&(T=T.add(P)),B&Xe&&(K=K.add(P)),P=P.double(),b>>=Xe,B>>=Xe;return E&&(T=T.negate()),x&&(K=K.negate()),K=new l(t.mul(K.px,w.beta),K.py,K.pz),T.add(K)}multiply(d){c(d);let y=d,w,E,{endo:b}=e;if(b){let{k1neg:x,k1:B,k2neg:T,k2:K}=b.splitScalar(y),{p:P,f:M}=this.wNAF(B),{p:D,f:L}=this.wNAF(K);P=m.constTimeNegate(x,P),D=m.constTimeNegate(T,D),D=new l(t.mul(D.px,b.beta),D.py,D.pz),w=P.add(D),E=M.add(L)}else{let{p:x,f:B}=this.wNAF(y);w=x,E=B}return l.normalizeZ([w,E])[0]}multiplyAndAddUnsafe(d,y,w){let E=l.BASE,b=(B,T)=>T===Vt||T===Xe||!B.equals(E)?B.multiplyUnsafe(T):B.multiply(T),x=b(this,y).add(b(d,w));return x.is0()?void 0:x}toAffine(d){let{px:y,py:w,pz:E}=this,b=this.is0();d==null&&(d=b?t.ONE:t.inv(E));let x=t.mul(y,d),B=t.mul(w,d),T=t.mul(E,d);if(b)return{x:t.ZERO,y:t.ZERO};if(!t.eql(T,t.ONE))throw new Error("invZ was invalid");return{x,y:B}}isTorsionFree(){let{h:d,isTorsionFree:y}=e;if(d===Xe)return!0;if(y)return y(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:y}=e;return d===Xe?this:y?y(l,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),n(l,this,d)}toHex(d=!0){return jt(this.toRawBytes(d))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let h=e.nBitLength,m=bo(l,e.endo?Math.ceil(h/2):h);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function c0(r){let e=fi(r);return We(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Vf(r){let e=c0(r),{Fp:t,n}=e,i=t.BYTES+1,o=2*t.BYTES+1;function s(S){return Vt<S&&S<t.ORDER}function c(S){return se(S,n)}function a(S){return xo(S,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:h}=s0({...e,toBytes(S,I,H){let k=I.toAffine(),g=t.toBytes(k.x),U=Ft;return H?U(Uint8Array.from([I.hasEvenY()?2:3]),g):U(Uint8Array.from([4]),g,t.toBytes(k.y))},fromBytes(S){let I=S.length,H=S[0],k=S.subarray(1);if(I===i&&(H===2||H===3)){let g=$t(k);if(!s(g))throw new Error("Point is not on curve");let U=l(g),C=t.sqrt(U),N=(C&Xe)===Xe;return(H&1)===1!==N&&(C=t.neg(C)),{x:g,y:C}}else if(I===o&&H===4){let g=t.fromBytes(k.subarray(0,t.BYTES)),U=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:g,y:U}}else throw new Error(`Point of length ${I} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),m=S=>jt(Oe(S,e.nByteLength));function p(S){let I=n>>Xe;return S>I}function d(S){return p(S)?c(-S):S}let y=(S,I,H)=>$t(S.slice(I,H));class w{constructor(I,H,k){this.r=I,this.s=H,this.recovery=k,this.assertValidity()}static fromCompact(I){let H=e.nByteLength;return I=ue("compactSignature",I,H*2),new w(y(I,0,H),y(I,H,2*H))}static fromDER(I){let{r:H,s:k}=Vr.toSig(ue("DER",I));return new w(H,k)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new w(this.r,this.s,I)}recoverPublicKey(I){let{r:H,s:k,recovery:g}=this,U=K(ue("msgHash",I));if(g==null||![0,1,2,3].includes(g))throw new Error("recovery id invalid");let C=g===2||g===3?H+e.n:H;if(C>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=g&1?"03":"02",F=u.fromHex(N+m(C)),G=a(C),te=c(-U*G),X=c(k*G),Z=u.BASE.multiplyAndAddUnsafe(F,te,X);if(!Z)throw new Error("point at infinify");return Z.assertValidity(),Z}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new w(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Jr(this.toDERHex())}toDERHex(){return Vr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Jr(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let E={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Hc(e.n);return Jf(e.randomBytes(S),e.n)},precompute(S=8,I=u.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function b(S,I=!0){return u.fromPrivateKey(S).toRawBytes(I)}function x(S){let I=st(S),H=typeof S=="string",k=(I||H)&&S.length;return I?k===i||k===o:H?k===2*i||k===2*o:S instanceof u}function B(S,I,H=!0){if(x(S))throw new Error("first arg must be private key");if(!x(I))throw new Error("second arg must be public key");return u.fromHex(I).multiply(f(S)).toRawBytes(H)}let T=e.bits2int||function(S){let I=$t(S),H=S.length*8-e.nBitLength;return H>0?I>>BigInt(H):I},K=e.bits2int_modN||function(S){return c(T(S))},P=ci(e.nBitLength);function M(S){if(typeof S!="bigint")throw new Error("bigint expected");if(!(Vt<=S&&S<P))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Oe(S,e.nByteLength)}function D(S,I,H=L){if(["recovered","canonical"].some(ce=>ce in H))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:g}=e,{lowS:U,prehash:C,extraEntropy:N}=H;U==null&&(U=!0),S=ue("msgHash",S),C&&(S=ue("prehashed msgHash",k(S)));let F=K(S),G=f(I),te=[M(G),M(F)];if(N!=null){let ce=N===!0?g(t.BYTES):N;te.push(ue("extraEntropy",ce))}let X=Ft(...te),Z=F;function ae(ce){let be=T(ce);if(!h(be))return;let Ee=a(be),me=u.BASE.multiply(be).toAffine(),ve=c(me.x);if(ve===Vt)return;let Kt=c(Ee*c(Z+ve*G));if(Kt===Vt)return;let Ar=(me.x===ve?0:2)|Number(me.y&Xe),Cn=Kt;return U&&p(Kt)&&(Cn=d(Kt),Ar^=1),new w(ve,Cn,Ar)}return{seed:X,k2sig:ae}}let L={lowS:e.lowS,prehash:!1},J={lowS:e.lowS,prehash:!1};function $(S,I,H=L){let{seed:k,k2sig:g}=D(S,I,H),U=e;return Cc(U.hash.outputLen,U.nByteLength,U.hmac)(k,g)}u.BASE._setWindowSize(8);function ee(S,I,H,k=J){let g=S;if(I=ue("msgHash",I),H=ue("publicKey",H),"strict"in k)throw new Error("options.strict was renamed to lowS");let{lowS:U,prehash:C}=k,N,F;try{if(typeof g=="string"||st(g))try{N=w.fromDER(g)}catch(me){if(!(me instanceof Vr.Err))throw me;N=w.fromCompact(g)}else if(typeof g=="object"&&typeof g.r=="bigint"&&typeof g.s=="bigint"){let{r:me,s:ve}=g;N=new w(me,ve)}else throw new Error("PARSE");F=u.fromHex(H)}catch(me){if(me.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(U&&N.hasHighS())return!1;C&&(I=e.hash(I));let{r:G,s:te}=N,X=K(I),Z=a(te),ae=c(X*Z),ce=c(G*Z),be=u.BASE.multiplyAndAddUnsafe(F,ae,ce)?.toAffine();return be?c(be.x)===G:!1}return{CURVE:e,getPublicKey:b,getSharedSecret:B,sign:$,verify:ee,ProjectivePoint:u,Signature:w,utils:E}}var Eo=class extends yn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Lf(e);let n=ai(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return pn(this),this.iHash.update(e),this}digestInto(e){pn(this),_c(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},$c=(r,e,t)=>new Eo(r,e).update(t).digest();$c.create=(r,e)=>new Eo(r,e);function a0(r){return{hash:r,hmac:(e,...t)=>$c(r,e,mo(...t)),randomBytes:ui}}function Ao(r,e){let t=n=>Vf({...r,...a0(n)});return Object.freeze({...t(e),create:t})}var zf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Gf=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),u0=BigInt(1),Jc=BigInt(2),qf=(r,e)=>(r+e/Jc)/e;function f0(r){let e=zf,t=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%e,f=u*u*r%e,l=fe(f,t,e)*f%e,h=fe(l,t,e)*f%e,m=fe(h,Jc,e)*u%e,p=fe(m,i,e)*m%e,d=fe(p,o,e)*p%e,y=fe(d,c,e)*d%e,w=fe(y,a,e)*y%e,E=fe(w,c,e)*d%e,b=fe(E,t,e)*f%e,x=fe(b,s,e)*p%e,B=fe(x,n,e)*u%e,T=fe(B,Jc,e);if(!Fc.eql(Fc.sqr(T),r))throw new Error("Cannot find square root");return T}var Fc=wn(zf,void 0,void 0,{sqrt:f0}),pe=Ao({a:BigInt(0),b:BigInt(7),Fp:Fc,n:Gf,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Gf,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-u0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=t,s=BigInt("0x100000000000000000000000000000000"),c=qf(o*r,e),a=qf(-n*r,e),u=se(r-c*t-a*i,e),f=se(-c*n-a*o,e),l=u>s,h=f>s;if(l&&(u=e-u),h&&(f=e-f),u>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:h,k2:f}}}},go),Ix=BigInt(0);var Cx=pe.ProjectivePoint;function vo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function l0(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function gn(r,...e){if(!l0(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function li(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vo(r.outputLen),vo(r.blockLen)}function xn(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Wf(r,e){gn(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Gt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Bo=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ut=(r,e)=>r<<32-e|r>>>e;var Mx=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function d0(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ar(r){return typeof r=="string"&&(r=d0(r)),gn(r),r}function Vc(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];gn(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var bn=class{clone(){return this._cloneInto()}},Dx={}.toString;function Xf(r){let e=n=>r().update(ar(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Zf(r=32){if(Gt&&typeof Gt.getRandomValues=="function")return Gt.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function h0(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),c=Number(t&o),a=n?4:0,u=n?0:4;r.setUint32(e+a,s,n),r.setUint32(e+u,c,n)}var Yf=(r,e,t)=>r&e^~r&t,Qf=(r,e,t)=>r&e^r&t^e&t,So=class extends bn{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Bo(this.buffer)}update(e){xn(this);let{view:t,buffer:n,blockLen:i}=this;e=ar(e);let o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Bo(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){xn(this),Wf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;h0(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Bo(e),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:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return e.length=i,e.pos=c,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var p0=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]),ur=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fr=new Uint32Array(64),Gc=class extends So{constructor(){super(64,32,8,!1),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0,this.F=ur[5]|0,this.G=ur[6]|0,this.H=ur[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,t,n,i,o,s,c,a]}set(e,t,n,i,o,s,c,a){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,t){for(let l=0;l<16;l++,t+=4)fr[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=fr[l-15],m=fr[l-2],p=ut(h,7)^ut(h,18)^h>>>3,d=ut(m,17)^ut(m,19)^m>>>10;fr[l]=d+fr[l-7]+p+fr[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 h=ut(c,6)^ut(c,11)^ut(c,25),m=f+h+Yf(c,a,u)+p0[l]+fr[l]|0,d=(ut(n,2)^ut(n,13)^ut(n,22))+Qf(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+d|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(){fr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Me=Xf(()=>new Gc);function el(r){let e=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=e(n[s]);return o}return n},t=e(r);return JSON.stringify(t)}var En=class{static async digest({data:e}){return Me(e)}};var qc="urn:jwk:";async function q({jwk:r}){let e=r.kty,t;if(e==="EC")t={crv:r.crv,kty:r.kty,x:r.x,y:r.y};else if(e==="oct")t={k:r.k,kty:r.kty};else if(e==="OKP")t={crv:r.crv,kty:r.kty,x:r.x};else if(e==="RSA")t={e:r.e,kty:r.kty,n:r.n};else throw new Error(`Unsupported key type: ${e}`);Ps(t);let n=el(t),i=_.string(n).toUint8Array(),o=await En.digest({data:i});return _.uint8Array(o).toBase64Url()}function Et(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 An(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 At(r){return!(!r||typeof r!="object"||!("kty"in r&&"k"in r)||r.kty!=="oct"||typeof r.k!="string")}function De(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 vn(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 tl(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 Qx(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 Ze=class r{static async adjustSignatureToLowS({signature:e}){let t=pe.Signature.fromCompact(e);return t.hasHighS()?t.normalizeS().toCompactRawBytes():e}static async bytesToPrivateKey({privateKeyBytes:e}){let t=await r.getCurvePoint({keyBytes:e}),n={kty:"EC",crv:"secp256k1",d:_.uint8Array(e).toBase64Url(),x:_.uint8Array(t.x).toBase64Url(),y:_.uint8Array(t.y).toBase64Url()};return n.kid=await q({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:e}){let t=await r.getCurvePoint({keyBytes:e}),n={kty:"EC",crv:"secp256k1",x:_.uint8Array(t.x).toBase64Url(),y:_.uint8Array(t.y).toBase64Url()};return n.kid=await q({jwk:n}),n}static async compressPublicKey({publicKeyBytes:e}){return pe.ProjectivePoint.fromHex(e).toRawBytes(!0)}static async computePublicKey({key:e}){let t=await r.privateKeyToBytes({privateKey:e}),n=await r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"secp256k1",x:_.uint8Array(n.x).toBase64Url(),y:_.uint8Array(n.y).toBase64Url()};return i.kid=await q({jwk:i}),i}static async convertDerToCompactSignature({derSignature:e}){return pe.Signature.fromDER(e).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:e}){return pe.ProjectivePoint.fromHex(e).toRawBytes(!1)}static async generateKey(){let e=pe.utils.randomPrivateKey(),t=await r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=await q({jwk:t}),t}static async getPublicKey({key:e}){if(!(Et(e)&&e.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:t,...n}=e;return n.kid??=await q({jwk:n}),n}static async privateKeyToBytes({privateKey:e}){if(!Et(e))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return _.base64Url(e.d).toUint8Array()}static async publicKeyToBytes({publicKey:e}){if(!(An(e)&&e.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let t=new Uint8Array([4]),n=_.base64Url(e.x).toUint8Array(),i=_.base64Url(e.y).toUint8Array();return new Uint8Array([...t,...n,...i])}static async sharedSecret({privateKeyA:e,publicKeyB:t}){if("x"in e&&"x"in t&&e.x===t.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:e}),i=await r.publicKeyToBytes({publicKey:t});return pe.getSharedSecret(n,i,!0).slice(1)}static async sign({data:e,key:t}){let n=await r.privateKeyToBytes({privateKey:t}),i=Me(e);return pe.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:e}){return pe.utils.isValidPrivateKey(e)}static async validatePublicKey({publicKeyBytes:e}){try{pe.ProjectivePoint.fromHex(e).assertValidity()}catch{return!1}return!0}static async verify({key:e,signature:t,data:n}){let i=await r.publicKeyToBytes({publicKey:e}),o=Me(n);return pe.verify(t,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:e}){e.byteLength===32&&(e=pe.getPublicKey(e));let t=pe.ProjectivePoint.fromHex(e),n=Oe(t.x,32),i=Oe(t.y,32);return{x:n,y:i}}};var rl=wn(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),y0=rl.create(BigInt("-3")),m0=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),w0=Ao({a:y0,b:m0,Fp:rl,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},go),He=w0;var Pe=class r{static async adjustSignatureToLowS({signature:e}){let t=He.Signature.fromCompact(e);return t.hasHighS()?t.normalizeS().toCompactRawBytes():e}static async bytesToPrivateKey({privateKeyBytes:e}){let t=await r.getCurvePoint({keyBytes:e}),n={kty:"EC",crv:"P-256",d:_.uint8Array(e).toBase64Url(),x:_.uint8Array(t.x).toBase64Url(),y:_.uint8Array(t.y).toBase64Url()};return n.kid=await q({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:e}){let t=await r.getCurvePoint({keyBytes:e}),n={kty:"EC",crv:"P-256",x:_.uint8Array(t.x).toBase64Url(),y:_.uint8Array(t.y).toBase64Url()};return n.kid=await q({jwk:n}),n}static async compressPublicKey({publicKeyBytes:e}){return He.ProjectivePoint.fromHex(e).toRawBytes(!0)}static async computePublicKey({key:e}){let t=await r.privateKeyToBytes({privateKey:e}),n=await r.getCurvePoint({keyBytes:t}),i={kty:"EC",crv:"P-256",x:_.uint8Array(n.x).toBase64Url(),y:_.uint8Array(n.y).toBase64Url()};return i.kid=await q({jwk:i}),i}static async convertDerToCompactSignature({derSignature:e}){return He.Signature.fromDER(e).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:e}){return He.ProjectivePoint.fromHex(e).toRawBytes(!1)}static async generateKey(){let e=He.utils.randomPrivateKey(),t=await r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=await q({jwk:t}),t}static async getPublicKey({key:e}){if(!(Et(e)&&e.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:t,...n}=e;return n.kid??=await q({jwk:n}),n}static async privateKeyToBytes({privateKey:e}){if(!Et(e))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return _.base64Url(e.d).toUint8Array()}static async publicKeyToBytes({publicKey:e}){if(!(An(e)&&e.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let t=new Uint8Array([4]),n=_.base64Url(e.x).toUint8Array(),i=_.base64Url(e.y).toUint8Array();return new Uint8Array([...t,...n,...i])}static async sharedSecret({privateKeyA:e,publicKeyB:t}){if("x"in e&&"x"in t&&e.x===t.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:e}),i=await r.publicKeyToBytes({publicKey:t});return He.getSharedSecret(n,i,!0).slice(1)}static async sign({data:e,key:t}){let n=await r.privateKeyToBytes({privateKey:t}),i=Me(e);return He.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:e}){return He.utils.isValidPrivateKey(e)}static async validatePublicKey({publicKeyBytes:e}){try{He.ProjectivePoint.fromHex(e).assertValidity()}catch{return!1}return!0}static async verify({key:e,signature:t,data:n}){let i=await r.publicKeyToBytes({publicKey:e}),o=Me(n);return He.verify(t,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:e}){e.byteLength===32&&(e=He.getPublicKey(e));let t=He.ProjectivePoint.fromHex(e),n=Oe(t.x,32),i=Oe(t.y,32);return{x:n,y:i}}};var di=class extends ye{async bytesToPrivateKey({algorithm:e,privateKeyBytes:t}){switch(e){case"ES256K":case"secp256k1":{let n=await Ze.bytesToPrivateKey({privateKeyBytes:t});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Pe.bytesToPrivateKey({privateKeyBytes:t});return n.alg="ES256",n}default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async bytesToPublicKey({algorithm:e,publicKeyBytes:t}){switch(e){case"ES256K":case"secp256k1":{let n=await Ze.bytesToPublicKey({publicKeyBytes:t});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Pe.bytesToPublicKey({publicKeyBytes:t});return n.alg="ES256",n}default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async computePublicKey({key:e}){if(!Et(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let t=await Ze.computePublicKey({key:e});return t.alg="ES256K",t}case"P-256":{let t=await Pe.computePublicKey({key:e});return t.alg="ES256",t}default:throw new Error(`Unsupported curve: ${e.crv}`)}}async generateKey({algorithm:e}){switch(e){case"ES256K":case"secp256k1":{let t=await Ze.generateKey();return t.alg="ES256K",t}case"ES256":case"secp256r1":{let t=await Pe.generateKey();return t.alg="ES256",t}}}async getPublicKey({key:e}){if(!Et(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let t=await Ze.getPublicKey({key:e});return t.alg="ES256K",t}case"P-256":{let t=await Pe.getPublicKey({key:e});return t.alg="ES256",t}default:throw new Error(`Unsupported curve: ${e.crv}`)}}async sign({key:e,data:t}){if(!Et(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":return await Ze.sign({key:e,data:t});case"P-256":return await Pe.sign({key:e,data:t});default:throw new Error(`Unsupported curve: ${e.crv}`)}}async verify({key:e,signature:t,data:n}){if(!An(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(e.crv){case"secp256k1":return await Ze.verify({key:e,signature:t,data:n});case"P-256":return await Pe.verify({key:e,signature:t,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}}async privateKeyToBytes({privateKey:e}){switch(e.crv){case"secp256k1":return await Ze.privateKeyToBytes({privateKey:e});case"P-256":return await Pe.privateKeyToBytes({privateKey:e});default:throw new V("algorithmNotSupported",`Curve not supported: ${e.crv}`)}}async publicKeyToBytes({publicKey:e}){switch(e.crv){case"secp256k1":return await Ze.publicKeyToBytes({publicKey:e});case"P-256":return await Pe.publicKeyToBytes({publicKey:e});default:throw new V("algorithmNotSupported",`Curve not supported: ${e.crv}`)}}};var ko=BigInt(4294967295),zc=BigInt(32);function nl(r,e=!1){return e?{h:Number(r&ko),l:Number(r>>zc&ko)}:{h:Number(r>>zc&ko)|0,l:Number(r&ko)|0}}function g0(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=nl(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var x0=(r,e)=>BigInt(r>>>0)<<zc|BigInt(e>>>0),b0=(r,e,t)=>r>>>t,E0=(r,e,t)=>r<<32-t|e>>>t,A0=(r,e,t)=>r>>>t|e<<32-t,v0=(r,e,t)=>r<<32-t|e>>>t,B0=(r,e,t)=>r<<64-t|e>>>t-32,S0=(r,e,t)=>r>>>t-32|e<<64-t,k0=(r,e)=>e,T0=(r,e)=>r,P0=(r,e,t)=>r<<t|e>>>32-t,U0=(r,e,t)=>e<<t|r>>>32-t,K0=(r,e,t)=>e<<t-32|r>>>64-t,I0=(r,e,t)=>r<<t-32|e>>>64-t;function C0(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var _0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),O0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,L0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),N0=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,R0=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),M0=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var D0={fromBig:nl,split:g0,toBig:x0,shrSH:b0,shrSL:E0,rotrSH:A0,rotrSL:v0,rotrBH:B0,rotrBL:S0,rotr32H:k0,rotr32L:T0,rotlSH:P0,rotlSL:U0,rotlBH:K0,rotlBL:I0,add:C0,add3L:_0,add3H:O0,add4L:L0,add4H:N0,add5H:M0,add5L:R0},Y=D0;var[H0,j0]=Y.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))),lr=new Uint32Array(80),dr=new Uint32Array(80),Wc=class extends mn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:h,Gh:m,Gl:p,Hh:d,Hl:y}=this;return[e,t,n,i,o,s,c,a,u,f,l,h,m,p,d,y]}set(e,t,n,i,o,s,c,a,u,f,l,h,m,p,d,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=m|0,this.Gl=p|0,this.Hh=d|0,this.Hl=y|0}process(e,t){for(let b=0;b<16;b++,t+=4)lr[b]=e.getUint32(t),dr[b]=e.getUint32(t+=4);for(let b=16;b<80;b++){let x=lr[b-15]|0,B=dr[b-15]|0,T=Y.rotrSH(x,B,1)^Y.rotrSH(x,B,8)^Y.shrSH(x,B,7),K=Y.rotrSL(x,B,1)^Y.rotrSL(x,B,8)^Y.shrSL(x,B,7),P=lr[b-2]|0,M=dr[b-2]|0,D=Y.rotrSH(P,M,19)^Y.rotrBH(P,M,61)^Y.shrSH(P,M,6),L=Y.rotrSL(P,M,19)^Y.rotrBL(P,M,61)^Y.shrSL(P,M,6),J=Y.add4L(K,L,dr[b-7],dr[b-16]),$=Y.add4H(J,T,D,lr[b-7],lr[b-16]);lr[b]=$|0,dr[b]=J|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:h,Fh:m,Fl:p,Gh:d,Gl:y,Hh:w,Hl:E}=this;for(let b=0;b<80;b++){let x=Y.rotrSH(l,h,14)^Y.rotrSH(l,h,18)^Y.rotrBH(l,h,41),B=Y.rotrSL(l,h,14)^Y.rotrSL(l,h,18)^Y.rotrBL(l,h,41),T=l&m^~l&d,K=h&p^~h&y,P=Y.add5L(E,B,K,j0[b],dr[b]),M=Y.add5H(P,w,x,T,H0[b],lr[b]),D=P|0,L=Y.rotrSH(n,i,28)^Y.rotrBH(n,i,34)^Y.rotrBH(n,i,39),J=Y.rotrSL(n,i,28)^Y.rotrBL(n,i,34)^Y.rotrBL(n,i,39),$=n&o^n&c^o&c,ee=i&s^i&a^s&a;w=d|0,E=y|0,d=m|0,y=p|0,m=l|0,p=h|0,{h:l,l:h}=Y.add(u|0,f|0,M|0,D|0),u=c|0,f=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let S=Y.add3L(D,J,ee);n=Y.add3H(S,M,L,$),i=S|0}({h:n,l:i}=Y.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=Y.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=Y.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Y.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Y.add(this.Eh|0,this.El|0,l|0,h|0),{h:m,l:p}=Y.add(this.Fh|0,this.Fl|0,m|0,p|0),{h:d,l:y}=Y.add(this.Gh|0,this.Gl|0,d|0,y|0),{h:w,l:E}=Y.add(this.Hh|0,this.Hl|0,w|0,E|0),this.set(n,i,o,s,c,a,u,f,l,h,m,p,d,y,w,E)}roundClean(){lr.fill(0),dr.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 Xc=wo(()=>new Wc);var ft=BigInt(0),je=BigInt(1),To=BigInt(2),$0=BigInt(8),J0={zip215:!0};function F0(r){let e=fi(r);return We(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Po(r){let e=F0(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=e,u=To<<BigInt(c*8)-je,f=t.create,l=e.uvRatio||((k,g)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(g))}}catch{return{isValid:!1,value:ft}}}),h=e.adjustScalarBytes||(k=>k),m=e.domain||((k,g,U)=>{if(g.length||U)throw new Error("Contexts/pre-hash are not supported");return k}),p=k=>typeof k=="bigint"&&ft<k,d=(k,g)=>p(k)&&p(g)&&k<g,y=k=>k===ft||d(k,u);function w(k,g){if(d(k,g))return k;throw new Error(`Expected valid scalar < ${g}, got ${typeof k} ${k}`)}function E(k){return k===ft?k:w(k,n)}let b=new Map;function x(k){if(!(k instanceof B))throw new Error("ExtendedPoint expected")}class B{constructor(g,U,C,N){if(this.ex=g,this.ey=U,this.ez=C,this.et=N,!y(g))throw new Error("x required");if(!y(U))throw new Error("y required");if(!y(C))throw new Error("z required");if(!y(N))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof B)throw new Error("extended point not allowed");let{x:U,y:C}=g||{};if(!y(U)||!y(C))throw new Error("invalid affine point");return new B(U,C,je,f(U*C))}static normalizeZ(g){let U=t.invertBatch(g.map(C=>C.ez));return g.map((C,N)=>C.toAffine(U[N])).map(B.fromAffine)}_setWindowSize(g){this._WINDOW_SIZE=g,b.delete(this)}assertValidity(){let{a:g,d:U}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:C,ey:N,ez:F,et:G}=this,te=f(C*C),X=f(N*N),Z=f(F*F),ae=f(Z*Z),ce=f(te*g),be=f(Z*f(ce+X)),Ee=f(ae+f(U*f(te*X)));if(be!==Ee)throw new Error("bad point: equation left != right (1)");let me=f(C*N),ve=f(F*G);if(me!==ve)throw new Error("bad point: equation left != right (2)")}equals(g){x(g);let{ex:U,ey:C,ez:N}=this,{ex:F,ey:G,ez:te}=g,X=f(U*te),Z=f(F*N),ae=f(C*te),ce=f(G*N);return X===Z&&ae===ce}is0(){return this.equals(B.ZERO)}negate(){return new B(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:g}=e,{ex:U,ey:C,ez:N}=this,F=f(U*U),G=f(C*C),te=f(To*f(N*N)),X=f(g*F),Z=U+C,ae=f(f(Z*Z)-F-G),ce=X+G,be=ce-te,Ee=X-G,me=f(ae*be),ve=f(ce*Ee),Kt=f(ae*Ee),Ar=f(be*ce);return new B(me,ve,Ar,Kt)}add(g){x(g);let{a:U,d:C}=e,{ex:N,ey:F,ez:G,et:te}=this,{ex:X,ey:Z,ez:ae,et:ce}=g;if(U===BigInt(-1)){let Ca=f((F-N)*(Z+X)),_a=f((F+N)*(Z-X)),ds=f(_a-Ca);if(ds===ft)return this.double();let Oa=f(G*To*ce),La=f(te*To*ae),Na=La+Oa,Ra=_a+Ca,Ma=La-Oa,ah=f(Na*ds),uh=f(Ra*Ma),fh=f(Na*Ma),lh=f(ds*Ra);return new B(ah,uh,lh,fh)}let be=f(N*X),Ee=f(F*Z),me=f(te*C*ce),ve=f(G*ae),Kt=f((N+F)*(X+Z)-be-Ee),Ar=ve-me,Cn=ve+me,Ia=f(Ee-U*be),ih=f(Kt*Ar),oh=f(Cn*Ia),sh=f(Kt*Ia),ch=f(Ar*Cn);return new B(ih,oh,ch,sh)}subtract(g){return this.add(g.negate())}wNAF(g){return P.wNAFCached(this,b,g,B.normalizeZ)}multiply(g){let{p:U,f:C}=this.wNAF(w(g,n));return B.normalizeZ([U,C])[0]}multiplyUnsafe(g){let U=E(g);return U===ft?K:this.equals(K)||U===je?this:this.equals(T)?this.wNAF(U).p:P.unsafeLadder(this,U)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(g){let{ex:U,ey:C,ez:N}=this,F=this.is0();g==null&&(g=F?$0:t.inv(N));let G=f(U*g),te=f(C*g),X=f(N*g);if(F)return{x:ft,y:je};if(X!==je)throw new Error("invZ was invalid");return{x:G,y:te}}clearCofactor(){let{h:g}=e;return g===je?this:this.multiplyUnsafe(g)}static fromHex(g,U=!1){let{d:C,a:N}=e,F=t.BYTES;g=ue("pointHex",g,F);let G=g.slice(),te=g[F-1];G[F-1]=te&-129;let X=ct(G);X===ft||(U?w(X,u):w(X,t.ORDER));let Z=f(X*X),ae=f(Z-je),ce=f(C*Z-N),{isValid:be,value:Ee}=l(ae,ce);if(!be)throw new Error("Point.fromHex: invalid y coordinate");let me=(Ee&je)===je,ve=(te&128)!==0;if(!U&&Ee===ft&&ve)throw new Error("Point.fromHex: x=0 and x_0=1");return ve!==me&&(Ee=f(-Ee)),B.fromAffine({x:Ee,y:X})}static fromPrivateKey(g){return L(g).point}toRawBytes(){let{x:g,y:U}=this.toAffine(),C=Jt(U,t.BYTES);return C[C.length-1]|=g&je?128:0,C}toHex(){return jt(this.toRawBytes())}}B.BASE=new B(e.Gx,e.Gy,je,f(e.Gx*e.Gy)),B.ZERO=new B(ft,je,je,ft);let{BASE:T,ZERO:K}=B,P=bo(B,c*8);function M(k){return se(k,n)}function D(k){return M(ct(k))}function L(k){let g=c;k=ue("private key",k,g);let U=ue("hashed private key",o(k),2*g),C=h(U.slice(0,g)),N=U.slice(g,2*g),F=D(C),G=T.multiply(F),te=G.toRawBytes();return{head:C,prefix:N,scalar:F,point:G,pointBytes:te}}function J(k){return L(k).pointBytes}function $(k=new Uint8Array,...g){let U=Ft(...g);return D(o(m(U,ue("context",k),!!i)))}function ee(k,g,U={}){k=ue("message",k),i&&(k=i(k));let{prefix:C,scalar:N,pointBytes:F}=L(g),G=$(U.context,C,k),te=T.multiply(G).toRawBytes(),X=$(U.context,te,F,k),Z=M(G+X*N);E(Z);let ae=Ft(te,Jt(Z,t.BYTES));return ue("result",ae,c*2)}let S=J0;function I(k,g,U,C=S){let{context:N,zip215:F}=C,G=t.BYTES;k=ue("signature",k,2*G),g=ue("message",g),i&&(g=i(g));let te=ct(k.slice(G,2*G)),X,Z,ae;try{X=B.fromHex(U,F),Z=B.fromHex(k.slice(0,G),F),ae=T.multiplyUnsafe(te)}catch{return!1}if(!F&&X.isSmallOrder())return!1;let ce=$(N,Z.toRawBytes(),X.toRawBytes(),g);return Z.add(X.multiplyUnsafe(ce)).subtract(ae).clearCofactor().equals(B.ZERO)}return T._setWindowSize(8),{CURVE:e,getPublicKey:J,sign:ee,verify:I,ExtendedPoint:B,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>s(t.BYTES),precompute(k=8,g=B.BASE){return g._setWindowSize(k),g.multiply(BigInt(3)),g}}}}var hi=BigInt(0),Zc=BigInt(1);function V0(r){return We(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function il(r){let e=V0(r),{P:t}=e,n=b=>se(b,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,c=e.adjustScalarBytes||(b=>b),a=e.powPminus2||(b=>Rc(b,t-BigInt(2),t));function u(b,x,B){let T=n(b*(x-B));return x=n(x-T),B=n(B+T),[x,B]}function f(b){if(typeof b=="bigint"&&hi<=b&&b<t)return b;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function h(b,x){let B=f(b),T=f(x),K=B,P=Zc,M=hi,D=B,L=Zc,J=hi,$;for(let S=BigInt(i-1);S>=hi;S--){let I=T>>S&Zc;J^=I,$=u(J,P,D),P=$[0],D=$[1],$=u(J,M,L),M=$[0],L=$[1],J=I;let H=P+M,k=n(H*H),g=P-M,U=n(g*g),C=k-U,N=D+L,F=D-L,G=n(F*H),te=n(N*g),X=G+te,Z=G-te;D=n(X*X),L=n(K*n(Z*Z)),P=n(k*U),M=n(C*(k+n(l*C)))}$=u(J,P,D),P=$[0],D=$[1],$=u(J,M,L),M=$[0],L=$[1];let ee=a(M);return n(P*ee)}function m(b){return Jt(n(b),o)}function p(b){let x=ue("u coordinate",b,o);return s===32&&(x[31]&=127),ct(x)}function d(b){let x=ue("scalar",b),B=x.length;if(B!==o&&B!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${B}`);return ct(c(x))}function y(b,x){let B=p(x),T=d(b),K=h(B,T);if(K===hi)throw new Error("Invalid private or public key received");return m(K)}let w=m(e.Gu);function E(b){return y(b,w)}return{scalarMult:y,scalarMultBase:E,getSharedSecret:(b,x)=>y(b,x),getPublicKey:b=>E(b),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:w}}var pi=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ol=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Hb=BigInt(0),G0=BigInt(1),Yc=BigInt(2),q0=BigInt(5),sl=BigInt(10),z0=BigInt(20),W0=BigInt(40),cl=BigInt(80);function al(r){let e=pi,n=r*r%e*r%e,i=fe(n,Yc,e)*n%e,o=fe(i,G0,e)*r%e,s=fe(o,q0,e)*o%e,c=fe(s,sl,e)*s%e,a=fe(c,z0,e)*c%e,u=fe(a,W0,e)*a%e,f=fe(u,cl,e)*u%e,l=fe(f,cl,e)*u%e,h=fe(l,sl,e)*s%e;return{pow_p_5_8:fe(h,Yc,e)*r%e,b2:n}}function ul(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function X0(r,e){let t=pi,n=se(e*e*e,t),i=se(n*n*e,t),o=al(r*i).pow_p_5_8,s=se(r*n*o,t),c=se(e*s*s,t),a=s,u=se(s*ol,t),f=c===r,l=c===se(-r,t),h=c===se(-r*ol,t);return f&&(s=a),(l||h)&&(s=u),Hf(s,t)&&(s=se(-s,t)),{isValid:f||l,value:s}}var Ye=wn(pi,void 0,!0),yi={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ye,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Xc,randomBytes:ui,adjustScalarBytes:ul,uvRatio:X0},hr=Po(yi);function fl(r,e,t){if(e.length>255)throw new Error("Context is too big");return mo(Oc("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var jb=Po({...yi,domain:fl}),$b=Po({...yi,domain:fl,prehash:Xc}),Gr=il({P:pi,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=pi,{pow_p_5_8:t,b2:n}=al(r);return se(fe(t,BigInt(3),e)*n,e)},adjustScalarBytes:ul,randomBytes:ui});function ll(r){let{y:e}=hr.ExtendedPoint.fromHex(r),t=BigInt(1);return Ye.toBytes(Ye.create((t+e)*Ye.inv(t-e)))}function dl(r){let e=yi.hash(r.subarray(0,32));return yi.adjustScalarBytes(e).subarray(0,32)}var Z0=(Ye.ORDER+BigInt(3))/BigInt(8),Jb=Ye.pow(Yc,Z0),Fb=Ye.sqrt(Ye.neg(Ye.ONE)),Vb=(Ye.ORDER-BigInt(5))/BigInt(8),Gb=BigInt(486662);var qb=jf(Ye,Ye.neg(BigInt(486664)));var zb=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Wb=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Xb=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Zb=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Yb=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ue=class r{static async bytesToPrivateKey({privateKeyBytes:e}){let t=hr.getPublicKey(e),n={crv:"Ed25519",d:_.uint8Array(e).toBase64Url(),kty:"OKP",x:_.uint8Array(t).toBase64Url()};return n.kid=await q({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:e}){let t={kty:"OKP",crv:"Ed25519",x:_.uint8Array(e).toBase64Url()};return t.kid=await q({jwk:t}),t}static async computePublicKey({key:e}){let t=await r.privateKeyToBytes({privateKey:e}),n=hr.getPublicKey(t),i={kty:"OKP",crv:"Ed25519",x:_.uint8Array(n).toBase64Url()};return i.kid=await q({jwk:i}),i}static async convertPrivateKeyToX25519({privateKey:e}){let t=await r.privateKeyToBytes({privateKey:e}),n=dl(t),i=Gr.getPublicKey(n),o={kty:"OKP",crv:"X25519",d:_.uint8Array(n).toBase64Url(),x:_.uint8Array(i).toBase64Url()};return o.kid=await q({jwk:o}),o}static async convertPublicKeyToX25519({publicKey:e}){let t=await r.publicKeyToBytes({publicKey:e});if(!await r.validatePublicKey({publicKeyBytes:t}))throw new Error("Ed25519: Invalid public key.");let i=ll(t),o={kty:"OKP",crv:"X25519",x:_.uint8Array(i).toBase64Url()};return o.kid=await q({jwk:o}),o}static async generateKey(){let e=hr.utils.randomPrivateKey(),t=await r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=await q({jwk:t}),t}static async getPublicKey({key:e}){if(!(De(e)&&e.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:t,...n}=e;return n.kid??=await q({jwk:n}),n}static async privateKeyToBytes({privateKey:e}){if(!De(e))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return _.base64Url(e.d).toUint8Array()}static async publicKeyToBytes({publicKey:e}){if(!vn(e))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return _.base64Url(e.x).toUint8Array()}static async sign({key:e,data:t}){let n=await r.privateKeyToBytes({privateKey:e});return hr.sign(t,n)}static async validatePublicKey({publicKeyBytes:e}){try{hr.ExtendedPoint.fromHex(e).assertValidity()}catch{return!1}return!0}static async verify({key:e,signature:t,data:n}){let i=await r.publicKeyToBytes({publicKey:e});return hr.verify(t,n,i)}};var Uo=class extends ye{async bytesToPrivateKey({algorithm:e,privateKeyBytes:t}){switch(e){case"Ed25519":{let n=await Ue.bytesToPrivateKey({privateKeyBytes:t});return n.alg="EdDSA",n}default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async bytesToPublicKey({algorithm:e,publicKeyBytes:t}){switch(e){case"Ed25519":{let n=await Ue.bytesToPublicKey({publicKeyBytes:t});return n.alg="EdDSA",n}default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async computePublicKey({key:e}){if(!De(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let t=await Ue.computePublicKey({key:e});return t.alg="EdDSA",t}default:throw new Error(`Unsupported curve: ${e.crv}`)}}async generateKey({algorithm:e}){switch(e){case"Ed25519":{let t=await Ue.generateKey();return t.alg="EdDSA",t}}}async getPublicKey({key:e}){if(!De(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let t=await Ue.getPublicKey({key:e});return t.alg="EdDSA",t}default:throw new Error(`Unsupported curve: ${e.crv}`)}}async sign({key:e,data:t}){if(!De(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":return await Ue.sign({key:e,data:t});default:throw new Error(`Unsupported curve: ${e.crv}`)}}async verify({key:e,signature:t,data:n}){if(!vn(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(e.crv){case"Ed25519":return await Ue.verify({key:e,signature:t,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}}async privateKeyToBytes({privateKey:e}){switch(e.crv){case"Ed25519":return await Ue.privateKeyToBytes({privateKey:e});default:throw new V("algorithmNotSupported",`Curve not supported: ${e.crv}`)}}async publicKeyToBytes({publicKey:e}){switch(e.crv){case"Ed25519":return await Ue.publicKeyToBytes({publicKey:e});default:throw new V("algorithmNotSupported",`Curve not supported: ${e.crv}`)}}};var Ko=class extends ye{async digest({algorithm:e,data:t}){switch(e){case"SHA-256":return await En.digest({data:t})}}};var pr=class r{static async bytesToPrivateKey({privateKeyBytes:e}){let t=Gr.getPublicKey(e),n={kty:"OKP",crv:"X25519",d:_.uint8Array(e).toBase64Url(),x:_.uint8Array(t).toBase64Url()};return n.kid=await q({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:e}){let t={kty:"OKP",crv:"X25519",x:_.uint8Array(e).toBase64Url()};return t.kid=await q({jwk:t}),t}static async computePublicKey({key:e}){let t=await r.privateKeyToBytes({privateKey:e}),n=Gr.getPublicKey(t),i={kty:"OKP",crv:"X25519",x:_.uint8Array(n).toBase64Url()};return i.kid=await q({jwk:i}),i}static async generateKey(){let e=Gr.utils.randomPrivateKey(),t=await r.bytesToPrivateKey({privateKeyBytes:e});return t.kid=await q({jwk:t}),t}static async getPublicKey({key:e}){if(!(De(e)&&e.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:t,...n}=e;return n.kid??=await q({jwk:n}),n}static async privateKeyToBytes({privateKey:e}){if(!De(e))throw new Error("X25519: The provided key is not a valid OKP private key.");return _.base64Url(e.d).toUint8Array()}static async publicKeyToBytes({publicKey:e}){if(!vn(e))throw new Error("X25519: The provided key is not a valid OKP public key.");return _.base64Url(e.x).toUint8Array()}static async sharedSecret({privateKeyA:e,publicKeyB:t}){if("x"in e&&"x"in t&&e.x===t.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:e}),i=await r.publicKeyToBytes({publicKey:t});return Gr.getSharedSecret(n,i)}};var Io=class extends ye{async bytesToPrivateKey({algorithm:e,privateKeyBytes:t}){switch(e){case"X25519":return pr.bytesToPrivateKey({privateKeyBytes:t});default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async computePublicKey({key:e}){if(!De(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return pr.computePublicKey({key:e});default:throw new V("algorithmNotSupported",`Unsupported curve: ${e.crv}`)}}async generateKey({algorithm:e}){switch(e){case"X25519":return pr.generateKey();default:throw new V("algorithmNotSupported",`Algorithm not supported: ${e}`)}}async getPublicKey({key:e}){if(!De(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return pr.getPublicKey({key:e});default:throw new V("algorithmNotSupported",`Unsupported curve: ${e.crv}`)}}async privateKeyToBytes({privateKey:e}){return pr.privateKeyToBytes({privateKey:e})}};var Qc={Ed25519:{implementation:Uo,names:["Ed25519"]},secp256k1:{implementation:di,names:["ES256K","secp256k1"]},secp256r1:{implementation:di,names:["ES256","secp256r1"]},"SHA-256":{implementation:Ko,names:["SHA-256"]},X25519:{implementation:Io,names:["X25519"]}},hl=class{constructor(e){this._algorithmInstances=new Map;this._keyStore=e?.keyStore??new fo}async digest({algorithm:e,data:t}){return await this.getAlgorithm({algorithm:e}).digest({algorithm:e,data:t})}async exportKey({keyUri:e}){return await this.getPrivateKey({keyUri:e})}async generateKey({algorithm:e}){let n=await this.getAlgorithm({algorithm:e}).generateKey({algorithm:e});if(n?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let i=`${qc}${n.kid}`;return await this._keyStore.set(i,n),i}async getKeyUri({key:e}){let t=await q({jwk:e});return`${qc}${t}`}async getPublicKey({keyUri:e}){let t=await this.getPrivateKey({keyUri:e}),n=this.getAlgorithmName({key:t});return await this.getAlgorithm({algorithm:n}).getPublicKey({key:t})}async importKey({key:e}){if(!tl(e))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let t=structuredClone(e);t.kid??=await q({jwk:t});let n=await this.getKeyUri({key:t});return await this._keyStore.set(n,t),n}async sign({keyUri:e,data:t}){let n=await this.getPrivateKey({keyUri:e}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:t,key:n})}async verify({key:e,signature:t,data:n}){let i=this.getAlgorithmName({key:e});return this.getAlgorithm({algorithm:i}).verify({key:e,signature:t,data:n})}getAlgorithm({algorithm:e}){let t=Qc[e]?.implementation;if(!t)throw new Error(`Algorithm not supported: ${e}`);return this._algorithmInstances.has(t)||this._algorithmInstances.set(t,new t),this._algorithmInstances.get(t)}getAlgorithmName({key:e}){let t=e.alg,n=e.crv;for(let i in Qc){let o=Qc[i];if(t&&o.names.includes(t))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${t}, crv=${n}`)}async getPrivateKey({keyUri:e}){let t=await this._keyStore.get(e);if(!t)throw new Error(`Key not found: ${e}`);return t}};var pl=class r{static getJoseSignatureAlgorithmFromPublicKey(e){let t={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(t).includes(e.alg))return e.alg;if(e.crv&&Object.keys(t).includes(e.crv))return t[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(t).join(", ")}. Supported 'crv' values: ${Object.keys(t).join(", ")}.`)}static randomBytes(e){return Zf(e)}static randomUuid(){return Gt.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let t=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let o=r.randomBytes(Math.ceil(e/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>t)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>t)}return n.toString().padStart(e,"0")}};function K1(r){return r!==null&&typeof r=="object"&&"encrypt"in r&&typeof r.encrypt=="function"&&"decrypt"in r&&typeof r.decrypt=="function"}function I1(r){return r!==null&&typeof r=="object"&&"exportKey"in r&&typeof r.exportKey=="function"}function C1(r){return r!==null&&typeof r=="object"&&"importKey"in r&&typeof r.importKey=="function"}function _1(r){return r!==null&&typeof r=="object"&&"wrapKey"in r&&typeof r.wrapKey=="function"&&"unwrapKey"in r&&typeof r.unwrapKey=="function"}var Y0=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function ea(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(r instanceof Uint8Array)return"Uint8Array";if(r.constructor===Object)return"Object";let t=Q0(r);return t||"Object"}function Q0(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Y0.includes(e))return e}var A=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,t){return e===t||e.major===t.major&&e.name===t.name}};A.uint=new A(0,"uint",!0);A.negint=new A(1,"negint",!0);A.bytes=new A(2,"bytes",!0);A.string=new A(3,"string",!0);A.array=new A(4,"array",!1);A.map=new A(5,"map",!1);A.tag=new A(6,"tag",!1);A.float=new A(7,"float",!0);A.false=new A(7,"false",!0);A.true=new A(7,"true",!0);A.null=new A(7,"null",!0);A.undefined=new A(7,"undefined",!0);A.break=new A(7,"break",!0);var R=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var mi=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",em=new TextEncoder;function Co(r){return mi&&globalThis.Buffer.isBuffer(r)}function wi(r){return r instanceof Uint8Array?Co(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var tm=24,rm=200,_o=mi?r=>r.length>=tm?globalThis.Buffer.from(r):yl(r):r=>r.length>=rm?em.encode(r):yl(r),vt=r=>Uint8Array.from(r),ml=mi?(r,e,t)=>Co(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),wl=mi?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),wi(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let i of r)n+i.length>t.length&&(i=i.subarray(0,t.length-n)),t.set(i,n),n+=i.length;return t},gl=mi?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Oo(r,e){if(Co(r)&&Co(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function yl(r){let e=[],t=0;for(let n=0;n<r.length;n++){let i=r.charCodeAt(n);i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128)}return e}var nm=256,gi=class{constructor(e=nm){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=t.length-(this.maxCursor-this.cursor)-1;t.set(e,i)}else{if(t){let i=t.length-(this.maxCursor-this.cursor)-1;i<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=gl(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=ml(n,0,this.cursor)}else t=wl(this.chunks,this.cursor);return e&&this.reset(),t}},Lo=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let t=this.dest.subarray(0,this.cursor);return e&&this.reset(),t}};var z="CBOR decode error:",No="CBOR encode error:",xi=[];xi[23]=1;xi[24]=2;xi[25]=3;xi[26]=5;xi[27]=9;function qt(r,e,t){if(r.length-e<t)throw new Error(`${z} not enough data for type`)}var xe=[24,256,65536,4294967296,BigInt("18446744073709551616")];function $e(r,e,t){qt(r,e,1);let n=r[e];if(t.strict===!0&&n<xe[0])throw new Error(`${z} integer encoded in more bytes than necessary (strict decode)`);return n}function Je(r,e,t){qt(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<xe[1])throw new Error(`${z} integer encoded in more bytes than necessary (strict decode)`);return n}function Fe(r,e,t){qt(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<xe[2])throw new Error(`${z} integer encoded in more bytes than necessary (strict decode)`);return n}function Ve(r,e,t){qt(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],i=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(t.strict===!0&&o<xe[3])throw new Error(`${z} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(t.allowBigInt===!0)return o;throw new Error(`${z} integers outside of the safe integer range are not supported`)}function xl(r,e,t,n){return new R(A.uint,$e(r,e+1,n),2)}function bl(r,e,t,n){return new R(A.uint,Je(r,e+1,n),3)}function El(r,e,t,n){return new R(A.uint,Fe(r,e+1,n),5)}function Al(r,e,t,n){return new R(A.uint,Ve(r,e+1,n),9)}function Qe(r,e){return le(r,0,e.value)}function le(r,e,t){if(t<xe[0]){let n=Number(t);r.push([e|n])}else if(t<xe[1]){let n=Number(t);r.push([e|24,n])}else if(t<xe[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<xe[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<xe[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,r.push(i)}else throw new Error(`${z} encountered BigInt larger than allowable range`)}}Qe.encodedSize=function(e){return le.encodedSize(e.value)};le.encodedSize=function(e){return e<xe[0]?1:e<xe[1]?2:e<xe[2]?3:e<xe[3]?5:9};Qe.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function vl(r,e,t,n){return new R(A.negint,-1-$e(r,e+1,n),2)}function Bl(r,e,t,n){return new R(A.negint,-1-Je(r,e+1,n),3)}function Sl(r,e,t,n){return new R(A.negint,-1-Fe(r,e+1,n),5)}var ta=BigInt(-1),kl=BigInt(1);function Tl(r,e,t,n){let i=Ve(r,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new R(A.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${z} integers outside of the safe integer range are not supported`);return new R(A.negint,ta-BigInt(i),9)}function Ro(r,e){let t=e.value,n=typeof t=="bigint"?t*ta-kl:t*-1-1;le(r,e.type.majorEncoded,n)}Ro.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ta-kl:t*-1-1;return n<xe[0]?1:n<xe[1]?2:n<xe[2]?3:n<xe[3]?5:9};Ro.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function bi(r,e,t,n){qt(r,e,t+n);let i=r.slice(e+t,e+t+n);return new R(A.bytes,i,t+n)}function Pl(r,e,t,n){return bi(r,e,1,t)}function Ul(r,e,t,n){return bi(r,e,2,$e(r,e+1,n))}function Kl(r,e,t,n){return bi(r,e,3,Je(r,e+1,n))}function Il(r,e,t,n){return bi(r,e,5,Fe(r,e+1,n))}function Cl(r,e,t,n){let i=Ve(r,e+1,n);if(typeof i=="bigint")throw new Error(`${z} 64-bit integer bytes lengths not supported`);return bi(r,e,9,i)}function Mo(r){return r.encodedBytes===void 0&&(r.encodedBytes=A.equals(r.type,A.string)?_o(r.value):r.value),r.encodedBytes}function Bn(r,e){let t=Mo(e);le(r,e.type.majorEncoded,t.length),r.push(t)}Bn.encodedSize=function(e){let t=Mo(e);return le.encodedSize(t.length)+t.length};Bn.compareTokens=function(e,t){return om(Mo(e),Mo(t))};function om(r,e){return r.length<e.length?-1:r.length>e.length?1:Oo(r,e)}var _l=new TextDecoder,cm=32;function am(r,e,t){if(t-e<cm){let i="";for(let o=e;o<t;o++){let s=r[o];if(s&128)return _l.decode(r.subarray(e,t));i+=String.fromCharCode(s)}return i}return _l.decode(r.subarray(e,t))}function Ei(r,e,t,n,i){let o=t+n;qt(r,e,o);let s=new R(A.string,am(r,e+t,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=r.slice(e+t,e+o)),s}function Ol(r,e,t,n){return Ei(r,e,1,t,n)}function Ll(r,e,t,n){return Ei(r,e,2,$e(r,e+1,n),n)}function Nl(r,e,t,n){return Ei(r,e,3,Je(r,e+1,n),n)}function Rl(r,e,t,n){return Ei(r,e,5,Fe(r,e+1,n),n)}function Ml(r,e,t,n){let i=Ve(r,e+1,n);if(typeof i=="bigint")throw new Error(`${z} 64-bit integer string lengths not supported`);return Ei(r,e,9,i,n)}var Dl=Bn;function Sn(r,e,t,n){return new R(A.array,n,t)}function Hl(r,e,t,n){return Sn(r,e,1,t)}function jl(r,e,t,n){return Sn(r,e,2,$e(r,e+1,n))}function $l(r,e,t,n){return Sn(r,e,3,Je(r,e+1,n))}function Jl(r,e,t,n){return Sn(r,e,5,Fe(r,e+1,n))}function Fl(r,e,t,n){let i=Ve(r,e+1,n);if(typeof i=="bigint")throw new Error(`${z} 64-bit integer array lengths not supported`);return Sn(r,e,9,i)}function Vl(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${z} indefinite length items not allowed`);return Sn(r,e,1,1/0)}function Do(r,e){le(r,A.array.majorEncoded,e.value)}Do.compareTokens=Qe.compareTokens;Do.encodedSize=function(e){return le.encodedSize(e.value)};function kn(r,e,t,n){return new R(A.map,n,t)}function Gl(r,e,t,n){return kn(r,e,1,t)}function ql(r,e,t,n){return kn(r,e,2,$e(r,e+1,n))}function zl(r,e,t,n){return kn(r,e,3,Je(r,e+1,n))}function Wl(r,e,t,n){return kn(r,e,5,Fe(r,e+1,n))}function Xl(r,e,t,n){let i=Ve(r,e+1,n);if(typeof i=="bigint")throw new Error(`${z} 64-bit integer map lengths not supported`);return kn(r,e,9,i)}function Zl(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${z} indefinite length items not allowed`);return kn(r,e,1,1/0)}function Ho(r,e){le(r,A.map.majorEncoded,e.value)}Ho.compareTokens=Qe.compareTokens;Ho.encodedSize=function(e){return le.encodedSize(e.value)};function Yl(r,e,t,n){return new R(A.tag,t,1)}function Ql(r,e,t,n){return new R(A.tag,$e(r,e+1,n),2)}function ed(r,e,t,n){return new R(A.tag,Je(r,e+1,n),3)}function td(r,e,t,n){return new R(A.tag,Fe(r,e+1,n),5)}function rd(r,e,t,n){return new R(A.tag,Ve(r,e+1,n),9)}function jo(r,e){le(r,A.tag.majorEncoded,e.value)}jo.compareTokens=Qe.compareTokens;jo.encodedSize=function(e){return le.encodedSize(e.value)};var ra=20,na=21,ia=22,oa=23;function nd(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${z} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new R(A.null,null,1):new R(A.undefined,void 0,1)}function id(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${z} indefinite length items not allowed`);return new R(A.break,void 0,1)}function sa(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${z} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${z} Infinity values are not supported`)}return new R(A.float,r,e)}function od(r,e,t,n){return sa(ca(r,e+1),3,n)}function sd(r,e,t,n){return sa(aa(r,e+1),5,n)}function cd(r,e,t,n){return sa(ld(r,e+1),9,n)}function Ai(r,e,t){let n=e.value;if(n===!1)r.push([A.float.majorEncoded|ra]);else if(n===!0)r.push([A.float.majorEncoded|na]);else if(n===null)r.push([A.float.majorEncoded|ia]);else if(n===void 0)r.push([A.float.majorEncoded|oa]);else{let i,o=!1;(!t||t.float64!==!0)&&(ud(n),i=ca(lt,1),n===i||Number.isNaN(n)?(lt[0]=249,r.push(lt.slice(0,3)),o=!0):(fd(n),i=aa(lt,1),n===i&&(lt[0]=250,r.push(lt.slice(0,5)),o=!0))),o||(hm(n),i=ld(lt,1),lt[0]=251,r.push(lt.slice(0,9)))}}Ai.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){ud(n);let i=ca(lt,1);if(n===i||Number.isNaN(n))return 3;if(fd(n),i=aa(lt,1),n===i)return 5}return 9};var ad=new ArrayBuffer(9),et=new DataView(ad,1),lt=new Uint8Array(ad,0);function ud(r){if(r===1/0)et.setUint16(0,31744,!1);else if(r===-1/0)et.setUint16(0,64512,!1);else if(Number.isNaN(r))et.setUint16(0,32256,!1);else{et.setFloat32(0,r);let e=et.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)et.setUint16(0,31744,!1);else if(t===0)et.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let i=t-127;i<-24?et.setUint16(0,0):i<-14?et.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):et.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function ca(r,e){if(r.length-e<2)throw new Error(`${z} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,i=t&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,t&32768?-o:o}function fd(r){et.setFloat32(0,r,!1)}function aa(r,e){if(r.length-e<4)throw new Error(`${z} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function hm(r){et.setFloat64(0,r,!1)}function ld(r,e){if(r.length-e<8)throw new Error(`${z} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}Ai.compareTokens=Qe.compareTokens;function oe(r,e,t){throw new Error(`${z} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function $o(r){return()=>{throw new Error(`${z} ${r}`)}}var O=[];for(let r=0;r<=23;r++)O[r]=oe;O[24]=xl;O[25]=bl;O[26]=El;O[27]=Al;O[28]=oe;O[29]=oe;O[30]=oe;O[31]=oe;for(let r=32;r<=55;r++)O[r]=oe;O[56]=vl;O[57]=Bl;O[58]=Sl;O[59]=Tl;O[60]=oe;O[61]=oe;O[62]=oe;O[63]=oe;for(let r=64;r<=87;r++)O[r]=Pl;O[88]=Ul;O[89]=Kl;O[90]=Il;O[91]=Cl;O[92]=oe;O[93]=oe;O[94]=oe;O[95]=$o("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)O[r]=Ol;O[120]=Ll;O[121]=Nl;O[122]=Rl;O[123]=Ml;O[124]=oe;O[125]=oe;O[126]=oe;O[127]=$o("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)O[r]=Hl;O[152]=jl;O[153]=$l;O[154]=Jl;O[155]=Fl;O[156]=oe;O[157]=oe;O[158]=oe;O[159]=Vl;for(let r=160;r<=183;r++)O[r]=Gl;O[184]=ql;O[185]=zl;O[186]=Wl;O[187]=Xl;O[188]=oe;O[189]=oe;O[190]=oe;O[191]=Zl;for(let r=192;r<=215;r++)O[r]=Yl;O[216]=Ql;O[217]=ed;O[218]=td;O[219]=rd;O[220]=oe;O[221]=oe;O[222]=oe;O[223]=oe;for(let r=224;r<=243;r++)O[r]=$o("simple values are not supported");O[244]=oe;O[245]=oe;O[246]=oe;O[247]=nd;O[248]=$o("simple values are not supported");O[249]=od;O[250]=sd;O[251]=cd;O[252]=oe;O[253]=oe;O[254]=oe;O[255]=id;var dt=[];for(let r=0;r<24;r++)dt[r]=new R(A.uint,r,1);for(let r=-1;r>=-24;r--)dt[31-r]=new R(A.negint,r,1);dt[64]=new R(A.bytes,new Uint8Array(0),1);dt[96]=new R(A.string,"",1);dt[128]=new R(A.array,0,1);dt[160]=new R(A.map,0,1);dt[244]=new R(A.false,!1,1);dt[245]=new R(A.true,!0,1);dt[246]=new R(A.null,null,1);function ua(r){switch(r.type){case A.false:return vt([244]);case A.true:return vt([245]);case A.null:return vt([246]);case A.bytes:return r.value.length?void 0:vt([64]);case A.string:return r.value===""?vt([96]):void 0;case A.array:return r.value===0?vt([128]):void 0;case A.map:return r.value===0?vt([160]):void 0;case A.uint:return r.value<24?vt([Number(r.value)]):void 0;case A.negint:if(r.value>=-24)return vt([31-Number(r.value)])}}var ym={float64:!1,mapSorter:gm,quickEncodeToken:ua},md=Object.freeze({float64:!0,mapSorter:xm,quickEncodeToken:ua});function mm(){let r=[];return r[A.uint.major]=Qe,r[A.negint.major]=Ro,r[A.bytes.major]=Bn,r[A.string.major]=Dl,r[A.array.major]=Do,r[A.map.major]=Ho,r[A.tag.major]=jo,r[A.float.major]=Ai,r}var Tn=mm(),Jo=new gi,Bi=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${No} object contains circular references`);return new r(t,e)}},yr={null:new R(A.null,null),undefined:new R(A.undefined,void 0),true:new R(A.true,!0),false:new R(A.false,!1),emptyArray:new R(A.array,0),emptyMap:new R(A.map,0)},Bt={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new R(A.float,r):r>=0?new R(A.uint,r):new R(A.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new R(A.uint,r):new R(A.negint,r)},Uint8Array(r,e,t,n){return new R(A.bytes,r)},string(r,e,t,n){return new R(A.string,r)},boolean(r,e,t,n){return r?yr.true:yr.false},null(r,e,t,n){return yr.null},undefined(r,e,t,n){return yr.undefined},ArrayBuffer(r,e,t,n){return new R(A.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new R(A.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[yr.emptyArray,new R(A.break)]:yr.emptyArray;n=Bi.createCheck(n,r);let i=[],o=0;for(let s of r)i[o++]=Fo(s,t,n);return t.addBreakTokens?[new R(A.array,r.length),i,new R(A.break)]:[new R(A.array,r.length),i]},Object(r,e,t,n){let i=e!=="Object",o=i?r.keys():Object.keys(r),s=i?r.size:o.length,c;if(s){c=new Array(s),n=Bi.createCheck(n,r);let a=!i&&t.ignoreUndefinedProperties,u=0;for(let f of o){let l=i?r.get(f):r[f];a&&l===void 0||(c[u++]=[Fo(f,t,n),Fo(l,t,n)])}u<s&&(c.length=u)}return c?.length?(wm(c,t),t.addBreakTokens?[new R(A.map,c.length),c,new R(A.break)]:[new R(A.map,c.length),c]):t.addBreakTokens===!0?[yr.emptyMap,new R(A.break)]:yr.emptyMap}};Bt.Map=Bt.Object;Bt.Buffer=Bt.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Bt[`${r}Array`]=Bt.DataView;function Fo(r,e={},t){let n=ea(r),i=e&&e.typeEncoders&&e.typeEncoders[n]||Bt[n];if(typeof i=="function"){let s=i(r,n,e,t);if(s!=null)return s}let o=Bt[n];if(!o)throw new Error(`${No} unsupported type: ${n}`);return o(r,n,e,t)}function wm(r,e){e.mapSorter&&r.sort(e.mapSorter)}function gm(r,e){let t=Array.isArray(r[0])?r[0][0]:r[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(t.type!==n.type)return t.type.compare(n.type);let i=t.type.major,o=Tn[i].compareTokens(t,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function xm(r,e){if(r[0]instanceof R&&e[0]instanceof R){let t=r[0],n=e[0];return t._keyBytes||(t._keyBytes=dd(t.value)),n._keyBytes||(n._keyBytes=dd(n.value)),Oo(t._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function dd(r){return gd(r,Tn,md)}function vi(r,e,t,n){if(Array.isArray(e))for(let i of e)vi(r,i,t,n);else t[e.type.major](r,e,n)}var hd=A.uint.majorEncoded,pd=A.negint.majorEncoded,bm=A.bytes.majorEncoded,Em=A.string.majorEncoded,yd=A.array.majorEncoded,Am=A.float.majorEncoded|ra,vm=A.float.majorEncoded|na,Bm=A.float.majorEncoded|ia,Sm=A.float.majorEncoded|oa,km=BigInt(-1),Tm=BigInt(1);function Pm(r){return r.addBreakTokens!==!0}function wd(r,e,t,n){let i=ea(e),o=t.typeEncoders&&t.typeEncoders[i];if(o){let s=o(e,i,t,n);if(s!=null){vi(r,s,Tn,t);return}}switch(i){case"null":r.push([Bm]);return;case"undefined":r.push([Sm]);return;case"boolean":r.push([e?vm:Am]);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Ai(r,new R(A.float,e),t):e>=0?le(r,hd,e):le(r,pd,e*-1-1);return;case"bigint":e>=BigInt(0)?le(r,hd,e):le(r,pd,e*km-Tm);return;case"string":{let s=_o(e);le(r,Em,s.length),r.push(s);return}case"Uint8Array":le(r,bm,e.length),r.push(e);return;case"Array":if(!e.length){r.push([yd]);return}n=Bi.createCheck(n,e),le(r,yd,e.length);for(let s of e)wd(r,s,t,n);return;case"Object":case"Map":{let s=Bt.Object(e,i,t,n);vi(r,s,Tn,t)}return;default:{let s=Bt[i];if(!s)throw new Error(`${No} unsupported type: ${i}`);let c=s(e,i,t,n);vi(r,c,Tn,t)}}}function gd(r,e,t,n){let i=n instanceof Uint8Array,o=i?new Lo(n):Jo,s=Fo(r,t);if(!Array.isArray(s)&&t.quickEncodeToken){let c=t.quickEncodeToken(s);if(c)return i?(o.push(c),o.toBytes()):c;let a=e[s.type.major];if(a.encodedSize){let u=a.encodedSize(s,t);if(i||(o=new gi(u)),a(o,s,t),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():wi(o.chunks[0])}}return o.reset(),vi(o,s,e,t),o.toBytes(!0)}function fa(r,e){return e=Object.assign({},ym,e),Pm(e)?(Jo.reset(),wd(Jo,r,e,void 0),Jo.toBytes(!0)):gd(r,Tn,e)}var Um={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Vo=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=dt[e];if(t===void 0){let n=O[e];if(!n)throw new Error(`${z} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;t=n(this.data,this._pos,i,this.options)}return this._pos+=t.encodedLength,t}},Si=Symbol.for("DONE"),Go=Symbol.for("BREAK");function Km(r,e,t){let n=[];for(let i=0;i<r.value;i++){let o=Pn(e,t);if(o===Go){if(r.value===1/0)break;throw new Error(`${z} got unexpected break to lengthed array`)}if(o===Si)throw new Error(`${z} found array but not enough entries (got ${i}, expected ${r.value})`);n[i]=o}return n}function Im(r,e,t){let n=t.useMaps===!0,i=t.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let c=0;c<r.value;c++){let a=Pn(e,t);if(a===Go){if(r.value===1/0)break;throw new Error(`${z} got unexpected break to lengthed map`)}if(a===Si)throw new Error(`${z} found map but not enough entries (got ${c} [no key], expected ${r.value})`);if(!n&&typeof a!="string")throw new Error(`${z} non-string keys not supported (got ${typeof a})`);if(i&&(n&&s.has(a)||!n&&Object.hasOwn(o,a)))throw new Error(`${z} found repeat map key "${a}"`);let u=Pn(e,t);if(u===Si)throw new Error(`${z} found map but not enough entries (got ${c} [no value], expected ${r.value})`);n?s.set(a,u):o[a]=u}return n?s:o}function Pn(r,e){if(r.done())return Si;let t=r.next();if(A.equals(t.type,A.break))return Go;if(t.type.terminal)return t.value;if(A.equals(t.type,A.array))return Km(t,r,e);if(A.equals(t.type,A.map))return Im(t,r,e);if(A.equals(t.type,A.tag)){if(e.tags&&typeof e.tags[t.value]=="function"){let n=Pn(r,e);return e.tags[t.value](n)}throw new Error(`${z} tag not supported (${t.value})`)}throw new Error("unsupported")}function xd(r,e){if(!(r instanceof Uint8Array))throw new Error(`${z} data to decode must be a Uint8Array`);e=Object.assign({},Um,e);let t=wi(r),n=e.tokenizer||new Vo(t,e),i=Pn(n,e);if(i===Si)throw new Error(`${z} did not find any content to decode`);if(i===Go)throw new Error(`${z} got unexpected break`);return[i,r.subarray(n.pos())]}function la(r,e){let[t,n]=xd(r,e);if(n.length>0)throw new Error(`${z} too many terminals, data makes no sense`);return t}var ht=class{static encode(e){return fa(e)}static decode(e){return la(e,{useMaps:!0})}};var Cm=(n=>(n[n.OKP=1]="OKP",n[n.EC2=2]="EC2",n[n.Symmetric=4]="Symmetric",n))(Cm||{}),_m=(a=>(a[a.P256=1]="P256",a[a.P384=2]="P384",a[a.P521=3]="P521",a[a.X25519=4]="X25519",a[a.X448=5]="X448",a[a.Ed25519=6]="Ed25519",a[a.Ed448=7]="Ed448",a[a.Secp256k1=8]="Secp256k1",a))(_m||{}),bd=(o=>(o[o.EdDSA=-8]="EdDSA",o[o.ES256=-7]="ES256",o[o.ES384=-35]="ES384",o[o.ES512=-36]="ES512",o[o.ES256K=-47]="ES256K",o))(bd||{});var qo={"P-256":1,"P-384":2,"P-521":3,X25519:4,Ed25519:6,Ed448:7,secp256k1:8},zo={1:"P-256",2:"P-384",3:"P-521",4:"X25519",6:"Ed25519",7:"Ed448",8:"secp256k1"},Wo={EdDSA:-8,ES256:-7,ES384:-35,ES512:-36,ES256K:-47},Xo={[-8]:"EdDSA",[-7]:"ES256",[-35]:"ES384",[-36]:"ES512",[-47]:"ES256K"},Zo=class r{static fromJwk(e){let t=new Map;if(e.kty==="OKP"){t.set(1,1);let n=e.crv;if(n===void 0||!(n in qo))throw new V("algorithmNotSupported",`CoseKey: unsupported OKP curve '${n}'`);t.set(-1,qo[n]),e.x!==void 0&&t.set(-2,_.base64Url(e.x).toUint8Array()),e.d!==void 0&&t.set(-4,_.base64Url(e.d).toUint8Array())}else if(e.kty==="EC"){t.set(1,2);let n=e.crv;if(n===void 0||!(n in qo))throw new V("algorithmNotSupported",`CoseKey: unsupported EC curve '${n}'`);t.set(-1,qo[n]),e.x!==void 0&&t.set(-2,_.base64Url(e.x).toUint8Array()),e.y!==void 0&&t.set(-3,_.base64Url(e.y).toUint8Array()),e.d!==void 0&&t.set(-4,_.base64Url(e.d).toUint8Array())}else throw new V("algorithmNotSupported",`CoseKey: unsupported key type '${e.kty}'`);return e.kid!==void 0&&t.set(2,_.string(e.kid).toUint8Array()),e.alg!==void 0&&e.alg in Wo&&t.set(3,Wo[e.alg]),t}static toJwk(e){let t=e.get(1);if(t===1){let n=e.get(-1);if(!(n in zo))throw new V("algorithmNotSupported",`CoseKey: unsupported COSE OKP curve ${n}`);let i={kty:"OKP",crv:zo[n]},o=e.get(-2);o!==void 0&&(i.x=_.uint8Array(o).toBase64Url());let s=e.get(-4);return s!==void 0&&(i.d=_.uint8Array(s).toBase64Url()),r.applyCommonFields(e,i),i}else if(t===2){let n=e.get(-1);if(!(n in zo))throw new V("algorithmNotSupported",`CoseKey: unsupported COSE EC2 curve ${n}`);let i={kty:"EC",crv:zo[n]},o=e.get(-2);o!==void 0&&(i.x=_.uint8Array(o).toBase64Url());let s=e.get(-3);s!==void 0&&(i.y=_.uint8Array(s).toBase64Url());let c=e.get(-4);return c!==void 0&&(i.d=_.uint8Array(c).toBase64Url()),r.applyCommonFields(e,i),i}else throw new V("algorithmNotSupported",`CoseKey: unsupported COSE key type ${t}`)}static algorithmFromJwk(e){if(e.alg!==void 0&&e.alg in Wo)return Wo[e.alg];if(e.kty==="OKP"){if(e.crv==="Ed25519"||e.crv==="Ed448")return-8}else if(e.kty==="EC")switch(e.crv){case"P-256":return-7;case"P-384":return-35;case"P-521":return-36;case"secp256k1":return-47}throw new V("algorithmNotSupported",`CoseKey: cannot determine COSE algorithm for key type '${e.kty}' curve '${e.crv}'`)}static algorithmToJwk(e){if(e in Xo)return Xo[e];throw new V("algorithmNotSupported",`CoseKey: unsupported COSE algorithm ${e}`)}static applyCommonFields(e,t){let n=e.get(2);n!==void 0&&(t.kid=_.uint8Array(n).toString());let i=e.get(3);i!==void 0&&i in Xo&&(t.alg=Xo[i])}};var ki=class r{static async create(e){let{key:t,payload:n,externalAad:i=new Uint8Array(0),detachedPayload:o=!1}=e,s=e.protectedHeader?.alg??Zo.algorithmFromJwk(t),c=r.buildProtectedHeaderMap(e.protectedHeader??{alg:s}),a=ht.encode(c),u=e.unprotectedHeader!==void 0?r.buildUnprotectedHeaderMap(e.unprotectedHeader):new Map,f=r.buildSigStructure1(a,i,n),l=ht.encode(f),h=await r.signBytes(s,t,l),m=[a,u,o?null:n,h];return ht.encode(m)}static async verify(e){let{coseSign1:t,key:n,externalAad:i=new Uint8Array(0)}=e,o=r.decode(t),s=o.payload??e.payload??null;if(s===null)throw new V("invalidCoseSign1","CoseSign1: payload is detached but no payload was provided for verification");let c=r.buildSigStructure1(o.protectedHeaderBytes,i,s),a=ht.encode(c),u=o.protectedHeader.alg;return r.verifyBytes(u,n,a,o.signature)}static decode(e){let t;try{t=ht.decode(e)}catch{throw new V("invalidCoseSign1","CoseSign1: failed to decode CBOR")}if(t!==null&&typeof t=="object"&&"tag"in t){let h=t;h.tag===18&&(t=h.value)}if(!Array.isArray(t)||t.length!==4)throw new V("invalidCoseSign1","CoseSign1: expected a CBOR array of 4 elements [protected, unprotected, payload, signature]");let[n,i,o,s]=t;if(!(n instanceof Uint8Array))throw new V("invalidCoseSign1","CoseSign1: protected header must be a byte string");if(!(s instanceof Uint8Array))throw new V("invalidCoseSign1","CoseSign1: signature must be a byte string");let c;if(n.length===0)c=new Map;else try{c=ht.decode(n)}catch{throw new V("invalidCoseSign1","CoseSign1: failed to decode protected header CBOR")}let a=c.get(1);if(a===void 0||typeof a!="number")throw new V("invalidCoseSign1","CoseSign1: protected header must contain an algorithm identifier (label 1)");let u={alg:a},f=c.get(3);f!==void 0&&(u.contentType=f);let l=c.get(4);return l!==void 0&&(u.kid=l),{protectedHeader:u,protectedHeaderBytes:n,unprotectedHeader:i instanceof Map?i:new Map,payload:o instanceof Uint8Array?o:null,signature:s}}static buildSigStructure1(e,t,n){return["Signature1",e,t,n]}static buildProtectedHeaderMap(e){let t=new Map;return t.set(1,e.alg),e.contentType!==void 0&&t.set(3,e.contentType),e.kid!==void 0&&t.set(4,e.kid),t}static buildUnprotectedHeaderMap(e){let t=new Map;return e.kid!==void 0&&t.set(4,e.kid),t}static async signBytes(e,t,n){switch(e){case-8:return Ue.sign({key:t,data:n});case-7:return Pe.sign({key:t,data:n});default:throw new V("algorithmNotSupported",`CoseSign1: signing algorithm ${e} is not supported`)}}static async verifyBytes(e,t,n,i){switch(e){case-8:return Ue.verify({key:t,signature:i,data:n});case-7:return Pe.verify({key:t,signature:i,data:n});default:throw new V("algorithmNotSupported",`CoseSign1: verification algorithm ${e} is not supported`)}}};var Om=(x=>(x[x.Iss=1]="Iss",x[x.Sub=2]="Sub",x[x.Aud=3]="Aud",x[x.Exp=4]="Exp",x[x.Nbf=5]="Nbf",x[x.Iat=6]="Iat",x[x.Cti=7]="Cti",x[x.Nonce=10]="Nonce",x[x.Ueid=256]="Ueid",x[x.Sueids=257]="Sueids",x[x.Oemid=258]="Oemid",x[x.Hwmodel=259]="Hwmodel",x[x.Hwversion=260]="Hwversion",x[x.Secboot=262]="Secboot",x[x.Dbgstat=263]="Dbgstat",x[x.Location=264]="Location",x[x.Profile=265]="Profile",x[x.Submods=266]="Submods",x[x.Measres=272]="Measres",x[x.Intuse=268]="Intuse",x))(Om||{}),Lm=(o=>(o[o.Enabled=0]="Enabled",o[o.Disabled=1]="Disabled",o[o.DisabledSinceBoot=2]="DisabledSinceBoot",o[o.DisabledPermanently=3]="DisabledPermanently",o[o.DisabledFullyAndPermanently=4]="DisabledFullyAndPermanently",o))(Lm||{}),Nm=(i=>(i[i.Unrestricted=1]="Unrestricted",i[i.Restricted=2]="Restricted",i[i.SecureRestricted=3]="SecureRestricted",i[i.Hardware=4]="Hardware",i))(Nm||{}),Ed=class r{static decode({token:e}){let t=ki.decode(e);if(t.payload===null)throw new V("invalidEat","Eat: token has detached payload; use verifyAndDecode with the payload provided separately");let n=r.parseClaims(t.payload);return{protectedHeader:t.protectedHeader,claims:n}}static async verifyAndDecode(e){let{token:t,key:n,externalAad:i}=e;if(!await ki.verify({coseSign1:t,key:n,externalAad:i}))throw new V("invalidEat","Eat: signature verification failed");return r.decode({token:t})}static parseClaims(e){let t;try{let E=ht.decode(e);if(E instanceof Map)t=E;else if(typeof E=="object"&&E!==null)t=new Map(Object.entries(E));else throw new Error("not a map")}catch(E){throw E instanceof V?E:new V("invalidEat","Eat: payload is not a valid CBOR map")}let n={rawClaims:t},i=t.get(1);i!==void 0&&(n.iss=i);let o=t.get(2);o!==void 0&&(n.sub=o);let s=t.get(3);s!==void 0&&(n.aud=s);let c=t.get(4);c!==void 0&&(n.exp=c);let a=t.get(5);a!==void 0&&(n.nbf=a);let u=t.get(6);u!==void 0&&(n.iat=u);let f=t.get(7);f!==void 0&&(n.cti=f);let l=t.get(10);l!==void 0&&(n.nonce=l);let h=t.get(256);h!==void 0&&(n.ueid=h);let m=t.get(259);m!==void 0&&(n.hwmodel=m);let p=t.get(260);p!==void 0&&(n.hwversion=p);let d=t.get(263);d!==void 0&&(n.dbgstat=d);let y=t.get(272);y!==void 0&&(n.measres=y);let w=t.get(266);return w!==void 0&&(n.submods=w),n}};var zr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function da(r=32){if(zr&&typeof zr.getRandomValues=="function")return zr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function he(){if(zr&&typeof zr.subtle=="object"&&zr.subtle!=null)return zr.subtle;throw new Error("crypto.subtle must be defined")}var Ti=128,Ad=[128,192,256],Yo=Ti,Un=class{static async bytesToPrivateKey({privateKeyBytes:e}){let t={k:_.uint8Array(e).toBase64Url(),kty:"oct"};return t.kid=await q({jwk:t}),t}static async decrypt({key:e,data:t,counter:n,length:i}){if(n.byteLength!==Ti/8)throw new TypeError(`The counter must be ${Ti} bits in length`);if(i===0||i>Yo)throw new TypeError(`The 'length' property must be in the range 1 to ${Yo}`);let o=he(),s=await o.importKey("jwk",e,{name:"AES-CTR"},!0,["decrypt"]),c=await o.decrypt({name:"AES-CTR",counter:n,length:i},s,t);return new Uint8Array(c)}static async encrypt({key:e,data:t,counter:n,length:i}){if(n.byteLength!==Ti/8)throw new TypeError(`The counter must be ${Ti} bits in length`);if(i===0||i>Yo)throw new TypeError(`The 'length' property must be in the range 1 to ${Yo}`);let o=he(),s=await o.importKey("jwk",e,{name:"AES-CTR"},!0,["encrypt","decrypt"]),c=await o.encrypt({name:"AES-CTR",counter:n,length:i},s,t);return new Uint8Array(c)}static async generateKey({length:e}){if(!Ad.includes(e))throw new RangeError(`The key length is invalid: Must be ${Ad.join(", ")} bits`);let t=he(),n=await t.generateKey({name:"AES-CTR",length:e},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await t.exportKey("jwk",n);return s.kid=await q({jwk:s}),s}static async privateKeyToBytes({privateKey:e}){if(!At(e))throw new Error("AesCtr: The provided key is not a valid oct private key.");return _.base64Url(e.k).toUint8Array()}};var vd=class extends ye{async decrypt(e){return Un.decrypt(e)}async encrypt(e){return Un.encrypt(e)}async generateKey({algorithm:e}){let t={A128CTR:128,A192CTR:192,A256CTR:256}[e],n=await Un.generateKey({length:t});return n.alg=e,n}};function Pi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function ha(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function pa(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function W(r,...e){if(!pa(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function mr(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Ui(r,e){W(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Qo=r=>new Uint8Array(r.buffer,r.byteOffset,r.byteLength);var re=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),wr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Rm=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Rm)throw new Error("Non little-endian hardware is not supported");function Mm(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function St(r){if(typeof r=="string")r=Mm(r);else if(pa(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function es(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];W(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}function Bd(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function Ki(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var kt=(r,e)=>(Object.assign(e,r),e);function Wr(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),c=Number(t&o),a=n?4:0,u=n?0:4;r.setUint32(e+a,s,n),r.setUint32(e+u,c,n)}var Sd={async encrypt(r,e,t,n){let i=he(),o=await i.importKey("raw",r,e,!0,["encrypt"]),s=await i.encrypt(t,o,n);return new Uint8Array(s)},async decrypt(r,e,t,n){let i=he(),o=await i.importKey("raw",r,e,!0,["decrypt"]),s=await i.decrypt(t,o,n);return new Uint8Array(s)}},Tt={CBC:"AES-CBC",CTR:"AES-CTR",GCM:"AES-GCM"};function Dm(r,e,t){if(r===Tt.CBC)return{name:Tt.CBC,iv:e};if(r===Tt.CTR)return{name:Tt.CTR,counter:e,length:64};if(r===Tt.GCM)return t?{name:Tt.GCM,iv:e,additionalData:t}:{name:Tt.GCM,iv:e};throw new Error("unknown aes block mode")}function ya(r){return(e,t,n)=>{W(e),W(t);let i={name:r,length:e.length*8},o=Dm(r,t,n);return{encrypt(s){return W(s),Sd.encrypt(e,i,o,s)},decrypt(s){return W(s),Sd.decrypt(e,i,o,s)}}}}var aE=ya(Tt.CBC),uE=ya(Tt.CTR),fE=ya(Tt.GCM);var ts=96,kd=[128,192,256],rs=[96,104,112,120,128],gr=class{static async bytesToPrivateKey({privateKeyBytes:e}){let t={k:_.uint8Array(e).toBase64Url(),kty:"oct"};return t.kid=await q({jwk:t}),t}static async decrypt({key:e,data:t,iv:n,additionalData:i,tagLength:o}){if(n.byteLength!==ts/8)throw new TypeError(`The initialization vector must be ${ts} bits in length`);if(o&&!rs.includes(o))throw new RangeError(`The tag length is invalid: Must be ${rs.join(", ")} bits`);let s=he(),c=await s.importKey("jwk",e,{name:"AES-GCM"},!0,["decrypt"]),a={name:"AES-GCM",iv:n,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.decrypt(a,c,t);return new Uint8Array(u)}static async encrypt({data:e,iv:t,key:n,additionalData:i,tagLength:o}){if(t.byteLength!==ts/8)throw new TypeError(`The initialization vector must be ${ts} bits in length`);if(o&&!rs.includes(o))throw new RangeError(`The tag length is invalid: Must be ${rs.join(", ")} bits`);let s=he(),c=await s.importKey("jwk",n,{name:"AES-GCM"},!0,["encrypt"]),a={name:"AES-GCM",iv:t,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.encrypt(a,c,e);return new Uint8Array(u)}static async generateKey({length:e}){if(!kd.includes(e))throw new RangeError(`The key length is invalid: Must be ${kd.join(", ")} bits`);let t=he(),n=await t.generateKey({name:"AES-GCM",length:e},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await t.exportKey("jwk",n);return s.kid=await q({jwk:s}),s}static async privateKeyToBytes({privateKey:e}){if(!At(e))throw new Error("AesGcm: The provided key is not a valid oct private key.");return _.base64Url(e.k).toUint8Array()}};var Td=class extends ye{async bytesToPrivateKey({privateKeyBytes:e}){let t=await gr.bytesToPrivateKey({privateKeyBytes:e});return t.alg={16:"A128GCM",24:"A192GCM",32:"A256GCM"}[e.length],t}async decrypt(e){return gr.decrypt(e)}async encrypt(e){return gr.encrypt(e)}async generateKey({algorithm:e}){let t={A128GCM:128,A192GCM:192,A256GCM:256}[e],n=await gr.generateKey({length:t});return n.alg=e,n}async privateKeyToBytes({privateKey:e}){return await gr.privateKeyToBytes({privateKey:e})}};var Pd=[128,192,256],xr=class{static async bytesToPrivateKey({privateKeyBytes:e}){let t={k:_.uint8Array(e).toBase64Url(),kty:"oct"};t.kid=await q({jwk:t});let n=e.length*8;return t.alg={128:"A128KW",192:"A192KW",256:"A256KW"}[n],t}static async generateKey({length:e}){if(!Pd.includes(e))throw new RangeError(`The key length is invalid: Must be ${Pd.join(", ")} bits`);let t=he(),n=await t.generateKey({name:"AES-KW",length:e},!0,["wrapKey","unwrapKey"]),{ext:i,key_ops:o,...s}=await t.exportKey("jwk",n);return s.kid=await q({jwk:s}),s}static async privateKeyToBytes({privateKey:e}){if(!At(e))throw new Error("AesKw: The provided key is not a valid oct private key.");return _.base64Url(e.k).toUint8Array()}static async unwrapKey({wrappedKeyBytes:e,wrappedKeyAlgorithm:t,decryptionKey:n}){if(!("alg"in n&&n.alg))throw new V("invalidJwk","The decryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(n.alg))throw new V("algorithmNotSupported",`The 'decryptionKey' algorithm is not supported: ${n.alg}`);let i=he(),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"}[t];if(!s)throw new V("algorithmNotSupported",`The 'wrappedKeyAlgorithm' is not supported: ${t}`);let c=await i.unwrapKey("raw",e.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 q({jwk:l}),l}static async wrapKey({unwrappedKey:e,encryptionKey:t}){if(!("alg"in t&&t.alg))throw new V("invalidJwk","The encryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(t.alg))throw new V("algorithmNotSupported",`The 'encryptionKey' algorithm is not supported: ${t.alg}`);if(!("alg"in e&&e.alg))throw new V("invalidJwk","The private key to wrap is missing the 'alg' property.");let n=he(),i=await n.importKey("jwk",t,{name:"AES-KW"},!0,["wrapKey"]),o={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[e.alg];if(!o)throw new V("algorithmNotSupported",`The 'unwrappedKey' algorithm is not supported: ${e.alg}`);let s=await n.importKey("jwk",e,{name:o},!0,["unwrapKey"]),c=await n.wrapKey("raw",s,i,"AES-KW");return new Uint8Array(c)}};var Ud=class extends ye{async bytesToPrivateKey({privateKeyBytes:e}){let t=await xr.bytesToPrivateKey({privateKeyBytes:e});return t.alg={16:"A128KW",24:"A192KW",32:"A256KW"}[e.length],t}async generateKey({algorithm:e}){let t={A128KW:128,A192KW:192,A256KW:256}[e],n=await xr.generateKey({length:t});return n.alg=e,n}async privateKeyToBytes({privateKey:e}){return await xr.privateKeyToBytes({privateKey:e})}async unwrapKey(e){return await xr.unwrapKey(e)}async wrapKey(e){return xr.wrapKey(e)}};var ns=class{static async deriveKeyBytes({baseKeyBytes:e,length:t,hash:n,salt:i,info:o=new Uint8Array}){let s=he(),c=await s.importKey("raw",e,{name:"HKDF"},!1,["deriveBits"]),a=typeof i=="string"?_.string(i).toUint8Array():i,u=typeof o=="string"?_.string(o).toUint8Array():o,f=await s.deriveBits({name:"HKDF",hash:n,salt:a,info:u},c,t);return new Uint8Array(f)}};var Kd=class extends ye{async deriveKeyBytes({algorithm:e,...t}){let n={"HKDF-256":"SHA-256","HKDF-384":"SHA-384","HKDF-512":"SHA-512"}[e];return await ns.deriveKeyBytes({...t,hash:n})}};var is=class{static async deriveKey({hash:e,password:t,salt:n,iterations:i,length:o}){let s=await Gt.subtle.importKey("raw",t,{name:"PBKDF2"},!1,["deriveBits"]),c=await Gt.subtle.deriveBits({name:"PBKDF2",hash:e,salt:n,iterations:i},s,o);return new Uint8Array(c)}static async deriveKeyBytes({baseKeyBytes:e,hash:t,salt:n,iterations:i,length:o}){let s=he(),c=await s.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"]),a=await s.deriveBits({name:"PBKDF2",hash:t,salt:n,iterations:i},c,o);return new Uint8Array(a)}};var Id=class extends ye{async deriveKeyBytes({algorithm:e,...t}){let[,n]=e.split(/[-+]/),i={HS256:"SHA-256",HS384:"SHA-384",HS512:"SHA-512"}[n];return await is.deriveKeyBytes({...t,hash:i})}};var Cd=class r{static async deriveKey({keyDataLen:e,fixedInfo:t,sharedSecret:n}){let o=Math.ceil(e/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(t);return Me(Vc(s,n,c)).slice(0,e/8)}static computeFixedInfo(e){let t=r.toDataLenData({data:e.algorithmId}),n=r.toDataLenData({data:e.partyUInfo}),i=r.toDataLenData({data:e.partyVInfo}),o=r.toDataLenData({data:e.suppPubInfo,variableLength:!1}),s=r.toDataLenData({data:e.suppPrivInfo});return Vc(t,n,i,o,s)}static toDataLenData({data:e,variableLength:t=!0}){let n,i=On(e);if(i==="Undefined")return new Uint8Array(0);if(t){let o=i==="Uint8Array"?e:new _(e,i).toUint8Array(),s=o.length;n=new Uint8Array(4+s),new DataView(n.buffer).setUint32(0,s),n.set(o,4)}else{if(typeof e!="number")throw TypeError("Fixed length input must be a number.");n=new Uint8Array(4),new DataView(n.buffer).setUint32(0,e)}return n}};var zt=16,wa=new Uint8Array(16),Pt=re(wa),Hm=225,jm=(r,e,t,n)=>{let i=n&1;return{s3:t<<31|n>>>1,s2:e<<31|t>>>1,s1:r<<31|e>>>1,s0:r>>>1^Hm<<24&-(i&1)}},tt=r=>(r>>>0&255)<<24|(r>>>8&255)<<16|(r>>>16&255)<<8|r>>>24&255|0;function $m(r){r.reverse();let e=r[15]&1,t=0;for(let n=0;n<r.length;n++){let i=r[n];r[n]=i>>>1|t,t=(i&1)<<7}return r[0]^=-e&225,r}var Jm=r=>r>64*1024?8:r>1024?4:2,os=class{constructor(e,t){this.blockLen=zt,this.outputLen=zt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=St(e),W(e,16);let n=wr(e),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:tt(i),s1:tt(o),s2:tt(s),s3:tt(c)}),{s0:i,s1:o,s2:s,s3:c}=jm(i,o,s,c);let u=Jm(t||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,h=this.windowSize=2**u,m=[];for(let p=0;p<l;p++)for(let d=0;d<h;d++){let y=0,w=0,E=0,b=0;for(let x=0;x<u;x++){if(!(d>>>u-x-1&1))continue;let{s0:T,s1:K,s2:P,s3:M}=a[u*p+x];y^=T,w^=K,E^=P,b^=M}m.push({s0:y,s1:w,s2:E,s3:b})}this.t=m}_updateBlock(e,t,n,i){e^=this.s0,t^=this.s1,n^=this.s2,i^=this.s3;let{W:o,t:s,windowSize:c}=this,a=0,u=0,f=0,l=0,h=(1<<o)-1,m=0;for(let p of[e,t,n,i])for(let d=0;d<4;d++){let y=p>>>8*d&255;for(let w=8/o-1;w>=0;w--){let E=y>>>o*w&h,{s0:b,s1:x,s2:B,s3:T}=s[m*c+E];a^=b,u^=x,f^=B,l^=T,m+=1}}this.s0=a,this.s1=u,this.s2=f,this.s3=l}update(e){e=St(e),mr(this);let t=re(e),n=Math.floor(e.length/zt),i=e.length%zt;for(let o=0;o<n;o++)this._updateBlock(t[o*4+0],t[o*4+1],t[o*4+2],t[o*4+3]);return i&&(wa.set(e.subarray(n*zt)),this._updateBlock(Pt[0],Pt[1],Pt[2],Pt[3]),Pt.fill(0)),this}destroy(){let{t:e}=this;for(let t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){mr(this),Ui(e,this),this.finished=!0;let{s0:t,s1:n,s2:i,s3:o}=this,s=re(e);return s[0]=t,s[1]=n,s[2]=i,s[3]=o,e}digest(){let e=new Uint8Array(zt);return this.digestInto(e),this.destroy(),e}},ma=class extends os{constructor(e,t){e=St(e);let n=$m(e.slice());super(n,t),n.fill(0)}update(e){e=St(e),mr(this);let t=re(e),n=e.length%zt,i=Math.floor(e.length/zt);for(let o=0;o<i;o++)this._updateBlock(tt(t[o*4+3]),tt(t[o*4+2]),tt(t[o*4+1]),tt(t[o*4+0]));return n&&(wa.set(e.subarray(i*zt)),this._updateBlock(tt(Pt[3]),tt(Pt[2]),tt(Pt[1]),tt(Pt[0])),Pt.fill(0)),this}digestInto(e){mr(this),Ui(e,this),this.finished=!0;let{s0:t,s1:n,s2:i,s3:o}=this,s=re(e);return s[0]=t,s[1]=n,s[2]=i,s[3]=o,e.reverse()}};function _d(r){let e=(n,i)=>r(i,n.length).update(St(n)).digest(),t=r(new Uint8Array(16),0);return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=(n,i)=>r(n,i),e}var ga=_d((r,e)=>new os(r,e)),Od=_d((r,e)=>new ma(r,e));var Ke=16,Ea=4,ss=new Uint8Array(Ke),Fm=283;function Aa(r){return r<<1^Fm&-(r>>7)}function Kn(r,e){let t=0;for(;e>0;e>>=1)t^=r&-(e&1),r=Aa(r);return t}var ba=(()=>{let r=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=Aa(n))r[t]=n;let e=new Uint8Array(256);e[0]=99;for(let t=0;t<255;t++){let n=r[255-t];n|=n<<8,e[r[t]]=(n^n>>4^n>>5^n>>6^n>>7^99)&255}return e})(),Vm=ba.map((r,e)=>ba.indexOf(e)),Gm=r=>r<<24|r>>>8,xa=r=>r<<8|r>>>24;function Ld(r,e){if(r.length!==256)throw new Error("Wrong sbox length");let t=new Uint32Array(256).map((u,f)=>e(r[f])),n=t.map(xa),i=n.map(xa),o=i.map(xa),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]=t[u]^n[f],c[l]=i[u]^o[f],a[l]=r[u]<<8|r[f]}return{sbox:r,sbox2:a,T0:t,T1:n,T2:i,T3:o,T01:s,T23:c}}var va=Ld(ba,r=>Kn(r,3)<<24|r<<16|r<<8|Kn(r,2)),Nd=Ld(Vm,r=>Kn(r,11)<<24|Kn(r,13)<<16|Kn(r,9)<<8|Kn(r,14)),qm=(()=>{let r=new Uint8Array(16);for(let e=0,t=1;e<16;e++,t=Aa(t))r[e]=t;return r})();function Er(r){W(r);let e=r.length;if(![16,24,32].includes(e))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${e}`);let{sbox2:t}=va,n=re(r),i=n.length,o=c=>Ut(t,c,c,c,c),s=new Uint32Array(e+28);s.set(n);for(let c=i;c<s.length;c++){let a=s[c-1];c%i===0?a=o(Gm(a))^qm[c/i-1]:i>6&&c%i===4&&(a=o(a)),s[c]=s[c-i]^a}return s}function Rd(r){let e=Er(r),t=e.slice(),n=e.length,{sbox2:i}=va,{T0:o,T1:s,T2:c,T3:a}=Nd;for(let u=0;u<n;u+=4)for(let f=0;f<4;f++)t[u+f]=e[n-u-4+f];e.fill(0);for(let u=4;u<n-4;u++){let f=t[u],l=Ut(i,f,f,f,f);t[u]=o[l&255]^s[l>>>8&255]^c[l>>>16&255]^a[l>>>24]}return t}function br(r,e,t,n,i,o){return r[t<<8&65280|n>>>8&255]^e[i>>>8&65280|o>>>24&255]}function Ut(r,e,t,n,i){return r[e&255|t&65280]|r[n>>>16&255|i>>>16&65280]<<16}function rt(r,e,t,n,i){let{sbox2:o,T01:s,T23:c}=va,a=0;e^=r[a++],t^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let d=r[a++]^br(s,c,e,t,n,i),y=r[a++]^br(s,c,t,n,i,e),w=r[a++]^br(s,c,n,i,e,t),E=r[a++]^br(s,c,i,e,t,n);e=d,t=y,n=w,i=E}let f=r[a++]^Ut(o,e,t,n,i),l=r[a++]^Ut(o,t,n,i,e),h=r[a++]^Ut(o,n,i,e,t),m=r[a++]^Ut(o,i,e,t,n);return{s0:f,s1:l,s2:h,s3:m}}function Md(r,e,t,n,i){let{sbox2:o,T01:s,T23:c}=Nd,a=0;e^=r[a++],t^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let d=r[a++]^br(s,c,e,i,n,t),y=r[a++]^br(s,c,t,e,i,n),w=r[a++]^br(s,c,n,t,e,i),E=r[a++]^br(s,c,i,n,t,e);e=d,t=y,n=w,i=E}let f=r[a++]^Ut(o,e,i,n,t),l=r[a++]^Ut(o,t,e,i,n),h=r[a++]^Ut(o,n,t,e,i),m=r[a++]^Ut(o,i,n,t,e);return{s0:f,s1:l,s2:h,s3:m}}function In(r,e){if(!e)return new Uint8Array(r);if(W(e),e.length<r)throw new Error(`aes: wrong destination length, expected at least ${r}, got: ${e.length}`);return e}function zm(r,e,t,n){W(e,Ke),W(t);let i=t.length;n=In(i,n);let o=e,s=re(o),{s0:c,s1:a,s2:u,s3:f}=rt(r,s[0],s[1],s[2],s[3]),l=re(t),h=re(n);for(let p=0;p+4<=l.length;p+=4){h[p+0]=l[p+0]^c,h[p+1]=l[p+1]^a,h[p+2]=l[p+2]^u,h[p+3]=l[p+3]^f;let d=1;for(let y=o.length-1;y>=0;y--)d=d+(o[y]&255)|0,o[y]=d&255,d>>>=8;({s0:c,s1:a,s2:u,s3:f}=rt(r,s[0],s[1],s[2],s[3]))}let m=Ke*Math.floor(l.length/Ea);if(m<i){let p=new Uint32Array([c,a,u,f]),d=Qo(p);for(let y=m,w=0;y<i;y++,w++)n[y]=t[y]^d[w]}return n}function Ii(r,e,t,n,i){W(t,Ke),W(n),i=In(n.length,i);let o=t,s=re(o),c=wr(o),a=re(n),u=re(i),f=e?0:12,l=n.length,h=c.getUint32(f,e),{s0:m,s1:p,s2:d,s3:y}=rt(r,s[0],s[1],s[2],s[3]);for(let E=0;E+4<=a.length;E+=4)u[E+0]=a[E+0]^m,u[E+1]=a[E+1]^p,u[E+2]=a[E+2]^d,u[E+3]=a[E+3]^y,h=h+1>>>0,c.setUint32(f,h,e),{s0:m,s1:p,s2:d,s3:y}=rt(r,s[0],s[1],s[2],s[3]);let w=Ke*Math.floor(a.length/Ea);if(w<l){let E=new Uint32Array([m,p,d,y]),b=Qo(E);for(let x=w,B=0;x<l;x++,B++)i[x]=n[x]^b[B]}return i}var WE=kt({blockSize:16,nonceLength:16},function(e,t){W(e),W(t,Ke);function n(i,o){let s=Er(e),c=t.slice(),a=zm(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 Dd(r){if(W(r),r.length%Ke!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Ke}`)}function Hd(r,e,t){let n=r.length,i=n%Ke;if(!e&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");let o=re(r);if(e){let a=Ke-i;a||(a=Ke),n=n+a}let s=In(n,t),c=re(s);return{b:o,o:c,out:s}}function jd(r,e){if(!e)return r;let t=r.length;if(!t)throw new Error("aes/pcks5: empty ciphertext not allowed");let n=r[t-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[t-o-1]!==n)throw new Error("aes/pcks5: wrong padding");return i}function $d(r){let e=new Uint8Array(16),t=re(e);e.set(r);let n=Ke-r.length;for(let i=Ke-n;i<Ke;i++)e[i]=n;return t}var XE=kt({blockSize:16},function(e,t={}){W(e);let n=!t.disablePadding;return{encrypt:(i,o)=>{W(i);let{b:s,o:c,out:a}=Hd(i,n,o),u=Er(e),f=0;for(;f+4<=s.length;){let{s0:l,s1:h,s2:m,s3:p}=rt(u,s[f+0],s[f+1],s[f+2],s[f+3]);c[f++]=l,c[f++]=h,c[f++]=m,c[f++]=p}if(n){let l=$d(i.subarray(f*4)),{s0:h,s1:m,s2:p,s3:d}=rt(u,l[0],l[1],l[2],l[3]);c[f++]=h,c[f++]=m,c[f++]=p,c[f++]=d}return u.fill(0),a},decrypt:(i,o)=>{Dd(i);let s=Rd(e),c=In(i.length,o),a=re(i),u=re(c);for(let f=0;f+4<=a.length;){let{s0:l,s1:h,s2:m,s3:p}=Md(s,a[f+0],a[f+1],a[f+2],a[f+3]);u[f++]=l,u[f++]=h,u[f++]=m,u[f++]=p}return s.fill(0),jd(c,n)}}}),ZE=kt({blockSize:16,nonceLength:16},function(e,t,n={}){W(e),W(t,16);let i=!n.disablePadding;return{encrypt:(o,s)=>{let c=Er(e),{b:a,o:u,out:f}=Hd(o,i,s),l=re(t),h=l[0],m=l[1],p=l[2],d=l[3],y=0;for(;y+4<=a.length;)h^=a[y+0],m^=a[y+1],p^=a[y+2],d^=a[y+3],{s0:h,s1:m,s2:p,s3:d}=rt(c,h,m,p,d),u[y++]=h,u[y++]=m,u[y++]=p,u[y++]=d;if(i){let w=$d(o.subarray(y*4));h^=w[0],m^=w[1],p^=w[2],d^=w[3],{s0:h,s1:m,s2:p,s3:d}=rt(c,h,m,p,d),u[y++]=h,u[y++]=m,u[y++]=p,u[y++]=d}return c.fill(0),f},decrypt:(o,s)=>{Dd(o);let c=Rd(e),a=re(t),u=In(o.length,s),f=re(o),l=re(u),h=a[0],m=a[1],p=a[2],d=a[3];for(let y=0;y+4<=f.length;){let w=h,E=m,b=p,x=d;h=f[y+0],m=f[y+1],p=f[y+2],d=f[y+3];let{s0:B,s1:T,s2:K,s3:P}=Md(c,h,m,p,d);l[y++]=B^w,l[y++]=T^E,l[y++]=K^b,l[y++]=P^x}return c.fill(0),jd(u,i)}}}),YE=kt({blockSize:16,nonceLength:16},function(e,t){W(e),W(t,16);function n(i,o,s){let c=Er(e),a=i.length;s=In(a,s);let u=re(i),f=re(s),l=o?f:u,h=re(t),m=h[0],p=h[1],d=h[2],y=h[3];for(let E=0;E+4<=u.length;){let{s0:b,s1:x,s2:B,s3:T}=rt(c,m,p,d,y);f[E+0]=u[E+0]^b,f[E+1]=u[E+1]^x,f[E+2]=u[E+2]^B,f[E+3]=u[E+3]^T,m=l[E++],p=l[E++],d=l[E++],y=l[E++]}let w=Ke*Math.floor(u.length/Ea);if(w<a){({s0:m,s1:p,s2:d,s3:y}=rt(c,m,p,d,y));let E=Qo(new Uint32Array([m,p,d,y]));for(let b=w,x=0;b<a;b++,x++)s[b]=i[b]^E[x];E.fill(0)}return c.fill(0),s}return{encrypt:(i,o)=>n(i,!0,o),decrypt:(i,o)=>n(i,!1,o)}});function Jd(r,e,t,n,i){let o=r.create(t,n.length+(i?.length||0));i&&o.update(i),o.update(n);let s=new Uint8Array(16),c=wr(s);return i&&Wr(c,0,BigInt(i.length*8),e),Wr(c,8,BigInt(n.length*8),e),o.update(s),o.digest()}var Ba=kt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){if(W(t),t.length===0)throw new Error("aes/gcm: empty nonce");let i=16;function o(c,a,u){let f=Jd(ga,!1,c,u,n);for(let l=0;l<a.length;l++)f[l]^=a[l];return f}function s(){let c=Er(e),a=ss.slice(),u=ss.slice();if(Ii(c,!1,u,u,a),t.length===12)u.set(t);else{let l=ss.slice(),h=wr(l);Wr(h,8,BigInt(t.length*8),!1),ga.create(a).update(t).update(l).digestInto(u)}let f=Ii(c,!1,u,ss);return{xk:c,authKey:a,counter:u,tagMask:f}}return{encrypt:c=>{W(c);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),h=new Uint8Array(c.length+i);Ii(a,!1,f,c,h);let m=o(u,l,h.subarray(0,h.length-i));return h.set(m,c.length),a.fill(0),h},decrypt:c=>{if(W(c),c.length<i)throw new Error(`aes/gcm: ciphertext less than tagLen (${i})`);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),h=c.subarray(0,-i),m=c.subarray(-i),p=o(u,l,h);if(!Ki(p,m))throw new Error("aes/gcm: invalid ghash tag");let d=Ii(a,!1,f,h);return u.fill(0),l.fill(0),a.fill(0),d}}}),cs=(r,e,t)=>n=>{if(!Number.isSafeInteger(n)||e>n||n>t)throw new Error(`${r}: invalid value=${n}, must be [${e}..${t}]`)},QE=kt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){let o=cs("AAD",0,68719476736),s=cs("plaintext",0,2**36),c=cs("nonce",12,12),a=cs("ciphertext",16,2**36+16);W(t),c(t.length),n&&(W(n),o(n.length));function u(){let h=e.length;if(h!==16&&h!==24&&h!==32)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${h} bytes`);let m=Er(e),p=new Uint8Array(h),d=new Uint8Array(16),y=re(t),w=0,E=y[0],b=y[1],x=y[2],B=0;for(let T of[d,p].map(re)){let K=re(T);for(let P=0;P<K.length;P+=2){let{s0:M,s1:D}=rt(m,w,E,b,x);K[P+0]=M,K[P+1]=D,w=++B}}return m.fill(0),{authKey:d,encKey:Er(p)}}function f(h,m,p){let d=Jd(Od,!0,m,p,n);for(let B=0;B<12;B++)d[B]^=t[B];d[15]&=127;let y=re(d),w=y[0],E=y[1],b=y[2],x=y[3];return{s0:w,s1:E,s2:b,s3:x}=rt(h,w,E,b,x),y[0]=w,y[1]=E,y[2]=b,y[3]=x,d}function l(h,m,p){let d=m.slice();return d[15]|=128,Ii(h,!0,d,p)}return{encrypt:h=>{W(h),s(h.length);let{encKey:m,authKey:p}=u(),d=f(m,p,h),y=new Uint8Array(h.length+16);return y.set(d,h.length),y.set(l(m,d,h)),m.fill(0),p.fill(0),y},decrypt:h=>{W(h),a(h.length);let m=h.subarray(-16),{encKey:p,authKey:d}=u(),y=l(p,m,h.subarray(0,-16)),w=f(p,d,y);if(p.fill(0),d.fill(0),!Ki(m,w))throw new Error("invalid polyval tag");return y}}});var as=class extends bn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,li(e);let n=ar(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return xn(this),this.iHash.update(e),this}digestInto(e){xn(this),gn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},us=(r,e,t)=>new as(r,e).update(t).digest();us.create=(r,e)=>new as(r,e);function Wm(r,e,t){return li(r),t===void 0&&(t=new Uint8Array(r.outputLen)),us(r,ar(t),ar(e))}var Sa=new Uint8Array([0]),Fd=new Uint8Array;function Xm(r,e,t,n=32){if(li(r),vo(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/r.outputLen);t===void 0&&(t=Fd);let o=new Uint8Array(i*r.outputLen),s=us.create(r,e),c=s._cloneInto(),a=new Uint8Array(s.outputLen);for(let u=0;u<i;u++)Sa[0]=u+1,c.update(u===0?Fd:a).update(t).update(Sa).digestInto(a),o.set(a,r.outputLen*u),s._cloneInto(c);return s.destroy(),c.destroy(),a.fill(0),Sa.fill(0),o.slice(0,n)}var ka=(r,e,t,n,i)=>Xm(r,Wm(r,e,t),n,i);var Vd=16,Zm=16,Gd=class{static encrypt(e,t){let n=pe.utils.randomPrivateKey(),i=pe.getPublicKey(n,!0),o=pe.getPublicKey(n,!1),s=pe.getSharedSecret(n,e,!1),c=ka(Me,es(o,s),void 0,void 0,32),a=da(Zm),u=Ba(c,a).encrypt(t);return{ephemeralPublicKey:i,initializationVector:a,messageAuthenticationCode:u.subarray(u.length-Vd),ciphertext:u.subarray(0,u.length-Vd)}}static decrypt(e){let{privateKey:t,ephemeralPublicKey:n,initializationVector:i,messageAuthenticationCode:o,ciphertext:s}=e,c=pe.ProjectivePoint.fromHex(n).toRawBytes(!1),a=pe.getSharedSecret(t,n,!1),u=ka(Me,es(c,a),void 0,void 0,32),f=es(s,o);return Ba(u,Uint8Array.from(i)).decrypt(f)}static get isEphemeralKeyCompressed(){return!0}};var Ae=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Ta=class{constructor(e){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,e=St(e),W(e,32);let t=Ae(e,0),n=Ae(e,2),i=Ae(e,4),o=Ae(e,6),s=Ae(e,8),c=Ae(e,10),a=Ae(e,12),u=Ae(e,14);this.r[0]=t&8191,this.r[1]=(t>>>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]=Ae(e,16+2*f)}process(e,t,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],h=s[5],m=s[6],p=s[7],d=s[8],y=s[9],w=Ae(e,t+0),E=Ae(e,t+2),b=Ae(e,t+4),x=Ae(e,t+6),B=Ae(e,t+8),T=Ae(e,t+10),K=Ae(e,t+12),P=Ae(e,t+14),M=o[0]+(w&8191),D=o[1]+((w>>>13|E<<3)&8191),L=o[2]+((E>>>10|b<<6)&8191),J=o[3]+((b>>>7|x<<9)&8191),$=o[4]+((x>>>4|B<<12)&8191),ee=o[5]+(B>>>1&8191),S=o[6]+((B>>>14|T<<2)&8191),I=o[7]+((T>>>11|K<<5)&8191),H=o[8]+((K>>>8|P<<8)&8191),k=o[9]+(P>>>5|i),g=0,U=g+M*c+D*(5*y)+L*(5*d)+J*(5*p)+$*(5*m);g=U>>>13,U&=8191,U+=ee*(5*h)+S*(5*l)+I*(5*f)+H*(5*u)+k*(5*a),g+=U>>>13,U&=8191;let C=g+M*a+D*c+L*(5*y)+J*(5*d)+$*(5*p);g=C>>>13,C&=8191,C+=ee*(5*m)+S*(5*h)+I*(5*l)+H*(5*f)+k*(5*u),g+=C>>>13,C&=8191;let N=g+M*u+D*a+L*c+J*(5*y)+$*(5*d);g=N>>>13,N&=8191,N+=ee*(5*p)+S*(5*m)+I*(5*h)+H*(5*l)+k*(5*f),g+=N>>>13,N&=8191;let F=g+M*f+D*u+L*a+J*c+$*(5*y);g=F>>>13,F&=8191,F+=ee*(5*d)+S*(5*p)+I*(5*m)+H*(5*h)+k*(5*l),g+=F>>>13,F&=8191;let G=g+M*l+D*f+L*u+J*a+$*c;g=G>>>13,G&=8191,G+=ee*(5*y)+S*(5*d)+I*(5*p)+H*(5*m)+k*(5*h),g+=G>>>13,G&=8191;let te=g+M*h+D*l+L*f+J*u+$*a;g=te>>>13,te&=8191,te+=ee*c+S*(5*y)+I*(5*d)+H*(5*p)+k*(5*m),g+=te>>>13,te&=8191;let X=g+M*m+D*h+L*l+J*f+$*u;g=X>>>13,X&=8191,X+=ee*a+S*c+I*(5*y)+H*(5*d)+k*(5*p),g+=X>>>13,X&=8191;let Z=g+M*p+D*m+L*h+J*l+$*f;g=Z>>>13,Z&=8191,Z+=ee*u+S*a+I*c+H*(5*y)+k*(5*d),g+=Z>>>13,Z&=8191;let ae=g+M*d+D*p+L*m+J*h+$*l;g=ae>>>13,ae&=8191,ae+=ee*f+S*u+I*a+H*c+k*(5*y),g+=ae>>>13,ae&=8191;let ce=g+M*y+D*d+L*p+J*m+$*h;g=ce>>>13,ce&=8191,ce+=ee*l+S*f+I*u+H*a+k*c,g+=ce>>>13,ce&=8191,g=(g<<2)+g|0,g=g+U|0,U=g&8191,g=g>>>13,C+=g,o[0]=U,o[1]=C,o[2]=N,o[3]=F,o[4]=G,o[5]=te,o[6]=X,o[7]=Z,o[8]=ae,o[9]=ce}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=i,i=e[c]>>>13,e[c]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=e[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++)e[c]=e[c]&o|n[c];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let c=1;c<8;c++)s=(e[c]+t[c]|0)+(s>>>16)|0,e[c]=s&65535}update(e){mr(this);let{buffer:t,blockLen:n}=this;e=St(e);let i=e.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(e,o);continue}t.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,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(e){mr(this),Ui(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:i}=this;if(i){for(t[i++]=1;i<16;i++)t[i]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)e[o++]=n[s]>>>0,e[o++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Ym(r){let e=(n,i)=>r(i).update(St(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var qd=Ym(r=>new Ta(r));var Wd=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),Qm=Wd("expand 16-byte k"),ew=Wd("expand 32-byte k"),tw=re(Qm),Xd=re(ew),b8=Xd.slice();function j(r,e){return r<<e|r>>>32-e}function Pa(r){return r.byteOffset%4===0}var fs=64,rw=16,Zd=2**32-1,zd=new Uint32Array;function nw(r,e,t,n,i,o,s,c){let a=i.length,u=new Uint8Array(fs),f=re(u),l=Pa(i)&&Pa(o),h=l?re(i):zd,m=l?re(o):zd;for(let p=0;p<a;s++){if(r(e,t,n,f,s,c),s>=Zd)throw new Error("arx: counter overflow");let d=Math.min(fs,a-p);if(l&&d===fs){let y=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let w=0,E;w<rw;w++)E=y+w,m[E]=h[E]^f[w];p+=fs;continue}for(let y=0,w;y<d;y++)w=p+y,o[w]=i[w]^u[y];p+=d}}function Ua(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=Bd({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Pi(i),Pi(s),ha(o),ha(t),(c,a,u,f,l=0)=>{W(c),W(a),W(u);let h=u.length;if(f||(f=new Uint8Array(h)),W(f),Pi(l),l<0||l>=Zd)throw new Error("arx: counter overflow");if(f.length<h)throw new Error(`arx: output (${f.length}) is shorter than data (${h})`);let m=[],p=c.length,d,y;if(p===32)d=c.slice(),m.push(d),y=Xd;else if(p===16&&t)d=new Uint8Array(32),d.set(c),d.set(c,16),y=tw,m.push(d);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Pa(a)||(a=a.slice(),m.push(a));let w=re(d);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(y,w,re(a.subarray(0,16)),w),a=a.subarray(16)}let E=16-i;if(E!==a.length)throw new Error(`arx: nonce must be ${E} or 16 bytes`);if(E!==12){let x=new Uint8Array(12);x.set(a,o?0:12-a.length),a=x,m.push(a)}let b=re(a);for(nw(r,y,w,b,u,f,l,s);m.length>0;)m.pop().fill(0);return f}}function eh(r,e,t,n,i,o=20){let s=r[0],c=r[1],a=r[2],u=r[3],f=e[0],l=e[1],h=e[2],m=e[3],p=e[4],d=e[5],y=e[6],w=e[7],E=i,b=t[0],x=t[1],B=t[2],T=s,K=c,P=a,M=u,D=f,L=l,J=h,$=m,ee=p,S=d,I=y,H=w,k=E,g=b,U=x,C=B;for(let F=0;F<o;F+=2)T=T+D|0,k=j(k^T,16),ee=ee+k|0,D=j(D^ee,12),T=T+D|0,k=j(k^T,8),ee=ee+k|0,D=j(D^ee,7),K=K+L|0,g=j(g^K,16),S=S+g|0,L=j(L^S,12),K=K+L|0,g=j(g^K,8),S=S+g|0,L=j(L^S,7),P=P+J|0,U=j(U^P,16),I=I+U|0,J=j(J^I,12),P=P+J|0,U=j(U^P,8),I=I+U|0,J=j(J^I,7),M=M+$|0,C=j(C^M,16),H=H+C|0,$=j($^H,12),M=M+$|0,C=j(C^M,8),H=H+C|0,$=j($^H,7),T=T+L|0,C=j(C^T,16),I=I+C|0,L=j(L^I,12),T=T+L|0,C=j(C^T,8),I=I+C|0,L=j(L^I,7),K=K+J|0,k=j(k^K,16),H=H+k|0,J=j(J^H,12),K=K+J|0,k=j(k^K,8),H=H+k|0,J=j(J^H,7),P=P+$|0,g=j(g^P,16),ee=ee+g|0,$=j($^ee,12),P=P+$|0,g=j(g^P,8),ee=ee+g|0,$=j($^ee,7),M=M+D|0,U=j(U^M,16),S=S+U|0,D=j(D^S,12),M=M+D|0,U=j(U^M,8),S=S+U|0,D=j(D^S,7);let N=0;n[N++]=s+T|0,n[N++]=c+K|0,n[N++]=a+P|0,n[N++]=u+M|0,n[N++]=f+D|0,n[N++]=l+L|0,n[N++]=h+J|0,n[N++]=m+$|0,n[N++]=p+ee|0,n[N++]=d+S|0,n[N++]=y+I|0,n[N++]=w+H|0,n[N++]=E+k|0,n[N++]=b+g|0,n[N++]=x+U|0,n[N++]=B+C|0}function iw(r,e,t,n){let i=r[0],o=r[1],s=r[2],c=r[3],a=e[0],u=e[1],f=e[2],l=e[3],h=e[4],m=e[5],p=e[6],d=e[7],y=t[0],w=t[1],E=t[2],b=t[3];for(let B=0;B<20;B+=2)i=i+a|0,y=j(y^i,16),h=h+y|0,a=j(a^h,12),i=i+a|0,y=j(y^i,8),h=h+y|0,a=j(a^h,7),o=o+u|0,w=j(w^o,16),m=m+w|0,u=j(u^m,12),o=o+u|0,w=j(w^o,8),m=m+w|0,u=j(u^m,7),s=s+f|0,E=j(E^s,16),p=p+E|0,f=j(f^p,12),s=s+f|0,E=j(E^s,8),p=p+E|0,f=j(f^p,7),c=c+l|0,b=j(b^c,16),d=d+b|0,l=j(l^d,12),c=c+l|0,b=j(b^c,8),d=d+b|0,l=j(l^d,7),i=i+u|0,b=j(b^i,16),p=p+b|0,u=j(u^p,12),i=i+u|0,b=j(b^i,8),p=p+b|0,u=j(u^p,7),o=o+f|0,y=j(y^o,16),d=d+y|0,f=j(f^d,12),o=o+f|0,y=j(y^o,8),d=d+y|0,f=j(f^d,7),s=s+l|0,w=j(w^s,16),h=h+w|0,l=j(l^h,12),s=s+l|0,w=j(w^s,8),h=h+w|0,l=j(l^h,7),c=c+a|0,E=j(E^c,16),m=m+E|0,a=j(a^m,12),c=c+a|0,E=j(E^c,8),m=m+E|0,a=j(a^m,7);let x=0;n[x++]=i,n[x++]=o,n[x++]=s,n[x++]=c,n[x++]=y,n[x++]=w,n[x++]=E,n[x++]=b}var ow=Ua(eh,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ls=Ua(eh,{counterRight:!1,counterLength:8,extendNonceFn:iw,allowShortKeys:!1});var sw=new Uint8Array(16),Yd=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(sw.subarray(t))},cw=new Uint8Array(32);function Qd(r,e,t,n,i){let o=r(e,t,cw),s=qd.create(o);i&&Yd(s,i),Yd(s,n);let c=new Uint8Array(16),a=wr(c);Wr(a,0,BigInt(i?i.length:0),!0),Wr(a,8,BigInt(n.length),!0),s.update(c);let u=s.digest();return o.fill(0),u}var th=r=>(e,t,n)=>(W(e,32),W(t),{encrypt:(o,s)=>{let c=o.length,a=c+16;s?W(s,a):s=new Uint8Array(a),r(e,t,o,s,1);let u=Qd(r,e,t,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?W(s,a):s=new Uint8Array(a);let u=o.subarray(0,-16),f=o.subarray(-16),l=Qd(r,e,t,u,n);if(!Ki(f,l))throw new Error("invalid tag");return r(e,t,u,s,1),s}}),k8=kt({blockSize:64,nonceLength:12,tagLength:16},th(ow)),Ka=kt({blockSize:64,nonceLength:24,tagLength:16},th(ls));var rh=class r{static async bytesToPrivateKey({privateKeyBytes:e}){let t={k:_.uint8Array(e).toBase64Url(),kty:"oct"};return t.kid=await q({jwk:t}),t}static async decrypt({data:e,key:t,nonce:n}){let i=await r.privateKeyToBytes({privateKey:t});return ls(i,n,e)}static async encrypt({data:e,key:t,nonce:n}){let i=await r.privateKeyToBytes({privateKey:t});return ls(i,n,e)}static async generateKey(){let e=he(),t=await e.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await e.exportKey("jwk",t);return s.kid=await q({jwk:s}),s}static async privateKeyToBytes({privateKey:e}){if(!At(e))throw new Error("XChaCha20: The provided key is not a valid oct private key.");return _.base64Url(e.k).toUint8Array()}};var R8=16,nh=class r{static async bytesToPrivateKey({privateKeyBytes:e}){let t={k:_.uint8Array(e).toBase64Url(),kty:"oct"};return t.kid=await q({jwk:t}),t}static async decrypt({data:e,key:t,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:t});return r.decryptRaw({data:e,keyBytes:o,nonce:n,additionalData:i})}static async decryptRaw({data:e,keyBytes:t,nonce:n,additionalData:i}){return Ka(t,n,i).decrypt(e)}static async encrypt({data:e,key:t,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:t});return r.encryptRaw({data:e,keyBytes:o,nonce:n,additionalData:i})}static async encryptRaw({data:e,keyBytes:t,nonce:n,additionalData:i}){return Ka(t,n,i).encrypt(e)}static async generateKey(){let e=he(),t=await e.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await e.exportKey("jwk",t);return s.kid=await q({jwk:s}),s}static async privateKeyToBytes({privateKey:e}){if(!At(e))throw new Error("XChaCha20Poly1305: The provided key is not a valid oct private key.");return _.base64Url(e.k).toUint8Array()}};export{rs as AES_GCM_TAG_LENGTHS,Un as AesCtr,vd as AesCtrAlgorithm,gr as AesGcm,Td as AesGcmAlgorithm,xr as AesKw,Ud as AesKwAlgorithm,ht as Cbor,Cd as ConcatKdf,bd as CoseAlgorithm,_m as CoseEllipticCurve,Zo as CoseKey,Cm as CoseKeyType,ki as CoseSign1,ye as CryptoAlgorithm,V as CryptoError,Wt as CryptoErrorCode,pl as CryptoUtils,Ed as Eat,Om as EatClaimKey,Lm as EatDebugStatus,Nm as EatSecurityLevel,di as EcdsaAlgorithm,Gd as EciesSecp256k1,Ue as Ed25519,Uo as EdDsaAlgorithm,ns as Hkdf,Kd as HkdfAlgorithm,qc as KEY_URI_PREFIX_JWK,hl as LocalKeyManager,Pe as P256,R8 as POLY1305_TAG_LENGTH,is as Pbkdf2,Id as Pbkdf2Algorithm,Ze as Secp256k1,Pe as Secp256r1,En as Sha256,Ko as Sha2Algorithm,pr as X25519,Io as X25519Algorithm,rh as XChaCha20,nh as XChaCha20Poly1305,el as canonicalize,q as computeJwkThumbprint,K1 as isCipher,Et as isEcPrivateJwk,An as isEcPublicJwk,I1 as isKeyExporter,C1 as isKeyImporter,_1 as isKeyWrapper,At as isOctPrivateJwk,De as isOkpPrivateJwk,vn as isOkpPublicJwk,tl as isPrivateJwk,Qx as isPublicJwk};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
ieee754/index.js:
|