@enbox/crypto 0.0.4 → 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/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 +4 -0
- package/dist/esm/index.js.map +1 -1
- 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 +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -3
- 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 +5 -0
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Vf=Object.create;var uo=Object.defineProperty;var qf=Object.getOwnPropertyDescriptor;var Ff=Object.getOwnPropertyNames;var $f=Object.getPrototypeOf,Wf=Object.prototype.hasOwnProperty;var Q=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Bc=(r,t)=>{for(var e in t)uo(r,e,{get:t[e],enumerable:!0})},zf=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ff(t))!Wf.call(r,i)&&i!==e&&uo(r,i,{get:()=>t[i],enumerable:!(n=qf(t,i))||n.enumerable});return r};var Pc=(r,t,e)=>(e=r!=null?Vf($f(r)):{},zf(t||!r||!r.__esModule?uo(e,"default",{value:r,enumerable:!0}):e,r));var Tc=Q((nd,Kc)=>{var Zf=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,zn=()=>Zf.now(),Yf=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),fo=r=>r===1/0||Yf(r),lo=class r{constructor({max:t=1/0,ttl:e,updateAgeOnGet:n=!1,checkAgeOnGet:i=!1,noUpdateTTL:o=!1,dispose:s,noDisposeOnSet:c=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,e!==void 0&&!fo(e))throw new TypeError("ttl must be positive integer or Infinity if set");if(!fo(t))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=e,this.max=t,this.updateAgeOnGet=!!n,this.checkAgeOnGet=!!i,this.noUpdateTTL=!!o,this.noDisposeOnSet=!!c,s!==void 0){if(typeof s!="function")throw new TypeError("dispose must be function if set");this.dispose=s}this.timer=void 0,this.timerExpiration=void 0}setTimer(t,e){if(this.timerExpiration<t)return;this.timer&&clearTimeout(this.timer);let n=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let i in this.expirations){this.setTimer(i,i-zn());break}},e);n.unref&&n.unref(),this.timerExpiration=t,this.timer=n}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let t=this.dispose!==r.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[e,n]of t)this.dispose(n,e,"delete")}setTTL(t,e=this.ttl){let n=this.expirationMap.get(t);if(n!==void 0){let i=this.expirations[n];!i||i.length<=1?delete this.expirations[n]:this.expirations[n]=i.filter(o=>o!==t)}if(e!==1/0){let i=Math.floor(zn()+e);this.expirationMap.set(t,i),this.expirations[i]||(this.expirations[i]=[],this.setTimer(i,e)),this.expirations[i].push(t)}else this.expirationMap.set(t,1/0)}set(t,e,{ttl:n=this.ttl,noUpdateTTL:i=this.noUpdateTTL,noDisposeOnSet:o=this.noDisposeOnSet}={}){if(!fo(n))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(t)){i||this.setTTL(t,n);let s=this.data.get(t);s!==e&&(this.data.set(t,e),o||this.dispose(s,t,"set"))}else this.setTTL(t,n),this.data.set(t,e);for(;this.size>this.max;)this.purgeToCapacity();return this}has(t){return this.data.has(t)}getRemainingTTL(t){let e=this.expirationMap.get(t);return e===1/0?e:e!==void 0?Math.max(0,Math.ceil(e-zn())):0}get(t,{updateAgeOnGet:e=this.updateAgeOnGet,ttl:n=this.ttl,checkAgeOnGet:i=this.checkAgeOnGet}={}){let o=this.data.get(t);if(i&&this.getRemainingTTL(t)===0){this.delete(t);return}return e&&this.setTTL(t,n),o}dispose(t,e){}delete(t){let e=this.expirationMap.get(t);if(e!==void 0){let n=this.data.get(t);this.data.delete(t),this.expirationMap.delete(t);let i=this.expirations[e];return i&&(i.length<=1?delete this.expirations[e]:this.expirations[e]=i.filter(o=>o!==t)),this.dispose(n,t,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let t in this.expirations){let e=this.expirations[t];if(this.size-e.length>=this.max){delete this.expirations[t];let n=[];for(let i of e)n.push([i,this.data.get(i)]),this.data.delete(i),this.expirationMap.delete(i);for(let[i,o]of n)this.dispose(o,i,"evict")}else{let n=this.size-this.max,i=[];for(let o of e.splice(0,n))i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"evict");return}}}get size(){return this.data.size}purgeStale(){let t=Math.ceil(zn());for(let e in this.expirations){if(e==="Infinity"||e>t)return;let n=[...this.expirations[e]||[]],i=[];delete this.expirations[e];for(let o of n)i.push([o,this.data.get(o)]),this.data.delete(o),this.expirationMap.delete(o);for(let[o,s]of i)this.dispose(s,o,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let t in this.expirations)for(let e of this.expirations[t])yield[e,this.data.get(e)]}*keys(){for(let t in this.expirations)for(let e of this.expirations[t])yield e}*values(){for(let t in this.expirations)for(let e of this.expirations[t])yield this.data.get(e)}[Symbol.iterator](){return this.entries()}};Kc.exports=lo});var Vc=Q(Gc=>{"use strict";Gc.supports=function(...t){let e=t.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(e,{snapshots:e.snapshots||!1,permanence:e.permanence||!1,seek:e.seek||!1,clear:e.clear||!1,getMany:e.getMany||!1,keyIterator:e.keyIterator||!1,valueIterator:e.valueIterator||!1,iteratorNextv:e.iteratorNextv||!1,iteratorAll:e.iteratorAll||!1,status:e.status||!1,createIfMissing:e.createIfMissing||!1,errorIfExists:e.errorIfExists||!1,deferredOpen:e.deferredOpen||!1,promises:e.promises||!1,streams:e.streams||!1,encodings:Object.assign({},e.encodings),events:Object.assign({},e.events),additionalMethods:Object.assign({},e.additionalMethods)})}});var Vt=Q((e0,qc)=>{"use strict";qc.exports=class extends Error{constructor(t,e){super(t||""),typeof e=="object"&&e!==null&&(e.code&&(this.code=String(e.code)),e.expected&&(this.expected=!0),e.transient&&(this.transient=!0),e.cause&&(this.cause=e.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var Wc=Q(Yn=>{"use strict";Yn.byteLength=Il;Yn.toByteArray=_l;Yn.fromByteArray=Rl;var te=[],_t=[],Ul=typeof Uint8Array<"u"?Uint8Array:Array,Ko="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(or=0,Fc=Ko.length;or<Fc;++or)te[or]=Ko[or],_t[Ko.charCodeAt(or)]=or;var or,Fc;_t[45]=62;_t[95]=63;function $c(r){var t=r.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");e===-1&&(e=t);var n=e===t?0:4-e%4;return[e,n]}function Il(r){var t=$c(r),e=t[0],n=t[1];return(e+n)*3/4-n}function Cl(r,t,e){return(t+e)*3/4-e}function _l(r){var t,e=$c(r),n=e[0],i=e[1],o=new Ul(Cl(r,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)t=_t[r.charCodeAt(a)]<<18|_t[r.charCodeAt(a+1)]<<12|_t[r.charCodeAt(a+2)]<<6|_t[r.charCodeAt(a+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=t&255;return i===2&&(t=_t[r.charCodeAt(a)]<<2|_t[r.charCodeAt(a+1)]>>4,o[s++]=t&255),i===1&&(t=_t[r.charCodeAt(a)]<<10|_t[r.charCodeAt(a+1)]<<4|_t[r.charCodeAt(a+2)]>>2,o[s++]=t>>8&255,o[s++]=t&255),o}function Ll(r){return te[r>>18&63]+te[r>>12&63]+te[r>>6&63]+te[r&63]}function Ol(r,t,e){for(var n,i=[],o=t;o<e;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(Ll(n));return i.join("")}function Rl(r){for(var t,e=r.length,n=e%3,i=[],o=16383,s=0,c=e-n;s<c;s+=o)i.push(Ol(r,s,s+o>c?c:s+o));return n===1?(t=r[e-1],i.push(te[t>>2]+te[t<<4&63]+"==")):n===2&&(t=(r[e-2]<<8)+r[e-1],i.push(te[t>>10]+te[t>>4&63]+te[t<<2&63]+"=")),i.join("")}});var zc=Q(To=>{To.read=function(r,t,e,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,u=a>>1,f=-7,l=e?i-1:0,y=e?-1:1,m=r[t+l];for(l+=y,o=m&(1<<-f)-1,m>>=-f,f+=c;f>0;o=o*256+r[t+l],l+=y,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=s*256+r[t+l],l+=y,f-=8);if(o===0)o=1-u;else{if(o===a)return s?NaN:(m?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-u}return(m?-1:1)*s*Math.pow(2,o-n)};To.write=function(r,t,e,n,i,o){var s,c,a,u=o*8-i-1,f=(1<<u)-1,l=f>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,m=n?0:o-1,p=n?1:-1,h=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+l>=1?t+=y/a:t+=y*Math.pow(2,1-l),t*a>=2&&(s++,a/=2),s+l>=f?(c=0,s=f):s+l>=1?(c=(t*a-1)*Math.pow(2,i),s=s+l):(c=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;r[e+m]=c&255,m+=p,c/=256,i-=8);for(s=s<<i|c,u+=i;u>0;r[e+m]=s&255,m+=p,s/=256,u-=8);r[e+m-p]|=h*128}});var ti=Q(Lr=>{"use strict";var So=Wc(),Cr=zc(),Zc=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Lr.Buffer=E;Lr.SlowBuffer=Jl;Lr.INSPECT_MAX_BYTES=50;var Xn=2147483647;Lr.kMaxLength=Xn;E.TYPED_ARRAY_SUPPORT=Nl();!E.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Nl(){try{let r=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(r,t),r.foo()===42}catch{return!1}}Object.defineProperty(E.prototype,"parent",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.buffer}});Object.defineProperty(E.prototype,"offset",{enumerable:!0,get:function(){if(E.isBuffer(this))return this.byteOffset}});function pe(r){if(r>Xn)throw new RangeError('The value "'+r+'" is invalid for option "size"');let t=new Uint8Array(r);return Object.setPrototypeOf(t,E.prototype),t}function E(r,t,e){if(typeof r=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Co(r)}return ta(r,t,e)}E.poolSize=8192;function ta(r,t,e){if(typeof r=="string")return Ml(r,t);if(ArrayBuffer.isView(r))return jl(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(ee(r,ArrayBuffer)||r&&ee(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(ee(r,SharedArrayBuffer)||r&&ee(r.buffer,SharedArrayBuffer)))return Uo(r,t,e);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return E.from(n,t,e);let i=Hl(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return E.from(r[Symbol.toPrimitive]("string"),t,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}E.from=function(r,t,e){return ta(r,t,e)};Object.setPrototypeOf(E.prototype,Uint8Array.prototype);Object.setPrototypeOf(E,Uint8Array);function ea(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function Dl(r,t,e){return ea(r),r<=0?pe(r):t!==void 0?typeof e=="string"?pe(r).fill(t,e):pe(r).fill(t):pe(r)}E.alloc=function(r,t,e){return Dl(r,t,e)};function Co(r){return ea(r),pe(r<0?0:_o(r)|0)}E.allocUnsafe=function(r){return Co(r)};E.allocUnsafeSlow=function(r){return Co(r)};function Ml(r,t){if((typeof t!="string"||t==="")&&(t="utf8"),!E.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let e=ra(r,t)|0,n=pe(e),i=n.write(r,t);return i!==e&&(n=n.slice(0,i)),n}function ko(r){let t=r.length<0?0:_o(r.length)|0,e=pe(t);for(let n=0;n<t;n+=1)e[n]=r[n]&255;return e}function jl(r){if(ee(r,Uint8Array)){let t=new Uint8Array(r);return Uo(t.buffer,t.byteOffset,t.byteLength)}return ko(r)}function Uo(r,t,e){if(t<0||r.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<t+(e||0))throw new RangeError('"length" is outside of buffer bounds');let n;return t===void 0&&e===void 0?n=new Uint8Array(r):e===void 0?n=new Uint8Array(r,t):n=new Uint8Array(r,t,e),Object.setPrototypeOf(n,E.prototype),n}function Hl(r){if(E.isBuffer(r)){let t=_o(r.length)|0,e=pe(t);return e.length===0||r.copy(e,0,0,t),e}if(r.length!==void 0)return typeof r.length!="number"||Oo(r.length)?pe(0):ko(r);if(r.type==="Buffer"&&Array.isArray(r.data))return ko(r.data)}function _o(r){if(r>=Xn)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xn.toString(16)+" bytes");return r|0}function Jl(r){return+r!=r&&(r=0),E.alloc(+r)}E.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==E.prototype};E.compare=function(t,e){if(ee(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),ee(e,Uint8Array)&&(e=E.from(e,e.offset,e.byteLength)),!E.isBuffer(t)||!E.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,i=e.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(t[o]!==e[o]){n=t[o],i=e[o];break}return n<i?-1:i<n?1:0};E.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};E.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return E.alloc(0);let n;if(e===void 0)for(e=0,n=0;n<t.length;++n)e+=t[n].length;let i=E.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){let s=t[n];if(ee(s,Uint8Array))o+s.length>i.length?(E.isBuffer(s)||(s=E.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(E.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function ra(r,t){if(E.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||ee(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let e=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&e===0)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Io(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return la(r).length;default:if(i)return n?-1:Io(r).length;t=(""+t).toLowerCase(),i=!0}}E.byteLength=ra;function Gl(r,t,e){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,t>>>=0,e<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return Ql(this,t,e);case"utf8":case"utf-8":return ia(this,t,e);case"ascii":return Yl(this,t,e);case"latin1":case"binary":return Xl(this,t,e);case"base64":return zl(this,t,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return th(this,t,e);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}E.prototype._isBuffer=!0;function sr(r,t,e){let n=r[t];r[t]=r[e],r[e]=n}E.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)sr(this,e,e+1);return this};E.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)sr(this,e,e+3),sr(this,e+1,e+2);return this};E.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)sr(this,e,e+7),sr(this,e+1,e+6),sr(this,e+2,e+5),sr(this,e+3,e+4);return this};E.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?ia(this,0,t):Gl.apply(this,arguments)};E.prototype.toLocaleString=E.prototype.toString;E.prototype.equals=function(t){if(!E.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:E.compare(this,t)===0};E.prototype.inspect=function(){let t="",e=Lr.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"};Zc&&(E.prototype[Zc]=E.prototype.inspect);E.prototype.compare=function(t,e,n,i,o){if(ee(t,Uint8Array)&&(t=E.from(t,t.offset,t.byteLength)),!E.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(e===void 0&&(e=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),e<0||n>t.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,i>>>=0,o>>>=0,this===t)return 0;let s=o-i,c=n-e,a=Math.min(s,c),u=this.slice(i,o),f=t.slice(e,n);for(let l=0;l<a;++l)if(u[l]!==f[l]){s=u[l],c=f[l];break}return s<c?-1:c<s?1:0};function na(r,t,e,n,i){if(r.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,Oo(e)&&(e=i?0:r.length-1),e<0&&(e=r.length+e),e>=r.length){if(i)return-1;e=r.length-1}else if(e<0)if(i)e=0;else return-1;if(typeof t=="string"&&(t=E.from(t,n)),E.isBuffer(t))return t.length===0?-1:Yc(r,t,e,n,i);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,t,e):Uint8Array.prototype.lastIndexOf.call(r,t,e):Yc(r,[t],e,n,i);throw new TypeError("val must be string, number or Buffer")}function Yc(r,t,e,n,i){let o=1,s=r.length,c=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||t.length<2)return-1;o=2,s/=2,c/=2,e/=2}function a(f,l){return o===1?f[l]:f.readUInt16BE(l*o)}let u;if(i){let f=-1;for(u=e;u<s;u++)if(a(r,u)===a(t,f===-1?0:u-f)){if(f===-1&&(f=u),u-f+1===c)return f*o}else f!==-1&&(u-=u-f),f=-1}else for(e+c>s&&(e=s-c),u=e;u>=0;u--){let f=!0;for(let l=0;l<c;l++)if(a(r,u+l)!==a(t,l)){f=!1;break}if(f)return u}return-1}E.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1};E.prototype.indexOf=function(t,e,n){return na(this,t,e,n,!0)};E.prototype.lastIndexOf=function(t,e,n){return na(this,t,e,n,!1)};function Vl(r,t,e,n){e=Number(e)||0;let i=r.length-e;n?(n=Number(n),n>i&&(n=i)):n=i;let o=t.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(t.substr(s*2,2),16);if(Oo(c))return s;r[e+s]=c}return s}function ql(r,t,e,n){return Qn(Io(t,r.length-e),r,e,n)}function Fl(r,t,e,n){return Qn(ih(t),r,e,n)}function $l(r,t,e,n){return Qn(la(t),r,e,n)}function Wl(r,t,e,n){return Qn(oh(t,r.length-e),r,e,n)}E.prototype.write=function(t,e,n,i){if(e===void 0)i="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")i=e,n=this.length,e=0;else if(isFinite(e))e=e>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-e;if((n===void 0||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Vl(this,t,e,n);case"utf8":case"utf-8":return ql(this,t,e,n);case"ascii":case"latin1":case"binary":return Fl(this,t,e,n);case"base64":return $l(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Wl(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};E.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function zl(r,t,e){return t===0&&e===r.length?So.fromByteArray(r):So.fromByteArray(r.slice(t,e))}function ia(r,t,e){e=Math.min(r.length,e);let n=[],i=t;for(;i<e;){let o=r[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=e){let a,u,f,l;switch(c){case 1:o<128&&(s=o);break;case 2:a=r[i+1],(a&192)===128&&(l=(o&31)<<6|a&63,l>127&&(s=l));break;case 3:a=r[i+1],u=r[i+2],(a&192)===128&&(u&192)===128&&(l=(o&15)<<12|(a&63)<<6|u&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:a=r[i+1],u=r[i+2],f=r[i+3],(a&192)===128&&(u&192)===128&&(f&192)===128&&(l=(o&15)<<18|(a&63)<<12|(u&63)<<6|f&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return Zl(n)}var Xc=4096;function Zl(r){let t=r.length;if(t<=Xc)return String.fromCharCode.apply(String,r);let e="",n=0;for(;n<t;)e+=String.fromCharCode.apply(String,r.slice(n,n+=Xc));return e}function Yl(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]&127);return n}function Xl(r,t,e){let n="";e=Math.min(r.length,e);for(let i=t;i<e;++i)n+=String.fromCharCode(r[i]);return n}function Ql(r,t,e){let n=r.length;(!t||t<0)&&(t=0),(!e||e<0||e>n)&&(e=n);let i="";for(let o=t;o<e;++o)i+=sh[r[o]];return i}function th(r,t,e){let n=r.slice(t,e),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}E.prototype.slice=function(t,e){let n=this.length;t=~~t,e=e===void 0?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);let i=this.subarray(t,e);return Object.setPrototypeOf(i,E.prototype),i};function ht(r,t,e){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>e)throw new RangeError("Trying to access beyond buffer length")}E.prototype.readUintLE=E.prototype.readUIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return i};E.prototype.readUintBE=E.prototype.readUIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t+--e],o=1;for(;e>0&&(o*=256);)i+=this[t+--e]*o;return i};E.prototype.readUint8=E.prototype.readUInt8=function(t,e){return t=t>>>0,e||ht(t,1,this.length),this[t]};E.prototype.readUint16LE=E.prototype.readUInt16LE=function(t,e){return t=t>>>0,e||ht(t,2,this.length),this[t]|this[t+1]<<8};E.prototype.readUint16BE=E.prototype.readUInt16BE=function(t,e){return t=t>>>0,e||ht(t,2,this.length),this[t]<<8|this[t+1]};E.prototype.readUint32LE=E.prototype.readUInt32LE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};E.prototype.readUint32BE=E.prototype.readUInt32BE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};E.prototype.readBigUInt64LE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});E.prototype.readBigUInt64BE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=e*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});E.prototype.readIntLE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=this[t],o=1,s=0;for(;++s<e&&(o*=256);)i+=this[t+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i};E.prototype.readIntBE=function(t,e,n){t=t>>>0,e=e>>>0,n||ht(t,e,this.length);let i=e,o=1,s=this[t+--i];for(;i>0&&(o*=256);)s+=this[t+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*e)),s};E.prototype.readInt8=function(t,e){return t=t>>>0,e||ht(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};E.prototype.readInt16LE=function(t,e){t=t>>>0,e||ht(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};E.prototype.readInt16BE=function(t,e){t=t>>>0,e||ht(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};E.prototype.readInt32LE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};E.prototype.readInt32BE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};E.prototype.readBigInt64LE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(e+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});E.prototype.readBigInt64BE=Ue(function(t){t=t>>>0,_r(t,"offset");let e=this[t],n=this[t+7];(e===void 0||n===void 0)&&yn(t,this.length-8);let i=(e<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n)});E.prototype.readFloatLE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),Cr.read(this,t,!0,23,4)};E.prototype.readFloatBE=function(t,e){return t=t>>>0,e||ht(t,4,this.length),Cr.read(this,t,!1,23,4)};E.prototype.readDoubleLE=function(t,e){return t=t>>>0,e||ht(t,8,this.length),Cr.read(this,t,!0,52,8)};E.prototype.readDoubleBE=function(t,e){return t=t>>>0,e||ht(t,8,this.length),Cr.read(this,t,!1,52,8)};function At(r,t,e,n,i,o){if(!E.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(e+n>r.length)throw new RangeError("Index out of range")}E.prototype.writeUintLE=E.prototype.writeUIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;At(this,t,e,n,c,0)}let o=1,s=0;for(this[e]=t&255;++s<n&&(o*=256);)this[e+s]=t/o&255;return e+n};E.prototype.writeUintBE=E.prototype.writeUIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;At(this,t,e,n,c,0)}let o=n-1,s=1;for(this[e+o]=t&255;--o>=0&&(s*=256);)this[e+o]=t/s&255;return e+n};E.prototype.writeUint8=E.prototype.writeUInt8=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,1,255,0),this[e]=t&255,e+1};E.prototype.writeUint16LE=E.prototype.writeUInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,65535,0),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeUint16BE=E.prototype.writeUInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeUint32LE=E.prototype.writeUInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=t&255,e+4};E.prototype.writeUint32BE=E.prototype.writeUInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};function oa(r,t,e,n,i){fa(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o,o=o>>8,r[e++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,s=s>>8,r[e++]=s,e}function sa(r,t,e,n,i){fa(t,n,i,r,e,7);let o=Number(t&BigInt(4294967295));r[e+7]=o,o=o>>8,r[e+6]=o,o=o>>8,r[e+5]=o,o=o>>8,r[e+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return r[e+3]=s,s=s>>8,r[e+2]=s,s=s>>8,r[e+1]=s,s=s>>8,r[e]=s,e+8}E.prototype.writeBigUInt64LE=Ue(function(t,e=0){return oa(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeBigUInt64BE=Ue(function(t,e=0){return sa(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))});E.prototype.writeIntLE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);At(this,t,e,n,a-1,-a)}let o=0,s=1,c=0;for(this[e]=t&255;++o<n&&(s*=256);)t<0&&c===0&&this[e+o-1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};E.prototype.writeIntBE=function(t,e,n,i){if(t=+t,e=e>>>0,!i){let a=Math.pow(2,8*n-1);At(this,t,e,n,a-1,-a)}let o=n-1,s=1,c=0;for(this[e+o]=t&255;--o>=0&&(s*=256);)t<0&&c===0&&this[e+o+1]!==0&&(c=1),this[e+o]=(t/s>>0)-c&255;return e+n};E.prototype.writeInt8=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=t&255,e+1};E.prototype.writeInt16LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,32767,-32768),this[e]=t&255,this[e+1]=t>>>8,e+2};E.prototype.writeInt16BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=t&255,e+2};E.prototype.writeInt32LE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,2147483647,-2147483648),this[e]=t&255,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4};E.prototype.writeInt32BE=function(t,e,n){return t=+t,e=e>>>0,n||At(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=t&255,e+4};E.prototype.writeBigInt64LE=Ue(function(t,e=0){return oa(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});E.prototype.writeBigInt64BE=Ue(function(t,e=0){return sa(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ca(r,t,e,n,i,o){if(e+n>r.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function aa(r,t,e,n,i){return t=+t,e=e>>>0,i||ca(r,t,e,4,34028234663852886e22,-34028234663852886e22),Cr.write(r,t,e,n,23,4),e+4}E.prototype.writeFloatLE=function(t,e,n){return aa(this,t,e,!0,n)};E.prototype.writeFloatBE=function(t,e,n){return aa(this,t,e,!1,n)};function ua(r,t,e,n,i){return t=+t,e=e>>>0,i||ca(r,t,e,8,17976931348623157e292,-17976931348623157e292),Cr.write(r,t,e,n,52,8),e+8}E.prototype.writeDoubleLE=function(t,e,n){return ua(this,t,e,!0,n)};E.prototype.writeDoubleBE=function(t,e,n){return ua(this,t,e,!1,n)};E.prototype.copy=function(t,e,n,i){if(!E.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-e<i-n&&(i=t.length-e+n);let o=i-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),e),o};E.prototype.fill=function(t,e,n,i){if(typeof t=="string"){if(typeof e=="string"?(i=e,e=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!E.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(t.length===1){let s=t.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e=e>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let o;if(typeof t=="number")for(o=e;o<n;++o)this[o]=t;else{let s=E.isBuffer(t)?t:E.from(t,i),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<n-e;++o)this[o+e]=s[o%c]}return this};var Ir={};function Lo(r,t,e){Ir[r]=class extends e{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Lo("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Lo("ERR_INVALID_ARG_TYPE",function(r,t){return`The "${r}" argument must be of type number. Received type ${typeof t}`},TypeError);Lo("ERR_OUT_OF_RANGE",function(r,t,e){let n=`The value of "${r}" is out of range.`,i=e;return Number.isInteger(e)&&Math.abs(e)>2**32?i=Qc(String(e)):typeof e=="bigint"&&(i=String(e),(e>BigInt(2)**BigInt(32)||e<-(BigInt(2)**BigInt(32)))&&(i=Qc(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);function Qc(r){let t="",e=r.length,n=r[0]==="-"?1:0;for(;e>=n+4;e-=3)t=`_${r.slice(e-3,e)}${t}`;return`${r.slice(0,e)}${t}`}function eh(r,t,e){_r(t,"offset"),(r[t]===void 0||r[t+e]===void 0)&&yn(t,r.length-(e+1))}function fa(r,t,e,n,i,o){if(r>e||r<t){let s=typeof t=="bigint"?"n":"",c;throw o>3?t===0||t===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:c=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:c=`>= ${t}${s} and <= ${e}${s}`,new Ir.ERR_OUT_OF_RANGE("value",c,r)}eh(n,i,o)}function _r(r,t){if(typeof r!="number")throw new Ir.ERR_INVALID_ARG_TYPE(t,"number",r)}function yn(r,t,e){throw Math.floor(r)!==r?(_r(r,e),new Ir.ERR_OUT_OF_RANGE(e||"offset","an integer",r)):t<0?new Ir.ERR_BUFFER_OUT_OF_BOUNDS:new Ir.ERR_OUT_OF_RANGE(e||"offset",`>= ${e?1:0} and <= ${t}`,r)}var rh=/[^+/0-9A-Za-z-_]/g;function nh(r){if(r=r.split("=")[0],r=r.trim().replace(rh,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Io(r,t){t=t||1/0;let e,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(e=r.charCodeAt(s),e>55295&&e<57344){if(!i){if(e>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(t-=3)>-1&&o.push(239,191,189),i=e;continue}e=(i-55296<<10|e-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((t-=1)<0)break;o.push(e)}else if(e<2048){if((t-=2)<0)break;o.push(e>>6|192,e&63|128)}else if(e<65536){if((t-=3)<0)break;o.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((t-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return o}function ih(r){let t=[];for(let e=0;e<r.length;++e)t.push(r.charCodeAt(e)&255);return t}function oh(r,t){let e,n,i,o=[];for(let s=0;s<r.length&&!((t-=2)<0);++s)e=r.charCodeAt(s),n=e>>8,i=e%256,o.push(i),o.push(n);return o}function la(r){return So.toByteArray(nh(r))}function Qn(r,t,e,n){let i;for(i=0;i<n&&!(i+e>=t.length||i>=r.length);++i)t[i+e]=r[i];return i}function ee(r,t){return r instanceof t||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===t.name}function Oo(r){return r!==r}var sh=function(){let r="0123456789abcdef",t=new Array(256);for(let e=0;e<16;++e){let n=e*16;for(let i=0;i<16;++i)t[n+i]=r[e]+r[i]}return t}();function Ue(r){return typeof BigInt>"u"?ch:r}function ch(){throw new Error("BigInt not supported")}});var No=Q((s0,ha)=>{"use strict";var Ro=null;ha.exports=function(){return Ro===null&&(Ro={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Ro}});var jo=Q(ya=>{"use strict";var Do=Vt(),ah=new Set(["buffer","view","utf8"]),Mo=class{constructor(t){if(this.encode=t.encode||this.encode,this.decode=t.decode||this.decode,this.name=t.name||this.name,this.format=t.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!ah.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");t.createViewTranscoder&&(this.createViewTranscoder=t.createViewTranscoder),t.createBufferTranscoder&&(this.createBufferTranscoder=t.createBufferTranscoder),t.createUTF8Transcoder&&(this.createUTF8Transcoder=t.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Do(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};ya.Encoding=Mo});var Vo=Q(ei=>{"use strict";var{Buffer:Jo}=ti()||{},{Encoding:Go}=jo(),uh=No(),pn=class extends Go{constructor(t){super({...t,format:"buffer"})}createViewTranscoder(){return new dn({encode:this.encode,decode:t=>this.decode(Jo.from(t.buffer,t.byteOffset,t.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},dn=class extends Go{constructor(t){super({...t,format:"view"})}createBufferTranscoder(){return new pn({encode:t=>{let e=this.encode(t);return Jo.from(e.buffer,e.byteOffset,e.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},Ho=class extends Go{constructor(t){super({...t,format:"utf8"})}createBufferTranscoder(){return new pn({encode:t=>Jo.from(this.encode(t),"utf8"),decode:t=>this.decode(t.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:t,textDecoder:e}=uh();return new dn({encode:n=>t.encode(this.encode(n)),decode:n=>this.decode(e.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};ei.BufferFormat=pn;ei.ViewFormat=dn;ei.UTF8Format=Ho});var wa=Q(cr=>{"use strict";var{Buffer:wt}=ti()||{Buffer:{isBuffer:()=>!1}},{textEncoder:da,textDecoder:pa}=No()(),{BufferFormat:mn,ViewFormat:qo,UTF8Format:ma}=Vo(),ri=r=>r;cr.utf8=new ma({encode:function(r){return wt.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?pa.decode(r):String(r)},decode:ri,name:"utf8",createViewTranscoder(){return new qo({encode:function(r){return ArrayBuffer.isView(r)?r:da.encode(r)},decode:function(r){return pa.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});cr.json=new ma({encode:JSON.stringify,decode:JSON.parse,name:"json"});cr.buffer=new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:ri,name:"buffer",createViewTranscoder(){return new qo({encode:function(r){return ArrayBuffer.isView(r)?r:wt.from(String(r),"utf8")},decode:function(r){return wt.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});cr.view=new qo({encode:function(r){return ArrayBuffer.isView(r)?r:da.encode(r)},decode:ri,name:"view",createBufferTranscoder(){return new mn({encode:function(r){return wt.isBuffer(r)?r:ArrayBuffer.isView(r)?wt.from(r.buffer,r.byteOffset,r.byteLength):wt.from(String(r),"utf8")},decode:ri,name:`${this.name}+buffer`})}});cr.hex=new mn({encode:function(r){return wt.isBuffer(r)?r:wt.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});cr.base64=new mn({encode:function(r){return wt.isBuffer(r)?r:wt.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var ba=Q(xa=>{"use strict";var ga=Vt(),ii=wa(),{Encoding:fh}=jo(),{BufferFormat:lh,ViewFormat:hh,UTF8Format:yh}=Vo(),wn=Symbol("formats"),ni=Symbol("encodings"),ph=new Set(["buffer","view","utf8"]),Fo=class{constructor(t){if(Array.isArray(t)){if(!t.every(e=>ph.has(e)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[ni]=new Map,this[wn]=new Set(t);for(let e in ii)try{this.encoding(e)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[ni].values()))}encoding(t){let e=this[ni].get(t);if(e===void 0){if(typeof t=="string"&&t!==""){if(e=gh[t],!e)throw new ga(`Encoding '${t}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof t!="object"||t===null)throw new TypeError("First argument 'encoding' must be a string or object");e=dh(t)}let{name:n,format:i}=e;if(!this[wn].has(i))if(this[wn].has("view"))e=e.createViewTranscoder();else if(this[wn].has("buffer"))e=e.createBufferTranscoder();else if(this[wn].has("utf8"))e=e.createUTF8Transcoder();else throw new ga(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let o of[t,n,e.name,e.commonName])this[ni].set(o,e)}return e}};xa.Transcoder=Fo;function dh(r){if(r instanceof fh)return r;let t="type"in r&&typeof r.type=="string"?r.type:void 0,e=r.name||t||`anonymous-${xh++}`;switch(mh(r)){case"view":return new hh({...r,name:e});case"utf8":return new yh({...r,name:e});case"buffer":return new lh({...r,name:e});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function mh(r){return"format"in r&&r.format!==void 0?r.format:"buffer"in r&&typeof r.buffer=="boolean"?r.buffer?"buffer":"utf8":"code"in r&&Number.isInteger(r.code)?"view":"buffer"}var wh={binary:ii.buffer,"utf-8":ii.utf8},gh={...ii,...wh},xh=0});var va=Q((l0,$o)=>{"use strict";var bh=Object.prototype.hasOwnProperty,bt="~";function gn(){}Object.create&&(gn.prototype=Object.create(null),new gn().__proto__||(bt=!1));function Eh(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ea(r,t,e,n,i){if(typeof e!="function")throw new TypeError("The listener must be a function");var o=new Eh(e,n||r,i),s=bt?bt+t:t;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],o]:r._events[s].push(o):(r._events[s]=o,r._eventsCount++),r}function oi(r,t){--r._eventsCount===0?r._events=new gn:delete r._events[t]}function gt(){this._events=new gn,this._eventsCount=0}gt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)bh.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};gt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};gt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};gt.prototype.emit=function(t,e,n,i,o,s){var c=bt?bt+t:t;if(!this._events[c])return!1;var a=this._events[c],u=arguments.length,f,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),u){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,i),!0;case 5:return a.fn.call(a.context,e,n,i,o),!0;case 6:return a.fn.call(a.context,e,n,i,o,s),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];a.fn.apply(a.context,f)}else{var y=a.length,m;for(l=0;l<y;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),u){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,e);break;case 3:a[l].fn.call(a[l].context,e,n);break;case 4:a[l].fn.call(a[l].context,e,n,i);break;default:if(!f)for(m=1,f=new Array(u-1);m<u;m++)f[m-1]=arguments[m];a[l].fn.apply(a[l].context,f)}}return!0};gt.prototype.on=function(t,e,n){return Ea(this,t,e,n,!1)};gt.prototype.once=function(t,e,n){return Ea(this,t,e,n,!0)};gt.prototype.removeListener=function(t,e,n,i){var o=bt?bt+t:t;if(!this._events[o])return this;if(!e)return oi(this,o),this;var s=this._events[o];if(s.fn)s.fn===e&&(!i||s.once)&&(!n||s.context===n)&&oi(this,o);else{for(var c=0,a=[],u=s.length;c<u;c++)(s[c].fn!==e||i&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[o]=a.length===1?a[0]:a:oi(this,o)}return this};gt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&oi(this,e)):(this._events=new gn,this._eventsCount=0),this};gt.prototype.off=gt.prototype.removeListener;gt.prototype.addListener=gt.prototype.on;gt.prefixed=bt;gt.EventEmitter=gt;typeof $o<"u"&&($o.exports=gt)});var Ba=Q((h0,Aa)=>{Aa.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)});var xn=Q(Wo=>{"use strict";var Pa=Ba();Wo.fromCallback=function(r,t){if(r===void 0){var e=new Promise(function(n,i){r=function(o,s){o?i(o):n(s)}});r[t!==void 0?t:"promise"]=e}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r};Wo.fromPromise=function(r,t){if(t===void 0)return r;r.then(function(e){Pa(()=>t(null,e))}).catch(function(e){Pa(()=>t(e))})}});var si=Q(zo=>{"use strict";zo.getCallback=function(r,t){return typeof r=="function"?r:t};zo.getOptions=function(r,t){return typeof r=="object"&&r!==null?r:t!==void 0?t:{}}});var Re=Q(fi=>{"use strict";var{fromCallback:Zo}=xn(),Kt=Vt(),{getOptions:Yo,getCallback:Ka}=si(),ar=Symbol("promise"),Or=Symbol("callback"),re=Symbol("working"),ur=Symbol("handleOne"),de=Symbol("handleMany"),Xo=Symbol("autoClose"),Le=Symbol("finishWork"),ne=Symbol("returnMany"),Ie=Symbol("closing"),bn=Symbol("handleClose"),ci=Symbol("closed"),En=Symbol("closeCallbacks"),_e=Symbol("keyEncoding"),fr=Symbol("valueEncoding"),Qo=Symbol("abortOnClose"),ai=Symbol("legacy"),ts=Symbol("keys"),es=Symbol("values"),Ce=Symbol("limit"),Lt=Symbol("count"),ui=Object.freeze({}),vh=()=>{},Ta=!1,vn=class{constructor(t,e,n){if(typeof t!="object"||t===null){let i=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}if(typeof e!="object"||e===null)throw new TypeError("The second argument must be an options object");this[ci]=!1,this[En]=[],this[re]=!1,this[Ie]=!1,this[Xo]=!1,this[Or]=null,this[ur]=this[ur].bind(this),this[de]=this[de].bind(this),this[bn]=this[bn].bind(this),this[_e]=e[_e],this[fr]=e[fr],this[ai]=n,this[Ce]=Number.isInteger(e.limit)&&e.limit>=0?e.limit:1/0,this[Lt]=0,this[Qo]=!!e.abortOnClose,this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get count(){return this[Lt]}get limit(){return this[Ce]}next(t){let e;if(t===void 0)e=new Promise((n,i)=>{t=(o,s,c)=>{o?i(o):this[ai]?s===void 0&&c===void 0?n():n([s,c]):n(s)}});else if(typeof t!="function")throw new TypeError("Callback must be a function");return this[Ie]?this.nextTick(t,new Kt("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(t,new Kt("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[re]=!0,this[Or]=t,this[Lt]>=this[Ce]?this.nextTick(this[ur],null):this._next(this[ur])),e}_next(t){this.nextTick(t)}nextv(t,e,n){return n=Ka(e,n),n=Zo(n,ar),e=Yo(e,ui),Number.isInteger(t)?(this[Ie]?this.nextTick(n,new Kt("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(n,new Kt("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(t<1&&(t=1),this[Ce]<1/0&&(t=Math.min(t,this[Ce]-this[Lt])),this[re]=!0,this[Or]=n,t<=0?this.nextTick(this[de],null,[]):this._nextv(t,e,this[de])),n[ar]):(this.nextTick(n,new TypeError("The first argument 'size' must be an integer")),n[ar])}_nextv(t,e,n){let i=[],o=(s,c,a)=>{if(s)return n(s);if(this[ai]?c===void 0&&a===void 0:c===void 0)return n(null,i);i.push(this[ai]?[c,a]:c),i.length===t?n(null,i):this._next(o)};this._next(o)}all(t,e){return e=Ka(t,e),e=Zo(e,ar),t=Yo(t,ui),this[Ie]?this.nextTick(e,new Kt("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[re]?this.nextTick(e,new Kt("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[re]=!0,this[Or]=e,this[Xo]=!0,this[Lt]>=this[Ce]?this.nextTick(this[de],null,[]):this._all(t,this[de])),e[ar]}_all(t,e){let n=this[Lt],i=[],o=()=>{let c=this[Ce]<1/0?Math.min(1e3,this[Ce]-n):1e3;c<=0?this.nextTick(e,null,i):this._nextv(c,ui,s)},s=(c,a)=>{c?e(c):a.length===0?e(null,i):(i.push.apply(i,a),n+=a.length,o())};o()}[Le](){let t=this[Or];return this[Qo]&&t===null?vh:(this[re]=!1,this[Or]=null,this[Ie]&&this._close(this[bn]),t)}[ne](t,e,n){this[Xo]?this.close(t.bind(null,e,n)):t(e,n)}seek(t,e){if(e=Yo(e,ui),!this[Ie]){if(this[re])throw new Kt("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(e.keyEncoding||this[_e]),i=n.format;e.keyEncoding!==i&&(e={...e,keyEncoding:i});let o=this.db.prefixKey(n.encode(t),i);this._seek(o,e)}}}_seek(t,e){throw new Kt("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(t){return t=Zo(t,ar),this[ci]?this.nextTick(t):this[Ie]?this[En].push(t):(this[Ie]=!0,this[En].push(t),this[re]?this[Qo]&&this[Le]()(new Kt("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[bn])),t[ar]}_close(t){this.nextTick(t)}[bn](){this[ci]=!0,this.db.detachResource(this);let t=this[En];this[En]=[];for(let e of t)e()}async*[Symbol.asyncIterator](){try{let t;for(;(t=await this.next())!==void 0;)yield t}finally{this[ci]||await this.close()}}},Rr=class extends vn{constructor(t,e){super(t,e,!0),this[ts]=e.keys!==!1,this[es]=e.values!==!1}[ur](t,e,n){let i=this[Le]();if(t)return i(t);try{e=this[ts]&&e!==void 0?this[_e].decode(e):void 0,n=this[es]&&n!==void 0?this[fr].decode(n):void 0}catch(o){return i(new Oe("entry",o))}e===void 0&&n===void 0||this[Lt]++,i(null,e,n)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i of e){let o=i[0],s=i[1];i[0]=this[ts]&&o!==void 0?this[_e].decode(o):void 0,i[1]=this[es]&&s!==void 0?this[fr].decode(s):void 0}}catch(i){return this[ne](n,new Oe("entries",i))}this[Lt]+=e.length,this[ne](n,null,e)}end(t){return!Ta&&typeof console<"u"&&(Ta=!0,console.warn(new Kt("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(t)}},rs=class extends vn{constructor(t,e){super(t,e,!1)}[ur](t,e){let n=this[Le]();if(t)return n(t);try{e=e!==void 0?this[_e].decode(e):void 0}catch(i){return n(new Oe("key",i))}e!==void 0&&this[Lt]++,n(null,e)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[_e].decode(o):void 0}}catch(i){return this[ne](n,new Oe("keys",i))}this[Lt]+=e.length,this[ne](n,null,e)}},ns=class extends vn{constructor(t,e){super(t,e,!1)}[ur](t,e){let n=this[Le]();if(t)return n(t);try{e=e!==void 0?this[fr].decode(e):void 0}catch(i){return n(new Oe("value",i))}e!==void 0&&this[Lt]++,n(null,e)}[de](t,e){let n=this[Le]();if(t)return this[ne](n,t);try{for(let i=0;i<e.length;i++){let o=e[i];e[i]=o!==void 0?this[fr].decode(o):void 0}}catch(i){return this[ne](n,new Oe("values",i))}this[Lt]+=e.length,this[ne](n,null,e)}},Oe=class extends Kt{constructor(t,e){super(`Iterator could not decode ${t}`,{code:"LEVEL_DECODE_ERROR",cause:e})}};for(let r of["_ended property","_nexting property","_end method"])Object.defineProperty(Rr.prototype,r.split(" ")[0],{get(){throw new Kt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new Kt(`The ${r} has been removed`,{code:"LEVEL_LEGACY"})}});Rr.keyEncoding=_e;Rr.valueEncoding=fr;fi.AbstractIterator=Rr;fi.AbstractKeyIterator=rs;fi.AbstractValueIterator=ns});var Sa=Q(is=>{"use strict";var{AbstractKeyIterator:Ah,AbstractValueIterator:Bh}=Re(),lr=Symbol("iterator"),An=Symbol("callback"),Nr=Symbol("handleOne"),hr=Symbol("handleMany"),Bn=class extends Ah{constructor(t,e){super(t,e),this[lr]=t.iterator({...e,keys:!0,values:!1}),this[Nr]=this[Nr].bind(this),this[hr]=this[hr].bind(this)}},li=class extends Bh{constructor(t,e){super(t,e),this[lr]=t.iterator({...e,keys:!1,values:!0}),this[Nr]=this[Nr].bind(this),this[hr]=this[hr].bind(this)}};for(let r of[Bn,li]){let t=r===Bn,e=t?n=>n[0]:n=>n[1];r.prototype._next=function(n){this[An]=n,this[lr].next(this[Nr])},r.prototype[Nr]=function(n,i,o){let s=this[An];n?s(n):s(null,t?i:o)},r.prototype._nextv=function(n,i,o){this[An]=o,this[lr].nextv(n,i,this[hr])},r.prototype._all=function(n,i){this[An]=i,this[lr].all(n,this[hr])},r.prototype[hr]=function(n,i){let o=this[An];n?o(n):o(null,i.map(e))},r.prototype._seek=function(n,i){this[lr].seek(n,i)},r.prototype._close=function(n){this[lr].close(n)}}is.DefaultKeyIterator=Bn;is.DefaultValueIterator=li});var ka=Q(wi=>{"use strict";var{AbstractIterator:Ph,AbstractKeyIterator:Kh,AbstractValueIterator:Th}=Re(),os=Vt(),Bt=Symbol("nut"),di=Symbol("undefer"),mi=Symbol("factory"),hi=class extends Ph{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.iterator(e),this.db.defer(()=>this[di]())}},yi=class extends Kh{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.keys(e),this.db.defer(()=>this[di]())}},pi=class extends Th{constructor(t,e){super(t,e),this[Bt]=null,this[mi]=()=>t.values(e),this.db.defer(()=>this[di]())}};for(let r of[hi,yi,pi])r.prototype[di]=function(){this.db.status==="open"&&(this[Bt]=this[mi]())},r.prototype._next=function(t){this[Bt]!==null?this[Bt].next(t):this.db.status==="opening"?this.db.defer(()=>this._next(t)):this.nextTick(t,new os("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._nextv=function(t,e,n){this[Bt]!==null?this[Bt].nextv(t,e,n):this.db.status==="opening"?this.db.defer(()=>this._nextv(t,e,n)):this.nextTick(n,new os("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._all=function(t,e){this[Bt]!==null?this[Bt].all(e):this.db.status==="opening"?this.db.defer(()=>this._all(t,e)):this.nextTick(e,new os("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},r.prototype._seek=function(t,e){this[Bt]!==null?this[Bt]._seek(t,e):this.db.status==="opening"&&this.db.defer(()=>this._seek(t,e))},r.prototype._close=function(t){this[Bt]!==null?this[Bt].close(t):this.db.status==="opening"?this.db.defer(()=>this._close(t)):this.nextTick(t)};wi.DeferredIterator=hi;wi.DeferredKeyIterator=yi;wi.DeferredValueIterator=pi});var cs=Q(Ia=>{"use strict";var{fromCallback:Ua}=xn(),gi=Vt(),{getCallback:Sh,getOptions:kh}=si(),xi=Symbol("promise"),Ot=Symbol("status"),Dr=Symbol("operations"),Pn=Symbol("finishClose"),Mr=Symbol("closeCallbacks"),ss=class{constructor(t){if(typeof t!="object"||t===null){let e=t===null?"null":typeof t;throw new TypeError(`The first argument must be an abstract-level database, received ${e}`)}this[Dr]=[],this[Mr]=[],this[Ot]="open",this[Pn]=this[Pn].bind(this),this.db=t,this.db.attachResource(this),this.nextTick=t.nextTick}get length(){return this[Dr].length}put(t,e,n){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let i=this.db._checkKey(t)||this.db._checkValue(e);if(i)throw i;let o=n&&n.sublevel!=null?n.sublevel:this.db,s=n,c=o.keyEncoding(n&&n.keyEncoding),a=o.valueEncoding(n&&n.valueEncoding),u=c.format;n={...n,keyEncoding:u,valueEncoding:a.format},o!==this.db&&(n.sublevel=null);let f=o.prefixKey(c.encode(t),u),l=a.encode(e);return this._put(f,l,n),this[Dr].push({...s,type:"put",key:t,value:e}),this}_put(t,e,n){}del(t,e){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let n=this.db._checkKey(t);if(n)throw n;let i=e&&e.sublevel!=null?e.sublevel:this.db,o=e,s=i.keyEncoding(e&&e.keyEncoding),c=s.format;return e={...e,keyEncoding:c},i!==this.db&&(e.sublevel=null),this._del(i.prefixKey(s.encode(t),c),e),this[Dr].push({...o,type:"del",key:t}),this}_del(t,e){}clear(){if(this[Ot]!=="open")throw new gi("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[Dr]=[],this}_clear(){}write(t,e){return e=Sh(t,e),e=Ua(e,xi),t=kh(t),this[Ot]!=="open"?this.nextTick(e,new gi("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(e):(this[Ot]="writing",this._write(t,n=>{this[Ot]="closing",this[Mr].push(()=>e(n)),n||this.db.emit("batch",this[Dr]),this._close(this[Pn])})),e[xi]}_write(t,e){}close(t){return t=Ua(t,xi),this[Ot]==="closing"?this[Mr].push(t):this[Ot]==="closed"?this.nextTick(t):(this[Mr].push(t),this[Ot]!=="writing"&&(this[Ot]="closing",this._close(this[Pn]))),t[xi]}_close(t){this.nextTick(t)}[Pn](){this[Ot]="closed",this.db.detachResource(this);let t=this[Mr];this[Mr]=[];for(let e of t)e()}};Ia.AbstractChainedBatch=ss});var _a=Q(Ca=>{"use strict";var{AbstractChainedBatch:Uh}=cs(),Ih=Vt(),jr=Symbol("encoded"),as=class extends Uh{constructor(t){super(t),this[jr]=[]}_put(t,e,n){this[jr].push({...n,type:"put",key:t,value:e})}_del(t,e){this[jr].push({...e,type:"del",key:t})}_clear(){this[jr]=[]}_write(t,e){this.db.status==="opening"?this.db.defer(()=>this._write(t,e)):this.db.status==="open"?this[jr].length===0?this.nextTick(e):this.db._batch(this[jr],t,e):this.nextTick(e,new Ih("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};Ca.DefaultChainedBatch=as});var Ra=Q((b0,Oa)=>{"use strict";var La=Vt(),Ch=Object.prototype.hasOwnProperty,_h=new Set(["lt","lte","gt","gte"]);Oa.exports=function(r,t){let e={};for(let n in r)if(Ch.call(r,n)&&!(n==="keyEncoding"||n==="valueEncoding")){if(n==="start"||n==="end")throw new La(`The legacy range option '${n}' has been removed`,{code:"LEVEL_LEGACY"});if(n==="encoding")throw new La("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});_h.has(n)?e[n]=t.encode(r[n]):e[n]=r[n]}return e.reverse=!!e.reverse,e.limit=Number.isInteger(e.limit)&&e.limit>=0?e.limit:-1,e}});var us=Q((E0,Da)=>{var Na;Da.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):r=>(Na||(Na=Promise.resolve())).then(r).catch(t=>setTimeout(()=>{throw t},0))});var Ha=Q((v0,ja)=>{"use strict";var Ma=us();ja.exports=function(r,...t){t.length===0?Ma(r):Ma(()=>r(...t))}});var Ja=Q(bi=>{"use strict";var{AbstractIterator:Lh,AbstractKeyIterator:Oh,AbstractValueIterator:Rh}=Re(),Hr=Symbol("unfix"),qt=Symbol("iterator"),yr=Symbol("handleOne"),Ne=Symbol("handleMany"),me=Symbol("callback"),Kn=class extends Lh{constructor(t,e,n,i){super(t,e),this[qt]=n,this[Hr]=i,this[yr]=this[yr].bind(this),this[Ne]=this[Ne].bind(this),this[me]=null}[yr](t,e,n){let i=this[me];if(t)return i(t);e!==void 0&&(e=this[Hr](e)),i(t,e,n)}[Ne](t,e){let n=this[me];if(t)return n(t);for(let i of e){let o=i[0];o!==void 0&&(i[0]=this[Hr](o))}n(t,e)}},Tn=class extends Oh{constructor(t,e,n,i){super(t,e),this[qt]=n,this[Hr]=i,this[yr]=this[yr].bind(this),this[Ne]=this[Ne].bind(this),this[me]=null}[yr](t,e){let n=this[me];if(t)return n(t);e!==void 0&&(e=this[Hr](e)),n(t,e)}[Ne](t,e){let n=this[me];if(t)return n(t);for(let i=0;i<e.length;i++){let o=e[i];o!==void 0&&(e[i]=this[Hr](o))}n(t,e)}},Sn=class extends Rh{constructor(t,e,n){super(t,e),this[qt]=n}};for(let r of[Kn,Tn])r.prototype._next=function(t){this[me]=t,this[qt].next(this[yr])},r.prototype._nextv=function(t,e,n){this[me]=n,this[qt].nextv(t,e,this[Ne])},r.prototype._all=function(t,e){this[me]=e,this[qt].all(t,this[Ne])};for(let r of[Sn])r.prototype._next=function(t){this[qt].next(t)},r.prototype._nextv=function(t,e,n){this[qt].nextv(t,e,n)},r.prototype._all=function(t,e){this[qt].all(t,e)};for(let r of[Kn,Tn,Sn])r.prototype._seek=function(t,e){this[qt].seek(t,e)},r.prototype._close=function(t){this[qt].close(t)};bi.AbstractSublevelIterator=Kn;bi.AbstractSublevelKeyIterator=Tn;bi.AbstractSublevelValueIterator=Sn});var Fa=Q((B0,qa)=>{"use strict";var fs=Vt(),{Buffer:ys}=ti()||{},{AbstractSublevelIterator:Nh,AbstractSublevelKeyIterator:Dh,AbstractSublevelValueIterator:Mh}=Ja(),we=Symbol("prefix"),Ga=Symbol("upperBound"),kn=Symbol("prefixRange"),Tt=Symbol("parent"),ls=Symbol("unfix"),Va=new TextEncoder,jh={separator:"!"};qa.exports=function({AbstractLevel:r}){class t extends r{static defaults(n){if(typeof n=="string")throw new fs("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(n&&n.open)throw new fs("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return n==null?jh:n.separator?n:{...n,separator:"!"}}constructor(n,i,o){let{separator:s,manifest:c,...a}=t.defaults(o);i=Jh(i,s);let u=s.charCodeAt(0)+1,f=n[Tt]||n;if(!Va.encode(i).every(m=>m>u&&m<127))throw new fs(`Prefix must use bytes > ${u} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(Hh(f,c),a);let l=(n.prefix||"")+s+i+s,y=l.slice(0,-1)+String.fromCharCode(u);this[Tt]=f,this[we]=new Ei(l),this[Ga]=new Ei(y),this[ls]=new ps,this.nextTick=f.nextTick}prefixKey(n,i){if(i==="utf8")return this[we].utf8+n;if(n.byteLength===0)return this[we][i];if(i==="view"){let o=this[we].view,s=new Uint8Array(o.byteLength+n.byteLength);return s.set(o,0),s.set(n,o.byteLength),s}else{let o=this[we].buffer;return ys.concat([o,n],o.byteLength+n.byteLength)}}[kn](n,i){n.gte!==void 0?n.gte=this.prefixKey(n.gte,i):n.gt!==void 0?n.gt=this.prefixKey(n.gt,i):n.gte=this[we][i],n.lte!==void 0?n.lte=this.prefixKey(n.lte,i):n.lt!==void 0?n.lt=this.prefixKey(n.lt,i):n.lte=this[Ga][i]}get prefix(){return this[we].utf8}get db(){return this[Tt]}_open(n,i){this[Tt].open({passive:!0},i)}_put(n,i,o,s){this[Tt].put(n,i,o,s)}_get(n,i,o){this[Tt].get(n,i,o)}_getMany(n,i,o){this[Tt].getMany(n,i,o)}_del(n,i,o){this[Tt].del(n,i,o)}_batch(n,i,o){this[Tt].batch(n,i,o)}_clear(n,i){this[kn](n,n.keyEncoding),this[Tt].clear(n,i)}_iterator(n){this[kn](n,n.keyEncoding);let i=this[Tt].iterator(n),o=this[ls].get(this[we].utf8.length,n.keyEncoding);return new Nh(this,n,i,o)}_keys(n){this[kn](n,n.keyEncoding);let i=this[Tt].keys(n),o=this[ls].get(this[we].utf8.length,n.keyEncoding);return new Dh(this,n,i,o)}_values(n){this[kn](n,n.keyEncoding);let i=this[Tt].values(n);return new Mh(this,n,i)}}return{AbstractSublevel:t}};var Hh=function(r,t){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...t,encodings:{utf8:hs(r,"utf8"),buffer:hs(r,"buffer"),view:hs(r,"view")}}},hs=function(r,t){return r.supports.encodings[t]?r.keyEncoding(t).name===t:!1},Ei=class{constructor(t){this.utf8=t,this.view=Va.encode(t),this.buffer=ys?ys.from(this.view.buffer,0,this.view.byteLength):{}}},ps=class{constructor(){this.cache=new Map}get(t,e){let n=this.cache.get(e);return n===void 0&&(e==="view"?n=(function(i,o){return o.subarray(i)}).bind(null,t):n=(function(i,o){return o.slice(i)}).bind(null,t),this.cache.set(e,n)),n}},Jh=function(r,t){let e=0,n=r.length;for(;e<n&&r[e]===t;)e++;for(;n>e&&r[n-1]===t;)n--;return r.slice(e,n)}});var xs=Q(gs=>{"use strict";var{supports:Gh}=Vc(),{Transcoder:Vh}=ba(),{EventEmitter:qh}=va(),{fromCallback:De}=xn(),Ft=Vt(),{AbstractIterator:pr}=Re(),{DefaultKeyIterator:Fh,DefaultValueIterator:$h}=Sa(),{DeferredIterator:Wh,DeferredKeyIterator:zh,DeferredValueIterator:Zh}=ka(),{DefaultChainedBatch:$a}=_a(),{getCallback:dr,getOptions:Me}=si(),vi=Ra(),W=Symbol("promise"),ge=Symbol("landed"),mr=Symbol("resources"),ds=Symbol("closeResources"),Un=Symbol("operations"),In=Symbol("undefer"),Ai=Symbol("deferOpen"),Wa=Symbol("options"),X=Symbol("status"),wr=Symbol("defaultOptions"),Jr=Symbol("transcoder"),Bi=Symbol("keyEncoding"),ms=Symbol("valueEncoding"),Yh=()=>{},Cn=class extends qh{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new TypeError("The first argument 'manifest' must be an object");e=Me(e);let{keyEncoding:n,valueEncoding:i,passive:o,...s}=e;this[mr]=new Set,this[Un]=[],this[Ai]=!0,this[Wa]=s,this[X]="opening",this.supports=Gh(t,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:t.snapshots!==!1,permanence:t.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:t.encodings||{},events:Object.assign({},t.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[Jr]=new Vh(Xh(this)),this[Bi]=this[Jr].encoding(n||"utf8"),this[ms]=this[Jr].encoding(i||"utf8");for(let c of this[Jr].encodings())this.supports.encodings[c.commonName]||(this.supports.encodings[c.commonName]=!0);this[wr]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[Bi].commonName,valueEncoding:this[ms].commonName}),key:Object.freeze({keyEncoding:this[Bi].commonName})},this.nextTick(()=>{this[Ai]&&this.open({passive:!1},Yh)})}get status(){return this[X]}keyEncoding(t){return this[Jr].encoding(t??this[Bi])}valueEncoding(t){return this[Jr].encoding(t??this[ms])}open(t,e){e=dr(t,e),e=De(e,W),t={...this[Wa],...Me(t)},t.createIfMissing=t.createIfMissing!==!1,t.errorIfExists=!!t.errorIfExists;let n=i=>{this[X]==="closing"||this[X]==="opening"?this.once(ge,i?()=>n(i):n):this[X]!=="open"?e(new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:i})):e()};return t.passive?this[X]==="opening"?this.once(ge,n):this.nextTick(n):this[X]==="closed"||this[Ai]?(this[Ai]=!1,this[X]="opening",this.emit("opening"),this._open(t,i=>{if(i){this[X]="closed",this[ds](()=>{this.emit(ge),n(i)}),this[In]();return}this[X]="open",this[In](),this.emit(ge),this[X]==="open"&&this.emit("open"),this[X]==="open"&&this.emit("ready"),n()})):this[X]==="open"?this.nextTick(n):this.once(ge,()=>this.open(t,e)),e[W]}_open(t,e){this.nextTick(e)}close(t){t=De(t,W);let e=n=>{this[X]==="opening"||this[X]==="closing"?this.once(ge,n?e(n):e):this[X]!=="closed"?t(new Ft("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:n})):t()};if(this[X]==="open"){this[X]="closing",this.emit("closing");let n=i=>{this[X]="open",this[In](),this.emit(ge),e(i)};this[ds](()=>{this._close(i=>{if(i)return n(i);this[X]="closed",this[In](),this.emit(ge),this[X]==="closed"&&this.emit("closed"),e()})})}else this[X]==="closed"?this.nextTick(e):this.once(ge,()=>this.close(t));return t[W]}[ds](t){if(this[mr].size===0)return this.nextTick(t);let e=this[mr].size,n=!0,i=()=>{--e===0&&(n?this.nextTick(t):t())};for(let o of this[mr])o.close(i);n=!1,this[mr].clear()}_close(t){this.nextTick(t)}get(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].entry),this[X]==="opening")return this.defer(()=>this.get(t,e,n)),n[W];if(Gr(this,n))return n[W];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[W];let o=this.keyEncoding(e.keyEncoding),s=this.valueEncoding(e.valueEncoding),c=o.format,a=s.format;return(e.keyEncoding!==c||e.valueEncoding!==a)&&(e=Object.assign({},e,{keyEncoding:c,valueEncoding:a})),this._get(this.prefixKey(o.encode(t),c),e,(u,f)=>{if(u)return(u.code==="LEVEL_NOT_FOUND"||u.notFound||/NotFound/i.test(u))&&(u.code||(u.code="LEVEL_NOT_FOUND"),u.notFound||(u.notFound=!0),u.status||(u.status=404)),n(u);try{f=s.decode(f)}catch(l){return n(new Ft("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[W]}_get(t,e,n){this.nextTick(n,new Error("NotFound"))}getMany(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].entry),this[X]==="opening")return this.defer(()=>this.getMany(t,e,n)),n[W];if(Gr(this,n))return n[W];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'keys' must be an array")),n[W];if(t.length===0)return this.nextTick(n,null,[]),n[W];let i=this.keyEncoding(e.keyEncoding),o=this.valueEncoding(e.valueEncoding),s=i.format,c=o.format;(e.keyEncoding!==s||e.valueEncoding!==c)&&(e=Object.assign({},e,{keyEncoding:s,valueEncoding:c}));let a=new Array(t.length);for(let u=0;u<t.length;u++){let f=t[u],l=this._checkKey(f);if(l)return this.nextTick(n,l),n[W];a[u]=this.prefixKey(i.encode(f),s)}return this._getMany(a,e,(u,f)=>{if(u)return n(u);try{for(let l=0;l<f.length;l++)f[l]!==void 0&&(f[l]=o.decode(f[l]))}catch(l){return n(new Ft(`Could not decode one or more of ${f.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:l}))}n(null,f)}),n[W]}_getMany(t,e,n){this.nextTick(n,null,new Array(t.length).fill(void 0))}put(t,e,n,i){if(i=dr(n,i),i=De(i,W),n=Me(n,this[wr].entry),this[X]==="opening")return this.defer(()=>this.put(t,e,n,i)),i[W];if(Gr(this,i))return i[W];let o=this._checkKey(t)||this._checkValue(e);if(o)return this.nextTick(i,o),i[W];let s=this.keyEncoding(n.keyEncoding),c=this.valueEncoding(n.valueEncoding),a=s.format,u=c.format;(n.keyEncoding!==a||n.valueEncoding!==u)&&(n=Object.assign({},n,{keyEncoding:a,valueEncoding:u}));let f=this.prefixKey(s.encode(t),a),l=c.encode(e);return this._put(f,l,n,y=>{if(y)return i(y);this.emit("put",t,e),i()}),i[W]}_put(t,e,n,i){this.nextTick(i)}del(t,e,n){if(n=dr(e,n),n=De(n,W),e=Me(e,this[wr].key),this[X]==="opening")return this.defer(()=>this.del(t,e,n)),n[W];if(Gr(this,n))return n[W];let i=this._checkKey(t);if(i)return this.nextTick(n,i),n[W];let o=this.keyEncoding(e.keyEncoding),s=o.format;return e.keyEncoding!==s&&(e=Object.assign({},e,{keyEncoding:s})),this._del(this.prefixKey(o.encode(t),s),e,c=>{if(c)return n(c);this.emit("del",t),n()}),n[W]}_del(t,e,n){this.nextTick(n)}batch(t,e,n){if(!arguments.length){if(this[X]==="opening")return new $a(this);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof t=="function"?n=t:n=dr(e,n),n=De(n,W),e=Me(e,this[wr].empty),this[X]==="opening")return this.defer(()=>this.batch(t,e,n)),n[W];if(Gr(this,n))return n[W];if(!Array.isArray(t))return this.nextTick(n,new TypeError("The first argument 'operations' must be an array")),n[W];if(t.length===0)return this.nextTick(n),n[W];let i=new Array(t.length),{keyEncoding:o,valueEncoding:s,...c}=e;for(let a=0;a<t.length;a++){if(typeof t[a]!="object"||t[a]===null)return this.nextTick(n,new TypeError("A batch operation must be an object")),n[W];let u=Object.assign({},t[a]);if(u.type!=="put"&&u.type!=="del")return this.nextTick(n,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),n[W];let f=this._checkKey(u.key);if(f)return this.nextTick(n,f),n[W];let l=u.sublevel!=null?u.sublevel:this,y=l.keyEncoding(u.keyEncoding||o),m=y.format;if(u.key=l.prefixKey(y.encode(u.key),m),u.keyEncoding=m,u.type==="put"){let p=this._checkValue(u.value);if(p)return this.nextTick(n,p),n[W];let h=l.valueEncoding(u.valueEncoding||s);u.value=h.encode(u.value),u.valueEncoding=h.format}l!==this&&(u.sublevel=null),i[a]=u}return this._batch(i,c,a=>{if(a)return n(a);this.emit("batch",t),n()}),n[W]}_batch(t,e,n){this.nextTick(n)}sublevel(t,e){return this._sublevel(t,ws.defaults(e))}_sublevel(t,e){return new ws(this,t,e)}prefixKey(t,e){return t}clear(t,e){if(e=dr(t,e),e=De(e,W),t=Me(t,this[wr].empty),this[X]==="opening")return this.defer(()=>this.clear(t,e)),e[W];if(Gr(this,e))return e[W];let n=t,i=this.keyEncoding(t.keyEncoding);return t=vi(t,i),t.keyEncoding=i.format,t.limit===0?this.nextTick(e):this._clear(t,o=>{if(o)return e(o);this.emit("clear",n),e()}),e[W]}_clear(t,e){this.nextTick(e)}iterator(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t.keys=t.keys!==!1,t.values=t.values!==!1,t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new Wh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(t)}_iterator(t){return new pr(this,t)}keys(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new zh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(t)}_keys(t){return new Fh(this,t)}values(t){let e=this.keyEncoding(t&&t.keyEncoding),n=this.valueEncoding(t&&t.valueEncoding);if(t=vi(t,e),t[pr.keyEncoding]=e,t[pr.valueEncoding]=n,t.keyEncoding=e.format,t.valueEncoding=n.format,this[X]==="opening")return new Zh(this,t);if(this[X]!=="open")throw new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(t)}_values(t){return new $h(this,t)}defer(t){if(typeof t!="function")throw new TypeError("The first argument must be a function");this[Un].push(t)}[In](){if(this[Un].length===0)return;let t=this[Un];this[Un]=[];for(let e of t)e()}attachResource(t){if(typeof t!="object"||t===null||typeof t.close!="function")throw new TypeError("The first argument must be a resource object");this[mr].add(t)}detachResource(t){this[mr].delete(t)}_chainedBatch(){return new $a(this)}_checkKey(t){if(t==null)return new Ft("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(t){if(t==null)return new Ft("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};Cn.prototype.nextTick=Ha();var{AbstractSublevel:ws}=Fa()({AbstractLevel:Cn});gs.AbstractLevel=Cn;gs.AbstractSublevel=ws;var Gr=function(r,t){return r[X]!=="open"?(r.nextTick(t,new Ft("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},Xh=function(r){return Object.keys(r.supports.encodings).filter(t=>!!r.supports.encodings[t])}});var bs=Q(gr=>{"use strict";gr.AbstractLevel=xs().AbstractLevel;gr.AbstractSublevel=xs().AbstractSublevel;gr.AbstractIterator=Re().AbstractIterator;gr.AbstractKeyIterator=Re().AbstractKeyIterator;gr.AbstractValueIterator=Re().AbstractValueIterator;gr.AbstractChainedBatch=cs().AbstractChainedBatch});var Za=Q((T0,za)=>{za.exports=ty;var Qh=us();function ty(r,t,e){if(typeof t!="number")throw new Error("second argument must be a Number");let n,i,o,s,c,a=!0,u;Array.isArray(r)?(n=[],o=i=r.length):(s=Object.keys(r),n={},o=i=s.length);function f(y){function m(){e&&e(y,n),e=null}a?Qh(m):m()}function l(y,m,p){if(n[y]=p,m&&(c=!0),--o===0||m)f(m);else if(!c&&u<i){let h;s?(h=s[u],u+=1,r[h](function(d,g){l(h,d,g)})):(h=u,u+=1,r[h](function(d,g){l(h,d,g)}))}}u=t,o?s?s.some(function(y,m){return r[y](function(p,h){l(y,p,h)}),m===t-1}):r.some(function(y,m){return y(function(p,h){l(m,p,h)}),m===t-1}):f(null),a=!1}});var Es=Q((S0,Ya)=>{"use strict";Ya.exports=function(t){let e=t.gte!==void 0?t.gte:t.gt!==void 0?t.gt:void 0,n=t.lte!==void 0?t.lte:t.lt!==void 0?t.lt:void 0,i=t.gte===void 0,o=t.lte===void 0;return e!==void 0&&n!==void 0?IDBKeyRange.bound(e,n,i,o):e!==void 0?IDBKeyRange.lowerBound(e,i):n!==void 0?IDBKeyRange.upperBound(n,o):null}});var vs=Q((k0,Xa)=>{"use strict";var ey=new TextEncoder;Xa.exports=function(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):ey.encode(r)}});var nu=Q(ru=>{"use strict";var{AbstractIterator:ry}=bs(),Qa=Es(),Pi=vs(),ie=Symbol("cache"),xe=Symbol("finished"),St=Symbol("options"),be=Symbol("currentOptions"),xr=Symbol("position"),As=Symbol("location"),Vr=Symbol("first"),tu={},Bs=class extends ry{constructor(t,e,n){super(t,n),this[ie]=[],this[xe]=this.limit===0,this[St]=n,this[be]={...n},this[xr]=void 0,this[As]=e,this[Vr]=!0}_nextv(t,e,n){if(this[Vr]=!1,this[xe])return this.nextTick(n,null,[]);if(this[ie].length>0)return t=Math.min(t,this[ie].length),this.nextTick(n,null,this[ie].splice(0,t));this[xr]!==void 0&&(this[St].reverse?(this[be].lt=this[xr],this[be].lte=void 0):(this[be].gt=this[xr],this[be].gte=void 0));let i;try{i=Qa(this[be])}catch{return this[xe]=!0,this.nextTick(n,null,[])}let o=this.db.db.transaction([this[As]],"readonly"),s=o.objectStore(this[As]),c=[];if(this[St].reverse){let a=!this[St].values&&s.openKeyCursor?"openKeyCursor":"openCursor";s[a](i,"prev").onsuccess=u=>{let f=u.target.result;if(f){let{key:l,value:y}=f;this[xr]=l,c.push([this[St].keys&&l!==void 0?Pi(l):void 0,this[St].values&&y!==void 0?Pi(y):void 0]),c.length<t?f.continue():eu(o)}else this[xe]=!0}}else{let a,u,f=()=>{if(a===void 0||u===void 0)return;let l=Math.max(a.length,u.length);l===0||t===1/0?this[xe]=!0:this[xr]=a[l-1],c.length=l;for(let y=0;y<l;y++){let m=a[y],p=u[y];c[y]=[this[St].keys&&m!==void 0?Pi(m):void 0,this[St].values&&p!==void 0?Pi(p):void 0]}eu(o)};this[St].keys||t<1/0?s.getAllKeys(i,t<1/0?t:void 0).onsuccess=l=>{a=l.target.result,f()}:(a=[],this.nextTick(f)),this[St].values?s.getAll(i,t<1/0?t:void 0).onsuccess=l=>{u=l.target.result,f()}:(u=[],this.nextTick(f))}o.onabort=()=>{n(o.error||new Error("aborted by user")),n=null},o.oncomplete=()=>{n(null,c),n=null}}_next(t){if(this[ie].length>0){let[e,n]=this[ie].shift();this.nextTick(t,null,e,n)}else if(this[xe])this.nextTick(t);else{let e=Math.min(100,this.limit-this.count);this[Vr]&&(this[Vr]=!1,e=1),this._nextv(e,tu,(n,i)=>{if(n)return t(n);this[ie]=i,this._next(t)})}}_all(t,e){this[Vr]=!1;let n=this[ie].splice(0,this[ie].length),i=this.limit-this.count-n.length;if(i<=0)return this.nextTick(e,null,n);this._nextv(i,tu,(o,s)=>{if(o)return e(o);n.length>0&&(s=n.concat(s)),e(null,s)})}_seek(t,e){this[Vr]=!0,this[ie]=[],this[xe]=!1,this[xr]=void 0,this[be]={...this[St]};let n;try{n=Qa(this[St])}catch{this[xe]=!0;return}n!==null&&!n.includes(t)?this[xe]=!0:this[St].reverse?this[be].lte=t:this[be].gte=t}};ru.Iterator=Bs;function eu(r){typeof r.commit=="function"&&r.commit()}});var ou=Q((I0,iu)=>{"use strict";iu.exports=function(t,e,n,i,o){if(i.limit===0)return t.nextTick(o);let s=t.db.transaction([e],"readwrite"),c=s.objectStore(e),a=0;s.oncomplete=function(){o()},s.onabort=function(){o(s.error||new Error("aborted by user"))};let u=c.openKeyCursor?"openKeyCursor":"openCursor",f=i.reverse?"prev":"next";c[u](n,f).onsuccess=function(l){let y=l.target.result;y&&(c.delete(y.key).onsuccess=function(){(i.limit<=0||++a<i.limit)&&y.continue()})}}});var lu=Q(fu=>{"use strict";var{AbstractLevel:ny}=bs(),su=Vt(),iy=Za(),{fromCallback:oy}=xn(),{Iterator:sy}=nu(),cu=vs(),cy=ou(),ay=Es(),uu="level-js-",_n=Symbol("idb"),Ps=Symbol("namePrefix"),Ee=Symbol("location"),Ks=Symbol("version"),br=Symbol("store"),Ln=Symbol("onComplete"),au=Symbol("promise"),Ki=class extends ny{constructor(t,e,n){if(typeof e=="function"||typeof n=="function")throw new su("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:i,version:o,...s}=e||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},s),typeof t!="string")throw new Error("constructor requires a location string argument");this[Ee]=t,this[Ps]=i??uu,this[Ks]=parseInt(o||1,10),this[_n]=null}get location(){return this[Ee]}get namePrefix(){return this[Ps]}get version(){return this[Ks]}get db(){return this[_n]}get type(){return"browser-level"}_open(t,e){let n=indexedDB.open(this[Ps]+this[Ee],this[Ks]);n.onerror=function(){e(n.error||new Error("unknown error"))},n.onsuccess=()=>{this[_n]=n.result,e()},n.onupgradeneeded=i=>{let o=i.target.result;o.objectStoreNames.contains(this[Ee])||o.createObjectStore(this[Ee])}}[br](t){return this[_n].transaction([this[Ee]],t).objectStore(this[Ee])}[Ln](t,e){let n=t.transaction;n.onabort=function(){e(n.error||new Error("aborted by user"))},n.oncomplete=function(){e(null,t.result)}}_get(t,e,n){let i=this[br]("readonly"),o;try{o=i.get(t)}catch(s){return this.nextTick(n,s)}this[Ln](o,function(s,c){if(s)return n(s);if(c===void 0)return n(new su("Entry not found",{code:"LEVEL_NOT_FOUND"}));n(null,cu(c))})}_getMany(t,e,n){let i=this[br]("readonly"),o=t.map(s=>c=>{let a;try{a=i.get(s)}catch(u){return c(u)}a.onsuccess=()=>{let u=a.result;c(null,u===void 0?u:cu(u))},a.onerror=u=>{u.stopPropagation(),c(a.error)}});iy(o,16,n)}_del(t,e,n){let i=this[br]("readwrite"),o;try{o=i.delete(t)}catch(s){return this.nextTick(n,s)}this[Ln](o,n)}_put(t,e,n,i){let o=this[br]("readwrite"),s;try{s=o.put(e,t)}catch(c){return this.nextTick(i,c)}this[Ln](s,i)}_iterator(t){return new sy(this,this[Ee],t)}_batch(t,e,n){let i=this[br]("readwrite"),o=i.transaction,s=0,c;o.onabort=function(){n(c||o.error||new Error("aborted by user"))},o.oncomplete=function(){n()};function a(){let u=t[s++],f=u.key,l;try{l=u.type==="del"?i.delete(f):i.put(u.value,f)}catch(y){c=y,o.abort();return}s<t.length?l.onsuccess=a:typeof o.commit=="function"&&o.commit()}a()}_clear(t,e){let n,i;try{n=ay(t)}catch{return this.nextTick(e)}if(t.limit>=0)return cy(this,this[Ee],n,t,e);try{let o=this[br]("readwrite");i=n?o.delete(n):o.clear()}catch(o){return this.nextTick(e,o)}this[Ln](i,e)}_close(t){this[_n].close(),this.nextTick(t)}};Ki.destroy=function(r,t,e){typeof t=="function"&&(e=t,t=uu),e=oy(e,au);let n=indexedDB.deleteDatabase(t+r);return n.onsuccess=function(){e()},n.onerror=function(i){e(i)},e[au]};fu.BrowserLevel=Ki});var yu=Q(hu=>{hu.Level=lu().BrowserLevel});var nt=class r extends Error{constructor(e,n){super(n);this.code=e;this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,r)}},sn=(o=>(o.AlgorithmNotSupported="algorithmNotSupported",o.EncodingError="encodingError",o.InvalidJwe="invalidJwe",o.InvalidJwk="invalidJwk",o.OperationNotSupported="operationNotSupported",o))(sn||{});var Xf=Pc(Tc(),1);var od=new Uint8Array(0);function Sc(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Sr(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function tl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,d=0,g=0,b=p.length;g!==b&&p[g]===0;)g++,h++;for(var x=(b-g)*f+1>>>0,A=new Uint8Array(x);g!==b;){for(var v=p[g],K=0,k=x-1;(v!==0||K<d)&&k!==-1;k--,K++)v+=256*A[k]>>>0,A[k]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");d=K,g++}for(var T=x-d;T!==x&&A[T]===0;)T++;for(var L=a.repeat(h);T<x;++T)L+=r.charAt(A[T]);return L}function y(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var d=0,g=0;p[h]===a;)d++,h++;for(var b=(p.length-h)*u+1>>>0,x=new Uint8Array(b);p[h];){var A=e[p.charCodeAt(h)];if(A===255)return;for(var v=0,K=b-1;(A!==0||v<g)&&K!==-1;K--,v++)A+=c*x[K]>>>0,x[K]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");g=v,h++}if(p[h]!==" "){for(var k=b-g;k!==b&&x[k]===0;)k++;for(var T=new Uint8Array(d+(b-k)),L=d;k!==b;)T[L++]=x[k++];return T}}}function m(p){var h=y(p);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:m}}var el=tl,rl=el,kc=rl;var ho=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Uc(this,t)}},po=class{decoders;constructor(t){this.decoders=t}or(t){return Uc(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Uc(r,t){return new po({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var mo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new ho(t,e,n),this.decoder=new yo(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ic({name:r,prefix:t,encode:e,decode:n}){return new mo(r,t,e,n)}function wo({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=kc(e,r);return Ic({prefix:t,name:r,encode:n,decode:o=>Sr(i(o))})}function nl(r,t,e,n){let i={};for(let f=0;f<t.length;++f)i[t[f]]=f;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),c=0,a=0,u=0;for(let f=0;f<o;++f){let l=i[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,s[u++]=255&a>>c)}if(c>=e||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s}function il(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],s+=8;s>e;)s-=e,o+=t[i&c>>s];if(s!==0&&(o+=t[i&c<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function xt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ic({prefix:t,name:r,encode(i){return il(i,n,e)},decode(i){return nl(i,n,e,r)}})}var cn=xt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ld=xt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hd=xt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yd=xt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pd=xt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dd=xt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),md=xt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wd=xt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),go=xt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vt=wo({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bd=wo({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ad=xt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bd=xt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xt=xt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pd=xt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Cc(r){return r.byteOffset!==0||r.byteLength!==r.buffer.byteLength}function _c(r){return typeof r!="object"||r===null?!1:typeof r[Symbol.asyncIterator]=="function"}function an(r){let e=Object.prototype.toString.call(r).match(/\s([a-zA-Z0-9]+)/),[n,i]=e;return i}var un=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{u(n.next(f))}catch(l){s(l)}}function a(f){try{u(n.throw(f))}catch(l){s(l)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((n=n.apply(r,t||[])).next())})},Lc=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=r[o]&&function(s){return new Promise(function(c,a){s=r[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(u){o({value:u,done:c})},s)}},Zn=new TextEncoder,rr=new TextDecoder,N=class r{constructor(t,e){this.data=t,this.format=e}static arrayBuffer(t){return new r(t,"ArrayBuffer")}static asyncIterable(t){if(!_c(t))throw new TypeError("Input must be of type AsyncIterable.");return new r(t,"AsyncIterable")}static base32Z(t){return new r(t,"Base32Z")}static base58Btc(t){return new r(t,"Base58Btc")}static base64Url(t){return new r(t,"Base64Url")}static bufferSource(t){return new r(t,"BufferSource")}static hex(t){if(typeof t!="string")throw new TypeError("Hex input must be a string.");if(t.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new r(t,"Hex")}static multibase(t){return new r(t,"Multibase")}static object(t){return new r(t,"Object")}static string(t){return new r(t,"String")}static uint8Array(t){return new r(t,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return vt.baseDecode(this.data).buffer;case"Base64Url":return Xt.baseDecode(this.data).buffer;case"BufferSource":{if(an(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return Cc(this.data)?this.data.buffer.slice(this.data.byteOffset,this.data.byteOffset+this.data.byteLength):this.data.buffer;throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":return this.toUint8Array().buffer;case"String":return this.toUint8Array().buffer;case"Uint8Array":return this.data.buffer;default:throw new TypeError(`Conversion from ${this.format} to ArrayBuffer is not supported.`)}}toArrayBufferAsync(){return un(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":return yield(yield this.toBlobAsync()).arrayBuffer();default:throw new TypeError(`Asynchronous conversion from ${this.format} to ArrayBuffer is not supported.`)}})}toBase32Z(){switch(this.format){case"Uint8Array":return go.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return vt.baseEncode(t)}case"Multibase":return this.data.substring(1);case"Uint8Array":return vt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let t=new Uint8Array(this.data);return Xt.baseEncode(t)}case"BufferSource":{let t=this.toUint8Array();return Xt.baseEncode(t)}case"Object":{let t=JSON.stringify(this.data),e=Zn.encode(t);return Xt.baseEncode(e)}case"String":{let t=Zn.encode(this.data);return Xt.baseEncode(t)}case"Uint8Array":return Xt.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return un(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a=[];try{for(var o=!0,s=Lc(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let f=i;a.push(f)}}catch(f){e={error:f}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return new Blob(a)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let t=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Base64Url":{let e=this.toUint8Array();return r.uint8Array(e).toHex()}case"Uint8Array":{let e="";for(let n=0;n<this.data.length;n++)e+=t[this.data[n]];return e}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let t=Xt.baseDecode(this.data),e=rr.decode(t);return JSON.parse(e)}case"String":return JSON.parse(this.data);case"Uint8Array":{let t=rr.decode(this.data);return JSON.parse(t)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return un(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toStringAsync();return JSON.parse(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return rr.decode(this.data);case"Base64Url":{let t=Xt.baseDecode(this.data);return rr.decode(t)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return rr.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return un(this,void 0,void 0,function*(){var t,e,n,i;switch(this.format){case"AsyncIterable":{let a="";try{for(var o=!0,s=Lc(this.data),c;c=yield s.next(),t=c.done,!t;o=!0){i=c.value,o=!1;let u=i;typeof u=="string"?a+=u:a+=rr.decode(u,{stream:!0})}}catch(u){e={error:u}}finally{try{!o&&!t&&(n=s.return)&&(yield n.call(s))}finally{if(e)throw e.error}}return a+=rr.decode(void 0,{stream:!1}),a}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return go.baseDecode(this.data);case"Base58Btc":return vt.baseDecode(this.data);case"Base64Url":return Xt.baseDecode(this.data);case"BufferSource":{let t=an(this.data);if(t==="Uint8Array")return this.data;if(t==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let t=new Uint8Array(this.data.length/2);for(let e=0;e<this.data.length;e+=2){let n=parseInt(this.data.substring(e,e+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");t[e/2]=n}return t}case"Object":{let t=JSON.stringify(this.data);return Zn.encode(t)}case"String":return Zn.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return un(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let t=yield this.toArrayBufferAsync();return new Uint8Array(t)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};var fn;(function(r){r.Debug="debug",r.Silent="silent"})(fn||(fn={}));var xo=class{constructor(){this.logLevel=fn.Silent}setLogLevel(t){this.logLevel=t}log(t){this.info(t)}info(t){this.logLevel!==fn.Silent&&console.info(t)}error(t){this.logLevel!==fn.Silent&&console.error(t)}},ol=new xo;typeof window<"u"&&(window.web5logger=ol);var ye={};Bc(ye,{decode:()=>kr,encodeTo:()=>nr,encodingLength:()=>ir});var sl=Nc,Oc=128,cl=127,al=~cl,ul=Math.pow(2,31);function Nc(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ul;)t[e++]=r&255|Oc,r/=128;for(;r&al;)t[e++]=r&255|Oc,r>>>=7;return t[e]=r|0,Nc.bytes=e-n+1,t}var fl=bo,ll=128,Rc=127;function bo(r,n){var e=0,n=n||0,i=0,o=n,s,c=r.length;do{if(o>=c)throw bo.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&Rc)<<i:(s&Rc)*Math.pow(2,i),i+=7}while(s>=ll);return bo.bytes=o-n,e}var hl=Math.pow(2,7),yl=Math.pow(2,14),pl=Math.pow(2,21),dl=Math.pow(2,28),ml=Math.pow(2,35),wl=Math.pow(2,42),gl=Math.pow(2,49),xl=Math.pow(2,56),bl=Math.pow(2,63),El=function(r){return r<hl?1:r<yl?2:r<pl?3:r<dl?4:r<ml?5:r<wl?6:r<gl?7:r<xl?8:r<bl?9:10},vl={encode:sl,decode:fl,encodingLength:El},Al=vl,ln=Al;function kr(r,t=0){return[ln.decode(r,t),ln.decode.bytes]}function nr(r,t,e=0){return ln.encode(r,t,e),t}function ir(r){return ln.encodingLength(r)}function Eo(r,t){let e=t.byteLength,n=ir(r),i=n+ir(e),o=new Uint8Array(i+e);return nr(r,o,0),nr(e,o,n),o.set(t,i),new Ur(r,e,t,o)}function Dc(r){let t=Sr(r),[e,n]=kr(t),[i,o]=kr(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new Ur(e,i,s,t)}function Mc(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Sc(r.bytes,e.bytes)}}var Ur=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};function jc(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Pl(e,Ao(r),t??vt.encoder);default:return Kl(e,Ao(r),t??cn.encoder)}}var Hc=new WeakMap;function Ao(r){let t=Hc.get(r);if(t==null){let e=new Map;return Hc.set(r,e),e}return t}var Bo=class r{code;version;multihash;bytes;"/";constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==hn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Tl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Eo(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Mc(t.multihash,n.multihash)}toString(t){return jc(this,t)}toJSON(){return{"/":jc(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??Jc(n,i,o.bytes))}else if(e[Sl]===!0){let{version:n,multihash:i,code:o}=e,s=Dc(i);return r.create(n,o,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==hn)throw new Error(`Version 0 CID must use dag-pb (code: ${hn}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Jc(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,hn,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=Sr(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new Ur(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,y]=kr(t.subarray(e));return e+=y,l},i=n(),o=hn;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,c=n(),a=n(),u=e+a,f=u-s;return{version:i,codec:o,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,e){let[n,i]=Bl(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ao(o).set(n,t),o}};function Bl(r,t){switch(r[0]){case"Q":{let e=t??vt;return[vt.prefix,e.decode(`${vt.prefix}${r}`)]}case vt.prefix:{let e=t??vt;return[vt.prefix,e.decode(r)]}case cn.prefix:{let e=t??cn;return[cn.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Pl(r,t,e){let{prefix:n}=e;if(n!==vt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i}function Kl(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i}var hn=112,Tl=18;function Jc(r,t,e){let n=ir(r),i=n+ir(t),o=new Uint8Array(i+e.byteLength);return nr(r,o,0),nr(t,o,n),o.set(e,i),o}var Sl=Symbol.for("@ipld/js-cid/CID");var Qt=class r{static addPrefix(t){var e;let{code:n,data:i,name:o}=t;if(!(o?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=r.codeToName.has(n)?n:r.nameToCode.get(o),n===void 0)throw new Error(`Unsupported multicodec: ${(e=t.name)!==null&&e!==void 0?e:t.code}`);let s=ye.encodingLength(n),c=new Uint8Array(s+i.byteLength);return c.set(i,s),ye.encodeTo(n,c),c}static getCodeFromData(t){let{prefixedData:e}=t,[n,i]=ye.decode(e);return n}static getCodeFromName(t){let{name:e}=t,n=r.nameToCode.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static getNameFromCode(t){let{code:e}=t,n=r.codeToName.get(e);if(n===void 0)throw new Error(`Unsupported multicodec: ${e}`);return n}static registerCodec(t){r.codeToName.set(t.code,t.name),r.nameToCode.set(t.name,t.code)}static removePrefix(t){let{prefixedData:e}=t,[n,i]=ye.decode(e),o=r.codeToName.get(n);if(o===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:e.slice(i),name:o}}};Qt.codeToName=new Map;Qt.nameToCode=new Map;Qt.registerCodec({code:237,name:"ed25519-pub"});Qt.registerCodec({code:4864,name:"ed25519-priv"});Qt.registerCodec({code:236,name:"x25519-pub"});Qt.registerCodec({code:4866,name:"x25519-priv"});Qt.registerCodec({code:231,name:"secp256k1-pub"});Qt.registerCodec({code:4865,name:"secp256k1-priv"});function Po(r){Object.keys(r).forEach(t=>{r[t]===void 0?delete r[t]:typeof r[t]=="object"&&Po(r[t])})}var uy=Pc(yu(),1),Er=function(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{u(n.next(f))}catch(l){s(l)}}function a(f){try{u(n.throw(f))}catch(l){s(l)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((n=n.apply(r,t||[])).next())})};var Ti=class{constructor(){this.store=new Map}clear(){return Er(this,void 0,void 0,function*(){this.store.clear()})}close(){return Er(this,void 0,void 0,function*(){})}delete(t){return Er(this,void 0,void 0,function*(){return this.store.delete(t)})}get(t){return Er(this,void 0,void 0,function*(){return this.store.get(t)})}has(t){return Er(this,void 0,void 0,function*(){return this.store.has(t)})}list(){return Er(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(t,e){return Er(this,void 0,void 0,function*(){this.store.set(t,e)})}};var ut=class{};var ki={};Bc(ki,{bitGet:()=>my,bitLen:()=>dy,bitMask:()=>On,bitSet:()=>wy,bytesToHex:()=>Ae,bytesToNumberBE:()=>Be,bytesToNumberLE:()=>Wt,concatBytes:()=>Ke,createHmacDrbg:()=>ks,ensureBytes:()=>it,equalBytes:()=>yy,hexToBytes:()=>vr,hexToNumber:()=>Ss,isBytes:()=>$t,numberToBytesBE:()=>Pt,numberToBytesLE:()=>Pe,numberToHexUnpadded:()=>wu,numberToVarBytesBE:()=>hy,utf8ToBytes:()=>py,validateObject:()=>Rt});var mu=BigInt(0),Si=BigInt(1),fy=BigInt(2);function $t(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var ly=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ae(r){if(!$t(r))throw new Error("Uint8Array expected");let t="";for(let e=0;e<r.length;e++)t+=ly[r[e]];return t}function wu(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Ss(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var ve={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function pu(r){if(r>=ve._0&&r<=ve._9)return r-ve._0;if(r>=ve._A&&r<=ve._F)return r-(ve._A-10);if(r>=ve._a&&r<=ve._f)return r-(ve._a-10)}function vr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let i=0,o=0;i<e;i++,o+=2){let s=pu(r.charCodeAt(o)),c=pu(r.charCodeAt(o+1));if(s===void 0||c===void 0){let a=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function Be(r){return Ss(Ae(r))}function Wt(r){if(!$t(r))throw new Error("Uint8Array expected");return Ss(Ae(Uint8Array.from(r).reverse()))}function Pt(r,t){return vr(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return Pt(r,t).reverse()}function hy(r){return vr(wu(r))}function it(r,t,e){let n;if(typeof t=="string")try{n=vr(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if($t(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof e=="number"&&i!==e)throw new Error(`${r} expected ${e} bytes, got ${i}`);return n}function Ke(...r){let t=0;for(let i=0;i<r.length;i++){let o=r[i];if(!$t(o))throw new Error("Uint8Array expected");t+=o.length}let e=new Uint8Array(t),n=0;for(let i=0;i<r.length;i++){let o=r[i];e.set(o,n),n+=o.length}return e}function yy(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function py(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function dy(r){let t;for(t=0;r>mu;r>>=Si,t+=1);return t}function my(r,t){return r>>BigInt(t)&Si}var wy=(r,t,e)=>r|(e?Si:mu)<<BigInt(t),On=r=>(fy<<BigInt(r-1))-Si,Ts=r=>new Uint8Array(r),du=r=>Uint8Array.from(r);function ks(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Ts(r),i=Ts(r),o=0,s=()=>{n.fill(1),i.fill(0),o=0},c=(...l)=>e(i,n,...l),a=(l=Ts())=>{i=c(du([0]),l),n=c(),l.length!==0&&(i=c(du([1]),l),n=c())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<t;){n=c();let m=n.slice();y.push(m),l+=n.length}return Ke(...y)};return(l,y)=>{s(),a(l);let m;for(;!(m=y(u()));)a();return s(),m}}var gy={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||$t(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Rt(r,t,e={}){let n=(i,o,s)=>{let c=gy[o];if(typeof c!="function")throw new Error(`Invalid validator "${o}", expected function`);let a=r[i];if(!(s&&a===void 0)&&!c(a,r))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${o}`)};for(let[i,o]of Object.entries(t))n(i,o,!1);for(let[i,o]of Object.entries(e))n(i,o,!0);return r}function gu(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function xy(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Us(r,...t){if(!xy(r))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function xu(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");gu(r.outputLen),gu(r.blockLen)}function qr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function bu(r,t){Us(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Ui=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Eu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var Ii=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),zt=(r,t)=>r<<32-t|r>>>t,by=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!by)throw new Error("Non little-endian hardware is not supported");function Is(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Rn(r){if(typeof r=="string"&&(r=Is(r)),!Eu(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ci(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];if(!Eu(i))throw new Error("Uint8Array expected");t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var Fr=class{clone(){return this._cloneInto()}},Z0={}.toString;function _i(r){let t=n=>r().update(Rn(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Nn(r=32){if(Ui&&typeof Ui.getRandomValues=="function")return Ui.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function Ey(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var $r=class extends Fr{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ii(this.buffer)}update(t){qr(this);let{view:e,buffer:n,blockLen:i}=this;t=Rn(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Ii(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){qr(this),bu(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)e[l]=0;Ey(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=Ii(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var vy=(r,t,e)=>r&t^~r&e,Ay=(r,t,e)=>r&t^r&e^t&e,By=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),je=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),He=new Uint32Array(64),Cs=class extends $r{constructor(){super(64,32,8,!1),this.A=je[0]|0,this.B=je[1]|0,this.C=je[2]|0,this.D=je[3]|0,this.E=je[4]|0,this.F=je[5]|0,this.G=je[6]|0,this.H=je[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)He[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let y=He[l-15],m=He[l-2],p=zt(y,7)^zt(y,18)^y>>>3,h=zt(m,17)^zt(m,19)^m>>>10;He[l]=h+He[l-7]+p+He[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let y=zt(c,6)^zt(c,11)^zt(c,25),m=f+y+vy(c,a,u)+By[l]+He[l]|0,h=(zt(n,2)^zt(n,13)^zt(n,22))+Ay(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+h|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,c,a,u,f)}roundClean(){He.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Li=_i(()=>new Cs);var lt=BigInt(0),st=BigInt(1),Ar=BigInt(2),Py=BigInt(3),_s=BigInt(4),vu=BigInt(5),Au=BigInt(8),Ky=BigInt(9),Ty=BigInt(16);function tt(r,t){let e=r%t;return e>=lt?e:t+e}function Ls(r,t,e){if(e<=lt||t<lt)throw new Error("Expected power/modulo > 0");if(e===st)return lt;let n=st;for(;t>lt;)t&st&&(n=n*r%e),r=r*r%e,t>>=st;return n}function ot(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Oi(r,t){if(r===lt||t<=lt)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=tt(r,t),n=t,i=lt,o=st,s=st,c=lt;for(;e!==lt;){let u=n/e,f=n%e,l=i-s*u,y=o-c*u;n=e,e=f,i=s,o=c,s=l,c=y}if(n!==st)throw new Error("invert: does not exist");return tt(i,t)}function Sy(r){let t=(r-st)/Ar,e,n,i;for(e=r-st,n=0;e%Ar===lt;e/=Ar,n++);for(i=Ar;i<r&&Ls(i,t,r)!==r-st;i++);if(n===1){let s=(r+st)/_s;return function(a,u){let f=a.pow(u,s);if(!a.eql(a.sqr(f),u))throw new Error("Cannot find square root");return f}}let o=(e+st)/Ar;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,f=c.pow(c.mul(c.ONE,i),e),l=c.pow(a,o),y=c.pow(a,e);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let m=1;for(let h=c.sqr(y);m<u&&!c.eql(h,c.ONE);m++)h=c.sqr(h);let p=c.pow(f,st<<BigInt(u-m-1));f=c.sqr(p),l=c.mul(l,p),y=c.mul(y,f),u=m}return l}}function ky(r){if(r%_s===Py){let t=(r+st)/_s;return function(n,i){let o=n.pow(i,t);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%Au===vu){let t=(r-vu)/Au;return function(n,i){let o=n.mul(i,Ar),s=n.pow(o,t),c=n.mul(i,s),a=n.mul(n.mul(c,Ar),s),u=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return r%Ty,Sy(r)}var Bu=(r,t)=>(tt(r,t)&st)===st,Uy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Os(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Uy.reduce((n,i)=>(n[i]="function",n),t);return Rt(r,e)}function Iy(r,t,e){if(e<lt)throw new Error("Expected power > 0");if(e===lt)return r.ONE;if(e===st)return t;let n=r.ONE,i=t;for(;e>lt;)e&st&&(n=r.mul(n,i)),i=r.sqr(i),e>>=st;return n}function Cy(r,t){let e=new Array(t.length),n=t.reduce((o,s,c)=>r.is0(s)?o:(e[c]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return t.reduceRight((o,s,c)=>r.is0(s)?o:(e[c]=r.mul(o,e[c]),r.mul(o,s)),i),e}function Rs(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Wr(r,t,e=!1,n={}){if(r<=lt)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Rs(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=ky(r),c=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:On(i),ZERO:lt,ONE:st,create:a=>tt(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return lt<=a&&a<r},is0:a=>a===lt,isOdd:a=>(a&st)===st,neg:a=>tt(-a,r),eql:(a,u)=>a===u,sqr:a=>tt(a*a,r),add:(a,u)=>tt(a+u,r),sub:(a,u)=>tt(a-u,r),mul:(a,u)=>tt(a*u,r),pow:(a,u)=>Iy(c,a,u),div:(a,u)=>tt(a*Oi(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>Oi(a,r),sqrt:n.sqrt||(a=>s(c,a)),invertBatch:a=>Cy(c,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>e?Pe(a,o):Pt(a,o),fromBytes:a=>{if(a.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${a.length}`);return e?Wt(a):Be(a)}});return Object.freeze(c)}function Pu(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function Ku(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Ns(r){let t=Ku(r);return t+Math.ceil(t/2)}function Tu(r,t,e=!1){let n=r.length,i=Ku(t),o=Ns(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=e?Be(r):Wt(r),c=tt(s,t-st)+st;return e?Pe(c,i):Pt(c,i)}var Ly=BigInt(0),Ds=BigInt(1);function Ri(r,t){let e=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(t/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:e,unsafeLadder(i,o){let s=r.ZERO,c=i;for(;o>Ly;)o&Ds&&(s=s.add(c)),c=c.double(),o>>=Ds;return s},precomputeWindow(i,o){let{windows:s,windowSize:c}=n(o),a=[],u=i,f=u;for(let l=0;l<s;l++){f=u,a.push(f);for(let y=1;y<c;y++)f=f.add(u),a.push(f);u=f.double()}return a},wNAF(i,o,s){let{windows:c,windowSize:a}=n(i),u=r.ZERO,f=r.BASE,l=BigInt(2**i-1),y=2**i,m=BigInt(i);for(let p=0;p<c;p++){let h=p*a,d=Number(s&l);s>>=m,d>a&&(d-=y,s+=Ds);let g=h,b=h+Math.abs(d)-1,x=p%2!==0,A=d<0;d===0?f=f.add(e(x,o[g])):u=u.add(e(A,o[b]))}return{p:u,f}},wNAFCached(i,o,s,c){let a=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&o.set(i,c(u))),this.wNAF(a,u,s)}}}function Dn(r){return Os(r.Fp),Rt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Rs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Oy(r){let t=Dn(r);Rt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:i}=t;if(e){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Ry,hexToBytes:Ny}=ki,Br={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Br;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Ry(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Br,e=typeof r=="string"?Ny(r):r;if(!$t(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:i,l:o}=Br._parseInt(e.subarray(2)),{d:s,l:c}=Br._parseInt(o);if(c.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(r){let t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,e=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),i=t(e(r.r)),o=n.length/2,s=i.length/2,c=e(o),a=e(s);return`30${e(s+o+4)}02${a}${i}02${c}${n}`}},Te=BigInt(0),Nt=BigInt(1),lm=BigInt(2),Su=BigInt(3),hm=BigInt(4);function Dy(r){let t=Oy(r),{Fp:e}=t,n=t.toBytes||((p,h,d)=>{let g=h.toAffine();return Ke(Uint8Array.from([4]),e.toBytes(g.x),e.toBytes(g.y))}),i=t.fromBytes||(p=>{let h=p.subarray(1),d=e.fromBytes(h.subarray(0,e.BYTES)),g=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:d,y:g}});function o(p){let{a:h,b:d}=t,g=e.sqr(p),b=e.mul(g,p);return e.add(e.add(b,e.mul(p,h)),d)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Te<p&&p<t.n}function c(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function a(p){let{allowedPrivateKeyLengths:h,nByteLength:d,wrapPrivateKey:g,n:b}=t;if(h&&typeof p!="bigint"){if($t(p)&&(p=Ae(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(d*2,"0")}let x;try{x=typeof p=="bigint"?p:Be(it("private key",p,d))}catch{throw new Error(`private key must be ${d} bytes, hex or bigint, not ${typeof p}`)}return g&&(x=tt(x,b)),c(x),x}let u=new Map;function f(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,d,g){if(this.px=h,this.py=d,this.pz=g,h==null||!e.isValid(h))throw new Error("x required");if(d==null||!e.isValid(d))throw new Error("y required");if(g==null||!e.isValid(g))throw new Error("z required")}static fromAffine(h){let{x:d,y:g}=h||{};if(!h||!e.isValid(d)||!e.isValid(g))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let b=x=>e.eql(x,e.ZERO);return b(d)&&b(g)?l.ZERO:new l(d,g,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let d=e.invertBatch(h.map(g=>g.pz));return h.map((g,b)=>g.toAffine(d[b])).map(l.fromAffine)}static fromHex(h){let d=l.fromAffine(i(it("pointHex",h)));return d.assertValidity(),d}static fromPrivateKey(h){return l.BASE.multiply(a(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=this.toAffine();if(!e.isValid(h)||!e.isValid(d))throw new Error("bad point: x or y not FE");let g=e.sqr(d),b=o(h);if(!e.eql(g,b))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:d,py:g,pz:b}=this,{px:x,py:A,pz:v}=h,K=e.eql(e.mul(d,v),e.mul(x,b)),k=e.eql(e.mul(g,v),e.mul(A,b));return K&&k}negate(){return new l(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:d}=t,g=e.mul(d,Su),{px:b,py:x,pz:A}=this,v=e.ZERO,K=e.ZERO,k=e.ZERO,T=e.mul(b,b),L=e.mul(x,x),O=e.mul(A,A),C=e.mul(b,x);return C=e.add(C,C),k=e.mul(b,A),k=e.add(k,k),v=e.mul(h,k),K=e.mul(g,O),K=e.add(v,K),v=e.sub(L,K),K=e.add(L,K),K=e.mul(v,K),v=e.mul(C,v),k=e.mul(g,k),O=e.mul(h,O),C=e.sub(T,O),C=e.mul(h,C),C=e.add(C,k),k=e.add(T,T),T=e.add(k,T),T=e.add(T,O),T=e.mul(T,C),K=e.add(K,T),O=e.mul(x,A),O=e.add(O,O),T=e.mul(O,C),v=e.sub(v,T),k=e.mul(O,L),k=e.add(k,k),k=e.add(k,k),new l(v,K,k)}add(h){f(h);let{px:d,py:g,pz:b}=this,{px:x,py:A,pz:v}=h,K=e.ZERO,k=e.ZERO,T=e.ZERO,L=t.a,O=e.mul(t.b,Su),C=e.mul(d,x),j=e.mul(g,A),M=e.mul(b,v),z=e.add(d,g),B=e.add(x,A);z=e.mul(z,B),B=e.add(C,j),z=e.sub(z,B),B=e.add(d,b);let U=e.add(x,v);return B=e.mul(B,U),U=e.add(C,M),B=e.sub(B,U),U=e.add(g,b),K=e.add(A,v),U=e.mul(U,K),K=e.add(j,M),U=e.sub(U,K),T=e.mul(L,B),K=e.mul(O,M),T=e.add(K,T),K=e.sub(j,T),T=e.add(j,T),k=e.mul(K,T),j=e.add(C,C),j=e.add(j,C),M=e.mul(L,M),B=e.mul(O,B),j=e.add(j,M),M=e.sub(C,M),M=e.mul(L,M),B=e.add(B,M),C=e.mul(j,B),k=e.add(k,C),C=e.mul(U,B),K=e.mul(z,K),K=e.sub(K,C),C=e.mul(z,j),T=e.mul(U,T),T=e.add(T,C),new l(K,k,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return m.wNAFCached(this,u,h,d=>{let g=e.invertBatch(d.map(b=>b.pz));return d.map((b,x)=>b.toAffine(g[x])).map(l.fromAffine)})}multiplyUnsafe(h){let d=l.ZERO;if(h===Te)return d;if(c(h),h===Nt)return this;let{endo:g}=t;if(!g)return m.unsafeLadder(this,h);let{k1neg:b,k1:x,k2neg:A,k2:v}=g.splitScalar(h),K=d,k=d,T=this;for(;x>Te||v>Te;)x&Nt&&(K=K.add(T)),v&Nt&&(k=k.add(T)),T=T.double(),x>>=Nt,v>>=Nt;return b&&(K=K.negate()),A&&(k=k.negate()),k=new l(e.mul(k.px,g.beta),k.py,k.pz),K.add(k)}multiply(h){c(h);let d=h,g,b,{endo:x}=t;if(x){let{k1neg:A,k1:v,k2neg:K,k2:k}=x.splitScalar(d),{p:T,f:L}=this.wNAF(v),{p:O,f:C}=this.wNAF(k);T=m.constTimeNegate(A,T),O=m.constTimeNegate(K,O),O=new l(e.mul(O.px,x.beta),O.py,O.pz),g=T.add(O),b=L.add(C)}else{let{p:A,f:v}=this.wNAF(d);g=A,b=v}return l.normalizeZ([g,b])[0]}multiplyAndAddUnsafe(h,d,g){let b=l.BASE,x=(v,K)=>K===Te||K===Nt||!v.equals(b)?v.multiplyUnsafe(K):v.multiply(K),A=x(this,d).add(x(h,g));return A.is0()?void 0:A}toAffine(h){let{px:d,py:g,pz:b}=this,x=this.is0();h==null&&(h=x?e.ONE:e.inv(b));let A=e.mul(d,h),v=e.mul(g,h),K=e.mul(b,h);if(x)return{x:e.ZERO,y:e.ZERO};if(!e.eql(K,e.ONE))throw new Error("invZ was invalid");return{x:A,y:v}}isTorsionFree(){let{h,isTorsionFree:d}=t;if(h===Nt)return!0;if(d)return d(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:d}=t;return h===Nt?this:d?d(l,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(l,this,h)}toHex(h=!0){return Ae(this.toRawBytes(h))}}l.BASE=new l(t.Gx,t.Gy,e.ONE),l.ZERO=new l(e.ZERO,e.ONE,e.ZERO);let y=t.nBitLength,m=Ri(l,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:o,isWithinCurveOrder:s}}function My(r){let t=Dn(r);return Rt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ku(r){let t=My(r),{Fp:e,n}=t,i=e.BYTES+1,o=2*e.BYTES+1;function s(B){return Te<B&&B<e.ORDER}function c(B){return tt(B,n)}function a(B){return Oi(B,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:l,isWithinCurveOrder:y}=Dy({...t,toBytes(B,U,R){let P=U.toAffine(),w=e.toBytes(P.x),S=Ke;return R?S(Uint8Array.from([U.hasEvenY()?2:3]),w):S(Uint8Array.from([4]),w,e.toBytes(P.y))},fromBytes(B){let U=B.length,R=B[0],P=B.subarray(1);if(U===i&&(R===2||R===3)){let w=Be(P);if(!s(w))throw new Error("Point is not on curve");let S=l(w),I=e.sqrt(S),_=(I&Nt)===Nt;return(R&1)===1!==_&&(I=e.neg(I)),{x:w,y:I}}else if(U===o&&R===4){let w=e.fromBytes(P.subarray(0,e.BYTES)),S=e.fromBytes(P.subarray(e.BYTES,2*e.BYTES));return{x:w,y:S}}else throw new Error(`Point of length ${U} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),m=B=>Ae(Pt(B,t.nByteLength));function p(B){let U=n>>Nt;return B>U}function h(B){return p(B)?c(-B):B}let d=(B,U,R)=>Be(B.slice(U,R));class g{constructor(U,R,P){this.r=U,this.s=R,this.recovery=P,this.assertValidity()}static fromCompact(U){let R=t.nByteLength;return U=it("compactSignature",U,R*2),new g(d(U,0,R),d(U,R,2*R))}static fromDER(U){let{r:R,s:P}=Br.toSig(it("DER",U));return new g(R,P)}assertValidity(){if(!y(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!y(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(U){return new g(this.r,this.s,U)}recoverPublicKey(U){let{r:R,s:P,recovery:w}=this,S=k(it("msgHash",U));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let I=w===2||w===3?R+t.n:R;if(I>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let _=w&1?"03":"02",H=u.fromHex(_+m(I)),J=a(I),Z=c(-S*J),q=c(P*J),F=u.BASE.multiplyAndAddUnsafe(H,Z,q);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return vr(this.toDERHex())}toDERHex(){return Br.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return vr(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let b={isValidPrivateKey(B){try{return f(B),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let B=Ns(t.n);return Tu(t.randomBytes(B),t.n)},precompute(B=8,U=u.BASE){return U._setWindowSize(B),U.multiply(BigInt(3)),U}};function x(B,U=!0){return u.fromPrivateKey(B).toRawBytes(U)}function A(B){let U=$t(B),R=typeof B=="string",P=(U||R)&&B.length;return U?P===i||P===o:R?P===2*i||P===2*o:B instanceof u}function v(B,U,R=!0){if(A(B))throw new Error("first arg must be private key");if(!A(U))throw new Error("second arg must be public key");return u.fromHex(U).multiply(f(B)).toRawBytes(R)}let K=t.bits2int||function(B){let U=Be(B),R=B.length*8-t.nBitLength;return R>0?U>>BigInt(R):U},k=t.bits2int_modN||function(B){return c(K(B))},T=On(t.nBitLength);function L(B){if(typeof B!="bigint")throw new Error("bigint expected");if(!(Te<=B&&B<T))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Pt(B,t.nByteLength)}function O(B,U,R=C){if(["recovered","canonical"].some(et=>et in R))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:w}=t,{lowS:S,prehash:I,extraEntropy:_}=R;S==null&&(S=!0),B=it("msgHash",B),I&&(B=it("prehashed msgHash",P(B)));let H=k(B),J=f(U),Z=[L(J),L(H)];if(_!=null){let et=_===!0?w(e.BYTES):_;Z.push(it("extraEntropy",et))}let q=Ke(...Z),F=H;function rt(et){let yt=K(et);if(!y(yt))return;let pt=a(yt),ft=u.BASE.multiply(yt).toAffine(),mt=c(ft.x);if(mt===Te)return;let he=c(pt*c(F+mt*J));if(he===Te)return;let er=(ft.x===mt?0:2)|Number(ft.y&Nt),on=he;return S&&p(he)&&(on=h(he),er^=1),new g(mt,on,er)}return{seed:q,k2sig:rt}}let C={lowS:t.lowS,prehash:!1},j={lowS:t.lowS,prehash:!1};function M(B,U,R=C){let{seed:P,k2sig:w}=O(B,U,R),S=t;return ks(S.hash.outputLen,S.nByteLength,S.hmac)(P,w)}u.BASE._setWindowSize(8);function z(B,U,R,P=j){let w=B;if(U=it("msgHash",U),R=it("publicKey",R),"strict"in P)throw new Error("options.strict was renamed to lowS");let{lowS:S,prehash:I}=P,_,H;try{if(typeof w=="string"||$t(w))try{_=g.fromDER(w)}catch(ft){if(!(ft instanceof Br.Err))throw ft;_=g.fromCompact(w)}else if(typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint"){let{r:ft,s:mt}=w;_=new g(ft,mt)}else throw new Error("PARSE");H=u.fromHex(R)}catch(ft){if(ft.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(S&&_.hasHighS())return!1;I&&(U=t.hash(U));let{r:J,s:Z}=_,q=k(U),F=a(Z),rt=c(q*F),et=c(J*F),yt=u.BASE.multiplyAndAddUnsafe(H,rt,et)?.toAffine();return yt?c(yt.x)===J:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:v,sign:M,verify:z,ProjectivePoint:u,Signature:g,utils:b}}var Ni=class extends Fr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,xu(t);let n=Rn(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return qr(this),this.iHash.update(t),this}digestInto(t){qr(this),Us(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ms=(r,t,e)=>new Ni(r,t).update(e).digest();Ms.create=(r,t)=>new Ni(r,t);function jy(r){return{hash:r,hmac:(t,...e)=>Ms(r,t,Ci(...e)),randomBytes:Nn}}function Di(r,t){let e=n=>ku({...r,...jy(n)});return Object.freeze({...e(t),create:e})}var Cu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Uu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Hy=BigInt(1),js=BigInt(2),Iu=(r,t)=>(r+t/js)/t;function Jy(r){let t=Cu,e=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=ot(f,e,t)*f%t,y=ot(l,e,t)*f%t,m=ot(y,js,t)*u%t,p=ot(m,i,t)*m%t,h=ot(p,o,t)*p%t,d=ot(h,c,t)*h%t,g=ot(d,a,t)*d%t,b=ot(g,c,t)*h%t,x=ot(b,e,t)*f%t,A=ot(x,s,t)*p%t,v=ot(A,n,t)*u%t,K=ot(v,js,t);if(!Hs.eql(Hs.sqr(K),r))throw new Error("Cannot find square root");return K}var Hs=Wr(Cu,void 0,void 0,{sqrt:Jy}),at=Di({a:BigInt(0),b:BigInt(7),Fp:Hs,n:Uu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Uu,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Hy*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,s=BigInt("0x100000000000000000000000000000000"),c=Iu(o*r,t),a=Iu(-n*r,t),u=tt(r-c*e-a*i,t),f=tt(-c*n-a*o,t),l=u>s,y=f>s;if(l&&(u=t-u),y&&(f=t-f),u>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:y,k2:f}}}},Li),Bm=BigInt(0);var Pm=at.ProjectivePoint;function Mi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Gy(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function zr(r,...t){if(!Gy(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Mn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Mi(r.outputLen),Mi(r.blockLen)}function Zr(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function _u(r,t){zr(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Se=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var ji=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Zt=(r,t)=>r<<32-t|r>>>t;var Im=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Vy(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Je(r){return typeof r=="string"&&(r=Vy(r)),zr(r),r}function Js(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];zr(i),t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}var Yr=class{clone(){return this._cloneInto()}},Cm={}.toString;function Lu(r){let t=n=>r().update(Je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ou(r=32){if(Se&&typeof Se.getRandomValues=="function")return Se.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function qy(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var Ru=(r,t,e)=>r&t^~r&e,Nu=(r,t,e)=>r&t^r&e^t&e,Hi=class extends Yr{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=ji(this.buffer)}update(t){Zr(this);let{view:e,buffer:n,blockLen:i}=this;t=Je(t);let o=t.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=ji(t);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Zr(this),_u(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)e[l]=0;qy(n,i-8,BigInt(this.length*8),o),this.process(n,0);let c=ji(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:i,finished:o,destroyed:s,pos:c}=this;return t.length=i,t.pos=c,t.finished=o,t.destroyed=s,i%e&&t.buffer.set(n),t}};var Fy=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ge=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ve=new Uint32Array(64),Gs=class extends Hi{constructor(){super(64,32,8,!1),this.A=Ge[0]|0,this.B=Ge[1]|0,this.C=Ge[2]|0,this.D=Ge[3]|0,this.E=Ge[4]|0,this.F=Ge[5]|0,this.G=Ge[6]|0,this.H=Ge[7]|0}get(){let{A:t,B:e,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[t,e,n,i,o,s,c,a]}set(t,e,n,i,o,s,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)Ve[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let y=Ve[l-15],m=Ve[l-2],p=Zt(y,7)^Zt(y,18)^y>>>3,h=Zt(m,17)^Zt(m,19)^m>>>10;Ve[l]=h+Ve[l-7]+p+Ve[l-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Zt(c,6)^Zt(c,11)^Zt(c,25),m=f+y+Ru(c,a,u)+Fy[l]+Ve[l]|0,h=(Zt(n,2)^Zt(n,13)^Zt(n,22))+Nu(n,i,o)|0;f=u,u=a,a=c,c=s+m|0,s=o,o=i,i=n,n=m+h|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,c,a,u,f)}roundClean(){Ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var kt=Lu(()=>new Gs);function Du(r){let t=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),o={};for(let s of i)o[s]=t(n[s]);return o}return n},e=t(r);return JSON.stringify(e)}var Xr=class{static async digest({data:t}){return kt(t)}};var Vs="urn:jwk:";async function G({jwk:r}){let t=r.kty,e;if(t==="EC")e={crv:r.crv,kty:r.kty,x:r.x,y:r.y};else if(t==="oct")e={k:r.k,kty:r.kty};else if(t==="OKP")e={crv:r.crv,kty:r.kty,x:r.x};else if(t==="RSA")e={e:r.e,kty:r.kty,n:r.n};else throw new Error(`Unsupported key type: ${t}`);Po(e);let n=Du(e),i=N.string(n).toUint8Array(),o=await Xr.digest({data:i});return N.uint8Array(o).toBase64Url()}function oe(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r&&"d"in r)||r.kty!=="EC"||typeof r.d!="string"||typeof r.x!="string")}function Qr(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r)||"d"in r||r.kty!=="EC"||typeof r.x!="string")}function se(r){return!(!r||typeof r!="object"||!("kty"in r&&"k"in r)||r.kty!=="oct"||typeof r.k!="string")}function Ut(r){return!(!r||typeof r!="object"||!("kty"in r&&"crv"in r&&"x"in r&&"d"in r)||r.kty!=="OKP"||typeof r.d!="string"||typeof r.x!="string")}function tn(r){return!(!r||typeof r!="object"||"d"in r||!("kty"in r&&"crv"in r&&"x"in r)||r.kty!=="OKP"||typeof r.x!="string")}function Mu(r){if(!r||typeof r!="object")return!1;switch(r.kty){case"EC":case"OKP":case"RSA":return"d"in r;case"oct":return"k"in r;default:return!1}}function Fm(r){if(!r||typeof r!="object")return!1;switch(r.kty){case"EC":case"OKP":return"x"in r&&!("d"in r);case"RSA":return"n"in r&&"e"in r&&!("d"in r);default:return!1}}var Dt=class r{static async adjustSignatureToLowS({signature:t}){let e=at.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"secp256k1",x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return at.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"secp256k1",x:N.uint8Array(n.x).toBase64Url(),y:N.uint8Array(n.y).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return at.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return at.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=at.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(oe(t)&&t.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!oe(t))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(Qr(t)&&t.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=N.base64Url(t.x).toUint8Array(),i=N.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return at.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=kt(t);return at.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return at.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{at.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=kt(n);return at.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=at.getPublicKey(t));let e=at.ProjectivePoint.fromHex(t),n=Pt(e.x,32),i=Pt(e.y,32);return{x:n,y:i}}};var ju=Wr(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),$y=ju.create(BigInt("-3")),Wy=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),zy=Di({a:$y,b:Wy,Fp:ju,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Li),It=zy;var Mt=class r{static async adjustSignatureToLowS({signature:t}){let e=It.Signature.fromCompact(t);return e.hasHighS()?e.normalizeS().toCompactRawBytes():t}static async bytesToPrivateKey({privateKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e=await r.getCurvePoint({keyBytes:t}),n={kty:"EC",crv:"P-256",x:N.uint8Array(e.x).toBase64Url(),y:N.uint8Array(e.y).toBase64Url()};return n.kid=await G({jwk:n}),n}static async compressPublicKey({publicKeyBytes:t}){return It.ProjectivePoint.fromHex(t).toRawBytes(!0)}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=await r.getCurvePoint({keyBytes:e}),i={kty:"EC",crv:"P-256",x:N.uint8Array(n.x).toBase64Url(),y:N.uint8Array(n.y).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertDerToCompactSignature({derSignature:t}){return It.Signature.fromDER(t).toCompactRawBytes()}static async decompressPublicKey({publicKeyBytes:t}){return It.ProjectivePoint.fromHex(t).toRawBytes(!1)}static async generateKey(){let t=It.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(oe(t)&&t.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!oe(t))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!(Qr(t)&&t.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let e=new Uint8Array([4]),n=N.base64Url(t.x).toUint8Array(),i=N.base64Url(t.y).toUint8Array();return new Uint8Array([...e,...n,...i])}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return It.getSharedSecret(n,i,!0).slice(1)}static async sign({data:t,key:e}){let n=await r.privateKeyToBytes({privateKey:e}),i=kt(t);return It.sign(i,n).toCompactRawBytes()}static async validatePrivateKey({privateKeyBytes:t}){return It.utils.isValidPrivateKey(t)}static async validatePublicKey({publicKeyBytes:t}){try{It.ProjectivePoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t}),o=kt(n);return It.verify(e,o,i,{lowS:!1})}static async getCurvePoint({keyBytes:t}){t.byteLength===32&&(t=It.getPublicKey(t));let e=It.ProjectivePoint.fromHex(t),n=Pt(e.x,32),i=Pt(e.y,32);return{x:n,y:i}}};var jn=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"ES256K":case"secp256k1":{let n=await Dt.bytesToPrivateKey({privateKeyBytes:e});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Mt.bytesToPrivateKey({privateKeyBytes:e});return n.alg="ES256",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async bytesToPublicKey({algorithm:t,publicKeyBytes:e}){switch(t){case"ES256K":case"secp256k1":{let n=await Dt.bytesToPublicKey({publicKeyBytes:e});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=await Mt.bytesToPublicKey({publicKeyBytes:e});return n.alg="ES256",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await Dt.computePublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Mt.computePublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"ES256K":case"secp256k1":{let e=await Dt.generateKey();return e.alg="ES256K",e}case"ES256":case"secp256r1":{let e=await Mt.generateKey();return e.alg="ES256",e}}}async getPublicKey({key:t}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":{let e=await Dt.getPublicKey({key:t});return e.alg="ES256K",e}case"P-256":{let e=await Mt.getPublicKey({key:t});return e.alg="ES256",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!oe(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(t.crv){case"secp256k1":return await Dt.sign({key:t,data:e});case"P-256":return await Mt.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!Qr(t))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(t.crv){case"secp256k1":return await Dt.verify({key:t,signature:e,data:n});case"P-256":return await Mt.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){switch(t.crv){case"secp256k1":return await Dt.privateKeyToBytes({privateKey:t});case"P-256":return await Mt.privateKeyToBytes({privateKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}async publicKeyToBytes({publicKey:t}){switch(t.crv){case"secp256k1":return await Dt.publicKeyToBytes({publicKey:t});case"P-256":return await Mt.publicKeyToBytes({publicKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}};var Ji=BigInt(4294967295),qs=BigInt(32);function Hu(r,t=!1){return t?{h:Number(r&Ji),l:Number(r>>qs&Ji)}:{h:Number(r>>qs&Ji)|0,l:Number(r&Ji)|0}}function Zy(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=Hu(r[i],t);[e[i],n[i]]=[o,s]}return[e,n]}var Yy=(r,t)=>BigInt(r>>>0)<<qs|BigInt(t>>>0),Xy=(r,t,e)=>r>>>e,Qy=(r,t,e)=>r<<32-e|t>>>e,tp=(r,t,e)=>r>>>e|t<<32-e,ep=(r,t,e)=>r<<32-e|t>>>e,rp=(r,t,e)=>r<<64-e|t>>>e-32,np=(r,t,e)=>r>>>e-32|t<<64-e,ip=(r,t)=>t,op=(r,t)=>r,sp=(r,t,e)=>r<<e|t>>>32-e,cp=(r,t,e)=>t<<e|r>>>32-e,ap=(r,t,e)=>t<<e-32|r>>>64-e,up=(r,t,e)=>r<<e-32|t>>>64-e;function fp(r,t,e,n){let i=(t>>>0)+(n>>>0);return{h:r+e+(i/2**32|0)|0,l:i|0}}var lp=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),hp=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,yp=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),pp=(r,t,e,n,i)=>t+e+n+i+(r/2**32|0)|0,dp=(r,t,e,n,i)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(i>>>0),mp=(r,t,e,n,i,o)=>t+e+n+i+o+(r/2**32|0)|0;var wp={fromBig:Hu,split:Zy,toBig:Yy,shrSH:Xy,shrSL:Qy,rotrSH:tp,rotrSL:ep,rotrBH:rp,rotrBL:np,rotr32H:ip,rotr32L:op,rotlSH:sp,rotlSL:cp,rotlBH:ap,rotlBL:up,add:fp,add3L:lp,add3H:hp,add4L:yp,add4H:pp,add5H:mp,add5L:dp},$=wp;var[gp,xp]=$.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),qe=new Uint32Array(80),Fe=new Uint32Array(80),Fs=class extends $r{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:i,Ch:o,Cl:s,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:y,Gh:m,Gl:p,Hh:h,Hl:d}=this;return[t,e,n,i,o,s,c,a,u,f,l,y,m,p,h,d]}set(t,e,n,i,o,s,c,a,u,f,l,y,m,p,h,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=m|0,this.Gl=p|0,this.Hh=h|0,this.Hl=d|0}process(t,e){for(let x=0;x<16;x++,e+=4)qe[x]=t.getUint32(e),Fe[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let A=qe[x-15]|0,v=Fe[x-15]|0,K=$.rotrSH(A,v,1)^$.rotrSH(A,v,8)^$.shrSH(A,v,7),k=$.rotrSL(A,v,1)^$.rotrSL(A,v,8)^$.shrSL(A,v,7),T=qe[x-2]|0,L=Fe[x-2]|0,O=$.rotrSH(T,L,19)^$.rotrBH(T,L,61)^$.shrSH(T,L,6),C=$.rotrSL(T,L,19)^$.rotrBL(T,L,61)^$.shrSL(T,L,6),j=$.add4L(k,C,Fe[x-7],Fe[x-16]),M=$.add4H(j,K,O,qe[x-7],qe[x-16]);qe[x]=M|0,Fe[x]=j|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:y,Fh:m,Fl:p,Gh:h,Gl:d,Hh:g,Hl:b}=this;for(let x=0;x<80;x++){let A=$.rotrSH(l,y,14)^$.rotrSH(l,y,18)^$.rotrBH(l,y,41),v=$.rotrSL(l,y,14)^$.rotrSL(l,y,18)^$.rotrBL(l,y,41),K=l&m^~l&h,k=y&p^~y&d,T=$.add5L(b,v,k,xp[x],Fe[x]),L=$.add5H(T,g,A,K,gp[x],qe[x]),O=T|0,C=$.rotrSH(n,i,28)^$.rotrBH(n,i,34)^$.rotrBH(n,i,39),j=$.rotrSL(n,i,28)^$.rotrBL(n,i,34)^$.rotrBL(n,i,39),M=n&o^n&c^o&c,z=i&s^i&a^s&a;g=h|0,b=d|0,h=m|0,d=p|0,m=l|0,p=y|0,{h:l,l:y}=$.add(u|0,f|0,L|0,O|0),u=c|0,f=a|0,c=o|0,a=s|0,o=n|0,s=i|0;let B=$.add3L(O,j,z);n=$.add3H(B,L,C,M),i=B|0}({h:n,l:i}=$.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=$.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:c,l:a}=$.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=$.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=$.add(this.Eh|0,this.El|0,l|0,y|0),{h:m,l:p}=$.add(this.Fh|0,this.Fl|0,m|0,p|0),{h,l:d}=$.add(this.Gh|0,this.Gl|0,h|0,d|0),{h:g,l:b}=$.add(this.Hh|0,this.Hl|0,g|0,b|0),this.set(n,i,o,s,c,a,u,f,l,y,m,p,h,d,g,b)}roundClean(){qe.fill(0),Fe.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var $s=_i(()=>new Fs);var Yt=BigInt(0),Ct=BigInt(1),Gi=BigInt(2),bp=BigInt(8),Ep={zip215:!0};function vp(r){let t=Dn(r);return Rt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Vi(r){let t=vp(r),{Fp:e,n,prehash:i,hash:o,randomBytes:s,nByteLength:c,h:a}=t,u=Gi<<BigInt(c*8)-Ct,f=e.create,l=t.uvRatio||((P,w)=>{try{return{isValid:!0,value:e.sqrt(P*e.inv(w))}}catch{return{isValid:!1,value:Yt}}}),y=t.adjustScalarBytes||(P=>P),m=t.domain||((P,w,S)=>{if(w.length||S)throw new Error("Contexts/pre-hash are not supported");return P}),p=P=>typeof P=="bigint"&&Yt<P,h=(P,w)=>p(P)&&p(w)&&P<w,d=P=>P===Yt||h(P,u);function g(P,w){if(h(P,w))return P;throw new Error(`Expected valid scalar < ${w}, got ${typeof P} ${P}`)}function b(P){return P===Yt?P:g(P,n)}let x=new Map;function A(P){if(!(P instanceof v))throw new Error("ExtendedPoint expected")}class v{constructor(w,S,I,_){if(this.ex=w,this.ey=S,this.ez=I,this.et=_,!d(w))throw new Error("x required");if(!d(S))throw new Error("y required");if(!d(I))throw new Error("z required");if(!d(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof v)throw new Error("extended point not allowed");let{x:S,y:I}=w||{};if(!d(S)||!d(I))throw new Error("invalid affine point");return new v(S,I,Ct,f(S*I))}static normalizeZ(w){let S=e.invertBatch(w.map(I=>I.ez));return w.map((I,_)=>I.toAffine(S[_])).map(v.fromAffine)}_setWindowSize(w){this._WINDOW_SIZE=w,x.delete(this)}assertValidity(){let{a:w,d:S}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:I,ey:_,ez:H,et:J}=this,Z=f(I*I),q=f(_*_),F=f(H*H),rt=f(F*F),et=f(Z*w),yt=f(F*f(et+q)),pt=f(rt+f(S*f(Z*q)));if(yt!==pt)throw new Error("bad point: equation left != right (1)");let ft=f(I*_),mt=f(H*J);if(ft!==mt)throw new Error("bad point: equation left != right (2)")}equals(w){A(w);let{ex:S,ey:I,ez:_}=this,{ex:H,ey:J,ez:Z}=w,q=f(S*Z),F=f(H*_),rt=f(I*Z),et=f(J*_);return q===F&&rt===et}is0(){return this.equals(v.ZERO)}negate(){return new v(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:w}=t,{ex:S,ey:I,ez:_}=this,H=f(S*S),J=f(I*I),Z=f(Gi*f(_*_)),q=f(w*H),F=S+I,rt=f(f(F*F)-H-J),et=q+J,yt=et-Z,pt=q-J,ft=f(rt*yt),mt=f(et*pt),he=f(rt*pt),er=f(yt*et);return new v(ft,mt,er,he)}add(w){A(w);let{a:S,d:I}=t,{ex:_,ey:H,ez:J,et:Z}=this,{ex:q,ey:F,ez:rt,et}=w;if(S===BigInt(-1)){let wc=f((H-_)*(F+q)),gc=f((H+_)*(F-q)),ao=f(gc-wc);if(ao===Yt)return this.double();let xc=f(J*Gi*et),bc=f(Z*Gi*rt),Ec=bc+xc,vc=gc+wc,Ac=bc-xc,jf=f(Ec*ao),Hf=f(vc*Ac),Jf=f(Ec*Ac),Gf=f(ao*vc);return new v(jf,Hf,Gf,Jf)}let yt=f(_*q),pt=f(H*F),ft=f(Z*I*et),mt=f(J*rt),he=f((_+H)*(q+F)-yt-pt),er=mt-ft,on=mt+ft,mc=f(pt-S*yt),Rf=f(he*er),Nf=f(on*mc),Df=f(he*mc),Mf=f(er*on);return new v(Rf,Nf,Mf,Df)}subtract(w){return this.add(w.negate())}wNAF(w){return T.wNAFCached(this,x,w,v.normalizeZ)}multiply(w){let{p:S,f:I}=this.wNAF(g(w,n));return v.normalizeZ([S,I])[0]}multiplyUnsafe(w){let S=b(w);return S===Yt?k:this.equals(k)||S===Ct?this:this.equals(K)?this.wNAF(S).p:T.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(w){let{ex:S,ey:I,ez:_}=this,H=this.is0();w==null&&(w=H?bp:e.inv(_));let J=f(S*w),Z=f(I*w),q=f(_*w);if(H)return{x:Yt,y:Ct};if(q!==Ct)throw new Error("invZ was invalid");return{x:J,y:Z}}clearCofactor(){let{h:w}=t;return w===Ct?this:this.multiplyUnsafe(w)}static fromHex(w,S=!1){let{d:I,a:_}=t,H=e.BYTES;w=it("pointHex",w,H);let J=w.slice(),Z=w[H-1];J[H-1]=Z&-129;let q=Wt(J);q===Yt||(S?g(q,u):g(q,e.ORDER));let F=f(q*q),rt=f(F-Ct),et=f(I*F-_),{isValid:yt,value:pt}=l(rt,et);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let ft=(pt&Ct)===Ct,mt=(Z&128)!==0;if(!S&&pt===Yt&&mt)throw new Error("Point.fromHex: x=0 and x_0=1");return mt!==ft&&(pt=f(-pt)),v.fromAffine({x:pt,y:q})}static fromPrivateKey(w){return C(w).point}toRawBytes(){let{x:w,y:S}=this.toAffine(),I=Pe(S,e.BYTES);return I[I.length-1]|=w&Ct?128:0,I}toHex(){return Ae(this.toRawBytes())}}v.BASE=new v(t.Gx,t.Gy,Ct,f(t.Gx*t.Gy)),v.ZERO=new v(Yt,Ct,Ct,Yt);let{BASE:K,ZERO:k}=v,T=Ri(v,c*8);function L(P){return tt(P,n)}function O(P){return L(Wt(P))}function C(P){let w=c;P=it("private key",P,w);let S=it("hashed private key",o(P),2*w),I=y(S.slice(0,w)),_=S.slice(w,2*w),H=O(I),J=K.multiply(H),Z=J.toRawBytes();return{head:I,prefix:_,scalar:H,point:J,pointBytes:Z}}function j(P){return C(P).pointBytes}function M(P=new Uint8Array,...w){let S=Ke(...w);return O(o(m(S,it("context",P),!!i)))}function z(P,w,S={}){P=it("message",P),i&&(P=i(P));let{prefix:I,scalar:_,pointBytes:H}=C(w),J=M(S.context,I,P),Z=K.multiply(J).toRawBytes(),q=M(S.context,Z,H,P),F=L(J+q*_);b(F);let rt=Ke(Z,Pe(F,e.BYTES));return it("result",rt,c*2)}let B=Ep;function U(P,w,S,I=B){let{context:_,zip215:H}=I,J=e.BYTES;P=it("signature",P,2*J),w=it("message",w),i&&(w=i(w));let Z=Wt(P.slice(J,2*J)),q,F,rt;try{q=v.fromHex(S,H),F=v.fromHex(P.slice(0,J),H),rt=K.multiplyUnsafe(Z)}catch{return!1}if(!H&&q.isSmallOrder())return!1;let et=M(_,F.toRawBytes(),q.toRawBytes(),w);return F.add(q.multiplyUnsafe(et)).subtract(rt).clearCofactor().equals(v.ZERO)}return K._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:z,verify:U,ExtendedPoint:v,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>s(e.BYTES),precompute(P=8,w=v.BASE){return w._setWindowSize(P),w.multiply(BigInt(3)),w}}}}var Hn=BigInt(0),Ws=BigInt(1);function Ap(r){return Rt(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Ju(r){let t=Ap(r),{P:e}=t,n=x=>tt(x,e),i=t.montgomeryBits,o=Math.ceil(i/8),s=t.nByteLength,c=t.adjustScalarBytes||(x=>x),a=t.powPminus2||(x=>Ls(x,e-BigInt(2),e));function u(x,A,v){let K=n(x*(A-v));return A=n(A-K),v=n(v+K),[A,v]}function f(x){if(typeof x=="bigint"&&Hn<=x&&x<e)return x;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(t.a-BigInt(2))/BigInt(4);function y(x,A){let v=f(x),K=f(A),k=v,T=Ws,L=Hn,O=v,C=Ws,j=Hn,M;for(let B=BigInt(i-1);B>=Hn;B--){let U=K>>B&Ws;j^=U,M=u(j,T,O),T=M[0],O=M[1],M=u(j,L,C),L=M[0],C=M[1],j=U;let R=T+L,P=n(R*R),w=T-L,S=n(w*w),I=P-S,_=O+C,H=O-C,J=n(H*R),Z=n(_*w),q=J+Z,F=J-Z;O=n(q*q),C=n(k*n(F*F)),T=n(P*S),L=n(I*(P+n(l*I)))}M=u(j,T,O),T=M[0],O=M[1],M=u(j,L,C),L=M[0],C=M[1];let z=a(L);return n(T*z)}function m(x){return Pe(n(x),o)}function p(x){let A=it("u coordinate",x,o);return s===32&&(A[31]&=127),Wt(A)}function h(x){let A=it("scalar",x),v=A.length;if(v!==o&&v!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${v}`);return Wt(c(A))}function d(x,A){let v=p(A),K=h(x),k=y(v,K);if(k===Hn)throw new Error("Invalid private or public key received");return m(k)}let g=m(t.Gu);function b(x){return d(x,g)}return{scalarMult:d,scalarMultBase:b,getSharedSecret:(x,A)=>d(x,A),getPublicKey:x=>b(x),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:g}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Gu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),_w=BigInt(0),Bp=BigInt(1),zs=BigInt(2),Pp=BigInt(5),Vu=BigInt(10),Kp=BigInt(20),Tp=BigInt(40),qu=BigInt(80);function Fu(r){let t=Jn,n=r*r%t*r%t,i=ot(n,zs,t)*n%t,o=ot(i,Bp,t)*r%t,s=ot(o,Pp,t)*o%t,c=ot(s,Vu,t)*s%t,a=ot(c,Kp,t)*c%t,u=ot(a,Tp,t)*a%t,f=ot(u,qu,t)*u%t,l=ot(f,qu,t)*u%t,y=ot(l,Vu,t)*s%t;return{pow_p_5_8:ot(y,zs,t)*r%t,b2:n}}function $u(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Sp(r,t){let e=Jn,n=tt(t*t*t,e),i=tt(n*n*t,e),o=Fu(r*i).pow_p_5_8,s=tt(r*n*o,e),c=tt(t*s*s,e),a=s,u=tt(s*Gu,e),f=c===r,l=c===tt(-r,e),y=c===tt(-r*Gu,e);return f&&(s=a),(l||y)&&(s=u),Bu(s,e)&&(s=tt(-s,e)),{isValid:f||l,value:s}}var jt=Wr(Jn,void 0,!0),Gn={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:jt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:$s,randomBytes:Nn,adjustScalarBytes:$u,uvRatio:Sp},$e=Vi(Gn);function Wu(r,t,e){if(t.length>255)throw new Error("Context is too big");return Ci(Is("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Lw=Vi({...Gn,domain:Wu}),Ow=Vi({...Gn,domain:Wu,prehash:$s}),Pr=Ju({P:Jn,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let t=Jn,{pow_p_5_8:e,b2:n}=Fu(r);return tt(ot(e,BigInt(3),t)*n,t)},adjustScalarBytes:$u,randomBytes:Nn});function zu(r){let{y:t}=$e.ExtendedPoint.fromHex(r),e=BigInt(1);return jt.toBytes(jt.create((e+t)*jt.inv(e-t)))}function Zu(r){let t=Gn.hash(r.subarray(0,32));return Gn.adjustScalarBytes(t).subarray(0,32)}var kp=(jt.ORDER+BigInt(3))/BigInt(8),Rw=jt.pow(zs,kp),Nw=jt.sqrt(jt.neg(jt.ONE)),Dw=(jt.ORDER-BigInt(5))/BigInt(8),Mw=BigInt(486662);var jw=Pu(jt,jt.neg(BigInt(486664)));var Hw=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Jw=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Gw=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vw=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var qw=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Ht=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=$e.getPublicKey(t),n={crv:"Ed25519",d:N.uint8Array(t).toBase64Url(),kty:"OKP",x:N.uint8Array(e).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"Ed25519",x:N.uint8Array(t).toBase64Url()};return e.kid=await G({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=$e.getPublicKey(e),i={kty:"OKP",crv:"Ed25519",x:N.uint8Array(n).toBase64Url()};return i.kid=await G({jwk:i}),i}static async convertPrivateKeyToX25519({privateKey:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=Zu(e),i=Pr.getPublicKey(n),o={kty:"OKP",crv:"X25519",d:N.uint8Array(n).toBase64Url(),x:N.uint8Array(i).toBase64Url()};return o.kid=await G({jwk:o}),o}static async convertPublicKeyToX25519({publicKey:t}){let e=await r.publicKeyToBytes({publicKey:t});if(!await r.validatePublicKey({publicKeyBytes:e}))throw new Error("Ed25519: Invalid public key.");let i=zu(e),o={kty:"OKP",crv:"X25519",x:N.uint8Array(i).toBase64Url()};return o.kid=await G({jwk:o}),o}static async generateKey(){let t=$e.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(Ut(t)&&t.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Ut(t))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!tn(t))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return N.base64Url(t.x).toUint8Array()}static async sign({key:t,data:e}){let n=await r.privateKeyToBytes({privateKey:t});return $e.sign(e,n)}static async validatePublicKey({publicKeyBytes:t}){try{$e.ExtendedPoint.fromHex(t).assertValidity()}catch{return!1}return!0}static async verify({key:t,signature:e,data:n}){let i=await r.publicKeyToBytes({publicKey:t});return $e.verify(e,n,i)}};var qi=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"Ed25519":{let n=await Ht.bytesToPrivateKey({privateKeyBytes:e});return n.alg="EdDSA",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async bytesToPublicKey({algorithm:t,publicKeyBytes:e}){switch(t){case"Ed25519":{let n=await Ht.bytesToPublicKey({publicKeyBytes:e});return n.alg="EdDSA",n}default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ht.computePublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"Ed25519":{let e=await Ht.generateKey();return e.alg="EdDSA",e}}}async getPublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":{let e=await Ht.getPublicKey({key:t});return e.alg="EdDSA",e}default:throw new Error(`Unsupported curve: ${t.crv}`)}}async sign({key:t,data:e}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"Ed25519":return await Ht.sign({key:t,data:e});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async verify({key:t,signature:e,data:n}){if(!tn(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(t.crv){case"Ed25519":return await Ht.verify({key:t,signature:e,data:n});default:throw new Error(`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){switch(t.crv){case"Ed25519":return await Ht.privateKeyToBytes({privateKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}async publicKeyToBytes({publicKey:t}){switch(t.crv){case"Ed25519":return await Ht.publicKeyToBytes({publicKey:t});default:throw new nt("algorithmNotSupported",`Curve not supported: ${t.crv}`)}}};var Fi=class extends ut{async digest({algorithm:t,data:e}){switch(t){case"SHA-256":return await Xr.digest({data:e})}}};var We=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e=Pr.getPublicKey(t),n={kty:"OKP",crv:"X25519",d:N.uint8Array(t).toBase64Url(),x:N.uint8Array(e).toBase64Url()};return n.kid=await G({jwk:n}),n}static async bytesToPublicKey({publicKeyBytes:t}){let e={kty:"OKP",crv:"X25519",x:N.uint8Array(t).toBase64Url()};return e.kid=await G({jwk:e}),e}static async computePublicKey({key:t}){let e=await r.privateKeyToBytes({privateKey:t}),n=Pr.getPublicKey(e),i={kty:"OKP",crv:"X25519",x:N.uint8Array(n).toBase64Url()};return i.kid=await G({jwk:i}),i}static async generateKey(){let t=Pr.utils.randomPrivateKey(),e=await r.bytesToPrivateKey({privateKeyBytes:t});return e.kid=await G({jwk:e}),e}static async getPublicKey({key:t}){if(!(Ut(t)&&t.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:e,...n}=t;return n.kid??=await G({jwk:n}),n}static async privateKeyToBytes({privateKey:t}){if(!Ut(t))throw new Error("X25519: The provided key is not a valid OKP private key.");return N.base64Url(t.d).toUint8Array()}static async publicKeyToBytes({publicKey:t}){if(!tn(t))throw new Error("X25519: The provided key is not a valid OKP public key.");return N.base64Url(t.x).toUint8Array()}static async sharedSecret({privateKeyA:t,publicKeyB:e}){if("x"in t&&"x"in e&&t.x===e.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let n=await r.privateKeyToBytes({privateKey:t}),i=await r.publicKeyToBytes({publicKey:e});return Pr.getSharedSecret(n,i)}};var $i=class extends ut{async bytesToPrivateKey({algorithm:t,privateKeyBytes:e}){switch(t){case"X25519":return We.bytesToPrivateKey({privateKeyBytes:e});default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async computePublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return We.computePublicKey({key:t});default:throw new nt("algorithmNotSupported",`Unsupported curve: ${t.crv}`)}}async generateKey({algorithm:t}){switch(t){case"X25519":return We.generateKey();default:throw new nt("algorithmNotSupported",`Algorithm not supported: ${t}`)}}async getPublicKey({key:t}){if(!Ut(t))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(t.crv){case"X25519":return We.getPublicKey({key:t});default:throw new nt("algorithmNotSupported",`Unsupported curve: ${t.crv}`)}}async privateKeyToBytes({privateKey:t}){return We.privateKeyToBytes({privateKey:t})}};var Zs={Ed25519:{implementation:qi,names:["Ed25519"]},secp256k1:{implementation:jn,names:["ES256K","secp256k1"]},secp256r1:{implementation:jn,names:["ES256","secp256r1"]},"SHA-256":{implementation:Fi,names:["SHA-256"]},X25519:{implementation:$i,names:["X25519"]}},Yu=class{constructor(t){this._algorithmInstances=new Map;this._keyStore=t?.keyStore??new Ti}async digest({algorithm:t,data:e}){return await this.getAlgorithm({algorithm:t}).digest({algorithm:t,data:e})}async exportKey({keyUri:t}){return await this.getPrivateKey({keyUri:t})}async generateKey({algorithm:t}){let n=await this.getAlgorithm({algorithm:t}).generateKey({algorithm:t});if(n?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let i=`${Vs}${n.kid}`;return await this._keyStore.set(i,n),i}async getKeyUri({key:t}){let e=await G({jwk:t});return`${Vs}${e}`}async getPublicKey({keyUri:t}){let e=await this.getPrivateKey({keyUri:t}),n=this.getAlgorithmName({key:e});return await this.getAlgorithm({algorithm:n}).getPublicKey({key:e})}async importKey({key:t}){if(!Mu(t))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let e=structuredClone(t);e.kid??=await G({jwk:e});let n=await this.getKeyUri({key:e});return await this._keyStore.set(n,e),n}async sign({keyUri:t,data:e}){let n=await this.getPrivateKey({keyUri:t}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:e,key:n})}async verify({key:t,signature:e,data:n}){let i=this.getAlgorithmName({key:t});return this.getAlgorithm({algorithm:i}).verify({key:t,signature:e,data:n})}getAlgorithm({algorithm:t}){let e=Zs[t]?.implementation;if(!e)throw new Error(`Algorithm not supported: ${t}`);return this._algorithmInstances.has(e)||this._algorithmInstances.set(e,new e),this._algorithmInstances.get(e)}getAlgorithmName({key:t}){let e=t.alg,n=t.crv;for(let i in Zs){let o=Zs[i];if(e&&o.names.includes(e))return i;if(n&&o.names.includes(n))return i}throw new Error(`Unable to determine algorithm based on provided input: alg=${e}, crv=${n}`)}async getPrivateKey({keyUri:t}){let e=await this._keyStore.get(t);if(!e)throw new Error(`Key not found: ${t}`);return e}};var Xu=class r{static getJoseSignatureAlgorithmFromPublicKey(t){let e={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(t.alg&&Object.values(e).includes(t.alg))return t.alg;if(t.crv&&Object.keys(e).includes(t.crv))return e[t.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${t.alg}, crv=${t.crv}. Supported 'alg' values: ${Object.values(e).join(", ")}. Supported 'crv' values: ${Object.keys(e).join(", ")}.`)}static randomBytes(t){return Ou(t)}static randomUuid(){return Se.randomUUID()}static randomPin({length:t}){if(3>t||t>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let e=Math.pow(10,t)-1,n;if(t<=6){let i=Math.pow(10,t);do{let o=r.randomBytes(Math.ceil(t/2));n=new DataView(o.buffer).getUint16(0,!1)%i}while(n>e)}else{let i=Math.pow(10,10);do{let o=r.randomBytes(4);n=new DataView(o.buffer).getUint32(0,!1)%i}while(n>e)}return n.toString().padStart(t,"0")}};function Ag(r){return r!==null&&typeof r=="object"&&"encrypt"in r&&typeof r.encrypt=="function"&&"decrypt"in r&&typeof r.decrypt=="function"}function Bg(r){return r!==null&&typeof r=="object"&&"exportKey"in r&&typeof r.exportKey=="function"}function Pg(r){return r!==null&&typeof r=="object"&&"importKey"in r&&typeof r.importKey=="function"}function Kg(r){return r!==null&&typeof r=="object"&&"wrapKey"in r&&typeof r.wrapKey=="function"&&"unwrapKey"in r&&typeof r.unwrapKey=="function"}var Kr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ys(r=32){if(Kr&&typeof Kr.getRandomValues=="function")return Kr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function ct(){if(Kr&&typeof Kr.subtle=="object"&&Kr.subtle!=null)return Kr.subtle;throw new Error("crypto.subtle must be defined")}var Vn=128,Qu=[128,192,256],Wi=Vn,en=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==Vn/8)throw new TypeError(`The counter must be ${Vn} bits in length`);if(i===0||i>Wi)throw new TypeError(`The 'length' property must be in the range 1 to ${Wi}`);let o=ct(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["decrypt"]),c=await o.decrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async encrypt({key:t,data:e,counter:n,length:i}){if(n.byteLength!==Vn/8)throw new TypeError(`The counter must be ${Vn} bits in length`);if(i===0||i>Wi)throw new TypeError(`The 'length' property must be in the range 1 to ${Wi}`);let o=ct(),s=await o.importKey("jwk",t,{name:"AES-CTR"},!0,["encrypt","decrypt"]),c=await o.encrypt({name:"AES-CTR",counter:n,length:i},s,e);return new Uint8Array(c)}static async generateKey({length:t}){if(!Qu.includes(t))throw new RangeError(`The key length is invalid: Must be ${Qu.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-CTR",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesCtr: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var tf=class extends ut{async decrypt(t){return en.decrypt(t)}async encrypt(t){return en.encrypt(t)}async generateKey({algorithm:t}){let e={A128CTR:128,A192CTR:192,A256CTR:256}[t],n=await en.generateKey({length:e});return n.alg=t,n}};function qn(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Xs(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Qs(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function V(r,...t){if(!Qs(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function ze(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Fn(r,t){V(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var zi=r=>new Uint8Array(r.buffer,r.byteOffset,r.byteLength);var Y=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Ze=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Up=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Up)throw new Error("Non little-endian hardware is not supported");function Ip(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ce(r){if(typeof r=="string")r=Ip(r);else if(Qs(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Zi(...r){let t=0;for(let n=0;n<r.length;n++){let i=r[n];V(i),t+=i.length}let e=new Uint8Array(t);for(let n=0,i=0;n<r.length;n++){let o=r[n];e.set(o,i),i+=o.length}return e}function ef(r,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(r,t)}function $n(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var ae=(r,t)=>(Object.assign(t,r),t);function Tr(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(e>>i&o),c=Number(e&o),a=n?4:0,u=n?0:4;r.setUint32(t+a,s,n),r.setUint32(t+u,c,n)}var rf={async encrypt(r,t,e,n){let i=ct(),o=await i.importKey("raw",r,t,!0,["encrypt"]),s=await i.encrypt(e,o,n);return new Uint8Array(s)},async decrypt(r,t,e,n){let i=ct(),o=await i.importKey("raw",r,t,!0,["decrypt"]),s=await i.decrypt(e,o,n);return new Uint8Array(s)}},ue={CBC:"AES-CBC",CTR:"AES-CTR",GCM:"AES-GCM"};function Cp(r,t,e){if(r===ue.CBC)return{name:ue.CBC,iv:t};if(r===ue.CTR)return{name:ue.CTR,counter:t,length:64};if(r===ue.GCM)return e?{name:ue.GCM,iv:t,additionalData:e}:{name:ue.GCM,iv:t};throw new Error("unknown aes block mode")}function tc(r){return(t,e,n)=>{V(t),V(e);let i={name:r,length:t.length*8},o=Cp(r,e,n);return{encrypt(s){return V(s),rf.encrypt(t,i,o,s)},decrypt(s){return V(s),rf.decrypt(t,i,o,s)}}}}var Hg=tc(ue.CBC),Jg=tc(ue.CTR),Gg=tc(ue.GCM);var Yi=96,nf=[128,192,256],Xi=[96,104,112,120,128],Ye=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({key:t,data:e,iv:n,additionalData:i,tagLength:o}){if(n.byteLength!==Yi/8)throw new TypeError(`The initialization vector must be ${Yi} bits in length`);if(o&&!Xi.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Xi.join(", ")} bits`);let s=ct(),c=await s.importKey("jwk",t,{name:"AES-GCM"},!0,["decrypt"]),a={name:"AES-GCM",iv:n,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.decrypt(a,c,e);return new Uint8Array(u)}static async encrypt({data:t,iv:e,key:n,additionalData:i,tagLength:o}){if(e.byteLength!==Yi/8)throw new TypeError(`The initialization vector must be ${Yi} bits in length`);if(o&&!Xi.includes(o))throw new RangeError(`The tag length is invalid: Must be ${Xi.join(", ")} bits`);let s=ct(),c=await s.importKey("jwk",n,{name:"AES-GCM"},!0,["encrypt"]),a={name:"AES-GCM",iv:e,...o&&{tagLength:o},...i&&{additionalData:i}},u=await s.encrypt(a,c,t);return new Uint8Array(u)}static async generateKey({length:t}){if(!nf.includes(t))throw new RangeError(`The key length is invalid: Must be ${nf.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-GCM",length:t},!0,["encrypt"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesGcm: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var of=class extends ut{async bytesToPrivateKey({privateKeyBytes:t}){let e=await Ye.bytesToPrivateKey({privateKeyBytes:t});return e.alg={16:"A128GCM",24:"A192GCM",32:"A256GCM"}[t.length],e}async decrypt(t){return Ye.decrypt(t)}async encrypt(t){return Ye.encrypt(t)}async generateKey({algorithm:t}){let e={A128GCM:128,A192GCM:192,A256GCM:256}[t],n=await Ye.generateKey({length:e});return n.alg=t,n}async privateKeyToBytes({privateKey:t}){return await Ye.privateKeyToBytes({privateKey:t})}};var sf=[128,192,256],Xe=class{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};e.kid=await G({jwk:e});let n=t.length*8;return e.alg={128:"A128KW",192:"A192KW",256:"A256KW"}[n],e}static async generateKey({length:t}){if(!sf.includes(t))throw new RangeError(`The key length is invalid: Must be ${sf.join(", ")} bits`);let e=ct(),n=await e.generateKey({name:"AES-KW",length:t},!0,["wrapKey","unwrapKey"]),{ext:i,key_ops:o,...s}=await e.exportKey("jwk",n);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("AesKw: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}static async unwrapKey({wrappedKeyBytes:t,wrappedKeyAlgorithm:e,decryptionKey:n}){if(!("alg"in n&&n.alg))throw new nt("invalidJwk","The decryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(n.alg))throw new nt("algorithmNotSupported",`The 'decryptionKey' algorithm is not supported: ${n.alg}`);let i=ct(),o=await i.importKey("jwk",n,{name:"AES-KW"},!0,["unwrapKey"]),s={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[e];if(!s)throw new nt("algorithmNotSupported",`The 'wrappedKeyAlgorithm' is not supported: ${e}`);let c=await i.unwrapKey("raw",t.buffer,o,"AES-KW",{name:s},!0,["unwrapKey"]),{ext:a,key_ops:u,...f}=await i.exportKey("jwk",c),l=f;return l.kid=await G({jwk:l}),l}static async wrapKey({unwrappedKey:t,encryptionKey:e}){if(!("alg"in e&&e.alg))throw new nt("invalidJwk","The encryption key is missing the 'alg' property.");if(!["A128KW","A192KW","A256KW"].includes(e.alg))throw new nt("algorithmNotSupported",`The 'encryptionKey' algorithm is not supported: ${e.alg}`);if(!("alg"in t&&t.alg))throw new nt("invalidJwk","The private key to wrap is missing the 'alg' property.");let n=ct(),i=await n.importKey("jwk",e,{name:"AES-KW"},!0,["wrapKey"]),o={A128KW:"AES-KW",A192KW:"AES-KW",A256KW:"AES-KW",A128GCM:"AES-GCM",A192GCM:"AES-GCM",A256GCM:"AES-GCM"}[t.alg];if(!o)throw new nt("algorithmNotSupported",`The 'unwrappedKey' algorithm is not supported: ${t.alg}`);let s=await n.importKey("jwk",t,{name:o},!0,["unwrapKey"]),c=await n.wrapKey("raw",s,i,"AES-KW");return new Uint8Array(c)}};var cf=class extends ut{async bytesToPrivateKey({privateKeyBytes:t}){let e=await Xe.bytesToPrivateKey({privateKeyBytes:t});return e.alg={16:"A128KW",24:"A192KW",32:"A256KW"}[t.length],e}async generateKey({algorithm:t}){let e={A128KW:128,A192KW:192,A256KW:256}[t],n=await Xe.generateKey({length:e});return n.alg=t,n}async privateKeyToBytes({privateKey:t}){return await Xe.privateKeyToBytes({privateKey:t})}async unwrapKey(t){return await Xe.unwrapKey(t)}async wrapKey(t){return Xe.wrapKey(t)}};var Qi=class{static async deriveKeyBytes({baseKeyBytes:t,length:e,hash:n,salt:i,info:o=new Uint8Array}){let s=ct(),c=await s.importKey("raw",t,{name:"HKDF"},!1,["deriveBits"]),a=typeof i=="string"?N.string(i).toUint8Array():i,u=typeof o=="string"?N.string(o).toUint8Array():o,f=await s.deriveBits({name:"HKDF",hash:n,salt:a,info:u},c,e);return new Uint8Array(f)}};var af=class extends ut{async deriveKeyBytes({algorithm:t,...e}){let n={"HKDF-256":"SHA-256","HKDF-384":"SHA-384","HKDF-512":"SHA-512"}[t];return await Qi.deriveKeyBytes({...e,hash:n})}};var to=class{static async deriveKey({hash:t,password:e,salt:n,iterations:i,length:o}){let s=await Se.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"]),c=await Se.subtle.deriveBits({name:"PBKDF2",hash:t,salt:n,iterations:i},s,o);return new Uint8Array(c)}static async deriveKeyBytes({baseKeyBytes:t,hash:e,salt:n,iterations:i,length:o}){let s=ct(),c=await s.importKey("raw",t,{name:"PBKDF2"},!1,["deriveBits"]),a=await s.deriveBits({name:"PBKDF2",hash:e,salt:n,iterations:i},c,o);return new Uint8Array(a)}};var uf=class extends ut{async deriveKeyBytes({algorithm:t,...e}){let[,n]=t.split(/[-+]/),i={HS256:"SHA-256",HS384:"SHA-384",HS512:"SHA-512"}[n];return await to.deriveKeyBytes({...e,hash:i})}};var ff=class r{static async deriveKey({keyDataLen:t,fixedInfo:e,sharedSecret:n}){let o=Math.ceil(t/256);if(o!==1)throw new Error(`Concat KDF with ${o} rounds not supported.`);let s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,o);let c=r.computeFixedInfo(e);return kt(Js(s,n,c)).slice(0,t/8)}static computeFixedInfo(t){let e=r.toDataLenData({data:t.algorithmId}),n=r.toDataLenData({data:t.partyUInfo}),i=r.toDataLenData({data:t.partyVInfo}),o=r.toDataLenData({data:t.suppPubInfo,variableLength:!1}),s=r.toDataLenData({data:t.suppPrivInfo});return Js(e,n,i,o,s)}static toDataLenData({data:t,variableLength:e=!0}){let n,i=an(t);if(i==="Undefined")return new Uint8Array(0);if(e){let o=i==="Uint8Array"?t:new N(t,i).toUint8Array(),s=o.length;n=new Uint8Array(4+s),new DataView(n.buffer).setUint32(0,s),n.set(o,4)}else{if(typeof t!="number")throw TypeError("Fixed length input must be a number.");n=new Uint8Array(4),new DataView(n.buffer).setUint32(0,t)}return n}};var ke=16,rc=new Uint8Array(16),fe=Y(rc),_p=225,Lp=(r,t,e,n)=>{let i=n&1;return{s3:e<<31|n>>>1,s2:t<<31|e>>>1,s1:r<<31|t>>>1,s0:r>>>1^_p<<24&-(i&1)}},Jt=r=>(r>>>0&255)<<24|(r>>>8&255)<<16|(r>>>16&255)<<8|r>>>24&255|0;function Op(r){r.reverse();let t=r[15]&1,e=0;for(let n=0;n<r.length;n++){let i=r[n];r[n]=i>>>1|e,e=(i&1)<<7}return r[0]^=-t&225,r}var Rp=r=>r>64*1024?8:r>1024?4:2,eo=class{constructor(t,e){this.blockLen=ke,this.outputLen=ke,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,t=ce(t),V(t,16);let n=Ze(t),i=n.getUint32(0,!1),o=n.getUint32(4,!1),s=n.getUint32(8,!1),c=n.getUint32(12,!1),a=[];for(let p=0;p<128;p++)a.push({s0:Jt(i),s1:Jt(o),s2:Jt(s),s3:Jt(c)}),{s0:i,s1:o,s2:s,s3:c}=Lp(i,o,s,c);let u=Rp(e||1024);if(![1,2,4,8].includes(u))throw new Error(`ghash: wrong window size=${u}, should be 2, 4 or 8`);this.W=u;let l=128/u,y=this.windowSize=2**u,m=[];for(let p=0;p<l;p++)for(let h=0;h<y;h++){let d=0,g=0,b=0,x=0;for(let A=0;A<u;A++){if(!(h>>>u-A-1&1))continue;let{s0:K,s1:k,s2:T,s3:L}=a[u*p+A];d^=K,g^=k,b^=T,x^=L}m.push({s0:d,s1:g,s2:b,s3:x})}this.t=m}_updateBlock(t,e,n,i){t^=this.s0,e^=this.s1,n^=this.s2,i^=this.s3;let{W:o,t:s,windowSize:c}=this,a=0,u=0,f=0,l=0,y=(1<<o)-1,m=0;for(let p of[t,e,n,i])for(let h=0;h<4;h++){let d=p>>>8*h&255;for(let g=8/o-1;g>=0;g--){let b=d>>>o*g&y,{s0:x,s1:A,s2:v,s3:K}=s[m*c+b];a^=x,u^=A,f^=v,l^=K,m+=1}}this.s0=a,this.s1=u,this.s2=f,this.s3=l}update(t){t=ce(t),ze(this);let e=Y(t),n=Math.floor(t.length/ke),i=t.length%ke;for(let o=0;o<n;o++)this._updateBlock(e[o*4+0],e[o*4+1],e[o*4+2],e[o*4+3]);return i&&(rc.set(t.subarray(n*ke)),this._updateBlock(fe[0],fe[1],fe[2],fe[3]),fe.fill(0)),this}destroy(){let{t}=this;for(let e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{s0:e,s1:n,s2:i,s3:o}=this,s=Y(t);return s[0]=e,s[1]=n,s[2]=i,s[3]=o,t}digest(){let t=new Uint8Array(ke);return this.digestInto(t),this.destroy(),t}},ec=class extends eo{constructor(t,e){t=ce(t);let n=Op(t.slice());super(n,e),n.fill(0)}update(t){t=ce(t),ze(this);let e=Y(t),n=t.length%ke,i=Math.floor(t.length/ke);for(let o=0;o<i;o++)this._updateBlock(Jt(e[o*4+3]),Jt(e[o*4+2]),Jt(e[o*4+1]),Jt(e[o*4+0]));return n&&(rc.set(t.subarray(i*ke)),this._updateBlock(Jt(fe[3]),Jt(fe[2]),Jt(fe[1]),Jt(fe[0])),fe.fill(0)),this}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{s0:e,s1:n,s2:i,s3:o}=this,s=Y(t);return s[0]=e,s[1]=n,s[2]=i,s[3]=o,t.reverse()}};function lf(r){let t=(n,i)=>r(i,n.length).update(ce(n)).digest(),e=r(new Uint8Array(16),0);return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=(n,i)=>r(n,i),t}var nc=lf((r,t)=>new eo(r,t)),hf=lf((r,t)=>new ec(r,t));var Et=16,sc=4,ro=new Uint8Array(Et),Np=283;function cc(r){return r<<1^Np&-(r>>7)}function rn(r,t){let e=0;for(;t>0;t>>=1)e^=r&-(t&1),r=cc(r);return e}var oc=(()=>{let r=new Uint8Array(256);for(let e=0,n=1;e<256;e++,n^=cc(n))r[e]=n;let t=new Uint8Array(256);t[0]=99;for(let e=0;e<255;e++){let n=r[255-e];n|=n<<8,t[r[e]]=(n^n>>4^n>>5^n>>6^n>>7^99)&255}return t})(),Dp=oc.map((r,t)=>oc.indexOf(t)),Mp=r=>r<<24|r>>>8,ic=r=>r<<8|r>>>24;function yf(r,t){if(r.length!==256)throw new Error("Wrong sbox length");let e=new Uint32Array(256).map((u,f)=>t(r[f])),n=e.map(ic),i=n.map(ic),o=i.map(ic),s=new Uint32Array(256*256),c=new Uint32Array(256*256),a=new Uint16Array(256*256);for(let u=0;u<256;u++)for(let f=0;f<256;f++){let l=u*256+f;s[l]=e[u]^n[f],c[l]=i[u]^o[f],a[l]=r[u]<<8|r[f]}return{sbox:r,sbox2:a,T0:e,T1:n,T2:i,T3:o,T01:s,T23:c}}var ac=yf(oc,r=>rn(r,3)<<24|r<<16|r<<8|rn(r,2)),pf=yf(Dp,r=>rn(r,11)<<24|rn(r,13)<<16|rn(r,9)<<8|rn(r,14)),jp=(()=>{let r=new Uint8Array(16);for(let t=0,e=1;t<16;t++,e=cc(e))r[t]=e;return r})();function tr(r){V(r);let t=r.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);let{sbox2:e}=ac,n=Y(r),i=n.length,o=c=>le(e,c,c,c,c),s=new Uint32Array(t+28);s.set(n);for(let c=i;c<s.length;c++){let a=s[c-1];c%i===0?a=o(Mp(a))^jp[c/i-1]:i>6&&c%i===4&&(a=o(a)),s[c]=s[c-i]^a}return s}function df(r){let t=tr(r),e=t.slice(),n=t.length,{sbox2:i}=ac,{T0:o,T1:s,T2:c,T3:a}=pf;for(let u=0;u<n;u+=4)for(let f=0;f<4;f++)e[u+f]=t[n-u-4+f];t.fill(0);for(let u=4;u<n-4;u++){let f=e[u],l=le(i,f,f,f,f);e[u]=o[l&255]^s[l>>>8&255]^c[l>>>16&255]^a[l>>>24]}return e}function Qe(r,t,e,n,i,o){return r[e<<8&65280|n>>>8&255]^t[i>>>8&65280|o>>>24&255]}function le(r,t,e,n,i){return r[t&255|e&65280]|r[n>>>16&255|i>>>16&65280]<<16}function Gt(r,t,e,n,i){let{sbox2:o,T01:s,T23:c}=ac,a=0;t^=r[a++],e^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let h=r[a++]^Qe(s,c,t,e,n,i),d=r[a++]^Qe(s,c,e,n,i,t),g=r[a++]^Qe(s,c,n,i,t,e),b=r[a++]^Qe(s,c,i,t,e,n);t=h,e=d,n=g,i=b}let f=r[a++]^le(o,t,e,n,i),l=r[a++]^le(o,e,n,i,t),y=r[a++]^le(o,n,i,t,e),m=r[a++]^le(o,i,t,e,n);return{s0:f,s1:l,s2:y,s3:m}}function mf(r,t,e,n,i){let{sbox2:o,T01:s,T23:c}=pf,a=0;t^=r[a++],e^=r[a++],n^=r[a++],i^=r[a++];let u=r.length/4-2;for(let p=0;p<u;p++){let h=r[a++]^Qe(s,c,t,i,n,e),d=r[a++]^Qe(s,c,e,t,i,n),g=r[a++]^Qe(s,c,n,e,t,i),b=r[a++]^Qe(s,c,i,n,e,t);t=h,e=d,n=g,i=b}let f=r[a++]^le(o,t,i,n,e),l=r[a++]^le(o,e,t,i,n),y=r[a++]^le(o,n,e,t,i),m=r[a++]^le(o,i,n,e,t);return{s0:f,s1:l,s2:y,s3:m}}function nn(r,t){if(!t)return new Uint8Array(r);if(V(t),t.length<r)throw new Error(`aes: wrong destination length, expected at least ${r}, got: ${t.length}`);return t}function Hp(r,t,e,n){V(t,Et),V(e);let i=e.length;n=nn(i,n);let o=t,s=Y(o),{s0:c,s1:a,s2:u,s3:f}=Gt(r,s[0],s[1],s[2],s[3]),l=Y(e),y=Y(n);for(let p=0;p+4<=l.length;p+=4){y[p+0]=l[p+0]^c,y[p+1]=l[p+1]^a,y[p+2]=l[p+2]^u,y[p+3]=l[p+3]^f;let h=1;for(let d=o.length-1;d>=0;d--)h=h+(o[d]&255)|0,o[d]=h&255,h>>>=8;({s0:c,s1:a,s2:u,s3:f}=Gt(r,s[0],s[1],s[2],s[3]))}let m=Et*Math.floor(l.length/sc);if(m<i){let p=new Uint32Array([c,a,u,f]),h=zi(p);for(let d=m,g=0;d<i;d++,g++)n[d]=e[d]^h[g]}return n}function Wn(r,t,e,n,i){V(e,Et),V(n),i=nn(n.length,i);let o=e,s=Y(o),c=Ze(o),a=Y(n),u=Y(i),f=t?0:12,l=n.length,y=c.getUint32(f,t),{s0:m,s1:p,s2:h,s3:d}=Gt(r,s[0],s[1],s[2],s[3]);for(let b=0;b+4<=a.length;b+=4)u[b+0]=a[b+0]^m,u[b+1]=a[b+1]^p,u[b+2]=a[b+2]^h,u[b+3]=a[b+3]^d,y=y+1>>>0,c.setUint32(f,y,t),{s0:m,s1:p,s2:h,s3:d}=Gt(r,s[0],s[1],s[2],s[3]);let g=Et*Math.floor(a.length/sc);if(g<l){let b=new Uint32Array([m,p,h,d]),x=zi(b);for(let A=g,v=0;A<l;A++,v++)i[A]=n[A]^x[v]}return i}var Sx=ae({blockSize:16,nonceLength:16},function(t,e){V(t),V(e,Et);function n(i,o){let s=tr(t),c=e.slice(),a=Hp(s,c,i,o);return s.fill(0),c.fill(0),a}return{encrypt:(i,o)=>n(i,o),decrypt:(i,o)=>n(i,o)}});function wf(r){if(V(r),r.length%Et!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${Et}`)}function gf(r,t,e){let n=r.length,i=n%Et;if(!t&&i!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");let o=Y(r);if(t){let a=Et-i;a||(a=Et),n=n+a}let s=nn(n,e),c=Y(s);return{b:o,o:c,out:s}}function xf(r,t){if(!t)return r;let e=r.length;if(!e)throw new Error("aes/pcks5: empty ciphertext not allowed");let n=r[e-1];if(n<=0||n>16)throw new Error(`aes/pcks5: wrong padding byte: ${n}`);let i=r.subarray(0,-n);for(let o=0;o<n;o++)if(r[e-o-1]!==n)throw new Error("aes/pcks5: wrong padding");return i}function bf(r){let t=new Uint8Array(16),e=Y(t);t.set(r);let n=Et-r.length;for(let i=Et-n;i<Et;i++)t[i]=n;return e}var kx=ae({blockSize:16},function(t,e={}){V(t);let n=!e.disablePadding;return{encrypt:(i,o)=>{V(i);let{b:s,o:c,out:a}=gf(i,n,o),u=tr(t),f=0;for(;f+4<=s.length;){let{s0:l,s1:y,s2:m,s3:p}=Gt(u,s[f+0],s[f+1],s[f+2],s[f+3]);c[f++]=l,c[f++]=y,c[f++]=m,c[f++]=p}if(n){let l=bf(i.subarray(f*4)),{s0:y,s1:m,s2:p,s3:h}=Gt(u,l[0],l[1],l[2],l[3]);c[f++]=y,c[f++]=m,c[f++]=p,c[f++]=h}return u.fill(0),a},decrypt:(i,o)=>{wf(i);let s=df(t),c=nn(i.length,o),a=Y(i),u=Y(c);for(let f=0;f+4<=a.length;){let{s0:l,s1:y,s2:m,s3:p}=mf(s,a[f+0],a[f+1],a[f+2],a[f+3]);u[f++]=l,u[f++]=y,u[f++]=m,u[f++]=p}return s.fill(0),xf(c,n)}}}),Ux=ae({blockSize:16,nonceLength:16},function(t,e,n={}){V(t),V(e,16);let i=!n.disablePadding;return{encrypt:(o,s)=>{let c=tr(t),{b:a,o:u,out:f}=gf(o,i,s),l=Y(e),y=l[0],m=l[1],p=l[2],h=l[3],d=0;for(;d+4<=a.length;)y^=a[d+0],m^=a[d+1],p^=a[d+2],h^=a[d+3],{s0:y,s1:m,s2:p,s3:h}=Gt(c,y,m,p,h),u[d++]=y,u[d++]=m,u[d++]=p,u[d++]=h;if(i){let g=bf(o.subarray(d*4));y^=g[0],m^=g[1],p^=g[2],h^=g[3],{s0:y,s1:m,s2:p,s3:h}=Gt(c,y,m,p,h),u[d++]=y,u[d++]=m,u[d++]=p,u[d++]=h}return c.fill(0),f},decrypt:(o,s)=>{wf(o);let c=df(t),a=Y(e),u=nn(o.length,s),f=Y(o),l=Y(u),y=a[0],m=a[1],p=a[2],h=a[3];for(let d=0;d+4<=f.length;){let g=y,b=m,x=p,A=h;y=f[d+0],m=f[d+1],p=f[d+2],h=f[d+3];let{s0:v,s1:K,s2:k,s3:T}=mf(c,y,m,p,h);l[d++]=v^g,l[d++]=K^b,l[d++]=k^x,l[d++]=T^A}return c.fill(0),xf(u,i)}}}),Ix=ae({blockSize:16,nonceLength:16},function(t,e){V(t),V(e,16);function n(i,o,s){let c=tr(t),a=i.length;s=nn(a,s);let u=Y(i),f=Y(s),l=o?f:u,y=Y(e),m=y[0],p=y[1],h=y[2],d=y[3];for(let b=0;b+4<=u.length;){let{s0:x,s1:A,s2:v,s3:K}=Gt(c,m,p,h,d);f[b+0]=u[b+0]^x,f[b+1]=u[b+1]^A,f[b+2]=u[b+2]^v,f[b+3]=u[b+3]^K,m=l[b++],p=l[b++],h=l[b++],d=l[b++]}let g=Et*Math.floor(u.length/sc);if(g<a){({s0:m,s1:p,s2:h,s3:d}=Gt(c,m,p,h,d));let b=zi(new Uint32Array([m,p,h,d]));for(let x=g,A=0;x<a;x++,A++)s[x]=i[x]^b[A];b.fill(0)}return c.fill(0),s}return{encrypt:(i,o)=>n(i,!0,o),decrypt:(i,o)=>n(i,!1,o)}});function Ef(r,t,e,n,i){let o=r.create(e,n.length+(i?.length||0));i&&o.update(i),o.update(n);let s=new Uint8Array(16),c=Ze(s);return i&&Tr(c,0,BigInt(i.length*8),t),Tr(c,8,BigInt(n.length*8),t),o.update(s),o.digest()}var uc=ae({blockSize:16,nonceLength:12,tagLength:16},function(t,e,n){if(V(e),e.length===0)throw new Error("aes/gcm: empty nonce");let i=16;function o(c,a,u){let f=Ef(nc,!1,c,u,n);for(let l=0;l<a.length;l++)f[l]^=a[l];return f}function s(){let c=tr(t),a=ro.slice(),u=ro.slice();if(Wn(c,!1,u,u,a),e.length===12)u.set(e);else{let l=ro.slice(),y=Ze(l);Tr(y,8,BigInt(e.length*8),!1),nc.create(a).update(e).update(l).digestInto(u)}let f=Wn(c,!1,u,ro);return{xk:c,authKey:a,counter:u,tagMask:f}}return{encrypt:c=>{V(c);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),y=new Uint8Array(c.length+i);Wn(a,!1,f,c,y);let m=o(u,l,y.subarray(0,y.length-i));return y.set(m,c.length),a.fill(0),y},decrypt:c=>{if(V(c),c.length<i)throw new Error(`aes/gcm: ciphertext less than tagLen (${i})`);let{xk:a,authKey:u,counter:f,tagMask:l}=s(),y=c.subarray(0,-i),m=c.subarray(-i),p=o(u,l,y);if(!$n(p,m))throw new Error("aes/gcm: invalid ghash tag");let h=Wn(a,!1,f,y);return u.fill(0),l.fill(0),a.fill(0),h}}}),no=(r,t,e)=>n=>{if(!Number.isSafeInteger(n)||t>n||n>e)throw new Error(`${r}: invalid value=${n}, must be [${t}..${e}]`)},Cx=ae({blockSize:16,nonceLength:12,tagLength:16},function(t,e,n){let o=no("AAD",0,68719476736),s=no("plaintext",0,2**36),c=no("nonce",12,12),a=no("ciphertext",16,2**36+16);V(e),c(e.length),n&&(V(n),o(n.length));function u(){let y=t.length;if(y!==16&&y!==24&&y!==32)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${y} bytes`);let m=tr(t),p=new Uint8Array(y),h=new Uint8Array(16),d=Y(e),g=0,b=d[0],x=d[1],A=d[2],v=0;for(let K of[h,p].map(Y)){let k=Y(K);for(let T=0;T<k.length;T+=2){let{s0:L,s1:O}=Gt(m,g,b,x,A);k[T+0]=L,k[T+1]=O,g=++v}}return m.fill(0),{authKey:h,encKey:tr(p)}}function f(y,m,p){let h=Ef(hf,!0,m,p,n);for(let v=0;v<12;v++)h[v]^=e[v];h[15]&=127;let d=Y(h),g=d[0],b=d[1],x=d[2],A=d[3];return{s0:g,s1:b,s2:x,s3:A}=Gt(y,g,b,x,A),d[0]=g,d[1]=b,d[2]=x,d[3]=A,h}function l(y,m,p){let h=m.slice();return h[15]|=128,Wn(y,!0,h,p)}return{encrypt:y=>{V(y),s(y.length);let{encKey:m,authKey:p}=u(),h=f(m,p,y),d=new Uint8Array(y.length+16);return d.set(h,y.length),d.set(l(m,h,y)),m.fill(0),p.fill(0),d},decrypt:y=>{V(y),a(y.length);let m=y.subarray(-16),{encKey:p,authKey:h}=u(),d=l(p,m,y.subarray(0,-16)),g=f(p,h,d);if(p.fill(0),h.fill(0),!$n(m,g))throw new Error("invalid polyval tag");return d}}});var io=class extends Yr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Mn(t);let n=Je(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?t.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return Zr(this),this.iHash.update(t),this}digestInto(t){Zr(this),zr(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:c}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},oo=(r,t,e)=>new io(r,t).update(e).digest();oo.create=(r,t)=>new io(r,t);function Jp(r,t,e){return Mn(r),e===void 0&&(e=new Uint8Array(r.outputLen)),oo(r,Je(e),Je(t))}var fc=new Uint8Array([0]),vf=new Uint8Array;function Gp(r,t,e,n=32){if(Mn(r),Mi(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/r.outputLen);e===void 0&&(e=vf);let o=new Uint8Array(i*r.outputLen),s=oo.create(r,t),c=s._cloneInto(),a=new Uint8Array(s.outputLen);for(let u=0;u<i;u++)fc[0]=u+1,c.update(u===0?vf:a).update(e).update(fc).digestInto(a),o.set(a,r.outputLen*u),s._cloneInto(c);return s.destroy(),c.destroy(),a.fill(0),fc.fill(0),o.slice(0,n)}var lc=(r,t,e,n,i)=>Gp(r,Jp(r,t,e),n,i);var Af=16,Vp=16,Bf=class{static encrypt(t,e){let n=at.utils.randomPrivateKey(),i=at.getPublicKey(n,!0),o=at.getPublicKey(n,!1),s=at.getSharedSecret(n,t,!1),c=lc(kt,Zi(o,s),void 0,void 0,32),a=Ys(Vp),u=uc(c,a).encrypt(e);return{ephemeralPublicKey:i,initializationVector:a,messageAuthenticationCode:u.subarray(u.length-Af),ciphertext:u.subarray(0,u.length-Af)}}static decrypt(t){let{privateKey:e,ephemeralPublicKey:n,initializationVector:i,messageAuthenticationCode:o,ciphertext:s}=t,c=at.ProjectivePoint.fromHex(n).toRawBytes(!1),a=at.getSharedSecret(e,n,!1),u=lc(kt,Zi(c,a),void 0,void 0,32),f=Zi(s,o);return uc(u,Uint8Array.from(i)).decrypt(f)}static get isEphemeralKeyCompressed(){return!0}};var dt=(r,t)=>r[t++]&255|(r[t++]&255)<<8,hc=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=ce(t),V(t,32);let e=dt(t,0),n=dt(t,2),i=dt(t,4),o=dt(t,6),s=dt(t,8),c=dt(t,10),a=dt(t,12),u=dt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=dt(t,16+2*f)}process(t,e,n=!1){let i=n?0:2048,{h:o,r:s}=this,c=s[0],a=s[1],u=s[2],f=s[3],l=s[4],y=s[5],m=s[6],p=s[7],h=s[8],d=s[9],g=dt(t,e+0),b=dt(t,e+2),x=dt(t,e+4),A=dt(t,e+6),v=dt(t,e+8),K=dt(t,e+10),k=dt(t,e+12),T=dt(t,e+14),L=o[0]+(g&8191),O=o[1]+((g>>>13|b<<3)&8191),C=o[2]+((b>>>10|x<<6)&8191),j=o[3]+((x>>>7|A<<9)&8191),M=o[4]+((A>>>4|v<<12)&8191),z=o[5]+(v>>>1&8191),B=o[6]+((v>>>14|K<<2)&8191),U=o[7]+((K>>>11|k<<5)&8191),R=o[8]+((k>>>8|T<<8)&8191),P=o[9]+(T>>>5|i),w=0,S=w+L*c+O*(5*d)+C*(5*h)+j*(5*p)+M*(5*m);w=S>>>13,S&=8191,S+=z*(5*y)+B*(5*l)+U*(5*f)+R*(5*u)+P*(5*a),w+=S>>>13,S&=8191;let I=w+L*a+O*c+C*(5*d)+j*(5*h)+M*(5*p);w=I>>>13,I&=8191,I+=z*(5*m)+B*(5*y)+U*(5*l)+R*(5*f)+P*(5*u),w+=I>>>13,I&=8191;let _=w+L*u+O*a+C*c+j*(5*d)+M*(5*h);w=_>>>13,_&=8191,_+=z*(5*p)+B*(5*m)+U*(5*y)+R*(5*l)+P*(5*f),w+=_>>>13,_&=8191;let H=w+L*f+O*u+C*a+j*c+M*(5*d);w=H>>>13,H&=8191,H+=z*(5*h)+B*(5*p)+U*(5*m)+R*(5*y)+P*(5*l),w+=H>>>13,H&=8191;let J=w+L*l+O*f+C*u+j*a+M*c;w=J>>>13,J&=8191,J+=z*(5*d)+B*(5*h)+U*(5*p)+R*(5*m)+P*(5*y),w+=J>>>13,J&=8191;let Z=w+L*y+O*l+C*f+j*u+M*a;w=Z>>>13,Z&=8191,Z+=z*c+B*(5*d)+U*(5*h)+R*(5*p)+P*(5*m),w+=Z>>>13,Z&=8191;let q=w+L*m+O*y+C*l+j*f+M*u;w=q>>>13,q&=8191,q+=z*a+B*c+U*(5*d)+R*(5*h)+P*(5*p),w+=q>>>13,q&=8191;let F=w+L*p+O*m+C*y+j*l+M*f;w=F>>>13,F&=8191,F+=z*u+B*a+U*c+R*(5*d)+P*(5*h),w+=F>>>13,F&=8191;let rt=w+L*h+O*p+C*m+j*y+M*l;w=rt>>>13,rt&=8191,rt+=z*f+B*u+U*a+R*c+P*(5*d),w+=rt>>>13,rt&=8191;let et=w+L*d+O*h+C*p+j*m+M*y;w=et>>>13,et&=8191,et+=z*l+B*f+U*u+R*a+P*c,w+=et>>>13,et&=8191,w=(w<<2)+w|0,w=w+S|0,S=w&8191,w=w>>>13,I+=w,o[0]=S,o[1]=I,o[2]=_,o[3]=H,o[4]=J,o[5]=Z,o[6]=q,o[7]=F,o[8]=rt,o[9]=et}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),i=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=i,i=t[c]>>>13,t[c]&=8191;t[0]+=i*5,i=t[0]>>>13,t[0]&=8191,t[1]+=i,i=t[1]>>>13,t[1]&=8191,t[2]+=i,n[0]=t[0]+5,i=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+i,i=n[c]>>>13,n[c]&=8191;n[9]-=8192;let o=(i^1)-1;for(let c=0;c<10;c++)n[c]&=o;o=~o;for(let c=0;c<10;c++)t[c]=t[c]&o|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let s=t[0]+e[0];t[0]=s&65535;for(let c=1;c<8;c++)s=(t[c]+e[c]|0)+(s>>>16)|0,t[c]=s&65535}update(t){ze(this);let{buffer:e,blockLen:n}=this;t=ce(t);let i=t.length;for(let o=0;o<i;){let s=Math.min(n-this.pos,i-o);if(s===n){for(;n<=i-o;o+=n)this.process(t,o);continue}e.set(t.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){ze(this),Fn(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:i}=this;if(i){for(e[i++]=1;i<16;i++)e[i]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)t[o++]=n[s]>>>0,t[o++]=n[s]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function qp(r){let t=(n,i)=>r(i).update(ce(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var Pf=qp(r=>new hc(r));var Tf=r=>Uint8Array.from(r.split("").map(t=>t.charCodeAt(0))),Fp=Tf("expand 16-byte k"),$p=Tf("expand 32-byte k"),Wp=Y(Fp),Sf=Y($p),Qx=Sf.slice();function D(r,t){return r<<t|r>>>32-t}function yc(r){return r.byteOffset%4===0}var so=64,zp=16,kf=2**32-1,Kf=new Uint32Array;function Zp(r,t,e,n,i,o,s,c){let a=i.length,u=new Uint8Array(so),f=Y(u),l=yc(i)&&yc(o),y=l?Y(i):Kf,m=l?Y(o):Kf;for(let p=0;p<a;s++){if(r(t,e,n,f,s,c),s>=kf)throw new Error("arx: counter overflow");let h=Math.min(so,a-p);if(l&&h===so){let d=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let g=0,b;g<zp;g++)b=d+g,m[b]=y[b]^f[g];p+=so;continue}for(let d=0,g;d<h;d++)g=p+d,o[g]=i[g]^u[d];p+=h}}function pc(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=ef({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return qn(i),qn(s),Xs(o),Xs(e),(c,a,u,f,l=0)=>{V(c),V(a),V(u);let y=u.length;if(f||(f=new Uint8Array(y)),V(f),qn(l),l<0||l>=kf)throw new Error("arx: counter overflow");if(f.length<y)throw new Error(`arx: output (${f.length}) is shorter than data (${y})`);let m=[],p=c.length,h,d;if(p===32)h=c.slice(),m.push(h),d=Sf;else if(p===16&&e)h=new Uint8Array(32),h.set(c),h.set(c,16),d=Wp,m.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);yc(a)||(a=a.slice(),m.push(a));let g=Y(h);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,g,Y(a.subarray(0,16)),g),a=a.subarray(16)}let b=16-i;if(b!==a.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){let A=new Uint8Array(12);A.set(a,o?0:12-a.length),a=A,m.push(a)}let x=Y(a);for(Zp(r,d,g,x,u,f,l,s);m.length>0;)m.pop().fill(0);return f}}function Cf(r,t,e,n,i,o=20){let s=r[0],c=r[1],a=r[2],u=r[3],f=t[0],l=t[1],y=t[2],m=t[3],p=t[4],h=t[5],d=t[6],g=t[7],b=i,x=e[0],A=e[1],v=e[2],K=s,k=c,T=a,L=u,O=f,C=l,j=y,M=m,z=p,B=h,U=d,R=g,P=b,w=x,S=A,I=v;for(let H=0;H<o;H+=2)K=K+O|0,P=D(P^K,16),z=z+P|0,O=D(O^z,12),K=K+O|0,P=D(P^K,8),z=z+P|0,O=D(O^z,7),k=k+C|0,w=D(w^k,16),B=B+w|0,C=D(C^B,12),k=k+C|0,w=D(w^k,8),B=B+w|0,C=D(C^B,7),T=T+j|0,S=D(S^T,16),U=U+S|0,j=D(j^U,12),T=T+j|0,S=D(S^T,8),U=U+S|0,j=D(j^U,7),L=L+M|0,I=D(I^L,16),R=R+I|0,M=D(M^R,12),L=L+M|0,I=D(I^L,8),R=R+I|0,M=D(M^R,7),K=K+C|0,I=D(I^K,16),U=U+I|0,C=D(C^U,12),K=K+C|0,I=D(I^K,8),U=U+I|0,C=D(C^U,7),k=k+j|0,P=D(P^k,16),R=R+P|0,j=D(j^R,12),k=k+j|0,P=D(P^k,8),R=R+P|0,j=D(j^R,7),T=T+M|0,w=D(w^T,16),z=z+w|0,M=D(M^z,12),T=T+M|0,w=D(w^T,8),z=z+w|0,M=D(M^z,7),L=L+O|0,S=D(S^L,16),B=B+S|0,O=D(O^B,12),L=L+O|0,S=D(S^L,8),B=B+S|0,O=D(O^B,7);let _=0;n[_++]=s+K|0,n[_++]=c+k|0,n[_++]=a+T|0,n[_++]=u+L|0,n[_++]=f+O|0,n[_++]=l+C|0,n[_++]=y+j|0,n[_++]=m+M|0,n[_++]=p+z|0,n[_++]=h+B|0,n[_++]=d+U|0,n[_++]=g+R|0,n[_++]=b+P|0,n[_++]=x+w|0,n[_++]=A+S|0,n[_++]=v+I|0}function Yp(r,t,e,n){let i=r[0],o=r[1],s=r[2],c=r[3],a=t[0],u=t[1],f=t[2],l=t[3],y=t[4],m=t[5],p=t[6],h=t[7],d=e[0],g=e[1],b=e[2],x=e[3];for(let v=0;v<20;v+=2)i=i+a|0,d=D(d^i,16),y=y+d|0,a=D(a^y,12),i=i+a|0,d=D(d^i,8),y=y+d|0,a=D(a^y,7),o=o+u|0,g=D(g^o,16),m=m+g|0,u=D(u^m,12),o=o+u|0,g=D(g^o,8),m=m+g|0,u=D(u^m,7),s=s+f|0,b=D(b^s,16),p=p+b|0,f=D(f^p,12),s=s+f|0,b=D(b^s,8),p=p+b|0,f=D(f^p,7),c=c+l|0,x=D(x^c,16),h=h+x|0,l=D(l^h,12),c=c+l|0,x=D(x^c,8),h=h+x|0,l=D(l^h,7),i=i+u|0,x=D(x^i,16),p=p+x|0,u=D(u^p,12),i=i+u|0,x=D(x^i,8),p=p+x|0,u=D(u^p,7),o=o+f|0,d=D(d^o,16),h=h+d|0,f=D(f^h,12),o=o+f|0,d=D(d^o,8),h=h+d|0,f=D(f^h,7),s=s+l|0,g=D(g^s,16),y=y+g|0,l=D(l^y,12),s=s+l|0,g=D(g^s,8),y=y+g|0,l=D(l^y,7),c=c+a|0,b=D(b^c,16),m=m+b|0,a=D(a^m,12),c=c+a|0,b=D(b^c,8),m=m+b|0,a=D(a^m,7);let A=0;n[A++]=i,n[A++]=o,n[A++]=s,n[A++]=c,n[A++]=d,n[A++]=g,n[A++]=b,n[A++]=x}var Xp=pc(Cf,{counterRight:!1,counterLength:4,allowShortKeys:!1}),co=pc(Cf,{counterRight:!1,counterLength:8,extendNonceFn:Yp,allowShortKeys:!1});var Qp=new Uint8Array(16),Uf=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(Qp.subarray(e))},td=new Uint8Array(32);function If(r,t,e,n,i){let o=r(t,e,td),s=Pf.create(o);i&&Uf(s,i),Uf(s,n);let c=new Uint8Array(16),a=Ze(c);Tr(a,0,BigInt(i?i.length:0),!0),Tr(a,8,BigInt(n.length),!0),s.update(c);let u=s.digest();return o.fill(0),u}var _f=r=>(t,e,n)=>(V(t,32),V(e),{encrypt:(o,s)=>{let c=o.length,a=c+16;s?V(s,a):s=new Uint8Array(a),r(t,e,o,s,1);let u=If(r,t,e,s.subarray(0,-16),n);return s.set(u,c),s},decrypt:(o,s)=>{let c=o.length,a=c-16;if(c<16)throw new Error("encrypted data must be at least 16 bytes");s?V(s,a):s=new Uint8Array(a);let u=o.subarray(0,-16),f=o.subarray(-16),l=If(r,t,e,u,n);if(!$n(f,l))throw new Error("invalid tag");return r(t,e,u,s,1),s}}),ob=ae({blockSize:64,nonceLength:12,tagLength:16},_f(Xp)),dc=ae({blockSize:64,nonceLength:24,tagLength:16},_f(co));var Lf=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return co(i,n,t)}static async encrypt({data:t,key:e,nonce:n}){let i=await r.privateKeyToBytes({privateKey:e});return co(i,n,t)}static async generateKey(){let t=ct(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("XChaCha20: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};var mb=16,Of=class r{static async bytesToPrivateKey({privateKeyBytes:t}){let e={k:N.uint8Array(t).toBase64Url(),kty:"oct"};return e.kid=await G({jwk:e}),e}static async decrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.decryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async decryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return dc(e,n,i).decrypt(t)}static async encrypt({data:t,key:e,nonce:n,additionalData:i}){let o=await r.privateKeyToBytes({privateKey:e});return r.encryptRaw({data:t,keyBytes:o,nonce:n,additionalData:i})}static async encryptRaw({data:t,keyBytes:e,nonce:n,additionalData:i}){return dc(e,n,i).encrypt(t)}static async generateKey(){let t=ct(),e=await t.generateKey({name:"AES-CTR",length:256},!0,["encrypt"]),{alg:n,ext:i,key_ops:o,...s}=await t.exportKey("jwk",e);return s.kid=await G({jwk:s}),s}static async privateKeyToBytes({privateKey:t}){if(!se(t))throw new Error("XChaCha20Poly1305: The provided key is not a valid oct private key.");return N.base64Url(t.k).toUint8Array()}};export{Xi as AES_GCM_TAG_LENGTHS,en as AesCtr,tf as AesCtrAlgorithm,Ye as AesGcm,of as AesGcmAlgorithm,Xe as AesKw,cf as AesKwAlgorithm,ff as ConcatKdf,ut as CryptoAlgorithm,nt as CryptoError,sn as CryptoErrorCode,Xu as CryptoUtils,jn as EcdsaAlgorithm,Bf as EciesSecp256k1,Ht as Ed25519,qi as EdDsaAlgorithm,Qi as Hkdf,af as HkdfAlgorithm,Vs as KEY_URI_PREFIX_JWK,Yu as LocalKeyManager,Mt as P256,mb as POLY1305_TAG_LENGTH,to as Pbkdf2,uf as Pbkdf2Algorithm,Dt as Secp256k1,Mt as Secp256r1,Xr as Sha256,Fi as Sha2Algorithm,We as X25519,$i as X25519Algorithm,Lf as XChaCha20,Of as XChaCha20Poly1305,Du as canonicalize,G as computeJwkThumbprint,Ag as isCipher,oe as isEcPrivateJwk,Qr as isEcPublicJwk,Bg as isKeyExporter,Pg as isKeyImporter,Kg as isKeyWrapper,se as isOctPrivateJwk,Ut as isOkpPrivateJwk,tn as isOkpPublicJwk,Mu as isPrivateJwk,Fm as isPublicJwk};
|
|
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:
|